Skip to content

Commit

Permalink
Add plusargs support to testbench.cc
Browse files Browse the repository at this point in the history
Signed-off-by: Claire Wolf <claire@symbioticeda.com>
  • Loading branch information
ldoolitt authored and clairexen committed Apr 23, 2020
1 parent 9129d18 commit e03c43e
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions testbench.cc
Expand Up @@ -7,23 +7,37 @@ int main(int argc, char **argv, char **env)
printf("Recommended: Verilator 4.0 or later.\n");

Verilated::commandArgs(argc, argv);
Verilated::traceEverOn(true);
Vpicorv32_wrapper* top = new Vpicorv32_wrapper;

VerilatedVcdC* tfp = new VerilatedVcdC;
top->trace (tfp, 99);
tfp->open ("testbench.vcd");
// Tracing (vcd)
VerilatedVcdC* tfp = NULL;
const char* flag_vcd = Verilated::commandArgsPlusMatch("vcd");
if (flag_vcd && 0==strcmp(flag_vcd, "+vcd")) {
Verilated::traceEverOn(true);
tfp = new VerilatedVcdC;
top->trace (tfp, 99);
tfp->open("testbench.vcd");
}

// Tracing (data bus, see showtrace.py)
FILE *trace_fd = NULL;
const char* flag_trace = Verilated::commandArgsPlusMatch("trace");
if (flag_trace && 0==strcmp(flag_trace, "+trace")) {
trace_fd = fopen("testbench.trace", "w");
}

top->clk = 0;
int t = 0;
while (!Verilated::gotFinish()) {
if (t > 200)
top->resetn = 1;
top->clk = !top->clk;
top->eval();
tfp->dump (t);
if (tfp) tfp->dump (t);
if (trace_fd && top->clk && top->trace_valid) fprintf(trace_fd, "%9.9lx\n", top->trace_data);
t += 5;
}
tfp->close();
if (tfp) tfp->close();
delete top;
exit(0);
}
Expand Down

0 comments on commit e03c43e

Please sign in to comment.