Internals: Rename AstCast to AstCCast

This commit is contained in:
Wilson Snyder 2011-03-17 21:09:52 -04:00
parent 2923893d34
commit 9704f59566
6 changed files with 33 additions and 33 deletions

View File

@ -522,7 +522,7 @@ void AstBasicDType::dump(ostream& str) {
str<<" ["<<keyword().ascii()<<"]"; str<<" ["<<keyword().ascii()<<"]";
if (implicit()) str<<" [IMPLICIT]"; if (implicit()) str<<" [IMPLICIT]";
} }
void AstCast::dump(ostream& str) { void AstCCast::dump(ostream& str) {
this->AstNode::dump(str); this->AstNode::dump(str);
str<<" sz"<<size(); str<<" sz"<<size();
} }

View File

@ -2622,27 +2622,27 @@ struct AstOneHot0 : public AstNodeUniop {
virtual int instrCount() const { return widthInstrs()*3; } virtual int instrCount() const { return widthInstrs()*3; }
}; };
struct AstCast : public AstNodeUniop { struct AstCCast : public AstNodeUniop {
// Cast to appropriate data type // Cast to appropriate data type
private: private:
int m_size; int m_size;
public: public:
AstCast(FileLine* fl, AstNode* lhsp, int setwidth) : AstNodeUniop(fl, lhsp) { AstCCast(FileLine* fl, AstNode* lhsp, int setwidth) : AstNodeUniop(fl, lhsp) {
m_size=setwidth; m_size=setwidth;
if (setwidth) { width(setwidth,setwidth); } if (setwidth) { width(setwidth,setwidth); }
} }
AstCast(FileLine* fl, AstNode* lhsp, AstNode* widthFromp) : AstNodeUniop(fl, lhsp) { AstCCast(FileLine* fl, AstNode* lhsp, AstNode* widthFromp) : AstNodeUniop(fl, lhsp) {
if (widthFromp) { widthSignedFrom(widthFromp); } if (widthFromp) { widthSignedFrom(widthFromp); }
m_size=width(); m_size=width();
} }
ASTNODE_NODE_FUNCS(Cast, CAST) ASTNODE_NODE_FUNCS(CCast, CCAST)
virtual void numberOperate(V3Number& out, const V3Number& lhs) { out.opAssign(lhs); } virtual void numberOperate(V3Number& out, const V3Number& lhs) { out.opAssign(lhs); }
virtual string emitVerilog() { return "%f$_CAST(%l)"; } virtual string emitVerilog() { return "%f$_CAST(%l)"; }
virtual string emitC() { return "VL_CAST_%nq%lq(%nw,%lw, %P, %li)"; } virtual string emitC() { return "VL_CAST_%nq%lq(%nw,%lw, %P, %li)"; }
virtual bool cleanOut() {return true;} virtual bool cleanLhs() {return true;} virtual bool cleanOut() {return true;} virtual bool cleanLhs() {return true;}
virtual bool sizeMattersLhs() {return false;} // Special cased in V3Cast virtual bool sizeMattersLhs() {return false;} // Special cased in V3Cast
virtual V3Hash sameHash() const { return V3Hash(size()); } virtual V3Hash sameHash() const { return V3Hash(size()); }
virtual bool same(AstNode* samep) const { return size()==samep->castCast()->size(); } virtual bool same(AstNode* samep) const { return size()==samep->castCCast()->size(); }
virtual void dump(ostream& str=cout); virtual void dump(ostream& str=cout);
// //
int size() const { return m_size; } int size() const { return m_size; }

View File

@ -77,7 +77,7 @@ private:
AstNRelinker relinkHandle; AstNRelinker relinkHandle;
nodep->unlinkFrBack(&relinkHandle); nodep->unlinkFrBack(&relinkHandle);
// //
AstCast* castp = new AstCast (nodep->fileline(), nodep, needsize); AstCCast* castp = new AstCCast (nodep->fileline(), nodep, needsize);
castp->width(needsize, nodep->widthMin()); castp->width(needsize, nodep->widthMin());
relinkHandle.relink(castp); relinkHandle.relink(castp);
//if (debug()>8) castp->dumpTree(cout,"-castins: "); //if (debug()>8) castp->dumpTree(cout,"-castins: ");
@ -97,13 +97,13 @@ private:
insertCast(nodep, castSize(nodep->backp())); insertCast(nodep, castSize(nodep->backp()));
} }
} }
void insureLower32Cast(AstCast* nodep) { void insureLower32Cast(AstCCast* nodep) {
// If we have uint64 = CAST(uint64(x)) then the upcasting // If we have uint64 = CAST(uint64(x)) then the upcasting
// really needs to be CAST(uint64(CAST(uint32(x))). // really needs to be CAST(uint64(CAST(uint32(x))).
// Otherwise a (uint64)(a>b) would return wrong value, as // Otherwise a (uint64)(a>b) would return wrong value, as
// less than has undeterministic signedness. // less than has undeterministic signedness.
if (nodep->isQuad() && !nodep->lhsp()->isQuad() if (nodep->isQuad() && !nodep->lhsp()->isQuad()
&& !nodep->lhsp()->castCast()) { && !nodep->lhsp()->castCCast()) {
insertCast(nodep->lhsp(), VL_WORDSIZE); insertCast(nodep->lhsp(), VL_WORDSIZE);
} }
} }
@ -130,7 +130,7 @@ private:
if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp()); if (nodep->sizeMattersRhs()) insureCast(nodep->rhsp());
if (nodep->sizeMattersThs()) insureCast(nodep->thsp()); if (nodep->sizeMattersThs()) insureCast(nodep->thsp());
} }
virtual void visit(AstCast* nodep, AstNUser*) { virtual void visit(AstCCast* nodep, AstNUser*) {
nodep->iterateChildren(*this); nodep->iterateChildren(*this);
insureLower32Cast(nodep); insureLower32Cast(nodep);
nodep->user1(1); nodep->user1(1);
@ -149,7 +149,7 @@ private:
} }
virtual void visit(AstVarRef* nodep, AstNUser*) { virtual void visit(AstVarRef* nodep, AstNUser*) {
if (!nodep->lvalue() if (!nodep->lvalue()
&& !nodep->backp()->castCast() && !nodep->backp()->castCCast()
&& nodep->backp()->castNodeMath() && nodep->backp()->castNodeMath()
&& nodep->backp()->width() && nodep->backp()->width()
&& castSize(nodep) != castSize(nodep->varp())) { && castSize(nodep) != castSize(nodep->varp())) {

View File

@ -475,7 +475,7 @@ public:
} }
visit(nodep->castNodeBiop(), vup); visit(nodep->castNodeBiop(), vup);
} }
virtual void visit(AstCast* nodep, AstNUser*) { virtual void visit(AstCCast* nodep, AstNUser*) {
// Extending a value of the same word width is just a NOP. // Extending a value of the same word width is just a NOP.
if (nodep->size()>VL_WORDSIZE) { if (nodep->size()>VL_WORDSIZE) {
puts("(QData)("); puts("(QData)(");

View File

@ -127,18 +127,18 @@ private:
} else if (nodep->isQuad() && word==0) { } else if (nodep->isQuad() && word==0) {
AstNode* quadfromp = nodep->cloneTree(true); AstNode* quadfromp = nodep->cloneTree(true);
quadfromp->width(VL_QUADSIZE,quadfromp->widthMin()); quadfromp->width(VL_QUADSIZE,quadfromp->widthMin());
return new AstCast (nodep->fileline(), return new AstCCast (nodep->fileline(),
quadfromp, quadfromp,
VL_WORDSIZE); VL_WORDSIZE);
} else if (nodep->isQuad() && word==1) { } else if (nodep->isQuad() && word==1) {
AstNode* quadfromp = nodep->cloneTree(true); AstNode* quadfromp = nodep->cloneTree(true);
quadfromp->width(VL_QUADSIZE,quadfromp->widthMin()); quadfromp->width(VL_QUADSIZE,quadfromp->widthMin());
return new AstCast (nodep->fileline(), return new AstCCast (nodep->fileline(),
new AstShiftR (nodep->fileline(), new AstShiftR (nodep->fileline(),
quadfromp, quadfromp,
new AstConst (nodep->fileline(), VL_WORDSIZE), new AstConst (nodep->fileline(), VL_WORDSIZE),
VL_WORDSIZE), VL_WORDSIZE),
VL_WORDSIZE); VL_WORDSIZE);
} else if (!nodep->isWide() && !nodep->isQuad() && word==0) { } else if (!nodep->isWide() && !nodep->isQuad() && word==0) {
return nodep->cloneTree(true); return nodep->cloneTree(true);
} else { // Out of bounds } else { // Out of bounds
@ -324,7 +324,7 @@ private:
nodep->v3fatalSrc("extending larger thing into smaller?"); nodep->v3fatalSrc("extending larger thing into smaller?");
} else { } else {
UINFO(8," EXTEND(q<-l) "<<nodep<<endl); UINFO(8," EXTEND(q<-l) "<<nodep<<endl);
newp = new AstCast (nodep->fileline(), lhsp, nodep); newp = new AstCCast (nodep->fileline(), lhsp, nodep);
} }
} else { // Long } else { // Long
if (lhsp->isQuad() || lhsp->isWide()) { if (lhsp->isQuad() || lhsp->isWide()) {
@ -366,7 +366,7 @@ private:
AstNode* lowwordp = new AstWordSel (nodep->fromp()->fileline(), AstNode* lowwordp = new AstWordSel (nodep->fromp()->fileline(),
nodep->fromp()->cloneTree(true), nodep->fromp()->cloneTree(true),
newSelBitWord(nodep->lsbp(), 0)); newSelBitWord(nodep->lsbp(), 0));
if (nodep->isQuad() && !lowwordp->isQuad()) lowwordp = new AstCast(nodep->fileline(), lowwordp, nodep); if (nodep->isQuad() && !lowwordp->isQuad()) lowwordp = new AstCCast(nodep->fileline(), lowwordp, nodep);
AstNode* lowp = new AstShiftR (nodep->fileline(), AstNode* lowp = new AstShiftR (nodep->fileline(),
lowwordp, lowwordp,
newSelBitBit(nodep->lsbp()), newSelBitBit(nodep->lsbp()),
@ -379,7 +379,7 @@ private:
new AstWordSel (nodep->fromp()->fileline(), new AstWordSel (nodep->fromp()->fileline(),
nodep->fromp()->cloneTree(true), nodep->fromp()->cloneTree(true),
newSelBitWord(nodep->lsbp(), 1)); newSelBitWord(nodep->lsbp(), 1));
if (nodep->isQuad() && !midwordp->isQuad()) midwordp = new AstCast(nodep->fileline(), midwordp, nodep); if (nodep->isQuad() && !midwordp->isQuad()) midwordp = new AstCCast(nodep->fileline(), midwordp, nodep);
// If we're selecting bit zero, then all 32 bits in word 1 get shifted << by 32 bits // If we're selecting bit zero, then all 32 bits in word 1 get shifted << by 32 bits
// else we need to form the lower word, so we << by 31 or less // else we need to form the lower word, so we << by 31 or less
// nbitsfromlow <= (lsb==0) ? 64-bitbit(lsb) : 32-bitbit(lsb) // nbitsfromlow <= (lsb==0) ? 64-bitbit(lsb) : 32-bitbit(lsb)
@ -417,7 +417,7 @@ private:
new AstWordSel (nodep->fromp()->fileline(), new AstWordSel (nodep->fromp()->fileline(),
nodep->fromp()->cloneTree(true), nodep->fromp()->cloneTree(true),
newSelBitWord(nodep->lsbp(), 2)); newSelBitWord(nodep->lsbp(), 2));
if (nodep->isQuad() && !hiwordp->isQuad()) hiwordp = new AstCast(nodep->fileline(), hiwordp, nodep); if (nodep->isQuad() && !hiwordp->isQuad()) hiwordp = new AstCCast(nodep->fileline(), hiwordp, nodep);
AstNode* himayp = AstNode* himayp =
new AstShiftL (nodep->fileline(), new AstShiftL (nodep->fileline(),
hiwordp, hiwordp,
@ -445,14 +445,14 @@ private:
UINFO(8," SEL->SHIFT "<<nodep<<endl); UINFO(8," SEL->SHIFT "<<nodep<<endl);
AstNode* fromp = nodep->fromp()->unlinkFrBack(); AstNode* fromp = nodep->fromp()->unlinkFrBack();
AstNode* lsbp = nodep->lsbp()->unlinkFrBack(); AstNode* lsbp = nodep->lsbp()->unlinkFrBack();
if (nodep->isQuad() && !fromp->isQuad()) fromp = new AstCast(nodep->fileline(), fromp, nodep); if (nodep->isQuad() && !fromp->isQuad()) fromp = new AstCCast(nodep->fileline(), fromp, nodep);
AstNode* newp = new AstShiftR (nodep->fileline(), AstNode* newp = new AstShiftR (nodep->fileline(),
fromp, fromp,
dropCondBound(lsbp), dropCondBound(lsbp),
nodep->width()); nodep->width());
newp->widthSignedFrom(nodep); newp->widthSignedFrom(nodep);
if (!nodep->isQuad() && fromp->isQuad()) { if (!nodep->isQuad() && fromp->isQuad()) {
newp = new AstCast (newp->fileline(), newp, nodep); newp = new AstCCast (newp->fileline(), newp, nodep);
} }
newp->widthSignedFrom(nodep); newp->widthSignedFrom(nodep);
replaceWithDelete(nodep,newp); nodep=NULL; replaceWithDelete(nodep,newp); nodep=NULL;
@ -546,7 +546,7 @@ private:
destp->deleteTree(); destp=NULL; destp->deleteTree(); destp=NULL;
} else { } else {
UINFO(8," ASSIGNSEL(const,narrow) "<<nodep<<endl); UINFO(8," ASSIGNSEL(const,narrow) "<<nodep<<endl);
if (destp->isQuad() && !rhsp->isQuad()) rhsp = new AstCast(nodep->fileline(), rhsp, nodep); if (destp->isQuad() && !rhsp->isQuad()) rhsp = new AstCCast(nodep->fileline(), rhsp, nodep);
AstNode* oldvalp = destp->cloneTree(true); AstNode* oldvalp = destp->cloneTree(true);
fixCloneLvalue(oldvalp); fixCloneLvalue(oldvalp);
if (!ones) oldvalp = new AstAnd (lhsp->fileline(), if (!ones) oldvalp = new AstAnd (lhsp->fileline(),
@ -620,7 +620,7 @@ private:
V3Number maskwidth (nodep->fileline(), destp->widthMin()); V3Number maskwidth (nodep->fileline(), destp->widthMin());
for (int bit=0; bit<(int)lhsp->widthConst(); bit++) maskwidth.setBit(bit,1); for (int bit=0; bit<(int)lhsp->widthConst(); bit++) maskwidth.setBit(bit,1);
if (destp->isQuad() && !rhsp->isQuad()) rhsp = new AstCast(nodep->fileline(), rhsp, nodep); if (destp->isQuad() && !rhsp->isQuad()) rhsp = new AstCCast(nodep->fileline(), rhsp, nodep);
if (!ones) if (!ones)
oldvalp = new AstAnd (lhsp->fileline(), oldvalp = new AstAnd (lhsp->fileline(),
new AstNot (lhsp->fileline(), new AstNot (lhsp->fileline(),
@ -655,8 +655,8 @@ private:
AstNode* lhsp = nodep->lhsp()->unlinkFrBack(); AstNode* lhsp = nodep->lhsp()->unlinkFrBack();
AstNode* rhsp = nodep->rhsp()->unlinkFrBack(); AstNode* rhsp = nodep->rhsp()->unlinkFrBack();
int rhsshift = rhsp->widthMin(); int rhsshift = rhsp->widthMin();
if (nodep->isQuad() && !lhsp->isQuad()) lhsp = new AstCast(nodep->fileline(), lhsp, nodep); if (nodep->isQuad() && !lhsp->isQuad()) lhsp = new AstCCast(nodep->fileline(), lhsp, nodep);
if (nodep->isQuad() && !rhsp->isQuad()) rhsp = new AstCast(nodep->fileline(), rhsp, nodep); if (nodep->isQuad() && !rhsp->isQuad()) rhsp = new AstCCast(nodep->fileline(), rhsp, nodep);
AstNode* newp = new AstOr (nodep->fileline(), AstNode* newp = new AstOr (nodep->fileline(),
new AstShiftL (nodep->fileline(), new AstShiftL (nodep->fileline(),
lhsp, lhsp,
@ -703,7 +703,7 @@ private:
AstConst* constp = nodep->rhsp()->castConst(); AstConst* constp = nodep->rhsp()->castConst();
if (!constp) nodep->v3fatalSrc("Replication value isn't a constant. Checked earlier!"); if (!constp) nodep->v3fatalSrc("Replication value isn't a constant. Checked earlier!");
uint32_t times = constp->toUInt(); uint32_t times = constp->toUInt();
if (nodep->isQuad() && !lhsp->isQuad()) lhsp = new AstCast(nodep->fileline(), lhsp, nodep); if (nodep->isQuad() && !lhsp->isQuad()) lhsp = new AstCCast(nodep->fileline(), lhsp, nodep);
newp = lhsp->cloneTree(true); newp = lhsp->cloneTree(true);
for (unsigned repnum=1; repnum<times; repnum++) { for (unsigned repnum=1; repnum<times; repnum++) {
int rhsshift = repnum*lhswidth; int rhsshift = repnum*lhswidth;

View File

@ -304,7 +304,7 @@ private:
if (debug()>5) nodep->dumpTree(cout," substw_old: "); if (debug()>5) nodep->dumpTree(cout," substw_old: ");
AstNode* newp = substp->cloneTree(true); AstNode* newp = substp->cloneTree(true);
if (!nodep->isQuad() && newp->isQuad()) { if (!nodep->isQuad() && newp->isQuad()) {
newp = new AstCast (newp->fileline(), newp, nodep); newp = new AstCCast (newp->fileline(), newp, nodep);
} }
if (debug()>5) newp->dumpTree(cout," w_new: "); if (debug()>5) newp->dumpTree(cout," w_new: ");
nodep->replaceWith(newp); nodep->replaceWith(newp);