From ce9fd0147f2fa1e227b2b6bf5df69172f1996301 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Wed, 18 Jun 2008 20:33:30 -0700 Subject: [PATCH] Detect and warn about anachronistic use of begin/end in generate. Verilog-2001 only allows a single generate item within a generate- endgenerate region, but allowed one to collect generate schemes with begin/end blocks. Verilog-2005 cleaned up that mess, and it is the 2005 syntax that Icarus Verilog implements. This patch detects the anachronistic use of begin/end within the generate region, ignores the begin/end words, and prints a warning that the user is using an obsolete syntax. --- parse.y | 9 +++++++++ parse_misc.cc | 19 +++++++++++-------- parse_misc.h | 3 +++ 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/parse.y b/parse.y index de839b334..f63ee1d9b 100644 --- a/parse.y +++ b/parse.y @@ -2200,6 +2200,15 @@ module_item K_endcase { pform_endgenerate(); } + /* Handle some anachronistic syntax cases. */ + | K_generate K_begin module_item_list_opt K_end K_endgenerate + { /* Detect and warn about anachronistic begin/end use */ + if (generation_flag > GN_VER2001) { + warn_count += 1; + cerr << @2 << ": warning: Anachronistic use of begin/end to surround generate schemes." << endl; + } + } + /* specify blocks are parsed but ignored. */ | K_specify K_endspecify diff --git a/parse_misc.cc b/parse_misc.cc index 60bd8b02e..546dec7cf 100644 --- a/parse_misc.cc +++ b/parse_misc.cc @@ -30,6 +30,15 @@ unsigned error_count = 0; unsigned warn_count = 0; unsigned long based_size = 0; +std::ostream& operator << (std::ostream&o, const YYLTYPE&loc) +{ + if (loc.text) + o << loc.text << ":"; + o << loc.first_line; + return o; +} + + void VLerror(const char*msg) { error_count += 1; @@ -39,20 +48,14 @@ void VLerror(const char*msg) void VLerror(const YYLTYPE&loc, const char*msg) { error_count += 1; - if (loc.text) - cerr << loc.text << ":"; - - cerr << loc.first_line << ": " << msg << endl; + cerr << loc << ": " << msg << endl; based_size = 0; /* Clear the base information if we have an error. */ } void yywarn(const YYLTYPE&loc, const char*msg) { warn_count += 1; - if (loc.text) - cerr << loc.text << ":"; - - cerr << loc.first_line << ": warning: " << msg << endl; + cerr << loc << ": warning: " << msg << endl; } int VLwrap() diff --git a/parse_misc.h b/parse_misc.h index 3960f1176..1d3e721a5 100644 --- a/parse_misc.h +++ b/parse_misc.h @@ -23,6 +23,7 @@ #endif # include +# include # include "compiler.h" # include "pform.h" @@ -62,6 +63,8 @@ extern void VLerror(const YYLTYPE&loc, const char*msg); #define yywarn VLwarn extern void VLwarn(const YYLTYPE&loc, const char*msg); +extern ostream& operator << (ostream&, const YYLTYPE&loc); + extern unsigned error_count, warn_count; extern unsigned long based_size;