From dfd22b2b0733502fd01d67de81ea8472b453360a Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 5 Nov 2017 06:51:29 -0500 Subject: [PATCH] Examples: Add +trace flag at runtime --- examples/tracing_c/Makefile | 2 +- examples/tracing_c/sim_main.cpp | 19 ++++++++++++------- examples/tracing_sc/Makefile | 2 +- examples/tracing_sc/sc_main.cpp | 17 +++++++++++------ 4 files changed, 25 insertions(+), 15 deletions(-) diff --git a/examples/tracing_c/Makefile b/examples/tracing_c/Makefile index 7383b7c42..70bb03dbd 100644 --- a/examples/tracing_c/Makefile +++ b/examples/tracing_c/Makefile @@ -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 ----------------" diff --git a/examples/tracing_c/sim_main.cpp b/examples/tracing_c/sim_main.cpp index 44dd601ea..76d126688 100644 --- a/examples/tracing_c/sim_main.cpp +++ b/examples/tracing_c/sim_main.cpp @@ -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 diff --git a/examples/tracing_sc/Makefile b/examples/tracing_sc/Makefile index df56150c3..6a24a4ebc 100644 --- a/examples/tracing_sc/Makefile +++ b/examples/tracing_sc/Makefile @@ -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 ----------------" diff --git a/examples/tracing_sc/sc_main.cpp b/examples/tracing_sc/sc_main.cpp index 29ed072cb..2365f0f60 100644 --- a/examples/tracing_sc/sc_main.cpp +++ b/examples/tracing_sc/sc_main.cpp @@ -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