Fix enum constant propagation, bug970.

This commit is contained in:
Wilson Snyder 2015-10-01 21:15:01 -04:00
parent dc57282168
commit c60ffd7fd9
4 changed files with 34 additions and 0 deletions

View File

@ -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]

View File

@ -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);

View File

@ -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