Inline constraints allows to add extra constraints to already existing constraints which are declared inside class. If you have constraints already defined for variavle var, solver solves those constraints along with the in-line constraints.
EXAMPLE: class inline;
randinteger Var;
constraint default_c { Var > 0 ; Var < 100;}
endclass
program inline_p_35;
inline obj;
initial begin obj = new();
repeat(5)
if(obj.randomize() with { Var == 50;})
$display(" Randodmize sucessful Var %d ",obj.Var);
else $display(" Randomization failes");
end endprogram
RESULTS:
# Randodmize sucessful Var 50 # Randodmize sucessful Var 50 # Randodmize sucessful Var 50 # Randodmize sucessful Var 50 # Randodmize sucessful Var 50
In the above example, by default only default_c constraints are considered. Using inline constraint Var == 50 resulted value on variable Var based on both the default_c and inline constraints.
The scope for variable names in a constraint block, from inner to outer, is randomize()...with object class, automatic and local variables, task and function arguments, class variables, and variables in the enclosing scope. The randomize()...with class is brought into scope at the innermost nesting level. In the f.randomize() with constraint block, x is a member of class Foo and hides the x in program Bar. It also hides the x argument in the doit() task. y is a member of Bar. z is a local argument.
In the example below, the randomize()...with class is Foo.
EXAMPLE: class Foo;
randinteger x;
endclass
program Bar_36;
Foo obj = new();
integer x;
integer y;
task doit(Foo f, integer x, integer z);
int result;
result = f.randomize() with {x < y + z;};
$display(":: obj.x : %d :: x : %d :: y : %d :: z : %d ::",obj.x,x,y,z);
endtask
initial begin x = 'd10;
repeat(5)
begin y = $urandom % 10;
doit(obj,x ,'d12);
end end endprogram
RESULTS:
:: obj.x : -1538701546 :: x : 10 :: y : 5 :: z : 12 :: :: obj.x : -1048494686 :: x : 10 :: y : 9 :: z : 12 :: :: obj.x : -1122673684 :: x : 10 :: y : 8 :: z : 12 :: :: obj.x : -2050360121 :: x : 10 :: y : 7 :: z : 12 :: :: obj.x : -886228933 :: x : 10 :: y : 3 :: z : 12 ::
By seeing this output we can tell the variable which used in inline constraint is class member x.
constraint { x < y + z } means { obj.x < Bar_36.y + do_it.z }