Fix preprocessing stringified newline escapes, bug915.

This commit is contained in:
Wilson Snyder 2015-05-07 21:41:54 -04:00
parent 994cde57af
commit d5eb92a071
4 changed files with 35 additions and 10 deletions

View File

@ -13,6 +13,8 @@ indicates the contributor was also the author of the fix; Thanks!
**** Fix Cygwin uint32 compile, bug914. [Matthew Barr]
**** Fix preprocessing stringified newline escapes, bug915. [Anton Rapp]
* Verilator 3.872 2015-04-05

View File

@ -58,6 +58,7 @@ static void appendDefValue(const char* t, size_t l) { LEXP->appendDefValue(t,l);
%x DEFFORM
%x DEFVAL
%x DEFCMT
%x STRIFY
%x ARGMODE
%x INCMODE
%x PRTMODE
@ -80,8 +81,8 @@ drop [\032]
/**************************************************************/
%%
<INITIAL>^{ws}*"`line"{ws}+.*{crnl} { LEXP->lineDirective(yytext);
return(VP_LINE); }
<INITIAL,STRIFY>^{ws}*"`line"{ws}+.*{crnl} { LEXP->lineDirective(yytext);
return(VP_LINE); }
/* Special directives we recognize */
<INITIAL>"`define" { return(VP_DEFINE); }
@ -93,17 +94,15 @@ drop [\032]
<INITIAL>"`include" { return(VP_INCLUDE); }
<INITIAL>"`undef" { return(VP_UNDEF); }
<INITIAL>"`undefineall" { return(VP_UNDEFINEALL); }
/* Optional directives we recognize */
<INITIAL>"`__FILE__" { static string rtnfile;
<INITIAL>"`error" { if (!pedantic()) return (VP_ERROR); else return(VP_DEFREF); }
<INITIAL,STRIFY>"`__FILE__" { static string rtnfile;
rtnfile = '"'; rtnfile += LEXP->curFilelinep()->filename();
rtnfile += '"'; yytext=(char*)rtnfile.c_str(); yyleng = rtnfile.length();
return (VP_STRING); }
<INITIAL>"`__LINE__" { static char buf[10];
<INITIAL,STRIFY>"`__LINE__" { static char buf[10];
sprintf(buf, "%d",LEXP->curFilelinep()->lineno());
yytext = buf; yyleng = strlen(yytext);
return (VP_TEXT); }
<INITIAL>"`error" { if (!pedantic()) return (VP_ERROR); else return(VP_DEFREF); }
/* Pass-through strings */
<INITIAL>{quote} { yy_push_state(STRMODE); yymore(); }
@ -118,8 +117,20 @@ drop [\032]
else return (VP_STRING); }
/* Stringification */
<INITIAL>{tickquote} { return VP_STRIFY; }
<INITIAL>"`\\`\"" { return VP_BACKQUOTE; }
<INITIAL>{tickquote} { yy_push_state(STRIFY); return VP_STRIFY; }
<STRIFY><<EOF>> { linenoInc(); yyerrorf("EOF in unterminated '\""); yyleng=0; yyterminate(); }
<STRIFY>"`\\`\"" { return VP_BACKQUOTE; }
<STRIFY>{quote} { yy_push_state(STRMODE); yymore(); }
<STRIFY>{tickquote} { yy_pop_state(); return VP_STRIFY; }
<STRIFY>{symbdef} { return (VP_SYMBOL); }
<STRIFY>{symbdef}`` { yyleng-=2; return (VP_SYMBOL_JOIN); }
<STRIFY>"`"{symbdef} { return (VP_DEFREF); }
<STRIFY>"`"{symbdef}`` { yyleng-=2; return (VP_DEFREF_JOIN); }
<STRIFY>{crnl} { linenoInc(); yytext=(char*)"\n"; yyleng=1; return(VP_WHITE); }
<STRIFY>{wsn}+ { return (VP_WHITE); }
<STRIFY>{drop} { }
<STRIFY>[\r] { }
<STRIFY>. { return (VP_TEXT); }
/* Protected blocks */
<INITIAL>"`protected" { yy_push_state(PRTMODE); yymore(); }

View File

@ -792,6 +792,13 @@ module t;
initial $write("Slashed=`%s'\n", "1//2.3");
initial
`line 531 "t/t_preproc.v" 0
$display("%s%s","a1","b2c3\n");
endmodule
@ -813,4 +820,4 @@ predef 1 1
predef 2 2
`line 548 "t/t_preproc.v" 2
`line 553 "t/t_preproc.v" 2

View File

@ -524,6 +524,11 @@ module t;
// bug845
`define SLASHED "1//2.3"
initial $write("Slashed=`%s'\n", `SLASHED);
//----
// bug915
`define BUG915(a,b,c) \
$display("%s%s",a,`"b``c``\n`")
initial `BUG915("a1",b2,c3);
endmodule
//======================================================================
// IEEE mandated predefines