Internals: Remove the name field from `AstVarRef` (#4395)

This commit is contained in:
Krzysztof Bieganski 2023-08-03 08:52:52 +02:00 committed by GitHub
parent 446f21d2a0
commit 9caa79a7ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
25 changed files with 110 additions and 152 deletions

View File

@ -125,9 +125,7 @@ string AstNode::encodeNumber(int64_t num) {
} }
} }
string AstNode::nameProtect() const VL_MT_STABLE { string AstNode::nameProtect() const { return VIdProtect::protectIf(name(), protect()); }
return VIdProtect::protectIf(name(), protect());
}
string AstNode::origNameProtect() const { return VIdProtect::protectIf(origName(), protect()); } string AstNode::origNameProtect() const { return VIdProtect::protectIf(origName(), protect()); }
string AstNode::shortName() const { string AstNode::shortName() const {
@ -285,7 +283,7 @@ string AstNode::vpiName(const string& namein) {
return pretty; return pretty;
} }
string AstNode::prettyTypeName() const VL_MT_STABLE { string AstNode::prettyTypeName() const {
if (name() == "") return typeName(); if (name() == "") return typeName();
return std::string{typeName()} + " '" + prettyName() + "'"; return std::string{typeName()} + " '" + prettyName() + "'";
} }

View File

@ -1686,7 +1686,7 @@ public:
static constexpr int INSTR_COUNT_PLI = 20; // PLI routines static constexpr int INSTR_COUNT_PLI = 20; // PLI routines
// ACCESSORS // ACCESSORS
virtual string name() const VL_MT_STABLE { return ""; } virtual string name() const { return ""; }
virtual string origName() const { return ""; } virtual string origName() const { return ""; }
virtual void name(const string& name) { virtual void name(const string& name) {
this->v3fatalSrc("name() called on object without name() method"); this->v3fatalSrc("name() called on object without name() method");
@ -1694,7 +1694,7 @@ public:
virtual void tag(const string& text) {} virtual void tag(const string& text) {}
virtual string tag() const { return ""; } virtual string tag() const { return ""; }
virtual string verilogKwd() const { return ""; } virtual string verilogKwd() const { return ""; }
string nameProtect() const VL_MT_STABLE; // Name with --protect-id applied string nameProtect() const; // Name with --protect-id applied
string origNameProtect() const; // origName with --protect-id applied string origNameProtect() const; // origName with --protect-id applied
string shortName() const; // Name with __PVT__ removed for concatenating scopes string shortName() const; // Name with __PVT__ removed for concatenating scopes
static string dedotName(const string& namein); // Name with dots removed static string dedotName(const string& namein); // Name with dots removed
@ -1707,10 +1707,10 @@ public:
static string encodeName(const string& namein); static string encodeName(const string& namein);
static string encodeNumber(int64_t num); // Encode number into internal C representation static string encodeNumber(int64_t num); // Encode number into internal C representation
static string vcdName(const string& namein); // Name for printing out to vcd files static string vcdName(const string& namein); // Name for printing out to vcd files
string prettyName() const VL_MT_STABLE { return prettyName(name()); } string prettyName() const { return prettyName(name()); }
string prettyNameQ() const { return prettyNameQ(name()); } string prettyNameQ() const { return prettyNameQ(name()); }
// "VARREF" for error messages (NOT dtype's pretty name) // "VARREF" for error messages (NOT dtype's pretty name)
string prettyTypeName() const VL_MT_STABLE; string prettyTypeName() const;
virtual string prettyOperatorName() const { return "operator " + prettyTypeName(); } virtual string prettyOperatorName() const { return "operator " + prettyTypeName(); }
FileLine* fileline() const VL_MT_SAFE { return m_fileline; } FileLine* fileline() const VL_MT_SAFE { return m_fileline; }
void fileline(FileLine* fl) { m_fileline = fl; } void fileline(FileLine* fl) { m_fileline = fl; }

View File

@ -154,12 +154,15 @@ AstCExpr::AstCExpr(FileLine* fl, const string& textStmt, int setwidth, bool clea
} }
AstVarRef::AstVarRef(FileLine* fl, AstVar* varp, const VAccess& access) AstVarRef::AstVarRef(FileLine* fl, AstVar* varp, const VAccess& access)
: ASTGEN_SUPER_VarRef(fl, varp->name(), varp, access) {} : ASTGEN_SUPER_VarRef(fl, varp, access) {}
// This form only allowed post-link (see above) // This form only allowed post-link (see above)
AstVarRef::AstVarRef(FileLine* fl, AstVarScope* varscp, const VAccess& access) AstVarRef::AstVarRef(FileLine* fl, AstVarScope* varscp, const VAccess& access)
: ASTGEN_SUPER_VarRef(fl, varscp->varp()->name(), varscp->varp(), access) { : ASTGEN_SUPER_VarRef(fl, varscp->varp(), access) {
varScopep(varscp); varScopep(varscp);
} }
string AstVarRef::name() const { return varp() ? varp()->name() : "<null>"; }
bool AstVarRef::same(const AstVarRef* samep) const { bool AstVarRef::same(const AstVarRef* samep) const {
if (varScopep()) { if (varScopep()) {
return (varScopep() == samep->varScopep() && access() == samep->access()); return (varScopep() == samep->varScopep() && access() == samep->access());
@ -179,7 +182,8 @@ bool AstVarRef::sameNoLvalue(AstVarRef* samep) const {
} }
AstVarXRef::AstVarXRef(FileLine* fl, AstVar* varp, const string& dotted, const VAccess& access) AstVarXRef::AstVarXRef(FileLine* fl, AstVar* varp, const string& dotted, const VAccess& access)
: ASTGEN_SUPER_VarXRef(fl, varp->name(), varp, access) : ASTGEN_SUPER_VarXRef(fl, varp, access)
, m_name{varp->name()}
, m_dotted{dotted} { , m_dotted{dotted} {
dtypeFrom(varp); dtypeFrom(varp);
} }

View File

@ -126,13 +126,13 @@ public:
const char* charIQWN() const { const char* charIQWN() const {
return (isString() ? "N" : isWide() ? "W" : isQuad() ? "Q" : "I"); return (isString() ? "N" : isWide() ? "W" : isQuad() ? "Q" : "I");
} }
string cType(const string& name, bool forFunc, bool isRef) const VL_MT_STABLE; string cType(const string& name, bool forFunc, bool isRef) const;
// Represents a C++ LiteralType? (can be constexpr) // Represents a C++ LiteralType? (can be constexpr)
bool isLiteralType() const VL_MT_STABLE; bool isLiteralType() const VL_MT_STABLE;
private: private:
class CTypeRecursed; class CTypeRecursed;
CTypeRecursed cTypeRecurse(bool compound) const VL_MT_STABLE; CTypeRecursed cTypeRecurse(bool compound) const;
}; };
class AstNodeArrayDType VL_NOT_FINAL : public AstNodeDType { class AstNodeArrayDType VL_NOT_FINAL : public AstNodeDType {
// Array data type, ie "some_dtype var_name [2:0]" // Array data type, ie "some_dtype var_name [2:0]"

View File

@ -450,20 +450,17 @@ class AstNodeVarRef VL_NOT_FINAL : public AstNodeExpr {
AstVar* m_varp; // [AfterLink] Pointer to variable itself AstVar* m_varp; // [AfterLink] Pointer to variable itself
AstVarScope* m_varScopep = nullptr; // Varscope for hierarchy AstVarScope* m_varScopep = nullptr; // Varscope for hierarchy
AstNodeModule* m_classOrPackagep = nullptr; // Package hierarchy AstNodeModule* m_classOrPackagep = nullptr; // Package hierarchy
string m_name; // Name of variable
string m_selfPointer; // Output code object pointer (e.g.: 'this') string m_selfPointer; // Output code object pointer (e.g.: 'this')
protected: protected:
AstNodeVarRef(VNType t, FileLine* fl, const string& name, const VAccess& access) AstNodeVarRef(VNType t, FileLine* fl, const VAccess& access)
: AstNodeExpr{t, fl} : AstNodeExpr{t, fl}
, m_access{access} , m_access{access} {
, m_name{name} {
varp(nullptr); varp(nullptr);
} }
AstNodeVarRef(VNType t, FileLine* fl, const string& name, AstVar* varp, const VAccess& access) AstNodeVarRef(VNType t, FileLine* fl, AstVar* varp, const VAccess& access)
: AstNodeExpr{t, fl} : AstNodeExpr{t, fl}
, m_access{access} , m_access{access} {
, m_name{name} {
// May have varp==nullptr // May have varp==nullptr
this->varp(varp); this->varp(varp);
} }
@ -474,8 +471,6 @@ public:
const char* broken() const override; const char* broken() const override;
int instrCount() const override { return widthInstrs(); } int instrCount() const override { return widthInstrs(); }
void cloneRelink() override; void cloneRelink() override;
string name() const override VL_MT_STABLE { return m_name; } // * = Var name
void name(const string& name) override { m_name = name; }
VAccess access() const { return m_access; } VAccess access() const { return m_access; }
void access(const VAccess& flag) { m_access = flag; } // Avoid using this; Set in constructor void access(const VAccess& flag) { m_access = flag; } // Avoid using this; Set in constructor
AstVar* varp() const { return m_varp; } // [After Link] Pointer to variable AstVar* varp() const { return m_varp; } // [After Link] Pointer to variable
@ -5355,15 +5350,15 @@ public:
class AstVarRef final : public AstNodeVarRef { class AstVarRef final : public AstNodeVarRef {
// A reference to a variable (lvalue or rvalue) // A reference to a variable (lvalue or rvalue)
public: public:
AstVarRef(FileLine* fl, const string& name, const VAccess& access)
: ASTGEN_SUPER_VarRef(fl, name, nullptr, access) {}
// This form only allowed post-link because output/wire compression may // This form only allowed post-link because output/wire compression may
// lead to deletion of AstVar's // lead to deletion of AstVar's
inline AstVarRef(FileLine* fl, AstVar* varp, const VAccess& access); inline AstVarRef(FileLine* fl, AstVar* varp, const VAccess& access);
// This form only allowed post-link (see above) // This form only allowed post-link (see above)
inline AstVarRef(FileLine* fl, AstVarScope* varscp, const VAccess& access); inline AstVarRef(FileLine* fl, AstVarScope* varscp, const VAccess& access);
ASTGEN_MEMBERS_AstVarRef; ASTGEN_MEMBERS_AstVarRef;
inline string name() const override; // * = Var name
void dump(std::ostream& str) const override; void dump(std::ostream& str) const override;
const char* broken() const override;
bool same(const AstNode* samep) const override; bool same(const AstNode* samep) const override;
inline bool same(const AstVarRef* samep) const; inline bool same(const AstVarRef* samep) const;
inline bool sameNoLvalue(AstVarRef* samep) const; inline bool sameNoLvalue(AstVarRef* samep) const;
@ -5375,14 +5370,17 @@ public:
class AstVarXRef final : public AstNodeVarRef { class AstVarXRef final : public AstNodeVarRef {
// A VarRef to something in another module before AstScope. // A VarRef to something in another module before AstScope.
// Includes pin on a cell, as part of a ASSIGN statement to connect I/Os until AstScope // Includes pin on a cell, as part of a ASSIGN statement to connect I/Os until AstScope
string m_name;
string m_dotted; // Dotted part of scope the name()'ed reference is under or "" string m_dotted; // Dotted part of scope the name()'ed reference is under or ""
string m_inlinedDots; // Dotted hierarchy flattened out string m_inlinedDots; // Dotted hierarchy flattened out
public: public:
AstVarXRef(FileLine* fl, const string& name, const string& dotted, const VAccess& access) AstVarXRef(FileLine* fl, const string& name, const string& dotted, const VAccess& access)
: ASTGEN_SUPER_VarXRef(fl, name, nullptr, access) : ASTGEN_SUPER_VarXRef(fl, nullptr, access)
, m_name{name}
, m_dotted{dotted} {} , m_dotted{dotted} {}
inline AstVarXRef(FileLine* fl, AstVar* varp, const string& dotted, const VAccess& access); inline AstVarXRef(FileLine* fl, AstVar* varp, const string& dotted, const VAccess& access);
ASTGEN_MEMBERS_AstVarXRef; ASTGEN_MEMBERS_AstVarXRef;
string name() const override VL_MT_STABLE { return m_name; } // * = Var name
void dump(std::ostream& str) const override; void dump(std::ostream& str) const override;
string dotted() const { return m_dotted; } string dotted() const { return m_dotted; }
void dotted(const string& dotted) { m_dotted = dotted; } void dotted(const string& dotted) { m_dotted = dotted; }

View File

@ -1812,7 +1812,7 @@ public:
string dpiTmpVarType(const string& varName) const; string dpiTmpVarType(const string& varName) const;
// Return Verilator internal type for argument: CData, SData, IData, WData // Return Verilator internal type for argument: CData, SData, IData, WData
string vlArgType(bool named, bool forReturn, bool forFunc, const string& namespc = "", string vlArgType(bool named, bool forReturn, bool forFunc, const string& namespc = "",
bool asRef = false) const VL_MT_STABLE; bool asRef = false) const;
string vlEnumType() const; // Return VerilatorVarType: VLVT_UINT32, etc string vlEnumType() const; // Return VerilatorVarType: VLVT_UINT32, etc
string vlEnumDir() const; // Return VerilatorVarDir: VLVD_INOUT, etc string vlEnumDir() const; // Return VerilatorVarDir: VLVD_INOUT, etc
string vlPropDecl(const string& propName) const; // Return VerilatorVarProps declaration string vlPropDecl(const string& propName) const; // Return VerilatorVarProps declaration

View File

@ -378,7 +378,7 @@ string AstVar::verilogKwd() const {
} }
string AstVar::vlArgType(bool named, bool forReturn, bool forFunc, const string& namespc, string AstVar::vlArgType(bool named, bool forReturn, bool forFunc, const string& namespc,
bool asRef) const VL_MT_STABLE { bool asRef) const {
UASSERT_OBJ(!forReturn, this, UASSERT_OBJ(!forReturn, this,
"Internal data is never passed as return, but as first argument"); "Internal data is never passed as return, but as first argument");
string ostatic; string ostatic;
@ -695,12 +695,12 @@ public:
} }
}; };
string AstNodeDType::cType(const string& name, bool /*forFunc*/, bool isRef) const VL_MT_STABLE { string AstNodeDType::cType(const string& name, bool /*forFunc*/, bool isRef) const {
const CTypeRecursed info = cTypeRecurse(false); const CTypeRecursed info = cTypeRecurse(false);
return info.render(name, isRef); return info.render(name, isRef);
} }
AstNodeDType::CTypeRecursed AstNodeDType::cTypeRecurse(bool compound) const VL_MT_STABLE { AstNodeDType::CTypeRecursed AstNodeDType::cTypeRecurse(bool compound) const {
// Legacy compound argument currently just passed through and unused // Legacy compound argument currently just passed through and unused
CTypeRecursed info; CTypeRecursed info;
@ -2076,6 +2076,10 @@ void AstVarRef::dump(std::ostream& str) const {
str << "UNLINKED"; str << "UNLINKED";
} }
} }
const char* AstVarRef::broken() const {
BROKEN_RTN(!varp());
return AstNodeVarRef::broken();
}
bool AstVarRef::same(const AstNode* samep) const { bool AstVarRef::same(const AstNode* samep) const {
return same(static_cast<const AstVarRef*>(samep)); return same(static_cast<const AstVarRef*>(samep));
} }

View File

@ -40,39 +40,6 @@ VL_DEFINE_DEBUG_FUNCTIONS;
//###################################################################### //######################################################################
class RenameStaticVisitor final : public VNVisitor {
private:
// STATE
const std::set<AstVar*>& m_staticFuncVarsr; // Static variables from m_ftaskp
AstNodeFTask* const m_ftaskp; // Current function/task
// VISITORS
void visit(AstVarRef* nodep) override {
const auto it = m_staticFuncVarsr.find(nodep->varp());
if (it != m_staticFuncVarsr.end()) nodep->name((*it)->name());
iterateChildren(nodep);
}
void visit(AstInitialStatic* nodep) override {
iterateChildren(nodep);
nodep->unlinkFrBack();
m_ftaskp->addHereThisAsNext(nodep);
}
void visit(AstNode* nodep) override { iterateChildren(nodep); }
public:
// CONSTRUCTORS
RenameStaticVisitor(std::set<AstVar*>& staticFuncVars, AstNodeFTask* ftaskp, AstNode* nodep)
: m_staticFuncVarsr(staticFuncVars)
, m_ftaskp(ftaskp) {
iterateChildren(nodep);
}
~RenameStaticVisitor() override = default;
};
//######################################################################
class BeginState final { class BeginState final {
private: private:
// NODE STATE // NODE STATE
@ -105,7 +72,6 @@ private:
string m_unnamedScope; // Name of begin blocks, including unnamed blocks string m_unnamedScope; // Name of begin blocks, including unnamed blocks
int m_ifDepth = 0; // Current if depth int m_ifDepth = 0; // Current if depth
bool m_keepBegins = false; // True if begins should not be inlined bool m_keepBegins = false; // True if begins should not be inlined
std::set<AstVar*> m_staticFuncVars; // Static variables from m_ftaskp
// METHODS // METHODS
@ -212,7 +178,10 @@ private:
m_ftaskp = nodep; m_ftaskp = nodep;
m_liftedp = nullptr; m_liftedp = nullptr;
iterateChildren(nodep); iterateChildren(nodep);
RenameStaticVisitor{m_staticFuncVars, m_ftaskp, nodep}; nodep->foreach([&](AstInitialStatic* const initp) {
initp->unlinkFrBack();
m_ftaskp->addHereThisAsNext(initp);
});
if (m_liftedp) { if (m_liftedp) {
// Place lifted nodes at beginning of stmtsp, so Var nodes appear before referenced // Place lifted nodes at beginning of stmtsp, so Var nodes appear before referenced
if (AstNode* const stmtsp = nodep->stmtsp()) { if (AstNode* const stmtsp = nodep->stmtsp()) {
@ -222,7 +191,6 @@ private:
nodep->addStmtsp(m_liftedp); nodep->addStmtsp(m_liftedp);
m_liftedp = nullptr; m_liftedp = nullptr;
} }
m_staticFuncVars.clear();
m_ftaskp = nullptr; m_ftaskp = nullptr;
} }
} }
@ -266,7 +234,6 @@ private:
nodep->name(newName); nodep->name(newName);
nodep->unlinkFrBack(); nodep->unlinkFrBack();
m_ftaskp->addHereThisAsNext(nodep); m_ftaskp->addHereThisAsNext(nodep);
m_staticFuncVars.insert(nodep);
nodep->funcLocal(false); nodep->funcLocal(false);
} else if (m_unnamedScope != "") { } else if (m_unnamedScope != "") {
// Rename it // Rename it
@ -377,7 +344,6 @@ private:
void visit(AstVarRef* nodep) override { void visit(AstVarRef* nodep) override {
if (nodep->varp()->user1()) { // It was converted if (nodep->varp()->user1()) { // It was converted
UINFO(9, " relinVarRef " << nodep << endl); UINFO(9, " relinVarRef " << nodep << endl);
nodep->name(nodep->varp()->name());
} }
iterateChildren(nodep); iterateChildren(nodep);
} }

View File

@ -62,7 +62,7 @@ public:
static string symClassAssign() { static string symClassAssign() {
return symClassName() + "* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;\n"; return symClassName() + "* const __restrict vlSymsp VL_ATTR_UNUSED = vlSelf->vlSymsp;\n";
} }
static string prefixNameProtect(const AstNode* nodep) VL_MT_STABLE { // C++ name with prefix static string prefixNameProtect(const AstNode* nodep) { // C++ name with prefix
return v3Global.opt.modPrefix() + "_" + VIdProtect::protect(nodep->name()); return v3Global.opt.modPrefix() + "_" + VIdProtect::protect(nodep->name());
} }
static bool isAnonOk(const AstVar* varp) { static bool isAnonOk(const AstVar* varp) {

View File

@ -147,7 +147,7 @@ class EmitCGatherDependencies final : VNVisitorConst {
} }
public: public:
static const std::set<std::string> gather(AstCFunc* cfuncp) VL_MT_STABLE { static const std::set<std::string> gather(AstCFunc* cfuncp) {
const EmitCGatherDependencies visitor{cfuncp}; const EmitCGatherDependencies visitor{cfuncp};
return std::move(visitor.m_dependencies); return std::move(visitor.m_dependencies);
} }
@ -566,8 +566,7 @@ class EmitCImp final : EmitCFunc {
~EmitCImp() override = default; ~EmitCImp() override = default;
public: public:
static void main(const AstNodeModule* modp, bool slow, static void main(const AstNodeModule* modp, bool slow, std::deque<AstCFile*>& cfilesr) {
std::deque<AstCFile*>& cfilesr) VL_MT_STABLE {
EmitCImp{modp, slow, cfilesr}; EmitCImp{modp, slow, cfilesr};
} }
}; };

View File

@ -176,9 +176,7 @@ public:
, m_slow{slow} {} , m_slow{slow} {}
~GateLogicVertex() override = default; ~GateLogicVertex() override = default;
// ACCESSORS // ACCESSORS
string name() const override VL_MT_STABLE { string name() const override { return (cvtToHex(m_nodep) + "@" + scopep()->prettyName()); }
return (cvtToHex(m_nodep) + "@" + scopep()->prettyName());
}
string dotColor() const override { return "purple"; } string dotColor() const override { return "purple"; }
FileLine* fileline() const override { return nodep()->fileline(); } FileLine* fileline() const override { return nodep()->fileline(); }
AstNode* nodep() const { return m_nodep; } AstNode* nodep() const { return m_nodep; }

View File

@ -384,7 +384,6 @@ private:
nodep->v3fatalSrc("Null connection?"); nodep->v3fatalSrc("Null connection?");
} }
} }
nodep->name(nodep->varp()->name());
} }
void visit(AstVarXRef* nodep) override { void visit(AstVarXRef* nodep) override {
// Track what scope it was originally under so V3LinkDot can resolve it // Track what scope it was originally under so V3LinkDot can resolve it

View File

@ -2065,40 +2065,38 @@ private:
} m_ds; // State to preserve across recursions } m_ds; // State to preserve across recursions
// METHODS - Variables // METHODS - Variables
void createImplicitVar(VSymEnt* /*lookupSymp*/, AstVarRef* nodep, AstNodeModule* modp, AstVar* createImplicitVar(VSymEnt* /*lookupSymp*/, AstParseRef* nodep, AstNodeModule* modp,
VSymEnt* moduleSymp, bool noWarn) { VSymEnt* moduleSymp, bool noWarn) {
// Create implicit after warning // Create implicit after warning
if (!nodep->varp()) { if (!noWarn) {
if (!noWarn) { if (nodep->fileline()->warnIsOff(V3ErrorCode::I_DEF_NETTYPE_WIRE)) {
if (nodep->fileline()->warnIsOff(V3ErrorCode::I_DEF_NETTYPE_WIRE)) { const string suggest = m_statep->suggestSymFallback(moduleSymp, nodep->name(),
const string suggest = m_statep->suggestSymFallback(moduleSymp, nodep->name(), LinkNodeMatcherVar{});
LinkNodeMatcherVar{}); nodep->v3error("Signal definition not found, and implicit disabled with "
nodep->v3error("Signal definition not found, and implicit disabled with " "`default_nettype: "
"`default_nettype: " << nodep->prettyNameQ() << '\n'
<< nodep->prettyNameQ() << '\n' << (suggest.empty() ? "" : nodep->warnMore() + suggest));
<< (suggest.empty() ? "" : nodep->warnMore() + suggest));
}
// Bypass looking for suggestions if IMPLICIT is turned off
// as there could be thousands of these suppressed in large netlists
else if (!nodep->fileline()->warnIsOff(V3ErrorCode::IMPLICIT)) {
const string suggest = m_statep->suggestSymFallback(moduleSymp, nodep->name(),
LinkNodeMatcherVar{});
nodep->v3warn(IMPLICIT,
"Signal definition not found, creating implicitly: "
<< nodep->prettyNameQ() << '\n'
<< (suggest.empty() ? "" : nodep->warnMore() + suggest));
}
} }
AstVar* const newp = new AstVar{nodep->fileline(), VVarType::WIRE, nodep->name(), // Bypass looking for suggestions if IMPLICIT is turned off
VFlagLogicPacked{}, 1}; // as there could be thousands of these suppressed in large netlists
newp->trace(modp->modTrace()); else if (!nodep->fileline()->warnIsOff(V3ErrorCode::IMPLICIT)) {
nodep->varp(newp); const string suggest = m_statep->suggestSymFallback(moduleSymp, nodep->name(),
modp->addStmtsp(newp); LinkNodeMatcherVar{});
// Link it to signal list, must add the variable under the module; nodep->v3warn(IMPLICIT,
// current scope might be lower now "Signal definition not found, creating implicitly: "
m_statep->insertSym(moduleSymp, newp->name(), newp, nullptr /*classOrPackagep*/); << nodep->prettyNameQ() << '\n'
<< (suggest.empty() ? "" : nodep->warnMore() + suggest));
}
} }
AstVar* const newp
= new AstVar{nodep->fileline(), VVarType::WIRE, nodep->name(), VFlagLogicPacked{}, 1};
newp->trace(modp->modTrace());
modp->addStmtsp(newp);
// Link it to signal list, must add the variable under the module;
// current scope might be lower now
m_statep->insertSym(moduleSymp, newp->name(), newp, nullptr /*classOrPackagep*/);
return newp;
} }
AstVar* foundToVarp(const VSymEnt* symp, AstNode* nodep, VAccess access) { AstVar* foundToVarp(const VSymEnt* symp, AstNode* nodep, VAccess access) {
// Return a variable if possible, auto converting a modport to variable // Return a variable if possible, auto converting a modport to variable
@ -2844,11 +2842,11 @@ private:
if (checkImplicit) { if (checkImplicit) {
// Create if implicit, and also if error (so only complain once) // Create if implicit, and also if error (so only complain once)
// Else if a scope is allowed, making a signal won't help error cascade // Else if a scope is allowed, making a signal won't help error cascade
auto varp = createImplicitVar(m_curSymp, nodep, m_modp, m_modSymp, err);
AstVarRef* const newp AstVarRef* const newp
= new AstVarRef{nodep->fileline(), nodep->name(), VAccess::READ}; = new AstVarRef{nodep->fileline(), varp, VAccess::READ};
nodep->replaceWith(newp); nodep->replaceWith(newp);
VL_DO_DANGLING(pushDeletep(nodep), nodep); VL_DO_DANGLING(pushDeletep(nodep), nodep);
createImplicitVar(m_curSymp, newp, m_modp, m_modSymp, err);
} }
} }
} }

View File

@ -370,9 +370,11 @@ private:
// Making an AstAssign (vs AstAssignW) to a wire is an error, suppress it // Making an AstAssign (vs AstAssignW) to a wire is an error, suppress it
FileLine* const newfl = new FileLine{fl}; FileLine* const newfl = new FileLine{fl};
newfl->warnOff(V3ErrorCode::PROCASSWIRE, true); newfl->warnOff(V3ErrorCode::PROCASSWIRE, true);
auto* const assp // Create a ParseRef to the wire. We cannot use the var as it may be deleted if
= new AstAssign{newfl, new AstVarRef{newfl, nodep->name(), VAccess::WRITE}, // it's a port (see t_var_set_link.v)
VN_AS(nodep->valuep()->unlinkFrBack(), NodeExpr)}; auto* const assp = new AstAssign{
newfl, new AstParseRef{newfl, VParseRefExp::PX_TEXT, nodep->name()},
VN_AS(nodep->valuep()->unlinkFrBack(), NodeExpr)};
if (nodep->lifetime().isAutomatic()) { if (nodep->lifetime().isAutomatic()) {
nodep->addNextHere(new AstInitialAutomatic{newfl, assp}); nodep->addNextHere(new AstInitialAutomatic{newfl, assp});
} else { } else {
@ -381,7 +383,7 @@ private:
} // 4. Under blocks, it's an initial value to be under an assign } // 4. Under blocks, it's an initial value to be under an assign
else { else {
nodep->addNextHere( nodep->addNextHere(
new AstAssign{fl, new AstVarRef{fl, nodep->name(), VAccess::WRITE}, new AstAssign{fl, new AstVarRef{fl, nodep, VAccess::WRITE},
VN_AS(nodep->valuep()->unlinkFrBack(), NodeExpr)}); VN_AS(nodep->valuep()->unlinkFrBack(), NodeExpr)});
} }
} }

View File

@ -89,12 +89,7 @@ private:
rename(nodep, false); rename(nodep, false);
} }
} }
void visit(AstVarRef* nodep) override { void visit(AstVarRef* nodep) override { iterate(nodep->varp()); }
if (nodep->varp()) {
iterate(nodep->varp());
nodep->name(nodep->varp()->name());
}
}
void visit(AstCell* nodep) override { void visit(AstCell* nodep) override {
if (!nodep->user1()) { if (!nodep->user1()) {
rename(nodep, (!nodep->modp()->modPublic() && !VN_IS(nodep->modp(), ClassPackage))); rename(nodep, (!nodep->modp()->modPublic() && !VN_IS(nodep->modp(), ClassPackage)));

View File

@ -85,9 +85,10 @@ AstArg* V3ParseGrammar::argWrapList(AstNodeExpr* nodep) {
} }
AstNode* V3ParseGrammar::createSupplyExpr(FileLine* fileline, const string& name, int value) { AstNode* V3ParseGrammar::createSupplyExpr(FileLine* fileline, const string& name, int value) {
AstAssignW* assignp = new AstAssignW{fileline, new AstVarRef{fileline, name, VAccess::WRITE}, AstAssignW* assignp
value ? new AstConst{fileline, AstConst::All1{}} = new AstAssignW{fileline, new AstParseRef{fileline, VParseRefExp::PX_TEXT, name},
: new AstConst{fileline, AstConst::All0{}}}; value ? new AstConst{fileline, AstConst::All1{}}
: new AstConst{fileline, AstConst::All0{}}};
AstStrengthSpec* strengthSpecp AstStrengthSpec* strengthSpecp
= new AstStrengthSpec{fileline, VStrength::SUPPLY, VStrength::SUPPLY}; = new AstStrengthSpec{fileline, VStrength::SUPPLY, VStrength::SUPPLY};
assignp->strengthSpecp(strengthSpecp); assignp->strengthSpecp(strengthSpecp);

View File

@ -109,9 +109,7 @@ protected:
// ACCESSORS // ACCESSORS
// Do not make accessor for nodep(), It may change due to // Do not make accessor for nodep(), It may change due to
// reordering a lower block, but we don't repair it // reordering a lower block, but we don't repair it
string name() const override VL_MT_STABLE { string name() const override { return cvtToHex(m_nodep) + ' ' + m_nodep->prettyTypeName(); }
return cvtToHex(m_nodep) + ' ' + m_nodep->prettyTypeName();
}
FileLine* fileline() const override { return nodep()->fileline(); } FileLine* fileline() const override { return nodep()->fileline(); }
public: public:
@ -148,7 +146,7 @@ public:
SplitVarPostVertex(V3Graph* graphp, AstNode* nodep) SplitVarPostVertex(V3Graph* graphp, AstNode* nodep)
: SplitNodeVertex{graphp, nodep} {} : SplitNodeVertex{graphp, nodep} {}
~SplitVarPostVertex() override = default; ~SplitVarPostVertex() override = default;
string name() const override VL_MT_STABLE { return string{"POST "} + SplitNodeVertex::name(); } string name() const override { return string{"POST "} + SplitNodeVertex::name(); }
string dotColor() const override { return "CadetBlue"; } string dotColor() const override { return "CadetBlue"; }
}; };

View File

@ -412,7 +412,6 @@ private:
AstVarScope* const newvscp = VN_AS(refp->varp()->user2p(), VarScope); AstVarScope* const newvscp = VN_AS(refp->varp()->user2p(), VarScope);
refp->varScopep(newvscp); refp->varScopep(newvscp);
refp->varp(refp->varScopep()->varp()); refp->varp(refp->varScopep()->varp());
refp->name(refp->varp()->name());
} }
}); });
} }

View File

@ -96,7 +96,7 @@ private:
AstNode* const m_nodep; // AST node represented by this graph vertex AstNode* const m_nodep; // AST node represented by this graph vertex
// ACCESSORS // ACCESSORS
string name() const override VL_MT_STABLE { string name() const override {
if (m_classp) { if (m_classp) {
if (VN_IS(nodep(), CFunc)) { if (VN_IS(nodep(), CFunc)) {
return cvtToHex(nodep()) + ' ' + classp()->name() + "::" + nodep()->name(); return cvtToHex(nodep()) + ' ' + classp()->name() + "::" + nodep()->name();

View File

@ -154,7 +154,7 @@ public:
// ACCESSORS // ACCESSORS
AstNode* nodep() const VL_MT_STABLE { return m_nodep; } AstNode* nodep() const VL_MT_STABLE { return m_nodep; }
const AstVar* varp() const { return VN_CAST(nodep(), Var); } const AstVar* varp() const { return VN_CAST(nodep(), Var); }
string name() const override VL_MT_STABLE { string name() const override {
return ((isTristate() ? "tri\\n" return ((isTristate() ? "tri\\n"
: feedsTri() ? "feed\\n" : feedsTri() ? "feed\\n"
: "-\\n") : "-\\n")
@ -672,8 +672,7 @@ class TristateVisitor final : public TristateBaseVisitor {
VFlagBitPacked{}, w}; // 2-state ok; sep enable VFlagBitPacked{}, w}; // 2-state ok; sep enable
UINFO(9, " newout " << newLhsp << endl); UINFO(9, " newout " << newLhsp << endl);
nodep->addStmtsp(newLhsp); nodep->addStmtsp(newLhsp);
refp->varp(newLhsp); // assign the new var to the varref refp->varp(newLhsp);
refp->name(newLhsp->name());
// create a new var for this drivers enable signal // create a new var for this drivers enable signal
AstVar* const newEnLhsp = new AstVar{varp->fileline(), VVarType::MODULETEMP, AstVar* const newEnLhsp = new AstVar{varp->fileline(), VVarType::MODULETEMP,

View File

@ -2251,7 +2251,7 @@ tf_variable_identifier<varp>: // IEEE: part of list_of_tf_variable_ide
id variable_dimensionListE sigAttrListE exprEqE id variable_dimensionListE sigAttrListE exprEqE
{ $$ = VARDONEA($<fl>1, *$1, $2, $3); { $$ = VARDONEA($<fl>1, *$1, $2, $3);
if ($4) AstNode::addNext<AstNode, AstNode>( if ($4) AstNode::addNext<AstNode, AstNode>(
$$, new AstAssign{$4->fileline(), new AstVarRef{$<fl>1, *$1, VAccess::WRITE}, $4}); } $$, new AstAssign{$4->fileline(), new AstParseRef{$<fl>1, VParseRefExp::PX_TEXT, *$1}, $4}); }
; ;
variable_declExpr<nodep>: // IEEE: part of variable_decl_assignment - rhs of expr variable_declExpr<nodep>: // IEEE: part of variable_decl_assignment - rhs of expr
@ -2995,7 +2995,7 @@ netSig<varp>: // IEEE: net_decl_assignment - one element from
{ $$ = VARDONEA($<fl>1, *$1, nullptr, $2); } { $$ = VARDONEA($<fl>1, *$1, nullptr, $2); }
| netId sigAttrListE '=' expr | netId sigAttrListE '=' expr
{ $$ = VARDONEA($<fl>1, *$1, nullptr, $2); { $$ = VARDONEA($<fl>1, *$1, nullptr, $2);
auto* const assignp = new AstAssignW{$3, new AstVarRef{$<fl>1, *$1, VAccess::WRITE}, $4}; auto* const assignp = new AstAssignW{$3, new AstParseRef{$<fl>1, VParseRefExp::PX_TEXT, *$1}, $4};
if (GRAMMARP->m_netStrengthp) assignp->strengthSpecp(GRAMMARP->m_netStrengthp->cloneTree(false)); if (GRAMMARP->m_netStrengthp) assignp->strengthSpecp(GRAMMARP->m_netStrengthp->cloneTree(false));
AstNode::addNext<AstNode, AstNode>($$, assignp); } AstNode::addNext<AstNode, AstNode>($$, assignp); }
| netId variable_dimensionList sigAttrListE | netId variable_dimensionList sigAttrListE
@ -3912,14 +3912,14 @@ for_initializationItem<nodep>: // IEEE: variable_assignment + for_varia
AstVar* const varp = VARDONEA($<fl>2, *$2, nullptr, nullptr); AstVar* const varp = VARDONEA($<fl>2, *$2, nullptr, nullptr);
varp->lifetime(VLifetime::AUTOMATIC); varp->lifetime(VLifetime::AUTOMATIC);
$$ = varp; $$ = varp;
$$->addNext(new AstAssign{$3, new AstVarRef{$<fl>2, *$2, VAccess::WRITE}, $4}); } $$->addNext(new AstAssign{$3, new AstParseRef{$<fl>2, VParseRefExp::PX_TEXT, *$2}, $4}); }
// // IEEE-2012: // // IEEE-2012:
| yVAR data_type idAny/*new*/ '=' expr | yVAR data_type idAny/*new*/ '=' expr
{ VARRESET_NONLIST(VAR); VARDTYPE($2); { VARRESET_NONLIST(VAR); VARDTYPE($2);
AstVar* const varp = VARDONEA($<fl>3, *$3, nullptr, nullptr); AstVar* const varp = VARDONEA($<fl>3, *$3, nullptr, nullptr);
varp->lifetime(VLifetime::AUTOMATIC); varp->lifetime(VLifetime::AUTOMATIC);
$$ = varp; $$ = varp;
$$->addNext(new AstAssign{$4, new AstVarRef{$<fl>3, *$3, VAccess::WRITE}, $5}); } $$->addNext(new AstAssign{$4, new AstParseRef{$<fl>3, VParseRefExp::PX_TEXT, *$3}, $5}); }
// // IEEE: variable_assignment // // IEEE: variable_assignment
// // UNSUP variable_lvalue below // // UNSUP variable_lvalue below
| varRefBase '=' expr { $$ = new AstAssign{$2, $1, $3}; } | varRefBase '=' expr { $$ = new AstAssign{$2, $1, $3}; }
@ -5614,8 +5614,8 @@ idArrayedForeach<nodeExprp>: // IEEE: id + select (under foreach expression)
; ;
// VarRef without any dots or vectorizaion // VarRef without any dots or vectorizaion
varRefBase<varRefp>: varRefBase<parseRefp>:
id { $$ = new AstVarRef{$<fl>1, *$1, VAccess::READ}; } id { $$ = new AstParseRef{$<fl>1, VParseRefExp::PX_TEXT, *$1}; }
; ;
// ParseRef // ParseRef

View File

@ -53,27 +53,27 @@
<varscope loc="d,50,22,50,23" name="t.cell2.q" dtype_id="1"/> <varscope loc="d,50,22,50,23" name="t.cell2.q" dtype_id="1"/>
<assignalias loc="d,15,22,15,23" dtype_id="1"> <assignalias loc="d,15,22,15,23" dtype_id="1">
<varref loc="d,15,22,15,23" name="q" dtype_id="1"/> <varref loc="d,15,22,15,23" name="q" dtype_id="1"/>
<varref loc="d,15,22,15,23" name="q" dtype_id="1"/> <varref loc="d,15,22,15,23" name="t.q" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,13,10,13,13" dtype_id="2"> <assignalias loc="d,13,10,13,13" dtype_id="2">
<varref loc="d,13,10,13,13" name="clk" dtype_id="2"/> <varref loc="d,13,10,13,13" name="clk" dtype_id="2"/>
<varref loc="d,13,10,13,13" name="clk" dtype_id="2"/> <varref loc="d,13,10,13,13" name="t.clk" dtype_id="2"/>
</assignalias> </assignalias>
<assignalias loc="d,14,16,14,17" dtype_id="1"> <assignalias loc="d,14,16,14,17" dtype_id="1">
<varref loc="d,14,16,14,17" name="d" dtype_id="1"/> <varref loc="d,14,16,14,17" name="d" dtype_id="1"/>
<varref loc="d,14,16,14,17" name="d" dtype_id="1"/> <varref loc="d,14,16,14,17" name="t.d" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,34,24,34,27" dtype_id="2"> <assignalias loc="d,34,24,34,27" dtype_id="2">
<varref loc="d,34,24,34,27" name="t.clk" dtype_id="2"/> <varref loc="d,34,24,34,27" name="t.clk" dtype_id="2"/>
<varref loc="d,34,24,34,27" name="cell1.clk" dtype_id="2"/> <varref loc="d,34,24,34,27" name="t.cell1.clk" dtype_id="2"/>
</assignalias> </assignalias>
<assignalias loc="d,35,30,35,31" dtype_id="1"> <assignalias loc="d,35,30,35,31" dtype_id="1">
<varref loc="d,35,30,35,31" name="t.d" dtype_id="1"/> <varref loc="d,35,30,35,31" name="t.d" dtype_id="1"/>
<varref loc="d,35,30,35,31" name="cell1.d" dtype_id="1"/> <varref loc="d,35,30,35,31" name="t.cell1.d" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,36,30,36,31" dtype_id="1"> <assignalias loc="d,36,30,36,31" dtype_id="1">
<varref loc="d,36,30,36,31" name="t.between" dtype_id="1"/> <varref loc="d,36,30,36,31" name="t.between" dtype_id="1"/>
<varref loc="d,36,30,36,31" name="cell1.q" dtype_id="1"/> <varref loc="d,36,30,36,31" name="t.cell1.q" dtype_id="1"/>
</assignalias> </assignalias>
<always loc="d,41,4,41,10"> <always loc="d,41,4,41,10">
<sentree loc="d,41,11,41,12"> <sentree loc="d,41,11,41,12">
@ -88,15 +88,15 @@
</always> </always>
<assignalias loc="d,48,10,48,13" dtype_id="2"> <assignalias loc="d,48,10,48,13" dtype_id="2">
<varref loc="d,48,10,48,13" name="t.clk" dtype_id="2"/> <varref loc="d,48,10,48,13" name="t.clk" dtype_id="2"/>
<varref loc="d,48,10,48,13" name="cell2.clk" dtype_id="2"/> <varref loc="d,48,10,48,13" name="t.cell2.clk" dtype_id="2"/>
</assignalias> </assignalias>
<assignalias loc="d,49,16,49,17" dtype_id="1"> <assignalias loc="d,49,16,49,17" dtype_id="1">
<varref loc="d,49,16,49,17" name="t.between" dtype_id="1"/> <varref loc="d,49,16,49,17" name="t.between" dtype_id="1"/>
<varref loc="d,49,16,49,17" name="cell2.d" dtype_id="1"/> <varref loc="d,49,16,49,17" name="t.cell2.d" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,50,22,50,23" dtype_id="1"> <assignalias loc="d,50,22,50,23" dtype_id="1">
<varref loc="d,50,22,50,23" name="t.q" dtype_id="1"/> <varref loc="d,50,22,50,23" name="t.q" dtype_id="1"/>
<varref loc="d,50,22,50,23" name="cell2.q" dtype_id="1"/> <varref loc="d,50,22,50,23" name="t.cell2.q" dtype_id="1"/>
</assignalias> </assignalias>
<contassign loc="d,53,13,53,14" dtype_id="1"> <contassign loc="d,53,13,53,14" dtype_id="1">
<varref loc="d,17,22,17,29" name="t.between" dtype_id="1"/> <varref loc="d,17,22,17,29" name="t.between" dtype_id="1"/>

View File

@ -25,11 +25,11 @@
<varscope loc="d,7,24,7,29" name="top.f.i_clk" dtype_id="1"/> <varscope loc="d,7,24,7,29" name="top.f.i_clk" dtype_id="1"/>
<assignalias loc="d,11,24,11,29" dtype_id="1"> <assignalias loc="d,11,24,11,29" dtype_id="1">
<varref loc="d,11,24,11,29" name="i_clk" dtype_id="1"/> <varref loc="d,11,24,11,29" name="i_clk" dtype_id="1"/>
<varref loc="d,11,24,11,29" name="i_clk" dtype_id="1"/> <varref loc="d,11,24,11,29" name="top.i_clk" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,7,24,7,29" dtype_id="1"> <assignalias loc="d,7,24,7,29" dtype_id="1">
<varref loc="d,7,24,7,29" name="top.i_clk" dtype_id="1"/> <varref loc="d,7,24,7,29" name="top.i_clk" dtype_id="1"/>
<varref loc="d,7,24,7,29" name="f.i_clk" dtype_id="1"/> <varref loc="d,7,24,7,29" name="top.f.i_clk" dtype_id="1"/>
</assignalias> </assignalias>
</scope> </scope>
</topscope> </topscope>

View File

@ -25,11 +25,11 @@
<varscope loc="d,7,24,7,29" name="top.f.i_clk" dtype_id="1"/> <varscope loc="d,7,24,7,29" name="top.f.i_clk" dtype_id="1"/>
<assignalias loc="d,11,24,11,29" dtype_id="1"> <assignalias loc="d,11,24,11,29" dtype_id="1">
<varref loc="d,11,24,11,29" name="i_clk" dtype_id="1"/> <varref loc="d,11,24,11,29" name="i_clk" dtype_id="1"/>
<varref loc="d,11,24,11,29" name="i_clk" dtype_id="1"/> <varref loc="d,11,24,11,29" name="top.i_clk" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,7,24,7,29" dtype_id="1"> <assignalias loc="d,7,24,7,29" dtype_id="1">
<varref loc="d,7,24,7,29" name="top.i_clk" dtype_id="1"/> <varref loc="d,7,24,7,29" name="top.i_clk" dtype_id="1"/>
<varref loc="d,7,24,7,29" name="f.i_clk" dtype_id="1"/> <varref loc="d,7,24,7,29" name="top.f.i_clk" dtype_id="1"/>
</assignalias> </assignalias>
</scope> </scope>
</topscope> </topscope>

View File

@ -43,19 +43,19 @@
<varscope loc="d,17,13,17,14" name="__Vfunc_vlvbound_test.foo__1__i" dtype_id="3"/> <varscope loc="d,17,13,17,14" name="__Vfunc_vlvbound_test.foo__1__i" dtype_id="3"/>
<assignalias loc="d,9,25,9,28" dtype_id="1"> <assignalias loc="d,9,25,9,28" dtype_id="1">
<varref loc="d,9,25,9,28" name="i_a" dtype_id="1"/> <varref loc="d,9,25,9,28" name="i_a" dtype_id="1"/>
<varref loc="d,9,25,9,28" name="i_a" dtype_id="1"/> <varref loc="d,9,25,9,28" name="vlvbound_test.i_a" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,10,25,10,28" dtype_id="1"> <assignalias loc="d,10,25,10,28" dtype_id="1">
<varref loc="d,10,25,10,28" name="i_b" dtype_id="1"/> <varref loc="d,10,25,10,28" name="i_b" dtype_id="1"/>
<varref loc="d,10,25,10,28" name="i_b" dtype_id="1"/> <varref loc="d,10,25,10,28" name="vlvbound_test.i_b" dtype_id="1"/>
</assignalias> </assignalias>
<assignalias loc="d,11,25,11,28" dtype_id="2"> <assignalias loc="d,11,25,11,28" dtype_id="2">
<varref loc="d,11,25,11,28" name="o_a" dtype_id="2"/> <varref loc="d,11,25,11,28" name="o_a" dtype_id="2"/>
<varref loc="d,11,25,11,28" name="o_a" dtype_id="2"/> <varref loc="d,11,25,11,28" name="vlvbound_test.o_a" dtype_id="2"/>
</assignalias> </assignalias>
<assignalias loc="d,12,25,12,28" dtype_id="2"> <assignalias loc="d,12,25,12,28" dtype_id="2">
<varref loc="d,12,25,12,28" name="o_b" dtype_id="2"/> <varref loc="d,12,25,12,28" name="o_b" dtype_id="2"/>
<varref loc="d,12,25,12,28" name="o_b" dtype_id="2"/> <varref loc="d,12,25,12,28" name="vlvbound_test.o_b" dtype_id="2"/>
</assignalias> </assignalias>
<always loc="d,24,14,24,15"> <always loc="d,24,14,24,15">
<comment loc="d,24,16,24,19" name="Function: foo"/> <comment loc="d,24,16,24,19" name="Function: foo"/>