Internals: Add more sym table debug, renames. Merge from dot. No functional change

This commit is contained in:
Wilson Snyder 2012-07-19 21:18:39 -04:00
parent 92809b95c9
commit b7d1c34aa6
5 changed files with 82 additions and 66 deletions

View File

@ -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<<dotted()<<". - ";
if (inlinedDots()!="") str<<" flat.="<<inlinedDots()<<" - ";
if (varScopep()) { varScopep()->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<<dotted()<<". - ";
if (inlinedDots()!="") str<<" flat.="<<inlinedDots()<<" - ";
if (varScopep()) { varScopep()->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<<dotted()<<". - "; }
if (taskp()) { taskp()->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);

View File

@ -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 {

View File

@ -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 "<<scopename<<" "<<nodep<<endl);
VSymEnt* symp = new VSymEnt(&m_syms, nodep);
UINFO(9," INSERTtop se"<<(void*)symp<<" "<<scopename<<" "<<nodep<<endl);
symp->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 "<<scopename<<" above="<<(void*)abovep<<" cells="<<(void*)cellSymp<<" node="<<nodep<<endl);
VSymEnt* symp = new VSymEnt(&m_syms, nodep);
UINFO(9," INSERTcel se"<<(void*)symp<<" "<<scopename<<" above=se"<<(void*)abovep<<" mods=se"<<(void*)modSymp<<" node="<<nodep<<endl);
symp->parentp(abovep);
symp->fallbackp(cellSymp);
symp->fallbackp(modSymp);
if (nodep->modp()) nodep->modp()->user1p(symp);
abovep->reinsert(nodep->origName(), symp);
if (abovep != cellSymp) {
if (abovep != modSymp) {
// If it's foo_DOT_bar, we need to be able to find it under that too.
// Duplicates are possible, as until resolve generates might have 2 same cells under an if
cellSymp->reinsert(nodep->name(), symp);
modSymp->reinsert(nodep->name(), symp);
}
if (forScopeCreation()) m_nameScopeMap.insert(make_pair(scopename, symp));
return symp;
}
VSymEnt* insertInline(VSymEnt* abovep, VSymEnt* cellSymp,
VSymEnt* insertInline(VSymEnt* abovep, VSymEnt* modSymp,
AstCellInline* nodep, const string& basename) {
// A fake point in the hierarchy, corresponding to an inlined module
// This refrences to another Sym, and eventually resolves to a module with a prefix
UINFO(9," INSERTcel "<<basename<<" above="<<(void*)abovep<<" cells="<<(void*)cellSymp<<" node="<<nodep<<endl);
if (!abovep) nodep->v3fatalSrc("Null symbol table inserting node");
VSymEnt* symp = new VSymEnt(&m_syms, nodep);
UINFO(9," INSERTinl se"<<(void*)symp<<" "<<basename<<" above=se"<<(void*)abovep<<" mods=se"<<(void*)modSymp<<" node="<<nodep<<endl);
symp->parentp(abovep);
symp->fallbackp(cellSymp);
symp->fallbackp(modSymp);
symp->symPrefix(nodep->name()+"__DOT__");
abovep->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="<<nodep<<endl);
if (!abovep) nodep->v3fatalSrc("Null symbol table inserting node");
VSymEnt* symp = new VSymEnt(&m_syms, nodep);
UINFO(9," INSERTblk se"<<(void*)symp<<" above=se"<<(void*)abovep<<" node="<<nodep<<endl);
symp->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='"<<name<<"' above="<<(void*)abovep<<" node="<<nodep<<endl);
if (!abovep) nodep->v3fatalSrc("Null symbol table inserting node");
// We don't remember the ent associated with each node, because we need a unique scope entry for each instantiation
VSymEnt* symp = new VSymEnt(&m_syms, nodep);
UINFO(9," INSERTsym name='"<<name<<"' above="<<(void*)abovep<<" node="<<nodep<<endl);
abovep->insert(name, symp);
}
bool existsModScope(AstNodeModule* nodep) {
static bool existsModScope(AstNodeModule* nodep) {
return nodep->user1p()!=NULL;
}
VSymEnt* getNodeSym(AstNodeModule* nodep) {
static VSymEnt* getNodeSym(AstNodeModule* nodep) {
VSymEnt* symp = nodep->user1p()->castSymEnt();
if (!symp) nodep->v3fatalSrc("Module never assigned a symbol entry?");
return symp;
@ -191,14 +194,14 @@ public:
m_syms.dumpFilePrefixed("linkdot-preerr");
}
}
VSymEnt* findDotted(VSymEnt* cellSymp, const string& dotname,
VSymEnt* findDotted(VSymEnt* lookupSymp, const string& dotname,
string& baddot, VSymEnt*& okSymp) {
// Given a dotted hierarchy name, return where in scope it is
// Note when dotname=="" we just fall through and return cellSymp
UINFO(8," dottedFind "<<dotname<<endl);
// Note when dotname=="" we just fall through and return lookupSymp
UINFO(8," dottedFind se"<<(void*)lookupSymp<<" '"<<dotname<<"'"<<endl);
bool firstId = true;
string leftname = dotname;
okSymp = cellSymp; // So can list bad scopes
okSymp = lookupSymp; // So can list bad scopes
while (leftname != "") { // foreach dotted part of xref name
string::size_type pos;
string ident;
@ -210,7 +213,7 @@ public:
leftname = "";
}
baddot = ident; // So user can see where they botched it
okSymp = cellSymp;
okSymp = lookupSymp;
string altIdent = "";
if (m_forPrearray) {
// Cell foo__[array] before we've expanded arrays is just foo.
@ -218,61 +221,61 @@ public:
altIdent = ident.substr(0,pos);
}
}
UINFO(8," id "<<ident<<" left "<<leftname<<" at "<<cellSymp<<endl);
UINFO(8," id "<<ident<<" left "<<leftname<<" at se"<<lookupSymp<<endl);
// Spec says; Look at exiting module (cellnames then modname),
// then look up (inst name or modname)
if (firstId) {
// Check this module - subcellnames
AstCell* cellp = cellSymp->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 "<<cellSymp<<endl);
while (lookupSymp) {
lookupSymp = lookupSymp->parentp();
cellp = lookupSymp->nodep()->castCell(); // Replicated above
inlinep = lookupSymp->nodep()->castCellInline(); // Replicated above
if (lookupSymp) {
UINFO(9,"\t\tUp to "<<lookupSymp<<endl);
if ((cellp && cellp->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 "<<dotname
<<((cellSymp->symPrefix()=="") ? "" : " as ")
<<((cellSymp->symPrefix()=="") ? "" : cellSymp->symPrefix()+dotname)
<<" at "<<cellSymp
<<((lookupSymp->symPrefix()=="") ? "" : " as ")
<<((lookupSymp->symPrefix()=="") ? "" : lookupSymp->symPrefix()+dotname)
<<" at se"<<lookupSymp
<<endl);
AstNode* nodep = cellSymp->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;
}

View File

@ -57,7 +57,8 @@ private:
public:
void dumpIterate(ostream& os, VSymMap& doneSymsr, const string& indent, int numLevels, const string& searchName) {
os<<indent<<"+ "<<left<<setw(30)<<(searchName==""?"\"\"":searchName)<<setw(0)<<right;
os<<" "<<setw(16)<<(void*)(this)<<setw(0);
os<<" se"<<(void*)(this)<<setw(0);
os<<" fallb=se"<<(void*)(m_fallbackp);
os<<" n="<<nodep();
os<<endl;
if (doneSymsr.find(this) != doneSymsr.end()) {
@ -88,7 +89,7 @@ public:
string symPrefix() const { return m_symPrefix; }
void symPrefix(const string& name) { m_symPrefix = name; }
void insert(const string& name, VSymEnt* entp) {
UINFO(9, " SymInsert "<<this<<" '"<<name<<"' "<<(void*)entp<<" "<<entp->nodep()<<endl);
UINFO(9, " SymInsert se"<<(void*)this<<" '"<<name<<"' se"<<(void*)entp<<" "<<entp->nodep()<<endl);
if (name != "" && m_idNameMap.find(name) != m_idNameMap.end()) {
if (!V3Error::errorCount()) { // Else may have just reported warning
if (debug()>=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 "<<this<<" '"<<name<<"' "<<(void*)entp<<" "<<entp->nodep()<<endl);
UINFO(9, " SymReinsert se"<<(void*)this<<" '"<<name<<"' se"<<(void*)entp<<" "<<entp->nodep()<<endl);
it->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 "<<this<<" '"<<name<<"' -> "<<(iter == m_idNameMap.end() ? "NONE" : cvtToStr((void*)(iter->second->nodep())))<<endl);
UINFO(9, " SymFind se"<<(void*)this<<" '"<<name
<<"' -> "<<(iter == m_idNameMap.end() ? "NONE"
: "se"+cvtToStr((void*)(iter->second))+" n="+cvtToStr((void*)(iter->second->nodep())))<<endl);
if (iter != m_idNameMap.end()) return (iter->second);
return NULL;
}
@ -151,6 +154,7 @@ public:
scopes += AstNode::prettyName(it->first);
}
}
if (scopes=="") scopes="<no cells found>";
cerr<<V3Error::msgPrefix()<<" Known scopes under '"<<lookp->prettyName()<<"': "
<<scopes<<endl;
if (debug()) dump(cerr,"\t\t KnownScope: ", 1);
@ -180,7 +184,7 @@ public:
void dump(ostream& os, const string& indent="") {
VSymMap doneSyms;
os<<"SymEnt Dump:\n";
m_symRootp->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 "<<filename<<endl);
const auto_ptr<ofstream> logp (V3File::new_ofstream(filename));
if (logp->fail()) v3fatalSrc("Can't write "<<filename);
dump(*logp, "");

View File

@ -1462,16 +1462,16 @@ generate_region<nodep>: // ==IEEE: generate_region
generate_block_or_null<nodep>: // 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<nodep>: // 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($<fl>6,*$1,$6); }
| id ':' yBEGIN genItemList yEND endLabelE { $$ = new AstBegin($2,*$1,$4,true); GRAMMARP->endLabel($<fl>6,*$1,$6); }
| id ':' yBEGIN yEND endLabelE { $$ = NULL; GRAMMARP->endLabel($<fl>5,*$1,$5); }
| yBEGIN ':' idAny genItemList yEND endLabelE { $$ = new AstBegin($2,*$3,$4); GRAMMARP->endLabel($<fl>6,*$3,$6); }
| yBEGIN ':' idAny genItemList yEND endLabelE { $$ = new AstBegin($2,*$3,$4,true); GRAMMARP->endLabel($<fl>6,*$3,$6); }
| yBEGIN ':' idAny yEND endLabelE { $$ = NULL; GRAMMARP->endLabel($<fl>5,*$3,$5); }
;
@ -1500,7 +1500,7 @@ conditional_generate_construct<nodep>: // ==IEEE: conditional_generate_construct
loop_generate_construct<nodep>: // ==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();