From f0217edef18b0889f832e480cd908b1cdb1463ac Mon Sep 17 00:00:00 2001 From: John Coiner Date: Thu, 30 Nov 2017 18:53:57 -0500 Subject: [PATCH] Internals: Keep a ptr to _eval in AstNetlist, make it easier to find. Signed-off-by: Wilson Snyder --- src/V3AstNodes.h | 18 +++++++++++++----- src/V3Clock.cpp | 3 +++ src/V3Stats.cpp | 26 ++++++++++++++------------ src/V3Trace.cpp | 2 +- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 8a55cd52f..80474ca8e 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -5471,13 +5471,19 @@ class AstNetlist : public AstNode { private: AstTypeTable* m_typeTablep; // Reference to top type table, for faster lookup AstPackage* m_dollarUnitPkgp; + AstCFunc* m_evalp; // The '_eval' function public: - AstNetlist() : AstNode(new FileLine("AstRoot",0)) { - m_typeTablep = NULL; - m_dollarUnitPkgp = NULL; - } + AstNetlist() + : AstNode(new FileLine("AstRoot",0)) + , m_typeTablep(NULL) + , m_dollarUnitPkgp(NULL) + , m_evalp(NULL) { } ASTNODE_NODE_FUNCS(Netlist) - virtual const char* broken() const { BROKEN_RTN(m_dollarUnitPkgp && !m_dollarUnitPkgp->brokeExists()); return NULL; } + virtual const char* broken() const { + BROKEN_RTN(m_dollarUnitPkgp && !m_dollarUnitPkgp->brokeExists()); + BROKEN_RTN(m_evalp && !m_evalp->brokeExists()); + return NULL; + } AstNodeModule* modulesp() const { return op1p()->castNodeModule();} // op1 = List of modules AstNodeModule* topModulep() const { return op1p()->castNodeModule(); } // * = Top module in hierarchy (first one added, for now) void addModulep(AstNodeModule* modulep) { addOp1p(modulep); } @@ -5497,6 +5503,8 @@ public: addModulep(m_dollarUnitPkgp); } return m_dollarUnitPkgp; } + AstCFunc* evalp() const { return m_evalp; } + void evalp(AstCFunc* evalp) { m_evalp = evalp; } }; //###################################################################### diff --git a/src/V3Clock.cpp b/src/V3Clock.cpp index 7838dd123..5977bafe8 100644 --- a/src/V3Clock.cpp +++ b/src/V3Clock.cpp @@ -394,6 +394,9 @@ public: m_scopep = NULL; // nodep->accept(*this); + // Allow downstream modules to find _eval() + // easily without iterating through the tree. + nodep->evalp(m_evalFuncp); } virtual ~ClockVisitor() {} }; diff --git a/src/V3Stats.cpp b/src/V3Stats.cpp index 3c68b4080..3b49b4c1c 100644 --- a/src/V3Stats.cpp +++ b/src/V3Stats.cpp @@ -90,19 +90,11 @@ private: virtual void visit(AstNodeModule* nodep) { allNodes(nodep); if (!m_fast) { - nodep->iterateChildrenConst(*this); - } else { - for (AstNode* searchp = nodep->stmtsp(); searchp; searchp=searchp->nextp()) { - if (AstCFunc* funcp = searchp->castCFunc()) { - if (funcp->name() == "_eval") { - m_instrs=0; - m_counting = true; - funcp->iterateChildrenConst(*this); - m_counting = false; - } - } - } + // Count all CFuncs below this module + nodep->iterateChildrenConst(*this); } + // Else we recursively trace fast CFuncs from the top _eval + // func, see visit(AstNetlist*) } virtual void visit(AstVar* nodep) { allNodes(nodep); @@ -213,6 +205,16 @@ private: allNodes(nodep); nodep->iterateChildrenConst(*this); } + virtual void visit(AstNetlist* nodep) { + if (m_fast && nodep->evalp()) { + m_instrs = 0; + m_counting = true; + nodep->evalp()->iterateChildrenConst(*this); + m_counting = false; + } + allNodes(nodep); + nodep->iterateChildrenConst(*this); + } public: // CONSTRUCTORS StatsVisitor(AstNetlist* nodep, const string& stage, bool fast) diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index 839c1fb12..b202a5c2e 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -625,7 +625,7 @@ private: V3GraphVertex* funcVtxp = getCFuncVertexp(nodep); if (!m_finding) { // If public, we need a unique activity code to allow for sets directly in this func if (nodep->funcPublic() || nodep->dpiExport() - || nodep->name() == "_eval") { + || nodep == v3Global.rootp()->evalp()) { // Need a non-null place to remember to later add a statement; make one if (!nodep->stmtsp()) nodep->addStmtsp(new AstComment(nodep->fileline(), "Tracing activity check")); V3GraphVertex* activityVtxp = getActivityVertexp(nodep->stmtsp(), nodep->slow());