In reply to dave_59:
In reply to MarshallX:
Please use code tags making your code easier to read. I have added them for you.
You have not connected through any constraint of reg_address to any value in reg_address_array.
The dist construct is not a hard constraint that a value in the set of ranges appear, only that values not in the ranges do not appear.
Maybe this helps
class base_b1;
rand bit [31:0] reg_address_array[$];
constraint b1_c {
foreach (reg_address_array[i])
reg_address_array[i] dist {5:/25, 10:/25, [25:50]:/50};
reg_address_array.or() with (item==25); // 25 must appear at least once
reg_address_array.or() with (item==50); // 50 must appear at least once
}
constraint size_c2 {
reg_address_array.size inside {[9:10]};
}
endclass: base_b1
//-----------------------------------------------
//--------------- Inheritence Examples ----------
//-----------------------------------------------
class base_b1;
rand bit [31:0] reg_address_array[$];
constraint size_c2 {
reg_address_array.size inside {[9:10]};
}
constraint address_c1 {
foreach (reg_address_array[i])
reg_address_array[i] dist {5:/25, 10:/25, [25:30]:/50};
reg_address_array.or() with (item == 05);
reg_address_array.or() with (item == 10);
}
virtual function display_var();
for (int i=0; i<reg_address_array.size(); i++) begin
$display("This is base class !! and reg_address is %0d", reg_address_array[i]);
end
endfunction: display_var
endclass: base_b1
//----------------------------------
//------------ module top ----------
//----------------------------------
module tb_top;
//------------------------------------------------------
//--- handle declaration must be outside "initial begin"
//------------------------------------------------------
base_b1 h_b1;
initial begin
$display("This is module top !!");
h_b1 = new();
assert(h_b1.randomize());
h_b1.display_var();
end
endmodule
Thanks much dave, the code is working, but have a question why (.or) operation used? The (dist) operator is generating the required values.