I want to write a constraint to make sure r_addr is only allowed when the same address has been used as w_addr before, but the following constraint doesn't work. Do you have any suggestion?
class try;
rand int w_addr;
rand int r_addr;
int ua[$];
int aa[int];
constraint unique_addr_c{
aa.size() == 0 || aa.exists(r_addr);
}
endclass
module test;
try a;
initial begin
a=new;
repeat(20) begin
if(a.randomize);
$display("add=%0d", a.w_addr);
$display("add=%0d", a.r_addr);
a.ua.push_back(a.w_addr);
a.aa[a.w_addr] = 1;
end
end
endmodule