Internals: Fix not clearing packagep on some assignments. Should affect assertions only.

This commit is contained in:
Wilson Snyder 2020-11-24 21:34:11 -05:00
parent fd21a41acd
commit dc1f44840d
1 changed files with 21 additions and 19 deletions

View File

@ -106,6 +106,9 @@ private:
} }
if (AstNode* subnodep = nodep->getChildDTypep()) subnodep->user1Inc(); if (AstNode* subnodep = nodep->getChildDTypep()) subnodep->user1Inc();
} }
void checkVarRef(AstNodeVarRef* nodep) {
if (nodep->packagep() && m_elimCells) { nodep->packagep(nullptr); }
}
void checkDType(AstNodeDType* nodep) { void checkDType(AstNodeDType* nodep) {
if (!nodep->generic() // Don't remove generic types if (!nodep->generic() // Don't remove generic types
&& m_elimDTypes // dtypes stick around until post-widthing && m_elimDTypes // dtypes stick around until post-widthing
@ -159,20 +162,16 @@ private:
} }
virtual void visit(AstNodeVarRef* nodep) override { virtual void visit(AstNodeVarRef* nodep) override {
// Note NodeAssign skips calling this in some cases
iterateChildren(nodep); iterateChildren(nodep);
checkAll(nodep); checkAll(nodep);
checkVarRef(nodep);
if (nodep->varScopep()) { if (nodep->varScopep()) {
nodep->varScopep()->user1Inc(); nodep->varScopep()->user1Inc();
nodep->varScopep()->varp()->user1Inc(); nodep->varScopep()->varp()->user1Inc();
} }
if (nodep->varp()) nodep->varp()->user1Inc(); if (nodep->varp()) nodep->varp()->user1Inc();
if (nodep->packagep()) { if (nodep->packagep()) nodep->packagep()->user1Inc();
if (m_elimCells) {
nodep->packagep(nullptr);
} else {
nodep->packagep()->user1Inc();
}
}
} }
virtual void visit(AstNodeFTaskRef* nodep) override { virtual void visit(AstNodeFTaskRef* nodep) override {
iterateChildren(nodep); iterateChildren(nodep);
@ -276,19 +275,22 @@ private:
// See if simple assignments to variables may be eliminated because // See if simple assignments to variables may be eliminated because
// that variable is never used. // that variable is never used.
// Similar code in V3Life // Similar code in V3Life
m_sideEffect = false; VL_RESTORER(m_sideEffect);
iterateAndNextNull(nodep->rhsp()); {
checkAll(nodep); m_sideEffect = false;
// Has to be direct assignment without any EXTRACTing. iterateAndNextNull(nodep->rhsp());
AstVarRef* varrefp = VN_CAST(nodep->lhsp(), VarRef); checkAll(nodep);
if (varrefp && !m_sideEffect // Has to be direct assignment without any EXTRACTing.
&& varrefp->varScopep()) { // For simplicity, we only remove post-scoping AstVarRef* varrefp = VN_CAST(nodep->lhsp(), VarRef);
m_assignMap.insert(make_pair(varrefp->varScopep(), nodep)); if (varrefp && !m_sideEffect
checkAll(varrefp); // Must track reference to dtype() && varrefp->varScopep()) { // For simplicity, we only remove post-scoping
} else { // Track like any other statement m_assignMap.insert(make_pair(varrefp->varScopep(), nodep));
iterateAndNextNull(nodep->lhsp()); checkAll(varrefp); // Must track reference to dtype()
checkVarRef(varrefp);
} else { // Track like any other statement
iterateAndNextNull(nodep->lhsp());
}
} }
checkAll(nodep);
} }
//----- //-----