diff --git a/Changes b/Changes index be76d962d..76d93f963 100644 --- a/Changes +++ b/Changes @@ -10,6 +10,8 @@ indicates the contributor was also the author of the fix; Thanks! *** Allow multiple .v files on command line. [Stefan Thiede] +*** Convert re-defining macro error to warning. [Stefan Thiede] + **** Fix genvar to be signed, so "< 0" works properly. [Niranjan Prabhu] **** Fix assignments to inputs inside functions/tasks. [Patricio Kaplan] diff --git a/bin/verilator b/bin/verilator index c4e995258..6565278f7 100755 --- a/bin/verilator +++ b/bin/verilator @@ -1695,6 +1695,23 @@ not really needed. The best solution is to insure that each module is in a unique file by the same name. Otherwise, make sure all library files are read in as libraries with -v, instead of automatically with -y. +=item REDEFMACRO + +Warns that you have redefined the same macro with a different value, for +example: + + `define MACRO def1 + //... + `define MACRO otherdef + +The best solution is to use a different name for the second macro. If this +is not possible, add a undef to indicate the code is overriding the value: + + `define MACRO def1 + //... + `undef MACRO + `define MACRO otherdef + =item STMTDLY Warns that you have a statement with a delayed time in front of it, for diff --git a/src/V3Error.h b/src/V3Error.h index bfae5fa84..c40f0aca5 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -53,6 +53,7 @@ public: IMPLICIT, // Implicit wire IMPURE, // Impure function not being inlined MULTIDRIVEN, // Driven from multiple blocks + REDEFMACRO, // Redefining existing define macro UNDRIVEN, // No drivers UNOPT, // Unoptimizable block UNOPTFLAT, // Unoptimizable block after flattening @@ -78,7 +79,7 @@ public: "BLKANDNBLK", "CASEINCOMPLETE", "CASEOVERLAP", "CASEX", "CMPCONST", "COMBDLY", "STMTDLY", "GENCLK", "IMPLICIT", "IMPURE", - "MULTIDRIVEN", + "MULTIDRIVEN", "REDEFMACRO", "UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNSIGNED", "UNUSED", "VARHIDDEN", "WIDTH", " MAX" diff --git a/src/V3PreProc.cpp b/src/V3PreProc.cpp index 0c4447293..a2130a850 100644 --- a/src/V3PreProc.cpp +++ b/src/V3PreProc.cpp @@ -207,8 +207,8 @@ void V3PreProcImp::define(FileLine* fl, const string& name, const string& value, UINFO(4,"DEFINE '"<v3error("Define already exists: "<v3error("Previous definition is here."); + fl->v3warn(REDEFMACRO,"Redefining existing define: "<v3warn(REDEFMACRO,"Previous definition is here, with value: "< ["-Wno-REDEFMACRO"], + ) if $Last_Self->{v3}; + +ok(1); +1; + diff --git a/test_regress/t/t_pp_dupdef.v b/test_regress/t/t_pp_dupdef.v new file mode 100644 index 000000000..8de2b8abe --- /dev/null +++ b/test_regress/t/t_pp_dupdef.v @@ -0,0 +1,17 @@ +// $Id$ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed into the Public Domain, for any use, +// without warranty, 2008 by Wilson Snyder. + +module t; + +`define DUP fred +`define DUP barney + +`define DUPP paramed(x) (x) +`define DUPP paramed(x,z) (x*z) + + initial $stop; // Should have failed + +endmodule diff --git a/test_regress/t/t_pp_dupdef_bad.pl b/test_regress/t/t_pp_dupdef_bad.pl new file mode 100755 index 000000000..bae7876fa --- /dev/null +++ b/test_regress/t/t_pp_dupdef_bad.pl @@ -0,0 +1,26 @@ +#!/usr/bin/perl +if (!$::Driver) { use FindBin; exec("./driver.pl", @ARGV, $0); die; } +# $Id$ +# 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 +# General Public License or the Perl Artistic License. + +top_filename("t/t_pp_dupdef.v"); + +compile ( + v_flags2 => ["--lint-only"], + fails=>1, + expect=> +'%Warning-REDEFMACRO: t/t_pp_dupdef.v:\d+: Redefining existing define: DUP, with different value: barney +%Warning-REDEFMACRO: Use .* to disable this message. +%Warning-REDEFMACRO: t/t_pp_dupdef.v:\d+: Previous definition is here, with value: fred +%Warning-REDEFMACRO: t/t_pp_dupdef.v:\d+: Redefining existing define: DUPP, with different value: .* +%Warning-REDEFMACRO: t/t_pp_dupdef.v:\d+: Previous definition is here, with value: .* +%Error: Exiting due to.*', + ) if $Last_Self->{v3}; + +ok(1); +1; +