mirror of
https://github.com/verilator/verilator.git
synced 2025-04-21 12:06:55 +00:00
Internals: Rename and cleanup some width() usages. No functional change.
This commit is contained in:
parent
71cd6f7b90
commit
29e24818a1
@ -394,7 +394,7 @@ private:
|
|||||||
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
|
nodep->unlinkFrBack()->deleteTree(); nodep=NULL;
|
||||||
} else if (nodep->varrefp()) {
|
} else if (nodep->varrefp()) {
|
||||||
// V3LinkResolve should have cleaned most of these up
|
// V3LinkResolve should have cleaned most of these up
|
||||||
if (nodep->varrefp()->width()>1) nodep->v3error("Unsupported: Non-single bit wide signal pos/negedge sensitivity: "
|
if (!nodep->varrefp()->width1()) nodep->v3error("Unsupported: Non-single bit wide signal pos/negedge sensitivity: "
|
||||||
<<nodep->varrefp()->prettyName());
|
<<nodep->varrefp()->prettyName());
|
||||||
m_itemSequent = true;
|
m_itemSequent = true;
|
||||||
nodep->varrefp()->varp()->usedClock(true);
|
nodep->varrefp()->varp()->usedClock(true);
|
||||||
|
12
src/V3Ast.h
12
src/V3Ast.h
@ -932,15 +932,17 @@ public:
|
|||||||
bool isAllOnes();
|
bool isAllOnes();
|
||||||
bool isAllOnesV(); // Verilog width rules apply
|
bool isAllOnesV(); // Verilog width rules apply
|
||||||
|
|
||||||
// METHODS
|
// METHODS - dump and error
|
||||||
|
void v3errorEnd(ostringstream& str) const;
|
||||||
|
virtual void dump(ostream& str=cout);
|
||||||
|
|
||||||
|
// METHODS - Tree modifications
|
||||||
AstNode* addNext(AstNode* newp); // Returns this, adds to end of list
|
AstNode* addNext(AstNode* newp); // Returns this, adds to end of list
|
||||||
AstNode* addNextNull(AstNode* newp); // Returns this, adds to end of list, NULL is OK
|
AstNode* addNextNull(AstNode* newp); // Returns this, adds to end of list, NULL is OK
|
||||||
void addNextHere(AstNode* newp); // Adds after speced node
|
void addNextHere(AstNode* newp); // Adds after speced node
|
||||||
void addPrev(AstNode* newp) { replaceWith(newp); newp->addNext(this); }
|
void addPrev(AstNode* newp) { replaceWith(newp); newp->addNext(this); }
|
||||||
void addHereThisAsNext(AstNode* newp); // Adds at old place of this, this becomes next
|
void addHereThisAsNext(AstNode* newp); // Adds at old place of this, this becomes next
|
||||||
void replaceWith(AstNode* newp); // Replace current node in tree with new node
|
void replaceWith(AstNode* newp); // Replace current node in tree with new node
|
||||||
void v3errorEnd(ostringstream& str) const;
|
|
||||||
virtual void dump(ostream& str=cout);
|
|
||||||
AstNode* unlinkFrBack(AstNRelinker* linkerp=NULL); // Unlink this from whoever points to it.
|
AstNode* unlinkFrBack(AstNRelinker* linkerp=NULL); // Unlink this from whoever points to it.
|
||||||
AstNode* unlinkFrBackWithNext(AstNRelinker* linkerp=NULL); // Unlink this from whoever points to it, keep entire next list with unlinked node
|
AstNode* unlinkFrBackWithNext(AstNRelinker* linkerp=NULL); // Unlink this from whoever points to it, keep entire next list with unlinked node
|
||||||
void swapWith(AstNode* bp);
|
void swapWith(AstNode* bp);
|
||||||
@ -1493,7 +1495,7 @@ public:
|
|||||||
inline bool AstNode::isZero() { return (this->castConst() && this->castConst()->num().isEqZero()); }
|
inline bool AstNode::isZero() { return (this->castConst() && this->castConst()->num().isEqZero()); }
|
||||||
inline bool AstNode::isNeqZero() { return (this->castConst() && this->castConst()->num().isNeqZero()); }
|
inline bool AstNode::isNeqZero() { return (this->castConst() && this->castConst()->num().isNeqZero()); }
|
||||||
inline bool AstNode::isOne() { return (this->castConst() && this->castConst()->num().isEqOne()); }
|
inline bool AstNode::isOne() { return (this->castConst() && this->castConst()->num().isEqOne()); }
|
||||||
inline bool AstNode::isAllOnes() { return (this->castConst() && this->castConst()->num().isEqAllOnes(this->width())); }
|
inline bool AstNode::isAllOnes() { return (this->castConst() && this->castConst()->isEqAllOnes()); }
|
||||||
inline bool AstNode::isAllOnesV() { return (this->castConst() && this->castConst()->num().isEqAllOnes(this->widthMin())); }
|
inline bool AstNode::isAllOnesV() { return (this->castConst() && this->castConst()->isEqAllOnesV()); }
|
||||||
|
|
||||||
#endif // Guard
|
#endif // Guard
|
||||||
|
@ -49,18 +49,18 @@ public:
|
|||||||
AstConst(FileLine* fl, const V3Number& num)
|
AstConst(FileLine* fl, const V3Number& num)
|
||||||
:AstNodeMath(fl)
|
:AstNodeMath(fl)
|
||||||
,m_num(num) {
|
,m_num(num) {
|
||||||
width(m_num.width(), m_num.sized()?0:m_num.minWidth());
|
width(m_num.width(), m_num.sized()?0:m_num.widthMin());
|
||||||
numeric(m_num.isDouble() ? AstNumeric::DOUBLE
|
numeric(m_num.isDouble() ? AstNumeric::DOUBLE
|
||||||
: m_num.isSigned() ? AstNumeric::SIGNED
|
: m_num.isSigned() ? AstNumeric::SIGNED
|
||||||
: AstNumeric::UNSIGNED);
|
: AstNumeric::UNSIGNED);
|
||||||
}
|
}
|
||||||
AstConst(FileLine* fl, uint32_t num)
|
AstConst(FileLine* fl, uint32_t num)
|
||||||
:AstNodeMath(fl)
|
:AstNodeMath(fl)
|
||||||
,m_num(V3Number(fl,32,num)) { width(m_num.width(), m_num.sized()?0:m_num.minWidth()); }
|
,m_num(V3Number(fl,32,num)) { width(m_num.width(), m_num.sized()?0:m_num.widthMin()); }
|
||||||
class Unsized32 {}; // for creator type-overload selection
|
class Unsized32 {}; // for creator type-overload selection
|
||||||
AstConst(FileLine* fl, Unsized32, uint32_t num) // Unsized 32-bit integer of specified value
|
AstConst(FileLine* fl, Unsized32, uint32_t num) // Unsized 32-bit integer of specified value
|
||||||
:AstNodeMath(fl)
|
:AstNodeMath(fl)
|
||||||
,m_num(V3Number(fl,32,num)) { m_num.width(32,false); width(32,m_num.minWidth()); }
|
,m_num(V3Number(fl,32,num)) { m_num.width(32,false); width(32,m_num.widthMin()); }
|
||||||
class RealDouble {}; // for creator type-overload selection
|
class RealDouble {}; // for creator type-overload selection
|
||||||
AstConst(FileLine* fl, RealDouble, double num)
|
AstConst(FileLine* fl, RealDouble, double num)
|
||||||
:AstNodeMath(fl)
|
:AstNodeMath(fl)
|
||||||
@ -87,6 +87,8 @@ public:
|
|||||||
virtual bool same(AstNode* samep) const {
|
virtual bool same(AstNode* samep) const {
|
||||||
return num().isCaseEq(samep->castConst()->num()); }
|
return num().isCaseEq(samep->castConst()->num()); }
|
||||||
virtual int instrCount() const { return widthInstrs(); }
|
virtual int instrCount() const { return widthInstrs(); }
|
||||||
|
bool isEqAllOnes() const { return num().isEqAllOnes(width()); }
|
||||||
|
bool isEqAllOnesV() const { return num().isEqAllOnes(widthMin()); }
|
||||||
};
|
};
|
||||||
|
|
||||||
struct AstConstString : public AstNodeMath {
|
struct AstConstString : public AstNodeMath {
|
||||||
@ -2595,8 +2597,8 @@ struct AstRedXor : public AstNodeUniop {
|
|||||||
virtual string emitVerilog() { return "%f(^ %l)"; }
|
virtual string emitVerilog() { return "%f(^ %l)"; }
|
||||||
virtual string emitC() { return "VL_REDXOR_%lq(%lW, %P, %li)"; }
|
virtual string emitC() { return "VL_REDXOR_%lq(%lW, %P, %li)"; }
|
||||||
virtual bool cleanOut() {return false;}
|
virtual bool cleanOut() {return false;}
|
||||||
virtual bool cleanLhs() {return (lhsp()->width()!=1 && lhsp()->width()!=2 && lhsp()->width()!=4
|
virtual bool cleanLhs() {int w = lhsp()->width();
|
||||||
&& lhsp()->width()!=8 && lhsp()->width()!=16);}
|
return (w!=1 && w!=2 && w!=4 && w!=8 && w!=16); }
|
||||||
virtual bool sizeMattersLhs() {return false;}
|
virtual bool sizeMattersLhs() {return false;}
|
||||||
virtual int instrCount() const { return 1+V3Number::log2b(width()); }
|
virtual int instrCount() const { return 1+V3Number::log2b(width()); }
|
||||||
};
|
};
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
// For each math operator, if it requires a clean operand,
|
// For each math operator, if it requires a clean operand,
|
||||||
// and the operand is dirty, insert a CLEAN node.
|
// and the operand is dirty, insert a CLEAN node.
|
||||||
// Resize operands to C++ 32/64/wide types.
|
// Resize operands to C++ 32/64/wide types.
|
||||||
// Copy all width() values to minWidth() so RANGE, etc can still see orig widths
|
// Copy all width() values to widthMin() so RANGE, etc can still see orig widths
|
||||||
//
|
//
|
||||||
//*************************************************************************
|
//*************************************************************************
|
||||||
|
|
||||||
@ -47,7 +47,7 @@ private:
|
|||||||
// NODE STATE
|
// NODE STATE
|
||||||
// Entire netlist:
|
// Entire netlist:
|
||||||
// AstNode::user() -> CleanState. For this node, 0==UNKNOWN
|
// AstNode::user() -> CleanState. For this node, 0==UNKNOWN
|
||||||
// AstNode::user2() -> bool. True indicates minWidth has been propagated
|
// AstNode::user2() -> bool. True indicates widthMin has been propagated
|
||||||
AstUser1InUse m_inuser1;
|
AstUser1InUse m_inuser1;
|
||||||
AstUser2InUse m_inuser2;
|
AstUser2InUse m_inuser2;
|
||||||
|
|
||||||
|
@ -83,10 +83,9 @@ private:
|
|||||||
AstVarScope* getCreateLastClk(AstVarScope* vscp) {
|
AstVarScope* getCreateLastClk(AstVarScope* vscp) {
|
||||||
if (vscp->user1p()) return ((AstVarScope*)vscp->user1p());
|
if (vscp->user1p()) return ((AstVarScope*)vscp->user1p());
|
||||||
AstVar* varp = vscp->varp();
|
AstVar* varp = vscp->varp();
|
||||||
if (varp->width()!=1) varp->v3error("Unsupported: Clock edge on non-single bit signal: "<<varp->prettyName());
|
if (!varp->width1()) varp->v3error("Unsupported: Clock edge on non-single bit signal: "<<varp->prettyName());
|
||||||
string newvarname = ((string)"__Vclklast__"+vscp->scopep()->nameDotless()+"__"+varp->shortName());
|
string newvarname = ((string)"__Vclklast__"+vscp->scopep()->nameDotless()+"__"+varp->shortName());
|
||||||
AstVar* newvarp = new AstVar (vscp->fileline(), AstVarType::MODULETEMP, newvarname, AstLogicPacked(), 1);
|
AstVar* newvarp = new AstVar (vscp->fileline(), AstVarType::MODULETEMP, newvarname, AstLogicPacked(), 1);
|
||||||
newvarp->width(1,1);
|
|
||||||
m_modp->addStmtp(newvarp);
|
m_modp->addStmtp(newvarp);
|
||||||
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopep, newvarp);
|
AstVarScope* newvscp = new AstVarScope(vscp->fileline(), m_scopep, newvarp);
|
||||||
vscp->user1p(newvscp);
|
vscp->user1p(newvscp);
|
||||||
|
@ -552,7 +552,7 @@ public:
|
|||||||
nodep->v3error("Unsupported: 4-state numbers in this context");
|
nodep->v3error("Unsupported: 4-state numbers in this context");
|
||||||
} else if (nodep->isWide()) {
|
} else if (nodep->isWide()) {
|
||||||
putbs("VL_CONST_W_");
|
putbs("VL_CONST_W_");
|
||||||
puts(cvtToStr(VL_WORDS_I(nodep->num().minWidth())));
|
puts(cvtToStr(VL_WORDS_I(nodep->num().widthMin())));
|
||||||
puts("X(");
|
puts("X(");
|
||||||
puts(cvtToStr(nodep->widthMin()));
|
puts(cvtToStr(nodep->widthMin()));
|
||||||
puts(",");
|
puts(",");
|
||||||
@ -564,7 +564,7 @@ public:
|
|||||||
} else {
|
} else {
|
||||||
assigntop->iterateAndNext(*this);
|
assigntop->iterateAndNext(*this);
|
||||||
}
|
}
|
||||||
for (int word=VL_WORDS_I(nodep->num().minWidth())-1; word>0; word--) {
|
for (int word=VL_WORDS_I(nodep->num().widthMin())-1; word>0; word--) {
|
||||||
// Only 32 bits - llx + long long here just to appease CPP format warning
|
// Only 32 bits - llx + long long here just to appease CPP format warning
|
||||||
ofp()->printf(",0x%08" VL_PRI64 "x", (vluint64_t)(nodep->num().dataWord(word)));
|
ofp()->printf(",0x%08" VL_PRI64 "x", (vluint64_t)(nodep->num().dataWord(word)));
|
||||||
}
|
}
|
||||||
|
@ -149,7 +149,8 @@ private:
|
|||||||
AstNode* decp = new AstAssign(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, true),
|
AstNode* decp = new AstAssign(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, true),
|
||||||
new AstSub(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
|
new AstSub(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
|
||||||
new AstConst(nodep->fileline(), 1)));
|
new AstConst(nodep->fileline(), 1)));
|
||||||
AstNode* zerosp = new AstConst(nodep->fileline(), 0); zerosp->numeric(AstNumeric::SIGNED);
|
V3Number zero (nodep->fileline(), 32, 0); zero.isSigned(true);
|
||||||
|
AstNode* zerosp = new AstConst(nodep->fileline(), zero);
|
||||||
AstNode* condp = new AstGtS(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
|
AstNode* condp = new AstGtS(nodep->fileline(), new AstVarRef(nodep->fileline(), varp, false),
|
||||||
zerosp);
|
zerosp);
|
||||||
AstNode* bodysp = nodep->bodysp(); if (bodysp) bodysp->unlinkFrBackWithNext();
|
AstNode* bodysp = nodep->bodysp(); if (bodysp) bodysp->unlinkFrBackWithNext();
|
||||||
|
@ -626,7 +626,7 @@ bool V3Number::isLt(const V3Number& rhs) const {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int V3Number::minWidth() const {
|
int V3Number::widthMin() const {
|
||||||
for(int bit=width()-1; bit>0; bit--) {
|
for(int bit=width()-1; bit>0; bit--) {
|
||||||
if (!bitIs0(bit)) return bit+1;
|
if (!bitIs0(bit)) return bit+1;
|
||||||
}
|
}
|
||||||
|
@ -150,7 +150,7 @@ public:
|
|||||||
string displayed(const string& format) const;
|
string displayed(const string& format) const;
|
||||||
static bool displayedFmtLegal(char format); // Is this a valid format letter?
|
static bool displayedFmtLegal(char format); // Is this a valid format letter?
|
||||||
int width() const { return m_width; }
|
int width() const { return m_width; }
|
||||||
int minWidth() const; // Minimum width that can represent this number (~== log2(num)+1)
|
int widthMin() const; // Minimum width that can represent this number (~== log2(num)+1)
|
||||||
bool sized() const { return m_sized; }
|
bool sized() const { return m_sized; }
|
||||||
bool autoExtend() const { return m_autoExtend; }
|
bool autoExtend() const { return m_autoExtend; }
|
||||||
bool isFromString() const { return m_fromString; }
|
bool isFromString() const { return m_fromString; }
|
||||||
|
@ -85,12 +85,12 @@ enum Stage { PRELIM=1,FINAL=2,BOTH=3 };
|
|||||||
class WidthVP : public AstNUser {
|
class WidthVP : public AstNUser {
|
||||||
// Parameters to pass down hierarchy with visit functions.
|
// Parameters to pass down hierarchy with visit functions.
|
||||||
int m_width; // Expression width, for (2+2), it's 32 bits
|
int m_width; // Expression width, for (2+2), it's 32 bits
|
||||||
int m_minWidth; // Minimum width, for (2+2), it's 2 bits, for 32'2+32'2 it's 32 bits
|
int m_widthMin; // Minimum width, for (2+2), it's 2 bits, for 32'2+32'2 it's 32 bits
|
||||||
Stage m_stage; // If true, report errors
|
Stage m_stage; // If true, report errors
|
||||||
public:
|
public:
|
||||||
WidthVP(int width, int minWidth, Stage stage) : m_width(width), m_minWidth(minWidth), m_stage(stage) {}
|
WidthVP(int width, int widthMin, Stage stage) : m_width(width), m_widthMin(widthMin), m_stage(stage) {}
|
||||||
int width() const { return m_width; }
|
int width() const { return m_width; }
|
||||||
int widthMin() const { return m_minWidth?m_minWidth:m_width; }
|
int widthMin() const { return m_widthMin?m_widthMin:m_width; }
|
||||||
bool prelim() const { return m_stage&1; }
|
bool prelim() const { return m_stage&1; }
|
||||||
bool final() const { return m_stage&2; }
|
bool final() const { return m_stage&2; }
|
||||||
};
|
};
|
||||||
@ -526,7 +526,7 @@ private:
|
|||||||
if (nodep->num().sized()) {
|
if (nodep->num().sized()) {
|
||||||
nodep->width(nodep->num().width(), nodep->num().width());
|
nodep->width(nodep->num().width(), nodep->num().width());
|
||||||
} else {
|
} else {
|
||||||
nodep->width(nodep->num().width(), nodep->num().minWidth());
|
nodep->width(nodep->num().width(), nodep->num().widthMin());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// We don't size the constant until we commit the widths, as need parameters
|
// We don't size the constant until we commit the widths, as need parameters
|
||||||
@ -1474,7 +1474,7 @@ private:
|
|||||||
checkCvtUS(nodep->lhsp());
|
checkCvtUS(nodep->lhsp());
|
||||||
}
|
}
|
||||||
int width = nodep->lhsp()->width();
|
int width = nodep->lhsp()->width();
|
||||||
int ewidth = nodep->lhsp()->width(); // Not minWidth; force it.
|
int ewidth = nodep->lhsp()->width(); // Not widthMin; force it.
|
||||||
nodep->width(width,ewidth);
|
nodep->width(width,ewidth);
|
||||||
nodep->numeric(rs_out);
|
nodep->numeric(rs_out);
|
||||||
if (vup->c()->final()) {
|
if (vup->c()->final()) {
|
||||||
|
@ -126,7 +126,7 @@ private:
|
|||||||
AstNode* newp = new AstSub(rhsp->fileline(),
|
AstNode* newp = new AstSub(rhsp->fileline(),
|
||||||
new AstConst(rhsp->fileline(), AstConst::Unsized32(), lhs),
|
new AstConst(rhsp->fileline(), AstConst::Unsized32(), lhs),
|
||||||
rhsp);
|
rhsp);
|
||||||
newp->numericFrom(rhsp); // Important as AstSub default is lhs's sign
|
newp->widthSignedFrom(rhsp); // Important as AstSub default is lhs's sign
|
||||||
return newp;
|
return newp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user