diff --git a/src/V3AstInlines.h b/src/V3AstInlines.h index ef91c2408..80611aa3e 100644 --- a/src/V3AstInlines.h +++ b/src/V3AstInlines.h @@ -149,6 +149,8 @@ bool AstActive::hasCombo() const { return m_sentreep->hasCombo(); } bool AstActive::hasInitial() const { return m_sentreep->hasInitial(); } bool AstActive::hasStatic() const { return m_sentreep->hasStatic(); } +bool AstNodeModule::isDollarUnit() const { return this == v3Global.rootp()->dollarUnitPkgp(); } + AstAlways::AstAlways(AstAssignW* assignp) : ASTGEN_SUPER_Always(assignp->fileline(), assignp) , m_keyword{VAlwaysKwd::CONT_ASSIGN} {} diff --git a/src/V3AstNodeOther.h b/src/V3AstNodeOther.h index ee8d701eb..602d604d0 100644 --- a/src/V3AstNodeOther.h +++ b/src/V3AstNodeOther.h @@ -358,6 +358,7 @@ public: bool maybePointedTo() const override VL_MT_SAFE { return true; } string name() const override VL_MT_STABLE { return m_name; } virtual bool timescaleMatters() const = 0; + inline bool isDollarUnit() const; // Is the $unit package // ACCESSORS void name(const string& name) override { m_name = name; } string origName() const override { return m_origName; } @@ -3231,8 +3232,6 @@ public: ASTGEN_MEMBERS_AstPackage; string verilogKwd() const override { return "package"; } bool timescaleMatters() const override { return !isDollarUnit(); } - static string dollarUnitName() { return AstNode::encodeName("$unit"); } - bool isDollarUnit() const { return name() == dollarUnitName(); } }; class AstPrimitive final : public AstNodeModule { // A primitive declaration diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index cfa3441de..d432ce163 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -1918,7 +1918,7 @@ AstNetlist::AstNetlist() : ASTGEN_SUPER_Netlist(new FileLine{FileLine::builtInFilename()}) , m_typeTablep{new AstTypeTable{fileline()}} , m_constPoolp{new AstConstPool{fileline()}} - , m_dollarUnitPkgp{new AstPackage{fileline(), AstPackage::dollarUnitName(), "work"}} { + , m_dollarUnitPkgp{new AstPackage{fileline(), AstNode::encodeName("$unit"), "work"}} { addMiscsp(m_typeTablep); addMiscsp(m_constPoolp); // packages are always libraries; don't want to make them a "top" diff --git a/src/V3Dead.cpp b/src/V3Dead.cpp index a7ed9974c..c45ab2c4f 100644 --- a/src/V3Dead.cpp +++ b/src/V3Dead.cpp @@ -670,7 +670,7 @@ class DeadVisitor final : public VNVisitor { nextmodp = VN_AS(modp->nextp(), NodeModule); // Keep $unit until m_elimCells stages. Note v3Global.opt.serializeOnly() // won't reach this stage, and will always have an empty $unit. That's ok. - const bool keep = !m_elimCells && modp == v3Global.rootp()->dollarUnitPkgp(); + const bool keep = !m_elimCells && modp->isDollarUnit(); if (modp->dead() || (!modp->isTop() && modp->user1() == 0 && !keep)) { // > 2 because L1 is the wrapper, L2 is the top user module UINFO(4, " Dead module " << modp); @@ -681,9 +681,7 @@ class DeadVisitor final : public VNVisitor { cellp->modp()->user1Inc(-1); }); } - if (modp == v3Global.rootp()->dollarUnitPkgp()) { - v3Global.rootp()->dollarUnitPkgp(nullptr); - } + if (modp->isDollarUnit()) v3Global.rootp()->dollarUnitPkgp(nullptr); deleting(modp); retry = true; } diff --git a/src/V3LinkCells.cpp b/src/V3LinkCells.cpp index ed14045ac..0aa09345b 100644 --- a/src/V3LinkCells.cpp +++ b/src/V3LinkCells.cpp @@ -469,7 +469,7 @@ class LinkCellsVisitor final : public VNVisitor { if (nodep->fileline()->filebasenameNoExt() != nodep->prettyName() && !v3Global.opt.isLibraryFile(nodep->fileline()->filename(), nodep->libname()) && !VN_IS(nodep, NotFoundModule) && !nodep->recursiveClone() - && nodep != v3Global.rootp()->dollarUnitPkgp() && m_modDepth == 1) { + && !nodep->isDollarUnit() && m_modDepth == 1) { // We only complain once per file, otherwise library-like files // have a huge mess of warnings const auto itFoundPair = m_declfnWarned.insert(nodep->fileline()->filename()); diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 881efee0d..79d546ba4 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -1220,8 +1220,7 @@ class LinkDotFindVisitor final : public VNVisitor { AstNodeModule* const modulesp = nodep->modulesp(); UASSERT_OBJ(modulesp, nodep, "$unit should always be in the netlist"); if (!modulesp->nextp()) { - UASSERT_OBJ(modulesp == v3Global.rootp()->dollarUnitPkgp(), modulesp, - "Sole module should be $unit"); + UASSERT_OBJ(modulesp->isDollarUnit(), modulesp, "Sole module should be $unit"); if (!modulesp->stmtsp()) nodep->v3error("No top level module found"); } for (AstNodeModule* modp = nodep->modulesp(); modp && modp->isTop();