Internals: Ast classes create declRange().

This commit is contained in:
Wilson Snyder 2013-01-17 20:41:45 -05:00
parent bbeb382cbb
commit de4016dcff
4 changed files with 9 additions and 11 deletions

View File

@ -1559,6 +1559,7 @@ public:
}
int lsb() const { return 0; }
int msb() const { return dtypep()->width()-1; } // Packed classes look like arrays
VNumRange declRange() const { return VNumRange(msb(), lsb(), false); }
};
struct AstNodeArrayDType : public AstNodeDType {
@ -1601,6 +1602,7 @@ public:
int msb() const;
int lsb() const;
int elementsConst() const;
VNumRange declRange() const;
};
struct AstNodeSel : public AstNodeBiop {
@ -1802,5 +1804,6 @@ inline void AstNodeArrayDType::rangep(AstRange* nodep) { setOp2p(nodep); }
inline int AstNodeArrayDType::msb() const { return rangep()->msbConst(); }
inline int AstNodeArrayDType::lsb() const { return rangep()->lsbConst(); }
inline int AstNodeArrayDType::elementsConst() const { return rangep()->elementsConst(); }
inline VNumRange AstNodeArrayDType::declRange() const { return VNumRange(msb(), lsb(), rangep()->littleEndian()); }
#endif // Guard

View File

@ -746,11 +746,11 @@ void AstNodeDType::dumpSmall(ostream& str) {
void AstNodeArrayDType::dumpSmall(ostream& str) {
this->AstNodeDType::dumpSmall(str);
if (castPackArrayDType()) str<<"p"; else str<<"u";
str<<"["<<msb()<<":"<<lsb()<<"]";
str<<"["<<declRange().left()<<":"<<declRange().right()<<"]";
}
void AstNodeArrayDType::dump(ostream& str) {
this->AstNodeDType::dump(str);
str<<" ["<<msb()<<":"<<lsb()<<"]";
str<<" ["<<declRange().left()<<":"<<declRange().right()<<"]";
}
void AstNodeModule::dump(ostream& str) {
this->AstNode::dump(str);

View File

@ -374,6 +374,7 @@ public:
int right() const { return littleEndian()?msb():lsb(); }
bool littleEndian() const { return (rangep() ? rangep()->littleEndian() : m.m_nrange.littleEndian()); }
bool implicit() const { return keyword() == AstBasicDTypeKwd::LOGIC_IMPLICIT; }
VNumRange declRange() const { return isRanged() ? VNumRange(msb(), lsb(), littleEndian()) : VNumRange(); }
void cvtRangeConst() { // Convert to smaller represenation
if (rangep() && rangep()->msbp()->castConst() && rangep()->lsbp()->castConst()) {
m.m_nrange.init(rangep()->msbConst(), rangep()->lsbConst(),

View File

@ -94,14 +94,10 @@ private:
AstNode* errp = ddtypep;
UINFO(9," fromData.ddtypep = "<<ddtypep<<endl);
if (AstNodeArrayDType* adtypep = ddtypep->castNodeArrayDType()) {
fromRange.init(adtypep->msb(),
adtypep->lsb(),
adtypep->rangep()->littleEndian());
fromRange = adtypep->declRange();
}
else if (AstNodeClassDType* adtypep = ddtypep->castNodeClassDType()) {
fromRange.init(adtypep->msb(),
adtypep->lsb(),
false); // big endian
fromRange = adtypep->declRange();
}
else if (AstBasicDType* adtypep = ddtypep->castBasicDType()) {
if (adtypep->isRanged()) {
@ -109,9 +105,7 @@ private:
&& (!adtypep->rangep()->msbp()->castConst()
|| !adtypep->rangep()->lsbp()->castConst()))
nodep->v3fatalSrc("Non-constant variable range; errored earlier"); // in constifyParam(bfdtypep)
fromRange.init(adtypep->msb(),
adtypep->lsb(),
adtypep->littleEndian());
fromRange = adtypep->declRange();
} else {
nodep->v3error("Illegal bit or array select; type does not have a bit range, or bad dimension: type is "
<<errp->prettyName());