diff --git a/bin/verilator b/bin/verilator index 4ace39ef1..f42a3fed0 100755 --- a/bin/verilator +++ b/bin/verilator @@ -4692,6 +4692,11 @@ declared before being used. Error that a procedural assignment is setting a wire. According to IEEE, a var/reg must be used as the target of procedural assignments. +=item RANDC + +Warns that the 'randc' keyword is currently unsupported, and that it is +being converted to 'rand'. + =item REALCVT Warns that a real number is being implicitly rounded to an integer, with diff --git a/src/V3Error.h b/src/V3Error.h index 08419d7f2..a1b780713 100644 --- a/src/V3Error.h +++ b/src/V3Error.h @@ -103,6 +103,7 @@ public: PINCONNECTEMPTY,// Cell pin connected by name with empty reference PKGNODECL, // Error: Package/class needs to be predeclared PROCASSWIRE, // Procedural assignment on wire + RANDC, // Unsupported: 'randc' converted to 'rand' REALCVT, // Real conversion REDEFMACRO, // Redefining existing define macro SELRANGE, // Selection index out of range @@ -164,7 +165,7 @@ public: "LITENDIAN", "MODDUP", "MULTIDRIVEN", "MULTITOP", "PINMISSING", "PINNOCONNECT", "PINCONNECTEMPTY", "PKGNODECL", "PROCASSWIRE", - "REALCVT", "REDEFMACRO", + "RANDC", "REALCVT", "REDEFMACRO", "SELRANGE", "SHORTREAL", "SPLITVAR", "STMTDLY", "SYMRSVDWORD", "SYNCASYNCNET", "TICKCOUNT", "TIMESCALEMOD", "UNDRIVEN", "UNOPT", "UNOPTFLAT", "UNOPTTHREADS", diff --git a/src/V3ParseImp.h b/src/V3ParseImp.h index d14ac1986..599c31592 100644 --- a/src/V3ParseImp.h +++ b/src/V3ParseImp.h @@ -83,7 +83,10 @@ struct VMemberQualifiers { } void applyToNodes(AstVar* nodesp) const { for (AstVar* nodep = nodesp; nodep; nodep = VN_CAST(nodep->nextp(), Var)) { - // Ignored for now: m_randc + if (m_randc) { + nodep->v3warn(RANDC, "Unsupported: Converting 'randc' to 'rand'"); + nodep->isRand(true); + } if (m_rand) nodep->isRand(true); if (m_local) nodep->isHideLocal(true); if (m_protected) nodep->isHideProtected(true); diff --git a/test_regress/t/t_class_unsup_bad.pl b/test_regress/t/t_class_unsup_bad.pl index 009248fc5..33a7f3beb 100755 --- a/test_regress/t/t_class_unsup_bad.pl +++ b/test_regress/t/t_class_unsup_bad.pl @@ -12,6 +12,7 @@ scenarios(vlt => 1); lint( fails => 1, + verilator_flags2 => ['-Wno-RANDC'], expect_filename => $Self->{golden_filename}, ); diff --git a/test_regress/t/t_randc_ignore_unsup.pl b/test_regress/t/t_randc_ignore_unsup.pl new file mode 100755 index 000000000..a161852b1 --- /dev/null +++ b/test_regress/t/t_randc_ignore_unsup.pl @@ -0,0 +1,22 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2020 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. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); + +compile( + verilator_flags2 => ['-Wno-RANDC'], + ); + +execute( + check_finished => 1, + ); + +ok(1); +1; diff --git a/test_regress/t/t_randc_ignore_unsup.v b/test_regress/t/t_randc_ignore_unsup.v new file mode 100644 index 000000000..a2087e6b0 --- /dev/null +++ b/test_regress/t/t_randc_ignore_unsup.v @@ -0,0 +1,38 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2019 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +class Cls; + randc int i; + + function new; + i = 0; + endfunction + +endclass + +module t (/*AUTOARG*/); + bit ok = 0; + + Cls obj; + + initial begin + int rand_result; + int prev_i; + for (int i = 0; i < 10; i++) begin + obj = new; + rand_result = obj.randomize(); + if (i > 0 && obj.i != prev_i) begin + ok = 1; + end + prev_i = obj.i; + end + if (ok) begin + $write("*-* All Finished *-*\n"); + $finish; + end + else $stop; + end +endmodule diff --git a/test_regress/t/t_randc_unsup.out b/test_regress/t/t_randc_unsup.out new file mode 100644 index 000000000..4ca619d14 --- /dev/null +++ b/test_regress/t/t_randc_unsup.out @@ -0,0 +1,5 @@ +%Warning-RANDC: t/t_randc_unsup.v:8:14: Unsupported: Converting 'randc' to 'rand' + 8 | randc int i; + | ^ + ... Use "/* verilator lint_off RANDC */" and lint_on around source to disable this message. +%Error: Exiting due to diff --git a/test_regress/t/t_randc_unsup.pl b/test_regress/t/t_randc_unsup.pl new file mode 100755 index 000000000..009248fc5 --- /dev/null +++ b/test_regress/t/t_randc_unsup.pl @@ -0,0 +1,19 @@ +#!/usr/bin/env perl +if (!$::Driver) { use FindBin; exec("$FindBin::Bin/bootstrap.pl", @ARGV, $0); die; } +# DESCRIPTION: Verilator: Verilog Test driver/expect definition +# +# Copyright 2020 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. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(vlt => 1); + +lint( + fails => 1, + expect_filename => $Self->{golden_filename}, + ); + +ok(1); +1; diff --git a/test_regress/t/t_randc_unsup.v b/test_regress/t/t_randc_unsup.v new file mode 100644 index 000000000..1a966261a --- /dev/null +++ b/test_regress/t/t_randc_unsup.v @@ -0,0 +1,12 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2019 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +class Cls; + randc int i; +endclass + +module t (/*AUTOARG*/); +endmodule