From 72218fb475810c30aadda0031bee2efe665963c2 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Thu, 18 Feb 2010 20:57:46 -0500 Subject: [PATCH] Defines with // comments still need continuation - spec ambiguity --- src/V3PreLex.l | 1 + src/V3PreProc.cpp | 11 +++++--- test_regress/t/t_preproc.out | 53 +++++++++++++++++++++++++++++++++++- test_regress/t/t_preproc.v | 45 ++++++++++++++++++++++++++++++ 4 files changed, 105 insertions(+), 5 deletions(-) diff --git a/src/V3PreLex.l b/src/V3PreLex.l index 26c3bae93..bac2e7bab 100644 --- a/src/V3PreLex.l +++ b/src/V3PreLex.l @@ -154,6 +154,7 @@ psl [p]sl /* Reading definition value */ "/*" { LEXP->m_defCmtSlash=false; yy_push_state(DEFCMT); yymore(); } /* Special comment parser */ +"//"[^\n\r]*[\\]{crnl} { linenoInc(); appendDefValue((char*)"\n",1); } /* Spec says // not part of define value */ "//"[^\n\r]* { return (VP_COMMENT);} {drop} { } <> { linenoInc(); yy_pop_state(); yytext=(char*)"\n"; yyleng=1; return (VP_DEFVALUE); } /* Technically illegal, but people complained */ diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index df35b3ec3..3cd3408f6 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -71,7 +71,7 @@ class V3DefineRef { string m_name; // Define last name being defined string m_params; // Define parameter list for next expansion string m_nextarg; // String being built for next argument - int m_parenLevel; // Parenthesis counting inside def args + int m_parenLevel; // Parenthesis counting inside def args (for PARENT not child) vector m_args; // List of define arguments public: @@ -80,9 +80,10 @@ public: string nextarg() const { return m_nextarg; } void nextarg(const string& value) { m_nextarg = value; } int parenLevel() const { return m_parenLevel; } + void parenLevel(int value) { m_parenLevel = value; } vector& args() { return m_args; } - V3DefineRef(const string& name, const string& params, int pl) - : m_name(name), m_params(params), m_parenLevel(pl) {} + V3DefineRef(const string& name, const string& params) + : m_name(name), m_params(params), m_parenLevel(0) {} ~V3DefineRef() {} }; @@ -1054,7 +1055,9 @@ int V3PreProcImp::getToken() { } else { // Found, with parameters UINFO(4,"Defref `"< parameterized"<m_parenLevel)); + // The CURRENT macro needs the paren saved, it's not a property of the child macro + if (!m_defRefs.empty()) m_defRefs.top().parenLevel(m_lexp->m_parenLevel); + m_defRefs.push(V3DefineRef(name, params)); m_state = ps_DEFPAREN; m_stateFor = tok; m_lexp->pushStateDefArg(0); goto next_tok; diff --git a/test_regress/t/t_preproc.out b/test_regress/t/t_preproc.out index 24a3d959a..d87221979 100644 --- a/test_regress/t/t_preproc.out +++ b/test_regress/t/t_preproc.out @@ -244,13 +244,64 @@ $display("bits %d %d", $bits(foo), `10); + + + + 1 /*verilator NOT IN DEFINE*/ (nodef) 2 /*verilator PART OF DEFINE*/ (hasdef) 3 /*verilator NOT PART OF DEFINE*/ (nodef) 4 /*verilator PART OF DEFINE*/ (nodef) +5 also in also3 (nodef) HAS a NEW LINE -`line 203 "t/t_preproc.v" 2 + + + + + + + + + + + + + + + + + +EXP: clxx_scen +clxx_scen +EXP: clxx_scen +"clxx_scen" + +EXP: do if (start("verilog/inc1.v", 25)) begin message({"Blah-", "clx_scen", " end"}); end while(0); +do +`line 231 "t/t_preproc.v" 0 + if (start("t/t_preproc.v", 231)) begin message({"Blah-", "clx_scen", " end"}); end while(0); + + + + + + + + + + +`line 241 "t/t_preproc.v" 0 + + +EXP: This is fooed +This is fooed + +EXP: This is fooed_2 +This is fooed_2 + + +`line 250 "t/t_preproc.v" 2 diff --git a/test_regress/t/t_preproc.v b/test_regress/t/t_preproc.v index a8456ca99..381ccc0a4 100644 --- a/test_regress/t/t_preproc.v +++ b/test_regress/t/t_preproc.v @@ -191,12 +191,57 @@ Line_Preproc_Check `__LINE__ OF DEFINE */ `define CMT4 /* verilator PART \ OF DEFINE */ +`define CMT5 // CMT NOT \ + also in // BUT TEXT IS \ + also3 // CMT NOT + 1 `CMT1 (nodef) 2 `CMT2 (hasdef) 3 `CMT3 (nodef) 4 `CMT4 (nodef) +5 `CMT5 (nodef) `define NL HAS a NEW \ LINE `NL //====================================================================== + +`define msg_fatal(log, msg) \ + do \ + /* synopsys translate_off */ \ +`ifdef NEVER \ + `error "WTF" \ +`else \ + if (start(`__FILE__, `__LINE__)) begin \ +`endif \ + message(msg); \ + end \ + /* synopsys translate_on */ \ + while(0) + +`define msg_scen_(cl) cl``_scen +`define MSG_MACRO_TO_STRING(x) `"x`" + +EXP: clxx_scen +`msg_scen_(clxx) +EXP: clxx_scen +`MSG_MACRO_TO_STRING(`msg_scen_(clxx)) +`define mf(clx) `msg_fatal(this.log, {"Blah-", `MSG_MACRO_TO_STRING(`msg_scen_(clx)), " end"}); +EXP: do if (start("verilog/inc1.v", 25)) begin message({"Blah-", "clx_scen", " end"}); end while(0); +`mf(clx) + +//====================================================================== + +`define makedefine(name) \ + `define def_``name This is name \ + `define def_``name``_2 This is name``_2 \ + +`makedefine(fooed) +`ifndef def_fooed `error "No def_fooed" `endif +//`ifndef def_fooed_2 `error "No def_fooed_2" `endif +EXP: This is fooed +`def_fooed +EXP: This is fooed_2 +`def_fooed_2 + +//======================================================================