Add Verilator support
This commit is contained in:
58
_web_server/server/top_verilator.cpp
Normal file
58
_web_server/server/top_verilator.cpp
Normal file
@@ -0,0 +1,58 @@
|
||||
#include "V@TOPMODULE@.h"
|
||||
|
||||
#include <cstdint>
|
||||
#include <verilated.h>
|
||||
#include <verilated_vcd_c.h>
|
||||
|
||||
#define DUMPFILE "@WORKDIR@/@TOPMODULE@.vcd"
|
||||
#define CLOCK_HALF_PERIOD 5000
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
VerilatedContext *ctx = new VerilatedContext;
|
||||
ctx->commandArgs(argc, argv);
|
||||
|
||||
/* Create model instance */
|
||||
V@TOPMODULE@ *top = new V@TOPMODULE@(ctx);
|
||||
|
||||
#if (VM_TRACE == 1)
|
||||
VerilatedVcdC *vcd = new VerilatedVcdC;
|
||||
ctx->traceEverOn(true);
|
||||
top->trace(vcd, 99);
|
||||
vcd->open(DUMPFILE);
|
||||
#endif
|
||||
|
||||
top->clock = 0;
|
||||
|
||||
/* ---- Evaluation loop ---- */
|
||||
for (;;) {
|
||||
/* Eval */
|
||||
top->eval();
|
||||
|
||||
/* Trace steady-state values */
|
||||
#if (VM_TRACE == 1)
|
||||
if (vcd) vcd->dump(ctx->time());
|
||||
#endif
|
||||
|
||||
/* Break exactly after calling $finish */
|
||||
if (ctx->gotFinish()) break;
|
||||
|
||||
/* Clock event */
|
||||
ctx->timeInc(CLOCK_HALF_PERIOD);
|
||||
top->clock = top->clock ? 0 : 1;
|
||||
}
|
||||
|
||||
top->final();
|
||||
printf("[%lu] Stop simulation\n", ctx->time());
|
||||
|
||||
#if (VM_TRACE == 1)
|
||||
if (vcd) {
|
||||
vcd->close();
|
||||
delete vcd;
|
||||
}
|
||||
#endif
|
||||
|
||||
delete top;
|
||||
delete ctx;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user