Internals: Change AstAssignVarScope into AstAliasScope (#6280) (#6512)

Rename and make it derive from AstNode instead of AstNodeAssign.

Small step towards #6280. No functional change.
This commit is contained in:
Geza Lore 2025-09-30 07:40:17 +02:00 committed by GitHub
parent 283810cbf7
commit e04f51ebd2
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 25 additions and 34 deletions

View File

@ -450,7 +450,7 @@ public:
inline bool hasCombo() const; inline bool hasCombo() const;
}; };
class AstAlias final : public AstNode { class AstAlias final : public AstNode {
// Alias statement // Alias construct - Used for source level net alias, and also for variable aliases internally
// @astgen op1 := itemsp : List[AstNodeExpr] // Alias operands // @astgen op1 := itemsp : List[AstNodeExpr] // Alias operands
public: public:
AstAlias(FileLine* fl, AstNodeExpr* itemsp) AstAlias(FileLine* fl, AstNodeExpr* itemsp)
@ -459,6 +459,18 @@ public:
} }
ASTGEN_MEMBERS_AstAlias; ASTGEN_MEMBERS_AstAlias;
}; };
class AstAliasScope final : public AstNode {
// Like AstAlias, but aliases two scopes instead of nets/variables
// @astgen op1 := rhsp : AstNodeExpr
// @astgen op2 := lhsp : AstNodeExpr
public:
AstAliasScope(FileLine* fl, AstNodeExpr* lhsp, AstNodeExpr* rhsp)
: ASTGEN_SUPER_AliasScope(fl) {
this->lhsp(lhsp);
this->rhsp(rhsp);
}
ASTGEN_MEMBERS_AstAliasScope;
};
class AstBind final : public AstNode { class AstBind final : public AstNode {
// Parents: MODULE // Parents: MODULE
// Children: CELL // Children: CELL

View File

@ -68,7 +68,6 @@ public:
bool sameNode(const AstNode*) const override { return true; } bool sameNode(const AstNode*) const override { return true; }
string verilogKwd() const override { return "="; } string verilogKwd() const override { return "="; }
bool isTimingControl() const override { return timingControlp(); } bool isTimingControl() const override { return timingControlp(); }
virtual bool brokeLhsMustBeLvalue() const = 0;
}; };
class AstNodeBlock VL_NOT_FINAL : public AstNodeStmt { class AstNodeBlock VL_NOT_FINAL : public AstNodeStmt {
// A Begin/fork block // A Begin/fork block
@ -1119,7 +1118,6 @@ public:
AstNode* const controlp = timingControlp() ? timingControlp()->cloneTree(false) : nullptr; AstNode* const controlp = timingControlp() ? timingControlp()->cloneTree(false) : nullptr;
return new AstAssign{fileline(), lhsp, rhsp, controlp}; return new AstAssign{fileline(), lhsp, rhsp, controlp};
} }
bool brokeLhsMustBeLvalue() const override { return true; }
}; };
class AstAssignDly final : public AstNodeAssign { class AstAssignDly final : public AstNodeAssign {
public: public:
@ -1133,7 +1131,6 @@ public:
} }
bool isGateOptimizable() const override { return false; } bool isGateOptimizable() const override { return false; }
string verilogKwd() const override { return "<="; } string verilogKwd() const override { return "<="; }
bool brokeLhsMustBeLvalue() const override { return true; }
}; };
class AstAssignForce final : public AstNodeAssign { class AstAssignForce final : public AstNodeAssign {
// Procedural 'force' statement // Procedural 'force' statement
@ -1144,20 +1141,6 @@ public:
AstNodeAssign* cloneType(AstNodeExpr* lhsp, AstNodeExpr* rhsp) override { AstNodeAssign* cloneType(AstNodeExpr* lhsp, AstNodeExpr* rhsp) override {
return new AstAssignForce{fileline(), lhsp, rhsp}; return new AstAssignForce{fileline(), lhsp, rhsp};
} }
bool brokeLhsMustBeLvalue() const override { return true; }
};
class AstAssignVarScope final : public AstNodeAssign {
// Assign two VarScopes to each other
public:
AstAssignVarScope(FileLine* fl, AstNodeExpr* lhsp, AstNodeExpr* rhsp)
: ASTGEN_SUPER_AssignVarScope(fl, lhsp, rhsp) {
dtypeFrom(rhsp);
}
ASTGEN_MEMBERS_AstAssignVarScope;
AstNodeAssign* cloneType(AstNodeExpr* lhsp, AstNodeExpr* rhsp) override {
return new AstAssignVarScope{fileline(), lhsp, rhsp};
}
bool brokeLhsMustBeLvalue() const override { return false; }
}; };
class AstAssignW final : public AstNodeAssign { class AstAssignW final : public AstNodeAssign {
// Like assign, but wire/assign's in verilog, the only setting of the specified variable // Like assign, but wire/assign's in verilog, the only setting of the specified variable
@ -1176,7 +1159,6 @@ public:
return refp->access().isWriteOrRW() && refp->varp()->delayp(); return refp->access().isWriteOrRW() && refp->varp()->delayp();
}); });
} }
bool brokeLhsMustBeLvalue() const override { return true; }
AstDelay* getLhsNetDelay() const; AstDelay* getLhsNetDelay() const;
AstAlways* convertToAlways(); AstAlways* convertToAlways();
}; };

View File

@ -225,8 +225,7 @@ private:
// VISITORS // VISITORS
void visit(AstNodeAssign* nodep) override { void visit(AstNodeAssign* nodep) override {
processAndIterate(nodep); processAndIterate(nodep);
UASSERT_OBJ(!(v3Global.assertDTypesResolved() && nodep->brokeLhsMustBeLvalue() UASSERT_OBJ(!(v3Global.assertDTypesResolved() && VN_IS(nodep->lhsp(), NodeVarRef)
&& VN_IS(nodep->lhsp(), NodeVarRef)
&& !VN_AS(nodep->lhsp(), NodeVarRef)->access().isWriteOrRW()), && !VN_AS(nodep->lhsp(), NodeVarRef)->access().isWriteOrRW()),
nodep, "Assignment LHS is not an lvalue"); nodep, "Assignment LHS is not an lvalue");
} }

View File

@ -3244,8 +3244,8 @@ class ConstVisitor final : public VNVisitor {
void visit(AstAlias* nodep) override { void visit(AstAlias* nodep) override {
// Don't perform any optimizations, keep the alias around // Don't perform any optimizations, keep the alias around
} }
void visit(AstAssignVarScope* nodep) override { void visit(AstAliasScope* nodep) override {
// Don't perform any optimizations, the node won't be linked yet // Don't perform any optimizations, keep the alias around
} }
void visit(AstAssignW* nodep) override { void visit(AstAssignW* nodep) override {
iterateChildren(nodep); iterateChildren(nodep);

View File

@ -499,7 +499,7 @@ void connectPort(AstNodeModule* modp, AstVar* nodep, AstNodeExpr* pinExprp) {
UINFO(6, "Inlning port variable: " << nodep); UINFO(6, "Inlning port variable: " << nodep);
if (nodep->isIfaceRef()) { if (nodep->isIfaceRef()) {
modp->addStmtsp( modp->addStmtsp(
new AstAssignVarScope{flp, portRef(VAccess::WRITE), pinRef(VAccess::READ)}); new AstAliasScope{flp, portRef(VAccess::WRITE), pinRef(VAccess::READ)});
} else { } else {
AstVarRef* const aliasArgsp = portRef(VAccess::WRITE); AstVarRef* const aliasArgsp = portRef(VAccess::WRITE);
aliasArgsp->addNext(pinRef(VAccess::READ)); aliasArgsp->addNext(pinRef(VAccess::READ));
@ -633,7 +633,7 @@ void process(AstNetlist* netlistp, ModuleStateUser1Allocator& moduleStates) {
// Clean up AstIfaceRefDType references // Clean up AstIfaceRefDType references
// If the cell has been removed let's make sure we don't leave a // If the cell has been removed let's make sure we don't leave a
// reference to it. This dtype may still be in use by the // reference to it. This dtype may still be in use by the
// AstAssignVarScope created earlier but that'll get cleared up later // AstAliasScope created earlier but that'll get cleared up later
netlistp->typeTablep()->foreach([](AstIfaceRefDType* nodep) { netlistp->typeTablep()->foreach([](AstIfaceRefDType* nodep) {
if (nodep->user1()) nodep->cellp(nullptr); if (nodep->user1()) nodep->cellp(nullptr);
}); });

View File

@ -90,7 +90,7 @@ class InstVisitor final : public VNVisitor {
->subDTypep() ->subDTypep()
->skipRefp(), ->skipRefp(),
IfaceRefDType))) { IfaceRefDType))) {
// Create an AstAssignVarScope for Vars to Cells so we can // Create an AstAliasScope for Vars to Cells so we can
// link with their scope later // link with their scope later
AstNodeExpr* const lhsp = new AstVarXRef{exprp->fileline(), nodep->modVarp(), AstNodeExpr* const lhsp = new AstVarXRef{exprp->fileline(), nodep->modVarp(),
m_cellp->name(), VAccess::READ}; m_cellp->name(), VAccess::READ};
@ -98,9 +98,7 @@ class InstVisitor final : public VNVisitor {
const AstVarXRef* const xrefp = VN_CAST(exprp, VarXRef); const AstVarXRef* const xrefp = VN_CAST(exprp, VarXRef);
UASSERT_OBJ(refp || xrefp, exprp, UASSERT_OBJ(refp || xrefp, exprp,
"Interfaces: Pin is not connected to a VarRef or VarXRef"); "Interfaces: Pin is not connected to a VarRef or VarXRef");
AstAssignVarScope* const assp m_cellp->addNextHere(new AstAliasScope{exprp->fileline(), lhsp, exprp});
= new AstAssignVarScope{exprp->fileline(), lhsp, exprp};
m_cellp->addNextHere(assp);
} else { } else {
nodep->v3error("Assigned pin is neither input nor output"); nodep->v3error("Assigned pin is neither input nor output");
} }

View File

@ -70,7 +70,7 @@ class InlineIntfRefVisitor final : public VNVisitor {
iterateChildren(modp); iterateChildren(modp);
} }
void visit(AstAssignVarScope* nodep) override { void visit(AstAliasScope* nodep) override {
// Reference // Reference
const AstVarRef* const reflp = VN_CAST(nodep->lhsp(), VarRef); const AstVarRef* const reflp = VN_CAST(nodep->lhsp(), VarRef);
// What the reference refers to // What the reference refers to

View File

@ -2326,8 +2326,8 @@ private:
iterateChildren(nodep); iterateChildren(nodep);
pushDeletep(nodep->unlinkFrBack()); pushDeletep(nodep->unlinkFrBack());
} }
void visit(AstAssignVarScope* nodep) override { // ScopeVisitor:: void visit(AstAliasScope* nodep) override { // ScopeVisitor::
UINFO(5, "ASSIGNVARSCOPE " << nodep); UINFO(5, "ALIASSCOPE " << nodep);
UINFOTREE(9, nodep, "", "avs"); UINFOTREE(9, nodep, "", "avs");
VSymEnt* rhsSymp; VSymEnt* rhsSymp;
{ {

View File

@ -216,7 +216,7 @@ class ScopeVisitor final : public VNVisitor {
m_scopep->addBlocksp(clonep); m_scopep->addBlocksp(clonep);
iterateChildren(clonep); // We iterate under the *clone* iterateChildren(clonep); // We iterate under the *clone*
} }
void visit(AstAssignVarScope* nodep) override { void visit(AstAliasScope* nodep) override {
// Copy under the scope but don't recurse // Copy under the scope but don't recurse
UINFO(4, " Move " << nodep); UINFO(4, " Move " << nodep);
AstNode* const clonep = nodep->cloneTree(false); AstNode* const clonep = nodep->cloneTree(false);
@ -354,7 +354,7 @@ class ScopeCleanupVisitor final : public VNVisitor {
void visit(AstNodeProcedure* nodep) override { movedDeleteOrIterate(nodep); } void visit(AstNodeProcedure* nodep) override { movedDeleteOrIterate(nodep); }
void visit(AstAlias* nodep) override { movedDeleteOrIterate(nodep); } void visit(AstAlias* nodep) override { movedDeleteOrIterate(nodep); }
void visit(AstAssignVarScope* nodep) override { movedDeleteOrIterate(nodep); } void visit(AstAliasScope* nodep) override { movedDeleteOrIterate(nodep); }
void visit(AstAssignW* nodep) override { movedDeleteOrIterate(nodep); } void visit(AstAssignW* nodep) override { movedDeleteOrIterate(nodep); }
void visit(AstCoverToggle* nodep) override { movedDeleteOrIterate(nodep); } void visit(AstCoverToggle* nodep) override { movedDeleteOrIterate(nodep); }
void visit(AstNodeFTask* nodep) override { movedDeleteOrIterate(nodep); } void visit(AstNodeFTask* nodep) override { movedDeleteOrIterate(nodep); }