From b12977d61a87060ae03aa4c248983da2e56c449e Mon Sep 17 00:00:00 2001 From: Cary R Date: Sun, 3 Sep 2023 21:30:45 -0700 Subject: [PATCH] A macro can only have `" and add `\`" for pragma comments We want to support `" and `\`" when a pragma comment is part of a macro definition, but this cannot be part of a normal pragma comment. --- ivlpp/lexor.lex | 3 ++- ivtest/ivltests/attrib_expr.v | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 07b0a4b0b0..653e5c1a9e 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -268,7 +268,8 @@ keywords (line|include|define|undef|ifdef|ifndef|else|elsif|endif) `[a-zA-Z][a-zA-Z0-9_$]* { if (macro_needs_args(yytext+1)) yy_push_state(MA_START); else do_expand(0); } -`\" { fputc('\"', yyout); } +`\" { if (!istack->file) fputc('"', yyout); else REJECT; } +`\\`\" { if (!istack->file) fputs("\\\"", yyout); else REJECT; } /* Strings do not contain preprocessor directives or macro expansions. */ diff --git a/ivtest/ivltests/attrib_expr.v b/ivtest/ivltests/attrib_expr.v index 537d5bc5c3..070ba9aa0d 100644 --- a/ivtest/ivltests/attrib_expr.v +++ b/ivtest/ivltests/attrib_expr.v @@ -74,9 +74,9 @@ endfunction (* attr = fn(10) *) reg attr46; -// Macro escaped -`define A_MACRO(arg) (* attr = `"arg`" *) - `A_MACRO(test) reg attr47; +// Macro escape only in a macro declaration +`define MACRO(arg) (* attr = `"`\`"arg`\`"`" *) +`MACRO(test) reg attr47; initial begin $display("PASSED");