Fix `pre_randomize`/`post_randomize` when no randomize (#6122).
This commit is contained in:
parent
e422c183ff
commit
75229cc03d
1
Changes
1
Changes
|
@ -77,6 +77,7 @@ Verilator 5.037 devel
|
|||
* Fix DFG binToOneHot table index missing driver (#6100). [Geza Lore]
|
||||
* Fix decoding octal string escapes with 1-2 digits (#6108).
|
||||
* Fix colon-divide operator without space (#6121). [Alex Solomatnikov]
|
||||
* Fix `pre_randomize`/`post_randomize` when no randomize (#6122). [Alex Solomatnikov]
|
||||
* Fix variables declared in fork after taskify (#6126). [Kamil Rakoczy, Antmicro Ltd.]
|
||||
* Fix method calls without parenthesis (#6127). [Alex Solomatnikov]
|
||||
|
||||
|
|
|
@ -3957,6 +3957,7 @@ class LinkDotResolveVisitor final : public VNVisitor {
|
|||
// Resolved in V3Width
|
||||
} else if (nodep->name() == "randomize" || nodep->name() == "srandom"
|
||||
|| nodep->name() == "get_randstate" || nodep->name() == "set_randstate"
|
||||
|| nodep->name() == "pre_randomize" || nodep->name() == "post_randomize"
|
||||
|| nodep->name() == "rand_mode" || nodep->name() == "constraint_mode") {
|
||||
if (AstClass* const classp = VN_CAST(m_modp, Class)) {
|
||||
nodep->classOrPackagep(classp);
|
||||
|
|
|
@ -4,52 +4,72 @@
|
|||
// any use, without warranty, 2022 by Wilson Snyder.
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
`define stop $stop
|
||||
`define checkd(gotv,expv) do if ((gotv) !== (expv)) begin $write("%%Error: %s:%0d: got=%0d exp=%0d\n", `__FILE__,`__LINE__, (gotv), (expv)); `stop; end while(0);
|
||||
|
||||
typedef enum int {
|
||||
RANDOMIZED = 20
|
||||
} enumed_t;
|
||||
|
||||
class Cls;
|
||||
int pre;
|
||||
rand enumed_t r;
|
||||
int post;
|
||||
class Base;
|
||||
int m_pre;
|
||||
rand enumed_t r;
|
||||
int m_post;
|
||||
|
||||
function void pre_randomize;
|
||||
if (pre != 0) $stop;
|
||||
$display("%d", r);
|
||||
if (r != enumed_t'(0)) $stop;
|
||||
if (post != 0) $stop;
|
||||
pre = 10;
|
||||
endfunction
|
||||
function void pre_randomize;
|
||||
`checkd(m_pre, 0);
|
||||
`checkd(r, enumed_t'(0));
|
||||
`checkd(m_post, 0);
|
||||
m_pre = 10;
|
||||
endfunction
|
||||
|
||||
function void post_randomize;
|
||||
if (pre != 10) $stop;
|
||||
if (r != RANDOMIZED) $stop;
|
||||
if (post != 0) $stop;
|
||||
post = 30;
|
||||
endfunction
|
||||
function void post_randomize;
|
||||
`checkd(m_pre, 10);
|
||||
`checkd(r, RANDOMIZED);
|
||||
`checkd(m_post, 0);
|
||||
m_post = 30;
|
||||
endfunction
|
||||
endclass
|
||||
|
||||
class Cls extends Base;
|
||||
int m_cpre;
|
||||
int m_cpost;
|
||||
function void pre_randomize;
|
||||
m_cpre = 111;
|
||||
super.pre_randomize();
|
||||
endfunction
|
||||
|
||||
function void post_randomize;
|
||||
m_cpost = 222;
|
||||
super.post_randomize();
|
||||
endfunction
|
||||
endclass
|
||||
|
||||
module t (/*AUTOARG*/);
|
||||
|
||||
initial begin
|
||||
Cls c;
|
||||
int rand_result;
|
||||
initial begin
|
||||
Cls c;
|
||||
int rand_result;
|
||||
|
||||
c = new;
|
||||
rand_result = c.randomize();
|
||||
if (rand_result != 1) $stop;
|
||||
if (c.pre != 10) $stop;
|
||||
if (c.r != RANDOMIZED) $stop;
|
||||
if (c.post != 30) $stop;
|
||||
c = new;
|
||||
rand_result = c.randomize();
|
||||
`checkd(rand_result, 1);
|
||||
`checkd(c.m_pre, 10);
|
||||
`checkd(c.m_cpre, 111);
|
||||
`checkd(c.r, RANDOMIZED);
|
||||
`checkd(c.m_post, 30);
|
||||
`checkd(c.m_cpost, 222);
|
||||
|
||||
c = new;
|
||||
rand_result = c.randomize() with { r == RANDOMIZED; };
|
||||
if (rand_result != 1) $stop;
|
||||
if (c.pre != 10) $stop;
|
||||
if (c.r != RANDOMIZED) $stop;
|
||||
if (c.post != 30) $stop;
|
||||
c = new;
|
||||
rand_result = c.randomize() with { r == RANDOMIZED; };
|
||||
`checkd(rand_result, 1);
|
||||
`checkd(c.m_pre, 10);
|
||||
`checkd(c.m_cpre, 111);
|
||||
`checkd(c.r, RANDOMIZED);
|
||||
`checkd(c.m_post, 30);
|
||||
`checkd(c.m_cpost, 222);
|
||||
|
||||
$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
$write("*-* All Finished *-*\n");
|
||||
$finish;
|
||||
end
|
||||
endmodule
|
||||
|
|
|
@ -0,0 +1,16 @@
|
|||
#!/usr/bin/env python3
|
||||
# DESCRIPTION: Verilator: Verilog Test driver/expect definition
|
||||
#
|
||||
# Copyright 2025 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
|
||||
|
||||
import vltest_bootstrap
|
||||
|
||||
test.scenarios('linter')
|
||||
|
||||
test.lint()
|
||||
|
||||
test.passes()
|
|
@ -0,0 +1,22 @@
|
|||
// DESCRIPTION: Verilator: Verilog Test module
|
||||
//
|
||||
// This file ONLY is placed under the Creative Commons Public Domain, for
|
||||
// any use, without warranty, 2025 by Wilson Snyder.
|
||||
// SPDX-License-Identifier: CC0-1.0
|
||||
|
||||
package uvm_pkg;
|
||||
class uvm_sequence_item;
|
||||
endclass
|
||||
endpackage
|
||||
|
||||
package tb_cpu_pkg;
|
||||
import uvm_pkg::*;
|
||||
class tb_cpu_seq_item extends uvm_sequence_item;
|
||||
function void pre_randomize();
|
||||
super.pre_randomize();
|
||||
endfunction
|
||||
function void post_randomize();
|
||||
super.post_randomize();
|
||||
endfunction
|
||||
endclass
|
||||
endpackage
|
Loading…
Reference in New Issue