diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index b72ad4ebd..c92e6e7db 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -679,16 +679,6 @@ void AstRefDType::dump(ostream& str) { if (defp()) { str<<" -> "; defp()->dump(str); } else { str<<" -> UNLINKED"; } } -void AstVarXRef::dump(ostream& str) { - this->AstNode::dump(str); - if (lvalue()) str<<" [LV] => "; - else str<<" [RV] <- "; - str<dump(str); } - else if (varp()) { varp()->dump(str); } - else { str<<"UNLINKED"; } -} void AstNodeDType::dump(ostream& str) { this->AstNode::dump(str); if (generic()) str<<" [GENERIC]"; @@ -762,8 +752,20 @@ void AstVarScope::dump(ostream& str) { if (varp()) { str<<" -> "; varp()->dump(str); } else { str<<" ->UNLINKED"; } } +void AstVarXRef::dump(ostream& str) { + this->AstNode::dump(str); + if (packagep()) { str<<" pkg=0x"<<(void*)packagep(); } + if (lvalue()) str<<" [LV] => "; + else str<<" [RV] <- "; + str<dump(str); } + else if (varp()) { varp()->dump(str); } + else { str<<"UNLINKED"; } +} void AstVarRef::dump(ostream& str) { this->AstNode::dump(str); + if (packagep()) { str<<" pkg=0x"<<(void*)packagep(); } if (lvalue()) str<<" [LV] => "; else str<<" [RV] <- "; if (varScopep()) { varScopep()->dump(str); } @@ -812,6 +814,7 @@ void AstActive::dump(ostream& str) { } void AstNodeFTaskRef::dump(ostream& str) { this->AstNode::dump(str); + if (packagep()) { str<<" pkg=0x"<<(void*)packagep(); } str<<" -> "; if (dotted()!="") { str<dump(str); } @@ -829,6 +832,7 @@ void AstBegin::dump(ostream& str) { this->AstNode::dump(str); if (unnamed()) str<<" [UNNAMED]"; if (hidden()) str<<" [HIDDEN]"; + if (generate()) str<<" [GEN]"; } void AstCoverDecl::dump(ostream& str) { this->AstNode::dump(str); diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index cf7f1e05b..6c24f72f4 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -1252,14 +1252,16 @@ private: string m_name; // Name of block bool m_unnamed; // Originally unnamed bool m_hidden; // Inserted by verilator, not user + bool m_generate; // Underneath a generate public: // Node that simply puts name into the output stream - AstBegin(FileLine* fileline, const string& name, AstNode* stmtsp) + AstBegin(FileLine* fileline, const string& name, AstNode* stmtsp, bool generate=false) : AstNode(fileline) , m_name(name) { addNOp1p(stmtsp); m_unnamed = (name==""); m_hidden = false; + m_generate = generate; } ASTNODE_NODE_FUNCS(Begin, BEGIN) virtual void dump(ostream& str); @@ -1273,6 +1275,8 @@ public: bool unnamed() const { return m_unnamed; } void hidden(bool flag) { m_hidden = flag; } bool hidden() const { return m_hidden; } + void generate(bool flag) { m_generate = flag; } + bool generate() const { return m_generate; } }; struct AstGenerate : public AstNode { diff --git a/src/V3LinkDot.cpp b/src/V3LinkDot.cpp index 9d0f6ac52..c9fd39163 100644 --- a/src/V3LinkDot.cpp +++ b/src/V3LinkDot.cpp @@ -104,54 +104,56 @@ private: public: VSymEnt* insertTopCell(AstNodeModule* nodep, const string& scopename) { // Only called on the module at the very top of the hierarchy - UINFO(9," INSERTtop "<parentp(m_syms.rootp()); // Needed so backward search can find name of top module nodep->user1p(symp); m_syms.rootp()->insert(nodep->origName(),symp); if (forScopeCreation()) m_nameScopeMap.insert(make_pair(scopename, symp)); return symp; } - VSymEnt* insertCell(VSymEnt* abovep, VSymEnt* cellSymp, + VSymEnt* insertCell(VSymEnt* abovep, VSymEnt* modSymp, AstCell* nodep, const string& scopename) { - UINFO(9," INSERTcel "<reinsert(basename, symp); - if (abovep != cellSymp) { + if (abovep != modSymp) { // If it's foo_DOT_bar, we need to be able to find it under that too. - cellSymp->reinsert(nodep->name(), symp); + modSymp->reinsert(nodep->name(), symp); } return symp; } - VSymEnt* insertBegin(VSymEnt* abovep, VSymEnt* cellSymp, + VSymEnt* insertBegin(VSymEnt* abovep, VSymEnt* modSymp, AstBegin* nodep) { // A fake point in the hierarchy, corresponding to a begin block // After we remove begins these will go away // Note we fallback to the symbol table of the parent, as we want to find variables there // However, cells walk the graph, so cells will appear under the begin itself - UINFO(9," INSERTbeg above="<<(void*)abovep<<" cells="<<(void*)cellSymp<<" node="<v3fatalSrc("Null symbol table inserting node"); VSymEnt* symp = new VSymEnt(&m_syms, nodep); + UINFO(9," INSERTblk se"<<(void*)symp<<" above=se"<<(void*)abovep<<" node="<parentp(abovep); symp->symPrefix(nodep->name()+"__DOT__"); if (nodep->name() != "") { @@ -161,15 +163,16 @@ public: return symp; } void insertSym(VSymEnt* abovep, const string& name, AstNode* nodep) { - UINFO(9," INSERTsym name='"<nodep()->castCell(); // Replicated below - AstCellInline* inlinep = cellSymp->nodep()->castCellInline(); // Replicated below - if (VSymEnt* findSymp = findWithAltFallback(cellSymp, ident, altIdent)) { - cellSymp = findSymp; + AstCell* cellp = lookupSymp->nodep()->castCell(); // Replicated below + AstCellInline* inlinep = lookupSymp->nodep()->castCellInline(); // Replicated below + if (VSymEnt* findSymp = findWithAltFallback(lookupSymp, ident, altIdent)) { + lookupSymp = findSymp; } // Check this module - cur modname else if ((cellp && cellp->modp()->origName() == ident) || (inlinep && inlinep->origModName() == ident)) {} // Move up and check cellname + modname else { - while (cellSymp) { - cellSymp = cellSymp->parentp(); - cellp = cellSymp->nodep()->castCell(); // Replicated above - inlinep = cellSymp->nodep()->castCellInline(); // Replicated above - if (cellSymp) { - UINFO(9,"\t\tUp to "<parentp(); + cellp = lookupSymp->nodep()->castCell(); // Replicated above + inlinep = lookupSymp->nodep()->castCellInline(); // Replicated above + if (lookupSymp) { + UINFO(9,"\t\tUp to "<modp()->origName() == ident) || (inlinep && inlinep->origModName() == ident)) { break; } - else if (VSymEnt* findSymp = findWithAltFallback(cellSymp, ident, altIdent)) { - cellSymp = findSymp; + else if (VSymEnt* findSymp = findWithAltFallback(lookupSymp, ident, altIdent)) { + lookupSymp = findSymp; break; } } else break; } - if (!cellSymp) return NULL; // Not found + if (!lookupSymp) return NULL; // Not found } } else { // Searching for middle submodule, must be a cell name - if (VSymEnt* findSymp = findWithAltFallback(cellSymp, ident, altIdent)) { - cellSymp = findSymp; + if (VSymEnt* findSymp = findWithAltFallback(lookupSymp, ident, altIdent)) { + lookupSymp = findSymp; } else { return NULL; // Not found } } firstId = false; } - return cellSymp; + return lookupSymp; } - AstNode* findSymPrefixed(VSymEnt* cellSymp, const string& dotname, string& baddot) { + AstNode* findSymPrefixed(VSymEnt* lookupSymp, const string& dotname, string& baddot) { // Find symbol in given point in hierarchy - // For simplicity cellSymp may be passed NULL result from findDotted - if (!cellSymp) return NULL; + // For simplicity lookupSymp may be passed NULL result from findDotted + if (!lookupSymp) return NULL; UINFO(8,"\t\tfindSymPrefixed "<symPrefix()=="") ? "" : " as ") - <<((cellSymp->symPrefix()=="") ? "" : cellSymp->symPrefix()+dotname) - <<" at "<symPrefix()=="") ? "" : " as ") + <<((lookupSymp->symPrefix()=="") ? "" : lookupSymp->symPrefix()+dotname) + <<" at se"<findIdFallback(cellSymp->symPrefix() + dotname)->nodep(); // Might be NULL + AstNode* nodep = lookupSymp->findIdFallback(lookupSymp->symPrefix() + dotname)->nodep(); // Might be NULL if (!nodep) baddot = dotname; return nodep; } diff --git a/src/V3SymTable.h b/src/V3SymTable.h index bfcb8e1f8..10f0574ca 100644 --- a/src/V3SymTable.h +++ b/src/V3SymTable.h @@ -57,7 +57,8 @@ private: public: void dumpIterate(ostream& os, VSymMap& doneSymsr, const string& indent, int numLevels, const string& searchName) { os<nodep()<nodep()<=9 || V3Error::debugDefault()) dump(cout,"- err-dump: ", 1); @@ -101,7 +102,7 @@ public: void reinsert(const string& name, VSymEnt* entp) { IdNameMap::iterator it = m_idNameMap.find(name); if (name!="" && it != m_idNameMap.end()) { - UINFO(9, " SymReinsert "<nodep()<nodep()<second = entp; // Replace } else { insert(name,entp); @@ -111,7 +112,9 @@ public: // Find identifier without looking upward through symbol hierarchy // First, scan this begin/end block or module for the name IdNameMap::const_iterator iter = m_idNameMap.find(name); - UINFO(9, " SymFind "< "<<(iter == m_idNameMap.end() ? "NONE" : cvtToStr((void*)(iter->second->nodep())))< "<<(iter == m_idNameMap.end() ? "NONE" + : "se"+cvtToStr((void*)(iter->second))+" n="+cvtToStr((void*)(iter->second->nodep())))<second); return NULL; } @@ -151,6 +154,7 @@ public: scopes += AstNode::prettyName(it->first); } } + if (scopes=="") scopes=""; cerr<prettyName()<<"': " <dumpIterate(os, doneSyms, indent, 9999, "TOP"); + m_symRootp->dumpIterate(os, doneSyms, indent, 9999, "$root"); bool first = false; for (SymStack::iterator it = m_symsp.begin(); it != m_symsp.end(); ++it) { if (doneSyms.find(*it) == doneSyms.end()) { @@ -192,6 +196,7 @@ public: void dumpFilePrefixed(const string& nameComment) { if (v3Global.opt.dumpTree()) { string filename = v3Global.debugFilename(nameComment)+".txt"; + UINFO(2,"Dumping "< logp (V3File::new_ofstream(filename)); if (logp->fail()) v3fatalSrc("Can't write "<: // ==IEEE: generate_region generate_block_or_null: // IEEE: generate_block_or_null // ';' // is included in // // IEEE: generate_block - generate_item { $$ = $1 ? (new AstBegin($1->fileline(),"genblk",$1)) : NULL; } + generate_item { $$ = $1 ? (new AstBegin($1->fileline(),"genblk",$1,true)) : NULL; } | genItemBegin { $$ = $1; } ; genItemBegin: // IEEE: part of generate_block - yBEGIN genItemList yEND { $$ = new AstBegin($1,"genblk",$2); } + yBEGIN genItemList yEND { $$ = new AstBegin($1,"genblk",$2,true); } | yBEGIN yEND { $$ = NULL; } - | id ':' yBEGIN genItemList yEND endLabelE { $$ = new AstBegin($2,*$1,$4); GRAMMARP->endLabel($6,*$1,$6); } + | id ':' yBEGIN genItemList yEND endLabelE { $$ = new AstBegin($2,*$1,$4,true); GRAMMARP->endLabel($6,*$1,$6); } | id ':' yBEGIN yEND endLabelE { $$ = NULL; GRAMMARP->endLabel($5,*$1,$5); } - | yBEGIN ':' idAny genItemList yEND endLabelE { $$ = new AstBegin($2,*$3,$4); GRAMMARP->endLabel($6,*$3,$6); } + | yBEGIN ':' idAny genItemList yEND endLabelE { $$ = new AstBegin($2,*$3,$4,true); GRAMMARP->endLabel($6,*$3,$6); } | yBEGIN ':' idAny yEND endLabelE { $$ = NULL; GRAMMARP->endLabel($5,*$3,$5); } ; @@ -1500,7 +1500,7 @@ conditional_generate_construct: // ==IEEE: conditional_generate_construct loop_generate_construct: // ==IEEE: loop_generate_construct yFOR '(' genvar_initialization ';' expr ';' genvar_iteration ')' generate_block_or_null - { AstBegin* blkp = new AstBegin($1,"",NULL); blkp->hidden(true); + { AstBegin* blkp = new AstBegin($1,"",NULL,true); blkp->hidden(true); AstNode* initp = $3; AstNode* varp = $3; if (varp->castVar()) { // Genvar initp = varp->nextp();