diff --git a/include/verilated_saif_c.cpp b/include/verilated_saif_c.cpp index ff3b1c3aa..ede0b27e7 100644 --- a/include/verilated_saif_c.cpp +++ b/include/verilated_saif_c.cpp @@ -230,10 +230,10 @@ void VerilatedSaif::close() VL_MT_SAFE_EXCLUDES(m_mutex) { printStr(")\n"); incrementIndent(); - printInstance(0); + recursivelyPrintScopes(TOP_SCOPE_INDEX); decrementIndent(); - printStr(")\n"); // SAIFILE + printStr(")\n"); // SAIFILE // This function is on the flush() call path const VerilatedLockGuard lock{m_mutex}; @@ -244,7 +244,7 @@ void VerilatedSaif::close() VL_MT_SAFE_EXCLUDES(m_mutex) { Super::closeBase(); } -void VerilatedSaif::printInstance(uint32_t scopeIndex) { +void VerilatedSaif::recursivelyPrintScopes(uint32_t scopeIndex) { const SaifScope& saifScope = m_scopes.at(scopeIndex); printIndent(); @@ -252,12 +252,11 @@ void VerilatedSaif::printInstance(uint32_t scopeIndex) { printStr(saifScope.scopeName.c_str()); printStr("\n"); - //NOTE: for now only care about NET, also PORT will be added incrementIndent(); - printIndent(); - printStr("(NET\n"); - incrementIndent(); + bool anyNetValid{true}; + + //NOTE: for now only care about NET, also PORT will be added for (auto& childSignalCode : saifScope.childSignalCodes) { ActivityVar& activity = m_activity.at(childSignalCode); for (size_t i = 0; i < activity.width; i++) { @@ -271,6 +270,14 @@ void VerilatedSaif::printInstance(uint32_t scopeIndex) { } assert(m_time >= bit.highTime); + if (!anyNetValid) { + printIndent(); + printStr("(NET\n"); + anyNetValid = true; + + incrementIndent(); + } + printIndent(); printStr("("); printStr(activity.name.c_str()); @@ -292,13 +299,16 @@ void VerilatedSaif::printInstance(uint32_t scopeIndex) { } activity.lastTime = m_time; } - decrementIndent(); - printIndent(); - printStr(")\n"); // NET + if (anyNetValid) { + decrementIndent(); + + printIndent(); + printStr(")\n"); // NET + } for (uint32_t childScopeIndex : saifScope.childScopesIndices) { - printInstance(childScopeIndex); + recursivelyPrintScopes(childScopeIndex); } decrementIndent(); diff --git a/include/verilated_saif_c.h b/include/verilated_saif_c.h index 56e8d9b02..17affc3a1 100644 --- a/include/verilated_saif_c.h +++ b/include/verilated_saif_c.h @@ -93,9 +93,9 @@ private: size_t m_maxSignalBytes = 0; // Upper bound on number of bytes a single signal can generate uint64_t m_wroteBytes = 0; // Number of bytes written to this file - std::vector m_scopes{}; - std::vector m_topScopes{}; + static constexpr int32_t TOP_SCOPE_INDEX{0}; int32_t m_currentScope{-1}; + std::vector m_scopes{}; std::unordered_map m_activity; std::vector> m_activityArena; @@ -123,7 +123,7 @@ private: void declare(uint32_t code, const char* name, const char* wirep, bool array, int arraynum, bool bussed, int msb, int lsb); - void printInstance(uint32_t scopeIndex); + void recursivelyPrintScopes(uint32_t scopeIndex); // CONSTRUCTORS VL_UNCOPYABLE(VerilatedSaif);