From cc1adf9b387f8328a61c24684c29e1009de5a965 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sun, 1 Apr 2012 21:04:28 -0400 Subject: [PATCH] Internals: merge V3Hashed cleanups. No functional change intended --- src/V3Ast.h | 11 +++++++---- src/V3Error.h | 4 ++-- src/V3Hashed.cpp | 18 +++++++----------- src/V3Hashed.h | 10 ++++++---- src/V3Simulate.h | 6 +++--- src/V3Trace.cpp | 4 ++-- 6 files changed, 27 insertions(+), 26 deletions(-) diff --git a/src/V3Ast.h b/src/V3Ast.h index 6ead99754..85fa9e538 100644 --- a/src/V3Ast.h +++ b/src/V3Ast.h @@ -693,11 +693,14 @@ public: // Creating from raw data (sameHash functions) V3Hash() { setBoth(1,0); } V3Hash(uint32_t val) { setBoth(1,val); } - V3Hash(void* vp) { setBoth(1,cvtToHash(vp)); } + V3Hash(const void* vp) { setBoth(1,cvtToHash(vp)); } V3Hash(const string& name); - V3Hash(V3Hash lh, V3Hash rh) { - setBoth(1,lh.hshval()*31+rh.hshval()); - } + V3Hash(V3Hash h1, V3Hash h2) { + setBoth(1,h1.hshval()*31+h2.hshval()); } + V3Hash(V3Hash h1, V3Hash h2, V3Hash h3) { + setBoth(1,(h1.hshval()*31+h2.hshval())*31+h3.hshval()); } + V3Hash(V3Hash h1, V3Hash h2, V3Hash h3, V3Hash h4) { + setBoth(1,((h1.hshval()*31+h2.hshval())*31+h3.hshval())*31+h4.hshval()); } }; ostream& operator<<(ostream& os, V3Hash rhs); diff --git a/src/V3Error.h b/src/V3Error.h index 7b5aab634..b655a94bc 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -244,10 +244,10 @@ template< class T> std::string cvtToStr (const T& t) { ostringstream os; os<user4()) { if (nodep->backp()->castCFunc() && !(nodep->castNodeStmt() || nodep->castCFunc())) { @@ -83,21 +83,21 @@ private: m_lowerHash = oldHash; } // Update what will become the above node's hash - m_lowerHash += V3Hash(nodep->user4p()); + m_lowerHash += V3Hashed::nodeHash(nodep); } //-------------------- // Default: Just iterate virtual void visit(AstVar*, AstNUser*) {} virtual void visit(AstNode* nodep, AstNUser*) { - hashNodeIterate(nodep); + nodeHashIterate(nodep); } public: // CONSTUCTORS HashedVisitor(AstNode* nodep) { - hashNodeIterate(nodep); - //UINFO(9," stmthash "<user4()<<" "<user4p()) { HashedVisitor visitor (nodep); } - m_hashMmap.insert(make_pair(V3Hash(nodep->user4p()), nodep)); + m_hashMmap.insert(make_pair(nodeHash(nodep), nodep)); } bool V3Hashed::sameNodes(AstNode* node1p, AstNode* node2p) { @@ -183,7 +179,7 @@ void V3Hashed::dumpFile(const string& filename, bool tree) { V3Hashed::iterator V3Hashed::findDuplicate(AstNode* nodep) { UINFO(8," findD "<user4p()) nodep->v3fatalSrc("Called findDuplicate on non-hashed node"); - pair eqrange = mmap().equal_range(V3Hash(nodep->user4p())); + pair 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)) { diff --git a/src/V3Hashed.h b/src/V3Hashed.h index 56c5c5dec..5118fd6f3 100644 --- a/src/V3Hashed.h +++ b/src/V3Hashed.h @@ -46,12 +46,13 @@ private: public: // CONSTRUCTORS - V3Hashed(); + V3Hashed() { clear(); } ~V3Hashed() {} + // ACCESSORS HashMmap& mmap() { return m_hashMmap; } // Return map for iteration - HashMmap::iterator begin() { return m_hashMmap.begin(); } - HashMmap::iterator end() { return m_hashMmap.end(); } + iterator begin() { return m_hashMmap.begin(); } + iterator end() { return m_hashMmap.end(); } // METHODS static int debug() { @@ -59,7 +60,7 @@ public: if (VL_UNLIKELY(level < 0)) level = v3Global.opt.debugSrcLevel(__FILE__); return level; } - void clear() { m_hashMmap.clear(); } + void clear() { m_hashMmap.clear(); AstNode::user4ClearTree(); } void hashAndInsert(AstNode* nodep); // Hash the node, and insert into map bool sameNodes(AstNode* node1p, AstNode* node2p); // After hashing, and tell if identical void erase(iterator it); // Remove node from structures @@ -67,6 +68,7 @@ public: AstNode* iteratorNodep(iterator it) { return it->second; } void dumpFile(const string& filename, bool tree); void dumpFilePrefixed(const string& nameComment, bool tree=false); + static V3Hash nodeHash(AstNode* nodep) { return V3Hash(nodep->user4p()); } }; #endif // Guard diff --git a/src/V3Simulate.h b/src/V3Simulate.h index 60e19e5c0..0954523dd 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -68,10 +68,10 @@ private: AstUser3InUse m_inuser3; // Checking: - // AstVarScope::user1() -> VarUsage. Set true to indicate tracking as lvalue/rvalue + // AstVar(Scope)::user1() -> VarUsage. Set true to indicate tracking as lvalue/rvalue // Simulating: - // AstVarScope::user3() -> V3Number*. Input value of variable or node (and output for non-delayed assignments) - // AstVarScope::user2() -> V3Number*. Output value of variable (delayed assignments) + // AstVar(Scope)::user3() -> V3Number*. Input value of variable or node (and output for non-delayed assignments) + // AstVar(Scope)::user2() -> V3Number*. Output value of variable (delayed assignments) enum VarUsage { VU_NONE=0, VU_LV=1, VU_RV=2, VU_LVDLY=4 }; diff --git a/src/V3Trace.cpp b/src/V3Trace.cpp index b5b9eee25..db15ef5bd 100644 --- a/src/V3Trace.cpp +++ b/src/V3Trace.cpp @@ -208,7 +208,7 @@ private: if (nodep->valuep()) { if (nodep->valuep()->backp() != nodep) nodep->v3fatalSrc("Trace duplicate back needs consistency, so we can map duplicates back to TRACEINCs"); hashed.hashAndInsert(nodep->valuep()); - UINFO(8, " Hashed "<valuep()->user4()<<" "<valuep())<<" "<