From fc7a449f6d4226d5835ad7cc50bd583598b18bdb Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Wed, 3 Sep 2008 17:40:01 -0400 Subject: [PATCH] Rename asInt/asQuad to indicate signed/unsigned. Internal code rename, no function change. --- src/V3AstNodes.h | 4 ++-- src/V3Const.cpp | 2 +- src/V3EmitC.cpp | 2 +- src/V3Number.cpp | 40 ++++++++++++++++++++-------------------- src/V3Number.h | 11 ++++++----- src/V3Unroll.cpp | 2 +- 6 files changed, 31 insertions(+), 30 deletions(-) diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index 6c5fc0256..6b642cfe5 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -51,11 +51,11 @@ public: virtual string name() const { return num().ascii(); } // * = Value virtual const V3Number& num() const { return m_num; } // * = Value uint32_t asInt() const { return num().asInt(); } - vluint64_t asQuad() const { return num().asQuad(); } + vluint64_t toUQuad() const { return num().toUQuad(); } virtual string emitVerilog() { V3ERROR_NA; return ""; } // Implemented specially virtual string emitC() { V3ERROR_NA; return ""; } virtual bool cleanOut() { return true; } - virtual V3Hash sameHash() const { return V3Hash(num().asHash()); } + virtual V3Hash sameHash() const { return V3Hash(num().toHash()); } virtual bool same(AstNode* samep) const { return num().isCaseEq(samep->castConst()->num()); } virtual int instrCount() const { return widthInstrs(); } diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 65e7b9a93..d0295469d 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -143,7 +143,7 @@ private: bool operandIsTwo(AstNode* nodep) { return (nodep->castConst() && nodep->width() <= VL_QUADSIZE - && nodep->castConst()->asQuad()==2); + && nodep->castConst()->toUQuad()==2); } bool operandIsTwostate(AstNode* nodep) { return (nodep->castConst() diff --git a/src/V3EmitC.cpp b/src/V3EmitC.cpp index b3c4e871c..657365e1e 100644 --- a/src/V3EmitC.cpp +++ b/src/V3EmitC.cpp @@ -484,7 +484,7 @@ public: } ofp()->printf(",0x%08x)", nodep->num().dataWord(0)); } else if (nodep->isQuad()) { - vluint64_t num = nodep->asQuad(); + vluint64_t num = nodep->toUQuad(); if (num<10) ofp()->printf("VL_ULL(%lld)", (long long)num); else ofp()->printf("VL_ULL(0x%llx)", (long long)num); } else { diff --git a/src/V3Number.cpp b/src/V3Number.cpp index 045193cae..ce7d09ccb 100644 --- a/src/V3Number.cpp +++ b/src/V3Number.cpp @@ -444,9 +444,9 @@ string V3Number::displayed(const string& vformat) const { return "ERR"; } if (issigned) { - str = cvtToStr(asSQuad()); + str = cvtToStr(toSQuad()); } else { - str = cvtToStr(asQuad()); + str = cvtToStr(toUQuad()); } int intfmtsize = atoi(fmtsize.c_str()); while ((int)(str.length()) < intfmtsize) str = " "+str; @@ -461,34 +461,34 @@ string V3Number::displayed(const string& vformat) const { //====================================================================== // ACCESSORS - as numbers -uint32_t V3Number::asInt() const { - UASSERT(!isFourState(),"asInt with 4-state "<<*this); +uint32_t V3Number::toUInt() const { + UASSERT(!isFourState(),"toUInt with 4-state "<<*this); UASSERT((width()<33 || (width()<65 && m_value[1]==0)), "Value too wide "<<*this); return m_value[0]; } -vlsint32_t V3Number::asSInt() const { - uint32_t v = asInt(); +vlsint32_t V3Number::toSInt() const { + uint32_t v = toUInt(); uint32_t signExtend = (-(v & (1UL<<(width()-1)))); uint32_t extended = v | signExtend; return (vlsint32_t)(extended); } -vluint64_t V3Number::asQuad() const { - UASSERT(!isFourState(),"asQuad with 4-state "<<*this); +vluint64_t V3Number::toUQuad() const { + UASSERT(!isFourState(),"toUQuad with 4-state "<<*this); UASSERT(width()<65, "Value too wide "<<*this); - if (width()<=32) return ((vluint64_t)(asInt())); + if (width()<=32) return ((vluint64_t)(toUInt())); return ((vluint64_t)m_value[1]<v3warn(WIDTHCONCAT,"Unsized numbers/parameters not allowed in replications."); - return opRepl(lhs, rhs.asInt()); + return opRepl(lhs, rhs.toUInt()); } V3Number& V3Number::opRepl (const V3Number& lhs, uint32_t rhsval) { // rhs is # of times to replicate @@ -937,7 +937,7 @@ V3Number& V3Number::opShiftR (const V3Number& lhs, const V3Number& rhs) { // L(lhs) bit return if (rhs.isFourState()) return setAllBitsX(); setZero(); - uint32_t rhsval = rhs.asInt(); + uint32_t rhsval = rhs.toUInt(); for (int bit=0; bitwidth(); bit++) { setBit(bit,lhs.bitIs(bit + rhsval)); } @@ -950,7 +950,7 @@ V3Number& V3Number::opShiftRS (const V3Number& lhs, const V3Number& rhs) { // We presume it is signed; as that's V3Signed's job to convert to opShiftR if (rhs.isFourState()) return setAllBitsX(); setZero(); - uint32_t rhsval = rhs.asInt(); + uint32_t rhsval = rhs.toUInt(); for (int bit=0; bitwidth(); bit++) { setBit(bit,lhs.bitIsExtend(bit + rhsval)); } @@ -960,7 +960,7 @@ V3Number& V3Number::opShiftRS (const V3Number& lhs, const V3Number& rhs) { V3Number& V3Number::opShiftL (const V3Number& lhs, const V3Number& rhs) { // L(lhs) bit return if (rhs.isFourState()) return setAllBitsX(); - uint32_t rhsval = rhs.asInt(); + uint32_t rhsval = rhs.toUInt(); setZero(); for (int bit=0; bitwidth(); bit++) { if (bit >= (int)rhsval) { @@ -1009,7 +1009,7 @@ V3Number& V3Number::opMul (const V3Number& lhs, const V3Number& rhs) { if (lhs.isFourState() || rhs.isFourState()) return setAllBitsX(); setZero(); if (width() <= 64) { - setQuad(lhs.asQuad() * rhs.asQuad()); + setQuad(lhs.toUQuad() * rhs.toUQuad()); opCleanThis(); // Mult produces extra bits in result } else { for (int lword=0; lword64) m_fileline->v3fatalSrc("Unsupported: Large / math not implemented yet: "<<*this); if (rhs.width()>64) m_fileline->v3fatalSrc("Unsupported: Large / math not implemented yet: "<<*this); - setQuad(lhs.asQuad() / rhs.asQuad()); + setQuad(lhs.toUQuad() / rhs.toUQuad()); return *this; } V3Number& V3Number::opDivS (const V3Number& lhs, const V3Number& rhs) { @@ -1070,7 +1070,7 @@ V3Number& V3Number::opModDiv (const V3Number& lhs, const V3Number& rhs) { if (rhs.isEqZero()) return setAllBitsX(); if (lhs.width()>64) m_fileline->v3fatalSrc("Unsupported: Large % math not implemented yet: "<<*this); if (rhs.width()>64) m_fileline->v3fatalSrc("Unsupported: Large % math not implemented yet: "<<*this); - setQuad(lhs.asQuad() % rhs.asQuad()); + setQuad(lhs.toUQuad() % rhs.toUQuad()); return *this; } V3Number& V3Number::opModDivS (const V3Number& lhs, const V3Number& rhs) { @@ -1151,7 +1151,7 @@ void V3Number::opCleanThis() { V3Number& V3Number::opRange (const V3Number& lhs, const V3Number& msb, const V3Number& lsb) { if (lsb.isFourState() || msb.isFourState()) return setAllBitsX(); - return opRange(lhs, msb.asInt(), lsb.asInt()); + return opRange(lhs, msb.toUInt(), lsb.toUInt()); } V3Number& V3Number::opRange (const V3Number& lhs, uint32_t msbval, uint32_t lsbval) { diff --git a/src/V3Number.h b/src/V3Number.h index 148a2ca29..8f377ab98 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -135,11 +135,12 @@ public: void width(int width, bool sized=true); void isSigned(bool ssigned) { m_signed=ssigned; } bool isUnknown() const; - uint32_t asInt() const; - vlsint32_t asSInt() const; - vluint64_t asQuad() const; - vlsint64_t asSQuad() const; - uint32_t asHash() const; + uint32_t asInt() const { return toUInt(); } // Deprecated, use toUInt/toSInt + uint32_t toUInt() const; + vlsint32_t toSInt() const; + vluint64_t toUQuad() const; + vlsint64_t toSQuad() const; + uint32_t toHash() const; uint32_t dataWord(int word) const; uint32_t countOnes() const; uint32_t mostSetBitP1() const; // Highest bit set plus one, IE for 16 return 5, for 0 return 0. diff --git a/src/V3Unroll.cpp b/src/V3Unroll.cpp index 8174cc9c7..d979ad92a 100644 --- a/src/V3Unroll.cpp +++ b/src/V3Unroll.cpp @@ -161,7 +161,7 @@ private: vlsint32_t valInit = constInitp->num().asInt(); // Extract as unsigned, then make signed vlsint32_t valStop = constStopp->num().asInt(); // Extract as unsigned, then make signed if (lte) valStop++; if (gte) valStop--; - vlsint32_t valInc = constIncp->num().asSInt(); + vlsint32_t valInc = constIncp->num().toSInt(); if (subtract) valInc = -valInc; UINFO(8," In Numbers: for (v="<