From 3c8519f2453bb33582beede43bd1c92a5a521961 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 3 Mar 2012 16:29:06 -0500 Subject: [PATCH] Fix inheriting real type across untyped parameters. --- Changes | 2 ++ src/V3Width.cpp | 33 +++++++++++++++++---------------- test_regress/t/t_param_value.v | 2 -- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/Changes b/Changes index 78486d9cd..aae3e08e5 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix expansion of back-slashed escaped macros, bug441. [Alberto Del Rio] +**** Fix inheriting real type across untyped parameters. + **** Fix core dump with over 100 deep UNOPTFLAT, bug432. [Joe Eiler] **** Fix false command not found warning in makefiles. [Ruben Diez] diff --git a/src/V3Width.cpp b/src/V3Width.cpp index 2db5a0ab9..258693d59 100644 --- a/src/V3Width.cpp +++ b/src/V3Width.cpp @@ -695,16 +695,21 @@ private: AstBasicDType* bdtypep = nodep->dtypep()->castBasicDType(); bool implicitParam = nodep->isParam() && bdtypep && bdtypep->implicit(); if (implicitParam) { - AstNumeric rs = AstNumeric::UNSIGNED; int width=0; + AstNumeric rs = AstNumeric::UNSIGNED; if (nodep->valuep()) { nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,PRELIM).p()); + UINFO(9,"implicitParamPRELIMIV "<valuep()<valuep()->iterateAndNext(*this,WidthVP(width,0,FINAL).p()); - rs = nodep->numeric(); - if (!rs.isDouble()) { + if (nodep->valuep()->isDouble()) { + nodep->dtypeChgDouble(); bdtypep=NULL; + nodep->dtypep()->dtypeChgDouble(); bdtypep=NULL; + nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,FINAL).p()); + } else { + nodep->valuep()->iterateAndNext(*this,WidthVP(width,0,FINAL).p()); + rs = nodep->numeric(); if (nodep->valuep()->widthSized()) { width = nodep->valuep()->width(); } else { @@ -712,24 +717,20 @@ private: width = 32; } } - } - // Parameter sizes can come from the thing they get assigned from - // They then "stick" to that width. - if (!width) width=32; // Or, if nothing, they're 32 bits. - // CLEANUP: If we have a TypeOf operator, or make dtype on every AstNode, - // this would be just a copy of the dtype into the var. - if (rs.isDouble()) { - AstBasicDType* newp = new AstBasicDType(nodep->fileline(), AstBasicDTypeKwd::DOUBLE); - bdtypep->replaceWith(newp); - bdtypep->deleteTree(); bdtypep=NULL; + UINFO(9,"implicitParamFromIV "<valuep()<isDouble()) { AstBasicDType* newp = new AstBasicDType(nodep->fileline(), AstLogicPacked(), width); newp->implicit(true); newp->numeric(rs); // SIGNED or UNSIGNED bdtypep->replaceWith(newp); bdtypep->deleteTree(); bdtypep=NULL; + nodep->dtypep()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); } - nodep->dtypep()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); } else { // non param or sized param nodep->dtypep()->iterateAndNext(*this,WidthVP(ANYSIZE,0,BOTH).p()); @@ -741,7 +742,7 @@ private: // See above note about valuep()->...FINAL nodep->widthSignedFrom(nodep->dtypep()); if (nodep->valuep()) { - if (implicitParam) { + if (implicitParam && !nodep->isDouble()) { nodep->width(nodep->width(), nodep->valuep()->widthMin()); // Needed as mwidth might not equal width } widthCheck(nodep,"Initial value",nodep->valuep(), diff --git a/test_regress/t/t_param_value.v b/test_regress/t/t_param_value.v index e25a00914..b7950b703 100644 --- a/test_regress/t/t_param_value.v +++ b/test_regress/t/t_param_value.v @@ -20,10 +20,8 @@ module t (/*AUTOARG*/); localparam A1_WIDE = UNSIGNED; `ASSERT($bits(A1_WIDE)==64); -`ifdef VERILATOR_BROKEN localparam A2_REAL = REAL; `ASSERT(A2_REAL == 1.234); -`endif `ifdef VERILATOR_BROKEN localparam A3_SIGNED = SIGNED;