From 9085e34d7096afa6c9354c9701322cbad946b6de Mon Sep 17 00:00:00 2001 From: Geza Lore Date: Mon, 18 Jul 2022 13:14:24 +0100 Subject: [PATCH] Pass VerilatedModel at trace registration time --- include/verilated_trace.h | 10 +++++----- include/verilated_trace_imp.h | 19 ++++++++++--------- src/V3EmitCModel.cpp | 2 +- src/V3Trace.cpp | 6 ++---- 4 files changed, 18 insertions(+), 19 deletions(-) diff --git a/include/verilated_trace.h b/include/verilated_trace.h index 0d0f7c0f6..5e7fc85c2 100644 --- a/include/verilated_trace.h +++ b/include/verilated_trace.h @@ -215,7 +215,7 @@ private: double m_timeRes = 1e-9; // Time resolution (ns/ms etc) double m_timeUnit = 1e-0; // Time units (ns/ms etc) - void addContext(VerilatedContext*) VL_MT_SAFE_EXCLUDES(m_mutex); + void addModel(VerilatedModel*) VL_MT_SAFE_EXCLUDES(m_mutex); void addCallbackRecord(std::vector& cbVec, CallbackRecord&& cbRec) VL_MT_SAFE_EXCLUDES(m_mutex); @@ -339,10 +339,10 @@ public: //========================================================================= // Non-hot path internal interface to Verilator generated code - void addInitCb(initCb_t cb, void* userp, VerilatedContext*) VL_MT_SAFE; - void addFullCb(dumpCb_t cb, void* userp, VerilatedContext*) VL_MT_SAFE; - void addChgCb(dumpCb_t cb, void* userp, VerilatedContext*) VL_MT_SAFE; - void addCleanupCb(cleanupCb_t cb, void* userp, VerilatedContext*) VL_MT_SAFE; + void addInitCb(initCb_t cb, void* userp, VerilatedModel*) VL_MT_SAFE; + void addFullCb(dumpCb_t cb, void* userp, VerilatedModel*) VL_MT_SAFE; + void addChgCb(dumpCb_t cb, void* userp, VerilatedModel*) VL_MT_SAFE; + void addCleanupCb(cleanupCb_t cb, void* userp, VerilatedModel*) VL_MT_SAFE; void scopeEscape(char flag) { m_scopeEscape = flag; } diff --git a/include/verilated_trace_imp.h b/include/verilated_trace_imp.h index a09ac0f43..d20c09166 100644 --- a/include/verilated_trace_imp.h +++ b/include/verilated_trace_imp.h @@ -604,9 +604,10 @@ void VerilatedTrace::dump(uint64_t timeui) VL_MT_SAFE_EXCLUD // Non-hot path internal interface to Verilator generated code template <> -void VerilatedTrace::addContext(VerilatedContext* contextp) +void VerilatedTrace::addModel(VerilatedModel* modelp) VL_MT_SAFE_EXCLUDES(m_mutex) { const VerilatedLockGuard lock{m_mutex}; + VerilatedContext* const contextp = modelp->contextp(); if (m_contextp && contextp != m_contextp) { VL_FATAL_MT( __FILE__, __LINE__, "", @@ -630,26 +631,26 @@ void VerilatedTrace::addCallbackRecord(std::vector void VerilatedTrace::addInitCb(initCb_t cb, void* userp, - VerilatedContext* contextp) VL_MT_SAFE { - addContext(contextp); + VerilatedModel* modelp) VL_MT_SAFE { + addModel(modelp); addCallbackRecord(m_initCbs, CallbackRecord{cb, userp}); } template <> void VerilatedTrace::addFullCb(dumpCb_t cb, void* userp, - VerilatedContext* contextp) VL_MT_SAFE { - addContext(contextp); + VerilatedModel* modelp) VL_MT_SAFE { + addModel(modelp); addCallbackRecord(m_fullCbs, CallbackRecord{cb, userp}); } template <> void VerilatedTrace::addChgCb(dumpCb_t cb, void* userp, - VerilatedContext* contextp) VL_MT_SAFE { - addContext(contextp); + VerilatedModel* modelp) VL_MT_SAFE { + addModel(modelp); addCallbackRecord(m_chgCbs, CallbackRecord{cb, userp}); } template <> void VerilatedTrace::addCleanupCb(cleanupCb_t cb, void* userp, - VerilatedContext* contextp) VL_MT_SAFE { - addContext(contextp); + VerilatedModel* modelp) VL_MT_SAFE { + addModel(modelp); addCallbackRecord(m_cleanupCbs, CallbackRecord{cb, userp}); } diff --git a/src/V3EmitCModel.cpp b/src/V3EmitCModel.cpp index 04b422a97..67c02e332 100644 --- a/src/V3EmitCModel.cpp +++ b/src/V3EmitCModel.cpp @@ -540,7 +540,7 @@ class EmitCModel final : public EmitCFunc { } puts(/**/ "if (false && levels && options) {} // Prevent unused\n"); puts(/**/ "tfp->spTrace()->addInitCb(&" + protect("trace_init") - + ", &(vlSymsp->TOP), contextp());\n"); + + ", &(vlSymsp->TOP), this);\n"); puts(/**/ topModNameProtected + "__" + protect("trace_register") + "(&(vlSymsp->TOP), tfp->spTrace());\n"); diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index 7113c5e0e..e7a445c1a 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -513,8 +513,7 @@ private: } m_regFuncp->addStmtsp(new AstAddrOfCFunc(flp, funcp)); m_regFuncp->addStmtsp(new AstText(flp, ", vlSelf", true)); - m_regFuncp->addStmtsp( - new AstText(flp, ", vlSelf->vlSymsp->__Vm_modelp->contextp()", true)); + m_regFuncp->addStmtsp(new AstText(flp, ", vlSelf->vlSymsp->__Vm_modelp", true)); m_regFuncp->addStmtsp(new AstText(flp, ");\n", true)); } else { // Sub functions @@ -702,8 +701,7 @@ private: // Register it m_regFuncp->addStmtsp(new AstText(fl, "tracep->addCleanupCb(", true)); m_regFuncp->addStmtsp(new AstAddrOfCFunc(fl, cleanupFuncp)); - m_regFuncp->addStmtsp( - new AstText(fl, ", vlSelf, vlSelf->vlSymsp->__Vm_modelp->contextp());\n", true)); + m_regFuncp->addStmtsp(new AstText(fl, ", vlSelf, vlSelf->vlSymsp->__Vm_modelp);\n", true)); // Clear global activity flag cleanupFuncp->addStmtsp(