From f3647578d4d56f5315523b87e9a9a7bdbdfcf952 Mon Sep 17 00:00:00 2001 From: Stephen Williams Date: Sat, 6 Feb 2016 16:07:50 -0800 Subject: [PATCH] Add the -Wimplicit-dimensions warning. --- compiler.h | 4 ++++ driver/main.c | 10 ++++++++++ elab_sig.cc | 17 +++++++++++++++++ main.cc | 4 ++++ scripts/devel-stub.conf | 2 +- 5 files changed, 36 insertions(+), 1 deletion(-) diff --git a/compiler.h b/compiler.h index 85b908b87..a7f5caefb 100644 --- a/compiler.h +++ b/compiler.h @@ -80,6 +80,10 @@ extern unsigned recursive_mod_limit; /* Implicit definitions of wires. */ extern bool warn_implicit; +/* Warn if dimensions of port or var/net are implicitly taken from + the input/output/inout declaration. */ +extern bool warn_implicit_dimensions; + /* inherit timescales across files. */ extern bool warn_timescale; diff --git a/driver/main.c b/driver/main.c index 2990d4706..1103f5f55 100644 --- a/driver/main.c +++ b/driver/main.c @@ -496,6 +496,7 @@ static void process_warning_switch(const char*name) if (strcmp(name,"all") == 0) { process_warning_switch("anachronisms"); process_warning_switch("implicit"); + process_warning_switch("implicit-dimensions"); process_warning_switch("portbind"); process_warning_switch("select-range"); process_warning_switch("timescale"); @@ -509,6 +510,9 @@ static void process_warning_switch(const char*name) } else if (strcmp(name,"implicit") == 0) { if (! strchr(warning_flags, 'i')) strcat(warning_flags, "i"); + } else if (strcmp(name,"implicit-dimensions") == 0) { + if (! strchr(warning_flags, 'd')) + strcat(warning_flags, "d"); } else if (strcmp(name,"portbind") == 0) { if (! strchr(warning_flags, 'p')) strcat(warning_flags, "p"); @@ -547,6 +551,12 @@ static void process_warning_switch(const char*name) cp[0] = cp[1]; cp += 1; } + } else if (strcmp(name,"no-implicit-dimensions") == 0) { + char*cp = strchr(warning_flags, 'd'); + if (cp) while (*cp) { + cp[0] = cp[1]; + cp += 1; + } } else if (strcmp(name,"no-portbind") == 0) { char*cp = strchr(warning_flags, 'p'); if (cp) while (*cp) { diff --git a/elab_sig.cc b/elab_sig.cc index 9b78b110f..a643a1d9c 100644 --- a/elab_sig.cc +++ b/elab_sig.cc @@ -976,6 +976,23 @@ NetNet* PWire::elaborate_sig(Design*des, NetScope*scope) const } if (port_set_ || net_set_) { + + if (warn_implicit_dimensions + && port_set_ && net_set_ + && net_.empty() && !port_.empty()) { + cerr << get_fileline() << ": warning: " + << "var/net declaration of " << basename() + << " inherits dimensions from port declaration." << endl; + } + + if (warn_implicit_dimensions + && port_set_ && net_set_ + && port_.empty() && net_.empty()) { + cerr << get_fileline() << ": warning: " + << "Port declaration of " << basename() + << " inherits dimensions from var/net." << endl; + } + bool bad_range = false; vector plist, nlist; /* If they exist get the port definition MSB and LSB */ diff --git a/main.cc b/main.cc index 66dd10765..48e2858b0 100644 --- a/main.cc +++ b/main.cc @@ -153,6 +153,7 @@ FILE *depend_file = NULL; * These are the warning enable flags. */ bool warn_implicit = false; +bool warn_implicit_dimensions = false; bool warn_timescale = false; bool warn_portbinding = false; bool warn_inf_loop = false; @@ -682,6 +683,9 @@ static void read_iconfig_file(const char*ipath) case 'i': warn_implicit = true; break; + case 'd': + warn_implicit_dimensions = true; + break; case 'l': warn_inf_loop = true; break; diff --git a/scripts/devel-stub.conf b/scripts/devel-stub.conf index def994a22..5936f6662 100644 --- a/scripts/devel-stub.conf +++ b/scripts/devel-stub.conf @@ -15,7 +15,7 @@ iwidth:32 sys_func:vpi/system.sft sys_func:vpi/v2005_math.sft sys_func:vpi/va_math.sft -warnings:afilnpstv +warnings:adfilnpstv debug:eval_tree debug:elaborate debug:emit