I was trying following code:
sequence s1;
int x;
( (a ##1 b, x = data) or ( d ##1 e ) ) ##1 (data1 == x + 1); // local variable 'x' assigned in only 1 sequence
endsequence
ap1:assert property( @(posedge clk) s1);
I observe following compilation:: Error: Local variable x referenced in expression where it does not flow.
Logically the error makes sense. Eg: when sequence ( d ## 1 e ) is true , ‘x’ is essentially uninitialized.
One of the solution is to assign local variable in both sequences of the ‘or’ operator.
sequence s2;
int x;
( (a ##1b, x = data) or ( d ##1e, x = data) ) ##1 (data1 == x + 1);
endsequence
ap2:assert property( @(posedge clk) s2);
However, when I use ‘and’ operator the following is legal:
sequence s3;
int x;
( (a ##1 b, x = data) and (d ##1 e) ) ##1 (data1 == x + 1); // local variable 'x' assigned in only 1 sequence
endsequence
ap3:assert property( @(posedge clk) s3);
and the following is illegal:
sequence s4;
int x;
( (a ##1 b, x = data) and (d ##1 e, x = data) ) ##1 (data1 == x + 1); // local variable 'x' assigned in both sequence
endsequence
ap4:assert property( @(posedge clk) s4);
**** Error: Local variable x referenced in expression where it does not flow.**
I am not clear on the following
- Why is sequence s4 considered illegal ? What could the logical reason behind it be ?
- Why is sequence s3 considered legal ( unlike sequence s1 ) ? When sequence ( d ## 1 e ) is true , won’t ‘x’ be unassigned ?
EDIT: The error with s1 exists only when local variable ‘x’ is used once after 'or’ed sequence
sequence s1;
int x;
( (a ##1 b, x = data) or ( d ##1 e ) ) ##1 1; // No error although 'x' is assigned in only 1 sequence
endsequence