diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 1fef6d4c0..c2ef9e0d5 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -1368,8 +1368,7 @@ class ConstVisitor final : public VNVisitor { nodep->rhsp(smallerp); constp->unlinkFrBack(); - V3Number num{constp, subsize}; - num.opAssign(constp->num()); + V3Number num{constp, subsize, constp->num()}; nodep->lhsp(new AstConst{constp->fileline(), num}); VL_DO_DANGLING(pushDeletep(constp), constp); if (debug() >= 9) nodep->dumpTree("- BI(EXTEND)-ou: "); diff --git a/src/V3Number.h b/src/V3Number.h index 806af9ab3..3b46b2e05 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -466,6 +466,11 @@ public: V3Number(AstNode* nodep, int width) { // 0=unsized init(nodep, width, width > 0); } + // Construct with value, changing to new width + V3Number(AstNode* nodep, int width, const V3Number& value) { + init(nodep, width, width > 0); + opAssign(value); + } V3Number(AstNode* nodep, int width, uint32_t value, bool sized = true) { init(nodep, width, sized); m_data.num()[0].m_value = value; diff --git a/src/V3Simulate.h b/src/V3Simulate.h index c98bfeb53..c2a3f79ea 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -603,8 +603,7 @@ private: // but in reality it would yield '0's without V3Table, so force 'x' bits to '0', // to ensure the result is the same with and without V3Table. if (!m_params && VN_IS(nodep, Sel) && valuep->num().isAnyX()) { - V3Number num{valuep, valuep->width()}; - num.opAssign(valuep->num()); + V3Number num{valuep, valuep->width(), valuep->num()}; valuep->num().opBitsOne(num); } } diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 1f5f5ae18..5e75473b2 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -6764,8 +6764,7 @@ class WidthVisitor final : public VNVisitor { if (nodep->rhsp()->width() > 32) { if (shiftp && shiftp->num().mostSetBitP1() <= 32) { // If (number)<<96'h1, then make it into (number)<<32'h1 - V3Number num(shiftp, 32, 0); - num.opAssign(shiftp->num()); + V3Number num{shiftp, 32, shiftp->num()}; AstNode* const shiftrhsp = nodep->rhsp(); nodep->rhsp()->replaceWith(new AstConst{shiftrhsp->fileline(), num}); VL_DO_DANGLING(shiftrhsp->deleteTree(), shiftrhsp); @@ -6935,8 +6934,7 @@ class WidthVisitor final : public VNVisitor { const int expWidth = expDTypep->width(); if (constp && !constp->num().isNegative()) { // Save later constant propagation work, just right-size it. - V3Number num(nodep, expWidth); - num.opAssign(constp->num()); + V3Number num{nodep, expWidth, constp->num()}; num.isSigned(false); AstNodeExpr* const newp = new AstConst{nodep->fileline(), num}; constp->replaceWith(newp); diff --git a/src/V3WidthCommit.h b/src/V3WidthCommit.h index c2b124f0e..60af3c782 100644 --- a/src/V3WidthCommit.h +++ b/src/V3WidthCommit.h @@ -30,8 +30,7 @@ public: static AstConst* newIfConstCommitSize(AstConst* nodep) { if (((nodep->dtypep()->width() != nodep->num().width()) || !nodep->num().sized()) && !nodep->num().isString()) { // Need to force the number from unsized to sized - V3Number num{nodep, nodep->dtypep()->width()}; - num.opAssign(nodep->num()); + V3Number num{nodep, nodep->dtypep()->width(), nodep->num()}; num.isSigned(nodep->isSigned()); AstConst* const newp = new AstConst{nodep->fileline(), num}; newp->dtypeFrom(nodep);