From 794e15ac56629cd65448fb8e760118ee8e817278 Mon Sep 17 00:00:00 2001 From: Martin Whitaker Date: Fri, 9 Oct 2020 08:09:04 +0100 Subject: [PATCH] Fix GitHub issue #374 - ordering of `` and embedded macro expansion. The IEEE standard does not clearly state whether the `` directive is applied before or after embedded macros are expanded. Other simulators vary in their behaviour. For maximum compatibility, this fix adopts the behaviour found in Verilator, where `prefix``suffix expands to suffix if prefix is a defined macro, otherwise it expands to (where <...> is the expanded macro text). Other simulators show this behaviour in at least some circumstances. (cherry picked from commit 65660727419a77c9ed552f2f3a71d2ea2328d03e) --- ivlpp/lexor.lex | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index 20c237c91..b43584436 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -154,9 +154,9 @@ static void ifdef_leave(void) result = (rc == 0) ? YY_NULL : rc; \ } else { \ /* We are expanding a macro. Handle the SV `` delimiter. \ - If the delimiter terminates a compiler directive, leave \ + If the delimiter terminates a defined macro usage, leave \ it in place, otherwise remove it now. */ \ - if (yytext[0] != '`') { \ + if (!(yytext[0] == '`' && is_defined(yytext+1))) { \ while ((istack->str[0] == '`') && \ (istack->str[1] == '`')) { \ istack->str += 2; \