Skip to content

Commit

Permalink
Fix rand fields of reference types (verilator#4627)
Browse files Browse the repository at this point in the history
  • Loading branch information
RRozak authored Oct 26, 2023
1 parent 9825263 commit 64af831
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
5 changes: 3 additions & 2 deletions src/V3Randomize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ class RandomizeMarkVisitor final : public VNVisitorConst {
for (auto* memberp = classp->stmtsp(); memberp; memberp = memberp->nextp()) {
// If member is rand and of class type, mark its class
if (VN_IS(memberp, Var) && VN_AS(memberp, Var)->isRand()) {
if (const auto* const classRefp = VN_CAST(memberp->dtypep(), ClassRefDType)) {
if (const auto* const classRefp
= VN_CAST(memberp->dtypep()->skipRefp(), ClassRefDType)) {
auto* const rclassp = classRefp->classp();
if (!rclassp->user1()) {
rclassp->user1(true);
Expand Down Expand Up @@ -100,7 +101,7 @@ class RandomizeMarkVisitor final : public VNVisitorConst {
iterateChildrenConst(nodep);
if (nodep->name() != "randomize") return;
if (const AstClassRefDType* const classRefp
= VN_CAST(nodep->fromp()->dtypep(), ClassRefDType)) {
= VN_CAST(nodep->fromp()->dtypep()->skipRefp(), ClassRefDType)) {
AstClass* const classp = classRefp->classp();
classp->user1(true);
markMembers(classp);
Expand Down
16 changes: 16 additions & 0 deletions test_regress/t/t_randomize_method.v
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,19 @@ class DeriveAndContainClsWithInt extends ClsWithInt;
endfunction
endclass

class ClsUsedOnlyHere;
rand int a;
endclass

typedef ClsUsedOnlyHere cls_used_only_here_t;

class ClsContainUsedOnlyHere;
rand cls_used_only_here_t c;
function new;
c = new;
endfunction
endclass

module t (/*AUTOARG*/);

DerivedCls derived;
Expand All @@ -121,6 +134,7 @@ module t (/*AUTOARG*/);
ContainsNull cont;
DeriveClsWithInt der_int;
DeriveAndContainClsWithInt der_contain;
ClsContainUsedOnlyHere cls_cont_used;

initial begin
int rand_result;
Expand All @@ -130,6 +144,7 @@ module t (/*AUTOARG*/);
der_int = new;
der_contain = new;
base = derived;
cls_cont_used = new;
for (int i = 0; i < 10; i++) begin
rand_result = base.randomize();
rand_result = other.randomize();
Expand Down Expand Up @@ -166,6 +181,7 @@ module t (/*AUTOARG*/);
`check_rand(der_int, der_int.a);
`check_rand(der_contain, der_contain.cls1.a);
`check_rand(der_contain, der_contain.a);
`check_rand(cls_cont_used, cls_cont_used.c.a);

$write("*-* All Finished *-*\n");
$finish;
Expand Down
20 changes: 15 additions & 5 deletions test_regress/t/t_uvm_pkg_todo.vh
Original file line number Diff line number Diff line change
Expand Up @@ -21074,15 +21074,21 @@ typedef class uvm_tlm_extension_base;
class uvm_tlm_generic_payload extends uvm_sequence_item;
rand bit [63:0] m_address;
rand uvm_tlm_command_e m_command;
rand byte unsigned m_data[];
//TODO issue-4625 - Rand fields of dynamic array types
//TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'byte[]'
/*TODO rand*/ byte unsigned m_data[];
rand int unsigned m_length;
rand uvm_tlm_response_status_e m_response_status;
bit m_dmi;
rand byte unsigned m_byte_enable[];
//TODO issue-4625 - Rand fields of dynamic array types
//TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'byte[]'
/*TODO rand*/ byte unsigned m_byte_enable[];
rand int unsigned m_byte_enable_length;
rand int unsigned m_streaming_width;
protected uvm_tlm_extension_base m_extensions [uvm_tlm_extension_base];
local rand uvm_tlm_extension_base m_rand_exts[];
//TODO issue-4625 - Rand fields of dynamic array types
//TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'CLASSREFDTYPE 'uvm_tlm_extension_base'[]'
local /*rand*/ uvm_tlm_extension_base m_rand_exts[];
typedef uvm_object_registry#(uvm_tlm_generic_payload,"uvm_tlm_generic_payload") type_id;
static function uvm_tlm_generic_payload type_id_create (string name="",
uvm_component parent=null,
Expand Down Expand Up @@ -22446,7 +22452,9 @@ class uvm_reg_item extends uvm_sequence_item;
uvm_elem_kind_e element_kind;
uvm_object element;
rand uvm_access_e kind;
rand uvm_reg_data_t value[];
//TODO issue-4625 - Rand fields of dynamic array types
//TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'bit[]'
/*rand*/ uvm_reg_data_t value[];
constraint max_values { value.size() > 0 && value.size() < 1000; }
rand uvm_reg_addr_t offset;
uvm_status_e status;
Expand Down Expand Up @@ -26866,7 +26874,9 @@ class uvm_reg_fifo extends uvm_reg;
local uvm_reg_field value;
local int m_set_cnt;
local int unsigned m_size;
rand uvm_reg_data_t fifo[$];
//TODO issue-4625 - Rand fields of dynamic array types
//TODO %Error-UNSUPPORTED: t/t_uvm_pkg_todo.vh:21081:35: Unsupported: random member variable with type 'bit[$]'
/*rand*/ uvm_reg_data_t fifo[$];
constraint valid_fifo_size {
fifo.size() <= m_size;
}
Expand Down

0 comments on commit 64af831

Please sign in to comment.