From 0c73b547f150417e1c130cfb1c8a987287779724 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Fri, 25 Apr 2008 14:01:50 +0000 Subject: [PATCH] Fix bug introduced in 3.661 with parametrized defines. git-svn-id: file://localhost/svn/verilator/trunk/verilator@1042 77ca24e4-aefa-0310-84f0-b9a241c72d87 --- Changes | 2 ++ src/V3PreLex.h | 2 +- src/V3PreLex.l | 7 +++++-- src/V3PreProc.cpp | 4 ++-- test_regress/t/t_preproc.out | 19 ++++++++++++++++--- test_regress/t/t_preproc.v | 13 +++++++++++++ 6 files changed, 39 insertions(+), 8 deletions(-) diff --git a/Changes b/Changes index 416fe3c8a..5ea9ce976 100644 --- a/Changes +++ b/Changes @@ -28,6 +28,8 @@ indicates the contributor was also the author of the fix; Thanks! **** Fix internal error when params get non-constants. [Johan Wouters] +**** Fix bug introduced in 3.661 with parametrized defines. + * Verilator 3.661 2008/04/04 *** The --enable-defenv configure option added in 3.660 is now the default. diff --git a/src/V3PreLex.h b/src/V3PreLex.h index f7a85e948..d65094cbb 100644 --- a/src/V3PreLex.h +++ b/src/V3PreLex.h @@ -133,7 +133,7 @@ class V3PreLex { void lineDirective(const char* text); void incLineno() { m_curFilelinep->incLineno(); } // Called by V3PreProc.cpp to inform lexer - void pushStateDefArg(); + void pushStateDefArg(int level); void pushStateDefValue(); void pushStateIncFilename(); void unputString(const char* textp); diff --git a/src/V3PreLex.l b/src/V3PreLex.l index 424b1a7a4..d72b9221a 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -141,6 +141,9 @@ psl [p]sl {crnl} { linenoInc(); yytext="\n"; yyleng=1; return(VP_WHITE); } {quote} { yy_push_state(STRMODE); yymore(); } [(] { V3PreLex::s_currentLexp->m_parenLevel++; + // Note paren level 0 means before "(" of starting args + // Level 1 means "," between arguments + // Level 2+ means one argument's internal () if (V3PreLex::s_currentLexp->m_parenLevel>1) { appendDefValue(yytext,yyleng); } else { @@ -210,10 +213,10 @@ psl [p]sl . { return (VP_TEXT); } %% -void V3PreLex::pushStateDefArg() { +void V3PreLex::pushStateDefArg(int level) { // Enter define substitution argument state yy_push_state(ARGMODE); - m_parenLevel = 0; + m_parenLevel = level; m_defValue = ""; } diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index e8b9e4aae..b7eb22fcb 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -759,7 +759,7 @@ int V3PreProcImp::getToken() { if (tok==VP_DEFARG && yyleng==1 && yytext[0]==',') { refp->args().push_back(refp->nextarg()); m_state = ps_DEFARG; - m_lexp->pushStateDefArg(); + m_lexp->pushStateDefArg(1); refp->nextarg(""); goto next_tok; } else if (tok==VP_DEFARG && yyleng==1 && yytext[0]==')') { @@ -901,7 +901,7 @@ int V3PreProcImp::getToken() { UINFO(4,"Defref `"< parameterized"<m_parenLevel)); m_state = ps_DEFPAREN; m_stateFor = tok; - m_lexp->pushStateDefArg(); + m_lexp->pushStateDefArg(0); goto next_tok; } } diff --git a/test_regress/t/t_preproc.out b/test_regress/t/t_preproc.out index 22ccea938..999585814 100644 --- a/test_regress/t/t_preproc.out +++ b/test_regress/t/t_preproc.out @@ -141,6 +141,19 @@ $c("Zap(\"","bug2","\");");; wire tmp_d1 = d1; wire tmp_o1 = tmp_d1 + 1; assign o1 = tmp_o1 ; wire tmp_d2 = d2 ; wire tmp_o2 = tmp_d2 + 1; assign o2 = tmp_o2 ; + + + + + + + + + + + + generate for (i=0; i<(3); i=i+1) begin psl cover { m5k.f .ctl._ctl_mvldx_m1.d[i] & ~m5k.f .ctl._ctl_mvldx_m1.q[i] & !m5k.f .ctl._ctl_mvldx_m1.cond & ((m5k.f .ctl.alive & m5k.f .ctl.alive_m1))} report "fondNoRise: m5kc_fcl._ctl_mvldx_m1"; psl cover { ~m5k.f .ctl._ctl_mvldx_m1.d[i] & m5k.f .ctl._ctl_mvldx_m1.q[i] & !m5k.f .ctl._ctl_mvldx_m1.cond & ((m5k.f .ctl.alive & m5k.f .ctl.alive_m1))} report "fondNoFall: m5kc_fcl._ctl_mvldx_m1"; end endgenerate + @@ -148,7 +161,7 @@ wire tmp_d2 = d2 ; wire tmp_o2 = tmp_d2 + 1; assign o2 = tmp_o2 ; -`line 104 "t/t_preproc.v" 0 +`line 117 "t/t_preproc.v" 0 -Line_Preproc_Check 105 -`line 106 "t/t_preproc.v" 2 +Line_Preproc_Check 118 +`line 119 "t/t_preproc.v" 2 diff --git a/test_regress/t/t_preproc.v b/test_regress/t/t_preproc.v index 19af7a196..05718830f 100644 --- a/test_regress/t/t_preproc.v +++ b/test_regress/t/t_preproc.v @@ -95,6 +95,19 @@ assign c = tmp_``c ; `ADD_UP(d1,o1) // expansion is OK `ADD_UP( d2 , o2 ) // expansion is bad + `define check(mod, width, flopname, gate, path) \ + generate for (i=0; i<(width); i=i+1) begin \ + psl cover { path.d[i] & ~path.q[i] & !path.cond & (gate)} report `"fondNoRise: mod.flopname`"; \ + psl cover { ~path.d[i] & path.q[i] & !path.cond & (gate)} report `"fondNoFall: mod.flopname`"; \ + end endgenerate + +// parameterized macro with arguments that are macros + `define MK m5k.f + `define MF `MK .ctl + `define CK_fr (`MF.alive & `MF.alive_m1) + + `check(m5kc_fcl, 3, _ctl_mvldx_m1, `CK_fr, `MF._ctl_mvldx_m1) // ignorecmt + //=========================================================================== // Ifdef