diff --git a/Changes b/Changes index 136e7d1f7..5b1a0b0a5 100644 --- a/Changes +++ b/Changes @@ -31,7 +31,7 @@ The contributors that suggested a given feature are shown in []. Thanks! **** Fix conditional slices and add related optimizations. -**** Fix `` expansion of empty `defines, bug1225. [Odd Magne Reitan] +**** Fix `` expansion of `defines, bug1225, bug1227, bug1228. [Odd Magne Reitan] **** Fix -E duplicating output, bug1226. [Odd Magne Reitan] diff --git a/src/V3PreLex.h b/src/V3PreLex.h index 0197b032e..cb00aec46 100644 --- a/src/V3PreLex.h +++ b/src/V3PreLex.h @@ -65,6 +65,7 @@ class V3PreProcImp; #define VP_BACKQUOTE 311 #define VP_SYMBOL_JOIN 312 #define VP_DEFREF_JOIN 313 +#define VP_JOIN 314 #define VP_PSL 350 diff --git a/src/V3PreLex.l b/src/V3PreLex.l index a532be812..3e3a9d115 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -126,6 +126,7 @@ drop [\032] {symbdef}`` { yyleng-=2; return (VP_SYMBOL_JOIN); } "`"{symbdef} { return (VP_DEFREF); } "`"{symbdef}`` { yyleng-=2; return (VP_DEFREF_JOIN); } +`` { yyleng-=2; return (VP_JOIN); } {crnl} { linenoInc(); yytext=(char*)"\n"; yyleng=1; return(VP_WHITE); } {wsn}+ { return (VP_WHITE); } {drop} { } @@ -229,6 +230,7 @@ drop [\032] }} "`"{symbdef} { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */ "`"{symbdef}`` { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */ +`` { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */ [^\/\*\n\r\\(,){}\[\]\"`]+ | . { appendDefValue(yytext,yyleng); } @@ -253,12 +255,14 @@ drop [\032] /* symbdef prevents normal lex rules from making `\`"foo a symbol {`"foo} instead of a BACKQUOTE */ "`"{symbdef} { return (VP_DEFREF); } "`"{symbdef}`` { yyleng-=2; return (VP_DEFREF_JOIN); } +`` { yyleng-=2; return (VP_JOIN); } /* Generics */ {crnl} { linenoInc(); yytext=(char*)"\n"; yyleng=1; return(VP_WHITE); } <> { yyterminate(); } /* A "normal" EOF */ {symb} { return (VP_SYMBOL); } {symb}`` { yyleng-=2; return (VP_SYMBOL_JOIN); } +`` { yyleng-=2; return (VP_JOIN); } {wsn}+ { return (VP_WHITE); } {drop} { } [\r] { } diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index c30f89763..f41611002 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -485,6 +485,7 @@ const char* V3PreProcImp::tokenName(int tok) { case VP_ERROR : return("ERROR"); case VP_IFDEF : return("IFDEF"); case VP_IFNDEF : return("IFNDEF"); + case VP_JOIN : return("JOIN"); case VP_INCLUDE : return("INCLUDE"); case VP_LINE : return("LINE"); case VP_STRIFY : return("STRIFY"); @@ -923,7 +924,7 @@ int V3PreProcImp::getStateToken() { // FALLTHRU, handle as with VP_SYMBOL_JOIN } } - if (tok==VP_SYMBOL_JOIN || tok==VP_DEFREF_JOIN) { // not else if, can fallthru from above if() + if (tok==VP_SYMBOL_JOIN || tok==VP_DEFREF_JOIN || tok==VP_JOIN) { // not else if, can fallthru from above if() // a`` -> string doesn't include the ``, so can just grab next and continue string out (yyourtext(),yyourleng()); UINFO(5,"`` LHS:"<{vlt} or $Self->skip("Verilator only test"); + +my $stdout_filename = "$Self->{obj_dir}/$Self->{name}__test.vpp"; + +compile ( + # Override default flags + v_flags => [''], + verilator_flags => ["-E -P +incdir+t"], + verilator_flags2 => ['',], + verilator_flags3 => ['',], + verilator_make_gcc => 0, + make_top_shell => 0, + stdout_filename => $stdout_filename, + ); + +ok(files_identical($stdout_filename, "t/$Self->{name}.out")); + +1; diff --git a/test_regress/t/t_preproc_ttempty.v b/test_regress/t/t_preproc_ttempty.v new file mode 100644 index 000000000..572108d87 --- /dev/null +++ b/test_regress/t/t_preproc_ttempty.v @@ -0,0 +1,8 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2017 by Wilson Snyder. + +//`define TARGET_PACKAGE + +`define TARGET_PACKAGE_```TARGET_PACKAGE