I would like to constraint state read and write as shown in this example. { read, write => read} and { read => read => read => read => write}; I get a compile error on EDA Playground.
As Dave pointed out, the initial code you posted is incomplete and insufficient.
I would approach this problem as below :
Start with the enum as a typedef.
Use this typedef-ed enum to define an array/queue of states.
Use a constraint on this array/queue of states.
// Code your testbench here
// or browse Examples
class foo;
typedef enum { read, write } states;
rand states states_da[];
function new(int number_of_states);
states_da = new[number_of_states];
endfunction
constraint c1 {
foreach(states_da[i]) {
if(i >= 2) {
(states_da[i-2]==read && states_da[i-1]==write) -> (states_da[i] == read);
}
}
foreach(states_da[i]) {
if(i >= 4) {
(states_da[i-4]==read && states_da[i-3]==read && states_da[i-2]==read && states_da[i-1]==read) -> (states_da[i] == write);
}
}
}
endclass
module top;
foo i_foo;
initial begin
i_foo =new(20);
i_foo.randomize();
$display("%p",i_foo.states_da);
end
endmodule
You get the idea. You can add more constraints as needed. You can also move the size of array inside the class, and randomize that as well, to suit your needs.