With --Wall, add DECLFILENAME warning on modules not matching filename.

This commit is contained in:
Wilson Snyder 2010-12-25 16:31:22 -05:00
parent fedf347b1a
commit 3e4e8feb29
13 changed files with 96 additions and 12 deletions

View File

@ -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.

View File

@ -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<message>
@ -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<http://www.sunburst-design.com/papers/CummingsSNUG2000SJ_NBA_rev1_2.pdf>
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

View File

@ -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 "
<<nodep->prettyTypeName()<<endl
<<V3Error::msgPrefix()<<errorp->fileline()<<"... Location of non-constant "
<<V3Error::msgPrefix(V3ErrorCode::EC_ERROR)<<errorp->fileline()<<"... Location of non-constant "
<<errorp->prettyTypeName()<<": "<<simvis.whyNotMessage());
replaceZero(nodep); nodep=NULL;
} else {

View File

@ -167,13 +167,19 @@ const string FileLine::filebasename() const {
return name;
}
const string FileLine::profileFuncname() const {
// Return string that is OK as a function name - for profiling
string name = filebasename();
const string FileLine::filebasenameNoExt() const {
string name = filebasename();
string::size_type pos;
if ((pos = name.find(".")) != string::npos) {
name = name.substr(0,pos);
}
return name;
}
const string FileLine::profileFuncname() const {
// Return string that is OK as a function name - for profiling
string name = filebasenameNoExt();
string::size_type pos;
while ((pos = name.find_first_not_of("abcdefghijlkmnopqrstuvwxyzABCDEFGHIJLKMNOPQRSTUVWXYZ0123456789_"))
!= string::npos) {
name.replace(pos, 1, "_");

View File

@ -62,6 +62,7 @@ public:
CMPCONST, // Comparison is constant due to limited range
COMBDLY, // Combinatorial delayed assignment
DEFPARAM, // Style: Defparam
DECLFILENAME, // Declaration doesn't match filename
STMTDLY, // Delayed statement
SYMRSVDWORD, // Symbol is Reserved Word
GENCLK, // Generated Clock
@ -102,7 +103,7 @@ public:
" EC_FIRST_WARN",
"BLKANDNBLK",
"CASEINCOMPLETE", "CASEOVERLAP", "CASEWITHX", "CASEX", "CDCRSTLOGIC", "CMPCONST",
"COMBDLY", "DEFPARAM",
"COMBDLY", "DEFPARAM", "DECLFILENAME",
"STMTDLY", "SYMRSVDWORD", "GENCLK", "IMPERFECTSCH", "IMPLICIT", "IMPURE",
"INCABSPATH",
"LITENDIAN", "MODDUP",
@ -134,6 +135,7 @@ public:
|| m_e==WIDTH); }
// Warnings that are style only
bool styleError() const { return ( m_e==DEFPARAM
|| m_e==DECLFILENAME
|| m_e==INCABSPATH
|| m_e==VARHIDDEN ); }
};
@ -267,6 +269,7 @@ public:
string ascii() const;
const string filename () const { return m_filename; }
const string filebasename () const;
const string filebasenameNoExt () const;
const string profileFuncname() const;
string lineDirectiveStrg(int enter_exit_level) const;
void warnOn(V3ErrorCode code, bool flag) { m_warnOn.set(code,flag); } // Turn on/off warning messages on this line.

View File

@ -227,6 +227,12 @@ private:
virtual void visit(AstNodeModule* nodep, AstNUser*) {
// Module: Create sim table for entire module and iterate
UINFO(2,"Link Module: "<<nodep<<endl);
if (m_idState == ID_FIND) {
if (nodep->fileline()->filebasenameNoExt() != nodep->prettyName()) {
nodep->v3warn(DECLFILENAME, "Filename '"<<nodep->fileline()->filebasenameNoExt()
<<"' does not match "<<nodep->typeName()<<" name: "<<nodep->prettyName());
}
}
AstCell* upperCellp = m_cellp;
V3SymTable* upperVarsp = m_curVarsp;
{

View File

@ -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;

View File

@ -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

View File

@ -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;

View File

@ -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...\)\)

View File

@ -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,

View File

@ -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

View File

@ -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