From bcba5075e8767e1c744a10b7ae2ed6f7094185ec Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 7 Sep 2013 16:43:43 -0400 Subject: [PATCH] Fix ordering of , msg1229. --- Changes | 3 ++- src/V3AstNodes.h | 2 ++ src/V3Const.cpp | 3 ++- test_regress/t/t_sys_file_basic.v | 20 ++++++++++++++++++++ test_regress/t/t_sys_file_basic_input.dat | 1 + 5 files changed, 27 insertions(+), 2 deletions(-) diff --git a/Changes b/Changes index 9b61e995c..2ef918e40 100644 --- a/Changes +++ b/Changes @@ -7,12 +7,13 @@ indicates the contributor was also the author of the fix; Thanks! *** Support named function and task arguments. [Chris Randall] +**** Fix ordering of $fgetc, msg1229. [Frederic Requin] + **** Fix --output-split-cfunc to count internal functions. [Chris Randall] **** Fix crash on 32-bit Ubuntu, bug670. [Mark Jackson Pulver] - * Verilator 3.851 2013-08-15 *** Fix ordering of clock enables with delayed assigns, bug613. [Jeremy Bennett] diff --git a/src/V3AstNodes.h b/src/V3AstNodes.h index c1ed6b917..a93a0bb81 100644 --- a/src/V3AstNodes.h +++ b/src/V3AstNodes.h @@ -3378,6 +3378,7 @@ struct AstFEof : public AstNodeUniop { virtual bool cleanOut() {return true;} virtual bool cleanLhs() {return true;} virtual bool sizeMattersLhs() {return false;} virtual int instrCount() const { return widthInstrs()*16; } + virtual bool isPure() const { return false; } // SPECIAL: $display has 'visual' ordering AstNode* filep() const { return lhsp(); } }; @@ -3391,6 +3392,7 @@ struct AstFGetC : public AstNodeUniop { virtual bool cleanOut() {return false;} virtual bool cleanLhs() {return true;} virtual bool sizeMattersLhs() {return false;} virtual int instrCount() const { return widthInstrs()*64; } + virtual bool isPure() const { return false; } // SPECIAL: $display has 'visual' ordering AstNode* filep() const { return lhsp(); } }; diff --git a/src/V3Const.cpp b/src/V3Const.cpp index dc785f40d..fbc4a21fe 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -815,9 +815,10 @@ private: bool varNotReferenced(AstNode* nodep, AstVar* varp, int level=0) { // Return true if varp never referenced under node. - // Return false if referenced, or tree too deep to be worth it + // Return false if referenced, or tree too deep to be worth it, or side effects if (!nodep) return true; if (level>2) return false; + if (nodep->isPure()) return false; // For example a $fgetc can't be reordered if (nodep->castNodeVarRef() && nodep->castNodeVarRef()->varp()==varp) return false; return (varNotReferenced (nodep->nextp(),varp,level+1) && varNotReferenced(nodep->op1p(),varp,level+1) diff --git a/test_regress/t/t_sys_file_basic.v b/test_regress/t/t_sys_file_basic.v index cdf2783a3..df8fcda6e 100644 --- a/test_regress/t/t_sys_file_basic.v +++ b/test_regress/t/t_sys_file_basic.v @@ -15,6 +15,10 @@ module t; reg [16*8:1] letterz; real r; + reg [7:0] v_a,v_b,v_c,v_d; + reg [31:0] v_worda; + reg [31:0] v_wordb; + `ifdef TEST_VERBOSE `define verbose 1'b1 `else @@ -174,6 +178,22 @@ module t; if (chars != 1) $stop; if (letterl != "\n") $stop; + // msg1229 + v_a = $fgetc(file); + v_b = $fgetc(file); + v_c = $fgetc(file); + v_d = $fgetc(file); + v_worda = { v_d, v_c, v_b, v_a }; + if (v_worda != "4321") $stop; + + v_wordb[7:0] = $fgetc(file); + v_wordb[15:8] = $fgetc(file); + v_wordb[23:16] = $fgetc(file); + v_wordb[31:24] = $fgetc(file); + if (v_wordb != "9876") $stop; + + if ($fgetc(file) != "\n") $stop; + $fclose(file); end diff --git a/test_regress/t/t_sys_file_basic_input.dat b/test_regress/t/t_sys_file_basic_input.dat index 0a085c6fb..67437584c 100644 --- a/test_regress/t/t_sys_file_basic_input.dat +++ b/test_regress/t/t_sys_file_basic_input.dat @@ -6,3 +6,4 @@ widestuff *oa=23 ob=12563 *d=-236123 *fredfishblah +12346789