Hello,
I used a helper array to get(randomize) the skittle array that is of enum type (since constraints work on integral expressions). But I still see an error:
typedef enum {A, B, C, D}skittles_e;
class Example;
skittles_e skittle[10];
rand bit[3:0] skittle_int[10];
constraint c1{skittle_int dist {1:=20, 2:=20, 3:=10, 4:=50};}
constraint c2{foreach (skittle_int[i]) {
skittle_int[i] inside {1, 2, 3, 4};
}};
function void post_randomize();
foreach(skittle_int[i]) begin
if(skittle_int[i] == 1) skittle[i] = A;
if(skittle_int[i] == 2) skittle[i] = B;
if(skittle_int[i] == 3) skittle[i] = C;
if(skittle_int[i] == 4) skittle[i] = D;
end
$display("skittle = %p", skittle);
endfunction
endclass
module TB;
Example E;
initial begin
E = new();
repeat(2)
assert(E.randomize());
end
endmodule
Error:
The variable skittle_int is not an integral type.
Change the type of the variable or remove it from the constraint expression.
Any idea what am I missing here? Thanks!