From c60ffd7fd9fa2ef16d758701051db6799d0da163 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 1 Oct 2015 21:15:01 -0400 Subject: [PATCH] Fix enum constant propagation, bug970. --- Changes | 2 ++ src/V3Simulate.h | 13 +++++++++++++ ...static_elab_struct.pl => t_static_elab.pl} | 0 ...t_static_elab_struct.v => t_static_elab.v} | 19 +++++++++++++++++++ 4 files changed, 34 insertions(+) rename test_regress/t/{t_static_elab_struct.pl => t_static_elab.pl} (100%) rename test_regress/t/{t_static_elab_struct.v => t_static_elab.v} (59%) diff --git a/Changes b/Changes index f0a936cb4..128bdffe6 100644 --- a/Changes +++ b/Changes @@ -15,6 +15,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix structure parameter constant propagation, bug968. [Todd Strader] +**** Fix enum constant propagation, bug970. [Todd Strader] + **** Fix mis-optimizing public DPI functions, bug963. [Wei Song] diff --git a/src/V3Simulate.h b/src/V3Simulate.h index b09abc03d..8bc4decb6 100644 --- a/src/V3Simulate.h +++ b/src/V3Simulate.h @@ -345,6 +345,19 @@ private: setNumber(nodep, &(nodep->num())); } } + virtual void visit(AstEnumItemRef* nodep, AstNUser*) { + checkNodeInfo(nodep); + if (!nodep->itemp()) nodep->v3fatalSrc("Not linked"); + if (!m_checkOnly && optimizable()) { + AstNode* valuep = nodep->itemp()->valuep(); + if (valuep) { + valuep->iterateAndNext(*this); + newNumber(nodep)->opAssign(*fetchNumber(valuep)); + } else { + clearOptimizable(nodep, "No value found for enum item"); + } + } + } virtual void visit(AstNodeUniop* nodep, AstNUser*) { if (!optimizable()) return; // Accelerate checkNodeInfo(nodep); diff --git a/test_regress/t/t_static_elab_struct.pl b/test_regress/t/t_static_elab.pl similarity index 100% rename from test_regress/t/t_static_elab_struct.pl rename to test_regress/t/t_static_elab.pl diff --git a/test_regress/t/t_static_elab_struct.v b/test_regress/t/t_static_elab.v similarity index 59% rename from test_regress/t/t_static_elab_struct.v rename to test_regress/t/t_static_elab.v index 18a50326e..213d7af67 100644 --- a/test_regress/t/t_static_elab_struct.v +++ b/test_regress/t/t_static_elab.v @@ -9,6 +9,11 @@ module t (/*AUTOARG*/); logic [ 31 : 0 ] _five; } five_t; + typedef enum { + LOW_FIVE = 32'hdeadbeef, + HIGH_FIVE + } five_style_t; + function five_t gimme_five (); automatic five_t result; @@ -17,7 +22,16 @@ module t (/*AUTOARG*/); return result; endfunction + function five_style_t gimme_high_five (); + automatic five_style_t result; + + result = HIGH_FIVE; + + return result; + endfunction + localparam five_t FIVE = gimme_five(); + localparam five_style_t THE_HIGH_FIVE = gimme_high_five(); initial begin if (FIVE._five != 5) begin @@ -25,6 +39,11 @@ module t (/*AUTOARG*/); $stop; end + if (THE_HIGH_FIVE != HIGH_FIVE) begin + $display("%%Error: Got 0b%b instead of HIGH_FIVE", THE_HIGH_FIVE); + $stop; + end + $write("*-* All Finished *-*\n"); $finish; end