Internals: Merge from dtype. Create subDTypep. No functional change intended.

This commit is contained in:
Wilson Snyder 2012-04-14 12:43:03 -04:00
parent 2b12ab4d5a
commit 4d0b964e36
8 changed files with 33 additions and 23 deletions

View File

@ -265,7 +265,7 @@ AstNodeDType* AstNodeDType::dtypeDimensionp(int dimension) {
if ((dim++)==dimension) {
return dtypep;
}
dtypep = adtypep->dtypep();
dtypep = adtypep->subDTypep();
continue;
}
else if (AstBasicDType* adtypep = dtypep->castBasicDType()) {
@ -289,7 +289,7 @@ uint32_t AstNodeDType::arrayElements() {
dtypep = dtypep->skipRefp(); // Skip AstRefDType/AstTypedef, or return same node
if (AstArrayDType* adtypep = dtypep->castArrayDType()) {
entries *= adtypep->elementsConst();
dtypep = adtypep->dtypep();
dtypep = adtypep->subDTypep();
}
else {
// AstBasicDType - nothing below, 1
@ -308,7 +308,7 @@ pair<uint32_t,uint32_t> AstNodeDType::dimensions() {
if (AstArrayDType* adtypep = dtypep->castArrayDType()) {
if (adtypep->isPacked()) packed += 1;
else unpacked += 1;
dtypep = adtypep->dtypep();
dtypep = adtypep->subDTypep();
}
else {
// AstBasicDType - nothing below, 1

View File

@ -170,6 +170,7 @@ public:
ASTNODE_NODE_FUNCS(Typedef, TYPEDEF)
AstNodeDType* dtypep() const { return op1p()->castNodeDType(); } // op1 = Range of variable
void dtypep(AstNodeDType* nodep) { setOp1p(nodep); }
AstNodeDType* subDTypep() const { return dtypep(); }
// METHODS
virtual string name() const { return m_name; }
virtual bool maybePointedTo() const { return true; }
@ -239,6 +240,7 @@ public:
AstNodeDType* dtypep() const { return op1p()->castNodeDType(); } // op1 = Range of variable
AstNodeDType* dtypeSkipRefp() const { return dtypep()->skipRefp(); } // op1 = Range of variable
void dtypep(AstNodeDType* nodep) { setOp1p(nodep); }
AstNodeDType* subDTypep() const { return dtypep(); }
AstRange* arrayp() const { return op2p()->castRange(); } // op2 = Array(s) of variable
void arrayp(AstRange* nodep) { setOp2p(nodep); }
// METHODS
@ -354,6 +356,7 @@ public:
ASTNODE_NODE_FUNCS(ConstDType, CONSTDTYPE)
AstNodeDType* dtypep() const { return op1p()->castNodeDType(); } // op1 = Range of variable
void dtypep(AstNodeDType* nodep) { setOp1p(nodep); }
AstNodeDType* subDTypep() const { return dtypep(); }
// METHODS
virtual AstBasicDType* basicp() const { return dtypep()->basicp(); } // (Slow) recurse down to find basic data type
virtual AstNodeDType* skipRefp() const { return (AstNodeDType*)this; }
@ -363,25 +366,25 @@ public:
struct AstRefDType : public AstNodeDType {
private:
AstNodeDType* m_defp; // data type pointed to, BELOW the AstTypedef
AstNodeDType* m_subDTypep; // data type pointed to, BELOW the AstTypedef
string m_name; // Name of an AstTypedef
AstPackage* m_packagep; // Package hierarchy
public:
AstRefDType(FileLine* fl, const string& name)
: AstNodeDType(fl), m_defp(NULL), m_name(name), m_packagep(NULL) {}
: AstNodeDType(fl), m_subDTypep(NULL), m_name(name), m_packagep(NULL) {}
AstRefDType(FileLine* fl, AstNodeDType* defp)
: AstNodeDType(fl), m_defp(defp), m_packagep(NULL) {
: AstNodeDType(fl), m_subDTypep(defp), m_packagep(NULL) {
widthSignedFrom(defp);
}
ASTNODE_NODE_FUNCS(RefDType, REFDTYPE)
// METHODS
virtual bool broken() const { return m_defp && !m_defp->brokeExists(); }
virtual void cloneRelink() { if (m_defp && m_defp->clonep()) {
m_defp = m_defp->clonep()->castNodeDType();
virtual bool broken() const { return m_subDTypep && !m_subDTypep->brokeExists(); }
virtual void cloneRelink() { if (m_subDTypep && m_subDTypep->clonep()) {
m_subDTypep = m_subDTypep->clonep()->castNodeDType();
}}
virtual V3Hash sameHash() const { return V3Hash(skipRefp()); }
virtual bool same(AstNode* samep) const {
return skipRefp()->sameTree(samep->castRefDType()->skipRefp()); }
virtual V3Hash sameHash() const { return V3Hash(skipRefp()); }
virtual void dump(ostream& str=cout);
virtual string name() const { return m_name; }
virtual AstBasicDType* basicp() const { return defp() ? defp()->basicp() : NULL; }
@ -398,8 +401,9 @@ public:
else { v3fatalSrc("Typedef not linked"); return NULL; }
}
AstNodeDType* dtypeSkipRefp() const { return defp()->skipRefp(); } // op1 = Range of variable
AstNodeDType* defp() const { return m_defp; }
void defp(AstNodeDType* nodep) { m_defp=nodep; }
AstNodeDType* defp() const { return m_subDTypep; }
AstNodeDType* subDTypep() const { return m_subDTypep; }
void subDTypep(AstNodeDType* nodep) { m_subDTypep=nodep; }
AstPackage* packagep() const { return m_packagep; }
void packagep(AstPackage* nodep) { m_packagep=nodep; }
};
@ -460,6 +464,7 @@ public:
void dtypep(AstNodeDType* nodep) { setOp1p(nodep); }
AstEnumItem* itemsp() const { return op2p()->castEnumItem(); } // op2 = AstEnumItem's
void addValuesp(AstNode* nodep) { addOp2p(nodep); }
AstNodeDType* subDTypep() const { return dtypep(); }
// METHODS
virtual AstBasicDType* basicp() const { return dtypep()->basicp(); } // (Slow) recurse down to find basic data type
virtual AstNodeDType* skipRefp() const { return dtypep()->skipRefp(); }

View File

@ -217,7 +217,7 @@ private:
ToggleEnt newent (above.m_comment+string("[")+cvtToStr(index_docs)+"]",
new AstArraySel(varp->fileline(), above.m_varRefp->cloneTree(true), index_code),
new AstArraySel(varp->fileline(), above.m_chgRefp->cloneTree(true), index_code));
toggleVarRecurse(adtypep->dtypeSkipRefp(), depth+1,
toggleVarRecurse(adtypep->subDTypep()->skipRefp(), depth+1,
newent,
varp, chgVarp);
newent.cleanup();

View File

@ -889,7 +889,7 @@ void EmitCStmts::emitVarDecl(AstVar* nodep, const string& prefixIfImp) {
puts(nodep->name());
if (isArray) {
for (AstArrayDType* arrayp=nodep->dtypeSkipRefp()->castArrayDType(); arrayp;
arrayp = arrayp->dtypeSkipRefp()->castArrayDType()) {
arrayp = arrayp->subDTypep()->skipRefp()->castArrayDType()) {
puts("["+cvtToStr(arrayp->elementsConst())+"]");
}
}
@ -910,7 +910,7 @@ void EmitCStmts::emitVarDecl(AstVar* nodep, const string& prefixIfImp) {
if (nodep->isWide()) puts("W");
puts("("+nodep->name());
for (AstArrayDType* arrayp=nodep->dtypeSkipRefp()->castArrayDType(); arrayp;
arrayp = arrayp->dtypeSkipRefp()->castArrayDType()) {
arrayp = arrayp->subDTypep()->skipRefp()->castArrayDType()) {
puts("["+cvtToStr(arrayp->elementsConst())+"]");
}
puts(","+cvtToStr(basicp->msb())+","+cvtToStr(basicp->lsb()));
@ -932,7 +932,7 @@ void EmitCStmts::emitVarDecl(AstVar* nodep, const string& prefixIfImp) {
puts(nodep->vlArgType(true,false));
// This isn't very robust and may need cleanup for other data types
for (AstArrayDType* arrayp=nodep->dtypeSkipRefp()->castArrayDType(); arrayp;
arrayp = arrayp->dtypeSkipRefp()->castArrayDType()) {
arrayp = arrayp->subDTypep()->skipRefp()->castArrayDType()) {
puts("["+cvtToStr(arrayp->elementsConst())+"]");
}
puts(";\n");
@ -958,7 +958,7 @@ void EmitCStmts::emitVarDecl(AstVar* nodep, const string& prefixIfImp) {
puts(nodep->name());
// This isn't very robust and may need cleanup for other data types
for (AstArrayDType* arrayp=nodep->dtypeSkipRefp()->castArrayDType(); arrayp;
arrayp = arrayp->dtypeSkipRefp()->castArrayDType()) {
arrayp = arrayp->subDTypep()->skipRefp()->castArrayDType()) {
puts("["+cvtToStr(arrayp->elementsConst())+"]");
}
puts(","+cvtToStr(basicp->msb())+","+cvtToStr(basicp->lsb()));
@ -1341,7 +1341,7 @@ void EmitCImp::emitVarResets(AstNodeModule* modp) {
int vects = 0;
// This isn't very robust and may need cleanup for other data types
for (AstArrayDType* arrayp=varp->dtypeSkipRefp()->castArrayDType(); arrayp;
arrayp = arrayp->dtypeSkipRefp()->castArrayDType()) {
arrayp = arrayp->subDTypep()->skipRefp()->castArrayDType()) {
int vecnum = vects++;
if (arrayp->msb() < arrayp->lsb()) varp->v3fatalSrc("Should have swapped msb & lsb earlier.");
string ivar = string("__Vi")+cvtToStr(vecnum);
@ -1517,7 +1517,7 @@ void EmitCImp::emitSensitives() {
int vects = 0;
// This isn't very robust and may need cleanup for other data types
for (AstArrayDType* arrayp=varp->dtypeSkipRefp()->castArrayDType(); arrayp;
arrayp = arrayp->dtypeSkipRefp()->castArrayDType()) {
arrayp = arrayp->subDTypep()->skipRefp()->castArrayDType()) {
int vecnum = vects++;
if (arrayp->msb() < arrayp->lsb()) varp->v3fatalSrc("Should have swapped msb & lsb earlier.");
string ivar = string("__Vi")+cvtToStr(vecnum);

View File

@ -465,7 +465,7 @@ void EmitCSyms::emitSymImp() {
bounds += " ,"; bounds += cvtToStr(adtypep->arrayp()->msbConst());
bounds += ","; bounds += cvtToStr(adtypep->arrayp()->lsbConst());
dim++;
dtypep = adtypep->dtypep();
dtypep = adtypep->subDTypep();
}
else break; // AstBasicDType - nothing below, 1
}

View File

@ -491,7 +491,11 @@ class EmitVBaseVisitor : public EmitCBaseVisitor {
}
virtual void visit(AstConstDType* nodep, AstNUser*) {
putfs(nodep,"const ");
nodep->dtypep()->iterateAndNext(*this);
nodep->subDTypep()->iterateAndNext(*this);
}
virtual void visit(AstArrayDType* nodep, AstNUser*) {
nodep->subDTypep()->iterateAndNext(*this);
nodep->arrayp()->iterateAndNext(*this);
}
virtual void visit(AstNodeFTaskRef* nodep, AstNUser*) {
if (nodep->dotted()!="") { putfs(nodep,nodep->dotted()); puts("."); puts(nodep->prettyName()); }

View File

@ -552,7 +552,7 @@ private:
defp = m_curVarsp->findIdUpward(nodep->name())->castTypedef();
}
if (!defp) { nodep->v3error("Can't find typedef: "<<nodep->prettyName()); }
nodep->defp(defp->dtypep());
nodep->subDTypep(defp->subDTypep());
nodep->packagep(packageFor(defp));
}
nodep->iterateChildren(*this);

View File

@ -80,7 +80,8 @@ private:
if ((int)nodep->dtypep()->arrayElements() > v3Global.opt.traceMaxArray()) return "Wide memory > --trace-max-array ents";
if (!(nodep->dtypeSkipRefp()->castBasicDType()
|| (nodep->dtypeSkipRefp()->castArrayDType()
&& nodep->dtypeSkipRefp()->castArrayDType()->dtypeSkipRefp()->castBasicDType()))) {
&& (nodep->dtypeSkipRefp()->castArrayDType()->subDTypep()
->skipRefp()->castBasicDType())))) {
return "Unsupported: Multi-dimensional array";
}
return NULL;