In reply to dave_59:
Thank you Dave! Knowing this way of using array method makes me feel a little wiser !!
I did slight modification to first 2 conditions and here is the complete code that generates expected output.
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< 18 && list[i] == ADD) {
list[i+1] != ADD;
list[i+2] != ADD;
}
else
if (i< 19 && list[i] == ADD) {
list[i+1] != ADD;
}
if (i< 17 && list[i] == MUL) {
list[i+1] != MUL;
list[i+2] != MUL;
list[i+3] != MUL;
} else
if (i< 18 && list[i] == MUL) {
list[i+1] != MUL;
list[i+2] != MUL;
} else
if (i< 19 && list[i] == MUL) {
list[i+1] != MUL;
}
foreach (list[j])
if(i<j && list[i]==SUB && list[j]==SUB)
list.sum() with (int'(item.index inside {[i+1:j-1]} && item != NOP)) >= 3;
}
}
endclass
A a_h;
initial begin
repeat (10) begin
a_h = new();
assert(a_h.randomize() );
$display("***************************** list = %0p ****************************************", a_h.list);
end
end
endmodule