From 9163ce0f6e3e6c77b42e6ebf315511f8953e6ab0 Mon Sep 17 00:00:00 2001 From: Byron Bradley Date: Fri, 9 Apr 2010 20:43:25 -0400 Subject: [PATCH] Internals: modify AstVar::dimensions() to return a pair, bug227 Signed-off-by: Wilson Snyder --- src/V3AstNodes.cpp | 12 +++++++----- src/V3AstNodes.h | 2 +- src/V3Slice.cpp | 9 ++++++--- 3 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/V3AstNodes.cpp b/src/V3AstNodes.cpp index c8ae80b7d..303bd3f74 100644 --- a/src/V3AstNodes.cpp +++ b/src/V3AstNodes.cpp @@ -295,13 +295,15 @@ uint32_t AstVar::arrayElements() const { return entries; } -uint32_t AstVar::dimensions() const { - // How many array dimensions does this Var have? - uint32_t dim = 0; +pair AstVar::dimensions() const { + // How many array dimensions (packed,unpacked) does this Var have? + uint32_t packed = 0; + uint32_t unpacked = 0; for (AstNodeDType* dtypep=this->dtypep(); dtypep; ) { dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node if (AstArrayDType* adtypep = dtypep->castArrayDType()) { - dim += 1; + if (adtypep->isPacked()) packed += 1; + else unpacked += 1; dtypep = adtypep->dtypep(); } else { @@ -309,7 +311,7 @@ uint32_t AstVar::dimensions() const { break; } } - return dim; + return make_pair(packed, unpacked); } // Special operators diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 13fed3504..b178d0387 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -621,7 +621,7 @@ public: AstNodeDType* dtypeSkipRefp() const { return dtypep()->skipRefp(); } // op1 = Range of variable (Note don't need virtual - AstVar isn't a NodeDType) AstBasicDType* basicp() const { return dtypep()->basicp(); } // (Slow) recurse down to find basic data type (Note don't need virtual - AstVar isn't a NodeDType) AstNodeDType* dtypeDimensionp(int depth) const; - uint32_t dimensions() const; + pair dimensions() const; AstNode* valuep() const { return op3p()->castNode(); } // op3 = Initial value that never changes (static const) void valuep(AstNode* nodep) { setOp3p(nodep); } // It's valuep, not constp, as may be more complicated than a AstConst void addAttrsp(AstNode* nodep) { addNOp4p(nodep); } diff --git a/src/V3Slice.cpp b/src/V3Slice.cpp index 3363b040b..8bfbaa7d7 100644 --- a/src/V3Slice.cpp +++ b/src/V3Slice.cpp @@ -76,7 +76,8 @@ class SliceCloneVisitor : public AstNVisitor { if (m_vecIdx == (int)m_selBits.size()) { m_selBits.push_back(vector()); AstVar* varp = m_refp->varp(); - int dimensions = varp->dimensions(); + pair arrDim = varp->dimensions(); + uint32_t dimensions = arrDim.first + arrDim.second; for (int i = 0; i < dimensions; ++i) { m_selBits[m_vecIdx].push_back(0); } @@ -229,7 +230,8 @@ class SliceVisitor : public AstNVisitor { // The LHS/RHS of an Assign may be to a Var that is an array. In this // case we need to create a slice accross the entire Var if (m_assignp && !nodep->backp()->castArraySel()) { - uint32_t dimensions = nodep->varp()->dimensions(); + pair arrDim = nodep->varp()->dimensions(); + uint32_t dimensions = arrDim.first + arrDim.second; if (dimensions > 0) { AstNode* newp = insertImplicit(nodep->cloneTree(false), 1, dimensions); nodep->replaceWith(newp); nodep = NULL; @@ -260,7 +262,8 @@ class SliceVisitor : public AstNVisitor { if (!m_assignp) return; unsigned dim = explicitDimensions(nodep); AstVarRef* refp = nodep->user1p()->castNode()->castVarRef(); - unsigned implicit = refp->varp()->dimensions() - dim; + pair arrDim = refp->varp()->dimensions(); + uint32_t implicit = (arrDim.first + arrDim.second) - dim; if (implicit > 0) { AstNode* backp = refp->backp(); AstNode* newp = insertImplicit(refp->cloneTree(false), dim+1, implicit);