diff --git a/src/V3EmitCSyms.cpp b/src/V3EmitCSyms.cpp index 926342257..47b890ae8 100644 --- a/src/V3EmitCSyms.cpp +++ b/src/V3EmitCSyms.cpp @@ -983,7 +983,8 @@ void EmitCSyms::emitSymImp() { varName += protect(varp->name()); if (varp->isParam()) { - if (varp->vlEnumType() == "VLVT_STRING") { + if (varp->vlEnumType() == "VLVT_STRING" + && !VN_IS(varp->subDTypep(), UnpackArrayDType)) { puts(", const_cast(static_cast("); puts(varName); puts(".c_str())), "); diff --git a/src/V3LinkParse.cpp b/src/V3LinkParse.cpp index ebd9c98f1..4b2116ed0 100644 --- a/src/V3LinkParse.cpp +++ b/src/V3LinkParse.cpp @@ -340,22 +340,20 @@ class LinkParseVisitor final : public VNVisitor { // Maybe this variable has a signal attribute V3Config::applyVarAttr(m_modp, m_ftaskp, nodep); - if (v3Global.opt.publicFlatRW() - || (v3Global.opt.publicDepth() && m_modp - && (m_modp->level() - 1) <= v3Global.opt.publicDepth())) { - - switch (nodep->varType()) { - case VVarType::VAR: // FALLTHRU - case VVarType::GPARAM: // FALLTHRU - case VVarType::LPARAM: // FALLTHRU - case VVarType::PORT: // FALLTHRU - case VVarType::WIRE: nodep->sigUserRWPublic(true); break; - default: break; + if (v3Global.opt.anyPublicFlat() && nodep->varType().isVPIAccessible()) { + if (v3Global.opt.publicFlatRW()) { + nodep->sigUserRWPublic(true); + } else if (v3Global.opt.publicParams() && nodep->isParam()) { + nodep->sigUserRWPublic(true); + } else if (m_modp && v3Global.opt.publicDepth()) { + if ((m_modp->level() - 1) <= v3Global.opt.publicDepth()) { + nodep->sigUserRWPublic(true); + } else if (VN_IS(m_modp, Package) && nodep->isParam()) { + nodep->sigUserRWPublic(true); + } } } - if (v3Global.opt.publicParams() && nodep->isParam()) nodep->sigUserRWPublic(true); - // We used modTrace before leveling, and we may now // want to turn it off now that we know the levelizations if (v3Global.opt.traceDepth() && m_modp diff --git a/src/V3Options.h b/src/V3Options.h index eb3d14194..c1ed66ec9 100644 --- a/src/V3Options.h +++ b/src/V3Options.h @@ -543,6 +543,8 @@ public: bool allPublic() const { return m_public; } bool publicParams() const { return m_public_params; } bool publicFlatRW() const { return m_publicFlatRW; } + int publicDepth() const { return m_publicDepth; } + bool anyPublicFlat() const { return m_public_params || m_publicFlatRW || m_publicDepth; } bool lintOnly() const VL_MT_SAFE { return m_lintOnly; } bool ignc() const { return m_ignc; } bool quietExit() const VL_MT_SAFE { return m_quietExit; } @@ -577,7 +579,6 @@ public: int outputSplitCTrace() const { return m_outputSplitCTrace; } int outputGroups() const { return m_outputGroups; } int pinsBv() const VL_MT_SAFE { return m_pinsBv; } - int publicDepth() const { return m_publicDepth; } int reloopLimit() const { return m_reloopLimit; } VOptionBool skipIdentical() const { return m_skipIdentical; } bool stopFail() const { return m_stopFail; } diff --git a/test_regress/t/t_vpi_package.cpp b/test_regress/t/t_vpi_package.cpp index 4feb00a48..c2ba1eb52 100644 --- a/test_regress/t/t_vpi_package.cpp +++ b/test_regress/t/t_vpi_package.cpp @@ -116,10 +116,12 @@ int mon_check() { CHECK_RESULT_Z(count_params(unitHandle, 1)); CHECK_RESULT_Z(count_params(pkgHandle, 2)); - CHECK_RESULT_Z(count_params(tHandle, 3)); + CHECK_RESULT_Z(count_params(tHandle, 6)); CHECK_RESULT_Z(check_handle(const_cast("someOtherInt"), tHandle)) CHECK_RESULT_Z(check_handle(const_cast("t.someOtherInt"), NULL)) + CHECK_RESULT_Z(check_handle(const_cast("someString"), tHandle)) + CHECK_RESULT_Z(check_handle(const_cast("t.someString"), NULL)) CHECK_RESULT_Z(check_handle(const_cast("someInt"), pkgHandle)) CHECK_RESULT_Z(check_handle(const_cast("somepackage::someInt"), NULL)) CHECK_RESULT_Z(check_handle(const_cast("dollarUnitInt"), unitHandle)) diff --git a/test_regress/t/t_vpi_package.py b/test_regress/t/t_vpi_package.py index 61cf61c9e..91593a3fe 100755 --- a/test_regress/t/t_vpi_package.py +++ b/test_regress/t/t_vpi_package.py @@ -14,7 +14,7 @@ test.scenarios('simulator') test.compile(make_top_shell=False, make_main=False, make_pli=True, - verilator_flags2=["--exe --vpi --no-l2name", test.pli_filename]) + verilator_flags2=["--exe --vpi --no-l2name --public-depth 1", test.pli_filename]) test.execute(use_libvpi=True) diff --git a/test_regress/t/t_vpi_package.v b/test_regress/t/t_vpi_package.v index 9f9ca4161..b69e2cdad 100644 --- a/test_regress/t/t_vpi_package.v +++ b/test_regress/t/t_vpi_package.v @@ -8,19 +8,24 @@ import "DPI-C" context function int mon_check(); -parameter int dollarUnitInt /*verilator public_flat_rd*/ = 3; +parameter int dollarUnitInt = 3; package somepackage; - parameter int someInt /*verilator public_flat_rd*/ = 5; - parameter int anotherInt /*verilator public_flat_rd*/ = 6; + parameter int someInt = 5; + parameter int anotherInt = 6; endpackage module t (/*AUTOARG*/ - ); /*verilator public_module*/ + ); - parameter int someOtherInt /* verilator public_flat_rd*/ = 7; - parameter int yetAnotherInt /* verilator public_flat_rd*/ = 9; - parameter int stillAnotherInt /* verilator public_flat_rd*/ = 17; + parameter int someOtherInt = 7; + parameter int yetAnotherInt = 9; + parameter int stillAnotherInt = 17; + parameter int register = 0; + parameter int n_str = 2; + // Edge case with pvi code generation + parameter string someString [n_str] = '{default: ""}; + logic reference; integer status;