From b947391662cbfa35f557db12368634ea6146df6e Mon Sep 17 00:00:00 2001 From: Todd Strader Date: Mon, 12 Aug 2019 08:33:58 -0400 Subject: [PATCH] Retain widthSized when simulating --- src/V3AstNodes.h | 6 ++++++ src/V3Number.h | 8 ++++---- src/V3Simulate.h | 5 ++--- test_regress/t/t_func_const2_bad.out | 6 +++--- test_regress/t/t_func_const_bad.out | 10 +++++----- test_regress/t/t_func_const_packed_array_bad.out | 6 +++--- test_regress/t/t_func_const_packed_struct_bad.out | 6 +++--- test_regress/t/t_func_const_packed_struct_bad2.out | 6 +++--- test_regress/t/t_func_const_struct_bad.out | 6 +++--- test_regress/t/t_generate_fatal_bad.out | 8 ++++---- test_regress/t/t_lint_width_genfor.pl | 2 +- test_regress/t/t_lint_width_genfor.v | 2 ++ test_regress/t/t_lint_width_genfor_bad.out | 2 +- 13 files changed, 40 insertions(+), 33 deletions(-) diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index ff398b2c1..234bfcf00 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -72,6 +72,12 @@ public: , m_num(this, width, value) { initWithNumber(); } + class DtypedValue{}; // for creator type-overload selection + AstConst(FileLine* fl, DtypedValue, AstNodeDType* nodedtypep, uint32_t value) + : AstNodeMath(fl) + , m_num(this, nodedtypep->width(), value, nodedtypep->widthSized()) { + initWithNumber(); + } class StringToParse {}; // for creator type-overload selection AstConst(FileLine* fl, StringToParse, const char* sourcep) : AstNodeMath(fl) diff --git a/src/V3Number.h b/src/V3Number.h index a43ac3e35..dd5f5c174 100644 --- a/src/V3Number.h +++ b/src/V3Number.h @@ -140,8 +140,8 @@ public: // CONSTRUCTORS explicit V3Number(AstNode* nodep) { init(nodep, 1); } V3Number(AstNode* nodep, int width) { init(nodep, width); } // 0=unsized - V3Number(AstNode* nodep, int width, uint32_t value) { - init(nodep, width); m_value[0] = value; opCleanThis(); + V3Number(AstNode* nodep, int width, uint32_t value, bool sized=true) { + init(nodep, width, sized); m_value[0] = value; opCleanThis(); } // Create from a verilog 32'hxxxx number. V3Number(AstNode* nodep, const char* sourcep) { V3NumberCreate(nodep, sourcep, NULL); } @@ -164,14 +164,14 @@ public: private: void V3NumberCreate(AstNode* nodep, const char* sourcep, FileLine* fl); - void init(AstNode* nodep, int swidth) { + void init(AstNode* nodep, int swidth, bool sized=true) { setNames(nodep); m_signed = false; m_double = false; m_isString = false; m_autoExtend = false; m_fromString = false; - width(swidth); + width(swidth, sized); for (int i=0; ifindLogicDType(nodep->width(), 0, AstNumeric::UNSIGNED); + AstNodeDType* dtypep = nodep->dtypep(); if (!m_constFreeps[dtypep].empty()) { //UINFO(7,"Num Reuse "<width()<num().nodep(nodep); } else { //UINFO(7,"Num New "<width()<fileline(), AstConst::WidthedValue(), nodep->width(), 0); - UASSERT_OBJ(dtypep == constp->dtypep(), nodep, "Unexpected dtype"); + constp = new AstConst(nodep->fileline(), AstConst::DtypedValue(), nodep->dtypep(), 0); m_constAllps[constp->dtypep()].push_back(constp); } constp->num().isDouble(nodep->isDouble()); diff --git a/test_regress/t/t_func_const2_bad.out b/test_regress/t/t_func_const2_bad.out index 71c8d6513..41cf4ff10 100644 --- a/test_regress/t/t_func_const2_bad.out +++ b/test_regress/t/t_func_const2_bad.out @@ -7,9 +7,9 @@ a = 32'h7 b = 32'h8 t/t_func_const2_bad.v:21: ... Called from f_add2() with parameters: - a = 32'h7 - b = 32'h8 - c = 32'h9 + a = ?32?h7 + b = ?32?h8 + c = ?32?h9 localparam SOMEP = f_add2(A, B, 9); ^~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_func_const_bad.out b/test_regress/t/t_func_const_bad.out index 714553f05..ba829d35c 100644 --- a/test_regress/t/t_func_const_bad.out +++ b/test_regress/t/t_func_const_bad.out @@ -7,28 +7,28 @@ : ... In instance t t/t_func_const_bad.v:22: ... Location of non-constant VARXREF 'EIGHT': Language violation: Dotted hierarchical references not allowed in constant functions t/t_func_const_bad.v:20: ... Called from f_bad_dotted() with parameters: - a = 32'h2 + a = ?32?h2 localparam B2 = f_bad_dotted(2); ^~~~~~~~~~~~ %Error: t/t_func_const_bad.v:27: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_nonparam' : ... In instance t t/t_func_const_bad.v:29: ... Location of non-constant VARREF 'modvar': Language violation: reference to non-function-local variable t/t_func_const_bad.v:27: ... Called from f_bad_nonparam() with parameters: - a = 32'h3 + a = ?32?h3 localparam B3 = f_bad_nonparam(3); ^~~~~~~~~~~~~~ %Error: t/t_func_const_bad.v:35: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_infinite' : ... In instance t t/t_func_const_bad.v:37: ... Location of non-constant WHILE: Loop unrolling took too long; probably this is an infinite loop, or set --unroll-count above 1024 t/t_func_const_bad.v:35: ... Called from f_bad_infinite() with parameters: - a = 32'h3 + a = ?32?h3 localparam B4 = f_bad_infinite(3); ^~~~~~~~~~~~~~ %Error: t/t_func_const_bad.v:43: Expecting expression to be constant, but can't determine constant for FUNCREF 'f_bad_stop' : ... In instance t t/t_func_const_bad.v:45: ... Location of non-constant STOP: $stop executed during function constification; maybe indicates assertion firing t/t_func_const_bad.v:43: ... Called from f_bad_stop() with parameters: - a = 32'h3 + a = ?32?h3 localparam BSTOP = f_bad_stop(3); ^~~~~~~~~~ -Info: "Printing in loop: 0" @@ -40,7 +40,7 @@ : ... In instance t t/t_func_const_bad.v:54: ... Location of non-constant STOP: $stop executed during function constification; maybe indicates assertion firing t/t_func_const_bad.v:49: ... Called from f_bad_fatal() with parameters: - a = 32'h3 + a = ?32?h3 localparam BFATAL = f_bad_fatal(3); ^~~~~~~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_func_const_packed_array_bad.out b/test_regress/t/t_func_const_packed_array_bad.out index e05bbd842..0c20156ca 100644 --- a/test_regress/t/t_func_const_packed_array_bad.out +++ b/test_regress/t/t_func_const_packed_array_bad.out @@ -6,9 +6,9 @@ t/t_func_const_packed_array_bad.v:30: ... Called from f_add() with parameters: params = [0 = 32'h7, 1 = 32'h8] t/t_func_const_packed_array_bad.v:11: ... Called from f_add2() with parameters: - a = 32'h7 - b = 32'h8 - c = 32'h9 + a = ?32?h7 + b = ?32?h8 + c = ?32?h9 localparam P24 = f_add2(7, 8, 9); ^~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_func_const_packed_struct_bad.out b/test_regress/t/t_func_const_packed_struct_bad.out index aff652851..c31d93f62 100644 --- a/test_regress/t/t_func_const_packed_struct_bad.out +++ b/test_regress/t/t_func_const_packed_struct_bad.out @@ -6,9 +6,9 @@ t/t_func_const_packed_struct_bad.v:32: ... Called from f_add() with parameters: params = [0 = '{a: 32'h7, b: 32'h22b}, 1 = '{a: 32'h3039, b: 32'h8}] t/t_func_const_packed_struct_bad.v:13: ... Called from f_add2() with parameters: - a = 32'h7 - b = 32'h8 - c = 32'h9 + a = ?32?h7 + b = ?32?h8 + c = ?32?h9 localparam P24 = f_add2(7, 8, 9); ^~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_func_const_packed_struct_bad2.out b/test_regress/t/t_func_const_packed_struct_bad2.out index 0fa45ef6f..d84f42319 100644 --- a/test_regress/t/t_func_const_packed_struct_bad2.out +++ b/test_regress/t/t_func_const_packed_struct_bad2.out @@ -6,9 +6,9 @@ t/t_func_const_packed_struct_bad2.v:42: ... Called from f_add() with parameters: params = [0 = '{a: 32'h7, foo: 6'hb, sub_params: '{b: 32'h37, bar: 8'h6f}}, 1 = '{a: 32'h3039, foo: 6'hc, sub_params: '{b: 32'h8, bar: 8'h70}}] t/t_func_const_packed_struct_bad2.v:19: ... Called from f_add2() with parameters: - a = 32'h7 - b = 32'h8 - c = 32'h9 + a = ?32?h7 + b = ?32?h8 + c = ?32?h9 localparam P24 = f_add2(7, 8, 9); ^~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_func_const_struct_bad.out b/test_regress/t/t_func_const_struct_bad.out index 632ab08bc..2e00d5bf7 100644 --- a/test_regress/t/t_func_const_struct_bad.out +++ b/test_regress/t/t_func_const_struct_bad.out @@ -6,9 +6,9 @@ t/t_func_const_struct_bad.v:37: ... Called from f_add() with parameters: params = '{a: 32'h7, b: 32'h8} t/t_func_const_struct_bad.v:16: ... Called from f_add2() with parameters: - a = 32'h7 - b = 32'h8 - c = 32'h9 + a = ?32?h7 + b = ?32?h8 + c = ?32?h9 localparam P24 = f_add2(7, 8, 9); ^~~~~~ %Error: Exiting due to diff --git a/test_regress/t/t_generate_fatal_bad.out b/test_regress/t/t_generate_fatal_bad.out index 63ad510d4..4e61e3f77 100644 --- a/test_regress/t/t_generate_fatal_bad.out +++ b/test_regress/t/t_generate_fatal_bad.out @@ -4,14 +4,14 @@ : ... In instance t.genloop[0].foo_inst t/t_generate_fatal_bad.v:8: ... Location of non-constant STOP: $stop executed during function constification; maybe indicates assertion firing t/t_generate_fatal_bad.v:12: ... Called from get_baz() with parameters: - bar = 32'h0 + bar = ?32?h0 localparam integer BAZ = get_baz(BAR); ^~~~~~~ %Error: t/t_generate_fatal_bad.v:12: Expecting expression to be constant, but can't determine constant for FUNCREF 'get_baz' : ... In instance t.genloop[1].foo_inst t/t_generate_fatal_bad.v:8: ... Location of non-constant STOP: $stop executed during function constification; maybe indicates assertion firing t/t_generate_fatal_bad.v:12: ... Called from get_baz() with parameters: - bar = 32'h1 + bar = ?32?h1 localparam integer BAZ = get_baz(BAR); ^~~~~~~ %Error: t/t_generate_fatal_bad.v:12: Expecting expression to be constant, but can't determine constant for FUNCREF 'get_baz' @@ -46,14 +46,14 @@ : ... In instance t.cond_true.foo_inst3 t/t_generate_fatal_bad.v:8: ... Location of non-constant STOP: $stop executed during function constification; maybe indicates assertion firing t/t_generate_fatal_bad.v:12: ... Called from get_baz() with parameters: - bar = 32'h6 + bar = ?32?h6 localparam integer BAZ = get_baz(BAR); ^~~~~~~ %Error: t/t_generate_fatal_bad.v:12: Expecting expression to be constant, but can't determine constant for FUNCREF 'get_baz' : ... In instance t.genblk1.foo_inst4 t/t_generate_fatal_bad.v:8: ... Location of non-constant STOP: $stop executed during function constification; maybe indicates assertion firing t/t_generate_fatal_bad.v:12: ... Called from get_baz() with parameters: - bar = 32'h7 + bar = ?32?h7 localparam integer BAZ = get_baz(BAR); ^~~~~~~ %Error: t/t_generate_fatal_bad.v:12: Expecting expression to be constant, but can't determine constant for FUNCREF 'get_baz' diff --git a/test_regress/t/t_lint_width_genfor.pl b/test_regress/t/t_lint_width_genfor.pl index 0477f4263..54d98b479 100755 --- a/test_regress/t/t_lint_width_genfor.pl +++ b/test_regress/t/t_lint_width_genfor.pl @@ -7,7 +7,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di # Lesser General Public License Version 3 or the Perl Artistic License # Version 2.0. -$Self->{vlt_all} and unsupported("Verilator unsupported, bug1487."); +$Self->{vlt_all}; scenarios(linter => 1); diff --git a/test_regress/t/t_lint_width_genfor.v b/test_regress/t/t_lint_width_genfor.v index 820641d2c..5cb1c001c 100644 --- a/test_regress/t/t_lint_width_genfor.v +++ b/test_regress/t/t_lint_width_genfor.v @@ -26,7 +26,9 @@ module t (/*AUTOARG*/ end initial begin for (integer i=0; i < 15; ++i) begin + /* verilator lint_off WIDTH */ ri = i; + /* verilator lint_on WIDTH */ end end diff --git a/test_regress/t/t_lint_width_genfor_bad.out b/test_regress/t/t_lint_width_genfor_bad.out index 8e403790e..4fb3f3a8b 100644 --- a/test_regress/t/t_lint_width_genfor_bad.out +++ b/test_regress/t/t_lint_width_genfor_bad.out @@ -1,4 +1,4 @@ -%Warning-WIDTH: t/t_lint_width_genfor_bad.v:24: Operator ASSIGN expects 4 bits on the Assign RHS, but Assign RHS's CONST '32'h10' generates 32 bits. +%Warning-WIDTH: t/t_lint_width_genfor_bad.v:24: Operator ASSIGN expects 4 bits on the Assign RHS, but Assign RHS's CONST '?32?h10' generates 32 or 5 bits. : ... In instance t rg = g; ^