diff --git a/src/verilog.y b/src/verilog.y index 5ce0b5135..55631624e 100644 --- a/src/verilog.y +++ b/src/verilog.y @@ -3433,7 +3433,8 @@ system_f_call_or_t: // IEEE: part of system_tf_call (can be task or func) | yD_PAST '(' expr ',' expr ',' expr ')' { $1->v3error("Unsupported: $past expr2 and clock arguments"); $$ = $3; } | yD_PAST '(' expr ',' expr ',' expr ',' expr')' { $1->v3error("Unsupported: $past expr2 and clock arguments"); $$ = $3; } | yD_POW '(' expr ',' expr ')' { $$ = new AstPowD($1,$3,$5); } - | yD_RANDOM '(' expr ')' { $$ = NULL; $1->v3error("Unsupported: Seeding $random doesn't map to C++, use $c(\"srand\")"); } + // // Seeding is unsupported as would be slow to invalidate all per-thread RNGs + | yD_RANDOM '(' expr ')' { $$ = new AstRand($1); $1->v3error("Unsupported: Seed on $random. Suggest use +verilator+seed+ runtime flag"); } | yD_RANDOM parenE { $$ = new AstRand($1); } | yD_REALTIME parenE { $$ = new AstTimeD($1, VTimescale(VTimescale::NONE)); } | yD_REALTOBITS '(' expr ')' { $$ = new AstRealToBits($1,$3); } diff --git a/test_regress/t/t_sys_rand_seed.out b/test_regress/t/t_sys_rand_seed.out new file mode 100644 index 000000000..26738d308 --- /dev/null +++ b/test_regress/t/t_sys_rand_seed.out @@ -0,0 +1,7 @@ +%Error: t/t_sys_rand_seed.v:13:16: Unsupported: Seed on $random. Suggest use +verilator+seed+ runtime flag + 13 | valuea = $random(10); + | ^~~~~~~ +%Error: t/t_sys_rand_seed.v:14:16: Unsupported: Seed on $random. Suggest use +verilator+seed+ runtime flag + 14 | valueb = $random(10); + | ^~~~~~~ +%Error: Exiting due to diff --git a/test_regress/t/t_sys_rand_seed.pl b/test_regress/t/t_sys_rand_seed.pl new file mode 100755 index 000000000..391ec23fd --- /dev/null +++ b/test_regress/t/t_sys_rand_seed.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 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. +# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0 + +scenarios(simulator => 1); + +compile( + fails => $Self->{vlt_all}, + expect_filename => $Self->{golden_filename}, + ); + +execute( + ) if !$Self->{vlt_all}; + +ok(1); +1; diff --git a/test_regress/t/t_sys_rand_seed.v b/test_regress/t/t_sys_rand_seed.v new file mode 100644 index 000000000..2780345a3 --- /dev/null +++ b/test_regress/t/t_sys_rand_seed.v @@ -0,0 +1,19 @@ +// DESCRIPTION: Verilator: Verilog Test module +// +// This file ONLY is placed under the Creative Commons Public Domain, for +// any use, without warranty, 2020 by Wilson Snyder. +// SPDX-License-Identifier: CC0-1.0 + +module t; + + int valuea; + int valueb; + + initial begin + valuea = $random(10); + valueb = $random(10); + if (valuea !== valueb) $stop; + $write("*-* All Finished *-*\n"); + $finish; + end +endmodule