In reply to vickydhudashia:
It would help if you actually did use an enumerated type to begin with. It would make your code much easier to read. Another piece of advice: do not use queues unless you plan to push/pop elements, they are not as efficient as dynamic arrays.
It’s hard to know from your question how programmable the constraints needs to be. There is always the brute force hardcoded constraint.
module top;
typedef enum { ADD=1,MUL,SUB,NOP} instruction_e;
class A;
rand instruction_e list[] = new[20];
constraint q_c {
foreach (list[i]) {
if (i< 17 && list[i] == ADD) {
list[i+1] != ADD;
list[i+2] != ADD;
}
if (i< 16 && list[i] == MUL) {
list[i+1] != MUL;
list[i+2] != MUL;
list[i+3] != MUL;
}
}
(list[17]!=SUB || list[18]!=SUB) &&
(list[18]!=SUB || list[19]!=SUB) &&
(list[17]!=SUB || list[19]!=SUB);
}
endclass
A a_h;
initial begin
repeat (5) begin
a_h = new();
assert(a_h.randomize());
$display("***************************** list = %0p ****************************************", a_h.list);
end
end
endmodule