Internals: Make V3MemberMap to remove member cache (#4350)
This commit is contained in:
parent
ff4923cf67
commit
f94c1b32e5
|
|
@ -2137,17 +2137,13 @@ public:
|
|||
// === AstNodeModule ===
|
||||
class AstClass final : public AstNodeModule {
|
||||
// @astgen op4 := extendsp : List[AstClassExtends]
|
||||
// TYPES
|
||||
using MemberNameMap = std::map<const std::string, AstNode*>;
|
||||
// MEMBERS
|
||||
MemberNameMap m_members; // Members or method children
|
||||
AstClassPackage* m_classOrPackagep = nullptr; // Class package this is under
|
||||
bool m_extended = false; // Is extension or extended by other classes
|
||||
bool m_interfaceClass = false; // Interface class
|
||||
bool m_needRNG = false; // Need RNG, uses srandom/randomize
|
||||
bool m_virtual = false; // Virtual class
|
||||
bool m_parameterized = false; // Parameterized class
|
||||
void insertCache(AstNode* nodep);
|
||||
|
||||
public:
|
||||
AstClass(FileLine* fl, const string& name)
|
||||
|
|
@ -2162,16 +2158,7 @@ public:
|
|||
AstClassPackage* classOrPackagep() const VL_MT_SAFE { return m_classOrPackagep; }
|
||||
void classOrPackagep(AstClassPackage* classpackagep) { m_classOrPackagep = classpackagep; }
|
||||
AstNode* membersp() const { return stmtsp(); }
|
||||
void addMembersp(AstNode* nodep) {
|
||||
insertCache(nodep);
|
||||
addStmtsp(nodep);
|
||||
}
|
||||
void clearCache() { m_members.clear(); }
|
||||
void repairCache();
|
||||
AstNode* findMember(const string& name) const {
|
||||
const auto it = m_members.find(name);
|
||||
return (it == m_members.end()) ? nullptr : it->second;
|
||||
}
|
||||
void addMembersp(AstNode* nodep) { addStmtsp(nodep); }
|
||||
bool isExtended() const { return m_extended; }
|
||||
void isExtended(bool flag) { m_extended = flag; }
|
||||
bool isInterfaceClass() const { return m_interfaceClass; }
|
||||
|
|
|
|||
|
|
@ -1411,30 +1411,6 @@ bool AstClass::isCacheableChild(const AstNode* nodep) {
|
|||
|| (VN_IS(nodep, NodeFTask) && !VN_AS(nodep, NodeFTask)->isExternProto())
|
||||
|| VN_IS(nodep, CFunc));
|
||||
}
|
||||
void AstClass::insertCache(AstNode* nodep) {
|
||||
const bool doit = (VN_IS(nodep, Var) || VN_IS(nodep, EnumItemRef)
|
||||
|| (VN_IS(nodep, NodeFTask) && !VN_AS(nodep, NodeFTask)->isExternProto())
|
||||
|| VN_IS(nodep, CFunc));
|
||||
if (doit) {
|
||||
if (m_members.find(nodep->name()) != m_members.end()) {
|
||||
nodep->v3error("Duplicate declaration of member name: " << nodep->prettyNameQ());
|
||||
} else {
|
||||
m_members.emplace(nodep->name(), nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
void AstClass::repairCache() {
|
||||
clearCache();
|
||||
for (auto* itemp = membersp(); itemp; itemp = itemp->nextp()) {
|
||||
if (const auto* const scopep = VN_CAST(itemp, Scope)) {
|
||||
for (auto* blockp = scopep->blocksp(); blockp; blockp = blockp->nextp()) {
|
||||
insertCache(blockp);
|
||||
}
|
||||
} else {
|
||||
insertCache(itemp);
|
||||
}
|
||||
}
|
||||
}
|
||||
AstClass* AstClass::baseMostClassp() {
|
||||
AstClass* basep = this;
|
||||
while (basep->extendsp() && basep->extendsp()->classp()) {
|
||||
|
|
|
|||
|
|
@ -106,7 +106,6 @@ private:
|
|||
m_prefix = nodep->name() + "__02e"; // .
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
nodep->repairCache();
|
||||
}
|
||||
void visit(AstNodeModule* nodep) override {
|
||||
// Visit for NodeModules that are not AstClass (AstClass is-a AstNodeModule)
|
||||
|
|
|
|||
|
|
@ -3492,7 +3492,6 @@ private:
|
|||
// V3Width when determines types needs to find enum values and such
|
||||
// so add members pointing to appropriate enum values
|
||||
{
|
||||
nodep->repairCache();
|
||||
VMemberMap memberMap;
|
||||
for (VSymEnt::const_iterator it = m_curSymp->begin(); it != m_curSymp->end(); ++it) {
|
||||
AstNode* const itemp = it->second->nodep();
|
||||
|
|
|
|||
|
|
@ -398,7 +398,6 @@ AstFunc* V3Randomize::newRandomizeFunc(AstClass* nodep) {
|
|||
funcp->classMethod(true);
|
||||
funcp->isVirtual(nodep->isExtended());
|
||||
nodep->addMembersp(funcp);
|
||||
nodep->repairCache();
|
||||
AstClass* const basep = nodep->baseMostClassp();
|
||||
basep->needRNG(true);
|
||||
}
|
||||
|
|
@ -422,7 +421,6 @@ AstFunc* V3Randomize::newSRandomFunc(AstClass* nodep) {
|
|||
funcp->classMethod(true);
|
||||
funcp->isVirtual(false);
|
||||
basep->addMembersp(funcp);
|
||||
basep->repairCache();
|
||||
funcp->addStmtsp(new AstCStmt{basep->fileline(), "__Vm_rng.srandom(seed);\n"});
|
||||
basep->needRNG(true);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2644,7 +2644,6 @@ private:
|
|||
m_classp = nodep;
|
||||
userIterateAndNext(nodep->extendsp(), nullptr);
|
||||
userIterateChildren(nodep, nullptr); // First size all members
|
||||
nodep->repairCache();
|
||||
}
|
||||
void visit(AstPackage* nodep) override {
|
||||
VL_RESTORER(m_pkgp);
|
||||
|
|
@ -2749,7 +2748,7 @@ private:
|
|||
AstClass* const first_classp = adtypep->classp();
|
||||
UASSERT_OBJ(first_classp, nodep, "Unlinked");
|
||||
for (AstClass* classp = first_classp; classp;) {
|
||||
if (AstNode* const foundp = classp->findMember(nodep->name())) {
|
||||
if (AstNode* const foundp = memberMap.findMember(classp, nodep->name())) {
|
||||
if (AstVar* const varp = VN_CAST(foundp, Var)) {
|
||||
if (!varp->didWidth()) userIterate(varp, nullptr);
|
||||
if (varp->lifetime().isStatic()) {
|
||||
|
|
@ -3516,7 +3515,7 @@ private:
|
|||
}
|
||||
}
|
||||
if (AstNodeFTask* const ftaskp
|
||||
= VN_CAST(classp->findMember(nodep->name()), NodeFTask)) {
|
||||
= VN_CAST(memberMap.findMember(classp, nodep->name()), NodeFTask)) {
|
||||
userIterate(ftaskp, nullptr);
|
||||
if (ftaskp->lifetime().isStatic()) {
|
||||
AstNodeExpr* argsp = nullptr;
|
||||
|
|
|
|||
|
|
@ -252,8 +252,9 @@ public:
|
|||
// Were changing widthMin's, so the table is now somewhat trashed
|
||||
nodep->typeTablep()->clearCache();
|
||||
iterate(nodep);
|
||||
// Don't want to repairCache, as all needed nodes have been added back in
|
||||
// a repair would prevent dead nodes from being detected
|
||||
// Don't want to AstTypeTable::repairCache, as all needed nodes
|
||||
// have been added back in; a repair would prevent dead nodes from
|
||||
// being detected
|
||||
}
|
||||
~WidthCommitVisitor() override = default;
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue