Hi ,
I was trying to understand working of const’() cast.
LRM 6.24.1 mentions
An expression may be changed to a constant with a const cast.
const'(x)
Consider the following code :
class C;
rand bit[2:0] a ;
function void pre_randomize();
// 'a' could be assigned here
endfunction
constraint CONST { a == const'(a) + 1 ; }
function void post_randomize();
// 'a' could be assigned here
endfunction
endclass
C c1;
module test;
initial begin
c1 = new();
repeat(5) begin
if( c1.randomize() )
$display("Success with %p",c1);
else $display("Fails");
// c1.a could also be assigned here prior to call randomize() again
end
end
endmodule
Consider following 3 cases where variable ‘a’ is assigned.
- Via pre_randomize()
- Via post_randomize()
- Via assignment to variable ‘a’ after randomize() call i.e assignment is done after post_randomize()
When we mention const’(a) which value of a should it pick ? Is it just before the constraints are solved i,e value assigned in pre_randomize() ?
There could be any possible combination of 1,2,3 i.e all 3 exist or only 1 and 2 exist or 1 and 3 exist , etc