40 lines
645 B
C++
40 lines
645 B
C++
#pragma once
|
|
#include <verilated.h>
|
|
#include "util.hpp"
|
|
|
|
/* https://zipcpu.com/blog/2017/06/21/looking-at-verilator.html */
|
|
template <class TOP> class TB {
|
|
int tick_count;
|
|
int bailout;
|
|
|
|
public:
|
|
TOP mod;
|
|
VerilatedContext vc;
|
|
|
|
TB(int argc, char *argv[], int _bailout = 0) : mod(), bailout(_bailout), vc() {
|
|
vc.commandArgs(argc, argv);
|
|
vc.traceEverOn(true);
|
|
|
|
mod.clk = 0;
|
|
tick_count = 0;
|
|
}
|
|
|
|
virtual ~TB() {
|
|
mod.final();
|
|
}
|
|
|
|
void run_clock() {
|
|
mod.clk = !mod.clk;
|
|
mod.eval();
|
|
vc.timeInc(1);
|
|
|
|
mod.clk = !mod.clk;
|
|
mod.eval();
|
|
vc.timeInc(1);
|
|
tick_count++;
|
|
|
|
if (bailout > 0 && tick_count >= bailout)
|
|
exit(1);
|
|
}
|
|
};
|