Internals: Detab and fix spacing style issues. No functional change.
When diff, recommend using "git diff --ignore-all-space" When merging, recommend using "git merge -Xignore-all-space"
This commit is contained in:
parent
59d7d9e8c3
commit
b83b606267
457
src/V3Active.cpp
457
src/V3Active.cpp
|
|
@ -21,12 +21,12 @@
|
|||
//
|
||||
// Note this can be called multiple times.
|
||||
// Create a IACTIVE(initial), SACTIVE(combo)
|
||||
// ALWAYS: Remove any-edges from sense list
|
||||
// If no POS/NEG in senselist, Fold into SACTIVE(combo)
|
||||
// Else fold into SACTIVE(sequent).
|
||||
// OPTIMIZE: When support async clocks, fold into that active if possible
|
||||
// INITIAL: Move into IACTIVE
|
||||
// WIRE: Move into SACTIVE(combo)
|
||||
// ALWAYS: Remove any-edges from sense list
|
||||
// If no POS/NEG in senselist, Fold into SACTIVE(combo)
|
||||
// Else fold into SACTIVE(sequent).
|
||||
// OPTIMIZE: When support async clocks, fold into that active if possible
|
||||
// INITIAL: Move into IACTIVE
|
||||
// WIRE: Move into SACTIVE(combo)
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -56,66 +56,68 @@ class ActiveNamer : public ActiveBaseVisitor {
|
|||
private:
|
||||
typedef std::map<string,AstActive*> ActiveNameMap;
|
||||
// STATE
|
||||
AstScope* m_scopep; // Current scope to add statement to
|
||||
AstActive* m_iActivep; // For current scope, the IActive we're building
|
||||
AstActive* m_cActivep; // For current scope, the SActive(combo) we're building
|
||||
AstScope* m_scopep; // Current scope to add statement to
|
||||
AstActive* m_iActivep; // For current scope, the IActive we're building
|
||||
AstActive* m_cActivep; // For current scope, the SActive(combo) we're building
|
||||
|
||||
SenTreeSet m_activeSens; // Sen lists for each active we've made
|
||||
SenTreeSet m_activeSens; // Sen lists for each active we've made
|
||||
typedef vl_unordered_map<AstSenTree*, AstActive*> ActiveMap;
|
||||
ActiveMap m_activeMap; // Map sentree to active, for folding.
|
||||
|
||||
// METHODS
|
||||
void addActive(AstActive* nodep) {
|
||||
if (!m_scopep) nodep->v3fatalSrc("NULL scope");
|
||||
m_scopep->addActivep(nodep);
|
||||
if (!m_scopep) nodep->v3fatalSrc("NULL scope");
|
||||
m_scopep->addActivep(nodep);
|
||||
}
|
||||
// VISITORS
|
||||
virtual void visit(AstScope* nodep) {
|
||||
m_scopep = nodep;
|
||||
m_iActivep = NULL;
|
||||
m_cActivep = NULL;
|
||||
m_scopep = nodep;
|
||||
m_iActivep = NULL;
|
||||
m_cActivep = NULL;
|
||||
m_activeSens.clear();
|
||||
m_activeMap.clear();
|
||||
iterateChildren(nodep);
|
||||
// Don't clear scopep, the namer persists beyond this visit
|
||||
// Don't clear scopep, the namer persists beyond this visit
|
||||
}
|
||||
virtual void visit(AstSenTree* nodep) {
|
||||
// Simplify sensitivity list
|
||||
V3Const::constifyExpensiveEdit(nodep); VL_DANGLING(nodep);
|
||||
// Simplify sensitivity list
|
||||
V3Const::constifyExpensiveEdit(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
// Empty visitors, speed things up
|
||||
virtual void visit(AstNodeStmt* nodep) { }
|
||||
//--------------------
|
||||
// Default
|
||||
virtual void visit(AstNode* nodep) {
|
||||
// Default: Just iterate
|
||||
// Default: Just iterate
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
// METHODS
|
||||
public:
|
||||
AstScope* scopep() { return m_scopep; }
|
||||
AstActive* getCActive(FileLine* fl) {
|
||||
if (!m_cActivep) {
|
||||
m_cActivep = new AstActive(fl, "combo",
|
||||
new AstSenTree(fl, new AstSenItem(fl,AstSenItem::Combo())));
|
||||
m_cActivep->sensesStorep(m_cActivep->sensesp());
|
||||
addActive(m_cActivep);
|
||||
}
|
||||
return m_cActivep;
|
||||
if (!m_cActivep) {
|
||||
m_cActivep = new AstActive(
|
||||
fl, "combo",
|
||||
new AstSenTree(fl, new AstSenItem(fl, AstSenItem::Combo())));
|
||||
m_cActivep->sensesStorep(m_cActivep->sensesp());
|
||||
addActive(m_cActivep);
|
||||
}
|
||||
return m_cActivep;
|
||||
}
|
||||
AstActive* getIActive(FileLine* fl) {
|
||||
if (!m_iActivep) {
|
||||
m_iActivep = new AstActive(fl, "initial",
|
||||
new AstSenTree(fl, new AstSenItem(fl,AstSenItem::Initial())));
|
||||
m_iActivep->sensesStorep(m_iActivep->sensesp());
|
||||
addActive(m_iActivep);
|
||||
}
|
||||
return m_iActivep;
|
||||
if (!m_iActivep) {
|
||||
m_iActivep = new AstActive(
|
||||
fl, "initial",
|
||||
new AstSenTree(fl, new AstSenItem(fl, AstSenItem::Initial())));
|
||||
m_iActivep->sensesStorep(m_iActivep->sensesp());
|
||||
addActive(m_iActivep);
|
||||
}
|
||||
return m_iActivep;
|
||||
}
|
||||
AstActive* getActive(FileLine* fl, AstSenTree* sensesp) {
|
||||
// Return a sentree in this scope that matches given sense list.
|
||||
// Return a sentree in this scope that matches given sense list.
|
||||
|
||||
AstActive* activep = NULL;
|
||||
AstActive* activep = NULL;
|
||||
AstSenTree* activeSenp = m_activeSens.find(sensesp);
|
||||
if (activeSenp) {
|
||||
ActiveMap::iterator it = m_activeMap.find(activeSenp);
|
||||
|
|
@ -123,26 +125,26 @@ public:
|
|||
activep = it->second;
|
||||
}
|
||||
|
||||
// Not found, form a new one
|
||||
if (!activep) {
|
||||
AstSenTree* newsenp = sensesp->cloneTree(false);
|
||||
activep = new AstActive(fl, "sequent", newsenp);
|
||||
activep->sensesStorep(activep->sensesp());
|
||||
UINFO(8," New ACTIVE "<<activep<<endl);
|
||||
// Form the sensitivity list
|
||||
addActive(activep);
|
||||
// Not found, form a new one
|
||||
if (!activep) {
|
||||
AstSenTree* newsenp = sensesp->cloneTree(false);
|
||||
activep = new AstActive(fl, "sequent", newsenp);
|
||||
activep->sensesStorep(activep->sensesp());
|
||||
UINFO(8," New ACTIVE "<<activep<<endl);
|
||||
// Form the sensitivity list
|
||||
addActive(activep);
|
||||
m_activeMap[newsenp] = activep;
|
||||
m_activeSens.add(newsenp);
|
||||
// Note actives may have also been added above in the Active visitor
|
||||
}
|
||||
return activep;
|
||||
// Note actives may have also been added above in the Active visitor
|
||||
}
|
||||
return activep;
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
ActiveNamer() {
|
||||
m_scopep = NULL;
|
||||
m_iActivep = NULL;
|
||||
m_cActivep = NULL;
|
||||
m_scopep = NULL;
|
||||
m_iActivep = NULL;
|
||||
m_cActivep = NULL;
|
||||
}
|
||||
virtual ~ActiveNamer() {}
|
||||
void main(AstScope* nodep) {
|
||||
|
|
@ -157,55 +159,55 @@ class ActiveDlyVisitor : public ActiveBaseVisitor {
|
|||
public:
|
||||
enum CheckType { CT_SEQ, CT_COMBO, CT_INITIAL, CT_LATCH };
|
||||
private:
|
||||
CheckType m_check; // Combo logic or other
|
||||
AstNode* m_alwaysp; // Always we're under
|
||||
AstNode* m_assignp; // In assign
|
||||
CheckType m_check; // Combo logic or other
|
||||
AstNode* m_alwaysp; // Always we're under
|
||||
AstNode* m_assignp; // In assign
|
||||
// VISITORS
|
||||
virtual void visit(AstAssignDly* nodep) {
|
||||
if (m_check != CT_SEQ) {
|
||||
// Convert to a non-delayed assignment
|
||||
UINFO(5," ASSIGNDLY "<<nodep<<endl);
|
||||
if (m_check == CT_INITIAL) {
|
||||
if (m_check != CT_SEQ) {
|
||||
// Convert to a non-delayed assignment
|
||||
UINFO(5," ASSIGNDLY "<<nodep<<endl);
|
||||
if (m_check == CT_INITIAL) {
|
||||
nodep->v3warn(INITIALDLY, "Delayed assignments (<=) in initial"
|
||||
" or final block; suggest blocking assignments (=).");
|
||||
} else if (m_check == CT_LATCH) {
|
||||
// Suppress. Shouldn't matter that the interior of the latch races
|
||||
} else {
|
||||
} else if (m_check == CT_LATCH) {
|
||||
// Suppress. Shouldn't matter that the interior of the latch races
|
||||
} else {
|
||||
nodep->v3warn(COMBDLY, "Delayed assignments (<=) in non-clocked"
|
||||
" (non flop or latch) block; suggest blocking assignments (=).");
|
||||
}
|
||||
}
|
||||
AstNode* newp = new AstAssign(nodep->fileline(),
|
||||
nodep->lhsp()->unlinkFrBack(),
|
||||
nodep->rhsp()->unlinkFrBack());
|
||||
nodep->replaceWith(newp);
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
nodep->replaceWith(newp);
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstAssign* nodep) {
|
||||
if (m_check == CT_SEQ) {
|
||||
AstNode* las = m_assignp;
|
||||
m_assignp = nodep;
|
||||
if (m_check == CT_SEQ) {
|
||||
AstNode* las = m_assignp;
|
||||
m_assignp = nodep;
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
m_assignp = las;
|
||||
}
|
||||
m_assignp = las;
|
||||
}
|
||||
}
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
AstVar* varp=nodep->varp();
|
||||
if (m_check == CT_SEQ
|
||||
&& m_assignp
|
||||
&& !varp->isUsedLoopIdx() // Ignore loop indicies
|
||||
&& !varp->isTemp()
|
||||
) {
|
||||
// Allow turning off warnings on the always, or the variable also
|
||||
if (!m_alwaysp->fileline()->warnIsOff(V3ErrorCode::BLKSEQ)
|
||||
&& !m_assignp->fileline()->warnIsOff(V3ErrorCode::BLKSEQ)
|
||||
&& !varp->fileline()->warnIsOff(V3ErrorCode::BLKSEQ)
|
||||
) {
|
||||
m_alwaysp->fileline()->modifyWarnOff(V3ErrorCode::BLKSEQ, true); // Complain just once for the entire always
|
||||
varp->fileline()->modifyWarnOff(V3ErrorCode::BLKSEQ, true);
|
||||
nodep->v3warn(BLKSEQ,"Blocking assignments (=) in sequential (flop or latch) block; suggest delayed assignments (<=).");
|
||||
}
|
||||
}
|
||||
AstVar* varp = nodep->varp();
|
||||
if (m_check == CT_SEQ
|
||||
&& m_assignp
|
||||
&& !varp->isUsedLoopIdx() // Ignore loop indicies
|
||||
&& !varp->isTemp()
|
||||
) {
|
||||
// Allow turning off warnings on the always, or the variable also
|
||||
if (!m_alwaysp->fileline()->warnIsOff(V3ErrorCode::BLKSEQ)
|
||||
&& !m_assignp->fileline()->warnIsOff(V3ErrorCode::BLKSEQ)
|
||||
&& !varp->fileline()->warnIsOff(V3ErrorCode::BLKSEQ)
|
||||
) {
|
||||
m_alwaysp->fileline()->modifyWarnOff(V3ErrorCode::BLKSEQ, true); // Complain just once for the entire always
|
||||
varp->fileline()->modifyWarnOff(V3ErrorCode::BLKSEQ, true);
|
||||
nodep->v3warn(BLKSEQ, "Blocking assignments (=) in sequential (flop or latch) block; suggest delayed assignments (<=).");
|
||||
}
|
||||
}
|
||||
}
|
||||
//--------------------
|
||||
virtual void visit(AstNode* nodep) {
|
||||
|
|
@ -214,9 +216,9 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
ActiveDlyVisitor(AstNode* nodep, CheckType check) {
|
||||
m_alwaysp = nodep;
|
||||
m_check = check;
|
||||
m_assignp = NULL;
|
||||
m_alwaysp = nodep;
|
||||
m_check = check;
|
||||
m_assignp = NULL;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~ActiveDlyVisitor() {}
|
||||
|
|
@ -229,183 +231,188 @@ class ActiveVisitor : public ActiveBaseVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Each call to V3Const::constify
|
||||
// AstNode::user4() Used by V3Const::constify, called below
|
||||
// AstNode::user4() Used by V3Const::constify, called below
|
||||
|
||||
// STATE
|
||||
ActiveNamer m_namer; // Tracking of active names
|
||||
AstCFunc* m_scopeFinalp; // Final function for this scope
|
||||
bool m_itemCombo; // Found a SenItem combo
|
||||
bool m_itemSequent; // Found a SenItem sequential
|
||||
ActiveNamer m_namer; // Tracking of active names
|
||||
AstCFunc* m_scopeFinalp; // Final function for this scope
|
||||
bool m_itemCombo; // Found a SenItem combo
|
||||
bool m_itemSequent; // Found a SenItem sequential
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstScope* nodep) {
|
||||
// Create required actives and add to scope
|
||||
UINFO(4," SCOPE "<<nodep<<endl);
|
||||
// Clear last scope's names, and collect this scope's existing names
|
||||
m_namer.main(nodep);
|
||||
m_scopeFinalp = NULL;
|
||||
// Create required actives and add to scope
|
||||
UINFO(4," SCOPE "<<nodep<<endl);
|
||||
// Clear last scope's names, and collect this scope's existing names
|
||||
m_namer.main(nodep);
|
||||
m_scopeFinalp = NULL;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstActive* nodep) {
|
||||
// Actives are being formed, so we can ignore any already made
|
||||
// Actives are being formed, so we can ignore any already made
|
||||
}
|
||||
virtual void visit(AstInitial* nodep) {
|
||||
// Relink to IACTIVE, unless already under it
|
||||
UINFO(4," INITIAL "<<nodep<<endl);
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_INITIAL);
|
||||
AstActive* wantactivep = m_namer.getIActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
// Relink to IACTIVE, unless already under it
|
||||
UINFO(4," INITIAL "<<nodep<<endl);
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_INITIAL);
|
||||
AstActive* wantactivep = m_namer.getIActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
}
|
||||
virtual void visit(AstAssignAlias* nodep) {
|
||||
// Relink to CACTIVE, unless already under it
|
||||
UINFO(4," ASSIGNW "<<nodep<<endl);
|
||||
AstActive* wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
// Relink to CACTIVE, unless already under it
|
||||
UINFO(4," ASSIGNW "<<nodep<<endl);
|
||||
AstActive* wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
}
|
||||
virtual void visit(AstAssignW* nodep) {
|
||||
// Relink to CACTIVE, unless already under it
|
||||
UINFO(4," ASSIGNW "<<nodep<<endl);
|
||||
AstActive* wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
// Relink to CACTIVE, unless already under it
|
||||
UINFO(4," ASSIGNW "<<nodep<<endl);
|
||||
AstActive* wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
}
|
||||
virtual void visit(AstCoverToggle* nodep) {
|
||||
// Relink to CACTIVE, unless already under it
|
||||
UINFO(4," COVERTOGGLE "<<nodep<<endl);
|
||||
AstActive* wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
// Relink to CACTIVE, unless already under it
|
||||
UINFO(4," COVERTOGGLE "<<nodep<<endl);
|
||||
AstActive* wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
}
|
||||
virtual void visit(AstFinal* nodep) {
|
||||
// Relink to CFUNC for the final
|
||||
UINFO(4," FINAL "<<nodep<<endl);
|
||||
if (!nodep->bodysp()) { // Empty, Kill it.
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_INITIAL);
|
||||
if (!m_scopeFinalp) {
|
||||
m_scopeFinalp = new AstCFunc(nodep->fileline(), "_final_"+m_namer.scopep()->nameDotless(), m_namer.scopep());
|
||||
m_scopeFinalp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
m_scopeFinalp->addInitsp(new AstCStmt(nodep->fileline(), EmitCBaseVisitor::symTopAssign()+"\n"));
|
||||
m_scopeFinalp->dontCombine(true);
|
||||
m_scopeFinalp->formCallTree(true);
|
||||
m_scopeFinalp->slow(true);
|
||||
m_namer.scopep()->addActivep(m_scopeFinalp);
|
||||
}
|
||||
nodep->unlinkFrBack();
|
||||
m_scopeFinalp->addStmtsp(new AstComment(nodep->fileline(), nodep->typeName()));
|
||||
m_scopeFinalp->addStmtsp(nodep->bodysp()->unlinkFrBackWithNext());
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
// Relink to CFUNC for the final
|
||||
UINFO(4," FINAL "<<nodep<<endl);
|
||||
if (!nodep->bodysp()) { // Empty, Kill it.
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_INITIAL);
|
||||
if (!m_scopeFinalp) {
|
||||
m_scopeFinalp = new AstCFunc(
|
||||
nodep->fileline(), "_final_"+m_namer.scopep()->nameDotless(),
|
||||
m_namer.scopep());
|
||||
m_scopeFinalp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
m_scopeFinalp->addInitsp(
|
||||
new AstCStmt(nodep->fileline(), EmitCBaseVisitor::symTopAssign()+"\n"));
|
||||
m_scopeFinalp->dontCombine(true);
|
||||
m_scopeFinalp->formCallTree(true);
|
||||
m_scopeFinalp->slow(true);
|
||||
m_namer.scopep()->addActivep(m_scopeFinalp);
|
||||
}
|
||||
nodep->unlinkFrBack();
|
||||
m_scopeFinalp->addStmtsp(new AstComment(nodep->fileline(), nodep->typeName()));
|
||||
m_scopeFinalp->addStmtsp(nodep->bodysp()->unlinkFrBackWithNext());
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
|
||||
// METHODS
|
||||
void visitAlways(AstNode* nodep, AstSenTree* oldsensesp, VAlwaysKwd kwd) {
|
||||
// Move always to appropriate ACTIVE based on its sense list
|
||||
if (oldsensesp
|
||||
&& oldsensesp->sensesp()
|
||||
// Move always to appropriate ACTIVE based on its sense list
|
||||
if (oldsensesp
|
||||
&& oldsensesp->sensesp()
|
||||
&& VN_IS(oldsensesp->sensesp(), SenItem)
|
||||
&& VN_CAST(oldsensesp->sensesp(), SenItem)->isNever()) {
|
||||
// Never executing. Kill it.
|
||||
if (oldsensesp->sensesp()->nextp()) nodep->v3fatalSrc("Never senitem should be alone, else the never should be eliminated.");
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
// Never executing. Kill it.
|
||||
if (oldsensesp->sensesp()->nextp()) nodep->v3fatalSrc("Never senitem should be alone, else the never should be eliminated.");
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
|
||||
// Read sensitivitues
|
||||
m_itemCombo = false;
|
||||
m_itemSequent = false;
|
||||
// Read sensitivitues
|
||||
m_itemCombo = false;
|
||||
m_itemSequent = false;
|
||||
iterateAndNextNull(oldsensesp);
|
||||
bool combo = m_itemCombo;
|
||||
bool sequent = m_itemSequent;
|
||||
bool combo = m_itemCombo;
|
||||
bool sequent = m_itemSequent;
|
||||
|
||||
if (!combo && !sequent) combo=true; // If no list, Verilog 2000: always @ (*)
|
||||
if (combo && sequent) {
|
||||
if (!v3Global.opt.bboxUnsup()) {
|
||||
nodep->v3error("Unsupported: Mixed edge (pos/negedge) and activity (no edge) sensitive activity list");
|
||||
}
|
||||
sequent = false;
|
||||
}
|
||||
if (!combo && !sequent) combo=true; // If no list, Verilog 2000: always @ (*)
|
||||
if (combo && sequent) {
|
||||
if (!v3Global.opt.bboxUnsup()) {
|
||||
nodep->v3error("Unsupported: Mixed edge (pos/negedge) and activity (no edge) sensitive activity list");
|
||||
}
|
||||
sequent = false;
|
||||
}
|
||||
|
||||
AstActive* wantactivep = NULL;
|
||||
if (combo && !sequent) {
|
||||
// Combo: Relink to ACTIVE(combo)
|
||||
wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
} else {
|
||||
// Sequential: Build a ACTIVE(name)
|
||||
// OPTIMIZE: We could substitute a constant for things in the sense list, for example
|
||||
// always (posedge RESET) { if (RESET).... } we know RESET is true.
|
||||
// Summarize a long list of combo inputs as just "combo"
|
||||
#ifndef __COVERITY__ // Else dead code on next line.
|
||||
if (combo) oldsensesp->addSensesp
|
||||
(new AstSenItem(nodep->fileline(),AstSenItem::Combo()));
|
||||
AstActive* wantactivep = NULL;
|
||||
if (combo && !sequent) {
|
||||
// Combo: Relink to ACTIVE(combo)
|
||||
wantactivep = m_namer.getCActive(nodep->fileline());
|
||||
} else {
|
||||
// Sequential: Build a ACTIVE(name)
|
||||
// OPTIMIZE: We could substitute a constant for things in the sense list, for example
|
||||
// always (posedge RESET) { if (RESET).... } we know RESET is true.
|
||||
// Summarize a long list of combo inputs as just "combo"
|
||||
#ifndef __COVERITY__ // Else dead code on next line.
|
||||
if (combo) oldsensesp->addSensesp
|
||||
(new AstSenItem(nodep->fileline(), AstSenItem::Combo()));
|
||||
#endif
|
||||
wantactivep = m_namer.getActive(nodep->fileline(), oldsensesp);
|
||||
}
|
||||
wantactivep = m_namer.getActive(nodep->fileline(), oldsensesp);
|
||||
}
|
||||
|
||||
// Delete sensitivity list
|
||||
if (oldsensesp) {
|
||||
oldsensesp->unlinkFrBackWithNext()->deleteTree(); VL_DANGLING(oldsensesp);
|
||||
}
|
||||
// Delete sensitivity list
|
||||
if (oldsensesp) {
|
||||
oldsensesp->unlinkFrBackWithNext()->deleteTree(); VL_DANGLING(oldsensesp);
|
||||
}
|
||||
|
||||
// Move node to new active
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
// Move node to new active
|
||||
nodep->unlinkFrBack();
|
||||
wantactivep->addStmtsp(nodep);
|
||||
|
||||
// Warn and/or convert any delayed assignments
|
||||
if (combo && !sequent) {
|
||||
if (kwd == VAlwaysKwd::ALWAYS_LATCH) {
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_LATCH);
|
||||
} else {
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_COMBO);
|
||||
}
|
||||
}
|
||||
else if (!combo && sequent) {
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_SEQ);
|
||||
}
|
||||
// Warn and/or convert any delayed assignments
|
||||
if (combo && !sequent) {
|
||||
if (kwd == VAlwaysKwd::ALWAYS_LATCH) {
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_LATCH);
|
||||
} else {
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_COMBO);
|
||||
}
|
||||
}
|
||||
else if (!combo && sequent) {
|
||||
ActiveDlyVisitor dlyvisitor (nodep, ActiveDlyVisitor::CT_SEQ);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstAlways* nodep) {
|
||||
// Move always to appropriate ACTIVE based on its sense list
|
||||
UINFO(4," ALW "<<nodep<<endl);
|
||||
//if (debug()>=9) nodep->dumpTree(cout," Alw: ");
|
||||
// Move always to appropriate ACTIVE based on its sense list
|
||||
UINFO(4," ALW "<<nodep<<endl);
|
||||
//if (debug()>=9) nodep->dumpTree(cout, " Alw: ");
|
||||
|
||||
if (!nodep->bodysp()) {
|
||||
// Empty always. Kill it.
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
visitAlways(nodep, nodep->sensesp(), nodep->keyword());
|
||||
if (!nodep->bodysp()) {
|
||||
// Empty always. Kill it.
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
visitAlways(nodep, nodep->sensesp(), nodep->keyword());
|
||||
}
|
||||
virtual void visit(AstAlwaysPublic* nodep) {
|
||||
// Move always to appropriate ACTIVE based on its sense list
|
||||
UINFO(4," ALWPub "<<nodep<<endl);
|
||||
//if (debug()>=9) nodep->dumpTree(cout," Alw: ");
|
||||
visitAlways(nodep, nodep->sensesp(), VAlwaysKwd::ALWAYS);
|
||||
// Move always to appropriate ACTIVE based on its sense list
|
||||
UINFO(4," ALWPub "<<nodep<<endl);
|
||||
//if (debug()>=9) nodep->dumpTree(cout, " Alw: ");
|
||||
visitAlways(nodep, nodep->sensesp(), VAlwaysKwd::ALWAYS);
|
||||
}
|
||||
virtual void visit(AstSenGate* nodep) {
|
||||
AstSenItem* subitemp = nodep->sensesp();
|
||||
if (subitemp->edgeType() != AstEdgeType::ET_ANYEDGE
|
||||
&& subitemp->edgeType() != AstEdgeType::ET_POSEDGE
|
||||
&& subitemp->edgeType() != AstEdgeType::ET_NEGEDGE) {
|
||||
nodep->v3fatalSrc("Strange activity type under SenGate");
|
||||
}
|
||||
AstSenItem* subitemp = nodep->sensesp();
|
||||
if (subitemp->edgeType() != AstEdgeType::ET_ANYEDGE
|
||||
&& subitemp->edgeType() != AstEdgeType::ET_POSEDGE
|
||||
&& subitemp->edgeType() != AstEdgeType::ET_NEGEDGE) {
|
||||
nodep->v3fatalSrc("Strange activity type under SenGate");
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstSenItem* nodep) {
|
||||
if (nodep->edgeType() == AstEdgeType::ET_ANYEDGE) {
|
||||
m_itemCombo = true;
|
||||
// Delete the sensitivity
|
||||
// We'll add it as a generic COMBO SenItem in a moment.
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
} else if (nodep->varrefp()) {
|
||||
// V3LinkResolve should have cleaned most of these up
|
||||
if (!nodep->varrefp()->width1()) nodep->v3error("Unsupported: Non-single bit wide signal pos/negedge sensitivity: "
|
||||
<<nodep->varrefp()->prettyName());
|
||||
m_itemSequent = true;
|
||||
nodep->varrefp()->varp()->usedClock(true);
|
||||
}
|
||||
if (nodep->edgeType() == AstEdgeType::ET_ANYEDGE) {
|
||||
m_itemCombo = true;
|
||||
// Delete the sensitivity
|
||||
// We'll add it as a generic COMBO SenItem in a moment.
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
} else if (nodep->varrefp()) {
|
||||
// V3LinkResolve should have cleaned most of these up
|
||||
if (!nodep->varrefp()->width1()) {
|
||||
nodep->v3error("Unsupported: Non-single bit wide signal pos/negedge sensitivity: "
|
||||
<<nodep->varrefp()->prettyName());
|
||||
}
|
||||
m_itemSequent = true;
|
||||
nodep->varrefp()->varp()->usedClock(true);
|
||||
}
|
||||
}
|
||||
|
||||
// Empty visitors, speed things up
|
||||
|
|
@ -418,9 +425,9 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit ActiveVisitor(AstNetlist* nodep) {
|
||||
m_scopeFinalp = NULL;
|
||||
m_itemCombo = false;
|
||||
m_itemSequent = false;
|
||||
m_scopeFinalp = NULL;
|
||||
m_itemCombo = false;
|
||||
m_itemSequent = false;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~ActiveVisitor() {}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void activeAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -21,9 +21,9 @@
|
|||
//
|
||||
// Note this can be called multiple times.
|
||||
// Across all ACTIVES
|
||||
// SenTrees are now under each ACTIVE statement, we want them global:
|
||||
// Find SenTree in under global TopScope, or create it there
|
||||
// Move SenTree the global SenTree
|
||||
// SenTrees are now under each ACTIVE statement, we want them global:
|
||||
// Find SenTree in under global TopScope, or create it there
|
||||
// Move SenTree the global SenTree
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -43,91 +43,95 @@ class ActiveTopVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist
|
||||
// AstNode::user() bool. True if processed
|
||||
// AstNode::user() bool. True if processed
|
||||
// Each call to V3Const::constify
|
||||
// AstNode::user4() Used by V3Const::constify, called below
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstNode::user4() Used by V3Const::constify, called below
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
AstTopScope* m_topscopep; // Top scope for adding sentrees under
|
||||
SenTreeFinder m_finder; // Find global sentree's and add them
|
||||
AstTopScope* m_topscopep; // Top scope for adding sentrees under
|
||||
SenTreeFinder m_finder; // Find global sentree's and add them
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstTopScope* nodep) {
|
||||
m_topscopep = nodep;
|
||||
m_finder.main(m_topscopep);
|
||||
m_topscopep = nodep;
|
||||
m_finder.main(m_topscopep);
|
||||
iterateChildren(nodep);
|
||||
m_topscopep = NULL;
|
||||
m_topscopep = NULL;
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
// Create required actives and add to module
|
||||
// We can start ordering at a module, or a scope
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
// Create required actives and add to module
|
||||
// We can start ordering at a module, or a scope
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstActive* nodep) {
|
||||
UINFO(4," ACTIVE "<<nodep<<endl);
|
||||
V3Const::constifyExpensiveEdit(nodep); // Remove duplicate clocks and such; sensesp() may change!
|
||||
AstSenTree* sensesp = nodep->sensesp();
|
||||
if (!sensesp) nodep->v3fatalSrc("NULL");
|
||||
if (sensesp->sensesp()
|
||||
UINFO(4," ACTIVE "<<nodep<<endl);
|
||||
V3Const::constifyExpensiveEdit(nodep); // Remove duplicate clocks and such; sensesp() may change!
|
||||
AstSenTree* sensesp = nodep->sensesp();
|
||||
if (!sensesp) nodep->v3fatalSrc("NULL");
|
||||
if (sensesp->sensesp()
|
||||
&& VN_IS(sensesp->sensesp(), SenItem)
|
||||
&& VN_CAST(sensesp->sensesp(), SenItem)->isNever()) {
|
||||
// Never executing. Kill it.
|
||||
if (sensesp->sensesp()->nextp()) nodep->v3fatalSrc("Never senitem should be alone, else the never should be eliminated.");
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
// Copy combo tree to settlement tree with duplicated statements
|
||||
if (sensesp->hasCombo()) {
|
||||
AstSenTree* newsentreep
|
||||
// Never executing. Kill it.
|
||||
if (sensesp->sensesp()->nextp()) {
|
||||
nodep->v3fatalSrc("Never senitem should be alone, else the never should be eliminated.");
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
// Copy combo tree to settlement tree with duplicated statements
|
||||
if (sensesp->hasCombo()) {
|
||||
AstSenTree* newsentreep
|
||||
= new AstSenTree(nodep->fileline(),
|
||||
new AstSenItem (nodep->fileline(), AstSenItem::Settle()));
|
||||
AstActive* newp = new AstActive(nodep->fileline(),"settle", newsentreep);
|
||||
newp->sensesStorep(newsentreep);
|
||||
if (nodep->stmtsp()) newp->addStmtsp(nodep->stmtsp()->cloneTree(true));
|
||||
nodep->addNextHere(newp);
|
||||
}
|
||||
// Move the SENTREE for each active up to the global level.
|
||||
// This way we'll easily see what clock domains are identical
|
||||
AstSenTree* wantp = m_finder.getSenTree(nodep->fileline(), sensesp);
|
||||
UINFO(4," lookdone\n");
|
||||
if (wantp != sensesp) {
|
||||
// Move the active's contents to the other active
|
||||
UINFO(4," merge active "<<sensesp<<" into "<<wantp<<endl);
|
||||
if (nodep->sensesStorep()) {
|
||||
if (sensesp != nodep->sensesStorep()) nodep->v3fatalSrc("sensesStore should have been deleted earlier if different");
|
||||
sensesp->unlinkFrBack();
|
||||
// There may be other references to same sense tree,
|
||||
// we'll be removing all references when we get to them,
|
||||
// but don't dangle our pointer yet!
|
||||
pushDeletep(sensesp);
|
||||
}
|
||||
nodep->sensesp(wantp);
|
||||
}
|
||||
// No need to do statements under it, they're already moved.
|
||||
new AstSenItem(nodep->fileline(), AstSenItem::Settle()));
|
||||
AstActive* newp = new AstActive(nodep->fileline(),"settle", newsentreep);
|
||||
newp->sensesStorep(newsentreep);
|
||||
if (nodep->stmtsp()) newp->addStmtsp(nodep->stmtsp()->cloneTree(true));
|
||||
nodep->addNextHere(newp);
|
||||
}
|
||||
// Move the SENTREE for each active up to the global level.
|
||||
// This way we'll easily see what clock domains are identical
|
||||
AstSenTree* wantp = m_finder.getSenTree(nodep->fileline(), sensesp);
|
||||
UINFO(4," lookdone\n");
|
||||
if (wantp != sensesp) {
|
||||
// Move the active's contents to the other active
|
||||
UINFO(4," merge active "<<sensesp<<" into "<<wantp<<endl);
|
||||
if (nodep->sensesStorep()) {
|
||||
if (sensesp != nodep->sensesStorep()) {
|
||||
nodep->v3fatalSrc("sensesStore should have been deleted earlier if different");
|
||||
}
|
||||
sensesp->unlinkFrBack();
|
||||
// There may be other references to same sense tree,
|
||||
// we'll be removing all references when we get to them,
|
||||
// but don't dangle our pointer yet!
|
||||
pushDeletep(sensesp);
|
||||
}
|
||||
nodep->sensesp(wantp);
|
||||
}
|
||||
// No need to do statements under it, they're already moved.
|
||||
//iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstInitial* nodep) {
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
}
|
||||
virtual void visit(AstAssignAlias* nodep) {
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
}
|
||||
virtual void visit(AstAssignW* nodep) {
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
}
|
||||
virtual void visit(AstAlways* nodep) {
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
}
|
||||
virtual void visit(AstAlwaysPublic* nodep) {
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
nodep->v3fatalSrc("Node should have been under ACTIVE");
|
||||
}
|
||||
virtual void visit(AstFinal* nodep) {
|
||||
nodep->v3fatalSrc("Node should have been deleted");
|
||||
nodep->v3fatalSrc("Node should have been deleted");
|
||||
}
|
||||
// Empty visitors, speed things up
|
||||
virtual void visit(AstNodeMath* nodep) {}
|
||||
|
|
@ -139,7 +143,7 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit ActiveTopVisitor(AstNetlist* nodep) {
|
||||
m_topscopep = NULL;
|
||||
m_topscopep = NULL;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~ActiveTopVisitor() {}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void activeTopAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
405
src/V3Assert.cpp
405
src/V3Assert.cpp
|
|
@ -37,46 +37,46 @@ class AssertVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE/TYPES
|
||||
// Cleared on netlist
|
||||
// AstNode::user() -> bool. True if processed
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstNode::user() -> bool. True if processed
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Last module
|
||||
AstBegin* m_beginp; // Last begin
|
||||
AstNodeModule* m_modp; // Last module
|
||||
AstBegin* m_beginp; // Last begin
|
||||
unsigned m_modPastNum; // Module past numbering
|
||||
V3Double0 m_statAsCover; // Statistic tracking
|
||||
V3Double0 m_statAsPsl; // Statistic tracking
|
||||
V3Double0 m_statAsFull; // Statistic tracking
|
||||
V3Double0 m_statAsSV; // Statistic tracking
|
||||
V3Double0 m_statAsCover; // Statistic tracking
|
||||
V3Double0 m_statAsPsl; // Statistic tracking
|
||||
V3Double0 m_statAsFull; // Statistic tracking
|
||||
V3Double0 m_statAsSV; // Statistic tracking
|
||||
|
||||
// METHODS
|
||||
string assertDisplayMessage(AstNode* nodep, const string& prefix, const string& message) {
|
||||
return (string("[%0t] "+prefix+": ")+nodep->fileline()->filebasename()
|
||||
+":"+cvtToStr(nodep->fileline()->lineno())
|
||||
+": Assertion failed in %m"
|
||||
+((message != "")?": ":"")+message
|
||||
+"\n");
|
||||
return (string("[%0t] "+prefix+": ")+nodep->fileline()->filebasename()
|
||||
+":"+cvtToStr(nodep->fileline()->lineno())
|
||||
+": Assertion failed in %m"
|
||||
+((message != "")?": ":"")+message
|
||||
+"\n");
|
||||
}
|
||||
void replaceDisplay(AstDisplay* nodep, const string& prefix) {
|
||||
nodep->displayType(AstDisplayType::DT_WRITE);
|
||||
nodep->fmtp()->text(assertDisplayMessage(nodep, prefix, nodep->fmtp()->text()));
|
||||
// cppcheck-suppress nullPointer
|
||||
AstNode* timenewp = new AstTime(nodep->fileline());
|
||||
if (AstNode* timesp = nodep->fmtp()->exprsp()) {
|
||||
timesp->unlinkFrBackWithNext();
|
||||
timenewp->addNext(timesp);
|
||||
}
|
||||
nodep->fmtp()->addExprsp(timenewp);
|
||||
if (!nodep->fmtp()->scopeNamep() && nodep->fmtp()->formatScopeTracking()) {
|
||||
nodep->fmtp()->scopeNamep(new AstScopeName(nodep->fileline()));
|
||||
}
|
||||
nodep->displayType(AstDisplayType::DT_WRITE);
|
||||
nodep->fmtp()->text(assertDisplayMessage(nodep, prefix, nodep->fmtp()->text()));
|
||||
// cppcheck-suppress nullPointer
|
||||
AstNode* timenewp = new AstTime(nodep->fileline());
|
||||
if (AstNode* timesp = nodep->fmtp()->exprsp()) {
|
||||
timesp->unlinkFrBackWithNext();
|
||||
timenewp->addNext(timesp);
|
||||
}
|
||||
nodep->fmtp()->addExprsp(timenewp);
|
||||
if (!nodep->fmtp()->scopeNamep() && nodep->fmtp()->formatScopeTracking()) {
|
||||
nodep->fmtp()->scopeNamep(new AstScopeName(nodep->fileline()));
|
||||
}
|
||||
}
|
||||
|
||||
AstNode* newIfAssertOn(AstNode* nodep) {
|
||||
// Add a internal if to check assertions are on.
|
||||
// Don't make this a AND term, as it's unlikely to need to test this.
|
||||
// Add a internal if to check assertions are on.
|
||||
// Don't make this a AND term, as it's unlikely to need to test this.
|
||||
FileLine* fl = nodep->fileline();
|
||||
AstNode* newp
|
||||
AstNode* newp
|
||||
= new AstIf(fl,
|
||||
// If assertions are off, have constant propagation rip them out later
|
||||
// This allows syntax errors and such to be detected normally.
|
||||
|
|
@ -84,46 +84,47 @@ private:
|
|||
? static_cast<AstNode*>(new AstCMath(fl, "Verilated::assertOn()", 1))
|
||||
: static_cast<AstNode*>(new AstConst(fl, AstConst::LogicFalse()))),
|
||||
nodep, NULL);
|
||||
newp->user1(true); // Don't assert/cover this if
|
||||
return newp;
|
||||
newp->user1(true); // Don't assert/cover this if
|
||||
return newp;
|
||||
}
|
||||
|
||||
AstNode* newFireAssertUnchecked(AstNode* nodep, const string& message) {
|
||||
// Like newFireAssert() but omits the asserts-on check
|
||||
AstDisplay* dispp = new AstDisplay(nodep->fileline(), AstDisplayType::DT_ERROR, message, NULL, NULL);
|
||||
AstNode* bodysp = dispp;
|
||||
replaceDisplay(dispp, "%%Error"); // Convert to standard DISPLAY format
|
||||
AstDisplay* dispp = new AstDisplay(nodep->fileline(),
|
||||
AstDisplayType::DT_ERROR, message, NULL, NULL);
|
||||
AstNode* bodysp = dispp;
|
||||
replaceDisplay(dispp, "%%Error"); // Convert to standard DISPLAY format
|
||||
bodysp->addNext(new AstStop(nodep->fileline()));
|
||||
return bodysp;
|
||||
}
|
||||
|
||||
AstNode* newFireAssert(AstNode* nodep, const string& message) {
|
||||
AstNode* bodysp = newFireAssertUnchecked(nodep, message);
|
||||
bodysp = newIfAssertOn(bodysp);
|
||||
return bodysp;
|
||||
bodysp = newIfAssertOn(bodysp);
|
||||
return bodysp;
|
||||
}
|
||||
|
||||
void newPslAssertion(AstNode* nodep, AstNode* propp, AstSenTree* sentreep,
|
||||
AstNode* stmtsp, const string& message) {
|
||||
propp->unlinkFrBack();
|
||||
sentreep->unlinkFrBack();
|
||||
if (stmtsp) stmtsp->unlinkFrBack();
|
||||
//
|
||||
AstNode* bodysp = NULL;
|
||||
bool selfDestruct = false;
|
||||
AstNode* stmtsp, const string& message) {
|
||||
propp->unlinkFrBack();
|
||||
sentreep->unlinkFrBack();
|
||||
if (stmtsp) stmtsp->unlinkFrBack();
|
||||
//
|
||||
AstNode* bodysp = NULL;
|
||||
bool selfDestruct = false;
|
||||
AstIf* ifp = NULL;
|
||||
if (AstPslCover* snodep = VN_CAST(nodep, PslCover)) {
|
||||
++m_statAsCover;
|
||||
if (!v3Global.opt.coverageUser()) {
|
||||
selfDestruct = true;
|
||||
} else {
|
||||
// V3Coverage assigned us a bucket to increment.
|
||||
if (!v3Global.opt.coverageUser()) {
|
||||
selfDestruct = true;
|
||||
} else {
|
||||
// V3Coverage assigned us a bucket to increment.
|
||||
AstCoverInc* covincp = VN_CAST(snodep->coverincp(), CoverInc);
|
||||
if (!covincp) snodep->v3fatalSrc("Missing AstCoverInc under assertion");
|
||||
covincp->unlinkFrBack();
|
||||
if (message!="") covincp->declp()->comment(message);
|
||||
bodysp = covincp;
|
||||
}
|
||||
if (!covincp) snodep->v3fatalSrc("Missing AstCoverInc under assertion");
|
||||
covincp->unlinkFrBack();
|
||||
if (message!="") covincp->declp()->comment(message);
|
||||
bodysp = covincp;
|
||||
}
|
||||
|
||||
if (bodysp && stmtsp) bodysp = bodysp->addNext(stmtsp);
|
||||
ifp = new AstIf(nodep->fileline(), propp, bodysp, NULL);
|
||||
|
|
@ -148,163 +149,167 @@ private:
|
|||
// IEEE says simulator ignores these
|
||||
pushDeletep(nodep->unlinkFrBack()); VL_DANGLING(nodep);
|
||||
return;
|
||||
} else {
|
||||
nodep->v3fatalSrc("Unknown node type");
|
||||
}
|
||||
} else {
|
||||
nodep->v3fatalSrc("Unknown node type");
|
||||
}
|
||||
|
||||
AstNode* newp = new AstAlways(nodep->fileline(),
|
||||
VAlwaysKwd::ALWAYS, sentreep, bodysp);
|
||||
// Install it
|
||||
if (selfDestruct) {
|
||||
// Delete it after making the tree. This way we can tell the user
|
||||
// if it wasn't constructed nicely or has other errors without needing --coverage.
|
||||
newp->deleteTree();
|
||||
nodep->unlinkFrBack();
|
||||
} else {
|
||||
nodep->replaceWith(newp);
|
||||
}
|
||||
// Bye
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
// Install it
|
||||
if (selfDestruct) {
|
||||
// Delete it after making the tree. This way we can tell the user
|
||||
// if it wasn't constructed nicely or has other errors without needing --coverage.
|
||||
newp->deleteTree();
|
||||
nodep->unlinkFrBack();
|
||||
} else {
|
||||
nodep->replaceWith(newp);
|
||||
}
|
||||
// Bye
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
|
||||
void newVAssertion(AstVAssert* nodep, AstNode* propp) {
|
||||
propp->unlinkFrBackWithNext();
|
||||
AstNode* passsp = nodep->passsp(); if (passsp) passsp->unlinkFrBackWithNext();
|
||||
AstNode* failsp = nodep->failsp(); if (failsp) failsp->unlinkFrBackWithNext();
|
||||
//
|
||||
propp->unlinkFrBackWithNext();
|
||||
AstNode* passsp = nodep->passsp(); if (passsp) passsp->unlinkFrBackWithNext();
|
||||
AstNode* failsp = nodep->failsp(); if (failsp) failsp->unlinkFrBackWithNext();
|
||||
//
|
||||
if (VN_IS(nodep, VAssert)) {
|
||||
if (passsp) passsp = newIfAssertOn(passsp);
|
||||
if (failsp) failsp = newIfAssertOn(failsp);
|
||||
} else {
|
||||
nodep->v3fatalSrc("Unknown node type");
|
||||
}
|
||||
if (passsp) passsp = newIfAssertOn(passsp);
|
||||
if (failsp) failsp = newIfAssertOn(failsp);
|
||||
} else {
|
||||
nodep->v3fatalSrc("Unknown node type");
|
||||
}
|
||||
|
||||
AstIf* ifp = new AstIf(nodep->fileline(), propp, passsp, failsp);
|
||||
AstNode* newp = ifp;
|
||||
AstNode* newp = ifp;
|
||||
if (VN_IS(nodep, VAssert)) ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
//
|
||||
// Install it
|
||||
nodep->replaceWith(newp);
|
||||
// Bye
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
//
|
||||
// Install it
|
||||
nodep->replaceWith(newp);
|
||||
// Bye
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstIf* nodep) {
|
||||
if (nodep->user1SetOnce()) return;
|
||||
if (nodep->uniquePragma() || nodep->unique0Pragma()) {
|
||||
AstNodeIf* ifp = nodep;
|
||||
AstNode* propp = NULL;
|
||||
bool hasDefaultElse = false;
|
||||
do {
|
||||
// If this statement ends with 'else if', then nextIf will point to the
|
||||
// nextIf statement. Otherwise it will be null.
|
||||
AstNodeIf* nextifp = dynamic_cast<AstNodeIf*>(ifp->elsesp());
|
||||
if (nodep->user1SetOnce()) return;
|
||||
if (nodep->uniquePragma() || nodep->unique0Pragma()) {
|
||||
AstNodeIf* ifp = nodep;
|
||||
AstNode* propp = NULL;
|
||||
bool hasDefaultElse = false;
|
||||
do {
|
||||
// If this statement ends with 'else if', then nextIf will point to the
|
||||
// nextIf statement. Otherwise it will be null.
|
||||
AstNodeIf* nextifp = dynamic_cast<AstNodeIf*>(ifp->elsesp());
|
||||
iterateAndNextNull(ifp->condp());
|
||||
|
||||
// Recurse into the true case.
|
||||
// Recurse into the true case.
|
||||
iterateAndNextNull(ifp->ifsp());
|
||||
|
||||
// If the last else is not an else if, recurse into that too.
|
||||
if (ifp->elsesp() && !nextifp) {
|
||||
// If the last else is not an else if, recurse into that too.
|
||||
if (ifp->elsesp() && !nextifp) {
|
||||
iterateAndNextNull(ifp->elsesp());
|
||||
}
|
||||
}
|
||||
|
||||
// Build a bitmask of the true predicates
|
||||
AstNode* predp = ifp->condp()->cloneTree(false);
|
||||
if (propp) {
|
||||
propp = new AstConcat(nodep->fileline(), predp, propp);
|
||||
} else {
|
||||
propp = predp;
|
||||
}
|
||||
// Build a bitmask of the true predicates
|
||||
AstNode* predp = ifp->condp()->cloneTree(false);
|
||||
if (propp) {
|
||||
propp = new AstConcat(nodep->fileline(), predp, propp);
|
||||
} else {
|
||||
propp = predp;
|
||||
}
|
||||
|
||||
// Record if this ends with an 'else' that does not have an if
|
||||
if (ifp->elsesp() && !nextifp) {
|
||||
hasDefaultElse = true;
|
||||
}
|
||||
// Record if this ends with an 'else' that does not have an if
|
||||
if (ifp->elsesp() && !nextifp) {
|
||||
hasDefaultElse = true;
|
||||
}
|
||||
|
||||
ifp = nextifp;
|
||||
} while (ifp);
|
||||
ifp = nextifp;
|
||||
} while (ifp);
|
||||
|
||||
AstNode *newifp = nodep->cloneTree(false);
|
||||
bool allow_none = nodep->unique0Pragma();
|
||||
AstNode *newifp = nodep->cloneTree(false);
|
||||
bool allow_none = nodep->unique0Pragma();
|
||||
|
||||
// Empty case means no property
|
||||
if (!propp) propp = new AstConst(nodep->fileline(), AstConst::LogicFalse());
|
||||
// Empty case means no property
|
||||
if (!propp) propp = new AstConst(nodep->fileline(), AstConst::LogicFalse());
|
||||
|
||||
// Note: if this ends with an 'else', then we don't need to validate that one of the
|
||||
// predicates evaluates to true.
|
||||
AstNode* ohot = ((allow_none || hasDefaultElse)
|
||||
? static_cast<AstNode*>(new AstOneHot0(nodep->fileline(), propp))
|
||||
: static_cast<AstNode*>(new AstOneHot (nodep->fileline(), propp)));
|
||||
// Note: if this ends with an 'else', then we don't need to validate that one of the
|
||||
// predicates evaluates to true.
|
||||
AstNode* ohot = ((allow_none || hasDefaultElse)
|
||||
? static_cast<AstNode*>(new AstOneHot0(nodep->fileline(), propp))
|
||||
: static_cast<AstNode*>(new AstOneHot(nodep->fileline(), propp)));
|
||||
AstIf* checkifp = new AstIf(nodep->fileline(),
|
||||
new AstLogNot(nodep->fileline(), ohot),
|
||||
newFireAssert(nodep, "'unique if' statement violated"),
|
||||
newifp);
|
||||
checkifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
nodep->replaceWith(checkifp);
|
||||
pushDeletep(nodep);
|
||||
} else {
|
||||
checkifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
nodep->replaceWith(checkifp);
|
||||
pushDeletep(nodep);
|
||||
} else {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//========== Case assertions
|
||||
virtual void visit(AstCase* nodep) {
|
||||
iterateChildren(nodep);
|
||||
if (!nodep->user1SetOnce()) {
|
||||
bool has_default=false;
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
if (itemp->isDefault()) has_default=true;
|
||||
}
|
||||
if (nodep->fullPragma() || nodep->priorityPragma()) {
|
||||
// Simply need to add a default if there isn't one already
|
||||
++m_statAsFull;
|
||||
if (!has_default) {
|
||||
nodep->addItemsp(new AstCaseItem(nodep->fileline(), NULL/*DEFAULT*/,
|
||||
newFireAssert(nodep, "synthesis full_case, but non-match found")));
|
||||
}
|
||||
}
|
||||
if (nodep->parallelPragma() || nodep->uniquePragma() || nodep->unique0Pragma()) {
|
||||
// Need to check that one, and only one of the case items match at any moment
|
||||
// If there's a default, we allow none to match, else exactly one must match
|
||||
++m_statAsFull;
|
||||
if (!has_default && !nodep->itemsp()) {
|
||||
// Not parallel, but harmlessly so.
|
||||
} else {
|
||||
AstNode* propp = NULL;
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondp->nextp()) {
|
||||
AstNode* onep;
|
||||
if (nodep->casex() || nodep->casez() || nodep->caseInside()) {
|
||||
onep = AstEqWild::newTyped(itemp->fileline(),
|
||||
nodep->exprp()->cloneTree(false),
|
||||
icondp->cloneTree(false));
|
||||
} else {
|
||||
onep = AstEq::newTyped(icondp->fileline(),
|
||||
nodep->exprp()->cloneTree(false),
|
||||
icondp->cloneTree(false));
|
||||
}
|
||||
if (propp) propp = new AstConcat(icondp->fileline(), onep, propp);
|
||||
else propp = onep;
|
||||
}
|
||||
}
|
||||
// Empty case means no property
|
||||
if (!propp) propp = new AstConst(nodep->fileline(), AstConst::LogicFalse());
|
||||
if (!nodep->user1SetOnce()) {
|
||||
bool has_default = false;
|
||||
for (AstCaseItem* itemp = nodep->itemsp();
|
||||
itemp; itemp = VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
if (itemp->isDefault()) has_default = true;
|
||||
}
|
||||
if (nodep->fullPragma() || nodep->priorityPragma()) {
|
||||
// Simply need to add a default if there isn't one already
|
||||
++m_statAsFull;
|
||||
if (!has_default) {
|
||||
nodep->addItemsp(new AstCaseItem(nodep->fileline(), NULL/*DEFAULT*/,
|
||||
newFireAssert(nodep, "synthesis full_case, but non-match found")));
|
||||
}
|
||||
}
|
||||
if (nodep->parallelPragma() || nodep->uniquePragma() || nodep->unique0Pragma()) {
|
||||
// Need to check that one, and only one of the case items match at any moment
|
||||
// If there's a default, we allow none to match, else exactly one must match
|
||||
++m_statAsFull;
|
||||
if (!has_default && !nodep->itemsp()) {
|
||||
// Not parallel, but harmlessly so.
|
||||
} else {
|
||||
AstNode* propp = NULL;
|
||||
for (AstCaseItem* itemp = nodep->itemsp();
|
||||
itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
for (AstNode* icondp = itemp->condsp();
|
||||
icondp!=NULL; icondp=icondp->nextp()) {
|
||||
AstNode* onep;
|
||||
if (nodep->casex() || nodep->casez() || nodep->caseInside()) {
|
||||
onep = AstEqWild::newTyped(itemp->fileline(),
|
||||
nodep->exprp()->cloneTree(false),
|
||||
icondp->cloneTree(false));
|
||||
} else {
|
||||
onep = AstEq::newTyped(icondp->fileline(),
|
||||
nodep->exprp()->cloneTree(false),
|
||||
icondp->cloneTree(false));
|
||||
}
|
||||
if (propp) propp = new AstConcat(icondp->fileline(), onep, propp);
|
||||
else propp = onep;
|
||||
}
|
||||
}
|
||||
// Empty case means no property
|
||||
if (!propp) propp = new AstConst(nodep->fileline(), AstConst::LogicFalse());
|
||||
|
||||
bool allow_none = has_default || nodep->unique0Pragma();
|
||||
AstNode* ohot = (allow_none
|
||||
? static_cast<AstNode*>(new AstOneHot0(nodep->fileline(), propp))
|
||||
: static_cast<AstNode*>(new AstOneHot (nodep->fileline(), propp)));
|
||||
bool allow_none = has_default || nodep->unique0Pragma();
|
||||
AstNode* ohot
|
||||
= (allow_none
|
||||
? static_cast<AstNode*>(new AstOneHot0(nodep->fileline(), propp))
|
||||
: static_cast<AstNode*>(new AstOneHot(nodep->fileline(), propp)));
|
||||
AstIf* ifp = new AstIf(nodep->fileline(),
|
||||
new AstLogNot(nodep->fileline(), ohot),
|
||||
newFireAssert(nodep, "synthesis parallel_case, but multiple matches found"),
|
||||
NULL);
|
||||
ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
nodep->addNotParallelp(ifp);
|
||||
}
|
||||
}
|
||||
}
|
||||
ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
nodep->addNotParallelp(ifp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//========== Past
|
||||
|
|
@ -341,46 +346,46 @@ private:
|
|||
//========== Statements
|
||||
virtual void visit(AstDisplay* nodep) {
|
||||
iterateChildren(nodep);
|
||||
// Replace the special types with standard text
|
||||
if (nodep->displayType()==AstDisplayType::DT_INFO) {
|
||||
replaceDisplay(nodep, "-Info");
|
||||
} else if (nodep->displayType()==AstDisplayType::DT_WARNING) {
|
||||
replaceDisplay(nodep, "%%Warning");
|
||||
} else if (nodep->displayType()==AstDisplayType::DT_ERROR
|
||||
|| nodep->displayType()==AstDisplayType::DT_FATAL) {
|
||||
replaceDisplay(nodep, "%%Error");
|
||||
}
|
||||
// Replace the special types with standard text
|
||||
if (nodep->displayType()==AstDisplayType::DT_INFO) {
|
||||
replaceDisplay(nodep, "-Info");
|
||||
} else if (nodep->displayType()==AstDisplayType::DT_WARNING) {
|
||||
replaceDisplay(nodep, "%%Warning");
|
||||
} else if (nodep->displayType()==AstDisplayType::DT_ERROR
|
||||
|| nodep->displayType()==AstDisplayType::DT_FATAL) {
|
||||
replaceDisplay(nodep, "%%Error");
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(AstNodePslCoverOrAssert* nodep) {
|
||||
iterateChildren(nodep);
|
||||
if (m_beginp && nodep->name() == "") nodep->name(m_beginp->name());
|
||||
newPslAssertion(nodep, nodep->propp(), nodep->sentreep(),
|
||||
nodep->stmtsp(), nodep->name()); VL_DANGLING(nodep);
|
||||
if (m_beginp && nodep->name() == "") nodep->name(m_beginp->name());
|
||||
newPslAssertion(nodep, nodep->propp(), nodep->sentreep(),
|
||||
nodep->stmtsp(), nodep->name()); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstVAssert* nodep) {
|
||||
iterateChildren(nodep);
|
||||
newVAssertion(nodep, nodep->propp()); VL_DANGLING(nodep);
|
||||
++m_statAsSV;
|
||||
newVAssertion(nodep, nodep->propp()); VL_DANGLING(nodep);
|
||||
++m_statAsSV;
|
||||
}
|
||||
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
m_modp = nodep;
|
||||
m_modPastNum = 0;
|
||||
//
|
||||
//
|
||||
iterateChildren(nodep);
|
||||
// Reset defaults
|
||||
m_modp = NULL;
|
||||
// Reset defaults
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstBegin* nodep) {
|
||||
// This code is needed rather than a visitor in V3Begin,
|
||||
// because V3Assert is called before V3Begin
|
||||
AstBegin* lastp = m_beginp;
|
||||
{
|
||||
m_beginp = nodep;
|
||||
// This code is needed rather than a visitor in V3Begin,
|
||||
// because V3Assert is called before V3Begin
|
||||
AstBegin* lastp = m_beginp;
|
||||
{
|
||||
m_beginp = nodep;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
m_beginp = lastp;
|
||||
}
|
||||
m_beginp = lastp;
|
||||
}
|
||||
|
||||
virtual void visit(AstNode* nodep) {
|
||||
|
|
@ -389,17 +394,17 @@ private:
|
|||
public:
|
||||
// CONSTRUCTORS
|
||||
explicit AssertVisitor(AstNetlist* nodep) {
|
||||
m_beginp = NULL;
|
||||
m_modp = NULL;
|
||||
m_beginp = NULL;
|
||||
m_modp = NULL;
|
||||
m_modPastNum = 0;
|
||||
// Process
|
||||
// Process
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~AssertVisitor() {
|
||||
V3Stats::addStat("Assertions, PSL asserts", m_statAsPsl);
|
||||
V3Stats::addStat("Assertions, SystemVerilog asserts", m_statAsSV);
|
||||
V3Stats::addStat("Assertions, cover statements", m_statAsCover);
|
||||
V3Stats::addStat("Assertions, full/parallel case", m_statAsFull);
|
||||
V3Stats::addStat("Assertions, PSL asserts", m_statAsPsl);
|
||||
V3Stats::addStat("Assertions, SystemVerilog asserts", m_statAsSV);
|
||||
V3Stats::addStat("Assertions, cover statements", m_statAsCover);
|
||||
V3Stats::addStat("Assertions, full/parallel case", m_statAsFull);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void assertAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// Pre steps:
|
||||
// Attach clocks to each assertion
|
||||
// Attach clocks to each assertion
|
||||
//*************************************************************************
|
||||
|
||||
#include "config_build.h"
|
||||
|
|
@ -51,37 +51,37 @@ private:
|
|||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
AstSenTree* newSenTree(AstNode* nodep) {
|
||||
// Create sentree based on clocked or default clock
|
||||
// Return NULL for always
|
||||
AstSenTree* newp = NULL;
|
||||
// Create sentree based on clocked or default clock
|
||||
// Return NULL for always
|
||||
AstSenTree* newp = NULL;
|
||||
AstNodeSenItem* senip = m_senip;
|
||||
if (!senip) senip = m_seniDefaultp;
|
||||
if (!senip) senip = m_seniAlwaysp;
|
||||
if (!senip) {
|
||||
nodep->v3error("Unsupported: Unclocked assertion");
|
||||
newp = new AstSenTree(nodep->fileline(), NULL);
|
||||
} else {
|
||||
newp = new AstSenTree(nodep->fileline(), senip->cloneTree(true));
|
||||
}
|
||||
return newp;
|
||||
if (!senip) {
|
||||
nodep->v3error("Unsupported: Unclocked assertion");
|
||||
newp = new AstSenTree(nodep->fileline(), NULL);
|
||||
} else {
|
||||
newp = new AstSenTree(nodep->fileline(), senip->cloneTree(true));
|
||||
}
|
||||
return newp;
|
||||
}
|
||||
void clearAssertInfo() {
|
||||
m_senip = NULL;
|
||||
m_senip = NULL;
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
//========== Statements
|
||||
virtual void visit(AstClocking* nodep) {
|
||||
UINFO(8," CLOCKING"<<nodep<<endl);
|
||||
// Store the new default clock, reset on new module
|
||||
m_seniDefaultp = nodep->sensesp();
|
||||
// Trash it, keeping children
|
||||
if (nodep->bodysp()) {
|
||||
nodep->replaceWith(nodep->bodysp()->unlinkFrBack());
|
||||
} else {
|
||||
nodep->unlinkFrBack();
|
||||
}
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
UINFO(8," CLOCKING"<<nodep<<endl);
|
||||
// Store the new default clock, reset on new module
|
||||
m_seniDefaultp = nodep->sensesp();
|
||||
// Trash it, keeping children
|
||||
if (nodep->bodysp()) {
|
||||
nodep->replaceWith(nodep->bodysp()->unlinkFrBack());
|
||||
} else {
|
||||
nodep->unlinkFrBack();
|
||||
}
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstAlways* nodep) {
|
||||
iterateAndNextNull(nodep->sensesp());
|
||||
|
|
@ -93,12 +93,12 @@ private:
|
|||
}
|
||||
|
||||
virtual void visit(AstNodePslCoverOrAssert* nodep) {
|
||||
if (nodep->sentreep()) return; // Already processed
|
||||
clearAssertInfo();
|
||||
if (nodep->sentreep()) return; // Already processed
|
||||
clearAssertInfo();
|
||||
// Find PslClocking's burried under nodep->exprsp
|
||||
iterateChildren(nodep);
|
||||
nodep->sentreep(newSenTree(nodep));
|
||||
clearAssertInfo();
|
||||
nodep->sentreep(newSenTree(nodep));
|
||||
clearAssertInfo();
|
||||
}
|
||||
virtual void visit(AstPast* nodep) {
|
||||
if (nodep->sentreep()) return; // Already processed
|
||||
|
|
@ -108,26 +108,26 @@ private:
|
|||
virtual void visit(AstPslClocked* nodep) {
|
||||
// No need to iterate the body, once replace will get iterated
|
||||
iterateAndNextNull(nodep->sensesp());
|
||||
if (m_senip) {
|
||||
nodep->v3error("Unsupported: Only one PSL clock allowed per assertion");
|
||||
}
|
||||
// Block is the new expression to evaluate
|
||||
AstNode* blockp = nodep->propp()->unlinkFrBack();
|
||||
if (nodep->disablep()) {
|
||||
blockp = new AstAnd(nodep->disablep()->fileline(),
|
||||
new AstNot(nodep->disablep()->fileline(),
|
||||
nodep->disablep()->unlinkFrBack()),
|
||||
blockp);
|
||||
}
|
||||
// Unlink and just keep a pointer to it, convert to sentree as needed
|
||||
m_senip = nodep->sensesp();
|
||||
nodep->replaceWith(blockp);
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
if (m_senip) {
|
||||
nodep->v3error("Unsupported: Only one PSL clock allowed per assertion");
|
||||
}
|
||||
// Block is the new expression to evaluate
|
||||
AstNode* blockp = nodep->propp()->unlinkFrBack();
|
||||
if (nodep->disablep()) {
|
||||
blockp = new AstAnd(nodep->disablep()->fileline(),
|
||||
new AstNot(nodep->disablep()->fileline(),
|
||||
nodep->disablep()->unlinkFrBack()),
|
||||
blockp);
|
||||
}
|
||||
// Unlink and just keep a pointer to it, convert to sentree as needed
|
||||
m_senip = nodep->sensesp();
|
||||
nodep->replaceWith(blockp);
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
iterateChildren(nodep);
|
||||
// Reset defaults
|
||||
m_seniDefaultp = NULL;
|
||||
// Reset defaults
|
||||
m_seniDefaultp = NULL;
|
||||
}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
|
|
@ -136,10 +136,10 @@ private:
|
|||
public:
|
||||
// CONSTRUCTORS
|
||||
explicit AssertPreVisitor(AstNetlist* nodep) {
|
||||
m_seniDefaultp = NULL;
|
||||
m_seniDefaultp = NULL;
|
||||
m_seniAlwaysp = NULL;
|
||||
clearAssertInfo();
|
||||
// Process
|
||||
clearAssertInfo();
|
||||
// Process
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~AssertPreVisitor() {}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void assertPreAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
743
src/V3Ast.cpp
743
src/V3Ast.cpp
File diff suppressed because it is too large
Load Diff
1853
src/V3Ast.h
1853
src/V3Ast.h
File diff suppressed because it is too large
Load Diff
|
|
@ -30,4 +30,4 @@
|
|||
#define deleteTree error_no_deleteTree_in_ConstOnlyVisitor
|
||||
#define unlinkFrBack error_no_unlinkFrBack_in_ConstOnlyVisitor
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ void AstNodeVarRef::cloneRelink() {
|
|||
}
|
||||
|
||||
int AstNodeSel::bitConst() const {
|
||||
AstConst* constp=VN_CAST(bitp(), Const);
|
||||
AstConst* constp = VN_CAST(bitp(), Const);
|
||||
return (constp ? constp->toSInt() : 0);
|
||||
}
|
||||
|
||||
|
|
@ -66,20 +66,20 @@ void AstNodeClassDType::repairMemberCache() {
|
|||
for (AstMemberDType* itemp = membersp(); itemp; itemp=VN_CAST(itemp->nextp(), MemberDType)) {
|
||||
if (m_members.find(itemp->name())!=m_members.end()) {
|
||||
itemp->v3error("Duplicate declaration of member name: "<<itemp->prettyName()); }
|
||||
else m_members.insert(make_pair(itemp->name(), itemp));
|
||||
else m_members.insert(make_pair(itemp->name(), itemp));
|
||||
}
|
||||
}
|
||||
|
||||
const char* AstNodeClassDType::broken() const {
|
||||
vl_unordered_set<AstMemberDType*> exists;
|
||||
for (AstMemberDType* itemp = membersp(); itemp; itemp=VN_CAST(itemp->nextp(), MemberDType)) {
|
||||
exists.insert(itemp);
|
||||
exists.insert(itemp);
|
||||
}
|
||||
for (MemberNameMap::const_iterator it=m_members.begin(); it!=m_members.end(); ++it) {
|
||||
if (VL_UNLIKELY(exists.find(it->second) == exists.end())) {
|
||||
this->v3error("Internal: Structure member broken: "<<it->first);
|
||||
return "member broken";
|
||||
}
|
||||
if (VL_UNLIKELY(exists.find(it->second) == exists.end())) {
|
||||
this->v3error("Internal: Structure member broken: "<<it->first);
|
||||
return "member broken";
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -121,37 +121,37 @@ int AstNodeClassDType::widthAlignBytes() const {
|
|||
|
||||
AstNodeBiop* AstEq::newTyped(FileLine* fl, AstNode* lhsp, AstNode* rhsp) {
|
||||
if (lhsp->isDouble() && rhsp->isDouble()) {
|
||||
return new AstEqD(fl, lhsp, rhsp);
|
||||
return new AstEqD(fl, lhsp, rhsp);
|
||||
} else {
|
||||
return new AstEq(fl, lhsp, rhsp);
|
||||
return new AstEq(fl, lhsp, rhsp);
|
||||
}
|
||||
}
|
||||
|
||||
AstNodeBiop* AstGte::newTyped(FileLine* fl, AstNode* lhsp, AstNode* rhsp) {
|
||||
if (lhsp->isDouble() && rhsp->isDouble()) {
|
||||
return new AstGteD(fl, lhsp, rhsp);
|
||||
return new AstGteD(fl, lhsp, rhsp);
|
||||
} else if (lhsp->isSigned() && rhsp->isSigned()) {
|
||||
return new AstGteS(fl, lhsp, rhsp);
|
||||
return new AstGteS(fl, lhsp, rhsp);
|
||||
} else {
|
||||
return new AstGte(fl, lhsp, rhsp);
|
||||
return new AstGte(fl, lhsp, rhsp);
|
||||
}
|
||||
}
|
||||
|
||||
AstNodeBiop* AstLte::newTyped(FileLine* fl, AstNode* lhsp, AstNode* rhsp) {
|
||||
if (lhsp->isDouble() && rhsp->isDouble()) {
|
||||
return new AstLteD(fl, lhsp, rhsp);
|
||||
return new AstLteD(fl, lhsp, rhsp);
|
||||
} else if (lhsp->isSigned() && rhsp->isSigned()) {
|
||||
return new AstLteS(fl, lhsp, rhsp);
|
||||
return new AstLteS(fl, lhsp, rhsp);
|
||||
} else {
|
||||
return new AstLte(fl, lhsp, rhsp);
|
||||
return new AstLte(fl, lhsp, rhsp);
|
||||
}
|
||||
}
|
||||
|
||||
AstNodeBiop* AstEqWild::newTyped(FileLine* fl, AstNode* lhsp, AstNode* rhsp) {
|
||||
if (lhsp->isDouble() && rhsp->isDouble()) {
|
||||
return new AstEqD(fl, lhsp, rhsp);
|
||||
return new AstEqD(fl, lhsp, rhsp);
|
||||
} else {
|
||||
return new AstEqWild(fl, lhsp, rhsp);
|
||||
return new AstEqWild(fl, lhsp, rhsp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -173,10 +173,12 @@ bool AstVar::isScBv() const {
|
|||
return ((isSc() && width() >= v3Global.opt.pinsBv()) || m_attrScBv);
|
||||
}
|
||||
bool AstVar::isScUint() const {
|
||||
return ((isSc() && v3Global.opt.pinsScUint() && width() >= 2 && width() <= 64) && !isScBv());
|
||||
return ((isSc() && v3Global.opt.pinsScUint()
|
||||
&& width() >= 2 && width() <= 64) && !isScBv());
|
||||
}
|
||||
bool AstVar::isScBigUint() const {
|
||||
return ((isSc() && v3Global.opt.pinsScBigUint() && width() >= 65 && width() <= 512) && !isScBv());
|
||||
return ((isSc() && v3Global.opt.pinsScBigUint()
|
||||
&& width() >= 65 && width() <= 512) && !isScBv());
|
||||
}
|
||||
|
||||
void AstVar::combineType(AstVarType type) {
|
||||
|
|
@ -213,7 +215,7 @@ string AstVar::verilogKwd() const {
|
|||
}
|
||||
|
||||
string AstVar::vlArgType(bool named, bool forReturn, bool forFunc) const {
|
||||
if (forReturn) named=false;
|
||||
if (forReturn) named = false;
|
||||
if (forReturn) v3fatalSrc("verilator internal data is never passed as return, but as first argument");
|
||||
string otype;
|
||||
AstBasicDType* bdtypep = basicp();
|
||||
|
|
@ -284,21 +286,21 @@ string AstVar::vlEnumType() const {
|
|||
AstBasicDType* bdtypep = basicp();
|
||||
bool strtype = bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::STRING;
|
||||
if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::CHARPTR) {
|
||||
return "VLVT_PTR";
|
||||
return "VLVT_PTR";
|
||||
} else if (bdtypep && bdtypep->keyword()==AstBasicDTypeKwd::SCOPEPTR) {
|
||||
return "VLVT_PTR";
|
||||
return "VLVT_PTR";
|
||||
} else if (strtype) {
|
||||
arg += "VLVT_STRING";
|
||||
arg += "VLVT_STRING";
|
||||
} else if (widthMin() <= 8) {
|
||||
arg += "VLVT_UINT8";
|
||||
arg += "VLVT_UINT8";
|
||||
} else if (widthMin() <= 16) {
|
||||
arg += "VLVT_UINT16";
|
||||
arg += "VLVT_UINT16";
|
||||
} else if (widthMin() <= VL_WORDSIZE) {
|
||||
arg += "VLVT_UINT32";
|
||||
arg += "VLVT_UINT32";
|
||||
} else if (isQuad()) {
|
||||
arg += "VLVT_UINT64";
|
||||
arg += "VLVT_UINT64";
|
||||
} else if (isWide()) {
|
||||
arg += "VLVT_WDATA";
|
||||
arg += "VLVT_WDATA";
|
||||
}
|
||||
// else return "VLVT_UNKNOWN"
|
||||
return arg;
|
||||
|
|
@ -344,28 +346,28 @@ string AstVar::vlPropInit() const {
|
|||
out += ", "+cvtToStr(adtypep->declRange().left())+", "+cvtToStr(adtypep->declRange().right());
|
||||
dtp = adtypep->subDTypep();
|
||||
}
|
||||
else break; // AstBasicDType - nothing below
|
||||
else break; // AstBasicDType - nothing below
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
string AstVar::cPubArgType(bool named, bool forReturn) const {
|
||||
if (forReturn) named=false;
|
||||
if (forReturn) named = false;
|
||||
string arg;
|
||||
if (isWide() && isReadOnly()) arg += "const ";
|
||||
if (widthMin() == 1) {
|
||||
arg += "bool";
|
||||
arg += "bool";
|
||||
} else if (widthMin() <= VL_WORDSIZE) {
|
||||
arg += "uint32_t";
|
||||
arg += "uint32_t";
|
||||
} else if (isWide()) {
|
||||
arg += "uint32_t"; // []'s added later
|
||||
arg += "uint32_t"; // []'s added later
|
||||
} else {
|
||||
arg += "vluint64_t";
|
||||
arg += "vluint64_t";
|
||||
}
|
||||
if (isWide()) {
|
||||
if (forReturn) v3error("Unsupported: Public functions with >64 bit outputs; make an output of a public task instead");
|
||||
arg += " (& "+name();
|
||||
arg += ")["+cvtToStr(widthWords())+"]";
|
||||
if (forReturn) v3error("Unsupported: Public functions with >64 bit outputs; make an output of a public task instead");
|
||||
arg += " (& "+name();
|
||||
arg += ")["+cvtToStr(widthWords())+"]";
|
||||
} else {
|
||||
if (!forReturn && (isWritable()
|
||||
|| direction().isRefOrConstRef())) arg += "&";
|
||||
|
|
@ -375,25 +377,25 @@ string AstVar::cPubArgType(bool named, bool forReturn) const {
|
|||
}
|
||||
|
||||
string AstVar::dpiArgType(bool named, bool forReturn) const {
|
||||
if (forReturn) named=false;
|
||||
if (forReturn) named = false;
|
||||
string arg;
|
||||
if (isDpiOpenArray()) {
|
||||
arg = "const svOpenArrayHandle";
|
||||
} else if (!basicp()) {
|
||||
arg = "UNKNOWN";
|
||||
} else if (basicp()->keyword().isDpiBitVal()) {
|
||||
if (widthMin() == 1) {
|
||||
arg = "unsigned char";
|
||||
if (widthMin() == 1) {
|
||||
arg = "unsigned char";
|
||||
if (!forReturn && isWritable()) arg += "*";
|
||||
} else {
|
||||
if (forReturn) {
|
||||
arg = "svBitVecVal";
|
||||
} else if (isReadOnly()) {
|
||||
arg = "const svBitVecVal*";
|
||||
} else {
|
||||
arg = "svBitVecVal*";
|
||||
}
|
||||
}
|
||||
arg = "const svBitVecVal*";
|
||||
} else {
|
||||
arg = "svBitVecVal*";
|
||||
}
|
||||
}
|
||||
} else if (basicp()->keyword().isDpiLogicVal()) {
|
||||
if (widthMin() == 1) {
|
||||
arg = "unsigned char";
|
||||
|
|
@ -408,9 +410,9 @@ string AstVar::dpiArgType(bool named, bool forReturn) const {
|
|||
}
|
||||
}
|
||||
} else {
|
||||
arg = basicp()->keyword().dpiType();
|
||||
if (basicp()->keyword().isDpiUnsignable() && !basicp()->isSigned()) {
|
||||
arg = "unsigned "+arg;
|
||||
arg = basicp()->keyword().dpiType();
|
||||
if (basicp()->keyword().isDpiUnsignable() && !basicp()->isSigned()) {
|
||||
arg = "unsigned "+arg;
|
||||
}
|
||||
if (!forReturn && isWritable()) arg += "*";
|
||||
}
|
||||
|
|
@ -420,23 +422,23 @@ string AstVar::dpiArgType(bool named, bool forReturn) const {
|
|||
|
||||
string AstVar::scType() const {
|
||||
if (isScBigUint()) {
|
||||
return (string("sc_biguint<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
|
||||
return (string("sc_biguint<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
|
||||
} else if (isScUint()) {
|
||||
return (string("sc_uint<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
|
||||
return (string("sc_uint<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
|
||||
} else if (isScBv()) {
|
||||
return (string("sc_bv<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
|
||||
return (string("sc_bv<")+cvtToStr(widthMin())+"> "); // Keep the space so don't get >>
|
||||
} else if (widthMin() == 1) {
|
||||
return "bool";
|
||||
return "bool";
|
||||
} else if (widthMin() <= VL_WORDSIZE) {
|
||||
if (widthMin() <= 8 && v3Global.opt.pinsUint8()) {
|
||||
return "uint8_t";
|
||||
} else if (widthMin() <= 16 && v3Global.opt.pinsUint8()) {
|
||||
return "uint16_t";
|
||||
} else {
|
||||
return "uint32_t";
|
||||
}
|
||||
if (widthMin() <= 8 && v3Global.opt.pinsUint8()) {
|
||||
return "uint8_t";
|
||||
} else if (widthMin() <= 16 && v3Global.opt.pinsUint8()) {
|
||||
return "uint16_t";
|
||||
} else {
|
||||
return "uint32_t";
|
||||
}
|
||||
} else {
|
||||
return "vluint64_t";
|
||||
return "vluint64_t";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -445,18 +447,18 @@ AstVar* AstVar::scVarRecurse(AstNode* nodep) {
|
|||
// Historically sc variables are identified by a variable
|
||||
// attribute. TODO it would better be a data type attribute.
|
||||
if (AstVar* anodep = VN_CAST(nodep, Var)) {
|
||||
if (anodep->isSc()) return anodep;
|
||||
else return NULL;
|
||||
if (anodep->isSc()) return anodep;
|
||||
else return NULL;
|
||||
}
|
||||
else if (VN_IS(nodep, VarRef)) {
|
||||
if (VN_CAST(nodep, VarRef)->varp()->isSc()) return VN_CAST(nodep, VarRef)->varp();
|
||||
else return NULL;
|
||||
else return NULL;
|
||||
}
|
||||
else if (VN_IS(nodep, ArraySel)) {
|
||||
if (nodep->op1p()) if (AstVar* p = scVarRecurse(nodep->op1p())) return p;
|
||||
if (nodep->op2p()) if (AstVar* p = scVarRecurse(nodep->op2p())) return p;
|
||||
if (nodep->op3p()) if (AstVar* p = scVarRecurse(nodep->op3p())) return p;
|
||||
if (nodep->op4p()) if (AstVar* p = scVarRecurse(nodep->op4p())) return p;
|
||||
if (nodep->op1p()) if (AstVar* p = scVarRecurse(nodep->op1p())) return p;
|
||||
if (nodep->op2p()) if (AstVar* p = scVarRecurse(nodep->op2p())) return p;
|
||||
if (nodep->op3p()) if (AstVar* p = scVarRecurse(nodep->op3p())) return p;
|
||||
if (nodep->op4p()) if (AstVar* p = scVarRecurse(nodep->op4p())) return p;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
@ -478,58 +480,58 @@ AstNodeDType* AstNodeDType::dtypeDimensionp(int dimension) {
|
|||
// ref order: a[1][2][3][4]
|
||||
// Created as: reg [4] a [1][2][3];
|
||||
// *or* reg a [1][2][3][4];
|
||||
// // The bit select is optional; used only if "leftover" []'s
|
||||
// SEL: SEL4(SEL3(SEL2(SEL1(VARREF0 a))))
|
||||
// DECL: VAR a (ARRAYSEL0 (ARRAYSEL1 (ARRAYSEL2 (DT RANGE3))))
|
||||
// *or* VAR a (ARRAYSEL0 (ARRAYSEL1 (ARRAYSEL2 (ARRAYSEL3 (DT))))
|
||||
// SEL1 needs to select from entire variable which is a pointer to ARRAYSEL0
|
||||
// // The bit select is optional; used only if "leftover" []'s
|
||||
// SEL: SEL4(SEL3(SEL2(SEL1(VARREF0 a))))
|
||||
// DECL: VAR a (ARRAYSEL0 (ARRAYSEL1 (ARRAYSEL2 (DT RANGE3))))
|
||||
// *or* VAR a (ARRAYSEL0 (ARRAYSEL1 (ARRAYSEL2 (ARRAYSEL3 (DT))))
|
||||
// SEL1 needs to select from entire variable which is a pointer to ARRAYSEL0
|
||||
// TODO this function should be removed in favor of recursing the dtype(),
|
||||
// as that allows for more complicated data types.
|
||||
int dim = 0;
|
||||
for (AstNodeDType* dtypep=this; dtypep; ) {
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
if (AstNodeArrayDType* adtypep = VN_CAST(dtypep, NodeArrayDType)) {
|
||||
if ((dim++)==dimension) {
|
||||
return dtypep;
|
||||
}
|
||||
dtypep = adtypep->subDTypep();
|
||||
continue;
|
||||
}
|
||||
if ((dim++)==dimension) {
|
||||
return dtypep;
|
||||
}
|
||||
dtypep = adtypep->subDTypep();
|
||||
continue;
|
||||
}
|
||||
else if (AstBasicDType* adtypep = VN_CAST(dtypep, BasicDType)) {
|
||||
// AstBasicDType - nothing below, return null
|
||||
if (adtypep->isRanged()) {
|
||||
if ((dim++) == dimension) {
|
||||
return adtypep;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
// AstBasicDType - nothing below, return null
|
||||
if (adtypep->isRanged()) {
|
||||
if ((dim++) == dimension) {
|
||||
return adtypep;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
else if (AstNodeClassDType* adtypep = VN_CAST(dtypep, NodeClassDType)) {
|
||||
if (adtypep->packed()) {
|
||||
if ((dim++) == dimension) {
|
||||
return adtypep;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
// Node no ->next in loop; use continue where necessary
|
||||
break;
|
||||
if (adtypep->packed()) {
|
||||
if ((dim++) == dimension) {
|
||||
return adtypep;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
// Node no ->next in loop; use continue where necessary
|
||||
break;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint32_t AstNodeDType::arrayUnpackedElements() {
|
||||
uint32_t entries=1;
|
||||
uint32_t entries = 1;
|
||||
for (AstNodeDType* dtypep=this; dtypep; ) {
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
if (AstUnpackArrayDType* adtypep = VN_CAST(dtypep, UnpackArrayDType)) {
|
||||
entries *= adtypep->elementsConst();
|
||||
dtypep = adtypep->subDTypep();
|
||||
}
|
||||
else {
|
||||
// AstBasicDType - nothing below, 1
|
||||
break;
|
||||
}
|
||||
entries *= adtypep->elementsConst();
|
||||
dtypep = adtypep->subDTypep();
|
||||
}
|
||||
else {
|
||||
// AstBasicDType - nothing below, 1
|
||||
break;
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
|
|
@ -539,17 +541,17 @@ std::pair<uint32_t,uint32_t> AstNodeDType::dimensions(bool includeBasic) {
|
|||
uint32_t packed = 0;
|
||||
uint32_t unpacked = 0;
|
||||
for (AstNodeDType* dtypep=this; dtypep; ) {
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
if (const AstNodeArrayDType* adtypep = VN_CAST(dtypep, NodeArrayDType)) {
|
||||
if (VN_IS(adtypep, PackArrayDType)) packed++;
|
||||
else unpacked++;
|
||||
dtypep = adtypep->subDTypep();
|
||||
continue;
|
||||
}
|
||||
else unpacked++;
|
||||
dtypep = adtypep->subDTypep();
|
||||
continue;
|
||||
}
|
||||
else if (const AstBasicDType* adtypep = VN_CAST(dtypep, BasicDType)) {
|
||||
if (includeBasic && adtypep->isRanged()) packed++;
|
||||
}
|
||||
break;
|
||||
if (includeBasic && adtypep->isRanged()) packed++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
return make_pair(packed, unpacked);
|
||||
}
|
||||
|
|
@ -558,7 +560,7 @@ int AstNodeDType::widthPow2() const {
|
|||
// I.e. width 30 returns 32, width 32 returns 32.
|
||||
uint32_t width = this->width();
|
||||
for (int p2=30; p2>=0; p2--) {
|
||||
if (width > (1UL<<p2)) return (1UL<<(p2+1));
|
||||
if (width > (1UL<<p2)) return (1UL<<(p2+1));
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -577,9 +579,9 @@ AstNode* AstArraySel::baseFromp(AstNode* nodep) { ///< What is the base variabl
|
|||
} else {
|
||||
nodep = VN_CAST(nodep, NodePreSel)->lhsp();
|
||||
}
|
||||
continue;
|
||||
}
|
||||
else break;
|
||||
continue;
|
||||
}
|
||||
else break;
|
||||
}
|
||||
return nodep;
|
||||
}
|
||||
|
|
@ -604,7 +606,7 @@ string AstScope::nameDotless() const {
|
|||
string out = shortName();
|
||||
string::size_type pos;
|
||||
while ((pos = out.find('.')) != string::npos) {
|
||||
out.replace(pos, 1, "__");
|
||||
out.replace(pos, 1, "__");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -612,29 +614,29 @@ string AstScope::nameDotless() const {
|
|||
string AstScopeName::scopePrettyNameFormatter(AstText* scopeTextp) const {
|
||||
string out;
|
||||
for (AstText* textp=scopeTextp; textp; textp=VN_CAST(textp->nextp(), Text)) {
|
||||
out += textp->text();
|
||||
out += textp->text();
|
||||
}
|
||||
// TOP will be replaced by top->name()
|
||||
if (out.substr(0,10) == "__DOT__TOP") out.replace(0,10,"");
|
||||
if (out.substr(0,7) == "__DOT__") out.replace(0,7,"");
|
||||
if (out.substr(0,1) == ".") out.replace(0,1,"");
|
||||
if (out.substr(0, 10) == "__DOT__TOP") out.replace(0, 10, "");
|
||||
if (out.substr(0, 7) == "__DOT__") out.replace(0, 7, "");
|
||||
if (out.substr(0, 1) == ".") out.replace(0, 1, "");
|
||||
return AstNode::prettyName(out);
|
||||
}
|
||||
|
||||
string AstScopeName::scopeNameFormatter(AstText* scopeTextp) const {
|
||||
string out;
|
||||
for (AstText* textp=scopeTextp; textp; textp=VN_CAST(textp->nextp(), Text)) {
|
||||
out += textp->text();
|
||||
out += textp->text();
|
||||
}
|
||||
if (out.substr(0,10) == "__DOT__TOP") out.replace(0,10,"");
|
||||
if (out.substr(0,7) == "__DOT__") out.replace(0,7,"");
|
||||
if (out.substr(0,1) == ".") out.replace(0,1,"");
|
||||
if (out.substr(0, 10) == "__DOT__TOP") out.replace(0, 10, "");
|
||||
if (out.substr(0, 7) == "__DOT__") out.replace(0, 7, "");
|
||||
if (out.substr(0, 1) == ".") out.replace(0, 1, "");
|
||||
string::size_type pos;
|
||||
while ((pos = out.find('.')) != string::npos) {
|
||||
out.replace(pos, 1, "__");
|
||||
out.replace(pos, 1, "__");
|
||||
}
|
||||
while ((pos=out.find("__DOT__")) != string::npos) {
|
||||
out.replace(pos, 7, "__");
|
||||
while ((pos = out.find("__DOT__")) != string::npos) {
|
||||
out.replace(pos, 7, "__");
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
|
@ -642,28 +644,28 @@ string AstScopeName::scopeNameFormatter(AstText* scopeTextp) const {
|
|||
bool AstSenTree::hasClocked() const {
|
||||
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
||||
for (AstNodeSenItem* senp = sensesp(); senp; senp=VN_CAST(senp->nextp(), NodeSenItem)) {
|
||||
if (senp->isClocked()) return true;
|
||||
if (senp->isClocked()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool AstSenTree::hasSettle() const {
|
||||
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
||||
for (AstNodeSenItem* senp = sensesp(); senp; senp=VN_CAST(senp->nextp(), NodeSenItem)) {
|
||||
if (senp->isSettle()) return true;
|
||||
if (senp->isSettle()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool AstSenTree::hasInitial() const {
|
||||
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
||||
for (AstNodeSenItem* senp = sensesp(); senp; senp=VN_CAST(senp->nextp(), NodeSenItem)) {
|
||||
if (senp->isInitial()) return true;
|
||||
if (senp->isInitial()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
bool AstSenTree::hasCombo() const {
|
||||
if (!sensesp()) this->v3fatalSrc("SENTREE without any SENITEMs under it");
|
||||
for (AstNodeSenItem* senp = sensesp(); senp; senp=VN_CAST(senp->nextp(), NodeSenItem)) {
|
||||
if (senp->isCombo()) return true;
|
||||
if (senp->isCombo()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
@ -672,20 +674,20 @@ void AstTypeTable::clearCache() {
|
|||
// When we mass-change widthMin in V3WidthCommit, we need to correct the table.
|
||||
// Just clear out the maps; the search functions will be used to rebuild the map
|
||||
for (int i=0; i < static_cast<int>(AstBasicDTypeKwd::_ENUM_MAX); ++i) {
|
||||
m_basicps[i] = NULL;
|
||||
m_basicps[i] = NULL;
|
||||
}
|
||||
for (int isbit=0; isbit<_IDX0_MAX; ++isbit) {
|
||||
for (int numer=0; numer<AstNumeric::_ENUM_MAX; ++numer) {
|
||||
LogicMap& mapr = m_logicMap[isbit][numer];
|
||||
mapr.clear();
|
||||
}
|
||||
for (int numer=0; numer<AstNumeric::_ENUM_MAX; ++numer) {
|
||||
LogicMap& mapr = m_logicMap[isbit][numer];
|
||||
mapr.clear();
|
||||
}
|
||||
}
|
||||
m_detailedMap.clear();
|
||||
// Clear generic()'s so dead detection will work
|
||||
for (AstNode* nodep = typesp(); nodep; nodep=nodep->nextp()) {
|
||||
if (AstBasicDType* bdtypep = VN_CAST(nodep, BasicDType)) {
|
||||
bdtypep->generic(false);
|
||||
}
|
||||
bdtypep->generic(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -694,8 +696,8 @@ void AstTypeTable::repairCache() {
|
|||
clearCache();
|
||||
for (AstNode* nodep = typesp(); nodep; nodep=nodep->nextp()) {
|
||||
if (AstBasicDType* bdtypep = VN_CAST(nodep, BasicDType)) {
|
||||
(void)findInsertSameDType(bdtypep);
|
||||
}
|
||||
(void)findInsertSameDType(bdtypep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -715,12 +717,12 @@ AstBasicDType* AstTypeTable::findBasicDType(FileLine* fl, AstBasicDTypeKwd kwd)
|
|||
}
|
||||
|
||||
AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kwd,
|
||||
int width, int widthMin, AstNumeric numeric) {
|
||||
int width, int widthMin, AstNumeric numeric) {
|
||||
int idx = IDX0_LOGIC;
|
||||
if (kwd == AstBasicDTypeKwd::LOGIC) idx = IDX0_LOGIC;
|
||||
else if (kwd == AstBasicDTypeKwd::BIT) idx = IDX0_BIT;
|
||||
else fl->v3fatalSrc("Bad kwd for findLogicBitDType");
|
||||
std::pair<int,int> widths = make_pair(width,widthMin);
|
||||
std::pair<int,int> widths = make_pair(width, widthMin);
|
||||
LogicMap& mapr = m_logicMap[idx][static_cast<int>(numeric)];
|
||||
LogicMap::const_iterator it = mapr.find(widths);
|
||||
if (it != mapr.end()) return it->second;
|
||||
|
|
@ -733,12 +735,12 @@ AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kw
|
|||
if (newp != new1p) new1p->deleteTree();
|
||||
else addTypesp(newp);
|
||||
//
|
||||
mapr.insert(make_pair(widths,newp));
|
||||
mapr.insert(make_pair(widths, newp));
|
||||
return newp;
|
||||
}
|
||||
|
||||
AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kwd,
|
||||
VNumRange range, int widthMin, AstNumeric numeric) {
|
||||
VNumRange range, int widthMin, AstNumeric numeric) {
|
||||
AstBasicDType* new1p = new AstBasicDType(fl, kwd, numeric, range, widthMin);
|
||||
AstBasicDType* newp = findInsertSameDType(new1p);
|
||||
if (newp != new1p) new1p->deleteTree();
|
||||
|
|
@ -748,11 +750,11 @@ AstBasicDType* AstTypeTable::findLogicBitDType(FileLine* fl, AstBasicDTypeKwd kw
|
|||
|
||||
AstBasicDType* AstTypeTable::findInsertSameDType(AstBasicDType* nodep) {
|
||||
VBasicTypeKey key (nodep->width(), nodep->widthMin(), nodep->numeric(),
|
||||
nodep->keyword(), nodep->nrange());
|
||||
nodep->keyword(), nodep->nrange());
|
||||
DetailedMap& mapr = m_detailedMap;
|
||||
DetailedMap::const_iterator it = mapr.find(key);
|
||||
if (it != mapr.end()) return it->second;
|
||||
mapr.insert(make_pair(key,nodep));
|
||||
mapr.insert(make_pair(key, nodep));
|
||||
nodep->generic(true);
|
||||
// No addTypesp; the upper function that called new() is responsible for adding
|
||||
return nodep;
|
||||
|
|
@ -784,39 +786,41 @@ void AstNodeStmt::addNextStmt(AstNode* newp, AstNode*) {
|
|||
void AstWhile::addBeforeStmt(AstNode* newp, AstNode* belowp) {
|
||||
// Special, as statements need to be put in different places
|
||||
// Belowp is how we came to recurse up to this point
|
||||
// Preconditions insert first just before themselves (the normal rule for other statement types)
|
||||
// Preconditions insert first just before themselves (the normal rule
|
||||
// for other statement types)
|
||||
if (belowp == precondsp()) {
|
||||
// Must have been first statement in precondsp list, so newp is new first statement
|
||||
belowp->addHereThisAsNext(newp);
|
||||
// Must have been first statement in precondsp list, so newp is new first statement
|
||||
belowp->addHereThisAsNext(newp);
|
||||
} else if (belowp == condp()) {
|
||||
// Goes before condition, IE in preconditions
|
||||
addPrecondsp(newp);
|
||||
// Goes before condition, IE in preconditions
|
||||
addPrecondsp(newp);
|
||||
} else if (belowp == bodysp()) {
|
||||
// Was first statement in body, so new front
|
||||
belowp->addHereThisAsNext(newp);
|
||||
// Was first statement in body, so new front
|
||||
belowp->addHereThisAsNext(newp);
|
||||
} else {
|
||||
belowp->v3fatalSrc("Doesn't look like this was really under the while");
|
||||
belowp->v3fatalSrc("Doesn't look like this was really under the while");
|
||||
}
|
||||
}
|
||||
void AstWhile::addNextStmt(AstNode* newp, AstNode* belowp) {
|
||||
// Special, as statements need to be put in different places
|
||||
// Belowp is how we came to recurse up to this point
|
||||
// Preconditions insert first just before themselves (the normal rule for other statement types)
|
||||
// Preconditions insert first just before themselves (the normal rule
|
||||
// for other statement types)
|
||||
if (belowp == precondsp()) {
|
||||
// Next in precond list
|
||||
belowp->addNextHere(newp);
|
||||
// Next in precond list
|
||||
belowp->addNextHere(newp);
|
||||
} else if (belowp == condp()) {
|
||||
// Becomes first statement in body, body may have been empty
|
||||
if (bodysp()) {
|
||||
bodysp()->addHereThisAsNext(newp);
|
||||
} else {
|
||||
addBodysp(newp);
|
||||
}
|
||||
// Becomes first statement in body, body may have been empty
|
||||
if (bodysp()) {
|
||||
bodysp()->addHereThisAsNext(newp);
|
||||
} else {
|
||||
addBodysp(newp);
|
||||
}
|
||||
} else if (belowp == bodysp()) {
|
||||
// Next statement in body
|
||||
belowp->addNextHere(newp);
|
||||
// Next statement in body
|
||||
belowp->addNextHere(newp);
|
||||
} else {
|
||||
belowp->v3fatalSrc("Doesn't look like this was really under the while");
|
||||
belowp->v3fatalSrc("Doesn't look like this was really under the while");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -836,12 +840,12 @@ void AstNode::dump(std::ostream& str) {
|
|||
if (user5p()) str<<" u5="<<cvtToHex(user5p());
|
||||
if (hasDType()) {
|
||||
// Final @ so less likely to by accident read it as a nodep
|
||||
if (dtypep()==this) str<<" @dt="<<"this@";
|
||||
if (dtypep()==this) str<<" @dt="<<"this@";
|
||||
else str<<" @dt="<<cvtToHex(dtypep())<<"@";
|
||||
if (AstNodeDType* dtp = dtypep()) {
|
||||
dtp->dumpSmall(str);
|
||||
}
|
||||
} else { // V3Broken will throw an error
|
||||
if (AstNodeDType* dtp = dtypep()) {
|
||||
dtp->dumpSmall(str);
|
||||
}
|
||||
} else { // V3Broken will throw an error
|
||||
if (dtypep()) str<<" %Error-dtype-exp=null,got="<<cvtToHex(dtypep());
|
||||
}
|
||||
if (name()!="") {
|
||||
|
|
@ -956,7 +960,7 @@ void AstNodeDType::dump(std::ostream& str) {
|
|||
if (generic()) str<<" [GENERIC]";
|
||||
if (AstNodeDType* dtp = virtRefDTypep()) {
|
||||
str<<" refdt="<<cvtToHex(dtp);
|
||||
dtp->dumpSmall(str);
|
||||
dtp->dumpSmall(str);
|
||||
}
|
||||
}
|
||||
void AstNodeDType::dumpSmall(std::ostream& str) {
|
||||
|
|
@ -967,7 +971,7 @@ void AstNodeDType::dumpSmall(std::ostream& str) {
|
|||
<<(isDouble()?"d":"")
|
||||
<<(isString()?"str":"");
|
||||
if (!isDouble() && !isString()) {
|
||||
str<<"w"<<(widthSized()?"":"u")<<width();
|
||||
str<<"w"<<(widthSized()?"":"u")<<width();
|
||||
}
|
||||
if (!widthSized()) str<<"/"<<widthMin();
|
||||
str<<")";
|
||||
|
|
@ -1001,8 +1005,8 @@ void AstPackageImport::dump(std::ostream& str) {
|
|||
void AstSel::dump(std::ostream& str) {
|
||||
this->AstNode::dump(str);
|
||||
if (declRange().ranged()) {
|
||||
str<<" decl"<<declRange()<<"]";
|
||||
if (declElWidth()!=1) str<<"/"<<declElWidth();
|
||||
str<<" decl"<<declRange()<<"]";
|
||||
if (declElWidth()!=1) str<<"/"<<declElWidth();
|
||||
}
|
||||
}
|
||||
void AstSliceSel::dump(std::ostream& str) {
|
||||
|
|
@ -1019,37 +1023,37 @@ void AstMTaskBody::dump(std::ostream& str) {
|
|||
void AstTypeTable::dump(std::ostream& str) {
|
||||
this->AstNode::dump(str);
|
||||
for (int i=0; i < static_cast<int>(AstBasicDTypeKwd::_ENUM_MAX); ++i) {
|
||||
if (AstBasicDType* subnodep=m_basicps[i]) {
|
||||
str<<endl; // Newline from caller, so newline first
|
||||
if (AstBasicDType* subnodep = m_basicps[i]) {
|
||||
str<<endl; // Newline from caller, so newline first
|
||||
str<<"\t\t"<<std::setw(8)<<AstBasicDTypeKwd(i).ascii();
|
||||
str<<" -> ";
|
||||
subnodep->dump(str);
|
||||
}
|
||||
str<<" -> ";
|
||||
subnodep->dump(str);
|
||||
}
|
||||
}
|
||||
for (int isbit=0; isbit<2; ++isbit) {
|
||||
for (int issigned=0; issigned<AstNumeric::_ENUM_MAX; ++issigned) {
|
||||
LogicMap& mapr = m_logicMap[isbit][issigned];
|
||||
for (LogicMap::const_iterator it = mapr.begin(); it != mapr.end(); ++it) {
|
||||
AstBasicDType* dtypep = it->second;
|
||||
str<<endl; // Newline from caller, so newline first
|
||||
for (int issigned=0; issigned<AstNumeric::_ENUM_MAX; ++issigned) {
|
||||
LogicMap& mapr = m_logicMap[isbit][issigned];
|
||||
for (LogicMap::const_iterator it = mapr.begin(); it != mapr.end(); ++it) {
|
||||
AstBasicDType* dtypep = it->second;
|
||||
str<<endl; // Newline from caller, so newline first
|
||||
std::stringstream nsstr;
|
||||
nsstr<<(isbit?"bw":"lw")
|
||||
<<it->first.first<<"/"<<it->first.second;
|
||||
nsstr<<(isbit?"bw":"lw")
|
||||
<<it->first.first<<"/"<<it->first.second;
|
||||
str<<"\t\t"<<std::setw(8)<<nsstr.str();
|
||||
if (issigned) str<<" s"; else str<<" u";
|
||||
str<<" -> ";
|
||||
dtypep->dump(str);
|
||||
}
|
||||
}
|
||||
if (issigned) str<<" s"; else str<<" u";
|
||||
str<<" -> ";
|
||||
dtypep->dump(str);
|
||||
}
|
||||
}
|
||||
}
|
||||
{
|
||||
DetailedMap& mapr = m_detailedMap;
|
||||
for (DetailedMap::const_iterator it = mapr.begin(); it != mapr.end(); ++it) {
|
||||
AstBasicDType* dtypep = it->second;
|
||||
str<<endl; // Newline from caller, so newline first
|
||||
str<<"\t\tdetailed -> ";
|
||||
dtypep->dump(str);
|
||||
}
|
||||
DetailedMap& mapr = m_detailedMap;
|
||||
for (DetailedMap::const_iterator it = mapr.begin(); it != mapr.end(); ++it) {
|
||||
AstBasicDType* dtypep = it->second;
|
||||
str<<endl; // Newline from caller, so newline first
|
||||
str<<"\t\tdetailed -> ";
|
||||
dtypep->dump(str);
|
||||
}
|
||||
}
|
||||
// Note get newline from caller too.
|
||||
}
|
||||
|
|
@ -1158,8 +1162,8 @@ void AstBegin::dump(std::ostream& str) {
|
|||
void AstCoverDecl::dump(std::ostream& str) {
|
||||
this->AstNode::dump(str);
|
||||
if (this->dataDeclNullp()) {
|
||||
str<<" -> ";
|
||||
this->dataDeclNullp()->dump(str);
|
||||
str<<" -> ";
|
||||
this->dataDeclNullp()->dump(str);
|
||||
} else {
|
||||
if (binNum()) { str<<" bin"<<std::dec<<binNum(); }
|
||||
}
|
||||
|
|
@ -1181,8 +1185,8 @@ void AstNodeText::dump(std::ostream& str) {
|
|||
string out = text();
|
||||
string::size_type pos;
|
||||
if ((pos = out.find('\n')) != string::npos) {
|
||||
out.erase(pos,out.length()-pos);
|
||||
out += "...";
|
||||
out.erase(pos, out.length()-pos);
|
||||
out += "...";
|
||||
}
|
||||
str<<" \""<<out<<"\"";
|
||||
}
|
||||
|
|
@ -1195,8 +1199,8 @@ void AstCFile::dump(std::ostream& str) {
|
|||
void AstCCall::dump(std::ostream& str) {
|
||||
this->AstNode::dump(str);
|
||||
if (funcp()) {
|
||||
str<<" "<<funcp()->name()<<" => ";
|
||||
funcp()->dump(str);
|
||||
str<<" "<<funcp()->name()<<" => ";
|
||||
funcp()->dump(str);
|
||||
}
|
||||
}
|
||||
void AstCFunc::dump(std::ostream& str) {
|
||||
|
|
|
|||
3820
src/V3AstNodes.h
3820
src/V3AstNodes.h
File diff suppressed because it is too large
Load Diff
300
src/V3Begin.cpp
300
src/V3Begin.cpp
|
|
@ -20,9 +20,9 @@
|
|||
// V3Begin's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// Look for BEGINs
|
||||
// BEGIN(VAR...) -> VAR ... {renamed}
|
||||
// FOR -> WHILEs
|
||||
// Look for BEGINs
|
||||
// BEGIN(VAR...) -> VAR ... {renamed}
|
||||
// FOR -> WHILEs
|
||||
//
|
||||
// There are two scopes; named BEGINs change %m and variable scopes.
|
||||
// Unnamed BEGINs change only variable, not $display("%m") scope.
|
||||
|
|
@ -47,17 +47,17 @@ class BeginState {
|
|||
private:
|
||||
// NODE STATE
|
||||
//Entire netlist:
|
||||
// AstNodeFTask::user1 -> bool, 1=processed
|
||||
AstUser1InUse m_inuser1;
|
||||
bool m_anyFuncInBegin;
|
||||
// AstNodeFTask::user1 -> bool, 1=processed
|
||||
AstUser1InUse m_inuser1;
|
||||
bool m_anyFuncInBegin;
|
||||
public:
|
||||
BeginState() {
|
||||
m_anyFuncInBegin = false;
|
||||
m_anyFuncInBegin = false;
|
||||
}
|
||||
~BeginState() {}
|
||||
void userMarkChanged(AstNode* nodep) {
|
||||
nodep->user1(true);
|
||||
m_anyFuncInBegin = true;
|
||||
nodep->user1(true);
|
||||
m_anyFuncInBegin = true;
|
||||
}
|
||||
bool anyFuncInBegin() const { return m_anyFuncInBegin; }
|
||||
};
|
||||
|
|
@ -67,159 +67,161 @@ public:
|
|||
class BeginVisitor : public AstNVisitor {
|
||||
private:
|
||||
// STATE
|
||||
BeginState* m_statep; // Current global state
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstNodeFTask* m_ftaskp; // Current function/task
|
||||
string m_namedScope; // Name of begin blocks above us
|
||||
string m_unnamedScope; // Name of begin blocks, including unnamed blocks
|
||||
int m_repeatNum; // Repeat counter
|
||||
int m_ifDepth; // Current if depth
|
||||
BeginState* m_statep; // Current global state
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstNodeFTask* m_ftaskp; // Current function/task
|
||||
string m_namedScope; // Name of begin blocks above us
|
||||
string m_unnamedScope; // Name of begin blocks, including unnamed blocks
|
||||
int m_repeatNum; // Repeat counter
|
||||
int m_ifDepth; // Current if depth
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
m_repeatNum = 0;
|
||||
m_modp = nodep;
|
||||
m_repeatNum = 0;
|
||||
iterateChildren(nodep);
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstNodeFTask* nodep) {
|
||||
UINFO(8," "<<nodep<<endl);
|
||||
// Rename it
|
||||
if (m_unnamedScope != "") {
|
||||
nodep->name(m_unnamedScope+"__DOT__"+nodep->name());
|
||||
UINFO(8," rename to "<<nodep->name()<<endl);
|
||||
m_statep->userMarkChanged(nodep);
|
||||
}
|
||||
// BEGIN wrapping a function rename that function, but don't affect the inside function's variables
|
||||
// We then restart with empty naming; so that any begin's inside the function will rename inside the function
|
||||
// Process children
|
||||
string oldScope = m_namedScope;
|
||||
string oldUnnamed = m_unnamedScope;
|
||||
{
|
||||
m_namedScope = "";
|
||||
m_unnamedScope = "";
|
||||
m_ftaskp = nodep;
|
||||
UINFO(8," "<<nodep<<endl);
|
||||
// Rename it
|
||||
if (m_unnamedScope != "") {
|
||||
nodep->name(m_unnamedScope+"__DOT__"+nodep->name());
|
||||
UINFO(8," rename to "<<nodep->name()<<endl);
|
||||
m_statep->userMarkChanged(nodep);
|
||||
}
|
||||
// BEGIN wrapping a function rename that function, but don't affect
|
||||
// the inside function's variables. We then restart with empty
|
||||
// naming; so that any begin's inside the function will rename
|
||||
// inside the function.
|
||||
// Process children
|
||||
string oldScope = m_namedScope;
|
||||
string oldUnnamed = m_unnamedScope;
|
||||
{
|
||||
m_namedScope = "";
|
||||
m_unnamedScope = "";
|
||||
m_ftaskp = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_ftaskp = NULL;
|
||||
}
|
||||
m_namedScope = oldScope;
|
||||
m_unnamedScope = oldUnnamed;
|
||||
m_ftaskp = NULL;
|
||||
}
|
||||
m_namedScope = oldScope;
|
||||
m_unnamedScope = oldUnnamed;
|
||||
}
|
||||
virtual void visit(AstBegin* nodep) {
|
||||
// Begin blocks were only useful in variable creation, change names and delete
|
||||
UINFO(8," "<<nodep<<endl);
|
||||
string oldScope = m_namedScope;
|
||||
string oldUnnamed = m_unnamedScope;
|
||||
{
|
||||
UINFO(8,"nname "<<m_namedScope<<endl);
|
||||
if (nodep->name() != "") { // Else unneeded unnamed block
|
||||
// Create data for dotted variable resolution
|
||||
string dottedname = nodep->name() + "__DOT__"; // So always found
|
||||
string::size_type pos;
|
||||
while ((pos=dottedname.find("__DOT__")) != string::npos) {
|
||||
string ident = dottedname.substr(0,pos);
|
||||
dottedname = dottedname.substr(pos+strlen("__DOT__"));
|
||||
if (!nodep->unnamed()) {
|
||||
if (m_namedScope=="") m_namedScope = ident;
|
||||
else m_namedScope = m_namedScope + "__DOT__"+ident;
|
||||
}
|
||||
if (m_unnamedScope=="") m_unnamedScope = ident;
|
||||
else m_unnamedScope = m_unnamedScope + "__DOT__"+ident;
|
||||
// Create CellInline for dotted var resolution
|
||||
if (!m_ftaskp) {
|
||||
AstCellInline* inlinep = new AstCellInline(nodep->fileline(),
|
||||
m_unnamedScope, "__BEGIN__");
|
||||
m_modp->addInlinesp(inlinep); // Must be parsed before any AstCells
|
||||
}
|
||||
}
|
||||
}
|
||||
// Begin blocks were only useful in variable creation, change names and delete
|
||||
UINFO(8," "<<nodep<<endl);
|
||||
string oldScope = m_namedScope;
|
||||
string oldUnnamed = m_unnamedScope;
|
||||
{
|
||||
UINFO(8,"nname "<<m_namedScope<<endl);
|
||||
if (nodep->name() != "") { // Else unneeded unnamed block
|
||||
// Create data for dotted variable resolution
|
||||
string dottedname = nodep->name() + "__DOT__"; // So always found
|
||||
string::size_type pos;
|
||||
while ((pos=dottedname.find("__DOT__")) != string::npos) {
|
||||
string ident = dottedname.substr(0, pos);
|
||||
dottedname = dottedname.substr(pos+strlen("__DOT__"));
|
||||
if (!nodep->unnamed()) {
|
||||
if (m_namedScope=="") m_namedScope = ident;
|
||||
else m_namedScope = m_namedScope + "__DOT__"+ident;
|
||||
}
|
||||
if (m_unnamedScope=="") m_unnamedScope = ident;
|
||||
else m_unnamedScope = m_unnamedScope + "__DOT__"+ident;
|
||||
// Create CellInline for dotted var resolution
|
||||
if (!m_ftaskp) {
|
||||
AstCellInline* inlinep = new AstCellInline(nodep->fileline(),
|
||||
m_unnamedScope, "__BEGIN__");
|
||||
m_modp->addInlinesp(inlinep); // Must be parsed before any AstCells
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remap var names and replace lower Begins
|
||||
// Remap var names and replace lower Begins
|
||||
iterateAndNextNull(nodep->stmtsp());
|
||||
if (nodep->genforp()) nodep->v3fatalSrc("GENFORs should have been expanded earlier");
|
||||
}
|
||||
m_namedScope = oldScope;
|
||||
m_unnamedScope = oldUnnamed;
|
||||
if (nodep->genforp()) nodep->v3fatalSrc("GENFORs should have been expanded earlier");
|
||||
}
|
||||
m_namedScope = oldScope;
|
||||
m_unnamedScope = oldUnnamed;
|
||||
|
||||
// Cleanup
|
||||
AstNode* addsp = NULL;
|
||||
if (AstNode* stmtsp = nodep->stmtsp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
if (addsp) { addsp = addsp->addNextNull(stmtsp); } else { addsp = stmtsp; }
|
||||
}
|
||||
if (addsp) {
|
||||
nodep->replaceWith(addsp);
|
||||
} else {
|
||||
nodep->unlinkFrBack();
|
||||
}
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
// Cleanup
|
||||
AstNode* addsp = NULL;
|
||||
if (AstNode* stmtsp = nodep->stmtsp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
if (addsp) { addsp = addsp->addNextNull(stmtsp); } else { addsp = stmtsp; }
|
||||
}
|
||||
if (addsp) {
|
||||
nodep->replaceWith(addsp);
|
||||
} else {
|
||||
nodep->unlinkFrBack();
|
||||
}
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstVar* nodep) {
|
||||
if (m_unnamedScope != "") {
|
||||
// Rename it
|
||||
nodep->name(m_unnamedScope+"__DOT__"+nodep->name());
|
||||
m_statep->userMarkChanged(nodep);
|
||||
// Move to module
|
||||
nodep->unlinkFrBack();
|
||||
if (m_ftaskp) m_ftaskp->addStmtsp(nodep); // Begins under funcs just move into the func
|
||||
else m_modp->addStmtp(nodep);
|
||||
}
|
||||
if (m_unnamedScope != "") {
|
||||
// Rename it
|
||||
nodep->name(m_unnamedScope+"__DOT__"+nodep->name());
|
||||
m_statep->userMarkChanged(nodep);
|
||||
// Move to module
|
||||
nodep->unlinkFrBack();
|
||||
if (m_ftaskp) m_ftaskp->addStmtsp(nodep); // Begins under funcs just move into the func
|
||||
else m_modp->addStmtp(nodep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstCell* nodep) {
|
||||
UINFO(8," CELL "<<nodep<<endl);
|
||||
if (m_namedScope != "") {
|
||||
m_statep->userMarkChanged(nodep);
|
||||
// Rename it
|
||||
nodep->name(m_namedScope+"__DOT__"+nodep->name());
|
||||
UINFO(8," rename to "<<nodep->name()<<endl);
|
||||
// Move to module
|
||||
nodep->unlinkFrBack();
|
||||
m_modp->addStmtp(nodep);
|
||||
}
|
||||
UINFO(8," CELL "<<nodep<<endl);
|
||||
if (m_namedScope != "") {
|
||||
m_statep->userMarkChanged(nodep);
|
||||
// Rename it
|
||||
nodep->name(m_namedScope+"__DOT__"+nodep->name());
|
||||
UINFO(8," rename to "<<nodep->name()<<endl);
|
||||
// Move to module
|
||||
nodep->unlinkFrBack();
|
||||
m_modp->addStmtp(nodep);
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstVarXRef* nodep) {
|
||||
UINFO(9, " VARXREF "<<nodep<<endl);
|
||||
if (m_namedScope != "" && nodep->inlinedDots() == "") {
|
||||
nodep->inlinedDots(m_namedScope);
|
||||
UINFO(9, " rescope to "<<nodep<<endl);
|
||||
}
|
||||
UINFO(9, " VARXREF "<<nodep<<endl);
|
||||
if (m_namedScope != "" && nodep->inlinedDots() == "") {
|
||||
nodep->inlinedDots(m_namedScope);
|
||||
UINFO(9, " rescope to "<<nodep<<endl);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstScopeName* nodep) {
|
||||
// If there's a %m in the display text, we add a special node that will contain the name()
|
||||
// Similar code in V3Inline
|
||||
if (nodep->user1SetOnce()) return; // Don't double-add text's
|
||||
if (m_namedScope != "") {
|
||||
// To keep correct visual order, must add before other Text's
|
||||
AstNode* afterp = nodep->scopeAttrp();
|
||||
if (afterp) afterp->unlinkFrBackWithNext();
|
||||
// If there's a %m in the display text, we add a special node that will contain the name()
|
||||
// Similar code in V3Inline
|
||||
if (nodep->user1SetOnce()) return; // Don't double-add text's
|
||||
if (m_namedScope != "") {
|
||||
// To keep correct visual order, must add before other Text's
|
||||
AstNode* afterp = nodep->scopeAttrp();
|
||||
if (afterp) afterp->unlinkFrBackWithNext();
|
||||
nodep->scopeAttrp(new AstText(nodep->fileline(), string("__DOT__")+m_namedScope));
|
||||
if (afterp) nodep->scopeAttrp(afterp);
|
||||
}
|
||||
if (afterp) nodep->scopeAttrp(afterp);
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCoverDecl* nodep) {
|
||||
// Don't need to fix path in coverage statements, they're not under
|
||||
// any BEGINs, but V3Coverage adds them all under the module itself.
|
||||
// Don't need to fix path in coverage statements, they're not under
|
||||
// any BEGINs, but V3Coverage adds them all under the module itself.
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
// VISITORS - LINT CHECK
|
||||
virtual void visit(AstIf* nodep) { // Note not AstNodeIf; other types don't get covered
|
||||
// Check IFDEPTH warning - could be in other transform files if desire
|
||||
int prevIfDepth = m_ifDepth;
|
||||
if (m_ifDepth == -1 || v3Global.opt.ifDepth()<1) { // Turned off
|
||||
} else if (nodep->uniquePragma() || nodep->unique0Pragma() || nodep->priorityPragma()) {
|
||||
m_ifDepth = -1;
|
||||
} else if (++m_ifDepth > v3Global.opt.ifDepth()) {
|
||||
nodep->v3warn(IFDEPTH,"Deep 'if' statement; suggest unique/priority to avoid slow logic");
|
||||
nodep->fileline()->modifyWarnOff(V3ErrorCode::IFDEPTH, true); // Warn only once
|
||||
m_ifDepth = -1;
|
||||
}
|
||||
virtual void visit(AstIf* nodep) { // Note not AstNodeIf; other types don't get covered
|
||||
// Check IFDEPTH warning - could be in other transform files if desire
|
||||
int prevIfDepth = m_ifDepth;
|
||||
if (m_ifDepth == -1 || v3Global.opt.ifDepth()<1) { // Turned off
|
||||
} else if (nodep->uniquePragma() || nodep->unique0Pragma() || nodep->priorityPragma()) {
|
||||
m_ifDepth = -1;
|
||||
} else if (++m_ifDepth > v3Global.opt.ifDepth()) {
|
||||
nodep->v3warn(IFDEPTH,"Deep 'if' statement; suggest unique/priority to avoid slow logic");
|
||||
nodep->fileline()->modifyWarnOff(V3ErrorCode::IFDEPTH, true); // Warn only once
|
||||
m_ifDepth = -1;
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
m_ifDepth = prevIfDepth;
|
||||
m_ifDepth = prevIfDepth;
|
||||
}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
|
|
@ -227,11 +229,11 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
BeginVisitor(AstNetlist* nodep, BeginState* statep) {
|
||||
m_statep = statep;
|
||||
m_modp = NULL;
|
||||
m_ftaskp = NULL;
|
||||
m_repeatNum = 0;
|
||||
m_ifDepth = 0;
|
||||
m_statep = statep;
|
||||
m_modp = NULL;
|
||||
m_ftaskp = NULL;
|
||||
m_repeatNum = 0;
|
||||
m_ifDepth = 0;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~BeginVisitor() {}
|
||||
|
|
@ -244,29 +246,29 @@ class BeginRelinkVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Input:
|
||||
// AstNodeFTask::user1p // Node replaced, rename it
|
||||
// AstNodeFTask::user1p // Node replaced, rename it
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeFTaskRef* nodep) {
|
||||
if (nodep->taskp()->user1()) { // It was converted
|
||||
UINFO(9, " relinkFTask "<<nodep<<endl);
|
||||
nodep->name(nodep->taskp()->name());
|
||||
}
|
||||
if (nodep->taskp()->user1()) { // It was converted
|
||||
UINFO(9, " relinkFTask "<<nodep<<endl);
|
||||
nodep->name(nodep->taskp()->name());
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
if (nodep->varp()->user1()) { // It was converted
|
||||
UINFO(9, " relinVarRef "<<nodep<<endl);
|
||||
nodep->name(nodep->varp()->name());
|
||||
}
|
||||
if (nodep->varp()->user1()) { // It was converted
|
||||
UINFO(9, " relinVarRef "<<nodep<<endl);
|
||||
nodep->name(nodep->varp()->name());
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstIfaceRefDType* nodep) {
|
||||
// May have changed cell names
|
||||
// TypeTable is always after all modules, so names are stable
|
||||
UINFO(8," IFACEREFDTYPE "<<nodep<<endl);
|
||||
if (nodep->cellp()) nodep->cellName(nodep->cellp()->name());
|
||||
UINFO(8," rename to "<<nodep<<endl);
|
||||
// May have changed cell names
|
||||
// TypeTable is always after all modules, so names are stable
|
||||
UINFO(8," IFACEREFDTYPE "<<nodep<<endl);
|
||||
if (nodep->cellp()) nodep->cellName(nodep->cellp()->name());
|
||||
UINFO(8," rename to "<<nodep<<endl);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
//--------------------
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void debeginAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
104
src/V3Branch.cpp
104
src/V3Branch.cpp
|
|
@ -18,12 +18,12 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// BRANCH TRANSFORMATIONS:
|
||||
// At each IF/(IF else).
|
||||
// Count underneath $display/$stop statements.
|
||||
// If more on if than else, this branch is unlikely, or vice-versa.
|
||||
// At each FTASKREF,
|
||||
// Count calls into the function
|
||||
// Then, if FTASK is called only once, add inline attribute
|
||||
// At each IF/(IF else).
|
||||
// Count underneath $display/$stop statements.
|
||||
// If more on if than else, this branch is unlikely, or vice-versa.
|
||||
// At each FTASKREF,
|
||||
// Count calls into the function
|
||||
// Then, if FTASK is called only once, add inline attribute
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -44,89 +44,89 @@ class BranchVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstFTask::user1() -> int. Number of references
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstFTask::user1() -> int. Number of references
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// TYPES
|
||||
typedef std::vector<AstCFunc*> CFuncVec;
|
||||
|
||||
// STATE
|
||||
int m_likely; // Excuses for branch likely taken
|
||||
int m_unlikely; // Excuses for branch likely not taken
|
||||
CFuncVec m_cfuncsp; // List of all tasks
|
||||
int m_likely; // Excuses for branch likely taken
|
||||
int m_unlikely; // Excuses for branch likely not taken
|
||||
CFuncVec m_cfuncsp; // List of all tasks
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void reset() {
|
||||
m_likely = false;
|
||||
m_unlikely = false;
|
||||
m_likely = false;
|
||||
m_unlikely = false;
|
||||
}
|
||||
void checkUnlikely(AstNode* nodep) {
|
||||
if (nodep->isUnlikely()) {
|
||||
UINFO(4," UNLIKELY: "<<nodep<<endl);
|
||||
m_unlikely++;
|
||||
}
|
||||
if (nodep->isUnlikely()) {
|
||||
UINFO(4," UNLIKELY: "<<nodep<<endl);
|
||||
m_unlikely++;
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeIf* nodep) {
|
||||
UINFO(4," IF: "<<nodep<<endl);
|
||||
int lastLikely = m_likely;
|
||||
int lastUnlikely = m_unlikely;
|
||||
{
|
||||
// Do if
|
||||
reset();
|
||||
UINFO(4," IF: "<<nodep<<endl);
|
||||
int lastLikely = m_likely;
|
||||
int lastUnlikely = m_unlikely;
|
||||
{
|
||||
// Do if
|
||||
reset();
|
||||
iterateAndNextNull(nodep->ifsp());
|
||||
int ifLikely = m_likely;
|
||||
int ifUnlikely = m_unlikely;
|
||||
// Do else
|
||||
reset();
|
||||
int ifLikely = m_likely;
|
||||
int ifUnlikely = m_unlikely;
|
||||
// Do else
|
||||
reset();
|
||||
iterateAndNextNull(nodep->elsesp());
|
||||
int elseLikely = m_likely;
|
||||
int elseUnlikely = m_unlikely;
|
||||
// Compute
|
||||
int likeness = ifLikely - ifUnlikely - (elseLikely - elseUnlikely);
|
||||
if (likeness>0) {
|
||||
nodep->branchPred(AstBranchPred::BP_LIKELY);
|
||||
} else if (likeness<0) {
|
||||
nodep->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
} // else leave unknown
|
||||
}
|
||||
m_likely = lastLikely;
|
||||
m_unlikely = lastUnlikely;
|
||||
int elseLikely = m_likely;
|
||||
int elseUnlikely = m_unlikely;
|
||||
// Compute
|
||||
int likeness = ifLikely - ifUnlikely - (elseLikely - elseUnlikely);
|
||||
if (likeness>0) {
|
||||
nodep->branchPred(AstBranchPred::BP_LIKELY);
|
||||
} else if (likeness<0) {
|
||||
nodep->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
} // else leave unknown
|
||||
}
|
||||
m_likely = lastLikely;
|
||||
m_unlikely = lastUnlikely;
|
||||
}
|
||||
virtual void visit(AstCCall* nodep) {
|
||||
checkUnlikely(nodep);
|
||||
nodep->funcp()->user1Inc();
|
||||
checkUnlikely(nodep);
|
||||
nodep->funcp()->user1Inc();
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
checkUnlikely(nodep);
|
||||
m_cfuncsp.push_back(nodep);
|
||||
checkUnlikely(nodep);
|
||||
m_cfuncsp.push_back(nodep);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
checkUnlikely(nodep);
|
||||
checkUnlikely(nodep);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
// METHODS
|
||||
void calc_tasks() {
|
||||
for (CFuncVec::iterator it=m_cfuncsp.begin(); it!=m_cfuncsp.end(); ++it) {
|
||||
AstCFunc* nodep = *it;
|
||||
if (!nodep->dontInline()) {
|
||||
nodep->isInline(true);
|
||||
}
|
||||
}
|
||||
for (CFuncVec::iterator it=m_cfuncsp.begin(); it!=m_cfuncsp.end(); ++it) {
|
||||
AstCFunc* nodep = *it;
|
||||
if (!nodep->dontInline()) {
|
||||
nodep->isInline(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
explicit BranchVisitor(AstNetlist* nodep) {
|
||||
reset();
|
||||
reset();
|
||||
iterateChildren(nodep);
|
||||
calc_tasks();
|
||||
calc_tasks();
|
||||
}
|
||||
virtual ~BranchVisitor() {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -35,4 +35,4 @@ public:
|
|||
static void branchAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
239
src/V3Broken.cpp
239
src/V3Broken.cpp
|
|
@ -20,8 +20,8 @@
|
|||
// V3Broken's Transformations:
|
||||
//
|
||||
// Entire netlist
|
||||
// Mark all nodes
|
||||
// Check all links point to marked nodes
|
||||
// Mark all nodes
|
||||
// Check all links point to marked nodes
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -47,125 +47,125 @@ private:
|
|||
// MEMBERS
|
||||
// For each node, we keep if it exists or not.
|
||||
typedef vl_unordered_map<const AstNode*,int> NodeMap; // Performance matters (when --debug)
|
||||
static NodeMap s_nodes; // Set of all nodes that exist
|
||||
static NodeMap s_nodes; // Set of all nodes that exist
|
||||
// BITMASK
|
||||
enum { FLAG_ALLOCATED = 0x01 }; // new() and not delete()ed
|
||||
enum { FLAG_IN_TREE = 0x02 }; // Is in netlist tree
|
||||
enum { FLAG_LINKABLE = 0x04 }; // Is in netlist tree, can be linked to
|
||||
enum { FLAG_LEAKED = 0x08 }; // Known to have been leaked
|
||||
enum { FLAG_UNDER_NOW = 0x10 }; // Is in tree as parent of current node
|
||||
enum { FLAG_ALLOCATED = 0x01 }; // new() and not delete()ed
|
||||
enum { FLAG_IN_TREE = 0x02 }; // Is in netlist tree
|
||||
enum { FLAG_LINKABLE = 0x04 }; // Is in netlist tree, can be linked to
|
||||
enum { FLAG_LEAKED = 0x08 }; // Known to have been leaked
|
||||
enum { FLAG_UNDER_NOW = 0x10 }; // Is in tree as parent of current node
|
||||
public:
|
||||
// METHODS
|
||||
static void deleted(const AstNode* nodep) {
|
||||
// Called by operator delete on any node - only if VL_LEAK_CHECKS
|
||||
// Called by operator delete on any node - only if VL_LEAK_CHECKS
|
||||
if (debug()>=9) cout<<"-nodeDel: "<<cvtToHex(nodep)<<endl;
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter==s_nodes.end() || !(iter->second & FLAG_ALLOCATED)) {
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter==s_nodes.end() || !(iter->second & FLAG_ALLOCATED)) {
|
||||
reinterpret_cast<const AstNode*>(nodep)
|
||||
->v3fatalSrc("Deleting AstNode object that was never tracked or already deleted");
|
||||
}
|
||||
if (iter!=s_nodes.end()) s_nodes.erase(iter);
|
||||
}
|
||||
if (iter!=s_nodes.end()) s_nodes.erase(iter);
|
||||
}
|
||||
#if defined(__GNUC__) && __GNUC__ == 4 && __GNUC_MINOR__ == 4
|
||||
// GCC 4.4.* compiler warning bug, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=39390
|
||||
# pragma GCC diagnostic ignored "-Wstrict-aliasing"
|
||||
#endif
|
||||
static void addNewed(const AstNode* nodep) {
|
||||
// Called by operator new on any node - only if VL_LEAK_CHECKS
|
||||
// Called by operator new on any node - only if VL_LEAK_CHECKS
|
||||
if (debug()>=9) cout<<"-nodeNew: "<<cvtToHex(nodep)<<endl;
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter!=s_nodes.end() || (iter->second & FLAG_ALLOCATED)) {
|
||||
nodep->v3fatalSrc("Newing AstNode object that is already allocated");
|
||||
}
|
||||
if (iter == s_nodes.end()) {
|
||||
int flags = FLAG_ALLOCATED; // This int needed to appease GCC 4.1.2
|
||||
s_nodes.insert(make_pair(nodep,flags));
|
||||
}
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter!=s_nodes.end() || (iter->second & FLAG_ALLOCATED)) {
|
||||
nodep->v3fatalSrc("Newing AstNode object that is already allocated");
|
||||
}
|
||||
if (iter == s_nodes.end()) {
|
||||
int flags = FLAG_ALLOCATED; // This int needed to appease GCC 4.1.2
|
||||
s_nodes.insert(make_pair(nodep, flags));
|
||||
}
|
||||
}
|
||||
static void setUnder(const AstNode* nodep, bool flag) {
|
||||
// Called by BrokenCheckVisitor when each node entered/exited
|
||||
if (!okIfLinkedTo(nodep)) return;
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter!=s_nodes.end()) {
|
||||
iter->second &= ~FLAG_UNDER_NOW;
|
||||
if (flag) iter->second |= FLAG_UNDER_NOW;
|
||||
}
|
||||
// Called by BrokenCheckVisitor when each node entered/exited
|
||||
if (!okIfLinkedTo(nodep)) return;
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter!=s_nodes.end()) {
|
||||
iter->second &= ~FLAG_UNDER_NOW;
|
||||
if (flag) iter->second |= FLAG_UNDER_NOW;
|
||||
}
|
||||
}
|
||||
static void addInTree(AstNode* nodep, bool linkable) {
|
||||
#ifndef VL_LEAK_CHECKS
|
||||
if (!linkable) return; // save some time, else the map will get huge!
|
||||
if (!linkable) return; // save some time, else the map will get huge!
|
||||
#endif
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter == s_nodes.end()) {
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter == s_nodes.end()) {
|
||||
#ifdef VL_LEAK_CHECKS
|
||||
nodep->v3fatalSrc("AstNode is in tree, but not allocated");
|
||||
nodep->v3fatalSrc("AstNode is in tree, but not allocated");
|
||||
#endif
|
||||
} else {
|
||||
if (!(iter->second & FLAG_ALLOCATED)) {
|
||||
} else {
|
||||
if (!(iter->second & FLAG_ALLOCATED)) {
|
||||
#ifdef VL_LEAK_CHECKS
|
||||
nodep->v3fatalSrc("AstNode is in tree, but not allocated");
|
||||
nodep->v3fatalSrc("AstNode is in tree, but not allocated");
|
||||
#endif
|
||||
}
|
||||
if (iter->second & FLAG_IN_TREE) {
|
||||
nodep->v3fatalSrc("AstNode is already in tree at another location");
|
||||
}
|
||||
}
|
||||
int or_flags = FLAG_IN_TREE | (linkable?FLAG_LINKABLE:0);
|
||||
if (iter == s_nodes.end()) {
|
||||
s_nodes.insert(make_pair(nodep,or_flags));
|
||||
} else {
|
||||
iter->second |= or_flags;
|
||||
}
|
||||
}
|
||||
if (iter->second & FLAG_IN_TREE) {
|
||||
nodep->v3fatalSrc("AstNode is already in tree at another location");
|
||||
}
|
||||
}
|
||||
int or_flags = FLAG_IN_TREE | (linkable?FLAG_LINKABLE:0);
|
||||
if (iter == s_nodes.end()) {
|
||||
s_nodes.insert(make_pair(nodep, or_flags));
|
||||
} else {
|
||||
iter->second |= or_flags;
|
||||
}
|
||||
}
|
||||
static bool okIfLinkedTo(const AstNode* nodep) {
|
||||
// Someone has a pointer to this node. Is it kosher?
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter == s_nodes.end()) return false;
|
||||
// Someone has a pointer to this node. Is it kosher?
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter == s_nodes.end()) return false;
|
||||
#ifdef VL_LEAK_CHECKS
|
||||
if (!(iter->second & FLAG_ALLOCATED)) return false;
|
||||
if (!(iter->second & FLAG_ALLOCATED)) return false;
|
||||
#endif
|
||||
if (!(iter->second & FLAG_IN_TREE)) return false;
|
||||
if (!(iter->second & FLAG_LINKABLE)) return false;
|
||||
return true;
|
||||
if (!(iter->second & FLAG_IN_TREE)) return false;
|
||||
if (!(iter->second & FLAG_LINKABLE)) return false;
|
||||
return true;
|
||||
}
|
||||
static bool okIfBelow(const AstNode* nodep) {
|
||||
// Must be linked to and below current node
|
||||
if (!okIfLinkedTo(nodep)) return false;
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter == s_nodes.end()) return false;
|
||||
if (!(iter->second & FLAG_UNDER_NOW)) return false;
|
||||
return true;
|
||||
// Must be linked to and below current node
|
||||
if (!okIfLinkedTo(nodep)) return false;
|
||||
NodeMap::iterator iter = s_nodes.find(nodep);
|
||||
if (iter == s_nodes.end()) return false;
|
||||
if (!(iter->second & FLAG_UNDER_NOW)) return false;
|
||||
return true;
|
||||
}
|
||||
static void prepForTree() {
|
||||
#ifndef VL_LEAK_CHECKS
|
||||
s_nodes.clear();
|
||||
s_nodes.clear();
|
||||
#endif
|
||||
for (NodeMap::iterator it = s_nodes.begin(); it != s_nodes.end(); ++it) {
|
||||
it->second &= ~FLAG_IN_TREE;
|
||||
it->second &= ~FLAG_LINKABLE;
|
||||
}
|
||||
for (NodeMap::iterator it = s_nodes.begin(); it != s_nodes.end(); ++it) {
|
||||
it->second &= ~FLAG_IN_TREE;
|
||||
it->second &= ~FLAG_LINKABLE;
|
||||
}
|
||||
}
|
||||
static void doneWithTree() {
|
||||
for (int backs=0; backs<2; backs++) { // Those with backp() are probably under one leaking without
|
||||
for (NodeMap::iterator it = s_nodes.begin(); it != s_nodes.end(); ++it) {
|
||||
if ((it->second & FLAG_ALLOCATED)
|
||||
&& !(it->second & FLAG_IN_TREE)
|
||||
&& !(it->second & FLAG_LEAKED)
|
||||
&& (it->first->backp() ? backs==1 : backs==0)) {
|
||||
// Use only AstNode::dump instead of the virtual one, as there
|
||||
// may be varp() and other cross links that are bad.
|
||||
if (v3Global.opt.debugCheck()) {
|
||||
for (int backs=0; backs<2; backs++) { // Those with backp() are probably under one leaking without
|
||||
for (NodeMap::iterator it = s_nodes.begin(); it != s_nodes.end(); ++it) {
|
||||
if ((it->second & FLAG_ALLOCATED)
|
||||
&& !(it->second & FLAG_IN_TREE)
|
||||
&& !(it->second & FLAG_LEAKED)
|
||||
&& (it->first->backp() ? backs==1 : backs==0)) {
|
||||
// Use only AstNode::dump instead of the virtual one, as there
|
||||
// may be varp() and other cross links that are bad.
|
||||
if (v3Global.opt.debugCheck()) {
|
||||
std::cerr<<"%Error: LeakedNode"<<(it->first->backp()?"Back: ":": ");
|
||||
AstNode* rawp = const_cast<AstNode*>
|
||||
(static_cast<const AstNode*>(it->first));
|
||||
rawp->AstNode::dump(std::cerr);
|
||||
std::cerr<<endl;
|
||||
V3Error::incErrors();
|
||||
}
|
||||
it->second |= FLAG_LEAKED;
|
||||
}
|
||||
}
|
||||
}
|
||||
V3Error::incErrors();
|
||||
}
|
||||
it->second |= FLAG_LEAKED;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
|
|
@ -190,16 +190,16 @@ class BrokenMarkVisitor : public AstNVisitor {
|
|||
// Mark every node in the tree
|
||||
private:
|
||||
// NODE STATE
|
||||
// Nothing! // This may be called deep inside other routines
|
||||
// // so userp and friends may not be used
|
||||
// Nothing! // This may be called deep inside other routines
|
||||
// // so userp and friends may not be used
|
||||
// METHODS
|
||||
void processAndIterate(AstNode* nodep) {
|
||||
BrokenTable::addInTree(nodep, nodep->maybePointedTo());
|
||||
BrokenTable::addInTree(nodep, nodep->maybePointedTo());
|
||||
iterateChildrenConst(nodep);
|
||||
}
|
||||
// VISITORS
|
||||
virtual void visit(AstNode* nodep) {
|
||||
processAndIterate(nodep);
|
||||
processAndIterate(nodep);
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
|
|
@ -215,17 +215,17 @@ public:
|
|||
class BrokenCheckVisitor : public AstNVisitor {
|
||||
private:
|
||||
void checkWidthMin(const AstNode* nodep) {
|
||||
if (nodep->width() != nodep->widthMin()
|
||||
&& v3Global.widthMinUsage()==VWidthMinUsage::MATCHES_WIDTH) {
|
||||
nodep->v3fatalSrc("Width != WidthMin");
|
||||
}
|
||||
if (nodep->width() != nodep->widthMin()
|
||||
&& v3Global.widthMinUsage()==VWidthMinUsage::MATCHES_WIDTH) {
|
||||
nodep->v3fatalSrc("Width != WidthMin");
|
||||
}
|
||||
}
|
||||
void processAndIterate(AstNode* nodep) {
|
||||
BrokenTable::setUnder(nodep,true);
|
||||
if (const char* whyp=nodep->broken()) {
|
||||
nodep->v3fatalSrc("Broken link in node (or something without maybePointedTo): "<<whyp);
|
||||
}
|
||||
if (nodep->dtypep()) {
|
||||
BrokenTable::setUnder(nodep, true);
|
||||
if (const char* whyp=nodep->broken()) {
|
||||
nodep->v3fatalSrc("Broken link in node (or something without maybePointedTo): "<<whyp);
|
||||
}
|
||||
if (nodep->dtypep()) {
|
||||
if (!nodep->dtypep()->brokeExists()) {
|
||||
nodep->v3fatalSrc("Broken link in node->dtypep() to "
|
||||
<<cvtToHex(nodep->dtypep()));
|
||||
|
|
@ -233,31 +233,34 @@ private:
|
|||
nodep->v3fatalSrc("Non-dtype link in node->dtypep() to "
|
||||
<<cvtToHex(nodep->dtypep()));
|
||||
}
|
||||
}
|
||||
if (v3Global.assertDTypesResolved()) {
|
||||
if (nodep->hasDType()) {
|
||||
if (!nodep->dtypep()) nodep->v3fatalSrc("No dtype on node with hasDType(): "<<nodep->prettyTypeName());
|
||||
} else {
|
||||
if (nodep->dtypep()) nodep->v3fatalSrc("DType on node without hasDType(): "<<nodep->prettyTypeName());
|
||||
}
|
||||
if (nodep->getChildDTypep()) nodep->v3fatalSrc("childDTypep() non-null on node after should have removed");
|
||||
}
|
||||
if (v3Global.assertDTypesResolved()) {
|
||||
if (nodep->hasDType()) {
|
||||
if (!nodep->dtypep()) nodep->v3fatalSrc(
|
||||
"No dtype on node with hasDType(): "<<nodep->prettyTypeName());
|
||||
} else {
|
||||
if (nodep->dtypep()) nodep->v3fatalSrc(
|
||||
"DType on node without hasDType(): "<<nodep->prettyTypeName());
|
||||
}
|
||||
if (nodep->getChildDTypep()) nodep->v3fatalSrc(
|
||||
"childDTypep() non-null on node after should have removed");
|
||||
if (const AstNodeDType* dnodep = VN_CAST(nodep, NodeDType)) checkWidthMin(dnodep);
|
||||
}
|
||||
checkWidthMin(nodep);
|
||||
}
|
||||
checkWidthMin(nodep);
|
||||
iterateChildrenConst(nodep);
|
||||
BrokenTable::setUnder(nodep,false);
|
||||
BrokenTable::setUnder(nodep, false);
|
||||
}
|
||||
virtual void visit(AstNodeAssign* nodep) {
|
||||
processAndIterate(nodep);
|
||||
if (v3Global.assertDTypesResolved()
|
||||
&& nodep->brokeLhsMustBeLvalue()
|
||||
processAndIterate(nodep);
|
||||
if (v3Global.assertDTypesResolved()
|
||||
&& nodep->brokeLhsMustBeLvalue()
|
||||
&& VN_IS(nodep->lhsp(), NodeVarRef)
|
||||
&& !VN_CAST(nodep->lhsp(), NodeVarRef)->lvalue()) {
|
||||
nodep->v3fatalSrc("Assignment LHS is not an lvalue");
|
||||
}
|
||||
nodep->v3fatalSrc("Assignment LHS is not an lvalue");
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
processAndIterate(nodep);
|
||||
processAndIterate(nodep);
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
|
|
@ -274,15 +277,15 @@ void V3Broken::brokenAll(AstNetlist* nodep) {
|
|||
//UINFO(9,__FUNCTION__<<": "<<endl);
|
||||
static bool inBroken = false;
|
||||
if (inBroken) {
|
||||
// A error called by broken can recurse back into broken; avoid this
|
||||
UINFO(1,"Broken called under broken, skipping recursion.\n");
|
||||
// A error called by broken can recurse back into broken; avoid this
|
||||
UINFO(1,"Broken called under broken, skipping recursion.\n");
|
||||
} else {
|
||||
inBroken = true;
|
||||
BrokenTable::prepForTree();
|
||||
BrokenMarkVisitor mvisitor (nodep);
|
||||
BrokenCheckVisitor cvisitor (nodep);
|
||||
BrokenTable::doneWithTree();
|
||||
inBroken = false;
|
||||
inBroken = true;
|
||||
BrokenTable::prepForTree();
|
||||
BrokenMarkVisitor mvisitor (nodep);
|
||||
BrokenCheckVisitor cvisitor (nodep);
|
||||
BrokenTable::doneWithTree();
|
||||
inBroken = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -36,4 +36,4 @@ public:
|
|||
static void deleted(AstNode* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
147
src/V3CCtors.cpp
147
src/V3CCtors.cpp
|
|
@ -18,14 +18,14 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// V3CCtors's Transformations:
|
||||
// Iterates over all modules and
|
||||
// for all AstVar, create a creates a AstCReset node in an _ctor_var_reset AstCFunc.
|
||||
// for all AstCoverDecl, move the declaration into a _configure_coverage AstCFunc.
|
||||
// For each variable that needs reset, add a AstCReset node.
|
||||
// Iterates over all modules and
|
||||
// for all AstVar, create a creates a AstCReset node in an _ctor_var_reset AstCFunc.
|
||||
// for all AstCoverDecl, move the declaration into a _configure_coverage AstCFunc.
|
||||
// For each variable that needs reset, add a AstCReset node.
|
||||
//
|
||||
// For primary inputs, add _eval_debug_assertions.
|
||||
// For primary inputs, add _eval_debug_assertions.
|
||||
//
|
||||
// This transformation honors outputSplitCFuncs.
|
||||
// This transformation honors outputSplitCFuncs.
|
||||
//*************************************************************************
|
||||
|
||||
#include "config_build.h"
|
||||
|
|
@ -43,59 +43,60 @@
|
|||
|
||||
class V3CCtorsVisitor {
|
||||
private:
|
||||
string m_basename;
|
||||
string m_argsp;
|
||||
string m_callargsp;
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_tlFuncp; // Top level function being built
|
||||
AstCFunc* m_funcp; // Current function
|
||||
int m_numStmts; // Number of statements output
|
||||
int m_funcNum; // Function number being built
|
||||
string m_basename;
|
||||
string m_argsp;
|
||||
string m_callargsp;
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_tlFuncp; // Top level function being built
|
||||
AstCFunc* m_funcp; // Current function
|
||||
int m_numStmts; // Number of statements output
|
||||
int m_funcNum; // Function number being built
|
||||
|
||||
public:
|
||||
void add(AstNode* nodep) {
|
||||
if (v3Global.opt.outputSplitCFuncs()
|
||||
&& v3Global.opt.outputSplitCFuncs() < m_numStmts) {
|
||||
m_funcp = NULL;
|
||||
}
|
||||
if (!m_funcp) {
|
||||
m_funcp = new AstCFunc(m_modp->fileline(), m_basename + "_" + cvtToStr(++m_funcNum), NULL, "void");
|
||||
m_funcp->isStatic(false);
|
||||
m_funcp->declPrivate(true);
|
||||
m_funcp->slow(true);
|
||||
m_funcp->argTypes(m_argsp);
|
||||
m_modp->addStmtp(m_funcp);
|
||||
if (v3Global.opt.outputSplitCFuncs()
|
||||
&& v3Global.opt.outputSplitCFuncs() < m_numStmts) {
|
||||
m_funcp = NULL;
|
||||
}
|
||||
if (!m_funcp) {
|
||||
m_funcp = new AstCFunc(m_modp->fileline(),
|
||||
m_basename+"_"+cvtToStr(++m_funcNum), NULL, "void");
|
||||
m_funcp->isStatic(false);
|
||||
m_funcp->declPrivate(true);
|
||||
m_funcp->slow(true);
|
||||
m_funcp->argTypes(m_argsp);
|
||||
m_modp->addStmtp(m_funcp);
|
||||
|
||||
// Add a top call to it
|
||||
AstCCall* callp = new AstCCall(m_modp->fileline(), m_funcp);
|
||||
callp->argTypes(m_callargsp);
|
||||
// Add a top call to it
|
||||
AstCCall* callp = new AstCCall(m_modp->fileline(), m_funcp);
|
||||
callp->argTypes(m_callargsp);
|
||||
|
||||
m_tlFuncp->addStmtsp(callp);
|
||||
m_numStmts = 0;
|
||||
}
|
||||
m_funcp->addStmtsp(nodep);
|
||||
m_numStmts += 1;
|
||||
m_tlFuncp->addStmtsp(callp);
|
||||
m_numStmts = 0;
|
||||
}
|
||||
m_funcp->addStmtsp(nodep);
|
||||
m_numStmts += 1;
|
||||
}
|
||||
|
||||
V3CCtorsVisitor(AstNodeModule* nodep, const string& basename,
|
||||
const string& argsp="", const string& callargsp="",
|
||||
const string& stmt="") {
|
||||
m_basename = basename;
|
||||
m_argsp = argsp;
|
||||
m_callargsp = callargsp;
|
||||
m_modp = nodep;
|
||||
m_numStmts = 0;
|
||||
m_funcNum = 0;
|
||||
m_tlFuncp = new AstCFunc(nodep->fileline(), basename, NULL, "void");
|
||||
m_tlFuncp->declPrivate(true);
|
||||
m_tlFuncp->isStatic(false);
|
||||
m_tlFuncp->slow(true);
|
||||
m_tlFuncp->argTypes(m_argsp);
|
||||
if (stmt != "") {
|
||||
m_tlFuncp->addStmtsp(new AstCStmt(nodep->fileline(), stmt));
|
||||
}
|
||||
m_funcp = m_tlFuncp;
|
||||
m_modp->addStmtp(m_tlFuncp);
|
||||
const string& stmt="") {
|
||||
m_basename = basename;
|
||||
m_argsp = argsp;
|
||||
m_callargsp = callargsp;
|
||||
m_modp = nodep;
|
||||
m_numStmts = 0;
|
||||
m_funcNum = 0;
|
||||
m_tlFuncp = new AstCFunc(nodep->fileline(), basename, NULL, "void");
|
||||
m_tlFuncp->declPrivate(true);
|
||||
m_tlFuncp->isStatic(false);
|
||||
m_tlFuncp->slow(true);
|
||||
m_tlFuncp->argTypes(m_argsp);
|
||||
if (stmt != "") {
|
||||
m_tlFuncp->addStmtsp(new AstCStmt(nodep->fileline(), stmt));
|
||||
}
|
||||
m_funcp = m_tlFuncp;
|
||||
m_modp->addStmtp(m_tlFuncp);
|
||||
}
|
||||
~V3CCtorsVisitor() {}
|
||||
private:
|
||||
|
|
@ -116,36 +117,38 @@ void V3CCtors::evalAsserts() {
|
|||
if (AstVar* varp = VN_CAST(np, Var)) {
|
||||
if (varp->isPrimaryInish() && !varp->isSc()) {
|
||||
if (AstBasicDType* basicp = VN_CAST(varp->dtypeSkipRefp(), BasicDType)) {
|
||||
int storedWidth = basicp->widthAlignBytes() * 8;
|
||||
int lastWordWidth = varp->width() % storedWidth;
|
||||
if (lastWordWidth != 0) {
|
||||
// if (signal & CONST(upper_non_clean_mask)) { fail; }
|
||||
AstNode* newp = new AstVarRef(varp->fileline(), varp, false);
|
||||
if (varp->isWide()) {
|
||||
newp = new AstWordSel(varp->fileline(), newp,
|
||||
new AstConst(varp->fileline(), varp->widthWords()-1));
|
||||
}
|
||||
int storedWidth = basicp->widthAlignBytes() * 8;
|
||||
int lastWordWidth = varp->width() % storedWidth;
|
||||
if (lastWordWidth != 0) {
|
||||
// if (signal & CONST(upper_non_clean_mask)) { fail; }
|
||||
AstNode* newp = new AstVarRef(varp->fileline(), varp, false);
|
||||
if (varp->isWide()) {
|
||||
newp = new AstWordSel(
|
||||
varp->fileline(), newp,
|
||||
new AstConst(varp->fileline(), varp->widthWords()-1));
|
||||
}
|
||||
uint64_t value = VL_MASK_Q(storedWidth) & ~VL_MASK_Q(lastWordWidth);
|
||||
V3Number num (varp, storedWidth, value);
|
||||
newp = new AstAnd(varp->fileline(), newp,
|
||||
new AstConst(varp->fileline(), num));
|
||||
AstNodeIf* ifp = new AstIf(varp->fileline(), newp,
|
||||
new AstConst(varp->fileline(), num));
|
||||
AstNodeIf* ifp = new AstIf(varp->fileline(), newp,
|
||||
new AstCStmt(varp->fileline(),
|
||||
"Verilated::overWidthError(\""+varp->prettyName()+"\");"));
|
||||
ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
newp = ifp;
|
||||
funcp->addStmtsp(newp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
ifp->branchPred(AstBranchPred::BP_UNLIKELY);
|
||||
newp = ifp;
|
||||
funcp->addStmtsp(newp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void V3CCtors::cctorsAll() {
|
||||
UINFO(2,__FUNCTION__<<": "<<endl);
|
||||
evalAsserts();
|
||||
for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; modp=VN_CAST(modp->nextp(), NodeModule)) {
|
||||
for (AstNodeModule* modp = v3Global.rootp()->modulesp();
|
||||
modp; modp = VN_CAST(modp->nextp(), NodeModule)) {
|
||||
// Process each module in turn
|
||||
{
|
||||
V3CCtorsVisitor var_reset (modp, "_ctor_var_reset");
|
||||
|
|
@ -153,14 +156,16 @@ void V3CCtors::cctorsAll() {
|
|||
if (AstVar* varp = VN_CAST(np, Var)) {
|
||||
if (!varp->isIfaceParent() && !varp->isIfaceRef()
|
||||
&& !varp->noReset()) {
|
||||
var_reset.add(new AstCReset(varp->fileline(), new AstVarRef(varp->fileline(), varp, true)));
|
||||
var_reset.add(new AstCReset(varp->fileline(),
|
||||
new AstVarRef(varp->fileline(), varp, true)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (v3Global.opt.coverage()) {
|
||||
V3CCtorsVisitor configure_coverage
|
||||
(modp, "_configure_coverage", EmitCBaseVisitor::symClassVar()+ ", bool first", "vlSymsp, first",
|
||||
(modp, "_configure_coverage",
|
||||
EmitCBaseVisitor::symClassVar()+ ", bool first", "vlSymsp, first",
|
||||
"if (0 && vlSymsp && first) {} // Prevent unused\n");
|
||||
for (AstNode* np = modp->stmtsp(); np; np = np->nextp()) {
|
||||
if (AstCoverDecl* coverp = VN_CAST(np, CoverDecl)) {
|
||||
|
|
|
|||
|
|
@ -37,4 +37,4 @@ private:
|
|||
};
|
||||
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
654
src/V3Case.cpp
654
src/V3Case.cpp
|
|
@ -20,20 +20,21 @@
|
|||
// V3Case's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// TBD: Eliminate tristates by adding __in, __inen, __en wires in parallel
|
||||
// Need __en in changed list if a signal is on the LHS of a assign
|
||||
// Cases:
|
||||
// CASE(v) CASEITEM(items,body) -> IF (OR (EQ (AND v mask)
|
||||
// (AND item1 mask))
|
||||
// (other items))
|
||||
// body
|
||||
// Or, converts to a if/else tree.
|
||||
// FUTURES:
|
||||
// Large 16+ bit tables with constants and no masking (address muxes)
|
||||
// TBD: Eliminate tristates by adding __in, __inen, __en wires in parallel
|
||||
// Need __en in changed list if a signal is on the LHS of a assign
|
||||
// Cases:
|
||||
// CASE(v) CASEITEM(items,body) -> IF (OR (EQ (AND v mask)
|
||||
// (AND item1 mask))
|
||||
// (other items))
|
||||
// body
|
||||
// Or, converts to a if/else tree.
|
||||
// FUTURES:
|
||||
// Large 16+ bit tables with constants and no masking (address muxes)
|
||||
// Enter all into std::multimap, sort by value and use a tree of < and == compares.
|
||||
// "Diagonal" find of {rightmost,leftmost} bit {set,clear}
|
||||
// "Diagonal" find of {rightmost,leftmost} bit {set,clear}
|
||||
// Ignoring mask, check each value is unique (using std::multimap as above?)
|
||||
// Each branch is then mask-and-compare operation (IE <000000001_000000000 at midpoint.)
|
||||
// Each branch is then mask-and-compare operation (IE
|
||||
// <000000001_000000000 at midpoint.)
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -48,60 +49,62 @@
|
|||
#include <algorithm>
|
||||
#include <cstdarg>
|
||||
|
||||
#define CASE_OVERLAP_WIDTH 12 // Maximum width we can check for overlaps in
|
||||
#define CASE_BARF 999999 // Magic width when non-constant
|
||||
#define CASE_ENCODER_GROUP_DEPTH 8 // Levels of priority to be ORed together in top IF tree
|
||||
#define CASE_OVERLAP_WIDTH 12 // Maximum width we can check for overlaps in
|
||||
#define CASE_BARF 999999 // Magic width when non-constant
|
||||
#define CASE_ENCODER_GROUP_DEPTH 8 // Levels of priority to be ORed together in top IF tree
|
||||
|
||||
//######################################################################
|
||||
|
||||
class CaseLintVisitor : public AstNVisitor {
|
||||
private:
|
||||
AstNodeCase* m_caseExprp; // Under a CASE value node, if so the relevant case statement
|
||||
AstNodeCase* m_caseExprp; // Under a CASE value node, if so the relevant case statement
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
virtual void visit(AstNodeCase* nodep) {
|
||||
if (VN_IS(nodep, Case) && VN_CAST(nodep, Case)->casex()) {
|
||||
nodep->v3warn(CASEX,"Suggest casez (with ?'s) in place of casex (with X's)");
|
||||
}
|
||||
// Detect multiple defaults
|
||||
bool hitDefault = false;
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
if (itemp->isDefault()) {
|
||||
if (hitDefault) {
|
||||
nodep->v3error("Multiple default statements in case statement.");
|
||||
}
|
||||
hitDefault = true;
|
||||
}
|
||||
}
|
||||
nodep->v3warn(CASEX, "Suggest casez (with ?'s) in place of casex (with X's)");
|
||||
}
|
||||
// Detect multiple defaults
|
||||
bool hitDefault = false;
|
||||
for (AstCaseItem* itemp = nodep->itemsp();
|
||||
itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
if (itemp->isDefault()) {
|
||||
if (hitDefault) {
|
||||
nodep->v3error("Multiple default statements in case statement.");
|
||||
}
|
||||
hitDefault = true;
|
||||
}
|
||||
}
|
||||
|
||||
// Check for X/Z in non-casex statements
|
||||
{
|
||||
m_caseExprp = nodep;
|
||||
// Check for X/Z in non-casex statements
|
||||
{
|
||||
m_caseExprp = nodep;
|
||||
iterate(nodep->exprp());
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
for (AstCaseItem* itemp = nodep->itemsp();
|
||||
itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
iterateAndNextNull(itemp->condsp());
|
||||
}
|
||||
m_caseExprp = NULL;
|
||||
}
|
||||
}
|
||||
m_caseExprp = NULL;
|
||||
}
|
||||
}
|
||||
virtual void visit(AstConst* nodep) {
|
||||
// See also neverItem
|
||||
if (m_caseExprp && nodep->num().isFourState()) {
|
||||
// See also neverItem
|
||||
if (m_caseExprp && nodep->num().isFourState()) {
|
||||
if (VN_IS(m_caseExprp, GenCase)) {
|
||||
nodep->v3error("Use of x/? constant in generate case statement, (no such thing as 'generate casez')");
|
||||
nodep->v3error("Use of x/? constant in generate case statement, (no such thing as 'generate casez')");
|
||||
} else if (VN_IS(m_caseExprp, Case) && VN_CAST(m_caseExprp, Case)->casex()) {
|
||||
// Don't sweat it, we already complained about casex in general
|
||||
// Don't sweat it, we already complained about casex in general
|
||||
} else if (VN_IS(m_caseExprp, Case) && (VN_CAST(m_caseExprp, Case)->casez()
|
||||
|| VN_CAST(m_caseExprp, Case)->caseInside())) {
|
||||
if (nodep->num().isUnknown()) {
|
||||
nodep->v3warn(CASEWITHX, "Use of x constant in casez statement, (perhaps intended ?/z in constant)");
|
||||
}
|
||||
} else {
|
||||
nodep->v3warn(CASEWITHX, "Use of x/? constant in case statement, (perhaps intended casex/casez)");
|
||||
}
|
||||
}
|
||||
if (nodep->num().isUnknown()) {
|
||||
nodep->v3warn(CASEWITHX, "Use of x constant in casez statement, (perhaps intended ?/z in constant)");
|
||||
}
|
||||
} else {
|
||||
nodep->v3warn(CASEWITHX, "Use of x/? constant in case statement, (perhaps intended casex/casez)");
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
|
|
@ -109,7 +112,7 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit CaseLintVisitor(AstNodeCase* nodep) {
|
||||
m_caseExprp = NULL;
|
||||
m_caseExprp = NULL;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~CaseLintVisitor() {}
|
||||
|
|
@ -122,340 +125,347 @@ class CaseVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared each Case
|
||||
// AstIf::user3() -> bool. Set true to indicate clone not needed
|
||||
AstUser3InUse m_inuser3;
|
||||
// AstIf::user3() -> bool. Set true to indicate clone not needed
|
||||
AstUser3InUse m_inuser3;
|
||||
|
||||
// STATE
|
||||
V3Double0 m_statCaseFast; // Statistic tracking
|
||||
V3Double0 m_statCaseSlow; // Statistic tracking
|
||||
V3Double0 m_statCaseFast; // Statistic tracking
|
||||
V3Double0 m_statCaseSlow; // Statistic tracking
|
||||
|
||||
// Per-CASE
|
||||
int m_caseWidth; // Width of valueItems
|
||||
int m_caseItems; // Number of caseItem unique values
|
||||
bool m_caseNoOverlapsAllCovered; // Proven to be synopsys parallel_case compliant
|
||||
AstNode* m_valueItem[1<<CASE_OVERLAP_WIDTH]; // For each possible value, the case branch we need
|
||||
int m_caseWidth; // Width of valueItems
|
||||
int m_caseItems; // Number of caseItem unique values
|
||||
bool m_caseNoOverlapsAllCovered; // Proven to be synopsys parallel_case compliant
|
||||
AstNode* m_valueItem[1<<CASE_OVERLAP_WIDTH]; // For each possible value, the case branch we need
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
bool isCaseTreeFast(AstCase* nodep) {
|
||||
int width = 0;
|
||||
bool opaque = false;
|
||||
m_caseItems = 0;
|
||||
m_caseNoOverlapsAllCovered = true;
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondp->nextp()) {
|
||||
if (icondp->width() > width) width = icondp->width();
|
||||
if (icondp->isDouble()) opaque = true;
|
||||
int width = 0;
|
||||
bool opaque = false;
|
||||
m_caseItems = 0;
|
||||
m_caseNoOverlapsAllCovered = true;
|
||||
for (AstCaseItem* itemp = nodep->itemsp();
|
||||
itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondp->nextp()) {
|
||||
if (icondp->width() > width) width = icondp->width();
|
||||
if (icondp->isDouble()) opaque = true;
|
||||
if (!VN_IS(icondp, Const)) width = CASE_BARF; // Can't parse; not a constant
|
||||
m_caseItems++;
|
||||
}
|
||||
}
|
||||
m_caseWidth = width;
|
||||
if (width==0 || width > CASE_OVERLAP_WIDTH || opaque) {
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
return false; // Too wide for analysis
|
||||
}
|
||||
UINFO(8,"Simple case statement: "<<nodep<<endl);
|
||||
// Zero list of items for each value
|
||||
m_caseItems++;
|
||||
}
|
||||
}
|
||||
m_caseWidth = width;
|
||||
if (width==0 || width > CASE_OVERLAP_WIDTH || opaque) {
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
return false; // Too wide for analysis
|
||||
}
|
||||
UINFO(8,"Simple case statement: "<<nodep<<endl);
|
||||
// Zero list of items for each value
|
||||
for (uint32_t i=0; i<(1UL<<m_caseWidth); ++i) m_valueItem[i] = NULL;
|
||||
// Now pick up the values for each assignment
|
||||
// We can cheat and use uint32_t's because we only support narrow case's
|
||||
bool bitched = false;
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondp->nextp()) {
|
||||
//if (debug()>=9) icondp->dumpTree(cout," caseitem: ");
|
||||
// Now pick up the values for each assignment
|
||||
// We can cheat and use uint32_t's because we only support narrow case's
|
||||
bool bitched = false;
|
||||
for (AstCaseItem* itemp = nodep->itemsp();
|
||||
itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondp->nextp()) {
|
||||
//if (debug()>=9) icondp->dumpTree(cout, " caseitem: ");
|
||||
AstConst* iconstp = VN_CAST(icondp, Const);
|
||||
if (!iconstp) nodep->v3fatalSrc("above 'can't parse' should have caught this");
|
||||
if (neverItem(nodep, iconstp)) {
|
||||
// X in casez can't ever be executed
|
||||
} else {
|
||||
if (!iconstp) nodep->v3fatalSrc("above 'can't parse' should have caught this");
|
||||
if (neverItem(nodep, iconstp)) {
|
||||
// X in casez can't ever be executed
|
||||
} else {
|
||||
V3Number nummask (itemp, iconstp->width());
|
||||
nummask.opBitsNonX(iconstp->num());
|
||||
uint32_t mask = nummask.toUInt();
|
||||
V3Number numval (itemp, iconstp->width());
|
||||
numval.opBitsOne(iconstp->num());
|
||||
uint32_t val = numval.toUInt();
|
||||
numval.opBitsOne(iconstp->num());
|
||||
uint32_t val = numval.toUInt();
|
||||
for (uint32_t i=0; i<(1UL<<m_caseWidth); ++i) {
|
||||
if ((i & mask) == val) {
|
||||
if (!m_valueItem[i]) {
|
||||
m_valueItem[i] = itemp;
|
||||
} else if (!itemp->ignoreOverlap() && !bitched) {
|
||||
itemp->v3warn(CASEOVERLAP,"Case values overlap (example pattern 0x"<<std::hex<<i<<")");
|
||||
bitched = true;
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Defaults were moved to last in the caseitem list by V3LinkDot
|
||||
if (itemp->isDefault()) { // Case statement's default... Fill the table
|
||||
if ((i & mask) == val) {
|
||||
if (!m_valueItem[i]) {
|
||||
m_valueItem[i] = itemp;
|
||||
} else if (!itemp->ignoreOverlap() && !bitched) {
|
||||
itemp->v3warn(CASEOVERLAP, "Case values overlap (example pattern 0x"
|
||||
<<std::hex<<i<<")");
|
||||
bitched = true;
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Defaults were moved to last in the caseitem list by V3LinkDot
|
||||
if (itemp->isDefault()) { // Case statement's default... Fill the table
|
||||
for (uint32_t i=0; i<(1UL<<m_caseWidth); ++i) {
|
||||
if (!m_valueItem[i]) m_valueItem[i] = itemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!m_valueItem[i]) m_valueItem[i] = itemp;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (uint32_t i=0; i<(1UL<<m_caseWidth); ++i) {
|
||||
if (!m_valueItem[i]) {
|
||||
nodep->v3warn(CASEINCOMPLETE,"Case values incompletely covered (example pattern 0x"<<std::hex<<i<<")");
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (m_caseItems <= 3) return false; // Not worth simplifing
|
||||
// Convert valueItem from AstCaseItem* to the expression
|
||||
// Not done earlier, as we may now have a NULL because it's just a ";" NOP branch
|
||||
if (!m_valueItem[i]) {
|
||||
nodep->v3warn(CASEINCOMPLETE, "Case values incompletely covered (example pattern 0x"
|
||||
<<std::hex<<i<<")");
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (m_caseItems <= 3) return false; // Not worth simplifing
|
||||
// Convert valueItem from AstCaseItem* to the expression
|
||||
// Not done earlier, as we may now have a NULL because it's just a ";" NOP branch
|
||||
for (uint32_t i=0; i<(1UL<<m_caseWidth); ++i) {
|
||||
m_valueItem[i] = VN_CAST(m_valueItem[i], CaseItem)->bodysp();
|
||||
}
|
||||
return true; // All is fine
|
||||
}
|
||||
return true; // All is fine
|
||||
}
|
||||
|
||||
AstNode* replaceCaseFastRecurse(AstNode* cexprp, int msb, uint32_t upperValue) {
|
||||
if (msb<0) {
|
||||
// There's no space for a IF. We know upperValue is thus down to a specific
|
||||
// exact value, so just return the tree value
|
||||
// Note can't clone here, as we're going to check for equivelence above
|
||||
return m_valueItem[upperValue];
|
||||
}
|
||||
else {
|
||||
// Make left and right subtrees
|
||||
// cexpr[msb:lsb] == 1
|
||||
AstNode* tree0p = replaceCaseFastRecurse(cexprp, msb-1, upperValue | 0);
|
||||
AstNode* tree1p = replaceCaseFastRecurse(cexprp, msb-1, upperValue | (1UL<<msb));
|
||||
if (msb<0) {
|
||||
// There's no space for a IF. We know upperValue is thus down to a specific
|
||||
// exact value, so just return the tree value
|
||||
// Note can't clone here, as we're going to check for equivelence above
|
||||
return m_valueItem[upperValue];
|
||||
}
|
||||
else {
|
||||
// Make left and right subtrees
|
||||
// cexpr[msb:lsb] == 1
|
||||
AstNode* tree0p = replaceCaseFastRecurse(cexprp, msb-1, upperValue | 0);
|
||||
AstNode* tree1p = replaceCaseFastRecurse(cexprp, msb-1, upperValue | (1UL<<msb));
|
||||
|
||||
if (tree0p == tree1p) {
|
||||
// Same logic on both sides, so we can just return one of 'em
|
||||
return tree0p;
|
||||
}
|
||||
// We could have a "checkerboard" with A B A B, we can use the same IF on both edges
|
||||
bool same = true;
|
||||
for (uint32_t a=upperValue,
|
||||
b=(upperValue|(1UL<<msb));
|
||||
a < (upperValue|(1UL<<msb));
|
||||
a++, b++) {
|
||||
if (m_valueItem[a] != m_valueItem[b]) { same=false; break; }
|
||||
}
|
||||
if (same) {
|
||||
tree1p->deleteTree(); VL_DANGLING(tree1p);
|
||||
return tree0p;
|
||||
}
|
||||
if (tree0p == tree1p) {
|
||||
// Same logic on both sides, so we can just return one of 'em
|
||||
return tree0p;
|
||||
}
|
||||
// We could have a "checkerboard" with A B A B, we can use the same IF on both edges
|
||||
bool same = true;
|
||||
for (uint32_t a=upperValue,
|
||||
b=(upperValue|(1UL<<msb));
|
||||
a < (upperValue|(1UL<<msb));
|
||||
a++, b++) {
|
||||
if (m_valueItem[a] != m_valueItem[b]) { same = false; break; }
|
||||
}
|
||||
if (same) {
|
||||
tree1p->deleteTree(); VL_DANGLING(tree1p);
|
||||
return tree0p;
|
||||
}
|
||||
|
||||
// Must have differing logic, so make a selection
|
||||
// Must have differing logic, so make a selection
|
||||
|
||||
// Case expressions can't be linked twice, so clone them
|
||||
if (tree0p && !tree0p->user3()) tree0p = tree0p->cloneTree(true);
|
||||
if (tree1p && !tree1p->user3()) tree1p = tree1p->cloneTree(true);
|
||||
// Case expressions can't be linked twice, so clone them
|
||||
if (tree0p && !tree0p->user3()) tree0p = tree0p->cloneTree(true);
|
||||
if (tree1p && !tree1p->user3()) tree1p = tree1p->cloneTree(true);
|
||||
|
||||
// Alternate scheme if we ever do multiple bits at a time:
|
||||
//V3Number nummask (cexprp, cexprp->width(), (1UL<<msb));
|
||||
//AstNode* and1p = new AstAnd(cexprp->fileline(), cexprp->cloneTree(false),
|
||||
// new AstConst(cexprp->fileline(), nummask));
|
||||
AstNode* and1p = new AstSel(cexprp->fileline(), cexprp->cloneTree(false),
|
||||
msb, 1);
|
||||
AstNode* eqp = new AstNeq(cexprp->fileline(),
|
||||
new AstConst(cexprp->fileline(), 0),
|
||||
and1p);
|
||||
AstIf* ifp = new AstIf(cexprp->fileline(), eqp, tree1p, tree0p);
|
||||
ifp->user3(1); // So we don't bother to clone it
|
||||
return ifp;
|
||||
}
|
||||
// new AstConst(cexprp->fileline(), nummask));
|
||||
AstNode* and1p = new AstSel(cexprp->fileline(), cexprp->cloneTree(false),
|
||||
msb, 1);
|
||||
AstNode* eqp = new AstNeq(cexprp->fileline(),
|
||||
new AstConst(cexprp->fileline(), 0),
|
||||
and1p);
|
||||
AstIf* ifp = new AstIf(cexprp->fileline(), eqp, tree1p, tree0p);
|
||||
ifp->user3(1); // So we don't bother to clone it
|
||||
return ifp;
|
||||
}
|
||||
}
|
||||
|
||||
void replaceCaseFast(AstCase* nodep) {
|
||||
// CASEx(cexpr,....
|
||||
// -> tree of IF(msb, IF(msb-1, 11, 10)
|
||||
// IF(msb-1, 01, 00))
|
||||
AstNode* cexprp = nodep->exprp()->unlinkFrBack();
|
||||
// CASEx(cexpr,....
|
||||
// -> tree of IF(msb, IF(msb-1, 11, 10)
|
||||
// IF(msb-1, 01, 00))
|
||||
AstNode* cexprp = nodep->exprp()->unlinkFrBack();
|
||||
|
||||
if (debug()>=9) {
|
||||
if (debug()>=9) {
|
||||
for (uint32_t i=0; i<(1UL<<m_caseWidth); ++i) {
|
||||
if (AstNode* itemp = m_valueItem[i]) {
|
||||
if (AstNode* itemp = m_valueItem[i]) {
|
||||
UINFO(9,"Value "<<std::hex<<i<<" "<<itemp<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Handle any assertions
|
||||
replaceCaseParallel(nodep, m_caseNoOverlapsAllCovered);
|
||||
// Handle any assertions
|
||||
replaceCaseParallel(nodep, m_caseNoOverlapsAllCovered);
|
||||
|
||||
AstNode::user3ClearTree();
|
||||
AstNode* ifrootp = replaceCaseFastRecurse(cexprp, m_caseWidth-1, 0UL);
|
||||
// Case expressions can't be linked twice, so clone them
|
||||
if (ifrootp && !ifrootp->user3()) ifrootp = ifrootp->cloneTree(true);
|
||||
AstNode::user3ClearTree();
|
||||
AstNode* ifrootp = replaceCaseFastRecurse(cexprp, m_caseWidth-1, 0UL);
|
||||
// Case expressions can't be linked twice, so clone them
|
||||
if (ifrootp && !ifrootp->user3()) ifrootp = ifrootp->cloneTree(true);
|
||||
|
||||
if (ifrootp) nodep->replaceWith(ifrootp);
|
||||
else nodep->unlinkFrBack();
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
cexprp->deleteTree(); VL_DANGLING(cexprp);
|
||||
if (debug()>=9) ifrootp->dumpTree(cout," _simp: ");
|
||||
if (ifrootp) nodep->replaceWith(ifrootp);
|
||||
else nodep->unlinkFrBack();
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
cexprp->deleteTree(); VL_DANGLING(cexprp);
|
||||
if (debug()>=9) ifrootp->dumpTree(cout, " _simp: ");
|
||||
}
|
||||
|
||||
void replaceCaseComplicated(AstCase* nodep) {
|
||||
// CASEx(cexpr,ITEM(icond1,istmts1),ITEM(icond2,istmts2),ITEM(default,istmts3))
|
||||
// -> IF((cexpr==icond1),istmts1,
|
||||
// IF((EQ (AND MASK cexpr) (AND MASK icond1)
|
||||
// ,istmts2, istmts3
|
||||
AstNode* cexprp = nodep->exprp()->unlinkFrBack();
|
||||
// We'll do this in two stages. First stage, convert the conditions to
|
||||
// the appropriate IF AND terms.
|
||||
if (debug()>=9) nodep->dumpTree(cout," _comp_IN: ");
|
||||
bool hadDefault = false;
|
||||
// CASEx(cexpr,ITEM(icond1,istmts1),ITEM(icond2,istmts2),ITEM(default,istmts3))
|
||||
// -> IF((cexpr==icond1),istmts1,
|
||||
// IF((EQ (AND MASK cexpr) (AND MASK icond1)
|
||||
// ,istmts2, istmts3
|
||||
AstNode* cexprp = nodep->exprp()->unlinkFrBack();
|
||||
// We'll do this in two stages. First stage, convert the conditions to
|
||||
// the appropriate IF AND terms.
|
||||
if (debug()>=9) nodep->dumpTree(cout, " _comp_IN: ");
|
||||
bool hadDefault = false;
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
if (!itemp->condsp()) {
|
||||
// Default clause. Just make true, we'll optimize it away later
|
||||
itemp->condsp(new AstConst(itemp->fileline(), AstConst::LogicTrue()));
|
||||
hadDefault = true;
|
||||
} else {
|
||||
// Expressioned clause
|
||||
AstNode* icondNextp = NULL;
|
||||
AstNode* ifexprp = NULL; // If expression to test
|
||||
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondNextp) {
|
||||
icondNextp = icondp->nextp();
|
||||
icondp->unlinkFrBack();
|
||||
if (!itemp->condsp()) {
|
||||
// Default clause. Just make true, we'll optimize it away later
|
||||
itemp->condsp(new AstConst(itemp->fileline(), AstConst::LogicTrue()));
|
||||
hadDefault = true;
|
||||
} else {
|
||||
// Expressioned clause
|
||||
AstNode* icondNextp = NULL;
|
||||
AstNode* ifexprp = NULL; // If expression to test
|
||||
for (AstNode* icondp = itemp->condsp(); icondp!=NULL; icondp=icondNextp) {
|
||||
icondNextp = icondp->nextp();
|
||||
icondp->unlinkFrBack();
|
||||
|
||||
AstNode* condp = NULL; // Default is to use and1p/and2p
|
||||
AstNode* condp = NULL; // Default is to use and1p/and2p
|
||||
AstConst* iconstp = VN_CAST(icondp, Const);
|
||||
if (iconstp && neverItem(nodep, iconstp)) {
|
||||
// X in casez can't ever be executed
|
||||
icondp->deleteTree(); VL_DANGLING(icondp); VL_DANGLING(iconstp);
|
||||
// For simplicity, make expression that is not equal, and let later
|
||||
// optimizations remove it
|
||||
condp = new AstConst(itemp->fileline(), AstConst::LogicFalse());
|
||||
if (iconstp && neverItem(nodep, iconstp)) {
|
||||
// X in casez can't ever be executed
|
||||
icondp->deleteTree(); VL_DANGLING(icondp); VL_DANGLING(iconstp);
|
||||
// For simplicity, make expression that is not equal, and let later
|
||||
// optimizations remove it
|
||||
condp = new AstConst(itemp->fileline(), AstConst::LogicFalse());
|
||||
} else if (AstInsideRange* irangep = VN_CAST(icondp, InsideRange)) {
|
||||
// Similar logic in V3Width::visit(AstInside)
|
||||
AstNode* ap = AstGte::newTyped(itemp->fileline(),
|
||||
cexprp->cloneTree(false),
|
||||
irangep->lhsp()->unlinkFrBack());
|
||||
AstNode* bp = AstLte::newTyped(itemp->fileline(),
|
||||
cexprp->cloneTree(false),
|
||||
irangep->rhsp()->unlinkFrBack());
|
||||
condp = new AstAnd(itemp->fileline(), ap, bp);
|
||||
} else if (iconstp && iconstp->num().isFourState()
|
||||
&& (nodep->casex() || nodep->casez() || nodep->caseInside())) {
|
||||
// Similar logic in V3Width::visit(AstInside)
|
||||
AstNode* ap = AstGte::newTyped(itemp->fileline(),
|
||||
cexprp->cloneTree(false),
|
||||
irangep->lhsp()->unlinkFrBack());
|
||||
AstNode* bp = AstLte::newTyped(itemp->fileline(),
|
||||
cexprp->cloneTree(false),
|
||||
irangep->rhsp()->unlinkFrBack());
|
||||
condp = new AstAnd(itemp->fileline(), ap, bp);
|
||||
} else if (iconstp && iconstp->num().isFourState()
|
||||
&& (nodep->casex() || nodep->casez() || nodep->caseInside())) {
|
||||
V3Number nummask (itemp, iconstp->width());
|
||||
nummask.opBitsNonX(iconstp->num());
|
||||
V3Number numval (itemp, iconstp->width());
|
||||
numval.opBitsOne(iconstp->num());
|
||||
AstNode* and1p = new AstAnd(itemp->fileline(), cexprp->cloneTree(false),
|
||||
new AstConst(itemp->fileline(), nummask));
|
||||
AstNode* and2p = new AstAnd(itemp->fileline(),
|
||||
new AstConst(itemp->fileline(), numval),
|
||||
new AstConst(itemp->fileline(), nummask));
|
||||
icondp->deleteTree(); VL_DANGLING(icondp); VL_DANGLING(iconstp);
|
||||
condp = AstEq::newTyped(itemp->fileline(), and1p, and2p);
|
||||
} else {
|
||||
// Not a caseX mask, we can simply build CASEEQ(cexpr icond)
|
||||
AstNode* and1p = cexprp->cloneTree(false);
|
||||
AstNode* and2p = icondp;
|
||||
condp = AstEq::newTyped(itemp->fileline(), and1p, and2p);
|
||||
}
|
||||
if (!ifexprp) {
|
||||
ifexprp = condp;
|
||||
} else {
|
||||
ifexprp = new AstLogOr(itemp->fileline(), ifexprp, condp);
|
||||
}
|
||||
}
|
||||
// Replace expression in tree
|
||||
itemp->condsp(ifexprp);
|
||||
}
|
||||
}
|
||||
cexprp->deleteTree(); VL_DANGLING(cexprp);
|
||||
if (!hadDefault) {
|
||||
// If there was no default, add a empty one, this greatly simplifies below code
|
||||
// and constant propagation will just eliminate it for us later.
|
||||
nodep->addItemsp(new AstCaseItem(nodep->fileline(),
|
||||
new AstConst(nodep->fileline(), AstConst::LogicTrue()),
|
||||
NULL));
|
||||
}
|
||||
if (debug()>=9) nodep->dumpTree(cout," _comp_COND: ");
|
||||
// Now build the IF statement tree
|
||||
// The tree can be quite huge. Pull ever group of 8 out, and make a OR tree.
|
||||
// This reduces the depth for the bottom elements, at the cost of some of the top elements.
|
||||
// If we ever have profiling data, we should pull out the most common item from here and
|
||||
// instead make it the first IF branch.
|
||||
int depth = 0;
|
||||
AstNode* grouprootp = NULL;
|
||||
AstIf* groupnextp = NULL;
|
||||
AstIf* itemnextp = NULL;
|
||||
numval.opBitsOne(iconstp->num());
|
||||
AstNode* and1p = new AstAnd(itemp->fileline(), cexprp->cloneTree(false),
|
||||
new AstConst(itemp->fileline(), nummask));
|
||||
AstNode* and2p = new AstAnd(itemp->fileline(),
|
||||
new AstConst(itemp->fileline(), numval),
|
||||
new AstConst(itemp->fileline(), nummask));
|
||||
icondp->deleteTree(); VL_DANGLING(icondp); VL_DANGLING(iconstp);
|
||||
condp = AstEq::newTyped(itemp->fileline(), and1p, and2p);
|
||||
} else {
|
||||
// Not a caseX mask, we can simply build CASEEQ(cexpr icond)
|
||||
AstNode* and1p = cexprp->cloneTree(false);
|
||||
AstNode* and2p = icondp;
|
||||
condp = AstEq::newTyped(itemp->fileline(), and1p, and2p);
|
||||
}
|
||||
if (!ifexprp) {
|
||||
ifexprp = condp;
|
||||
} else {
|
||||
ifexprp = new AstLogOr(itemp->fileline(), ifexprp, condp);
|
||||
}
|
||||
}
|
||||
// Replace expression in tree
|
||||
itemp->condsp(ifexprp);
|
||||
}
|
||||
}
|
||||
cexprp->deleteTree(); VL_DANGLING(cexprp);
|
||||
if (!hadDefault) {
|
||||
// If there was no default, add a empty one, this greatly simplifies below code
|
||||
// and constant propagation will just eliminate it for us later.
|
||||
nodep->addItemsp(new AstCaseItem(nodep->fileline(),
|
||||
new AstConst(nodep->fileline(), AstConst::LogicTrue()),
|
||||
NULL));
|
||||
}
|
||||
if (debug()>=9) nodep->dumpTree(cout, " _comp_COND: ");
|
||||
// Now build the IF statement tree
|
||||
// The tree can be quite huge. Pull ever group of 8 out, and make a OR tree.
|
||||
// This reduces the depth for the bottom elements, at the cost of
|
||||
// some of the top elements. If we ever have profiling data, we
|
||||
// should pull out the most common item from here and instead make
|
||||
// it the first IF branch.
|
||||
int depth = 0;
|
||||
AstNode* grouprootp = NULL;
|
||||
AstIf* groupnextp = NULL;
|
||||
AstIf* itemnextp = NULL;
|
||||
for (AstCaseItem* itemp = nodep->itemsp(); itemp; itemp=VN_CAST(itemp->nextp(), CaseItem)) {
|
||||
AstNode* istmtsp = itemp->bodysp(); // Maybe null -- no action.
|
||||
if (istmtsp) istmtsp->unlinkFrBackWithNext();
|
||||
// Expressioned clause
|
||||
AstNode* ifexprp = itemp->condsp()->unlinkFrBack();
|
||||
{ // Prepare for next group
|
||||
if (++depth > CASE_ENCODER_GROUP_DEPTH) depth = 1;
|
||||
if (depth == 1) { // First group or starting new group
|
||||
itemnextp = NULL;
|
||||
AstIf* newp = new AstIf(itemp->fileline(), ifexprp->cloneTree(true), NULL, NULL);
|
||||
if (groupnextp) groupnextp->addElsesp(newp);
|
||||
else grouprootp = newp;
|
||||
groupnextp = newp;
|
||||
} else { // Continue group, modify if condition to OR in this new condition
|
||||
AstNode* condp = groupnextp->condp()->unlinkFrBack();
|
||||
groupnextp->condp(new AstOr(ifexprp->fileline(),
|
||||
condp,
|
||||
ifexprp->cloneTree(true)));
|
||||
}
|
||||
}
|
||||
{ // Make the new lower IF and attach in the tree
|
||||
AstNode* itemexprp = ifexprp; VL_DANGLING(ifexprp);
|
||||
if (depth == (CASE_ENCODER_GROUP_DEPTH)) { // End of group - can skip the condition
|
||||
itemexprp->deleteTree(); VL_DANGLING(itemexprp);
|
||||
itemexprp = new AstConst(itemp->fileline(), AstConst::LogicTrue());
|
||||
}
|
||||
AstIf* newp = new AstIf(itemp->fileline(), itemexprp, istmtsp, NULL);
|
||||
if (itemnextp) itemnextp->addElsesp(newp);
|
||||
else groupnextp->addIfsp(newp); // First in a new group
|
||||
itemnextp = newp;
|
||||
}
|
||||
}
|
||||
if (debug()>=9) nodep->dumpTree(cout," _comp_TREE: ");
|
||||
// Handle any assertions
|
||||
replaceCaseParallel(nodep, false);
|
||||
// Replace the CASE... with IF...
|
||||
if (debug()>=9 && grouprootp) grouprootp->dumpTree(cout," _new: ");
|
||||
if (grouprootp) nodep->replaceWith(grouprootp);
|
||||
else nodep->unlinkFrBack();
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
AstNode* istmtsp = itemp->bodysp(); // Maybe null -- no action.
|
||||
if (istmtsp) istmtsp->unlinkFrBackWithNext();
|
||||
// Expressioned clause
|
||||
AstNode* ifexprp = itemp->condsp()->unlinkFrBack();
|
||||
{ // Prepare for next group
|
||||
if (++depth > CASE_ENCODER_GROUP_DEPTH) depth = 1;
|
||||
if (depth == 1) { // First group or starting new group
|
||||
itemnextp = NULL;
|
||||
AstIf* newp = new AstIf(itemp->fileline(),
|
||||
ifexprp->cloneTree(true), NULL, NULL);
|
||||
if (groupnextp) groupnextp->addElsesp(newp);
|
||||
else grouprootp = newp;
|
||||
groupnextp = newp;
|
||||
} else { // Continue group, modify if condition to OR in this new condition
|
||||
AstNode* condp = groupnextp->condp()->unlinkFrBack();
|
||||
groupnextp->condp(new AstOr(ifexprp->fileline(),
|
||||
condp,
|
||||
ifexprp->cloneTree(true)));
|
||||
}
|
||||
}
|
||||
{ // Make the new lower IF and attach in the tree
|
||||
AstNode* itemexprp = ifexprp; VL_DANGLING(ifexprp);
|
||||
if (depth == (CASE_ENCODER_GROUP_DEPTH)) { // End of group - can skip the condition
|
||||
itemexprp->deleteTree(); VL_DANGLING(itemexprp);
|
||||
itemexprp = new AstConst(itemp->fileline(), AstConst::LogicTrue());
|
||||
}
|
||||
AstIf* newp = new AstIf(itemp->fileline(), itemexprp, istmtsp, NULL);
|
||||
if (itemnextp) itemnextp->addElsesp(newp);
|
||||
else groupnextp->addIfsp(newp); // First in a new group
|
||||
itemnextp = newp;
|
||||
}
|
||||
}
|
||||
if (debug()>=9) nodep->dumpTree(cout, " _comp_TREE: ");
|
||||
// Handle any assertions
|
||||
replaceCaseParallel(nodep, false);
|
||||
// Replace the CASE... with IF...
|
||||
if (debug()>=9 && grouprootp) grouprootp->dumpTree(cout, " _new: ");
|
||||
if (grouprootp) nodep->replaceWith(grouprootp);
|
||||
else nodep->unlinkFrBack();
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
|
||||
void replaceCaseParallel(AstCase* nodep, bool noOverlapsAllCovered) {
|
||||
// Take the notParallelp tree under the case statement created by V3Assert
|
||||
// If the statement was proven to have no overlaps and all cases covered, we're done with it.
|
||||
// Else, convert to a normal statement parallel with the case statement.
|
||||
if (nodep->notParallelp() && !noOverlapsAllCovered) {
|
||||
AstNode* parp = nodep->notParallelp()->unlinkFrBackWithNext();
|
||||
nodep->addNextHere(parp);
|
||||
}
|
||||
// Take the notParallelp tree under the case statement created by V3Assert
|
||||
// If the statement was proven to have no overlaps and all cases
|
||||
// covered, we're done with it.
|
||||
// Else, convert to a normal statement parallel with the case statement.
|
||||
if (nodep->notParallelp() && !noOverlapsAllCovered) {
|
||||
AstNode* parp = nodep->notParallelp()->unlinkFrBackWithNext();
|
||||
nodep->addNextHere(parp);
|
||||
}
|
||||
}
|
||||
|
||||
bool neverItem(AstCase* casep, AstConst* itemp) {
|
||||
// Xs in case or casez are impossible due to two state simulations
|
||||
if (casep->casex()) {
|
||||
} else if (casep->casez() || casep->caseInside()) {
|
||||
if (itemp->num().isUnknown()) return true;
|
||||
} else {
|
||||
if (itemp->num().isFourState()) return true;
|
||||
}
|
||||
return false;
|
||||
// Xs in case or casez are impossible due to two state simulations
|
||||
if (casep->casex()) {
|
||||
} else if (casep->casez() || casep->caseInside()) {
|
||||
if (itemp->num().isUnknown()) return true;
|
||||
} else {
|
||||
if (itemp->num().isFourState()) return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstCase* nodep) {
|
||||
V3Case::caseLint(nodep);
|
||||
V3Case::caseLint(nodep);
|
||||
iterateChildren(nodep);
|
||||
if (debug()>=9) nodep->dumpTree(cout," case_old: ");
|
||||
if (isCaseTreeFast(nodep) && v3Global.opt.oCase()) {
|
||||
// It's a simple priority encoder or complete statement
|
||||
// we can make a tree of statements to avoid extra comparisons
|
||||
++m_statCaseFast;
|
||||
replaceCaseFast(nodep); VL_DANGLING(nodep);
|
||||
} else {
|
||||
++m_statCaseSlow;
|
||||
replaceCaseComplicated(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
if (debug()>=9) nodep->dumpTree(cout, " case_old: ");
|
||||
if (isCaseTreeFast(nodep) && v3Global.opt.oCase()) {
|
||||
// It's a simple priority encoder or complete statement
|
||||
// we can make a tree of statements to avoid extra comparisons
|
||||
++m_statCaseFast;
|
||||
replaceCaseFast(nodep); VL_DANGLING(nodep);
|
||||
} else {
|
||||
++m_statCaseSlow;
|
||||
replaceCaseComplicated(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
//--------------------
|
||||
// Default: Just iterate
|
||||
|
|
@ -468,15 +478,15 @@ public:
|
|||
explicit CaseVisitor(AstNetlist* nodep) {
|
||||
m_caseWidth = 0;
|
||||
m_caseItems = 0;
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
m_caseNoOverlapsAllCovered = false;
|
||||
for (uint32_t i=0; i<(1UL<<CASE_OVERLAP_WIDTH); ++i) {
|
||||
m_valueItem[i] = NULL;
|
||||
}
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~CaseVisitor() {
|
||||
V3Stats::addStat("Optimizations, Cases parallelized", m_statCaseFast);
|
||||
V3Stats::addStat("Optimizations, Cases complex", m_statCaseSlow);
|
||||
V3Stats::addStat("Optimizations, Cases parallelized", m_statCaseFast);
|
||||
V3Stats::addStat("Optimizations, Cases complex", m_statCaseSlow);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,4 +35,4 @@ public:
|
|||
static void caseLint(AstNodeCase* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
144
src/V3Cast.cpp
144
src/V3Cast.cpp
|
|
@ -20,24 +20,24 @@
|
|||
// V3Cast's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// For each math operator, if above operator requires 32 bits,
|
||||
// and this isn't, cast to 32 bits.
|
||||
// Likewise for 64 bit operators.
|
||||
// For each math operator, if above operator requires 32 bits,
|
||||
// and this isn't, cast to 32 bits.
|
||||
// Likewise for 64 bit operators.
|
||||
//
|
||||
// C++ rules:
|
||||
// Integral promotions allow conversion to larger int. Unsigned is only
|
||||
// used if a int would not fit the value.
|
||||
// Integral promotions allow conversion to larger int. Unsigned is only
|
||||
// used if a int would not fit the value.
|
||||
//
|
||||
// Bools converts to int, not unsigned.
|
||||
// Bools converts to int, not unsigned.
|
||||
//
|
||||
// Most operations return unsigned if either operand is unsigned.
|
||||
// Most operations return unsigned if either operand is unsigned.
|
||||
//
|
||||
// Unsignedness can be lost on results of the below operations, as they
|
||||
// may need the sign bit for proper operation:
|
||||
// /, %, /=, %=, <, <=, >, or >=
|
||||
// Unsignedness can be lost on results of the below operations, as they
|
||||
// may need the sign bit for proper operation:
|
||||
// /, %, /=, %=, <, <=, >, or >=
|
||||
//
|
||||
// Signed values are always sign extended on promotion or right shift,
|
||||
// even if assigning to a unsigned.
|
||||
// Signed values are always sign extended on promotion or right shift,
|
||||
// even if assigning to a unsigned.
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -58,8 +58,8 @@ class CastVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstNode::user() // bool. Indicates node is of known size
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstNode::user() // bool. Indicates node is of known size
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
|
||||
|
|
@ -67,97 +67,97 @@ private:
|
|||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void insertCast(AstNode* nodep, int needsize) { // We'll insert ABOVE passed node
|
||||
UINFO(4," NeedCast "<<nodep<<endl);
|
||||
AstNRelinker relinkHandle;
|
||||
nodep->unlinkFrBack(&relinkHandle);
|
||||
//
|
||||
UINFO(4," NeedCast "<<nodep<<endl);
|
||||
AstNRelinker relinkHandle;
|
||||
nodep->unlinkFrBack(&relinkHandle);
|
||||
//
|
||||
AstCCast* castp = new AstCCast(nodep->fileline(), nodep, needsize, nodep->widthMin());
|
||||
relinkHandle.relink(castp);
|
||||
//if (debug()>8) castp->dumpTree(cout,"-castins: ");
|
||||
//
|
||||
insureLower32Cast(castp);
|
||||
nodep->user1(1); // Now must be of known size
|
||||
relinkHandle.relink(castp);
|
||||
//if (debug()>8) castp->dumpTree(cout, "-castins: ");
|
||||
//
|
||||
insureLower32Cast(castp);
|
||||
nodep->user1(1); // Now must be of known size
|
||||
}
|
||||
int castSize(AstNode* nodep) {
|
||||
if (nodep->isQuad()) return VL_QUADSIZE;
|
||||
else if (nodep->width()<=8) return 8;
|
||||
else if (nodep->width()<=16) return 16;
|
||||
else return VL_WORDSIZE;
|
||||
if (nodep->isQuad()) return VL_QUADSIZE;
|
||||
else if (nodep->width()<=8) return 8;
|
||||
else if (nodep->width()<=16) return 16;
|
||||
else return VL_WORDSIZE;
|
||||
}
|
||||
void insureCast(AstNode* nodep) {
|
||||
if (castSize(nodep->backp()) != castSize(nodep)
|
||||
|| !nodep->user1()) {
|
||||
insertCast(nodep, castSize(nodep->backp()));
|
||||
}
|
||||
if (castSize(nodep->backp()) != castSize(nodep)
|
||||
|| !nodep->user1()) {
|
||||
insertCast(nodep, castSize(nodep->backp()));
|
||||
}
|
||||
}
|
||||
void insureLower32Cast(AstCCast* nodep) {
|
||||
// If we have uint64 = CAST(uint64(x)) then the upcasting
|
||||
// really needs to be CAST(uint64(CAST(uint32(x))).
|
||||
// Otherwise a (uint64)(a>b) would return wrong value, as
|
||||
// less than has undeterministic signedness.
|
||||
if (nodep->isQuad() && !nodep->lhsp()->isQuad()
|
||||
// If we have uint64 = CAST(uint64(x)) then the upcasting
|
||||
// really needs to be CAST(uint64(CAST(uint32(x))).
|
||||
// Otherwise a (uint64)(a>b) would return wrong value, as
|
||||
// less than has undeterministic signedness.
|
||||
if (nodep->isQuad() && !nodep->lhsp()->isQuad()
|
||||
&& !VN_IS(nodep->lhsp(), CCast)) {
|
||||
insertCast(nodep->lhsp(), VL_WORDSIZE);
|
||||
}
|
||||
insertCast(nodep->lhsp(), VL_WORDSIZE);
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeUniop* nodep) {
|
||||
iterateChildren(nodep);
|
||||
nodep->user1(nodep->lhsp()->user1());
|
||||
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
|
||||
nodep->user1(nodep->lhsp()->user1());
|
||||
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
|
||||
}
|
||||
virtual void visit(AstNodeBiop* nodep) {
|
||||
iterateChildren(nodep);
|
||||
nodep->user1(nodep->lhsp()->user1()
|
||||
| nodep->rhsp()->user1());
|
||||
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
|
||||
if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp());
|
||||
nodep->user1(nodep->lhsp()->user1()
|
||||
| nodep->rhsp()->user1());
|
||||
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
|
||||
if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp());
|
||||
}
|
||||
virtual void visit(AstNodeTriop* nodep) {
|
||||
iterateChildren(nodep);
|
||||
nodep->user1(nodep->lhsp()->user1()
|
||||
| nodep->rhsp()->user1()
|
||||
| nodep->thsp()->user1());
|
||||
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
|
||||
if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp());
|
||||
if (nodep->sizeMattersThs()) insureCast(nodep->thsp());
|
||||
nodep->user1(nodep->lhsp()->user1()
|
||||
| nodep->rhsp()->user1()
|
||||
| nodep->thsp()->user1());
|
||||
if (nodep->sizeMattersLhs()) insureCast(nodep->lhsp());
|
||||
if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp());
|
||||
if (nodep->sizeMattersThs()) insureCast(nodep->thsp());
|
||||
}
|
||||
virtual void visit(AstCCast* nodep) {
|
||||
iterateChildren(nodep);
|
||||
insureLower32Cast(nodep);
|
||||
nodep->user1(1);
|
||||
insureLower32Cast(nodep);
|
||||
nodep->user1(1);
|
||||
}
|
||||
virtual void visit(AstNegate* nodep) {
|
||||
iterateChildren(nodep);
|
||||
nodep->user1(nodep->lhsp()->user1());
|
||||
if (nodep->lhsp()->widthMin()==1) {
|
||||
// We want to avoid a GCC "converting of negative value" warning
|
||||
// from our expansion of
|
||||
// out = {32{a<b}} => out = - (a<b)
|
||||
insertCast(nodep->lhsp(), castSize(nodep));
|
||||
} else {
|
||||
insureCast(nodep->lhsp());
|
||||
}
|
||||
nodep->user1(nodep->lhsp()->user1());
|
||||
if (nodep->lhsp()->widthMin()==1) {
|
||||
// We want to avoid a GCC "converting of negative value" warning
|
||||
// from our expansion of
|
||||
// out = {32{a<b}} => out = - (a<b)
|
||||
insertCast(nodep->lhsp(), castSize(nodep));
|
||||
} else {
|
||||
insureCast(nodep->lhsp());
|
||||
}
|
||||
}
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
if (!nodep->lvalue()
|
||||
if (!nodep->lvalue()
|
||||
&& !VN_IS(nodep->backp(), CCast)
|
||||
&& VN_IS(nodep->backp(), NodeMath)
|
||||
&& !VN_IS(nodep->backp(), ArraySel)
|
||||
&& nodep->backp()->width()
|
||||
&& castSize(nodep) != castSize(nodep->varp())) {
|
||||
// Cast vars to IData first, else below has upper bits wrongly set
|
||||
// CData x=3; out = (QData)(x<<30);
|
||||
&& nodep->backp()->width()
|
||||
&& castSize(nodep) != castSize(nodep->varp())) {
|
||||
// Cast vars to IData first, else below has upper bits wrongly set
|
||||
// CData x=3; out = (QData)(x<<30);
|
||||
insertCast(nodep, castSize(nodep));
|
||||
}
|
||||
nodep->user1(1);
|
||||
}
|
||||
nodep->user1(1);
|
||||
}
|
||||
virtual void visit(AstConst* nodep) {
|
||||
// Constants are of unknown size if smaller than 33 bits, becase
|
||||
// we're too lazy to wrap every constant in the universe in
|
||||
// ((IData)#).
|
||||
nodep->user1(nodep->isQuad() || nodep->isWide());
|
||||
// Constants are of unknown size if smaller than 33 bits, becase
|
||||
// we're too lazy to wrap every constant in the universe in
|
||||
// ((IData)#).
|
||||
nodep->user1(nodep->isQuad() || nodep->isWide());
|
||||
}
|
||||
|
||||
// NOPs
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void castAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
845
src/V3Cdc.cpp
845
src/V3Cdc.cpp
File diff suppressed because it is too large
Load Diff
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void cdcAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@
|
|||
// V3Changed's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// Each combo block
|
||||
// For each variable that comes from combo block and is generated AFTER a usage
|
||||
// Add __Vlast_{var} to local section, init to current value (just use array?)
|
||||
// Change = if any var != last.
|
||||
// If a signal is used as a clock in this module or any
|
||||
// module *below*, and it isn't a input to this module,
|
||||
// we need to indicate a new clock has been created.
|
||||
// Each combo block
|
||||
// For each variable that comes from combo block and is generated AFTER a usage
|
||||
// Add __Vlast_{var} to local section, init to current value (just use array?)
|
||||
// Change = if any var != last.
|
||||
// If a signal is used as a clock in this module or any
|
||||
// module *below*, and it isn't a input to this module,
|
||||
// we need to indicate a new clock has been created.
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -47,56 +47,60 @@
|
|||
class ChangedState {
|
||||
public:
|
||||
// STATE
|
||||
AstNodeModule* m_topModp; // Top module
|
||||
AstScope* m_scopetopp; // Scope under TOPSCOPE
|
||||
AstCFunc* m_chgFuncp; // Change function we're building
|
||||
AstCFunc* m_tlChgFuncp; // Top level change function we're building
|
||||
int m_numStmts; // Number of statements added to m_chgFuncp
|
||||
int m_funcNum; // Number of change functions emitted
|
||||
AstNodeModule* m_topModp; // Top module
|
||||
AstScope* m_scopetopp; // Scope under TOPSCOPE
|
||||
AstCFunc* m_chgFuncp; // Change function we're building
|
||||
AstCFunc* m_tlChgFuncp; // Top level change function we're building
|
||||
int m_numStmts; // Number of statements added to m_chgFuncp
|
||||
int m_funcNum; // Number of change functions emitted
|
||||
|
||||
ChangedState() {
|
||||
m_topModp = NULL;
|
||||
m_chgFuncp = NULL;
|
||||
m_scopetopp = NULL;
|
||||
m_tlChgFuncp = NULL;
|
||||
m_numStmts = 0;
|
||||
m_funcNum = 0;
|
||||
m_topModp = NULL;
|
||||
m_chgFuncp = NULL;
|
||||
m_scopetopp = NULL;
|
||||
m_tlChgFuncp = NULL;
|
||||
m_numStmts = 0;
|
||||
m_funcNum = 0;
|
||||
}
|
||||
~ChangedState() {}
|
||||
|
||||
void maybeCreateChgFuncp() {
|
||||
// Don't create an extra function call if splitting is disabled
|
||||
if (!v3Global.opt.outputSplitCFuncs()) {
|
||||
m_chgFuncp = m_tlChgFuncp;
|
||||
return;
|
||||
}
|
||||
if (!m_chgFuncp || v3Global.opt.outputSplitCFuncs() < m_numStmts) {
|
||||
m_chgFuncp = new AstCFunc(m_scopetopp->fileline(), "_change_request_" + cvtToStr(++m_funcNum), m_scopetopp, "QData");
|
||||
m_chgFuncp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
m_chgFuncp->symProlog(true);
|
||||
m_chgFuncp->declPrivate(true);
|
||||
m_scopetopp->addActivep(m_chgFuncp);
|
||||
// Don't create an extra function call if splitting is disabled
|
||||
if (!v3Global.opt.outputSplitCFuncs()) {
|
||||
m_chgFuncp = m_tlChgFuncp;
|
||||
return;
|
||||
}
|
||||
if (!m_chgFuncp || v3Global.opt.outputSplitCFuncs() < m_numStmts) {
|
||||
m_chgFuncp = new AstCFunc(m_scopetopp->fileline(),
|
||||
"_change_request_" + cvtToStr(++m_funcNum),
|
||||
m_scopetopp, "QData");
|
||||
m_chgFuncp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
m_chgFuncp->symProlog(true);
|
||||
m_chgFuncp->declPrivate(true);
|
||||
m_scopetopp->addActivep(m_chgFuncp);
|
||||
|
||||
// Add a top call to it
|
||||
AstCCall* callp = new AstCCall(m_scopetopp->fileline(), m_chgFuncp);
|
||||
callp->argTypes("vlSymsp");
|
||||
// Add a top call to it
|
||||
AstCCall* callp = new AstCCall(m_scopetopp->fileline(), m_chgFuncp);
|
||||
callp->argTypes("vlSymsp");
|
||||
|
||||
if (!m_tlChgFuncp->stmtsp()) {
|
||||
m_tlChgFuncp->addStmtsp(new AstCReturn(m_scopetopp->fileline(), callp));
|
||||
} else {
|
||||
if (!m_tlChgFuncp->stmtsp()) {
|
||||
m_tlChgFuncp->addStmtsp(new AstCReturn(m_scopetopp->fileline(), callp));
|
||||
} else {
|
||||
AstCReturn* returnp = VN_CAST(m_tlChgFuncp->stmtsp(), CReturn);
|
||||
if (!returnp) m_scopetopp->v3fatalSrc("Lost CReturn in top change function");
|
||||
// This is currently using AstLogOr which will shortcut the evaluation if
|
||||
// any function returns true. This is likely what we want and is similar to the logic already in use
|
||||
// inside V3EmitC, however, it also means that verbose logging may miss to print change detect variables.
|
||||
AstNode* newp = new AstCReturn(m_scopetopp->fileline(),
|
||||
new AstLogOr(m_scopetopp->fileline(), callp,
|
||||
returnp->lhsp()->unlinkFrBack()));
|
||||
returnp->replaceWith(newp);
|
||||
returnp->deleteTree(); VL_DANGLING(returnp);
|
||||
}
|
||||
m_numStmts = 0;
|
||||
}
|
||||
if (!returnp) m_scopetopp->v3fatalSrc("Lost CReturn in top change function");
|
||||
// This is currently using AstLogOr which will shortcut the
|
||||
// evaluation if any function returns true. This is likely what
|
||||
// we want and is similar to the logic already in use inside
|
||||
// V3EmitC, however, it also means that verbose logging may
|
||||
// miss to print change detect variables.
|
||||
AstNode* newp = new AstCReturn(m_scopetopp->fileline(),
|
||||
new AstLogOr(m_scopetopp->fileline(), callp,
|
||||
returnp->lhsp()->unlinkFrBack()));
|
||||
returnp->replaceWith(newp);
|
||||
returnp->deleteTree(); VL_DANGLING(returnp);
|
||||
}
|
||||
m_numStmts = 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -106,82 +110,84 @@ public:
|
|||
class ChangedInsertVisitor : public AstNVisitor {
|
||||
private:
|
||||
// STATE
|
||||
ChangedState* m_statep; // Shared state across visitors
|
||||
AstVarScope* m_vscp; // Original (non-change) variable we're change-detecting
|
||||
AstVarScope* m_newvscp; // New (change detect) variable we're change-detecting
|
||||
AstNode* m_varEqnp; // Original var's equation to get var value
|
||||
AstNode* m_newLvEqnp; // New var's equation to read value
|
||||
AstNode* m_newRvEqnp; // New var's equation to set value
|
||||
uint32_t m_detects; // # detects created
|
||||
ChangedState* m_statep; // Shared state across visitors
|
||||
AstVarScope* m_vscp; // Original (non-change) variable we're change-detecting
|
||||
AstVarScope* m_newvscp; // New (change detect) variable we're change-detecting
|
||||
AstNode* m_varEqnp; // Original var's equation to get var value
|
||||
AstNode* m_newLvEqnp; // New var's equation to read value
|
||||
AstNode* m_newRvEqnp; // New var's equation to set value
|
||||
uint32_t m_detects; // # detects created
|
||||
|
||||
// CONSTANTS
|
||||
enum MiscConsts {
|
||||
DETECTARRAY_MAX_INDEXES = 256 // How many indexes before error
|
||||
// Ok to increase this, but may result in much slower model
|
||||
DETECTARRAY_MAX_INDEXES = 256 // How many indexes before error
|
||||
// Ok to increase this, but may result in much slower model
|
||||
};
|
||||
|
||||
void newChangeDet() {
|
||||
if (++m_detects > DETECTARRAY_MAX_INDEXES) {
|
||||
m_vscp->v3warn(E_DETECTARRAY, "Unsupported: Can't detect more than "<<cvtToStr(DETECTARRAY_MAX_INDEXES)
|
||||
<<" array indexes (probably with UNOPTFLAT warning suppressed): "<<m_vscp->prettyName()<<endl
|
||||
<<m_vscp->warnMore()
|
||||
<<"... Could recompile with DETECTARRAY_MAX_INDEXES increased"<<endl);
|
||||
return;
|
||||
}
|
||||
m_statep->maybeCreateChgFuncp();
|
||||
if (++m_detects > DETECTARRAY_MAX_INDEXES) {
|
||||
m_vscp->v3warn(E_DETECTARRAY, "Unsupported: Can't detect more than "
|
||||
<<cvtToStr(DETECTARRAY_MAX_INDEXES)
|
||||
<<" array indexes (probably with UNOPTFLAT warning suppressed): "
|
||||
<<m_vscp->prettyName()<<endl
|
||||
<<m_vscp->warnMore()
|
||||
<<"... Could recompile with DETECTARRAY_MAX_INDEXES increased"<<endl);
|
||||
return;
|
||||
}
|
||||
m_statep->maybeCreateChgFuncp();
|
||||
|
||||
AstChangeDet* changep = new AstChangeDet(m_vscp->fileline(),
|
||||
m_varEqnp->cloneTree(true),
|
||||
m_newRvEqnp->cloneTree(true), false);
|
||||
m_statep->m_chgFuncp->addStmtsp(changep);
|
||||
m_statep->m_chgFuncp->addStmtsp(changep);
|
||||
AstAssign* initp = new AstAssign(m_vscp->fileline(),
|
||||
m_newLvEqnp->cloneTree(true),
|
||||
m_varEqnp->cloneTree(true));
|
||||
m_statep->m_chgFuncp->addFinalsp(initp);
|
||||
EmitCBaseCounterVisitor visitor(initp);
|
||||
m_statep->m_numStmts += visitor.count();
|
||||
m_statep->m_chgFuncp->addFinalsp(initp);
|
||||
EmitCBaseCounterVisitor visitor(initp);
|
||||
m_statep->m_numStmts += visitor.count();
|
||||
}
|
||||
|
||||
virtual void visit(AstBasicDType* nodep) {
|
||||
newChangeDet();
|
||||
newChangeDet();
|
||||
}
|
||||
virtual void visit(AstPackArrayDType* nodep) {
|
||||
newChangeDet();
|
||||
newChangeDet();
|
||||
}
|
||||
virtual void visit(AstUnpackArrayDType* nodep) {
|
||||
for (int index=0; index < nodep->elementsConst(); ++index) {
|
||||
AstNode* origVEp = m_varEqnp;
|
||||
AstNode* origNLEp = m_newLvEqnp;
|
||||
AstNode* origNREp = m_newRvEqnp;
|
||||
for (int index=0; index < nodep->elementsConst(); ++index) {
|
||||
AstNode* origVEp = m_varEqnp;
|
||||
AstNode* origNLEp = m_newLvEqnp;
|
||||
AstNode* origNREp = m_newRvEqnp;
|
||||
|
||||
m_varEqnp = new AstArraySel(nodep->fileline(), m_varEqnp->cloneTree(true), index);
|
||||
m_newLvEqnp = new AstArraySel(nodep->fileline(), m_newLvEqnp->cloneTree(true), index);
|
||||
m_newRvEqnp = new AstArraySel(nodep->fileline(), m_newRvEqnp->cloneTree(true), index);
|
||||
m_varEqnp = new AstArraySel(nodep->fileline(), m_varEqnp->cloneTree(true), index);
|
||||
m_newLvEqnp = new AstArraySel(nodep->fileline(), m_newLvEqnp->cloneTree(true), index);
|
||||
m_newRvEqnp = new AstArraySel(nodep->fileline(), m_newRvEqnp->cloneTree(true), index);
|
||||
|
||||
iterate(nodep->subDTypep()->skipRefp());
|
||||
|
||||
m_varEqnp->deleteTree();
|
||||
m_newLvEqnp->deleteTree();
|
||||
m_newRvEqnp->deleteTree();
|
||||
m_varEqnp->deleteTree();
|
||||
m_newLvEqnp->deleteTree();
|
||||
m_newRvEqnp->deleteTree();
|
||||
|
||||
m_varEqnp = origVEp;
|
||||
m_newLvEqnp = origNLEp;
|
||||
m_newRvEqnp = origNREp;
|
||||
}
|
||||
m_varEqnp = origVEp;
|
||||
m_newLvEqnp = origNLEp;
|
||||
m_newRvEqnp = origNREp;
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeClassDType* nodep) {
|
||||
if (nodep->packedUnsup()) {
|
||||
newChangeDet();
|
||||
} else {
|
||||
if (debug()) nodep->dumpTree(cout,"-DETECTARRAY-class-");
|
||||
if (nodep->packedUnsup()) {
|
||||
newChangeDet();
|
||||
} else {
|
||||
if (debug()) nodep->dumpTree(cout, "-DETECTARRAY-class-");
|
||||
m_vscp->v3warn(E_DETECTARRAY, "Unsupported: Can't detect changes on complex variable"
|
||||
" (probably with UNOPTFLAT warning suppressed): "
|
||||
<<m_vscp->varp()->prettyName());
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
if (debug()) nodep->dumpTree(cout,"-DETECTARRAY-general-");
|
||||
if (debug()) nodep->dumpTree(cout, "-DETECTARRAY-general-");
|
||||
m_vscp->v3warn(E_DETECTARRAY, "Unsupported: Can't detect changes on complex variable"
|
||||
" (probably with UNOPTFLAT warning suppressed): "
|
||||
<<m_vscp->varp()->prettyName());
|
||||
|
|
@ -189,29 +195,31 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
ChangedInsertVisitor(AstVarScope* vscp, ChangedState* statep) {
|
||||
m_statep = statep;
|
||||
m_vscp = vscp;
|
||||
m_detects = 0;
|
||||
{
|
||||
AstVar* varp = m_vscp->varp();
|
||||
string newvarname = "__Vchglast__"+m_vscp->scopep()->nameDotless()+"__"+varp->shortName();
|
||||
// Create: VARREF(_last)
|
||||
// ASSIGN(VARREF(_last), VARREF(var))
|
||||
// ...
|
||||
// CHANGEDET(VARREF(_last), VARREF(var))
|
||||
AstVar* newvarp = new AstVar(varp->fileline(), AstVarType::MODULETEMP, newvarname, varp);
|
||||
m_statep->m_topModp->addStmtp(newvarp);
|
||||
m_newvscp = new AstVarScope(m_vscp->fileline(), m_statep->m_scopetopp, newvarp);
|
||||
m_statep->m_scopetopp->addVarp(m_newvscp);
|
||||
m_statep = statep;
|
||||
m_vscp = vscp;
|
||||
m_detects = 0;
|
||||
{
|
||||
AstVar* varp = m_vscp->varp();
|
||||
string newvarname = ("__Vchglast__"+m_vscp->scopep()->nameDotless()
|
||||
+"__"+varp->shortName());
|
||||
// Create: VARREF(_last)
|
||||
// ASSIGN(VARREF(_last), VARREF(var))
|
||||
// ...
|
||||
// CHANGEDET(VARREF(_last), VARREF(var))
|
||||
AstVar* newvarp = new AstVar(varp->fileline(), AstVarType::MODULETEMP,
|
||||
newvarname, varp);
|
||||
m_statep->m_topModp->addStmtp(newvarp);
|
||||
m_newvscp = new AstVarScope(m_vscp->fileline(), m_statep->m_scopetopp, newvarp);
|
||||
m_statep->m_scopetopp->addVarp(m_newvscp);
|
||||
|
||||
m_varEqnp = new AstVarRef(m_vscp->fileline(), m_vscp, false);
|
||||
m_newLvEqnp = new AstVarRef(m_vscp->fileline(), m_newvscp, true);
|
||||
m_newRvEqnp = new AstVarRef(m_vscp->fileline(), m_newvscp, false);
|
||||
}
|
||||
m_varEqnp = new AstVarRef(m_vscp->fileline(), m_vscp, false);
|
||||
m_newLvEqnp = new AstVarRef(m_vscp->fileline(), m_newvscp, true);
|
||||
m_newRvEqnp = new AstVarRef(m_vscp->fileline(), m_newvscp, false);
|
||||
}
|
||||
iterate(vscp->dtypep()->skipRefp());
|
||||
m_varEqnp->deleteTree();
|
||||
m_newLvEqnp->deleteTree();
|
||||
m_newRvEqnp->deleteTree();
|
||||
m_varEqnp->deleteTree();
|
||||
m_newLvEqnp->deleteTree();
|
||||
m_newRvEqnp->deleteTree();
|
||||
}
|
||||
virtual ~ChangedInsertVisitor() {}
|
||||
};
|
||||
|
|
@ -223,61 +231,63 @@ class ChangedVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstVarScope::user1() -> bool. True indicates processed
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstVarScope::user1() -> bool. True indicates processed
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
ChangedState* m_statep; // Shared state across visitors
|
||||
ChangedState* m_statep; // Shared state across visitors
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void genChangeDet(AstVarScope* vscp) {
|
||||
vscp->v3warn(IMPERFECTSCH,"Imperfect scheduling of variable: "<<vscp);
|
||||
ChangedInsertVisitor visitor (vscp, m_statep);
|
||||
vscp->v3warn(IMPERFECTSCH, "Imperfect scheduling of variable: "<<vscp);
|
||||
ChangedInsertVisitor visitor (vscp, m_statep);
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
if (nodep->isTop()) {
|
||||
m_statep->m_topModp = nodep;
|
||||
}
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
if (nodep->isTop()) {
|
||||
m_statep->m_topModp = nodep;
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
virtual void visit(AstTopScope* nodep) {
|
||||
UINFO(4," TS "<<nodep<<endl);
|
||||
// Clearing
|
||||
AstNode::user1ClearTree();
|
||||
// Create the change detection function
|
||||
AstScope* scopep = nodep->scopep();
|
||||
if (!scopep) nodep->v3fatalSrc("No scope found on top level, perhaps you have no statements?");
|
||||
m_statep->m_scopetopp = scopep;
|
||||
UINFO(4," TS "<<nodep<<endl);
|
||||
// Clearing
|
||||
AstNode::user1ClearTree();
|
||||
// Create the change detection function
|
||||
AstScope* scopep = nodep->scopep();
|
||||
if (!scopep) nodep->v3fatalSrc("No scope found on top level,"
|
||||
" perhaps you have no statements?");
|
||||
m_statep->m_scopetopp = scopep;
|
||||
|
||||
// Create a wrapper change detection function that calls each change detection function
|
||||
m_statep->m_tlChgFuncp = new AstCFunc(nodep->fileline(), "_change_request", scopep, "QData");
|
||||
m_statep->m_tlChgFuncp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
m_statep->m_tlChgFuncp->symProlog(true);
|
||||
m_statep->m_tlChgFuncp->declPrivate(true);
|
||||
m_statep->m_scopetopp->addActivep(m_statep->m_tlChgFuncp);
|
||||
// Each change detection function needs at least one AstChangeDet
|
||||
// to ensure that V3EmitC outputs the necessary code.
|
||||
m_statep->maybeCreateChgFuncp();
|
||||
m_statep->m_chgFuncp->addStmtsp(new AstChangeDet(nodep->fileline(), NULL, NULL, false));
|
||||
// Create a wrapper change detection function that calls each change detection function
|
||||
m_statep->m_tlChgFuncp = new AstCFunc(nodep->fileline(),
|
||||
"_change_request", scopep, "QData");
|
||||
m_statep->m_tlChgFuncp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
m_statep->m_tlChgFuncp->symProlog(true);
|
||||
m_statep->m_tlChgFuncp->declPrivate(true);
|
||||
m_statep->m_scopetopp->addActivep(m_statep->m_tlChgFuncp);
|
||||
// Each change detection function needs at least one AstChangeDet
|
||||
// to ensure that V3EmitC outputs the necessary code.
|
||||
m_statep->maybeCreateChgFuncp();
|
||||
m_statep->m_chgFuncp->addStmtsp(new AstChangeDet(nodep->fileline(), NULL, NULL, false));
|
||||
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstVarScope* nodep) {
|
||||
if (nodep->isCircular()) {
|
||||
UINFO(8," CIRC "<<nodep<<endl);
|
||||
if (!nodep->user1SetOnce()) {
|
||||
genChangeDet(nodep);
|
||||
}
|
||||
}
|
||||
if (nodep->isCircular()) {
|
||||
UINFO(8," CIRC "<<nodep<<endl);
|
||||
if (!nodep->user1SetOnce()) {
|
||||
genChangeDet(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeMath* nodep) {
|
||||
// Short-circuit
|
||||
// Short-circuit
|
||||
}
|
||||
//--------------------
|
||||
// Default: Just iterate
|
||||
|
|
@ -288,7 +298,7 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
ChangedVisitor(AstNetlist* nodep, ChangedState* statep) {
|
||||
m_statep = statep;
|
||||
m_statep = statep;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~ChangedVisitor() {}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void changedAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
202
src/V3Clean.cpp
202
src/V3Clean.cpp
|
|
@ -20,10 +20,10 @@
|
|||
// V3Clean's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// For each math operator, if it requires a clean operand,
|
||||
// and the operand is dirty, insert a CLEAN node.
|
||||
// Resize operands to C++ 32/64/wide types.
|
||||
// Copy all width() values to widthMin() so RANGE, etc can still see orig widths
|
||||
// For each math operator, if it requires a clean operand,
|
||||
// and the operand is dirty, insert a CLEAN node.
|
||||
// Resize operands to C++ 32/64/wide types.
|
||||
// Copy all width() values to widthMin() so RANGE, etc can still see orig widths
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -44,12 +44,12 @@ class CleanVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstNode::user() -> CleanState. For this node, 0==UNKNOWN
|
||||
// AstNode::user2() -> bool. True indicates widthMin has been propagated
|
||||
// AstNodeDType::user3() -> AstNodeDType*. Alternative node with C size
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
// AstNode::user() -> CleanState. For this node, 0==UNKNOWN
|
||||
// AstNode::user2() -> bool. True indicates widthMin has been propagated
|
||||
// AstNodeDType::user3() -> AstNodeDType*. Alternative node with C size
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
|
||||
// TYPES
|
||||
enum CleanState { CS_UNKNOWN, CS_CLEAN, CS_DIRTY };
|
||||
|
|
@ -62,153 +62,153 @@ private:
|
|||
|
||||
// Width resetting
|
||||
int cppWidth(AstNode* nodep) {
|
||||
if (nodep->width()<=VL_WORDSIZE) return VL_WORDSIZE;
|
||||
else if (nodep->width()<=VL_QUADSIZE) return VL_QUADSIZE;
|
||||
else return nodep->widthWords()*VL_WORDSIZE;
|
||||
if (nodep->width()<=VL_WORDSIZE) return VL_WORDSIZE;
|
||||
else if (nodep->width()<=VL_QUADSIZE) return VL_QUADSIZE;
|
||||
else return nodep->widthWords()*VL_WORDSIZE;
|
||||
}
|
||||
void setCppWidth(AstNode* nodep) {
|
||||
nodep->user2(true); // Don't resize it again
|
||||
AstNodeDType* old_dtypep = nodep->dtypep();
|
||||
int width=cppWidth(nodep); // widthMin is unchanged
|
||||
if (old_dtypep->width() != width) {
|
||||
// Since any given dtype's cppWidth() is the same, we can just
|
||||
// remember one convertion for each, and reuse it
|
||||
nodep->user2(true); // Don't resize it again
|
||||
AstNodeDType* old_dtypep = nodep->dtypep();
|
||||
int width = cppWidth(nodep); // widthMin is unchanged
|
||||
if (old_dtypep->width() != width) {
|
||||
// Since any given dtype's cppWidth() is the same, we can just
|
||||
// remember one convertion for each, and reuse it
|
||||
if (AstNodeDType* new_dtypep = VN_CAST(old_dtypep->user3p(), NodeDType)) {
|
||||
nodep->dtypep(new_dtypep);
|
||||
} else {
|
||||
nodep->dtypeChgWidth(width, nodep->widthMin());
|
||||
AstNodeDType* new_dtypep2 = nodep->dtypep();
|
||||
if (new_dtypep2 == old_dtypep) nodep->v3fatalSrc("Dtype didn't change when width changed");
|
||||
old_dtypep->user3p(new_dtypep2); // Remember for next time
|
||||
}
|
||||
}
|
||||
nodep->dtypep(new_dtypep);
|
||||
} else {
|
||||
nodep->dtypeChgWidth(width, nodep->widthMin());
|
||||
AstNodeDType* new_dtypep2 = nodep->dtypep();
|
||||
if (new_dtypep2 == old_dtypep) nodep->v3fatalSrc("Dtype didn't change when width changed");
|
||||
old_dtypep->user3p(new_dtypep2); // Remember for next time
|
||||
}
|
||||
}
|
||||
}
|
||||
void computeCppWidth(AstNode* nodep) {
|
||||
if (!nodep->user2() && nodep->hasDType()) {
|
||||
if (!nodep->user2() && nodep->hasDType()) {
|
||||
if (VN_IS(nodep, Var) || VN_IS(nodep, NodeDType) // Don't want to change variable widths!
|
||||
|| VN_IS(nodep->dtypep()->skipRefp(), UnpackArrayDType)) { // Or arrays
|
||||
} else {
|
||||
setCppWidth(nodep);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
setCppWidth(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Store the clean state in the userp on each node
|
||||
void setCleanState(AstNode* nodep, CleanState clean) {
|
||||
nodep->user1(clean);
|
||||
nodep->user1(clean);
|
||||
}
|
||||
CleanState getCleanState(AstNode* nodep) {
|
||||
return static_cast<CleanState>(nodep->user1());
|
||||
}
|
||||
bool isClean(AstNode* nodep) {
|
||||
CleanState clstate = getCleanState(nodep);
|
||||
if (clstate==CS_CLEAN) return true;
|
||||
if (clstate==CS_DIRTY) return false;
|
||||
nodep->v3fatalSrc("Unknown clean state on node: "+nodep->prettyTypeName());
|
||||
return false;
|
||||
CleanState clstate = getCleanState(nodep);
|
||||
if (clstate==CS_CLEAN) return true;
|
||||
if (clstate==CS_DIRTY) return false;
|
||||
nodep->v3fatalSrc("Unknown clean state on node: "+nodep->prettyTypeName());
|
||||
return false;
|
||||
}
|
||||
void setClean(AstNode* nodep, bool isClean) {
|
||||
computeCppWidth(nodep); // Just to be sure it's in widthMin
|
||||
bool wholeUint = ((nodep->widthMin() % VL_WORDSIZE) == 0); //32,64,...
|
||||
setCleanState(nodep, ((isClean||wholeUint) ? CS_CLEAN:CS_DIRTY));
|
||||
bool wholeUint = ((nodep->widthMin() % VL_WORDSIZE) == 0); // 32,64,...
|
||||
setCleanState(nodep, ((isClean||wholeUint) ? CS_CLEAN:CS_DIRTY));
|
||||
}
|
||||
|
||||
// Operate on nodes
|
||||
void insertClean(AstNode* nodep) { // We'll insert ABOVE passed node
|
||||
UINFO(4," NeedClean "<<nodep<<endl);
|
||||
AstNRelinker relinkHandle;
|
||||
nodep->unlinkFrBack(&relinkHandle);
|
||||
//
|
||||
UINFO(4," NeedClean "<<nodep<<endl);
|
||||
AstNRelinker relinkHandle;
|
||||
nodep->unlinkFrBack(&relinkHandle);
|
||||
//
|
||||
computeCppWidth(nodep);
|
||||
V3Number mask (nodep, cppWidth(nodep));
|
||||
mask.setMask(nodep->widthMin());
|
||||
AstNode* cleanp = new AstAnd(nodep->fileline(),
|
||||
new AstConst(nodep->fileline(), mask),
|
||||
nodep);
|
||||
cleanp->dtypeFrom(nodep); // Otherwise the AND normally picks LHS
|
||||
relinkHandle.relink(cleanp);
|
||||
cleanp->dtypeFrom(nodep); // Otherwise the AND normally picks LHS
|
||||
relinkHandle.relink(cleanp);
|
||||
}
|
||||
void insureClean(AstNode* nodep) {
|
||||
computeCppWidth(nodep);
|
||||
if (!isClean(nodep)) insertClean(nodep);
|
||||
computeCppWidth(nodep);
|
||||
if (!isClean(nodep)) insertClean(nodep);
|
||||
}
|
||||
void insureCleanAndNext(AstNode* nodep) {
|
||||
// Editing list, careful looping!
|
||||
for (AstNode* exprp = nodep; exprp; ) {
|
||||
AstNode* nextp = exprp->nextp();
|
||||
insureClean(exprp);
|
||||
exprp = nextp;
|
||||
}
|
||||
// Editing list, careful looping!
|
||||
for (AstNode* exprp = nodep; exprp; ) {
|
||||
AstNode* nextp = exprp->nextp();
|
||||
insureClean(exprp);
|
||||
exprp = nextp;
|
||||
}
|
||||
}
|
||||
|
||||
// Base type handling methods
|
||||
void operandBiop(AstNodeBiop* nodep) {
|
||||
iterateChildren(nodep);
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanLhs()) {
|
||||
insureClean(nodep->lhsp());
|
||||
}
|
||||
if (nodep->cleanRhs()) {
|
||||
insureClean(nodep->rhsp());
|
||||
}
|
||||
//no setClean.. must do it in each user routine.
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanLhs()) {
|
||||
insureClean(nodep->lhsp());
|
||||
}
|
||||
if (nodep->cleanRhs()) {
|
||||
insureClean(nodep->rhsp());
|
||||
}
|
||||
//no setClean.. must do it in each user routine.
|
||||
}
|
||||
void operandTriop(AstNodeTriop* nodep) {
|
||||
iterateChildren(nodep);
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanLhs()) {
|
||||
insureClean(nodep->lhsp());
|
||||
}
|
||||
if (nodep->cleanRhs()) {
|
||||
insureClean(nodep->rhsp());
|
||||
}
|
||||
if (nodep->cleanThs()) {
|
||||
insureClean(nodep->thsp());
|
||||
}
|
||||
//no setClean.. must do it in each user routine.
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanLhs()) {
|
||||
insureClean(nodep->lhsp());
|
||||
}
|
||||
if (nodep->cleanRhs()) {
|
||||
insureClean(nodep->rhsp());
|
||||
}
|
||||
if (nodep->cleanThs()) {
|
||||
insureClean(nodep->thsp());
|
||||
}
|
||||
//no setClean.. must do it in each user routine.
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
m_modp = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstNodeUniop* nodep) {
|
||||
iterateChildren(nodep);
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanLhs()) {
|
||||
insureClean(nodep->lhsp());
|
||||
}
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanLhs()) {
|
||||
insureClean(nodep->lhsp());
|
||||
}
|
||||
setClean(nodep, nodep->cleanOut());
|
||||
}
|
||||
virtual void visit(AstNodeBiop* nodep) {
|
||||
operandBiop(nodep);
|
||||
operandBiop(nodep);
|
||||
setClean(nodep, nodep->cleanOut());
|
||||
}
|
||||
virtual void visit(AstAnd* nodep) {
|
||||
operandBiop(nodep);
|
||||
operandBiop(nodep);
|
||||
setClean(nodep, isClean(nodep->lhsp()) || isClean(nodep->rhsp()));
|
||||
}
|
||||
virtual void visit(AstXor* nodep) {
|
||||
operandBiop(nodep);
|
||||
operandBiop(nodep);
|
||||
setClean(nodep, isClean(nodep->lhsp()) && isClean(nodep->rhsp()));
|
||||
}
|
||||
virtual void visit(AstOr* nodep) {
|
||||
operandBiop(nodep);
|
||||
operandBiop(nodep);
|
||||
setClean(nodep, isClean(nodep->lhsp()) && isClean(nodep->rhsp()));
|
||||
}
|
||||
virtual void visit(AstNodeMath* nodep) {
|
||||
iterateChildren(nodep);
|
||||
computeCppWidth(nodep);
|
||||
computeCppWidth(nodep);
|
||||
setClean(nodep, nodep->cleanOut());
|
||||
}
|
||||
virtual void visit(AstNodeAssign* nodep) {
|
||||
iterateChildren(nodep);
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanRhs()) {
|
||||
insureClean(nodep->rhsp());
|
||||
}
|
||||
computeCppWidth(nodep);
|
||||
if (nodep->cleanRhs()) {
|
||||
insureClean(nodep->rhsp());
|
||||
}
|
||||
}
|
||||
virtual void visit(AstText* nodep) {
|
||||
setClean(nodep, true);
|
||||
|
|
@ -217,17 +217,17 @@ private:
|
|||
setClean(nodep, true);
|
||||
}
|
||||
virtual void visit(AstSel* nodep) {
|
||||
operandTriop(nodep);
|
||||
operandTriop(nodep);
|
||||
setClean(nodep, nodep->cleanOut());
|
||||
}
|
||||
virtual void visit(AstUCFunc* nodep) {
|
||||
iterateChildren(nodep);
|
||||
computeCppWidth(nodep);
|
||||
computeCppWidth(nodep);
|
||||
setClean(nodep, false);
|
||||
// We always clean, as we don't trust those pesky users.
|
||||
// We always clean, as we don't trust those pesky users.
|
||||
if (!VN_IS(nodep->backp(), And)) {
|
||||
insertClean(nodep);
|
||||
}
|
||||
insertClean(nodep);
|
||||
}
|
||||
insureCleanAndNext(nodep->bodysp());
|
||||
}
|
||||
virtual void visit(AstTraceDecl* nodep) {
|
||||
|
|
@ -239,32 +239,32 @@ private:
|
|||
insureCleanAndNext(nodep->valuep());
|
||||
}
|
||||
virtual void visit(AstTypedef* nodep) {
|
||||
// No cleaning, or would loose pointer to enum
|
||||
// No cleaning, or would loose pointer to enum
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstParamTypeDType* nodep) {
|
||||
// No cleaning, or would loose pointer to enum
|
||||
// No cleaning, or would loose pointer to enum
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
// Control flow operators
|
||||
virtual void visit(AstNodeCond* nodep) {
|
||||
iterateChildren(nodep);
|
||||
insureClean(nodep->condp());
|
||||
setClean(nodep, isClean(nodep->expr1p()) && isClean(nodep->expr2p()));
|
||||
insureClean(nodep->condp());
|
||||
setClean(nodep, isClean(nodep->expr1p()) && isClean(nodep->expr2p()));
|
||||
}
|
||||
virtual void visit(AstWhile* nodep) {
|
||||
iterateChildren(nodep);
|
||||
insureClean(nodep->condp());
|
||||
insureClean(nodep->condp());
|
||||
}
|
||||
virtual void visit(AstNodeIf* nodep) {
|
||||
iterateChildren(nodep);
|
||||
insureClean(nodep->condp());
|
||||
insureClean(nodep->condp());
|
||||
}
|
||||
virtual void visit(AstSFormatF* nodep) {
|
||||
iterateChildren(nodep);
|
||||
insureCleanAndNext(nodep->exprsp());
|
||||
setClean(nodep, true); // generates a string, so not relevant
|
||||
setClean(nodep, true); // generates a string, so not relevant
|
||||
}
|
||||
virtual void visit(AstUCStmt* nodep) {
|
||||
iterateChildren(nodep);
|
||||
|
|
@ -280,7 +280,7 @@ private:
|
|||
// Default: Just iterate
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
computeCppWidth(nodep);
|
||||
computeCppWidth(nodep);
|
||||
}
|
||||
|
||||
public:
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void cleanAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
1143
src/V3ClkGater.cpp
1143
src/V3ClkGater.cpp
File diff suppressed because it is too large
Load Diff
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void clkGaterAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
537
src/V3Clock.cpp
537
src/V3Clock.cpp
|
|
@ -22,11 +22,11 @@
|
|||
// Top Scope:
|
||||
// Check created ACTIVEs
|
||||
// Compress adjacent ACTIVEs with same sensitivity list
|
||||
// Form master _eval function
|
||||
// Add around the SENTREE a (IF POSEDGE(..))
|
||||
// Add a __Vlast_{clock} for the comparison
|
||||
// Set the __Vlast_{clock} at the end of the block
|
||||
// Replace UNTILSTABLEs with loops until specified signals become const.
|
||||
// Form master _eval function
|
||||
// Add around the SENTREE a (IF POSEDGE(..))
|
||||
// Add a __Vlast_{clock} for the comparison
|
||||
// Set the __Vlast_{clock} at the end of the block
|
||||
// Replace UNTILSTABLEs with loops until specified signals become const.
|
||||
// Create global calling function for any per-scope functions. (For FINALs).
|
||||
//
|
||||
//*************************************************************************
|
||||
|
|
@ -49,22 +49,22 @@ class ClockVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared each Module:
|
||||
// AstVarScope::user1p() -> AstVarScope*. Temporary signal that was created.
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstVarScope::user1p() -> AstVarScope*. Temporary signal that was created.
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// TYPES
|
||||
enum { DOUBLE_OR_RATE = 10 }; // How many | per ||, Determined experimentally as best
|
||||
enum { DOUBLE_OR_RATE = 10 }; // How many | per ||, Determined experimentally as best
|
||||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstTopScope* m_topScopep; // Current top scope
|
||||
AstScope* m_scopep; // Current scope
|
||||
AstCFunc* m_evalFuncp; // Top eval function we are creating
|
||||
AstCFunc* m_initFuncp; // Top initial function we are creating
|
||||
AstCFunc* m_finalFuncp; // Top final function we are creating
|
||||
AstCFunc* m_settleFuncp; // Top settlement function we are creating
|
||||
AstSenTree* m_lastSenp; // Last sensitivity match, so we can detect duplicates.
|
||||
AstIf* m_lastIfp; // Last sensitivity if active to add more under
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstTopScope* m_topScopep; // Current top scope
|
||||
AstScope* m_scopep; // Current scope
|
||||
AstCFunc* m_evalFuncp; // Top eval function we are creating
|
||||
AstCFunc* m_initFuncp; // Top initial function we are creating
|
||||
AstCFunc* m_finalFuncp; // Top final function we are creating
|
||||
AstCFunc* m_settleFuncp; // Top settlement function we are creating
|
||||
AstSenTree* m_lastSenp; // Last sensitivity match, so we can detect duplicates.
|
||||
AstIf* m_lastIfp; // Last sensitivity if active to add more under
|
||||
AstMTaskBody* m_mtaskBodyp; // Current mtask body
|
||||
|
||||
// METHODS
|
||||
|
|
@ -72,15 +72,18 @@ private:
|
|||
|
||||
AstVarScope* getCreateLastClk(AstVarScope* vscp) {
|
||||
if (vscp->user1p()) return static_cast<AstVarScope*>(vscp->user1p());
|
||||
AstVar* varp = vscp->varp();
|
||||
if (!varp->width1()) varp->v3error("Unsupported: Clock edge on non-single bit signal: "<<varp->prettyName());
|
||||
string newvarname = (string("__Vclklast__")+vscp->scopep()->nameDotless()+"__"+varp->name());
|
||||
AstVar* newvarp = new AstVar(vscp->fileline(), AstVarType::MODULETEMP, newvarname, VFlagLogicPacked(), 1);
|
||||
AstVar* varp = vscp->varp();
|
||||
if (!varp->width1()) varp->v3error("Unsupported: Clock edge on non-single bit signal: "
|
||||
<<varp->prettyName());
|
||||
string newvarname = (string("__Vclklast__")
|
||||
+vscp->scopep()->nameDotless()+"__"+varp->name());
|
||||
AstVar* newvarp = new AstVar(vscp->fileline(),
|
||||
AstVarType::MODULETEMP, newvarname, VFlagLogicPacked(), 1);
|
||||
newvarp->noReset(true); // Reset by below assign
|
||||
m_modp->addStmtp(newvarp);
|
||||
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopep, newvarp);
|
||||
vscp->user1p(newvscp);
|
||||
m_scopep->addVarp(newvscp);
|
||||
m_modp->addStmtp(newvarp);
|
||||
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopep, newvarp);
|
||||
vscp->user1p(newvscp);
|
||||
m_scopep->addVarp(newvscp);
|
||||
// Add init
|
||||
AstNode* fromp = new AstVarRef(newvarp->fileline(), vscp, false);
|
||||
if (v3Global.opt.xInitialEdge()) fromp = new AstNot(fromp->fileline(), fromp);
|
||||
|
|
@ -88,243 +91,245 @@ private:
|
|||
new AstVarRef(newvarp->fileline(), newvscp, true),
|
||||
fromp);
|
||||
addToInitial(newinitp);
|
||||
// At bottom, assign them
|
||||
AstAssign* finalp
|
||||
// At bottom, assign them
|
||||
AstAssign* finalp
|
||||
= new AstAssign(vscp->fileline(),
|
||||
new AstVarRef(vscp->fileline(), newvscp, true),
|
||||
new AstVarRef(vscp->fileline(), vscp, false));
|
||||
m_evalFuncp->addFinalsp(finalp);
|
||||
//
|
||||
UINFO(4,"New Last: "<<newvscp<<endl);
|
||||
return newvscp;
|
||||
m_evalFuncp->addFinalsp(finalp);
|
||||
//
|
||||
UINFO(4,"New Last: "<<newvscp<<endl);
|
||||
return newvscp;
|
||||
}
|
||||
AstNode* createSenItemEquation(AstSenItem* nodep) {
|
||||
// We know the var is clean, and one bit, so we use binary ops
|
||||
// for speed instead of logical ops.
|
||||
// POSEDGE: var & ~var_last
|
||||
// NEGEDGE: ~var & var_last
|
||||
// BOTHEDGE: var ^ var_last
|
||||
// HIGHEDGE: var
|
||||
// LOWEDGE: ~var
|
||||
AstNode* newp = NULL;
|
||||
if (nodep->edgeType()==AstEdgeType::ET_ILLEGAL) {
|
||||
if (!v3Global.opt.bboxUnsup()) {
|
||||
nodep->v3error("Unsupported: Complicated event expression in sensitive activity list");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
AstVarScope* clkvscp = nodep->varrefp()->varScopep();
|
||||
if (nodep->edgeType()==AstEdgeType::ET_POSEDGE) {
|
||||
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
||||
newp = new AstAnd(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
nodep->varrefp()->varScopep(), false),
|
||||
new AstNot(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
lastVscp, false)));
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_NEGEDGE) {
|
||||
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
||||
newp = new AstAnd(nodep->fileline(),
|
||||
new AstNot(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
nodep->varrefp()->varScopep(), false)),
|
||||
new AstVarRef(nodep->fileline(), lastVscp, false));
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_BOTHEDGE) {
|
||||
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
||||
newp = new AstXor(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
nodep->varrefp()->varScopep(), false),
|
||||
new AstVarRef(nodep->fileline(), lastVscp, false));
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_HIGHEDGE) {
|
||||
newp = new AstVarRef(nodep->fileline(),
|
||||
clkvscp, false);
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_LOWEDGE) {
|
||||
newp = new AstNot(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
clkvscp, false));
|
||||
} else {
|
||||
nodep->v3fatalSrc("Bad edge type");
|
||||
}
|
||||
return newp;
|
||||
// We know the var is clean, and one bit, so we use binary ops
|
||||
// for speed instead of logical ops.
|
||||
// POSEDGE: var & ~var_last
|
||||
// NEGEDGE: ~var & var_last
|
||||
// BOTHEDGE: var ^ var_last
|
||||
// HIGHEDGE: var
|
||||
// LOWEDGE: ~var
|
||||
AstNode* newp = NULL;
|
||||
if (nodep->edgeType()==AstEdgeType::ET_ILLEGAL) {
|
||||
if (!v3Global.opt.bboxUnsup()) {
|
||||
nodep->v3error("Unsupported: Complicated event expression in sensitive activity list");
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
AstVarScope* clkvscp = nodep->varrefp()->varScopep();
|
||||
if (nodep->edgeType()==AstEdgeType::ET_POSEDGE) {
|
||||
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
||||
newp = new AstAnd(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
nodep->varrefp()->varScopep(), false),
|
||||
new AstNot(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
lastVscp, false)));
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_NEGEDGE) {
|
||||
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
||||
newp = new AstAnd(nodep->fileline(),
|
||||
new AstNot(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
nodep->varrefp()->varScopep(), false)),
|
||||
new AstVarRef(nodep->fileline(), lastVscp, false));
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_BOTHEDGE) {
|
||||
AstVarScope* lastVscp = getCreateLastClk(clkvscp);
|
||||
newp = new AstXor(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
nodep->varrefp()->varScopep(), false),
|
||||
new AstVarRef(nodep->fileline(), lastVscp, false));
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_HIGHEDGE) {
|
||||
newp = new AstVarRef(nodep->fileline(),
|
||||
clkvscp, false);
|
||||
} else if (nodep->edgeType()==AstEdgeType::ET_LOWEDGE) {
|
||||
newp = new AstNot(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(),
|
||||
clkvscp, false));
|
||||
} else {
|
||||
nodep->v3fatalSrc("Bad edge type");
|
||||
}
|
||||
return newp;
|
||||
}
|
||||
AstNode* createSenGateEquation(AstSenGate* nodep) {
|
||||
AstNode* newp = new AstAnd(nodep->fileline(),
|
||||
createSenseEquation(nodep->sensesp()),
|
||||
nodep->rhsp()->cloneTree(true));
|
||||
return newp;
|
||||
AstNode* newp = new AstAnd(nodep->fileline(),
|
||||
createSenseEquation(nodep->sensesp()),
|
||||
nodep->rhsp()->cloneTree(true));
|
||||
return newp;
|
||||
}
|
||||
AstNode* createSenseEquation(AstNodeSenItem* nodesp) {
|
||||
// Nodep may be a list of elements; we need to walk it
|
||||
AstNode* senEqnp = NULL;
|
||||
for (AstNodeSenItem* senp = nodesp; senp; senp=VN_CAST(senp->nextp(), NodeSenItem)) {
|
||||
AstNode* senOnep = NULL;
|
||||
// Nodep may be a list of elements; we need to walk it
|
||||
AstNode* senEqnp = NULL;
|
||||
for (AstNodeSenItem* senp = nodesp; senp; senp = VN_CAST(senp->nextp(), NodeSenItem)) {
|
||||
AstNode* senOnep = NULL;
|
||||
if (AstSenItem* itemp = VN_CAST(senp, SenItem)) {
|
||||
senOnep = createSenItemEquation(itemp);
|
||||
senOnep = createSenItemEquation(itemp);
|
||||
} else if (AstSenGate* itemp = VN_CAST(senp, SenGate)) {
|
||||
senOnep = createSenGateEquation(itemp);
|
||||
} else {
|
||||
senp->v3fatalSrc("Strange node under sentree");
|
||||
}
|
||||
if (senEqnp) {
|
||||
// Add new OR to the sensitivity list equation
|
||||
senEqnp = new AstOr(senp->fileline(), senEqnp, senOnep);
|
||||
} else {
|
||||
senEqnp = senOnep;
|
||||
}
|
||||
}
|
||||
return senEqnp;
|
||||
senOnep = createSenGateEquation(itemp);
|
||||
} else {
|
||||
senp->v3fatalSrc("Strange node under sentree");
|
||||
}
|
||||
if (senEqnp) {
|
||||
// Add new OR to the sensitivity list equation
|
||||
senEqnp = new AstOr(senp->fileline(), senEqnp, senOnep);
|
||||
} else {
|
||||
senEqnp = senOnep;
|
||||
}
|
||||
}
|
||||
return senEqnp;
|
||||
}
|
||||
AstIf* makeActiveIf(AstSenTree* sensesp) {
|
||||
AstNode* senEqnp = createSenseEquation(sensesp->sensesp());
|
||||
if (!senEqnp) sensesp->v3fatalSrc("No sense equation, shouldn't be in sequent activation.");
|
||||
AstNode* senEqnp = createSenseEquation(sensesp->sensesp());
|
||||
if (!senEqnp) sensesp->v3fatalSrc("No sense equation, shouldn't be in sequent activation.");
|
||||
AstIf* newifp = new AstIf(sensesp->fileline(), senEqnp, NULL, NULL);
|
||||
return (newifp);
|
||||
return (newifp);
|
||||
}
|
||||
void clearLastSen() {
|
||||
m_lastSenp = NULL;
|
||||
m_lastIfp = NULL;
|
||||
m_lastSenp = NULL;
|
||||
m_lastIfp = NULL;
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstTopScope* nodep) {
|
||||
UINFO(4," TOPSCOPE "<<nodep<<endl);
|
||||
m_topScopep=nodep;
|
||||
m_scopep = nodep->scopep();
|
||||
if (!m_scopep) nodep->v3fatalSrc("No scope found on top level, perhaps you have no statements?");
|
||||
//VV***** We reset all user1p()
|
||||
AstNode::user1ClearTree();
|
||||
// Make top functions
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval", m_scopep);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->dontCombine(true);
|
||||
funcp->symProlog(true);
|
||||
funcp->isStatic(true);
|
||||
funcp->entryPoint(true);
|
||||
m_scopep->addActivep(funcp);
|
||||
m_evalFuncp = funcp;
|
||||
}
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval_initial", m_scopep);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->dontCombine(true);
|
||||
funcp->slow(true);
|
||||
funcp->symProlog(true);
|
||||
funcp->isStatic(true);
|
||||
funcp->entryPoint(true);
|
||||
m_scopep->addActivep(funcp);
|
||||
m_initFuncp = funcp;
|
||||
}
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "final", m_scopep);
|
||||
funcp->skipDecl(true);
|
||||
funcp->dontCombine(true);
|
||||
funcp->slow(true);
|
||||
funcp->isStatic(false);
|
||||
funcp->entryPoint(true);
|
||||
funcp->addInitsp(new AstCStmt(nodep->fileline(),
|
||||
EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n"));
|
||||
funcp->addInitsp(new AstCStmt(nodep->fileline(), EmitCBaseVisitor::symTopAssign()+"\n"));
|
||||
m_scopep->addActivep(funcp);
|
||||
m_finalFuncp = funcp;
|
||||
}
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval_settle", m_scopep);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->dontCombine(true);
|
||||
funcp->slow(true);
|
||||
funcp->isStatic(true);
|
||||
funcp->symProlog(true);
|
||||
funcp->entryPoint(true);
|
||||
m_scopep->addActivep(funcp);
|
||||
m_settleFuncp = funcp;
|
||||
}
|
||||
// Process the activates
|
||||
UINFO(4," TOPSCOPE "<<nodep<<endl);
|
||||
m_topScopep = nodep;
|
||||
m_scopep = nodep->scopep();
|
||||
if (!m_scopep) nodep->v3fatalSrc("No scope found on top level, perhaps you have no statements?");
|
||||
//VV***** We reset all user1p()
|
||||
AstNode::user1ClearTree();
|
||||
// Make top functions
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval", m_scopep);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->dontCombine(true);
|
||||
funcp->symProlog(true);
|
||||
funcp->isStatic(true);
|
||||
funcp->entryPoint(true);
|
||||
m_scopep->addActivep(funcp);
|
||||
m_evalFuncp = funcp;
|
||||
}
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval_initial", m_scopep);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->dontCombine(true);
|
||||
funcp->slow(true);
|
||||
funcp->symProlog(true);
|
||||
funcp->isStatic(true);
|
||||
funcp->entryPoint(true);
|
||||
m_scopep->addActivep(funcp);
|
||||
m_initFuncp = funcp;
|
||||
}
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "final", m_scopep);
|
||||
funcp->skipDecl(true);
|
||||
funcp->dontCombine(true);
|
||||
funcp->slow(true);
|
||||
funcp->isStatic(false);
|
||||
funcp->entryPoint(true);
|
||||
funcp->addInitsp(new AstCStmt
|
||||
(nodep->fileline(),
|
||||
EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n"));
|
||||
funcp->addInitsp(new AstCStmt(nodep->fileline(),
|
||||
EmitCBaseVisitor::symTopAssign()+"\n"));
|
||||
m_scopep->addActivep(funcp);
|
||||
m_finalFuncp = funcp;
|
||||
}
|
||||
{
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), "_eval_settle", m_scopep);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->dontCombine(true);
|
||||
funcp->slow(true);
|
||||
funcp->isStatic(true);
|
||||
funcp->symProlog(true);
|
||||
funcp->entryPoint(true);
|
||||
m_scopep->addActivep(funcp);
|
||||
m_settleFuncp = funcp;
|
||||
}
|
||||
// Process the activates
|
||||
iterateChildren(nodep);
|
||||
// Done, clear so we can detect errors
|
||||
UINFO(4," TOPSCOPEDONE "<<nodep<<endl);
|
||||
clearLastSen();
|
||||
m_topScopep=NULL;
|
||||
m_scopep = NULL;
|
||||
// Done, clear so we can detect errors
|
||||
UINFO(4," TOPSCOPEDONE "<<nodep<<endl);
|
||||
clearLastSen();
|
||||
m_topScopep = NULL;
|
||||
m_scopep = NULL;
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
//UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
//UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_modp= NULL;
|
||||
m_modp= NULL;
|
||||
}
|
||||
virtual void visit(AstScope* nodep) {
|
||||
//UINFO(4," SCOPE "<<nodep<<endl);
|
||||
m_scopep = nodep;
|
||||
//UINFO(4," SCOPE "<<nodep<<endl);
|
||||
m_scopep = nodep;
|
||||
iterateChildren(nodep);
|
||||
if (AstNode* movep = nodep->finalClksp()) {
|
||||
if (!m_topScopep) nodep->v3fatalSrc("Final clocks under non-top scope");
|
||||
movep->unlinkFrBackWithNext();
|
||||
m_evalFuncp->addFinalsp(movep);
|
||||
}
|
||||
m_scopep = NULL;
|
||||
if (AstNode* movep = nodep->finalClksp()) {
|
||||
if (!m_topScopep) nodep->v3fatalSrc("Final clocks under non-top scope");
|
||||
movep->unlinkFrBackWithNext();
|
||||
m_evalFuncp->addFinalsp(movep);
|
||||
}
|
||||
m_scopep = NULL;
|
||||
}
|
||||
virtual void visit(AstAlways* nodep) {
|
||||
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
||||
nodep->replaceWith(cmtp);
|
||||
if (AstNode* stmtsp = nodep->bodysp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
cmtp->addNextHere(stmtsp);
|
||||
}
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
||||
nodep->replaceWith(cmtp);
|
||||
if (AstNode* stmtsp = nodep->bodysp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
cmtp->addNextHere(stmtsp);
|
||||
}
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstAlwaysPost* nodep) {
|
||||
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
||||
nodep->replaceWith(cmtp);
|
||||
if (AstNode* stmtsp = nodep->bodysp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
cmtp->addNextHere(stmtsp);
|
||||
}
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
||||
nodep->replaceWith(cmtp);
|
||||
if (AstNode* stmtsp = nodep->bodysp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
cmtp->addNextHere(stmtsp);
|
||||
}
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstCoverToggle* nodep) {
|
||||
//nodep->dumpTree(cout,"ct:");
|
||||
//COVERTOGGLE(INC, ORIG, CHANGE) ->
|
||||
// IF(ORIG ^ CHANGE) { INC; CHANGE = ORIG; }
|
||||
AstNode* incp = nodep->incp()->unlinkFrBack();
|
||||
AstNode* origp = nodep->origp()->unlinkFrBack();
|
||||
AstNode* changep = nodep->changep()->unlinkFrBack();
|
||||
AstIf* newp = new AstIf(nodep->fileline(),
|
||||
new AstXor(nodep->fileline(),
|
||||
origp,
|
||||
changep),
|
||||
incp, NULL);
|
||||
// We could add another IF to detect posedges, and only increment if so.
|
||||
// It's another whole branch though verus a potential memory miss.
|
||||
// We'll go with the miss.
|
||||
newp->addIfsp(new AstAssign(nodep->fileline(),
|
||||
changep->cloneTree(false),
|
||||
origp->cloneTree(false)));
|
||||
nodep->replaceWith(newp); nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
//nodep->dumpTree(cout, "ct:");
|
||||
//COVERTOGGLE(INC, ORIG, CHANGE) ->
|
||||
// IF(ORIG ^ CHANGE) { INC; CHANGE = ORIG; }
|
||||
AstNode* incp = nodep->incp()->unlinkFrBack();
|
||||
AstNode* origp = nodep->origp()->unlinkFrBack();
|
||||
AstNode* changep = nodep->changep()->unlinkFrBack();
|
||||
AstIf* newp = new AstIf(nodep->fileline(),
|
||||
new AstXor(nodep->fileline(),
|
||||
origp,
|
||||
changep),
|
||||
incp, NULL);
|
||||
// We could add another IF to detect posedges, and only increment if so.
|
||||
// It's another whole branch though verus a potential memory miss.
|
||||
// We'll go with the miss.
|
||||
newp->addIfsp(new AstAssign(nodep->fileline(),
|
||||
changep->cloneTree(false),
|
||||
origp->cloneTree(false)));
|
||||
nodep->replaceWith(newp); nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstInitial* nodep) {
|
||||
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
||||
nodep->replaceWith(cmtp);
|
||||
if (AstNode* stmtsp = nodep->bodysp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
cmtp->addNextHere(stmtsp);
|
||||
}
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
AstNode* cmtp = new AstComment(nodep->fileline(), nodep->typeName());
|
||||
nodep->replaceWith(cmtp);
|
||||
if (AstNode* stmtsp = nodep->bodysp()) {
|
||||
stmtsp->unlinkFrBackWithNext();
|
||||
cmtp->addNextHere(stmtsp);
|
||||
}
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
iterateChildren(nodep);
|
||||
// Link to global function
|
||||
if (nodep->formCallTree()) {
|
||||
UINFO(4, " formCallTree "<<nodep<<endl);
|
||||
AstCCall* callp = new AstCCall(nodep->fileline(), nodep);
|
||||
callp->argTypes("vlSymsp");
|
||||
m_finalFuncp->addStmtsp(callp);
|
||||
}
|
||||
// Link to global function
|
||||
if (nodep->formCallTree()) {
|
||||
UINFO(4, " formCallTree "<<nodep<<endl);
|
||||
AstCCall* callp = new AstCCall(nodep->fileline(), nodep);
|
||||
callp->argTypes("vlSymsp");
|
||||
m_finalFuncp->addStmtsp(callp);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstSenTree* nodep) {
|
||||
// Delete it later; Actives still pointing to it
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep);
|
||||
// Delete it later; Actives still pointing to it
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep);
|
||||
}
|
||||
void addToEvalLoop(AstNode* stmtsp) {
|
||||
m_evalFuncp->addStmtsp(stmtsp); // add to top level function
|
||||
|
|
@ -336,13 +341,13 @@ private:
|
|||
m_initFuncp->addStmtsp(stmtsp); // add to top level function
|
||||
}
|
||||
virtual void visit(AstActive* nodep) {
|
||||
// Careful if adding variables here, ACTIVES can be under other ACTIVES
|
||||
// Need to save and restore any member state in AstUntilStable block
|
||||
if (!m_topScopep || !nodep->stmtsp()) {
|
||||
// Not at the top or empty block...
|
||||
// Only empty blocks should be leftover on the non-top. Killem.
|
||||
if (nodep->stmtsp()) nodep->v3fatalSrc("Non-empty lower active");
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
// Careful if adding variables here, ACTIVES can be under other ACTIVES
|
||||
// Need to save and restore any member state in AstUntilStable block
|
||||
if (!m_topScopep || !nodep->stmtsp()) {
|
||||
// Not at the top or empty block...
|
||||
// Only empty blocks should be leftover on the non-top. Killem.
|
||||
if (nodep->stmtsp()) nodep->v3fatalSrc("Non-empty lower active");
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
} else if (m_mtaskBodyp) {
|
||||
UINFO(4," TR ACTIVE "<<nodep<<endl);
|
||||
AstNode* stmtsp = nodep->stmtsp()->unlinkFrBackWithNext();
|
||||
|
|
@ -367,39 +372,39 @@ private:
|
|||
m_mtaskBodyp->addStmtsp(stmtsp);
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
} else {
|
||||
UINFO(4," ACTIVE "<<nodep<<endl);
|
||||
AstNode* stmtsp = nodep->stmtsp()->unlinkFrBackWithNext();
|
||||
if (nodep->hasClocked()) {
|
||||
// Remember the latest sensitivity so we can compare it next time
|
||||
if (nodep->hasInitial()) nodep->v3fatalSrc("Initial block should not have clock sensitivity");
|
||||
if (m_lastSenp && nodep->sensesp()->sameTree(m_lastSenp)) {
|
||||
UINFO(4," sameSenseTree\n");
|
||||
} else {
|
||||
clearLastSen();
|
||||
m_lastSenp = nodep->sensesp();
|
||||
// Make a new if statement
|
||||
m_lastIfp = makeActiveIf(m_lastSenp);
|
||||
addToEvalLoop(m_lastIfp);
|
||||
}
|
||||
// Move statements to if
|
||||
m_lastIfp->addIfsp(stmtsp);
|
||||
} else if (nodep->hasInitial()) {
|
||||
// Don't need to: clearLastSen();, as we're adding it to different cfunc
|
||||
// Move statements to function
|
||||
addToInitial(stmtsp);
|
||||
} else if (nodep->hasSettle()) {
|
||||
// Don't need to: clearLastSen();, as we're adding it to different cfunc
|
||||
// Move statements to function
|
||||
addToSettleLoop(stmtsp);
|
||||
} else {
|
||||
// Combo
|
||||
clearLastSen();
|
||||
// Move statements to function
|
||||
addToEvalLoop(stmtsp);
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
} else {
|
||||
UINFO(4," ACTIVE "<<nodep<<endl);
|
||||
AstNode* stmtsp = nodep->stmtsp()->unlinkFrBackWithNext();
|
||||
if (nodep->hasClocked()) {
|
||||
// Remember the latest sensitivity so we can compare it next time
|
||||
if (nodep->hasInitial()) nodep->v3fatalSrc("Initial block should not have clock sensitivity");
|
||||
if (m_lastSenp && nodep->sensesp()->sameTree(m_lastSenp)) {
|
||||
UINFO(4," sameSenseTree\n");
|
||||
} else {
|
||||
clearLastSen();
|
||||
m_lastSenp = nodep->sensesp();
|
||||
// Make a new if statement
|
||||
m_lastIfp = makeActiveIf(m_lastSenp);
|
||||
addToEvalLoop(m_lastIfp);
|
||||
}
|
||||
// Move statements to if
|
||||
m_lastIfp->addIfsp(stmtsp);
|
||||
} else if (nodep->hasInitial()) {
|
||||
// Don't need to: clearLastSen();, as we're adding it to different cfunc
|
||||
// Move statements to function
|
||||
addToInitial(stmtsp);
|
||||
} else if (nodep->hasSettle()) {
|
||||
// Don't need to: clearLastSen();, as we're adding it to different cfunc
|
||||
// Move statements to function
|
||||
addToSettleLoop(stmtsp);
|
||||
} else {
|
||||
// Combo
|
||||
clearLastSen();
|
||||
// Move statements to function
|
||||
addToEvalLoop(stmtsp);
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstExecGraph* nodep) {
|
||||
for (m_mtaskBodyp = VN_CAST(nodep->op1p(), MTaskBody);
|
||||
|
|
@ -426,16 +431,16 @@ public:
|
|||
// CONSTUCTORS
|
||||
explicit ClockVisitor(AstNetlist* nodep) {
|
||||
m_modp = NULL;
|
||||
m_evalFuncp = NULL;
|
||||
m_evalFuncp = NULL;
|
||||
m_initFuncp = NULL;
|
||||
m_finalFuncp = NULL;
|
||||
m_settleFuncp = NULL;
|
||||
m_topScopep = NULL;
|
||||
m_lastSenp = NULL;
|
||||
m_lastIfp = NULL;
|
||||
m_scopep = NULL;
|
||||
m_lastIfp = NULL;
|
||||
m_scopep = NULL;
|
||||
m_mtaskBodyp = NULL;
|
||||
//
|
||||
//
|
||||
iterate(nodep);
|
||||
// Allow downstream modules to find _eval()
|
||||
// easily without iterating through the tree.
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void clockAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -19,18 +19,18 @@
|
|||
//*************************************************************************
|
||||
// V3Combine's Transformations:
|
||||
//
|
||||
// For every function that we spit out
|
||||
// Examine code to find largest common blocks
|
||||
// Hash each node depth first
|
||||
// Hash includes varp name and operator type, and constants
|
||||
// Form lookup table based on hash of each statement w/ nodep and next nodep
|
||||
// GO through table
|
||||
// Lookup in hash, while next of each statement match, grow that common block
|
||||
// Foreach common block
|
||||
// If common block large enough (> 20 statements) & used 2x or more
|
||||
// Make new function
|
||||
// Move common block to function
|
||||
// Replace each common block ref with funccall
|
||||
// For every function that we spit out
|
||||
// Examine code to find largest common blocks
|
||||
// Hash each node depth first
|
||||
// Hash includes varp name and operator type, and constants
|
||||
// Form lookup table based on hash of each statement w/ nodep and next nodep
|
||||
// GO through table
|
||||
// Lookup in hash, while next of each statement match, grow that common block
|
||||
// Foreach common block
|
||||
// If common block large enough (> 20 statements) & used 2x or more
|
||||
// Make new function
|
||||
// Move common block to function
|
||||
// Replace each common block ref with funccall
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -50,7 +50,7 @@
|
|||
|
||||
//######################################################################
|
||||
|
||||
#define COMBINE_MIN_STATEMENTS 50 // Min # of statements to be worth making a function
|
||||
#define COMBINE_MIN_STATEMENTS 50 // Min # of statements to be worth making a function
|
||||
|
||||
//######################################################################
|
||||
|
||||
|
|
@ -79,57 +79,59 @@ class CombCallVisitor : CombBaseVisitor {
|
|||
// Find all CCALLS of each CFUNC, so that we can later rename them
|
||||
private:
|
||||
// NODE STATE
|
||||
bool m_find; // Find mode vs. delete mode
|
||||
bool m_find; // Find mode vs. delete mode
|
||||
typedef std::multimap<AstCFunc*,AstCCall*> CallMmap;
|
||||
CallMmap m_callMmap; // Associative array of {function}{call}
|
||||
CallMmap m_callMmap; // Associative array of {function}{call}
|
||||
// METHODS
|
||||
public:
|
||||
void replaceFunc(AstCFunc* oldfuncp, AstCFunc* newfuncp) {
|
||||
if (oldfuncp==newfuncp) return;
|
||||
if (newfuncp) {
|
||||
UINFO(4, " Replace "<<oldfuncp<<" -WITH-> "<<newfuncp<<endl);
|
||||
} else UINFO(4, " Remove "<<oldfuncp<<endl);
|
||||
std::pair <CallMmap::iterator,CallMmap::iterator> eqrange = m_callMmap.equal_range(oldfuncp);
|
||||
for (CallMmap::iterator nextit = eqrange.first; nextit != eqrange.second;) {
|
||||
CallMmap::iterator eqit = nextit++;
|
||||
AstCCall* callp = eqit->second;
|
||||
if (!callp->user3()) { // !already done
|
||||
UINFO(4, " Called "<<callp<<endl);
|
||||
if (callp->funcp() != oldfuncp) callp->v3fatalSrc("Call list broken, points to call w/different func");
|
||||
if (newfuncp) {
|
||||
AstCCall* newp = new AstCCall(callp, newfuncp);
|
||||
// Special new AstCCall form above transfers children of callp to newfuncp
|
||||
callp->replaceWith(newp);
|
||||
addCall(newp); // Fix the table
|
||||
} else { // Just deleting empty function
|
||||
callp->unlinkFrBack();
|
||||
}
|
||||
callp->user3(true); // Dead now
|
||||
pushDeletep(callp); VL_DANGLING(callp);
|
||||
m_callMmap.erase(eqit); // Fix the table
|
||||
}
|
||||
}
|
||||
if (oldfuncp==newfuncp) return;
|
||||
if (newfuncp) {
|
||||
UINFO(4, " Replace "<<oldfuncp<<" -WITH-> "<<newfuncp<<endl);
|
||||
} else UINFO(4, " Remove "<<oldfuncp<<endl);
|
||||
std::pair <CallMmap::iterator,CallMmap::iterator> eqrange
|
||||
= m_callMmap.equal_range(oldfuncp);
|
||||
for (CallMmap::iterator nextit = eqrange.first; nextit != eqrange.second;) {
|
||||
CallMmap::iterator eqit = nextit++;
|
||||
AstCCall* callp = eqit->second;
|
||||
if (!callp->user3()) { // !already done
|
||||
UINFO(4, " Called "<<callp<<endl);
|
||||
if (callp->funcp() != oldfuncp) callp->v3fatalSrc("Call list broken, points to call w/different func");
|
||||
if (newfuncp) {
|
||||
AstCCall* newp = new AstCCall(callp, newfuncp);
|
||||
// Special new AstCCall form above transfers children of callp to newfuncp
|
||||
callp->replaceWith(newp);
|
||||
addCall(newp); // Fix the table
|
||||
} else { // Just deleting empty function
|
||||
callp->unlinkFrBack();
|
||||
}
|
||||
callp->user3(true); // Dead now
|
||||
pushDeletep(callp); VL_DANGLING(callp);
|
||||
m_callMmap.erase(eqit); // Fix the table
|
||||
}
|
||||
}
|
||||
}
|
||||
// METHODS
|
||||
void addCall(AstCCall* nodep) {
|
||||
m_callMmap.insert(make_pair(nodep->funcp(), nodep));
|
||||
m_callMmap.insert(make_pair(nodep->funcp(), nodep));
|
||||
}
|
||||
void deleteCall(AstCCall* nodep) {
|
||||
std::pair<CallMmap::iterator,CallMmap::iterator> eqrange = m_callMmap.equal_range(nodep->funcp());
|
||||
for (CallMmap::iterator nextit = eqrange.first; nextit != eqrange.second;) {
|
||||
CallMmap::iterator eqit = nextit++;
|
||||
AstCCall* callp = eqit->second;
|
||||
if (callp==nodep) {
|
||||
m_callMmap.erase(eqit);
|
||||
return;
|
||||
}
|
||||
}
|
||||
nodep->v3fatalSrc("deleteCall node not found in table");
|
||||
std::pair<CallMmap::iterator,CallMmap::iterator> eqrange
|
||||
= m_callMmap.equal_range(nodep->funcp());
|
||||
for (CallMmap::iterator nextit = eqrange.first; nextit != eqrange.second;) {
|
||||
CallMmap::iterator eqit = nextit++;
|
||||
AstCCall* callp = eqit->second;
|
||||
if (callp==nodep) {
|
||||
m_callMmap.erase(eqit);
|
||||
return;
|
||||
}
|
||||
}
|
||||
nodep->v3fatalSrc("deleteCall node not found in table");
|
||||
}
|
||||
private:
|
||||
// VISITORS
|
||||
virtual void visit(AstCCall* nodep) {
|
||||
addCall(nodep);
|
||||
addCall(nodep);
|
||||
}
|
||||
// Speed things up
|
||||
virtual void visit(AstNodeAssign* nodep) {}
|
||||
|
|
@ -140,7 +142,7 @@ private:
|
|||
public:
|
||||
// CONSTRUCTORS
|
||||
CombCallVisitor() {
|
||||
m_find = false;
|
||||
m_find = false;
|
||||
}
|
||||
virtual ~CombCallVisitor() {}
|
||||
void main(AstNetlist* nodep) {
|
||||
|
|
@ -155,10 +157,10 @@ class CombMarkVisitor : CombBaseVisitor {
|
|||
// Mark all nodes under specified one.
|
||||
private:
|
||||
// OUTPUT:
|
||||
// AstNode::user3() -> bool. True to indicate duplicated
|
||||
// AstNode::user3() -> bool. True to indicate duplicated
|
||||
// VISITORS
|
||||
virtual void visit(AstNode* nodep) {
|
||||
nodep->user3(true);
|
||||
nodep->user3(true);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
public:
|
||||
|
|
@ -176,273 +178,276 @@ class CombineVisitor : CombBaseVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstNodeStmt::user() -> bool. True if iterated already
|
||||
// AstCFunc::user3p() -> AstCFunc*, If set, replace ccalls to this func with new func
|
||||
// AstNodeStmt::user3() -> AstNode*. True if to ignore this cell
|
||||
// AstNodeStmt::user4() -> V3Hashed::V3Hash. Hash value of this node (hash of 0 is illegal)
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser3InUse m_inuser3;
|
||||
//AstUser4InUse part of V3Hashed
|
||||
// AstNodeStmt::user() -> bool. True if iterated already
|
||||
// AstCFunc::user3p() -> AstCFunc*, If set, replace ccalls to this func with new func
|
||||
// AstNodeStmt::user3() -> AstNode*. True if to ignore this cell
|
||||
// AstNodeStmt::user4() -> V3Hashed::V3Hash. Hash value of this node (hash of 0 is illegal)
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser3InUse m_inuser3;
|
||||
//AstUser4InUse part of V3Hashed
|
||||
|
||||
// STATE
|
||||
typedef enum {STATE_IDLE, STATE_HASH, STATE_DUP} CombineState;
|
||||
V3Double0 m_statCombs; // Statistic tracking
|
||||
CombineState m_state; // Major state
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_funcp; // Current function
|
||||
V3Hash m_lowerHash; // Hash of the statement we're building
|
||||
CombCallVisitor m_call; // Tracking of function call users
|
||||
int m_modNFuncs; // Number of functions made
|
||||
AstNode* m_walkLast1p; // Final node that is the same in duplicate list
|
||||
AstNode* m_walkLast2p; // Final node that is the same in duplicate list
|
||||
V3Hashed m_hashed; // Hash for every node in module
|
||||
V3Double0 m_statCombs; // Statistic tracking
|
||||
CombineState m_state; // Major state
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_funcp; // Current function
|
||||
V3Hash m_lowerHash; // Hash of the statement we're building
|
||||
CombCallVisitor m_call; // Tracking of function call users
|
||||
int m_modNFuncs; // Number of functions made
|
||||
AstNode* m_walkLast1p; // Final node that is the same in duplicate list
|
||||
AstNode* m_walkLast2p; // Final node that is the same in duplicate list
|
||||
V3Hashed m_hashed; // Hash for every node in module
|
||||
|
||||
// METHODS
|
||||
void hashStatement(AstNode* nodep) {
|
||||
// Compute hash on entire tree of this statement
|
||||
m_hashed.hashAndInsert(nodep);
|
||||
//UINFO(9," stmthash "<<hex<<nodep->user4()<<" "<<nodep<<endl);
|
||||
// Compute hash on entire tree of this statement
|
||||
m_hashed.hashAndInsert(nodep);
|
||||
//UINFO(9," stmthash "<<hex<<nodep->user4()<<" "<<nodep<<endl);
|
||||
}
|
||||
void hashFunctions(AstCFunc* nodep) {
|
||||
// Compute hash of all statement trees in the function
|
||||
CombineState oldState = m_state;
|
||||
{
|
||||
m_state = STATE_HASH;
|
||||
// Compute hash of all statement trees in the function
|
||||
CombineState oldState = m_state;
|
||||
{
|
||||
m_state = STATE_HASH;
|
||||
iterate(nodep);
|
||||
}
|
||||
m_state = oldState;
|
||||
}
|
||||
m_state = oldState;
|
||||
}
|
||||
void walkEmptyFuncs() {
|
||||
for (V3Hashed::iterator it = m_hashed.begin(); it != m_hashed.end(); ++it) {
|
||||
AstNode* node1p = it->second;
|
||||
for (V3Hashed::iterator it = m_hashed.begin(); it != m_hashed.end(); ++it) {
|
||||
AstNode* node1p = it->second;
|
||||
AstCFunc* oldfuncp = VN_CAST(node1p, CFunc);
|
||||
if (oldfuncp
|
||||
&& oldfuncp->emptyBody()
|
||||
&& !oldfuncp->dontCombine()) {
|
||||
UINFO(5," EmptyFunc "<<std::hex<<V3Hash(oldfuncp->user4p())<<" "<<oldfuncp<<endl);
|
||||
// Mark user3p on entire old tree, so we don't process it more
|
||||
CombMarkVisitor visitor(oldfuncp);
|
||||
m_call.replaceFunc(oldfuncp, NULL);
|
||||
oldfuncp->unlinkFrBack();
|
||||
pushDeletep(oldfuncp); VL_DANGLING(oldfuncp);
|
||||
}
|
||||
}
|
||||
if (oldfuncp
|
||||
&& oldfuncp->emptyBody()
|
||||
&& !oldfuncp->dontCombine()) {
|
||||
UINFO(5," EmptyFunc "<<std::hex<<V3Hash(oldfuncp->user4p())
|
||||
<<" "<<oldfuncp<<endl);
|
||||
// Mark user3p on entire old tree, so we don't process it more
|
||||
CombMarkVisitor visitor(oldfuncp);
|
||||
m_call.replaceFunc(oldfuncp, NULL);
|
||||
oldfuncp->unlinkFrBack();
|
||||
pushDeletep(oldfuncp); VL_DANGLING(oldfuncp);
|
||||
}
|
||||
}
|
||||
}
|
||||
void walkDupFuncs() {
|
||||
for (V3Hashed::iterator it = m_hashed.begin(); it != m_hashed.end(); ++it) {
|
||||
V3Hash hashval = it->first;
|
||||
AstNode* node1p = it->second;
|
||||
for (V3Hashed::iterator it = m_hashed.begin(); it != m_hashed.end(); ++it) {
|
||||
V3Hash hashval = it->first;
|
||||
AstNode* node1p = it->second;
|
||||
if (!VN_IS(node1p, CFunc)) continue;
|
||||
if (hashval.isIllegal()) node1p->v3fatalSrc("Illegal (unhashed) nodes");
|
||||
for (V3Hashed::iterator eqit = it; eqit != m_hashed.end(); ++eqit) {
|
||||
AstNode* node2p = eqit->second;
|
||||
if (!(eqit->first == hashval)) break;
|
||||
if (node1p==node2p) continue; // Identical iterator
|
||||
if (node1p->user3p() || node2p->user3p()) continue; // Already merged
|
||||
if (node1p->sameTree(node2p)) { // walk of tree has same comparison
|
||||
// Replace AstCCall's that point here
|
||||
if (hashval.isIllegal()) node1p->v3fatalSrc("Illegal (unhashed) nodes");
|
||||
for (V3Hashed::iterator eqit = it; eqit != m_hashed.end(); ++eqit) {
|
||||
AstNode* node2p = eqit->second;
|
||||
if (!(eqit->first == hashval)) break;
|
||||
if (node1p==node2p) continue; // Identical iterator
|
||||
if (node1p->user3p() || node2p->user3p()) continue; // Already merged
|
||||
if (node1p->sameTree(node2p)) { // walk of tree has same comparison
|
||||
// Replace AstCCall's that point here
|
||||
replaceFuncWFunc(VN_CAST(node2p, CFunc), VN_CAST(node1p, CFunc));
|
||||
// Replacement may promote a slow routine to fast path
|
||||
// Replacement may promote a slow routine to fast path
|
||||
if (!VN_CAST(node2p, CFunc)->slow()) VN_CAST(node1p, CFunc)->slow(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
void replaceFuncWFunc(AstCFunc* oldfuncp, AstCFunc* newfuncp) {
|
||||
UINFO(5," DupFunc "<<std::hex<<V3Hash(newfuncp->user4p())<<" "<<newfuncp<<endl);
|
||||
UINFO(5," and "<<std::hex<<V3Hash(oldfuncp->user4p())<<" "<<oldfuncp<<endl);
|
||||
// Mark user3p on entire old tree, so we don't process it more
|
||||
++m_statCombs;
|
||||
CombMarkVisitor visitor(oldfuncp);
|
||||
m_call.replaceFunc(oldfuncp, newfuncp);
|
||||
oldfuncp->unlinkFrBack();
|
||||
pushDeletep(oldfuncp); VL_DANGLING(oldfuncp);
|
||||
// Mark user3p on entire old tree, so we don't process it more
|
||||
++m_statCombs;
|
||||
CombMarkVisitor visitor(oldfuncp);
|
||||
m_call.replaceFunc(oldfuncp, newfuncp);
|
||||
oldfuncp->unlinkFrBack();
|
||||
pushDeletep(oldfuncp); VL_DANGLING(oldfuncp);
|
||||
}
|
||||
void replaceOnlyCallFunc(AstCCall* nodep) {
|
||||
if (AstCFunc* oldfuncp = VN_CAST(nodep->backp(), CFunc)) {
|
||||
//oldfuncp->dumpTree(cout,"MAYDEL: ");
|
||||
if (nodep->nextp()==NULL
|
||||
&& oldfuncp->initsp()==NULL
|
||||
&& oldfuncp->stmtsp()==nodep
|
||||
&& oldfuncp->finalsp()==NULL) {
|
||||
UINFO(9," Function only has call "<<oldfuncp<<endl);
|
||||
m_call.deleteCall(nodep);
|
||||
CombMarkVisitor visitor(oldfuncp);
|
||||
replaceFuncWFunc(oldfuncp, nodep->funcp()); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
//oldfuncp->dumpTree(cout, "MAYDEL: ");
|
||||
if (nodep->nextp()==NULL
|
||||
&& oldfuncp->initsp()==NULL
|
||||
&& oldfuncp->stmtsp()==nodep
|
||||
&& oldfuncp->finalsp()==NULL) {
|
||||
UINFO(9," Function only has call "<<oldfuncp<<endl);
|
||||
m_call.deleteCall(nodep);
|
||||
CombMarkVisitor visitor(oldfuncp);
|
||||
replaceFuncWFunc(oldfuncp, nodep->funcp()); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void walkDupCodeStart(AstNode* node1p) {
|
||||
V3Hash hashval(node1p->user4p());
|
||||
//UINFO(4," STMT "<<hashval<<" "<<node1p<<endl);
|
||||
//
|
||||
int bestDepth = 0; // Best substitution found in the search
|
||||
AstNode* bestNode2p = NULL;
|
||||
AstNode* bestLast1p = NULL;
|
||||
AstNode* bestLast2p = NULL;
|
||||
//
|
||||
std::pair<V3Hashed::iterator,V3Hashed::iterator> eqrange = m_hashed.mmap().equal_range(hashval);
|
||||
for (V3Hashed::iterator eqit = eqrange.first; eqit != eqrange.second; ++eqit) {
|
||||
AstNode* node2p = eqit->second;
|
||||
if (node1p==node2p) continue;
|
||||
//
|
||||
// We need to mark iteration to prevent matching code inside code (abab matching in ababab)
|
||||
AstNode::user1ClearTree(); // user1p() used on entire tree
|
||||
m_walkLast1p = NULL;
|
||||
m_walkLast2p = NULL;
|
||||
int depth = walkDupCodeNext(node1p, node2p, 1);
|
||||
if (depth>COMBINE_MIN_STATEMENTS
|
||||
&& depth>bestDepth) {
|
||||
bestDepth = depth;
|
||||
bestNode2p = node2p;
|
||||
bestLast1p = m_walkLast1p;
|
||||
bestLast2p = m_walkLast2p;
|
||||
}
|
||||
}
|
||||
if (bestDepth) {
|
||||
// Found a replacement
|
||||
UINFO(5," Duplicate of depth "<<bestDepth<<endl);
|
||||
UINFO(5," DupFunc "<<" "<<node1p<<endl);
|
||||
UINFO(5," and "<<" "<<bestNode2p<<endl);
|
||||
UINFO(5," Through "<<" "<<bestLast1p<<endl);
|
||||
UINFO(5," and "<<" "<<bestLast2p<<endl);
|
||||
//
|
||||
walkReplace(node1p, bestNode2p, bestLast1p, bestLast2p);
|
||||
}
|
||||
//UINFO(4," STMT "<<hashval<<" "<<node1p<<endl);
|
||||
//
|
||||
int bestDepth = 0; // Best substitution found in the search
|
||||
AstNode* bestNode2p = NULL;
|
||||
AstNode* bestLast1p = NULL;
|
||||
AstNode* bestLast2p = NULL;
|
||||
//
|
||||
std::pair<V3Hashed::iterator,V3Hashed::iterator> eqrange
|
||||
= m_hashed.mmap().equal_range(hashval);
|
||||
for (V3Hashed::iterator eqit = eqrange.first; eqit != eqrange.second; ++eqit) {
|
||||
AstNode* node2p = eqit->second;
|
||||
if (node1p==node2p) continue;
|
||||
//
|
||||
// We need to mark iteration to prevent matching code inside
|
||||
// code (abab matching in ababab)
|
||||
AstNode::user1ClearTree(); // user1p() used on entire tree
|
||||
m_walkLast1p = NULL;
|
||||
m_walkLast2p = NULL;
|
||||
int depth = walkDupCodeNext(node1p, node2p, 1);
|
||||
if (depth>COMBINE_MIN_STATEMENTS
|
||||
&& depth>bestDepth) {
|
||||
bestDepth = depth;
|
||||
bestNode2p = node2p;
|
||||
bestLast1p = m_walkLast1p;
|
||||
bestLast2p = m_walkLast2p;
|
||||
}
|
||||
}
|
||||
if (bestDepth) {
|
||||
// Found a replacement
|
||||
UINFO(5," Duplicate of depth "<<bestDepth<<endl);
|
||||
UINFO(5," DupFunc "<<" "<<node1p<<endl);
|
||||
UINFO(5," and "<<" "<<bestNode2p<<endl);
|
||||
UINFO(5," Through "<<" "<<bestLast1p<<endl);
|
||||
UINFO(5," and "<<" "<<bestLast2p<<endl);
|
||||
//
|
||||
walkReplace(node1p, bestNode2p, bestLast1p, bestLast2p);
|
||||
}
|
||||
}
|
||||
|
||||
int walkDupCodeNext(AstNode* node1p, AstNode* node2p, int level) {
|
||||
// Find number of common statements between the two node1p_nextp's...
|
||||
if (node1p->user1p() || node2p->user1p()) return 0; // Already iterated
|
||||
if (node1p->user3p() || node2p->user3p()) return 0; // Already merged
|
||||
if (!m_hashed.sameNodes(node1p,node2p)) return 0; // walk of tree has same comparison
|
||||
V3Hash hashval(node1p->user4p());
|
||||
//UINFO(9," wdup1 "<<level<<" "<<V3Hash(node1p->user4p())<<" "<<node1p<<endl);
|
||||
//UINFO(9," wdup2 "<<level<<" "<<V3Hash(node2p->user4p())<<" "<<node2p<<endl);
|
||||
m_walkLast1p = node1p;
|
||||
m_walkLast2p = node2p;
|
||||
node1p->user1(true);
|
||||
node2p->user1(true);
|
||||
if (node1p->nextp() && node2p->nextp()) {
|
||||
return hashval.depth()+walkDupCodeNext(node1p->nextp(), node2p->nextp(), level+1);
|
||||
}
|
||||
return hashval.depth();
|
||||
// Find number of common statements between the two node1p_nextp's...
|
||||
if (node1p->user1p() || node2p->user1p()) return 0; // Already iterated
|
||||
if (node1p->user3p() || node2p->user3p()) return 0; // Already merged
|
||||
if (!m_hashed.sameNodes(node1p, node2p)) return 0; // walk of tree has same comparison
|
||||
V3Hash hashval(node1p->user4p());
|
||||
//UINFO(9," wdup1 "<<level<<" "<<V3Hash(node1p->user4p())<<" "<<node1p<<endl);
|
||||
//UINFO(9," wdup2 "<<level<<" "<<V3Hash(node2p->user4p())<<" "<<node2p<<endl);
|
||||
m_walkLast1p = node1p;
|
||||
m_walkLast2p = node2p;
|
||||
node1p->user1(true);
|
||||
node2p->user1(true);
|
||||
if (node1p->nextp() && node2p->nextp()) {
|
||||
return hashval.depth()+walkDupCodeNext(node1p->nextp(), node2p->nextp(), level+1);
|
||||
}
|
||||
return hashval.depth();
|
||||
}
|
||||
|
||||
void walkReplace(AstNode* node1p, AstNode* node2p,
|
||||
AstNode* last1p, AstNode* last2p) { // Final node in linked list, maybe null if all statements to be grabbed
|
||||
// Make new function
|
||||
string oldname = m_funcp->name();
|
||||
string::size_type pos;
|
||||
if ((pos=oldname.find("_common")) != string::npos) {
|
||||
oldname.erase(pos);
|
||||
}
|
||||
if ((pos=oldname.find("__")) != string::npos) {
|
||||
oldname.erase(pos);
|
||||
}
|
||||
AstCFunc* newfuncp = new AstCFunc(node1p->fileline(),
|
||||
oldname+"_common"+cvtToStr(++m_modNFuncs),
|
||||
NULL);
|
||||
m_modp->addStmtp(newfuncp);
|
||||
// Create calls
|
||||
AstCCall* call1p = new AstCCall(node1p->fileline(), newfuncp);
|
||||
AstCCall* call2p = new AstCCall(node2p->fileline(), newfuncp);
|
||||
// Grab statement bodies
|
||||
AstNRelinker relink1Handle;
|
||||
AstNRelinker relink2Handle;
|
||||
for (AstNode* nextp, *walkp = node1p; 1; walkp = nextp) {
|
||||
nextp = walkp->nextp();
|
||||
if (walkp==node1p) walkp->unlinkFrBack(&relink1Handle);
|
||||
else { walkp->unlinkFrBack(); node1p->addNext(walkp); }
|
||||
if (walkp==last1p) break;
|
||||
}
|
||||
for (AstNode* nextp, *walkp = node2p; 1; walkp = nextp) {
|
||||
nextp = walkp->nextp();
|
||||
if (walkp==node2p) walkp->unlinkFrBack(&relink2Handle);
|
||||
else { walkp->unlinkFrBack(); node2p->addNext(walkp); }
|
||||
if (walkp==last2p) break;
|
||||
}
|
||||
// Move node1 statements to new function
|
||||
newfuncp->addStmtsp(node1p);
|
||||
//newfuncp->dumpTree(cout," newfunctree: ");
|
||||
// Mark node2 statements as dead
|
||||
CombMarkVisitor visitor(node2p);
|
||||
pushDeletep(node2p); // Delete later
|
||||
// Link in new function
|
||||
relink1Handle.relink(call1p);
|
||||
relink2Handle.relink(call2p);
|
||||
// Hash the new function
|
||||
hashFunctions(newfuncp);
|
||||
m_call.addCall(call1p);
|
||||
m_call.addCall(call2p);
|
||||
// If either new statement makes a func with only a single call, replace
|
||||
// the above callers to call it directly
|
||||
replaceOnlyCallFunc(call1p); VL_DANGLING(call1p);
|
||||
replaceOnlyCallFunc(call2p); VL_DANGLING(call2p);
|
||||
AstNode* last1p, AstNode* last2p) { // Final node in linked list, maybe null if all statements to be grabbed
|
||||
// Make new function
|
||||
string oldname = m_funcp->name();
|
||||
string::size_type pos;
|
||||
if ((pos = oldname.find("_common")) != string::npos) {
|
||||
oldname.erase(pos);
|
||||
}
|
||||
if ((pos = oldname.find("__")) != string::npos) {
|
||||
oldname.erase(pos);
|
||||
}
|
||||
AstCFunc* newfuncp = new AstCFunc(node1p->fileline(),
|
||||
oldname+"_common"+cvtToStr(++m_modNFuncs),
|
||||
NULL);
|
||||
m_modp->addStmtp(newfuncp);
|
||||
// Create calls
|
||||
AstCCall* call1p = new AstCCall(node1p->fileline(), newfuncp);
|
||||
AstCCall* call2p = new AstCCall(node2p->fileline(), newfuncp);
|
||||
// Grab statement bodies
|
||||
AstNRelinker relink1Handle;
|
||||
AstNRelinker relink2Handle;
|
||||
for (AstNode* nextp, *walkp = node1p; 1; walkp = nextp) {
|
||||
nextp = walkp->nextp();
|
||||
if (walkp==node1p) walkp->unlinkFrBack(&relink1Handle);
|
||||
else { walkp->unlinkFrBack(); node1p->addNext(walkp); }
|
||||
if (walkp==last1p) break;
|
||||
}
|
||||
for (AstNode* nextp, *walkp = node2p; 1; walkp = nextp) {
|
||||
nextp = walkp->nextp();
|
||||
if (walkp==node2p) walkp->unlinkFrBack(&relink2Handle);
|
||||
else { walkp->unlinkFrBack(); node2p->addNext(walkp); }
|
||||
if (walkp==last2p) break;
|
||||
}
|
||||
// Move node1 statements to new function
|
||||
newfuncp->addStmtsp(node1p);
|
||||
//newfuncp->dumpTree(cout, " newfunctree: ");
|
||||
// Mark node2 statements as dead
|
||||
CombMarkVisitor visitor(node2p);
|
||||
pushDeletep(node2p); // Delete later
|
||||
// Link in new function
|
||||
relink1Handle.relink(call1p);
|
||||
relink2Handle.relink(call2p);
|
||||
// Hash the new function
|
||||
hashFunctions(newfuncp);
|
||||
m_call.addCall(call1p);
|
||||
m_call.addCall(call2p);
|
||||
// If either new statement makes a func with only a single call, replace
|
||||
// the above callers to call it directly
|
||||
replaceOnlyCallFunc(call1p); VL_DANGLING(call1p);
|
||||
replaceOnlyCallFunc(call2p); VL_DANGLING(call2p);
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNetlist* nodep) {
|
||||
// Track all callers of each function
|
||||
m_call.main(nodep);
|
||||
//
|
||||
//In V3Hashed AstNode::user4ClearTree(); // user4p() used on entire tree
|
||||
// Iterate modules backwards, in bottom-up order.
|
||||
// Required so that a module instantiating another can benefit from collapsing.
|
||||
// Track all callers of each function
|
||||
m_call.main(nodep);
|
||||
//
|
||||
//In V3Hashed AstNode::user4ClearTree(); // user4p() used on entire tree
|
||||
// Iterate modules backwards, in bottom-up order.
|
||||
// Required so that a module instantiating another can benefit from collapsing.
|
||||
iterateChildrenBackwards(nodep);
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
m_modNFuncs = 0;
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
m_modNFuncs = 0;
|
||||
m_walkLast2p = NULL;
|
||||
m_hashed.clear();
|
||||
// Compute hash of all statement trees in the function
|
||||
m_state = STATE_HASH;
|
||||
m_hashed.clear();
|
||||
// Compute hash of all statement trees in the function
|
||||
m_state = STATE_HASH;
|
||||
iterateChildren(nodep);
|
||||
m_state = STATE_IDLE;
|
||||
if (debug()>=9) {
|
||||
m_hashed.dumpFilePrefixed("combine");
|
||||
}
|
||||
// Walk the hashes removing empty functions
|
||||
if (emptyFunctionDeletion()) {
|
||||
walkEmptyFuncs();
|
||||
}
|
||||
// Walk the hashes looking for duplicate functions
|
||||
if (duplicateFunctionCombine()) {
|
||||
walkDupFuncs();
|
||||
}
|
||||
// Walk the statements looking for large replicated code sections
|
||||
if (statementCombine()) {
|
||||
m_state = STATE_DUP;
|
||||
m_state = STATE_IDLE;
|
||||
if (debug()>=9) {
|
||||
m_hashed.dumpFilePrefixed("combine");
|
||||
}
|
||||
// Walk the hashes removing empty functions
|
||||
if (emptyFunctionDeletion()) {
|
||||
walkEmptyFuncs();
|
||||
}
|
||||
// Walk the hashes looking for duplicate functions
|
||||
if (duplicateFunctionCombine()) {
|
||||
walkDupFuncs();
|
||||
}
|
||||
// Walk the statements looking for large replicated code sections
|
||||
if (statementCombine()) {
|
||||
m_state = STATE_DUP;
|
||||
iterateChildren(nodep);
|
||||
m_state = STATE_IDLE;
|
||||
}
|
||||
m_modp = NULL;
|
||||
m_state = STATE_IDLE;
|
||||
}
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
m_funcp = nodep;
|
||||
if (!nodep->dontCombine()) {
|
||||
if (m_state == STATE_HASH) {
|
||||
hashStatement(nodep); // Hash the entire function - it might be identical
|
||||
} else if (m_state == STATE_DUP) {
|
||||
m_funcp = nodep;
|
||||
if (!nodep->dontCombine()) {
|
||||
if (m_state == STATE_HASH) {
|
||||
hashStatement(nodep); // Hash the entire function - it might be identical
|
||||
} else if (m_state == STATE_DUP) {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
}
|
||||
m_funcp = NULL;
|
||||
}
|
||||
}
|
||||
m_funcp = NULL;
|
||||
}
|
||||
virtual void visit(AstNodeStmt* nodep) {
|
||||
if (!nodep->isStatement()) {
|
||||
iterateChildren(nodep);
|
||||
return;
|
||||
}
|
||||
if (m_state == STATE_HASH && m_funcp) {
|
||||
hashStatement(nodep);
|
||||
}
|
||||
else if (m_state == STATE_DUP && m_funcp) {
|
||||
walkDupCodeStart(nodep);
|
||||
}
|
||||
if (m_state == STATE_HASH && m_funcp) {
|
||||
hashStatement(nodep);
|
||||
}
|
||||
else if (m_state == STATE_DUP && m_funcp) {
|
||||
walkDupCodeStart(nodep);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------
|
||||
|
|
@ -457,7 +462,7 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit CombineVisitor(AstNetlist* nodep) {
|
||||
m_state = STATE_IDLE;
|
||||
m_state = STATE_IDLE;
|
||||
m_modp = NULL;
|
||||
m_funcp = NULL;
|
||||
m_modNFuncs = 0;
|
||||
|
|
@ -466,7 +471,7 @@ public:
|
|||
iterate(nodep);
|
||||
}
|
||||
virtual ~CombineVisitor() {
|
||||
V3Stats::addStat("Optimizations, Combined CFuncs", m_statCombs);
|
||||
V3Stats::addStat("Optimizations, Combined CFuncs", m_statCombs);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void combineAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
157
src/V3Config.cpp
157
src/V3Config.cpp
|
|
@ -33,110 +33,113 @@
|
|||
|
||||
class V3ConfigLine {
|
||||
public:
|
||||
int m_lineno; // Line number to make change at
|
||||
V3ErrorCode m_code; // Error code
|
||||
bool m_on; // True to enaable message
|
||||
int m_lineno; // Line number to make change at
|
||||
V3ErrorCode m_code; // Error code
|
||||
bool m_on; // True to enaable message
|
||||
V3ConfigLine(V3ErrorCode code, int lineno, bool on)
|
||||
: m_lineno(lineno), m_code(code), m_on(on) {}
|
||||
: m_lineno(lineno), m_code(code), m_on(on) {}
|
||||
~V3ConfigLine() {}
|
||||
inline bool operator< (const V3ConfigLine& rh) const {
|
||||
if (m_lineno<rh.m_lineno) return true;
|
||||
if (m_lineno>rh.m_lineno) return false;
|
||||
if (m_code<rh.m_code) return true;
|
||||
if (m_code>rh.m_code) return false;
|
||||
// Always turn "on" before "off" so that overlapping lines will end up finally with the error "off"
|
||||
return (m_on>rh.m_on);
|
||||
if (m_lineno<rh.m_lineno) return true;
|
||||
if (m_lineno>rh.m_lineno) return false;
|
||||
if (m_code<rh.m_code) return true;
|
||||
if (m_code>rh.m_code) return false;
|
||||
// Always turn "on" before "off" so that overlapping lines will end
|
||||
// up finally with the error "off"
|
||||
return (m_on>rh.m_on);
|
||||
}
|
||||
};
|
||||
std::ostream& operator<<(std::ostream& os, V3ConfigLine rhs) { return os<<rhs.m_lineno<<", "<<rhs.m_code<<", "<<rhs.m_on; }
|
||||
std::ostream& operator<<(std::ostream& os, V3ConfigLine rhs) {
|
||||
return os<<rhs.m_lineno<<", "<<rhs.m_code<<", "<<rhs.m_on; }
|
||||
|
||||
class V3ConfigIgnores {
|
||||
typedef std::multiset<V3ConfigLine> IgnLines; // list of {line,code,on}
|
||||
typedef std::map<string,IgnLines> IgnFiles; // {filename} => list of {line,code,on}
|
||||
|
||||
// MEMBERS
|
||||
string m_lastFilename; // Last filename looked up
|
||||
int m_lastLineno; // Last linenumber looked up
|
||||
string m_lastFilename; // Last filename looked up
|
||||
int m_lastLineno; // Last linenumber looked up
|
||||
|
||||
IgnLines::const_iterator m_lastIt; // Point with next linenumber > current line number
|
||||
IgnLines::const_iterator m_lastEnd; // Point with end()
|
||||
IgnLines::const_iterator m_lastIt; // Point with next linenumber > current line number
|
||||
IgnLines::const_iterator m_lastEnd; // Point with end()
|
||||
|
||||
IgnFiles m_ignWilds; // Ignores for each wildcarded filename
|
||||
IgnFiles m_ignFiles; // Ignores for each non-wildcarded filename
|
||||
IgnFiles m_ignWilds; // Ignores for each wildcarded filename
|
||||
IgnFiles m_ignFiles; // Ignores for each non-wildcarded filename
|
||||
|
||||
static V3ConfigIgnores s_singleton; // Singleton (not via local static, as that's slow)
|
||||
static V3ConfigIgnores s_singleton; // Singleton (not via local static, as that's slow)
|
||||
|
||||
V3ConfigIgnores() { m_lastLineno = -1; }
|
||||
~V3ConfigIgnores() {}
|
||||
|
||||
// METHODS
|
||||
inline IgnLines* findWilds(const string& wildname) {
|
||||
IgnFiles::iterator it = m_ignWilds.find(wildname);
|
||||
if (it != m_ignWilds.end()) {
|
||||
return &(it->second);
|
||||
} else {
|
||||
m_ignWilds.insert(make_pair(wildname, IgnLines()));
|
||||
it = m_ignWilds.find(wildname);
|
||||
return &(it->second);
|
||||
}
|
||||
IgnFiles::iterator it = m_ignWilds.find(wildname);
|
||||
if (it != m_ignWilds.end()) {
|
||||
return &(it->second);
|
||||
} else {
|
||||
m_ignWilds.insert(make_pair(wildname, IgnLines()));
|
||||
it = m_ignWilds.find(wildname);
|
||||
return &(it->second);
|
||||
}
|
||||
}
|
||||
inline void absBuild(const string& filename) {
|
||||
// Given a filename, find all wildcard matches against it and build
|
||||
// hash with the specific filename. This avoids having to wildmatch
|
||||
// more than once against any filename.
|
||||
IgnFiles::iterator it = m_ignFiles.find(filename);
|
||||
if (it == m_ignFiles.end()) {
|
||||
// Haven't seen this filename before
|
||||
m_ignFiles.insert(make_pair(filename, IgnLines()));
|
||||
it = m_ignFiles.find(filename);
|
||||
// Make new list for this file of all matches
|
||||
for (IgnFiles::iterator fnit = m_ignWilds.begin(); fnit != m_ignWilds.end(); ++fnit) {
|
||||
if (VString::wildmatch(filename.c_str(), fnit->first.c_str())) {
|
||||
for (IgnLines::iterator lit = fnit->second.begin(); lit != fnit->second.end(); ++lit) {
|
||||
it->second.insert(*lit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_lastIt = it->second.begin();
|
||||
m_lastEnd = it->second.end();
|
||||
// Given a filename, find all wildcard matches against it and build
|
||||
// hash with the specific filename. This avoids having to wildmatch
|
||||
// more than once against any filename.
|
||||
IgnFiles::iterator it = m_ignFiles.find(filename);
|
||||
if (it == m_ignFiles.end()) {
|
||||
// Haven't seen this filename before
|
||||
m_ignFiles.insert(make_pair(filename, IgnLines()));
|
||||
it = m_ignFiles.find(filename);
|
||||
// Make new list for this file of all matches
|
||||
for (IgnFiles::iterator fnit = m_ignWilds.begin(); fnit != m_ignWilds.end(); ++fnit) {
|
||||
if (VString::wildmatch(filename.c_str(), fnit->first.c_str())) {
|
||||
for (IgnLines::iterator lit = fnit->second.begin();
|
||||
lit != fnit->second.end(); ++lit) {
|
||||
it->second.insert(*lit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
m_lastIt = it->second.begin();
|
||||
m_lastEnd = it->second.end();
|
||||
}
|
||||
|
||||
public:
|
||||
inline static V3ConfigIgnores& singleton() { return s_singleton; }
|
||||
|
||||
void addIgnore(V3ErrorCode code, const string& wildname, int lineno, bool on) {
|
||||
// Insert
|
||||
IgnLines* linesp = findWilds(wildname);
|
||||
UINFO(9,"config addIgnore "<<wildname<<":"<<lineno<<", "<<code<<", "<<on<<endl);
|
||||
linesp->insert(V3ConfigLine(code, lineno, on));
|
||||
// Flush the match cache, due to a change in the rules.
|
||||
m_ignFiles.clear();
|
||||
m_lastFilename = " ";
|
||||
// Insert
|
||||
IgnLines* linesp = findWilds(wildname);
|
||||
UINFO(9,"config addIgnore "<<wildname<<":"<<lineno<<", "<<code<<", "<<on<<endl);
|
||||
linesp->insert(V3ConfigLine(code, lineno, on));
|
||||
// Flush the match cache, due to a change in the rules.
|
||||
m_ignFiles.clear();
|
||||
m_lastFilename = " ";
|
||||
}
|
||||
inline void applyIgnores(FileLine* filelinep) {
|
||||
// HOT routine, called each parsed token line
|
||||
if (m_lastLineno != filelinep->lineno()
|
||||
|| m_lastFilename != filelinep->filename()) {
|
||||
//UINFO(9," ApplyIgnores for "<<filelinep->ascii()<<endl);
|
||||
if (VL_UNLIKELY(m_lastFilename != filelinep->filename())) {
|
||||
absBuild(filelinep->filename());
|
||||
m_lastFilename = filelinep->filename();
|
||||
}
|
||||
// Process all on/offs for lines up to and including the current line
|
||||
int curlineno = filelinep->lineno();
|
||||
for (; m_lastIt != m_lastEnd; ++m_lastIt) {
|
||||
if (m_lastIt->m_lineno > curlineno) break;
|
||||
//UINFO(9," Hit "<<*m_lastIt<<endl);
|
||||
filelinep->warnOn(m_lastIt->m_code, m_lastIt->m_on);
|
||||
}
|
||||
if (0 && debug() >= 9) {
|
||||
for (IgnLines::const_iterator it=m_lastIt; it != m_lastEnd; ++it) {
|
||||
UINFO(9," NXT "<<*it<<endl);
|
||||
}
|
||||
}
|
||||
m_lastLineno = filelinep->lineno();
|
||||
}
|
||||
// HOT routine, called each parsed token line
|
||||
if (m_lastLineno != filelinep->lineno()
|
||||
|| m_lastFilename != filelinep->filename()) {
|
||||
//UINFO(9," ApplyIgnores for "<<filelinep->ascii()<<endl);
|
||||
if (VL_UNLIKELY(m_lastFilename != filelinep->filename())) {
|
||||
absBuild(filelinep->filename());
|
||||
m_lastFilename = filelinep->filename();
|
||||
}
|
||||
// Process all on/offs for lines up to and including the current line
|
||||
int curlineno = filelinep->lineno();
|
||||
for (; m_lastIt != m_lastEnd; ++m_lastIt) {
|
||||
if (m_lastIt->m_lineno > curlineno) break;
|
||||
//UINFO(9," Hit "<<*m_lastIt<<endl);
|
||||
filelinep->warnOn(m_lastIt->m_code, m_lastIt->m_on);
|
||||
}
|
||||
if (0 && debug() >= 9) {
|
||||
for (IgnLines::const_iterator it=m_lastIt; it != m_lastEnd; ++it) {
|
||||
UINFO(9," NXT "<<*it<<endl);
|
||||
}
|
||||
}
|
||||
m_lastLineno = filelinep->lineno();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -147,10 +150,10 @@ V3ConfigIgnores V3ConfigIgnores::s_singleton;
|
|||
|
||||
void V3Config::addIgnore(V3ErrorCode code, bool on, const string& filename, int min, int max) {
|
||||
if (filename=="*") {
|
||||
FileLine::globalWarnOff(code,!on);
|
||||
FileLine::globalWarnOff(code,!on);
|
||||
} else {
|
||||
V3ConfigIgnores::singleton().addIgnore(code, filename, min, on);
|
||||
if (max) V3ConfigIgnores::singleton().addIgnore(code, filename, max, !on);
|
||||
V3ConfigIgnores::singleton().addIgnore(code, filename, min, on);
|
||||
if (max) V3ConfigIgnores::singleton().addIgnore(code, filename, max, !on);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -35,4 +35,4 @@ public:
|
|||
static void applyIgnores(FileLine* filelinep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
3254
src/V3Const.cpp
3254
src/V3Const.cpp
File diff suppressed because it is too large
Load Diff
|
|
@ -49,4 +49,4 @@ public:
|
|||
static AstNode* constifyExpensiveEdit(AstNode* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// COVERAGE TRANSFORMATIONS:
|
||||
// At each IF/(IF else)/CASEITEM,
|
||||
// If there's no coverage off on the block below it,
|
||||
// or a $stop
|
||||
// Insert a COVERDECL node in the module.
|
||||
// (V3Emit reencodes into per-module numbers for emitting.)
|
||||
// Insert a COVERINC node at the end of the statement list
|
||||
// for that if/else/case.
|
||||
// At each IF/(IF else)/CASEITEM,
|
||||
// If there's no coverage off on the block below it,
|
||||
// or a $stop
|
||||
// Insert a COVERDECL node in the module.
|
||||
// (V3Emit reencodes into per-module numbers for emitting.)
|
||||
// Insert a COVERINC node at the end of the statement list
|
||||
// for that if/else/case.
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -47,334 +47,347 @@ private:
|
|||
typedef std::map<string,int> FileMap;
|
||||
|
||||
struct ToggleEnt {
|
||||
string m_comment; // Comment for coverage dump
|
||||
AstNode* m_varRefp; // How to get to this element
|
||||
AstNode* m_chgRefp; // How to get to this element
|
||||
ToggleEnt(const string& comment, AstNode* vp, AstNode* cp)
|
||||
: m_comment(comment), m_varRefp(vp), m_chgRefp(cp) {}
|
||||
~ToggleEnt() {}
|
||||
void cleanup() {
|
||||
m_varRefp->deleteTree(); m_varRefp=NULL;
|
||||
m_chgRefp->deleteTree(); m_chgRefp=NULL;
|
||||
}
|
||||
string m_comment; // Comment for coverage dump
|
||||
AstNode* m_varRefp; // How to get to this element
|
||||
AstNode* m_chgRefp; // How to get to this element
|
||||
ToggleEnt(const string& comment, AstNode* vp, AstNode* cp)
|
||||
: m_comment(comment), m_varRefp(vp), m_chgRefp(cp) {}
|
||||
~ToggleEnt() {}
|
||||
void cleanup() {
|
||||
m_varRefp->deleteTree(); m_varRefp = NULL;
|
||||
m_chgRefp->deleteTree(); m_chgRefp = NULL;
|
||||
}
|
||||
};
|
||||
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstIf::user1() -> bool. True indicates ifelse processed
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstIf::user1() -> bool. True indicates ifelse processed
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
bool m_checkBlock; // Should this block get covered?
|
||||
AstNodeModule* m_modp; // Current module to add statement to
|
||||
bool m_inToggleOff; // In function/task etc
|
||||
bool m_inModOff; // In module with no coverage
|
||||
FileMap m_fileps; // Column counts for each fileline
|
||||
string m_beginHier; // AstBegin hier name for user coverage points
|
||||
bool m_checkBlock; // Should this block get covered?
|
||||
AstNodeModule* m_modp; // Current module to add statement to
|
||||
bool m_inToggleOff; // In function/task etc
|
||||
bool m_inModOff; // In module with no coverage
|
||||
FileMap m_fileps; // Column counts for each fileline
|
||||
string m_beginHier; // AstBegin hier name for user coverage points
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
const char* varIgnoreToggle(AstVar* nodep) {
|
||||
// Return true if this shouldn't be traced
|
||||
// See also similar rule in V3TraceDecl::varIgnoreTrace
|
||||
if (!nodep->isToggleCoverable())
|
||||
return "Not relevant signal type";
|
||||
if (!v3Global.opt.coverageUnderscore()) {
|
||||
string prettyName = nodep->prettyName();
|
||||
if (prettyName[0] == '_')
|
||||
return "Leading underscore";
|
||||
if (prettyName.find("._") != string::npos)
|
||||
return "Inlined leading underscore";
|
||||
}
|
||||
if ((nodep->width()*nodep->dtypep()->arrayUnpackedElements()) > 256) return "Wide bus/array > 256 bits";
|
||||
// We allow this, though tracing doesn't
|
||||
// if (nodep->arrayp(1)) return "Unsupported: Multi-dimensional array";
|
||||
return NULL;
|
||||
// Return true if this shouldn't be traced
|
||||
// See also similar rule in V3TraceDecl::varIgnoreTrace
|
||||
if (!nodep->isToggleCoverable())
|
||||
return "Not relevant signal type";
|
||||
if (!v3Global.opt.coverageUnderscore()) {
|
||||
string prettyName = nodep->prettyName();
|
||||
if (prettyName[0] == '_')
|
||||
return "Leading underscore";
|
||||
if (prettyName.find("._") != string::npos)
|
||||
return "Inlined leading underscore";
|
||||
}
|
||||
if ((nodep->width()*nodep->dtypep()->arrayUnpackedElements()) > 256) {
|
||||
return "Wide bus/array > 256 bits";
|
||||
}
|
||||
// We allow this, though tracing doesn't
|
||||
// if (nodep->arrayp(1)) return "Unsupported: Multi-dimensional array";
|
||||
return NULL;
|
||||
}
|
||||
|
||||
AstCoverInc* newCoverInc(FileLine* fl, const string& hier,
|
||||
const string& page_prefix, const string& comment) {
|
||||
// For line coverage, we may have multiple if's on one line, so disambiguate if
|
||||
// everything is otherwise identical
|
||||
// (Don't set column otherwise as it may result in making bins not match up with
|
||||
// different types of coverage enabled.)
|
||||
string key = fl->filename()+"\001"+cvtToStr(fl->lineno())+"\001"+hier+"\001"+page_prefix+"\001"+comment;
|
||||
int column = 0;
|
||||
FileMap::iterator it = m_fileps.find(key);
|
||||
if (it == m_fileps.end()) {
|
||||
m_fileps.insert(make_pair(key,column+1));
|
||||
} else {
|
||||
column = (it->second)++;
|
||||
}
|
||||
const string& page_prefix, const string& comment) {
|
||||
// For line coverage, we may have multiple if's on one line, so disambiguate if
|
||||
// everything is otherwise identical
|
||||
// (Don't set column otherwise as it may result in making bins not match up with
|
||||
// different types of coverage enabled.)
|
||||
string key = fl->filename()+"\001"+cvtToStr(fl->lineno())
|
||||
+"\001"+hier+"\001"+page_prefix+"\001"+comment;
|
||||
int column = 0;
|
||||
FileMap::iterator it = m_fileps.find(key);
|
||||
if (it == m_fileps.end()) {
|
||||
m_fileps.insert(make_pair(key, column+1));
|
||||
} else {
|
||||
column = (it->second)++;
|
||||
}
|
||||
|
||||
// We could use the basename of the filename to the page, but seems better for code
|
||||
// from an include file to be listed under the module using it rather than the include file.
|
||||
// Note the module name could have parameters appended, we'll consider this
|
||||
// a feature as it allows for each parameterized block to be counted separately.
|
||||
// Someday the user might be allowed to specify a different page suffix
|
||||
string page = page_prefix + "/" + m_modp->prettyName();
|
||||
// We could use the basename of the filename to the page, but seems
|
||||
// better for code from an include file to be listed under the
|
||||
// module using it rather than the include file.
|
||||
// Note the module name could have parameters appended, we'll consider this
|
||||
// a feature as it allows for each parameterized block to be counted separately.
|
||||
// Someday the user might be allowed to specify a different page suffix
|
||||
string page = page_prefix + "/" + m_modp->prettyName();
|
||||
|
||||
AstCoverDecl* declp = new AstCoverDecl(fl, column, page, comment);
|
||||
declp->hier(hier);
|
||||
m_modp->addStmtp(declp);
|
||||
AstCoverDecl* declp = new AstCoverDecl(fl, column, page, comment);
|
||||
declp->hier(hier);
|
||||
m_modp->addStmtp(declp);
|
||||
|
||||
return new AstCoverInc(fl, declp);
|
||||
return new AstCoverInc(fl, declp);
|
||||
}
|
||||
|
||||
// VISITORS - BOTH
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
m_inModOff = nodep->isTop(); // Ignore coverage on top module; it's a shell we created
|
||||
m_fileps.clear();
|
||||
m_modp = nodep;
|
||||
m_inModOff = nodep->isTop(); // Ignore coverage on top module; it's a shell we created
|
||||
m_fileps.clear();
|
||||
iterateChildren(nodep);
|
||||
m_modp = NULL;
|
||||
m_inModOff = true;
|
||||
m_modp = NULL;
|
||||
m_inModOff = true;
|
||||
}
|
||||
|
||||
// VISITORS - TOGGLE COVERAGE
|
||||
virtual void visit(AstNodeFTask* nodep) {
|
||||
bool oldtog = m_inToggleOff;
|
||||
{
|
||||
m_inToggleOff = true;
|
||||
bool oldtog = m_inToggleOff;
|
||||
{
|
||||
m_inToggleOff = true;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
m_inToggleOff = oldtog;
|
||||
}
|
||||
m_inToggleOff = oldtog;
|
||||
}
|
||||
virtual void visit(AstVar* nodep) {
|
||||
iterateChildren(nodep);
|
||||
if (m_modp && !m_inModOff && !m_inToggleOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageToggle()) {
|
||||
const char* disablep = varIgnoreToggle(nodep);
|
||||
if (disablep) {
|
||||
UINFO(4, " Disable Toggle: "<<disablep<<" "<<nodep<<endl);
|
||||
} else {
|
||||
UINFO(4, " Toggle: "<<nodep<<endl);
|
||||
// There's several overall ways to approach this
|
||||
// Treat like tracing, where a end-of-timestamp action sees all changes
|
||||
// Works ok, but would be quite slow as need to reform vectors before the calls
|
||||
// Convert to "always @ (posedge signal[#]) coverinc"
|
||||
// Would mark many signals as clocks, precluding many later optimizations
|
||||
// Convert to "if (x & !lastx) CoverInc"
|
||||
// OK, but we couldn't later detect them to schedule where the IFs get called
|
||||
// Convert to "AstCoverInc(CoverInc...)"
|
||||
// We'll do this, and make the if(...) coverinc later.
|
||||
if (m_modp && !m_inModOff && !m_inToggleOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageToggle()) {
|
||||
const char* disablep = varIgnoreToggle(nodep);
|
||||
if (disablep) {
|
||||
UINFO(4, " Disable Toggle: "<<disablep<<" "<<nodep<<endl);
|
||||
} else {
|
||||
UINFO(4, " Toggle: "<<nodep<<endl);
|
||||
// There's several overall ways to approach this
|
||||
// Treat like tracing, where a end-of-timestamp action sees all changes
|
||||
// Works ok, but would be quite slow as need to reform
|
||||
// vectors before the calls
|
||||
// Convert to "always @ (posedge signal[#]) coverinc"
|
||||
// Would mark many signals as clocks, precluding many later optimizations
|
||||
// Convert to "if (x & !lastx) CoverInc"
|
||||
// OK, but we couldn't later detect them to schedule where the IFs get called
|
||||
// Convert to "AstCoverInc(CoverInc...)"
|
||||
// We'll do this, and make the if(...) coverinc later.
|
||||
|
||||
// Add signal to hold the old value
|
||||
// Add signal to hold the old value
|
||||
string newvarname = string("__Vtogcov__")+nodep->shortName();
|
||||
AstVar* chgVarp = new AstVar(nodep->fileline(), AstVarType::MODULETEMP, newvarname, nodep);
|
||||
chgVarp->fileline()->modifyWarnOff(V3ErrorCode::UNUSED, true);
|
||||
m_modp->addStmtp(chgVarp);
|
||||
AstVar* chgVarp = new AstVar(nodep->fileline(),
|
||||
AstVarType::MODULETEMP, newvarname, nodep);
|
||||
chgVarp->fileline()->modifyWarnOff(V3ErrorCode::UNUSED, true);
|
||||
m_modp->addStmtp(chgVarp);
|
||||
|
||||
// Create bucket for each dimension * bit.
|
||||
// This is necessarily an O(n^2) expansion, which is why
|
||||
// we limit coverage to signals with < 256 bits.
|
||||
// Create bucket for each dimension * bit.
|
||||
// This is necessarily an O(n^2) expansion, which is why
|
||||
// we limit coverage to signals with < 256 bits.
|
||||
|
||||
ToggleEnt newvec (string(""),
|
||||
new AstVarRef(nodep->fileline(), nodep, false),
|
||||
new AstVarRef(nodep->fileline(), chgVarp, true));
|
||||
toggleVarRecurse(nodep->dtypeSkipRefp(), 0, newvec,
|
||||
nodep, chgVarp);
|
||||
newvec.cleanup();
|
||||
}
|
||||
}
|
||||
ToggleEnt newvec (string(""),
|
||||
new AstVarRef(nodep->fileline(), nodep, false),
|
||||
new AstVarRef(nodep->fileline(), chgVarp, true));
|
||||
toggleVarRecurse(nodep->dtypeSkipRefp(), 0, newvec,
|
||||
nodep, chgVarp);
|
||||
newvec.cleanup();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void toggleVarBottom(const ToggleEnt& above, const AstVar* varp) {
|
||||
AstCoverToggle* newp
|
||||
AstCoverToggle* newp
|
||||
= new AstCoverToggle(varp->fileline(),
|
||||
newCoverInc(varp->fileline(), "", "v_toggle",
|
||||
varp->name()+above.m_comment),
|
||||
above.m_varRefp->cloneTree(true),
|
||||
above.m_chgRefp->cloneTree(true));
|
||||
m_modp->addStmtp(newp);
|
||||
m_modp->addStmtp(newp);
|
||||
}
|
||||
|
||||
void toggleVarRecurse(AstNodeDType* dtypep, int depth, // per-iteration
|
||||
const ToggleEnt& above,
|
||||
AstVar* varp, AstVar* chgVarp) { // Constant
|
||||
void toggleVarRecurse(AstNodeDType* dtypep, int depth, // per-iteration
|
||||
const ToggleEnt& above,
|
||||
AstVar* varp, AstVar* chgVarp) { // Constant
|
||||
if (const AstBasicDType* bdtypep = VN_CAST(dtypep, BasicDType)) {
|
||||
if (bdtypep->isRanged()) {
|
||||
for (int index_docs=bdtypep->lsb(); index_docs<bdtypep->msb()+1; index_docs++) {
|
||||
int index_code = index_docs - bdtypep->lsb();
|
||||
ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]",
|
||||
new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code, 1),
|
||||
new AstSel(varp->fileline(), above.m_chgRefp->cloneTree(true), index_code, 1));
|
||||
if (bdtypep->isRanged()) {
|
||||
for (int index_docs=bdtypep->lsb(); index_docs<bdtypep->msb()+1; index_docs++) {
|
||||
int index_code = index_docs - bdtypep->lsb();
|
||||
ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]",
|
||||
new AstSel(varp->fileline(),
|
||||
above.m_varRefp->cloneTree(true), index_code, 1),
|
||||
new AstSel(varp->fileline(),
|
||||
above.m_chgRefp->cloneTree(true), index_code, 1));
|
||||
toggleVarBottom(newent, varp);
|
||||
newent.cleanup();
|
||||
}
|
||||
} else {
|
||||
newent.cleanup();
|
||||
}
|
||||
} else {
|
||||
toggleVarBottom(above, varp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (AstUnpackArrayDType* adtypep = VN_CAST(dtypep, UnpackArrayDType)) {
|
||||
for (int index_docs=adtypep->lsb(); index_docs<=adtypep->msb(); ++index_docs) {
|
||||
int index_code = index_docs - adtypep->lsb();
|
||||
ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]",
|
||||
new AstArraySel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code),
|
||||
new AstArraySel(varp->fileline(), above.m_chgRefp->cloneTree(true), index_code));
|
||||
toggleVarRecurse(adtypep->subDTypep()->skipRefp(), depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
for (int index_docs=adtypep->lsb(); index_docs<=adtypep->msb(); ++index_docs) {
|
||||
int index_code = index_docs - adtypep->lsb();
|
||||
ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]",
|
||||
new AstArraySel(varp->fileline(),
|
||||
above.m_varRefp->cloneTree(true), index_code),
|
||||
new AstArraySel(varp->fileline(),
|
||||
above.m_chgRefp->cloneTree(true), index_code));
|
||||
toggleVarRecurse(adtypep->subDTypep()->skipRefp(), depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
else if (AstPackArrayDType* adtypep = VN_CAST(dtypep, PackArrayDType)) {
|
||||
for (int index_docs=adtypep->lsb(); index_docs<=adtypep->msb(); ++index_docs) {
|
||||
AstNodeDType* subtypep = adtypep->subDTypep()->skipRefp();
|
||||
int index_code = index_docs - adtypep->lsb();
|
||||
ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]",
|
||||
new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true),
|
||||
index_code*subtypep->width(), subtypep->width()),
|
||||
new AstSel(varp->fileline(), above.m_chgRefp->cloneTree(true),
|
||||
index_code*subtypep->width(), subtypep->width()));
|
||||
toggleVarRecurse(adtypep->subDTypep()->skipRefp(), depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
for (int index_docs=adtypep->lsb(); index_docs<=adtypep->msb(); ++index_docs) {
|
||||
AstNodeDType* subtypep = adtypep->subDTypep()->skipRefp();
|
||||
int index_code = index_docs - adtypep->lsb();
|
||||
ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]",
|
||||
new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true),
|
||||
index_code*subtypep->width(), subtypep->width()),
|
||||
new AstSel(varp->fileline(), above.m_chgRefp->cloneTree(true),
|
||||
index_code*subtypep->width(), subtypep->width()));
|
||||
toggleVarRecurse(adtypep->subDTypep()->skipRefp(), depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
else if (AstStructDType* adtypep = VN_CAST(dtypep, StructDType)) {
|
||||
// For now it's packed, so similar to array
|
||||
for (AstMemberDType* itemp = adtypep->membersp(); itemp; itemp=VN_CAST(itemp->nextp(), MemberDType)) {
|
||||
AstNodeDType* subtypep = itemp->subDTypep()->skipRefp();
|
||||
int index_code = itemp->lsb();
|
||||
ToggleEnt newent (above.m_comment+string(".")+itemp->name(),
|
||||
new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true),
|
||||
index_code, subtypep->width()),
|
||||
new AstSel(varp->fileline(), above.m_chgRefp->cloneTree(true),
|
||||
index_code, subtypep->width()));
|
||||
toggleVarRecurse(subtypep, depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
// For now it's packed, so similar to array
|
||||
for (AstMemberDType* itemp = adtypep->membersp();
|
||||
itemp; itemp=VN_CAST(itemp->nextp(), MemberDType)) {
|
||||
AstNodeDType* subtypep = itemp->subDTypep()->skipRefp();
|
||||
int index_code = itemp->lsb();
|
||||
ToggleEnt newent (above.m_comment+string(".")+itemp->name(),
|
||||
new AstSel(varp->fileline(), above.m_varRefp->cloneTree(true),
|
||||
index_code, subtypep->width()),
|
||||
new AstSel(varp->fileline(), above.m_chgRefp->cloneTree(true),
|
||||
index_code, subtypep->width()));
|
||||
toggleVarRecurse(subtypep, depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
else if (AstUnionDType* adtypep = VN_CAST(dtypep, UnionDType)) {
|
||||
// Arbitrarially handle only the first member of the union
|
||||
if (AstMemberDType* itemp = adtypep->membersp()) {
|
||||
AstNodeDType* subtypep = itemp->subDTypep()->skipRefp();
|
||||
ToggleEnt newent (above.m_comment+string(".")+itemp->name(),
|
||||
above.m_varRefp->cloneTree(true),
|
||||
above.m_chgRefp->cloneTree(true));
|
||||
toggleVarRecurse(subtypep, depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
else {
|
||||
dtypep->v3fatalSrc("Unexpected node data type in toggle coverage generation: "<<dtypep->prettyTypeName());
|
||||
}
|
||||
// Arbitrarially handle only the first member of the union
|
||||
if (AstMemberDType* itemp = adtypep->membersp()) {
|
||||
AstNodeDType* subtypep = itemp->subDTypep()->skipRefp();
|
||||
ToggleEnt newent (above.m_comment+string(".")+itemp->name(),
|
||||
above.m_varRefp->cloneTree(true),
|
||||
above.m_chgRefp->cloneTree(true));
|
||||
toggleVarRecurse(subtypep, depth+1,
|
||||
newent,
|
||||
varp, chgVarp);
|
||||
newent.cleanup();
|
||||
}
|
||||
}
|
||||
else {
|
||||
dtypep->v3fatalSrc("Unexpected node data type in toggle coverage generation: "
|
||||
<<dtypep->prettyTypeName());
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS - LINE COVERAGE
|
||||
virtual void visit(AstIf* nodep) { // Note not AstNodeIf; other types don't get covered
|
||||
UINFO(4," IF: "<<nodep<<endl);
|
||||
if (m_checkBlock) {
|
||||
// An else-if. When we iterate the if, use "elsif" marking
|
||||
virtual void visit(AstIf* nodep) { // Note not AstNodeIf; other types don't get covered
|
||||
UINFO(4," IF: "<<nodep<<endl);
|
||||
if (m_checkBlock) {
|
||||
// An else-if. When we iterate the if, use "elsif" marking
|
||||
bool elsif = (VN_IS(nodep->elsesp(), If)
|
||||
&& !VN_CAST(nodep->elsesp(), If)->nextp());
|
||||
if (elsif) VN_CAST(nodep->elsesp(), If)->user1(true);
|
||||
//
|
||||
//
|
||||
iterateAndNextNull(nodep->ifsp());
|
||||
if (m_checkBlock && !m_inModOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) { // if a "if" branch didn't disable it
|
||||
UINFO(4," COVER: "<<nodep<<endl);
|
||||
if (nodep->user1()) {
|
||||
nodep->addIfsp(newCoverInc(nodep->fileline(), "", "v_line", "elsif"));
|
||||
} else {
|
||||
nodep->addIfsp(newCoverInc(nodep->fileline(), "", "v_line", "if"));
|
||||
}
|
||||
}
|
||||
// Don't do empty else's, only empty if/case's
|
||||
if (nodep->elsesp()) {
|
||||
m_checkBlock = true;
|
||||
if (m_checkBlock && !m_inModOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) { // if a "if" branch didn't disable it
|
||||
UINFO(4," COVER: "<<nodep<<endl);
|
||||
if (nodep->user1()) {
|
||||
nodep->addIfsp(newCoverInc(nodep->fileline(), "", "v_line", "elsif"));
|
||||
} else {
|
||||
nodep->addIfsp(newCoverInc(nodep->fileline(), "", "v_line", "if"));
|
||||
}
|
||||
}
|
||||
// Don't do empty else's, only empty if/case's
|
||||
if (nodep->elsesp()) {
|
||||
m_checkBlock = true;
|
||||
iterateAndNextNull(nodep->elsesp());
|
||||
if (m_checkBlock && !m_inModOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) { // if a "else" branch didn't disable it
|
||||
UINFO(4," COVER: "<<nodep<<endl);
|
||||
if (!elsif) { // elsif done inside if()
|
||||
nodep->addElsesp(newCoverInc(nodep->elsesp()->fileline(), "", "v_line", "else"));
|
||||
}
|
||||
}
|
||||
}
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
}
|
||||
if (m_checkBlock && !m_inModOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) { // if a "else" branch didn't disable it
|
||||
UINFO(4," COVER: "<<nodep<<endl);
|
||||
if (!elsif) { // elsif done inside if()
|
||||
nodep->addElsesp(newCoverInc(nodep->elsesp()->fileline(),
|
||||
"", "v_line", "else"));
|
||||
}
|
||||
}
|
||||
}
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
}
|
||||
}
|
||||
virtual void visit(AstCaseItem* nodep) {
|
||||
UINFO(4," CASEI: "<<nodep<<endl);
|
||||
if (m_checkBlock && !m_inModOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) {
|
||||
UINFO(4," CASEI: "<<nodep<<endl);
|
||||
if (m_checkBlock && !m_inModOff
|
||||
&& nodep->fileline()->coverageOn() && v3Global.opt.coverageLine()) {
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
if (m_checkBlock) { // if the case body didn't disable it
|
||||
UINFO(4," COVER: "<<nodep<<endl);
|
||||
nodep->addBodysp(newCoverInc(nodep->fileline(), "", "v_line", "case"));
|
||||
}
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
}
|
||||
if (m_checkBlock) { // if the case body didn't disable it
|
||||
UINFO(4," COVER: "<<nodep<<endl);
|
||||
nodep->addBodysp(newCoverInc(nodep->fileline(), "", "v_line", "case"));
|
||||
}
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
}
|
||||
}
|
||||
virtual void visit(AstPslCover* nodep) {
|
||||
UINFO(4," PSLCOVER: "<<nodep<<endl);
|
||||
m_checkBlock = true; // Always do cover blocks, even if there's a $stop
|
||||
UINFO(4," PSLCOVER: "<<nodep<<endl);
|
||||
m_checkBlock = true; // Always do cover blocks, even if there's a $stop
|
||||
iterateChildren(nodep);
|
||||
if (!nodep->coverincp()) {
|
||||
// Note the name may be overridden by V3Assert processing
|
||||
nodep->coverincp(newCoverInc(nodep->fileline(), m_beginHier, "v_user", "cover"));
|
||||
}
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
if (!nodep->coverincp()) {
|
||||
// Note the name may be overridden by V3Assert processing
|
||||
nodep->coverincp(newCoverInc(nodep->fileline(), m_beginHier, "v_user", "cover"));
|
||||
}
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
}
|
||||
virtual void visit(AstStop* nodep) {
|
||||
UINFO(4," STOP: "<<nodep<<endl);
|
||||
m_checkBlock = false;
|
||||
UINFO(4," STOP: "<<nodep<<endl);
|
||||
m_checkBlock = false;
|
||||
}
|
||||
virtual void visit(AstPragma* nodep) {
|
||||
if (nodep->pragType() == AstPragmaType::COVERAGE_BLOCK_OFF) {
|
||||
// Skip all NEXT nodes under this block, and skip this if/case branch
|
||||
UINFO(4," OFF: "<<nodep<<endl);
|
||||
m_checkBlock = false;
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
} else {
|
||||
if (nodep->pragType() == AstPragmaType::COVERAGE_BLOCK_OFF) {
|
||||
// Skip all NEXT nodes under this block, and skip this if/case branch
|
||||
UINFO(4," OFF: "<<nodep<<endl);
|
||||
m_checkBlock = false;
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
} else {
|
||||
if (m_checkBlock) iterateChildren(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstBegin* nodep) {
|
||||
// Record the hierarchy of any named begins, so we can apply to user
|
||||
// coverage points. This is because there may be cov points inside
|
||||
// generate blocks; each point should get separate consideration.
|
||||
// (Currently ignored for line coverage, since any generate iteration
|
||||
// covers the code in that line.)
|
||||
string oldHier = m_beginHier;
|
||||
bool oldtog = m_inToggleOff;
|
||||
{
|
||||
m_inToggleOff = true;
|
||||
if (nodep->name()!="") {
|
||||
m_beginHier = m_beginHier + (m_beginHier!=""?".":"") + nodep->name();
|
||||
}
|
||||
// Record the hierarchy of any named begins, so we can apply to user
|
||||
// coverage points. This is because there may be cov points inside
|
||||
// generate blocks; each point should get separate consideration.
|
||||
// (Currently ignored for line coverage, since any generate iteration
|
||||
// covers the code in that line.)
|
||||
string oldHier = m_beginHier;
|
||||
bool oldtog = m_inToggleOff;
|
||||
{
|
||||
m_inToggleOff = true;
|
||||
if (nodep->name()!="") {
|
||||
m_beginHier = m_beginHier + (m_beginHier!=""?".":"") + nodep->name();
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
m_beginHier = oldHier;
|
||||
m_inToggleOff = oldtog;
|
||||
}
|
||||
m_beginHier = oldHier;
|
||||
m_inToggleOff = oldtog;
|
||||
}
|
||||
|
||||
// VISITORS - BOTH
|
||||
virtual void visit(AstNode* nodep) {
|
||||
// Default: Just iterate
|
||||
if (m_checkBlock) {
|
||||
// Default: Just iterate
|
||||
if (m_checkBlock) {
|
||||
iterateChildren(nodep);
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
}
|
||||
m_checkBlock = true; // Reset as a child may have cleared it
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
explicit CoverageVisitor(AstNetlist* rootp) {
|
||||
// Operate on all modules
|
||||
m_checkBlock = true;
|
||||
// Operate on all modules
|
||||
m_checkBlock = true;
|
||||
m_modp = NULL;
|
||||
m_beginHier = "";
|
||||
m_inToggleOff = false;
|
||||
m_inModOff = true;
|
||||
m_beginHier = "";
|
||||
m_inToggleOff = false;
|
||||
m_inModOff = true;
|
||||
iterateChildren(rootp);
|
||||
}
|
||||
virtual ~CoverageVisitor() {}
|
||||
|
|
|
|||
|
|
@ -35,4 +35,4 @@ public:
|
|||
static void coverage(AstNetlist* rootp);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// COVERAGEJOIN TRANSFORMATIONS:
|
||||
// If two COVERTOGGLEs have same VARSCOPE, combine them
|
||||
// If two COVERTOGGLEs have same VARSCOPE, combine them
|
||||
//*************************************************************************
|
||||
|
||||
|
||||
|
|
@ -40,72 +40,76 @@ class CoverageJoinVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// V3Hashed
|
||||
// AstCoverToggle->VarRef::user4() // V3Hashed calculation
|
||||
// AstCoverToggle->VarRef::user4() // V3Hashed calculation
|
||||
|
||||
//AstUser4InUse In V3Hashed
|
||||
//AstUser4InUse In V3Hashed
|
||||
|
||||
// TYPES
|
||||
typedef std::vector<AstCoverToggle*> ToggleList;
|
||||
|
||||
// STATE
|
||||
ToggleList m_toggleps; // List of of all AstCoverToggle's
|
||||
ToggleList m_toggleps; // List of of all AstCoverToggle's
|
||||
|
||||
V3Double0 m_statToggleJoins; // Statistic tracking
|
||||
V3Double0 m_statToggleJoins; // Statistic tracking
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void detectDuplicates() {
|
||||
UINFO(9,"Finding duplicates\n");
|
||||
// Note uses user4
|
||||
V3Hashed hashed; // Duplicate code detection
|
||||
// Hash all of the original signals we toggle cover
|
||||
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
|
||||
AstCoverToggle* nodep = *it;
|
||||
hashed.hashAndInsert(nodep->origp());
|
||||
}
|
||||
// Find if there are any duplicates
|
||||
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
|
||||
AstCoverToggle* nodep = *it;
|
||||
if (nodep->backp()) { // nodep->backp() is null if we already detected it's a duplicate and unlinked it
|
||||
// Want to choose a base node, and keep finding duplicates that are identical
|
||||
// This prevents making chains where a->b, then c->d, then b->c, as we'll find a->b, a->c, a->d directly.
|
||||
while (1) {
|
||||
V3Hashed::iterator dupit = hashed.findDuplicate(nodep->origp());
|
||||
if (dupit == hashed.end()) break;
|
||||
//
|
||||
AstNode* duporigp = hashed.iteratorNodep(dupit);
|
||||
// Note hashed will point to the original variable (what's duplicated), not the covertoggle,
|
||||
// but we need to get back to the covertoggle which is immediately above, so:
|
||||
UINFO(9,"Finding duplicates\n");
|
||||
// Note uses user4
|
||||
V3Hashed hashed; // Duplicate code detection
|
||||
// Hash all of the original signals we toggle cover
|
||||
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
|
||||
AstCoverToggle* nodep = *it;
|
||||
hashed.hashAndInsert(nodep->origp());
|
||||
}
|
||||
// Find if there are any duplicates
|
||||
for (ToggleList::iterator it = m_toggleps.begin(); it != m_toggleps.end(); ++it) {
|
||||
AstCoverToggle* nodep = *it;
|
||||
// nodep->backp() is null if we already detected it's a duplicate and unlinked it.
|
||||
if (nodep->backp()) {
|
||||
// Want to choose a base node, and keep finding duplicates that are identical.
|
||||
// This prevents making chains where a->b, then c->d, then b->c, as we'll
|
||||
// find a->b, a->c, a->d directly.
|
||||
while (1) {
|
||||
V3Hashed::iterator dupit = hashed.findDuplicate(nodep->origp());
|
||||
if (dupit == hashed.end()) break;
|
||||
//
|
||||
AstNode* duporigp = hashed.iteratorNodep(dupit);
|
||||
// Note hashed will point to the original variable (what's
|
||||
// duplicated), not the covertoggle, but we need to get back to the
|
||||
// covertoggle which is immediately above, so:
|
||||
AstCoverToggle* removep = VN_CAST(duporigp->backp(), CoverToggle);
|
||||
if (!removep) nodep->v3fatalSrc("CoverageJoin duplicate of wrong type");
|
||||
UINFO(8," Orig "<<nodep<<" -->> "<<nodep->incp()->declp()<<endl);
|
||||
UINFO(8," dup "<<removep<<" -->> "<<removep->incp()->declp()<<endl);
|
||||
// The CoverDecl the duplicate pointed to now needs to point to the original's data
|
||||
// IE the duplicate will get the coverage number from the non-duplicate
|
||||
AstCoverDecl* datadeclp = nodep->incp()->declp()->dataDeclThisp();
|
||||
if (!removep) nodep->v3fatalSrc("CoverageJoin duplicate of wrong type");
|
||||
UINFO(8," Orig "<<nodep<<" -->> "<<nodep->incp()->declp()<<endl);
|
||||
UINFO(8," dup "<<removep<<" -->> "<<removep->incp()->declp()<<endl);
|
||||
// The CoverDecl the duplicate pointed to now needs to point to the
|
||||
// original's data. I.e. the duplicate will get the coverage number
|
||||
// from the non-duplicate
|
||||
AstCoverDecl* datadeclp = nodep->incp()->declp()->dataDeclThisp();
|
||||
removep->incp()->declp()->dataDeclp(datadeclp);
|
||||
UINFO(8," new "<<removep->incp()->declp()<<endl);
|
||||
// Mark the found node as a duplicate of the first node
|
||||
// (Not vice-versa as we have the iterator for the found node)
|
||||
removep->unlinkFrBack(); pushDeletep(removep); VL_DANGLING(removep);
|
||||
// Remove node from comparison so don't hit it again
|
||||
hashed.erase(dupit);
|
||||
++m_statToggleJoins;
|
||||
}
|
||||
}
|
||||
}
|
||||
UINFO(8," new "<<removep->incp()->declp()<<endl);
|
||||
// Mark the found node as a duplicate of the first node
|
||||
// (Not vice-versa as we have the iterator for the found node)
|
||||
removep->unlinkFrBack(); pushDeletep(removep); VL_DANGLING(removep);
|
||||
// Remove node from comparison so don't hit it again
|
||||
hashed.erase(dupit);
|
||||
++m_statToggleJoins;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNetlist* nodep) {
|
||||
// Find all Coverage's
|
||||
// Find all Coverage's
|
||||
iterateChildren(nodep);
|
||||
// Simplify
|
||||
detectDuplicates();
|
||||
// Simplify
|
||||
detectDuplicates();
|
||||
}
|
||||
virtual void visit(AstCoverToggle* nodep) {
|
||||
m_toggleps.push_back(nodep);
|
||||
m_toggleps.push_back(nodep);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
//--------------------
|
||||
|
|
@ -120,7 +124,7 @@ public:
|
|||
iterate(nodep);
|
||||
}
|
||||
virtual ~CoverageJoinVisitor() {
|
||||
V3Stats::addStat("Coverage, Toggle points joined", m_statToggleJoins);
|
||||
V3Stats::addStat("Coverage, Toggle points joined", m_statToggleJoins);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -35,4 +35,4 @@ public:
|
|||
static void coverageJoin(AstNetlist* rootp);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
462
src/V3Dead.cpp
462
src/V3Dead.cpp
|
|
@ -18,8 +18,8 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// DEAD TRANSFORMATIONS:
|
||||
// Remove any unreferenced modules
|
||||
// Remove any unreferenced variables
|
||||
// Remove any unreferenced modules
|
||||
// Remove any unreferenced variables
|
||||
//
|
||||
// TODO: A graph would make the process of circular and interlinked
|
||||
// dependencies easier to resolve.
|
||||
|
|
@ -59,7 +59,7 @@ private:
|
|||
// VISITORS
|
||||
virtual void visit(AstCell* nodep) {
|
||||
iterateChildren(nodep);
|
||||
nodep->modp()->user1Inc(-1);
|
||||
nodep->modp()->user1Inc(-1);
|
||||
}
|
||||
//-----
|
||||
virtual void visit(AstNodeMath* nodep) {} // Accelerate
|
||||
|
|
@ -81,337 +81,341 @@ class DeadVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire Netlist:
|
||||
// AstNodeModule::user1() -> int. Count of number of cells referencing this module.
|
||||
// AstVar::user1() -> int. Count of number of references
|
||||
// AstVarScope::user1() -> int. Count of number of references
|
||||
// AstNodeDType::user1() -> int. Count of number of references
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstNodeModule::user1() -> int. Count of number of cells referencing this module.
|
||||
// AstVar::user1() -> int. Count of number of references
|
||||
// AstVarScope::user1() -> int. Count of number of references
|
||||
// AstNodeDType::user1() -> int. Count of number of references
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// TYPES
|
||||
typedef std::multimap<AstVarScope*,AstNodeAssign*> AssignMap;
|
||||
typedef std::multimap<AstVarScope*,AstNodeAssign*> AssignMap;
|
||||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstNodeModule* m_modp; // Current module
|
||||
std::vector<AstVar*> m_varsp; // List of all encountered to avoid another loop through tree
|
||||
std::vector<AstNode*> m_dtypesp; // List of all encountered to avoid another loop through tree
|
||||
std::vector<AstVarScope*> m_vscsp; // List of all encountered to avoid another loop through tree
|
||||
std::vector<AstScope*> m_scopesp; // List of all encountered to avoid another loop through tree
|
||||
std::vector<AstCell*> m_cellsp; // List of all encountered to avoid another loop through tree
|
||||
AssignMap m_assignMap; // List of all simple assignments for each variable
|
||||
bool m_elimUserVars; // Allow removal of user's vars
|
||||
bool m_elimDTypes; // Allow removal of DTypes
|
||||
bool m_elimScopes; // Allow removal of Scopes
|
||||
bool m_elimCells; // Allow removal of Cells
|
||||
bool m_sideEffect; // Side effects discovered in assign RHS
|
||||
AssignMap m_assignMap; // List of all simple assignments for each variable
|
||||
bool m_elimUserVars; // Allow removal of user's vars
|
||||
bool m_elimDTypes; // Allow removal of DTypes
|
||||
bool m_elimScopes; // Allow removal of Scopes
|
||||
bool m_elimCells; // Allow removal of Cells
|
||||
bool m_sideEffect; // Side effects discovered in assign RHS
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void checkAll(AstNode* nodep) {
|
||||
if (nodep != nodep->dtypep()) { // NodeDTypes reference themselves
|
||||
if (AstNode* subnodep = nodep->dtypep()) {
|
||||
subnodep->user1Inc();
|
||||
}
|
||||
}
|
||||
if (AstNode* subnodep = nodep->getChildDTypep()) {
|
||||
subnodep->user1Inc();
|
||||
}
|
||||
if (nodep != nodep->dtypep()) { // NodeDTypes reference themselves
|
||||
if (AstNode* subnodep = nodep->dtypep()) {
|
||||
subnodep->user1Inc();
|
||||
}
|
||||
}
|
||||
if (AstNode* subnodep = nodep->getChildDTypep()) {
|
||||
subnodep->user1Inc();
|
||||
}
|
||||
}
|
||||
void checkDType(AstNodeDType* nodep) {
|
||||
if (!nodep->generic() // Don't remove generic types
|
||||
&& m_elimDTypes // dtypes stick around until post-widthing
|
||||
if (!nodep->generic() // Don't remove generic types
|
||||
&& m_elimDTypes // dtypes stick around until post-widthing
|
||||
&& !VN_IS(nodep, MemberDType) // Keep member names iff upper type exists
|
||||
) {
|
||||
m_dtypesp.push_back(nodep);
|
||||
}
|
||||
if (AstNode* subnodep = nodep->virtRefDTypep()) {
|
||||
subnodep->user1Inc();
|
||||
}
|
||||
) {
|
||||
m_dtypesp.push_back(nodep);
|
||||
}
|
||||
if (AstNode* subnodep = nodep->virtRefDTypep()) {
|
||||
subnodep->user1Inc();
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
if (!nodep->dead()) {
|
||||
m_modp = nodep;
|
||||
if (!nodep->dead()) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
}
|
||||
m_modp = NULL;
|
||||
checkAll(nodep);
|
||||
}
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->scopep()) nodep->scopep()->user1Inc();
|
||||
checkAll(nodep);
|
||||
if (nodep->scopep()) nodep->scopep()->user1Inc();
|
||||
}
|
||||
virtual void visit(AstScope* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->aboveScopep()) nodep->aboveScopep()->user1Inc();
|
||||
checkAll(nodep);
|
||||
if (nodep->aboveScopep()) nodep->aboveScopep()->user1Inc();
|
||||
|
||||
if (!nodep->isTop() && !nodep->varsp() && !nodep->blocksp() && !nodep->finalClksp()) {
|
||||
m_scopesp.push_back(nodep);
|
||||
}
|
||||
if (!nodep->isTop() && !nodep->varsp() && !nodep->blocksp() && !nodep->finalClksp()) {
|
||||
m_scopesp.push_back(nodep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstCell* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
m_cellsp.push_back(nodep);
|
||||
nodep->modp()->user1Inc();
|
||||
checkAll(nodep);
|
||||
m_cellsp.push_back(nodep);
|
||||
nodep->modp()->user1Inc();
|
||||
}
|
||||
|
||||
virtual void visit(AstNodeVarRef* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->varScopep()) {
|
||||
nodep->varScopep()->user1Inc();
|
||||
nodep->varScopep()->varp()->user1Inc();
|
||||
}
|
||||
if (nodep->varp()) {
|
||||
nodep->varp()->user1Inc();
|
||||
}
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
checkAll(nodep);
|
||||
if (nodep->varScopep()) {
|
||||
nodep->varScopep()->user1Inc();
|
||||
nodep->varScopep()->varp()->user1Inc();
|
||||
}
|
||||
if (nodep->varp()) {
|
||||
nodep->varp()->user1Inc();
|
||||
}
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeFTaskRef* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
checkAll(nodep);
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
}
|
||||
virtual void visit(AstRefDType* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkDType(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
checkDType(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeDType* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkDType(nodep);
|
||||
checkAll(nodep);
|
||||
checkDType(nodep);
|
||||
checkAll(nodep);
|
||||
}
|
||||
virtual void visit(AstEnumItemRef* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
checkAll(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->packagep()) {
|
||||
if (m_elimCells) nodep->packagep(NULL);
|
||||
else nodep->packagep()->user1Inc();
|
||||
}
|
||||
checkAll(nodep);
|
||||
}
|
||||
virtual void visit(AstModport* nodep) {
|
||||
iterateChildren(nodep);
|
||||
if (m_elimCells) {
|
||||
if (!nodep->varsp()) {
|
||||
pushDeletep(nodep->unlinkFrBack()); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
}
|
||||
checkAll(nodep);
|
||||
if (m_elimCells) {
|
||||
if (!nodep->varsp()) {
|
||||
pushDeletep(nodep->unlinkFrBack()); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
}
|
||||
checkAll(nodep);
|
||||
}
|
||||
virtual void visit(AstTypedef* nodep) {
|
||||
iterateChildren(nodep);
|
||||
if (m_elimCells && !nodep->attrPublic()) {
|
||||
pushDeletep(nodep->unlinkFrBack()); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
checkAll(nodep);
|
||||
// Don't let packages with only public variables disappear
|
||||
// Normal modules may disappear, e.g. if they are parameterized then removed
|
||||
if (m_elimCells && !nodep->attrPublic()) {
|
||||
pushDeletep(nodep->unlinkFrBack()); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
checkAll(nodep);
|
||||
// Don't let packages with only public variables disappear
|
||||
// Normal modules may disappear, e.g. if they are parameterized then removed
|
||||
if (nodep->attrPublic() && m_modp && VN_IS(m_modp, Package)) m_modp->user1Inc();
|
||||
}
|
||||
virtual void visit(AstVarScope* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->scopep()) nodep->scopep()->user1Inc();
|
||||
if (mightElimVar(nodep->varp())) {
|
||||
m_vscsp.push_back(nodep);
|
||||
}
|
||||
checkAll(nodep);
|
||||
if (nodep->scopep()) nodep->scopep()->user1Inc();
|
||||
if (mightElimVar(nodep->varp())) {
|
||||
m_vscsp.push_back(nodep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstVar* nodep) {
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
checkAll(nodep);
|
||||
if (nodep->isSigPublic() && m_modp && VN_IS(m_modp, Package)) m_modp->user1Inc();
|
||||
if (mightElimVar(nodep)) {
|
||||
m_varsp.push_back(nodep);
|
||||
}
|
||||
if (mightElimVar(nodep)) {
|
||||
m_varsp.push_back(nodep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeAssign* nodep) {
|
||||
// See if simple assignments to variables may be eliminated because that variable is never used.
|
||||
// Similar code in V3Life
|
||||
m_sideEffect = false;
|
||||
// See if simple assignments to variables may be eliminated because
|
||||
// that variable is never used.
|
||||
// Similar code in V3Life
|
||||
m_sideEffect = false;
|
||||
iterateAndNextNull(nodep->rhsp());
|
||||
checkAll(nodep);
|
||||
// Has to be direct assignment without any EXTRACTing.
|
||||
checkAll(nodep);
|
||||
// Has to be direct assignment without any EXTRACTing.
|
||||
AstVarRef* varrefp = VN_CAST(nodep->lhsp(), VarRef);
|
||||
if (varrefp && !m_sideEffect
|
||||
&& varrefp->varScopep()) { // For simplicity, we only remove post-scoping
|
||||
m_assignMap.insert(make_pair(varrefp->varScopep(), nodep));
|
||||
checkAll(varrefp); // Must track reference to dtype()
|
||||
} else { // Track like any other statement
|
||||
if (varrefp && !m_sideEffect
|
||||
&& varrefp->varScopep()) { // For simplicity, we only remove post-scoping
|
||||
m_assignMap.insert(make_pair(varrefp->varScopep(), nodep));
|
||||
checkAll(varrefp); // Must track reference to dtype()
|
||||
} else { // Track like any other statement
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
}
|
||||
checkAll(nodep);
|
||||
}
|
||||
checkAll(nodep);
|
||||
}
|
||||
|
||||
//-----
|
||||
virtual void visit(AstNode* nodep) {
|
||||
if (nodep->isOutputter()) m_sideEffect=true;
|
||||
if (nodep->isOutputter()) m_sideEffect = true;
|
||||
iterateChildren(nodep);
|
||||
checkAll(nodep);
|
||||
checkAll(nodep);
|
||||
}
|
||||
|
||||
// METHODS
|
||||
void deadCheckMod() {
|
||||
// Kill any unused modules
|
||||
// V3LinkCells has a graph that is capable of this too, but we need to do it
|
||||
// after we've done all the generate blocks
|
||||
for (bool retry=true; retry; ) {
|
||||
retry=false;
|
||||
AstNodeModule* nextmodp;
|
||||
for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; modp=nextmodp) {
|
||||
// Kill any unused modules
|
||||
// V3LinkCells has a graph that is capable of this too, but we need to do it
|
||||
// after we've done all the generate blocks
|
||||
for (bool retry=true; retry; ) {
|
||||
retry = false;
|
||||
AstNodeModule* nextmodp;
|
||||
for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; modp=nextmodp) {
|
||||
nextmodp = VN_CAST(modp->nextp(), NodeModule);
|
||||
if (modp->dead() || (modp->level()>2 && modp->user1()==0 && !modp->internal())) {
|
||||
// > 2 because L1 is the wrapper, L2 is the top user module
|
||||
UINFO(4," Dead module "<<modp<<endl);
|
||||
// And its children may now be killable too; correct counts
|
||||
// Recurse, as cells may not be directly under the module but in a generate
|
||||
if (!modp->dead()) { // If was dead didn't increment user1's
|
||||
DeadModVisitor visitor(modp);
|
||||
}
|
||||
modp->unlinkFrBack()->deleteTree(); VL_DANGLING(modp);
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (modp->dead() || (modp->level()>2 && modp->user1()==0 && !modp->internal())) {
|
||||
// > 2 because L1 is the wrapper, L2 is the top user module
|
||||
UINFO(4," Dead module "<<modp<<endl);
|
||||
// And its children may now be killable too; correct counts
|
||||
// Recurse, as cells may not be directly under the module but in a generate
|
||||
if (!modp->dead()) { // If was dead didn't increment user1's
|
||||
DeadModVisitor visitor(modp);
|
||||
}
|
||||
modp->unlinkFrBack()->deleteTree(); VL_DANGLING(modp);
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
bool mightElimVar(AstVar* nodep) {
|
||||
return (!nodep->isSigPublic() // Can't elim publics!
|
||||
&& !nodep->isIO()
|
||||
&& (nodep->isTemp()
|
||||
|| (nodep->isParam() && !nodep->isTrace())
|
||||
|| m_elimUserVars)); // Post-Trace can kill most anything
|
||||
return (!nodep->isSigPublic() // Can't elim publics!
|
||||
&& !nodep->isIO()
|
||||
&& (nodep->isTemp()
|
||||
|| (nodep->isParam() && !nodep->isTrace())
|
||||
|| m_elimUserVars)); // Post-Trace can kill most anything
|
||||
}
|
||||
|
||||
void deadCheckScope() {
|
||||
for (bool retry=true; retry; ) {
|
||||
retry = false;
|
||||
for (std::vector<AstScope*>::iterator it = m_scopesp.begin(); it != m_scopesp.end();++it) {
|
||||
AstScope* scp = *it;
|
||||
if (!scp)
|
||||
continue;
|
||||
if (scp->user1() == 0) {
|
||||
for (bool retry=true; retry; ) {
|
||||
retry = false;
|
||||
for (std::vector<AstScope*>::iterator it = m_scopesp.begin();
|
||||
it != m_scopesp.end();++it) {
|
||||
AstScope* scp = *it;
|
||||
if (!scp)
|
||||
continue;
|
||||
if (scp->user1() == 0) {
|
||||
UINFO(4, " Dead AstScope " << scp << endl);
|
||||
scp->aboveScopep()->user1Inc(-1);
|
||||
if (scp->dtypep()) {
|
||||
scp->dtypep()->user1Inc(-1);
|
||||
}
|
||||
scp->unlinkFrBack()->deleteTree(); VL_DANGLING(scp);
|
||||
*it = NULL;
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
scp->aboveScopep()->user1Inc(-1);
|
||||
if (scp->dtypep()) {
|
||||
scp->dtypep()->user1Inc(-1);
|
||||
}
|
||||
scp->unlinkFrBack()->deleteTree(); VL_DANGLING(scp);
|
||||
*it = NULL;
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deadCheckCells() {
|
||||
for (std::vector<AstCell*>::iterator it = m_cellsp.begin(); it!=m_cellsp.end(); ++it) {
|
||||
AstCell* cellp = *it;
|
||||
if (cellp->user1() == 0 && !cellp->modp()->stmtsp()) {
|
||||
cellp->modp()->user1Inc(-1);
|
||||
cellp->unlinkFrBack()->deleteTree(); VL_DANGLING(cellp);
|
||||
}
|
||||
}
|
||||
AstCell* cellp = *it;
|
||||
if (cellp->user1() == 0 && !cellp->modp()->stmtsp()) {
|
||||
cellp->modp()->user1Inc(-1);
|
||||
cellp->unlinkFrBack()->deleteTree(); VL_DANGLING(cellp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void deadCheckVar() {
|
||||
// Delete any unused varscopes
|
||||
// Delete any unused varscopes
|
||||
for (std::vector<AstVarScope*>::iterator it = m_vscsp.begin(); it!=m_vscsp.end(); ++it) {
|
||||
AstVarScope* vscp = *it;
|
||||
if (vscp->user1() == 0) {
|
||||
UINFO(4," Dead "<<vscp<<endl);
|
||||
std::pair<AssignMap::iterator,AssignMap::iterator> eqrange = m_assignMap.equal_range(vscp);
|
||||
for (AssignMap::iterator itr = eqrange.first; itr != eqrange.second; ++itr) {
|
||||
AstNodeAssign* assp = itr->second;
|
||||
AstVarScope* vscp = *it;
|
||||
if (vscp->user1() == 0) {
|
||||
UINFO(4," Dead "<<vscp<<endl);
|
||||
std::pair<AssignMap::iterator,AssignMap::iterator> eqrange
|
||||
= m_assignMap.equal_range(vscp);
|
||||
for (AssignMap::iterator itr = eqrange.first; itr != eqrange.second; ++itr) {
|
||||
AstNodeAssign* assp = itr->second;
|
||||
UINFO(4," Dead assign "<<assp<<endl);
|
||||
assp->dtypep()->user1Inc(-1);
|
||||
assp->unlinkFrBack()->deleteTree(); VL_DANGLING(assp);
|
||||
}
|
||||
if (vscp->scopep()) vscp->scopep()->user1Inc(-1);
|
||||
vscp->dtypep()->user1Inc(-1);
|
||||
vscp->unlinkFrBack()->deleteTree(); VL_DANGLING(vscp);
|
||||
}
|
||||
}
|
||||
for (bool retry=true; retry; ) {
|
||||
retry = false;
|
||||
assp->dtypep()->user1Inc(-1);
|
||||
assp->unlinkFrBack()->deleteTree(); VL_DANGLING(assp);
|
||||
}
|
||||
if (vscp->scopep()) vscp->scopep()->user1Inc(-1);
|
||||
vscp->dtypep()->user1Inc(-1);
|
||||
vscp->unlinkFrBack()->deleteTree(); VL_DANGLING(vscp);
|
||||
}
|
||||
}
|
||||
for (bool retry=true; retry; ) {
|
||||
retry = false;
|
||||
for (std::vector<AstVar *>::iterator it = m_varsp.begin(); it != m_varsp.end();++it) {
|
||||
AstVar* varp = *it;
|
||||
if (!varp)
|
||||
continue;
|
||||
if (varp->user1() == 0) {
|
||||
AstVar* varp = *it;
|
||||
if (!varp)
|
||||
continue;
|
||||
if (varp->user1() == 0) {
|
||||
UINFO(4, " Dead " << varp << endl);
|
||||
if (varp->dtypep()) {
|
||||
varp->dtypep()->user1Inc(-1);
|
||||
}
|
||||
varp->unlinkFrBack()->deleteTree(); VL_DANGLING(varp);
|
||||
*it = NULL;
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (varp->dtypep()) {
|
||||
varp->dtypep()->user1Inc(-1);
|
||||
}
|
||||
varp->unlinkFrBack()->deleteTree(); VL_DANGLING(varp);
|
||||
*it = NULL;
|
||||
retry = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (std::vector<AstNode*>::iterator it = m_dtypesp.begin(); it != m_dtypesp.end();++it) {
|
||||
if ((*it)->user1() == 0) {
|
||||
AstNodeClassDType *classp;
|
||||
// It's possible that there if a reference to each individual member, but
|
||||
// not to the dtype itself. Check and don't remove the parent dtype if
|
||||
// members are still alive.
|
||||
if ((*it)->user1() == 0) {
|
||||
AstNodeClassDType *classp;
|
||||
// It's possible that there if a reference to each individual member, but
|
||||
// not to the dtype itself. Check and don't remove the parent dtype if
|
||||
// members are still alive.
|
||||
if ((classp = VN_CAST((*it), NodeClassDType))) {
|
||||
bool cont = true;
|
||||
bool cont = true;
|
||||
for (AstMemberDType *memberp = classp->membersp();
|
||||
memberp; memberp = VN_CAST(memberp->nextp(), MemberDType)) {
|
||||
if (memberp->user1() != 0) {
|
||||
cont = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!cont)
|
||||
continue;
|
||||
}
|
||||
(*it)->unlinkFrBack()->deleteTree(); VL_DANGLING(*it);
|
||||
}
|
||||
}
|
||||
if (memberp->user1() != 0) {
|
||||
cont = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!cont)
|
||||
continue;
|
||||
}
|
||||
(*it)->unlinkFrBack()->deleteTree(); VL_DANGLING(*it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
DeadVisitor(AstNetlist* nodep, bool elimUserVars, bool elimDTypes, bool elimScopes, bool elimCells) {
|
||||
m_modp = NULL;
|
||||
m_elimCells = elimCells;
|
||||
m_elimUserVars = elimUserVars;
|
||||
m_elimDTypes = elimDTypes;
|
||||
m_elimScopes = elimScopes;
|
||||
m_sideEffect = false;
|
||||
// Prepare to remove some datatypes
|
||||
nodep->typeTablep()->clearCache();
|
||||
// Operate on whole netlist
|
||||
DeadVisitor(AstNetlist* nodep, bool elimUserVars, bool elimDTypes,
|
||||
bool elimScopes, bool elimCells) {
|
||||
m_modp = NULL;
|
||||
m_elimCells = elimCells;
|
||||
m_elimUserVars = elimUserVars;
|
||||
m_elimDTypes = elimDTypes;
|
||||
m_elimScopes = elimScopes;
|
||||
m_sideEffect = false;
|
||||
// Prepare to remove some datatypes
|
||||
nodep->typeTablep()->clearCache();
|
||||
// Operate on whole netlist
|
||||
iterate(nodep);
|
||||
|
||||
deadCheckVar();
|
||||
// We only elimate scopes when in a flattened structure
|
||||
// Otherwise we have no easy way to know if a scope is used
|
||||
if (elimScopes) deadCheckScope();
|
||||
if (elimCells) deadCheckCells();
|
||||
// Modules after vars, because might be vars we delete inside a mod we delete
|
||||
deadCheckMod();
|
||||
deadCheckVar();
|
||||
// We only elimate scopes when in a flattened structure
|
||||
// Otherwise we have no easy way to know if a scope is used
|
||||
if (elimScopes) deadCheckScope();
|
||||
if (elimCells) deadCheckCells();
|
||||
// Modules after vars, because might be vars we delete inside a mod we delete
|
||||
deadCheckMod();
|
||||
|
||||
// We may have removed some datatypes, cleanup
|
||||
nodep->typeTablep()->repairCache();
|
||||
// We may have removed some datatypes, cleanup
|
||||
nodep->typeTablep()->repairCache();
|
||||
}
|
||||
virtual ~DeadVisitor() {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -41,4 +41,4 @@ public:
|
|||
static void deadifyAllScoped(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -20,34 +20,35 @@
|
|||
// V3Delayed's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// Replace ASSIGNDLY var, exp
|
||||
// With ASSIGNDLY newvar, exp
|
||||
// At top of block: VAR newvar
|
||||
// At bottom of block: ASSIGNW var newvar
|
||||
// Need _x_dly = x at top of active if "x" is not always set
|
||||
// For now we'll say it's set if at top of block (not under IF, etc)
|
||||
// Need x = _x_dly at bottom of active if "x" is never referenced on LHS
|
||||
// in the active, and above rule applies too. (If so, use x on LHS, not _x_dly.)
|
||||
// Replace ASSIGNDLY var, exp
|
||||
// With ASSIGNDLY newvar, exp
|
||||
// At top of block: VAR newvar
|
||||
// At bottom of block: ASSIGNW var newvar
|
||||
// Need _x_dly = x at top of active if "x" is not always set
|
||||
// For now we'll say it's set if at top of block (not under IF, etc)
|
||||
// Need x = _x_dly at bottom of active if "x" is never referenced on LHS
|
||||
// in the active, and above rule applies too.
|
||||
// (If so, use x on LHS, not _x_dly.)
|
||||
//
|
||||
// If a signal is set in multiple always blocks, we need a dly read & set with
|
||||
// multiple clock sensitivities. We have 3 options:
|
||||
// 1. When detected, make a new ACTIVE and move earlier created delayed assignment there
|
||||
// 2. Form unique ACTIVE for every multiple clocked assignment
|
||||
// 3. Predetect signals from multiple always blocks and do #2 on them
|
||||
// Since all 3 require a top activation cleanup, we do #2 which is easiest.
|
||||
// If a signal is set in multiple always blocks, we need a dly read & set with
|
||||
// multiple clock sensitivities. We have 3 options:
|
||||
// 1. When detected, make a new ACTIVE and move earlier created delayed assignment there
|
||||
// 2. Form unique ACTIVE for every multiple clocked assignment
|
||||
// 3. Predetect signals from multiple always blocks and do #2 on them
|
||||
// Since all 3 require a top activation cleanup, we do #2 which is easiest.
|
||||
//
|
||||
// ASSIGNDLY (BITSEL(ARRAYSEL (VARREF(v), bits), selbits), rhs)
|
||||
// -> VAR __Vdlyvset_x
|
||||
// VAR __Vdlyvval_x
|
||||
// VAR __Vdlyvdim_x
|
||||
// VAR __Vdlyvlsb_x
|
||||
// ASSIGNW (__Vdlyvset_x,0)
|
||||
// ...
|
||||
// ASSIGNW (VARREF(__Vdlyvval_x), rhs)
|
||||
// ASSIGNW (__Vdlyvdim_x, dimension_number)
|
||||
// ASSIGNW (__Vdlyvset_x, 1)
|
||||
// ...
|
||||
// ASSIGNW (BITSEL(ARRAYSEL(VARREF(x), __Vdlyvdim_x), __Vdlyvlsb_x), __Vdlyvval_x)
|
||||
// -> VAR __Vdlyvset_x
|
||||
// VAR __Vdlyvval_x
|
||||
// VAR __Vdlyvdim_x
|
||||
// VAR __Vdlyvlsb_x
|
||||
// ASSIGNW (__Vdlyvset_x,0)
|
||||
// ...
|
||||
// ASSIGNW (VARREF(__Vdlyvval_x), rhs)
|
||||
// ASSIGNW (__Vdlyvdim_x, dimension_number)
|
||||
// ASSIGNW (__Vdlyvset_x, 1)
|
||||
// ...
|
||||
// ASSIGNW (BITSEL(ARRAYSEL(VARREF(x), __Vdlyvdim_x), __Vdlyvlsb_x), __Vdlyvval_x)
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -71,76 +72,81 @@ class DelayedVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared each module:
|
||||
// AstVarScope::user1p() -> AstVarScope*. Points to temp var created.
|
||||
// AstVarScope::user2p() -> AstActive*. Points to activity block of signal (valid when AstVarScope::user1p is valid)
|
||||
// AstVarScope::user4p() -> AstAlwaysPost*. Post block for this variable
|
||||
// AstVarScope::user5() -> VarUsage. Tracks delayed vs non-delayed usage
|
||||
// AstVar::user2() -> bool. Set true if already made warning
|
||||
// AstVarRef::user2() -> bool. Set true if already processed
|
||||
// AstAlwaysPost::user2() -> ActActive*. Points to activity block of signal (valid when AstAlwaysPost::user4p is valid)
|
||||
// AstAlwaysPost::user4() -> AstIf*. Last IF (__Vdlyvset__) created under this AlwaysPost
|
||||
// AstVarScope::user1p() -> AstVarScope*. Points to temp var created.
|
||||
// AstVarScope::user2p() -> AstActive*. Points to activity block of signal
|
||||
// (valid when AstVarScope::user1p is valid)
|
||||
// AstVarScope::user4p() -> AstAlwaysPost*. Post block for this variable
|
||||
// AstVarScope::user5() -> VarUsage. Tracks delayed vs non-delayed usage
|
||||
// AstVar::user2() -> bool. Set true if already made warning
|
||||
// AstVarRef::user2() -> bool. Set true if already processed
|
||||
// AstAlwaysPost::user2() -> ActActive*. Points to activity block of signal
|
||||
// (valid when AstAlwaysPost::user4p is valid)
|
||||
// AstAlwaysPost::user4() -> AstIf*. Last IF (__Vdlyvset__) created under this AlwaysPost
|
||||
// Cleared each scope/active:
|
||||
// AstAssignDly::user3() -> AstVarScope*. __Vdlyvset__ created for this assign
|
||||
// AstAlwaysPost::user3() -> AstVarScope*. __Vdlyvset__ last referenced in IF
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
AstUser4InUse m_inuser4;
|
||||
AstUser5InUse m_inuser5;
|
||||
// AstAssignDly::user3() -> AstVarScope*. __Vdlyvset__ created for this assign
|
||||
// AstAlwaysPost::user3() -> AstVarScope*. __Vdlyvset__ last referenced in IF
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
AstUser4InUse m_inuser4;
|
||||
AstUser5InUse m_inuser5;
|
||||
|
||||
enum VarUsage { VU_NONE=0, VU_DLY=1, VU_NONDLY=2 };
|
||||
|
||||
// STATE
|
||||
AstActive* m_activep; // Current activate
|
||||
AstCFunc* m_cfuncp; // Current public C Function
|
||||
AstAssignDly* m_nextDlyp; // Next delayed assignment in a list of assignments
|
||||
bool m_inDly; // True in delayed assignments
|
||||
bool m_inLoop; // True in for loops
|
||||
bool m_inInitial; // True in intial blocks
|
||||
AstActive* m_activep; // Current activate
|
||||
AstCFunc* m_cfuncp; // Current public C Function
|
||||
AstAssignDly* m_nextDlyp; // Next delayed assignment in a list of assignments
|
||||
bool m_inDly; // True in delayed assignments
|
||||
bool m_inLoop; // True in for loops
|
||||
bool m_inInitial; // True in intial blocks
|
||||
typedef std::map<std::pair<AstNodeModule*,string>,AstVar*> VarMap;
|
||||
VarMap m_modVarMap; // Table of new var names created under module
|
||||
V3Double0 m_statSharedSet;// Statistic tracking
|
||||
VarMap m_modVarMap; // Table of new var names created under module
|
||||
V3Double0 m_statSharedSet;// Statistic tracking
|
||||
typedef std::map<AstVarScope*,int> ScopeVecMap;
|
||||
ScopeVecMap m_scopeVecMap; // Next var number for each scope
|
||||
ScopeVecMap m_scopeVecMap; // Next var number for each scope
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void markVarUsage(AstVarScope* nodep, uint32_t flags) {
|
||||
//UINFO(4," MVU "<<flags<<" "<<nodep<<endl);
|
||||
nodep->user5( nodep->user5() | flags );
|
||||
if ((nodep->user5() & VU_DLY) && (nodep->user5() & VU_NONDLY)) {
|
||||
nodep->v3warn(BLKANDNBLK,"Unsupported: Blocked and non-blocking assignments to same variable: "
|
||||
//UINFO(4," MVU "<<flags<<" "<<nodep<<endl);
|
||||
nodep->user5( nodep->user5() | flags );
|
||||
if ((nodep->user5() & VU_DLY) && (nodep->user5() & VU_NONDLY)) {
|
||||
nodep->v3warn(BLKANDNBLK, "Unsupported: Blocked and non-blocking assignments to same variable: "
|
||||
<<nodep->varp()->prettyName());
|
||||
}
|
||||
}
|
||||
}
|
||||
AstVarScope* createVarSc(AstVarScope* oldvarscp, const string& name,
|
||||
int width/*0==fromoldvar*/, AstNodeDType* newdtypep) {
|
||||
// Because we've already scoped it, we may need to add both the AstVar and the AstVarScope
|
||||
if (!oldvarscp->scopep()) oldvarscp->v3fatalSrc("Var unscoped");
|
||||
AstVar* varp;
|
||||
AstNodeModule* addmodp = oldvarscp->scopep()->modp();
|
||||
// We need a new AstVar, but only one for all scopes, to match the new AstVarScope
|
||||
VarMap::iterator it = m_modVarMap.find(make_pair(addmodp,name));
|
||||
if (it != m_modVarMap.end()) {
|
||||
// Created module's AstVar earlier under some other scope
|
||||
varp = it->second;
|
||||
} else {
|
||||
if (newdtypep) {
|
||||
varp = new AstVar(oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, newdtypep);
|
||||
} else if (width==0) {
|
||||
varp = new AstVar(oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, oldvarscp->varp());
|
||||
varp->dtypeFrom(oldvarscp);
|
||||
} else { // Used for vset and dimensions, so can zero init
|
||||
varp = new AstVar(oldvarscp->fileline(), AstVarType::BLOCKTEMP, name, VFlagBitPacked(), width);
|
||||
}
|
||||
addmodp->addStmtp(varp);
|
||||
m_modVarMap.insert(make_pair(make_pair(addmodp, name), varp));
|
||||
}
|
||||
// Because we've already scoped it, we may need to add both the AstVar and the AstVarScope
|
||||
if (!oldvarscp->scopep()) oldvarscp->v3fatalSrc("Var unscoped");
|
||||
AstVar* varp;
|
||||
AstNodeModule* addmodp = oldvarscp->scopep()->modp();
|
||||
// We need a new AstVar, but only one for all scopes, to match the new AstVarScope
|
||||
VarMap::iterator it = m_modVarMap.find(make_pair(addmodp, name));
|
||||
if (it != m_modVarMap.end()) {
|
||||
// Created module's AstVar earlier under some other scope
|
||||
varp = it->second;
|
||||
} else {
|
||||
if (newdtypep) {
|
||||
varp = new AstVar(oldvarscp->fileline(), AstVarType::BLOCKTEMP,
|
||||
name, newdtypep);
|
||||
} else if (width==0) {
|
||||
varp = new AstVar(oldvarscp->fileline(), AstVarType::BLOCKTEMP,
|
||||
name, oldvarscp->varp());
|
||||
varp->dtypeFrom(oldvarscp);
|
||||
} else { // Used for vset and dimensions, so can zero init
|
||||
varp = new AstVar(oldvarscp->fileline(), AstVarType::BLOCKTEMP,
|
||||
name, VFlagBitPacked(), width);
|
||||
}
|
||||
addmodp->addStmtp(varp);
|
||||
m_modVarMap.insert(make_pair(make_pair(addmodp, name), varp));
|
||||
}
|
||||
|
||||
AstVarScope* varscp = new AstVarScope(oldvarscp->fileline(), oldvarscp->scopep(), varp);
|
||||
oldvarscp->scopep()->addVarp(varscp);
|
||||
return varscp;
|
||||
oldvarscp->scopep()->addVarp(varscp);
|
||||
return varscp;
|
||||
}
|
||||
|
||||
AstActive* createActivePost(AstVarRef* varrefp) {
|
||||
|
|
@ -148,299 +154,302 @@ private:
|
|||
m_activep->sensesp());
|
||||
// Was addNext(), but addNextHere() avoids a linear search.
|
||||
m_activep->addNextHere(newactp);
|
||||
return newactp;
|
||||
return newactp;
|
||||
}
|
||||
void checkActivePost(AstVarRef* varrefp, AstActive* oldactivep) {
|
||||
// Check for MULTIDRIVEN, and if so make new sentree that joins old & new sentree
|
||||
if (!oldactivep) varrefp->v3fatalSrc("<= old dly assignment not put under sensitivity block");
|
||||
if (oldactivep->sensesp() != m_activep->sensesp()) {
|
||||
if (!varrefp->varp()->fileline()->warnIsOff(V3ErrorCode::MULTIDRIVEN)
|
||||
&& !varrefp->varp()->user2()) {
|
||||
varrefp->varp()->v3warn(MULTIDRIVEN,"Signal has multiple driving blocks with different clocking: "
|
||||
<<varrefp->varp()->prettyName()<<endl
|
||||
<<varrefp->warnMore()<<"... Location of first driving block"<<endl
|
||||
<<oldactivep->warnMore()<<"... Location of other driving block");
|
||||
varrefp->varp()->user2(true);
|
||||
}
|
||||
UINFO(4,"AssignDupDlyVar: "<<varrefp<<endl);
|
||||
UINFO(4," Act: "<<m_activep<<endl);
|
||||
UINFO(4," Act: "<<oldactivep<<endl);
|
||||
// Make a new sensitivity list, which is the combination of both blocks
|
||||
AstNodeSenItem* sena = m_activep->sensesp()->sensesp()->cloneTree(true);
|
||||
AstNodeSenItem* senb = oldactivep->sensesp()->sensesp()->cloneTree(true);
|
||||
AstSenTree* treep = new AstSenTree(m_activep->fileline(), sena);
|
||||
if (senb) treep->addSensesp(senb);
|
||||
if (AstSenTree* storep = oldactivep->sensesStorep()) {
|
||||
storep->unlinkFrBack();
|
||||
pushDeletep(storep);
|
||||
}
|
||||
oldactivep->sensesStorep(treep);
|
||||
oldactivep->sensesp(treep);
|
||||
}
|
||||
// Check for MULTIDRIVEN, and if so make new sentree that joins old & new sentree
|
||||
if (!oldactivep) varrefp->v3fatalSrc("<= old dly assignment not put under sensitivity block");
|
||||
if (oldactivep->sensesp() != m_activep->sensesp()) {
|
||||
if (!varrefp->varp()->fileline()->warnIsOff(V3ErrorCode::MULTIDRIVEN)
|
||||
&& !varrefp->varp()->user2()) {
|
||||
varrefp->varp()->v3warn(
|
||||
MULTIDRIVEN, "Signal has multiple driving blocks with different clocking: "
|
||||
<<varrefp->varp()->prettyName()<<endl
|
||||
<<varrefp->warnMore()<<"... Location of first driving block"<<endl
|
||||
<<oldactivep->warnMore()<<"... Location of other driving block");
|
||||
varrefp->varp()->user2(true);
|
||||
}
|
||||
UINFO(4,"AssignDupDlyVar: "<<varrefp<<endl);
|
||||
UINFO(4," Act: "<<m_activep<<endl);
|
||||
UINFO(4," Act: "<<oldactivep<<endl);
|
||||
// Make a new sensitivity list, which is the combination of both blocks
|
||||
AstNodeSenItem* sena = m_activep->sensesp()->sensesp()->cloneTree(true);
|
||||
AstNodeSenItem* senb = oldactivep->sensesp()->sensesp()->cloneTree(true);
|
||||
AstSenTree* treep = new AstSenTree(m_activep->fileline(), sena);
|
||||
if (senb) treep->addSensesp(senb);
|
||||
if (AstSenTree* storep = oldactivep->sensesStorep()) {
|
||||
storep->unlinkFrBack();
|
||||
pushDeletep(storep);
|
||||
}
|
||||
oldactivep->sensesStorep(treep);
|
||||
oldactivep->sensesp(treep);
|
||||
}
|
||||
}
|
||||
|
||||
AstNode* createDlyArray(AstAssignDly* nodep, AstNode* lhsp) {
|
||||
// Create delayed assignment
|
||||
// See top of this file for transformation
|
||||
// Return the new LHS for the assignment, Null = unlink
|
||||
// Find selects
|
||||
AstNode* newlhsp = NULL; // NULL = unlink old assign
|
||||
AstSel* bitselp = NULL;
|
||||
AstArraySel* arrayselp = NULL;
|
||||
// Create delayed assignment
|
||||
// See top of this file for transformation
|
||||
// Return the new LHS for the assignment, Null = unlink
|
||||
// Find selects
|
||||
AstNode* newlhsp = NULL; // NULL = unlink old assign
|
||||
AstSel* bitselp = NULL;
|
||||
AstArraySel* arrayselp = NULL;
|
||||
if (VN_IS(lhsp, Sel)) {
|
||||
bitselp = VN_CAST(lhsp, Sel);
|
||||
arrayselp = VN_CAST(bitselp->fromp(), ArraySel);
|
||||
} else {
|
||||
} else {
|
||||
arrayselp = VN_CAST(lhsp, ArraySel);
|
||||
}
|
||||
if (!arrayselp) nodep->v3fatalSrc("No arraysel under bitsel?");
|
||||
}
|
||||
if (!arrayselp) nodep->v3fatalSrc("No arraysel under bitsel?");
|
||||
if (VN_IS(arrayselp->dtypep()->skipRefp(), UnpackArrayDType)) {
|
||||
nodep->v3fatalSrc("ArraySel with unpacked arrays should have been removed in V3Slice");
|
||||
}
|
||||
UINFO(4,"AssignDlyArray: "<<nodep<<endl);
|
||||
//
|
||||
//=== Dimensions: __Vdlyvdim__
|
||||
std::deque<AstNode*> dimvalp; // Assignment value for each dimension of assignment
|
||||
AstNode* dimselp=arrayselp;
|
||||
UINFO(4,"AssignDlyArray: "<<nodep<<endl);
|
||||
//
|
||||
//=== Dimensions: __Vdlyvdim__
|
||||
std::deque<AstNode*> dimvalp; // Assignment value for each dimension of assignment
|
||||
AstNode* dimselp = arrayselp;
|
||||
for (; VN_IS(dimselp, ArraySel); dimselp=VN_CAST(dimselp, ArraySel)->fromp()) {
|
||||
AstNode* valp = VN_CAST(dimselp, ArraySel)->bitp()->unlinkFrBack();
|
||||
dimvalp.push_front(valp);
|
||||
}
|
||||
dimvalp.push_front(valp);
|
||||
}
|
||||
AstVarRef* varrefp = VN_CAST(dimselp, VarRef);
|
||||
if (!varrefp) nodep->v3fatalSrc("No var underneath arraysels");
|
||||
if (!varrefp->varScopep()) varrefp->v3fatalSrc("Var didn't get varscoped in V3Scope.cpp");
|
||||
varrefp->unlinkFrBack();
|
||||
AstVar* oldvarp = varrefp->varp();
|
||||
int modVecNum = m_scopeVecMap[varrefp->varScopep()]++;
|
||||
//
|
||||
std::deque<AstNode*> dimreadps; // Read value for each dimension of assignment
|
||||
for (unsigned dimension=0; dimension<dimvalp.size(); dimension++) {
|
||||
AstNode* dimp = dimvalp[dimension];
|
||||
if (!varrefp) nodep->v3fatalSrc("No var underneath arraysels");
|
||||
if (!varrefp->varScopep()) varrefp->v3fatalSrc("Var didn't get varscoped in V3Scope.cpp");
|
||||
varrefp->unlinkFrBack();
|
||||
AstVar* oldvarp = varrefp->varp();
|
||||
int modVecNum = m_scopeVecMap[varrefp->varScopep()]++;
|
||||
//
|
||||
std::deque<AstNode*> dimreadps; // Read value for each dimension of assignment
|
||||
for (unsigned dimension=0; dimension<dimvalp.size(); dimension++) {
|
||||
AstNode* dimp = dimvalp[dimension];
|
||||
if (VN_IS(dimp, Const)) { // bit = const, can just use it
|
||||
dimreadps.push_front(dimp);
|
||||
} else {
|
||||
string bitvarname = (string("__Vdlyvdim")+cvtToStr(dimension)
|
||||
+"__"+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, dimp->width(), NULL);
|
||||
AstAssign* bitassignp
|
||||
dimreadps.push_front(dimp);
|
||||
} else {
|
||||
string bitvarname = (string("__Vdlyvdim")+cvtToStr(dimension)
|
||||
+"__"+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(),
|
||||
bitvarname, dimp->width(), NULL);
|
||||
AstAssign* bitassignp
|
||||
= new AstAssign(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), bitvscp, true),
|
||||
dimp);
|
||||
nodep->addNextHere(bitassignp);
|
||||
dimreadps.push_front(new AstVarRef(nodep->fileline(), bitvscp, false));
|
||||
}
|
||||
}
|
||||
//
|
||||
//=== Bitselect: __Vdlyvlsb__
|
||||
AstNode* bitreadp=NULL; // Code to read Vdlyvlsb
|
||||
if (bitselp) {
|
||||
AstNode* lsbvaluep = bitselp->lsbp()->unlinkFrBack();
|
||||
nodep->addNextHere(bitassignp);
|
||||
dimreadps.push_front(new AstVarRef(nodep->fileline(), bitvscp, false));
|
||||
}
|
||||
}
|
||||
//
|
||||
//=== Bitselect: __Vdlyvlsb__
|
||||
AstNode* bitreadp = NULL; // Code to read Vdlyvlsb
|
||||
if (bitselp) {
|
||||
AstNode* lsbvaluep = bitselp->lsbp()->unlinkFrBack();
|
||||
if (VN_IS(bitselp->fromp(), Const)) { // vlsb = constant, can just push constant into where we use it
|
||||
bitreadp = lsbvaluep;
|
||||
} else {
|
||||
string bitvarname = (string("__Vdlyvlsb__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(), bitvarname, lsbvaluep->width(), NULL);
|
||||
bitreadp = lsbvaluep;
|
||||
} else {
|
||||
string bitvarname = (string("__Vdlyvlsb__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
AstVarScope* bitvscp = createVarSc(varrefp->varScopep(),
|
||||
bitvarname, lsbvaluep->width(), NULL);
|
||||
AstAssign* bitassignp = new AstAssign(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), bitvscp, true),
|
||||
lsbvaluep);
|
||||
nodep->addNextHere(bitassignp);
|
||||
bitreadp = new AstVarRef(nodep->fileline(), bitvscp, false);
|
||||
}
|
||||
}
|
||||
//
|
||||
//=== Value: __Vdlyvval__
|
||||
AstNode* valreadp; // Code to read Vdlyvval
|
||||
nodep->addNextHere(bitassignp);
|
||||
bitreadp = new AstVarRef(nodep->fileline(), bitvscp, false);
|
||||
}
|
||||
}
|
||||
//
|
||||
//=== Value: __Vdlyvval__
|
||||
AstNode* valreadp; // Code to read Vdlyvval
|
||||
if (VN_IS(nodep->rhsp(), Const)) { // vval = constant, can just push constant into where we use it
|
||||
valreadp = nodep->rhsp()->unlinkFrBack();
|
||||
} else {
|
||||
string valvarname = (string("__Vdlyvval__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
AstVarScope* valvscp = createVarSc(varrefp->varScopep(), valvarname, 0, nodep->rhsp()->dtypep());
|
||||
newlhsp = new AstVarRef(nodep->fileline(), valvscp, true);
|
||||
valreadp = new AstVarRef(nodep->fileline(), valvscp, false);
|
||||
}
|
||||
//
|
||||
//=== Setting/not setting boolean: __Vdlyvset__
|
||||
AstVarScope* setvscp;
|
||||
AstAssignPre* setinitp = NULL;
|
||||
valreadp = nodep->rhsp()->unlinkFrBack();
|
||||
} else {
|
||||
string valvarname = (string("__Vdlyvval__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
AstVarScope* valvscp = createVarSc(varrefp->varScopep(), valvarname, 0, nodep->rhsp()->dtypep());
|
||||
newlhsp = new AstVarRef(nodep->fileline(), valvscp, true);
|
||||
valreadp = new AstVarRef(nodep->fileline(), valvscp, false);
|
||||
}
|
||||
//
|
||||
//=== Setting/not setting boolean: __Vdlyvset__
|
||||
AstVarScope* setvscp;
|
||||
AstAssignPre* setinitp = NULL;
|
||||
|
||||
if (nodep->user3p()) {
|
||||
// Simplistic optimization. If the previous statement in same scope was also a =>,
|
||||
// then we told this nodep->user3 we can use its Vdlyvset rather than making a new one.
|
||||
// This is good for code like:
|
||||
// for (i=0; i<5; i++) vector[i] <= something;
|
||||
if (nodep->user3p()) {
|
||||
// Simplistic optimization. If the previous statement in same scope was also a =>,
|
||||
// then we told this nodep->user3 we can use its Vdlyvset rather than making a new one.
|
||||
// This is good for code like:
|
||||
// for (i=0; i<5; i++) vector[i] <= something;
|
||||
setvscp = VN_CAST(nodep->user3p(), VarScope);
|
||||
++m_statSharedSet;
|
||||
} else { // Create new one
|
||||
string setvarname = (string("__Vdlyvset__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
setvscp = createVarSc(varrefp->varScopep(), setvarname, 1, NULL);
|
||||
++m_statSharedSet;
|
||||
} else { // Create new one
|
||||
string setvarname = (string("__Vdlyvset__")+oldvarp->shortName()+"__v"+cvtToStr(modVecNum));
|
||||
setvscp = createVarSc(varrefp->varScopep(), setvarname, 1, NULL);
|
||||
setinitp = new AstAssignPre(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), setvscp, true),
|
||||
new AstConst(nodep->fileline(), 0));
|
||||
AstAssign* setassignp
|
||||
AstAssign* setassignp
|
||||
= new AstAssign(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), setvscp, true),
|
||||
new AstConst(nodep->fileline(),
|
||||
V3Number(nodep, 1, true)));
|
||||
nodep->addNextHere(setassignp);
|
||||
}
|
||||
if (m_nextDlyp) { // Tell next assigndly it can share the variable
|
||||
m_nextDlyp->user3p(setvscp);
|
||||
}
|
||||
//
|
||||
// Create ALWAYSPOST for delayed variable
|
||||
// We add all logic to the same block if it's for the same memory
|
||||
// This ensures that multiple assignments to the same memory will result
|
||||
// in correctly ordered code - the last assignment must be last.
|
||||
// It also has the nice side effect of assisting cache locality.
|
||||
AstNode* selectsp = varrefp;
|
||||
for (int dimension=int(dimreadps.size())-1; dimension>=0; --dimension) {
|
||||
selectsp = new AstArraySel(nodep->fileline(), selectsp, dimreadps[dimension]);
|
||||
}
|
||||
if (bitselp) {
|
||||
selectsp = new AstSel(nodep->fileline(), selectsp, bitreadp,
|
||||
bitselp->widthp()->cloneTree(false));
|
||||
}
|
||||
// Build "IF (changeit) ...
|
||||
UINFO(9," For "<<setvscp<<endl);
|
||||
UINFO(9," & "<<varrefp<<endl);
|
||||
if (m_nextDlyp) { // Tell next assigndly it can share the variable
|
||||
m_nextDlyp->user3p(setvscp);
|
||||
}
|
||||
//
|
||||
// Create ALWAYSPOST for delayed variable
|
||||
// We add all logic to the same block if it's for the same memory
|
||||
// This ensures that multiple assignments to the same memory will result
|
||||
// in correctly ordered code - the last assignment must be last.
|
||||
// It also has the nice side effect of assisting cache locality.
|
||||
AstNode* selectsp = varrefp;
|
||||
for (int dimension=int(dimreadps.size())-1; dimension>=0; --dimension) {
|
||||
selectsp = new AstArraySel(nodep->fileline(), selectsp, dimreadps[dimension]);
|
||||
}
|
||||
if (bitselp) {
|
||||
selectsp = new AstSel(nodep->fileline(), selectsp, bitreadp,
|
||||
bitselp->widthp()->cloneTree(false));
|
||||
}
|
||||
// Build "IF (changeit) ...
|
||||
UINFO(9," For "<<setvscp<<endl);
|
||||
UINFO(9," & "<<varrefp<<endl);
|
||||
AstAlwaysPost* finalp = VN_CAST(varrefp->varScopep()->user4p(), AlwaysPost);
|
||||
if (finalp) {
|
||||
if (finalp) {
|
||||
AstActive* oldactivep = VN_CAST(finalp->user2p(), Active);
|
||||
checkActivePost(varrefp, oldactivep);
|
||||
if (setinitp) oldactivep->addStmtsp(setinitp);
|
||||
} else { // first time we've dealt with this memory
|
||||
finalp = new AstAlwaysPost(nodep->fileline(), NULL/*sens*/, NULL/*body*/);
|
||||
UINFO(9," Created "<<finalp<<endl);
|
||||
AstActive* newactp = createActivePost(varrefp);
|
||||
newactp->addStmtsp(finalp);
|
||||
varrefp->varScopep()->user4p(finalp);
|
||||
finalp->user2p(newactp);
|
||||
if (setinitp) newactp->addStmtsp(setinitp);
|
||||
}
|
||||
AstIf* postLogicp;
|
||||
if (finalp->user3p() == setvscp) {
|
||||
// Optimize as above; if sharing Vdlyvset *ON SAME VARIABLE*,
|
||||
// we can share the IF statement too
|
||||
checkActivePost(varrefp, oldactivep);
|
||||
if (setinitp) oldactivep->addStmtsp(setinitp);
|
||||
} else { // first time we've dealt with this memory
|
||||
finalp = new AstAlwaysPost(nodep->fileline(), NULL/*sens*/, NULL/*body*/);
|
||||
UINFO(9," Created "<<finalp<<endl);
|
||||
AstActive* newactp = createActivePost(varrefp);
|
||||
newactp->addStmtsp(finalp);
|
||||
varrefp->varScopep()->user4p(finalp);
|
||||
finalp->user2p(newactp);
|
||||
if (setinitp) newactp->addStmtsp(setinitp);
|
||||
}
|
||||
AstIf* postLogicp;
|
||||
if (finalp->user3p() == setvscp) {
|
||||
// Optimize as above; if sharing Vdlyvset *ON SAME VARIABLE*,
|
||||
// we can share the IF statement too
|
||||
postLogicp = VN_CAST(finalp->user4p(), If);
|
||||
if (!postLogicp) nodep->v3fatalSrc("Delayed assignment misoptimized; prev var found w/o associated IF");
|
||||
} else {
|
||||
if (!postLogicp) nodep->v3fatalSrc("Delayed assignment misoptimized; prev var found w/o associated IF");
|
||||
} else {
|
||||
postLogicp = new AstIf(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), setvscp, false),
|
||||
NULL, NULL);
|
||||
UINFO(9," Created "<<postLogicp<<endl);
|
||||
finalp->addBodysp(postLogicp);
|
||||
finalp->user3p(setvscp); // Remember IF's vset variable
|
||||
finalp->user4p(postLogicp); // and the associated IF, as we may be able to reuse it
|
||||
}
|
||||
postLogicp->addIfsp(new AstAssign(nodep->fileline(), selectsp, valreadp));
|
||||
return newlhsp;
|
||||
UINFO(9," Created "<<postLogicp<<endl);
|
||||
finalp->addBodysp(postLogicp);
|
||||
finalp->user3p(setvscp); // Remember IF's vset variable
|
||||
finalp->user4p(postLogicp); // and the associated IF, as we may be able to reuse it
|
||||
}
|
||||
postLogicp->addIfsp(new AstAssign(nodep->fileline(), selectsp, valreadp));
|
||||
return newlhsp;
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNetlist* nodep) {
|
||||
//VV***** We reset all userp() on the netlist
|
||||
m_modVarMap.clear();
|
||||
//VV***** We reset all userp() on the netlist
|
||||
m_modVarMap.clear();
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstScope* nodep) {
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
AstNode::user3ClearTree();
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
AstNode::user3ClearTree();
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
m_cfuncp = nodep;
|
||||
m_cfuncp = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_cfuncp = NULL;
|
||||
m_cfuncp = NULL;
|
||||
}
|
||||
virtual void visit(AstActive* nodep) {
|
||||
m_activep = nodep;
|
||||
bool oldinit = m_inInitial;
|
||||
m_inInitial = nodep->hasInitial();
|
||||
AstNode::user3ClearTree(); // Two sets to same variable in different actives must use different vars.
|
||||
m_activep = nodep;
|
||||
bool oldinit = m_inInitial;
|
||||
m_inInitial = nodep->hasInitial();
|
||||
AstNode::user3ClearTree(); // Two sets to same variable in different actives must use different vars.
|
||||
iterateChildren(nodep);
|
||||
m_inInitial = oldinit;
|
||||
m_inInitial = oldinit;
|
||||
}
|
||||
virtual void visit(AstAssignDly* nodep) {
|
||||
m_inDly = true;
|
||||
m_inDly = true;
|
||||
m_nextDlyp = VN_CAST(nodep->nextp(), AssignDly); // Next assignment in same block, maybe NULL.
|
||||
if (m_cfuncp) nodep->v3error("Unsupported: Delayed assignment inside public function/task");
|
||||
if (m_cfuncp) nodep->v3error("Unsupported: Delayed assignment inside public function/task");
|
||||
if (VN_IS(nodep->lhsp(), ArraySel)
|
||||
|| (VN_IS(nodep->lhsp(), Sel)
|
||||
&& VN_IS(VN_CAST(nodep->lhsp(), Sel)->fromp(), ArraySel))) {
|
||||
AstNode* lhsp = nodep->lhsp()->unlinkFrBack();
|
||||
AstNode* newlhsp = createDlyArray(nodep, lhsp);
|
||||
if (m_inLoop) nodep->v3warn(BLKLOOPINIT,"Unsupported: Delayed assignment to array inside for loops (non-delayed is ok - see docs)");
|
||||
if (newlhsp) {
|
||||
nodep->lhsp(newlhsp);
|
||||
} else {
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
lhsp->deleteTree(); VL_DANGLING(lhsp);
|
||||
}
|
||||
else {
|
||||
AstNode* lhsp = nodep->lhsp()->unlinkFrBack();
|
||||
AstNode* newlhsp = createDlyArray(nodep, lhsp);
|
||||
if (m_inLoop) nodep->v3warn(BLKLOOPINIT, "Unsupported: Delayed assignment to array inside for loops (non-delayed is ok - see docs)");
|
||||
if (newlhsp) {
|
||||
nodep->lhsp(newlhsp);
|
||||
} else {
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
lhsp->deleteTree(); VL_DANGLING(lhsp);
|
||||
}
|
||||
else {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
m_inDly = false;
|
||||
m_nextDlyp = NULL;
|
||||
}
|
||||
m_inDly = false;
|
||||
m_nextDlyp = NULL;
|
||||
}
|
||||
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
if (!nodep->user2Inc()) { // Not done yet
|
||||
if (m_inDly && nodep->lvalue()) {
|
||||
UINFO(4,"AssignDlyVar: "<<nodep<<endl);
|
||||
markVarUsage(nodep->varScopep(), VU_DLY);
|
||||
if (!m_activep) nodep->v3fatalSrc("<= not under sensitivity block");
|
||||
if (!nodep->user2Inc()) { // Not done yet
|
||||
if (m_inDly && nodep->lvalue()) {
|
||||
UINFO(4,"AssignDlyVar: "<<nodep<<endl);
|
||||
markVarUsage(nodep->varScopep(), VU_DLY);
|
||||
if (!m_activep) nodep->v3fatalSrc("<= not under sensitivity block");
|
||||
if (!m_activep->hasClocked()) {
|
||||
nodep->v3error("Internal: Blocking <= assignment in non-clocked block, should have converted in V3Active");
|
||||
}
|
||||
AstVarScope* oldvscp = nodep->varScopep();
|
||||
if (!oldvscp) nodep->v3fatalSrc("Var didn't get varscoped in V3Scope.cpp");
|
||||
AstVarScope* oldvscp = nodep->varScopep();
|
||||
if (!oldvscp) nodep->v3fatalSrc("Var didn't get varscoped in V3Scope.cpp");
|
||||
AstVarScope* dlyvscp = VN_CAST(oldvscp->user1p(), VarScope);
|
||||
if (dlyvscp) { // Multiple use of delayed variable
|
||||
if (dlyvscp) { // Multiple use of delayed variable
|
||||
AstActive* oldactivep = VN_CAST(dlyvscp->user2p(), Active);
|
||||
checkActivePost(nodep, oldactivep);
|
||||
}
|
||||
if (!dlyvscp) { // First use of this delayed variable
|
||||
string newvarname = (string("__Vdly__")+nodep->varp()->shortName());
|
||||
dlyvscp = createVarSc(oldvscp, newvarname, 0, NULL);
|
||||
AstNodeAssign* prep
|
||||
checkActivePost(nodep, oldactivep);
|
||||
}
|
||||
if (!dlyvscp) { // First use of this delayed variable
|
||||
string newvarname = (string("__Vdly__")+nodep->varp()->shortName());
|
||||
dlyvscp = createVarSc(oldvscp, newvarname, 0, NULL);
|
||||
AstNodeAssign* prep
|
||||
= new AstAssignPre(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), dlyvscp, true),
|
||||
new AstVarRef(nodep->fileline(), oldvscp, false));
|
||||
AstNodeAssign* postp
|
||||
AstNodeAssign* postp
|
||||
= new AstAssignPost(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), oldvscp, true),
|
||||
new AstVarRef(nodep->fileline(), dlyvscp, false));
|
||||
postp->lhsp()->user2(true); // Don't detect this assignment
|
||||
oldvscp->user1p(dlyvscp); // So we can find it later
|
||||
// Make new ACTIVE with identical sensitivity tree
|
||||
AstActive* newactp = createActivePost(nodep);
|
||||
dlyvscp->user2p(newactp);
|
||||
newactp->addStmtsp(prep); // Add to FRONT of statements
|
||||
newactp->addStmtsp(postp);
|
||||
}
|
||||
AstVarRef* newrefp = new AstVarRef(nodep->fileline(), dlyvscp, true);
|
||||
newrefp->user2(true); // No reason to do it again
|
||||
nodep->replaceWith(newrefp); nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
else if (!m_inDly && nodep->lvalue()) {
|
||||
//UINFO(9,"NBA "<<nodep<<endl);
|
||||
if (!m_inInitial) {
|
||||
UINFO(4,"AssignNDlyVar: "<<nodep<<endl);
|
||||
markVarUsage(nodep->varScopep(), VU_NONDLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
postp->lhsp()->user2(true); // Don't detect this assignment
|
||||
oldvscp->user1p(dlyvscp); // So we can find it later
|
||||
// Make new ACTIVE with identical sensitivity tree
|
||||
AstActive* newactp = createActivePost(nodep);
|
||||
dlyvscp->user2p(newactp);
|
||||
newactp->addStmtsp(prep); // Add to FRONT of statements
|
||||
newactp->addStmtsp(postp);
|
||||
}
|
||||
AstVarRef* newrefp = new AstVarRef(nodep->fileline(), dlyvscp, true);
|
||||
newrefp->user2(true); // No reason to do it again
|
||||
nodep->replaceWith(newrefp); nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
else if (!m_inDly && nodep->lvalue()) {
|
||||
//UINFO(9,"NBA "<<nodep<<endl);
|
||||
if (!m_inInitial) {
|
||||
UINFO(4,"AssignNDlyVar: "<<nodep<<endl);
|
||||
markVarUsage(nodep->varScopep(), VU_NONDLY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(AstNodeFor* nodep) {
|
||||
nodep->v3fatalSrc("For statements should have been converted to while statements in V3Begin");
|
||||
nodep->v3fatalSrc("For statements should have been converted to while statements in V3Begin");
|
||||
}
|
||||
virtual void visit(AstWhile* nodep) {
|
||||
bool oldloop = m_inLoop;
|
||||
m_inLoop = true;
|
||||
bool oldloop = m_inLoop;
|
||||
m_inLoop = true;
|
||||
iterateChildren(nodep);
|
||||
m_inLoop = oldloop;
|
||||
m_inLoop = oldloop;
|
||||
}
|
||||
|
||||
//--------------------
|
||||
|
|
@ -452,17 +461,17 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit DelayedVisitor(AstNetlist* nodep) {
|
||||
m_inDly = false;
|
||||
m_activep=NULL;
|
||||
m_cfuncp=NULL;
|
||||
m_nextDlyp=NULL;
|
||||
m_inLoop = false;
|
||||
m_inInitial = false;
|
||||
m_inDly = false;
|
||||
m_activep = NULL;
|
||||
m_cfuncp = NULL;
|
||||
m_nextDlyp = NULL;
|
||||
m_inLoop = false;
|
||||
m_inInitial = false;
|
||||
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~DelayedVisitor() {
|
||||
V3Stats::addStat("Optimizations, Delayed shared-sets", m_statSharedSet);
|
||||
V3Stats::addStat("Optimizations, Delayed shared-sets", m_statSharedSet);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void delayedAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
118
src/V3Depth.cpp
118
src/V3Depth.cpp
|
|
@ -20,10 +20,10 @@
|
|||
// V3Depth's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// For each wide OP, assign a temporary variable.
|
||||
// For each deep expression, assign expression to temporary.
|
||||
// For each wide OP, assign a temporary variable.
|
||||
// For each deep expression, assign expression to temporary.
|
||||
// Each CFunc:
|
||||
// Any statements that need "this" are marked non-static
|
||||
// Any statements that need "this" are marked non-static
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -44,62 +44,64 @@ private:
|
|||
// NODE STATE
|
||||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_funcp; // Current block
|
||||
AstNode* m_stmtp; // Current statement
|
||||
int m_depth; // How deep in an expression
|
||||
int m_maxdepth; // Maximum depth in an expression
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_funcp; // Current block
|
||||
AstNode* m_stmtp; // Current statement
|
||||
int m_depth; // How deep in an expression
|
||||
int m_maxdepth; // Maximum depth in an expression
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void createDeepTemp(AstNode* nodep) {
|
||||
UINFO(6," Deep "<<nodep<<endl);
|
||||
//if (debug()>=9) nodep->dumpTree(cout,"deep:");
|
||||
UINFO(6," Deep "<<nodep<<endl);
|
||||
//if (debug()>=9) nodep->dumpTree(cout, "deep:");
|
||||
|
||||
string newvarname = (string("__Vdeeptemp")+cvtToStr(m_modp->varNumGetInc()));
|
||||
AstVar* varp = new AstVar(nodep->fileline(), AstVarType::STMTTEMP, newvarname,
|
||||
// Width, not widthMin, as we may be in middle of BITSEL expression which
|
||||
// though it's one bit wide, needs the mask in the upper bits.
|
||||
// (Someday we'll have a valid bitmask instead of widths....)
|
||||
// Width, not widthMin, as we may be in
|
||||
// middle of BITSEL expression which though
|
||||
// it's one bit wide, needs the mask in the
|
||||
// upper bits. (Someday we'll have a valid
|
||||
// bitmask instead of widths....)
|
||||
// See t_func_crc for an example test that requires this
|
||||
VFlagLogicPacked(), nodep->width());
|
||||
if (!m_funcp) nodep->v3fatalSrc("Deep expression not under a function");
|
||||
m_funcp->addInitsp(varp);
|
||||
// Replace node tree with reference to var
|
||||
if (!m_funcp) nodep->v3fatalSrc("Deep expression not under a function");
|
||||
m_funcp->addInitsp(varp);
|
||||
// Replace node tree with reference to var
|
||||
AstVarRef* newp = new AstVarRef(nodep->fileline(), varp, false);
|
||||
nodep->replaceWith(newp);
|
||||
// Put assignment before the referencing statement
|
||||
nodep->replaceWith(newp);
|
||||
// Put assignment before the referencing statement
|
||||
AstAssign* assp = new AstAssign(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), varp, true),
|
||||
nodep);
|
||||
AstNRelinker linker2;
|
||||
m_stmtp->unlinkFrBack(&linker2);
|
||||
assp->addNext(m_stmtp);
|
||||
linker2.relink(assp);
|
||||
AstNRelinker linker2;
|
||||
m_stmtp->unlinkFrBack(&linker2);
|
||||
assp->addNext(m_stmtp);
|
||||
linker2.relink(assp);
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
m_funcp = NULL;
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
m_funcp = NULL;
|
||||
iterateChildren(nodep);
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
m_funcp = nodep;
|
||||
m_depth = 0;
|
||||
m_maxdepth = 0;
|
||||
m_funcp = nodep;
|
||||
m_depth = 0;
|
||||
m_maxdepth = 0;
|
||||
iterateChildren(nodep);
|
||||
m_funcp = NULL;
|
||||
m_funcp = NULL;
|
||||
}
|
||||
void visitStmt(AstNodeStmt* nodep) {
|
||||
m_depth = 0;
|
||||
m_maxdepth = 0;
|
||||
m_stmtp = nodep;
|
||||
m_depth = 0;
|
||||
m_maxdepth = 0;
|
||||
m_stmtp = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_stmtp = NULL;
|
||||
m_stmtp = NULL;
|
||||
}
|
||||
virtual void visit(AstNodeStmt* nodep) {
|
||||
if (!nodep->isStatement()) {
|
||||
|
|
@ -112,20 +114,20 @@ private:
|
|||
virtual void visit(AstNodeTermop* nodep) {
|
||||
}
|
||||
virtual void visit(AstNodeMath* nodep) {
|
||||
// We have some operator defines that use 2 parens, so += 2.
|
||||
m_depth += 2;
|
||||
if (m_depth>m_maxdepth) m_maxdepth=m_depth;
|
||||
// We have some operator defines that use 2 parens, so += 2.
|
||||
m_depth += 2;
|
||||
if (m_depth>m_maxdepth) m_maxdepth = m_depth;
|
||||
iterateChildren(nodep);
|
||||
m_depth -= 2;
|
||||
m_depth -= 2;
|
||||
|
||||
if (m_stmtp
|
||||
&& (v3Global.opt.compLimitParens() >= 1) // Else compiler doesn't need it
|
||||
&& (m_maxdepth-m_depth) > v3Global.opt.compLimitParens()
|
||||
if (m_stmtp
|
||||
&& (v3Global.opt.compLimitParens() >= 1) // Else compiler doesn't need it
|
||||
&& (m_maxdepth-m_depth) > v3Global.opt.compLimitParens()
|
||||
&& !VN_IS(nodep->backp(), NodeStmt) // Not much point if we're about to use it
|
||||
) {
|
||||
m_maxdepth = m_depth;
|
||||
createDeepTemp(nodep);
|
||||
}
|
||||
) {
|
||||
m_maxdepth = m_depth;
|
||||
createDeepTemp(nodep);
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------
|
||||
|
|
@ -134,22 +136,22 @@ private:
|
|||
void needNonStaticFunc(AstNode* nodep) {
|
||||
if (!m_funcp) nodep->v3fatalSrc("Non-static accessor not under a function");
|
||||
if (m_funcp->isStatic().trueU()) {
|
||||
UINFO(5,"Mark non-public due to "<<nodep<<endl);
|
||||
m_funcp->isStatic(false);
|
||||
}
|
||||
UINFO(5,"Mark non-public due to "<<nodep<<endl);
|
||||
m_funcp->isStatic(false);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstUCFunc* nodep) {
|
||||
needNonStaticFunc(nodep);
|
||||
needNonStaticFunc(nodep);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstUCStmt* nodep) {
|
||||
needNonStaticFunc(nodep);
|
||||
visitStmt(nodep);
|
||||
needNonStaticFunc(nodep);
|
||||
visitStmt(nodep);
|
||||
}
|
||||
|
||||
//--------------------
|
||||
// Default: Just iterate
|
||||
virtual void visit(AstVar* nodep) {} // Don't hit varrefs under vars
|
||||
virtual void visit(AstVar* nodep) {} // Don't hit varrefs under vars
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
|
@ -157,12 +159,12 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit DepthVisitor(AstNetlist* nodep) {
|
||||
m_modp=NULL;
|
||||
m_funcp=NULL;
|
||||
m_stmtp=NULL;
|
||||
m_depth=0;
|
||||
m_maxdepth=0;
|
||||
//
|
||||
m_modp = NULL;
|
||||
m_funcp = NULL;
|
||||
m_stmtp = NULL;
|
||||
m_depth = 0;
|
||||
m_maxdepth = 0;
|
||||
//
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~DepthVisitor() {}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void depthAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@
|
|||
// V3DepthBlock's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// For each deep block, create cfunc including that block.
|
||||
// For each deep block, create cfunc including that block.
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -42,69 +42,69 @@ private:
|
|||
// NODE STATE
|
||||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_funcp; // Current function
|
||||
int m_depth; // How deep in an expression
|
||||
int m_deepNum; // How many functions made
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_funcp; // Current function
|
||||
int m_depth; // How deep in an expression
|
||||
int m_deepNum; // How many functions made
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
AstCFunc* createDeepFunc(AstNode* nodep) {
|
||||
AstNRelinker relinkHandle;
|
||||
nodep->unlinkFrBack(&relinkHandle);
|
||||
// Create function
|
||||
string name = m_funcp->name()+"__deep"+cvtToStr(++m_deepNum);
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), name, NULL);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->symProlog(true);
|
||||
funcp->slow(m_funcp->slow());
|
||||
funcp->addStmtsp(nodep);
|
||||
m_modp->addStmtp(funcp);
|
||||
// Call it at the point where the body was removed from
|
||||
AstCCall* callp = new AstCCall(nodep->fileline(), funcp);
|
||||
callp->argTypes("vlSymsp");
|
||||
UINFO(6," New "<<callp<<endl);
|
||||
//
|
||||
relinkHandle.relink(callp);
|
||||
return funcp;
|
||||
AstNRelinker relinkHandle;
|
||||
nodep->unlinkFrBack(&relinkHandle);
|
||||
// Create function
|
||||
string name = m_funcp->name()+"__deep"+cvtToStr(++m_deepNum);
|
||||
AstCFunc* funcp = new AstCFunc(nodep->fileline(), name, NULL);
|
||||
funcp->argTypes(EmitCBaseVisitor::symClassVar());
|
||||
funcp->symProlog(true);
|
||||
funcp->slow(m_funcp->slow());
|
||||
funcp->addStmtsp(nodep);
|
||||
m_modp->addStmtp(funcp);
|
||||
// Call it at the point where the body was removed from
|
||||
AstCCall* callp = new AstCCall(nodep->fileline(), funcp);
|
||||
callp->argTypes("vlSymsp");
|
||||
UINFO(6," New "<<callp<<endl);
|
||||
//
|
||||
relinkHandle.relink(callp);
|
||||
return funcp;
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
m_deepNum = 0;
|
||||
UINFO(4," MOD "<<nodep<<endl);
|
||||
m_modp = nodep;
|
||||
m_deepNum = 0;
|
||||
iterateChildren(nodep);
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
// We recurse into this.
|
||||
int lastDepth = m_depth;
|
||||
AstCFunc* lastFuncp = m_funcp;
|
||||
{
|
||||
m_depth = 0;
|
||||
m_funcp = nodep;
|
||||
// We recurse into this.
|
||||
int lastDepth = m_depth;
|
||||
AstCFunc* lastFuncp = m_funcp;
|
||||
{
|
||||
m_depth = 0;
|
||||
m_funcp = nodep;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
m_depth = lastDepth;
|
||||
m_funcp = lastFuncp;
|
||||
}
|
||||
m_depth = lastDepth;
|
||||
m_funcp = lastFuncp;
|
||||
}
|
||||
void visitStmt(AstNodeStmt* nodep) {
|
||||
m_depth++;
|
||||
if (m_depth > v3Global.opt.compLimitBlocks()
|
||||
m_depth++;
|
||||
if (m_depth > v3Global.opt.compLimitBlocks()
|
||||
&& !VN_IS(nodep, CCall)) { // Already done
|
||||
UINFO(4, "DeepBlocks "<<m_depth<<" "<<nodep<<endl);
|
||||
AstNode* backp = nodep->backp(); // Only for debug
|
||||
if (debug()>=9) backp->dumpTree(cout,"- pre : ");
|
||||
AstCFunc* funcp = createDeepFunc(nodep);
|
||||
UINFO(4, "DeepBlocks "<<m_depth<<" "<<nodep<<endl);
|
||||
AstNode* backp = nodep->backp(); // Only for debug
|
||||
if (debug()>=9) backp->dumpTree(cout, "- pre : ");
|
||||
AstCFunc* funcp = createDeepFunc(nodep);
|
||||
iterate(funcp);
|
||||
if (debug()>=9) backp->dumpTree(cout,"- post: ");
|
||||
if (debug()>=9) funcp->dumpTree(cout,"- func: ");
|
||||
} else {
|
||||
if (debug()>=9) backp->dumpTree(cout, "- post: ");
|
||||
if (debug()>=9) funcp->dumpTree(cout, "- func: ");
|
||||
} else {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
m_depth--;
|
||||
}
|
||||
m_depth--;
|
||||
}
|
||||
virtual void visit(AstNodeStmt* nodep) {
|
||||
if (!nodep->isStatement()) {
|
||||
|
|
@ -117,7 +117,7 @@ private:
|
|||
virtual void visit(AstNodeMath* nodep) {} // Accelerate
|
||||
//--------------------
|
||||
// Default: Just iterate
|
||||
virtual void visit(AstVar* nodep) {} // Don't hit varrefs under vars
|
||||
virtual void visit(AstVar* nodep) {} // Don't hit varrefs under vars
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
|
@ -129,7 +129,7 @@ public:
|
|||
m_funcp = NULL;
|
||||
m_depth = 0;
|
||||
m_deepNum = 0;
|
||||
//
|
||||
//
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~DepthBlockVisitor() {}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void depthBlockAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -18,11 +18,11 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// DESCOPE TRANSFORMATIONS:
|
||||
// All modules:
|
||||
// Each VARREF/FUNCCALL
|
||||
// Change varref name() to be relative to current module
|
||||
// Remove varScopep()
|
||||
// This allows for better V3Combine'ing.
|
||||
// All modules:
|
||||
// Each VARREF/FUNCCALL
|
||||
// Change varref name() to be relative to current module
|
||||
// Remove varScopep()
|
||||
// This allows for better V3Combine'ing.
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -43,19 +43,19 @@ class DescopeVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared entire netlist
|
||||
// AstCFunc::user() // bool. Indicates processing completed
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstCFunc::user() // bool. Indicates processing completed
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// TYPES
|
||||
typedef std::multimap<string,AstCFunc*> FuncMmap;
|
||||
typedef std::multimap<string,AstCFunc*> FuncMmap;
|
||||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstScope* m_scopep; // Current scope
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstScope* m_scopep; // Current scope
|
||||
bool m_modSingleton; // m_modp is only instanced once
|
||||
bool m_allowThis; // Allow function non-static
|
||||
bool m_needThis; // Make function non-static
|
||||
FuncMmap m_modFuncs; // Name of public functions added
|
||||
FuncMmap m_modFuncs; // Name of public functions added
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
|
@ -84,7 +84,7 @@ private:
|
|||
string descopedName(const AstScope* scopep, bool& hierThisr,
|
||||
const AstVar* varp=NULL) {
|
||||
UASSERT(scopep, "Var/Func not scoped");
|
||||
hierThisr = (scopep == m_scopep);
|
||||
hierThisr = (scopep == m_scopep);
|
||||
|
||||
// It's possible to disable relative references. This is a concession
|
||||
// to older compilers (gcc < 4.5.x) that don't understand __restrict__
|
||||
|
|
@ -119,9 +119,9 @@ private:
|
|||
relativeRefOk = false;
|
||||
}
|
||||
|
||||
if (varp && varp->isFuncLocal()) {
|
||||
if (varp && varp->isFuncLocal()) {
|
||||
hierThisr = true;
|
||||
return ""; // Relative to function, not in this
|
||||
return ""; // Relative to function, not in this
|
||||
} else if (relativeRefOk && scopep == m_scopep) {
|
||||
m_needThis = true;
|
||||
return "this->";
|
||||
|
|
@ -131,7 +131,7 @@ private:
|
|||
string name = scopep->name();
|
||||
string::size_type pos;
|
||||
if ((pos = name.rfind('.')) != string::npos) {
|
||||
name.erase(0,pos+1);
|
||||
name.erase(0, pos+1);
|
||||
}
|
||||
m_needThis = true;
|
||||
return name+"->";
|
||||
|
|
@ -141,7 +141,7 @@ private:
|
|||
UINFO(8," Descope "<<scopep<<endl);
|
||||
UINFO(8," to "<<scopep->name()<<endl);
|
||||
UINFO(8," under "<<m_scopep->name()<<endl);
|
||||
if (!scopep->aboveScopep()) { // Top
|
||||
if (!scopep->aboveScopep()) { // Top
|
||||
// We could also return "vlSymsp->TOPp->" here, but GCC would
|
||||
// suspect aliases.
|
||||
return "vlTOPp->";
|
||||
|
|
@ -152,41 +152,43 @@ private:
|
|||
}
|
||||
|
||||
void makePublicFuncWrappers() {
|
||||
// We recorded all public functions in m_modFuncs.
|
||||
// If for any given name only one function exists, we can use that function directly.
|
||||
// If multiple functions exist, we need to select the appropriate scope.
|
||||
for (FuncMmap::iterator it = m_modFuncs.begin(); it!=m_modFuncs.end(); ++it) {
|
||||
string name = it->first;
|
||||
AstCFunc* topFuncp = it->second;
|
||||
FuncMmap::iterator nextIt1 = it; ++nextIt1;
|
||||
bool moreOfSame1 = (nextIt1!=m_modFuncs.end() && nextIt1->first == name);
|
||||
if (moreOfSame1) {
|
||||
// Multiple functions under this name, need a wrapper function
|
||||
UINFO(6," Wrapping "<<name<<" multifuncs\n");
|
||||
AstCFunc* newfuncp = topFuncp->cloneTree(false);
|
||||
if (newfuncp->initsp()) newfuncp->initsp()->unlinkFrBackWithNext()->deleteTree();
|
||||
if (newfuncp->stmtsp()) newfuncp->stmtsp()->unlinkFrBackWithNext()->deleteTree();
|
||||
if (newfuncp->finalsp()) newfuncp->finalsp()->unlinkFrBackWithNext()->deleteTree();
|
||||
newfuncp->name(name);
|
||||
newfuncp->isStatic(false);
|
||||
newfuncp->addInitsp(
|
||||
new AstCStmt(newfuncp->fileline(),
|
||||
EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n"));
|
||||
newfuncp->addInitsp(new AstCStmt(newfuncp->fileline(), EmitCBaseVisitor::symTopAssign()+"\n"));
|
||||
topFuncp->addNextHere(newfuncp);
|
||||
// In the body, call each function if it matches the given scope
|
||||
for (FuncMmap::iterator eachIt = it; eachIt!=m_modFuncs.end() && eachIt->first==name; ++eachIt) {
|
||||
it = eachIt;
|
||||
AstCFunc* funcp = eachIt->second;
|
||||
FuncMmap::iterator nextIt2 = eachIt; ++nextIt2;
|
||||
bool moreOfSame = (nextIt2!=m_modFuncs.end() && nextIt2->first == name);
|
||||
if (!funcp->scopep()) funcp->v3fatalSrc("Not scoped");
|
||||
// We recorded all public functions in m_modFuncs.
|
||||
// If for any given name only one function exists, we can use that function directly.
|
||||
// If multiple functions exist, we need to select the appropriate scope.
|
||||
for (FuncMmap::iterator it = m_modFuncs.begin(); it!=m_modFuncs.end(); ++it) {
|
||||
string name = it->first;
|
||||
AstCFunc* topFuncp = it->second;
|
||||
FuncMmap::iterator nextIt1 = it; ++nextIt1;
|
||||
bool moreOfSame1 = (nextIt1!=m_modFuncs.end() && nextIt1->first == name);
|
||||
if (moreOfSame1) {
|
||||
// Multiple functions under this name, need a wrapper function
|
||||
UINFO(6," Wrapping "<<name<<" multifuncs\n");
|
||||
AstCFunc* newfuncp = topFuncp->cloneTree(false);
|
||||
if (newfuncp->initsp()) newfuncp->initsp()->unlinkFrBackWithNext()->deleteTree();
|
||||
if (newfuncp->stmtsp()) newfuncp->stmtsp()->unlinkFrBackWithNext()->deleteTree();
|
||||
if (newfuncp->finalsp()) newfuncp->finalsp()->unlinkFrBackWithNext()->deleteTree();
|
||||
newfuncp->name(name);
|
||||
newfuncp->isStatic(false);
|
||||
newfuncp->addInitsp(
|
||||
new AstCStmt(newfuncp->fileline(),
|
||||
EmitCBaseVisitor::symClassVar()+" = this->__VlSymsp;\n"));
|
||||
newfuncp->addInitsp(new AstCStmt(newfuncp->fileline(),
|
||||
EmitCBaseVisitor::symTopAssign()+"\n"));
|
||||
topFuncp->addNextHere(newfuncp);
|
||||
// In the body, call each function if it matches the given scope
|
||||
for (FuncMmap::iterator eachIt = it;
|
||||
eachIt != m_modFuncs.end() && eachIt->first==name; ++eachIt) {
|
||||
it = eachIt;
|
||||
AstCFunc* funcp = eachIt->second;
|
||||
FuncMmap::iterator nextIt2 = eachIt; ++nextIt2;
|
||||
bool moreOfSame = (nextIt2!=m_modFuncs.end() && nextIt2->first == name);
|
||||
if (!funcp->scopep()) funcp->v3fatalSrc("Not scoped");
|
||||
|
||||
UINFO(6," Wrapping "<<name<<" "<<funcp<<endl);
|
||||
UINFO(6," at "<<newfuncp->argTypes()<<" und "<<funcp->argTypes()<<endl);
|
||||
funcp->declPrivate(true);
|
||||
AstNode* argsp = NULL;
|
||||
for (AstNode* stmtp = newfuncp->argsp(); stmtp; stmtp=stmtp->nextp()) {
|
||||
UINFO(6," Wrapping "<<name<<" "<<funcp<<endl);
|
||||
UINFO(6," at "<<newfuncp->argTypes()<<" und "<<funcp->argTypes()<<endl);
|
||||
funcp->declPrivate(true);
|
||||
AstNode* argsp = NULL;
|
||||
for (AstNode* stmtp = newfuncp->argsp(); stmtp; stmtp=stmtp->nextp()) {
|
||||
if (AstVar* portp = VN_CAST(stmtp, Var)) {
|
||||
if (portp->isIO() && !portp->isFuncReturn()) {
|
||||
AstNode* newp = new AstVarRef(portp->fileline(),
|
||||
|
|
@ -201,7 +203,7 @@ private:
|
|||
new AstCCall(funcp->fileline(),
|
||||
funcp, argsp));
|
||||
|
||||
if (moreOfSame) {
|
||||
if (moreOfSame) {
|
||||
AstIf* ifp = new AstIf(funcp->fileline(),
|
||||
new AstEq(funcp->fileline(),
|
||||
new AstCMath(funcp->fileline(),
|
||||
|
|
@ -210,86 +212,89 @@ private:
|
|||
string("&(")
|
||||
+funcp->scopep()->nameVlSym()
|
||||
+")", 64)),
|
||||
returnp, NULL);
|
||||
newfuncp->addStmtsp(ifp);
|
||||
} else {
|
||||
newfuncp->addStmtsp(returnp);
|
||||
}
|
||||
}
|
||||
// Not really any way the user could do this, and we'd need to come up with some return value
|
||||
//newfuncp->addStmtsp(new AstDisplay (newfuncp->fileline(), AstDisplayType::DT_WARNING,
|
||||
// string("%%Error: ")+name+"() called with bad scope", NULL));
|
||||
//newfuncp->addStmtsp(new AstStop (newfuncp->fileline()));
|
||||
if (debug()>=9) newfuncp->dumpTree(cout," newfunc: ");
|
||||
} else {
|
||||
// Only a single function under this name, we can simply rename it
|
||||
UINFO(6," Wrapping "<<name<<" just one "<<topFuncp<<endl);
|
||||
topFuncp->name(name);
|
||||
}
|
||||
}
|
||||
returnp, NULL);
|
||||
newfuncp->addStmtsp(ifp);
|
||||
} else {
|
||||
newfuncp->addStmtsp(returnp);
|
||||
}
|
||||
}
|
||||
// Not really any way the user could do this, and we'd need
|
||||
// to come up with some return value
|
||||
//newfuncp->addStmtsp(new AstDisplay(newfuncp->fileline(),
|
||||
// AstDisplayType::DT_WARNING,
|
||||
// string("%%Error: ")+name+"() called with bad scope", NULL));
|
||||
//newfuncp->addStmtsp(new AstStop(newfuncp->fileline()));
|
||||
if (debug()>=9) newfuncp->dumpTree(cout, " newfunc: ");
|
||||
} else {
|
||||
// Only a single function under this name, we can simply rename it
|
||||
UINFO(6," Wrapping "<<name<<" just one "<<topFuncp<<endl);
|
||||
topFuncp->name(name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
m_modFuncs.clear();
|
||||
m_modp = nodep;
|
||||
m_modFuncs.clear();
|
||||
m_modSingleton = modIsSingleton(m_modp);
|
||||
iterateChildren(nodep);
|
||||
makePublicFuncWrappers();
|
||||
m_modp = NULL;
|
||||
makePublicFuncWrappers();
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstScope* nodep) {
|
||||
m_scopep = nodep;
|
||||
m_scopep = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_scopep = NULL;
|
||||
m_scopep = NULL;
|
||||
}
|
||||
virtual void visit(AstVarScope* nodep) {
|
||||
// Delete the varscope when we're finished
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep);
|
||||
// Delete the varscope when we're finished
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep);
|
||||
}
|
||||
virtual void visit(AstNodeVarRef* nodep) {
|
||||
iterateChildren(nodep);
|
||||
// Convert the hierch name
|
||||
if (!m_scopep) nodep->v3fatalSrc("Node not under scope");
|
||||
bool hierThis;
|
||||
nodep->hiername(descopedName(nodep->varScopep()->scopep(), hierThis/*ref*/, nodep->varScopep()->varp()));
|
||||
nodep->hierThis(hierThis);
|
||||
nodep->varScopep(NULL);
|
||||
// Convert the hierch name
|
||||
if (!m_scopep) nodep->v3fatalSrc("Node not under scope");
|
||||
bool hierThis;
|
||||
nodep->hiername(descopedName(nodep->varScopep()->scopep(), hierThis/*ref*/,
|
||||
nodep->varScopep()->varp()));
|
||||
nodep->hierThis(hierThis);
|
||||
nodep->varScopep(NULL);
|
||||
}
|
||||
virtual void visit(AstCCall* nodep) {
|
||||
//UINFO(9," "<<nodep<<endl);
|
||||
//UINFO(9," "<<nodep<<endl);
|
||||
iterateChildren(nodep);
|
||||
// Convert the hierch name
|
||||
if (!m_scopep) nodep->v3fatalSrc("Node not under scope");
|
||||
if (!nodep->funcp()->scopep()) nodep->v3fatalSrc("CFunc not under scope");
|
||||
bool hierThis;
|
||||
nodep->hiername(descopedName(nodep->funcp()->scopep(), hierThis/*ref*/));
|
||||
// Can't do this, as we may have more calls later
|
||||
// nodep->funcp()->scopep(NULL);
|
||||
// Convert the hierch name
|
||||
if (!m_scopep) nodep->v3fatalSrc("Node not under scope");
|
||||
if (!nodep->funcp()->scopep()) nodep->v3fatalSrc("CFunc not under scope");
|
||||
bool hierThis;
|
||||
nodep->hiername(descopedName(nodep->funcp()->scopep(), hierThis/*ref*/));
|
||||
// Can't do this, as we may have more calls later
|
||||
// nodep->funcp()->scopep(NULL);
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
if (!nodep->user1()) {
|
||||
m_needThis = false;
|
||||
if (!nodep->user1()) {
|
||||
m_needThis = false;
|
||||
m_allowThis = nodep->isStatic().falseU(); // Non-static or unknown if static
|
||||
iterateChildren(nodep);
|
||||
nodep->user1(true);
|
||||
if (m_needThis) {
|
||||
nodep->isStatic(false);
|
||||
}
|
||||
// If it's under a scope, move it up to the top
|
||||
if (m_scopep) {
|
||||
nodep->unlinkFrBack();
|
||||
m_modp->addStmtp(nodep);
|
||||
}
|
||||
// If it's under a scope, move it up to the top
|
||||
if (m_scopep) {
|
||||
nodep->unlinkFrBack();
|
||||
m_modp->addStmtp(nodep);
|
||||
|
||||
if (nodep->funcPublic()) {
|
||||
// There may be multiple public functions by the same name;
|
||||
// record for later correction or making of shells
|
||||
m_modFuncs.insert(make_pair(nodep->name(), nodep));
|
||||
nodep->name(m_scopep->nameDotless() +"__" + nodep->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (nodep->funcPublic()) {
|
||||
// There may be multiple public functions by the same name;
|
||||
// record for later correction or making of shells
|
||||
m_modFuncs.insert(make_pair(nodep->name(), nodep));
|
||||
nodep->name(m_scopep->nameDotless() +"__" + nodep->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstVar*) {}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void descopeAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
2757
src/V3EmitC.cpp
2757
src/V3EmitC.cpp
File diff suppressed because it is too large
Load Diff
|
|
@ -37,4 +37,4 @@ public:
|
|||
static void emitcTrace();
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -37,9 +37,9 @@
|
|||
class EmitCBaseVisitor : public AstNVisitor {
|
||||
public:
|
||||
// STATE
|
||||
V3OutCFile* m_ofp;
|
||||
V3OutCFile* m_ofp;
|
||||
// METHODS
|
||||
V3OutCFile* ofp() const { return m_ofp; }
|
||||
V3OutCFile* ofp() const { return m_ofp; }
|
||||
void puts(const string& str) { ofp()->puts(str); }
|
||||
void putbs(const string& str) { ofp()->putbs(str); }
|
||||
void putsDecoration(const string& str) { if (v3Global.opt.decoration()) puts(str); }
|
||||
|
|
@ -47,46 +47,47 @@ public:
|
|||
bool optSystemC() { return v3Global.opt.systemC(); }
|
||||
static string symClassName() { return v3Global.opt.prefix()+"__Syms"; }
|
||||
static string symClassVar() { return symClassName()+"* __restrict vlSymsp"; }
|
||||
static string symTopAssign() { return v3Global.opt.prefix()+"* __restrict vlTOPp VL_ATTR_UNUSED = vlSymsp->TOPp;"; }
|
||||
static string modClassName(AstNodeModule* modp) { // Return name of current module being processed
|
||||
if (modp->isTop()) {
|
||||
return v3Global.opt.prefix();
|
||||
} else {
|
||||
return v3Global.opt.modPrefix() + "_" + modp->name();
|
||||
}
|
||||
static string symTopAssign() {
|
||||
return v3Global.opt.prefix()+"* __restrict vlTOPp VL_ATTR_UNUSED = vlSymsp->TOPp;"; }
|
||||
static string modClassName(AstNodeModule* modp) { // Return name of current module being processed
|
||||
if (modp->isTop()) {
|
||||
return v3Global.opt.prefix();
|
||||
} else {
|
||||
return v3Global.opt.modPrefix() + "_" + modp->name();
|
||||
}
|
||||
}
|
||||
static string topClassName() { // Return name of top wrapper module
|
||||
return v3Global.opt.prefix();
|
||||
static string topClassName() { // Return name of top wrapper module
|
||||
return v3Global.opt.prefix();
|
||||
}
|
||||
static AstCFile* newCFile(const string& filename, bool slow, bool source) {
|
||||
AstCFile* cfilep = new AstCFile(v3Global.rootp()->fileline(), filename);
|
||||
cfilep->slow(slow);
|
||||
cfilep->source(source);
|
||||
v3Global.rootp()->addFilesp(cfilep);
|
||||
return cfilep;
|
||||
AstCFile* cfilep = new AstCFile(v3Global.rootp()->fileline(), filename);
|
||||
cfilep->slow(slow);
|
||||
cfilep->source(source);
|
||||
v3Global.rootp()->addFilesp(cfilep);
|
||||
return cfilep;
|
||||
}
|
||||
string cFuncArgs(const AstCFunc* nodep) {
|
||||
// Return argument list for given C function
|
||||
string args = nodep->argTypes();
|
||||
// Might be a user function with argument list.
|
||||
// Return argument list for given C function
|
||||
string args = nodep->argTypes();
|
||||
// Might be a user function with argument list.
|
||||
for (const AstNode* stmtp = nodep->argsp(); stmtp; stmtp=stmtp->nextp()) {
|
||||
if (const AstVar* portp = VN_CAST_CONST(stmtp, Var)) {
|
||||
if (portp->isIO() && !portp->isFuncReturn()) {
|
||||
if (args != "") args+= ", ";
|
||||
if (nodep->dpiImport() || nodep->dpiExportWrapper())
|
||||
args += portp->dpiArgType(true,false);
|
||||
else if (nodep->funcPublic())
|
||||
args += portp->cPubArgType(true,false);
|
||||
else args += portp->vlArgType(true,false,true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
if (portp->isIO() && !portp->isFuncReturn()) {
|
||||
if (args != "") args+= ", ";
|
||||
if (nodep->dpiImport() || nodep->dpiExportWrapper())
|
||||
args += portp->dpiArgType(true, false);
|
||||
else if (nodep->funcPublic())
|
||||
args += portp->cPubArgType(true, false);
|
||||
else args += portp->vlArgType(true, false, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
return args;
|
||||
}
|
||||
|
||||
// CONSTRUCTORS
|
||||
EmitCBaseVisitor() {
|
||||
m_ofp = NULL;
|
||||
m_ofp = NULL;
|
||||
}
|
||||
virtual ~EmitCBaseVisitor() {}
|
||||
};
|
||||
|
|
@ -96,21 +97,21 @@ public:
|
|||
|
||||
class EmitCBaseCounterVisitor : public AstNVisitor {
|
||||
private:
|
||||
// STATE
|
||||
int m_count; // Number of statements
|
||||
// MEMBERS
|
||||
int m_count; // Number of statements
|
||||
// VISITORS
|
||||
virtual void visit(AstNode* nodep) {
|
||||
m_count++;
|
||||
m_count++;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
explicit EmitCBaseCounterVisitor(AstNode* nodep) {
|
||||
m_count = 0;
|
||||
m_count = 0;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~EmitCBaseCounterVisitor() {}
|
||||
int count() const { return m_count; }
|
||||
};
|
||||
|
||||
#endif // guard
|
||||
#endif // guard
|
||||
|
|
|
|||
|
|
@ -84,7 +84,7 @@ void EmitCInlines::emitInt() {
|
|||
// Placeholder - v3Global.needHInlines(true) currently not used
|
||||
|
||||
puts("//======================\n\n");
|
||||
puts("#endif // guard\n");
|
||||
puts("#endif // guard\n");
|
||||
}
|
||||
|
||||
//######################################################################
|
||||
|
|
|
|||
|
|
@ -39,22 +39,24 @@
|
|||
class EmitCSyms : EmitCBaseVisitor {
|
||||
// NODE STATE
|
||||
// Cleared on Netlist
|
||||
// AstNodeModule::user1() -> bool. Set true __Vconfigure called
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstNodeModule::user1() -> bool. Set true __Vconfigure called
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// TYPES
|
||||
struct ScopeNameData { string m_symName; string m_prettyName;
|
||||
ScopeNameData(const string& symName, const string& prettyName)
|
||||
: m_symName(symName), m_prettyName(prettyName) {}
|
||||
ScopeNameData(const string& symName, const string& prettyName)
|
||||
: m_symName(symName), m_prettyName(prettyName) {}
|
||||
};
|
||||
struct ScopeFuncData { AstScopeName* m_scopep; AstCFunc* m_funcp; AstNodeModule* m_modp;
|
||||
ScopeFuncData(AstScopeName* scopep, AstCFunc* funcp, AstNodeModule* modp)
|
||||
: m_scopep(scopep), m_funcp(funcp), m_modp(modp) {}
|
||||
ScopeFuncData(AstScopeName* scopep, AstCFunc* funcp, AstNodeModule* modp)
|
||||
: m_scopep(scopep), m_funcp(funcp), m_modp(modp) {}
|
||||
};
|
||||
struct ScopeVarData { string m_scopeName; string m_varBasePretty; AstVar* m_varp;
|
||||
AstNodeModule* m_modp; AstScope* m_scopep;
|
||||
ScopeVarData(const string& scopeName, const string& varBasePretty, AstVar* varp, AstNodeModule* modp, AstScope* scopep)
|
||||
: m_scopeName(scopeName), m_varBasePretty(varBasePretty), m_varp(varp), m_modp(modp), m_scopep(scopep) {}
|
||||
AstNodeModule* m_modp; AstScope* m_scopep;
|
||||
ScopeVarData(const string& scopeName, const string& varBasePretty,
|
||||
AstVar* varp, AstNodeModule* modp, AstScope* scopep)
|
||||
: m_scopeName(scopeName), m_varBasePretty(varBasePretty)
|
||||
, m_varp(varp), m_modp(modp), m_scopep(scopep) {}
|
||||
};
|
||||
typedef std::map<string,ScopeFuncData> ScopeFuncs;
|
||||
typedef std::map<string,ScopeVarData> ScopeVars;
|
||||
|
|
@ -63,31 +65,31 @@ class EmitCSyms : EmitCBaseVisitor {
|
|||
typedef std::pair<AstNodeModule*,AstVar*> ModVarPair;
|
||||
struct CmpName {
|
||||
inline bool operator() (const ScopeModPair& lhsp, const ScopeModPair& rhsp) const {
|
||||
return lhsp.first->name() < rhsp.first->name();
|
||||
}
|
||||
return lhsp.first->name() < rhsp.first->name();
|
||||
}
|
||||
};
|
||||
struct CmpDpi {
|
||||
inline bool operator() (const AstCFunc* lhsp, const AstCFunc* rhsp) const {
|
||||
if (lhsp->dpiImport() != rhsp->dpiImport()) {
|
||||
// cppcheck-suppress comparisonOfFuncReturningBoolError
|
||||
return lhsp->dpiImport() < rhsp->dpiImport();
|
||||
}
|
||||
return lhsp->name() < rhsp->name();
|
||||
}
|
||||
if (lhsp->dpiImport() != rhsp->dpiImport()) {
|
||||
// cppcheck-suppress comparisonOfFuncReturningBoolError
|
||||
return lhsp->dpiImport() < rhsp->dpiImport();
|
||||
}
|
||||
return lhsp->name() < rhsp->name();
|
||||
}
|
||||
};
|
||||
|
||||
// STATE
|
||||
AstCFunc* m_funcp; // Current function
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCFunc* m_funcp; // Current function
|
||||
AstNodeModule* m_modp; // Current module
|
||||
std::vector<ScopeModPair> m_scopes; // Every scope by module
|
||||
std::vector<AstCFunc*> m_dpis; // DPI functions
|
||||
std::vector<ModVarPair> m_modVars; // Each public {mod,var}
|
||||
ScopeNames m_scopeNames; // Each unique AstScopeName
|
||||
ScopeFuncs m_scopeFuncs; // Each {scope,dpi-export-func}
|
||||
ScopeVars m_scopeVars; // Each {scope,public-var}
|
||||
V3LanguageWords m_words; // Reserved word detector
|
||||
int m_coverBins; // Coverage bin number
|
||||
int m_labelNum; // Next label number
|
||||
ScopeNames m_scopeNames; // Each unique AstScopeName
|
||||
ScopeFuncs m_scopeFuncs; // Each {scope,dpi-export-func}
|
||||
ScopeVars m_scopeVars; // Each {scope,public-var}
|
||||
V3LanguageWords m_words; // Reserved word detector
|
||||
int m_coverBins; // Coverage bin number
|
||||
int m_labelNum; // Next label number
|
||||
|
||||
// METHODS
|
||||
void emitSymHdr();
|
||||
|
|
@ -96,143 +98,151 @@ class EmitCSyms : EmitCBaseVisitor {
|
|||
void emitDpiImp();
|
||||
|
||||
void nameCheck(AstNode* nodep) {
|
||||
// Prevent GCC compile time error; name check all things that reach C++ code
|
||||
if (nodep->name() != "") {
|
||||
string rsvd = m_words.isKeyword(nodep->name());
|
||||
if (rsvd != "") {
|
||||
// Generally V3Name should find all of these and throw SYMRSVDWORD.
|
||||
// We'll still check here because the compiler errors resulting if we miss this warning are SO nasty
|
||||
// Prevent GCC compile time error; name check all things that reach C++ code
|
||||
if (nodep->name() != "") {
|
||||
string rsvd = m_words.isKeyword(nodep->name());
|
||||
if (rsvd != "") {
|
||||
// Generally V3Name should find all of these and throw SYMRSVDWORD.
|
||||
// We'll still check here because the compiler errors
|
||||
// resulting if we miss this warning are SO nasty
|
||||
nodep->v3error("Symbol matching "+rsvd+" reserved word reached emitter,"
|
||||
" should have hit SYMRSVDWORD: '"<<nodep->prettyName()<<"'");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void varsExpand() {
|
||||
// We didn'e have all m_scopes loaded when we encountered variables, so expand them now
|
||||
// It would be less code if each module inserted its own variables.
|
||||
// Someday. For now public isn't common.
|
||||
for (std::vector<ScopeModPair>::iterator itsc = m_scopes.begin(); itsc != m_scopes.end(); ++itsc) {
|
||||
AstScope* scopep = itsc->first; AstNodeModule* smodp = itsc->second;
|
||||
for (std::vector<ModVarPair>::iterator it = m_modVars.begin(); it != m_modVars.end(); ++it) {
|
||||
AstNodeModule* modp = it->first;
|
||||
AstVar* varp = it->second;
|
||||
if (modp == smodp) {
|
||||
// Need to split the module + var name into the original-ish full scope and variable name under that scope.
|
||||
// The module instance name is included later, when we know the scopes this module is under
|
||||
string whole = scopep->name()+"__DOT__"+varp->name();
|
||||
string scpName;
|
||||
string varBase;
|
||||
if (whole.substr(0,10) == "__DOT__TOP") whole.replace(0,10,"");
|
||||
string::size_type dpos = whole.rfind("__DOT__");
|
||||
if (dpos != string::npos) {
|
||||
scpName = whole.substr(0,dpos);
|
||||
varBase = whole.substr(dpos+strlen("__DOT__"));
|
||||
} else {
|
||||
varBase = whole;
|
||||
}
|
||||
//UINFO(9,"For "<<scopep->name()<<" - "<<varp->name()<<" Scp "<<scpName<<" Var "<<varBase<<endl);
|
||||
string varBasePretty = AstNode::prettyName(varBase);
|
||||
string scpPretty = AstNode::prettyName(scpName);
|
||||
string scpSym;
|
||||
{
|
||||
string out = scpName;
|
||||
string::size_type pos;
|
||||
while ((pos=out.find("__PVT__")) != string::npos) {
|
||||
out.replace(pos, 7, "");
|
||||
}
|
||||
if (out.substr(0,10) == "TOP__DOT__") out.replace(0,10,"");
|
||||
if (out.substr(0,4) == "TOP.") out.replace(0,4,"");
|
||||
// We didn'e have all m_scopes loaded when we encountered variables, so expand them now
|
||||
// It would be less code if each module inserted its own variables.
|
||||
// Someday. For now public isn't common.
|
||||
for (std::vector<ScopeModPair>::iterator itsc = m_scopes.begin();
|
||||
itsc != m_scopes.end(); ++itsc) {
|
||||
AstScope* scopep = itsc->first; AstNodeModule* smodp = itsc->second;
|
||||
for (std::vector<ModVarPair>::iterator it = m_modVars.begin();
|
||||
it != m_modVars.end(); ++it) {
|
||||
AstNodeModule* modp = it->first;
|
||||
AstVar* varp = it->second;
|
||||
if (modp == smodp) {
|
||||
// Need to split the module + var name into the
|
||||
// original-ish full scope and variable name under that scope.
|
||||
// The module instance name is included later, when we
|
||||
// know the scopes this module is under
|
||||
string whole = scopep->name()+"__DOT__"+varp->name();
|
||||
string scpName;
|
||||
string varBase;
|
||||
if (whole.substr(0, 10) == "__DOT__TOP") whole.replace(0, 10, "");
|
||||
string::size_type dpos = whole.rfind("__DOT__");
|
||||
if (dpos != string::npos) {
|
||||
scpName = whole.substr(0, dpos);
|
||||
varBase = whole.substr(dpos+strlen("__DOT__"));
|
||||
} else {
|
||||
varBase = whole;
|
||||
}
|
||||
//UINFO(9,"For "<<scopep->name()<<" - "<<varp->name()<<" Scp "<<scpName<<" Var "<<varBase<<endl);
|
||||
string varBasePretty = AstNode::prettyName(varBase);
|
||||
string scpPretty = AstNode::prettyName(scpName);
|
||||
string scpSym;
|
||||
{
|
||||
string out = scpName;
|
||||
string::size_type pos;
|
||||
while ((pos = out.find("__PVT__")) != string::npos) {
|
||||
out.replace(pos, 7, "");
|
||||
}
|
||||
if (out.substr(0, 10) == "TOP__DOT__") out.replace(0, 10, "");
|
||||
if (out.substr(0, 4) == "TOP.") out.replace(0, 4, "");
|
||||
while ((pos = out.find('.')) != string::npos) {
|
||||
out.replace(pos, 1, "__");
|
||||
}
|
||||
while ((pos=out.find("__DOT__")) != string::npos) {
|
||||
out.replace(pos, 7, "__");
|
||||
}
|
||||
scpSym = out;
|
||||
}
|
||||
//UINFO(9," scnameins sp "<<scpName<<" sp "<<scpPretty<<" ss "<<scpSym<<endl);
|
||||
if (m_scopeNames.find(scpSym) == m_scopeNames.end()) {
|
||||
m_scopeNames.insert(make_pair(scpSym, ScopeNameData(scpSym, scpPretty)));
|
||||
}
|
||||
m_scopeVars.insert(make_pair(scpSym + " " + varp->name(),
|
||||
ScopeVarData(scpSym, varBasePretty, varp, modp, scopep)));
|
||||
}
|
||||
}
|
||||
}
|
||||
out.replace(pos, 1, "__");
|
||||
}
|
||||
while ((pos = out.find("__DOT__")) != string::npos) {
|
||||
out.replace(pos, 7, "__");
|
||||
}
|
||||
scpSym = out;
|
||||
}
|
||||
//UINFO(9," scnameins sp "<<scpName<<" sp "<<scpPretty<<" ss "<<scpSym<<endl);
|
||||
if (m_scopeNames.find(scpSym) == m_scopeNames.end()) {
|
||||
m_scopeNames.insert(make_pair(scpSym, ScopeNameData(scpSym, scpPretty)));
|
||||
}
|
||||
m_scopeVars.insert(
|
||||
make_pair(scpSym + " " + varp->name(),
|
||||
ScopeVarData(scpSym, varBasePretty, varp, modp, scopep)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNetlist* nodep) {
|
||||
// Collect list of scopes
|
||||
// Collect list of scopes
|
||||
iterateChildren(nodep);
|
||||
varsExpand();
|
||||
varsExpand();
|
||||
|
||||
// Sort by names, so line/process order matters less
|
||||
stable_sort(m_scopes.begin(), m_scopes.end(), CmpName());
|
||||
stable_sort(m_dpis.begin(), m_dpis.end(), CmpDpi());
|
||||
// Sort by names, so line/process order matters less
|
||||
stable_sort(m_scopes.begin(), m_scopes.end(), CmpName());
|
||||
stable_sort(m_dpis.begin(), m_dpis.end(), CmpDpi());
|
||||
|
||||
// Output
|
||||
emitSymHdr();
|
||||
emitSymImp();
|
||||
if (v3Global.dpi()) {
|
||||
emitDpiHdr();
|
||||
emitDpiImp();
|
||||
}
|
||||
// Output
|
||||
emitSymHdr();
|
||||
emitSymImp();
|
||||
if (v3Global.dpi()) {
|
||||
emitDpiHdr();
|
||||
emitDpiImp();
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
nameCheck(nodep);
|
||||
m_modp = nodep;
|
||||
m_labelNum = 0;
|
||||
nameCheck(nodep);
|
||||
m_modp = nodep;
|
||||
m_labelNum = 0;
|
||||
iterateChildren(nodep);
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstScope* nodep) {
|
||||
nameCheck(nodep);
|
||||
m_scopes.push_back(make_pair(nodep, m_modp));
|
||||
nameCheck(nodep);
|
||||
m_scopes.push_back(make_pair(nodep, m_modp));
|
||||
}
|
||||
virtual void visit(AstScopeName* nodep) {
|
||||
string name = nodep->scopeSymName();
|
||||
//UINFO(9,"scnameins sp "<<nodep->name()<<" sp "<<nodep->scopePrettySymName()<<" ss "<<name<<endl);
|
||||
if (m_scopeNames.find(name) == m_scopeNames.end()) {
|
||||
m_scopeNames.insert(make_pair(name, ScopeNameData(name, nodep->scopePrettySymName())));
|
||||
}
|
||||
if (nodep->dpiExport()) {
|
||||
if (!m_funcp) nodep->v3fatalSrc("ScopeName not under DPI function");
|
||||
m_scopeFuncs.insert(make_pair(name + " " + m_funcp->name(),
|
||||
ScopeFuncData(nodep, m_funcp, m_modp)));
|
||||
} else {
|
||||
if (m_scopeNames.find(nodep->scopeDpiName()) == m_scopeNames.end()) {
|
||||
m_scopeNames.insert(make_pair(nodep->scopeDpiName(), ScopeNameData(nodep->scopeDpiName(), nodep->scopePrettyDpiName())));
|
||||
}
|
||||
}
|
||||
string name = nodep->scopeSymName();
|
||||
//UINFO(9,"scnameins sp "<<nodep->name()<<" sp "<<nodep->scopePrettySymName()<<" ss "<<name<<endl);
|
||||
if (m_scopeNames.find(name) == m_scopeNames.end()) {
|
||||
m_scopeNames.insert(make_pair(name, ScopeNameData(name, nodep->scopePrettySymName())));
|
||||
}
|
||||
if (nodep->dpiExport()) {
|
||||
if (!m_funcp) nodep->v3fatalSrc("ScopeName not under DPI function");
|
||||
m_scopeFuncs.insert(make_pair(name + " " + m_funcp->name(),
|
||||
ScopeFuncData(nodep, m_funcp, m_modp)));
|
||||
} else {
|
||||
if (m_scopeNames.find(nodep->scopeDpiName()) == m_scopeNames.end()) {
|
||||
m_scopeNames.insert(make_pair(nodep->scopeDpiName(),
|
||||
ScopeNameData(nodep->scopeDpiName(),
|
||||
nodep->scopePrettyDpiName())));
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstVar* nodep) {
|
||||
nameCheck(nodep);
|
||||
nameCheck(nodep);
|
||||
iterateChildren(nodep);
|
||||
if (nodep->isSigUserRdPublic()
|
||||
&& !nodep->isParam()) { // The VPI functions require a pointer to allow modification, but parameters are constants
|
||||
m_modVars.push_back(make_pair(m_modp, nodep));
|
||||
}
|
||||
if (nodep->isSigUserRdPublic()
|
||||
&& !nodep->isParam()) { // The VPI functions require a pointer to allow modification, but parameters are constants
|
||||
m_modVars.push_back(make_pair(m_modp, nodep));
|
||||
}
|
||||
}
|
||||
virtual void visit(AstCoverDecl* nodep) {
|
||||
// Assign numbers to all bins, so we know how big of an array to use
|
||||
if (!nodep->dataDeclNullp()) { // else duplicate we don't need code for
|
||||
nodep->binNum(m_coverBins++);
|
||||
}
|
||||
// Assign numbers to all bins, so we know how big of an array to use
|
||||
if (!nodep->dataDeclNullp()) { // else duplicate we don't need code for
|
||||
nodep->binNum(m_coverBins++);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstJumpLabel* nodep) {
|
||||
nodep->labelNum(++m_labelNum);
|
||||
nodep->labelNum(++m_labelNum);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
nameCheck(nodep);
|
||||
if (nodep->dpiImport() || nodep->dpiExportWrapper()) {
|
||||
m_dpis.push_back(nodep);
|
||||
}
|
||||
m_funcp = nodep;
|
||||
nameCheck(nodep);
|
||||
if (nodep->dpiImport() || nodep->dpiExportWrapper()) {
|
||||
m_dpis.push_back(nodep);
|
||||
}
|
||||
m_funcp = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_funcp = NULL;
|
||||
m_funcp = NULL;
|
||||
}
|
||||
// NOPs
|
||||
virtual void visit(AstConst*) {}
|
||||
|
|
@ -244,10 +254,10 @@ class EmitCSyms : EmitCBaseVisitor {
|
|||
// ACCESSORS
|
||||
public:
|
||||
explicit EmitCSyms(AstNetlist* nodep) {
|
||||
m_funcp = NULL;
|
||||
m_modp = NULL;
|
||||
m_coverBins = 0;
|
||||
m_labelNum = 0;
|
||||
m_funcp = NULL;
|
||||
m_modp = NULL;
|
||||
m_coverBins = 0;
|
||||
m_labelNum = 0;
|
||||
iterate(nodep);
|
||||
}
|
||||
};
|
||||
|
|
@ -271,30 +281,31 @@ void EmitCSyms::emitSymHdr() {
|
|||
|
||||
ofp()->putsIntTopInclude();
|
||||
if (v3Global.needHeavy()) {
|
||||
puts("#include \"verilated_heavy.h\"\n");
|
||||
puts("#include \"verilated_heavy.h\"\n");
|
||||
} else {
|
||||
puts("#include \"verilated.h\"\n");
|
||||
puts("#include \"verilated.h\"\n");
|
||||
}
|
||||
|
||||
// for
|
||||
puts("\n// INCLUDE MODULE CLASSES\n");
|
||||
for (AstNodeModule* nodep = v3Global.rootp()->modulesp(); nodep; nodep=VN_CAST(nodep->nextp(), NodeModule)) {
|
||||
puts("#include \""+modClassName(nodep)+".h\"\n");
|
||||
for (AstNodeModule* nodep = v3Global.rootp()->modulesp();
|
||||
nodep; nodep=VN_CAST(nodep->nextp(), NodeModule)) {
|
||||
puts("#include \""+modClassName(nodep)+".h\"\n");
|
||||
}
|
||||
|
||||
if (v3Global.dpi()) {
|
||||
puts("\n// DPI TYPES for DPI Export callbacks (Internal use)\n");
|
||||
std::map<string,int> types; // Remove duplicates and sort
|
||||
for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
|
||||
AstCFunc* funcp = it->second.m_funcp;
|
||||
if (funcp->dpiExport()) {
|
||||
string cbtype = v3Global.opt.prefix()+"__Vcb_"+funcp->cname()+"_t";
|
||||
types["typedef void (*"+cbtype+") ("+cFuncArgs(funcp)+");\n"] = 1;
|
||||
}
|
||||
}
|
||||
for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
|
||||
AstCFunc* funcp = it->second.m_funcp;
|
||||
if (funcp->dpiExport()) {
|
||||
string cbtype = v3Global.opt.prefix()+"__Vcb_"+funcp->cname()+"_t";
|
||||
types["typedef void (*"+cbtype+") ("+cFuncArgs(funcp)+");\n"] = 1;
|
||||
}
|
||||
}
|
||||
for (std::map<string,int>::iterator it = types.begin(); it != types.end(); ++it) {
|
||||
puts(it->first);
|
||||
}
|
||||
puts(it->first);
|
||||
}
|
||||
}
|
||||
|
||||
puts("\n// SYMS CLASS\n");
|
||||
|
|
@ -302,39 +313,39 @@ void EmitCSyms::emitSymHdr() {
|
|||
ofp()->putsPrivate(false); // public:
|
||||
|
||||
puts("\n// LOCAL STATE\n");
|
||||
puts("const char* __Vm_namep;\n"); // Must be before subcells, as constructor order needed before _vlCoverInsert.
|
||||
puts("const char* __Vm_namep;\n"); // Must be before subcells, as constructor order needed before _vlCoverInsert.
|
||||
if (v3Global.opt.trace()) {
|
||||
puts("bool __Vm_activity; ///< Used by trace routines to determine change occurred\n");
|
||||
puts("bool __Vm_activity; ///< Used by trace routines to determine change occurred\n");
|
||||
}
|
||||
puts("bool __Vm_didInit;\n");
|
||||
|
||||
puts("\n// SUBCELL STATE\n");
|
||||
for (std::vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (modp->isTop()) {
|
||||
ofp()->printf("%-30s ", (modClassName(modp)+"*").c_str());
|
||||
puts(scopep->nameDotless()+"p;\n");
|
||||
}
|
||||
else {
|
||||
ofp()->printf("%-30s ", (modClassName(modp)+"").c_str());
|
||||
puts(scopep->nameDotless()+";\n");
|
||||
}
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (modp->isTop()) {
|
||||
ofp()->printf("%-30s ", (modClassName(modp)+"*").c_str());
|
||||
puts(scopep->nameDotless()+"p;\n");
|
||||
}
|
||||
else {
|
||||
ofp()->printf("%-30s ", (modClassName(modp)+"").c_str());
|
||||
puts(scopep->nameDotless()+";\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (m_coverBins) {
|
||||
puts("\n// COVERAGE\n");
|
||||
puts("uint32_t __Vcoverage["); puts(cvtToStr(m_coverBins)); puts("];\n");
|
||||
puts("\n// COVERAGE\n");
|
||||
puts("uint32_t __Vcoverage["); puts(cvtToStr(m_coverBins)); puts("];\n");
|
||||
}
|
||||
|
||||
{ // Scope names
|
||||
bool did = false;
|
||||
for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
|
||||
if (!did) {
|
||||
did = true;
|
||||
puts("\n// SCOPE NAMES\n");
|
||||
}
|
||||
puts("VerilatedScope __Vscope_"+it->second.m_symName+";\n");
|
||||
}
|
||||
bool did = false;
|
||||
for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
|
||||
if (!did) {
|
||||
did = true;
|
||||
puts("\n// SCOPE NAMES\n");
|
||||
}
|
||||
puts("VerilatedScope __Vscope_"+it->second.m_symName+";\n");
|
||||
}
|
||||
}
|
||||
|
||||
puts("\n// CREATORS\n");
|
||||
|
|
@ -344,16 +355,16 @@ void EmitCSyms::emitSymHdr() {
|
|||
puts("\n// METHODS\n");
|
||||
puts("inline const char* name() { return __Vm_namep; }\n");
|
||||
if (v3Global.opt.trace()) {
|
||||
puts("inline bool getClearActivity() { bool r=__Vm_activity; __Vm_activity=false; return r; }\n");
|
||||
puts("inline bool getClearActivity() { bool r=__Vm_activity; __Vm_activity=false; return r; }\n");
|
||||
}
|
||||
if (v3Global.opt.savable() ) {
|
||||
puts("void __Vserialize(VerilatedSerialize& os);\n");
|
||||
puts("void __Vdeserialize(VerilatedDeserialize& os);\n");
|
||||
puts("void __Vserialize(VerilatedSerialize& os);\n");
|
||||
puts("void __Vdeserialize(VerilatedDeserialize& os);\n");
|
||||
}
|
||||
puts("\n");
|
||||
puts("} VL_ATTR_ALIGNED(64);\n");
|
||||
puts("\n");
|
||||
puts("#endif // guard\n");
|
||||
puts("#endif // guard\n");
|
||||
}
|
||||
|
||||
void EmitCSyms::emitSymImp() {
|
||||
|
|
@ -369,8 +380,9 @@ void EmitCSyms::emitSymImp() {
|
|||
|
||||
// Includes
|
||||
puts("#include \""+symClassName()+".h\"\n");
|
||||
for (AstNodeModule* nodep = v3Global.rootp()->modulesp(); nodep; nodep=VN_CAST(nodep->nextp(), NodeModule)) {
|
||||
puts("#include \""+modClassName(nodep)+".h\"\n");
|
||||
for (AstNodeModule* nodep = v3Global.rootp()->modulesp();
|
||||
nodep; nodep=VN_CAST(nodep->nextp(), NodeModule)) {
|
||||
puts("#include \""+modClassName(nodep)+".h\"\n");
|
||||
}
|
||||
|
||||
//puts("\n// GLOBALS\n");
|
||||
|
|
@ -378,25 +390,25 @@ void EmitCSyms::emitSymImp() {
|
|||
puts("\n// FUNCTIONS\n");
|
||||
puts(symClassName()+"::"+symClassName()+"("+topClassName()+"* topp, const char* namep)\n");
|
||||
puts("\t// Setup locals\n");
|
||||
puts("\t: __Vm_namep(namep)\n"); // No leak, as we get destroyed when the top is destroyed
|
||||
puts("\t: __Vm_namep(namep)\n"); // No leak, as we get destroyed when the top is destroyed
|
||||
if (v3Global.opt.trace()) {
|
||||
puts("\t, __Vm_activity(false)\n");
|
||||
puts("\t, __Vm_activity(false)\n");
|
||||
}
|
||||
puts("\t, __Vm_didInit(false)\n");
|
||||
puts("\t// Setup submodule names\n");
|
||||
char comma=',';
|
||||
for (std::vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (modp->isTop()) {
|
||||
} else {
|
||||
string nameDl = scopep->nameDotless();
|
||||
ofp()->printf("\t%c %-30s ", comma, nameDl.c_str());
|
||||
puts("(Verilated::catName(topp->name(),");
|
||||
// The "." is added by catName
|
||||
putsQuoted(scopep->prettyName());
|
||||
puts("))\n");
|
||||
comma=',';
|
||||
}
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (modp->isTop()) {
|
||||
} else {
|
||||
string nameDl = scopep->nameDotless();
|
||||
ofp()->printf("\t%c %-30s ", comma, nameDl.c_str());
|
||||
puts("(Verilated::catName(topp->name(),");
|
||||
// The "." is added by catName
|
||||
putsQuoted(scopep->prettyName());
|
||||
puts("))\n");
|
||||
comma=',';
|
||||
}
|
||||
}
|
||||
puts("{\n");
|
||||
|
||||
|
|
@ -404,144 +416,145 @@ void EmitCSyms::emitSymImp() {
|
|||
puts("TOPp = topp;\n");
|
||||
puts("// Setup each module's pointers to their submodules\n");
|
||||
for (std::vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (!modp->isTop()) {
|
||||
string arrow = scopep->name();
|
||||
string::size_type pos;
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (!modp->isTop()) {
|
||||
string arrow = scopep->name();
|
||||
string::size_type pos;
|
||||
while ((pos = arrow.find('.')) != string::npos) {
|
||||
arrow.replace(pos, 1, "->");
|
||||
}
|
||||
if (arrow.substr(0,5) == "TOP->") arrow.replace(0,5,"TOPp->");
|
||||
ofp()->printf("%-30s ", arrow.c_str());
|
||||
puts(" = &");
|
||||
puts(scopep->nameDotless()+";\n");
|
||||
}
|
||||
arrow.replace(pos, 1, "->");
|
||||
}
|
||||
if (arrow.substr(0, 5) == "TOP->") arrow.replace(0, 5, "TOPp->");
|
||||
ofp()->printf("%-30s ", arrow.c_str());
|
||||
puts(" = &");
|
||||
puts(scopep->nameDotless()+";\n");
|
||||
}
|
||||
}
|
||||
|
||||
puts("// Setup each module's pointer back to symbol table (for public functions)\n");
|
||||
puts("TOPp->__Vconfigure(this, true);\n");
|
||||
for (std::vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (!modp->isTop()) {
|
||||
// first is used by AstCoverDecl's call to __vlCoverInsert
|
||||
bool first = !modp->user1();
|
||||
modp->user1(true);
|
||||
puts(scopep->nameDotless()+".__Vconfigure(this, "
|
||||
+(first?"true":"false")
|
||||
+");\n");
|
||||
}
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (!modp->isTop()) {
|
||||
// first is used by AstCoverDecl's call to __vlCoverInsert
|
||||
bool first = !modp->user1();
|
||||
modp->user1(true);
|
||||
puts(scopep->nameDotless()+".__Vconfigure(this, "
|
||||
+(first?"true":"false")
|
||||
+");\n");
|
||||
}
|
||||
}
|
||||
|
||||
{ // Setup scope names
|
||||
bool did = false;
|
||||
for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
|
||||
if (!did) {
|
||||
did = true;
|
||||
puts("// Setup scope names\n");
|
||||
}
|
||||
puts("__Vscope_"+it->second.m_symName+".configure(this,name(),");
|
||||
putsQuoted(it->second.m_prettyName);
|
||||
puts(");\n");
|
||||
}
|
||||
bool did = false;
|
||||
for (ScopeNames::iterator it = m_scopeNames.begin(); it != m_scopeNames.end(); ++it) {
|
||||
if (!did) {
|
||||
did = true;
|
||||
puts("// Setup scope names\n");
|
||||
}
|
||||
puts("__Vscope_"+it->second.m_symName+".configure(this,name(),");
|
||||
putsQuoted(it->second.m_prettyName);
|
||||
puts(");\n");
|
||||
}
|
||||
}
|
||||
|
||||
if (v3Global.dpi()) {
|
||||
puts("// Setup export functions\n");
|
||||
puts("for (int __Vfinal=0; __Vfinal<2; __Vfinal++) {\n");
|
||||
for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
|
||||
AstScopeName* scopep = it->second.m_scopep;
|
||||
AstCFunc* funcp = it->second.m_funcp;
|
||||
AstNodeModule* modp = it->second.m_modp;
|
||||
if (funcp->dpiExport()) {
|
||||
puts("__Vscope_"+scopep->scopeSymName()+".exportInsert(__Vfinal,");
|
||||
putsQuoted(funcp->cname());
|
||||
puts(", (void*)(&");
|
||||
puts(modClassName(modp));
|
||||
puts("::");
|
||||
puts(funcp->name());
|
||||
puts("));\n");
|
||||
}
|
||||
}
|
||||
// It would be less code if each module inserted its own variables.
|
||||
// Someday. For now public isn't common.
|
||||
for (ScopeVars::iterator it = m_scopeVars.begin(); it != m_scopeVars.end(); ++it) {
|
||||
AstNodeModule* modp = it->second.m_modp;
|
||||
AstScope* scopep = it->second.m_scopep;
|
||||
AstVar* varp = it->second.m_varp;
|
||||
//
|
||||
int pdim=0;
|
||||
int udim=0;
|
||||
string bounds;
|
||||
if (AstBasicDType* basicp = varp->basicp()) {
|
||||
// Range is always first, it's not in "C" order
|
||||
if (basicp->isRanged()) {
|
||||
bounds += " ,"; bounds += cvtToStr(basicp->msb());
|
||||
bounds += ","; bounds += cvtToStr(basicp->lsb());
|
||||
pdim++;
|
||||
}
|
||||
for (AstNodeDType* dtypep=varp->dtypep(); dtypep; ) {
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
puts("// Setup export functions\n");
|
||||
puts("for (int __Vfinal=0; __Vfinal<2; __Vfinal++) {\n");
|
||||
for (ScopeFuncs::iterator it = m_scopeFuncs.begin(); it != m_scopeFuncs.end(); ++it) {
|
||||
AstScopeName* scopep = it->second.m_scopep;
|
||||
AstCFunc* funcp = it->second.m_funcp;
|
||||
AstNodeModule* modp = it->second.m_modp;
|
||||
if (funcp->dpiExport()) {
|
||||
puts("__Vscope_"+scopep->scopeSymName()+".exportInsert(__Vfinal,");
|
||||
putsQuoted(funcp->cname());
|
||||
puts(", (void*)(&");
|
||||
puts(modClassName(modp));
|
||||
puts("::");
|
||||
puts(funcp->name());
|
||||
puts("));\n");
|
||||
}
|
||||
}
|
||||
// It would be less code if each module inserted its own variables.
|
||||
// Someday. For now public isn't common.
|
||||
for (ScopeVars::iterator it = m_scopeVars.begin(); it != m_scopeVars.end(); ++it) {
|
||||
AstNodeModule* modp = it->second.m_modp;
|
||||
AstScope* scopep = it->second.m_scopep;
|
||||
AstVar* varp = it->second.m_varp;
|
||||
//
|
||||
int pdim = 0;
|
||||
int udim = 0;
|
||||
string bounds;
|
||||
if (AstBasicDType* basicp = varp->basicp()) {
|
||||
// Range is always first, it's not in "C" order
|
||||
if (basicp->isRanged()) {
|
||||
bounds += " ,"; bounds += cvtToStr(basicp->msb());
|
||||
bounds += ","; bounds += cvtToStr(basicp->lsb());
|
||||
pdim++;
|
||||
}
|
||||
for (AstNodeDType* dtypep = varp->dtypep(); dtypep; ) {
|
||||
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
|
||||
if (const AstNodeArrayDType* adtypep = VN_CAST(dtypep, NodeArrayDType)) {
|
||||
bounds += " ,"; bounds += cvtToStr(adtypep->msb());
|
||||
bounds += ","; bounds += cvtToStr(adtypep->lsb());
|
||||
bounds += " ,"; bounds += cvtToStr(adtypep->msb());
|
||||
bounds += ","; bounds += cvtToStr(adtypep->lsb());
|
||||
if (VN_IS(dtypep, PackArrayDType)) pdim++; else udim++;
|
||||
dtypep = adtypep->subDTypep();
|
||||
}
|
||||
else break; // AstBasicDType - nothing below, 1
|
||||
}
|
||||
}
|
||||
//
|
||||
if (pdim>1 || udim>1) {
|
||||
puts("//UNSUP "); // VerilatedImp can't deal with >2d or packed arrays
|
||||
}
|
||||
puts("__Vscope_"+it->second.m_scopeName+".varInsert(__Vfinal,");
|
||||
putsQuoted(it->second.m_varBasePretty);
|
||||
puts(", &(");
|
||||
if (modp->isTop()) {
|
||||
puts(scopep->nameDotless());
|
||||
puts("p->");
|
||||
} else {
|
||||
puts(scopep->nameDotless());
|
||||
puts(".");
|
||||
}
|
||||
puts(varp->name());
|
||||
puts("), ");
|
||||
puts(varp->vlEnumType()); // VLVT_UINT32 etc
|
||||
puts(",");
|
||||
puts(varp->vlEnumDir()); // VLVD_IN etc
|
||||
puts(",");
|
||||
puts(cvtToStr(pdim+udim));
|
||||
puts(bounds);
|
||||
puts(");\n");
|
||||
}
|
||||
puts("}\n");
|
||||
dtypep = adtypep->subDTypep();
|
||||
}
|
||||
else break; // AstBasicDType - nothing below, 1
|
||||
}
|
||||
}
|
||||
//
|
||||
if (pdim>1 || udim>1) {
|
||||
puts("//UNSUP "); // VerilatedImp can't deal with >2d or packed arrays
|
||||
}
|
||||
puts("__Vscope_"+it->second.m_scopeName+".varInsert(__Vfinal,");
|
||||
putsQuoted(it->second.m_varBasePretty);
|
||||
puts(", &(");
|
||||
if (modp->isTop()) {
|
||||
puts(scopep->nameDotless());
|
||||
puts("p->");
|
||||
} else {
|
||||
puts(scopep->nameDotless());
|
||||
puts(".");
|
||||
}
|
||||
puts(varp->name());
|
||||
puts("), ");
|
||||
puts(varp->vlEnumType()); // VLVT_UINT32 etc
|
||||
puts(",");
|
||||
puts(varp->vlEnumDir()); // VLVD_IN etc
|
||||
puts(",");
|
||||
puts(cvtToStr(pdim+udim));
|
||||
puts(bounds);
|
||||
puts(");\n");
|
||||
}
|
||||
puts("}\n");
|
||||
}
|
||||
|
||||
puts("}\n");
|
||||
|
||||
if (v3Global.opt.savable() ) {
|
||||
puts("\n");
|
||||
for (int de=0; de<2; ++de) {
|
||||
string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize";
|
||||
string funcname = de ? "__Vdeserialize" : "__Vserialize";
|
||||
string op = de ? ">>" : "<<";
|
||||
puts("\n");
|
||||
for (int de=0; de<2; ++de) {
|
||||
string classname = de ? "VerilatedDeserialize" : "VerilatedSerialize";
|
||||
string funcname = de ? "__Vdeserialize" : "__Vserialize";
|
||||
string op = de ? ">>" : "<<";
|
||||
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
|
||||
puts("void "+symClassName()+"::"+funcname+"("+classname+"& os) {\n");
|
||||
puts( "// LOCAL STATE\n");
|
||||
// __Vm_namep presumably already correct
|
||||
if (v3Global.opt.trace()) {
|
||||
puts( "os"+op+"__Vm_activity;\n");
|
||||
}
|
||||
puts( "os"+op+"__Vm_didInit;\n");
|
||||
puts( "// SUBCELL STATE\n");
|
||||
for (std::vector<ScopeModPair>::iterator it = m_scopes.begin(); it != m_scopes.end(); ++it) {
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (!modp->isTop()) {
|
||||
puts( scopep->nameDotless()+"."+funcname+"(os);\n");
|
||||
}
|
||||
}
|
||||
puts("}\n");
|
||||
}
|
||||
puts("void "+symClassName()+"::"+funcname+"("+classname+"& os) {\n");
|
||||
puts( "// LOCAL STATE\n");
|
||||
// __Vm_namep presumably already correct
|
||||
if (v3Global.opt.trace()) {
|
||||
puts( "os"+op+"__Vm_activity;\n");
|
||||
}
|
||||
puts( "os"+op+"__Vm_didInit;\n");
|
||||
puts( "// SUBCELL STATE\n");
|
||||
for (std::vector<ScopeModPair>::iterator it = m_scopes.begin();
|
||||
it != m_scopes.end(); ++it) {
|
||||
AstScope* scopep = it->first; AstNodeModule* modp = it->second;
|
||||
if (!modp->isTop()) {
|
||||
puts( scopep->nameDotless()+"."+funcname+"(os);\n");
|
||||
}
|
||||
}
|
||||
puts("}\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -572,17 +585,17 @@ void EmitCSyms::emitDpiHdr() {
|
|||
int firstExp = 0;
|
||||
int firstImp = 0;
|
||||
for (std::vector<AstCFunc*>::iterator it = m_dpis.begin(); it != m_dpis.end(); ++it) {
|
||||
AstCFunc* nodep = *it;
|
||||
if (nodep->dpiExportWrapper()) {
|
||||
if (!firstExp++) puts("\n// DPI EXPORTS\n");
|
||||
puts("// DPI export at "+nodep->fileline()->ascii()+"\n");
|
||||
puts("extern "+nodep->rtnTypeVoid()+" "+nodep->name()+" ("+cFuncArgs(nodep)+");\n");
|
||||
}
|
||||
else if (nodep->dpiImport()) {
|
||||
if (!firstImp++) puts("\n// DPI IMPORTS\n");
|
||||
puts("// DPI import at "+nodep->fileline()->ascii()+"\n");
|
||||
puts("extern "+nodep->rtnTypeVoid()+" "+nodep->name()+" ("+cFuncArgs(nodep)+");\n");
|
||||
}
|
||||
AstCFunc* nodep = *it;
|
||||
if (nodep->dpiExportWrapper()) {
|
||||
if (!firstExp++) puts("\n// DPI EXPORTS\n");
|
||||
puts("// DPI export at "+nodep->fileline()->ascii()+"\n");
|
||||
puts("extern "+nodep->rtnTypeVoid()+" "+nodep->name()+" ("+cFuncArgs(nodep)+");\n");
|
||||
}
|
||||
else if (nodep->dpiImport()) {
|
||||
if (!firstImp++) puts("\n// DPI IMPORTS\n");
|
||||
puts("// DPI import at "+nodep->fileline()->ascii()+"\n");
|
||||
puts("extern "+nodep->rtnTypeVoid()+" "+nodep->name()+" ("+cFuncArgs(nodep)+");\n");
|
||||
}
|
||||
}
|
||||
|
||||
puts("\n");
|
||||
|
|
@ -620,27 +633,27 @@ void EmitCSyms::emitDpiImp() {
|
|||
puts("\n");
|
||||
|
||||
for (std::vector<AstCFunc*>::iterator it = m_dpis.begin(); it != m_dpis.end(); ++it) {
|
||||
AstCFunc* nodep = *it;
|
||||
if (nodep->dpiExportWrapper()) {
|
||||
puts("#ifndef _VL_DPIDECL_"+nodep->name()+"\n");
|
||||
puts("#define _VL_DPIDECL_"+nodep->name()+"\n");
|
||||
puts(nodep->rtnTypeVoid()+" "+nodep->name()+" ("+cFuncArgs(nodep)+") {\n");
|
||||
puts("// DPI Export at "+nodep->fileline()->ascii()+"\n");
|
||||
puts("return "+topClassName()+"::"+nodep->name()+"(");
|
||||
string args;
|
||||
for (AstNode* stmtp = nodep->argsp(); stmtp; stmtp=stmtp->nextp()) {
|
||||
AstCFunc* nodep = *it;
|
||||
if (nodep->dpiExportWrapper()) {
|
||||
puts("#ifndef _VL_DPIDECL_"+nodep->name()+"\n");
|
||||
puts("#define _VL_DPIDECL_"+nodep->name()+"\n");
|
||||
puts(nodep->rtnTypeVoid()+" "+nodep->name()+" ("+cFuncArgs(nodep)+") {\n");
|
||||
puts("// DPI Export at "+nodep->fileline()->ascii()+"\n");
|
||||
puts("return "+topClassName()+"::"+nodep->name()+"(");
|
||||
string args;
|
||||
for (AstNode* stmtp = nodep->argsp(); stmtp; stmtp=stmtp->nextp()) {
|
||||
if (const AstVar* portp = VN_CAST(stmtp, Var)) {
|
||||
if (portp->isIO() && !portp->isFuncReturn()) {
|
||||
if (args != "") args+= ", ";
|
||||
args += portp->name();
|
||||
}
|
||||
}
|
||||
}
|
||||
puts(args+");\n");
|
||||
puts("}\n");
|
||||
puts("#endif\n");
|
||||
puts("\n");
|
||||
}
|
||||
if (portp->isIO() && !portp->isFuncReturn()) {
|
||||
if (args != "") args+= ", ";
|
||||
args += portp->name();
|
||||
}
|
||||
}
|
||||
}
|
||||
puts(args+");\n");
|
||||
puts("}\n");
|
||||
puts("#endif\n");
|
||||
puts("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
304
src/V3EmitMk.cpp
304
src/V3EmitMk.cpp
|
|
@ -42,198 +42,200 @@ public:
|
|||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
void putMakeClassEntry(V3OutMkFile& of, const string& name) {
|
||||
of.puts("\t"+V3Os::filenameNonDirExt(name)+" \\\n");
|
||||
of.puts("\t"+V3Os::filenameNonDirExt(name)+" \\\n");
|
||||
}
|
||||
|
||||
void emitClassMake() {
|
||||
// Generate the makefile
|
||||
V3OutMkFile of (v3Global.opt.makeDir()+"/"+ v3Global.opt.prefix() + "_classes.mk");
|
||||
of.putsHeader();
|
||||
of.puts("# DESCR" "IPTION: Verilator output: Make include file with class lists\n");
|
||||
of.puts("#\n");
|
||||
of.puts("# This file lists generated Verilated files, for including in higher level makefiles.\n");
|
||||
of.puts("# See "+v3Global.opt.prefix()+".mk"+" for the caller.\n");
|
||||
// Generate the makefile
|
||||
V3OutMkFile of (v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"_classes.mk");
|
||||
of.putsHeader();
|
||||
of.puts("# DESCR" "IPTION: Verilator output: Make include file with class lists\n");
|
||||
of.puts("#\n");
|
||||
of.puts("# This file lists generated Verilated files, for including in higher level makefiles.\n");
|
||||
of.puts("# See "+v3Global.opt.prefix()+".mk"+" for the caller.\n");
|
||||
|
||||
of.puts("\n### Switches...\n");
|
||||
of.puts("# Coverage output mode? 0/1 (from --coverage)\n");
|
||||
of.puts("VM_COVERAGE = "); of.puts(v3Global.opt.coverage()?"1":"0"); of.puts("\n");
|
||||
of.puts("# Threaded output mode? 0/1/N threads (from --threads)\n");
|
||||
of.puts("VM_THREADS = "); of.puts(cvtToStr(v3Global.opt.threads())); of.puts("\n");
|
||||
of.puts("# Tracing output mode? 0/1 (from --trace)\n");
|
||||
of.puts("VM_TRACE = "); of.puts(v3Global.opt.trace()?"1":"0"); of.puts("\n");
|
||||
of.puts("\n### Switches...\n");
|
||||
of.puts("# Coverage output mode? 0/1 (from --coverage)\n");
|
||||
of.puts("VM_COVERAGE = "); of.puts(v3Global.opt.coverage()?"1":"0"); of.puts("\n");
|
||||
of.puts("# Threaded output mode? 0/1/N threads (from --threads)\n");
|
||||
of.puts("VM_THREADS = "); of.puts(cvtToStr(v3Global.opt.threads())); of.puts("\n");
|
||||
of.puts("# Tracing output mode? 0/1 (from --trace)\n");
|
||||
of.puts("VM_TRACE = "); of.puts(v3Global.opt.trace()?"1":"0"); of.puts("\n");
|
||||
of.puts("# Tracing threadeds output mode? 0/1 (from --trace-fst-thread)\n");
|
||||
of.puts("VM_TRACE_THREADED = "); of.puts(v3Global.opt.traceFormat().threaded()
|
||||
?"1":"0"); of.puts("\n");
|
||||
|
||||
of.puts("\n### Object file lists...\n");
|
||||
for (int support=0; support<3; support++) {
|
||||
for (int slow=0; slow<2; slow++) {
|
||||
if (support==2) of.puts("# Global classes, need linked once per executable");
|
||||
else if (support) of.puts("# Generated support classes");
|
||||
else of.puts("# Generated module classes");
|
||||
if (slow) of.puts(", non-fast-path, compile with low/medium optimization\n");
|
||||
else of.puts(", fast-path, compile with highest optimization\n");
|
||||
of.puts(support==2?"VM_GLOBAL":support==1?"VM_SUPPORT":"VM_CLASSES");
|
||||
of.puts(slow?"_SLOW":"_FAST");
|
||||
of.puts(" += \\\n");
|
||||
if (support==2 && !slow) {
|
||||
putMakeClassEntry(of, "verilated.cpp");
|
||||
if (v3Global.dpi()) {
|
||||
putMakeClassEntry(of, "verilated_dpi.cpp");
|
||||
}
|
||||
if (v3Global.opt.vpi()) {
|
||||
putMakeClassEntry(of, "verilated_vpi.cpp");
|
||||
}
|
||||
if (v3Global.opt.savable()) {
|
||||
putMakeClassEntry(of, "verilated_save.cpp");
|
||||
}
|
||||
if (v3Global.opt.coverage()) {
|
||||
putMakeClassEntry(of, "verilated_cov.cpp");
|
||||
}
|
||||
if (v3Global.opt.trace()) {
|
||||
of.puts("\n### Object file lists...\n");
|
||||
for (int support=0; support<3; ++support) {
|
||||
for (int slow=0; slow<2; ++slow) {
|
||||
if (support==2) of.puts("# Global classes, need linked once per executable");
|
||||
else if (support) of.puts("# Generated support classes");
|
||||
else of.puts("# Generated module classes");
|
||||
if (slow) of.puts(", non-fast-path, compile with low/medium optimization\n");
|
||||
else of.puts(", fast-path, compile with highest optimization\n");
|
||||
of.puts(support==2?"VM_GLOBAL":support==1?"VM_SUPPORT":"VM_CLASSES");
|
||||
of.puts(slow?"_SLOW":"_FAST");
|
||||
of.puts(" += \\\n");
|
||||
if (support==2 && !slow) {
|
||||
putMakeClassEntry(of, "verilated.cpp");
|
||||
if (v3Global.dpi()) {
|
||||
putMakeClassEntry(of, "verilated_dpi.cpp");
|
||||
}
|
||||
if (v3Global.opt.vpi()) {
|
||||
putMakeClassEntry(of, "verilated_vpi.cpp");
|
||||
}
|
||||
if (v3Global.opt.savable()) {
|
||||
putMakeClassEntry(of, "verilated_save.cpp");
|
||||
}
|
||||
if (v3Global.opt.coverage()) {
|
||||
putMakeClassEntry(of, "verilated_cov.cpp");
|
||||
}
|
||||
if (v3Global.opt.trace()) {
|
||||
putMakeClassEntry(of, v3Global.opt.traceSourceName()+"_c.cpp");
|
||||
if (v3Global.opt.systemC()) {
|
||||
if (v3Global.opt.systemC()) {
|
||||
if (v3Global.opt.traceFormat() != TraceFormat::VCD) {
|
||||
v3error("Unsupported: This trace format is not supported in SystemC, use VCD format.");
|
||||
} else {
|
||||
putMakeClassEntry(of, v3Global.opt.traceSourceName()+"_sc.cpp");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (v3Global.opt.mtasks()) {
|
||||
putMakeClassEntry(of, "verilated_threads.cpp");
|
||||
}
|
||||
}
|
||||
else if (support==2 && slow) {
|
||||
}
|
||||
else {
|
||||
for (AstCFile* nodep = v3Global.rootp()->filesp(); nodep; nodep=VN_CAST(nodep->nextp(), CFile)) {
|
||||
if (nodep->source() && nodep->slow()==(slow!=0) && nodep->support()==(support!=0)) {
|
||||
putMakeClassEntry(of, nodep->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
of.puts("\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (support==2 && slow) {
|
||||
}
|
||||
else {
|
||||
for (AstCFile* nodep = v3Global.rootp()->filesp();
|
||||
nodep; nodep = VN_CAST(nodep->nextp(), CFile)) {
|
||||
if (nodep->source() && nodep->slow()==(slow!=0)
|
||||
&& nodep->support()==(support!=0)) {
|
||||
putMakeClassEntry(of, nodep->name());
|
||||
}
|
||||
}
|
||||
}
|
||||
of.puts("\n");
|
||||
}
|
||||
}
|
||||
|
||||
of.puts("\n");
|
||||
of.putsHeader();
|
||||
of.puts("\n");
|
||||
of.putsHeader();
|
||||
}
|
||||
|
||||
void emitOverallMake() {
|
||||
// Generate the makefile
|
||||
V3OutMkFile of (v3Global.opt.makeDir()+"/"+ v3Global.opt.prefix() + ".mk");
|
||||
of.putsHeader();
|
||||
of.puts("# DESCR" "IPTION: Verilator output: Makefile for building Verilated archive or executable\n");
|
||||
of.puts("#\n");
|
||||
of.puts("# Execute this makefile from the object directory:\n");
|
||||
of.puts("# make -f "+v3Global.opt.prefix()+".mk"+"\n");
|
||||
of.puts("\n");
|
||||
// Generate the makefile
|
||||
V3OutMkFile of (v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+".mk");
|
||||
of.putsHeader();
|
||||
of.puts("# DESCR" "IPTION: Verilator output: Makefile for building Verilated archive or executable\n");
|
||||
of.puts("#\n");
|
||||
of.puts("# Execute this makefile from the object directory:\n");
|
||||
of.puts("# make -f "+v3Global.opt.prefix()+".mk"+"\n");
|
||||
of.puts("\n");
|
||||
|
||||
if (v3Global.opt.exe()) {
|
||||
of.puts("default: "+v3Global.opt.exeName()+"\n");
|
||||
} else {
|
||||
of.puts("default: "+v3Global.opt.prefix()+"__ALL.a\n");
|
||||
}
|
||||
of.puts("\n### Constants...\n");
|
||||
of.puts("# Perl executable (from $PERL)\n");
|
||||
of.puts("PERL = "+V3Options::getenvPERL()+"\n");
|
||||
of.puts("# Path to Verilator kit (from $VERILATOR_ROOT)\n");
|
||||
of.puts("VERILATOR_ROOT = "+V3Options::getenvVERILATOR_ROOT()+"\n");
|
||||
of.puts("# SystemC include directory with systemc.h (from $SYSTEMC_INCLUDE)\n");
|
||||
of.puts(string("SYSTEMC_INCLUDE ?= ")+V3Options::getenvSYSTEMC_INCLUDE()+"\n");
|
||||
of.puts("# SystemC library directory with libsystemc.a (from $SYSTEMC_LIBDIR)\n");
|
||||
of.puts(string("SYSTEMC_LIBDIR ?= ")+V3Options::getenvSYSTEMC_LIBDIR()+"\n");
|
||||
if (v3Global.opt.exe()) {
|
||||
of.puts("default: "+v3Global.opt.exeName()+"\n");
|
||||
} else {
|
||||
of.puts("default: "+v3Global.opt.prefix()+"__ALL.a\n");
|
||||
}
|
||||
of.puts("\n### Constants...\n");
|
||||
of.puts("# Perl executable (from $PERL)\n");
|
||||
of.puts("PERL = "+V3Options::getenvPERL()+"\n");
|
||||
of.puts("# Path to Verilator kit (from $VERILATOR_ROOT)\n");
|
||||
of.puts("VERILATOR_ROOT = "+V3Options::getenvVERILATOR_ROOT()+"\n");
|
||||
of.puts("# SystemC include directory with systemc.h (from $SYSTEMC_INCLUDE)\n");
|
||||
of.puts(string("SYSTEMC_INCLUDE ?= ")+V3Options::getenvSYSTEMC_INCLUDE()+"\n");
|
||||
of.puts("# SystemC library directory with libsystemc.a (from $SYSTEMC_LIBDIR)\n");
|
||||
of.puts(string("SYSTEMC_LIBDIR ?= ")+V3Options::getenvSYSTEMC_LIBDIR()+"\n");
|
||||
|
||||
of.puts("\n### Switches...\n");
|
||||
of.puts("# SystemC output mode? 0/1 (from --sc)\n");
|
||||
of.puts(string("VM_SC = ")+((v3Global.opt.systemC())?"1":"0")+"\n");
|
||||
of.puts("# Legacy or SystemC output mode? 0/1 (from --sc)\n");
|
||||
of.puts(string("VM_SP_OR_SC = $(VM_SC)\n"));
|
||||
of.puts("# Deprecated\n");
|
||||
of.puts(string("VM_PCLI = ")+(v3Global.opt.systemC()?"0":"1")+"\n");
|
||||
of.puts("# Deprecated: SystemC architecture to find link library path (from $SYSTEMC_ARCH)\n");
|
||||
of.puts(string("VM_SC_TARGET_ARCH = ")+V3Options::getenvSYSTEMC_ARCH()+"\n");
|
||||
of.puts("\n### Switches...\n");
|
||||
of.puts("# SystemC output mode? 0/1 (from --sc)\n");
|
||||
of.puts(string("VM_SC = ")+((v3Global.opt.systemC())?"1":"0")+"\n");
|
||||
of.puts("# Legacy or SystemC output mode? 0/1 (from --sc)\n");
|
||||
of.puts(string("VM_SP_OR_SC = $(VM_SC)\n"));
|
||||
of.puts("# Deprecated\n");
|
||||
of.puts(string("VM_PCLI = ")+(v3Global.opt.systemC()?"0":"1")+"\n");
|
||||
of.puts("# Deprecated: SystemC architecture to find link library path (from $SYSTEMC_ARCH)\n");
|
||||
of.puts(string("VM_SC_TARGET_ARCH = ")+V3Options::getenvSYSTEMC_ARCH()+"\n");
|
||||
|
||||
of.puts("\n### Vars...\n");
|
||||
of.puts("# Design prefix (from --prefix)\n");
|
||||
of.puts(string("VM_PREFIX = ")+v3Global.opt.prefix()+"\n");
|
||||
of.puts("# Module prefix (from --prefix)\n");
|
||||
of.puts(string("VM_MODPREFIX = ")+v3Global.opt.modPrefix()+"\n");
|
||||
of.puts("\n### Vars...\n");
|
||||
of.puts("# Design prefix (from --prefix)\n");
|
||||
of.puts(string("VM_PREFIX = ")+v3Global.opt.prefix()+"\n");
|
||||
of.puts("# Module prefix (from --prefix)\n");
|
||||
of.puts(string("VM_MODPREFIX = ")+v3Global.opt.modPrefix()+"\n");
|
||||
|
||||
of.puts("# User CFLAGS (from -CFLAGS on Verilator command line)\n");
|
||||
of.puts("VM_USER_CFLAGS = \\\n");
|
||||
const V3StringList& cFlags = v3Global.opt.cFlags();
|
||||
for (V3StringList::const_iterator it = cFlags.begin(); it != cFlags.end(); ++it) {
|
||||
of.puts("\t"+*it+" \\\n");
|
||||
}
|
||||
of.puts("\n");
|
||||
of.puts("# User CFLAGS (from -CFLAGS on Verilator command line)\n");
|
||||
of.puts("VM_USER_CFLAGS = \\\n");
|
||||
const V3StringList& cFlags = v3Global.opt.cFlags();
|
||||
for (V3StringList::const_iterator it = cFlags.begin(); it != cFlags.end(); ++it) {
|
||||
of.puts("\t"+*it+" \\\n");
|
||||
}
|
||||
of.puts("\n");
|
||||
|
||||
of.puts("# User LDLIBS (from -LDFLAGS on Verilator command line)\n");
|
||||
of.puts("VM_USER_LDLIBS = \\\n");
|
||||
const V3StringList& ldLibs = v3Global.opt.ldLibs();
|
||||
for (V3StringList::const_iterator it = ldLibs.begin(); it != ldLibs.end(); ++it) {
|
||||
of.puts("\t"+*it+" \\\n");
|
||||
}
|
||||
of.puts("\n");
|
||||
of.puts("# User LDLIBS (from -LDFLAGS on Verilator command line)\n");
|
||||
of.puts("VM_USER_LDLIBS = \\\n");
|
||||
const V3StringList& ldLibs = v3Global.opt.ldLibs();
|
||||
for (V3StringList::const_iterator it = ldLibs.begin(); it != ldLibs.end(); ++it) {
|
||||
of.puts("\t"+*it+" \\\n");
|
||||
}
|
||||
of.puts("\n");
|
||||
|
||||
V3StringSet dirs;
|
||||
of.puts("# User .cpp files (from .cpp's on Verilator command line)\n");
|
||||
of.puts("VM_USER_CLASSES = \\\n");
|
||||
const V3StringSet& cppFiles = v3Global.opt.cppFiles();
|
||||
for (V3StringSet::const_iterator it = cppFiles.begin(); it != cppFiles.end(); ++it) {
|
||||
string cppfile = *it;
|
||||
of.puts("\t"+V3Os::filenameNonExt(cppfile)+" \\\n");
|
||||
string dir = V3Os::filenameDir(cppfile);
|
||||
if (dirs.find(dir) == dirs.end()) dirs.insert(dir);
|
||||
}
|
||||
of.puts("\n");
|
||||
V3StringSet dirs;
|
||||
of.puts("# User .cpp files (from .cpp's on Verilator command line)\n");
|
||||
of.puts("VM_USER_CLASSES = \\\n");
|
||||
const V3StringSet& cppFiles = v3Global.opt.cppFiles();
|
||||
for (V3StringSet::const_iterator it = cppFiles.begin(); it != cppFiles.end(); ++it) {
|
||||
string cppfile = *it;
|
||||
of.puts("\t"+V3Os::filenameNonExt(cppfile)+" \\\n");
|
||||
string dir = V3Os::filenameDir(cppfile);
|
||||
if (dirs.find(dir) == dirs.end()) dirs.insert(dir);
|
||||
}
|
||||
of.puts("\n");
|
||||
|
||||
of.puts("# User .cpp directories (from .cpp's on Verilator command line)\n");
|
||||
of.puts("VM_USER_DIR = \\\n");
|
||||
for (V3StringSet::iterator it = dirs.begin(); it!=dirs.end(); ++it) {
|
||||
of.puts("\t"+*it+" \\\n");
|
||||
}
|
||||
of.puts("\n");
|
||||
of.puts("# User .cpp directories (from .cpp's on Verilator command line)\n");
|
||||
of.puts("VM_USER_DIR = \\\n");
|
||||
for (V3StringSet::iterator it = dirs.begin(); it!=dirs.end(); ++it) {
|
||||
of.puts("\t"+*it+" \\\n");
|
||||
}
|
||||
of.puts("\n");
|
||||
|
||||
of.puts("\n### Default rules...\n");
|
||||
of.puts("# Include list of all generated classes\n");
|
||||
of.puts("include "+v3Global.opt.prefix()+"_classes.mk\n");
|
||||
of.puts("# Include global rules\n");
|
||||
of.puts("include $(VERILATOR_ROOT)/include/verilated.mk\n");
|
||||
of.puts("\n### Default rules...\n");
|
||||
of.puts("# Include list of all generated classes\n");
|
||||
of.puts("include "+v3Global.opt.prefix()+"_classes.mk\n");
|
||||
of.puts("# Include global rules\n");
|
||||
of.puts("include $(VERILATOR_ROOT)/include/verilated.mk\n");
|
||||
|
||||
if (v3Global.opt.exe()) {
|
||||
of.puts("\n### Executable rules... (from --exe)\n");
|
||||
of.puts("VPATH += $(VM_USER_DIR)\n");
|
||||
of.puts("\n");
|
||||
for (V3StringSet::const_iterator it = cppFiles.begin(); it != cppFiles.end(); ++it) {
|
||||
string cppfile = *it;
|
||||
string basename = V3Os::filenameNonExt(cppfile);
|
||||
if (v3Global.opt.exe()) {
|
||||
of.puts("\n### Executable rules... (from --exe)\n");
|
||||
of.puts("VPATH += $(VM_USER_DIR)\n");
|
||||
of.puts("\n");
|
||||
for (V3StringSet::const_iterator it = cppFiles.begin(); it != cppFiles.end(); ++it) {
|
||||
string cppfile = *it;
|
||||
string basename = V3Os::filenameNonExt(cppfile);
|
||||
// NOLINTNEXTLINE(performance-inefficient-string-concatenation)
|
||||
of.puts(basename+".o: "+cppfile+"\n");
|
||||
of.puts("\t$(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $<\n");
|
||||
}
|
||||
of.puts(basename+".o: "+cppfile+"\n");
|
||||
of.puts("\t$(OBJCACHE) $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(OPT_FAST) -c -o $@ $<\n");
|
||||
}
|
||||
|
||||
of.puts("\n### Link rules... (from --exe)\n");
|
||||
of.puts(v3Global.opt.exeName()+": $(VK_USER_OBJS) $(VK_GLOBAL_OBJS) $(VM_PREFIX)__ALL.a\n");
|
||||
of.puts("\t$(LINK) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ $(LIBS) $(SC_LIBS)\n");
|
||||
of.puts("\n");
|
||||
}
|
||||
of.puts("\n### Link rules... (from --exe)\n");
|
||||
of.puts(v3Global.opt.exeName()+": $(VK_USER_OBJS) $(VK_GLOBAL_OBJS) $(VM_PREFIX)__ALL.a\n");
|
||||
of.puts("\t$(LINK) $(LDFLAGS) $^ $(LOADLIBES) $(LDLIBS) -o $@ $(LIBS) $(SC_LIBS)\n");
|
||||
of.puts("\n");
|
||||
}
|
||||
|
||||
of.puts("\n");
|
||||
of.putsHeader();
|
||||
of.puts("\n");
|
||||
of.putsHeader();
|
||||
}
|
||||
|
||||
//--------------------
|
||||
virtual void visit(AstNode* nodep) {
|
||||
nodep->v3fatalSrc("No visitors implemented.");
|
||||
nodep->v3fatalSrc("No visitors implemented.");
|
||||
}
|
||||
|
||||
public:
|
||||
explicit EmitMkVisitor(AstNetlist*) {
|
||||
emitClassMake();
|
||||
emitOverallMake();
|
||||
emitClassMake();
|
||||
emitOverallMake();
|
||||
}
|
||||
virtual ~EmitMkVisitor() {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void emitmk(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
633
src/V3EmitV.cpp
633
src/V3EmitV.cpp
|
|
@ -36,8 +36,8 @@
|
|||
|
||||
class EmitVBaseVisitor : public EmitCBaseVisitor {
|
||||
// MEMBERS
|
||||
bool m_suppressSemi;
|
||||
AstSenTree* m_sensesp;
|
||||
bool m_suppressSemi;
|
||||
AstSenTree* m_sensesp;
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
|
@ -48,12 +48,12 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
virtual void putqs(AstNode* nodep, const string& str) = 0; // Fileline quiet w/o %% mark
|
||||
virtual void putsNoTracking(const string& str) = 0;
|
||||
virtual void putsQuoted(const string& str) {
|
||||
// Quote \ and " for use inside C programs
|
||||
// Don't use to quote a filename for #include - #include doesn't \ escape.
|
||||
// Duplicate in V3File - here so we can print to string
|
||||
putsNoTracking("\"");
|
||||
// Quote \ and " for use inside C programs
|
||||
// Don't use to quote a filename for #include - #include doesn't \ escape.
|
||||
// Duplicate in V3File - here so we can print to string
|
||||
putsNoTracking("\"");
|
||||
putsNoTracking(V3OutFormatter::quoteNameControls(str));
|
||||
putsNoTracking("\"");
|
||||
putsNoTracking("\"");
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
|
|
@ -61,199 +61,200 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
putfs(nodep, nodep->verilogKwd()+" "+modClassName(nodep)+";\n");
|
||||
putfs(nodep, nodep->verilogKwd()+" "+modClassName(nodep)+";\n");
|
||||
iterateChildren(nodep);
|
||||
putqs(nodep, "end"+nodep->verilogKwd()+"\n");
|
||||
putqs(nodep, "end"+nodep->verilogKwd()+"\n");
|
||||
}
|
||||
virtual void visit(AstNodeFTask* nodep) {
|
||||
putfs(nodep, nodep->isFunction() ? "function":"task");
|
||||
puts(" ");
|
||||
puts(nodep->prettyName());
|
||||
puts(";\n");
|
||||
putqs(nodep, "begin\n"); // Only putfs the first time for each visitor; later for same node is putqs
|
||||
putfs(nodep, nodep->isFunction() ? "function":"task");
|
||||
puts(" ");
|
||||
puts(nodep->prettyName());
|
||||
puts(";\n");
|
||||
putqs(nodep, "begin\n"); // Only putfs the first time for each visitor; later for same node is putqs
|
||||
iterateAndNextNull(nodep->stmtsp());
|
||||
putqs(nodep, "end\n");
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
|
||||
virtual void visit(AstBegin* nodep) {
|
||||
if (nodep->unnamed()) {
|
||||
putbs("begin\n");
|
||||
} else {
|
||||
putbs("begin : "+nodep->name()+"\n");
|
||||
}
|
||||
if (nodep->unnamed()) {
|
||||
putbs("begin\n");
|
||||
} else {
|
||||
putbs("begin : "+nodep->name()+"\n");
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
puts("end\n");
|
||||
puts("end\n");
|
||||
}
|
||||
virtual void visit(AstGenerate* nodep) {
|
||||
putfs(nodep, "generate\n");
|
||||
putfs(nodep, "generate\n");
|
||||
iterateChildren(nodep);
|
||||
putqs(nodep, "end\n");
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstFinal* nodep) {
|
||||
putfs(nodep, "final begin\n");
|
||||
putfs(nodep, "final begin\n");
|
||||
iterateChildren(nodep);
|
||||
putqs(nodep, "end\n");
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstInitial* nodep) {
|
||||
putfs(nodep,"initial begin\n");
|
||||
putfs(nodep, "initial begin\n");
|
||||
iterateChildren(nodep);
|
||||
putqs(nodep, "end\n");
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstAlways* nodep) {
|
||||
putfs(nodep,"always ");
|
||||
putfs(nodep, "always ");
|
||||
if (m_sensesp) iterateAndNextNull(m_sensesp); // In active
|
||||
else iterateAndNextNull(nodep->sensesp());
|
||||
putbs(" begin\n");
|
||||
putbs(" begin\n");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
putqs(nodep,"end\n");
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstAlwaysPublic* nodep) {
|
||||
putfs(nodep,"/*verilator public_flat_rw ");
|
||||
putfs(nodep, "/*verilator public_flat_rw ");
|
||||
if (m_sensesp) iterateAndNextNull(m_sensesp); // In active
|
||||
else iterateAndNextNull(nodep->sensesp());
|
||||
putqs(nodep," ");
|
||||
putqs(nodep, " ");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
putqs(nodep,"*/\n");
|
||||
putqs(nodep, "*/\n");
|
||||
}
|
||||
virtual void visit(AstNodeAssign* nodep) {
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
putfs(nodep," "+nodep->verilogKwd()+" ");
|
||||
putfs(nodep, " "+nodep->verilogKwd()+" ");
|
||||
iterateAndNextNull(nodep->rhsp());
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
}
|
||||
virtual void visit(AstAssignDly* nodep) {
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
putfs(nodep," <= ");
|
||||
putfs(nodep, " <= ");
|
||||
iterateAndNextNull(nodep->rhsp());
|
||||
puts(";\n");
|
||||
puts(";\n");
|
||||
}
|
||||
virtual void visit(AstAssignAlias* nodep) {
|
||||
putbs("alias ");
|
||||
putbs("alias ");
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
putfs(nodep," = ");
|
||||
putfs(nodep, " = ");
|
||||
iterateAndNextNull(nodep->rhsp());
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
}
|
||||
virtual void visit(AstAssignW* nodep) {
|
||||
putfs(nodep,"assign ");
|
||||
putfs(nodep, "assign ");
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
putbs(" = ");
|
||||
putbs(" = ");
|
||||
iterateAndNextNull(nodep->rhsp());
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
}
|
||||
virtual void visit(AstBreak* nodep) {
|
||||
putbs("break");
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
putbs("break");
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
}
|
||||
virtual void visit(AstSenTree* nodep) {
|
||||
// AstSenItem is called for dumping in isolation by V3Order
|
||||
putfs(nodep,"@(");
|
||||
for (AstNode* expp=nodep->sensesp(); expp; expp = expp->nextp()) {
|
||||
// AstSenItem is called for dumping in isolation by V3Order
|
||||
putfs(nodep, "@(");
|
||||
for (AstNode* expp=nodep->sensesp(); expp; expp = expp->nextp()) {
|
||||
iterate(expp);
|
||||
if (expp->nextp()) putqs(expp->nextp()," or ");
|
||||
}
|
||||
puts(")");
|
||||
if (expp->nextp()) putqs(expp->nextp(), " or ");
|
||||
}
|
||||
puts(")");
|
||||
}
|
||||
virtual void visit(AstSenGate* nodep) {
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->sensesp(), nodep->rhsp());
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->sensesp(), nodep->rhsp());
|
||||
}
|
||||
virtual void visit(AstSenItem* nodep) {
|
||||
putfs(nodep,"");
|
||||
puts(nodep->edgeType().verilogKwd());
|
||||
if (nodep->sensp()) puts(" ");
|
||||
putfs(nodep, "");
|
||||
puts(nodep->edgeType().verilogKwd());
|
||||
if (nodep->sensp()) puts(" ");
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstNodeCase* nodep) {
|
||||
putfs(nodep,"");
|
||||
putfs(nodep, "");
|
||||
if (const AstCase* casep = VN_CAST(nodep, Case)) {
|
||||
if (casep->priorityPragma()) puts("priority ");
|
||||
if (casep->uniquePragma()) puts("unique ");
|
||||
if (casep->unique0Pragma()) puts("unique0 ");
|
||||
}
|
||||
puts(nodep->verilogKwd());
|
||||
puts(" (");
|
||||
if (casep->priorityPragma()) puts("priority ");
|
||||
if (casep->uniquePragma()) puts("unique ");
|
||||
if (casep->unique0Pragma()) puts("unique0 ");
|
||||
}
|
||||
puts(nodep->verilogKwd());
|
||||
puts(" (");
|
||||
iterateAndNextNull(nodep->exprp());
|
||||
puts(")\n");
|
||||
puts(")\n");
|
||||
if (const AstCase* casep = VN_CAST(nodep, Case)) {
|
||||
if (casep->fullPragma() || casep->parallelPragma()) {
|
||||
puts(" // synopsys");
|
||||
if (casep->fullPragma()) puts(" full_case");
|
||||
if (casep->parallelPragma()) puts(" parallel_case");
|
||||
}
|
||||
}
|
||||
if (casep->fullPragma() || casep->parallelPragma()) {
|
||||
puts(" // synopsys");
|
||||
if (casep->fullPragma()) puts(" full_case");
|
||||
if (casep->parallelPragma()) puts(" parallel_case");
|
||||
}
|
||||
}
|
||||
iterateAndNextNull(nodep->itemsp());
|
||||
putqs(nodep,"endcase\n");
|
||||
putqs(nodep, "endcase\n");
|
||||
}
|
||||
virtual void visit(AstCaseItem* nodep) {
|
||||
if (nodep->condsp()) {
|
||||
if (nodep->condsp()) {
|
||||
iterateAndNextNull(nodep->condsp());
|
||||
} else putbs("default");
|
||||
putfs(nodep,": begin ");
|
||||
} else putbs("default");
|
||||
putfs(nodep, ": begin ");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
putqs(nodep,"end\n");
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstComment* nodep) {
|
||||
puts(string("// ")+nodep->name()+"\n");
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstContinue* nodep) {
|
||||
putbs("continue");
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
putbs("continue");
|
||||
if (!m_suppressSemi) puts(";\n");
|
||||
}
|
||||
virtual void visit(AstCoverDecl*) {} // N/A
|
||||
virtual void visit(AstCoverInc*) {} // N/A
|
||||
virtual void visit(AstCoverToggle*) {} // N/A
|
||||
|
||||
void visitNodeDisplay(AstNode* nodep, AstNode* fileOrStrgp, const string& text, AstNode* exprsp) {
|
||||
putfs(nodep,nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
void visitNodeDisplay(AstNode* nodep, AstNode* fileOrStrgp,
|
||||
const string& text, AstNode* exprsp) {
|
||||
putfs(nodep, nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
if (fileOrStrgp) { iterateAndNextNull(fileOrStrgp); putbs(","); }
|
||||
putsQuoted(text);
|
||||
for (AstNode* expp=exprsp; expp; expp = expp->nextp()) {
|
||||
puts(",");
|
||||
putsQuoted(text);
|
||||
for (AstNode* expp=exprsp; expp; expp = expp->nextp()) {
|
||||
puts(",");
|
||||
iterateAndNextNull(expp);
|
||||
}
|
||||
puts(");\n");
|
||||
}
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstDisable* nodep) {
|
||||
putbs("disable "+nodep->name()+";\n");
|
||||
putbs("disable "+nodep->name()+";\n");
|
||||
}
|
||||
virtual void visit(AstDisplay* nodep) {
|
||||
visitNodeDisplay(nodep, nodep->filep(), nodep->fmtp()->text(), nodep->fmtp()->exprsp());
|
||||
visitNodeDisplay(nodep, nodep->filep(), nodep->fmtp()->text(), nodep->fmtp()->exprsp());
|
||||
}
|
||||
virtual void visit(AstFScanF* nodep) {
|
||||
visitNodeDisplay(nodep, nodep->filep(), nodep->text(), nodep->exprsp());
|
||||
visitNodeDisplay(nodep, nodep->filep(), nodep->text(), nodep->exprsp());
|
||||
}
|
||||
virtual void visit(AstSScanF* nodep) {
|
||||
visitNodeDisplay(nodep, nodep->fromp(), nodep->text(), nodep->exprsp());
|
||||
visitNodeDisplay(nodep, nodep->fromp(), nodep->text(), nodep->exprsp());
|
||||
}
|
||||
virtual void visit(AstSFormat* nodep) {
|
||||
visitNodeDisplay(nodep, nodep->lhsp(), nodep->fmtp()->text(), nodep->fmtp()->exprsp());
|
||||
visitNodeDisplay(nodep, nodep->lhsp(), nodep->fmtp()->text(), nodep->fmtp()->exprsp());
|
||||
}
|
||||
virtual void visit(AstSFormatF* nodep) {
|
||||
visitNodeDisplay(nodep, NULL, nodep->text(), nodep->exprsp());
|
||||
visitNodeDisplay(nodep, NULL, nodep->text(), nodep->exprsp());
|
||||
}
|
||||
virtual void visit(AstFOpen* nodep) {
|
||||
putfs(nodep,nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
putfs(nodep, nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
if (nodep->filep()) iterateAndNextNull(nodep->filep());
|
||||
putbs(",");
|
||||
putbs(",");
|
||||
if (nodep->filenamep()) iterateAndNextNull(nodep->filenamep());
|
||||
putbs(",");
|
||||
putbs(",");
|
||||
if (nodep->modep()) iterateAndNextNull(nodep->modep());
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstFClose* nodep) {
|
||||
putfs(nodep,nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
putfs(nodep, nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
if (nodep->filep()) iterateAndNextNull(nodep->filep());
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstFFlush* nodep) {
|
||||
putfs(nodep,nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
putfs(nodep, nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
if (nodep->filep()) iterateAndNextNull(nodep->filep());
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstJumpGo* nodep) {
|
||||
putbs("disable "+cvtToHex(nodep->labelp())+";\n");
|
||||
|
|
@ -261,75 +262,75 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
virtual void visit(AstJumpLabel* nodep) {
|
||||
putbs("begin : "+cvtToHex(nodep)+"\n");
|
||||
if (nodep->stmtsp()) iterateAndNextNull(nodep->stmtsp());
|
||||
puts("end\n");
|
||||
puts("end\n");
|
||||
}
|
||||
virtual void visit(AstNodeReadWriteMem* nodep) {
|
||||
putfs(nodep,nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
putfs(nodep, nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
if (nodep->filenamep()) iterateAndNextNull(nodep->filenamep());
|
||||
putbs(",");
|
||||
putbs(",");
|
||||
if (nodep->memp()) iterateAndNextNull(nodep->memp());
|
||||
if (nodep->lsbp()) { putbs(","); iterateAndNextNull(nodep->lsbp()); }
|
||||
if (nodep->msbp()) { putbs(","); iterateAndNextNull(nodep->msbp()); }
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstSysFuncAsTask* nodep) {
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
puts(";\n");
|
||||
}
|
||||
virtual void visit(AstSysIgnore* nodep) {
|
||||
putfs(nodep,nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
putfs(nodep, nodep->verilogKwd());
|
||||
putbs(" (");
|
||||
iterateAndNextNull(nodep->exprsp());
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstNodeFor* nodep) {
|
||||
putfs(nodep,"for (");
|
||||
m_suppressSemi = true;
|
||||
putfs(nodep, "for (");
|
||||
m_suppressSemi = true;
|
||||
iterateAndNextNull(nodep->initsp());
|
||||
puts(";");
|
||||
puts(";");
|
||||
iterateAndNextNull(nodep->condp());
|
||||
puts(";");
|
||||
puts(";");
|
||||
iterateAndNextNull(nodep->incsp());
|
||||
m_suppressSemi = false;
|
||||
puts(") begin\n");
|
||||
m_suppressSemi = false;
|
||||
puts(") begin\n");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
putqs(nodep,"end\n");
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstRepeat* nodep) {
|
||||
putfs(nodep,"repeat (");
|
||||
putfs(nodep, "repeat (");
|
||||
iterateAndNextNull(nodep->countp());
|
||||
puts(") begin\n");
|
||||
puts(") begin\n");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
putfs(nodep,"end\n");
|
||||
putfs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstWhile* nodep) {
|
||||
iterateAndNextNull(nodep->precondsp());
|
||||
putfs(nodep,"while (");
|
||||
putfs(nodep, "while (");
|
||||
iterateAndNextNull(nodep->condp());
|
||||
puts(") begin\n");
|
||||
puts(") begin\n");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
iterateAndNextNull(nodep->incsp());
|
||||
iterateAndNextNull(nodep->precondsp()); // Need to recompute before next loop
|
||||
putfs(nodep,"end\n");
|
||||
putfs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstNodeIf* nodep) {
|
||||
putfs(nodep,"");
|
||||
putfs(nodep, "");
|
||||
if (const AstIf* ifp = VN_CAST(nodep, If)) {
|
||||
if (ifp->priorityPragma()) puts("priority ");
|
||||
if (ifp->uniquePragma()) puts("unique ");
|
||||
if (ifp->unique0Pragma()) puts("unique0 ");
|
||||
}
|
||||
puts("if (");
|
||||
if (ifp->priorityPragma()) puts("priority ");
|
||||
if (ifp->uniquePragma()) puts("unique ");
|
||||
if (ifp->unique0Pragma()) puts("unique0 ");
|
||||
}
|
||||
puts("if (");
|
||||
iterateAndNextNull(nodep->condp());
|
||||
puts(") begin\n");
|
||||
puts(") begin\n");
|
||||
iterateAndNextNull(nodep->ifsp());
|
||||
if (nodep->elsesp()) {
|
||||
putqs(nodep,"end\n");
|
||||
putqs(nodep,"else begin\n");
|
||||
if (nodep->elsesp()) {
|
||||
putqs(nodep, "end\n");
|
||||
putqs(nodep, "else begin\n");
|
||||
iterateAndNextNull(nodep->elsesp());
|
||||
}
|
||||
putqs(nodep,"end\n");
|
||||
}
|
||||
putqs(nodep, "end\n");
|
||||
}
|
||||
virtual void visit(AstPast* nodep) {
|
||||
putfs(nodep, "$past(");
|
||||
|
|
@ -341,184 +342,184 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
puts(")");
|
||||
}
|
||||
virtual void visit(AstReturn* nodep) {
|
||||
putfs(nodep,"return ");
|
||||
putfs(nodep, "return ");
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
puts(";\n");
|
||||
puts(";\n");
|
||||
}
|
||||
virtual void visit(AstStop* nodep) {
|
||||
putfs(nodep,"$stop;\n");
|
||||
putfs(nodep, "$stop;\n");
|
||||
}
|
||||
virtual void visit(AstFinish* nodep) {
|
||||
putfs(nodep,"$finish;\n");
|
||||
putfs(nodep, "$finish;\n");
|
||||
}
|
||||
virtual void visit(AstText* nodep) {
|
||||
putsNoTracking(nodep->text());
|
||||
putsNoTracking(nodep->text());
|
||||
}
|
||||
virtual void visit(AstScopeName* nodep) {
|
||||
}
|
||||
virtual void visit(AstCStmt* nodep) {
|
||||
putfs(nodep,"$_CSTMT(");
|
||||
putfs(nodep, "$_CSTMT(");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstCMath* nodep) {
|
||||
putfs(nodep,"$_CMATH(");
|
||||
putfs(nodep, "$_CMATH(");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstUCStmt* nodep) {
|
||||
putfs(nodep,"$c(");
|
||||
putfs(nodep, "$c(");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
puts(");\n");
|
||||
puts(");\n");
|
||||
}
|
||||
virtual void visit(AstUCFunc* nodep) {
|
||||
putfs(nodep,"$c(");
|
||||
putfs(nodep, "$c(");
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
puts(")");
|
||||
puts(")");
|
||||
}
|
||||
|
||||
// Operators
|
||||
virtual void emitVerilogFormat(AstNode* nodep, const string& format,
|
||||
AstNode* lhsp=NULL, AstNode* rhsp=NULL, AstNode* thsp=NULL) {
|
||||
// Look at emitVerilog() format for term/uni/dual/triops,
|
||||
// and write out appropriate text.
|
||||
// %f Potential fileline-if-change and line break
|
||||
// %l lhsp - if appropriate
|
||||
// %r rhsp - if appropriate
|
||||
// %t thsp - if appropriate
|
||||
// %d dtypep - if appropriate
|
||||
// %k Potential line break
|
||||
bool inPct = false;
|
||||
putbs("");
|
||||
for (string::const_iterator pos = format.begin(); pos != format.end(); ++pos) {
|
||||
if (pos[0]=='%') {
|
||||
inPct = true;
|
||||
} else if (!inPct) { // Normal text
|
||||
string s; s+=pos[0]; puts(s);
|
||||
} else { // Format character
|
||||
inPct = false;
|
||||
switch (*pos) {
|
||||
case '%': puts("%"); break;
|
||||
case 'f': putfs(nodep,""); break;
|
||||
case 'k': putbs(""); break;
|
||||
case 'l': {
|
||||
if (!lhsp) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
AstNode* lhsp=NULL, AstNode* rhsp=NULL, AstNode* thsp=NULL) {
|
||||
// Look at emitVerilog() format for term/uni/dual/triops,
|
||||
// and write out appropriate text.
|
||||
// %f Potential fileline-if-change and line break
|
||||
// %l lhsp - if appropriate
|
||||
// %r rhsp - if appropriate
|
||||
// %t thsp - if appropriate
|
||||
// %d dtypep - if appropriate
|
||||
// %k Potential line break
|
||||
bool inPct = false;
|
||||
putbs("");
|
||||
for (string::const_iterator pos = format.begin(); pos != format.end(); ++pos) {
|
||||
if (pos[0]=='%') {
|
||||
inPct = true;
|
||||
} else if (!inPct) { // Normal text
|
||||
string s; s+=pos[0]; puts(s);
|
||||
} else { // Format character
|
||||
inPct = false;
|
||||
switch (*pos) {
|
||||
case '%': puts("%"); break;
|
||||
case 'f': putfs(nodep, ""); break;
|
||||
case 'k': putbs(""); break;
|
||||
case 'l': {
|
||||
if (!lhsp) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
else iterateAndNextNull(lhsp);
|
||||
break;
|
||||
}
|
||||
case 'r': {
|
||||
if (!rhsp) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
break;
|
||||
}
|
||||
case 'r': {
|
||||
if (!rhsp) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
else iterateAndNextNull(rhsp);
|
||||
break;
|
||||
}
|
||||
case 't': {
|
||||
if (!thsp) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
break;
|
||||
}
|
||||
case 't': {
|
||||
if (!thsp) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
else iterateAndNextNull(thsp);
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
if (!nodep->dtypep()) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
break;
|
||||
}
|
||||
case 'd': {
|
||||
if (!nodep->dtypep()) { nodep->v3fatalSrc("emitVerilog() references undef node"); }
|
||||
else iterateAndNextNull(nodep->dtypep());
|
||||
break;
|
||||
}
|
||||
default:
|
||||
nodep->v3fatalSrc("Unknown emitVerilog format code: %"<<pos[0]);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
nodep->v3fatalSrc("Unknown emitVerilog format code: %"<<pos[0]);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(AstNodeTermop* nodep) {
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog());
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog());
|
||||
}
|
||||
virtual void visit(AstNodeUniop* nodep) {
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->lhsp());
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->lhsp());
|
||||
}
|
||||
virtual void visit(AstNodeBiop* nodep) {
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->lhsp(), nodep->rhsp());
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->lhsp(), nodep->rhsp());
|
||||
}
|
||||
virtual void visit(AstNodeTriop* nodep) {
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->lhsp(), nodep->rhsp(), nodep->thsp());
|
||||
emitVerilogFormat(nodep, nodep->emitVerilog(), nodep->lhsp(), nodep->rhsp(), nodep->thsp());
|
||||
}
|
||||
virtual void visit(AstAttrOf* nodep) {
|
||||
putfs(nodep,"$_ATTROF(");
|
||||
putfs(nodep, "$_ATTROF(");
|
||||
iterateAndNextNull(nodep->fromp());
|
||||
if (nodep->dimp()) {
|
||||
putbs(",");
|
||||
if (nodep->dimp()) {
|
||||
putbs(",");
|
||||
iterateAndNextNull(nodep->dimp());
|
||||
}
|
||||
puts(")");
|
||||
}
|
||||
puts(")");
|
||||
}
|
||||
virtual void visit(AstInitArray* nodep) {
|
||||
putfs(nodep,"`{");
|
||||
int pos = 0;
|
||||
for (AstNode* itemp = nodep->initsp(); itemp; ++pos, itemp=itemp->nextp()) {
|
||||
int index = nodep->posIndex(pos);
|
||||
puts(cvtToStr(index));
|
||||
puts(":");
|
||||
putfs(nodep, "`{");
|
||||
int pos = 0;
|
||||
for (AstNode* itemp = nodep->initsp(); itemp; ++pos, itemp=itemp->nextp()) {
|
||||
int index = nodep->posIndex(pos);
|
||||
puts(cvtToStr(index));
|
||||
puts(":");
|
||||
iterate(itemp);
|
||||
if (itemp->nextp()) putbs(",");
|
||||
}
|
||||
puts("}");
|
||||
if (itemp->nextp()) putbs(",");
|
||||
}
|
||||
puts("}");
|
||||
}
|
||||
virtual void visit(AstNodeCond* nodep) {
|
||||
putbs("(");
|
||||
iterateAndNextNull(nodep->condp()); putfs(nodep," ? ");
|
||||
putbs("(");
|
||||
iterateAndNextNull(nodep->condp()); putfs(nodep, " ? ");
|
||||
iterateAndNextNull(nodep->expr1p()); putbs(" : ");
|
||||
iterateAndNextNull(nodep->expr2p()); puts(")");
|
||||
}
|
||||
virtual void visit(AstRange* nodep) {
|
||||
puts("[");
|
||||
puts("[");
|
||||
if (VN_IS(nodep->msbp(), Const) && VN_IS(nodep->lsbp(), Const)) {
|
||||
// Looks nicer if we print [1:0] rather than [32'sh1:32sh0]
|
||||
// Looks nicer if we print [1:0] rather than [32'sh1:32sh0]
|
||||
puts(cvtToStr(VN_CAST(nodep->leftp(), Const)->toSInt())); puts(":");
|
||||
puts(cvtToStr(VN_CAST(nodep->rightp(), Const)->toSInt())); puts("]");
|
||||
} else {
|
||||
} else {
|
||||
iterateAndNextNull(nodep->leftp()); puts(":");
|
||||
iterateAndNextNull(nodep->rightp()); puts("]");
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstSel* nodep) {
|
||||
iterateAndNextNull(nodep->fromp()); puts("[");
|
||||
if (VN_IS(nodep->lsbp(), Const)) {
|
||||
if (nodep->widthp()->isOne()) {
|
||||
if (nodep->widthp()->isOne()) {
|
||||
if (VN_IS(nodep->lsbp(), Const)) {
|
||||
puts(cvtToStr(VN_CAST(nodep->lsbp(), Const)->toSInt()));
|
||||
} else {
|
||||
} else {
|
||||
iterateAndNextNull(nodep->lsbp());
|
||||
}
|
||||
} else {
|
||||
}
|
||||
} else {
|
||||
puts(cvtToStr(VN_CAST(nodep->lsbp(), Const)->toSInt()
|
||||
+ VN_CAST(nodep->widthp(), Const)->toSInt()
|
||||
- 1));
|
||||
puts(":");
|
||||
puts(":");
|
||||
puts(cvtToStr(VN_CAST(nodep->lsbp(), Const)->toSInt()));
|
||||
}
|
||||
} else {
|
||||
iterateAndNextNull(nodep->lsbp()); putfs(nodep,"+:");
|
||||
}
|
||||
} else {
|
||||
iterateAndNextNull(nodep->lsbp()); putfs(nodep, "+:");
|
||||
iterateAndNextNull(nodep->widthp()); puts("]");
|
||||
}
|
||||
puts("]");
|
||||
}
|
||||
puts("]");
|
||||
}
|
||||
virtual void visit(AstSliceSel* nodep) {
|
||||
iterateAndNextNull(nodep->fromp());
|
||||
puts(cvtToStr(nodep->declRange()));
|
||||
}
|
||||
virtual void visit(AstTypedef* nodep) {
|
||||
putfs(nodep,"typedef ");
|
||||
putfs(nodep, "typedef ");
|
||||
iterateAndNextNull(nodep->dtypep()); puts(" ");
|
||||
puts(nodep->prettyName());
|
||||
puts(";\n");
|
||||
puts(nodep->prettyName());
|
||||
puts(";\n");
|
||||
}
|
||||
virtual void visit(AstBasicDType* nodep) {
|
||||
if (nodep->isSigned()) putfs(nodep,"signed ");
|
||||
putfs(nodep,nodep->prettyName());
|
||||
if (nodep->isSigned()) putfs(nodep, "signed ");
|
||||
putfs(nodep, nodep->prettyName());
|
||||
if (nodep->rangep()) { puts(" "); iterateAndNextNull(nodep->rangep()); puts(" "); }
|
||||
else if (nodep->isRanged()) { puts(" ["); puts(cvtToStr(nodep->msb())); puts(":0] "); }
|
||||
else if (nodep->isRanged()) { puts(" ["); puts(cvtToStr(nodep->msb())); puts(":0] "); }
|
||||
}
|
||||
virtual void visit(AstConstDType* nodep) {
|
||||
putfs(nodep,"const ");
|
||||
putfs(nodep, "const ");
|
||||
iterate(nodep->subDTypep());
|
||||
}
|
||||
virtual void visit(AstNodeArrayDType* nodep) {
|
||||
|
|
@ -526,24 +527,25 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
iterateAndNextNull(nodep->rangep());
|
||||
}
|
||||
virtual void visit(AstNodeClassDType* nodep) {
|
||||
puts(nodep->verilogKwd()+" ");
|
||||
if (nodep->packed()) puts("packed ");
|
||||
puts("\n");
|
||||
puts(nodep->verilogKwd()+" ");
|
||||
if (nodep->packed()) puts("packed ");
|
||||
puts("\n");
|
||||
iterateAndNextNull(nodep->membersp());
|
||||
puts("}");
|
||||
puts("}");
|
||||
}
|
||||
virtual void visit(AstMemberDType* nodep) {
|
||||
iterate(nodep->subDTypep());
|
||||
puts(" ");
|
||||
puts(nodep->name());
|
||||
puts("}");
|
||||
puts(" ");
|
||||
puts(nodep->name());
|
||||
puts("}");
|
||||
}
|
||||
virtual void visit(AstNodeFTaskRef* nodep) {
|
||||
if (nodep->dotted()!="") { putfs(nodep,nodep->dotted()); puts("."); puts(nodep->prettyName()); }
|
||||
else { putfs(nodep,nodep->prettyName()); }
|
||||
puts("(");
|
||||
if (nodep->dotted()!="") {
|
||||
putfs(nodep, nodep->dotted()); puts("."); puts(nodep->prettyName());
|
||||
} else { putfs(nodep, nodep->prettyName()); }
|
||||
puts("(");
|
||||
iterateAndNextNull(nodep->pinsp());
|
||||
puts(")");
|
||||
puts(")");
|
||||
}
|
||||
virtual void visit(AstArg* nodep) {
|
||||
iterateAndNextNull(nodep->exprp());
|
||||
|
|
@ -551,19 +553,19 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
// Terminals
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
if (nodep->varScopep()) {
|
||||
putfs(nodep,nodep->varScopep()->prettyName());
|
||||
putfs(nodep, nodep->varScopep()->prettyName());
|
||||
} else {
|
||||
putfs(nodep,nodep->hiername());
|
||||
puts(nodep->varp()->prettyName());
|
||||
}
|
||||
putfs(nodep, nodep->hiername());
|
||||
puts(nodep->varp()->prettyName());
|
||||
}
|
||||
}
|
||||
virtual void visit(AstVarXRef* nodep) {
|
||||
putfs(nodep,nodep->dotted());
|
||||
puts(".");
|
||||
puts(nodep->varp()->prettyName());
|
||||
putfs(nodep, nodep->dotted());
|
||||
puts(".");
|
||||
puts(nodep->varp()->prettyName());
|
||||
}
|
||||
virtual void visit(AstConst* nodep) {
|
||||
putfs(nodep,nodep->num().ascii(true,true));
|
||||
putfs(nodep, nodep->num().ascii(true, true));
|
||||
}
|
||||
|
||||
// Just iterate
|
||||
|
|
@ -574,16 +576,16 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstVar* nodep) {
|
||||
putfs(nodep,nodep->verilogKwd());
|
||||
puts(" ");
|
||||
putfs(nodep, nodep->verilogKwd());
|
||||
puts(" ");
|
||||
iterate(nodep->dtypep()); puts(" ");
|
||||
puts(nodep->prettyName());
|
||||
puts(";\n");
|
||||
puts(nodep->prettyName());
|
||||
puts(";\n");
|
||||
}
|
||||
virtual void visit(AstActive* nodep) {
|
||||
m_sensesp = nodep->sensesp();
|
||||
m_sensesp = nodep->sensesp();
|
||||
iterateAndNextNull(nodep->stmtsp());
|
||||
m_sensesp = NULL;
|
||||
m_sensesp = NULL;
|
||||
}
|
||||
virtual void visit(AstVarScope*) {}
|
||||
virtual void visit(AstNodeText*) {}
|
||||
|
|
@ -591,19 +593,20 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
|
|||
virtual void visit(AstTraceInc*) {}
|
||||
// NOPs
|
||||
virtual void visit(AstPragma*) {}
|
||||
virtual void visit(AstCell*) {} // Handled outside the Visit class
|
||||
virtual void visit(AstCell*) {} // Handled outside the Visit class
|
||||
// Default
|
||||
virtual void visit(AstNode* nodep) {
|
||||
puts(string("\n???? // ")+nodep->prettyTypeName()+"\n");
|
||||
iterateChildren(nodep);
|
||||
// Not v3fatalSrc so we keep processing
|
||||
nodep->v3error("Internal: Unknown node type reached emitter: "<<nodep->prettyTypeName());
|
||||
// Not v3fatalSrc so we keep processing
|
||||
nodep->v3error("Internal: Unknown node type reached emitter: "<<nodep->prettyTypeName());
|
||||
}
|
||||
|
||||
public:
|
||||
explicit EmitVBaseVisitor(AstSenTree* domainp=NULL) { // Domain for printing one a ALWAYS under a ACTIVE
|
||||
m_suppressSemi = false;
|
||||
m_sensesp = domainp;
|
||||
explicit EmitVBaseVisitor(AstSenTree* domainp=NULL) {
|
||||
// Domain for printing one a ALWAYS under a ACTIVE
|
||||
m_suppressSemi = false;
|
||||
m_sensesp = domainp;
|
||||
}
|
||||
virtual ~EmitVBaseVisitor() {}
|
||||
};
|
||||
|
|
@ -613,9 +616,9 @@ public:
|
|||
|
||||
class EmitVFileVisitor : public EmitVBaseVisitor {
|
||||
// MEMBERS
|
||||
V3OutFile* m_ofp;
|
||||
V3OutFile* m_ofp;
|
||||
// METHODS
|
||||
V3OutFile* ofp() const { return m_ofp; }
|
||||
V3OutFile* ofp() const { return m_ofp; }
|
||||
virtual void puts(const string& str) { ofp()->puts(str); }
|
||||
virtual void putbs(const string& str) { ofp()->putbs(str); }
|
||||
virtual void putfs(AstNode*, const string& str) { putbs(str); }
|
||||
|
|
@ -623,7 +626,7 @@ class EmitVFileVisitor : public EmitVBaseVisitor {
|
|||
virtual void putsNoTracking(const string& str) { ofp()->putsNoTracking(str); }
|
||||
public:
|
||||
EmitVFileVisitor(AstNode* nodep, V3OutFile* ofp) {
|
||||
m_ofp = ofp;
|
||||
m_ofp = ofp;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~EmitVFileVisitor() {}
|
||||
|
|
@ -643,7 +646,7 @@ class EmitVStreamVisitor : public EmitVBaseVisitor {
|
|||
virtual void putqs(AstNode*, const string& str) { putbs(str); }
|
||||
public:
|
||||
EmitVStreamVisitor(AstNode* nodep, std::ostream& os)
|
||||
: m_os(os) {
|
||||
: m_os(os) {
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~EmitVStreamVisitor() {}
|
||||
|
|
@ -654,67 +657,67 @@ public:
|
|||
|
||||
class EmitVPrefixedFormatter : public V3OutFormatter {
|
||||
std::ostream& m_os;
|
||||
string m_prefix; // What to print at beginning of each line
|
||||
int m_flWidth; // Padding of fileline
|
||||
int m_column; // Rough location; need just zero or non-zero
|
||||
FileLine* m_prefixFl;
|
||||
string m_prefix; // What to print at beginning of each line
|
||||
int m_flWidth; // Padding of fileline
|
||||
int m_column; // Rough location; need just zero or non-zero
|
||||
FileLine* m_prefixFl;
|
||||
// METHODS
|
||||
virtual void putcOutput(char chr) {
|
||||
if (chr == '\n') {
|
||||
m_column = 0;
|
||||
m_os<<chr;
|
||||
} else {
|
||||
if (m_column == 0) {
|
||||
m_column = 10;
|
||||
m_os<<m_prefixFl->ascii()+":";
|
||||
m_os<<V3OutFile::indentSpaces(m_flWidth-(m_prefixFl->ascii().length()+1));
|
||||
m_os<<" ";
|
||||
m_os<<m_prefix;
|
||||
}
|
||||
m_column++;
|
||||
m_os<<chr;
|
||||
}
|
||||
if (chr == '\n') {
|
||||
m_column = 0;
|
||||
m_os<<chr;
|
||||
} else {
|
||||
if (m_column == 0) {
|
||||
m_column = 10;
|
||||
m_os<<m_prefixFl->ascii()+":";
|
||||
m_os<<V3OutFile::indentSpaces(m_flWidth-(m_prefixFl->ascii().length()+1));
|
||||
m_os<<" ";
|
||||
m_os<<m_prefix;
|
||||
}
|
||||
m_column++;
|
||||
m_os<<chr;
|
||||
}
|
||||
}
|
||||
public:
|
||||
void prefixFl(FileLine* fl) { m_prefixFl = fl; }
|
||||
FileLine* prefixFl() const { return m_prefixFl; }
|
||||
int column() const { return m_column; }
|
||||
EmitVPrefixedFormatter(std::ostream& os, const string& prefix, int flWidth)
|
||||
: V3OutFormatter("__STREAM", V3OutFormatter::LA_VERILOG)
|
||||
, m_os(os), m_prefix(prefix), m_flWidth(flWidth) {
|
||||
m_column = 0;
|
||||
m_prefixFl = v3Global.rootp()->fileline(); // NETLIST's fileline instead of NULL to avoid NULL checks
|
||||
: V3OutFormatter("__STREAM", V3OutFormatter::LA_VERILOG)
|
||||
, m_os(os), m_prefix(prefix), m_flWidth(flWidth) {
|
||||
m_column = 0;
|
||||
m_prefixFl = v3Global.rootp()->fileline(); // NETLIST's fileline instead of NULL to avoid NULL checks
|
||||
}
|
||||
virtual ~EmitVPrefixedFormatter() {
|
||||
if (m_column) puts("\n");
|
||||
if (m_column) puts("\n");
|
||||
}
|
||||
};
|
||||
|
||||
class EmitVPrefixedVisitor : public EmitVBaseVisitor {
|
||||
// MEMBERS
|
||||
EmitVPrefixedFormatter m_formatter; // Special verilog formatter (Way down the inheritance is another unused V3OutFormatter)
|
||||
EmitVPrefixedFormatter m_formatter; // Special verilog formatter (Way down the inheritance is another unused V3OutFormatter)
|
||||
// METHODS
|
||||
virtual void putsNoTracking(const string& str) { m_formatter.putsNoTracking(str); }
|
||||
virtual void puts(const string& str) { m_formatter.puts(str); }
|
||||
// We don't use m_formatter's putbs because the tokens will change filelines
|
||||
// and insert returns at the proper locations
|
||||
virtual void putbs(const string& str) { m_formatter.puts(str); }
|
||||
virtual void putfs(AstNode* nodep, const string& str) { putfsqs(nodep,str,false); }
|
||||
virtual void putqs(AstNode* nodep, const string& str) { putfsqs(nodep,str,true); }
|
||||
virtual void putfs(AstNode* nodep, const string& str) { putfsqs(nodep, str, false); }
|
||||
virtual void putqs(AstNode* nodep, const string& str) { putfsqs(nodep, str, true); }
|
||||
void putfsqs(AstNode* nodep, const string& str, bool quiet) {
|
||||
if (m_formatter.prefixFl() != nodep->fileline()) {
|
||||
m_formatter.prefixFl(nodep->fileline());
|
||||
if (m_formatter.column()) puts("\n"); // This in turn will print the m_prefixFl
|
||||
}
|
||||
if (!quiet && nodep->user3()) puts("%%");
|
||||
putbs(str);
|
||||
if (m_formatter.prefixFl() != nodep->fileline()) {
|
||||
m_formatter.prefixFl(nodep->fileline());
|
||||
if (m_formatter.column()) puts("\n"); // This in turn will print the m_prefixFl
|
||||
}
|
||||
if (!quiet && nodep->user3()) puts("%%");
|
||||
putbs(str);
|
||||
}
|
||||
|
||||
public:
|
||||
EmitVPrefixedVisitor(AstNode* nodep, std::ostream& os, const string& prefix, int flWidth,
|
||||
AstSenTree* domainp, bool user3mark)
|
||||
: EmitVBaseVisitor(domainp), m_formatter(os, prefix, flWidth) {
|
||||
if (user3mark) { AstUser3InUse::check(); }
|
||||
AstSenTree* domainp, bool user3mark)
|
||||
: EmitVBaseVisitor(domainp), m_formatter(os, prefix, flWidth) {
|
||||
if (user3mark) { AstUser3InUse::check(); }
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~EmitVPrefixedVisitor() {}
|
||||
|
|
@ -726,19 +729,20 @@ public:
|
|||
void V3EmitV::emitv() {
|
||||
UINFO(2,__FUNCTION__<<": "<<endl);
|
||||
if (1) {
|
||||
// All-in-one file
|
||||
V3OutVFile of (v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"__Vout.v");
|
||||
of.putsHeader();
|
||||
of.puts("# DESCR" "IPTION: Verilator output: Verilog representation of internal tree for debug\n");
|
||||
EmitVFileVisitor visitor (v3Global.rootp(), &of);
|
||||
// All-in-one file
|
||||
V3OutVFile of (v3Global.opt.makeDir()+"/"+v3Global.opt.prefix()+"__Vout.v");
|
||||
of.putsHeader();
|
||||
of.puts("# DESCR" "IPTION: Verilator output: Verilog representation of internal tree for debug\n");
|
||||
EmitVFileVisitor visitor (v3Global.rootp(), &of);
|
||||
} else {
|
||||
// Process each module in turn
|
||||
for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; modp=VN_CAST(modp->nextp(), NodeModule)) {
|
||||
V3OutVFile of (v3Global.opt.makeDir()
|
||||
+"/"+EmitCBaseVisitor::modClassName(modp)+"__Vout.v");
|
||||
of.putsHeader();
|
||||
EmitVFileVisitor visitor (modp, &of);
|
||||
}
|
||||
// Process each module in turn
|
||||
for (AstNodeModule* modp = v3Global.rootp()->modulesp();
|
||||
modp; modp=VN_CAST(modp->nextp(), NodeModule)) {
|
||||
V3OutVFile of (v3Global.opt.makeDir()
|
||||
+"/"+EmitCBaseVisitor::modClassName(modp)+"__Vout.v");
|
||||
of.putsHeader();
|
||||
EmitVFileVisitor visitor (modp, &of);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -746,7 +750,8 @@ void V3EmitV::verilogForTree(AstNode* nodep, std::ostream& os) {
|
|||
EmitVStreamVisitor(nodep, os);
|
||||
}
|
||||
|
||||
void V3EmitV::verilogPrefixedTree(AstNode* nodep, std::ostream& os, const string& prefix, int flWidth,
|
||||
AstSenTree* domainp, bool user3mark) {
|
||||
void V3EmitV::verilogPrefixedTree(AstNode* nodep, std::ostream& os,
|
||||
const string& prefix, int flWidth,
|
||||
AstSenTree* domainp, bool user3mark) {
|
||||
EmitVPrefixedVisitor(nodep, os, prefix, flWidth, domainp, user3mark);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -33,8 +33,9 @@ class V3EmitV {
|
|||
public:
|
||||
static void emitv();
|
||||
static void verilogForTree(AstNode* nodep, std::ostream& os=std::cout);
|
||||
static void verilogPrefixedTree(AstNode* nodep, std::ostream& os, const string& prefix, int flWidth,
|
||||
static void verilogPrefixedTree(AstNode* nodep, std::ostream& os,
|
||||
const string& prefix, int flWidth,
|
||||
AstSenTree* domainp, bool user3mark);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -41,78 +41,80 @@ class EmitXmlFileVisitor : public AstNVisitor {
|
|||
// AstNode::user1 -> uint64_t, number to connect crossrefs
|
||||
|
||||
// MEMBERS
|
||||
V3OutFile* m_ofp;
|
||||
uint64_t m_id;
|
||||
V3OutFile* m_ofp;
|
||||
uint64_t m_id;
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// Outfile methods
|
||||
V3OutFile* ofp() const { return m_ofp; }
|
||||
V3OutFile* ofp() const { return m_ofp; }
|
||||
virtual void puts(const string& str) { ofp()->puts(str); }
|
||||
virtual void putbs(const string& str) { ofp()->putbs(str); }
|
||||
virtual void putfs(AstNode*, const string& str) { putbs(str); }
|
||||
virtual void putqs(AstNode*, const string& str) { putbs(str); }
|
||||
virtual void putsNoTracking(const string& str) { ofp()->putsNoTracking(str); }
|
||||
virtual void putsQuoted(const string& str) {
|
||||
// Quote \ and " for use inside C programs
|
||||
// Don't use to quote a filename for #include - #include doesn't \ escape.
|
||||
// Duplicate in V3File - here so we can print to string
|
||||
putsNoTracking("\"");
|
||||
// Quote \ and " for use inside C programs
|
||||
// Don't use to quote a filename for #include - #include doesn't \ escape.
|
||||
// Duplicate in V3File - here so we can print to string
|
||||
putsNoTracking("\"");
|
||||
putsNoTracking(V3OutFormatter::quoteNameControls(str));
|
||||
putsNoTracking("\"");
|
||||
putsNoTracking("\"");
|
||||
}
|
||||
|
||||
// XML methods
|
||||
void outputId(AstNode* nodep) {
|
||||
if (!nodep->user1()) { nodep->user1(++m_id); }
|
||||
puts("\""+cvtToStr(nodep->user1())+"\"");
|
||||
if (!nodep->user1()) { nodep->user1(++m_id); }
|
||||
puts("\""+cvtToStr(nodep->user1())+"\"");
|
||||
}
|
||||
void outputTag(AstNode* nodep, string tag) {
|
||||
if (tag=="") tag = VString::downcase(nodep->typeName());
|
||||
puts("<"+tag+" "+nodep->fileline()->xml());
|
||||
if (tag=="") tag = VString::downcase(nodep->typeName());
|
||||
puts("<"+tag+" "+nodep->fileline()->xml());
|
||||
if (VN_IS(nodep, NodeDType)) { puts(" id="); outputId(nodep); }
|
||||
if (nodep->name()!="") { puts(" name="); putsQuoted(nodep->prettyName()); }
|
||||
if (nodep->tag()!="") { puts(" tag="); putsQuoted(nodep->tag()); }
|
||||
if (nodep->name()!="") { puts(" name="); putsQuoted(nodep->prettyName()); }
|
||||
if (nodep->tag()!="") { puts(" tag="); putsQuoted(nodep->tag()); }
|
||||
if (AstNodeDType* dtp = VN_CAST(nodep, NodeDType)) {
|
||||
if (dtp->subDTypep()) { puts(" sub_dtype_id="); outputId(dtp->subDTypep()->skipRefp()); }
|
||||
} else {
|
||||
if (nodep->dtypep()) { puts(" dtype_id="); outputId(nodep->dtypep()->skipRefp()); }
|
||||
}
|
||||
if (dtp->subDTypep()) {
|
||||
puts(" sub_dtype_id="); outputId(dtp->subDTypep()->skipRefp());
|
||||
}
|
||||
} else {
|
||||
if (nodep->dtypep()) { puts(" dtype_id="); outputId(nodep->dtypep()->skipRefp()); }
|
||||
}
|
||||
}
|
||||
void outputChildrenEnd(AstNode* nodep, string tag) {
|
||||
if (tag=="") tag = VString::downcase(nodep->typeName());
|
||||
if (nodep->op1p() || nodep->op2p() || nodep->op3p() || nodep->op4p()) {
|
||||
puts(">\n");
|
||||
if (tag=="") tag = VString::downcase(nodep->typeName());
|
||||
if (nodep->op1p() || nodep->op2p() || nodep->op3p() || nodep->op4p()) {
|
||||
puts(">\n");
|
||||
iterateChildren(nodep);
|
||||
puts("</"+tag+">\n");
|
||||
} else {
|
||||
puts("/>\n");
|
||||
}
|
||||
puts("</"+tag+">\n");
|
||||
} else {
|
||||
puts("/>\n");
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstAssignW* nodep) {
|
||||
outputTag(nodep, "contassign"); // IEEE: vpiContAssign
|
||||
outputTag(nodep, "contassign"); // IEEE: vpiContAssign
|
||||
outputChildrenEnd(nodep, "contassign");
|
||||
}
|
||||
virtual void visit(AstCell* nodep) {
|
||||
outputTag(nodep, "instance"); // IEEE: vpiInstance
|
||||
outputTag(nodep, "instance"); // IEEE: vpiInstance
|
||||
puts(" defName="); putsQuoted(nodep->modName()); // IEEE vpiDefName
|
||||
puts(" origName="); putsQuoted(nodep->origName());
|
||||
outputChildrenEnd(nodep, "instance");
|
||||
}
|
||||
virtual void visit(AstNetlist* nodep) {
|
||||
puts("<netlist>\n");
|
||||
puts("<netlist>\n");
|
||||
iterateChildren(nodep);
|
||||
puts("</netlist>\n");
|
||||
puts("</netlist>\n");
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
outputTag(nodep, "");
|
||||
puts(" origName="); putsQuoted(nodep->origName());
|
||||
if (nodep->level()==1 || nodep->level()==2) // ==2 because we don't add wrapper when in XML mode
|
||||
puts(" topModule=\"1\""); // IEEE vpiTopModule
|
||||
outputChildrenEnd(nodep, "");
|
||||
outputTag(nodep, "");
|
||||
puts(" origName="); putsQuoted(nodep->origName());
|
||||
if (nodep->level()==1 || nodep->level()==2) // ==2 because we don't add wrapper when in XML mode
|
||||
puts(" topModule=\"1\""); // IEEE vpiTopModule
|
||||
outputChildrenEnd(nodep, "");
|
||||
}
|
||||
virtual void visit(AstVar* nodep) {
|
||||
AstVarType typ = nodep->varType();
|
||||
|
|
@ -126,8 +128,8 @@ class EmitXmlFileVisitor : public AstNVisitor {
|
|||
} else {
|
||||
puts(" vartype="); putsQuoted(!vt.empty() ? vt : kw);
|
||||
}
|
||||
puts(" origName="); putsQuoted(nodep->origName());
|
||||
outputChildrenEnd(nodep, "");
|
||||
puts(" origName="); putsQuoted(nodep->origName());
|
||||
outputChildrenEnd(nodep, "");
|
||||
}
|
||||
virtual void visit(AstPin* nodep) {
|
||||
// What we call a pin in verilator is a port in the IEEE spec.
|
||||
|
|
@ -159,12 +161,12 @@ class EmitXmlFileVisitor : public AstNVisitor {
|
|||
|
||||
// Data types
|
||||
virtual void visit(AstBasicDType* nodep) {
|
||||
outputTag(nodep, "basicdtype ");
|
||||
if (nodep->isRanged()) {
|
||||
puts(" left=\""+cvtToStr(nodep->left())+"\"");
|
||||
puts(" right=\""+cvtToStr(nodep->right())+"\"");
|
||||
}
|
||||
puts("/>\n");
|
||||
outputTag(nodep, "basicdtype ");
|
||||
if (nodep->isRanged()) {
|
||||
puts(" left=\""+cvtToStr(nodep->left())+"\"");
|
||||
puts(" right=\""+cvtToStr(nodep->right())+"\"");
|
||||
}
|
||||
puts("/>\n");
|
||||
}
|
||||
virtual void visit(AstIfaceRefDType* nodep) {
|
||||
string mpn;
|
||||
|
|
@ -193,13 +195,13 @@ class EmitXmlFileVisitor : public AstNVisitor {
|
|||
|
||||
// Default
|
||||
virtual void visit(AstNode* nodep) {
|
||||
outputTag(nodep, "");
|
||||
outputChildrenEnd(nodep, "");
|
||||
outputTag(nodep, "");
|
||||
outputChildrenEnd(nodep, "");
|
||||
}
|
||||
public:
|
||||
EmitXmlFileVisitor(AstNode* nodep, V3OutFile* ofp) {
|
||||
m_ofp = ofp;
|
||||
m_id = 0;
|
||||
m_ofp = ofp;
|
||||
m_id = 0;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~EmitXmlFileVisitor() {}
|
||||
|
|
@ -336,9 +338,9 @@ void V3EmitXml::emitxml() {
|
|||
of.puts("<!-- DESCR" "IPTION: Verilator output: XML representation of netlist -->\n");
|
||||
of.puts("<verilator_xml>\n");
|
||||
{
|
||||
std::stringstream sstr;
|
||||
FileLine::fileNameNumMapDumpXml(sstr);
|
||||
of.puts(sstr.str());
|
||||
std::stringstream sstr;
|
||||
FileLine::fileNameNumMapDumpXml(sstr);
|
||||
of.puts(sstr.str());
|
||||
}
|
||||
{
|
||||
std::stringstream sstr;
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void emitxml();
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
121
src/V3Error.cpp
121
src/V3Error.cpp
|
|
@ -57,9 +57,9 @@ V3ErrorCode::V3ErrorCode(const char* msgp) {
|
|||
// Return error encoding for given string, or ERROR, which is a bad code
|
||||
for (int codei=V3ErrorCode::EC_MIN; codei<V3ErrorCode::_ENUM_MAX; codei++) {
|
||||
V3ErrorCode code = V3ErrorCode(codei);
|
||||
if (0==strcasecmp(msgp,code.ascii())) {
|
||||
m_e = code; return;
|
||||
}
|
||||
if (0==strcasecmp(msgp, code.ascii())) {
|
||||
m_e = code; return;
|
||||
}
|
||||
}
|
||||
m_e = V3ErrorCode::EC_ERROR;
|
||||
}
|
||||
|
|
@ -69,12 +69,12 @@ V3ErrorCode::V3ErrorCode(const char* msgp) {
|
|||
|
||||
void V3Error::init() {
|
||||
for (int i=0; i<V3ErrorCode::_ENUM_MAX; i++) {
|
||||
s_describedEachWarn[i] = false;
|
||||
s_pretendError[i] = V3ErrorCode(i).pretendError();
|
||||
s_describedEachWarn[i] = false;
|
||||
s_pretendError[i] = V3ErrorCode(i).pretendError();
|
||||
}
|
||||
|
||||
if (string(V3ErrorCode(V3ErrorCode::_ENUM_MAX).ascii()) != " MAX") {
|
||||
v3fatalSrc("Enum table in V3ErrorCode::EC_ascii() is munged");
|
||||
v3fatalSrc("Enum table in V3ErrorCode::EC_ascii() is munged");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,7 +99,8 @@ void V3Error::incErrors() {
|
|||
void V3Error::abortIfWarnings() {
|
||||
bool exwarn = warnFatal() && warnCount();
|
||||
if (errorCount() && exwarn) {
|
||||
v3fatal("Exiting due to "<<std::dec<<errorCount()<<" error(s), "<<warnCount()<<" warning(s)\n");
|
||||
v3fatal("Exiting due to "<<std::dec<<errorCount()<<" error(s), "
|
||||
<<warnCount()<<" warning(s)\n");
|
||||
} else if (errorCount()) {
|
||||
v3fatal("Exiting due to "<<std::dec<<errorCount()<<" error(s)\n");
|
||||
} else if (exwarn) {
|
||||
|
|
@ -115,13 +116,13 @@ bool V3Error::isError(V3ErrorCode code, bool supp) {
|
|||
else if (code==V3ErrorCode::EC_FATALSRC) return true;
|
||||
else if (code==V3ErrorCode::EC_ERROR) return true;
|
||||
else if (code<V3ErrorCode::EC_FIRST_WARN
|
||||
|| s_pretendError[code]) return true;
|
||||
|| s_pretendError[code]) return true;
|
||||
else return false;
|
||||
}
|
||||
|
||||
string V3Error::msgPrefix() {
|
||||
V3ErrorCode code=s_errorCode;
|
||||
bool supp=s_errorSuppressed;
|
||||
V3ErrorCode code = s_errorCode;
|
||||
bool supp = s_errorSuppressed;
|
||||
if (supp) return "-arning-suppressed: ";
|
||||
else if (code==V3ErrorCode::USERINFO) return "-Info: ";
|
||||
else if (code==V3ErrorCode::EC_INFO) return "-Info: ";
|
||||
|
|
@ -138,9 +139,9 @@ string V3Error::msgPrefix() {
|
|||
void V3Error::vlAbort() {
|
||||
if (V3Error::debugDefault()) {
|
||||
std::cerr<<msgPrefix()<<"Aborting since under --debug"<<endl;
|
||||
abort();
|
||||
abort();
|
||||
} else {
|
||||
exit(10);
|
||||
exit(10);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -150,9 +151,9 @@ void V3Error::vlAbort() {
|
|||
void V3Error::suppressThisWarning() {
|
||||
if (s_errorCode>=V3ErrorCode::EC_MIN) {
|
||||
#ifndef _V3ERROR_NO_GLOBAL_
|
||||
V3Stats::addStatSum(string("Warnings, Suppressed ")+s_errorCode.ascii(), 1);
|
||||
V3Stats::addStatSum(string("Warnings, Suppressed ")+s_errorCode.ascii(), 1);
|
||||
#endif
|
||||
s_errorSuppressed = true;
|
||||
s_errorSuppressed = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -166,8 +167,8 @@ void V3Error::v3errorEnd(std::ostringstream& sstr) {
|
|||
#endif
|
||||
// Skip suppressed messages
|
||||
if (s_errorSuppressed
|
||||
// On debug, show only non default-off warning to prevent pages of warnings
|
||||
&& (!debug() || s_errorCode.defaultsOff())) return;
|
||||
// On debug, show only non default-off warning to prevent pages of warnings
|
||||
&& (!debug() || s_errorCode.defaultsOff())) return;
|
||||
string msg = msgPrefix()+sstr.str();
|
||||
if (msg[msg.length()-1] != '\n') msg += '\n';
|
||||
// Suppress duplicates
|
||||
|
|
@ -176,57 +177,57 @@ void V3Error::v3errorEnd(std::ostringstream& sstr) {
|
|||
// Output
|
||||
std::cerr<<msg;
|
||||
if (!s_errorSuppressed && !(s_errorCode==V3ErrorCode::EC_INFO
|
||||
|| s_errorCode==V3ErrorCode::USERINFO)) {
|
||||
if (!s_describedEachWarn[s_errorCode]
|
||||
&& !s_pretendError[s_errorCode]) {
|
||||
s_describedEachWarn[s_errorCode] = true;
|
||||
if (s_errorCode>=V3ErrorCode::EC_FIRST_WARN && !s_describedWarnings) {
|
||||
|| s_errorCode==V3ErrorCode::USERINFO)) {
|
||||
if (!s_describedEachWarn[s_errorCode]
|
||||
&& !s_pretendError[s_errorCode]) {
|
||||
s_describedEachWarn[s_errorCode] = true;
|
||||
if (s_errorCode>=V3ErrorCode::EC_FIRST_WARN && !s_describedWarnings) {
|
||||
std::cerr<<msgPrefix()<<"Use \"/* verilator lint_off "<<s_errorCode.ascii()
|
||||
<<" */\" and lint_on around source to disable this message."<<endl;
|
||||
s_describedWarnings = true;
|
||||
}
|
||||
if (s_errorCode.dangerous()) {
|
||||
s_describedWarnings = true;
|
||||
}
|
||||
if (s_errorCode.dangerous()) {
|
||||
std::cerr<<msgPrefix()<<"*** See the manual before disabling this,"<<endl;
|
||||
std::cerr<<msgPrefix()<<"else you may end up with different sim results."<<endl;
|
||||
}
|
||||
}
|
||||
// If first warning is not the user's fault (internal/unsupported) then give the website
|
||||
// Not later warnings, as a internal may be caused by an earlier problem
|
||||
if (s_tellManual == 0) {
|
||||
if (s_errorCode.mentionManual()
|
||||
|| sstr.str().find("Unsupported") != string::npos) {
|
||||
s_tellManual = 1;
|
||||
} else {
|
||||
s_tellManual = 2;
|
||||
}
|
||||
}
|
||||
if (isError(s_errorCode, s_errorSuppressed)) incErrors();
|
||||
else incWarnings();
|
||||
if (s_errorCode==V3ErrorCode::EC_FATAL
|
||||
|| s_errorCode==V3ErrorCode::EC_FATALSRC) {
|
||||
static bool inFatal = false;
|
||||
if (!inFatal) {
|
||||
inFatal = true;
|
||||
if (s_tellManual==1) {
|
||||
}
|
||||
}
|
||||
// If first warning is not the user's fault (internal/unsupported) then give the website
|
||||
// Not later warnings, as a internal may be caused by an earlier problem
|
||||
if (s_tellManual == 0) {
|
||||
if (s_errorCode.mentionManual()
|
||||
|| sstr.str().find("Unsupported") != string::npos) {
|
||||
s_tellManual = 1;
|
||||
} else {
|
||||
s_tellManual = 2;
|
||||
}
|
||||
}
|
||||
if (isError(s_errorCode, s_errorSuppressed)) incErrors();
|
||||
else incWarnings();
|
||||
if (s_errorCode==V3ErrorCode::EC_FATAL
|
||||
|| s_errorCode==V3ErrorCode::EC_FATALSRC) {
|
||||
static bool inFatal = false;
|
||||
if (!inFatal) {
|
||||
inFatal = true;
|
||||
if (s_tellManual==1) {
|
||||
std::cerr<<msgPrefix()<<"See the manual and http://www.veripool.org/verilator for more assistance."<<endl;
|
||||
s_tellManual = 2;
|
||||
}
|
||||
s_tellManual = 2;
|
||||
}
|
||||
#ifndef _V3ERROR_NO_GLOBAL_
|
||||
if (debug()) {
|
||||
v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("final.tree",990));
|
||||
if (s_errorExitCb) s_errorExitCb();
|
||||
V3Stats::statsFinalAll(v3Global.rootp());
|
||||
V3Stats::statsReport();
|
||||
}
|
||||
if (debug()) {
|
||||
v3Global.rootp()->dumpTreeFile(v3Global.debugFilename("final.tree", 990));
|
||||
if (s_errorExitCb) s_errorExitCb();
|
||||
V3Stats::statsFinalAll(v3Global.rootp());
|
||||
V3Stats::statsReport();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
vlAbort();
|
||||
}
|
||||
else if (isError(s_errorCode, s_errorSuppressed)) {
|
||||
// We don't dump tree on any error because a Visitor may be in middle of
|
||||
// a tree cleanup and cause a false broken problem.
|
||||
if (s_errorExitCb) s_errorExitCb();
|
||||
}
|
||||
vlAbort();
|
||||
}
|
||||
else if (isError(s_errorCode, s_errorSuppressed)) {
|
||||
// We don't dump tree on any error because a Visitor may be in middle of
|
||||
// a tree cleanup and cause a false broken problem.
|
||||
if (s_errorExitCb) s_errorExitCb();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
277
src/V3Error.h
277
src/V3Error.h
|
|
@ -36,86 +36,86 @@
|
|||
class V3ErrorCode {
|
||||
public:
|
||||
enum en {
|
||||
EC_MIN=0, // Keep first
|
||||
//
|
||||
EC_INFO, // General information out
|
||||
EC_FATAL, // Kill the program
|
||||
EC_FATALSRC, // Kill the program, for internal source errors
|
||||
EC_ERROR, // General error out, can't suppress
|
||||
// Boolean information we track per-line, but aren't errors
|
||||
I_COVERAGE, // Coverage is on/off from /*verilator coverage_on/off*/
|
||||
I_TRACING, // Tracing is on/off from /*verilator tracing_on/off*/
|
||||
I_LINT, // All lint messages
|
||||
I_DEF_NETTYPE_WIRE, // `default_nettype is WIRE (false=NONE)
|
||||
// Error codes:
|
||||
E_DETECTARRAY, // Error: Unsupported: Can't detect changes on arrayed variable
|
||||
EC_MIN=0, // Keep first
|
||||
//
|
||||
EC_INFO, // General information out
|
||||
EC_FATAL, // Kill the program
|
||||
EC_FATALSRC, // Kill the program, for internal source errors
|
||||
EC_ERROR, // General error out, can't suppress
|
||||
// Boolean information we track per-line, but aren't errors
|
||||
I_COVERAGE, // Coverage is on/off from /*verilator coverage_on/off*/
|
||||
I_TRACING, // Tracing is on/off from /*verilator tracing_on/off*/
|
||||
I_LINT, // All lint messages
|
||||
I_DEF_NETTYPE_WIRE, // `default_nettype is WIRE (false=NONE)
|
||||
// Error codes:
|
||||
E_DETECTARRAY, // Error: Unsupported: Can't detect changes on arrayed variable
|
||||
E_MULTITOP, // Error: Multiple top level modules
|
||||
E_PORTSHORT, // Error: Output port is connected to a constant, electrical short
|
||||
E_TASKNSVAR, // Error: Task I/O not simple
|
||||
//
|
||||
// Warning codes:
|
||||
EC_FIRST_WARN, // Just a code so the program knows where to start warnings
|
||||
//
|
||||
ALWCOMBORDER, // Always_comb with unordered statements
|
||||
ASSIGNDLY, // Assignment delays
|
||||
ASSIGNIN, // Assigning to input
|
||||
BLKANDNBLK, // Blocked and non-blocking assignments to same variable
|
||||
BLKLOOPINIT, // Delayed assignment to array inside for loops
|
||||
BLKSEQ, // Blocking assignments in sequential block
|
||||
BSSPACE, // Backslash space
|
||||
CASEINCOMPLETE, // Case statement has missing values
|
||||
CASEOVERLAP, // Case statements overlap
|
||||
CASEWITHX, // Case with X values
|
||||
CASEX, // Casex
|
||||
CDCRSTLOGIC, // Logic in async reset path
|
||||
CLKDATA, // Clock used as data
|
||||
CMPCONST, // Comparison is constant due to limited range
|
||||
COLONPLUS, // :+ instead of +:
|
||||
//
|
||||
// Warning codes:
|
||||
EC_FIRST_WARN, // Just a code so the program knows where to start warnings
|
||||
//
|
||||
ALWCOMBORDER, // Always_comb with unordered statements
|
||||
ASSIGNDLY, // Assignment delays
|
||||
ASSIGNIN, // Assigning to input
|
||||
BLKANDNBLK, // Blocked and non-blocking assignments to same variable
|
||||
BLKLOOPINIT, // Delayed assignment to array inside for loops
|
||||
BLKSEQ, // Blocking assignments in sequential block
|
||||
BSSPACE, // Backslash space
|
||||
CASEINCOMPLETE, // Case statement has missing values
|
||||
CASEOVERLAP, // Case statements overlap
|
||||
CASEWITHX, // Case with X values
|
||||
CASEX, // Casex
|
||||
CDCRSTLOGIC, // Logic in async reset path
|
||||
CLKDATA, // Clock used as data
|
||||
CMPCONST, // Comparison is constant due to limited range
|
||||
COLONPLUS, // :+ instead of +:
|
||||
COMBDLY, // Combinatorial delayed assignment
|
||||
CONTASSREG, // Continuous assignment on reg
|
||||
DEFPARAM, // Style: Defparam
|
||||
DECLFILENAME, // Declaration doesn't match filename
|
||||
ENDLABEL, // End lable name mismatch
|
||||
GENCLK, // Generated Clock
|
||||
IFDEPTH, // If statements too deep
|
||||
ENDLABEL, // End lable name mismatch
|
||||
GENCLK, // Generated Clock
|
||||
IFDEPTH, // If statements too deep
|
||||
IGNOREDRETURN, // Ignoring return value (funcation as task)
|
||||
IMPERFECTSCH, // Imperfect schedule (disabled by default)
|
||||
IMPLICIT, // Implicit wire
|
||||
IMPORTSTAR, // Import::* in $unit
|
||||
IMPURE, // Impure function not being inlined
|
||||
INCABSPATH, // Include has absolute path
|
||||
INCABSPATH, // Include has absolute path
|
||||
INFINITELOOP, // Infinite loop
|
||||
INITIALDLY, // Initial delayed statement
|
||||
LITENDIAN, // Little bit endian vector
|
||||
MODDUP, // Duplicate module
|
||||
MULTIDRIVEN, // Driven from multiple blocks
|
||||
PINMISSING, // Cell pin not specified
|
||||
PINNOCONNECT, // Cell pin not connected
|
||||
INITIALDLY, // Initial delayed statement
|
||||
LITENDIAN, // Little bit endian vector
|
||||
MODDUP, // Duplicate module
|
||||
MULTIDRIVEN, // Driven from multiple blocks
|
||||
PINMISSING, // Cell pin not specified
|
||||
PINNOCONNECT, // Cell pin not connected
|
||||
PINCONNECTEMPTY,// Cell pin connected by name with empty reference
|
||||
PROCASSWIRE, // Procedural assignment on wire
|
||||
REALCVT, // Real conversion
|
||||
REDEFMACRO, // Redefining existing define macro
|
||||
SELRANGE, // Selection index out of range
|
||||
STMTDLY, // Delayed statement
|
||||
SYMRSVDWORD, // Symbol is Reserved Word
|
||||
SYNCASYNCNET, // Mixed sync + async reset
|
||||
REDEFMACRO, // Redefining existing define macro
|
||||
SELRANGE, // Selection index out of range
|
||||
STMTDLY, // Delayed statement
|
||||
SYMRSVDWORD, // Symbol is Reserved Word
|
||||
SYNCASYNCNET, // Mixed sync + async reset
|
||||
TICKCOUNT, // Too large tick count
|
||||
UNDRIVEN, // No drivers
|
||||
UNOPT, // Unoptimizable block
|
||||
UNOPTFLAT, // Unoptimizable block after flattening
|
||||
UNDRIVEN, // No drivers
|
||||
UNOPT, // Unoptimizable block
|
||||
UNOPTFLAT, // Unoptimizable block after flattening
|
||||
UNOPTTHREADS, // Thread partitioner unable to fill all requested threads
|
||||
UNPACKED, // Unsupported unpacked
|
||||
UNSIGNED, // Comparison is constant due to unsigned arithmetic
|
||||
UNUSED, // No receivers
|
||||
USERERROR, // Elaboration time $error
|
||||
USERFATAL, // Elaboration time $fatal
|
||||
USERINFO, // Elaboration time $info
|
||||
USERWARN, // Elaboration time $warning
|
||||
VARHIDDEN, // Hiding variable
|
||||
WIDTH, // Width mismatch
|
||||
WIDTHCONCAT, // Unsized numbers/parameters in concatenations
|
||||
_ENUM_MAX
|
||||
// ***Add new elements below also***
|
||||
UNPACKED, // Unsupported unpacked
|
||||
UNSIGNED, // Comparison is constant due to unsigned arithmetic
|
||||
UNUSED, // No receivers
|
||||
USERERROR, // Elaboration time $error
|
||||
USERFATAL, // Elaboration time $fatal
|
||||
USERINFO, // Elaboration time $info
|
||||
USERWARN, // Elaboration time $warning
|
||||
VARHIDDEN, // Hiding variable
|
||||
WIDTH, // Width mismatch
|
||||
WIDTHCONCAT, // Unsized numbers/parameters in concatenations
|
||||
_ENUM_MAX
|
||||
// ***Add new elements below also***
|
||||
};
|
||||
enum en m_e;
|
||||
inline V3ErrorCode() : m_e(EC_MIN) {}
|
||||
|
|
@ -125,17 +125,17 @@ public:
|
|||
explicit inline V3ErrorCode(int _e) : m_e(static_cast<en>(_e)) {}
|
||||
operator en() const { return m_e; }
|
||||
const char* ascii() const {
|
||||
const char* names[] = {
|
||||
// Leading spaces indicate it can't be disabled.
|
||||
" MIN", " INFO", " FATAL", " FATALSRC", " ERROR",
|
||||
// Boolean
|
||||
" I_COVERAGE", " I_TRACING", " I_LINT", " I_DEF_NETTYPE_WIRE",
|
||||
const char* names[] = {
|
||||
// Leading spaces indicate it can't be disabled.
|
||||
" MIN", " INFO", " FATAL", " FATALSRC", " ERROR",
|
||||
// Boolean
|
||||
" I_COVERAGE", " I_TRACING", " I_LINT", " I_DEF_NETTYPE_WIRE",
|
||||
// Errors
|
||||
"DETECTARRAY", "MULTITOP", "PORTSHORT", "TASKNSVAR",
|
||||
// Warnings
|
||||
" EC_FIRST_WARN",
|
||||
"ALWCOMBORDER", "ASSIGNDLY", "ASSIGNIN",
|
||||
"BLKANDNBLK", "BLKLOOPINIT", "BLKSEQ", "BSSPACE",
|
||||
" EC_FIRST_WARN",
|
||||
"ALWCOMBORDER", "ASSIGNDLY", "ASSIGNIN",
|
||||
"BLKANDNBLK", "BLKLOOPINIT", "BLKSEQ", "BSSPACE",
|
||||
"CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CDCRSTLOGIC", "CLKDATA",
|
||||
"CMPCONST", "COLONPLUS", "COMBDLY", "CONTASSREG",
|
||||
"DEFPARAM", "DECLFILENAME",
|
||||
|
|
@ -146,16 +146,16 @@ public:
|
|||
"LITENDIAN", "MODDUP",
|
||||
"MULTIDRIVEN",
|
||||
"PINMISSING", "PINNOCONNECT", "PINCONNECTEMPTY", "PROCASSWIRE",
|
||||
"REALCVT", "REDEFMACRO",
|
||||
"SELRANGE", "STMTDLY", "SYMRSVDWORD", "SYNCASYNCNET",
|
||||
"REALCVT", "REDEFMACRO",
|
||||
"SELRANGE", "STMTDLY", "SYMRSVDWORD", "SYNCASYNCNET",
|
||||
"TICKCOUNT",
|
||||
"UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNOPTTHREADS",
|
||||
"UNPACKED", "UNSIGNED", "UNUSED",
|
||||
"USERERROR", "USERFATAL", "USERINFO", "USERWARN",
|
||||
"VARHIDDEN", "WIDTH", "WIDTHCONCAT",
|
||||
" MAX"
|
||||
};
|
||||
return names[m_e];
|
||||
"USERERROR", "USERFATAL", "USERINFO", "USERWARN",
|
||||
"VARHIDDEN", "WIDTH", "WIDTHCONCAT",
|
||||
" MAX"
|
||||
};
|
||||
return names[m_e];
|
||||
}
|
||||
// Warnings that default to off
|
||||
bool defaultsOff() const { return ( m_e==IMPERFECTSCH || styleError()); }
|
||||
|
|
@ -170,39 +170,39 @@ public:
|
|||
|| m_e==PROCASSWIRE); }
|
||||
// Warnings to mention manual
|
||||
bool mentionManual() const { return ( m_e==EC_FATALSRC || m_e==SYMRSVDWORD
|
||||
|| pretendError() ); }
|
||||
|| pretendError() ); }
|
||||
|
||||
// Warnings that are lint only
|
||||
bool lintError() const { return ( m_e==ALWCOMBORDER
|
||||
|| m_e==BSSPACE
|
||||
|| m_e==CASEINCOMPLETE || m_e==CASEOVERLAP
|
||||
|| m_e==CASEWITHX || m_e==CASEX
|
||||
|| m_e==CMPCONST
|
||||
|| m_e==COLONPLUS
|
||||
|| m_e==ENDLABEL
|
||||
|| m_e==IMPLICIT
|
||||
|| m_e==LITENDIAN
|
||||
|| m_e==PINMISSING
|
||||
|| m_e==REALCVT
|
||||
|| m_e==UNSIGNED
|
||||
|| m_e==WIDTH); }
|
||||
|| m_e==BSSPACE
|
||||
|| m_e==CASEINCOMPLETE || m_e==CASEOVERLAP
|
||||
|| m_e==CASEWITHX || m_e==CASEX
|
||||
|| m_e==CMPCONST
|
||||
|| m_e==COLONPLUS
|
||||
|| m_e==ENDLABEL
|
||||
|| m_e==IMPLICIT
|
||||
|| m_e==LITENDIAN
|
||||
|| m_e==PINMISSING
|
||||
|| m_e==REALCVT
|
||||
|| m_e==UNSIGNED
|
||||
|| m_e==WIDTH); }
|
||||
// Warnings that are style only
|
||||
bool styleError() const { return ( m_e==ASSIGNDLY // More than style, but for backward compatibility
|
||||
|| m_e==BLKSEQ
|
||||
|| m_e==DEFPARAM
|
||||
|| m_e==DECLFILENAME
|
||||
|| m_e==BLKSEQ
|
||||
|| m_e==DEFPARAM
|
||||
|| m_e==DECLFILENAME
|
||||
|| m_e==IMPORTSTAR
|
||||
|| m_e==INCABSPATH
|
||||
|| m_e==PINCONNECTEMPTY
|
||||
|| m_e==PINNOCONNECT
|
||||
|| m_e==SYNCASYNCNET
|
||||
|| m_e==UNDRIVEN
|
||||
|| m_e==UNUSED
|
||||
|| m_e==VARHIDDEN ); }
|
||||
|| m_e==SYNCASYNCNET
|
||||
|| m_e==UNDRIVEN
|
||||
|| m_e==UNUSED
|
||||
|| m_e==VARHIDDEN ); }
|
||||
};
|
||||
inline bool operator== (V3ErrorCode lhs, V3ErrorCode rhs) { return (lhs.m_e == rhs.m_e); }
|
||||
inline bool operator== (V3ErrorCode lhs, V3ErrorCode::en rhs) { return (lhs.m_e == rhs); }
|
||||
inline bool operator== (V3ErrorCode::en lhs, V3ErrorCode rhs) { return (lhs == rhs.m_e); }
|
||||
inline bool operator==(V3ErrorCode lhs, V3ErrorCode rhs) { return (lhs.m_e == rhs.m_e); }
|
||||
inline bool operator==(V3ErrorCode lhs, V3ErrorCode::en rhs) { return (lhs.m_e == rhs); }
|
||||
inline bool operator==(V3ErrorCode::en lhs, V3ErrorCode rhs) { return (lhs == rhs.m_e); }
|
||||
inline std::ostream& operator<<(std::ostream& os, V3ErrorCode rhs) { return os<<rhs.ascii(); }
|
||||
|
||||
//######################################################################
|
||||
|
|
@ -214,50 +214,50 @@ class V3Error {
|
|||
typedef void (*ErrorExitCb)(void);
|
||||
|
||||
private:
|
||||
static bool s_describedWarnings; // Told user how to disable warns
|
||||
static bool s_describedEachWarn[V3ErrorCode::_ENUM_MAX]; // Told user specifics about this warning
|
||||
static bool s_pretendError[V3ErrorCode::_ENUM_MAX]; // Pretend this warning is an error
|
||||
static int s_debugDefault; // Option: --debugi Default debugging level
|
||||
static int s_errorLimit; // Option: --error-limit Number of errors before exit
|
||||
static bool s_warnFatal; // Option: --warnFatal Warnings are fatal
|
||||
static int s_errCount; // Error count
|
||||
static int s_warnCount; // Warning count
|
||||
static int s_tellManual; // Tell user to see manual, 0=not yet, 1=doit, 2=disable
|
||||
static bool s_describedWarnings; // Told user how to disable warns
|
||||
static bool s_describedEachWarn[V3ErrorCode::_ENUM_MAX]; // Told user specifics about this warning
|
||||
static bool s_pretendError[V3ErrorCode::_ENUM_MAX]; // Pretend this warning is an error
|
||||
static int s_debugDefault; // Option: --debugi Default debugging level
|
||||
static int s_errorLimit; // Option: --error-limit Number of errors before exit
|
||||
static bool s_warnFatal; // Option: --warnFatal Warnings are fatal
|
||||
static int s_errCount; // Error count
|
||||
static int s_warnCount; // Warning count
|
||||
static int s_tellManual; // Tell user to see manual, 0=not yet, 1=doit, 2=disable
|
||||
static std::ostringstream s_errorStr; // Error string being formed
|
||||
static V3ErrorCode s_errorCode; // Error string being formed will abort
|
||||
static bool s_errorSuppressed; // Error being formed should be suppressed
|
||||
static MessagesSet s_messages; // What errors we've outputted
|
||||
static ErrorExitCb s_errorExitCb; // Callback when error occurs for dumping
|
||||
static V3ErrorCode s_errorCode; // Error string being formed will abort
|
||||
static bool s_errorSuppressed; // Error being formed should be suppressed
|
||||
static MessagesSet s_messages; // What errors we've outputted
|
||||
static ErrorExitCb s_errorExitCb; // Callback when error occurs for dumping
|
||||
|
||||
enum MaxErrors { MAX_ERRORS = 50 }; // Fatal after this may errors
|
||||
enum MaxErrors { MAX_ERRORS = 50 }; // Fatal after this may errors
|
||||
|
||||
V3Error() { std::cerr<<("Static class"); abort(); }
|
||||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
// ACCESSORS
|
||||
static void debugDefault(int level) { s_debugDefault = level; }
|
||||
static int debugDefault() { return s_debugDefault; }
|
||||
static void errorLimit(int level) { s_errorLimit = level; }
|
||||
static int errorLimit() { return s_errorLimit; }
|
||||
static void warnFatal(bool flag) { s_warnFatal = flag; }
|
||||
static bool warnFatal() { return s_warnFatal; }
|
||||
static string msgPrefix(); // returns %Error/%Warn
|
||||
static int errorCount() { return s_errCount; }
|
||||
static int warnCount() { return s_warnCount; }
|
||||
static int errorOrWarnCount() { return errorCount()+warnCount(); }
|
||||
static void debugDefault(int level) { s_debugDefault = level; }
|
||||
static int debugDefault() { return s_debugDefault; }
|
||||
static void errorLimit(int level) { s_errorLimit = level; }
|
||||
static int errorLimit() { return s_errorLimit; }
|
||||
static void warnFatal(bool flag) { s_warnFatal = flag; }
|
||||
static bool warnFatal() { return s_warnFatal; }
|
||||
static string msgPrefix(); // returns %Error/%Warn
|
||||
static int errorCount() { return s_errCount; }
|
||||
static int warnCount() { return s_warnCount; }
|
||||
static int errorOrWarnCount() { return errorCount()+warnCount(); }
|
||||
// METHODS
|
||||
static void incErrors();
|
||||
static void incWarnings() { s_warnCount++; }
|
||||
static void init();
|
||||
static void abortIfErrors() { if (errorCount()) abortIfWarnings(); }
|
||||
static void abortIfWarnings();
|
||||
static void suppressThisWarning(); // Suppress next %Warn if user has it off
|
||||
static void pretendError(V3ErrorCode code, bool flag) { s_pretendError[code]=flag; }
|
||||
static bool isError(V3ErrorCode code, bool supp);
|
||||
static void incErrors();
|
||||
static void incWarnings() { s_warnCount++; }
|
||||
static void init();
|
||||
static void abortIfErrors() { if (errorCount()) abortIfWarnings(); }
|
||||
static void abortIfWarnings();
|
||||
static void suppressThisWarning(); // Suppress next %Warn if user has it off
|
||||
static void pretendError(V3ErrorCode code, bool flag) { s_pretendError[code] = flag; }
|
||||
static bool isError(V3ErrorCode code, bool supp);
|
||||
static string lineStr(const char* filename, int lineno);
|
||||
static V3ErrorCode errorCode() { return s_errorCode; }
|
||||
static void errorExitCb(ErrorExitCb cb) { s_errorExitCb = cb; }
|
||||
static void errorExitCb(ErrorExitCb cb) { s_errorExitCb = cb; }
|
||||
|
||||
// When printing an error/warning, print prefix for multiline message
|
||||
static string warnMore();
|
||||
|
|
@ -265,16 +265,17 @@ class V3Error {
|
|||
// Internals for v3error()/v3fatal() macros only
|
||||
// Error end takes the string stream to output, be careful to seek() as needed
|
||||
static void v3errorPrep(V3ErrorCode code) {
|
||||
s_errorStr.str(""); s_errorCode=code; s_errorSuppressed=false; }
|
||||
s_errorStr.str(""); s_errorCode = code; s_errorSuppressed = false; }
|
||||
static std::ostringstream& v3errorStr() { return s_errorStr; }
|
||||
static void vlAbort();
|
||||
static void vlAbort();
|
||||
static void v3errorEnd(std::ostringstream& sstr); // static, but often overridden in classes.
|
||||
};
|
||||
|
||||
// Global versions, so that if the class doesn't define a operator, we get the functions anyways.
|
||||
inline int debug() { return V3Error::debugDefault(); }
|
||||
inline void v3errorEnd(std::ostringstream& sstr) { V3Error::v3errorEnd(sstr); }
|
||||
inline void v3errorEndFatal(std::ostringstream& sstr) { V3Error::v3errorEnd(sstr); assert(0); VL_UNREACHABLE }
|
||||
inline void v3errorEndFatal(std::ostringstream& sstr) {
|
||||
V3Error::v3errorEnd(sstr); assert(0); VL_UNREACHABLE }
|
||||
|
||||
// Theses allow errors using << operators: v3error("foo"<<"bar");
|
||||
// Careful, you can't put () around msg, as you would in most macro definitions
|
||||
|
|
@ -341,7 +342,7 @@ inline uint32_t cvtToHash(const void* vp) {
|
|||
// We can shove a 64 bit pointer into a 32 bit bucket
|
||||
// On 32-bit systems, lower is always 0, but who cares?
|
||||
union { const void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
|
||||
u.l.upper=0; u.l.lower=0; u.up=vp;
|
||||
u.l.upper = 0; u.l.lower = 0; u.up = vp;
|
||||
return u.l.upper^u.l.lower;
|
||||
}
|
||||
|
||||
|
|
@ -351,4 +352,4 @@ inline string ucfirst(const string& text) {
|
|||
return out;
|
||||
}
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
931
src/V3Expand.cpp
931
src/V3Expand.cpp
File diff suppressed because it is too large
Load Diff
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void expandAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
888
src/V3File.cpp
888
src/V3File.cpp
File diff suppressed because it is too large
Load Diff
101
src/V3File.h
101
src/V3File.h
|
|
@ -37,28 +37,28 @@
|
|||
class V3File {
|
||||
public:
|
||||
static std::ifstream* new_ifstream(const string& filename) {
|
||||
addSrcDepend(filename);
|
||||
addSrcDepend(filename);
|
||||
return new_ifstream_nodepend(filename);
|
||||
}
|
||||
static std::ifstream* new_ifstream_nodepend(const string& filename) {
|
||||
return new std::ifstream(filename.c_str());
|
||||
}
|
||||
static std::ofstream* new_ofstream(const string& filename, bool append=false) {
|
||||
addTgtDepend(filename);
|
||||
addTgtDepend(filename);
|
||||
return new_ofstream_nodepend(filename, append);
|
||||
}
|
||||
static std::ofstream* new_ofstream_nodepend(const string& filename, bool append=false) {
|
||||
if (filename != VL_DEV_NULL) createMakeDir();
|
||||
if (append) {
|
||||
if (filename != VL_DEV_NULL) createMakeDir();
|
||||
if (append) {
|
||||
return new std::ofstream(filename.c_str(), std::ios::app);
|
||||
} else {
|
||||
} else {
|
||||
return new std::ofstream(filename.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
static FILE* new_fopen_w(const string& filename) {
|
||||
if (filename != VL_DEV_NULL) createMakeDir();
|
||||
addTgtDepend(filename);
|
||||
return fopen(filename.c_str(),"w");
|
||||
if (filename != VL_DEV_NULL) createMakeDir();
|
||||
addTgtDepend(filename);
|
||||
return fopen(filename.c_str(), "w");
|
||||
}
|
||||
|
||||
// Dependencies
|
||||
|
|
@ -102,33 +102,33 @@ public:
|
|||
class V3OutFormatter {
|
||||
// TYPES
|
||||
enum MiscConsts {
|
||||
MAXSPACE = 80}; // After this indent, stop indenting more
|
||||
MAXSPACE = 80}; // After this indent, stop indenting more
|
||||
public:
|
||||
enum AlignClass {
|
||||
AL_AUTO = 0,
|
||||
AL_STATIC = 1};
|
||||
AL_AUTO = 0,
|
||||
AL_STATIC = 1};
|
||||
enum Language {
|
||||
LA_C = 0,
|
||||
LA_VERILOG = 1,
|
||||
LA_MK = 2,
|
||||
LA_XML = 3,
|
||||
LA_C = 0,
|
||||
LA_VERILOG = 1,
|
||||
LA_MK = 2,
|
||||
LA_XML = 3,
|
||||
};
|
||||
|
||||
private:
|
||||
// MEMBERS
|
||||
string m_filename;
|
||||
Language m_lang; // Indenting Verilog code
|
||||
int m_blockIndent; // Characters per block indent
|
||||
int m_commaWidth; // Width after which to break at ,'s
|
||||
int m_lineno;
|
||||
int m_column;
|
||||
int m_nobreak; // Basic operator or begin paren, don't break next
|
||||
bool m_prependIndent;
|
||||
int m_indentLevel; // Current {} indentation
|
||||
string m_filename;
|
||||
Language m_lang; // Indenting Verilog code
|
||||
int m_blockIndent; // Characters per block indent
|
||||
int m_commaWidth; // Width after which to break at ,'s
|
||||
int m_lineno;
|
||||
int m_column;
|
||||
int m_nobreak; // Basic operator or begin paren, don't break next
|
||||
bool m_prependIndent;
|
||||
int m_indentLevel; // Current {} indentation
|
||||
std::stack<int> m_parenVec; // Stack of columns where last ( was
|
||||
int m_bracketLevel; // Intenting = { block, indicates number of {'s seen.
|
||||
|
||||
int endLevels(const char* strg);
|
||||
int endLevels(const char* strg);
|
||||
const char* indentStr(int num);
|
||||
void putcNoTracking(char chr);
|
||||
|
||||
|
|
@ -138,7 +138,7 @@ public:
|
|||
// ACCESSORS
|
||||
int column() const { return m_column; }
|
||||
int blockIndent() const { return m_blockIndent; }
|
||||
void blockIndent(int flag) { m_blockIndent=flag; }
|
||||
void blockIndent(int flag) { m_blockIndent = flag; }
|
||||
// METHODS
|
||||
void printf(const char* fmt...) VL_ATTR_PRINTF(2);
|
||||
void puts(const char* strg);
|
||||
|
|
@ -154,7 +154,7 @@ public:
|
|||
bool tokenEnd(const char* cp);
|
||||
void indentInc() { m_indentLevel += m_blockIndent; }
|
||||
void indentDec() {
|
||||
m_indentLevel -= m_blockIndent;
|
||||
m_indentLevel -= m_blockIndent;
|
||||
UASSERT(m_indentLevel>=0, ": "<<m_filename<<": Underflow of indentation");
|
||||
}
|
||||
void blockInc() { m_parenVec.push(m_indentLevel + m_blockIndent); }
|
||||
|
|
@ -173,7 +173,7 @@ public:
|
|||
|
||||
class V3OutFile : public V3OutFormatter {
|
||||
// MEMBERS
|
||||
FILE* m_fp;
|
||||
FILE* m_fp;
|
||||
public:
|
||||
V3OutFile(const string& filename, V3OutFormatter::Language lang);
|
||||
virtual ~V3OutFile();
|
||||
|
|
@ -187,30 +187,30 @@ private:
|
|||
// V3OutCFile: A class for abstracting out SystemC/C++ details
|
||||
|
||||
class V3OutCFile : public V3OutFile {
|
||||
int m_private;
|
||||
int m_private;
|
||||
public:
|
||||
explicit V3OutCFile(const string& filename) : V3OutFile(filename, V3OutFormatter::LA_C) {
|
||||
resetPrivate();
|
||||
resetPrivate();
|
||||
}
|
||||
virtual ~V3OutCFile() {}
|
||||
virtual void putsCellDecl(const string& classname, const string& cellname) {
|
||||
string classStar = classname + "*";
|
||||
this->printf("%-19s\t%s;\n", classStar.c_str(), cellname.c_str());
|
||||
string classStar = classname + "*";
|
||||
this->printf("%-19s\t%s;\n", classStar.c_str(), cellname.c_str());
|
||||
}
|
||||
virtual void putsHeader() { puts("// Verilated -*- C++ -*-\n"); }
|
||||
virtual void putsIntTopInclude() {
|
||||
putsForceIncs();
|
||||
putsForceIncs();
|
||||
}
|
||||
// Print out public/privates
|
||||
void resetPrivate() { m_private = 0; }
|
||||
void putsPrivate(bool setPrivate) {
|
||||
if (setPrivate && m_private!=1) {
|
||||
puts("private:\n");
|
||||
m_private = 1;
|
||||
} else if (!setPrivate && m_private!=2) {
|
||||
puts("public:\n");
|
||||
m_private = 2;
|
||||
}
|
||||
if (setPrivate && m_private!=1) {
|
||||
puts("private:\n");
|
||||
m_private = 1;
|
||||
} else if (!setPrivate && m_private!=2) {
|
||||
puts("public:\n");
|
||||
m_private = 2;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -220,23 +220,25 @@ public:
|
|||
virtual ~V3OutScFile() {}
|
||||
virtual void putsHeader() { puts("// Verilated -*- SystemC -*-\n"); }
|
||||
virtual void putsIntTopInclude() {
|
||||
putsForceIncs();
|
||||
puts("#include \"systemc.h\"\n");
|
||||
puts("#include \"verilated_sc.h\"\n");
|
||||
putsForceIncs();
|
||||
puts("#include \"systemc.h\"\n");
|
||||
puts("#include \"verilated_sc.h\"\n");
|
||||
}
|
||||
};
|
||||
|
||||
class V3OutVFile : public V3OutFile {
|
||||
public:
|
||||
explicit V3OutVFile(const string& filename) : V3OutFile(filename, V3OutFormatter::LA_VERILOG) {}
|
||||
explicit V3OutVFile(const string& filename)
|
||||
: V3OutFile(filename, V3OutFormatter::LA_VERILOG) {}
|
||||
virtual ~V3OutVFile() {}
|
||||
virtual void putsHeader() { puts("// Verilated -*- Verilog -*-\n"); }
|
||||
};
|
||||
|
||||
class V3OutXmlFile : public V3OutFile {
|
||||
public:
|
||||
explicit V3OutXmlFile(const string& filename) : V3OutFile(filename, V3OutFormatter::LA_XML) {
|
||||
blockIndent(2);
|
||||
explicit V3OutXmlFile(const string& filename)
|
||||
: V3OutFile(filename, V3OutFormatter::LA_XML) {
|
||||
blockIndent(2);
|
||||
}
|
||||
virtual ~V3OutXmlFile() {}
|
||||
virtual void putsHeader() { puts("<?xml version=\"1.0\" ?>\n"); }
|
||||
|
|
@ -244,7 +246,8 @@ public:
|
|||
|
||||
class V3OutMkFile : public V3OutFile {
|
||||
public:
|
||||
explicit V3OutMkFile(const string& filename) : V3OutFile(filename, V3OutFormatter::LA_MK) {}
|
||||
explicit V3OutMkFile(const string& filename)
|
||||
: V3OutFile(filename, V3OutFormatter::LA_MK) {}
|
||||
virtual ~V3OutMkFile() {}
|
||||
virtual void putsHeader() { puts("# Verilated -*- Makefile -*-\n"); }
|
||||
// No automatic indentation yet.
|
||||
|
|
@ -252,4 +255,4 @@ public:
|
|||
void puts(const string& strg) { putsNoTracking(strg); }
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ int FileLineSingleton::nameToNumber(const string& filename) {
|
|||
int num = m_names.size();
|
||||
m_names.push_back(filename);
|
||||
m_languages.push_back(V3LangCode::mostRecent());
|
||||
m_namemap.insert(make_pair(filename,num));
|
||||
m_namemap.insert(make_pair(filename, num));
|
||||
return num;
|
||||
}
|
||||
|
||||
|
|
@ -73,9 +73,9 @@ int FileLineSingleton::nameToNumber(const string& filename) {
|
|||
void FileLineSingleton::fileNameNumMapDumpXml(std::ostream& os) {
|
||||
os<<"<files>\n";
|
||||
for (FileNameNumMap::const_iterator it = m_namemap.begin(); it != m_namemap.end(); ++it) {
|
||||
os<<"<file id=\""<<filenameLetters(it->second)
|
||||
<<"\" filename=\""<<it->first
|
||||
<<"\" language=\""<<numberToLang(it->second).ascii()<<"\"/>\n";
|
||||
os<<"<file id=\""<<filenameLetters(it->second)
|
||||
<<"\" filename=\""<<it->first
|
||||
<<"\" language=\""<<numberToLang(it->second).ascii()<<"\"/>\n";
|
||||
}
|
||||
os<<"</files>\n";
|
||||
}
|
||||
|
|
@ -85,10 +85,10 @@ void FileLineSingleton::fileNameNumMapDumpXml(std::ostream& os) {
|
|||
|
||||
FileLine::FileLine(FileLine::EmptySecret) {
|
||||
// Sort of a singleton
|
||||
m_lineno=0;
|
||||
m_filenameno=singleton().nameToNumber("AstRoot");
|
||||
m_lineno = 0;
|
||||
m_filenameno = singleton().nameToNumber("AstRoot");
|
||||
|
||||
m_warnOn=0;
|
||||
m_warnOn = 0;
|
||||
for (int codei=V3ErrorCode::EC_MIN; codei<V3ErrorCode::_ENUM_MAX; codei++) {
|
||||
V3ErrorCode code = V3ErrorCode(codei);
|
||||
warnOff(code, code.defaultsOff());
|
||||
|
|
@ -112,7 +112,7 @@ void FileLine::lineDirective(const char* textp, int& enterExitRef) {
|
|||
const char *ln = textp;
|
||||
while (*textp && !isspace(*textp)) textp++;
|
||||
if (isdigit(*ln)) {
|
||||
lineno(atoi(ln));
|
||||
lineno(atoi(ln));
|
||||
}
|
||||
while (*textp && (isspace(*textp) || *textp=='"')) textp++;
|
||||
|
||||
|
|
@ -120,9 +120,9 @@ void FileLine::lineDirective(const char* textp, int& enterExitRef) {
|
|||
const char *fn = textp;
|
||||
while (*textp && !(isspace(*textp) || *textp=='"')) textp++;
|
||||
if (textp != fn) {
|
||||
string strfn = fn;
|
||||
strfn = strfn.substr(0, textp-fn);
|
||||
filename(strfn);
|
||||
string strfn = fn;
|
||||
strfn = strfn.substr(0, textp-fn);
|
||||
filename(strfn);
|
||||
}
|
||||
|
||||
// Grab level
|
||||
|
|
@ -143,7 +143,7 @@ FileLine* FileLine::copyOrSameFileLine() {
|
|||
#endif
|
||||
static FileLine* lastNewp = NULL;
|
||||
if (lastNewp && *lastNewp == *this) { // Compares lineno, filename, etc
|
||||
return lastNewp;
|
||||
return lastNewp;
|
||||
}
|
||||
FileLine* newp = new FileLine(this);
|
||||
lastNewp = newp;
|
||||
|
|
@ -154,7 +154,7 @@ const string FileLine::filebasename() const {
|
|||
string name = filename();
|
||||
string::size_type pos;
|
||||
if ((pos = name.rfind('/')) != string::npos) {
|
||||
name.erase(0,pos+1);
|
||||
name.erase(0, pos+1);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
|
@ -163,7 +163,7 @@ const string FileLine::filebasenameNoExt() const {
|
|||
string name = filebasename();
|
||||
string::size_type pos;
|
||||
if ((pos = name.find('.')) != string::npos) {
|
||||
name = name.substr(0,pos);
|
||||
name = name.substr(0, pos);
|
||||
}
|
||||
return name;
|
||||
}
|
||||
|
|
@ -173,8 +173,8 @@ const string FileLine::profileFuncname() const {
|
|||
string name = filebasenameNoExt();
|
||||
string::size_type pos;
|
||||
while ((pos = name.find_first_not_of("abcdefghijlkmnopqrstuvwxyzABCDEFGHIJLKMNOPQRSTUVWXYZ0123456789_"))
|
||||
!= string::npos) {
|
||||
name.replace(pos, 1, "_");
|
||||
!= string::npos) {
|
||||
name.replace(pos, 1, "_");
|
||||
}
|
||||
name += "__l"+cvtToStr(lineno());
|
||||
return name;
|
||||
|
|
@ -191,15 +191,15 @@ std::ostream& operator<<(std::ostream& os, FileLine* fileline) {
|
|||
bool FileLine::warnOff(const string& msg, bool flag) {
|
||||
V3ErrorCode code (msg.c_str());
|
||||
if (code < V3ErrorCode::EC_FIRST_WARN) {
|
||||
return false;
|
||||
return false;
|
||||
#ifndef _V3ERROR_NO_GLOBAL_
|
||||
} else if (v3Global.opt.lintOnly() // Lint mode is allowed to suppress some errors
|
||||
&& code < V3ErrorCode::EC_MIN) {
|
||||
return false;
|
||||
} else if (v3Global.opt.lintOnly() // Lint mode is allowed to suppress some errors
|
||||
&& code < V3ErrorCode::EC_MIN) {
|
||||
return false;
|
||||
#endif
|
||||
} else {
|
||||
warnOff(code, flag);
|
||||
return true;
|
||||
warnOff(code, flag);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -222,7 +222,8 @@ bool FileLine::warnIsOff(V3ErrorCode code) const {
|
|||
if (!defaultFileLine().m_warnOn.test(code)) return true; // Global overrides local
|
||||
// UNOPTFLAT implies UNOPT
|
||||
if (code==V3ErrorCode::UNOPT && !m_warnOn.test(V3ErrorCode::UNOPTFLAT)) return true;
|
||||
if ((code.lintError() || code.styleError()) && !m_warnOn.test(V3ErrorCode::I_LINT)) return true;
|
||||
if ((code.lintError() || code.styleError())
|
||||
&& !m_warnOn.test(V3ErrorCode::I_LINT)) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
@ -244,9 +245,9 @@ void FileLine::v3errorEnd(std::ostringstream& str) {
|
|||
|
||||
string FileLine::warnMore() const {
|
||||
if (m_lineno) {
|
||||
return V3Error::warnMore()+ascii()+": ";
|
||||
return V3Error::warnMore()+ascii()+": ";
|
||||
} else {
|
||||
return V3Error::warnMore();
|
||||
return V3Error::warnMore();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -265,9 +266,9 @@ void FileLine::operator delete(void* objp, size_t size) {
|
|||
FileLine* flp = static_cast<FileLine*>(objp);
|
||||
FileLineCheckSet::iterator it = fileLineLeakChecks.find(flp);
|
||||
if (it != fileLineLeakChecks.end()) {
|
||||
fileLineLeakChecks.erase(it);
|
||||
fileLineLeakChecks.erase(it);
|
||||
} else {
|
||||
flp->v3fatalSrc("Deleting FileLine object that was never tracked");
|
||||
flp->v3fatalSrc("Deleting FileLine object that was never tracked");
|
||||
}
|
||||
::operator delete(objp);
|
||||
}
|
||||
|
|
@ -279,11 +280,11 @@ void FileLine::deleteAllRemaining() {
|
|||
// that way. Unfortunately this makes our leak checking a big mess, so
|
||||
// only when leak checking we'll track them all and cleanup.
|
||||
while (1) {
|
||||
FileLineCheckSet::iterator it=fileLineLeakChecks.begin();
|
||||
if (it==fileLineLeakChecks.end()) break;
|
||||
delete *it;
|
||||
// Operator delete will remove the iterated object from the list.
|
||||
// Eventually the list will be empty and terminate the loop.
|
||||
FileLineCheckSet::iterator it = fileLineLeakChecks.begin();
|
||||
if (it==fileLineLeakChecks.end()) break;
|
||||
delete *it;
|
||||
// Operator delete will remove the iterated object from the list.
|
||||
// Eventually the list will be empty and terminate the loop.
|
||||
}
|
||||
fileLineLeakChecks.clear();
|
||||
singleton().clear();
|
||||
|
|
|
|||
|
|
@ -46,9 +46,9 @@ class FileLineSingleton {
|
|||
typedef std::map<string,int> FileNameNumMap;
|
||||
typedef std::map<string,V3LangCode> FileLangNumMap;
|
||||
// MEMBERS
|
||||
FileNameNumMap m_namemap; // filenameno for each filename
|
||||
FileNameNumMap m_namemap; // filenameno for each filename
|
||||
std::deque<string> m_names; // filename text for each filenameno
|
||||
std::deque<V3LangCode> m_languages; // language for each filenameno
|
||||
std::deque<V3LangCode> m_languages; // language for each filenameno
|
||||
// COSNTRUCTORS
|
||||
FileLineSingleton() { }
|
||||
~FileLineSingleton() { }
|
||||
|
|
@ -70,19 +70,19 @@ protected:
|
|||
//! millions). To save space, per-file information (e.g. filename, source
|
||||
//! language is held in tables in the FileLineSingleton class.
|
||||
class FileLine {
|
||||
int m_lineno;
|
||||
int m_filenameno;
|
||||
int m_lineno;
|
||||
int m_filenameno;
|
||||
std::bitset<V3ErrorCode::_ENUM_MAX> m_warnOn;
|
||||
|
||||
private:
|
||||
struct EmptySecret {};
|
||||
inline static FileLineSingleton& singleton() {
|
||||
static FileLineSingleton s;
|
||||
return s;
|
||||
static FileLineSingleton s;
|
||||
return s;
|
||||
}
|
||||
inline static FileLine& defaultFileLine() {
|
||||
static FileLine* defFilelinep = new FileLine(FileLine::EmptySecret());
|
||||
return *defFilelinep;
|
||||
static FileLine* defFilelinep = new FileLine(FileLine::EmptySecret());
|
||||
return *defFilelinep;
|
||||
}
|
||||
protected:
|
||||
// User routines should never need to change line numbers
|
||||
|
|
@ -101,13 +101,18 @@ protected:
|
|||
FileLine* copyOrSameFileLine();
|
||||
public:
|
||||
FileLine(const string& filename, int lineno) {
|
||||
m_lineno=lineno; m_filenameno = singleton().nameToNumber(filename);
|
||||
m_warnOn=defaultFileLine().m_warnOn; }
|
||||
m_lineno = lineno;
|
||||
m_filenameno = singleton().nameToNumber(filename);
|
||||
m_warnOn = defaultFileLine().m_warnOn;
|
||||
}
|
||||
explicit FileLine(FileLine* fromp) {
|
||||
m_lineno=fromp->m_lineno; m_filenameno = fromp->m_filenameno; m_warnOn=fromp->m_warnOn; }
|
||||
m_lineno = fromp->m_lineno;
|
||||
m_filenameno = fromp->m_filenameno;
|
||||
m_warnOn = fromp->m_warnOn;
|
||||
}
|
||||
explicit FileLine(EmptySecret);
|
||||
~FileLine() { }
|
||||
FileLine* create(const string& filename, int lineno) { return new FileLine(filename,lineno); }
|
||||
FileLine* create(const string& filename, int lineno) { return new FileLine(filename, lineno); }
|
||||
FileLine* create(int lineno) { return create(filename(), lineno); }
|
||||
static void deleteAllRemaining();
|
||||
#ifdef VL_LEAK_CHECKS
|
||||
|
|
@ -125,32 +130,33 @@ public:
|
|||
const string profileFuncname() const;
|
||||
const string xml() const { return "fl=\""+filenameLetters()+cvtToStr(lineno())+"\""; }
|
||||
string lineDirectiveStrg(int enterExit) const;
|
||||
void warnOn(V3ErrorCode code, bool flag) { m_warnOn.set(code,flag); } // Turn on/off warning messages on this line.
|
||||
void warnOff(V3ErrorCode code, bool flag) { warnOn(code,!flag); }
|
||||
// Turn on/off warning messages on this line.
|
||||
void warnOn(V3ErrorCode code, bool flag) { m_warnOn.set(code, flag); }
|
||||
void warnOff(V3ErrorCode code, bool flag) { warnOn(code, !flag); }
|
||||
bool warnOff(const string& msg, bool flag); // Returns 1 if ok
|
||||
bool warnIsOff(V3ErrorCode code) const;
|
||||
void warnLintOff(bool flag);
|
||||
void warnStyleOff(bool flag);
|
||||
void warnStateFrom(const FileLine& from) { m_warnOn=from.m_warnOn; }
|
||||
void warnStateFrom(const FileLine& from) { m_warnOn = from.m_warnOn; }
|
||||
void warnResetDefault() { warnStateFrom(defaultFileLine()); }
|
||||
|
||||
// Specific flag ACCESSORS/METHODS
|
||||
bool coverageOn() const { return m_warnOn.test(V3ErrorCode::I_COVERAGE); }
|
||||
void coverageOn(bool flag) { warnOn(V3ErrorCode::I_COVERAGE,flag); }
|
||||
void coverageOn(bool flag) { warnOn(V3ErrorCode::I_COVERAGE, flag); }
|
||||
bool tracingOn() const { return m_warnOn.test(V3ErrorCode::I_TRACING); }
|
||||
void tracingOn(bool flag) { warnOn(V3ErrorCode::I_TRACING,flag); }
|
||||
void tracingOn(bool flag) { warnOn(V3ErrorCode::I_TRACING, flag); }
|
||||
|
||||
// METHODS - Global
|
||||
static void globalWarnLintOff(bool flag) {
|
||||
defaultFileLine().warnLintOff(flag); }
|
||||
defaultFileLine().warnLintOff(flag); }
|
||||
static void globalWarnStyleOff(bool flag) {
|
||||
defaultFileLine().warnStyleOff(flag); }
|
||||
defaultFileLine().warnStyleOff(flag); }
|
||||
static void globalWarnOff(V3ErrorCode code, bool flag) {
|
||||
defaultFileLine().warnOff(code, flag); }
|
||||
defaultFileLine().warnOff(code, flag); }
|
||||
static bool globalWarnOff(const string& code, bool flag) {
|
||||
return defaultFileLine().warnOff(code, flag); }
|
||||
return defaultFileLine().warnOff(code, flag); }
|
||||
static void fileNameNumMapDumpXml(std::ostream& os) {
|
||||
singleton().fileNameNumMapDumpXml(os); }
|
||||
singleton().fileNameNumMapDumpXml(os); }
|
||||
|
||||
// METHODS - Called from netlist
|
||||
// Merge warning disables from another fileline
|
||||
|
|
@ -158,14 +164,15 @@ public:
|
|||
// Change the current fileline due to actions discovered after parsing
|
||||
// and may have side effects on other nodes sharing this FileLine.
|
||||
// Use only when this is intended
|
||||
void modifyWarnOff(V3ErrorCode code, bool flag) { warnOff(code,flag); }
|
||||
void modifyWarnOff(V3ErrorCode code, bool flag) { warnOff(code, flag); }
|
||||
|
||||
// OPERATORS
|
||||
void v3errorEnd(std::ostringstream& str);
|
||||
void v3errorEndFatal(std::ostringstream& str);
|
||||
string warnMore() const;
|
||||
inline bool operator==(FileLine rhs) const {
|
||||
return (m_lineno==rhs.m_lineno && m_filenameno==rhs.m_filenameno && m_warnOn==rhs.m_warnOn);
|
||||
return (m_lineno==rhs.m_lineno && m_filenameno==rhs.m_filenameno
|
||||
&& m_warnOn==rhs.m_warnOn);
|
||||
}
|
||||
private:
|
||||
void v3errorEndFatalGuts(std::ostringstream& str);
|
||||
|
|
|
|||
1748
src/V3Gate.cpp
1748
src/V3Gate.cpp
File diff suppressed because it is too large
Load Diff
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void gateAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
161
src/V3GenClk.cpp
161
src/V3GenClk.cpp
|
|
@ -18,8 +18,8 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// GENCLK TRANSFORMATIONS:
|
||||
// Follow control-flow graph with assignments and var usages
|
||||
// ASSIGNDLY to variable later used as clock requires change detect
|
||||
// Follow control-flow graph with assignments and var usages
|
||||
// ASSIGNDLY to variable later used as clock requires change detect
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -47,72 +47,73 @@ class GenClkRenameVisitor : public GenClkBaseVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared on top scope
|
||||
// AstVarScope::user2() -> AstVarScope*. Signal replacing activation with
|
||||
// AstVarRef::user3() -> bool. Signal is replaced activation (already done)
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
// AstVarScope::user2() -> AstVarScope*. Signal replacing activation with
|
||||
// AstVarRef::user3() -> bool. Signal is replaced activation (already done)
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
|
||||
// STATE
|
||||
AstActive* m_activep; // Inside activate statement
|
||||
AstNodeModule* m_topModp; // Top module
|
||||
AstScope* m_scopetopp; // Scope under TOPSCOPE
|
||||
AstActive* m_activep; // Inside activate statement
|
||||
AstNodeModule* m_topModp; // Top module
|
||||
AstScope* m_scopetopp; // Scope under TOPSCOPE
|
||||
|
||||
// METHODS
|
||||
AstVarScope* genInpClk(AstVarScope* vscp) {
|
||||
if (vscp->user2p()) {
|
||||
if (vscp->user2p()) {
|
||||
return VN_CAST(vscp->user2p(), VarScope);
|
||||
} else {
|
||||
AstVar* varp = vscp->varp();
|
||||
string newvarname = "__VinpClk__"+vscp->scopep()->nameDotless()+"__"+varp->name();
|
||||
// Create: VARREF(inpclk)
|
||||
// ...
|
||||
// ASSIGN(VARREF(inpclk), VARREF(var))
|
||||
AstVar* newvarp = new AstVar(varp->fileline(), AstVarType::MODULETEMP, newvarname, varp);
|
||||
m_topModp->addStmtp(newvarp);
|
||||
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopetopp, newvarp);
|
||||
m_scopetopp->addVarp(newvscp);
|
||||
} else {
|
||||
AstVar* varp = vscp->varp();
|
||||
string newvarname = "__VinpClk__"+vscp->scopep()->nameDotless()+"__"+varp->name();
|
||||
// Create: VARREF(inpclk)
|
||||
// ...
|
||||
// ASSIGN(VARREF(inpclk), VARREF(var))
|
||||
AstVar* newvarp = new AstVar(varp->fileline(),
|
||||
AstVarType::MODULETEMP, newvarname, varp);
|
||||
m_topModp->addStmtp(newvarp);
|
||||
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopetopp, newvarp);
|
||||
m_scopetopp->addVarp(newvscp);
|
||||
AstAssign* asninitp = new AstAssign(vscp->fileline(),
|
||||
new AstVarRef(vscp->fileline(), newvscp, true),
|
||||
new AstVarRef(vscp->fileline(), vscp, false));
|
||||
m_scopetopp->addFinalClkp(asninitp);
|
||||
//
|
||||
vscp->user2p(newvscp);
|
||||
return newvscp;
|
||||
}
|
||||
m_scopetopp->addFinalClkp(asninitp);
|
||||
//
|
||||
vscp->user2p(newvscp);
|
||||
return newvscp;
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstTopScope* nodep) {
|
||||
AstNode::user2ClearTree(); // user2p() used on entire tree
|
||||
AstNode::user2ClearTree(); // user2p() used on entire tree
|
||||
|
||||
AstScope* scopep = nodep->scopep();
|
||||
if (!scopep) nodep->v3fatalSrc("No scope found on top level");
|
||||
m_scopetopp = scopep;
|
||||
AstScope* scopep = nodep->scopep();
|
||||
if (!scopep) nodep->v3fatalSrc("No scope found on top level");
|
||||
m_scopetopp = scopep;
|
||||
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
//----
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
// Consumption/generation of a variable,
|
||||
AstVarScope* vscp = nodep->varScopep();
|
||||
if (!vscp) nodep->v3fatalSrc("Scope not assigned");
|
||||
if (m_activep && !nodep->user3()) {
|
||||
nodep->user3(true);
|
||||
if (vscp->isCircular()) {
|
||||
UINFO(8," VarActReplace "<<nodep<<endl);
|
||||
// Replace with the new variable
|
||||
AstVarScope* newvscp = genInpClk(vscp);
|
||||
AstVarRef* newrefp = new AstVarRef(nodep->fileline(), newvscp, nodep->lvalue());
|
||||
nodep->replaceWith(newrefp);
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
// Consumption/generation of a variable,
|
||||
AstVarScope* vscp = nodep->varScopep();
|
||||
if (!vscp) nodep->v3fatalSrc("Scope not assigned");
|
||||
if (m_activep && !nodep->user3()) {
|
||||
nodep->user3(true);
|
||||
if (vscp->isCircular()) {
|
||||
UINFO(8," VarActReplace "<<nodep<<endl);
|
||||
// Replace with the new variable
|
||||
AstVarScope* newvscp = genInpClk(vscp);
|
||||
AstVarRef* newrefp = new AstVarRef(nodep->fileline(), newvscp, nodep->lvalue());
|
||||
nodep->replaceWith(newrefp);
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstActive* nodep) {
|
||||
m_activep = nodep;
|
||||
m_activep = nodep;
|
||||
if (!nodep->sensesp()) nodep->v3fatalSrc("Unlinked");
|
||||
iterateChildren(nodep->sensesp()); // iterateAndNext?
|
||||
m_activep = NULL;
|
||||
m_activep = NULL;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
|
|
@ -126,9 +127,9 @@ private:
|
|||
public:
|
||||
// CONSTRUCTORS
|
||||
GenClkRenameVisitor(AstTopScope* nodep, AstNodeModule* topModp) {
|
||||
m_topModp = topModp;
|
||||
m_scopetopp = NULL;
|
||||
m_activep = NULL;
|
||||
m_topModp = topModp;
|
||||
m_scopetopp = NULL;
|
||||
m_activep = NULL;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~GenClkRenameVisitor() {}
|
||||
|
|
@ -141,8 +142,8 @@ class GenClkReadVisitor : public GenClkBaseVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared on top scope
|
||||
// AstVarScope::user() -> bool. Set when the var has been used as clock
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstVarScope::user() -> bool. Set when the var has been used as clock
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
AstActive* m_activep; // Inside activate statement
|
||||
|
|
@ -152,20 +153,20 @@ private:
|
|||
|
||||
// VISITORS
|
||||
virtual void visit(AstTopScope* nodep) {
|
||||
AstNode::user1ClearTree(); // user1p() used on entire tree
|
||||
AstNode::user1ClearTree(); // user1p() used on entire tree
|
||||
iterateChildren(nodep);
|
||||
{
|
||||
// Make the new clock signals and replace any activate references
|
||||
// See rename, it does some AstNode::userClearTree()'s
|
||||
GenClkRenameVisitor visitor (nodep, m_topModp);
|
||||
}
|
||||
{
|
||||
// Make the new clock signals and replace any activate references
|
||||
// See rename, it does some AstNode::userClearTree()'s
|
||||
GenClkRenameVisitor visitor (nodep, m_topModp);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
// Only track the top scopes, not lower level functions
|
||||
if (nodep->isTop()) {
|
||||
m_topModp = nodep;
|
||||
// Only track the top scopes, not lower level functions
|
||||
if (nodep->isTop()) {
|
||||
m_topModp = nodep;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstCCall* nodep) {
|
||||
iterateChildren(nodep);
|
||||
|
|
@ -188,37 +189,37 @@ private:
|
|||
//----
|
||||
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
// Consumption/generation of a variable,
|
||||
AstVarScope* vscp = nodep->varScopep();
|
||||
if (!vscp) nodep->v3fatalSrc("Scope not assigned");
|
||||
if (m_activep) {
|
||||
UINFO(8," VarAct "<<nodep<<endl);
|
||||
vscp->user1(true);
|
||||
}
|
||||
if (m_assignp && nodep->lvalue() && vscp->user1()) {
|
||||
// Variable was previously used as a clock, and is now being set
|
||||
// Thus a unordered generated clock...
|
||||
UINFO(8," VarSetAct "<<nodep<<endl);
|
||||
vscp->circular(true);
|
||||
}
|
||||
// Consumption/generation of a variable,
|
||||
AstVarScope* vscp = nodep->varScopep();
|
||||
if (!vscp) nodep->v3fatalSrc("Scope not assigned");
|
||||
if (m_activep) {
|
||||
UINFO(8," VarAct "<<nodep<<endl);
|
||||
vscp->user1(true);
|
||||
}
|
||||
if (m_assignp && nodep->lvalue() && vscp->user1()) {
|
||||
// Variable was previously used as a clock, and is now being set
|
||||
// Thus a unordered generated clock...
|
||||
UINFO(8," VarSetAct "<<nodep<<endl);
|
||||
vscp->circular(true);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeAssign* nodep) {
|
||||
//UINFO(8,"ASS "<<nodep<<endl);
|
||||
m_assignp = nodep;
|
||||
//UINFO(8,"ASS "<<nodep<<endl);
|
||||
m_assignp = nodep;
|
||||
iterateChildren(nodep);
|
||||
m_assignp = NULL;
|
||||
m_assignp = NULL;
|
||||
}
|
||||
virtual void visit(AstActive* nodep) {
|
||||
UINFO(8,"ACTIVE "<<nodep<<endl);
|
||||
m_activep = nodep;
|
||||
UINFO(8,"ACTIVE "<<nodep<<endl);
|
||||
m_activep = nodep;
|
||||
if (!nodep->sensesp()) nodep->v3fatalSrc("Unlinked");
|
||||
iterateChildren(nodep->sensesp()); // iterateAndNext?
|
||||
m_activep = NULL;
|
||||
m_activep = NULL;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
//-----
|
||||
virtual void visit(AstVar*) {} // Don't want varrefs under it
|
||||
virtual void visit(AstVar*) {} // Don't want varrefs under it
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void genClkAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -45,9 +45,9 @@ class AstNetlist;
|
|||
class VWidthMinUsage {
|
||||
public:
|
||||
enum en {
|
||||
LINT_WIDTH,
|
||||
MATCHES_WIDTH,
|
||||
VERILOG_WIDTH
|
||||
LINT_WIDTH,
|
||||
MATCHES_WIDTH,
|
||||
VERILOG_WIDTH
|
||||
};
|
||||
enum en m_e;
|
||||
inline VWidthMinUsage() : m_e(LINT_WIDTH) {}
|
||||
|
|
@ -56,40 +56,40 @@ public:
|
|||
explicit inline VWidthMinUsage(int _e) : m_e(static_cast<en>(_e)) {}
|
||||
operator en() const { return m_e; }
|
||||
};
|
||||
inline bool operator== (VWidthMinUsage lhs, VWidthMinUsage rhs) { return (lhs.m_e == rhs.m_e); }
|
||||
inline bool operator== (VWidthMinUsage lhs, VWidthMinUsage::en rhs) { return (lhs.m_e == rhs); }
|
||||
inline bool operator== (VWidthMinUsage::en lhs, VWidthMinUsage rhs) { return (lhs == rhs.m_e); }
|
||||
inline bool operator==(VWidthMinUsage lhs, VWidthMinUsage rhs) { return (lhs.m_e == rhs.m_e); }
|
||||
inline bool operator==(VWidthMinUsage lhs, VWidthMinUsage::en rhs) { return (lhs.m_e == rhs); }
|
||||
inline bool operator==(VWidthMinUsage::en lhs, VWidthMinUsage rhs) { return (lhs == rhs.m_e); }
|
||||
|
||||
//######################################################################
|
||||
// V3Global - The top level class for the entire program
|
||||
|
||||
class V3Global {
|
||||
// Globals
|
||||
AstNetlist* m_rootp; // Root of entire netlist
|
||||
VWidthMinUsage m_widthMinUsage; // What AstNode::widthMin() is used for
|
||||
AstNetlist* m_rootp; // Root of entire netlist
|
||||
VWidthMinUsage m_widthMinUsage; // What AstNode::widthMin() is used for
|
||||
|
||||
int m_debugFileNumber; // Number to append to debug files created
|
||||
bool m_assertDTypesResolved; // Tree should have dtypep()'s
|
||||
bool m_constRemoveXs; // Const needs to strip any Xs
|
||||
bool m_needHInlines; // Need __Inlines file
|
||||
bool m_needHeavy; // Need verilated_heavy.h include
|
||||
bool m_dpi; // Need __Dpi include files
|
||||
int m_debugFileNumber; // Number to append to debug files created
|
||||
bool m_assertDTypesResolved; // Tree should have dtypep()'s
|
||||
bool m_constRemoveXs; // Const needs to strip any Xs
|
||||
bool m_needHInlines; // Need __Inlines file
|
||||
bool m_needHeavy; // Need verilated_heavy.h include
|
||||
bool m_dpi; // Need __Dpi include files
|
||||
|
||||
public:
|
||||
// Options
|
||||
V3Options opt; // All options; let user see them directly
|
||||
V3Options opt; // All options; let user see them directly
|
||||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
V3Global() {
|
||||
m_debugFileNumber = 0;
|
||||
m_widthMinUsage = VWidthMinUsage::LINT_WIDTH;
|
||||
m_assertDTypesResolved = false;
|
||||
m_constRemoveXs = false;
|
||||
m_needHInlines = false;
|
||||
m_needHeavy = false;
|
||||
m_dpi = false;
|
||||
m_rootp = NULL; // created by makeInitNetlist() so static constructors run first
|
||||
m_debugFileNumber = 0;
|
||||
m_widthMinUsage = VWidthMinUsage::LINT_WIDTH;
|
||||
m_assertDTypesResolved = false;
|
||||
m_constRemoveXs = false;
|
||||
m_needHInlines = false;
|
||||
m_needHeavy = false;
|
||||
m_dpi = false;
|
||||
m_rootp = NULL; // created by makeInitNetlist() so static constructors run first
|
||||
}
|
||||
AstNetlist* makeNetlist();
|
||||
void boot() { UASSERT(!m_rootp,"call once"); m_rootp = makeNetlist(); }
|
||||
|
|
@ -108,10 +108,10 @@ public:
|
|||
bool constRemoveXs() const { return m_constRemoveXs; }
|
||||
void constRemoveXs(bool flag) { m_constRemoveXs = flag; }
|
||||
string debugFilename(const string& nameComment, int newNumber=0) {
|
||||
++m_debugFileNumber;
|
||||
if (newNumber) m_debugFileNumber = newNumber;
|
||||
char digits[100]; sprintf(digits, "%03d", m_debugFileNumber);
|
||||
return opt.makeDir()+"/"+opt.prefix()+"_"+digits+"_"+nameComment;
|
||||
++m_debugFileNumber;
|
||||
if (newNumber) m_debugFileNumber = newNumber;
|
||||
char digits[100]; sprintf(digits, "%03d", m_debugFileNumber);
|
||||
return opt.makeDir()+"/"+opt.prefix()+"_"+digits+"_"+nameComment;
|
||||
}
|
||||
bool needHInlines() const { return m_needHInlines; }
|
||||
void needHInlines(bool flag) { m_needHInlines=flag; }
|
||||
|
|
|
|||
178
src/V3Graph.cpp
178
src/V3Graph.cpp
|
|
@ -55,14 +55,14 @@ void V3GraphVertex::verticesPushBack(V3Graph* graphp) {
|
|||
|
||||
void V3GraphVertex::unlinkEdges(V3Graph* graphp) {
|
||||
for (V3GraphEdge* edgep = outBeginp(); edgep; /*BELOW*/) {
|
||||
V3GraphEdge* nextp = edgep->outNextp();
|
||||
edgep->unlinkDelete();
|
||||
edgep = nextp;
|
||||
V3GraphEdge* nextp = edgep->outNextp();
|
||||
edgep->unlinkDelete();
|
||||
edgep = nextp;
|
||||
}
|
||||
for (V3GraphEdge* edgep = inBeginp(); edgep; /*BELOW*/) {
|
||||
V3GraphEdge* nextp = edgep->inNextp();
|
||||
edgep->unlinkDelete();
|
||||
edgep = nextp;
|
||||
V3GraphEdge* nextp = edgep->inNextp();
|
||||
edgep->unlinkDelete();
|
||||
edgep = nextp;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -72,17 +72,17 @@ void V3GraphVertex::unlinkDelete(V3Graph* graphp) {
|
|||
// Unlink from vertex list
|
||||
m_vertices.unlink(graphp->m_vertices, this);
|
||||
// Delete
|
||||
delete this; //this=NULL;
|
||||
delete this; //this=NULL;
|
||||
}
|
||||
|
||||
void V3GraphVertex::rerouteEdges(V3Graph* graphp) {
|
||||
// Make new edges for each from/to pair
|
||||
for (V3GraphEdge* iedgep = inBeginp(); iedgep; iedgep=iedgep->inNextp()) {
|
||||
for (V3GraphEdge* oedgep = outBeginp(); oedgep; oedgep=oedgep->outNextp()) {
|
||||
for (V3GraphEdge* oedgep = outBeginp(); oedgep; oedgep=oedgep->outNextp()) {
|
||||
new V3GraphEdge(graphp, iedgep->fromp(), oedgep->top(),
|
||||
std::min(iedgep->weight(),oedgep->weight()),
|
||||
std::min(iedgep->weight(), oedgep->weight()),
|
||||
iedgep->cutable() && oedgep->cutable());
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove old edges
|
||||
unlinkEdges(graphp);
|
||||
|
|
@ -101,17 +101,17 @@ uint32_t V3GraphVertex::inHash() const {
|
|||
// So we need an associative operator, like XOR.
|
||||
// However with XOR multiple edges to the same source will cancel out,
|
||||
// so we use ADD. (Generally call this only after removing duplicates though)
|
||||
uint32_t hash=0;
|
||||
uint32_t hash = 0;
|
||||
for (V3GraphEdge* edgep = this->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
hash += cvtToHash(edgep->fromp());
|
||||
hash += cvtToHash(edgep->fromp());
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint32_t V3GraphVertex::outHash() const {
|
||||
uint32_t hash=0;
|
||||
uint32_t hash = 0;
|
||||
for (V3GraphEdge* edgep = this->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
hash += cvtToHash(edgep->top());
|
||||
hash += cvtToHash(edgep->top());
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
|
@ -163,8 +163,8 @@ std::ostream& operator<<(std::ostream& os, V3GraphVertex* vertexp) {
|
|||
// Edges
|
||||
|
||||
void V3GraphEdge::init(V3Graph* graphp,
|
||||
V3GraphVertex* fromp, V3GraphVertex* top, int weight,
|
||||
bool cutable) {
|
||||
V3GraphVertex* fromp, V3GraphVertex* top, int weight,
|
||||
bool cutable) {
|
||||
UASSERT(fromp, "Null from pointer");
|
||||
UASSERT(top, "Null to pointer");
|
||||
m_fromp = fromp;
|
||||
|
|
@ -191,7 +191,7 @@ void V3GraphEdge::unlinkDelete() {
|
|||
// Unlink to side
|
||||
m_ins.unlink(m_top->m_ins, this);
|
||||
// Delete
|
||||
delete this; //this=NULL;
|
||||
delete this; //this=NULL;
|
||||
}
|
||||
|
||||
void V3GraphEdge::outPushBack() {
|
||||
|
|
@ -222,18 +222,18 @@ void V3Graph::clear() {
|
|||
// Empty it of all points, as if making a new object
|
||||
// Delete the old edges
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; /*BELOW*/) {
|
||||
V3GraphEdge* nextp = edgep->outNextp();
|
||||
delete edgep;
|
||||
edgep = nextp;
|
||||
}
|
||||
vertexp->outUnlink();
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; /*BELOW*/) {
|
||||
V3GraphEdge* nextp = edgep->outNextp();
|
||||
delete edgep;
|
||||
edgep = nextp;
|
||||
}
|
||||
vertexp->outUnlink();
|
||||
}
|
||||
// Delete the old vertices
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; /*BELOW*/) {
|
||||
V3GraphVertex* nextp = vertexp->verticesNextp();
|
||||
delete vertexp;
|
||||
vertexp = nextp;
|
||||
V3GraphVertex* nextp = vertexp->verticesNextp();
|
||||
delete vertexp;
|
||||
vertexp = nextp;
|
||||
}
|
||||
verticesUnlink();
|
||||
}
|
||||
|
|
@ -246,25 +246,25 @@ void V3Graph::userClearVertices() {
|
|||
// the extra code on each read of user() would probably slow things
|
||||
// down more than help.
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->user(0);
|
||||
vertexp->userp(NULL); // Its a union, but might be different size than user()
|
||||
vertexp->user(0);
|
||||
vertexp->userp(NULL); // Its a union, but might be different size than user()
|
||||
}
|
||||
}
|
||||
|
||||
void V3Graph::userClearEdges() {
|
||||
// Clear user() in all of tree
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->user(0);
|
||||
edgep->userp(NULL); // Its a union, but might be different size than user()
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->user(0);
|
||||
edgep->userp(NULL); // Its a union, but might be different size than user()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void V3Graph::clearColors() {
|
||||
// Reset colors
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->m_color = 0;
|
||||
vertexp->m_color = 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -285,34 +285,34 @@ void V3Graph::dump(std::ostream& os) {
|
|||
os<<" Graph:\n";
|
||||
// Print vertices
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
os<<"\tNode: "<<vertexp->name();
|
||||
if (vertexp->color()) os<<" color="<<vertexp->color();
|
||||
os<<endl;
|
||||
// Print edges
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
os<<"\tNode: "<<vertexp->name();
|
||||
if (vertexp->color()) os<<" color="<<vertexp->color();
|
||||
os<<endl;
|
||||
// Print edges
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
dumpEdge(os, vertexp, edgep);
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
dumpEdge(os, vertexp, edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void V3Graph::dumpEdge(std::ostream& os, V3GraphVertex* vertexp, V3GraphEdge* edgep) {
|
||||
if (edgep->weight()
|
||||
&& (edgep->fromp() == vertexp
|
||||
|| edgep->top() == vertexp)) {
|
||||
os<<"\t\t";
|
||||
if (edgep->fromp() == vertexp) os << "-> "<<edgep->top()->name();
|
||||
if (edgep->top() == vertexp) os << "<- "<<edgep->fromp()->name();
|
||||
if (edgep->cutable()) os<<" [CUTABLE]";
|
||||
os<<endl;
|
||||
&& (edgep->fromp() == vertexp
|
||||
|| edgep->top() == vertexp)) {
|
||||
os<<"\t\t";
|
||||
if (edgep->fromp() == vertexp) os << "-> "<<edgep->top()->name();
|
||||
if (edgep->top() == vertexp) os << "<- "<<edgep->fromp()->name();
|
||||
if (edgep->cutable()) os<<" [CUTABLE]";
|
||||
os<<endl;
|
||||
}
|
||||
}
|
||||
|
||||
void V3Graph::dumpDotFilePrefixed(const string& nameComment, bool colorAsSubgraph) const {
|
||||
if (v3Global.opt.dumpTree()) {
|
||||
dumpDotFile(v3Global.debugFilename(nameComment)+".dot", colorAsSubgraph);
|
||||
dumpDotFile(v3Global.debugFilename(nameComment)+".dot", colorAsSubgraph);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -338,8 +338,9 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
|
|||
typedef std::multimap<string,V3GraphVertex*> SubgraphMmap;
|
||||
SubgraphMmap subgraphs;
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
string vertexSubgraph = (colorAsSubgraph && vertexp->color()) ? cvtToStr(vertexp->color()) : "";
|
||||
subgraphs.insert(make_pair(vertexSubgraph, vertexp));
|
||||
string vertexSubgraph
|
||||
= (colorAsSubgraph && vertexp->color()) ? cvtToStr(vertexp->color()) : "";
|
||||
subgraphs.insert(make_pair(vertexSubgraph, vertexp));
|
||||
}
|
||||
|
||||
// We use a map here, as we don't want to corrupt anything (userp) in the graph,
|
||||
|
|
@ -347,50 +348,51 @@ void V3Graph::dumpDotFile(const string& filename, bool colorAsSubgraph) const {
|
|||
std::map<V3GraphVertex*,int> numMap;
|
||||
|
||||
// Print vertices
|
||||
int n=0;
|
||||
int n = 0;
|
||||
string subgr;
|
||||
for (SubgraphMmap::iterator it = subgraphs.begin(); it!=subgraphs.end(); ++it) {
|
||||
string vertexSubgraph = it->first;
|
||||
V3GraphVertex* vertexp = it->second;
|
||||
numMap[vertexp] = n;
|
||||
if (subgr != vertexSubgraph) {
|
||||
if (subgr!="") *logp<<"\t};\n";
|
||||
subgr = vertexSubgraph;
|
||||
if (subgr!="") *logp<<"\tsubgraph cluster_"<<subgr<<" {\n";
|
||||
}
|
||||
if (subgr!="") *logp<<"\t";
|
||||
*logp<<"\tn"<<vertexp->dotName()<<(n++)
|
||||
<<"\t[fontsize=8 "
|
||||
<<"label=\""<<(vertexp->name()!="" ? vertexp->name() : "\\N");
|
||||
if (vertexp->rank()) *logp<<" r"<<vertexp->rank();
|
||||
if (vertexp->fanout()!=0.0) *logp<<" f"<<vertexp->fanout();
|
||||
if (vertexp->color()) *logp<<"\\n c"<<vertexp->color();
|
||||
*logp<<"\"";
|
||||
*logp<<", color="<<vertexp->dotColor();
|
||||
if (vertexp->dotStyle()!="") *logp<<", style="<<vertexp->dotStyle();
|
||||
if (vertexp->dotShape()!="") *logp<<", shape="<<vertexp->dotShape();
|
||||
*logp<<"];\n";
|
||||
string vertexSubgraph = it->first;
|
||||
V3GraphVertex* vertexp = it->second;
|
||||
numMap[vertexp] = n;
|
||||
if (subgr != vertexSubgraph) {
|
||||
if (subgr!="") *logp<<"\t};\n";
|
||||
subgr = vertexSubgraph;
|
||||
if (subgr!="") *logp<<"\tsubgraph cluster_"<<subgr<<" {\n";
|
||||
}
|
||||
if (subgr!="") *logp<<"\t";
|
||||
*logp<<"\tn"<<vertexp->dotName()<<(n++)
|
||||
<<"\t[fontsize=8 "
|
||||
<<"label=\""<<(vertexp->name()!="" ? vertexp->name() : "\\N");
|
||||
if (vertexp->rank()) *logp<<" r"<<vertexp->rank();
|
||||
if (vertexp->fanout()!=0.0) *logp<<" f"<<vertexp->fanout();
|
||||
if (vertexp->color()) *logp<<"\\n c"<<vertexp->color();
|
||||
*logp<<"\"";
|
||||
*logp<<", color="<<vertexp->dotColor();
|
||||
if (vertexp->dotStyle()!="") *logp<<", style="<<vertexp->dotStyle();
|
||||
if (vertexp->dotShape()!="") *logp<<", shape="<<vertexp->dotShape();
|
||||
*logp<<"];\n";
|
||||
}
|
||||
if (subgr!="") *logp<<"\t};\n";
|
||||
|
||||
// Print edges
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->weight()) {
|
||||
int fromVnum = numMap[edgep->fromp()];
|
||||
int toVnum = numMap[edgep->top()];
|
||||
*logp<<"\tn"<<edgep->fromp()->dotName()<<fromVnum
|
||||
<<" -> n"<<edgep->top()->dotName()<<toVnum
|
||||
<<" ["
|
||||
//<<"fontsize=8 label=\""<<(edgep->name()!="" ? edgep->name() : "\\E")<<"\""
|
||||
<<"fontsize=8 label=\""<<(edgep->dotLabel()!="" ? edgep->dotLabel() : "")<<"\""
|
||||
<<" weight="<<edgep->weight()
|
||||
<<" color="<<edgep->dotColor();
|
||||
if (edgep->dotStyle()!="") *logp<<" style="<<edgep->dotStyle();
|
||||
//if (edgep->cutable()) { *logp<<",constraint=false"; } // to rank without following edges
|
||||
*logp<<"];\n";
|
||||
}
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->weight()) {
|
||||
int fromVnum = numMap[edgep->fromp()];
|
||||
int toVnum = numMap[edgep->top()];
|
||||
*logp<<"\tn"<<edgep->fromp()->dotName()<<fromVnum
|
||||
<<" -> n"<<edgep->top()->dotName()<<toVnum
|
||||
<<" ["
|
||||
//<<"fontsize=8 label=\""<<(edgep->name()!="" ? edgep->name() : "\\E")<<"\""
|
||||
<<"fontsize=8 label=\""
|
||||
<<(edgep->dotLabel()!="" ? edgep->dotLabel() : "")<<"\""
|
||||
<<" weight="<<edgep->weight()
|
||||
<<" color="<<edgep->dotColor();
|
||||
if (edgep->dotStyle()!="") *logp<<" style="<<edgep->dotStyle();
|
||||
//if (edgep->cutable()) { *logp<<",constraint=false"; } // to rank without following edges
|
||||
*logp<<"];\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
// Vertex::m_user end, now unused
|
||||
|
||||
|
|
|
|||
137
src/V3Graph.h
137
src/V3Graph.h
|
|
@ -79,8 +79,8 @@ inline bool operator==(GraphWay::en lhs, GraphWay rhs) { return (lhs == rhs.m_e)
|
|||
|
||||
class V3Graph {
|
||||
private:
|
||||
// STATE
|
||||
V3List<V3GraphVertex*> m_vertices; // All vertices
|
||||
// MEMBERS
|
||||
V3List<V3GraphVertex*> m_vertices; // All vertices
|
||||
static int s_debug;
|
||||
protected:
|
||||
friend class V3GraphVertex; friend class V3GraphEdge;
|
||||
|
|
@ -99,10 +99,10 @@ public:
|
|||
V3Graph();
|
||||
virtual ~V3Graph();
|
||||
static void debug(int level) { s_debug = level; }
|
||||
virtual string dotRankDir() const { return "TB"; } // rankdir for dot plotting
|
||||
virtual string dotRankDir() const { return "TB"; } // rankdir for dot plotting
|
||||
|
||||
// METHODS
|
||||
void clear(); // Empty it of all vertices/edges, as if making a new object
|
||||
void clear(); // Empty it of all vertices/edges, as if making a new object
|
||||
void clearColors();
|
||||
|
||||
V3GraphVertex* verticesBeginp() const { return m_vertices.begin(); }
|
||||
|
|
@ -191,22 +191,22 @@ class V3GraphVertex {
|
|||
protected:
|
||||
friend class V3Graph; friend class V3GraphEdge;
|
||||
friend class GraphAcyc; friend class GraphAlgRank;
|
||||
V3ListEnt<V3GraphVertex*> m_vertices;// All vertices, linked list
|
||||
V3List<V3GraphEdge*> m_outs; // Outbound edges,linked list
|
||||
V3List<V3GraphEdge*> m_ins; // Inbound edges, linked list
|
||||
double m_fanout; // Order fanout
|
||||
uint32_t m_color; // Color of the node
|
||||
uint32_t m_rank; // Rank of edge
|
||||
V3ListEnt<V3GraphVertex*> m_vertices; // All vertices, linked list
|
||||
V3List<V3GraphEdge*> m_outs; // Outbound edges,linked list
|
||||
V3List<V3GraphEdge*> m_ins; // Inbound edges, linked list
|
||||
double m_fanout; // Order fanout
|
||||
uint32_t m_color; // Color of the node
|
||||
uint32_t m_rank; // Rank of edge
|
||||
union {
|
||||
void* m_userp; // Marker for some algorithms
|
||||
uint32_t m_user; // Marker for some algorithms
|
||||
void* m_userp; // Marker for some algorithms
|
||||
uint32_t m_user; // Marker for some algorithms
|
||||
};
|
||||
// METHODS
|
||||
void verticesPushBack(V3Graph* graphp);
|
||||
// ACCESSORS
|
||||
void fanout(double fanout) { m_fanout = fanout; }
|
||||
void inUnlink() { m_ins.reset(); } // Low level; normally unlinkDelete is what you want
|
||||
void outUnlink() { m_outs.reset(); } // Low level; normally unlinkDelete is what you want
|
||||
void inUnlink() { m_ins.reset(); } // Low level; normally unlinkDelete is what you want
|
||||
void outUnlink() { m_outs.reset(); } // Low level; normally unlinkDelete is what you want
|
||||
protected:
|
||||
// CONSTRUCTORS
|
||||
V3GraphVertex(V3Graph* graphp, const V3GraphVertex& old);
|
||||
|
|
@ -214,10 +214,10 @@ public:
|
|||
explicit V3GraphVertex(V3Graph* graphp);
|
||||
//! Clone copy constructor. Doesn't copy edges or user/userp.
|
||||
virtual V3GraphVertex* clone(V3Graph* graphp) const {
|
||||
return new V3GraphVertex(graphp, *this); }
|
||||
return new V3GraphVertex(graphp, *this); }
|
||||
virtual ~V3GraphVertex() {}
|
||||
void unlinkEdges(V3Graph* graphp);
|
||||
void unlinkDelete(V3Graph* graphp);
|
||||
void unlinkEdges(V3Graph* graphp);
|
||||
void unlinkDelete(V3Graph* graphp);
|
||||
|
||||
// ACCESSORS
|
||||
virtual string name() const { return ""; }
|
||||
|
|
@ -228,32 +228,32 @@ public:
|
|||
virtual uint32_t rankAdder() const { return 1; }
|
||||
virtual FileLine* fileline() const { return NULL; } // NULL for unknown
|
||||
virtual int sortCmp(const V3GraphVertex* rhsp) const {
|
||||
// LHS goes first if of lower rank, or lower fanout
|
||||
if (m_rank < rhsp->m_rank) return -1;
|
||||
if (m_rank > rhsp->m_rank) return 1;
|
||||
if (m_fanout < rhsp->m_fanout) return -1;
|
||||
if (m_fanout > rhsp->m_fanout) return 1;
|
||||
return 0;
|
||||
// LHS goes first if of lower rank, or lower fanout
|
||||
if (m_rank < rhsp->m_rank) return -1;
|
||||
if (m_rank > rhsp->m_rank) return 1;
|
||||
if (m_fanout < rhsp->m_fanout) return -1;
|
||||
if (m_fanout > rhsp->m_fanout) return 1;
|
||||
return 0;
|
||||
}
|
||||
uint32_t color() const { return m_color; }
|
||||
void color(uint32_t color) { m_color = color; }
|
||||
uint32_t rank() const { return m_rank; }
|
||||
uint32_t color() const { return m_color; }
|
||||
void color(uint32_t color) { m_color = color; }
|
||||
uint32_t rank() const { return m_rank; }
|
||||
void rank(uint32_t rank) { m_rank = rank; }
|
||||
double fanout() const { return m_fanout; }
|
||||
void user(uint32_t user) { m_user = user; }
|
||||
uint32_t user() const { return m_user; }
|
||||
void userp(void* userp) { m_userp = userp; }
|
||||
void* userp() const { return m_userp; }
|
||||
double fanout() const { return m_fanout; }
|
||||
void user(uint32_t user) { m_user = user; }
|
||||
uint32_t user() const { return m_user; }
|
||||
void userp(void* userp) { m_userp = userp; }
|
||||
void* userp() const { return m_userp; }
|
||||
// ITERATORS
|
||||
V3GraphVertex* verticesNextp() const { return m_vertices.nextp(); }
|
||||
V3GraphEdge* inBeginp() const { return m_ins.begin(); }
|
||||
bool inEmpty() const { return inBeginp()==NULL; }
|
||||
bool inSize1() const;
|
||||
uint32_t inHash() const;
|
||||
bool inEmpty() const { return inBeginp()==NULL; }
|
||||
bool inSize1() const;
|
||||
uint32_t inHash() const;
|
||||
V3GraphEdge* outBeginp() const { return m_outs.begin(); }
|
||||
bool outEmpty() const { return outBeginp()==NULL; }
|
||||
bool outSize1() const;
|
||||
uint32_t outHash() const;
|
||||
bool outEmpty() const { return outBeginp()==NULL; }
|
||||
bool outSize1() const;
|
||||
uint32_t outHash() const;
|
||||
V3GraphEdge* beginp(GraphWay way) const {
|
||||
return way.forward() ? outBeginp() : inBeginp(); }
|
||||
// METHODS
|
||||
|
|
@ -275,39 +275,42 @@ class V3GraphEdge {
|
|||
// Wires/variables aren't edges. Edges have only a single to/from vertex
|
||||
public:
|
||||
// ENUMS
|
||||
enum Cuttable { NOT_CUTABLE = false, CUTABLE = true }; // For passing to V3GraphEdge
|
||||
enum Cuttable { NOT_CUTABLE = false, CUTABLE = true }; // For passing to V3GraphEdge
|
||||
protected:
|
||||
friend class V3Graph; friend class V3GraphVertex;
|
||||
friend class GraphAcyc; friend class GraphAcycEdge;
|
||||
V3ListEnt<V3GraphEdge*> m_outs; // Next Outbound edge for same vertex (linked list)
|
||||
V3ListEnt<V3GraphEdge*> m_ins; // Next Inbound edge for same vertex (linked list)
|
||||
friend class V3Graph; friend class V3GraphVertex;
|
||||
friend class GraphAcyc; friend class GraphAcycEdge;
|
||||
V3ListEnt<V3GraphEdge*> m_outs; // Next Outbound edge for same vertex (linked list)
|
||||
V3ListEnt<V3GraphEdge*> m_ins; // Next Inbound edge for same vertex (linked list)
|
||||
//
|
||||
V3GraphVertex* m_fromp; // Vertices pointing to this edge
|
||||
V3GraphVertex* m_top; // Vertices this edge points to
|
||||
int m_weight; // Weight of the connection
|
||||
bool m_cutable; // Interconnect may be broken in order sorting
|
||||
V3GraphVertex* m_fromp; // Vertices pointing to this edge
|
||||
V3GraphVertex* m_top; // Vertices this edge points to
|
||||
int m_weight; // Weight of the connection
|
||||
bool m_cutable; // Interconnect may be broken in order sorting
|
||||
union {
|
||||
void* m_userp; // Marker for some algorithms
|
||||
uint32_t m_user; // Marker for some algorithms
|
||||
void* m_userp; // Marker for some algorithms
|
||||
uint32_t m_user; // Marker for some algorithms
|
||||
};
|
||||
// METHODS
|
||||
void init(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top, int weight, bool cutable=false);
|
||||
void cut() { m_weight = 0; } // 0 weight is same as disconnected
|
||||
void init(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top,
|
||||
int weight, bool cutable=false);
|
||||
void cut() { m_weight = 0; } // 0 weight is same as disconnected
|
||||
void outPushBack();
|
||||
void inPushBack();
|
||||
// CONSTRUCTORS
|
||||
protected:
|
||||
V3GraphEdge(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top, const V3GraphEdge& old) {
|
||||
init(graphp, fromp, top, old.m_weight, old.m_cutable);
|
||||
V3GraphEdge(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top,
|
||||
const V3GraphEdge& old) {
|
||||
init(graphp, fromp, top, old.m_weight, old.m_cutable);
|
||||
}
|
||||
public:
|
||||
//! Add DAG from one node to the specified node
|
||||
V3GraphEdge(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top, int weight, bool cutable=false) {
|
||||
init(graphp, fromp, top, weight, cutable);
|
||||
V3GraphEdge(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top,
|
||||
int weight, bool cutable=false) {
|
||||
init(graphp, fromp, top, weight, cutable);
|
||||
}
|
||||
//! Clone copy constructor. Doesn't copy existing vertices or user/userp.
|
||||
virtual V3GraphEdge* clone(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top) const {
|
||||
return new V3GraphEdge(graphp, fromp, top, *this); }
|
||||
return new V3GraphEdge(graphp, fromp, top, *this); }
|
||||
virtual ~V3GraphEdge() {}
|
||||
// METHODS
|
||||
virtual string name() const { return m_fromp->name()+"->"+m_top->name(); }
|
||||
|
|
@ -315,20 +318,20 @@ public:
|
|||
virtual string dotColor() const { return cutable()?"yellowGreen":"red"; }
|
||||
virtual string dotStyle() const { return cutable()?"dashed":""; }
|
||||
virtual int sortCmp(const V3GraphEdge* rhsp) const {
|
||||
if (!m_weight || !rhsp->m_weight) return 0;
|
||||
return top()->sortCmp(rhsp->top());
|
||||
if (!m_weight || !rhsp->m_weight) return 0;
|
||||
return top()->sortCmp(rhsp->top());
|
||||
}
|
||||
void unlinkDelete();
|
||||
void unlinkDelete();
|
||||
V3GraphEdge* relinkFromp(V3GraphVertex* newFromp);
|
||||
// ACCESSORS
|
||||
int weight() const { return m_weight; }
|
||||
void weight(int weight) { m_weight=weight; }
|
||||
bool cutable() const { return m_cutable; }
|
||||
void cutable(bool cutable) { m_cutable=cutable; }
|
||||
void userp(void* user) { m_userp = user; }
|
||||
void* userp() const { return m_userp; }
|
||||
void user(uint32_t user) { m_user = user; }
|
||||
uint32_t user() const { return m_user; }
|
||||
int weight() const { return m_weight; }
|
||||
void weight(int weight) { m_weight = weight; }
|
||||
bool cutable() const { return m_cutable; }
|
||||
void cutable(bool cutable) { m_cutable = cutable; }
|
||||
void userp(void* user) { m_userp = user; }
|
||||
void* userp() const { return m_userp; }
|
||||
void user(uint32_t user) { m_user = user; }
|
||||
uint32_t user() const { return m_user; }
|
||||
V3GraphVertex* fromp() const { return m_fromp; }
|
||||
V3GraphVertex* top() const { return m_top; }
|
||||
V3GraphVertex* closerp(GraphWay way) const { return way.forward() ? fromp() : top(); }
|
||||
|
|
@ -345,4 +348,4 @@ public:
|
|||
|
||||
//============================================================================
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -32,22 +32,22 @@
|
|||
//######################################################################
|
||||
//######################################################################
|
||||
// Algorithms - acyclic
|
||||
// Break the minimal number of backward edges to make the graph acyclic
|
||||
// Break the minimal number of backward edges to make the graph acyclic
|
||||
|
||||
class GraphAcycVertex : public V3GraphVertex {
|
||||
// user() is used for various sub-algorithm pieces
|
||||
V3GraphVertex* m_origVertexp; // Pointer to first vertex this represents
|
||||
V3GraphVertex* m_origVertexp; // Pointer to first vertex this represents
|
||||
protected:
|
||||
friend class GraphAcyc;
|
||||
V3ListEnt<GraphAcycVertex*> m_work; // List of vertices with optimization work left
|
||||
uint32_t m_storedRank; // Rank held until commit to edge placement
|
||||
bool m_onWorkList; // True if already on list of work to do
|
||||
bool m_deleted; // True if deleted
|
||||
V3ListEnt<GraphAcycVertex*> m_work; // List of vertices with optimization work left
|
||||
uint32_t m_storedRank; // Rank held until commit to edge placement
|
||||
bool m_onWorkList; // True if already on list of work to do
|
||||
bool m_deleted; // True if deleted
|
||||
public:
|
||||
|
||||
GraphAcycVertex(V3Graph* graphp, V3GraphVertex* origVertexp)
|
||||
: V3GraphVertex(graphp), m_origVertexp(origVertexp)
|
||||
, m_storedRank(0), m_onWorkList(false), m_deleted(false) {
|
||||
: V3GraphVertex(graphp), m_origVertexp(origVertexp)
|
||||
, m_storedRank(0), m_onWorkList(false), m_deleted(false) {
|
||||
}
|
||||
virtual ~GraphAcycVertex() {}
|
||||
V3GraphVertex* origVertexp() const { return m_origVertexp; }
|
||||
|
|
@ -64,14 +64,15 @@ class GraphAcycEdge : public V3GraphEdge {
|
|||
// userp() is always used to point to the head original graph edge
|
||||
private:
|
||||
typedef std::list<V3GraphEdge*> OrigEdgeList; // List of orig edges, see also GraphAcyc's decl
|
||||
V3GraphEdge* origEdgep() const {
|
||||
V3GraphEdge* origEdgep() const {
|
||||
OrigEdgeList* oEListp = static_cast<OrigEdgeList*>(userp());
|
||||
if (!oEListp) v3fatalSrc("No original edge associated with acyc edge "<<this<<endl);
|
||||
return (oEListp->front());
|
||||
if (!oEListp) v3fatalSrc("No original edge associated with acyc edge "<<this<<endl);
|
||||
return (oEListp->front());
|
||||
}
|
||||
public:
|
||||
GraphAcycEdge(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top, int weight, bool cutable=false)
|
||||
: V3GraphEdge(graphp, fromp, top, weight, cutable) {
|
||||
GraphAcycEdge(V3Graph* graphp, V3GraphVertex* fromp, V3GraphVertex* top,
|
||||
int weight, bool cutable=false)
|
||||
: V3GraphEdge(graphp, fromp, top, weight, cutable) {
|
||||
}
|
||||
virtual ~GraphAcycEdge() {}
|
||||
// yellow=we might still cut it, else oldEdge: yellowGreen=made uncutable, red=uncutable
|
||||
|
|
@ -82,9 +83,9 @@ public:
|
|||
|
||||
struct GraphAcycEdgeCmp {
|
||||
inline bool operator() (const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
|
||||
if (lhsp->weight() > rhsp->weight()) return 1; // LHS goes first
|
||||
if (lhsp->weight() < rhsp->weight()) return 0; // RHS goes first
|
||||
return 0;
|
||||
if (lhsp->weight() > rhsp->weight()) return 1; // LHS goes first
|
||||
if (lhsp->weight() < rhsp->weight()) return 0; // RHS goes first
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -96,17 +97,17 @@ private:
|
|||
typedef std::list<V3GraphEdge*> OrigEdgeList; // List of orig edges, see also GraphAcycEdge's decl
|
||||
// GRAPH USERS
|
||||
// origGraph
|
||||
// GraphVertex::user() GraphAycVerted* New graph node
|
||||
// GraphVertex::user() GraphAycVerted* New graph node
|
||||
// m_breakGraph
|
||||
// GraphEdge::user() OrigEdgeList* Old graph edges
|
||||
// GraphVertex::user bool Detection of loops in simplifyDupIterate
|
||||
// GraphEdge::user() OrigEdgeList* Old graph edges
|
||||
// GraphVertex::user bool Detection of loops in simplifyDupIterate
|
||||
// MEMBERS
|
||||
V3Graph* m_origGraphp; // Original graph
|
||||
V3Graph m_breakGraph; // Graph with only breakable edges represented
|
||||
V3List<GraphAcycVertex*> m_work; // List of vertices with optimization work left
|
||||
V3Graph* m_origGraphp; // Original graph
|
||||
V3Graph m_breakGraph; // Graph with only breakable edges represented
|
||||
V3List<GraphAcycVertex*> m_work; // List of vertices with optimization work left
|
||||
std::vector<OrigEdgeList*> m_origEdgeDelp; // List of deletions to do when done
|
||||
V3EdgeFuncP m_origEdgeFuncp; // Function that says we follow this edge (in original graph)
|
||||
uint32_t m_placeStep; // Number that user() must be equal to to indicate processing
|
||||
V3EdgeFuncP m_origEdgeFuncp; // Function that says we follow this edge (in original graph)
|
||||
uint32_t m_placeStep; // Number that user() must be equal to to indicate processing
|
||||
|
||||
static int debug() { return V3Graph::debug(); }
|
||||
|
||||
|
|
@ -126,73 +127,75 @@ private:
|
|||
bool placeIterate(GraphAcycVertex* vertexp, uint32_t currentRank);
|
||||
|
||||
inline bool origFollowEdge(V3GraphEdge* edgep) {
|
||||
return (edgep->weight() && (m_origEdgeFuncp)(edgep));
|
||||
return (edgep->weight() && (m_origEdgeFuncp)(edgep));
|
||||
}
|
||||
V3GraphEdge* edgeFromEdge(V3GraphEdge* oldedgep, V3GraphVertex* fromp, V3GraphVertex* top) {
|
||||
// Make new breakGraph edge, with old edge as a template
|
||||
// Make new breakGraph edge, with old edge as a template
|
||||
GraphAcycEdge* newEdgep = new GraphAcycEdge(&m_breakGraph, fromp, top,
|
||||
oldedgep->weight(), oldedgep->cutable());
|
||||
newEdgep->userp(oldedgep->userp()); // Keep pointer to OrigEdgeList
|
||||
return newEdgep;
|
||||
newEdgep->userp(oldedgep->userp()); // Keep pointer to OrigEdgeList
|
||||
return newEdgep;
|
||||
}
|
||||
void addOrigEdgep(V3GraphEdge* toEdgep, V3GraphEdge* addEdgep) {
|
||||
// Add addEdge (or it's list) to list of edges that break edge represents
|
||||
// Note addEdge may already have a bunch of similar linked edge representations. Yuk.
|
||||
UASSERT(addEdgep, "Adding NULL");
|
||||
if (!toEdgep->userp()) {
|
||||
OrigEdgeList* oep = new OrigEdgeList;
|
||||
m_origEdgeDelp.push_back(oep);
|
||||
toEdgep->userp(oep);
|
||||
}
|
||||
// Add addEdge (or it's list) to list of edges that break edge represents
|
||||
// Note addEdge may already have a bunch of similar linked edge representations. Yuk.
|
||||
UASSERT(addEdgep, "Adding NULL");
|
||||
if (!toEdgep->userp()) {
|
||||
OrigEdgeList* oep = new OrigEdgeList;
|
||||
m_origEdgeDelp.push_back(oep);
|
||||
toEdgep->userp(oep);
|
||||
}
|
||||
OrigEdgeList* oEListp = static_cast<OrigEdgeList*>(toEdgep->userp());
|
||||
if (OrigEdgeList* addListp = static_cast<OrigEdgeList*>(addEdgep->userp())) {
|
||||
for (OrigEdgeList::iterator it = addListp->begin(); it != addListp->end(); ++it) {
|
||||
oEListp->push_back(*it);
|
||||
}
|
||||
addListp->clear(); // Done with it
|
||||
} else {
|
||||
oEListp->push_back(addEdgep);
|
||||
}
|
||||
for (OrigEdgeList::iterator it = addListp->begin(); it != addListp->end(); ++it) {
|
||||
oEListp->push_back(*it);
|
||||
}
|
||||
addListp->clear(); // Done with it
|
||||
} else {
|
||||
oEListp->push_back(addEdgep);
|
||||
}
|
||||
}
|
||||
void cutOrigEdge(V3GraphEdge* breakEdgep, const char* why) {
|
||||
// From the break edge, cut edges in original graph it represents
|
||||
UINFO(8,why<<" CUT "<<breakEdgep->fromp()<<endl);
|
||||
breakEdgep->cut();
|
||||
// From the break edge, cut edges in original graph it represents
|
||||
UINFO(8,why<<" CUT "<<breakEdgep->fromp()<<endl);
|
||||
breakEdgep->cut();
|
||||
OrigEdgeList* oEListp = static_cast<OrigEdgeList*>(breakEdgep->userp());
|
||||
if (!oEListp) v3fatalSrc("No original edge associated with cutting edge "<<breakEdgep<<endl);
|
||||
// The breakGraph edge may represent multiple real edges; cut them all
|
||||
for (OrigEdgeList::iterator it = oEListp->begin(); it != oEListp->end(); ++it) {
|
||||
V3GraphEdge* origEdgep = *it;
|
||||
origEdgep->cut();
|
||||
UINFO(8," "<<why<<" "<<origEdgep->fromp()<<" ->"<<origEdgep->top()<<endl);
|
||||
}
|
||||
if (!oEListp) v3fatalSrc("No original edge associated with cutting edge "
|
||||
<<breakEdgep<<endl);
|
||||
// The breakGraph edge may represent multiple real edges; cut them all
|
||||
for (OrigEdgeList::iterator it = oEListp->begin(); it != oEListp->end(); ++it) {
|
||||
V3GraphEdge* origEdgep = *it;
|
||||
origEdgep->cut();
|
||||
UINFO(8," "<<why<<" "<<origEdgep->fromp()<<" ->"<<origEdgep->top()<<endl);
|
||||
}
|
||||
}
|
||||
// Work Que
|
||||
void workPush(V3GraphVertex* vertexp) {
|
||||
GraphAcycVertex* avertexp = static_cast<GraphAcycVertex*>(vertexp);
|
||||
// Add vertex to list of nodes needing further optimization trials
|
||||
if (!avertexp->m_onWorkList) {
|
||||
avertexp->m_onWorkList = true;
|
||||
avertexp->m_work.pushBack(m_work, avertexp);
|
||||
}
|
||||
// Add vertex to list of nodes needing further optimization trials
|
||||
if (!avertexp->m_onWorkList) {
|
||||
avertexp->m_onWorkList = true;
|
||||
avertexp->m_work.pushBack(m_work, avertexp);
|
||||
}
|
||||
}
|
||||
GraphAcycVertex* workBeginp() { return m_work.begin(); }
|
||||
void workPop() {
|
||||
GraphAcycVertex* avertexp = workBeginp();
|
||||
avertexp->m_onWorkList = false;
|
||||
avertexp->m_work.unlink(m_work, avertexp); }
|
||||
GraphAcycVertex* avertexp = workBeginp();
|
||||
avertexp->m_onWorkList = false;
|
||||
avertexp->m_work.unlink(m_work, avertexp); }
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
GraphAcyc(V3Graph* origGraphp, V3EdgeFuncP edgeFuncp) {
|
||||
m_origGraphp = origGraphp;
|
||||
m_origEdgeFuncp = edgeFuncp;
|
||||
m_placeStep = 0;
|
||||
m_origGraphp = origGraphp;
|
||||
m_origEdgeFuncp = edgeFuncp;
|
||||
m_placeStep = 0;
|
||||
}
|
||||
~GraphAcyc() {
|
||||
for (std::vector<OrigEdgeList*>::iterator it = m_origEdgeDelp.begin(); it != m_origEdgeDelp.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
m_origEdgeDelp.clear();
|
||||
for (std::vector<OrigEdgeList*>::iterator it = m_origEdgeDelp.begin();
|
||||
it != m_origEdgeDelp.end(); ++it) {
|
||||
delete (*it);
|
||||
}
|
||||
m_origEdgeDelp.clear();
|
||||
}
|
||||
void main();
|
||||
};
|
||||
|
|
@ -206,59 +209,62 @@ void GraphAcyc::buildGraph(V3Graph* origGraphp) {
|
|||
// For each old node, make a new graph node for optimization
|
||||
origGraphp->userClearVertices();
|
||||
origGraphp->userClearEdges();
|
||||
for (V3GraphVertex* overtexp = origGraphp->verticesBeginp(); overtexp; overtexp=overtexp->verticesNextp()) {
|
||||
if (overtexp->color()) {
|
||||
GraphAcycVertex* avertexp = new GraphAcycVertex(&m_breakGraph, overtexp);
|
||||
overtexp->userp(avertexp); // Stash so can look up later
|
||||
}
|
||||
for (V3GraphVertex* overtexp = origGraphp->verticesBeginp();
|
||||
overtexp; overtexp = overtexp->verticesNextp()) {
|
||||
if (overtexp->color()) {
|
||||
GraphAcycVertex* avertexp = new GraphAcycVertex(&m_breakGraph, overtexp);
|
||||
overtexp->userp(avertexp); // Stash so can look up later
|
||||
}
|
||||
}
|
||||
|
||||
// Build edges between logic vertices
|
||||
for (V3GraphVertex* overtexp = origGraphp->verticesBeginp(); overtexp; overtexp=overtexp->verticesNextp()) {
|
||||
if (overtexp->color()) {
|
||||
for (V3GraphVertex* overtexp = origGraphp->verticesBeginp();
|
||||
overtexp; overtexp = overtexp->verticesNextp()) {
|
||||
if (overtexp->color()) {
|
||||
GraphAcycVertex* avertexp = static_cast<GraphAcycVertex*>(overtexp->userp());
|
||||
buildGraphIterate(overtexp, avertexp);
|
||||
}
|
||||
buildGraphIterate(overtexp, avertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphAcyc::buildGraphIterate(V3GraphVertex* overtexp, GraphAcycVertex* avertexp) {
|
||||
// Make new edges
|
||||
for (V3GraphEdge* edgep = overtexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (origFollowEdge(edgep)) { // not cut
|
||||
V3GraphVertex* toVertexp = edgep->top();
|
||||
if (toVertexp->color()) {
|
||||
if (origFollowEdge(edgep)) { // not cut
|
||||
V3GraphVertex* toVertexp = edgep->top();
|
||||
if (toVertexp->color()) {
|
||||
GraphAcycVertex* toAVertexp = static_cast<GraphAcycVertex*>(toVertexp->userp());
|
||||
// Replicate the old edge into the new graph
|
||||
// There may be multiple edges between same pairs of vertices
|
||||
V3GraphEdge* breakEdgep = new GraphAcycEdge
|
||||
(&m_breakGraph, avertexp, toAVertexp, edgep->weight(), edgep->cutable());
|
||||
// Replicate the old edge into the new graph
|
||||
// There may be multiple edges between same pairs of vertices
|
||||
V3GraphEdge* breakEdgep = new GraphAcycEdge
|
||||
(&m_breakGraph, avertexp, toAVertexp, edgep->weight(), edgep->cutable());
|
||||
addOrigEdgep(breakEdgep, edgep); // So can find original edge
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GraphAcyc::simplify(bool allowCut) {
|
||||
// Add all nodes to list of work to do
|
||||
for (V3GraphVertex* vertexp = m_breakGraph.verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
workPush(vertexp);
|
||||
for (V3GraphVertex* vertexp = m_breakGraph.verticesBeginp();
|
||||
vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
workPush(vertexp);
|
||||
}
|
||||
// Optimize till everything finished
|
||||
while (GraphAcycVertex* vertexp = workBeginp()) {
|
||||
workPop();
|
||||
simplifyNone(vertexp);
|
||||
simplifyOne(vertexp);
|
||||
simplifyOut(vertexp);
|
||||
simplifyDup(vertexp);
|
||||
if (allowCut) {
|
||||
// The main algorithm works without these, though slower
|
||||
// So if changing the main algorithm, comment these out for a test run
|
||||
if (v3Global.opt.oAcycSimp()) {
|
||||
cutBasic(vertexp);
|
||||
cutBackward(vertexp);
|
||||
}
|
||||
}
|
||||
workPop();
|
||||
simplifyNone(vertexp);
|
||||
simplifyOne(vertexp);
|
||||
simplifyOut(vertexp);
|
||||
simplifyDup(vertexp);
|
||||
if (allowCut) {
|
||||
// The main algorithm works without these, though slower
|
||||
// So if changing the main algorithm, comment these out for a test run
|
||||
if (v3Global.opt.oAcycSimp()) {
|
||||
cutBasic(vertexp);
|
||||
cutBackward(vertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
deleteMarked();
|
||||
}
|
||||
|
|
@ -266,11 +272,11 @@ void GraphAcyc::simplify(bool allowCut) {
|
|||
void GraphAcyc::deleteMarked() {
|
||||
// Delete nodes marked for removal
|
||||
for (V3GraphVertex* nextp, *vertexp = m_breakGraph.verticesBeginp(); vertexp; vertexp=nextp) {
|
||||
nextp = vertexp->verticesNextp();
|
||||
nextp = vertexp->verticesNextp();
|
||||
GraphAcycVertex* avertexp = static_cast<GraphAcycVertex*>(vertexp);
|
||||
if (avertexp->isDelete()) {
|
||||
avertexp->unlinkDelete(&m_breakGraph); VL_DANGLING(avertexp);
|
||||
}
|
||||
if (avertexp->isDelete()) {
|
||||
avertexp->unlinkDelete(&m_breakGraph); VL_DANGLING(avertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -279,21 +285,21 @@ void GraphAcyc::simplifyNone(GraphAcycVertex* avertexp) {
|
|||
// Likewise, vertices with no outputs
|
||||
if (avertexp->isDelete()) return;
|
||||
if (avertexp->inEmpty() || avertexp->outEmpty()) {
|
||||
UINFO(9," SimplifyNoneRemove "<<avertexp<<endl);
|
||||
avertexp->setDelete(); // Mark so we won't delete it twice
|
||||
// Remove edges
|
||||
while (V3GraphEdge* edgep = avertexp->outBeginp()) {
|
||||
V3GraphVertex* otherVertexp = edgep->top();
|
||||
//UINFO(9," out "<<otherVertexp<<endl);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(otherVertexp);
|
||||
}
|
||||
while (V3GraphEdge* edgep = avertexp->inBeginp()) {
|
||||
V3GraphVertex* otherVertexp = edgep->fromp();
|
||||
//UINFO(9," in "<<otherVertexp<<endl);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(otherVertexp);
|
||||
}
|
||||
UINFO(9," SimplifyNoneRemove "<<avertexp<<endl);
|
||||
avertexp->setDelete(); // Mark so we won't delete it twice
|
||||
// Remove edges
|
||||
while (V3GraphEdge* edgep = avertexp->outBeginp()) {
|
||||
V3GraphVertex* otherVertexp = edgep->top();
|
||||
//UINFO(9," out "<<otherVertexp<<endl);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(otherVertexp);
|
||||
}
|
||||
while (V3GraphEdge* edgep = avertexp->inBeginp()) {
|
||||
V3GraphVertex* otherVertexp = edgep->fromp();
|
||||
//UINFO(9," in "<<otherVertexp<<endl);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(otherVertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -301,32 +307,32 @@ void GraphAcyc::simplifyOne(GraphAcycVertex* avertexp) {
|
|||
// If a node has one input and one output, we can remove it and change the edges
|
||||
if (avertexp->isDelete()) return;
|
||||
if (avertexp->inSize1() && avertexp->outSize1()) {
|
||||
V3GraphEdge* inEdgep = avertexp->inBeginp();
|
||||
V3GraphEdge* outEdgep = avertexp->outBeginp();
|
||||
V3GraphVertex* inVertexp = inEdgep->fromp();
|
||||
V3GraphVertex* outVertexp = outEdgep->top();
|
||||
// The in and out may be the same node; we'll make a loop
|
||||
// The in OR out may be THIS node; we can't delete it then.
|
||||
if (inVertexp!=avertexp && outVertexp!=avertexp) {
|
||||
UINFO(9," SimplifyOneRemove "<<avertexp<<endl);
|
||||
avertexp->setDelete(); // Mark so we won't delete it twice
|
||||
// Make a new edge connecting the two vertices directly
|
||||
// If both are breakable, we pick the one with less weight, else it's arbitrary
|
||||
// We can forget about the origEdge list for the "non-selected" set of edges,
|
||||
// as we need to break only one set or the other set of edges, not both.
|
||||
// (This is why we must give preference to the cutable set.)
|
||||
V3GraphEdge* templateEdgep = ( (inEdgep->cutable()
|
||||
&& (!outEdgep->cutable()
|
||||
|| inEdgep->weight()<outEdgep->weight() ))
|
||||
? inEdgep : outEdgep);
|
||||
// cppcheck-suppress leakReturnValNotUsed
|
||||
edgeFromEdge(templateEdgep, inVertexp, outVertexp);
|
||||
// Remove old edge
|
||||
inEdgep->unlinkDelete(); VL_DANGLING(inEdgep);
|
||||
outEdgep->unlinkDelete(); VL_DANGLING(outEdgep); VL_DANGLING(templateEdgep);
|
||||
workPush(inVertexp);
|
||||
workPush(outVertexp);
|
||||
}
|
||||
V3GraphEdge* inEdgep = avertexp->inBeginp();
|
||||
V3GraphEdge* outEdgep = avertexp->outBeginp();
|
||||
V3GraphVertex* inVertexp = inEdgep->fromp();
|
||||
V3GraphVertex* outVertexp = outEdgep->top();
|
||||
// The in and out may be the same node; we'll make a loop
|
||||
// The in OR out may be THIS node; we can't delete it then.
|
||||
if (inVertexp!=avertexp && outVertexp!=avertexp) {
|
||||
UINFO(9," SimplifyOneRemove "<<avertexp<<endl);
|
||||
avertexp->setDelete(); // Mark so we won't delete it twice
|
||||
// Make a new edge connecting the two vertices directly
|
||||
// If both are breakable, we pick the one with less weight, else it's arbitrary
|
||||
// We can forget about the origEdge list for the "non-selected" set of edges,
|
||||
// as we need to break only one set or the other set of edges, not both.
|
||||
// (This is why we must give preference to the cutable set.)
|
||||
V3GraphEdge* templateEdgep = ( (inEdgep->cutable()
|
||||
&& (!outEdgep->cutable()
|
||||
|| inEdgep->weight()<outEdgep->weight() ))
|
||||
? inEdgep : outEdgep);
|
||||
// cppcheck-suppress leakReturnValNotUsed
|
||||
edgeFromEdge(templateEdgep, inVertexp, outVertexp);
|
||||
// Remove old edge
|
||||
inEdgep->unlinkDelete(); VL_DANGLING(inEdgep);
|
||||
outEdgep->unlinkDelete(); VL_DANGLING(outEdgep); VL_DANGLING(templateEdgep);
|
||||
workPush(inVertexp);
|
||||
workPush(outVertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -335,34 +341,34 @@ void GraphAcyc::simplifyOut(GraphAcycVertex* avertexp) {
|
|||
// to the next node in the list
|
||||
if (avertexp->isDelete()) return;
|
||||
if (avertexp->outSize1()) {
|
||||
V3GraphEdge* outEdgep = avertexp->outBeginp();
|
||||
if (!outEdgep->cutable()) {
|
||||
V3GraphVertex* outVertexp = outEdgep->top();
|
||||
UINFO(9," SimplifyOutRemove "<<avertexp<<endl);
|
||||
avertexp->setDelete(); // Mark so we won't delete it twice
|
||||
for (V3GraphEdge* nextp, *inEdgep = avertexp->inBeginp(); inEdgep; inEdgep=nextp) {
|
||||
nextp = inEdgep->inNextp();
|
||||
V3GraphVertex* inVertexp = inEdgep->fromp();
|
||||
if (inVertexp == avertexp) {
|
||||
if (debug()) v3error("Non-cutable edge forms a loop, vertex="<<avertexp);
|
||||
v3error("Circular logic when ordering code (non-cutable edge loop)");
|
||||
m_origGraphp->reportLoops(&V3GraphEdge::followNotCutable,
|
||||
avertexp->origVertexp()); // calls OrderGraph::loopsVertexCb
|
||||
// Things are unlikely to end well at this point,
|
||||
// but we'll try something to get to further errors...
|
||||
inEdgep->cutable(true);
|
||||
return;
|
||||
}
|
||||
// Make a new edge connecting the two vertices directly
|
||||
// cppcheck-suppress leakReturnValNotUsed
|
||||
edgeFromEdge(inEdgep, inVertexp, outVertexp);
|
||||
// Remove old edge
|
||||
inEdgep->unlinkDelete(); VL_DANGLING(inEdgep);
|
||||
workPush(inVertexp);
|
||||
}
|
||||
outEdgep->unlinkDelete(); VL_DANGLING(outEdgep);
|
||||
workPush(outVertexp);
|
||||
}
|
||||
V3GraphEdge* outEdgep = avertexp->outBeginp();
|
||||
if (!outEdgep->cutable()) {
|
||||
V3GraphVertex* outVertexp = outEdgep->top();
|
||||
UINFO(9," SimplifyOutRemove "<<avertexp<<endl);
|
||||
avertexp->setDelete(); // Mark so we won't delete it twice
|
||||
for (V3GraphEdge* nextp, *inEdgep = avertexp->inBeginp(); inEdgep; inEdgep=nextp) {
|
||||
nextp = inEdgep->inNextp();
|
||||
V3GraphVertex* inVertexp = inEdgep->fromp();
|
||||
if (inVertexp == avertexp) {
|
||||
if (debug()) v3error("Non-cutable edge forms a loop, vertex="<<avertexp);
|
||||
v3error("Circular logic when ordering code (non-cutable edge loop)");
|
||||
m_origGraphp->reportLoops(&V3GraphEdge::followNotCutable,
|
||||
avertexp->origVertexp()); // calls OrderGraph::loopsVertexCb
|
||||
// Things are unlikely to end well at this point,
|
||||
// but we'll try something to get to further errors...
|
||||
inEdgep->cutable(true);
|
||||
return;
|
||||
}
|
||||
// Make a new edge connecting the two vertices directly
|
||||
// cppcheck-suppress leakReturnValNotUsed
|
||||
edgeFromEdge(inEdgep, inVertexp, outVertexp);
|
||||
// Remove old edge
|
||||
inEdgep->unlinkDelete(); VL_DANGLING(inEdgep);
|
||||
workPush(inVertexp);
|
||||
}
|
||||
outEdgep->unlinkDelete(); VL_DANGLING(outEdgep);
|
||||
workPush(outVertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -371,37 +377,37 @@ void GraphAcyc::simplifyDup(GraphAcycVertex* avertexp) {
|
|||
if (avertexp->isDelete()) return;
|
||||
// Clear marks
|
||||
for (V3GraphEdge* edgep = avertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->top()->userp(NULL);
|
||||
edgep->top()->userp(NULL);
|
||||
}
|
||||
// Mark edges and detect duplications
|
||||
for (V3GraphEdge* nextp, *edgep = avertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
V3GraphVertex* outVertexp = edgep->top();
|
||||
nextp = edgep->outNextp();
|
||||
V3GraphVertex* outVertexp = edgep->top();
|
||||
V3GraphEdge* prevEdgep = static_cast<V3GraphEdge*>(outVertexp->userp());
|
||||
if (prevEdgep) {
|
||||
if (!prevEdgep->cutable()) {
|
||||
// !cutable duplicates prev !cutable: we can ignore it, redundant
|
||||
// cutable duplicates prev !cutable: know it's not a relevant loop, ignore it
|
||||
UINFO(8," DelDupEdge "<<avertexp<<" -> "<<edgep->top()<<endl);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
} else if (!edgep->cutable()) {
|
||||
// !cutable duplicates prev cutable: delete the earlier cutable
|
||||
UINFO(8," DelDupPrev "<<avertexp<<" -> "<<prevEdgep->top()<<endl);
|
||||
prevEdgep->unlinkDelete(); VL_DANGLING(prevEdgep);
|
||||
outVertexp->userp(edgep);
|
||||
} else {
|
||||
// cutable duplicates prev cutable: combine weights
|
||||
UINFO(8," DelDupComb "<<avertexp<<" -> "<<edgep->top()<<endl);
|
||||
if (prevEdgep) {
|
||||
if (!prevEdgep->cutable()) {
|
||||
// !cutable duplicates prev !cutable: we can ignore it, redundant
|
||||
// cutable duplicates prev !cutable: know it's not a relevant loop, ignore it
|
||||
UINFO(8," DelDupEdge "<<avertexp<<" -> "<<edgep->top()<<endl);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
} else if (!edgep->cutable()) {
|
||||
// !cutable duplicates prev cutable: delete the earlier cutable
|
||||
UINFO(8," DelDupPrev "<<avertexp<<" -> "<<prevEdgep->top()<<endl);
|
||||
prevEdgep->unlinkDelete(); VL_DANGLING(prevEdgep);
|
||||
outVertexp->userp(edgep);
|
||||
} else {
|
||||
// cutable duplicates prev cutable: combine weights
|
||||
UINFO(8," DelDupComb "<<avertexp<<" -> "<<edgep->top()<<endl);
|
||||
prevEdgep->weight(prevEdgep->weight() + edgep->weight());
|
||||
addOrigEdgep(prevEdgep, edgep);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
}
|
||||
workPush(outVertexp);
|
||||
workPush(avertexp);
|
||||
} else {
|
||||
// No previous assignment
|
||||
outVertexp->userp(edgep);
|
||||
}
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
}
|
||||
workPush(outVertexp);
|
||||
workPush(avertexp);
|
||||
} else {
|
||||
// No previous assignment
|
||||
outVertexp->userp(edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -409,12 +415,12 @@ void GraphAcyc::cutBasic(GraphAcycVertex* avertexp) {
|
|||
// Detect and cleanup any loops from node to itself
|
||||
if (avertexp->isDelete()) return;
|
||||
for (V3GraphEdge* nextp, *edgep = avertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
if (edgep->cutable() && edgep->top()==avertexp) {
|
||||
nextp = edgep->outNextp();
|
||||
if (edgep->cutable() && edgep->top()==avertexp) {
|
||||
cutOrigEdge(edgep, " Cut Basic");
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(avertexp);
|
||||
}
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(avertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -423,19 +429,19 @@ void GraphAcyc::cutBackward(GraphAcycVertex* avertexp) {
|
|||
if (avertexp->isDelete()) return;
|
||||
// Clear marks
|
||||
for (V3GraphEdge* edgep = avertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->top()->user(false);
|
||||
edgep->top()->user(false);
|
||||
}
|
||||
for (V3GraphEdge* edgep = avertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
if (!edgep->cutable()) edgep->fromp()->user(true);
|
||||
if (!edgep->cutable()) edgep->fromp()->user(true);
|
||||
}
|
||||
// Detect duplications
|
||||
for (V3GraphEdge* nextp, *edgep = avertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
if (edgep->cutable() && edgep->top()->user()) {
|
||||
nextp = edgep->outNextp();
|
||||
if (edgep->cutable() && edgep->top()->user()) {
|
||||
cutOrigEdge(edgep, " Cut A->B->A");
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(avertexp);
|
||||
}
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
workPush(avertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -444,24 +450,26 @@ void GraphAcyc::place() {
|
|||
|
||||
// Make a list of all cutable edges in the graph
|
||||
int numEdges = 0;
|
||||
for (V3GraphVertex* vertexp = m_breakGraph.verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->weight() && edgep->cutable()) {
|
||||
numEdges++;
|
||||
}
|
||||
}
|
||||
for (V3GraphVertex* vertexp = m_breakGraph.verticesBeginp();
|
||||
vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->weight() && edgep->cutable()) {
|
||||
numEdges++;
|
||||
}
|
||||
}
|
||||
}
|
||||
UINFO(4, " Cutable edges = "<<numEdges<<endl);
|
||||
|
||||
std::vector<V3GraphEdge*> edges; // List of all edges to be processed
|
||||
edges.reserve(numEdges+1); // Make the vector properly sized right off the bat -- faster than reallocating
|
||||
for (V3GraphVertex* vertexp = m_breakGraph.verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->user(0); // Clear in prep of next step
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->weight() && edgep->cutable()) {
|
||||
edges.push_back(edgep);
|
||||
}
|
||||
}
|
||||
edges.reserve(numEdges+1); // Make the vector properly sized right off the bat -- faster than reallocating
|
||||
for (V3GraphVertex* vertexp = m_breakGraph.verticesBeginp();
|
||||
vertexp; vertexp = vertexp->verticesNextp()) {
|
||||
vertexp->user(0); // Clear in prep of next step
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->weight() && edgep->cutable()) {
|
||||
edges.push_back(edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Sort by weight, then by vertex (so that we completely process one vertex, when possible)
|
||||
|
|
@ -470,8 +478,8 @@ void GraphAcyc::place() {
|
|||
// Process each edge in weighted order
|
||||
m_placeStep = 10;
|
||||
for (std::vector<V3GraphEdge*>::iterator it = edges.begin(); it!=edges.end(); ++it) {
|
||||
V3GraphEdge* edgep = (*it);
|
||||
placeTryEdge(edgep);
|
||||
V3GraphEdge* edgep = (*it);
|
||||
placeTryEdge(edgep);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -487,23 +495,23 @@ void GraphAcyc::placeTryEdge(V3GraphEdge* edgep) {
|
|||
bool loop = placeIterate(static_cast<GraphAcycVertex*>(edgep->top()),
|
||||
edgep->fromp()->rank()+1);
|
||||
if (!loop) {
|
||||
// No loop, we can keep it as uncutable
|
||||
// Commit the new ranks we calculated
|
||||
// Just cleanup the list. If this is slow, we can add another set of
|
||||
// user counters to avoid cleaning up the list.
|
||||
while (workBeginp()) {
|
||||
workPop();
|
||||
}
|
||||
// No loop, we can keep it as uncutable
|
||||
// Commit the new ranks we calculated
|
||||
// Just cleanup the list. If this is slow, we can add another set of
|
||||
// user counters to avoid cleaning up the list.
|
||||
while (workBeginp()) {
|
||||
workPop();
|
||||
}
|
||||
} else {
|
||||
// Adding this edge would cause a loop, kill it
|
||||
edgep->cutable(true); // So graph still looks pretty
|
||||
// Adding this edge would cause a loop, kill it
|
||||
edgep->cutable(true); // So graph still looks pretty
|
||||
cutOrigEdge(edgep, " Cut loop");
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
// Backout the ranks we calculated
|
||||
while (GraphAcycVertex* vertexp = workBeginp()) {
|
||||
workPop();
|
||||
vertexp->rank(vertexp->m_storedRank);
|
||||
}
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
// Backout the ranks we calculated
|
||||
while (GraphAcycVertex* vertexp = workBeginp()) {
|
||||
workPop();
|
||||
vertexp->rank(vertexp->m_storedRank);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -517,18 +525,18 @@ bool GraphAcyc::placeIterate(GraphAcycVertex* vertexp, uint32_t currentRank) {
|
|||
vertexp->user(m_placeStep);
|
||||
// Remember we're changing the rank of this node; might need to back out
|
||||
if (!vertexp->m_onWorkList) {
|
||||
vertexp->m_storedRank = vertexp->rank();
|
||||
workPush(vertexp);
|
||||
vertexp->m_storedRank = vertexp->rank();
|
||||
workPush(vertexp);
|
||||
}
|
||||
vertexp->rank(currentRank);
|
||||
// Follow all edges and increase their ranks
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->weight() && !edgep->cutable()) {
|
||||
if (edgep->weight() && !edgep->cutable()) {
|
||||
if (placeIterate(static_cast<GraphAcycVertex*>(edgep->top()), currentRank+1)) {
|
||||
// We don't need to reset user(); we'll use a different placeStep for the next edge
|
||||
return true; // Loop detected
|
||||
}
|
||||
}
|
||||
// We don't need to reset user(); we'll use a different placeStep for the next edge
|
||||
return true; // Loop detected
|
||||
}
|
||||
}
|
||||
}
|
||||
vertexp->user(0);
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -41,30 +41,30 @@ void V3Graph::deleteCutableOnlyEdges() {
|
|||
// Vertex::m_user begin: indicates can be deleted
|
||||
// Pass 1, mark those. Don't delete now, as we don't want to rip out whole trees
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->user(true);
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
if (!edgep->cutable()) {
|
||||
vertexp->user(false); // Can't delete it
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (!edgep->cutable()) {
|
||||
vertexp->user(false); // Can't delete it
|
||||
break;
|
||||
}
|
||||
}
|
||||
vertexp->user(true);
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
if (!edgep->cutable()) {
|
||||
vertexp->user(false); // Can't delete it
|
||||
break;
|
||||
}
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (!edgep->cutable()) {
|
||||
vertexp->user(false); // Can't delete it
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Pass 2, delete those marked
|
||||
// Rather than doing a delete() we set the weight to 0 which disconnects the edge.
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (vertexp->user()) {
|
||||
//UINFO(7,"Disconnect "<<vertexp->name()<<endl);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->cut();
|
||||
}
|
||||
}
|
||||
if (vertexp->user()) {
|
||||
//UINFO(7,"Disconnect "<<vertexp->name()<<endl);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->cut();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Vertex::m_user end, now unused
|
||||
|
|
@ -75,54 +75,55 @@ void V3Graph::deleteCutableOnlyEdges() {
|
|||
// Algorithms - weakly connected components
|
||||
|
||||
class GraphRemoveRedundant : GraphAlg<> {
|
||||
bool m_sumWeights; ///< Sum, rather then maximize weights
|
||||
bool m_sumWeights; ///< Sum, rather then maximize weights
|
||||
private:
|
||||
void main() {
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexIterate(vertexp);
|
||||
}
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexIterate(vertexp);
|
||||
}
|
||||
}
|
||||
void vertexIterate(V3GraphVertex* vertexp) {
|
||||
// Clear marks
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->top()->userp(NULL);
|
||||
}
|
||||
// Mark edges and detect duplications
|
||||
for (V3GraphEdge* nextp, *edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
if (followEdge(edgep)) {
|
||||
V3GraphVertex* outVertexp = edgep->top();
|
||||
// Clear marks
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
edgep->top()->userp(NULL);
|
||||
}
|
||||
// Mark edges and detect duplications
|
||||
for (V3GraphEdge* nextp, *edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
if (followEdge(edgep)) {
|
||||
V3GraphVertex* outVertexp = edgep->top();
|
||||
V3GraphEdge* prevEdgep = static_cast<V3GraphEdge*>(outVertexp->userp());
|
||||
if (!prevEdgep) { // No previous assignment
|
||||
outVertexp->userp(edgep);
|
||||
} else { // Duplicate
|
||||
bool saveOld = true;
|
||||
if (prevEdgep->cutable() && !edgep->cutable()) {
|
||||
saveOld = false; // new !cutable more important than old
|
||||
} else if (!prevEdgep->cutable() && edgep->cutable()) {
|
||||
saveOld = true; // old !cutable more important than new
|
||||
} else {
|
||||
saveOld = true;
|
||||
if (!m_sumWeights && (prevEdgep->weight() < edgep->weight())) { // Keep max weight
|
||||
prevEdgep->weight(edgep->weight());
|
||||
}
|
||||
}
|
||||
if (saveOld) {
|
||||
if (m_sumWeights) prevEdgep->weight(prevEdgep->weight() + edgep->weight());
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
} else {
|
||||
if (m_sumWeights) edgep->weight(prevEdgep->weight() + edgep->weight());
|
||||
prevEdgep->unlinkDelete(); VL_DANGLING(prevEdgep);
|
||||
outVertexp->userp(edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!prevEdgep) { // No previous assignment
|
||||
outVertexp->userp(edgep);
|
||||
} else { // Duplicate
|
||||
bool saveOld = true;
|
||||
if (prevEdgep->cutable() && !edgep->cutable()) {
|
||||
saveOld = false; // new !cutable more important than old
|
||||
} else if (!prevEdgep->cutable() && edgep->cutable()) {
|
||||
saveOld = true; // old !cutable more important than new
|
||||
} else {
|
||||
saveOld = true;
|
||||
if (!m_sumWeights && (prevEdgep->weight() < edgep->weight())) { // Keep max weight
|
||||
prevEdgep->weight(edgep->weight());
|
||||
}
|
||||
}
|
||||
if (saveOld) {
|
||||
if (m_sumWeights) prevEdgep->weight(prevEdgep->weight() + edgep->weight());
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
} else {
|
||||
if (m_sumWeights) edgep->weight(prevEdgep->weight() + edgep->weight());
|
||||
prevEdgep->unlinkDelete(); VL_DANGLING(prevEdgep);
|
||||
outVertexp->userp(edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
GraphRemoveRedundant(V3Graph* graphp, V3EdgeFuncP edgeFuncp, bool sumWeights)
|
||||
: GraphAlg<>(graphp, edgeFuncp), m_sumWeights(sumWeights) {
|
||||
main();
|
||||
main();
|
||||
}
|
||||
~GraphRemoveRedundant() {}
|
||||
};
|
||||
|
|
@ -181,36 +182,37 @@ void V3Graph::removeTransitiveEdges() {
|
|||
class GraphAlgWeakly : GraphAlg<> {
|
||||
private:
|
||||
void main() {
|
||||
// Initialize state
|
||||
m_graphp->clearColors();
|
||||
// Color graph
|
||||
uint32_t currentColor = 0;
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
currentColor ++;
|
||||
vertexIterate(vertexp, currentColor);
|
||||
}
|
||||
// Initialize state
|
||||
m_graphp->clearColors();
|
||||
// Color graph
|
||||
uint32_t currentColor = 0;
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
currentColor ++;
|
||||
vertexIterate(vertexp, currentColor);
|
||||
}
|
||||
}
|
||||
|
||||
void vertexIterate(V3GraphVertex* vertexp, uint32_t currentColor) {
|
||||
// Assign new color to each unvisited node
|
||||
// then visit each of its edges, giving them the same color
|
||||
if (vertexp->color()) return; // Already colored it
|
||||
vertexp->color(currentColor);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->top(), currentColor);
|
||||
}
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->fromp(), currentColor);
|
||||
}
|
||||
}
|
||||
// Assign new color to each unvisited node
|
||||
// then visit each of its edges, giving them the same color
|
||||
if (vertexp->color()) return; // Already colored it
|
||||
vertexp->color(currentColor);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->top(), currentColor);
|
||||
}
|
||||
}
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->fromp(), currentColor);
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
GraphAlgWeakly(V3Graph* graphp, V3EdgeFuncP edgeFuncp)
|
||||
: GraphAlg<>(graphp, edgeFuncp) {
|
||||
main();
|
||||
main();
|
||||
}
|
||||
~GraphAlgWeakly() {}
|
||||
};
|
||||
|
|
@ -225,78 +227,81 @@ void V3Graph::weaklyConnected(V3EdgeFuncP edgeFuncp) {
|
|||
|
||||
class GraphAlgStrongly : GraphAlg<> {
|
||||
private:
|
||||
uint32_t m_currentDfs; // DFS count
|
||||
uint32_t m_currentDfs; // DFS count
|
||||
std::vector<V3GraphVertex*> m_callTrace; // List of everything we hit processing so far
|
||||
|
||||
void main() {
|
||||
// Use Tarjan's algorithm to find the strongly connected subgraphs.
|
||||
// Node State:
|
||||
// Vertex::user // DFS number indicating possible root of subtree, 0=not iterated
|
||||
// Vertex::color // Output subtree number (fully processed)
|
||||
// Use Tarjan's algorithm to find the strongly connected subgraphs.
|
||||
// Node State:
|
||||
// Vertex::user // DFS number indicating possible root of subtree, 0=not iterated
|
||||
// Vertex::color // Output subtree number (fully processed)
|
||||
|
||||
// Clear info
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->color(0);
|
||||
vertexp->user(0);
|
||||
}
|
||||
// Color graph
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (!vertexp->user()) {
|
||||
m_currentDfs++;
|
||||
vertexIterate(vertexp);
|
||||
}
|
||||
}
|
||||
// If there's a single vertex of a color, it doesn't need a subgraph
|
||||
// This simplifies the consumer's code, and reduces graph debugging clutter
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
bool onecolor = true;
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
if (vertexp->color() == edgep->top()->color()) {
|
||||
onecolor = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onecolor) vertexp->color(0);
|
||||
}
|
||||
// Clear info
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->color(0);
|
||||
vertexp->user(0);
|
||||
}
|
||||
// Color graph
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (!vertexp->user()) {
|
||||
m_currentDfs++;
|
||||
vertexIterate(vertexp);
|
||||
}
|
||||
}
|
||||
// If there's a single vertex of a color, it doesn't need a subgraph
|
||||
// This simplifies the consumer's code, and reduces graph debugging clutter
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
bool onecolor = true;
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
if (vertexp->color() == edgep->top()->color()) {
|
||||
onecolor = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (onecolor) vertexp->color(0);
|
||||
}
|
||||
}
|
||||
|
||||
void vertexIterate(V3GraphVertex* vertexp) {
|
||||
uint32_t thisDfsNum = m_currentDfs++;
|
||||
vertexp->user(thisDfsNum);
|
||||
vertexp->color(0);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
V3GraphVertex* top = edgep->top();
|
||||
if (!top->user()) { // Dest not computed yet
|
||||
vertexIterate(top);
|
||||
}
|
||||
if (!top->color()) { // Dest not in a component
|
||||
if (vertexp->user() > top->user()) vertexp->user(top->user());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vertexp->user() == thisDfsNum) { // New head of subtree
|
||||
vertexp->color(thisDfsNum); // Mark as component
|
||||
while (!m_callTrace.empty()) {
|
||||
V3GraphVertex* popVertexp = m_callTrace.back();
|
||||
if (popVertexp->user() >= thisDfsNum) { // Lower node is part of this subtree
|
||||
m_callTrace.pop_back();
|
||||
popVertexp->color(thisDfsNum);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else { // In another subtree (maybe...)
|
||||
m_callTrace.push_back(vertexp);
|
||||
}
|
||||
uint32_t thisDfsNum = m_currentDfs++;
|
||||
vertexp->user(thisDfsNum);
|
||||
vertexp->color(0);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
V3GraphVertex* top = edgep->top();
|
||||
if (!top->user()) { // Dest not computed yet
|
||||
vertexIterate(top);
|
||||
}
|
||||
if (!top->color()) { // Dest not in a component
|
||||
if (vertexp->user() > top->user()) vertexp->user(top->user());
|
||||
}
|
||||
}
|
||||
}
|
||||
if (vertexp->user() == thisDfsNum) { // New head of subtree
|
||||
vertexp->color(thisDfsNum); // Mark as component
|
||||
while (!m_callTrace.empty()) {
|
||||
V3GraphVertex* popVertexp = m_callTrace.back();
|
||||
if (popVertexp->user() >= thisDfsNum) { // Lower node is part of this subtree
|
||||
m_callTrace.pop_back();
|
||||
popVertexp->color(thisDfsNum);
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else { // In another subtree (maybe...)
|
||||
m_callTrace.push_back(vertexp);
|
||||
}
|
||||
}
|
||||
public:
|
||||
GraphAlgStrongly(V3Graph* graphp, V3EdgeFuncP edgeFuncp)
|
||||
: GraphAlg<>(graphp, edgeFuncp) {
|
||||
m_currentDfs = 0;
|
||||
main();
|
||||
m_currentDfs = 0;
|
||||
main();
|
||||
}
|
||||
~GraphAlgStrongly() {}
|
||||
};
|
||||
|
|
@ -312,43 +317,45 @@ void V3Graph::stronglyConnected(V3EdgeFuncP edgeFuncp) {
|
|||
class GraphAlgRank : GraphAlg<> {
|
||||
private:
|
||||
void main() {
|
||||
// Rank each vertex, ignoring cutable edges
|
||||
// Vertex::m_user begin: 1 indicates processing, 2 indicates completed
|
||||
// Clear existing ranks
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->rank(0);
|
||||
vertexp->user(0);
|
||||
}
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (!vertexp->user()) {
|
||||
vertexIterate(vertexp,1);
|
||||
}
|
||||
}
|
||||
// Rank each vertex, ignoring cutable edges
|
||||
// Vertex::m_user begin: 1 indicates processing, 2 indicates completed
|
||||
// Clear existing ranks
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertexp->rank(0);
|
||||
vertexp->user(0);
|
||||
}
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (!vertexp->user()) {
|
||||
vertexIterate(vertexp, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void vertexIterate(V3GraphVertex* vertexp, uint32_t currentRank) {
|
||||
// Assign rank to each unvisited node
|
||||
// If larger rank is found, assign it and loop back through
|
||||
// If we hit a back node make a list of all loops
|
||||
if (vertexp->user() == 1) {
|
||||
m_graphp->reportLoops(m_edgeFuncp, vertexp);
|
||||
m_graphp->loopsMessageCb(vertexp);
|
||||
return;
|
||||
}
|
||||
if (vertexp->rank() >= currentRank) return; // Already processed it
|
||||
vertexp->user(1);
|
||||
vertexp->rank(currentRank);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->top(), currentRank + vertexp->rankAdder());
|
||||
}
|
||||
}
|
||||
vertexp->user(2);
|
||||
// Assign rank to each unvisited node
|
||||
// If larger rank is found, assign it and loop back through
|
||||
// If we hit a back node make a list of all loops
|
||||
if (vertexp->user() == 1) {
|
||||
m_graphp->reportLoops(m_edgeFuncp, vertexp);
|
||||
m_graphp->loopsMessageCb(vertexp);
|
||||
return;
|
||||
}
|
||||
if (vertexp->rank() >= currentRank) return; // Already processed it
|
||||
vertexp->user(1);
|
||||
vertexp->rank(currentRank);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->top(), currentRank + vertexp->rankAdder());
|
||||
}
|
||||
}
|
||||
vertexp->user(2);
|
||||
}
|
||||
public:
|
||||
GraphAlgRank(V3Graph* graphp, V3EdgeFuncP edgeFuncp)
|
||||
: GraphAlg<>(graphp, edgeFuncp) {
|
||||
main();
|
||||
main();
|
||||
}
|
||||
~GraphAlgRank() {}
|
||||
};
|
||||
|
|
@ -368,46 +375,46 @@ void V3Graph::rank(V3EdgeFuncP edgeFuncp) {
|
|||
class GraphAlgRLoops : GraphAlg<> {
|
||||
private:
|
||||
std::vector<V3GraphVertex*> m_callTrace; // List of everything we hit processing so far
|
||||
bool m_done; // Exit algorithm
|
||||
bool m_done; // Exit algorithm
|
||||
|
||||
void main(V3GraphVertex* vertexp) {
|
||||
// Vertex::m_user begin: 1 indicates processing, 2 indicates completed
|
||||
// Clear existing ranks
|
||||
m_graphp->userClearVertices();
|
||||
m_callTrace.reserve(100);
|
||||
vertexIterate(vertexp, 0);
|
||||
// Vertex::m_user begin: 1 indicates processing, 2 indicates completed
|
||||
// Clear existing ranks
|
||||
m_graphp->userClearVertices();
|
||||
m_callTrace.reserve(100);
|
||||
vertexIterate(vertexp, 0);
|
||||
}
|
||||
|
||||
void vertexIterate(V3GraphVertex* vertexp, uint32_t currentRank) {
|
||||
// Assign rank to each unvisited node
|
||||
// When we hit ourself again, return the list of all loops
|
||||
if (m_done) return;
|
||||
// Assign rank to each unvisited node
|
||||
// When we hit ourself again, return the list of all loops
|
||||
if (m_done) return;
|
||||
|
||||
// Can't just reserve(), unless we modify size() before setting array directly
|
||||
while (m_callTrace.size() <= currentRank) m_callTrace.push_back(vertexp);
|
||||
m_callTrace[currentRank++] = vertexp;
|
||||
// Can't just reserve(), unless we modify size() before setting array directly
|
||||
while (m_callTrace.size() <= currentRank) m_callTrace.push_back(vertexp);
|
||||
m_callTrace[currentRank++] = vertexp;
|
||||
|
||||
if (vertexp->user() == 1) {
|
||||
for (unsigned i=0; i<currentRank; i++) {
|
||||
m_graphp->loopsVertexCb(m_callTrace[i]);
|
||||
}
|
||||
m_done = true;
|
||||
return;
|
||||
}
|
||||
if (vertexp->user() == 2) return; // Already processed it
|
||||
vertexp->user(1);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->top(),currentRank);
|
||||
}
|
||||
}
|
||||
vertexp->user(2);
|
||||
if (vertexp->user() == 1) {
|
||||
for (unsigned i=0; i<currentRank; i++) {
|
||||
m_graphp->loopsVertexCb(m_callTrace[i]);
|
||||
}
|
||||
m_done = true;
|
||||
return;
|
||||
}
|
||||
if (vertexp->user() == 2) return; // Already processed it
|
||||
vertexp->user(1);
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
vertexIterate(edgep->top(), currentRank);
|
||||
}
|
||||
}
|
||||
vertexp->user(2);
|
||||
}
|
||||
public:
|
||||
GraphAlgRLoops(V3Graph* graphp, V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp)
|
||||
: GraphAlg<>(graphp, edgeFuncp) {
|
||||
m_done = false;
|
||||
main(vertexp);
|
||||
m_done = false;
|
||||
main(vertexp);
|
||||
}
|
||||
~GraphAlgRLoops() {}
|
||||
};
|
||||
|
|
@ -428,43 +435,43 @@ private:
|
|||
//! Iterate through all connected nodes of a graph with a loop or loops.
|
||||
V3GraphVertex* vertexIterateAll(V3GraphVertex* vertexp) {
|
||||
if (V3GraphVertex* newVertexp = static_cast<V3GraphVertex*>(vertexp->userp())) {
|
||||
return newVertexp;
|
||||
} else {
|
||||
newVertexp = vertexp->clone(m_loopGraphp);
|
||||
vertexp->userp(newVertexp);
|
||||
return newVertexp;
|
||||
} else {
|
||||
newVertexp = vertexp->clone(m_loopGraphp);
|
||||
vertexp->userp(newVertexp);
|
||||
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp();
|
||||
edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp();
|
||||
edgep; edgep=edgep->outNextp()) {
|
||||
if (followEdge(edgep)) {
|
||||
V3GraphEdge* newEdgep = static_cast<V3GraphEdge*>(edgep->userp());
|
||||
if (!newEdgep) {
|
||||
V3GraphVertex* newTop = vertexIterateAll(edgep->top());
|
||||
newEdgep = edgep->clone(m_loopGraphp, newVertexp,
|
||||
newTop);
|
||||
edgep->userp(newEdgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
return newVertexp;
|
||||
}
|
||||
if (!newEdgep) {
|
||||
V3GraphVertex* newTop = vertexIterateAll(edgep->top());
|
||||
newEdgep = edgep->clone(m_loopGraphp, newVertexp,
|
||||
newTop);
|
||||
edgep->userp(newEdgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
return newVertexp;
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
GraphAlgSubtrees(V3Graph* graphp, V3Graph* loopGraphp,
|
||||
V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp)
|
||||
V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp)
|
||||
: GraphAlg<>(graphp, edgeFuncp), m_loopGraphp(loopGraphp) {
|
||||
// Vertex::m_userp - New vertex if we have seen this vertex already
|
||||
// Edge::m_userp - New edge if we have seen this edge already
|
||||
m_graphp->userClearVertices();
|
||||
m_graphp->userClearEdges();
|
||||
(void) vertexIterateAll(vertexp);
|
||||
// Vertex::m_userp - New vertex if we have seen this vertex already
|
||||
// Edge::m_userp - New edge if we have seen this edge already
|
||||
m_graphp->userClearVertices();
|
||||
m_graphp->userClearEdges();
|
||||
(void) vertexIterateAll(vertexp);
|
||||
}
|
||||
~GraphAlgSubtrees() {}
|
||||
};
|
||||
|
||||
//! Report the entire connected graph with a loop or loops
|
||||
void V3Graph::subtreeLoops(V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp,
|
||||
V3Graph* loopGraphp) {
|
||||
V3Graph* loopGraphp) {
|
||||
GraphAlgSubtrees(this, loopGraphp, edgeFuncp, vertexp);
|
||||
}
|
||||
|
||||
|
|
@ -474,12 +481,12 @@ void V3Graph::subtreeLoops(V3EdgeFuncP edgeFuncp, V3GraphVertex* vertexp,
|
|||
|
||||
void V3Graph::makeEdgesNonCutable(V3EdgeFuncP edgeFuncp) {
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
// Only need one direction, we'll always see the other at some point...
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) {
|
||||
if (edgep->cutable() && edgep->weight() && (edgeFuncp)(edgep)) {
|
||||
edgep->cutable(false);
|
||||
}
|
||||
}
|
||||
// Only need one direction, we'll always see the other at some point...
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) {
|
||||
if (edgep->cutable() && edgep->weight() && (edgeFuncp)(edgep)) {
|
||||
edgep->cutable(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -489,12 +496,12 @@ void V3Graph::makeEdgesNonCutable(V3EdgeFuncP edgeFuncp) {
|
|||
|
||||
struct GraphSortVertexCmp {
|
||||
inline bool operator() (const V3GraphVertex* lhsp, const V3GraphVertex* rhsp) const {
|
||||
return lhsp->sortCmp(rhsp) < 0;
|
||||
return lhsp->sortCmp(rhsp) < 0;
|
||||
}
|
||||
};
|
||||
struct GraphSortEdgeCmp {
|
||||
inline bool operator() (const V3GraphEdge* lhsp, const V3GraphEdge* rhsp) const {
|
||||
return lhsp->sortCmp(rhsp) < 0;
|
||||
return lhsp->sortCmp(rhsp) < 0;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -502,12 +509,12 @@ void V3Graph::sortVertices() {
|
|||
// Sort list of vertices by rank, then fanout
|
||||
std::vector<V3GraphVertex*> vertices;
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
vertices.push_back(vertexp);
|
||||
vertices.push_back(vertexp);
|
||||
}
|
||||
std::stable_sort(vertices.begin(), vertices.end(), GraphSortVertexCmp());
|
||||
this->verticesUnlink();
|
||||
for (std::vector<V3GraphVertex*>::iterator it = vertices.begin(); it!=vertices.end(); ++it) {
|
||||
(*it)->verticesPushBack(this);
|
||||
(*it)->verticesPushBack(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -515,32 +522,32 @@ void V3Graph::sortEdges() {
|
|||
// Sort edges by rank then fanout of node they point to
|
||||
std::vector<V3GraphEdge*> edges;
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
// Make a vector
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
edges.push_back(edgep);
|
||||
}
|
||||
// Sort
|
||||
std::stable_sort(edges.begin(), edges.end(), GraphSortEdgeCmp());
|
||||
// Make a vector
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
edges.push_back(edgep);
|
||||
}
|
||||
// Sort
|
||||
std::stable_sort(edges.begin(), edges.end(), GraphSortEdgeCmp());
|
||||
|
||||
// Relink edges in specified order
|
||||
// We know the vector contains all of the edges that were
|
||||
// there originally (didn't delete or add)
|
||||
vertexp->outUnlink();
|
||||
// Relink edges in specified order
|
||||
// We know the vector contains all of the edges that were
|
||||
// there originally (didn't delete or add)
|
||||
vertexp->outUnlink();
|
||||
for (std::vector<V3GraphEdge*>::const_iterator it = edges.begin(); it!=edges.end(); ++it) {
|
||||
(*it)->outPushBack();
|
||||
}
|
||||
// Prep for next
|
||||
edges.clear();
|
||||
(*it)->outPushBack();
|
||||
}
|
||||
// Prep for next
|
||||
edges.clear();
|
||||
}
|
||||
}
|
||||
|
||||
//######################################################################
|
||||
//######################################################################
|
||||
// Algorithms - ordering
|
||||
// Compute near optimal ordering of the nodes, where:
|
||||
// If a required edge is A->B, rank(A)<rank(B)
|
||||
// Visit edges and assign ranks to keep minimal crossings
|
||||
// (Results in better dcache packing.)
|
||||
// Compute near optimal ordering of the nodes, where:
|
||||
// If a required edge is A->B, rank(A)<rank(B)
|
||||
// Visit edges and assign ranks to keep minimal crossings
|
||||
// (Results in better dcache packing.)
|
||||
|
||||
void V3Graph::order() {
|
||||
UINFO(2,"Order:\n");
|
||||
|
|
@ -555,9 +562,9 @@ void V3Graph::orderPreRanked() {
|
|||
// Vertex::m_user begin: 1 indicates processing, 2 indicates completed
|
||||
userClearVertices();
|
||||
for (V3GraphVertex* vertexp = verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (!vertexp->user()) {
|
||||
orderDFSIterate(vertexp);
|
||||
}
|
||||
if (!vertexp->user()) {
|
||||
orderDFSIterate(vertexp);
|
||||
}
|
||||
}
|
||||
|
||||
// Sort list of vertices by rank, then fanout. Fanout is a bit of a
|
||||
|
|
@ -576,11 +583,11 @@ double V3Graph::orderDFSIterate(V3GraphVertex* vertexp) {
|
|||
vertexp->user(1);
|
||||
double fanout = 0;
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep = edgep->outNextp()) {
|
||||
if (edgep->weight()) fanout += orderDFSIterate(edgep->m_top);
|
||||
if (edgep->weight()) fanout += orderDFSIterate(edgep->m_top);
|
||||
}
|
||||
// Just count inbound edges
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep = edgep->inNextp()) {
|
||||
if (edgep->weight()) fanout ++;
|
||||
if (edgep->weight()) fanout ++;
|
||||
}
|
||||
vertexp->fanout(fanout);
|
||||
vertexp->user(2);
|
||||
|
|
|
|||
|
|
@ -48,4 +48,4 @@ protected:
|
|||
|
||||
//============================================================================
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -36,15 +36,16 @@
|
|||
|
||||
DfaVertex* DfaGraph::findStart() {
|
||||
DfaVertex* startp = NULL;
|
||||
for (V3GraphVertex* vertexp = this->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
if (vvertexp->start()) {
|
||||
for (V3GraphVertex* vertexp = this->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
if (vvertexp->start()) {
|
||||
if (startp) vertexp->v3fatalSrc("Multiple start points in NFA graph");
|
||||
startp = vvertexp;
|
||||
}
|
||||
} else {
|
||||
startp = vvertexp;
|
||||
}
|
||||
} else {
|
||||
vertexp->v3fatalSrc("Non DfaVertex in DfaGraph");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!startp) v3fatalSrc("No start point in NFA graph");
|
||||
return startp;
|
||||
|
|
@ -66,8 +67,8 @@ private:
|
|||
typedef std::multimap<vluint64_t,DfaVertex*> HashMap;
|
||||
|
||||
// MEMBERS
|
||||
uint32_t m_step; // Processing step, so we can avoid clearUser all the time
|
||||
HashMap m_hashMap; // Dfa Vertex for each set of NFA vertexes
|
||||
uint32_t m_step; // Processing step, so we can avoid clearUser all the time
|
||||
HashMap m_hashMap; // Dfa Vertex for each set of NFA vertexes
|
||||
|
||||
#ifdef VL_CPPCHECK
|
||||
static int debug() { return 9; }
|
||||
|
|
@ -83,271 +84,286 @@ private:
|
|||
void nextStep() { m_step++; }
|
||||
|
||||
bool unseenNfaThisStep(V3GraphVertex* vertexp) {
|
||||
// A nfa node not already seen this processing step
|
||||
return (nfaState(vertexp) && !(vertexp->user()==m_step));
|
||||
// A nfa node not already seen this processing step
|
||||
return (nfaState(vertexp) && !(vertexp->user()==m_step));
|
||||
}
|
||||
|
||||
DfaVertex* newDfaVertex(DfaVertex* nfaTemplatep=NULL) {
|
||||
DfaVertex* vertexp = new DfaVertex(graphp());
|
||||
vertexp->color(1); // Mark as dfa
|
||||
if (nfaTemplatep && nfaTemplatep->start()) vertexp->start(true);
|
||||
if (nfaTemplatep && nfaTemplatep->accepting()) vertexp->accepting(true);
|
||||
UINFO(9, " New "<<vertexp<<endl);
|
||||
return vertexp;
|
||||
vertexp->color(1); // Mark as dfa
|
||||
if (nfaTemplatep && nfaTemplatep->start()) vertexp->start(true);
|
||||
if (nfaTemplatep && nfaTemplatep->accepting()) vertexp->accepting(true);
|
||||
UINFO(9, " New "<<vertexp<<endl);
|
||||
return vertexp;
|
||||
}
|
||||
|
||||
// Hashing
|
||||
static uint32_t hashVertex(V3GraphVertex* vertexp) {
|
||||
union { void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
|
||||
u.l.upper=0; u.l.lower=0; u.up=vertexp;
|
||||
return u.l.upper ^ u.l.lower;
|
||||
union { void* up; struct {uint32_t upper; uint32_t lower;} l;} u;
|
||||
u.l.upper = 0; u.l.lower = 0; u.up = vertexp;
|
||||
return u.l.upper ^ u.l.lower;
|
||||
}
|
||||
|
||||
uint32_t hashDfaOrigins(DfaVertex* dfaStatep) {
|
||||
// Find the NFA states this dfa came from,
|
||||
// Record a checksum, so we can search for it later by the list of nfa nodes.
|
||||
// The order of the nodes is not deterministic; the hash thus must not depend on order of edges
|
||||
uint32_t hash = 0;
|
||||
// Foreach NFA state (this DFA state was formed from)
|
||||
if (debug()) nextStep();
|
||||
for (V3GraphEdge* dfaEdgep = dfaStatep->outBeginp(); dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
DfaVertex* nfaStatep = static_cast<DfaVertex*>(dfaEdgep->top());
|
||||
hash ^= hashVertex(nfaStatep);
|
||||
if (debug()) {
|
||||
// Find the NFA states this dfa came from,
|
||||
// Record a checksum, so we can search for it later by the list of nfa nodes.
|
||||
// The order of the nodes is not deterministic; the hash thus must
|
||||
// not depend on order of edges
|
||||
uint32_t hash = 0;
|
||||
// Foreach NFA state (this DFA state was formed from)
|
||||
if (debug()) nextStep();
|
||||
for (V3GraphEdge* dfaEdgep = dfaStatep->outBeginp();
|
||||
dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
DfaVertex* nfaStatep = static_cast<DfaVertex*>(dfaEdgep->top());
|
||||
hash ^= hashVertex(nfaStatep);
|
||||
if (debug()) {
|
||||
if (nfaStatep->user()==m_step) {
|
||||
nfaStatep->v3fatalSrc("DFA state points to duplicate NFA state.");
|
||||
}
|
||||
nfaStatep->user(m_step);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
nfaStatep->user(m_step);
|
||||
}
|
||||
}
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
uint32_t hashDfaOrigins(const DfaStates& nfasWithInput) {
|
||||
// Find the NFA states this dfa came from,
|
||||
uint32_t hash = 0;
|
||||
for (DfaStates::const_iterator nfaIt=nfasWithInput.begin(); nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
DfaVertex* nfaStatep = *nfaIt;
|
||||
hash ^= hashVertex(nfaStatep);
|
||||
}
|
||||
return hash;
|
||||
// Find the NFA states this dfa came from,
|
||||
uint32_t hash = 0;
|
||||
for (DfaStates::const_iterator nfaIt=nfasWithInput.begin();
|
||||
nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
DfaVertex* nfaStatep = *nfaIt;
|
||||
hash ^= hashVertex(nfaStatep);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
|
||||
bool compareDfaOrigins(const DfaStates& nfasWithInput, DfaVertex* dfa2p) {
|
||||
// Return true if the NFA nodes both DFAs came from are the same list
|
||||
// Assume there are no duplicates in either input list or NFAs under dfa2
|
||||
nextStep();
|
||||
// Mark all input vertexes
|
||||
int num1s = 0;
|
||||
for (DfaStates::const_iterator nfaIt=nfasWithInput.begin(); nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
DfaVertex* nfaStatep = *nfaIt;
|
||||
nfaStatep->user(m_step);
|
||||
num1s++;
|
||||
}
|
||||
if (!num1s) v3fatalSrc("DFA node construction that contains no NFA states");
|
||||
// Return true if the NFA nodes both DFAs came from are the same list
|
||||
// Assume there are no duplicates in either input list or NFAs under dfa2
|
||||
nextStep();
|
||||
// Mark all input vertexes
|
||||
int num1s = 0;
|
||||
for (DfaStates::const_iterator nfaIt=nfasWithInput.begin();
|
||||
nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
DfaVertex* nfaStatep = *nfaIt;
|
||||
nfaStatep->user(m_step);
|
||||
num1s++;
|
||||
}
|
||||
if (!num1s) v3fatalSrc("DFA node construction that contains no NFA states");
|
||||
|
||||
// Check comparison; must all be marked
|
||||
// (Check all in dfa2p were in dfa1p)
|
||||
int num2s = 0;
|
||||
for (V3GraphEdge* dfaEdgep = dfa2p->outBeginp(); dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
if (dfaEdgep->top()->user() != m_step) return false;
|
||||
num2s++;
|
||||
}
|
||||
}
|
||||
// If we saw all of the nodes, then they have the same number of hits
|
||||
// (Else something in dfa1p that wasn't in dfa2p)
|
||||
// Check comparison; must all be marked
|
||||
// (Check all in dfa2p were in dfa1p)
|
||||
int num2s = 0;
|
||||
for (V3GraphEdge* dfaEdgep = dfa2p->outBeginp(); dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
if (dfaEdgep->top()->user() != m_step) return false;
|
||||
num2s++;
|
||||
}
|
||||
}
|
||||
// If we saw all of the nodes, then they have the same number of hits
|
||||
// (Else something in dfa1p that wasn't in dfa2p)
|
||||
return (num1s == num2s);
|
||||
}
|
||||
|
||||
void insertDfaOrigins(DfaVertex* dfaStatep) {
|
||||
// Record the NFA states this dfa came from
|
||||
uint32_t hash = hashDfaOrigins(dfaStatep);
|
||||
m_hashMap.insert(make_pair(hash,dfaStatep));
|
||||
// Record the NFA states this dfa came from
|
||||
uint32_t hash = hashDfaOrigins(dfaStatep);
|
||||
m_hashMap.insert(make_pair(hash, dfaStatep));
|
||||
}
|
||||
|
||||
DfaVertex* findDfaOrigins(const DfaStates& nfasWithInput) {
|
||||
// Find another DFA state which comes from the identical set of NFA states
|
||||
// The order of the nodes is not deterministic; the hash thus must not depend on order of edges
|
||||
uint32_t hash = hashDfaOrigins(nfasWithInput);
|
||||
// Find another DFA state which comes from the identical set of NFA states
|
||||
// The order of the nodes is not deterministic; the hash thus must
|
||||
// not depend on order of edges
|
||||
uint32_t hash = hashDfaOrigins(nfasWithInput);
|
||||
|
||||
std::pair<HashMap::iterator,HashMap::iterator> eqrange = m_hashMap.equal_range(hash);
|
||||
for (HashMap::iterator it = eqrange.first; it != eqrange.second; ++it) {
|
||||
DfaVertex* testp = it->second;
|
||||
if (compareDfaOrigins(nfasWithInput, testp)) {
|
||||
UINFO(9," DFA match for set: "<<testp<<endl);
|
||||
return testp; // Identical
|
||||
}
|
||||
}
|
||||
return NULL; // No match
|
||||
for (HashMap::iterator it = eqrange.first; it != eqrange.second; ++it) {
|
||||
DfaVertex* testp = it->second;
|
||||
if (compareDfaOrigins(nfasWithInput, testp)) {
|
||||
UINFO(9," DFA match for set: "<<testp<<endl);
|
||||
return testp; // Identical
|
||||
}
|
||||
}
|
||||
return NULL; // No match
|
||||
}
|
||||
|
||||
void findNfasWithInput(DfaVertex* dfaStatep, DfaInput input,
|
||||
DfaStates& nfasWithInput) {
|
||||
// Return all NFA states, with the given input transition from
|
||||
// the nfa states a given dfa state was constructed from.
|
||||
nextStep();
|
||||
nfasWithInput.clear(); // NFAs with given input
|
||||
DfaStates& nfasWithInput) {
|
||||
// Return all NFA states, with the given input transition from
|
||||
// the nfa states a given dfa state was constructed from.
|
||||
nextStep();
|
||||
nfasWithInput.clear(); // NFAs with given input
|
||||
|
||||
// Foreach NFA state (this DFA state was formed from)
|
||||
for (V3GraphEdge* dfaEdgep = dfaStatep->outBeginp(); dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
DfaVertex* nfaStatep = static_cast<DfaVertex*>(dfaEdgep->top());
|
||||
// Foreach input transition (on this nfaStatep)
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp(); nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
if (cNfaEdgep->input().toNodep() == input.toNodep()) {
|
||||
DfaVertex* nextStatep = static_cast<DfaVertex*>(cNfaEdgep->top());
|
||||
if (unseenNfaThisStep(nextStatep)) { // Not processed?
|
||||
nfasWithInput.push_back(nextStatep);
|
||||
nextStatep->user(m_step);
|
||||
UINFO(9," Reachable "<<nextStatep<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Foreach NFA state (this DFA state was formed from)
|
||||
for (V3GraphEdge* dfaEdgep = dfaStatep->outBeginp();
|
||||
dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
DfaVertex* nfaStatep = static_cast<DfaVertex*>(dfaEdgep->top());
|
||||
// Foreach input transition (on this nfaStatep)
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp();
|
||||
nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
if (cNfaEdgep->input().toNodep() == input.toNodep()) {
|
||||
DfaVertex* nextStatep = static_cast<DfaVertex*>(cNfaEdgep->top());
|
||||
if (unseenNfaThisStep(nextStatep)) { // Not processed?
|
||||
nfasWithInput.push_back(nextStatep);
|
||||
nextStatep->user(m_step);
|
||||
UINFO(9," Reachable "<<nextStatep<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Expand the nfasWithInput list to include epsilon states reachable by those on nfasWithInput
|
||||
for (DfaStates::iterator nfaIt=nfasWithInput.begin(); nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
DfaVertex* nfaStatep = *nfaIt;
|
||||
// Foreach epsilon-reachable (on this nfaStatep)
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp(); nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
if (cNfaEdgep->epsilon()) {
|
||||
DfaVertex* nextStatep = static_cast<DfaVertex*>(cNfaEdgep->top());
|
||||
if (unseenNfaThisStep(nextStatep)) { // Not processed?
|
||||
nfasWithInput.push_back(nextStatep);
|
||||
nextStatep->user(m_step);
|
||||
UINFO(9," Epsilon Reachable "<<nextStatep<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Expand the nfasWithInput list to include epsilon states
|
||||
// reachable by those on nfasWithInput
|
||||
for (DfaStates::iterator nfaIt=nfasWithInput.begin();
|
||||
nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
DfaVertex* nfaStatep = *nfaIt;
|
||||
// Foreach epsilon-reachable (on this nfaStatep)
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp();
|
||||
nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
if (cNfaEdgep->epsilon()) {
|
||||
DfaVertex* nextStatep = static_cast<DfaVertex*>(cNfaEdgep->top());
|
||||
if (unseenNfaThisStep(nextStatep)) { // Not processed?
|
||||
nfasWithInput.push_back(nextStatep);
|
||||
nextStatep->user(m_step);
|
||||
UINFO(9," Epsilon Reachable "<<nextStatep<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void main() {
|
||||
UINFO(5,"Dfa to Nfa conversion...\n");
|
||||
// Vertex::color() begin: 1 indicates vertex on DFA graph, 0=NFA graph
|
||||
m_graphp->clearColors();
|
||||
// Vertex::m_user begin: # indicates processed this m_step number
|
||||
m_graphp->userClearVertices();
|
||||
UINFO(5,"Dfa to Nfa conversion...\n");
|
||||
// Vertex::color() begin: 1 indicates vertex on DFA graph, 0=NFA graph
|
||||
m_graphp->clearColors();
|
||||
// Vertex::m_user begin: # indicates processed this m_step number
|
||||
m_graphp->userClearVertices();
|
||||
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_nfa");
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_nfa");
|
||||
|
||||
// Find NFA start
|
||||
DfaVertex* nfaStartp = graphp()->findStart();
|
||||
// Find NFA start
|
||||
DfaVertex* nfaStartp = graphp()->findStart();
|
||||
|
||||
// Create new DFA State (start state) from the NFA states
|
||||
DfaVertex* dfaStartp = newDfaVertex(nfaStartp);
|
||||
// Create new DFA State (start state) from the NFA states
|
||||
DfaVertex* dfaStartp = newDfaVertex(nfaStartp);
|
||||
|
||||
DfaStates dfaUnprocps; // Unprocessed DFA nodes
|
||||
dfaUnprocps.push_back(dfaStartp);
|
||||
DfaStates dfaUnprocps; // Unprocessed DFA nodes
|
||||
dfaUnprocps.push_back(dfaStartp);
|
||||
|
||||
UINFO(5,"Starting state conversion...\n");
|
||||
// Form DFA starting state from epsilon closure of NFA start
|
||||
nextStep();
|
||||
DfaStates workps; workps.push_back(nfaStartp);
|
||||
UINFO(5,"Starting state conversion...\n");
|
||||
// Form DFA starting state from epsilon closure of NFA start
|
||||
nextStep();
|
||||
DfaStates workps; workps.push_back(nfaStartp);
|
||||
|
||||
while (!workps.empty()) { // While work
|
||||
DfaVertex* nfaStatep = workps.back(); workps.pop_back();
|
||||
//UINFO(9," Processing "<<nfaStatep<<endl);
|
||||
nfaStatep->user(m_step); // Mark as processed
|
||||
// Add a edge so we can find NFAs from a given DFA.
|
||||
// The NFA will never see this edge, because we only look at TO edges.
|
||||
new DfaEdge(graphp(), dfaStartp, nfaStatep, DfaEdge::NA());
|
||||
// Find epsilon closure of this nfa node, and destinations to work list
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp(); nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
DfaVertex* ecNfaStatep = static_cast<DfaVertex*>(nfaEdgep->top());
|
||||
//UINFO(9," Consider "<<nfaEdgep->top()<<" EP "<<cNfaEdgep->epsilon()<<endl);
|
||||
if (cNfaEdgep->epsilon()
|
||||
&& unseenNfaThisStep(ecNfaStatep)) { // Not processed?
|
||||
workps.push_back(ecNfaStatep);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_start");
|
||||
insertDfaOrigins(dfaStartp);
|
||||
while (!workps.empty()) { // While work
|
||||
DfaVertex* nfaStatep = workps.back(); workps.pop_back();
|
||||
//UINFO(9," Processing "<<nfaStatep<<endl);
|
||||
nfaStatep->user(m_step); // Mark as processed
|
||||
// Add a edge so we can find NFAs from a given DFA.
|
||||
// The NFA will never see this edge, because we only look at TO edges.
|
||||
new DfaEdge(graphp(), dfaStartp, nfaStatep, DfaEdge::NA());
|
||||
// Find epsilon closure of this nfa node, and destinations to work list
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp();
|
||||
nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
DfaVertex* ecNfaStatep = static_cast<DfaVertex*>(nfaEdgep->top());
|
||||
//UINFO(9," Consider "<<nfaEdgep->top()<<" EP "<<cNfaEdgep->epsilon()<<endl);
|
||||
if (cNfaEdgep->epsilon()
|
||||
&& unseenNfaThisStep(ecNfaStatep)) { // Not processed?
|
||||
workps.push_back(ecNfaStatep);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_start");
|
||||
insertDfaOrigins(dfaStartp);
|
||||
|
||||
int i=0;
|
||||
UINFO(5,"Main state conversion...\n");
|
||||
while (!dfaUnprocps.empty()) {
|
||||
DfaVertex* dfaStatep = dfaUnprocps.back(); dfaUnprocps.pop_back();
|
||||
UINFO(9," On dfaState "<<dfaStatep<<endl);
|
||||
int i = 0;
|
||||
UINFO(5,"Main state conversion...\n");
|
||||
while (!dfaUnprocps.empty()) {
|
||||
DfaVertex* dfaStatep = dfaUnprocps.back(); dfaUnprocps.pop_back();
|
||||
UINFO(9," On dfaState "<<dfaStatep<<endl);
|
||||
|
||||
// From this dfaState, what corresponding nfaStates have what inputs?
|
||||
// From this dfaState, what corresponding nfaStates have what inputs?
|
||||
std::set<int> inputs;
|
||||
// Foreach NFA state (this DFA state was formed from)
|
||||
for (V3GraphEdge* dfaEdgep = dfaStatep->outBeginp(); dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
DfaVertex* nfaStatep = static_cast<DfaVertex*>(dfaEdgep->top());
|
||||
// Foreach input on this nfaStatep
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp(); nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
if (!cNfaEdgep->epsilon()) {
|
||||
if (inputs.find(cNfaEdgep->input().toInt()) == inputs.end()) {
|
||||
inputs.insert(cNfaEdgep->input().toInt());
|
||||
UINFO(9," Input to "<<dfaStatep<<" is "<<(cNfaEdgep->input().toInt())<<" via "<<nfaStatep<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Foreach NFA state (this DFA state was formed from)
|
||||
for (V3GraphEdge* dfaEdgep = dfaStatep->outBeginp();
|
||||
dfaEdgep; dfaEdgep=dfaEdgep->outNextp()) {
|
||||
if (nfaState(dfaEdgep->top())) {
|
||||
DfaVertex* nfaStatep = static_cast<DfaVertex*>(dfaEdgep->top());
|
||||
// Foreach input on this nfaStatep
|
||||
for (V3GraphEdge* nfaEdgep = nfaStatep->outBeginp();
|
||||
nfaEdgep; nfaEdgep=nfaEdgep->outNextp()) {
|
||||
DfaEdge* cNfaEdgep = static_cast<DfaEdge*>(nfaEdgep);
|
||||
if (!cNfaEdgep->epsilon()) {
|
||||
if (inputs.find(cNfaEdgep->input().toInt()) == inputs.end()) {
|
||||
inputs.insert(cNfaEdgep->input().toInt());
|
||||
UINFO(9," Input to "<<dfaStatep<<" is "
|
||||
<<(cNfaEdgep->input().toInt())<<" via "<<nfaStatep<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Foreach input state (NFA inputs of this DFA state)
|
||||
// Foreach input state (NFA inputs of this DFA state)
|
||||
for (std::set<int>::const_iterator inIt=inputs.begin(); inIt!=inputs.end(); ++inIt) {
|
||||
DfaInput input = *inIt;
|
||||
UINFO(9," ==="<<++i<<"=======================\n");
|
||||
DfaInput input = *inIt;
|
||||
UINFO(9," ==="<<++i<<"=======================\n");
|
||||
UINFO(9," On input "<<cvtToHex(input.toNodep())<<endl);
|
||||
|
||||
// Find all states reachable for given input
|
||||
DfaStates nfasWithInput;
|
||||
findNfasWithInput(dfaStatep, input, nfasWithInput/*ref*/);
|
||||
// Find all states reachable for given input
|
||||
DfaStates nfasWithInput;
|
||||
findNfasWithInput(dfaStatep, input, nfasWithInput/*ref*/);
|
||||
|
||||
// nfasWithInput now maps to the DFA we want a transition to.
|
||||
// Does a DFA already exist with this, and only this subset of NFA's?
|
||||
DfaVertex* toDfaStatep = findDfaOrigins(nfasWithInput);
|
||||
if (!toDfaStatep) {
|
||||
// Doesn't exist, make new dfa state corresponding to this one,
|
||||
toDfaStatep = newDfaVertex();
|
||||
dfaUnprocps.push_back(toDfaStatep); // Add to process list
|
||||
// Track what nfa's point to it.
|
||||
for (DfaStates::const_iterator nfaIt=nfasWithInput.begin(); nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
UINFO(9," NewContainsNfa "<<*nfaIt<<endl);
|
||||
// nfasWithInput now maps to the DFA we want a transition to.
|
||||
// Does a DFA already exist with this, and only this subset of NFA's?
|
||||
DfaVertex* toDfaStatep = findDfaOrigins(nfasWithInput);
|
||||
if (!toDfaStatep) {
|
||||
// Doesn't exist, make new dfa state corresponding to this one,
|
||||
toDfaStatep = newDfaVertex();
|
||||
dfaUnprocps.push_back(toDfaStatep); // Add to process list
|
||||
// Track what nfa's point to it.
|
||||
for (DfaStates::const_iterator nfaIt=nfasWithInput.begin();
|
||||
nfaIt!=nfasWithInput.end(); ++nfaIt) {
|
||||
UINFO(9," NewContainsNfa "<<*nfaIt<<endl);
|
||||
new DfaEdge(graphp(), toDfaStatep, *nfaIt, DfaEdge::NA());
|
||||
if ((*nfaIt)->accepting()) toDfaStatep->accepting(true);
|
||||
}
|
||||
insertDfaOrigins(toDfaStatep);
|
||||
}
|
||||
// Add input transition
|
||||
if ((*nfaIt)->accepting()) toDfaStatep->accepting(true);
|
||||
}
|
||||
insertDfaOrigins(toDfaStatep);
|
||||
}
|
||||
// Add input transition
|
||||
new DfaEdge(graphp(), dfaStatep, toDfaStatep, input);
|
||||
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("step");
|
||||
}
|
||||
}
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("step");
|
||||
}
|
||||
}
|
||||
|
||||
// Remove old NFA states
|
||||
UINFO(5,"Removing NFA states...\n");
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_withnfa");
|
||||
for (V3GraphVertex* nextp,*vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=nextp) {
|
||||
nextp = vertexp->verticesNextp();
|
||||
if (nfaState(vertexp)) {
|
||||
vertexp->unlinkDelete(m_graphp); VL_DANGLING(vertexp);
|
||||
}
|
||||
}
|
||||
// Remove old NFA states
|
||||
UINFO(5,"Removing NFA states...\n");
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_withnfa");
|
||||
for (V3GraphVertex* nextp,*vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=nextp) {
|
||||
nextp = vertexp->verticesNextp();
|
||||
if (nfaState(vertexp)) {
|
||||
vertexp->unlinkDelete(m_graphp); VL_DANGLING(vertexp);
|
||||
}
|
||||
}
|
||||
|
||||
UINFO(5,"Done.\n");
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_done");
|
||||
UINFO(5,"Done.\n");
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("dfa_done");
|
||||
}
|
||||
|
||||
public:
|
||||
GraphNfaToDfa(V3Graph* graphp, V3EdgeFuncP edgeFuncp)
|
||||
: GraphAlg<>(graphp, edgeFuncp) {
|
||||
m_step = 0;
|
||||
main();
|
||||
m_step = 0;
|
||||
main();
|
||||
}
|
||||
~GraphNfaToDfa() {}
|
||||
};
|
||||
|
|
@ -369,113 +385,115 @@ private:
|
|||
DfaGraph* graphp() { return static_cast<DfaGraph*>(m_graphp); }
|
||||
|
||||
bool isDead(DfaVertex* vertexp) {
|
||||
// A state is dead if not accepting, and goes nowhere
|
||||
if (vertexp->accepting() || vertexp->start()) return false;
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->top() != vertexp) return false;
|
||||
}
|
||||
return true;
|
||||
// A state is dead if not accepting, and goes nowhere
|
||||
if (vertexp->accepting() || vertexp->start()) return false;
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
if (edgep->top() != vertexp) return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void optimize_accepting_out() {
|
||||
// Delete outbound edges from accepting states
|
||||
// (As once we've accepted, we no longer care about anything else.)
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
if (vvertexp->accepting()) {
|
||||
for (V3GraphEdge* nextp,*edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Delete outbound edges from accepting states
|
||||
// (As once we've accepted, we no longer care about anything else.)
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
if (vvertexp->accepting()) {
|
||||
for (V3GraphEdge* nextp,*edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void optimize_orphans() {
|
||||
// Remove states that don't come from start
|
||||
// Presumably the previous optimization orphaned them.
|
||||
// Remove states that don't come from start
|
||||
// Presumably the previous optimization orphaned them.
|
||||
|
||||
// Vertex::m_user begin: 1 indicates on the work list, 2 processed
|
||||
// (Otherwise we might have nodes on the list twice, and reference after deleting them.)
|
||||
m_graphp->userClearVertices();
|
||||
// Vertex::m_user begin: 1 indicates on the work list, 2 processed
|
||||
// (Otherwise we might have nodes on the list twice, and reference after deleting them.)
|
||||
m_graphp->userClearVertices();
|
||||
|
||||
DfaVertex* startp = graphp()->findStart();
|
||||
DfaVertex* startp = graphp()->findStart();
|
||||
std::stack<V3GraphVertex*> workps; workps.push(startp);
|
||||
|
||||
// Mark all nodes connected to start
|
||||
while (!workps.empty()) {
|
||||
V3GraphVertex* vertexp = workps.top(); workps.pop();
|
||||
vertexp->user(2); // Processed
|
||||
// Add nodes from here to the work list
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
V3GraphVertex* tovertexp = edgep->top();
|
||||
if (!tovertexp->user()) {
|
||||
workps.push(tovertexp);
|
||||
tovertexp->user(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Mark all nodes connected to start
|
||||
while (!workps.empty()) {
|
||||
V3GraphVertex* vertexp = workps.top(); workps.pop();
|
||||
vertexp->user(2); // Processed
|
||||
// Add nodes from here to the work list
|
||||
for (V3GraphEdge* edgep = vertexp->outBeginp(); edgep; edgep=edgep->outNextp()) {
|
||||
V3GraphVertex* tovertexp = edgep->top();
|
||||
if (!tovertexp->user()) {
|
||||
workps.push(tovertexp);
|
||||
tovertexp->user(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Delete all nodes not connected
|
||||
for (V3GraphVertex* nextp,*vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=nextp) {
|
||||
nextp = vertexp->verticesNextp();
|
||||
if (!vertexp->user()) {
|
||||
vertexp->unlinkDelete(m_graphp); VL_DANGLING(vertexp);
|
||||
}
|
||||
}
|
||||
// Delete all nodes not connected
|
||||
for (V3GraphVertex* nextp,*vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=nextp) {
|
||||
nextp = vertexp->verticesNextp();
|
||||
if (!vertexp->user()) {
|
||||
vertexp->unlinkDelete(m_graphp); VL_DANGLING(vertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void optimize_no_outbound() {
|
||||
// Non-accepting states with no outbound transitions may be
|
||||
// deleted. Then, any arcs feeding those states, and perhaps those
|
||||
// states...
|
||||
// Non-accepting states with no outbound transitions may be
|
||||
// deleted. Then, any arcs feeding those states, and perhaps those
|
||||
// states...
|
||||
|
||||
// Vertex::m_user begin: 1 indicates on the work list
|
||||
// (Otherwise we might have nodes on the list twice, and reference after deleting them.)
|
||||
m_graphp->userClearVertices();
|
||||
// Vertex::m_user begin: 1 indicates on the work list
|
||||
// (Otherwise we might have nodes on the list twice, and reference after deleting them.)
|
||||
m_graphp->userClearVertices();
|
||||
|
||||
// Find all dead vertexes
|
||||
// Find all dead vertexes
|
||||
std::stack<DfaVertex*> workps;
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
workps.push(vvertexp);
|
||||
vertexp->user(1);
|
||||
} else {
|
||||
// If ever remove this, need dyn cast below
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
workps.push(vvertexp);
|
||||
vertexp->user(1);
|
||||
} else {
|
||||
// If ever remove this, need dyn cast below
|
||||
vertexp->v3fatalSrc("Non DfaVertex in dfa graph");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// While deadness... Delete and find new dead nodes.
|
||||
while (!workps.empty()) {
|
||||
DfaVertex* vertexp = workps.top(); workps.pop();
|
||||
vertexp->user(0);
|
||||
if (isDead(vertexp)) {
|
||||
// Add nodes that go here to the work list
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
DfaVertex* fromvertexp = static_cast<DfaVertex*>(edgep->fromp());
|
||||
if (fromvertexp != vertexp
|
||||
&& !fromvertexp->user()) {
|
||||
workps.push(fromvertexp);
|
||||
fromvertexp->user(1);
|
||||
}
|
||||
}
|
||||
// Transitions to this state removed by the unlink function
|
||||
vertexp->unlinkDelete(m_graphp); VL_DANGLING(vertexp);
|
||||
}
|
||||
}
|
||||
// While deadness... Delete and find new dead nodes.
|
||||
while (!workps.empty()) {
|
||||
DfaVertex* vertexp = workps.top(); workps.pop();
|
||||
vertexp->user(0);
|
||||
if (isDead(vertexp)) {
|
||||
// Add nodes that go here to the work list
|
||||
for (V3GraphEdge* edgep = vertexp->inBeginp(); edgep; edgep=edgep->inNextp()) {
|
||||
DfaVertex* fromvertexp = static_cast<DfaVertex*>(edgep->fromp());
|
||||
if (fromvertexp != vertexp
|
||||
&& !fromvertexp->user()) {
|
||||
workps.push(fromvertexp);
|
||||
fromvertexp->user(1);
|
||||
}
|
||||
}
|
||||
// Transitions to this state removed by the unlink function
|
||||
vertexp->unlinkDelete(m_graphp); VL_DANGLING(vertexp);
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
DfaGraphReduce(V3Graph* graphp, V3EdgeFuncP edgeFuncp)
|
||||
: GraphAlg<>(graphp, edgeFuncp) {
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_in");
|
||||
optimize_accepting_out();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_acc");
|
||||
optimize_orphans();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_orph");
|
||||
optimize_no_outbound();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_noout");
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_in");
|
||||
optimize_accepting_out();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_acc");
|
||||
optimize_orphans();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_orph");
|
||||
optimize_no_outbound();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("opt_noout");
|
||||
}
|
||||
~DfaGraphReduce() {}
|
||||
};
|
||||
|
|
@ -514,62 +532,64 @@ private:
|
|||
DfaGraph* graphp() { return static_cast<DfaGraph*>(m_graphp); }
|
||||
|
||||
void add_complement_edges() {
|
||||
// Find accepting vertex
|
||||
DfaVertex* acceptp = NULL;
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
if (vvertexp->accepting()) {
|
||||
acceptp = vvertexp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!acceptp) v3fatalSrc("No accepting vertex in DFA");
|
||||
// Find accepting vertex
|
||||
DfaVertex* acceptp = NULL;
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
if (vvertexp->accepting()) {
|
||||
acceptp = vvertexp;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!acceptp) v3fatalSrc("No accepting vertex in DFA");
|
||||
|
||||
// Remap edges
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp(); vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
//UINFO(9, " on vertex "<<vvertexp->name()<<endl);
|
||||
if (!vvertexp->accepting() && vvertexp != m_tempNewerReject) {
|
||||
for (V3GraphEdge* nextp, *edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
if (!edgep->user()) { // Not processed
|
||||
// Old edges to accept now go to new reject
|
||||
DfaEdge* vedgep = static_cast<DfaEdge*>(edgep);
|
||||
DfaVertex* tovertexp = static_cast<DfaVertex*>(edgep->top());
|
||||
if (tovertexp->accepting()) {
|
||||
new DfaEdge(graphp(), vvertexp, m_tempNewerReject, vedgep);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
}
|
||||
// Remap edges
|
||||
for (V3GraphVertex* vertexp = m_graphp->verticesBeginp();
|
||||
vertexp; vertexp=vertexp->verticesNextp()) {
|
||||
if (DfaVertex* vvertexp = dynamic_cast<DfaVertex*>(vertexp)) {
|
||||
//UINFO(9, " on vertex "<<vvertexp->name()<<endl);
|
||||
if (!vvertexp->accepting() && vvertexp != m_tempNewerReject) {
|
||||
for (V3GraphEdge* nextp, *edgep = vertexp->outBeginp(); edgep; edgep=nextp) {
|
||||
nextp = edgep->outNextp();
|
||||
if (!edgep->user()) { // Not processed
|
||||
// Old edges to accept now go to new reject
|
||||
DfaEdge* vedgep = static_cast<DfaEdge*>(edgep);
|
||||
DfaVertex* tovertexp = static_cast<DfaVertex*>(edgep->top());
|
||||
if (tovertexp->accepting()) {
|
||||
new DfaEdge(graphp(), vvertexp, m_tempNewerReject, vedgep);
|
||||
edgep->unlinkDelete(); VL_DANGLING(edgep);
|
||||
}
|
||||
|
||||
// NOT of all values goes to accept
|
||||
// We make a edge for each value to OR, IE
|
||||
// edge(complemented,a) edge(complemented,b) means !(a | b)
|
||||
if (!tovertexp->accepting()) { // Note we must include edges moved above to reject
|
||||
// NOT of all values goes to accept
|
||||
// We make a edge for each value to OR, IE
|
||||
// edge(complemented,a) edge(complemented,b) means !(a | b)
|
||||
if (!tovertexp->accepting()) { // Note we must include edges moved above to reject
|
||||
DfaEdge* newp = new DfaEdge(graphp(), vvertexp, acceptp, vedgep);
|
||||
newp->complement(!newp->complement());
|
||||
newp->user(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
newp->complement(!newp->complement());
|
||||
newp->user(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public:
|
||||
DfaGraphComplement(V3Graph* dfagraphp, V3EdgeFuncP edgeFuncp)
|
||||
: GraphAlg<>(dfagraphp, edgeFuncp) {
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("comp_in");
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("comp_in");
|
||||
|
||||
// Vertex::m_user begin: 1 indicates new edge, no more processing
|
||||
m_graphp->userClearEdges();
|
||||
// Vertex::m_user begin: 1 indicates new edge, no more processing
|
||||
m_graphp->userClearEdges();
|
||||
|
||||
m_tempNewerReject = new DfaVertex(graphp());
|
||||
add_complement_edges();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("comp_preswap");
|
||||
m_tempNewerReject = new DfaVertex(graphp());
|
||||
add_complement_edges();
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("comp_preswap");
|
||||
|
||||
m_tempNewerReject->unlinkDelete(graphp()); m_tempNewerReject=NULL;
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("comp_out");
|
||||
m_tempNewerReject->unlinkDelete(graphp()); m_tempNewerReject = NULL;
|
||||
if (debug()>=6) m_graphp->dumpDotFilePrefixed("comp_out");
|
||||
}
|
||||
~DfaGraphComplement() {}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -33,10 +33,10 @@ class DfaEdge;
|
|||
|
||||
//=============================================================================
|
||||
// NFA/DFA Graphs
|
||||
/// The NFA graph consists of:
|
||||
/// DfaVertex(START) The starting point
|
||||
/// DfaVertex() Interior states
|
||||
/// DfaVertex(ACCEPT) The completion point
|
||||
/// The NFA graph consists of:
|
||||
/// DfaVertex(START) The starting point
|
||||
/// DfaVertex() Interior states
|
||||
/// DfaVertex(ACCEPT) The completion point
|
||||
///
|
||||
/// Transitions include a list of all inputs (arbitrary user pointers),
|
||||
/// or epsilon, represented as a empty list of inputs.
|
||||
|
|
@ -48,36 +48,32 @@ class DfaEdge;
|
|||
///
|
||||
/// Common transforms:
|
||||
///
|
||||
/// "*": DfaVertex(START) --> [epsilon] -->DfaVertex(ACCEPT)
|
||||
/// "*": DfaVertex(START) --> [epsilon] -->DfaVertex(ACCEPT)
|
||||
///
|
||||
/// "L": ...->[ON_L]-->DfaVtx-->[epsilon]-->DfaVtx(ACCEPT)
|
||||
/// "L": ...->[ON_L]-->DfaVtx-->[epsilon]-->DfaVtx(ACCEPT)
|
||||
///
|
||||
/// "LR": ...->[ON_L]-->DfaVtx-->[epsilon]-->DfaVtx(ACCEPT)
|
||||
/// ->[ON_R]-->DfaVtx-->[epsilon]-/
|
||||
/// "LR": ...->[ON_L]-->DfaVtx-->[epsilon]-->DfaVtx(ACCEPT)
|
||||
/// ->[ON_R]-->DfaVtx-->[epsilon]-/
|
||||
///
|
||||
/// "L|R": ...->DfaVtx-->[epsilon]-->DfaVtx-->[ON_L]-->DfaVtx()->[epsilon]-->DfaVtx(ACCEPT)
|
||||
/// \->[epsilon]-->DfaVtx-->[ON_R]-->DfaVtx()->[epsilon]-/
|
||||
/// "L|R": ...->DfaVtx-->[epsilon]-->DfaVtx-->[ON_L]-->DfaVtx()->[epsilon]-->DfaVtx(ACCEPT)
|
||||
/// \->[epsilon]-->DfaVtx-->[ON_R]-->DfaVtx()->[epsilon]-/
|
||||
///
|
||||
/// "L*": ...->DfaVtx-->[epsilon]-->DfaVtx-->[ON_L]-->DfaVtx()->[epsilon]-->DfaVtx(ACCEPT)
|
||||
/// | ^\----[epsilon]<-------/ |
|
||||
/// \->[epsilon]-----------------------------------------/
|
||||
/// "L*": ...->DfaVtx-->[epsilon]-->DfaVtx-->[ON_L]-->DfaVtx()->[epsilon]-->DfaVtx(ACCEPT)
|
||||
/// | ^\----[epsilon]<-------/ |
|
||||
/// \->[epsilon]-----------------------------------------/
|
||||
|
||||
class DfaGraph : public V3Graph {
|
||||
// STATE
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
DfaGraph() {}
|
||||
virtual ~DfaGraph() {}
|
||||
|
||||
// METHODS
|
||||
/// Find start node
|
||||
DfaVertex* findStart();
|
||||
|
||||
/// Convert automata: NFA to DFA
|
||||
void nfaToDfa();
|
||||
|
||||
/// Simplify a DFA automata
|
||||
void dfaReduce();
|
||||
|
||||
/// Complement result (must already be dfa)
|
||||
void dfaComplement();
|
||||
};
|
||||
|
|
@ -89,24 +85,24 @@ class DfaVertex : public V3GraphVertex {
|
|||
// Each DFA state is captured in this vertex.
|
||||
// Start and accepting are members, rather than the more intuitive
|
||||
// subclasses, as subclassing them would make it harder to inherit from here.
|
||||
bool m_start; // Start state
|
||||
bool m_accepting; // Accepting state?
|
||||
bool m_start; // Start state
|
||||
bool m_accepting; // Accepting state?
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
DfaVertex(DfaGraph* graphp, bool start=false, bool accepting=false)
|
||||
: V3GraphVertex(graphp)
|
||||
, m_start(start), m_accepting(accepting) {}
|
||||
: V3GraphVertex(graphp)
|
||||
, m_start(start), m_accepting(accepting) {}
|
||||
using V3GraphVertex::clone; // We are overriding, not overloading clone(V3Graph*)
|
||||
virtual DfaVertex* clone(DfaGraph* graphp) {
|
||||
return new DfaVertex(graphp, start(), accepting()); }
|
||||
return new DfaVertex(graphp, start(), accepting()); }
|
||||
virtual ~DfaVertex() {}
|
||||
// ACCESSORS
|
||||
virtual string dotShape() const { return (accepting()?"doublecircle":""); }
|
||||
virtual string dotColor() const { return start()?"blue":(color()?"red":"black"); }
|
||||
bool start() const { return m_start; }
|
||||
void start(bool flag) { m_start=flag; }
|
||||
void start(bool flag) { m_start = flag; }
|
||||
bool accepting() const { return m_accepting; }
|
||||
void accepting(bool flag) { m_accepting=flag; }
|
||||
void accepting(bool flag) { m_accepting = flag; }
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
|
|
@ -118,37 +114,37 @@ typedef VNUser DfaInput;
|
|||
// Edge types
|
||||
|
||||
class DfaEdge : public V3GraphEdge {
|
||||
DfaInput m_input;
|
||||
bool m_complement; // Invert value when doing compare
|
||||
DfaInput m_input;
|
||||
bool m_complement; // Invert value when doing compare
|
||||
public:
|
||||
static DfaInput EPSILON() { return VNUser::fromInt(0); }
|
||||
static DfaInput NA() { return VNUser::fromInt(1); } // as in not-applicable
|
||||
static DfaInput NA() { return VNUser::fromInt(1); } // as in not-applicable
|
||||
// CONSTRUCTORS
|
||||
DfaEdge(DfaGraph* graphp, DfaVertex* fromp, DfaVertex* top, const DfaInput& input)
|
||||
: V3GraphEdge(graphp, fromp, top, 1)
|
||||
, m_input(input), m_complement(false) {}
|
||||
: V3GraphEdge(graphp, fromp, top, 1)
|
||||
, m_input(input), m_complement(false) {}
|
||||
DfaEdge(DfaGraph* graphp, DfaVertex* fromp, DfaVertex* top, const DfaEdge* copyfrom)
|
||||
: V3GraphEdge(graphp, fromp, top, copyfrom->weight())
|
||||
, m_input(copyfrom->input()), m_complement(copyfrom->complement()) {}
|
||||
: V3GraphEdge(graphp, fromp, top, copyfrom->weight())
|
||||
, m_input(copyfrom->input()), m_complement(copyfrom->complement()) {}
|
||||
virtual ~DfaEdge() {}
|
||||
// METHODS
|
||||
virtual string dotColor() const {
|
||||
return (na() ? "yellow"
|
||||
: epsilon() ? "green"
|
||||
: "black"); }
|
||||
return (na() ? "yellow"
|
||||
: epsilon() ? "green"
|
||||
: "black"); }
|
||||
virtual string dotLabel() const {
|
||||
return (na() ? ""
|
||||
: epsilon() ? "e"
|
||||
: complement() ? ("not "+cvtToStr(input().toInt()))
|
||||
: cvtToStr(input().toInt())); }
|
||||
return (na() ? ""
|
||||
: epsilon() ? "e"
|
||||
: complement() ? ("not "+cvtToStr(input().toInt()))
|
||||
: cvtToStr(input().toInt())); }
|
||||
virtual string dotStyle() const { return (na()||cutable())?"dashed":""; }
|
||||
bool epsilon() const { return input().toInt()==EPSILON().toInt(); }
|
||||
bool na() const { return input().toInt()==NA().toInt(); }
|
||||
bool complement() const { return m_complement; }
|
||||
void complement(bool value) { m_complement=value; }
|
||||
DfaInput input() const { return m_input; }
|
||||
void complement(bool value) { m_complement = value; }
|
||||
DfaInput input() const { return m_input; }
|
||||
};
|
||||
|
||||
//============================================================================
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -35,10 +35,10 @@ class V3GraphTest {
|
|||
public:
|
||||
// ***These tests only run with DEBUG ON***
|
||||
static int debug() {
|
||||
static int level = -1;
|
||||
// Note setting just --debug will not enable this, as we exit when we run the test
|
||||
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__, 0);
|
||||
return level;
|
||||
static int level = -1;
|
||||
// Note setting just --debug will not enable this, as we exit when we run the test
|
||||
if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__, 0);
|
||||
return level;
|
||||
}
|
||||
|
||||
protected:
|
||||
|
|
@ -46,21 +46,21 @@ protected:
|
|||
DfaGraph m_graph;
|
||||
|
||||
// METHODS - for children
|
||||
virtual void runTest() = 0; // Run the test
|
||||
virtual string name() = 0; // Name of the test
|
||||
virtual void runTest() = 0; // Run the test
|
||||
virtual string name() = 0; // Name of the test
|
||||
|
||||
// Utilities
|
||||
void dump() {
|
||||
if (debug()>=9) {
|
||||
m_graph.dumpDotFilePrefixed("v3graphtest_"+name());
|
||||
}
|
||||
if (debug()>=9) {
|
||||
m_graph.dumpDotFilePrefixed("v3graphtest_"+name());
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
V3GraphTest() {}
|
||||
virtual ~V3GraphTest() {}
|
||||
void run() {
|
||||
if (debug()) runTest();
|
||||
if (debug()) runTest();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -69,9 +69,10 @@ public:
|
|||
// Vertices and nodes
|
||||
|
||||
class V3GraphTestVertex : public V3GraphVertex {
|
||||
string m_name;
|
||||
string m_name;
|
||||
public:
|
||||
V3GraphTestVertex(V3Graph* graphp, const string& name) : V3GraphVertex(graphp), m_name(name) {}
|
||||
V3GraphTestVertex(V3Graph* graphp, const string& name)
|
||||
: V3GraphVertex(graphp), m_name(name) {}
|
||||
virtual ~V3GraphTestVertex() {}
|
||||
// ACCESSORS
|
||||
virtual string name() const { return m_name; }
|
||||
|
|
@ -79,7 +80,8 @@ public:
|
|||
|
||||
class V3GraphTestVarVertex : public V3GraphTestVertex {
|
||||
public:
|
||||
V3GraphTestVarVertex(V3Graph* graphp, const string& name) : V3GraphTestVertex(graphp, name) {}
|
||||
V3GraphTestVarVertex(V3Graph* graphp, const string& name)
|
||||
: V3GraphTestVertex(graphp, name) {}
|
||||
virtual ~V3GraphTestVarVertex() {}
|
||||
// ACCESSORS
|
||||
virtual string dotColor() const { return "blue"; }
|
||||
|
|
@ -93,30 +95,30 @@ class V3GraphTestStrong : public V3GraphTest {
|
|||
public:
|
||||
virtual string name() { return "strong"; }
|
||||
virtual void runTest() {
|
||||
V3Graph* gp = &m_graph;
|
||||
// Verify we break edges at a good point
|
||||
// A simple alg would make 3 breaks, below only requires b->i to break
|
||||
V3GraphTestVertex* i = new V3GraphTestVarVertex(gp,"*INPUTS*");
|
||||
V3GraphTestVertex* a = new V3GraphTestVarVertex(gp,"a");
|
||||
V3GraphTestVertex* b = new V3GraphTestVarVertex(gp,"b");
|
||||
V3GraphTestVertex* g1 = new V3GraphTestVarVertex(gp,"g1");
|
||||
V3GraphTestVertex* g2 = new V3GraphTestVarVertex(gp,"g2");
|
||||
V3GraphTestVertex* g3 = new V3GraphTestVarVertex(gp,"g3");
|
||||
V3GraphTestVertex* q = new V3GraphTestVarVertex(gp,"q");
|
||||
new V3GraphEdge(gp, i, a, 2, true);
|
||||
new V3GraphEdge(gp, a, b, 2, true);
|
||||
new V3GraphEdge(gp, b, g1, 2, true);
|
||||
new V3GraphEdge(gp, b, g2, 2, true);
|
||||
new V3GraphEdge(gp, b, g3, 2, true);
|
||||
new V3GraphEdge(gp, g1, a, 2, true);
|
||||
new V3GraphEdge(gp, g3, g2, 2, true);
|
||||
new V3GraphEdge(gp, g2, g3, 2, true);
|
||||
new V3GraphEdge(gp, g1, q, 2, true);
|
||||
new V3GraphEdge(gp, g2, q, 2, true);
|
||||
new V3GraphEdge(gp, g3, q, 2, true);
|
||||
V3Graph* gp = &m_graph;
|
||||
// Verify we break edges at a good point
|
||||
// A simple alg would make 3 breaks, below only requires b->i to break
|
||||
V3GraphTestVertex* i = new V3GraphTestVarVertex(gp, "*INPUTS*");
|
||||
V3GraphTestVertex* a = new V3GraphTestVarVertex(gp, "a");
|
||||
V3GraphTestVertex* b = new V3GraphTestVarVertex(gp, "b");
|
||||
V3GraphTestVertex* g1 = new V3GraphTestVarVertex(gp, "g1");
|
||||
V3GraphTestVertex* g2 = new V3GraphTestVarVertex(gp, "g2");
|
||||
V3GraphTestVertex* g3 = new V3GraphTestVarVertex(gp, "g3");
|
||||
V3GraphTestVertex* q = new V3GraphTestVarVertex(gp, "q");
|
||||
new V3GraphEdge(gp, i, a, 2, true);
|
||||
new V3GraphEdge(gp, a, b, 2, true);
|
||||
new V3GraphEdge(gp, b, g1, 2, true);
|
||||
new V3GraphEdge(gp, b, g2, 2, true);
|
||||
new V3GraphEdge(gp, b, g3, 2, true);
|
||||
new V3GraphEdge(gp, g1, a, 2, true);
|
||||
new V3GraphEdge(gp, g3, g2, 2, true);
|
||||
new V3GraphEdge(gp, g2, g3, 2, true);
|
||||
new V3GraphEdge(gp, g1, q, 2, true);
|
||||
new V3GraphEdge(gp, g2, q, 2, true);
|
||||
new V3GraphEdge(gp, g3, q, 2, true);
|
||||
|
||||
gp->stronglyConnected(&V3GraphEdge::followAlwaysTrue);
|
||||
dump();
|
||||
gp->stronglyConnected(&V3GraphEdge::followAlwaysTrue);
|
||||
dump();
|
||||
|
||||
UASSERT(i->color()!=a->color() && a->color() != g2->color() && g2->color() != q->color(),
|
||||
"SelfTest: Separate colors not assigned");
|
||||
|
|
@ -131,27 +133,27 @@ class V3GraphTestAcyc : public V3GraphTest {
|
|||
public:
|
||||
virtual string name() { return "acyc"; }
|
||||
virtual void runTest() {
|
||||
V3Graph* gp = &m_graph;
|
||||
// Verify we break edges at a good point
|
||||
// A simple alg would make 3 breaks, below only requires b->i to break
|
||||
V3GraphTestVertex* i = new V3GraphTestVarVertex(gp,"*INPUTS*");
|
||||
V3GraphTestVertex* a = new V3GraphTestVarVertex(gp,"a");
|
||||
V3GraphTestVertex* b = new V3GraphTestVarVertex(gp,"b");
|
||||
V3GraphTestVertex* g1 = new V3GraphTestVarVertex(gp,"g1");
|
||||
V3GraphTestVertex* g2 = new V3GraphTestVarVertex(gp,"g2");
|
||||
V3GraphTestVertex* g3 = new V3GraphTestVarVertex(gp,"g3");
|
||||
new V3GraphEdge(gp, i, a, 2, true);
|
||||
new V3GraphEdge(gp, a, b, 2, true);
|
||||
new V3GraphEdge(gp, b, g1, 2, true);
|
||||
new V3GraphEdge(gp, b, g2, 2, true);
|
||||
new V3GraphEdge(gp, b, g3, 2, true);
|
||||
new V3GraphEdge(gp, g1, a, 2, true);
|
||||
new V3GraphEdge(gp, g2, a, 2, true);
|
||||
new V3GraphEdge(gp, g3, a, 2, true);
|
||||
V3Graph* gp = &m_graph;
|
||||
// Verify we break edges at a good point
|
||||
// A simple alg would make 3 breaks, below only requires b->i to break
|
||||
V3GraphTestVertex* i = new V3GraphTestVarVertex(gp, "*INPUTS*");
|
||||
V3GraphTestVertex* a = new V3GraphTestVarVertex(gp, "a");
|
||||
V3GraphTestVertex* b = new V3GraphTestVarVertex(gp, "b");
|
||||
V3GraphTestVertex* g1 = new V3GraphTestVarVertex(gp, "g1");
|
||||
V3GraphTestVertex* g2 = new V3GraphTestVarVertex(gp, "g2");
|
||||
V3GraphTestVertex* g3 = new V3GraphTestVarVertex(gp, "g3");
|
||||
new V3GraphEdge(gp, i, a, 2, true);
|
||||
new V3GraphEdge(gp, a, b, 2, true);
|
||||
new V3GraphEdge(gp, b, g1, 2, true);
|
||||
new V3GraphEdge(gp, b, g2, 2, true);
|
||||
new V3GraphEdge(gp, b, g3, 2, true);
|
||||
new V3GraphEdge(gp, g1, a, 2, true);
|
||||
new V3GraphEdge(gp, g2, a, 2, true);
|
||||
new V3GraphEdge(gp, g3, a, 2, true);
|
||||
|
||||
gp->acyclic(&V3GraphEdge::followAlwaysTrue);
|
||||
gp->order();
|
||||
dump();
|
||||
gp->acyclic(&V3GraphEdge::followAlwaysTrue);
|
||||
gp->order();
|
||||
dump();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -159,118 +161,118 @@ class V3GraphTestVars : public V3GraphTest {
|
|||
public:
|
||||
virtual string name() { return "vars"; }
|
||||
virtual void runTest() {
|
||||
V3Graph* gp = &m_graph;
|
||||
V3Graph* gp = &m_graph;
|
||||
|
||||
V3GraphTestVertex* clk = new V3GraphTestVarVertex(gp,"$clk");
|
||||
V3GraphTestVertex* clk = new V3GraphTestVarVertex(gp, "$clk");
|
||||
|
||||
V3GraphTestVertex* a = new V3GraphTestVarVertex(gp,"$a");
|
||||
V3GraphTestVertex* a_dly = new V3GraphTestVarVertex(gp,"$a_dly");
|
||||
V3GraphTestVertex* a_dlyblk= new V3GraphTestVarVertex(gp,"$a_dlyblk");
|
||||
V3GraphTestVertex* b = new V3GraphTestVarVertex(gp,"$b");
|
||||
V3GraphTestVertex* b_dly = new V3GraphTestVarVertex(gp,"$b_dly");
|
||||
V3GraphTestVertex* b_dlyblk= new V3GraphTestVarVertex(gp,"$b_dlyblk");
|
||||
V3GraphTestVertex* c = new V3GraphTestVarVertex(gp,"$c");
|
||||
V3GraphTestVertex* i = new V3GraphTestVarVertex(gp,"$i");
|
||||
V3GraphTestVertex* a = new V3GraphTestVarVertex(gp, "$a");
|
||||
V3GraphTestVertex* a_dly = new V3GraphTestVarVertex(gp, "$a_dly");
|
||||
V3GraphTestVertex* a_dlyblk= new V3GraphTestVarVertex(gp, "$a_dlyblk");
|
||||
V3GraphTestVertex* b = new V3GraphTestVarVertex(gp, "$b");
|
||||
V3GraphTestVertex* b_dly = new V3GraphTestVarVertex(gp, "$b_dly");
|
||||
V3GraphTestVertex* b_dlyblk= new V3GraphTestVarVertex(gp, "$b_dlyblk");
|
||||
V3GraphTestVertex* c = new V3GraphTestVarVertex(gp, "$c");
|
||||
V3GraphTestVertex* i = new V3GraphTestVarVertex(gp, "$i");
|
||||
|
||||
V3GraphTestVertex* ap = new V3GraphTestVarVertex(gp,"$a_pre");
|
||||
V3GraphTestVertex* bp = new V3GraphTestVarVertex(gp,"$b_pre");
|
||||
V3GraphTestVertex* cp = new V3GraphTestVarVertex(gp,"$c_pre");
|
||||
V3GraphTestVertex* ap = new V3GraphTestVarVertex(gp, "$a_pre");
|
||||
V3GraphTestVertex* bp = new V3GraphTestVarVertex(gp, "$b_pre");
|
||||
V3GraphTestVertex* cp = new V3GraphTestVarVertex(gp, "$c_pre");
|
||||
|
||||
V3GraphTestVertex* n;
|
||||
V3GraphTestVertex* n;
|
||||
|
||||
// Logical order between clk, and posedge blocks
|
||||
// implemented by special CLK prod/cons?
|
||||
// Required order between first x_DLY<=x_pre and final x<=x_DLY
|
||||
// implemented by producer/consumer on a_dly signals
|
||||
// Required order between first x_DLY<=x_pre and x_DLY<=setters
|
||||
// implemented by fake dependency on _dlyblk
|
||||
// Required order between x_DLY<=setters and final x<=x_DLY
|
||||
// implemented by producer/consumer on a_dly signals
|
||||
// Desired order between different _DLY blocks so we can elim temporaries
|
||||
// implemented by cutable "pre" signal dependencies
|
||||
// Logical order between clk, and posedge blocks
|
||||
// implemented by special CLK prod/cons?
|
||||
// Required order between first x_DLY<=x_pre and final x<=x_DLY
|
||||
// implemented by producer/consumer on a_dly signals
|
||||
// Required order between first x_DLY<=x_pre and x_DLY<=setters
|
||||
// implemented by fake dependency on _dlyblk
|
||||
// Required order between x_DLY<=setters and final x<=x_DLY
|
||||
// implemented by producer/consumer on a_dly signals
|
||||
// Desired order between different _DLY blocks so we can elim temporaries
|
||||
// implemented by cutable "pre" signal dependencies
|
||||
|
||||
|
||||
n = new V3GraphTestVertex(gp,"*INPUTS*"); {
|
||||
new V3GraphEdge(gp, n, clk, 2);
|
||||
new V3GraphEdge(gp, n, i, 2);
|
||||
}
|
||||
n = new V3GraphTestVertex(gp, "*INPUTS*"); {
|
||||
new V3GraphEdge(gp, n, clk, 2);
|
||||
new V3GraphEdge(gp, n, i, 2);
|
||||
}
|
||||
|
||||
V3GraphTestVertex* posedge = n = new V3GraphTestVertex(gp,"*posedge clk*"); {
|
||||
new V3GraphEdge(gp, clk, n, 2);
|
||||
}
|
||||
V3GraphTestVertex* posedge = n = new V3GraphTestVertex(gp, "*posedge clk*"); {
|
||||
new V3GraphEdge(gp, clk, n, 2);
|
||||
}
|
||||
|
||||
// AssignPre's VarRefs on LHS: generate special BLK
|
||||
// normal: VarRefs on LHS: generate normal
|
||||
// underSBlock: VarRefs on RHS: consume 'pre' (required to save cutable tests)
|
||||
n = new V3GraphTestVertex(gp,"a_dly<PRE=a"); {
|
||||
new V3GraphEdge(gp, n, a_dlyblk, 2); // Block ordering
|
||||
new V3GraphEdge(gp, n, a_dly, 2);
|
||||
new V3GraphEdge(gp, ap, n, 2, true); // DESIRED delayed ordering (inp is required)
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
n = new V3GraphTestVertex(gp,"b_dly<PRE=b"); {
|
||||
new V3GraphEdge(gp, n, b_dlyblk, 2); // Block ordering
|
||||
new V3GraphEdge(gp, n, b_dly, 2);
|
||||
new V3GraphEdge(gp, bp, n, 2, true); // DESIRED delayed ordering
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
// AssignPre's VarRefs on LHS: generate special BLK
|
||||
// normal: VarRefs on LHS: generate normal
|
||||
// underSBlock: VarRefs on RHS: consume 'pre' (required to save cutable tests)
|
||||
n = new V3GraphTestVertex(gp, "a_dly<PRE=a"); {
|
||||
new V3GraphEdge(gp, n, a_dlyblk, 2); // Block ordering
|
||||
new V3GraphEdge(gp, n, a_dly, 2);
|
||||
new V3GraphEdge(gp, ap, n, 2, true); // DESIRED delayed ordering (inp is required)
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
n = new V3GraphTestVertex(gp, "b_dly<PRE=b"); {
|
||||
new V3GraphEdge(gp, n, b_dlyblk, 2); // Block ordering
|
||||
new V3GraphEdge(gp, n, b_dly, 2);
|
||||
new V3GraphEdge(gp, bp, n, 2, true); // DESIRED delayed ordering
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
|
||||
// AssignDly's VarRefs on LHS: consume special BLK
|
||||
// normal: VarRefs on LHS: generate normal
|
||||
// underSBlock: VarRefs on RHS: generate 'pre' signals (cutable)
|
||||
// SenItems: consume CLOCK dependency
|
||||
n = new V3GraphTestVertex(gp,"a_dly<=b|c"); {
|
||||
new V3GraphEdge(gp, a_dlyblk, n, 2); // Block ordering in
|
||||
new V3GraphEdge(gp, n, a_dly, 2);
|
||||
// Note we don't include ap as we're generating a_dly
|
||||
new V3GraphEdge(gp, n, bp, 2); // DESIRED delayed usage
|
||||
new V3GraphEdge(gp, n, cp, 2); // DESIRED delayed usage
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
n = new V3GraphTestVertex(gp,"b_dly<=a"); {
|
||||
new V3GraphEdge(gp, b_dlyblk, n, 2); // Block ordering in
|
||||
new V3GraphEdge(gp, n, b_dly, 2);
|
||||
new V3GraphEdge(gp, n, ap, 2); // DESIRED delayed usage
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
// AssignDly's VarRefs on LHS: consume special BLK
|
||||
// normal: VarRefs on LHS: generate normal
|
||||
// underSBlock: VarRefs on RHS: generate 'pre' signals (cutable)
|
||||
// SenItems: consume CLOCK dependency
|
||||
n = new V3GraphTestVertex(gp, "a_dly<=b|c"); {
|
||||
new V3GraphEdge(gp, a_dlyblk, n, 2); // Block ordering in
|
||||
new V3GraphEdge(gp, n, a_dly, 2);
|
||||
// Note we don't include ap as we're generating a_dly
|
||||
new V3GraphEdge(gp, n, bp, 2); // DESIRED delayed usage
|
||||
new V3GraphEdge(gp, n, cp, 2); // DESIRED delayed usage
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
n = new V3GraphTestVertex(gp, "b_dly<=a"); {
|
||||
new V3GraphEdge(gp, b_dlyblk, n, 2); // Block ordering in
|
||||
new V3GraphEdge(gp, n, b_dly, 2);
|
||||
new V3GraphEdge(gp, n, ap, 2); // DESIRED delayed usage
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
|
||||
// AssignPost's
|
||||
// normal: VarRefs on LHS: generate normal
|
||||
// underSBlock: VarRefs on RHS: consume normal
|
||||
n = new V3GraphTestVertex(gp,"a=POST=a_dly"); {
|
||||
new V3GraphEdge(gp, n, a, 3);
|
||||
new V3GraphEdge(gp, a_dly, n, 3);
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
n = new V3GraphTestVertex(gp,"b=POST=b_dly"); {
|
||||
new V3GraphEdge(gp, n, b, 3);
|
||||
new V3GraphEdge(gp, b_dly, n, 3);
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
// AssignPost's
|
||||
// normal: VarRefs on LHS: generate normal
|
||||
// underSBlock: VarRefs on RHS: consume normal
|
||||
n = new V3GraphTestVertex(gp, "a=POST=a_dly"); {
|
||||
new V3GraphEdge(gp, n, a, 3);
|
||||
new V3GraphEdge(gp, a_dly, n, 3);
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
n = new V3GraphTestVertex(gp, "b=POST=b_dly"); {
|
||||
new V3GraphEdge(gp, n, b, 3);
|
||||
new V3GraphEdge(gp, b_dly, n, 3);
|
||||
new V3GraphEdge(gp, posedge, n, 2);
|
||||
}
|
||||
|
||||
// COMBO
|
||||
// Inbound edges are always uncutable, because we must put combo logic after sequential
|
||||
// Outbound are cutable, as we may need to evaluate multiple times
|
||||
// COMBO
|
||||
// Inbound edges are always uncutable, because we must put combo logic after sequential
|
||||
// Outbound are cutable, as we may need to evaluate multiple times
|
||||
|
||||
{
|
||||
n = new V3GraphTestVertex(gp,"c=a|b|i");
|
||||
new V3GraphEdge(gp, n, c, 1, true);
|
||||
new V3GraphEdge(gp, a, n, 1, false);
|
||||
new V3GraphEdge(gp, b, n, 1, false);
|
||||
new V3GraphEdge(gp, i, n, 1, false);
|
||||
}
|
||||
{
|
||||
n = new V3GraphTestVertex(gp, "c=a|b|i");
|
||||
new V3GraphEdge(gp, n, c, 1, true);
|
||||
new V3GraphEdge(gp, a, n, 1, false);
|
||||
new V3GraphEdge(gp, b, n, 1, false);
|
||||
new V3GraphEdge(gp, i, n, 1, false);
|
||||
}
|
||||
|
||||
gp->acyclic(&V3GraphEdge::followAlwaysTrue);
|
||||
gp->order();
|
||||
gp->acyclic(&V3GraphEdge::followAlwaysTrue);
|
||||
gp->order();
|
||||
|
||||
dump();
|
||||
dump();
|
||||
}
|
||||
};
|
||||
|
||||
//======================================================================
|
||||
|
||||
class DfaTestVertex : public DfaVertex {
|
||||
string m_name;
|
||||
string m_name;
|
||||
public:
|
||||
DfaTestVertex(DfaGraph* graphp, const string& name) : DfaVertex(graphp), m_name(name) {}
|
||||
virtual ~DfaTestVertex() {}
|
||||
|
|
@ -283,43 +285,43 @@ class V3GraphTestDfa : public V3GraphTest {
|
|||
public:
|
||||
virtual string name() { return "dfa"; }
|
||||
virtual void runTest() {
|
||||
DfaGraph* gp = &m_graph;
|
||||
DfaGraph* gp = &m_graph;
|
||||
|
||||
// NFA Pattern for ( (LR) | (L*R)) Z
|
||||
DfaTestVertex* st = new DfaTestVertex(gp,"*START*"); st->start(true);
|
||||
DfaTestVertex* sl = new DfaTestVertex(gp,"sL");
|
||||
DfaTestVertex* srs = new DfaTestVertex(gp,"sR*");
|
||||
DfaTestVertex* sls = new DfaTestVertex(gp,"sL*");
|
||||
DfaTestVertex* sr = new DfaTestVertex(gp,"sR");
|
||||
DfaTestVertex* sz = new DfaTestVertex(gp,"sZ");
|
||||
DfaTestVertex* sac = new DfaTestVertex(gp,"*ACCEPT*"); sac->accepting(true);
|
||||
// NFA Pattern for ( (LR) | (L*R)) Z
|
||||
DfaTestVertex* st = new DfaTestVertex(gp, "*START*"); st->start(true);
|
||||
DfaTestVertex* sl = new DfaTestVertex(gp, "sL");
|
||||
DfaTestVertex* srs = new DfaTestVertex(gp, "sR*");
|
||||
DfaTestVertex* sls = new DfaTestVertex(gp, "sL*");
|
||||
DfaTestVertex* sr = new DfaTestVertex(gp, "sR");
|
||||
DfaTestVertex* sz = new DfaTestVertex(gp, "sZ");
|
||||
DfaTestVertex* sac = new DfaTestVertex(gp, "*ACCEPT*"); sac->accepting(true);
|
||||
|
||||
VNUser L = VNUser::fromInt(0xaa);
|
||||
VNUser R = VNUser::fromInt(0xbb);
|
||||
VNUser Z = VNUser::fromInt(0xcc);
|
||||
VNUser L = VNUser::fromInt(0xaa);
|
||||
VNUser R = VNUser::fromInt(0xbb);
|
||||
VNUser Z = VNUser::fromInt(0xcc);
|
||||
|
||||
new DfaEdge(gp, st, sl, DfaEdge::EPSILON());
|
||||
new DfaEdge(gp, sl, srs, L);
|
||||
new DfaEdge(gp, srs, srs, R);
|
||||
new DfaEdge(gp, srs, sz, Z);
|
||||
new DfaEdge(gp, sz, sac, DfaEdge::EPSILON());
|
||||
new DfaEdge(gp, st, sl, DfaEdge::EPSILON());
|
||||
new DfaEdge(gp, sl, srs, L);
|
||||
new DfaEdge(gp, srs, srs, R);
|
||||
new DfaEdge(gp, srs, sz, Z);
|
||||
new DfaEdge(gp, sz, sac, DfaEdge::EPSILON());
|
||||
|
||||
new DfaEdge(gp, st, sls, DfaEdge::EPSILON());
|
||||
new DfaEdge(gp, sls, sls, L);
|
||||
new DfaEdge(gp, sls, sr, R);
|
||||
new DfaEdge(gp, sr, sz, Z);
|
||||
new DfaEdge(gp, sz, sac, DfaEdge::EPSILON());
|
||||
new DfaEdge(gp, st, sls, DfaEdge::EPSILON());
|
||||
new DfaEdge(gp, sls, sls, L);
|
||||
new DfaEdge(gp, sls, sr, R);
|
||||
new DfaEdge(gp, sr, sz, Z);
|
||||
new DfaEdge(gp, sz, sac, DfaEdge::EPSILON());
|
||||
|
||||
dump();
|
||||
gp->nfaToDfa();
|
||||
dump();
|
||||
gp->dfaReduce();
|
||||
dump();
|
||||
dump();
|
||||
gp->nfaToDfa();
|
||||
dump();
|
||||
gp->dfaReduce();
|
||||
dump();
|
||||
|
||||
gp->dfaComplement();
|
||||
dump();
|
||||
gp->dfaReduce();
|
||||
dump();
|
||||
gp->dfaComplement();
|
||||
dump();
|
||||
gp->dfaReduce();
|
||||
dump();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -336,14 +338,14 @@ class V3GraphTestImport : public V3GraphTest {
|
|||
public:
|
||||
virtual string name() { return "import"; }
|
||||
virtual void runTest() {
|
||||
DfaGraph* gp = &m_graph;
|
||||
DfaGraph* gp = &m_graph;
|
||||
if (V3GraphTest::debug()) DfaGraph::debug(9);
|
||||
dotImport();
|
||||
dump();
|
||||
gp->acyclic(&V3GraphEdge::followAlwaysTrue);
|
||||
dump();
|
||||
gp->rank(&V3GraphEdge::followAlwaysTrue);
|
||||
dump();
|
||||
dotImport();
|
||||
dump();
|
||||
gp->acyclic(&V3GraphEdge::followAlwaysTrue);
|
||||
dump();
|
||||
gp->rank(&V3GraphEdge::followAlwaysTrue);
|
||||
dump();
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
123
src/V3Hashed.cpp
123
src/V3Hashed.cpp
|
|
@ -19,9 +19,9 @@
|
|||
//*************************************************************************
|
||||
// V3Hashed's Transformations:
|
||||
//
|
||||
// Hash each node depth first
|
||||
// Hash includes varp name and operator type, and constants
|
||||
// Form lookup table based on hash of each statement w/ nodep and next nodep
|
||||
// Hash each node depth first
|
||||
// Hash includes varp name and operator type, and constants
|
||||
// Form lookup table based on hash of each statement w/ nodep and next nodep
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -46,11 +46,11 @@ class HashedVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstNodeStmt::user4() -> V3Hash. Hash value of this node (hash of 0 is illegal)
|
||||
//AstUser4InUse in V3Hashed.h
|
||||
// AstNodeStmt::user4() -> V3Hash. Hash value of this node (hash of 0 is illegal)
|
||||
//AstUser4InUse in V3Hashed.h
|
||||
|
||||
// STATE
|
||||
V3Hash m_lowerHash; // Hash of the statement we're building
|
||||
V3Hash m_lowerHash; // Hash of the statement we're building
|
||||
bool m_cacheInUser4; // Use user4 to cache each V3Hash?
|
||||
|
||||
// METHODS
|
||||
|
|
@ -61,26 +61,28 @@ private:
|
|||
if (!m_cacheInUser4 || !nodep->user4()) {
|
||||
if (VN_IS(nodep->backp(), CFunc)
|
||||
&& !(VN_IS(nodep, NodeStmt) || VN_IS(nodep, CFunc))) {
|
||||
nodep->v3fatalSrc("Node "<<nodep->prettyTypeName()<<" in statement position but not marked stmt (node under function)");
|
||||
}
|
||||
nodep->v3fatalSrc("Node "<<nodep->prettyTypeName()<<" in statement position but not marked stmt (node under function)");
|
||||
}
|
||||
V3Hash oldHash = m_lowerHash;
|
||||
{
|
||||
m_lowerHash = nodep->sameHash();
|
||||
if (m_lowerHash.isIllegal()) {
|
||||
nodep->v3fatalSrc("sameHash function undefined (returns 0) for node under CFunc.");
|
||||
}
|
||||
// For identical nodes, the type should be the same thus dtypep should be the same too
|
||||
m_lowerHash = V3Hash(m_lowerHash, V3Hash(nodep->type()<<6, V3Hash(nodep->dtypep())));
|
||||
// Now update m_lowerHash for our children's (and next children) contributions
|
||||
{
|
||||
m_lowerHash = nodep->sameHash();
|
||||
if (m_lowerHash.isIllegal()) {
|
||||
nodep->v3fatalSrc("sameHash function undefined (returns 0) for node under CFunc.");
|
||||
}
|
||||
// For identical nodes, the type should be the same thus
|
||||
// dtypep should be the same too
|
||||
m_lowerHash = V3Hash(m_lowerHash, V3Hash(nodep->type()<<6,
|
||||
V3Hash(nodep->dtypep())));
|
||||
// Now update m_lowerHash for our children's (and next children) contributions
|
||||
iterateChildren(nodep);
|
||||
// Store the hash value
|
||||
nodep->user4(m_lowerHash.fullValue());
|
||||
//UINFO(9, " hashnode "<<m_lowerHash<<" "<<nodep<<endl);
|
||||
}
|
||||
// Store the hash value
|
||||
nodep->user4(m_lowerHash.fullValue());
|
||||
//UINFO(9, " hashnode "<<m_lowerHash<<" "<<nodep<<endl);
|
||||
}
|
||||
thisHash = m_lowerHash;
|
||||
m_lowerHash = oldHash;
|
||||
}
|
||||
// Update what will become the above node's hash
|
||||
m_lowerHash = oldHash;
|
||||
}
|
||||
// Update what will become the above node's hash
|
||||
m_lowerHash += m_cacheInUser4
|
||||
? V3Hashed::nodeHash(nodep) : thisHash;
|
||||
}
|
||||
|
|
@ -91,15 +93,15 @@ private:
|
|||
virtual void visit(AstTypedef*) {}
|
||||
virtual void visit(AstParamTypeDType*) {}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
nodeHashIterate(nodep);
|
||||
nodeHashIterate(nodep);
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
explicit HashedVisitor(AstNode* nodep) {
|
||||
m_cacheInUser4 = true;
|
||||
nodeHashIterate(nodep);
|
||||
//UINFO(9," stmthash "<<hex<<V3Hashed::nodeHash(nodep)<<" "<<nodep<<endl);
|
||||
nodeHashIterate(nodep);
|
||||
//UINFO(9," stmthash "<<hex<<V3Hashed::nodeHash(nodep)<<" "<<nodep<<endl);
|
||||
}
|
||||
explicit HashedVisitor(const AstNode* nodep) {
|
||||
m_cacheInUser4 = false;
|
||||
|
|
@ -125,7 +127,7 @@ V3Hashed::iterator V3Hashed::hashAndInsert(AstNode* nodep) {
|
|||
void V3Hashed::hash(AstNode* nodep) {
|
||||
UINFO(8," hashI "<<nodep<<endl);
|
||||
if (!nodep->user4p()) {
|
||||
HashedVisitor visitor (nodep);
|
||||
HashedVisitor visitor (nodep);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -133,7 +135,7 @@ bool V3Hashed::sameNodes(AstNode* node1p, AstNode* node2p) {
|
|||
if (!node1p->user4p()) node1p->v3fatalSrc("Called isIdentical on non-hashed nodes");
|
||||
if (!node2p->user4p()) node2p->v3fatalSrc("Called isIdentical on non-hashed nodes");
|
||||
return (node1p->user4p() == node2p->user4p() // Same hash
|
||||
&& node1p->sameTree(node2p));
|
||||
&& node1p->sameTree(node2p));
|
||||
}
|
||||
|
||||
void V3Hashed::erase(iterator it) {
|
||||
|
|
@ -141,12 +143,12 @@ void V3Hashed::erase(iterator it) {
|
|||
UINFO(8," erase "<<nodep<<endl);
|
||||
if (!nodep->user4p()) nodep->v3fatalSrc("Called removeNode on non-hashed node");
|
||||
m_hashMmap.erase(it);
|
||||
nodep->user4p(NULL); // So we don't allow removeNode again
|
||||
nodep->user4p(NULL); // So we don't allow removeNode again
|
||||
}
|
||||
|
||||
void V3Hashed::dumpFilePrefixed(const string& nameComment, bool tree) {
|
||||
if (v3Global.opt.dumpTree()) {
|
||||
dumpFile(v3Global.debugFilename(nameComment)+".hash", tree);
|
||||
dumpFile(v3Global.debugFilename(nameComment)+".hash", tree);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -159,19 +161,19 @@ void V3Hashed::dumpFile(const string& filename, bool tree) {
|
|||
V3Hash lasthash;
|
||||
int num_in_bucket = 0;
|
||||
for (HashMmap::iterator it=begin(); 1; ++it) {
|
||||
if (lasthash != it->first || it==end()) {
|
||||
if (it!=end()) lasthash = it->first;
|
||||
if (num_in_bucket) {
|
||||
if (dist.find(num_in_bucket)==dist.end()) {
|
||||
dist.insert(make_pair(num_in_bucket,1));
|
||||
} else {
|
||||
++dist[num_in_bucket];
|
||||
}
|
||||
}
|
||||
num_in_bucket = 0;
|
||||
}
|
||||
if (it==end()) break;
|
||||
num_in_bucket++;
|
||||
if (lasthash != it->first || it==end()) {
|
||||
if (it!=end()) lasthash = it->first;
|
||||
if (num_in_bucket) {
|
||||
if (dist.find(num_in_bucket)==dist.end()) {
|
||||
dist.insert(make_pair(num_in_bucket, 1));
|
||||
} else {
|
||||
++dist[num_in_bucket];
|
||||
}
|
||||
}
|
||||
num_in_bucket = 0;
|
||||
}
|
||||
if (it==end()) break;
|
||||
num_in_bucket++;
|
||||
}
|
||||
*logp <<"\n*** STATS:\n"<<endl;
|
||||
*logp<<" #InBucket Occurrences\n";
|
||||
|
|
@ -181,14 +183,14 @@ void V3Hashed::dumpFile(const string& filename, bool tree) {
|
|||
|
||||
*logp <<"\n*** Dump:\n"<<endl;
|
||||
for (HashMmap::iterator it=begin(); it!=end(); ++it) {
|
||||
if (lasthash != it->first) {
|
||||
lasthash = it->first;
|
||||
*logp <<" "<<it->first<<endl;
|
||||
}
|
||||
*logp <<"\t"<<it->second<<endl;
|
||||
// Dumping the entire tree may make nearly N^2 sized dumps,
|
||||
// because the nodes under this one may also be in the hash table!
|
||||
if (tree) it->second->dumpTree(*logp,"\t\t");
|
||||
if (lasthash != it->first) {
|
||||
lasthash = it->first;
|
||||
*logp <<" "<<it->first<<endl;
|
||||
}
|
||||
*logp <<"\t"<<it->second<<endl;
|
||||
// Dumping the entire tree may make nearly N^2 sized dumps,
|
||||
// because the nodes under this one may also be in the hash table!
|
||||
if (tree) it->second->dumpTree(*logp, "\t\t");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -197,10 +199,10 @@ V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) {
|
|||
if (!nodep->user4p()) nodep->v3fatalSrc("Called findDuplicate on non-hashed node");
|
||||
std::pair<HashMmap::iterator,HashMmap::iterator> eqrange = mmap().equal_range(nodeHash(nodep));
|
||||
for (HashMmap::iterator eqit = eqrange.first; eqit != eqrange.second; ++eqit) {
|
||||
AstNode* node2p = eqit->second;
|
||||
if (nodep != node2p && sameNodes(nodep, node2p)) {
|
||||
return eqit;
|
||||
}
|
||||
AstNode* node2p = eqit->second;
|
||||
if (nodep != node2p && sameNodes(nodep, node2p)) {
|
||||
return eqit;
|
||||
}
|
||||
}
|
||||
return end();
|
||||
}
|
||||
|
|
@ -208,12 +210,13 @@ V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) {
|
|||
V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep, V3HashedUserCheck* checkp) {
|
||||
UINFO(8," findD "<<nodep<<endl);
|
||||
if (!nodep->user4p()) nodep->v3fatalSrc("Called findDuplicate on non-hashed node");
|
||||
std::pair<HashMmap::iterator,HashMmap::iterator> eqrange = mmap().equal_range(nodeHash(nodep));
|
||||
std::pair<HashMmap::iterator,HashMmap::iterator> eqrange
|
||||
= mmap().equal_range(nodeHash(nodep));
|
||||
for (HashMmap::iterator eqit = eqrange.first; eqit != eqrange.second; ++eqit) {
|
||||
AstNode* node2p = eqit->second;
|
||||
if (nodep != node2p && checkp->check(nodep,node2p) && sameNodes(nodep, node2p)) {
|
||||
return eqit;
|
||||
}
|
||||
AstNode* node2p = eqit->second;
|
||||
if (nodep != node2p && checkp->check(nodep, node2p) && sameNodes(nodep, node2p)) {
|
||||
return eqit;
|
||||
}
|
||||
}
|
||||
return end();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,15 +42,15 @@ public:
|
|||
|
||||
struct V3HashedUserCheck {
|
||||
// Functor for V3Hashed::findDuplicate
|
||||
virtual bool check(AstNode*,AstNode*) =0;
|
||||
virtual bool check(AstNode*, AstNode*) = 0;
|
||||
V3HashedUserCheck() {}
|
||||
virtual ~V3HashedUserCheck() {}
|
||||
};
|
||||
|
||||
class V3Hashed : public VHashedBase {
|
||||
// NODE STATE
|
||||
// AstNode::user4() -> V3Hash. Hash value of this node (hash of 0 is illegal)
|
||||
AstUser4InUse m_inuser4;
|
||||
// AstNode::user4() -> V3Hash. Hash value of this node (hash of 0 is illegal)
|
||||
AstUser4InUse m_inuser4;
|
||||
|
||||
// TYPES
|
||||
typedef std::multimap<V3Hash,AstNode*> HashMmap;
|
||||
|
|
@ -58,7 +58,7 @@ public:
|
|||
typedef HashMmap::iterator iterator;
|
||||
private:
|
||||
// MEMBERS
|
||||
HashMmap m_hashMmap; // hashvalue -> nodes with that hash
|
||||
HashMmap m_hashMmap; // hashvalue -> nodes with that hash
|
||||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
|
|
@ -66,18 +66,18 @@ public:
|
|||
~V3Hashed() {}
|
||||
|
||||
// ACCESSORS
|
||||
HashMmap& mmap() { return m_hashMmap; } // Return map for iteration
|
||||
HashMmap& mmap() { return m_hashMmap; } // Return map for iteration
|
||||
iterator begin() { return m_hashMmap.begin(); }
|
||||
iterator end() { return m_hashMmap.end(); }
|
||||
|
||||
// METHODS
|
||||
void clear() { m_hashMmap.clear(); AstNode::user4ClearTree(); }
|
||||
iterator hashAndInsert(AstNode* nodep); // Hash the node, and insert into map. Return iterator to inserted
|
||||
void hash(AstNode* nodep); // Only hash the node
|
||||
bool sameNodes(AstNode* node1p, AstNode* node2p); // After hashing, and tell if identical
|
||||
void erase(iterator it); // Remove node from structures
|
||||
iterator findDuplicate(AstNode* nodep); // Return duplicate in hash, if any
|
||||
iterator findDuplicate(AstNode* nodep, V3HashedUserCheck* checkp); // Extra user checks for sameness
|
||||
iterator hashAndInsert(AstNode* nodep); // Hash the node, and insert into map. Return iterator to inserted
|
||||
void hash(AstNode* nodep); // Only hash the node
|
||||
bool sameNodes(AstNode* node1p, AstNode* node2p); // After hashing, and tell if identical
|
||||
void erase(iterator it); // Remove node from structures
|
||||
iterator findDuplicate(AstNode* nodep); // Return duplicate in hash, if any
|
||||
iterator findDuplicate(AstNode* nodep, V3HashedUserCheck* checkp); // Extra user checks for sameness
|
||||
AstNode* iteratorNodep(iterator it) { return it->second; }
|
||||
void dumpFile(const string& filename, bool tree);
|
||||
void dumpFilePrefixed(const string& nameComment, bool tree=false);
|
||||
|
|
@ -86,4 +86,4 @@ public:
|
|||
static V3Hash uncachedHash(const AstNode* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
483
src/V3Inline.cpp
483
src/V3Inline.cpp
|
|
@ -20,11 +20,11 @@
|
|||
// V3Inline's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// Look for CELL... PRAGMA INLINE_MODULE
|
||||
// Replicate the cell's module
|
||||
// Convert pins to wires that make assignments
|
||||
// Rename vars to include cell name
|
||||
// Insert cell's module statements into the upper module
|
||||
// Look for CELL... PRAGMA INLINE_MODULE
|
||||
// Replicate the cell's module
|
||||
// Convert pins to wires that make assignments
|
||||
// Rename vars to include cell name
|
||||
// Insert cell's module statements into the upper module
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -44,7 +44,7 @@
|
|||
#include VL_INCLUDE_UNORDERED_SET
|
||||
|
||||
// CONFIG
|
||||
static const int INLINE_MODS_SMALLER = 100; // If a mod is < this # nodes, can always inline it
|
||||
static const int INLINE_MODS_SMALLER = 100; // If a mod is < this # nodes, can always inline it
|
||||
|
||||
//######################################################################
|
||||
// Inline state, as a visitor of each AstNode
|
||||
|
|
@ -53,13 +53,13 @@ class InlineMarkVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Output
|
||||
// AstNodeModule::user1() // OUTPUT: bool. User request to inline this module
|
||||
// AstNodeModule::user1() // OUTPUT: bool. User request to inline this module
|
||||
// Internal state (can be cleared after this visit completes)
|
||||
// AstNodeModule::user2() // CIL_*. Allowed to automatically inline module
|
||||
// AstNodeModule::user3() // int. Number of cells referencing this module
|
||||
// AstNodeModule::user2() // CIL_*. Allowed to automatically inline module
|
||||
// AstNodeModule::user3() // int. Number of cells referencing this module
|
||||
// AstNodeModule::user4() // int. Statements in module
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
AstUser4InUse m_inuser4;
|
||||
|
||||
// For the user2 field:
|
||||
|
|
@ -70,10 +70,10 @@ private:
|
|||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Current module
|
||||
V3Double0 m_statUnsup; // Statistic tracking
|
||||
V3Double0 m_statUnsup; // Statistic tracking
|
||||
|
||||
typedef std::vector<AstNodeModule*> ModVec;
|
||||
ModVec m_allMods; // All modules, in top-down order.
|
||||
ModVec m_allMods; // All modules, in top-down order.
|
||||
|
||||
// Within the context of a given module, LocalInstanceMap maps
|
||||
// from child modules to the count of each child's local instantiations.
|
||||
|
|
@ -85,35 +85,35 @@ private:
|
|||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
void cantInline(const char* reason, bool hard) {
|
||||
if (hard) {
|
||||
if (m_modp->user2() != CIL_NOTHARD) {
|
||||
UINFO(4," No inline hard: "<<reason<<" "<<m_modp<<endl);
|
||||
m_modp->user2(CIL_NOTHARD);
|
||||
++m_statUnsup;
|
||||
}
|
||||
} else {
|
||||
if (m_modp->user2() == CIL_MAYBE) {
|
||||
UINFO(4," No inline soft: "<<reason<<" "<<m_modp<<endl);
|
||||
m_modp->user2(CIL_NOTSOFT);
|
||||
}
|
||||
}
|
||||
if (hard) {
|
||||
if (m_modp->user2() != CIL_NOTHARD) {
|
||||
UINFO(4," No inline hard: "<<reason<<" "<<m_modp<<endl);
|
||||
m_modp->user2(CIL_NOTHARD);
|
||||
++m_statUnsup;
|
||||
}
|
||||
} else {
|
||||
if (m_modp->user2() == CIL_MAYBE) {
|
||||
UINFO(4," No inline soft: "<<reason<<" "<<m_modp<<endl);
|
||||
m_modp->user2(CIL_NOTSOFT);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
m_modp = nodep;
|
||||
m_allMods.push_back(nodep);
|
||||
m_modp->user2(CIL_MAYBE);
|
||||
m_modp->user4(0); // statement count
|
||||
m_modp->user2(CIL_MAYBE);
|
||||
m_modp->user4(0); // statement count
|
||||
if (VN_IS(m_modp, Iface)) {
|
||||
// Inlining an interface means we no longer have a cell handle to resolve to.
|
||||
// If inlining moves post-scope this can perhaps be relaxed.
|
||||
cantInline("modIface",true);
|
||||
}
|
||||
if (m_modp->modPublic()) cantInline("modPublic",false);
|
||||
// Inlining an interface means we no longer have a cell handle to resolve to.
|
||||
// If inlining moves post-scope this can perhaps be relaxed.
|
||||
cantInline("modIface", true);
|
||||
}
|
||||
if (m_modp->modPublic()) cantInline("modPublic", false);
|
||||
|
||||
iterateChildren(nodep);
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
}
|
||||
virtual void visit(AstCell* nodep) {
|
||||
nodep->modp()->user3Inc(); // Inc refs
|
||||
|
|
@ -121,42 +121,42 @@ private:
|
|||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstPragma* nodep) {
|
||||
if (nodep->pragType() == AstPragmaType::INLINE_MODULE) {
|
||||
//UINFO(0,"PRAG MARK "<<m_modp<<endl);
|
||||
if (!m_modp) {
|
||||
nodep->v3error("Inline pragma not under a module");
|
||||
if (nodep->pragType() == AstPragmaType::INLINE_MODULE) {
|
||||
//UINFO(0,"PRAG MARK "<<m_modp<<endl);
|
||||
if (!m_modp) {
|
||||
nodep->v3error("Inline pragma not under a module");
|
||||
} else if (m_modp->user2() == CIL_MAYBE
|
||||
|| m_modp->user2() == CIL_NOTSOFT) {
|
||||
m_modp->user2(CIL_USER);
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep); // Remove so don't propagate to upper cell...
|
||||
} else if (nodep->pragType() == AstPragmaType::NO_INLINE_MODULE) {
|
||||
if (!m_modp) {
|
||||
nodep->v3error("Inline pragma not under a module");
|
||||
} else {
|
||||
cantInline("Pragma NO_INLINE_MODULE",false);
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep); // Remove so don't propagate to upper cell...
|
||||
} else {
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep); // Remove so don't propagate to upper cell...
|
||||
} else if (nodep->pragType() == AstPragmaType::NO_INLINE_MODULE) {
|
||||
if (!m_modp) {
|
||||
nodep->v3error("Inline pragma not under a module");
|
||||
} else {
|
||||
cantInline("Pragma NO_INLINE_MODULE", false);
|
||||
}
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep); // Remove so don't propagate to upper cell...
|
||||
} else {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstVarXRef* nodep) {
|
||||
// Cleanup link until V3LinkDot can correct it
|
||||
nodep->varp(NULL);
|
||||
// Cleanup link until V3LinkDot can correct it
|
||||
nodep->varp(NULL);
|
||||
}
|
||||
virtual void visit(AstNodeFTaskRef* nodep) {
|
||||
// Cleanup link until V3LinkDot can correct it
|
||||
if (!nodep->packagep()) nodep->taskp(NULL);
|
||||
// Cleanup link until V3LinkDot can correct it
|
||||
if (!nodep->packagep()) nodep->taskp(NULL);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstAlways* nodep) {
|
||||
iterateChildren(nodep);
|
||||
m_modp->user4Inc(); // statement count
|
||||
m_modp->user4Inc(); // statement count
|
||||
}
|
||||
virtual void visit(AstNodeAssign* nodep) {
|
||||
// Don't count assignments, as they'll likely flatten out
|
||||
// Still need to iterate though to nullify VarXRefs
|
||||
// Don't count assignments, as they'll likely flatten out
|
||||
// Still need to iterate though to nullify VarXRefs
|
||||
int oldcnt = m_modp->user4();
|
||||
iterateChildren(nodep);
|
||||
m_modp->user4(oldcnt);
|
||||
|
|
@ -208,20 +208,20 @@ private:
|
|||
iterateChildren(nodep);
|
||||
if (m_modp) {
|
||||
m_modp->user4Inc(); // Inc statement count
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
explicit InlineMarkVisitor(AstNode* nodep) {
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~InlineMarkVisitor() {
|
||||
V3Stats::addStat("Optimizations, Inline unsupported", m_statUnsup);
|
||||
// Done with these, are not outputs
|
||||
AstNode::user2ClearTree();
|
||||
AstNode::user3ClearTree();
|
||||
V3Stats::addStat("Optimizations, Inline unsupported", m_statUnsup);
|
||||
// Done with these, are not outputs
|
||||
AstNode::user2ClearTree();
|
||||
AstNode::user3ClearTree();
|
||||
AstNode::user4ClearTree();
|
||||
}
|
||||
};
|
||||
|
|
@ -234,14 +234,14 @@ class InlineCollectVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Output:
|
||||
// AstCell::user4p() // AstCell* of the created clone
|
||||
// AstCell::user4p() // AstCell* of the created clone
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstCell* nodep) {
|
||||
nodep->user4p(nodep->clonep());
|
||||
nodep->user4p(nodep->clonep());
|
||||
}
|
||||
// Accelerate
|
||||
virtual void visit(AstNodeStmt* nodep) {}
|
||||
|
|
@ -271,52 +271,52 @@ private:
|
|||
|
||||
// STATE
|
||||
StringSet m_renamedInterfaces; // Name of renamed interface variables
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCell* m_cellp; // Cell being cloned
|
||||
AstNodeModule* m_modp; // Current module
|
||||
AstCell* m_cellp; // Cell being cloned
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstCellInline* nodep) {
|
||||
// Inlined cell under the inline cell, need to move to avoid conflicts
|
||||
nodep->unlinkFrBack();
|
||||
m_modp->addInlinesp(nodep);
|
||||
// Rename
|
||||
string name = m_cellp->name() + "__DOT__" + nodep->name();
|
||||
nodep->name(name);
|
||||
UINFO(6, " Inline "<<nodep<<endl);
|
||||
// Do CellInlines under this, but don't move them
|
||||
// Inlined cell under the inline cell, need to move to avoid conflicts
|
||||
nodep->unlinkFrBack();
|
||||
m_modp->addInlinesp(nodep);
|
||||
// Rename
|
||||
string name = m_cellp->name() + "__DOT__" + nodep->name();
|
||||
nodep->name(name);
|
||||
UINFO(6, " Inline "<<nodep<<endl);
|
||||
// Do CellInlines under this, but don't move them
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCell* nodep) {
|
||||
// Cell under the inline cell, need to rename to avoid conflicts
|
||||
string name = m_cellp->name() + "__DOT__" + nodep->name();
|
||||
nodep->name(name);
|
||||
// Cell under the inline cell, need to rename to avoid conflicts
|
||||
string name = m_cellp->name() + "__DOT__" + nodep->name();
|
||||
nodep->name(name);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstModule* nodep) {
|
||||
m_renamedInterfaces.clear();
|
||||
m_renamedInterfaces.clear();
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstVar* nodep) {
|
||||
if (nodep->user2p()) {
|
||||
// Make an assignment, so we'll trace it properly
|
||||
// user2p is either a const or a var.
|
||||
if (nodep->user2p()) {
|
||||
// Make an assignment, so we'll trace it properly
|
||||
// user2p is either a const or a var.
|
||||
AstConst* exprconstp = VN_CAST(nodep->user2p(), Const);
|
||||
AstVarRef* exprvarrefp = VN_CAST(nodep->user2p(), VarRef);
|
||||
UINFO(8,"connectto: "<<nodep->user2p()<<endl);
|
||||
if (!exprconstp && !exprvarrefp) {
|
||||
nodep->v3fatalSrc("Unknown interconnect type; pinReconnectSimple should have cleared up");
|
||||
}
|
||||
if (exprconstp) {
|
||||
m_modp->addStmtp(new AstAssignW(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), nodep, true),
|
||||
exprconstp->cloneTree(true)));
|
||||
} else if (nodep->user3()) {
|
||||
// Public variable at the lower module end - we need to make sure we propagate
|
||||
// the logic changes up and down; if we aliased, we might remove the change detection
|
||||
// on the output variable.
|
||||
UINFO(8,"connectto: "<<nodep->user2p()<<endl);
|
||||
if (!exprconstp && !exprvarrefp) {
|
||||
nodep->v3fatalSrc("Unknown interconnect type; pinReconnectSimple should have cleared up");
|
||||
}
|
||||
if (exprconstp) {
|
||||
m_modp->addStmtp(new AstAssignW(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), nodep, true),
|
||||
exprconstp->cloneTree(true)));
|
||||
} else if (nodep->user3()) {
|
||||
// Public variable at the lower module end - we need to make sure we propagate
|
||||
// the logic changes up and down; if we aliased, we might
|
||||
// remove the change detection on the output variable.
|
||||
UINFO(9,"public pin assign: "<<exprvarrefp<<endl);
|
||||
if (nodep->isNonOutput()) nodep->v3fatalSrc("Outputs only - inputs use AssignAlias");
|
||||
m_modp->addStmtp(
|
||||
|
|
@ -327,82 +327,87 @@ private:
|
|||
m_modp->addStmtp(
|
||||
new AstAssignVarScope(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), nodep, true),
|
||||
new AstVarRef(nodep->fileline(), exprvarrefp->varp(), false)));
|
||||
AstNode* nodebp=exprvarrefp->varp();
|
||||
new AstVarRef(nodep->fileline(),
|
||||
exprvarrefp->varp(), false)));
|
||||
AstNode* nodebp = exprvarrefp->varp();
|
||||
nodep ->fileline()->modifyStateInherit(nodebp->fileline());
|
||||
nodebp->fileline()->modifyStateInherit(nodep ->fileline());
|
||||
} else {
|
||||
// Do to inlining child's variable now within the same module, so a AstVarRef not AstVarXRef below
|
||||
// Do to inlining child's variable now within the same
|
||||
// module, so a AstVarRef not AstVarXRef below
|
||||
m_modp->addStmtp(
|
||||
new AstAssignAlias(nodep->fileline(),
|
||||
new AstVarRef(nodep->fileline(), nodep, true),
|
||||
new AstVarRef(nodep->fileline(), exprvarrefp->varp(), false)));
|
||||
AstNode* nodebp=exprvarrefp->varp();
|
||||
nodep ->fileline()->modifyStateInherit(nodebp->fileline());
|
||||
nodebp->fileline()->modifyStateInherit(nodep ->fileline());
|
||||
}
|
||||
}
|
||||
// Iterate won't hit AstIfaceRefDType directly as it is no longer underneath the module
|
||||
new AstVarRef(nodep->fileline(),
|
||||
exprvarrefp->varp(), false)));
|
||||
AstNode* nodebp = exprvarrefp->varp();
|
||||
nodep ->fileline()->modifyStateInherit(nodebp->fileline());
|
||||
nodebp->fileline()->modifyStateInherit(nodep ->fileline());
|
||||
}
|
||||
}
|
||||
// Iterate won't hit AstIfaceRefDType directly as it is no longer underneath the module
|
||||
if (AstIfaceRefDType* ifacerefp = VN_CAST(nodep->dtypep(), IfaceRefDType)) {
|
||||
m_renamedInterfaces.insert(nodep->name());
|
||||
// Each inlined cell that contain an interface variable need to copy the IfaceRefDType and point it to
|
||||
// the newly cloned interface cell.
|
||||
m_renamedInterfaces.insert(nodep->name());
|
||||
// Each inlined cell that contain an interface variable need to
|
||||
// copy the IfaceRefDType and point it to the newly cloned
|
||||
// interface cell.
|
||||
AstIfaceRefDType* newdp = VN_CAST(ifacerefp->cloneTree(false), IfaceRefDType);
|
||||
nodep->dtypep(newdp);
|
||||
ifacerefp->addNextHere(newdp);
|
||||
// Relink to point to newly cloned cell
|
||||
if (newdp->cellp()) {
|
||||
nodep->dtypep(newdp);
|
||||
ifacerefp->addNextHere(newdp);
|
||||
// Relink to point to newly cloned cell
|
||||
if (newdp->cellp()) {
|
||||
if (AstCell* newcellp = VN_CAST(newdp->cellp()->user4p(), Cell)) {
|
||||
newdp->cellp(newcellp);
|
||||
newdp->cellName(newcellp->name());
|
||||
// Tag the old ifacerefp to ensure it leaves no stale reference to the inlined cell.
|
||||
newdp->user5(false);
|
||||
ifacerefp->user5(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Variable under the inline cell, need to rename to avoid conflicts
|
||||
// Also clear I/O bits, as it is now local.
|
||||
string name = m_cellp->name() + "__DOT__" + nodep->name();
|
||||
if (!nodep->isFuncLocal()) nodep->inlineAttrReset(name);
|
||||
if (!m_cellp->isTrace()) nodep->trace(false);
|
||||
if (debug()>=9) { nodep->dumpTree(cout,"varchanged:"); }
|
||||
if (debug()>=9 && nodep->valuep()) { nodep->valuep()->dumpTree(cout,"varchangei:"); }
|
||||
newdp->cellp(newcellp);
|
||||
newdp->cellName(newcellp->name());
|
||||
// Tag the old ifacerefp to ensure it leaves no stale
|
||||
// reference to the inlined cell.
|
||||
newdp->user5(false);
|
||||
ifacerefp->user5(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Variable under the inline cell, need to rename to avoid conflicts
|
||||
// Also clear I/O bits, as it is now local.
|
||||
string name = m_cellp->name() + "__DOT__" + nodep->name();
|
||||
if (!nodep->isFuncLocal()) nodep->inlineAttrReset(name);
|
||||
if (!m_cellp->isTrace()) nodep->trace(false);
|
||||
if (debug()>=9) { nodep->dumpTree(cout, "varchanged:"); }
|
||||
if (debug()>=9 && nodep->valuep()) { nodep->valuep()->dumpTree(cout, "varchangei:"); }
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstNodeFTask* nodep) {
|
||||
// Function under the inline cell, need to rename to avoid conflicts
|
||||
nodep->name(m_cellp->name() + "__DOT__" + nodep->name());
|
||||
// Function under the inline cell, need to rename to avoid conflicts
|
||||
nodep->name(m_cellp->name() + "__DOT__" + nodep->name());
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstTypedef* nodep) {
|
||||
// Typedef under the inline cell, need to rename to avoid conflicts
|
||||
nodep->name(m_cellp->name() + "__DOT__" + nodep->name());
|
||||
// Typedef under the inline cell, need to rename to avoid conflicts
|
||||
nodep->name(m_cellp->name() + "__DOT__" + nodep->name());
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
if (nodep->varp()->user2p() // It's being converted to an alias.
|
||||
&& !nodep->varp()->user3()
|
||||
if (nodep->varp()->user2p() // It's being converted to an alias.
|
||||
&& !nodep->varp()->user3()
|
||||
&& !VN_IS(nodep->backp(), AssignAlias)) { // Don't constant propagate aliases (we just made)
|
||||
AstConst* exprconstp = VN_CAST(nodep->varp()->user2p(), Const);
|
||||
AstVarRef* exprvarrefp = VN_CAST(nodep->varp()->user2p(), VarRef);
|
||||
if (exprconstp) {
|
||||
nodep->replaceWith(exprconstp->cloneTree(true));
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
else if (exprvarrefp) {
|
||||
nodep->varp( exprvarrefp->varp() );
|
||||
}
|
||||
else {
|
||||
nodep->v3fatalSrc("Null connection?");
|
||||
}
|
||||
}
|
||||
nodep->name(nodep->varp()->name());
|
||||
if (exprconstp) {
|
||||
nodep->replaceWith(exprconstp->cloneTree(true));
|
||||
nodep->deleteTree(); VL_DANGLING(nodep);
|
||||
return;
|
||||
}
|
||||
else if (exprvarrefp) {
|
||||
nodep->varp( exprvarrefp->varp() );
|
||||
}
|
||||
else {
|
||||
nodep->v3fatalSrc("Null connection?");
|
||||
}
|
||||
}
|
||||
nodep->name(nodep->varp()->name());
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstVarXRef* nodep) {
|
||||
// Track what scope it was originally under so V3LinkDot can resolve it
|
||||
// Track what scope it was originally under so V3LinkDot can resolve it
|
||||
string newdots = VString::dot(m_cellp->name(), ".", nodep->inlinedDots());
|
||||
nodep->inlinedDots(newdots);
|
||||
for (string tryname = nodep->dotted(); 1;) {
|
||||
|
|
@ -421,13 +426,13 @@ private:
|
|||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstNodeFTaskRef* nodep) {
|
||||
// Track what scope it was originally under so V3LinkDot can resolve it
|
||||
// Track what scope it was originally under so V3LinkDot can resolve it
|
||||
string newdots = VString::dot(m_cellp->name(), ".", nodep->inlinedDots());
|
||||
nodep->inlinedDots(newdots);
|
||||
if (m_renamedInterfaces.count(nodep->dotted())) {
|
||||
nodep->dotted(m_cellp->name() + "__DOT__" + nodep->dotted());
|
||||
}
|
||||
UINFO(8," "<<nodep<<endl);
|
||||
if (m_renamedInterfaces.count(nodep->dotted())) {
|
||||
nodep->dotted(m_cellp->name() + "__DOT__" + nodep->dotted());
|
||||
}
|
||||
UINFO(8," "<<nodep<<endl);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
|
|
@ -435,21 +440,21 @@ private:
|
|||
//virtual void visit(AstRefDType* nodep) {}
|
||||
|
||||
virtual void visit(AstScopeName* nodep) {
|
||||
// If there's a %m in the display text, we add a special node that will contain the name()
|
||||
// Similar code in V3Begin
|
||||
// To keep correct visual order, must add before other Text's
|
||||
AstNode* afterp = nodep->scopeAttrp();
|
||||
if (afterp) afterp->unlinkFrBackWithNext();
|
||||
// If there's a %m in the display text, we add a special node that will contain the name()
|
||||
// Similar code in V3Begin
|
||||
// To keep correct visual order, must add before other Text's
|
||||
AstNode* afterp = nodep->scopeAttrp();
|
||||
if (afterp) afterp->unlinkFrBackWithNext();
|
||||
nodep->scopeAttrp(new AstText(nodep->fileline(), string("__DOT__")+m_cellp->name()));
|
||||
if (afterp) nodep->scopeAttrp(afterp);
|
||||
afterp = nodep->scopeEntrp();
|
||||
if (afterp) afterp->unlinkFrBackWithNext();
|
||||
if (afterp) nodep->scopeAttrp(afterp);
|
||||
afterp = nodep->scopeEntrp();
|
||||
if (afterp) afterp->unlinkFrBackWithNext();
|
||||
nodep->scopeEntrp(new AstText(nodep->fileline(), string("__DOT__")+m_cellp->name()));
|
||||
if (afterp) nodep->scopeEntrp(afterp);
|
||||
if (afterp) nodep->scopeEntrp(afterp);
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCoverDecl* nodep) {
|
||||
// Fix path in coverage statements
|
||||
// Fix path in coverage statements
|
||||
nodep->hier(VString::dot(m_cellp->prettyName(), ".", nodep->hier()));
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
|
@ -460,8 +465,8 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
InlineRelinkVisitor(AstNodeModule* cloneModp, AstNodeModule* oldModp, AstCell* cellp) {
|
||||
m_modp = oldModp;
|
||||
m_cellp = cellp;
|
||||
m_modp = oldModp;
|
||||
m_cellp = cellp;
|
||||
iterate(cloneModp);
|
||||
}
|
||||
virtual ~InlineRelinkVisitor() {}
|
||||
|
|
@ -474,81 +479,83 @@ class InlineVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared entire netlist
|
||||
// AstIfaceRefDType::user5p() // Whether the cell pointed to by this AstIfaceRefDType has been inlined
|
||||
// AstIfaceRefDType::user5p() // Whether the cell pointed to by this
|
||||
// // AstIfaceRefDType has been inlined
|
||||
// Input:
|
||||
// AstNodeModule::user1p() // bool. True to inline this module (from InlineMarkVisitor)
|
||||
// AstNodeModule::user1p() // bool. True to inline this module (from InlineMarkVisitor)
|
||||
// Cleared each cell
|
||||
// AstVar::user2p() // AstVarRef*/AstConst* Points to signal this is a direct connect to
|
||||
// AstVar::user3() // bool Don't alias the user2, keep it as signal
|
||||
// AstCell::user4 // AstCell* of the created clone
|
||||
// AstVar::user2p() // AstVarRef*/AstConst* Points to signal this
|
||||
// // is a direct connect to
|
||||
// AstVar::user3() // bool Don't alias the user2, keep it as signal
|
||||
// AstCell::user4 // AstCell* of the created clone
|
||||
|
||||
AstUser2InUse m_inuser2;
|
||||
AstUser3InUse m_inuser3;
|
||||
AstUser4InUse m_inuser4;
|
||||
AstUser5InUse m_inuser5;
|
||||
AstUser5InUse m_inuser5;
|
||||
|
||||
// STATE
|
||||
AstNodeModule* m_modp; // Current module
|
||||
V3Double0 m_statCells; // Statistic tracking
|
||||
V3Double0 m_statCells; // Statistic tracking
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstNetlist* nodep) {
|
||||
// Iterate modules backwards, in bottom-up order. Required!
|
||||
// Iterate modules backwards, in bottom-up order. Required!
|
||||
iterateChildrenBackwards(nodep);
|
||||
}
|
||||
virtual void visit(AstIfaceRefDType* nodep) {
|
||||
if (nodep->user5()) {
|
||||
// The cell has been removed so let's make sure we don't leave a reference to it
|
||||
// This dtype may still be in use by the AstAssignVarScope created earlier
|
||||
// but that'll get cleared up later
|
||||
nodep->cellp(NULL);
|
||||
}
|
||||
if (nodep->user5()) {
|
||||
// The cell has been removed so let's make sure we don't leave a reference to it
|
||||
// This dtype may still be in use by the AstAssignVarScope created earlier
|
||||
// but that'll get cleared up later
|
||||
nodep->cellp(NULL);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
m_modp = nodep;
|
||||
m_modp = nodep;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCell* nodep) {
|
||||
if (nodep->modp()->user1()) { // Marked with inline request
|
||||
UINFO(5," Inline CELL "<<nodep<<endl);
|
||||
UINFO(5," To MOD "<<m_modp<<endl);
|
||||
++m_statCells;
|
||||
if (nodep->modp()->user1()) { // Marked with inline request
|
||||
UINFO(5," Inline CELL "<<nodep<<endl);
|
||||
UINFO(5," To MOD "<<m_modp<<endl);
|
||||
++m_statCells;
|
||||
|
||||
// Before cloning simplify pin assignments
|
||||
// Better off before, as if module has multiple instantiations
|
||||
// we'll save work, and we can't call pinReconnectSimple in
|
||||
// this loop as it clone()s itself.
|
||||
// Before cloning simplify pin assignments
|
||||
// Better off before, as if module has multiple instantiations
|
||||
// we'll save work, and we can't call pinReconnectSimple in
|
||||
// this loop as it clone()s itself.
|
||||
for (AstPin* pinp = nodep->pinsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
||||
if (!pinp->exprp()) continue;
|
||||
if (!pinp->exprp()) continue;
|
||||
V3Inst::pinReconnectSimple(pinp, nodep, false);
|
||||
}
|
||||
}
|
||||
|
||||
// Clone original module
|
||||
if (debug()>=9) { nodep->dumpTree(cout,"inlcell:"); }
|
||||
//if (debug()>=9) { nodep->modp()->dumpTree(cout,"oldmod:"); }
|
||||
AstNodeModule* newmodp = nodep->modp()->cloneTree(false);
|
||||
if (debug()>=9) { newmodp->dumpTree(cout,"newmod:"); }
|
||||
// Clear var markings and find cell cross references
|
||||
AstNode::user2ClearTree();
|
||||
AstNode::user4ClearTree();
|
||||
{ InlineCollectVisitor(nodep->modp()); } // {} to destroy visitor immediately
|
||||
// Create data for dotted variable resolution
|
||||
AstCellInline* inlinep = new AstCellInline(nodep->fileline(),
|
||||
nodep->name(), nodep->modp()->origName());
|
||||
m_modp->addInlinesp(inlinep); // Must be parsed before any AstCells
|
||||
// Create assignments to the pins
|
||||
// Clone original module
|
||||
if (debug()>=9) { nodep->dumpTree(cout, "inlcell:"); }
|
||||
//if (debug()>=9) { nodep->modp()->dumpTree(cout,"oldmod:"); }
|
||||
AstNodeModule* newmodp = nodep->modp()->cloneTree(false);
|
||||
if (debug()>=9) { newmodp->dumpTree(cout, "newmod:"); }
|
||||
// Clear var markings and find cell cross references
|
||||
AstNode::user2ClearTree();
|
||||
AstNode::user4ClearTree();
|
||||
{ InlineCollectVisitor(nodep->modp()); } // {} to destroy visitor immediately
|
||||
// Create data for dotted variable resolution
|
||||
AstCellInline* inlinep = new AstCellInline(nodep->fileline(),
|
||||
nodep->name(), nodep->modp()->origName());
|
||||
m_modp->addInlinesp(inlinep); // Must be parsed before any AstCells
|
||||
// Create assignments to the pins
|
||||
for (AstPin* pinp = nodep->pinsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
||||
if (!pinp->exprp()) continue;
|
||||
UINFO(6," Pin change from "<<pinp->modVarp()<<endl);
|
||||
// Make new signal; even though we'll optimize the interconnect, we
|
||||
// need an alias to trace correctly. If tracing is disabled, we'll
|
||||
// delete it in later optimizations.
|
||||
AstVar* pinOldVarp = pinp->modVarp();
|
||||
AstVar* pinNewVarp = pinOldVarp->clonep();
|
||||
if (!pinNewVarp) pinOldVarp->v3fatalSrc("Cloning failed");
|
||||
if (!pinp->exprp()) continue;
|
||||
UINFO(6," Pin change from "<<pinp->modVarp()<<endl);
|
||||
// Make new signal; even though we'll optimize the interconnect, we
|
||||
// need an alias to trace correctly. If tracing is disabled, we'll
|
||||
// delete it in later optimizations.
|
||||
AstVar* pinOldVarp = pinp->modVarp();
|
||||
AstVar* pinNewVarp = pinOldVarp->clonep();
|
||||
if (!pinNewVarp) pinOldVarp->v3fatalSrc("Cloning failed");
|
||||
|
||||
AstNode* connectRefp = pinp->exprp();
|
||||
if (!VN_IS(connectRefp, Const) && !VN_IS(connectRefp, VarRef)) {
|
||||
|
|
@ -556,18 +563,18 @@ private:
|
|||
}
|
||||
V3Inst::checkOutputShort(pinp);
|
||||
|
||||
// Propagate any attributes across the interconnect
|
||||
pinNewVarp->propagateAttrFrom(pinOldVarp);
|
||||
// Propagate any attributes across the interconnect
|
||||
pinNewVarp->propagateAttrFrom(pinOldVarp);
|
||||
if (VN_IS(connectRefp, VarRef)) {
|
||||
VN_CAST(connectRefp, VarRef)->varp()->propagateAttrFrom(pinOldVarp);
|
||||
}
|
||||
}
|
||||
|
||||
// One to one interconnect won't make a temporary variable.
|
||||
// This prevents creating a lot of extra wires for clock signals.
|
||||
// It will become a tracing alias.
|
||||
UINFO(6,"One-to-one "<<connectRefp<<endl);
|
||||
UINFO(6," -to "<<pinNewVarp<<endl);
|
||||
pinNewVarp->user2p(connectRefp);
|
||||
// One to one interconnect won't make a temporary variable.
|
||||
// This prevents creating a lot of extra wires for clock signals.
|
||||
// It will become a tracing alias.
|
||||
UINFO(6,"One-to-one "<<connectRefp<<endl);
|
||||
UINFO(6," -to "<<pinNewVarp<<endl);
|
||||
pinNewVarp->user2p(connectRefp);
|
||||
// Public output inside the cell must go via an assign rather
|
||||
// than alias. Else the public logic will set the alias, losing
|
||||
// the value to be propagated up (InOnly isn't a problem as the
|
||||
|
|
@ -575,19 +582,19 @@ private:
|
|||
pinNewVarp->user3(pinNewVarp->isSigUserRWPublic()
|
||||
&& pinNewVarp->direction()==VDirection::OUTPUT);
|
||||
}
|
||||
// Cleanup var names, etc, to not conflict
|
||||
{ InlineRelinkVisitor(newmodp, m_modp, nodep); }
|
||||
// Move statements to top module
|
||||
if (debug()>=9) { newmodp->dumpTree(cout,"fixmod:"); }
|
||||
AstNode* stmtsp = newmodp->stmtsp();
|
||||
if (stmtsp) stmtsp->unlinkFrBackWithNext();
|
||||
if (stmtsp) m_modp->addStmtp(stmtsp);
|
||||
// Remove the cell
|
||||
newmodp->deleteTree(); VL_DANGLING(newmodp); // Clear any leftover ports, etc
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
if (debug()>=9) { m_modp->dumpTree(cout,"donemod:"); }
|
||||
}
|
||||
// Cleanup var names, etc, to not conflict
|
||||
{ InlineRelinkVisitor(newmodp, m_modp, nodep); }
|
||||
// Move statements to top module
|
||||
if (debug()>=9) { newmodp->dumpTree(cout, "fixmod:"); }
|
||||
AstNode* stmtsp = newmodp->stmtsp();
|
||||
if (stmtsp) stmtsp->unlinkFrBackWithNext();
|
||||
if (stmtsp) m_modp->addStmtp(stmtsp);
|
||||
// Remove the cell
|
||||
newmodp->deleteTree(); VL_DANGLING(newmodp); // Clear any leftover ports, etc
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
if (debug()>=9) { m_modp->dumpTree(cout, "donemod:"); }
|
||||
}
|
||||
}
|
||||
|
||||
//--------------------
|
||||
|
|
@ -600,11 +607,11 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit InlineVisitor(AstNode* nodep) {
|
||||
m_modp = NULL;
|
||||
m_modp = NULL;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~InlineVisitor() {
|
||||
V3Stats::addStat("Optimizations, Inlined cells", m_statCells);
|
||||
V3Stats::addStat("Optimizations, Inlined cells", m_statCells);
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -613,8 +620,8 @@ public:
|
|||
|
||||
void V3Inline::inlineAll(AstNetlist* nodep) {
|
||||
UINFO(2,__FUNCTION__<<": "<<endl);
|
||||
AstUser1InUse m_inuser1; // output of InlineMarkVisitor,
|
||||
// input to InlineVisitor.
|
||||
AstUser1InUse m_inuser1; // output of InlineMarkVisitor,
|
||||
// input to InlineVisitor.
|
||||
{
|
||||
// Scoped to clean up temp userN's
|
||||
InlineMarkVisitor mvisitor (nodep);
|
||||
|
|
@ -628,9 +635,9 @@ void V3Inline::inlineAll(AstNetlist* nodep) {
|
|||
AstNodeModule* nextmodp;
|
||||
for (AstNodeModule* modp = v3Global.rootp()->modulesp(); modp; modp=nextmodp) {
|
||||
nextmodp = VN_CAST(modp->nextp(), NodeModule);
|
||||
if (modp->user1()) { // Was inlined
|
||||
modp->unlinkFrBack()->deleteTree(); VL_DANGLING(modp);
|
||||
}
|
||||
if (modp->user1()) { // Was inlined
|
||||
modp->unlinkFrBack()->deleteTree(); VL_DANGLING(modp);
|
||||
}
|
||||
}
|
||||
V3Global::dumpCheckGlobalTree("inline", 0, v3Global.opt.dumpTreeLevel(__FILE__) >= 3);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void inlineAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
573
src/V3Inst.cpp
573
src/V3Inst.cpp
|
|
@ -20,8 +20,8 @@
|
|||
// V3Inst's Transformations:
|
||||
//
|
||||
// Each module:
|
||||
// Pins:
|
||||
// Create a wire assign to interconnect to submodule
|
||||
// Pins:
|
||||
// Create a wire assign to interconnect to submodule
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -44,8 +44,8 @@ class InstVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Cleared each Cell:
|
||||
// AstPin::user1p() -> bool. True if created assignment already
|
||||
AstUser1InUse m_inuser1;
|
||||
// AstPin::user1p() -> bool. True if created assignment already
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
AstCell* m_cellp; // Current cell
|
||||
|
|
@ -55,19 +55,19 @@ private:
|
|||
|
||||
// VISITORS
|
||||
virtual void visit(AstCell* nodep) {
|
||||
UINFO(4," CELL "<<nodep<<endl);
|
||||
m_cellp = nodep;
|
||||
//VV***** We reset user1p() on each cell!!!
|
||||
AstNode::user1ClearTree();
|
||||
UINFO(4," CELL "<<nodep<<endl);
|
||||
m_cellp = nodep;
|
||||
//VV***** We reset user1p() on each cell!!!
|
||||
AstNode::user1ClearTree();
|
||||
iterateChildren(nodep);
|
||||
m_cellp = NULL;
|
||||
m_cellp = NULL;
|
||||
}
|
||||
virtual void visit(AstPin* nodep) {
|
||||
// PIN(p,expr) -> ASSIGNW(VARXREF(p),expr) (if sub's input)
|
||||
// or ASSIGNW(expr,VARXREF(p)) (if sub's output)
|
||||
UINFO(4," PIN "<<nodep<<endl);
|
||||
if (!nodep->exprp()) return; // No-connect
|
||||
if (debug()>=9) nodep->dumpTree(cout," Pin_oldb: ");
|
||||
if (debug()>=9) nodep->dumpTree(cout, " Pin_oldb: ");
|
||||
V3Inst::checkOutputShort(nodep);
|
||||
// Use user1p on the PIN to indicate we created an assign for this pin
|
||||
if (!nodep->user1SetOnce()) {
|
||||
|
|
@ -81,42 +81,46 @@ private:
|
|||
if (nodep->modVarp()->isInoutish()) {
|
||||
nodep->v3fatalSrc("Unsupported: Verilator is a 2-state simulator");
|
||||
} else if (nodep->modVarp()->isWritable()) {
|
||||
AstNode* rhsp = new AstVarXRef(exprp->fileline(), nodep->modVarp(), m_cellp->name(), false);
|
||||
AstNode* rhsp = new AstVarXRef(exprp->fileline(),
|
||||
nodep->modVarp(), m_cellp->name(), false);
|
||||
AstAssignW* assp = new AstAssignW(exprp->fileline(), exprp, rhsp);
|
||||
m_cellp->addNextHere(assp);
|
||||
} else if (nodep->modVarp()->isNonOutput()) {
|
||||
// Don't bother moving constants now,
|
||||
// we'll be pushing the const down to the cell soon enough.
|
||||
AstNode* assp = new AstAssignW
|
||||
(exprp->fileline(),
|
||||
new AstVarXRef(exprp->fileline(), nodep->modVarp(), m_cellp->name(), true),
|
||||
exprp);
|
||||
// Don't bother moving constants now,
|
||||
// we'll be pushing the const down to the cell soon enough.
|
||||
AstNode* assp = new AstAssignW
|
||||
(exprp->fileline(),
|
||||
new AstVarXRef(exprp->fileline(), nodep->modVarp(), m_cellp->name(), true),
|
||||
exprp);
|
||||
m_cellp->addNextHere(assp);
|
||||
if (debug()>=9) assp->dumpTree(cout," _new: ");
|
||||
} else if (nodep->modVarp()->isIfaceRef()
|
||||
if (debug()>=9) assp->dumpTree(cout, " _new: ");
|
||||
} else if (nodep->modVarp()->isIfaceRef()
|
||||
|| (VN_IS(nodep->modVarp()->subDTypep(), UnpackArrayDType)
|
||||
&& VN_IS(VN_CAST(nodep->modVarp()->subDTypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType))) {
|
||||
// Create an AstAssignVarScope for Vars to Cells so we can link with their scope later
|
||||
AstNode* lhsp = new AstVarXRef(exprp->fileline(), nodep->modVarp(), m_cellp->name(), false);
|
||||
&& VN_IS(VN_CAST(nodep->modVarp()->subDTypep(),
|
||||
UnpackArrayDType)->subDTypep(), IfaceRefDType))) {
|
||||
// Create an AstAssignVarScope for Vars to Cells so we can
|
||||
// link with their scope later
|
||||
AstNode* lhsp = new AstVarXRef(exprp->fileline(),
|
||||
nodep->modVarp(), m_cellp->name(), false);
|
||||
const AstVarRef* refp = VN_CAST(exprp, VarRef);
|
||||
const AstVarXRef* xrefp = VN_CAST(exprp, VarXRef);
|
||||
if (!refp && !xrefp) exprp->v3fatalSrc("Interfaces: Pin is not connected to a VarRef or VarXRef");
|
||||
AstAssignVarScope* assp = new AstAssignVarScope(exprp->fileline(), lhsp, exprp);
|
||||
if (!refp && !xrefp) exprp->v3fatalSrc("Interfaces: Pin is not connected to a VarRef or VarXRef");
|
||||
AstAssignVarScope* assp = new AstAssignVarScope(exprp->fileline(), lhsp, exprp);
|
||||
m_cellp->addNextHere(assp);
|
||||
} else {
|
||||
nodep->v3error("Assigned pin is neither input nor output");
|
||||
}
|
||||
}
|
||||
} else {
|
||||
nodep->v3error("Assigned pin is neither input nor output");
|
||||
}
|
||||
}
|
||||
|
||||
// We're done with the pin
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
// We're done with the pin
|
||||
nodep->unlinkFrBack()->deleteTree(); VL_DANGLING(nodep);
|
||||
}
|
||||
|
||||
virtual void visit(AstUdpTable* nodep) {
|
||||
if (!v3Global.opt.bboxUnsup()) {
|
||||
// If we support primitives, update V3Undriven to remove special case
|
||||
nodep->v3error("Unsupported: Verilog 1995 UDP Tables. Use --bbox-unsup to ignore tables.");
|
||||
}
|
||||
if (!v3Global.opt.bboxUnsup()) {
|
||||
// If we support primitives, update V3Undriven to remove special case
|
||||
nodep->v3error("Unsupported: Verilog 1995 UDP Tables. Use --bbox-unsup to ignore tables.");
|
||||
}
|
||||
}
|
||||
|
||||
// Save some time
|
||||
|
|
@ -132,8 +136,8 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit InstVisitor(AstNetlist* nodep) {
|
||||
m_cellp=NULL;
|
||||
//
|
||||
m_cellp = NULL;
|
||||
//
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~InstVisitor() {}
|
||||
|
|
@ -146,16 +150,16 @@ class InstDeModVarVisitor : public AstNVisitor {
|
|||
private:
|
||||
// STATE
|
||||
typedef std::map<string,AstVar*> VarNameMap;
|
||||
VarNameMap m_modVarNameMap; // Per module, name of cloned variables
|
||||
VarNameMap m_modVarNameMap; // Per module, name of cloned variables
|
||||
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstVar* nodep) {
|
||||
if (VN_IS(nodep->dtypep(), IfaceRefDType)) {
|
||||
UINFO(8," dm-1-VAR "<<nodep<<endl);
|
||||
insert(nodep);
|
||||
}
|
||||
UINFO(8," dm-1-VAR "<<nodep<<endl);
|
||||
insert(nodep);
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
// Save some time
|
||||
|
|
@ -167,28 +171,28 @@ private:
|
|||
public:
|
||||
// METHODS
|
||||
void insert(AstVar* nodep) {
|
||||
UINFO(8," dmINSERT "<<nodep<<endl);
|
||||
m_modVarNameMap.insert(make_pair(nodep->name(), nodep));
|
||||
UINFO(8," dmINSERT "<<nodep<<endl);
|
||||
m_modVarNameMap.insert(make_pair(nodep->name(), nodep));
|
||||
}
|
||||
AstVar* find(const string& name) {
|
||||
VarNameMap::iterator it = m_modVarNameMap.find(name);
|
||||
if (it != m_modVarNameMap.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
VarNameMap::iterator it = m_modVarNameMap.find(name);
|
||||
if (it != m_modVarNameMap.end()) {
|
||||
return it->second;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
void dump() {
|
||||
for (VarNameMap::iterator it=m_modVarNameMap.begin(); it!=m_modVarNameMap.end(); ++it) {
|
||||
cout<<"-namemap: "<<it->first<<" -> "<<it->second<<endl;
|
||||
}
|
||||
for (VarNameMap::iterator it=m_modVarNameMap.begin(); it!=m_modVarNameMap.end(); ++it) {
|
||||
cout<<"-namemap: "<<it->first<<" -> "<<it->second<<endl;
|
||||
}
|
||||
}
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
explicit InstDeModVarVisitor() {}
|
||||
void main(AstNodeModule* nodep) {
|
||||
UINFO(8," dmMODULE "<<nodep<<endl);
|
||||
m_modVarNameMap.clear();
|
||||
UINFO(8," dmMODULE "<<nodep<<endl);
|
||||
m_modVarNameMap.clear();
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~InstDeModVarVisitor() {}
|
||||
|
|
@ -200,9 +204,9 @@ class InstDeVisitor : public AstNVisitor {
|
|||
// Find all cells with arrays, and convert to non-arrayed
|
||||
private:
|
||||
// STATE
|
||||
AstRange* m_cellRangep; // Range for arrayed instantiations, NULL for normal instantiations
|
||||
int m_instSelNum; // Current instantiation count 0..N-1
|
||||
InstDeModVarVisitor m_deModVars; // State of variables for current cell module
|
||||
AstRange* m_cellRangep; // Range for arrayed instantiations, NULL for normal instantiations
|
||||
int m_instSelNum; // Current instantiation count 0..N-1
|
||||
InstDeModVarVisitor m_deModVars; // State of variables for current cell module
|
||||
|
||||
typedef std::map<string,AstVar*> VarNameMap;
|
||||
|
||||
|
|
@ -212,221 +216,228 @@ private:
|
|||
virtual void visit(AstVar* nodep) {
|
||||
if (VN_IS(nodep->dtypep(), UnpackArrayDType)
|
||||
&& VN_IS(VN_CAST(nodep->dtypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType)) {
|
||||
UINFO(8," dv-vec-VAR "<<nodep<<endl);
|
||||
UINFO(8," dv-vec-VAR "<<nodep<<endl);
|
||||
AstUnpackArrayDType* arrdtype = VN_CAST(nodep->dtypep(), UnpackArrayDType);
|
||||
AstNode* prevp = NULL;
|
||||
for (int i = arrdtype->lsb(); i <= arrdtype->msb(); ++i) {
|
||||
string varNewName = nodep->name() + "__BRA__" + cvtToStr(i) + "__KET__";
|
||||
UINFO(8,"VAR name insert "<<varNewName<<" "<<nodep<<endl);
|
||||
if (!m_deModVars.find(varNewName)) {
|
||||
AstIfaceRefDType* ifaceRefp = VN_CAST(arrdtype->subDTypep(), IfaceRefDType)->cloneTree(false);
|
||||
arrdtype->addNextHere(ifaceRefp);
|
||||
ifaceRefp->cellp(NULL);
|
||||
AstNode* prevp = NULL;
|
||||
for (int i = arrdtype->lsb(); i <= arrdtype->msb(); ++i) {
|
||||
string varNewName = nodep->name() + "__BRA__" + cvtToStr(i) + "__KET__";
|
||||
UINFO(8,"VAR name insert "<<varNewName<<" "<<nodep<<endl);
|
||||
if (!m_deModVars.find(varNewName)) {
|
||||
AstIfaceRefDType* ifaceRefp
|
||||
= VN_CAST(arrdtype->subDTypep(), IfaceRefDType)->cloneTree(false);
|
||||
arrdtype->addNextHere(ifaceRefp);
|
||||
ifaceRefp->cellp(NULL);
|
||||
|
||||
AstVar* varNewp = nodep->cloneTree(false);
|
||||
varNewp->name(varNewName);
|
||||
varNewp->origName(varNewp->origName() + "__BRA__" + cvtToStr(i) + "__KET__");
|
||||
varNewp->dtypep(ifaceRefp);
|
||||
m_deModVars.insert(varNewp);
|
||||
if (!prevp) {
|
||||
prevp = varNewp;
|
||||
} else {
|
||||
prevp->addNextHere(varNewp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prevp) nodep->addNextHere(prevp);
|
||||
if (prevp && debug()==9) { prevp->dumpTree(cout, "newintf: "); cout << endl; }
|
||||
}
|
||||
AstVar* varNewp = nodep->cloneTree(false);
|
||||
varNewp->name(varNewName);
|
||||
varNewp->origName(varNewp->origName() + "__BRA__" + cvtToStr(i) + "__KET__");
|
||||
varNewp->dtypep(ifaceRefp);
|
||||
m_deModVars.insert(varNewp);
|
||||
if (!prevp) {
|
||||
prevp = varNewp;
|
||||
} else {
|
||||
prevp->addNextHere(varNewp);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (prevp) nodep->addNextHere(prevp);
|
||||
if (prevp && debug()==9) { prevp->dumpTree(cout, "newintf: "); cout << endl; }
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
virtual void visit(AstCell* nodep) {
|
||||
UINFO(4," CELL "<<nodep<<endl);
|
||||
// Find submodule vars
|
||||
if (!nodep->modp()) nodep->v3fatalSrc("Unlinked");
|
||||
m_deModVars.main(nodep->modp());
|
||||
//
|
||||
if (nodep->rangep()) {
|
||||
m_cellRangep = nodep->rangep();
|
||||
UINFO(4," CELL "<<nodep<<endl);
|
||||
// Find submodule vars
|
||||
if (!nodep->modp()) nodep->v3fatalSrc("Unlinked");
|
||||
m_deModVars.main(nodep->modp());
|
||||
//
|
||||
if (nodep->rangep()) {
|
||||
m_cellRangep = nodep->rangep();
|
||||
|
||||
AstVar* ifaceVarp = VN_CAST(nodep->nextp(), Var);
|
||||
bool isIface = ifaceVarp
|
||||
bool isIface = ifaceVarp
|
||||
&& VN_IS(ifaceVarp->dtypep(), UnpackArrayDType)
|
||||
&& VN_IS(VN_CAST(ifaceVarp->dtypep(), UnpackArrayDType)->subDTypep(), IfaceRefDType);
|
||||
&& VN_IS(VN_CAST(ifaceVarp->dtypep(),
|
||||
UnpackArrayDType)->subDTypep(), IfaceRefDType);
|
||||
|
||||
// Make all of the required clones
|
||||
for (int i = 0; i < m_cellRangep->elementsConst(); i++) {
|
||||
m_instSelNum = m_cellRangep->littleEndian() ? (m_cellRangep->elementsConst() - 1 - i) : i;
|
||||
int instNum = m_cellRangep->lsbConst() + i;
|
||||
// Make all of the required clones
|
||||
for (int i = 0; i < m_cellRangep->elementsConst(); i++) {
|
||||
m_instSelNum = m_cellRangep->littleEndian() ? (m_cellRangep->elementsConst() - 1 - i) : i;
|
||||
int instNum = m_cellRangep->lsbConst() + i;
|
||||
|
||||
AstCell* newp = nodep->cloneTree(false);
|
||||
nodep->addNextHere(newp);
|
||||
// Remove ranging and fix name
|
||||
newp->rangep()->unlinkFrBack()->deleteTree();
|
||||
// Somewhat illogically, we need to rename the orignal name of the cell too.
|
||||
// as that is the name users expect for dotting
|
||||
// The spec says we add [x], but that won't work in C...
|
||||
newp->name(newp->name()+"__BRA__"+cvtToStr(instNum)+"__KET__");
|
||||
newp->origName(newp->origName()+"__BRA__"+cvtToStr(instNum)+"__KET__");
|
||||
UINFO(8," CELL loop "<<newp<<endl);
|
||||
AstCell* newp = nodep->cloneTree(false);
|
||||
nodep->addNextHere(newp);
|
||||
// Remove ranging and fix name
|
||||
newp->rangep()->unlinkFrBack()->deleteTree();
|
||||
// Somewhat illogically, we need to rename the orignal name of the cell too.
|
||||
// as that is the name users expect for dotting
|
||||
// The spec says we add [x], but that won't work in C...
|
||||
newp->name(newp->name()+"__BRA__"+cvtToStr(instNum)+"__KET__");
|
||||
newp->origName(newp->origName()+"__BRA__"+cvtToStr(instNum)+"__KET__");
|
||||
UINFO(8," CELL loop "<<newp<<endl);
|
||||
|
||||
// If this AstCell is actually an interface instantiation, also clone the IfaceRef
|
||||
// within the same parent module as the cell
|
||||
if (isIface) {
|
||||
// If this AstCell is actually an interface instantiation, also clone the IfaceRef
|
||||
// within the same parent module as the cell
|
||||
if (isIface) {
|
||||
AstUnpackArrayDType* arrdtype = VN_CAST(ifaceVarp->dtypep(), UnpackArrayDType);
|
||||
AstIfaceRefDType* origIfaceRefp = VN_CAST(arrdtype->subDTypep(), IfaceRefDType);
|
||||
origIfaceRefp->cellp(NULL);
|
||||
AstVar* varNewp = ifaceVarp->cloneTree(false);
|
||||
AstIfaceRefDType* ifaceRefp = VN_CAST(arrdtype->subDTypep(), IfaceRefDType)->cloneTree(false);
|
||||
arrdtype->addNextHere(ifaceRefp);
|
||||
ifaceRefp->cellp(newp);
|
||||
ifaceRefp->cellName(newp->name());
|
||||
varNewp->name(varNewp->name() + "__BRA__" + cvtToStr(instNum) + "__KET__");
|
||||
varNewp->origName(varNewp->origName() + "__BRA__" + cvtToStr(instNum) + "__KET__");
|
||||
varNewp->dtypep(ifaceRefp);
|
||||
newp->addNextHere(varNewp);
|
||||
if (debug()==9) { varNewp->dumpTree(cout, "newintf: "); cout << endl; }
|
||||
}
|
||||
// Fixup pins
|
||||
origIfaceRefp->cellp(NULL);
|
||||
AstVar* varNewp = ifaceVarp->cloneTree(false);
|
||||
AstIfaceRefDType* ifaceRefp
|
||||
= VN_CAST(arrdtype->subDTypep(), IfaceRefDType)->cloneTree(false);
|
||||
arrdtype->addNextHere(ifaceRefp);
|
||||
ifaceRefp->cellp(newp);
|
||||
ifaceRefp->cellName(newp->name());
|
||||
varNewp->name(varNewp->name() + "__BRA__" + cvtToStr(instNum) + "__KET__");
|
||||
varNewp->origName(varNewp->origName() + "__BRA__" + cvtToStr(instNum) + "__KET__");
|
||||
varNewp->dtypep(ifaceRefp);
|
||||
newp->addNextHere(varNewp);
|
||||
if (debug()==9) { varNewp->dumpTree(cout, "newintf: "); cout << endl; }
|
||||
}
|
||||
// Fixup pins
|
||||
iterateAndNextNull(newp->pinsp());
|
||||
if (debug()==9) { newp->dumpTree(cout,"newcell: "); cout<<endl; }
|
||||
}
|
||||
if (debug()==9) { newp->dumpTree(cout, "newcell: "); cout<<endl; }
|
||||
}
|
||||
|
||||
// Done. Delete original
|
||||
m_cellRangep=NULL;
|
||||
if (isIface) {
|
||||
ifaceVarp->unlinkFrBack(); pushDeletep(ifaceVarp); VL_DANGLING(ifaceVarp);
|
||||
}
|
||||
nodep->unlinkFrBack(); pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
} else {
|
||||
m_cellRangep = NULL;
|
||||
// Done. Delete original
|
||||
m_cellRangep = NULL;
|
||||
if (isIface) {
|
||||
ifaceVarp->unlinkFrBack(); pushDeletep(ifaceVarp); VL_DANGLING(ifaceVarp);
|
||||
}
|
||||
nodep->unlinkFrBack(); pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
} else {
|
||||
m_cellRangep = NULL;
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
virtual void visit(AstPin* nodep) {
|
||||
// Any non-direct pins need reconnection with a part-select
|
||||
if (!nodep->exprp()) return; // No-connect
|
||||
if (m_cellRangep) {
|
||||
UINFO(4," PIN "<<nodep<<endl);
|
||||
int pinwidth = nodep->modVarp()->width();
|
||||
int expwidth = nodep->exprp()->width();
|
||||
// Any non-direct pins need reconnection with a part-select
|
||||
if (!nodep->exprp()) return; // No-connect
|
||||
if (m_cellRangep) {
|
||||
UINFO(4," PIN "<<nodep<<endl);
|
||||
int pinwidth = nodep->modVarp()->width();
|
||||
int expwidth = nodep->exprp()->width();
|
||||
std::pair<uint32_t,uint32_t> pinDim = nodep->modVarp()->dtypep()->dimensions(false);
|
||||
std::pair<uint32_t,uint32_t> expDim = nodep->exprp()->dtypep()->dimensions(false);
|
||||
UINFO(4," PINVAR "<<nodep->modVarp()<<endl);
|
||||
UINFO(4," EXP "<<nodep->exprp()<<endl);
|
||||
UINFO(4," pinwidth ew="<<expwidth<<" pw="<<pinwidth
|
||||
<<" ed="<<expDim.first<<","<<expDim.second
|
||||
<<" pd="<<pinDim.first<<","<<pinDim.second<<endl);
|
||||
if (expDim.first == pinDim.first && expDim.second == pinDim.second+1) {
|
||||
// Connection to array, where array dimensions match the instant dimension
|
||||
AstNode* exprp = nodep->exprp()->unlinkFrBack();
|
||||
UINFO(4," PINVAR "<<nodep->modVarp()<<endl);
|
||||
UINFO(4," EXP "<<nodep->exprp()<<endl);
|
||||
UINFO(4," pinwidth ew="<<expwidth<<" pw="<<pinwidth
|
||||
<<" ed="<<expDim.first<<","<<expDim.second
|
||||
<<" pd="<<pinDim.first<<","<<pinDim.second<<endl);
|
||||
if (expDim.first == pinDim.first && expDim.second == pinDim.second+1) {
|
||||
// Connection to array, where array dimensions match the instant dimension
|
||||
AstNode* exprp = nodep->exprp()->unlinkFrBack();
|
||||
exprp = new AstArraySel(exprp->fileline(), exprp, m_instSelNum);
|
||||
nodep->exprp(exprp);
|
||||
} else if (expwidth == pinwidth) {
|
||||
// NOP: Arrayed instants: widths match so connect to each instance
|
||||
} else if (expwidth == pinwidth*m_cellRangep->elementsConst()) {
|
||||
// Arrayed instants: one bit for each of the instants (each assign is 1 pinwidth wide)
|
||||
if (m_cellRangep->littleEndian()) {
|
||||
nodep->v3warn(LITENDIAN,"Little endian cell range connecting to vector: MSB < LSB of cell range: "
|
||||
<<m_cellRangep->lsbConst()<<":"<<m_cellRangep->msbConst());
|
||||
}
|
||||
nodep->exprp(exprp);
|
||||
} else if (expwidth == pinwidth) {
|
||||
// NOP: Arrayed instants: widths match so connect to each instance
|
||||
} else if (expwidth == pinwidth*m_cellRangep->elementsConst()) {
|
||||
// Arrayed instants: one bit for each of the instants (each
|
||||
// assign is 1 pinwidth wide)
|
||||
if (m_cellRangep->littleEndian()) {
|
||||
nodep->v3warn(LITENDIAN, "Little endian cell range connecting to vector: MSB < LSB of cell range: "
|
||||
<<m_cellRangep->lsbConst()<<":"<<m_cellRangep->msbConst());
|
||||
}
|
||||
AstNode* exprp = nodep->exprp()->unlinkFrBack();
|
||||
bool inputPin = nodep->modVarp()->isNonOutput();
|
||||
if (!inputPin && !VN_IS(exprp, VarRef)
|
||||
&& !VN_IS(exprp, Concat) // V3Const will collapse the SEL with the one we're about to make
|
||||
&& !VN_IS(exprp, Sel)) { // V3Const will collapse the SEL with the one we're about to make
|
||||
nodep->v3error("Unsupported: Per-bit array instantiations with output connections to non-wires.");
|
||||
// Note spec allows more complicated matches such as slices and such
|
||||
}
|
||||
nodep->v3error("Unsupported: Per-bit array instantiations with output connections to non-wires.");
|
||||
// Note spec allows more complicated matches such as slices and such
|
||||
}
|
||||
exprp = new AstSel(exprp->fileline(), exprp,
|
||||
pinwidth*m_instSelNum,
|
||||
pinwidth);
|
||||
nodep->exprp(exprp);
|
||||
} else {
|
||||
nodep->v3fatalSrc("Width mismatch; V3Width should have errored out.");
|
||||
}
|
||||
nodep->exprp(exprp);
|
||||
} else {
|
||||
nodep->v3fatalSrc("Width mismatch; V3Width should have errored out.");
|
||||
}
|
||||
} else if (AstArraySel* arrselp = VN_CAST(nodep->exprp(), ArraySel)) {
|
||||
if (AstUnpackArrayDType* arrp = VN_CAST(arrselp->lhsp()->dtypep(), UnpackArrayDType)) {
|
||||
if (!VN_IS(arrp->subDTypep(), IfaceRefDType))
|
||||
return;
|
||||
return;
|
||||
|
||||
V3Const::constifyParamsEdit(arrselp->rhsp());
|
||||
V3Const::constifyParamsEdit(arrselp->rhsp());
|
||||
const AstConst* constp = VN_CAST(arrselp->rhsp(), Const);
|
||||
if (!constp) {
|
||||
nodep->v3error("Unsupported: Non-constant index when passing interface to module");
|
||||
return;
|
||||
}
|
||||
string index = AstNode::encodeNumber(constp->toSInt());
|
||||
if (!constp) {
|
||||
nodep->v3error("Unsupported: Non-constant index when passing interface to module");
|
||||
return;
|
||||
}
|
||||
string index = AstNode::encodeNumber(constp->toSInt());
|
||||
AstVarRef* varrefp = VN_CAST(arrselp->lhsp(), VarRef);
|
||||
AstVarXRef* newp = new AstVarXRef(nodep->fileline(), varrefp->name()+"__BRA__"+index+"__KET__", "", true);
|
||||
newp->dtypep(nodep->modVarp()->dtypep());
|
||||
newp->packagep(varrefp->packagep());
|
||||
arrselp->addNextHere(newp);
|
||||
arrselp->unlinkFrBack()->deleteTree();
|
||||
}
|
||||
} else {
|
||||
AstVar* pinVarp = nodep->modVarp();
|
||||
AstVarXRef* newp = new AstVarXRef(nodep->fileline(),
|
||||
varrefp->name()+"__BRA__"+index+"__KET__",
|
||||
"", true);
|
||||
newp->dtypep(nodep->modVarp()->dtypep());
|
||||
newp->packagep(varrefp->packagep());
|
||||
arrselp->addNextHere(newp);
|
||||
arrselp->unlinkFrBack()->deleteTree();
|
||||
}
|
||||
} else {
|
||||
AstVar* pinVarp = nodep->modVarp();
|
||||
AstUnpackArrayDType* pinArrp = VN_CAST(pinVarp->dtypep(), UnpackArrayDType);
|
||||
if (!pinArrp || !VN_IS(pinArrp->subDTypep(), IfaceRefDType))
|
||||
return;
|
||||
AstNode* prevp = NULL;
|
||||
AstNode* prevPinp = NULL;
|
||||
// Clone the var referenced by the pin, and clone each var referenced by the varref
|
||||
// Clone pin varp:
|
||||
for (int i = pinArrp->lsb(); i <= pinArrp->msb(); ++i) {
|
||||
string varNewName = pinVarp->name() + "__BRA__" + cvtToStr(i) + "__KET__";
|
||||
AstVar* varNewp = NULL;
|
||||
return;
|
||||
AstNode* prevp = NULL;
|
||||
AstNode* prevPinp = NULL;
|
||||
// Clone the var referenced by the pin, and clone each var referenced by the varref
|
||||
// Clone pin varp:
|
||||
for (int i = pinArrp->lsb(); i <= pinArrp->msb(); ++i) {
|
||||
string varNewName = pinVarp->name() + "__BRA__" + cvtToStr(i) + "__KET__";
|
||||
AstVar* varNewp = NULL;
|
||||
|
||||
// Only clone the var once for all usages of a given child module
|
||||
if (!pinVarp->backp()) {
|
||||
varNewp = m_deModVars.find(varNewName);
|
||||
} else {
|
||||
// Only clone the var once for all usages of a given child module
|
||||
if (!pinVarp->backp()) {
|
||||
varNewp = m_deModVars.find(varNewName);
|
||||
} else {
|
||||
AstIfaceRefDType* ifaceRefp = VN_CAST(pinArrp->subDTypep(), IfaceRefDType);
|
||||
ifaceRefp->cellp(NULL);
|
||||
varNewp = pinVarp->cloneTree(false);
|
||||
varNewp->name(varNewName);
|
||||
varNewp->origName(varNewp->origName() + "__BRA__" + cvtToStr(i) + "__KET__");
|
||||
varNewp->dtypep(ifaceRefp);
|
||||
m_deModVars.insert(varNewp);
|
||||
if (!prevp) {
|
||||
prevp = varNewp;
|
||||
} else {
|
||||
prevp->addNextHere(varNewp);
|
||||
}
|
||||
}
|
||||
if (!varNewp) {
|
||||
if (debug()>=9) m_deModVars.dump();
|
||||
nodep->v3fatalSrc("Module dearray failed for "<<AstNode::prettyName(varNewName));
|
||||
}
|
||||
ifaceRefp->cellp(NULL);
|
||||
varNewp = pinVarp->cloneTree(false);
|
||||
varNewp->name(varNewName);
|
||||
varNewp->origName(varNewp->origName() + "__BRA__" + cvtToStr(i) + "__KET__");
|
||||
varNewp->dtypep(ifaceRefp);
|
||||
m_deModVars.insert(varNewp);
|
||||
if (!prevp) {
|
||||
prevp = varNewp;
|
||||
} else {
|
||||
prevp->addNextHere(varNewp);
|
||||
}
|
||||
}
|
||||
if (!varNewp) {
|
||||
if (debug()>=9) m_deModVars.dump();
|
||||
nodep->v3fatalSrc("Module dearray failed for "
|
||||
<<AstNode::prettyName(varNewName));
|
||||
}
|
||||
|
||||
// But clone the pin for each module instance
|
||||
// Now also clone the pin itself and update its varref
|
||||
AstPin* newp = nodep->cloneTree(false);
|
||||
newp->modVarp(varNewp);
|
||||
newp->name(newp->name() + "__BRA__" + cvtToStr(i) + "__KET__");
|
||||
// And replace exprp with a new varxref
|
||||
// But clone the pin for each module instance
|
||||
// Now also clone the pin itself and update its varref
|
||||
AstPin* newp = nodep->cloneTree(false);
|
||||
newp->modVarp(varNewp);
|
||||
newp->name(newp->name() + "__BRA__" + cvtToStr(i) + "__KET__");
|
||||
// And replace exprp with a new varxref
|
||||
const AstVarRef* varrefp = VN_CAST(newp->exprp(), VarRef);
|
||||
string newname = varrefp->name() + "__BRA__" + cvtToStr(i) + "__KET__";
|
||||
string newname = varrefp->name() + "__BRA__" + cvtToStr(i) + "__KET__";
|
||||
AstVarXRef* newVarXRefp = new AstVarXRef(nodep->fileline(), newname, "", true);
|
||||
newVarXRefp->varp(newp->modVarp());
|
||||
newVarXRefp->dtypep(newp->modVarp()->dtypep());
|
||||
newp->exprp()->unlinkFrBack()->deleteTree();
|
||||
newp->exprp(newVarXRefp);
|
||||
if (!prevPinp) {
|
||||
prevPinp = newp;
|
||||
} else {
|
||||
prevPinp->addNextHere(newp);
|
||||
}
|
||||
}
|
||||
if (prevp) {
|
||||
pinVarp->replaceWith(prevp);
|
||||
pushDeletep(pinVarp);
|
||||
} // else pinVarp already unlinked when another instance did this step
|
||||
nodep->replaceWith(prevPinp);
|
||||
pushDeletep(nodep);
|
||||
}
|
||||
newVarXRefp->varp(newp->modVarp());
|
||||
newVarXRefp->dtypep(newp->modVarp()->dtypep());
|
||||
newp->exprp()->unlinkFrBack()->deleteTree();
|
||||
newp->exprp(newVarXRefp);
|
||||
if (!prevPinp) {
|
||||
prevPinp = newp;
|
||||
} else {
|
||||
prevPinp->addNextHere(newp);
|
||||
}
|
||||
}
|
||||
if (prevp) {
|
||||
pinVarp->replaceWith(prevp);
|
||||
pushDeletep(pinVarp);
|
||||
} // else pinVarp already unlinked when another instance did this step
|
||||
nodep->replaceWith(prevPinp);
|
||||
pushDeletep(nodep);
|
||||
}
|
||||
}
|
||||
|
||||
// Save some time
|
||||
|
|
@ -439,9 +450,9 @@ private:
|
|||
public:
|
||||
// CONSTUCTORS
|
||||
explicit InstDeVisitor(AstNetlist* nodep) {
|
||||
m_cellRangep=NULL;
|
||||
m_instSelNum=0;
|
||||
//
|
||||
m_cellRangep = NULL;
|
||||
m_instSelNum = 0;
|
||||
//
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~InstDeVisitor() {}
|
||||
|
|
@ -453,64 +464,64 @@ public:
|
|||
class InstStatic {
|
||||
private:
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
InstStatic() {} // Static class
|
||||
InstStatic() {} // Static class
|
||||
|
||||
static AstNode* extendOrSel(FileLine* fl, AstNode* rhsp, AstNode* cmpWidthp) {
|
||||
if (cmpWidthp->width() > rhsp->width()) {
|
||||
rhsp = (rhsp->isSigned()
|
||||
? static_cast<AstNode*>(new AstExtendS(fl, rhsp))
|
||||
: static_cast<AstNode*>(new AstExtend (fl, rhsp)));
|
||||
rhsp->dtypeFrom(cmpWidthp); // Need proper widthMin, which may differ from AstSel created above
|
||||
} else if (cmpWidthp->width() < rhsp->width()) {
|
||||
if (cmpWidthp->width() > rhsp->width()) {
|
||||
rhsp = (rhsp->isSigned()
|
||||
? static_cast<AstNode*>(new AstExtendS(fl, rhsp))
|
||||
: static_cast<AstNode*>(new AstExtend (fl, rhsp)));
|
||||
rhsp->dtypeFrom(cmpWidthp); // Need proper widthMin, which may differ from AstSel created above
|
||||
} else if (cmpWidthp->width() < rhsp->width()) {
|
||||
rhsp = new AstSel(fl, rhsp, 0, cmpWidthp->width());
|
||||
rhsp->dtypeFrom(cmpWidthp); // Need proper widthMin, which may differ from AstSel created above
|
||||
}
|
||||
// else don't change dtype, as might be e.g. array of something
|
||||
return rhsp;
|
||||
rhsp->dtypeFrom(cmpWidthp); // Need proper widthMin, which may differ from AstSel created above
|
||||
}
|
||||
// else don't change dtype, as might be e.g. array of something
|
||||
return rhsp;
|
||||
}
|
||||
|
||||
public:
|
||||
static AstAssignW* pinReconnectSimple(AstPin* pinp, AstCell* cellp,
|
||||
bool forTristate, bool alwaysCvt) {
|
||||
// If a pin connection is "simple" leave it as-is
|
||||
// Else create a intermediate wire to perform the interconnect
|
||||
// Return the new assignment, if one was made
|
||||
// Note this module calles cloneTree() via new AstVar
|
||||
bool forTristate, bool alwaysCvt) {
|
||||
// If a pin connection is "simple" leave it as-is
|
||||
// Else create a intermediate wire to perform the interconnect
|
||||
// Return the new assignment, if one was made
|
||||
// Note this module calles cloneTree() via new AstVar
|
||||
|
||||
AstVar* pinVarp = pinp->modVarp();
|
||||
AstVar* pinVarp = pinp->modVarp();
|
||||
AstVarRef* connectRefp = VN_CAST(pinp->exprp(), VarRef);
|
||||
AstVarXRef* connectXRefp = VN_CAST(pinp->exprp(), VarXRef);
|
||||
AstBasicDType* pinBasicp = VN_CAST(pinVarp->dtypep(), BasicDType); // Maybe NULL
|
||||
AstBasicDType* connBasicp = NULL;
|
||||
AstAssignW* assignp = NULL;
|
||||
AstBasicDType* connBasicp = NULL;
|
||||
AstAssignW* assignp = NULL;
|
||||
if (connectRefp) connBasicp = VN_CAST(connectRefp->varp()->dtypep(), BasicDType);
|
||||
//
|
||||
if (!alwaysCvt
|
||||
&& connectRefp
|
||||
&& connectRefp->varp()->dtypep()->sameTree(pinVarp->dtypep())
|
||||
&& !connectRefp->varp()->isSc()) { // Need the signal as a 'shell' to convert types
|
||||
// Done. Same data type
|
||||
} else if (!alwaysCvt
|
||||
&& connectRefp
|
||||
&& connectRefp->varp()->isIfaceRef()) {
|
||||
// Done. Interface
|
||||
} else if (!alwaysCvt
|
||||
&& connectXRefp
|
||||
&& connectXRefp->varp()
|
||||
&& connectXRefp->varp()->isIfaceRef()) {
|
||||
} else if (!alwaysCvt
|
||||
&& connBasicp
|
||||
&& pinBasicp
|
||||
&& connBasicp->width() == pinBasicp->width()
|
||||
&& connBasicp->lsb() == pinBasicp->lsb()
|
||||
&& !connectRefp->varp()->isSc() // Need the signal as a 'shell' to convert types
|
||||
&& connBasicp->width() == pinVarp->width()) {
|
||||
// Done. One to one interconnect won't need a temporary variable.
|
||||
//
|
||||
if (!alwaysCvt
|
||||
&& connectRefp
|
||||
&& connectRefp->varp()->dtypep()->sameTree(pinVarp->dtypep())
|
||||
&& !connectRefp->varp()->isSc()) { // Need the signal as a 'shell' to convert types
|
||||
// Done. Same data type
|
||||
} else if (!alwaysCvt
|
||||
&& connectRefp
|
||||
&& connectRefp->varp()->isIfaceRef()) {
|
||||
// Done. Interface
|
||||
} else if (!alwaysCvt
|
||||
&& connectXRefp
|
||||
&& connectXRefp->varp()
|
||||
&& connectXRefp->varp()->isIfaceRef()) {
|
||||
} else if (!alwaysCvt
|
||||
&& connBasicp
|
||||
&& pinBasicp
|
||||
&& connBasicp->width() == pinBasicp->width()
|
||||
&& connBasicp->lsb() == pinBasicp->lsb()
|
||||
&& !connectRefp->varp()->isSc() // Need the signal as a 'shell' to convert types
|
||||
&& connBasicp->width() == pinVarp->width()) {
|
||||
// Done. One to one interconnect won't need a temporary variable.
|
||||
} else if (!alwaysCvt && !forTristate && VN_IS(pinp->exprp(), Const)) {
|
||||
// Done. Constant.
|
||||
} else {
|
||||
// Make a new temp wire
|
||||
//if (1||debug()>=9) { pinp->dumpTree(cout,"-in_pin:"); }
|
||||
// Done. Constant.
|
||||
} else {
|
||||
// Make a new temp wire
|
||||
//if (1||debug()>=9) { pinp->dumpTree(cout, "-in_pin:"); }
|
||||
V3Inst::checkOutputShort(pinp);
|
||||
AstNode* pinexprp = pinp->exprp()->unlinkFrBack();
|
||||
string newvarname = (string(pinVarp->isWritable() ? "__Vcellout" : "__Vcellinp")
|
||||
|
|
@ -540,12 +551,12 @@ public:
|
|||
new AstVarRef(pinp->fileline(), newvarp, true),
|
||||
pinexprp);
|
||||
pinp->exprp(new AstVarRef(pinexprp->fileline(), newvarp, false));
|
||||
}
|
||||
if (assignp) cellp->addNextHere(assignp);
|
||||
//if (debug()) { pinp->dumpTree(cout,"- out:"); }
|
||||
//if (debug()) { assignp->dumpTree(cout,"- aout:"); }
|
||||
}
|
||||
return assignp;
|
||||
}
|
||||
if (assignp) cellp->addNextHere(assignp);
|
||||
//if (debug()) { pinp->dumpTree(cout, "- out:"); }
|
||||
//if (debug()) { assignp->dumpTree(cout, "- aout:"); }
|
||||
}
|
||||
return assignp;
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -38,4 +38,4 @@ public:
|
|||
static void checkOutputShort(AstPin* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -35,34 +35,34 @@
|
|||
class V3LangCode {
|
||||
public:
|
||||
enum en {
|
||||
L_ERROR, // Must be first.
|
||||
L1364_1995,
|
||||
L1364_2001,
|
||||
L1364_2005,
|
||||
L1800_2005,
|
||||
L1800_2009,
|
||||
L1800_2012,
|
||||
L1800_2017,
|
||||
// ***Add new elements below also***
|
||||
_ENUM_END
|
||||
L_ERROR, // Must be first.
|
||||
L1364_1995,
|
||||
L1364_2001,
|
||||
L1364_2005,
|
||||
L1800_2005,
|
||||
L1800_2009,
|
||||
L1800_2012,
|
||||
L1800_2017,
|
||||
// ***Add new elements below also***
|
||||
_ENUM_END
|
||||
};
|
||||
const char* ascii() const {
|
||||
const char* const names[] = {
|
||||
// These must match the `begin_keywords values.
|
||||
" ERROR",
|
||||
"1364-1995",
|
||||
"1364-2001",
|
||||
"1364-2005",
|
||||
"1800-2005",
|
||||
"1800-2009",
|
||||
"1800-2012",
|
||||
"1800-2017"
|
||||
};
|
||||
return names[m_e];
|
||||
const char* const names[] = {
|
||||
// These must match the `begin_keywords values.
|
||||
" ERROR",
|
||||
"1364-1995",
|
||||
"1364-2001",
|
||||
"1364-2005",
|
||||
"1800-2005",
|
||||
"1800-2009",
|
||||
"1800-2012",
|
||||
"1800-2017"
|
||||
};
|
||||
return names[m_e];
|
||||
};
|
||||
static V3LangCode mostRecent() { return V3LangCode(L1800_2017); }
|
||||
bool systemVerilog() const { return m_e == L1800_2005 || m_e == L1800_2009
|
||||
|| m_e == L1800_2012 || m_e == L1800_2017; }
|
||||
|| m_e == L1800_2012 || m_e == L1800_2017; }
|
||||
bool legal() const { return m_e != L_ERROR; }
|
||||
//
|
||||
enum en m_e;
|
||||
|
|
@ -76,4 +76,4 @@ public:
|
|||
|
||||
//######################################################################
|
||||
|
||||
#endif // guard
|
||||
#endif // guard
|
||||
|
|
|
|||
|
|
@ -36,153 +36,153 @@ class V3LanguageWords {
|
|||
KeywordMap m_kwdMap; // List of keywords, and what language applies
|
||||
|
||||
void addKwd(const string& kwd, const string& why) {
|
||||
m_kwdMap.insert(make_pair(kwd,why));
|
||||
m_kwdMap.insert(make_pair(kwd, why));
|
||||
}
|
||||
public:
|
||||
string isKeyword(const string& kwd) {
|
||||
KeywordMap::iterator it = m_kwdMap.find(kwd);
|
||||
if (it == m_kwdMap.end()) return "";
|
||||
return it->second;
|
||||
if (it == m_kwdMap.end()) return "";
|
||||
return it->second;
|
||||
}
|
||||
|
||||
public:
|
||||
V3LanguageWords() {
|
||||
// C++ keywords
|
||||
// C++
|
||||
addKwd("NULL", "C++ common word");
|
||||
addKwd("abort", "C++ common word");
|
||||
addKwd("alignas", "C++11 keyword");
|
||||
addKwd("alignof", "C++11 keyword");
|
||||
addKwd("and", "C++11 keyword");
|
||||
addKwd("and_eq", "C++11 keyword");
|
||||
addKwd("asm", "C++ common word");
|
||||
addKwd("atomic_cancel", "C++ TM TS keyword");
|
||||
addKwd("atomic_commit", "C++ TM TS keyword");
|
||||
addKwd("atomic_noexcept", "C++ TM TS keyword");
|
||||
addKwd("auto", "C++ keyword");
|
||||
addKwd("bit_vector", "C++ common word");
|
||||
addKwd("bitand", "C++ keyword");
|
||||
addKwd("bitor", "C++ keyword");
|
||||
addKwd("bool", "C++ keyword");
|
||||
addKwd("break", "C++ keyword");
|
||||
addKwd("case", "C++ keyword");
|
||||
addKwd("catch", "C++ keyword");
|
||||
addKwd("cdecl", "C++ common word");
|
||||
addKwd("char", "C++ keyword");
|
||||
addKwd("char16_t", "C++11 keyword");
|
||||
addKwd("char32_t", "C++11 keyword");
|
||||
addKwd("class", "C++11 keyword");
|
||||
addKwd("compl", "C++11 keyword");
|
||||
addKwd("complex", "C++ common word");
|
||||
addKwd("concept", "C++20 keyword");
|
||||
addKwd("const", "C++ keyword");
|
||||
addKwd("const_cast", "C++ common word");
|
||||
addKwd("const_iterator", "C++ common word");
|
||||
addKwd("const_reference ", "C++ common word");
|
||||
addKwd("constexpr", "C++11 keyword");
|
||||
addKwd("continue", "C++ keyword");
|
||||
addKwd("decltype", "C++11 keyword");
|
||||
addKwd("default", "C++ keyword");
|
||||
addKwd("delete", "C++ keyword");
|
||||
addKwd("deque", "C++ common word");
|
||||
addKwd("do", "C++ keyword");
|
||||
addKwd("double", "C++ keyword");
|
||||
addKwd("dynamic_cast", "C++ keyword");
|
||||
addKwd("else", "C++ keyword");
|
||||
addKwd("enum", "C++ keyword");
|
||||
addKwd("explicit", "C++ keyword");
|
||||
addKwd("export", "C++ keyword");
|
||||
addKwd("extern", "C++ keyword");
|
||||
addKwd("false", "C++ keyword");
|
||||
addKwd("far", "C++ common word");
|
||||
addKwd("float", "C++ keyword");
|
||||
addKwd("for", "C++ keyword");
|
||||
addKwd("friend", "C++ keyword");
|
||||
addKwd("goto", "C++ keyword");
|
||||
addKwd("huge", "C++ keyword");
|
||||
addKwd("if", "C++ keyword");
|
||||
addKwd("import", "C++ modules TS keyword");
|
||||
addKwd("inline", "C++ keyword");
|
||||
addKwd("int", "C++ keyword");
|
||||
addKwd("interrupt", "C++ common word");
|
||||
addKwd("iterator", "C++ common word");
|
||||
addKwd("list", "C++ common word");
|
||||
addKwd("long", "C++ keyword");
|
||||
addKwd("map", "C++ common word");
|
||||
addKwd("module", "C++ modules TS keyword");
|
||||
// C++ keywords
|
||||
// C++
|
||||
addKwd("NULL", "C++ common word");
|
||||
addKwd("abort", "C++ common word");
|
||||
addKwd("alignas", "C++11 keyword");
|
||||
addKwd("alignof", "C++11 keyword");
|
||||
addKwd("and", "C++11 keyword");
|
||||
addKwd("and_eq", "C++11 keyword");
|
||||
addKwd("asm", "C++ common word");
|
||||
addKwd("atomic_cancel", "C++ TM TS keyword");
|
||||
addKwd("atomic_commit", "C++ TM TS keyword");
|
||||
addKwd("atomic_noexcept", "C++ TM TS keyword");
|
||||
addKwd("auto", "C++ keyword");
|
||||
addKwd("bit_vector", "C++ common word");
|
||||
addKwd("bitand", "C++ keyword");
|
||||
addKwd("bitor", "C++ keyword");
|
||||
addKwd("bool", "C++ keyword");
|
||||
addKwd("break", "C++ keyword");
|
||||
addKwd("case", "C++ keyword");
|
||||
addKwd("catch", "C++ keyword");
|
||||
addKwd("cdecl", "C++ common word");
|
||||
addKwd("char", "C++ keyword");
|
||||
addKwd("char16_t", "C++11 keyword");
|
||||
addKwd("char32_t", "C++11 keyword");
|
||||
addKwd("class", "C++11 keyword");
|
||||
addKwd("compl", "C++11 keyword");
|
||||
addKwd("complex", "C++ common word");
|
||||
addKwd("concept", "C++20 keyword");
|
||||
addKwd("const", "C++ keyword");
|
||||
addKwd("const_cast", "C++ common word");
|
||||
addKwd("const_iterator", "C++ common word");
|
||||
addKwd("const_reference ", "C++ common word");
|
||||
addKwd("constexpr", "C++11 keyword");
|
||||
addKwd("continue", "C++ keyword");
|
||||
addKwd("decltype", "C++11 keyword");
|
||||
addKwd("default", "C++ keyword");
|
||||
addKwd("delete", "C++ keyword");
|
||||
addKwd("deque", "C++ common word");
|
||||
addKwd("do", "C++ keyword");
|
||||
addKwd("double", "C++ keyword");
|
||||
addKwd("dynamic_cast", "C++ keyword");
|
||||
addKwd("else", "C++ keyword");
|
||||
addKwd("enum", "C++ keyword");
|
||||
addKwd("explicit", "C++ keyword");
|
||||
addKwd("export", "C++ keyword");
|
||||
addKwd("extern", "C++ keyword");
|
||||
addKwd("false", "C++ keyword");
|
||||
addKwd("far", "C++ common word");
|
||||
addKwd("float", "C++ keyword");
|
||||
addKwd("for", "C++ keyword");
|
||||
addKwd("friend", "C++ keyword");
|
||||
addKwd("goto", "C++ keyword");
|
||||
addKwd("huge", "C++ keyword");
|
||||
addKwd("if", "C++ keyword");
|
||||
addKwd("import", "C++ modules TS keyword");
|
||||
addKwd("inline", "C++ keyword");
|
||||
addKwd("int", "C++ keyword");
|
||||
addKwd("interrupt", "C++ common word");
|
||||
addKwd("iterator", "C++ common word");
|
||||
addKwd("list", "C++ common word");
|
||||
addKwd("long", "C++ keyword");
|
||||
addKwd("map", "C++ common word");
|
||||
addKwd("module", "C++ modules TS keyword");
|
||||
addKwd("std::multimap", "C++ common word");
|
||||
addKwd("std::multiset", "C++ common word");
|
||||
addKwd("mutable", "C++ keyword");
|
||||
addKwd("namespace", "C++ keyword");
|
||||
addKwd("near", "C++ common word");
|
||||
addKwd("new", "C++ keyword");
|
||||
addKwd("noexcept", "C++11 keyword");
|
||||
addKwd("not", "C++ keyword");
|
||||
addKwd("not_eq", "C++ keyword");
|
||||
addKwd("nullptr", "C++11 keyword");
|
||||
addKwd("operator", "C++ keyword");
|
||||
addKwd("or", "C++ keyword");
|
||||
addKwd("or_eq", "C++ keyword");
|
||||
addKwd("override", "C++ common word");
|
||||
addKwd("pascal", "C++ keyword");
|
||||
addKwd("private", "C++ keyword");
|
||||
addKwd("protected", "C++ keyword");
|
||||
addKwd("public", "C++ keyword");
|
||||
addKwd("queue", "C++ common word");
|
||||
addKwd("reference", "C++ common word");
|
||||
addKwd("register", "C++ keyword");
|
||||
addKwd("reinterpret_cast ", "C++ keyword");
|
||||
addKwd("requires", "C++20 keyword");
|
||||
addKwd("restrict", "C++ keyword");
|
||||
addKwd("return", "C++ keyword");
|
||||
addKwd("set", "C++ common word");
|
||||
addKwd("short", "C++ keyword");
|
||||
addKwd("signed", "C++ keyword");
|
||||
addKwd("sizeof", "C++ keyword");
|
||||
addKwd("stack", "C++ common word");
|
||||
addKwd("static", "C++ keyword");
|
||||
addKwd("static_assert", "C++11 keyword");
|
||||
addKwd("static_cast", "C++ keyword");
|
||||
addKwd("struct", "C++ keyword");
|
||||
addKwd("switch", "C++ keyword");
|
||||
addKwd("synchronized", "C++ TM TS keyword");
|
||||
addKwd("template", "C++ keyword");
|
||||
addKwd("this", "C++ keyword");
|
||||
addKwd("thread_local", "C++11 keyword");
|
||||
addKwd("throw", "C++ keyword");
|
||||
addKwd("transaction_safe", "C++ common word");
|
||||
addKwd("transaction_safe_dynamic", "C++ common word");
|
||||
addKwd("true", "C++ keyword");
|
||||
addKwd("try", "C++ keyword");
|
||||
addKwd("type_info", "C++ common word");
|
||||
addKwd("typedef", "C++ keyword");
|
||||
addKwd("typeid", "C++ keyword");
|
||||
addKwd("typename", "C++ keyword");
|
||||
addKwd("uint16_t", "C++ common word");
|
||||
addKwd("uint32_t", "C++ common word");
|
||||
addKwd("uint8_t", "C++ common word");
|
||||
addKwd("union", "C++ keyword");
|
||||
addKwd("unsigned", "C++ keyword");
|
||||
addKwd("using", "C++ keyword");
|
||||
addKwd("vector", "C++ common word");
|
||||
addKwd("virtual", "C++ keyword");
|
||||
addKwd("void", "C++ keyword");
|
||||
addKwd("volatile", "C++ keyword");
|
||||
addKwd("wchar_t", "C++ keyword");
|
||||
addKwd("while", "C++ keyword");
|
||||
addKwd("xor", "C++ keyword");
|
||||
addKwd("xor_eq", "C++ keyword");
|
||||
// This conflicts with header functions, so is ignored
|
||||
//dKwd("final", "C++11 keyword"); // Member function or class head, otherwise not reserved
|
||||
// SystemC
|
||||
addKwd("sc_clock", "SystemC common word");
|
||||
addKwd("sc_in", "SystemC common word");
|
||||
addKwd("sc_inout", "SystemC common word");
|
||||
addKwd("sc_out", "SystemC common word");
|
||||
addKwd("sc_signal", "SystemC common word");
|
||||
addKwd("sensitive", "SystemC common word");
|
||||
addKwd("sensitive_neg", "SystemC common word");
|
||||
addKwd("sensitive_pos", "SystemC common word");
|
||||
addKwd("mutable", "C++ keyword");
|
||||
addKwd("namespace", "C++ keyword");
|
||||
addKwd("near", "C++ common word");
|
||||
addKwd("new", "C++ keyword");
|
||||
addKwd("noexcept", "C++11 keyword");
|
||||
addKwd("not", "C++ keyword");
|
||||
addKwd("not_eq", "C++ keyword");
|
||||
addKwd("nullptr", "C++11 keyword");
|
||||
addKwd("operator", "C++ keyword");
|
||||
addKwd("or", "C++ keyword");
|
||||
addKwd("or_eq", "C++ keyword");
|
||||
addKwd("override", "C++ common word");
|
||||
addKwd("pascal", "C++ keyword");
|
||||
addKwd("private", "C++ keyword");
|
||||
addKwd("protected", "C++ keyword");
|
||||
addKwd("public", "C++ keyword");
|
||||
addKwd("queue", "C++ common word");
|
||||
addKwd("reference", "C++ common word");
|
||||
addKwd("register", "C++ keyword");
|
||||
addKwd("reinterpret_cast ", "C++ keyword");
|
||||
addKwd("requires", "C++20 keyword");
|
||||
addKwd("restrict", "C++ keyword");
|
||||
addKwd("return", "C++ keyword");
|
||||
addKwd("set", "C++ common word");
|
||||
addKwd("short", "C++ keyword");
|
||||
addKwd("signed", "C++ keyword");
|
||||
addKwd("sizeof", "C++ keyword");
|
||||
addKwd("stack", "C++ common word");
|
||||
addKwd("static", "C++ keyword");
|
||||
addKwd("static_assert", "C++11 keyword");
|
||||
addKwd("static_cast", "C++ keyword");
|
||||
addKwd("struct", "C++ keyword");
|
||||
addKwd("switch", "C++ keyword");
|
||||
addKwd("synchronized", "C++ TM TS keyword");
|
||||
addKwd("template", "C++ keyword");
|
||||
addKwd("this", "C++ keyword");
|
||||
addKwd("thread_local", "C++11 keyword");
|
||||
addKwd("throw", "C++ keyword");
|
||||
addKwd("transaction_safe", "C++ common word");
|
||||
addKwd("transaction_safe_dynamic", "C++ common word");
|
||||
addKwd("true", "C++ keyword");
|
||||
addKwd("try", "C++ keyword");
|
||||
addKwd("type_info", "C++ common word");
|
||||
addKwd("typedef", "C++ keyword");
|
||||
addKwd("typeid", "C++ keyword");
|
||||
addKwd("typename", "C++ keyword");
|
||||
addKwd("uint16_t", "C++ common word");
|
||||
addKwd("uint32_t", "C++ common word");
|
||||
addKwd("uint8_t", "C++ common word");
|
||||
addKwd("union", "C++ keyword");
|
||||
addKwd("unsigned", "C++ keyword");
|
||||
addKwd("using", "C++ keyword");
|
||||
addKwd("vector", "C++ common word");
|
||||
addKwd("virtual", "C++ keyword");
|
||||
addKwd("void", "C++ keyword");
|
||||
addKwd("volatile", "C++ keyword");
|
||||
addKwd("wchar_t", "C++ keyword");
|
||||
addKwd("while", "C++ keyword");
|
||||
addKwd("xor", "C++ keyword");
|
||||
addKwd("xor_eq", "C++ keyword");
|
||||
// This conflicts with header functions, so is ignored
|
||||
//dKwd("final", "C++11 keyword");
|
||||
// SystemC
|
||||
addKwd("sc_clock", "SystemC common word");
|
||||
addKwd("sc_in", "SystemC common word");
|
||||
addKwd("sc_inout", "SystemC common word");
|
||||
addKwd("sc_out", "SystemC common word");
|
||||
addKwd("sc_signal", "SystemC common word");
|
||||
addKwd("sensitive", "SystemC common word");
|
||||
addKwd("sensitive_neg", "SystemC common word");
|
||||
addKwd("sensitive_pos", "SystemC common word");
|
||||
}
|
||||
};
|
||||
|
||||
|
|
|
|||
541
src/V3Life.cpp
541
src/V3Life.cpp
|
|
@ -18,12 +18,12 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// LIFE TRANSFORMATIONS:
|
||||
// Build control-flow graph with assignments and var usages
|
||||
// All modules:
|
||||
// ASSIGN(x,...), ASSIGN(x,...) => delete first one
|
||||
// We also track across if statements:
|
||||
// ASSIGN(X,...) IF( ..., ASSIGN(X,...), ASSIGN(X,...)) => deletes first
|
||||
// We don't do the opposite yet though (remove assigns in if followed by outside if)
|
||||
// Build control-flow graph with assignments and var usages
|
||||
// All modules:
|
||||
// ASSIGN(x,...), ASSIGN(x,...) => delete first one
|
||||
// We also track across if statements:
|
||||
// ASSIGN(X,...) IF( ..., ASSIGN(X,...), ASSIGN(X,...)) => deletes first
|
||||
// We don't do the opposite yet though (remove assigns in if followed by outside if)
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -46,24 +46,25 @@
|
|||
class LifeState {
|
||||
// NODE STATE
|
||||
// See below
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser1InUse m_inuser1;
|
||||
|
||||
// STATE
|
||||
public:
|
||||
V3Double0 m_statAssnDel; // Statistic tracking
|
||||
V3Double0 m_statAssnCon; // Statistic tracking
|
||||
V3Double0 m_statAssnDel; // Statistic tracking
|
||||
V3Double0 m_statAssnCon; // Statistic tracking
|
||||
std::vector<AstNode*> m_unlinkps;
|
||||
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
LifeState() {}
|
||||
~LifeState() {
|
||||
V3Stats::addStatSum("Optimizations, Lifetime assign deletions", m_statAssnDel);
|
||||
V3Stats::addStatSum("Optimizations, Lifetime constant prop", m_statAssnCon);
|
||||
for (std::vector<AstNode*>::iterator it = m_unlinkps.begin(); it != m_unlinkps.end(); ++it) {
|
||||
(*it)->unlinkFrBack();
|
||||
(*it)->deleteTree();
|
||||
}
|
||||
V3Stats::addStatSum("Optimizations, Lifetime assign deletions", m_statAssnDel);
|
||||
V3Stats::addStatSum("Optimizations, Lifetime constant prop", m_statAssnCon);
|
||||
for (std::vector<AstNode*>::iterator it = m_unlinkps.begin();
|
||||
it != m_unlinkps.end(); ++it) {
|
||||
(*it)->unlinkFrBack();
|
||||
(*it)->deleteTree();
|
||||
}
|
||||
}
|
||||
// METHODS
|
||||
void pushUnlinkDeletep(AstNode* nodep) { m_unlinkps.push_back(nodep); }
|
||||
|
|
@ -73,16 +74,16 @@ public:
|
|||
// Structure for each variable encountered
|
||||
|
||||
class LifeVarEntry {
|
||||
AstNodeAssign* m_assignp; // Last assignment to this varscope, NULL if no longer relevant
|
||||
AstConst* m_constp; // Known constant value
|
||||
bool m_setBeforeUse; // First access was a set (and thus block above may have a set that can be deleted
|
||||
bool m_everSet; // Was ever assigned (and thus above block may not preserve constant propagation)
|
||||
AstNodeAssign* m_assignp; // Last assignment to this varscope, NULL if no longer relevant
|
||||
AstConst* m_constp; // Known constant value
|
||||
bool m_setBeforeUse; // First access was a set (and thus block above may have a set that can be deleted
|
||||
bool m_everSet; // Was ever assigned (and thus above block may not preserve constant propagation)
|
||||
|
||||
inline void init(bool setBeforeUse) {
|
||||
m_assignp = NULL;
|
||||
m_constp = NULL;
|
||||
m_setBeforeUse = setBeforeUse;
|
||||
m_everSet = false;
|
||||
m_assignp = NULL;
|
||||
m_constp = NULL;
|
||||
m_setBeforeUse = setBeforeUse;
|
||||
m_everSet = false;
|
||||
}
|
||||
public:
|
||||
class SIMPLEASSIGN {};
|
||||
|
|
@ -90,28 +91,28 @@ public:
|
|||
class CONSUMED {};
|
||||
|
||||
LifeVarEntry(SIMPLEASSIGN, AstNodeAssign* assp) {
|
||||
init(true); simpleAssign(assp);
|
||||
init(true); simpleAssign(assp);
|
||||
}
|
||||
explicit LifeVarEntry(COMPLEXASSIGN) {
|
||||
init(false); complexAssign();
|
||||
init(false); complexAssign();
|
||||
}
|
||||
explicit LifeVarEntry(CONSUMED) {
|
||||
init(false); consumed();
|
||||
init(false); consumed();
|
||||
}
|
||||
~LifeVarEntry() {}
|
||||
inline void simpleAssign(AstNodeAssign* assp) { // New simple A=.... assignment
|
||||
m_assignp = assp;
|
||||
m_constp = NULL;
|
||||
m_everSet = true;
|
||||
inline void simpleAssign(AstNodeAssign* assp) { // New simple A=.... assignment
|
||||
m_assignp = assp;
|
||||
m_constp = NULL;
|
||||
m_everSet = true;
|
||||
if (VN_IS(assp->rhsp(), Const)) m_constp = VN_CAST(assp->rhsp(), Const);
|
||||
}
|
||||
inline void complexAssign() { // A[x]=... or some complicated assignment
|
||||
m_assignp = NULL;
|
||||
m_constp = NULL;
|
||||
m_everSet = true;
|
||||
m_assignp = NULL;
|
||||
m_constp = NULL;
|
||||
m_everSet = true;
|
||||
}
|
||||
inline void consumed() { // Rvalue read of A
|
||||
m_assignp = NULL;
|
||||
m_assignp = NULL;
|
||||
}
|
||||
AstNodeAssign* assignp() const { return m_assignp; }
|
||||
AstConst* constNodep() const { return m_constp; }
|
||||
|
|
@ -125,152 +126,152 @@ public:
|
|||
class LifeBlock {
|
||||
// NODE STATE
|
||||
// Cleared each AstIf:
|
||||
// AstVarScope::user1() -> int. Used in combining to detect duplicates
|
||||
// AstVarScope::user1() -> int. Used in combining to detect duplicates
|
||||
|
||||
// LIFE MAP
|
||||
// For each basic block, we'll make a new map of what variables that if/else is changing
|
||||
typedef std::map<AstVarScope*, LifeVarEntry> LifeMap;
|
||||
LifeMap m_map; // Current active lifetime map for current scope
|
||||
LifeBlock* m_aboveLifep; // Upper life, or NULL
|
||||
LifeState* m_statep; // Current global state
|
||||
LifeMap m_map; // Current active lifetime map for current scope
|
||||
LifeBlock* m_aboveLifep; // Upper life, or NULL
|
||||
LifeState* m_statep; // Current global state
|
||||
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
public:
|
||||
LifeBlock(LifeBlock* aboveLifep, LifeState* statep) {
|
||||
m_aboveLifep = aboveLifep; // Null if top
|
||||
m_statep = statep;
|
||||
m_aboveLifep = aboveLifep; // Null if top
|
||||
m_statep = statep;
|
||||
}
|
||||
~LifeBlock() {}
|
||||
// METHODS
|
||||
void checkRemoveAssign(const LifeMap::iterator& it) {
|
||||
AstVar* varp = it->first->varp();
|
||||
LifeVarEntry* entp = &(it->second);
|
||||
if (!varp->isSigPublic()) {
|
||||
// Rather than track what sigs AstUCFunc/AstUCStmt may change,
|
||||
// we just don't optimize any public sigs
|
||||
// Check the var entry, and remove if appropriate
|
||||
if (AstNode* oldassp = entp->assignp()) {
|
||||
UINFO(7," PREV: "<<oldassp<<endl);
|
||||
// Redundant assignment, in same level block
|
||||
// Don't delete it now as it will confuse iteration since it maybe WAY
|
||||
// above our current iteration point.
|
||||
if (debug()>4) oldassp->dumpTree(cout, " REMOVE/SAMEBLK ");
|
||||
entp->complexAssign();
|
||||
m_statep->pushUnlinkDeletep(oldassp); VL_DANGLING(oldassp);
|
||||
++m_statep->m_statAssnDel;
|
||||
}
|
||||
}
|
||||
AstVar* varp = it->first->varp();
|
||||
LifeVarEntry* entp = &(it->second);
|
||||
if (!varp->isSigPublic()) {
|
||||
// Rather than track what sigs AstUCFunc/AstUCStmt may change,
|
||||
// we just don't optimize any public sigs
|
||||
// Check the var entry, and remove if appropriate
|
||||
if (AstNode* oldassp = entp->assignp()) {
|
||||
UINFO(7," PREV: "<<oldassp<<endl);
|
||||
// Redundant assignment, in same level block
|
||||
// Don't delete it now as it will confuse iteration since it maybe WAY
|
||||
// above our current iteration point.
|
||||
if (debug()>4) oldassp->dumpTree(cout, " REMOVE/SAMEBLK ");
|
||||
entp->complexAssign();
|
||||
m_statep->pushUnlinkDeletep(oldassp); VL_DANGLING(oldassp);
|
||||
++m_statep->m_statAssnDel;
|
||||
}
|
||||
}
|
||||
}
|
||||
void simpleAssign(AstVarScope* nodep, AstNodeAssign* assp) {
|
||||
// Do we have a old assignment we can nuke?
|
||||
UINFO(4," ASSIGNof: "<<nodep<<endl);
|
||||
UINFO(7," new: "<<assp<<endl);
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
checkRemoveAssign(it);
|
||||
it->second.simpleAssign(assp);
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep,LifeVarEntry(LifeVarEntry::SIMPLEASSIGN(), assp)));
|
||||
}
|
||||
//lifeDump();
|
||||
// Do we have a old assignment we can nuke?
|
||||
UINFO(4," ASSIGNof: "<<nodep<<endl);
|
||||
UINFO(7," new: "<<assp<<endl);
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
checkRemoveAssign(it);
|
||||
it->second.simpleAssign(assp);
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::SIMPLEASSIGN(), assp)));
|
||||
}
|
||||
//lifeDump();
|
||||
}
|
||||
void complexAssign(AstVarScope* nodep) {
|
||||
UINFO(4," clearof: "<<nodep<<endl);
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
it->second.complexAssign();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep,LifeVarEntry(LifeVarEntry::COMPLEXASSIGN())));
|
||||
}
|
||||
UINFO(4," clearof: "<<nodep<<endl);
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
it->second.complexAssign();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::COMPLEXASSIGN())));
|
||||
}
|
||||
}
|
||||
void varUsageReplace(AstVarScope* nodep, AstVarRef* varrefp) {
|
||||
// Variable rvalue. If it references a constant, we can simply replace it
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
if (AstConst* constp = it->second.constNodep()) {
|
||||
if (!varrefp->varp()->isSigPublic()) {
|
||||
// Aha, variable is constant; substitute in.
|
||||
// We'll later constant propagate
|
||||
UINFO(4," replaceconst: "<<varrefp<<endl);
|
||||
varrefp->replaceWith(constp->cloneTree(false));
|
||||
varrefp->deleteTree(); VL_DANGLING(varrefp);
|
||||
++m_statep->m_statAssnCon;
|
||||
return; // **DONE, no longer a var reference**
|
||||
}
|
||||
}
|
||||
UINFO(4," usage: "<<nodep<<endl);
|
||||
it->second.consumed();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep,LifeVarEntry(LifeVarEntry::CONSUMED())));
|
||||
}
|
||||
// Variable rvalue. If it references a constant, we can simply replace it
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
if (AstConst* constp = it->second.constNodep()) {
|
||||
if (!varrefp->varp()->isSigPublic()) {
|
||||
// Aha, variable is constant; substitute in.
|
||||
// We'll later constant propagate
|
||||
UINFO(4," replaceconst: "<<varrefp<<endl);
|
||||
varrefp->replaceWith(constp->cloneTree(false));
|
||||
varrefp->deleteTree(); VL_DANGLING(varrefp);
|
||||
++m_statep->m_statAssnCon;
|
||||
return; // **DONE, no longer a var reference**
|
||||
}
|
||||
}
|
||||
UINFO(4," usage: "<<nodep<<endl);
|
||||
it->second.consumed();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::CONSUMED())));
|
||||
}
|
||||
}
|
||||
void complexAssignFind(AstVarScope* nodep) {
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
UINFO(4," casfind: "<<it->first<<endl);
|
||||
it->second.complexAssign();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep,LifeVarEntry(LifeVarEntry::COMPLEXASSIGN())));
|
||||
}
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
UINFO(4," casfind: "<<it->first<<endl);
|
||||
it->second.complexAssign();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::COMPLEXASSIGN())));
|
||||
}
|
||||
}
|
||||
void consumedFind(AstVarScope* nodep) {
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
it->second.consumed();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep,LifeVarEntry(LifeVarEntry::CONSUMED())));
|
||||
}
|
||||
LifeMap::iterator it = m_map.find(nodep);
|
||||
if (it != m_map.end()) {
|
||||
it->second.consumed();
|
||||
} else {
|
||||
m_map.insert(make_pair(nodep, LifeVarEntry(LifeVarEntry::CONSUMED())));
|
||||
}
|
||||
}
|
||||
void lifeToAbove() {
|
||||
// Any varrefs under a if/else branch affect statements outside and after the if/else
|
||||
if (!m_aboveLifep) v3fatalSrc("Pushing life when already at the top level");
|
||||
for (LifeMap::iterator it = m_map.begin(); it!=m_map.end(); ++it) {
|
||||
AstVarScope* nodep = it->first;
|
||||
m_aboveLifep->complexAssignFind(nodep);
|
||||
if (it->second.everSet()) {
|
||||
// Record there may be an assignment, so we don't constant propagate across the if.
|
||||
complexAssignFind(nodep);
|
||||
} else {
|
||||
// Record consumption, so we don't eliminate earlier assignments
|
||||
consumedFind(nodep);
|
||||
}
|
||||
}
|
||||
// Any varrefs under a if/else branch affect statements outside and after the if/else
|
||||
if (!m_aboveLifep) v3fatalSrc("Pushing life when already at the top level");
|
||||
for (LifeMap::iterator it = m_map.begin(); it!=m_map.end(); ++it) {
|
||||
AstVarScope* nodep = it->first;
|
||||
m_aboveLifep->complexAssignFind(nodep);
|
||||
if (it->second.everSet()) {
|
||||
// Record there may be an assignment, so we don't constant propagate across the if.
|
||||
complexAssignFind(nodep);
|
||||
} else {
|
||||
// Record consumption, so we don't eliminate earlier assignments
|
||||
consumedFind(nodep);
|
||||
}
|
||||
}
|
||||
}
|
||||
void dualBranch(LifeBlock* life1p, LifeBlock* life2p) {
|
||||
// Find any common sets on both branches of IF and propagate upwards
|
||||
//life1p->lifeDump();
|
||||
//life2p->lifeDump();
|
||||
AstNode::user1ClearTree(); // user1p() used on entire tree
|
||||
for (LifeMap::iterator it = life1p->m_map.begin(); it!=life1p->m_map.end(); ++it) {
|
||||
// When the if branch sets a var before it's used, mark that variable
|
||||
if (it->second.setBeforeUse()) it->first->user1(1);
|
||||
}
|
||||
for (LifeMap::iterator it = life2p->m_map.begin(); it!=life2p->m_map.end(); ++it) {
|
||||
// When the else branch sets a var before it's used
|
||||
AstVarScope* nodep = it->first;
|
||||
if (it->second.setBeforeUse() && nodep->user1()) {
|
||||
// Both branches set the var, we can remove the assignment before the IF.
|
||||
UINFO(4,"DUALBRANCH "<<nodep<<endl);
|
||||
LifeMap::iterator itab = m_map.find(nodep);
|
||||
if (itab != m_map.end()) {
|
||||
checkRemoveAssign(itab);
|
||||
}
|
||||
}
|
||||
}
|
||||
//this->lifeDump();
|
||||
// Find any common sets on both branches of IF and propagate upwards
|
||||
//life1p->lifeDump();
|
||||
//life2p->lifeDump();
|
||||
AstNode::user1ClearTree(); // user1p() used on entire tree
|
||||
for (LifeMap::iterator it = life1p->m_map.begin(); it!=life1p->m_map.end(); ++it) {
|
||||
// When the if branch sets a var before it's used, mark that variable
|
||||
if (it->second.setBeforeUse()) it->first->user1(1);
|
||||
}
|
||||
for (LifeMap::iterator it = life2p->m_map.begin(); it!=life2p->m_map.end(); ++it) {
|
||||
// When the else branch sets a var before it's used
|
||||
AstVarScope* nodep = it->first;
|
||||
if (it->second.setBeforeUse() && nodep->user1()) {
|
||||
// Both branches set the var, we can remove the assignment before the IF.
|
||||
UINFO(4,"DUALBRANCH "<<nodep<<endl);
|
||||
LifeMap::iterator itab = m_map.find(nodep);
|
||||
if (itab != m_map.end()) {
|
||||
checkRemoveAssign(itab);
|
||||
}
|
||||
}
|
||||
}
|
||||
//this->lifeDump();
|
||||
}
|
||||
// DEBUG
|
||||
void lifeDump() {
|
||||
UINFO(5, " LifeMap:"<<endl);
|
||||
for (LifeMap::iterator it = m_map.begin(); it!=m_map.end(); ++it) {
|
||||
UINFO(5, " Ent: "
|
||||
<<(it->second.setBeforeUse()?"[F] ":" ")
|
||||
<<it->first<<endl);
|
||||
if (it->second.assignp()) {
|
||||
UINFO(5, " Ass: "<<it->second.assignp()<<endl);
|
||||
}
|
||||
}
|
||||
UINFO(5, " LifeMap:"<<endl);
|
||||
for (LifeMap::iterator it = m_map.begin(); it!=m_map.end(); ++it) {
|
||||
UINFO(5, " Ent: "
|
||||
<<(it->second.setBeforeUse()?"[F] ":" ")
|
||||
<<it->first<<endl);
|
||||
if (it->second.assignp()) {
|
||||
UINFO(5, " Ass: "<<it->second.assignp()<<endl);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -280,164 +281,164 @@ public:
|
|||
class LifeVisitor : public AstNVisitor {
|
||||
private:
|
||||
// STATE
|
||||
LifeState* m_statep; // Current state
|
||||
bool m_sideEffect; // Side effects discovered in assign RHS
|
||||
bool m_noopt; // Disable optimization of variables in this block
|
||||
bool m_tracingCall; // Iterating into a CCall to a CFunc
|
||||
LifeState* m_statep; // Current state
|
||||
bool m_sideEffect; // Side effects discovered in assign RHS
|
||||
bool m_noopt; // Disable optimization of variables in this block
|
||||
bool m_tracingCall; // Iterating into a CCall to a CFunc
|
||||
|
||||
// LIFE MAP
|
||||
// For each basic block, we'll make a new map of what variables that if/else is changing
|
||||
typedef std::map<AstVarScope*, LifeVarEntry> LifeMap;
|
||||
// cppcheck-suppress memleak // cppcheck bug - it is deleted
|
||||
LifeBlock* m_lifep; // Current active lifetime map for current scope
|
||||
LifeBlock* m_lifep; // Current active lifetime map for current scope
|
||||
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstVarRef* nodep) {
|
||||
// Consumption/generation of a variable,
|
||||
// it's used so can't elim assignment before this use.
|
||||
if (!nodep->varScopep()) nodep->v3fatalSrc("NULL");
|
||||
//
|
||||
AstVarScope* vscp = nodep->varScopep();
|
||||
if (!vscp) nodep->v3fatalSrc("Scope not assigned");
|
||||
if (nodep->lvalue()) {
|
||||
m_lifep->complexAssign(vscp);
|
||||
} else {
|
||||
m_lifep->varUsageReplace(vscp, nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
// Consumption/generation of a variable,
|
||||
// it's used so can't elim assignment before this use.
|
||||
if (!nodep->varScopep()) nodep->v3fatalSrc("NULL");
|
||||
//
|
||||
AstVarScope* vscp = nodep->varScopep();
|
||||
if (!vscp) nodep->v3fatalSrc("Scope not assigned");
|
||||
if (nodep->lvalue()) {
|
||||
m_lifep->complexAssign(vscp);
|
||||
} else {
|
||||
m_lifep->varUsageReplace(vscp, nodep); VL_DANGLING(nodep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeAssign* nodep) {
|
||||
// Collect any used variables first, as lhs may also be on rhs
|
||||
// Similar code in V3Dead
|
||||
vluint64_t lastEdit = AstNode::editCountGbl(); // When it was last edited
|
||||
m_sideEffect = false;
|
||||
// Collect any used variables first, as lhs may also be on rhs
|
||||
// Similar code in V3Dead
|
||||
vluint64_t lastEdit = AstNode::editCountGbl(); // When it was last edited
|
||||
m_sideEffect = false;
|
||||
iterateAndNextNull(nodep->rhsp());
|
||||
if (lastEdit != AstNode::editCountGbl()) {
|
||||
// We changed something, try to constant propagate, but don't delete the
|
||||
// assignment as we still need nodep to remain.
|
||||
V3Const::constifyEdit(nodep->rhsp()); // rhsp may change
|
||||
}
|
||||
// Has to be direct assignment without any EXTRACTing.
|
||||
if (lastEdit != AstNode::editCountGbl()) {
|
||||
// We changed something, try to constant propagate, but don't delete the
|
||||
// assignment as we still need nodep to remain.
|
||||
V3Const::constifyEdit(nodep->rhsp()); // rhsp may change
|
||||
}
|
||||
// Has to be direct assignment without any EXTRACTing.
|
||||
if (VN_IS(nodep->lhsp(), VarRef) && !m_sideEffect && !m_noopt) {
|
||||
AstVarScope* vscp = VN_CAST(nodep->lhsp(), VarRef)->varScopep();
|
||||
if (!vscp) nodep->v3fatalSrc("Scope lost on variable");
|
||||
m_lifep->simpleAssign(vscp, nodep);
|
||||
} else {
|
||||
if (!vscp) nodep->v3fatalSrc("Scope lost on variable");
|
||||
m_lifep->simpleAssign(vscp, nodep);
|
||||
} else {
|
||||
iterateAndNextNull(nodep->lhsp());
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstAssignDly* nodep) {
|
||||
// Don't treat as normal assign; V3Life doesn't understand time sense
|
||||
// Don't treat as normal assign; V3Life doesn't understand time sense
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
//---- Track control flow changes
|
||||
virtual void visit(AstNodeIf* nodep) {
|
||||
UINFO(4," IF "<<nodep<<endl);
|
||||
// Condition is part of PREVIOUS block
|
||||
UINFO(4," IF "<<nodep<<endl);
|
||||
// Condition is part of PREVIOUS block
|
||||
iterateAndNextNull(nodep->condp());
|
||||
LifeBlock* prevLifep = m_lifep;
|
||||
LifeBlock* prevLifep = m_lifep;
|
||||
LifeBlock* ifLifep = new LifeBlock(prevLifep, m_statep);
|
||||
LifeBlock* elseLifep = new LifeBlock(prevLifep, m_statep);
|
||||
{
|
||||
m_lifep = ifLifep;
|
||||
{
|
||||
m_lifep = ifLifep;
|
||||
iterateAndNextNull(nodep->ifsp());
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
{
|
||||
m_lifep = elseLifep;
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
{
|
||||
m_lifep = elseLifep;
|
||||
iterateAndNextNull(nodep->elsesp());
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
UINFO(4," join "<<endl);
|
||||
// Find sets on both flows
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
UINFO(4," join "<<endl);
|
||||
// Find sets on both flows
|
||||
m_lifep->dualBranch(ifLifep, elseLifep);
|
||||
// For the next assignments, clear any variables that were read or written in the block
|
||||
ifLifep->lifeToAbove();
|
||||
elseLifep->lifeToAbove();
|
||||
delete ifLifep;
|
||||
delete elseLifep;
|
||||
// For the next assignments, clear any variables that were read or written in the block
|
||||
ifLifep->lifeToAbove();
|
||||
elseLifep->lifeToAbove();
|
||||
delete ifLifep;
|
||||
delete elseLifep;
|
||||
}
|
||||
|
||||
virtual void visit(AstWhile* nodep) {
|
||||
// While's are a problem, as we don't allow loops in the graph. We
|
||||
// may go around the cond/body multiple times. Thus a
|
||||
// lifelication just in the body is ok, but we can't delete an
|
||||
// assignment in the body that's used in the cond. (And otherwise
|
||||
// would because it only appears used after-the-fact. So, we model
|
||||
// it as a IF statement, and just don't allow elimination of
|
||||
// variables across the body.
|
||||
LifeBlock* prevLifep = m_lifep;
|
||||
// While's are a problem, as we don't allow loops in the graph. We
|
||||
// may go around the cond/body multiple times. Thus a
|
||||
// lifelication just in the body is ok, but we can't delete an
|
||||
// assignment in the body that's used in the cond. (And otherwise
|
||||
// would because it only appears used after-the-fact. So, we model
|
||||
// it as a IF statement, and just don't allow elimination of
|
||||
// variables across the body.
|
||||
LifeBlock* prevLifep = m_lifep;
|
||||
LifeBlock* condLifep = new LifeBlock(prevLifep, m_statep);
|
||||
LifeBlock* bodyLifep = new LifeBlock(prevLifep, m_statep);
|
||||
{
|
||||
m_lifep = condLifep;
|
||||
{
|
||||
m_lifep = condLifep;
|
||||
iterateAndNextNull(nodep->precondsp());
|
||||
iterateAndNextNull(nodep->condp());
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
{
|
||||
m_lifep = bodyLifep;
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
{
|
||||
m_lifep = bodyLifep;
|
||||
iterateAndNextNull(nodep->bodysp());
|
||||
iterateAndNextNull(nodep->incsp());
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
UINFO(4," joinfor"<<endl);
|
||||
// For the next assignments, clear any variables that were read or written in the block
|
||||
condLifep->lifeToAbove();
|
||||
bodyLifep->lifeToAbove();
|
||||
delete condLifep;
|
||||
delete bodyLifep;
|
||||
m_lifep = prevLifep;
|
||||
}
|
||||
UINFO(4," joinfor"<<endl);
|
||||
// For the next assignments, clear any variables that were read or written in the block
|
||||
condLifep->lifeToAbove();
|
||||
bodyLifep->lifeToAbove();
|
||||
delete condLifep;
|
||||
delete bodyLifep;
|
||||
}
|
||||
virtual void visit(AstJumpLabel* nodep) {
|
||||
// As with While's we can't predict if a JumpGo will kill us or not
|
||||
// It's worse though as an IF(..., JUMPGO) may change the control flow.
|
||||
// Just don't optimize blocks with labels; they're rare - so far.
|
||||
LifeBlock* prevLifep = m_lifep;
|
||||
// As with While's we can't predict if a JumpGo will kill us or not
|
||||
// It's worse though as an IF(..., JUMPGO) may change the control flow.
|
||||
// Just don't optimize blocks with labels; they're rare - so far.
|
||||
LifeBlock* prevLifep = m_lifep;
|
||||
LifeBlock* bodyLifep = new LifeBlock(prevLifep, m_statep);
|
||||
bool prev_noopt = m_noopt;
|
||||
{
|
||||
m_lifep = bodyLifep;
|
||||
m_noopt = true;
|
||||
bool prev_noopt = m_noopt;
|
||||
{
|
||||
m_lifep = bodyLifep;
|
||||
m_noopt = true;
|
||||
iterateAndNextNull(nodep->stmtsp());
|
||||
m_lifep = prevLifep;
|
||||
m_noopt = prev_noopt;
|
||||
}
|
||||
UINFO(4," joinjump"<<endl);
|
||||
// For the next assignments, clear any variables that were read or written in the block
|
||||
bodyLifep->lifeToAbove();
|
||||
delete bodyLifep;
|
||||
m_lifep = prevLifep;
|
||||
m_noopt = prev_noopt;
|
||||
}
|
||||
UINFO(4," joinjump"<<endl);
|
||||
// For the next assignments, clear any variables that were read or written in the block
|
||||
bodyLifep->lifeToAbove();
|
||||
delete bodyLifep;
|
||||
}
|
||||
virtual void visit(AstCCall* nodep) {
|
||||
//UINFO(4," CCALL "<<nodep<<endl);
|
||||
//UINFO(4," CCALL "<<nodep<<endl);
|
||||
iterateChildren(nodep);
|
||||
// Enter the function and trace it
|
||||
if (!nodep->funcp()->entryPoint()) { // else is non-inline or public function we optimize separately
|
||||
// Enter the function and trace it
|
||||
if (!nodep->funcp()->entryPoint()) { // else is non-inline or public function we optimize separately
|
||||
m_tracingCall = true;
|
||||
iterate(nodep->funcp());
|
||||
}
|
||||
}
|
||||
}
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
//UINFO(4," CCALL "<<nodep<<endl);
|
||||
//UINFO(4," CCALL "<<nodep<<endl);
|
||||
if (!m_tracingCall && !nodep->entryPoint()) return;
|
||||
m_tracingCall = false;
|
||||
if (nodep->dpiImport() && !nodep->pure()) {
|
||||
m_sideEffect = true; // If appears on assign RHS, don't ever delete the assignment
|
||||
}
|
||||
if (nodep->dpiImport() && !nodep->pure()) {
|
||||
m_sideEffect = true; // If appears on assign RHS, don't ever delete the assignment
|
||||
}
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstUCFunc* nodep) {
|
||||
m_sideEffect = true; // If appears on assign RHS, don't ever delete the assignment
|
||||
m_sideEffect = true; // If appears on assign RHS, don't ever delete the assignment
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
virtual void visit(AstCMath* nodep) {
|
||||
m_sideEffect = true; // If appears on assign RHS, don't ever delete the assignment
|
||||
m_sideEffect = true; // If appears on assign RHS, don't ever delete the assignment
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
virtual void visit(AstVar*) {} // Don't want varrefs under it
|
||||
virtual void visit(AstVar*) {} // Don't want varrefs under it
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
|
@ -445,19 +446,19 @@ private:
|
|||
public:
|
||||
// CONSTRUCTORS
|
||||
LifeVisitor(AstNode* nodep, LifeState* statep) {
|
||||
UINFO(4," LifeVisitor on "<<nodep<<endl);
|
||||
m_statep = statep;
|
||||
m_sideEffect = false;
|
||||
m_noopt = false;
|
||||
UINFO(4," LifeVisitor on "<<nodep<<endl);
|
||||
m_statep = statep;
|
||||
m_sideEffect = false;
|
||||
m_noopt = false;
|
||||
m_tracingCall = false;
|
||||
{
|
||||
{
|
||||
m_lifep = new LifeBlock(NULL, m_statep);
|
||||
iterate(nodep);
|
||||
if (m_lifep) { delete m_lifep; m_lifep=NULL; }
|
||||
}
|
||||
if (m_lifep) { delete m_lifep; m_lifep = NULL; }
|
||||
}
|
||||
}
|
||||
virtual ~LifeVisitor() {
|
||||
if (m_lifep) { delete m_lifep; m_lifep=NULL; }
|
||||
if (m_lifep) { delete m_lifep; m_lifep = NULL; }
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -468,37 +469,37 @@ class LifeTopVisitor : public AstNVisitor {
|
|||
// finding code within.
|
||||
private:
|
||||
// STATE
|
||||
LifeState* m_statep; // Current state
|
||||
LifeState* m_statep; // Current state
|
||||
|
||||
// VISITORS
|
||||
virtual void visit(AstCFunc* nodep) {
|
||||
if (nodep->entryPoint()) {
|
||||
// Usage model 1: Simulate all C code, doing lifetime analysis
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
}
|
||||
if (nodep->entryPoint()) {
|
||||
// Usage model 1: Simulate all C code, doing lifetime analysis
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
}
|
||||
}
|
||||
virtual void visit(AstAlways* nodep) {
|
||||
// Usage model 2: Cleanup basic blocks
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
// Usage model 2: Cleanup basic blocks
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
}
|
||||
virtual void visit(AstInitial* nodep) {
|
||||
// Usage model 2: Cleanup basic blocks
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
// Usage model 2: Cleanup basic blocks
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
}
|
||||
virtual void visit(AstFinal* nodep) {
|
||||
// Usage model 2: Cleanup basic blocks
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
// Usage model 2: Cleanup basic blocks
|
||||
LifeVisitor visitor (nodep, m_statep);
|
||||
}
|
||||
virtual void visit(AstVar*) {} // Accelerate
|
||||
virtual void visit(AstNodeStmt*) {} // Accelerate
|
||||
virtual void visit(AstNodeMath*) {} // Accelerate
|
||||
virtual void visit(AstVar*) {} // Accelerate
|
||||
virtual void visit(AstNodeStmt*) {} // Accelerate
|
||||
virtual void visit(AstNodeMath*) {} // Accelerate
|
||||
virtual void visit(AstNode* nodep) {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
public:
|
||||
// CONSTRUCTORS
|
||||
LifeTopVisitor(AstNetlist* nodep, LifeState* statep) {
|
||||
m_statep = statep;
|
||||
m_statep = statep;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~LifeTopVisitor() {}
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void lifeAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
// ASSIGN(Vdly, a)
|
||||
// ... {no reads or writes of a after the first write to Vdly}
|
||||
// ... {no reads of a after the first write to Vdly}
|
||||
// ASSIGNPOST(Vdly,tmp)
|
||||
// ASSIGNPOST(Vdly, tmp)
|
||||
//
|
||||
//*************************************************************************
|
||||
|
||||
|
|
@ -51,7 +51,8 @@ private:
|
|||
|
||||
// NODE STATE
|
||||
// INPUT:
|
||||
// AstVarScope::user4p() -> AstVarScope*, If set, replace this varscope with specified new one
|
||||
// AstVarScope::user4p() -> AstVarScope*, If set, replace this
|
||||
// varscope with specified new one
|
||||
// STATE
|
||||
// METHODS
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
|
@ -223,7 +224,7 @@ private:
|
|||
// Proof (1)
|
||||
const std::set<LifeLocation>& dlyVarReads = m_reads[dlyVarp];
|
||||
if (!dlyVarReads.empty()) {
|
||||
continue; // do not scrunch, go to next LifePostLocation
|
||||
continue; // do not scrunch, go to next LifePostLocation
|
||||
}
|
||||
|
||||
// Proof (2)
|
||||
|
|
|
|||
|
|
@ -34,4 +34,4 @@ public:
|
|||
static void lifepostAll(AstNetlist* nodep);
|
||||
};
|
||||
|
||||
#endif // Guard
|
||||
#endif // Guard
|
||||
|
|
|
|||
|
|
@ -18,13 +18,13 @@
|
|||
//
|
||||
//*************************************************************************
|
||||
// NO EDITS: Don't replace or delete nodes, as the parser symbol table
|
||||
// has pointers into the ast tree.
|
||||
// has pointers into the ast tree.
|
||||
//
|
||||
// LINK TRANSFORMATIONS:
|
||||
// Top-down traversal
|
||||
// Cells:
|
||||
// Read module if needed
|
||||
// Link to module that instantiates it
|
||||
// Top-down traversal
|
||||
// Cells:
|
||||
// Read module if needed
|
||||
// Link to module that instantiates it
|
||||
//*************************************************************************
|
||||
|
||||
#include "config_build.h"
|
||||
|
|
@ -57,31 +57,33 @@ class LinkCellsVertex : public V3GraphVertex {
|
|||
AstNodeModule* m_modp;
|
||||
public:
|
||||
LinkCellsVertex(V3Graph* graphp, AstNodeModule* modp)
|
||||
: V3GraphVertex(graphp), m_modp(modp) {}
|
||||
: V3GraphVertex(graphp), m_modp(modp) {}
|
||||
virtual ~LinkCellsVertex() {}
|
||||
AstNodeModule* modp() const { return m_modp; }
|
||||
virtual string name() const { return modp()->name(); }
|
||||
virtual FileLine* fileline() const { return modp()->fileline(); }
|
||||
// Recursive modules get space for maximum recursion
|
||||
virtual uint32_t rankAdder() const { return m_modp->recursiveClone() ? (1+v3Global.opt.moduleRecursionDepth()) : 1; }
|
||||
virtual uint32_t rankAdder() const {
|
||||
return m_modp->recursiveClone() ? (1+v3Global.opt.moduleRecursionDepth()) : 1;
|
||||
}
|
||||
};
|
||||
|
||||
class LibraryVertex : public V3GraphVertex {
|
||||
public:
|
||||
explicit LibraryVertex(V3Graph* graphp)
|
||||
: V3GraphVertex(graphp) {}
|
||||
: V3GraphVertex(graphp) {}
|
||||
virtual ~LibraryVertex() {}
|
||||
virtual string name() const { return "*LIBRARY*"; }
|
||||
};
|
||||
|
||||
void LinkCellsGraph::loopsMessageCb(V3GraphVertex* vertexp) {
|
||||
if (LinkCellsVertex* vvertexp = dynamic_cast<LinkCellsVertex*>(vertexp)) {
|
||||
vvertexp->modp()->v3error("Unsupported: Recursive multiple modules (module instantiates something leading back to itself): "
|
||||
<<vvertexp->modp()->prettyName());
|
||||
vvertexp->modp()->v3error("Note self-recursion (module instantiating itself directly) is supported.");
|
||||
V3Error::abortIfErrors();
|
||||
vvertexp->modp()->v3error("Unsupported: Recursive multiple modules (module instantiates something leading back to itself): "
|
||||
<<vvertexp->modp()->prettyName());
|
||||
vvertexp->modp()->v3error("Note self-recursion (module instantiating itself directly) is supported.");
|
||||
V3Error::abortIfErrors();
|
||||
} else { // Everything should match above, but...
|
||||
v3fatalSrc("Recursive instantiations");
|
||||
v3fatalSrc("Recursive instantiations");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -92,380 +94,395 @@ class LinkCellsVisitor : public AstNVisitor {
|
|||
private:
|
||||
// NODE STATE
|
||||
// Entire netlist:
|
||||
// AstNodeModule::user1p() // V3GraphVertex* Vertex describing this module
|
||||
// AstNodeModule::user2p() // AstNodeModule* clone used for de-recursing
|
||||
// AstCell::user1p() // ==V3NodeModule* if done, != if unprocessed
|
||||
// AstCell::user2() // bool clone renaming completed
|
||||
// AstNodeModule::user1p() // V3GraphVertex* Vertex describing this module
|
||||
// AstNodeModule::user2p() // AstNodeModule* clone used for de-recursing
|
||||
// AstCell::user1p() // ==V3NodeModule* if done, != if unprocessed
|
||||
// AstCell::user2() // bool clone renaming completed
|
||||
// Allocated across all readFiles in V3Global::readFiles:
|
||||
// AstNode::user4p() // VSymEnt* Package and typedef symbol names
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser2InUse m_inuser2;
|
||||
// AstNode::user4p() // VSymEnt* Package and typedef symbol names
|
||||
AstUser1InUse m_inuser1;
|
||||
AstUser2InUse m_inuser2;
|
||||
|
||||
// STATE
|
||||
V3InFilter* m_filterp; // Parser filter
|
||||
V3ParseSym* m_parseSymp; // Parser symbol table
|
||||
V3InFilter* m_filterp; // Parser filter
|
||||
V3ParseSym* m_parseSymp; // Parser symbol table
|
||||
|
||||
// Below state needs to be preserved between each module call.
|
||||
AstNodeModule* m_modp; // Current module
|
||||
VSymGraph m_mods; // Symbol table of all module names
|
||||
LinkCellsGraph m_graph; // Linked graph of all cell interconnects
|
||||
LibraryVertex* m_libVertexp; // Vertex at root of all libraries
|
||||
V3GraphVertex* m_topVertexp; // Vertex of top module
|
||||
AstNodeModule* m_modp; // Current module
|
||||
VSymGraph m_mods; // Symbol table of all module names
|
||||
LinkCellsGraph m_graph; // Linked graph of all cell interconnects
|
||||
LibraryVertex* m_libVertexp; // Vertex at root of all libraries
|
||||
V3GraphVertex* m_topVertexp; // Vertex of top module
|
||||
vl_unordered_set<string> m_declfnWarned; // Files we issued DECLFILENAME on
|
||||
|
||||
VL_DEBUG_FUNC; // Declare debug()
|
||||
|
||||
// METHODS
|
||||
V3GraphVertex* vertex(AstNodeModule* nodep) {
|
||||
// Return corresponding vertex for this module
|
||||
if (!nodep->user1p()) {
|
||||
nodep->user1p(new LinkCellsVertex(&m_graph, nodep));
|
||||
}
|
||||
return (nodep->user1u().toGraphVertex());
|
||||
// Return corresponding vertex for this module
|
||||
if (!nodep->user1p()) {
|
||||
nodep->user1p(new LinkCellsVertex(&m_graph, nodep));
|
||||
}
|
||||
return (nodep->user1u().toGraphVertex());
|
||||
}
|
||||
|
||||
AstNodeModule* findModuleSym(const string& modName) {
|
||||
VSymEnt* foundp = m_mods.rootp()->findIdFallback(modName);
|
||||
if (!foundp) return NULL;
|
||||
VSymEnt* foundp = m_mods.rootp()->findIdFallback(modName);
|
||||
if (!foundp) return NULL;
|
||||
else return VN_CAST(foundp->nodep(), NodeModule);
|
||||
}
|
||||
|
||||
AstNodeModule* resolveModule(AstNode* nodep, const string& modName) {
|
||||
AstNodeModule* modp = findModuleSym(modName);
|
||||
if (!modp) {
|
||||
// Read-subfile
|
||||
// If file not found, make AstNotFoundModule, rather than error out.
|
||||
// We'll throw the error when we know the module will really be needed.
|
||||
string prettyName = AstNode::prettyName(modName);
|
||||
V3Parse parser (v3Global.rootp(), m_filterp, m_parseSymp);
|
||||
parser.parseFile(nodep->fileline(), prettyName, false, "");
|
||||
V3Error::abortIfErrors();
|
||||
// We've read new modules, grab new pointers to their names
|
||||
readModNames();
|
||||
// Check again
|
||||
modp = findModuleSym(modName);
|
||||
if (!modp) {
|
||||
// This shouldn't throw a message as parseFile will create a AstNotFoundModule for us
|
||||
nodep->v3error("Can't resolve module reference: "<<prettyName);
|
||||
}
|
||||
}
|
||||
return modp;
|
||||
AstNodeModule* modp = findModuleSym(modName);
|
||||
if (!modp) {
|
||||
// Read-subfile
|
||||
// If file not found, make AstNotFoundModule, rather than error out.
|
||||
// We'll throw the error when we know the module will really be needed.
|
||||
string prettyName = AstNode::prettyName(modName);
|
||||
V3Parse parser (v3Global.rootp(), m_filterp, m_parseSymp);
|
||||
parser.parseFile(nodep->fileline(), prettyName, false, "");
|
||||
V3Error::abortIfErrors();
|
||||
// We've read new modules, grab new pointers to their names
|
||||
readModNames();
|
||||
// Check again
|
||||
modp = findModuleSym(modName);
|
||||
if (!modp) {
|
||||
// This shouldn't throw a message as parseFile will create
|
||||
// a AstNotFoundModule for us
|
||||
nodep->v3error("Can't resolve module reference: "<<prettyName);
|
||||
}
|
||||
}
|
||||
return modp;
|
||||
}
|
||||
|
||||
// VISITs
|
||||
virtual void visit(AstNetlist* nodep) {
|
||||
AstNode::user1ClearTree();
|
||||
readModNames();
|
||||
AstNode::user1ClearTree();
|
||||
readModNames();
|
||||
iterateChildren(nodep);
|
||||
// Find levels in graph
|
||||
m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue);
|
||||
m_graph.dumpDotFilePrefixed("linkcells");
|
||||
m_graph.rank();
|
||||
for (V3GraphVertex* itp = m_graph.verticesBeginp(); itp; itp=itp->verticesNextp()) {
|
||||
if (LinkCellsVertex* vvertexp = dynamic_cast<LinkCellsVertex*>(itp)) {
|
||||
// +1 so we leave level 1 for the new wrapper we'll make in a moment
|
||||
AstNodeModule* modp = vvertexp->modp();
|
||||
modp->level(vvertexp->rank()+1);
|
||||
if (vvertexp == m_topVertexp && modp->level() != 2) {
|
||||
AstNodeModule* abovep = NULL;
|
||||
if (V3GraphEdge* edgep = vvertexp->inBeginp()) {
|
||||
if (LinkCellsVertex* eFromVertexp = dynamic_cast<LinkCellsVertex*>(edgep->fromp())) {
|
||||
abovep = eFromVertexp->modp();
|
||||
}
|
||||
}
|
||||
v3error("Specified --top-module '"<<v3Global.opt.topModule()
|
||||
<<"' isn't at the top level, it's under another cell '"
|
||||
<<(abovep ? abovep->prettyName() : "UNKNOWN")<<"'");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (v3Global.opt.topModule()!=""
|
||||
&& !m_topVertexp) {
|
||||
v3error("Specified --top-module '"<<v3Global.opt.topModule()<<"' was not found in design.");
|
||||
}
|
||||
// Find levels in graph
|
||||
m_graph.removeRedundantEdges(&V3GraphEdge::followAlwaysTrue);
|
||||
m_graph.dumpDotFilePrefixed("linkcells");
|
||||
m_graph.rank();
|
||||
for (V3GraphVertex* itp = m_graph.verticesBeginp(); itp; itp=itp->verticesNextp()) {
|
||||
if (LinkCellsVertex* vvertexp = dynamic_cast<LinkCellsVertex*>(itp)) {
|
||||
// +1 so we leave level 1 for the new wrapper we'll make in a moment
|
||||
AstNodeModule* modp = vvertexp->modp();
|
||||
modp->level(vvertexp->rank()+1);
|
||||
if (vvertexp == m_topVertexp && modp->level() != 2) {
|
||||
AstNodeModule* abovep = NULL;
|
||||
if (V3GraphEdge* edgep = vvertexp->inBeginp()) {
|
||||
if (LinkCellsVertex* eFromVertexp
|
||||
= dynamic_cast<LinkCellsVertex*>(edgep->fromp())) {
|
||||
abovep = eFromVertexp->modp();
|
||||
}
|
||||
}
|
||||
v3error("Specified --top-module '"<<v3Global.opt.topModule()
|
||||
<<"' isn't at the top level, it's under another cell '"
|
||||
<<(abovep ? abovep->prettyName() : "UNKNOWN")<<"'");
|
||||
}
|
||||
}
|
||||
}
|
||||
if (v3Global.opt.topModule()!=""
|
||||
&& !m_topVertexp) {
|
||||
v3error("Specified --top-module '"<<v3Global.opt.topModule()<<"' was not found in design.");
|
||||
}
|
||||
}
|
||||
virtual void visit(AstNodeModule* nodep) {
|
||||
// Module: Pick up modnames, so we can resolve cells later
|
||||
m_modp = nodep;
|
||||
UINFO(2,"Link Module: "<<nodep<<endl);
|
||||
if (nodep->fileline()->filebasenameNoExt() != nodep->prettyName()
|
||||
&& !v3Global.opt.isLibraryFile(nodep->fileline()->filename())
|
||||
&& !nodep->recursiveClone()
|
||||
&& !nodep->internal()) {
|
||||
// We only complain once per file, otherwise library-like files have a huge mess of warnings
|
||||
if (m_declfnWarned.find(nodep->fileline()->filename()) == m_declfnWarned.end()) {
|
||||
m_declfnWarned.insert(nodep->fileline()->filename());
|
||||
nodep->v3warn(DECLFILENAME, "Filename '"<<nodep->fileline()->filebasenameNoExt()
|
||||
<<"' does not match "<<nodep->typeName()<<" name: "<<nodep->prettyName());
|
||||
}
|
||||
}
|
||||
// Module: Pick up modnames, so we can resolve cells later
|
||||
m_modp = nodep;
|
||||
UINFO(2,"Link Module: "<<nodep<<endl);
|
||||
if (nodep->fileline()->filebasenameNoExt() != nodep->prettyName()
|
||||
&& !v3Global.opt.isLibraryFile(nodep->fileline()->filename())
|
||||
&& !nodep->recursiveClone()
|
||||
&& !nodep->internal()) {
|
||||
// We only complain once per file, otherwise library-like files
|
||||
// have a huge mess of warnings
|
||||
if (m_declfnWarned.find(nodep->fileline()->filename()) == m_declfnWarned.end()) {
|
||||
m_declfnWarned.insert(nodep->fileline()->filename());
|
||||
nodep->v3warn(DECLFILENAME, "Filename '"<<nodep->fileline()->filebasenameNoExt()
|
||||
<<"' does not match "<<nodep->typeName()
|
||||
<<" name: "<<nodep->prettyName());
|
||||
}
|
||||
}
|
||||
if (VN_IS(nodep, Iface) || VN_IS(nodep, Package)) nodep->inLibrary(true); // Interfaces can't be at top, unless asked
|
||||
bool topMatch = (v3Global.opt.topModule()==nodep->prettyName());
|
||||
if (topMatch) {
|
||||
m_topVertexp = vertex(nodep);
|
||||
UINFO(2,"Link --top-module: "<<nodep<<endl);
|
||||
nodep->inLibrary(false); // Safer to make sure it doesn't disappear
|
||||
}
|
||||
if (v3Global.opt.topModule()==""
|
||||
? nodep->inLibrary() // Library cells are lower
|
||||
: !topMatch) { // Any non-specified module is lower
|
||||
// Put under a fake vertex so that the graph ranking won't indicate
|
||||
// this is a top level module
|
||||
if (!m_libVertexp) m_libVertexp = new LibraryVertex(&m_graph);
|
||||
new V3GraphEdge(&m_graph, m_libVertexp, vertex(nodep), 1, false);
|
||||
}
|
||||
// Note AstBind also has iteration on cells
|
||||
bool topMatch = (v3Global.opt.topModule()==nodep->prettyName());
|
||||
if (topMatch) {
|
||||
m_topVertexp = vertex(nodep);
|
||||
UINFO(2,"Link --top-module: "<<nodep<<endl);
|
||||
nodep->inLibrary(false); // Safer to make sure it doesn't disappear
|
||||
}
|
||||
if (v3Global.opt.topModule()==""
|
||||
? nodep->inLibrary() // Library cells are lower
|
||||
: !topMatch) { // Any non-specified module is lower
|
||||
// Put under a fake vertex so that the graph ranking won't indicate
|
||||
// this is a top level module
|
||||
if (!m_libVertexp) m_libVertexp = new LibraryVertex(&m_graph);
|
||||
new V3GraphEdge(&m_graph, m_libVertexp, vertex(nodep), 1, false);
|
||||
}
|
||||
// Note AstBind also has iteration on cells
|
||||
iterateChildren(nodep);
|
||||
nodep->checkTree();
|
||||
m_modp = NULL;
|
||||
nodep->checkTree();
|
||||
m_modp = NULL;
|
||||
}
|
||||
|
||||
virtual void visit(AstIfaceRefDType* nodep) {
|
||||
// Cell: Resolve its filename. If necessary, parse it.
|
||||
UINFO(4,"Link IfaceRef: "<<nodep<<endl);
|
||||
// Use findIdUpward instead of findIdFlat; it doesn't matter for now
|
||||
// but we might support modules-under-modules someday.
|
||||
AstNodeModule* modp = resolveModule(nodep, nodep->ifaceName());
|
||||
if (modp) {
|
||||
// Cell: Resolve its filename. If necessary, parse it.
|
||||
UINFO(4,"Link IfaceRef: "<<nodep<<endl);
|
||||
// Use findIdUpward instead of findIdFlat; it doesn't matter for now
|
||||
// but we might support modules-under-modules someday.
|
||||
AstNodeModule* modp = resolveModule(nodep, nodep->ifaceName());
|
||||
if (modp) {
|
||||
if (VN_IS(modp, Iface)) {
|
||||
// Track module depths, so can sort list from parent down to children
|
||||
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(modp), 1, false);
|
||||
// Track module depths, so can sort list from parent down to children
|
||||
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(modp), 1, false);
|
||||
if (!nodep->cellp()) nodep->ifacep(VN_CAST(modp, Iface));
|
||||
} else if (VN_IS(modp, NotFoundModule)) { // Will error out later
|
||||
} else {
|
||||
nodep->v3error("Non-interface used as an interface: "<<nodep->prettyName());
|
||||
}
|
||||
}
|
||||
// Note cannot do modport resolution here; modports are allowed underneath generates
|
||||
} else {
|
||||
nodep->v3error("Non-interface used as an interface: "<<nodep->prettyName());
|
||||
}
|
||||
}
|
||||
// Note cannot do modport resolution here; modports are allowed underneath generates
|
||||
}
|
||||
|
||||
virtual void visit(AstPackageImport* nodep) {
|
||||
// Package Import: We need to do the package before the use of a package
|
||||
// Package Import: We need to do the package before the use of a package
|
||||
iterateChildren(nodep);
|
||||
if (!nodep->packagep()) nodep->v3fatalSrc("Unlinked package"); // Parser should set packagep
|
||||
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(nodep->packagep()), 1, false);
|
||||
if (!nodep->packagep()) nodep->v3fatalSrc("Unlinked package"); // Parser should set packagep
|
||||
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(nodep->packagep()), 1, false);
|
||||
}
|
||||
|
||||
virtual void visit(AstBind* nodep) {
|
||||
// Bind: Has cells underneath that need to be put into the new module, and cells which need resolution
|
||||
// TODO this doesn't allow bind to dotted hier names, that would require
|
||||
// this move to post param, which would mean we do not auto-read modules
|
||||
// and means we cannot compute module levels until later.
|
||||
UINFO(4,"Link Bind: "<<nodep<<endl);
|
||||
AstNodeModule* modp = resolveModule(nodep,nodep->name());
|
||||
if (modp) {
|
||||
AstNode* cellsp = nodep->cellsp()->unlinkFrBackWithNext();
|
||||
// Module may have already linked, so need to pick up these new cells
|
||||
AstNodeModule* oldModp = m_modp;
|
||||
{
|
||||
m_modp = modp;
|
||||
modp->addStmtp(cellsp); // Important that this adds to end, as next iterate assumes does all cells
|
||||
// Bind: Has cells underneath that need to be put into the new
|
||||
// module, and cells which need resolution
|
||||
// TODO this doesn't allow bind to dotted hier names, that would require
|
||||
// this move to post param, which would mean we do not auto-read modules
|
||||
// and means we cannot compute module levels until later.
|
||||
UINFO(4,"Link Bind: "<<nodep<<endl);
|
||||
AstNodeModule* modp = resolveModule(nodep, nodep->name());
|
||||
if (modp) {
|
||||
AstNode* cellsp = nodep->cellsp()->unlinkFrBackWithNext();
|
||||
// Module may have already linked, so need to pick up these new cells
|
||||
AstNodeModule* oldModp = m_modp;
|
||||
{
|
||||
m_modp = modp;
|
||||
modp->addStmtp(cellsp); // Important that this adds to end, as next iterate assumes does all cells
|
||||
iterateAndNextNull(cellsp);
|
||||
}
|
||||
m_modp = oldModp;
|
||||
}
|
||||
pushDeletep(nodep->unlinkFrBack());
|
||||
}
|
||||
m_modp = oldModp;
|
||||
}
|
||||
pushDeletep(nodep->unlinkFrBack());
|
||||
}
|
||||
|
||||
virtual void visit(AstCell* nodep) {
|
||||
// Cell: Resolve its filename. If necessary, parse it.
|
||||
// Execute only once. Complication is that cloning may result in user1 being set (for pre-clone)
|
||||
// so check if user1() matches the m_mod, if 0 never did it, if !=, it is an unprocessed clone
|
||||
bool cloned = (nodep->user1p() && nodep->user1p()!=m_modp);
|
||||
if (nodep->user1p()==m_modp) return; // AstBind and AstNodeModule may call a cell twice
|
||||
nodep->user1p(m_modp);
|
||||
//
|
||||
if (!nodep->modp() || cloned) {
|
||||
UINFO(4,"Link Cell: "<<nodep<<endl);
|
||||
// Use findIdFallback instead of findIdFlat; it doesn't matter for now
|
||||
// but we might support modules-under-modules someday.
|
||||
AstNodeModule* cellmodp = resolveModule(nodep, nodep->modName());
|
||||
if (cellmodp) {
|
||||
if (cellmodp == m_modp
|
||||
|| cellmodp->user2p() == m_modp) {
|
||||
UINFO(1,"Self-recursive module "<<cellmodp<<endl);
|
||||
cellmodp->recursive(true);
|
||||
nodep->recursive(true);
|
||||
if (!cellmodp->recursiveClone()) {
|
||||
// In the non-Vrcm, which needs to point to Vrcm flavor
|
||||
//
|
||||
// Make a clone which this cell points to
|
||||
// Later, the clone's cells will also point clone'd name
|
||||
// This lets us link the XREFs between the (uncloned) children so
|
||||
// they don't point to the same module which would
|
||||
// break parameter resolution.
|
||||
// Cell: Resolve its filename. If necessary, parse it.
|
||||
// Execute only once. Complication is that cloning may result in
|
||||
// user1 being set (for pre-clone) so check if user1() matches the
|
||||
// m_mod, if 0 never did it, if !=, it is an unprocessed clone
|
||||
bool cloned = (nodep->user1p() && nodep->user1p()!=m_modp);
|
||||
if (nodep->user1p()==m_modp) return; // AstBind and AstNodeModule may call a cell twice
|
||||
nodep->user1p(m_modp);
|
||||
//
|
||||
if (!nodep->modp() || cloned) {
|
||||
UINFO(4,"Link Cell: "<<nodep<<endl);
|
||||
// Use findIdFallback instead of findIdFlat; it doesn't matter for now
|
||||
// but we might support modules-under-modules someday.
|
||||
AstNodeModule* cellmodp = resolveModule(nodep, nodep->modName());
|
||||
if (cellmodp) {
|
||||
if (cellmodp == m_modp
|
||||
|| cellmodp->user2p() == m_modp) {
|
||||
UINFO(1,"Self-recursive module "<<cellmodp<<endl);
|
||||
cellmodp->recursive(true);
|
||||
nodep->recursive(true);
|
||||
if (!cellmodp->recursiveClone()) {
|
||||
// In the non-Vrcm, which needs to point to Vrcm flavor
|
||||
//
|
||||
// Make a clone which this cell points to
|
||||
// Later, the clone's cells will also point clone'd name
|
||||
// This lets us link the XREFs between the (uncloned) children so
|
||||
// they don't point to the same module which would
|
||||
// break parameter resolution.
|
||||
AstNodeModule* otherModp = VN_CAST(cellmodp->user2p(), NodeModule);
|
||||
if (!otherModp) {
|
||||
otherModp = cellmodp->cloneTree(false);
|
||||
otherModp->name(otherModp->name()+"__Vrcm");
|
||||
otherModp->user1p(NULL); // Need new vertex
|
||||
otherModp->user2p(cellmodp);
|
||||
otherModp->recursiveClone(true);
|
||||
// user1 etc will retain its pre-clone value
|
||||
cellmodp->user2p(otherModp);
|
||||
v3Global.rootp()->addModulep(otherModp);
|
||||
new V3GraphEdge(&m_graph, vertex(cellmodp), vertex(otherModp), 1, false);
|
||||
}
|
||||
cellmodp = otherModp;
|
||||
nodep->modp(cellmodp);
|
||||
}
|
||||
else {
|
||||
// In the Vrcm, which needs to point back to Vrcm flavor
|
||||
// The cell already has the correct resolution (to Vrcm)
|
||||
nodep->modp(cellmodp);
|
||||
// We don't create a V3GraphEdge (as it would be circular)
|
||||
}
|
||||
}
|
||||
else { // Non-recursive
|
||||
// Track module depths, so can sort list from parent down to children
|
||||
nodep->modp(cellmodp);
|
||||
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(cellmodp), 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove AstCell(AstPin("",NULL)), it's a side effect of how we parse "()"
|
||||
// the empty middle is identical to the empty rule that must find pins in "(,)".
|
||||
if (nodep->pinsp() && !nodep->pinsp()->nextp()
|
||||
&& nodep->pinsp()->name() == ""
|
||||
&& !nodep->pinsp()->exprp()) {
|
||||
pushDeletep(nodep->pinsp()->unlinkFrBackWithNext());
|
||||
}
|
||||
if (nodep->paramsp() && !nodep->paramsp()->nextp()
|
||||
&& nodep->paramsp()->name() == ""
|
||||
&& !nodep->paramsp()->exprp()) {
|
||||
pushDeletep(nodep->paramsp()->unlinkFrBackWithNext());
|
||||
}
|
||||
// Convert .* to list of pins
|
||||
bool pinStar = false;
|
||||
for (AstPin* nextp, *pinp = nodep->pinsp(); pinp; pinp=nextp) {
|
||||
if (!otherModp) {
|
||||
otherModp = cellmodp->cloneTree(false);
|
||||
otherModp->name(otherModp->name()+"__Vrcm");
|
||||
otherModp->user1p(NULL); // Need new vertex
|
||||
otherModp->user2p(cellmodp);
|
||||
otherModp->recursiveClone(true);
|
||||
// user1 etc will retain its pre-clone value
|
||||
cellmodp->user2p(otherModp);
|
||||
v3Global.rootp()->addModulep(otherModp);
|
||||
new V3GraphEdge(&m_graph, vertex(cellmodp),
|
||||
vertex(otherModp), 1, false);
|
||||
}
|
||||
cellmodp = otherModp;
|
||||
nodep->modp(cellmodp);
|
||||
}
|
||||
else {
|
||||
// In the Vrcm, which needs to point back to Vrcm flavor
|
||||
// The cell already has the correct resolution (to Vrcm)
|
||||
nodep->modp(cellmodp);
|
||||
// We don't create a V3GraphEdge (as it would be circular)
|
||||
}
|
||||
}
|
||||
else { // Non-recursive
|
||||
// Track module depths, so can sort list from parent down to children
|
||||
nodep->modp(cellmodp);
|
||||
new V3GraphEdge(&m_graph, vertex(m_modp), vertex(cellmodp), 1, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Remove AstCell(AstPin("",NULL)), it's a side effect of how we parse "()"
|
||||
// the empty middle is identical to the empty rule that must find pins in "(,)".
|
||||
if (nodep->pinsp() && !nodep->pinsp()->nextp()
|
||||
&& nodep->pinsp()->name() == ""
|
||||
&& !nodep->pinsp()->exprp()) {
|
||||
pushDeletep(nodep->pinsp()->unlinkFrBackWithNext());
|
||||
}
|
||||
if (nodep->paramsp() && !nodep->paramsp()->nextp()
|
||||
&& nodep->paramsp()->name() == ""
|
||||
&& !nodep->paramsp()->exprp()) {
|
||||
pushDeletep(nodep->paramsp()->unlinkFrBackWithNext());
|
||||
}
|
||||
// Convert .* to list of pins
|
||||
bool pinStar = false;
|
||||
for (AstPin* nextp, *pinp = nodep->pinsp(); pinp; pinp=nextp) {
|
||||
nextp = VN_CAST(pinp->nextp(), Pin);
|
||||
if (pinp->dotStar()) {
|
||||
if (pinStar) pinp->v3error("Duplicate .* in a cell");
|
||||
pinStar = true;
|
||||
// Done with this fake pin
|
||||
pinp->unlinkFrBack()->deleteTree(); VL_DANGLING(pinp);
|
||||
}
|
||||
}
|
||||
// Convert unnamed pins to pin number based assignments
|
||||
if (pinp->dotStar()) {
|
||||
if (pinStar) pinp->v3error("Duplicate .* in a cell");
|
||||
pinStar = true;
|
||||
// Done with this fake pin
|
||||
pinp->unlinkFrBack()->deleteTree(); VL_DANGLING(pinp);
|
||||
}
|
||||
}
|
||||
// Convert unnamed pins to pin number based assignments
|
||||
for (AstPin* pinp = nodep->pinsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
||||
if (pinp->name()=="") pinp->name("__pinNumber"+cvtToStr(pinp->pinNum()));
|
||||
}
|
||||
if (pinp->name()=="") pinp->name("__pinNumber"+cvtToStr(pinp->pinNum()));
|
||||
}
|
||||
for (AstPin* pinp = nodep->paramsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
||||
pinp->param(true);
|
||||
if (pinp->name()=="") pinp->name("__paramNumber"+cvtToStr(pinp->pinNum()));
|
||||
}
|
||||
if (nodep->modp()) {
|
||||
nodep->modName(nodep->modp()->name());
|
||||
// Note what pins exist
|
||||
vl_unordered_set<string> ports; // Symbol table of all connected port names
|
||||
pinp->param(true);
|
||||
if (pinp->name()=="") pinp->name("__paramNumber"+cvtToStr(pinp->pinNum()));
|
||||
}
|
||||
if (nodep->modp()) {
|
||||
nodep->modName(nodep->modp()->name());
|
||||
// Note what pins exist
|
||||
vl_unordered_set<string> ports; // Symbol table of all connected port names
|
||||
for (AstPin* pinp = nodep->pinsp(); pinp; pinp=VN_CAST(pinp->nextp(), Pin)) {
|
||||
if (pinp->name()=="") pinp->v3error("Connect by position is illegal in .* connected cells");
|
||||
if (!pinp->exprp()) {
|
||||
if (pinp->name().substr(0, 11) == "__pinNumber") {
|
||||
pinp->v3warn(PINNOCONNECT,"Cell pin is not connected: "<<pinp->prettyName());
|
||||
} else {
|
||||
pinp->v3warn(PINCONNECTEMPTY,"Cell pin connected by name with empty reference: "<<pinp->prettyName());
|
||||
}
|
||||
}
|
||||
if (ports.find(pinp->name()) == ports.end()) {
|
||||
ports.insert(pinp->name());
|
||||
}
|
||||
}
|
||||
// We search ports, rather than in/out declarations as they aren't resolved yet,
|
||||
// and it's easier to do it now than in V3LinkDot when we'd need to repeat steps.
|
||||
for (AstNode* portnodep = nodep->modp()->stmtsp(); portnodep; portnodep=portnodep->nextp()) {
|
||||
if (pinp->name()=="") pinp->v3error("Connect by position is illegal in .* connected cells");
|
||||
if (!pinp->exprp()) {
|
||||
if (pinp->name().substr(0, 11) == "__pinNumber") {
|
||||
pinp->v3warn(PINNOCONNECT, "Cell pin is not connected: "
|
||||
<<pinp->prettyName());
|
||||
} else {
|
||||
pinp->v3warn(PINCONNECTEMPTY,
|
||||
"Cell pin connected by name with empty reference: "
|
||||
<<pinp->prettyName());
|
||||
}
|
||||
}
|
||||
if (ports.find(pinp->name()) == ports.end()) {
|
||||
ports.insert(pinp->name());
|
||||
}
|
||||
}
|
||||
// We search ports, rather than in/out declarations as they aren't resolved yet,
|
||||
// and it's easier to do it now than in V3LinkDot when we'd need to repeat steps.
|
||||
for (AstNode* portnodep = nodep->modp()->stmtsp();
|
||||
portnodep; portnodep=portnodep->nextp()) {
|
||||
if (const AstPort* portp = VN_CAST(portnodep, Port)) {
|
||||
if (ports.find(portp->name()) == ports.end()
|
||||
&& ports.find("__pinNumber"+cvtToStr(portp->pinNum())) == ports.end()) {
|
||||
if (pinStar) {
|
||||
UINFO(9," need .* PORT "<<portp<<endl);
|
||||
// Create any not already connected
|
||||
AstPin* newp = new AstPin(nodep->fileline(),0,portp->name(),
|
||||
new AstParseRef(nodep->fileline(),
|
||||
AstParseRefExp::PX_TEXT, portp->name(), NULL, NULL));
|
||||
newp->svImplicit(true);
|
||||
nodep->addPinsp(newp);
|
||||
} else { // warn on the CELL that needs it, not the port
|
||||
nodep->v3warn(PINMISSING, "Cell has missing pin: "<<portp->prettyName());
|
||||
AstPin* newp = new AstPin(nodep->fileline(),0,portp->name(),NULL);
|
||||
nodep->addPinsp(newp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (ports.find(portp->name()) == ports.end()
|
||||
&& ports.find("__pinNumber"+cvtToStr(portp->pinNum())) == ports.end()) {
|
||||
if (pinStar) {
|
||||
UINFO(9," need .* PORT "<<portp<<endl);
|
||||
// Create any not already connected
|
||||
AstPin* newp = new AstPin(nodep->fileline(), 0, portp->name(),
|
||||
new AstParseRef(nodep->fileline(),
|
||||
AstParseRefExp::PX_TEXT,
|
||||
portp->name(), NULL, NULL));
|
||||
newp->svImplicit(true);
|
||||
nodep->addPinsp(newp);
|
||||
} else { // warn on the CELL that needs it, not the port
|
||||
nodep->v3warn(PINMISSING, "Cell has missing pin: "
|
||||
<<portp->prettyName());
|
||||
AstPin* newp = new AstPin(nodep->fileline(), 0, portp->name(), NULL);
|
||||
nodep->addPinsp(newp);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (VN_IS(nodep->modp(), Iface)) {
|
||||
// Cell really is the parent's instantiation of an interface, not a normal module
|
||||
// Make sure we have a variable to refer to this cell, so can <ifacename>.<innermember>
|
||||
// in the same way that a child does. Rename though to avoid conflict with cell.
|
||||
// This is quite similar to how classes work; when unpacked classes are better supported
|
||||
// may remap interfaces to be more like a class.
|
||||
if (!nodep->hasIfaceVar()) {
|
||||
string varName = nodep->name() + "__Viftop"; // V3LinkDot looks for this naming
|
||||
AstIfaceRefDType* idtypep = new AstIfaceRefDType(nodep->fileline(), nodep->name(),
|
||||
nodep->modp()->name());
|
||||
idtypep->ifacep(NULL); // cellp overrides
|
||||
// In the case of arrayed interfaces, we replace cellp when de-arraying in V3Inst
|
||||
idtypep->cellp(nodep); // Only set when real parent cell known.
|
||||
AstVar* varp;
|
||||
if (nodep->rangep()) {
|
||||
// Cell really is the parent's instantiation of an interface, not a normal module
|
||||
// Make sure we have a variable to refer to this cell, so can <ifacename>.<innermember>
|
||||
// in the same way that a child does. Rename though to avoid conflict with cell.
|
||||
// This is quite similar to how classes work; when unpacked classes are better supported
|
||||
// may remap interfaces to be more like a class.
|
||||
if (!nodep->hasIfaceVar()) {
|
||||
string varName = nodep->name() + "__Viftop"; // V3LinkDot looks for this naming
|
||||
AstIfaceRefDType* idtypep = new AstIfaceRefDType(nodep->fileline(), nodep->name(),
|
||||
nodep->modp()->name());
|
||||
idtypep->ifacep(NULL); // cellp overrides
|
||||
// In the case of arrayed interfaces, we replace cellp when de-arraying in V3Inst
|
||||
idtypep->cellp(nodep); // Only set when real parent cell known.
|
||||
AstVar* varp;
|
||||
if (nodep->rangep()) {
|
||||
AstNodeArrayDType* arrp
|
||||
= new AstUnpackArrayDType(nodep->fileline(), VFlagChildDType(),
|
||||
idtypep, nodep->rangep()->cloneTree(true));
|
||||
varp = new AstVar(nodep->fileline(), AstVarType::IFACEREF, varName,
|
||||
VFlagChildDType(), arrp);
|
||||
} else {
|
||||
varp = new AstVar(nodep->fileline(), AstVarType::IFACEREF, varName,
|
||||
VFlagChildDType(), idtypep);
|
||||
}
|
||||
varp->isIfaceParent(true);
|
||||
nodep->addNextHere(varp);
|
||||
nodep->hasIfaceVar(true);
|
||||
}
|
||||
}
|
||||
if (nodep->modp()) {
|
||||
varp = new AstVar(nodep->fileline(), AstVarType::IFACEREF, varName,
|
||||
VFlagChildDType(), arrp);
|
||||
} else {
|
||||
varp = new AstVar(nodep->fileline(), AstVarType::IFACEREF, varName,
|
||||
VFlagChildDType(), idtypep);
|
||||
}
|
||||
varp->isIfaceParent(true);
|
||||
nodep->addNextHere(varp);
|
||||
nodep->hasIfaceVar(true);
|
||||
}
|
||||
}
|
||||
if (nodep->modp()) {
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
UINFO(4," Link Cell done: "<<nodep<<endl);
|
||||
}
|
||||
UINFO(4," Link Cell done: "<<nodep<<endl);
|
||||
}
|
||||
|
||||
// Accelerate the recursion
|
||||
// Must do statements to support Generates, math though...
|
||||
virtual void visit(AstNodeMath* nodep) {}
|
||||
virtual void visit(AstNode* nodep) {
|
||||
// Default: Just iterate
|
||||
// Default: Just iterate
|
||||
iterateChildren(nodep);
|
||||
}
|
||||
|
||||
// METHODS
|
||||
void readModNames() {
|
||||
// Look at all modules, and store pointers to all module names
|
||||
for (AstNodeModule* nextp,* nodep = v3Global.rootp()->modulesp(); nodep; nodep=nextp) {
|
||||
// Look at all modules, and store pointers to all module names
|
||||
for (AstNodeModule* nextp,* nodep = v3Global.rootp()->modulesp(); nodep; nodep=nextp) {
|
||||
nextp = VN_CAST(nodep->nextp(), NodeModule);
|
||||
AstNodeModule* foundp = findModuleSym(nodep->name());
|
||||
if (foundp && foundp != nodep) {
|
||||
if (!(foundp->fileline()->warnIsOff(V3ErrorCode::MODDUP) || nodep->fileline()->warnIsOff(V3ErrorCode::MODDUP))) {
|
||||
nodep->v3warn(MODDUP,"Duplicate declaration of module: "<<nodep->prettyName()<<endl
|
||||
<<foundp->warnMore()<<"... Location of original declaration");
|
||||
}
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
} else if (!foundp) {
|
||||
m_mods.rootp()->insert(nodep->name(), new VSymEnt(&m_mods, nodep));
|
||||
}
|
||||
}
|
||||
//if (debug()>=9) m_mods.dump(cout, "-syms: ");
|
||||
AstNodeModule* foundp = findModuleSym(nodep->name());
|
||||
if (foundp && foundp != nodep) {
|
||||
if (!(foundp->fileline()->warnIsOff(V3ErrorCode::MODDUP)
|
||||
|| nodep->fileline()->warnIsOff(V3ErrorCode::MODDUP))) {
|
||||
nodep->v3warn(MODDUP, "Duplicate declaration of module: "
|
||||
<<nodep->prettyName()<<endl
|
||||
<<foundp->warnMore()<<"... Location of original declaration");
|
||||
}
|
||||
nodep->unlinkFrBack();
|
||||
pushDeletep(nodep); VL_DANGLING(nodep);
|
||||
} else if (!foundp) {
|
||||
m_mods.rootp()->insert(nodep->name(), new VSymEnt(&m_mods, nodep));
|
||||
}
|
||||
}
|
||||
//if (debug()>=9) m_mods.dump(cout, "-syms: ");
|
||||
}
|
||||
|
||||
public:
|
||||
// CONSTUCTORS
|
||||
LinkCellsVisitor(AstNetlist* nodep, V3InFilter* filterp, V3ParseSym* parseSymp)
|
||||
: m_mods(nodep) {
|
||||
m_filterp = filterp;
|
||||
m_parseSymp = parseSymp;
|
||||
m_modp = NULL;
|
||||
m_libVertexp = NULL;
|
||||
m_topVertexp = NULL;
|
||||
m_filterp = filterp;
|
||||
m_parseSymp = parseSymp;
|
||||
m_modp = NULL;
|
||||
m_libVertexp = NULL;
|
||||
m_topVertexp = NULL;
|
||||
iterate(nodep);
|
||||
}
|
||||
virtual ~LinkCellsVisitor() {}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue