mirror of
https://github.com/verilator/verilator.git
synced 2025-05-02 21:46:54 +00:00
Internals: modify AstVar::dimensions() to return a pair, bug227
Signed-off-by: Wilson Snyder <wsnyder@wsnyder.org>
This commit is contained in:
parent
d776638f53
commit
9163ce0f6e
@ -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<uint32_t,uint32_t> 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
|
||||
|
@ -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<uint32_t,uint32_t> 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); }
|
||||
|
@ -76,7 +76,8 @@ class SliceCloneVisitor : public AstNVisitor {
|
||||
if (m_vecIdx == (int)m_selBits.size()) {
|
||||
m_selBits.push_back(vector<unsigned>());
|
||||
AstVar* varp = m_refp->varp();
|
||||
int dimensions = varp->dimensions();
|
||||
pair<uint32_t,uint32_t> 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<uint32_t,uint32_t> 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<uint32_t,uint32_t> 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);
|
||||
|
Loading…
Reference in New Issue
Block a user