From 3e4e8feb295db873992d6490e7829f8c402055eb Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 25 Dec 2010 16:31:22 -0500 Subject: [PATCH] With --Wall, add DECLFILENAME warning on modules not matching filename. --- Changes | 2 ++ bin/verilator | 15 +++++++++++-- src/V3Const.cpp | 4 ++-- src/V3Error.cpp | 12 ++++++++--- src/V3Error.h | 5 ++++- src/V3Link.cpp | 6 ++++++ test_regress/t/t_lint_declfilename.pl | 19 +++++++++++++++++ test_regress/t/t_lint_declfilename.v | 11 ++++++++++ test_regress/t/t_lint_declfilename_bad.pl | 26 +++++++++++++++++++++++ test_regress/t/t_lint_defparam_bad.pl | 2 +- test_regress/t/t_lint_incabspath_bad.pl | 2 +- test_regress/t/t_var_bad_hide.pl | 2 +- test_regress/t/t_var_bad_hide2.pl | 2 +- 13 files changed, 96 insertions(+), 12 deletions(-) create mode 100755 test_regress/t/t_lint_declfilename.pl create mode 100644 test_regress/t/t_lint_declfilename.v create mode 100755 test_regress/t/t_lint_declfilename_bad.pl diff --git a/Changes b/Changes index 922d4d822..62d9c2aae 100644 --- a/Changes +++ b/Changes @@ -16,6 +16,8 @@ indicates the contributor was also the author of the fix; Thanks! *** Suppress WIDTH warnings when adding/subtracting 1'b1. +*** With --Wall, add DECLFILENAME warning on modules not matching filename. + *** With --Wall, add DEFPARAM warning on deprecated defparam statements. *** With --Wall, add INCABSPATH warning on `include with absolute paths. diff --git a/bin/verilator b/bin/verilator index 149dc06ed..af9f9edf0 100755 --- a/bin/verilator +++ b/bin/verilator @@ -877,7 +877,8 @@ 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 -Wno-VARHIDDEN". +already disabled). This is equivalent to "-Wno-DECLFILENAME -Wno-DEFPARAM +-Wno-INCABSPATH -Wno-VARHIDDEN". =item -Wwarn-I @@ -894,7 +895,7 @@ enabled), but do not affect style messages. This is equivalent to =item -Wwarn-style Enable all code style related warning messages. This is equivalent to -"-Wwarn-DEFPARAM -Wwarn-VARHIDDEN". +"-Wwarn-DECLFILENAME -Wwarn-DEFPARAM -Wwarn-INCABSPATH -Wwarn-VARHIDDEN". =item -x-assign 0 @@ -2388,6 +2389,16 @@ L Ignoring this warning may make Verilator simulations differ from other simulators. +=item DECLFILENAME + +Warns that a module or other declaration's name doesn't match the filename +with path and extension stripped that it is declared in. The filename a +modules/interfaces/programs is declared in should match the name of the +module etc. so that -y directory searching will work. + +Disabled by default as this is a code style warning, it will simulate +correctly. + =item DEFPARAM Warns that the "defparam" statement was deprecated in Verilog 2001 and all diff --git a/src/V3Const.cpp b/src/V3Const.cpp index 42e3783f2..1219a7cb3 100644 --- a/src/V3Const.cpp +++ b/src/V3Const.cpp @@ -855,10 +855,10 @@ private: // Run it - may be unoptimizable due to large for loop, etc simvis.mainParamEmulate(nodep); if (!simvis.optimizable()) { - AstNode* errorp = simvis.whyNotNodep(); if (!errorp) errorp = nodep; + AstNode* errorp = simvis.whyNotNodep(); if (!errorp) errorp = nodep; nodep->v3error("Expecting expression to be constant, but can't determine constant for " <prettyTypeName()<fileline()<<"... Location of non-constant " + <fileline()<<"... Location of non-constant " <prettyTypeName()<<": "<fileline()->filebasenameNoExt() != nodep->prettyName()) { + nodep->v3warn(DECLFILENAME, "Filename '"<fileline()->filebasenameNoExt() + <<"' does not match "<typeName()<<" name: "<prettyName()); + } + } AstCell* upperCellp = m_cellp; V3SymTable* upperVarsp = m_curVarsp; { diff --git a/test_regress/t/t_lint_declfilename.pl b/test_regress/t/t_lint_declfilename.pl new file mode 100755 index 000000000..1cdbc8f7c --- /dev/null +++ b/test_regress/t/t_lint_declfilename.pl @@ -0,0 +1,19 @@ +#!/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"], + verilator_make_gcc => 0, + make_top_shell => 0, + make_main => 0, + ) if $Self->{v3}; + +ok(1); +1; + diff --git a/test_regress/t/t_lint_declfilename.v b/test_regress/t/t_lint_declfilename.v new file mode 100644 index 000000000..862be675f --- /dev/null +++ b/test_regress/t/t_lint_declfilename.v @@ -0,0 +1,11 @@ +// 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; + t_lint_declfilename sub (); +endmodule + +module t_lint_declfilename; +endmodule diff --git a/test_regress/t/t_lint_declfilename_bad.pl b/test_regress/t/t_lint_declfilename_bad.pl new file mode 100755 index 000000000..ecff0bf01 --- /dev/null +++ b/test_regress/t/t_lint_declfilename_bad.pl @@ -0,0 +1,26 @@ +#!/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_declfilename.v"); + +compile ( + v_flags2 => ["--lint-only -Wall"], + fails=>1, + verilator_make_gcc => 0, + make_top_shell => 0, + make_main => 0, + expect=> +'%Warning-DECLFILENAME: t/t_lint_declfilename.v:6: Filename \'t_lint_declfilename\' does not match MODULE name: t +%Warning-DECLFILENAME: Use .* to disable this message. +%Error: Exiting due to.*', + ) if $Self->{v3}; + +ok(1); +1; + diff --git a/test_regress/t/t_lint_defparam_bad.pl b/test_regress/t/t_lint_defparam_bad.pl index bdaf74fd2..9cf9d8df3 100755 --- a/test_regress/t/t_lint_defparam_bad.pl +++ b/test_regress/t/t_lint_defparam_bad.pl @@ -10,7 +10,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di top_filename("t/t_lint_defparam.v"); compile ( - v_flags2 => ["--lint-only -Wwarn-style"], + v_flags2 => ["--lint-only -Wwarn-style -Wno-DECLFILENAME"], fails=>1, expect=> '%Warning-DEFPARAM: t/t_lint_defparam.v:\d+: Suggest replace defparam with Verilog 2001 #\(.P\(...etc...\)\) diff --git a/test_regress/t/t_lint_incabspath_bad.pl b/test_regress/t/t_lint_incabspath_bad.pl index 08aba95af..24b886b07 100755 --- a/test_regress/t/t_lint_incabspath_bad.pl +++ b/test_regress/t/t_lint_incabspath_bad.pl @@ -10,7 +10,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di top_filename("t/t_lint_incabspath.v"); compile ( - v_flags2 => ["--lint-only -Wall"], + v_flags2 => ["--lint-only -Wall -Wno-DECLFILENAME"], fails=>1, verilator_make_gcc => 0, make_top_shell => 0, diff --git a/test_regress/t/t_var_bad_hide.pl b/test_regress/t/t_var_bad_hide.pl index 759101b77..6a0fa0094 100755 --- a/test_regress/t/t_var_bad_hide.pl +++ b/test_regress/t/t_var_bad_hide.pl @@ -8,7 +8,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di # Version 2.0. compile ( - v_flags2 => ["--lint-only -Wall"], + v_flags2 => ["--lint-only -Wall -Wno-DECLFILENAME"], fails=>$Self->{v3}, expect=> '%Warning-VARHIDDEN: t/t_var_bad_hide.v:\d+: Declaration of signal hides declaration in upper scope: top diff --git a/test_regress/t/t_var_bad_hide2.pl b/test_regress/t/t_var_bad_hide2.pl index a87517e62..9fb47f2d8 100755 --- a/test_regress/t/t_var_bad_hide2.pl +++ b/test_regress/t/t_var_bad_hide2.pl @@ -8,7 +8,7 @@ if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); di # Version 2.0. compile ( - v_flags2 => ["--lint-only -Wall"], + v_flags2 => ["--lint-only -Wall -Wno-DECLFILENAME"], fails=>$Self->{v3}, expect=> '%Warning-VARHIDDEN: t/t_var_bad_hide2.v:\d+: Declaration of signal hides declaration in upper scope: t