From 73167563d5f1d05ddb690038420c4b23d1d1e1dd Mon Sep 17 00:00:00 2001 From: Andrew Andrianov Date: Sun, 8 Oct 2017 14:18:32 +0300 Subject: [PATCH] ivlpp: Warn about macro redefinition Verilog spec has a very nasty system of macros jumping from file to file, resulting in a global macro scope. We abosolutely MUST track macro redefinitions and warn user about them. Signed-off-by: Andrew Andrianov --- ivlpp/lexor.lex | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ivlpp/lexor.lex b/ivlpp/lexor.lex index c81af7397..a0aa71b42 100644 --- a/ivlpp/lexor.lex +++ b/ivlpp/lexor.lex @@ -858,6 +858,19 @@ void define_macro(const char* name, const char* value, int keyword, int argc) { int idx; struct define_t* def; + struct define_t* prev; + + /* Verilog spec has a very nasty system of macros jumping from + * file to file, resulting in a global macro scope. We abosolutely + * MUST track macro redefinitions and warn user about them. + */ + + prev = def_lookup(name); + if (prev) { + emit_pathline(istack); + fprintf(stderr, "warning: redefinition of macro %s\n", + name); + } def = malloc(sizeof(struct define_t)); def->name = strdup(name);