From 323c96f42fe395caec77b39bbe2693c910489f60 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 25 Dec 2010 15:13:56 -0500 Subject: [PATCH] Add -Wwarn-style, -Wno-style, and DEFPARAM warnings --- Changes | 5 ++++ bin/verilator | 39 ++++++++++++++++++++++++--- src/V3Error.cpp | 7 +++++ src/V3Error.h | 13 ++++++--- src/V3Link.cpp | 1 + src/V3Options.cpp | 7 +++++ test_regress/t/t_lint_defparam.pl | 16 +++++++++++ test_regress/t/t_lint_defparam.v | 15 +++++++++++ test_regress/t/t_lint_defparam_bad.pl | 23 ++++++++++++++++ 9 files changed, 119 insertions(+), 7 deletions(-) create mode 100755 test_regress/t/t_lint_defparam.pl create mode 100644 test_regress/t/t_lint_defparam.v create mode 100755 test_regress/t/t_lint_defparam_bad.pl diff --git a/Changes b/Changes index ff2f42f63..ee465d9af 100644 --- a/Changes +++ b/Changes @@ -7,12 +7,17 @@ indicates the contributor was also the author of the fix; Thanks! ** Add limited support for VPI access to public signals, see docs. +** Add -Wwarn-style, -Wno-style to enable code style warnings that are + added to this release and disabled by default. + *** Add -F option to read relative option files, bug297. [Neil Hamilton] *** Support ++,--,+= etc as standalone statements. [Alex Solomatnikov] *** Suppress WIDTH warnings when adding/subtracting 1'b1. +*** Add optional DEFPARAM warning to find deprecated defparam statements. + **** When running with VERILATOR_ROOT, optionally find binaries under bin. * Verilator 3.805 2010/11/02 diff --git a/bin/verilator b/bin/verilator index ae6866521..ee4deb605 100755 --- a/bin/verilator +++ b/bin/verilator @@ -301,6 +301,7 @@ descriptions in the next sections for more information. -Wfuture- Disable unknown message warnings -Wno- Disable warning -Wno-lint Disable all lint warnings + -Wno-style Disable all style warnings -x-assign Initially assign Xs to this value -y Directory to search for modules @@ -608,6 +609,9 @@ fairly standard across Verilog tools. Check the files for lint violations only, do not create any other output. +You may also want the -Wwarn-style option to enable messages that are +considered stylistic and not enabled by default. + If the design is not to be completely Verilated see also the --bbox-sys and --bbox-unsup options. @@ -855,19 +859,38 @@ Disable the specified warning message. =item -Wno-lint -Disable all lint related warning messages. This is equivalent to -"-Wno-CASEINCOMPLETE -Wno-CASEOVERLAP -Wno-CASEX -Wno-CASEWITHX --Wno-CMPCONST -Wno-IMPLICIT -Wno-LITENDIAN -Wno-UNDRIVEN -Wno-UNSIGNED --Wno-UNUSED -Wno-VARHIDDEN -Wno-WIDTH". +Disable all lint related warning messages, and all style warnings. This is +equivalent to "-Wno-CASEINCOMPLETE -Wno-CASEOVERLAP -Wno-CASEX +-Wno-CASEWITHX -Wno-CMPCONST -Wno-IMPLICIT -Wno-LITENDIAN -Wno-UNDRIVEN +-Wno-UNSIGNED -Wno-UNUSED -Wno-VARHIDDEN -Wno-WIDTH" plus the list shown +for Wno-style. It is strongly recommended you cleanup your code rather than using this option, it is only intended to be use when running test-cases of code received from third parties. +=item -Wno-style + +Disable all code style related warning messages (note by default they are already disabled). This is equivalent to +"-Wno-DEFPARAM". + =item -Wwarn-I Enables the specified warning message. +=item -Wwarn-lint + +Enable all lint related warning messages (note by default they are already +enabled), but do not affect style messages. This is equivalent to +"-Wwarn-CASEINCOMPLETE -Wwarn-CASEOVERLAP -Wwarn-CASEX -Wwarn-CASEWITHX +-Wwarn-CMPCONST -Wwarn-IMPLICIT -Wwarn-LITENDIAN -Wwarn-UNDRIVEN +-Wwarn-UNSIGNED -Wwarn-UNUSED -Wwarn-VARHIDDEN -Wwarn-WIDTH". + +=item -Wwarn-style + +Enable all code style related warning messages. This is equivalent to +"-WDEFPARAM". + =item -x-assign 0 =item -x-assign 1 @@ -2360,6 +2383,14 @@ L Ignoring this warning may make Verilator simulations differ from other simulators. +=item DEFPARAM + +Warns that the "defparam" statement was deprecated in Verilog 2001 and all +designs should now be using the #(...) format to specify parameters. + +Disabled by default as this is a code style warning, it will simulate +correctly. + =item GENCLK Warns that the specified signal is generated, but is also being used as a diff --git a/src/V3Error.cpp b/src/V3Error.cpp index bbf313a60..b37afd6b8 100644 --- a/src/V3Error.cpp +++ b/src/V3Error.cpp @@ -134,6 +134,13 @@ void FileLine::warnLintOff(bool flag) { } } +void FileLine::warnStyleOff(bool flag) { + for (int codei=V3ErrorCode::EC_FIRST_WARN; codeiiterateChildren(*this); if (m_idState==ID_PARAM) { + nodep->v3warn(DEFPARAM,"Suggest replace defparam with Verilog 2001 #(."<name()<<"(...etc...))"); AstNode* foundp = m_curVarsp->findIdUpward(nodep->path()); AstCell* cellp = foundp->castCell(); if (!cellp) { diff --git a/src/V3Options.cpp b/src/V3Options.cpp index 0fa7df808..e87ba1db2 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -791,6 +791,10 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char else if ( !strncmp (sw, "-Wno-",5) ) { if (!strcmp (sw, "-Wno-lint")) { FileLine::globalWarnLintOff(true); + FileLine::globalWarnStyleOff(true); + } + else if (!strcmp (sw, "-Wno-style")) { + FileLine::globalWarnStyleOff(true); } else { string msg = sw+strlen("-Wno-"); @@ -803,6 +807,9 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char if (!strcmp (sw, "-Wwarn-lint")) { FileLine::globalWarnLintOff(false); } + else if (!strcmp (sw, "-Wwarn-style")) { + FileLine::globalWarnStyleOff(false); + } else { string msg = sw+strlen("-Wwarn-"); if (!(FileLine::globalWarnOff(msg, false))) { diff --git a/test_regress/t/t_lint_defparam.pl b/test_regress/t/t_lint_defparam.pl new file mode 100755 index 000000000..3e31930e1 --- /dev/null +++ b/test_regress/t/t_lint_defparam.pl @@ -0,0 +1,16 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2003 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +compile ( + v_flags2 => ["--lint-only"], + ) if $Self->{v3}; + +ok(1); +1; + diff --git a/test_regress/t/t_lint_defparam.v b/test_regress/t/t_lint_defparam.v new file mode 100644 index 000000000..079fb0bd2 --- /dev/null +++ b/test_regress/t/t_lint_defparam.v @@ -0,0 +1,15 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2010 by Wilson Snyder. + +module t; + + sub sub (); + defparam sub.P = 2; + +endmodule + +module sub; + parameter P = 6; +endmodule diff --git a/test_regress/t/t_lint_defparam_bad.pl b/test_regress/t/t_lint_defparam_bad.pl new file mode 100755 index 000000000..bdaf74fd2 --- /dev/null +++ b/test_regress/t/t_lint_defparam_bad.pl @@ -0,0 +1,23 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2008 by Wilson Snyder. This program is free software; you can +# redistribute it and/or modify it under the terms of either the GNU +# Lesser General Public License Version 3 or the Perl Artistic License +# Version 2.0. + +top_filename("t/t_lint_defparam.v"); + +compile ( + v_flags2 => ["--lint-only -Wwarn-style"], + fails=>1, + expect=> +'%Warning-DEFPARAM: t/t_lint_defparam.v:\d+: Suggest replace defparam with Verilog 2001 #\(.P\(...etc...\)\) +%Warning-DEFPARAM: Use .* to disable this message. +%Error: Exiting due to.*', + ) if $Self->{v3}; + +ok(1); +1; +