diff --git a/docs/guide/faq.rst b/docs/guide/faq.rst index ca99d5e7e..5628828ec 100644 --- a/docs/guide/faq.rst +++ b/docs/guide/faq.rst @@ -118,9 +118,9 @@ A. Pass the :vlopt:`--trace` option to Verilator, and in your top level C B. Or, for finer-grained control, or C++ files with multiple Verilated modules you may also create the trace purely from C++. Create a - VerilatedVcdC object, and in your main loop call - ``trace_object->dump(time)`` every time step, and finally call - ``trace_object->close()``. + VerilatedVcdC object, and in your main loop right after ``eval()`` call + ``trace_object->dump(contextp->time())`` every time step, and finally + call ``trace_object->close()``. .. code-block:: C++ :emphasize-lines: 1,5-8,12 @@ -128,15 +128,17 @@ B. Or, for finer-grained control, or C++ files with multiple Verilated #include "verilated_vcd_c.h" ... int main(int argc, char** argv, char** env) { + const std::unique_ptr contextp{new VerilatedContext}; ... Verilated::traceEverOn(true); VerilatedVcdC* tfp = new VerilatedVcdC; topp->trace(tfp, 99); // Trace 99 levels of hierarchy tfp->open("obj_dir/t_trace_ena_cc/simx.vcd"); ... - while (Verilated::time() < sim_time && !Verilated::gotFinish()) { - Verilated::timeInc(1); - tfp->dump(main_time); + while (contextp->time() < sim_time && !contextp->gotFinish()) { + contextp->timeInc(1); + topp->eval(); + tfp->dump(contextp->time()); } tfp->close(); } diff --git a/include/verilated_fst_c.h b/include/verilated_fst_c.h index 3a8e404c5..2426a3e5a 100644 --- a/include/verilated_fst_c.h +++ b/include/verilated_fst_c.h @@ -152,6 +152,8 @@ public: /// Flush dump void flush() VL_MT_SAFE { m_sptrace.flush(); } /// Write one cycle of dump data + /// Call with the current context's time just after eval'ed, + /// e.g. ->dump(contextp->time()) void dump(vluint64_t timeui) { m_sptrace.dump(timeui); } /// Write one cycle of dump data - backward compatible and to reduce /// conversion warnings. It's better to use a vluint64_t time instead. diff --git a/include/verilated_vcd_c.h b/include/verilated_vcd_c.h index f6fdd1494..d167d3977 100644 --- a/include/verilated_vcd_c.h +++ b/include/verilated_vcd_c.h @@ -368,6 +368,8 @@ public: /// Flush dump void flush() VL_MT_SAFE { m_sptrace.flush(); } /// Write one cycle of dump data + /// Call with the current context's time just after eval'ed, + /// e.g. ->dump(contextp->time()) void dump(vluint64_t timeui) VL_MT_SAFE { m_sptrace.dump(timeui); } /// Write one cycle of dump data - backward compatible and to reduce /// conversion warnings. It's better to use a vluint64_t time instead.