User guide

24-48
SystemVerilog Testbench Constructs
rand A a1;
rand E e1;
extern function f1();
constraint c;
endclass
//out of class body method declared with the help of ::
//operator
function C::f1();
int i;
$display("Accessing enum label in constraint block
through :: operator");
repeat (5)
begin
i = this.randomize();
if(i)
$display("e1 = %s", this.e1.name);
else
$display("Randomization Failed");
end
// accessing enum label through :: operator in out
// of class body method
$display("Accessing enum label in function block
through :: operator");
i = this.randomize with {e1 != C::S2;};
if(i)
$display("e1 = %s", this.e1.name);
else
$display("Randomization Failed");
endfunction
// out of block constraint declaration accessing enum label
// through :: operator
constraint C::c { a1 == X; e1 inside {C::S1,C::S2,C::S3}; }
C c1 = new; // creating object of class C
initial begin
c1.f1();