Examples: Add +trace flag at runtime

This commit is contained in:
Wilson Snyder 2017-11-05 06:51:29 -05:00
parent 6edaef9598
commit dfd22b2b07
4 changed files with 25 additions and 15 deletions

View File

@ -73,7 +73,7 @@ run:
@echo
@echo "-- RUN ---------------------"
@mkdir -p logs
obj_dir/Vtop | tee logs/sim.log
obj_dir/Vtop +trace | tee logs/sim.log
@echo
@echo "-- COVERAGE ----------------"

View File

@ -41,14 +41,19 @@ int main(int argc, char** argv, char** env) {
// Construct the Verilated model, from Vtop.h generated from Verilating "top.v"
Vtop* top = new Vtop; // Or use a const unique_ptr, or the VL_UNIQUE_PTR wrapper
// If verilator was invoked with --trace, open trace
#if VM_TRACE
Verilated::traceEverOn(true); // Verilator must compute traced signals
VL_PRINTF("Enabling waves into logs/vlt_dump.vcd...\n");
VerilatedVcdC* tfp = new VerilatedVcdC;
top->trace(tfp, 99); // Trace 99 levels of hierarchy
mkdir("logs", 0777);
tfp->open("logs/vlt_dump.vcd"); // Open the dump file
// If verilator was invoked with --trace argument,
// and if at run time passed the +trace argument, turn on tracing
VerilatedVcdC* tfp = NULL;
const char* flag = Verilated::commandArgsPlusMatch("trace");
if (flag && 0==strcmp(flag, "+trace")) {
Verilated::traceEverOn(true); // Verilator must compute traced signals
VL_PRINTF("Enabling waves into logs/vlt_dump.vcd...\n");
tfp = new VerilatedVcdC;
top->trace(tfp, 99); // Trace 99 levels of hierarchy
mkdir("logs", 0777);
tfp->open("logs/vlt_dump.vcd"); // Open the dump file
}
#endif
// Set some inputs

View File

@ -81,7 +81,7 @@ run:
@echo
@echo "-- RUN ---------------------"
@mkdir -p logs
obj_dir/Vtop | tee logs/sim.log
obj_dir/Vtop +trace | tee logs/sim.log
@echo
@echo "-- COVERAGE ----------------"

View File

@ -87,13 +87,18 @@ int sc_main(int argc, char* argv[]) {
sc_start(1);
#endif
// Turn on waves
#if VM_TRACE
cout << "Enabling waves into logs/vlt_dump.vcd...\n";
VerilatedVcdSc* tfp = new VerilatedVcdSc;
top->trace (tfp, 99);
mkdir("logs", 0777);
tfp->open ("logs/vlt_dump.vcd");
// If verilator was invoked with --trace argument,
// and if at run time passed the +trace argument, turn on tracing
VerilatedVcdSc* tfp = NULL;
const char* flag = Verilated::commandArgsPlusMatch("trace");
if (flag && 0==strcmp(flag, "+trace")) {
cout << "Enabling waves into logs/vlt_dump.vcd...\n";
VerilatedVcdSc* tfp = new VerilatedVcdSc;
top->trace (tfp, 99);
mkdir("logs", 0777);
tfp->open ("logs/vlt_dump.vcd");
}
#endif
// Simulate until $finish