Fix ` expansion of defines, bug1227, bug1228.

This commit is contained in:
Wilson Snyder 2017-10-10 18:44:10 -04:00
parent 440fbef79b
commit 12be852a43
9 changed files with 58 additions and 4 deletions

View File

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

View File

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

View File

@ -126,6 +126,7 @@ drop [\032]
<STRIFY>{symbdef}`` { yyleng-=2; return (VP_SYMBOL_JOIN); }
<STRIFY>"`"{symbdef} { return (VP_DEFREF); }
<STRIFY>"`"{symbdef}`` { yyleng-=2; return (VP_DEFREF_JOIN); }
<STRIFY>`` { yyleng-=2; return (VP_JOIN); }
<STRIFY>{crnl} { linenoInc(); yytext=(char*)"\n"; yyleng=1; return(VP_WHITE); }
<STRIFY>{wsn}+ { return (VP_WHITE); }
<STRIFY>{drop} { }
@ -229,6 +230,7 @@ drop [\032]
}}
<ARGMODE>"`"{symbdef} { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */
<ARGMODE>"`"{symbdef}`` { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */
<ARGMODE>`` { appendDefValue(yytext,yyleng); } /* defref in defref - outer macro expands first */
<ARGMODE>[^\/\*\n\r\\(,){}\[\]\"`]+ |
<ARGMODE>. { appendDefValue(yytext,yyleng); }
@ -253,12 +255,14 @@ drop [\032]
/* symbdef prevents normal lex rules from making `\`"foo a symbol {`"foo} instead of a BACKQUOTE */
<INITIAL>"`"{symbdef} { return (VP_DEFREF); }
<INITIAL>"`"{symbdef}`` { yyleng-=2; return (VP_DEFREF_JOIN); }
<INITIAL>`` { yyleng-=2; return (VP_JOIN); }
/* Generics */
<INITIAL>{crnl} { linenoInc(); yytext=(char*)"\n"; yyleng=1; return(VP_WHITE); }
<INITIAL><<EOF>> { yyterminate(); } /* A "normal" EOF */
<INITIAL>{symb} { return (VP_SYMBOL); }
<INITIAL>{symb}`` { yyleng-=2; return (VP_SYMBOL_JOIN); }
<INITIAL>`` { yyleng-=2; return (VP_JOIN); }
<INITIAL>{wsn}+ { return (VP_WHITE); }
<INITIAL>{drop} { }
<INITIAL>[\r] { }

View File

@ -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:"<<out<<endl);
@ -1188,7 +1189,10 @@ int V3PreProcImp::getStateToken() {
statePop();
goto next_tok;
} else if (tok==VP_EOF || tok==VP_WHITE || tok == VP_COMMENT || tok==VP_STRING) {
error((string)"Expecting symbol to terminate ``; whitespace etc cannot follow ``. Found: "+tokenName(tok)+"\n");
// Other compilers just ignore this, so no warning
// "Expecting symbol to terminate ``; whitespace etc cannot follow ``. Found: "+tokenName(tok)+"\n"
string lhs = m_joinStack.top(); m_joinStack.pop();
unputString(lhs);
statePop();
goto next_tok;
} else {

View File

@ -894,6 +894,11 @@ XYS_FAMILY = XYS_foo
`line 610 "t/t_preproc.v" 0
(.mySig (myInterface.pa5),
`line 614 "t/t_preproc.v" 0
predef 0 0
predef 1 1
@ -912,4 +917,4 @@ predef 1 1
predef 2 2
`line 630 "t/t_preproc.v" 2
`line 634 "t/t_preproc.v" 2

View File

@ -607,6 +607,10 @@ NYS_FAMILY = `NYS_FAMILY
`endif // NEVER
//bug1227
`define INSTANCE(NAME) (.mySig (myInterface.``NAME),
`INSTANCE(pa5)
//======================================================================
// IEEE mandated predefines
`undefineall // undefineall should have no effect on these

View File

@ -0,0 +1 @@
`TARGET_PACKAGE

View File

@ -0,0 +1,27 @@
#!/usr/bin/perl
if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; }
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
#
# Copyright 2003-2017 by Wilson Snyder. This program is free software; you can
# redistribute it and/or modify it under the terms of either the GNU
# Lesser General Public License Version 3 or the Perl Artistic License
# Version 2.0.
$Self->{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;

View File

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