From 1611362c224743ff5e4ccd380b1bb15e38ae1097 Mon Sep 17 00:00:00 2001 From: Wilson Snyder Date: Sat, 1 Jan 2011 19:43:22 -0500 Subject: [PATCH] Add --unused-regexp --- bin/verilator | 29 +++++++++++++++++++++++++++-- src/V3Options.cpp | 4 ++++ src/V3Options.h | 4 +++- src/V3Undriven.cpp | 17 +++++++++++++---- test_regress/t/t_lint_unused_bad.v | 2 ++ 5 files changed, 49 insertions(+), 7 deletions(-) diff --git a/bin/verilator b/bin/verilator index 1bca19dc4..386c629fd 100755 --- a/bin/verilator +++ b/bin/verilator @@ -296,6 +296,7 @@ descriptions in the next sections for more information. -U Undefine preprocessor define --unroll-count Tune maximum loop iterations --unroll-stmts Tune maximum loop body size + --unused-regexp Tune UNUSED lint signals -V Verbose version and config -v Verilog library -Werror- Convert warning to error @@ -834,6 +835,12 @@ unrolled. See also BLKLOOPINIT warning. Rarely needed. Specifies the maximum number of statements in a loop for that loop to be unrolled. See also BLKLOOPINIT warning. +=item --unused-regexp I + +Rarely needed. Specifies a simple regexp with * and ? that if a signal +name matches will suppress the UNUSED warning. Defaults to "*unused*". +Setting it to "" disables matching. + =item -V Shows the verbose version, including configuration information compiled @@ -2705,12 +2712,30 @@ correctly. =item UNUSED Warns that the specified signal is never sinked. Verilator is fairly -liberal in the usage calculations; making a signal public, or accessing -only a single array element marks the entire signal as used. +liberal in the usage calculations; making a signal public, a signal +matching --unused-regexp ("*unused*") or accessing only a single array +element marks the entire signal as used. Disabled by default as this is a code style warning; it will simulate correctly. +A recommended style for unused nets is to put at the bottom of a file code +similar to the following: + + wire _unused_ok = &{1'b0, + sig_not_used_a, + sig_not_used_yet_b, // To be fixed + 1'b0}; + +The reduction AND and constant zeros mean the net will always be zero, so +won't use simulation time. The redundant leading and trailing zeros avoid +syntax errors if there are no signals between them. The magic name +"unused" (-unused-regexp) is recognized by Verilator and suppresses +warnings; if using other lint tools, either teach to tool to ignore signals +with "unused" in the name, or put the appropriate lint_off around the wire. +Having unused signals in one place makes it easy to find what is unused, +and reduces the number of lint_off pragmas, reducing bugs. + =item VARHIDDEN Warns that a task, function, or begin/end block is declaring a variable by diff --git a/src/V3Options.cpp b/src/V3Options.cpp index b960fa388..f11db1fec 100644 --- a/src/V3Options.cpp +++ b/src/V3Options.cpp @@ -872,6 +872,9 @@ void V3Options::parseOptsList(FileLine* fl, const string& optdir, int argc, char else if ( !strcmp (sw, "-top-module") && (i+1)prettyName().c_str(), regexpp); + } void reportViolations() { // Combine bits into overall state AstVar* nodep = m_varp; @@ -163,18 +168,22 @@ public: } else if (!anyD && !anyU) { // UNDRIVEN is considered more serious - as is more likely a bug, // thus undriven+unused bits get UNUSED warnings, as they're not as buggy. - nodep->v3warn(UNUSED, "Signal is not driven, nor used: "<prettyName()); + if (!unusedMatch(nodep)) { + nodep->v3warn(UNUSED, "Signal is not driven, nor used: "<prettyName()); + } } else if (allD && !anyU) { - nodep->v3warn(UNUSED, "Signal is not used: "<prettyName()); + if (!unusedMatch(nodep)) { + nodep->v3warn(UNUSED, "Signal is not used: "<prettyName()); + } } else if (!anyD && allU) { nodep->v3warn(UNDRIVEN, "Signal is not driven: "<prettyName()); } else { // Bits have different dispositions - if (anynotDU) { + if (anynotDU && !unusedMatch(nodep)) { nodep->v3warn(UNUSED, "Bits of signal are not driven, nor used: "<prettyName() <v3warn(UNUSED, "Bits of signal are not used: "<prettyName() <