Assume that I have a class include three properties as follows:
rand bit [3:0] A [][];
rand byte num_src[];
rand byte num_users;
Size of num_src and first-dimensional size of A is num_users. Second-dimensional size of each A[i] is num_src[i]. All this means A is an irregular dynamic array with sizes dependent on num_src[i] values.
Here is my full code:
class test_class;
rand bit [3:0] A [][];
rand byte num_src[];
rand byte num_users;
constraint c_1 { num_users>3; num_users<5; }
constraint c_4 {num_src.size==num_users;
foreach (num_src[i]) num_src[i]==i+2;
}
constraint o2 {solve num_users before num_src; solve num_src before A; solve num_users before A;}
constraint c_3 {A.size==num_users;
A[0].size()==num_src[0];
foreach (A[i,j]) A[i][j]==i+j;
}
function void pre_randomize;
A = new[10];
foreach (A[i]) A[i]=new[10];
endfunction
endclass
module testtop();
test_class Ac;
initial begin
#0;
Ac = new();
if (!Ac.randomize()) $error("randomize fail"); else $display("A = %p, num_src = %p, num_users = %p",Ac.A,Ac.num_src, Ac.num_users);
#100;
end
/*reg [250*8-1:0] wave_file;
string LOG_DIR;
initial begin
if(!$value$plusargs("LOG_DIR=%0s",LOG_DIR)) begin
$display("Warning: Cannot get LOG_DIR");
end
fork
begin
$swrite(wave_file,"%0s/wave.shm", LOG_DIR);
$shm_open(wave_file,0,,1);
$shm_probe(testtop,"ASCMTF");
#(4000*1ns);
$shm_close;
end
join_none
end*/
endmodule
When I compile the code assembling these, I got this error:
ncsim> run
if (!Ac.randomize()) $error(“randomize fail”); else $display(“A = %p, num_src = %p, num_users = %p”,Ac.A,Ac.num_src, Ac.num_users);
|
ncsim: *W,SVRNDF (…/sv/testtop.sv,32|20): The randomize method call failed.
Observed simulation time : 0 FS + 1
ncsim: *W,RNDOCS: These constraints contribute to the set of conflicting constraints:
A[0].size()==num_src[0]; (../sv/testtop.sv,15)
foreach (num_src[i]) num_src[i]==i+2; (../sv/testtop.sv,11)
ncsim: *W,RNDOCS: These variables contribute to the set of conflicting constraints:
rand variables:
num_src[4] […/sv/testtop.sv, 6]
I have no idea while there are conflicts so I appreciate help from anyone who knows this issue.