forked from github/verilator
Internals: V3Link uses new common func to make symbol table
This commit is contained in:
parent
71bdfd9710
commit
ecb08b0cf3
@ -78,6 +78,18 @@ private:
|
|||||||
}
|
}
|
||||||
|
|
||||||
// METHODS
|
// METHODS
|
||||||
|
V3SymTable* symsFindNew(AstNode* nodep, V3SymTable* upperVarsp) {
|
||||||
|
// Find or create symbol table for this node
|
||||||
|
if (V3SymTable* symsp = nodep->user1p()->castSymTable()) {
|
||||||
|
return symsp;
|
||||||
|
} else {
|
||||||
|
V3SymTable* symsp = new V3SymTable(upperVarsp);
|
||||||
|
m_delSymps.push_back(symsp);
|
||||||
|
nodep->user1p(symsp);
|
||||||
|
return symsp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void linkVarName (AstVarRef* nodep) {
|
void linkVarName (AstVarRef* nodep) {
|
||||||
if (!nodep->varp()) {
|
if (!nodep->varp()) {
|
||||||
AstVar* varp = m_curVarsp->findIdName(nodep->name())->castVar();
|
AstVar* varp = m_curVarsp->findIdName(nodep->name())->castVar();
|
||||||
@ -85,7 +97,7 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const char* varTextType(AstNode* nodep) {
|
const char* nodeTextType(AstNode* nodep) {
|
||||||
const char* what = "node";
|
const char* what = "node";
|
||||||
if (nodep->castVar()) what = "variable";
|
if (nodep->castVar()) what = "variable";
|
||||||
else if (nodep->castCell()) what = "cell";
|
else if (nodep->castCell()) what = "cell";
|
||||||
@ -115,9 +127,7 @@ private:
|
|||||||
virtual void visit(AstNetlist* nodep, AstNUser*) {
|
virtual void visit(AstNetlist* nodep, AstNUser*) {
|
||||||
// Look at all modules, and store pointers to all module names
|
// Look at all modules, and store pointers to all module names
|
||||||
for (AstModule* modp = v3Global.rootp()->modulesp(); modp; modp=modp->nextp()->castModule()) {
|
for (AstModule* modp = v3Global.rootp()->modulesp(); modp; modp=modp->nextp()->castModule()) {
|
||||||
V3SymTable* symp = new V3SymTable(NULL);
|
symsFindNew(modp, NULL);
|
||||||
m_delSymps.push_back(symp);
|
|
||||||
modp->user1p(symp);
|
|
||||||
}
|
}
|
||||||
// And recurse...
|
// And recurse...
|
||||||
m_idState = ID_FIND;
|
m_idState = ID_FIND;
|
||||||
@ -134,7 +144,7 @@ private:
|
|||||||
UINFO(2,"Link Module: "<<nodep<<endl);
|
UINFO(2,"Link Module: "<<nodep<<endl);
|
||||||
m_modp = nodep;
|
m_modp = nodep;
|
||||||
// This state must be save/restored in the cell visitor function
|
// This state must be save/restored in the cell visitor function
|
||||||
m_curVarsp = nodep->user1p()->castSymTable();
|
m_curVarsp = symsFindNew(nodep, NULL);
|
||||||
if (!m_curVarsp) nodep->v3fatalSrc("NULL");
|
if (!m_curVarsp) nodep->v3fatalSrc("NULL");
|
||||||
m_cellVarsp = NULL;
|
m_cellVarsp = NULL;
|
||||||
m_paramNum = 0;
|
m_paramNum = 0;
|
||||||
@ -164,7 +174,7 @@ private:
|
|||||||
ins=true;
|
ins=true;
|
||||||
} else if (!findvarp) {
|
} else if (!findvarp) {
|
||||||
nodep->v3error("Unsupported in C: Variable has same name as "
|
nodep->v3error("Unsupported in C: Variable has same name as "
|
||||||
<<varTextType(findidp)<<": "<<nodep->prettyName());
|
<<nodeTextType(findidp)<<": "<<nodep->prettyName());
|
||||||
} else if (findvarp != nodep) {
|
} else if (findvarp != nodep) {
|
||||||
UINFO(4,"DupVar: "<<nodep<<" ;; "<<findvarp<<endl);
|
UINFO(4,"DupVar: "<<nodep<<" ;; "<<findvarp<<endl);
|
||||||
if (findvarp->user1p() == m_curVarsp) { // Only when on same level
|
if (findvarp->user1p() == m_curVarsp) { // Only when on same level
|
||||||
@ -224,13 +234,8 @@ private:
|
|||||||
V3SymTable* upperVarsp = m_curVarsp;
|
V3SymTable* upperVarsp = m_curVarsp;
|
||||||
{
|
{
|
||||||
// Create symbol table for the task's vars
|
// Create symbol table for the task's vars
|
||||||
if (V3SymTable* localVarsp = nodep->user1p()->castSymTable()) {
|
m_curVarsp = symsFindNew(nodep, upperVarsp);
|
||||||
m_curVarsp = localVarsp;
|
|
||||||
} else {
|
|
||||||
m_curVarsp = new V3SymTable(upperVarsp);
|
|
||||||
m_delSymps.push_back(m_curVarsp);
|
|
||||||
nodep->user1p(m_curVarsp);
|
|
||||||
}
|
|
||||||
// Convert the func's range to the output variable
|
// Convert the func's range to the output variable
|
||||||
// This should probably be done in the Parser instead, as then we could
|
// This should probably be done in the Parser instead, as then we could
|
||||||
// just attact normal signal attributes to it.
|
// just attact normal signal attributes to it.
|
||||||
@ -260,7 +265,7 @@ private:
|
|||||||
m_curVarsp->insert(nodep->name(), nodep);
|
m_curVarsp->insert(nodep->name(), nodep);
|
||||||
} else if (!findtaskp) {
|
} else if (!findtaskp) {
|
||||||
nodep->v3error("Unsupported in C: Task/function has same name as "
|
nodep->v3error("Unsupported in C: Task/function has same name as "
|
||||||
<<varTextType(findidp)<<": "<<nodep->prettyName());
|
<<nodeTextType(findidp)<<": "<<nodep->prettyName());
|
||||||
} else if (findtaskp!=nodep) {
|
} else if (findtaskp!=nodep) {
|
||||||
nodep->v3error("Duplicate declaration of task/function: "<<nodep->prettyName());
|
nodep->v3error("Duplicate declaration of task/function: "<<nodep->prettyName());
|
||||||
}
|
}
|
||||||
@ -282,13 +287,7 @@ private:
|
|||||||
m_beginNum = 0;
|
m_beginNum = 0;
|
||||||
{
|
{
|
||||||
// Create symbol table for the task's vars
|
// Create symbol table for the task's vars
|
||||||
if (V3SymTable* localVarsp = nodep->user1p()->castSymTable()) {
|
m_curVarsp = symsFindNew(nodep, upperVarsp);
|
||||||
m_curVarsp = localVarsp;
|
|
||||||
} else {
|
|
||||||
m_curVarsp = new V3SymTable(upperVarsp);
|
|
||||||
m_delSymps.push_back(m_curVarsp);
|
|
||||||
nodep->user1p(m_curVarsp);
|
|
||||||
}
|
|
||||||
nodep->iterateChildren(*this);
|
nodep->iterateChildren(*this);
|
||||||
}
|
}
|
||||||
m_curVarsp = upperVarsp;
|
m_curVarsp = upperVarsp;
|
||||||
@ -316,7 +315,7 @@ private:
|
|||||||
m_curVarsp->insert(nodep->name(), nodep);
|
m_curVarsp->insert(nodep->name(), nodep);
|
||||||
} else if (!findcellp) {
|
} else if (!findcellp) {
|
||||||
nodep->v3error("Unsupported in C: Cell has same name as "
|
nodep->v3error("Unsupported in C: Cell has same name as "
|
||||||
<<varTextType(findidp)<<": "<<nodep->prettyName());
|
<<nodeTextType(findidp)<<": "<<nodep->prettyName());
|
||||||
} else if (findcellp != nodep) {
|
} else if (findcellp != nodep) {
|
||||||
nodep->v3error("Duplicate name of cell: "<<nodep->prettyName());
|
nodep->v3error("Duplicate name of cell: "<<nodep->prettyName());
|
||||||
}
|
}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
// -*- C++ -*-
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
// DESCRIPTION: Verilator: Symbol table
|
// DESCRIPTION: Verilator: Symbol table
|
||||||
//
|
//
|
||||||
|
Loading…
Reference in New Issue
Block a user