diff --git a/include/verilated.cpp b/include/verilated.cpp index 070eeb990..5f1b6bae0 100644 --- a/include/verilated.cpp +++ b/include/verilated.cpp @@ -3506,13 +3506,12 @@ void VerilatedScope::exportInsert(int finalize, const char* namep, void* cb) VL_ } } -void VerilatedScope::varInsert(int finalize, const char* namep, void* datap, bool isParam, +void VerilatedScope::varInsert(const char* namep, void* datap, bool isParam, VerilatedVarType vltype, int vlflags, int udims, int pdims...) VL_MT_UNSAFE { // Grab dimensions // In the future we may just create a large table at emit time and // statically construct from that. - if (!finalize) return; if (!m_varsp) m_varsp = new VerilatedVarNameMap; VerilatedVar var(namep, datap, vltype, static_cast(vlflags), udims, pdims, diff --git a/include/verilated.h b/include/verilated.h index 467c9d90f..5b7795652 100644 --- a/include/verilated.h +++ b/include/verilated.h @@ -713,8 +713,8 @@ public: // But internals only - called from verilated modules const char* identifier, const char* defnamep, int8_t timeunit, const Type& type) VL_MT_UNSAFE; void exportInsert(int finalize, const char* namep, void* cb) VL_MT_UNSAFE; - void varInsert(int finalize, const char* namep, void* datap, bool isParam, - VerilatedVarType vltype, int vlflags, int udims, int pdims, ...) VL_MT_UNSAFE; + void varInsert(const char* namep, void* datap, bool isParam, VerilatedVarType vltype, + int vlflags, int udims, int pdims, ...) VL_MT_UNSAFE; // ACCESSORS const char* name() const VL_MT_SAFE_POSTINIT { return m_namep; } const char* identifier() const VL_MT_SAFE_POSTINIT { return m_identifierp; } diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index ba63b8702..eb53d0c4a 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -751,31 +751,34 @@ std::vector EmitCSyms::getSymCtorStmts() { emitScopeHier(stmts, false); - if (!v3Global.dpi()) return stmts; + if (v3Global.dpi()) { + for (const std::string vfinal : {"0", "1"}) { + add("// Setup export functions - final: " + vfinal); + for (const auto& itpair : m_scopeFuncs) { + const ScopeFuncData& sfd = itpair.second; + const AstScopeName* const scopep = sfd.m_scopep; + const AstCFunc* const funcp = sfd.m_cfuncp; + const AstNodeModule* const modp = sfd.m_modp; + if (!funcp->dpiExportImpl()) continue; - for (const std::string vfinal : {"0", "1"}) { - add("// Setup export functions - final: " + vfinal); - for (const auto& itpair : m_scopeFuncs) { - const ScopeFuncData& sfd = itpair.second; - const AstScopeName* const scopep = sfd.m_scopep; - const AstCFunc* const funcp = sfd.m_cfuncp; - const AstNodeModule* const modp = sfd.m_modp; - if (!funcp->dpiExportImpl()) continue; - - std::string stmt; - stmt += protect("__Vscope_" + scopep->scopeSymName()) + ".exportInsert("; - stmt += vfinal + ", \""; - // Not protected - user asked for import/export - stmt += V3OutFormatter::quoteNameControls(funcp->cname()); - stmt += "\", (void*)(&"; - stmt += EmitCUtil::prefixNameProtect(modp); - stmt += "__"; - stmt += funcp->nameProtect(); - stmt += "));"; - add(stmt); + std::string stmt; + stmt += protect("__Vscope_" + scopep->scopeSymName()) + ".exportInsert("; + stmt += vfinal + ", \""; + // Not protected - user asked for import/export + stmt += V3OutFormatter::quoteNameControls(funcp->cname()); + stmt += "\", (void*)(&"; + stmt += EmitCUtil::prefixNameProtect(modp); + stmt += "__"; + stmt += funcp->nameProtect(); + stmt += "));"; + add(stmt); + } } - // It would be less code if each module inserted its own variables. - // Someday. For now public isn't common. + } + + // It would be less code if each module inserted its own variables. Someday. + if (!m_scopeVars.empty()) { + add("// Setup public variables"); for (const auto& itpair : m_scopeVars) { const ScopeVarData& svd = itpair.second; const AstScope* const scopep = svd.m_scopep; @@ -812,8 +815,7 @@ std::vector EmitCSyms::getSymCtorStmts() { } std::string stmt; - stmt += protect("__Vscope_" + svd.m_scopeName) + ".varInsert("; - stmt += vfinal + ", \""; + stmt += protect("__Vscope_" + svd.m_scopeName) + ".varInsert(\""; stmt += V3OutFormatter::quoteNameControls(protect(svd.m_varBasePretty)) + '"'; const std::string varName diff --git a/test_regress/t/t_flag_csplit_groups.py b/test_regress/t/t_flag_csplit_groups.py index 33ba50c14..bf39c13bb 100755 --- a/test_regress/t/t_flag_csplit_groups.py +++ b/test_regress/t/t_flag_csplit_groups.py @@ -125,7 +125,7 @@ test.file_grep_not(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", "vm_clas test.file_grep_not(test.obj_dir + "/" + test.vm_prefix + "_classes.mk", "vm_classes_2") # Check combine count -test.file_grep(test.stats, r'Node count, CFILE + (\d+)', (270 if test.vltmt else 253)) +test.file_grep(test.stats, r'Node count, CFILE + (\d+)', (264 if test.vltmt else 247)) test.file_grep(test.stats, r'Makefile targets, VM_CLASSES_FAST + (\d+)', 2) test.file_grep(test.stats, r'Makefile targets, VM_CLASSES_SLOW + (\d+)', 2) diff --git a/test_regress/t/t_vpi_public_depthn_1.out b/test_regress/t/t_vpi_public_depthn_1.out index 47439d8ee..272680bb1 100644 --- a/test_regress/t/t_vpi_public_depthn_1.out +++ b/test_regress/t/t_vpi_public_depthn_1.out @@ -1,5 +1,7 @@ scopesDump: SCOPE 0x#: top.TOP + VAR 0x#: clk SCOPE 0x#: top.t + VAR 0x#: clk *-* All Finished *-* diff --git a/test_regress/t/t_vpi_public_depthn_2.out b/test_regress/t/t_vpi_public_depthn_2.out index 89d26bbea..803e08a7f 100644 --- a/test_regress/t/t_vpi_public_depthn_2.out +++ b/test_regress/t/t_vpi_public_depthn_2.out @@ -1,7 +1,15 @@ scopesDump: SCOPE 0x#: top.TOP + VAR 0x#: clk SCOPE 0x#: top.t + VAR 0x#: clk SCOPE 0x#: top.t.s_axis_if + VAR 0x#: aclk + VAR 0x#: tdata + VAR 0x#: tready + VAR 0x#: tuser + VAR 0x#: tvalid SCOPE 0x#: top.t.u_dut + VAR 0x#: clk *-* All Finished *-* diff --git a/test_regress/t/t_vpi_public_depthn_3.out b/test_regress/t/t_vpi_public_depthn_3.out index e7b4f1596..960d5407e 100644 --- a/test_regress/t/t_vpi_public_depthn_3.out +++ b/test_regress/t/t_vpi_public_depthn_3.out @@ -1,8 +1,17 @@ scopesDump: SCOPE 0x#: top.TOP + VAR 0x#: clk SCOPE 0x#: top.t + VAR 0x#: clk SCOPE 0x#: top.t.s_axis_if + VAR 0x#: aclk + VAR 0x#: tdata + VAR 0x#: tready + VAR 0x#: tuser + VAR 0x#: tvalid SCOPE 0x#: top.t.u_dut + VAR 0x#: clk SCOPE 0x#: top.t.u_dut.u_sub + VAR 0x#: clk *-* All Finished *-*