All: I have revised the proposal for mantis 1668 (local variable initializers) based on comments received off the reflector. I have put the updated proposal on mantis and attached it. J.H. -- This message has been scanned for viruses and dangerous content by MailScanner, and is believed to be clean.
Proposal for Mantis 1668: Local Variable Initializers
The goal of this proposal is to allow an initialization assignment to be written as part of the declaration of a local variable in either a sequence or a property declaration. The intended semantics is that declaration assignments be performed in order at the beginning of each evaluation attempt of an instance of the named sequence or property. The exception occurs when the evaluation attempt completes on the empty word, as in an empty match of a sequence, in which case the declaration assignments are understood not to be performed.
In the proposed Syntax 17-13, the subroutine_call option for sequence_match_item is replaced by an ellipsis because that feature is not discussed in this section.
This proposal clarifies, in alignment with Mantis 1704, that
a local variable assignment cannot be attached to a sequence that admits an
empty match.
The description of the declaration assignments involves expansion of the initial description of local variables. Parts of the text of 17.8 have been rewritten and expanded to improve clarity. For example, there was before no clear description of when a local variable can be referenced and the relationship between a local variable’s “not flowing” and its “becoming unassigned”.
17.8, p. 259: REPLACE
The dynamic creation of a variable and its assignment is achieved by using the local variable declaration in a sequence or property declaration and making an assignment in the sequence.
[
sequence_expr ::=
...
| ( expression_or_dist {, sequence_match_item } ) [ boolean_abbrev ]
| ( sequence_expr {, sequence_match_item} ) [ sequence_abbrev ]
...
sequence_match_item ::=
operator_assignment
| inc_or_dec_expression
| subroutine_call
]
Syntax 17-12 -- Variable assignment syntax (excerpt from Annex A)
The type of variable is explicitly specified. The variable can be assigned at the end point of any syntactic subsequence by placing the subsequence, comma separated from the sampling assignment, in parentheses. For example, if in
a ##1
b[->1] ##1 c[*2]
it is desired to assign x = e at the match of b[->1], the sequence can be rewritten as
a
##1 (b[->1], x = e) ##1 c[*2]
The local variable can be reassigned later in the sequence, as in
a
##1 (b[->1], x = e) ##1 (c[*2], x = x + 1)
For every attempt, a new copy of the variable is created for the sequence. The variable value can be tested like any other SystemVerilog variable.
Hierarchical references to a local variable are not allowed.
WITH
The dynamic creation of a local variable is achieved by using an assertion variable declaration within the declaration of a named sequence or property (see 17.11).
[
assertion_variable_declaration ::=
var_data_type list_of_variable_decl_assignments ;
]
Syntax 17-12 -- Assertion variable declaration syntax (excerpt from Annex A)
The data type of an assertion variable declaration shall be specified explicitly. The data type is followed by a comma-separated list of one or more identifiers with optional declaration assignments. If present, a declaration assignment is used to place an initial value in the corresponding local variable. The initial value is defined by an expression, which need not be constant.
At the beginning of each evaluation attempt of an instance of a named sequence or property, a new copy of each of its local variables is created and, if present, the corresponding declaration assignment is performed. The exception is that no local variables are created and no declaration assignments are performed for an evaluation attempt that completes on the empty word, such as an empty match of a sequence instance. Declaration assignments are performed in the order that they appear in the sequence or property declaration. The expression of a declaration assignment to a local variable can refer to a previously declared local variable, but in this case the previously declared local variable must itself have a declaration assignment. Local variables do not have default initial values. A local variable without a declaration assignment is unassigned at the beginning of the evaluation attempt.
For example, at the beginning of an evaluation attempt of an instance of
sequence s;
logic u, v = a, w = v || b;
...
endsequence
the assignment of a to v is performed first and the assignment of v || b to w is performed second. The local variable u is unassigned at the beginning of the evaluation attempt.
Local variables can be assigned and re-assigned within the body of the sequence or property in which they are declared.
[
sequence_expr ::=
...
| ( expression_or_dist {, sequence_match_item } ) [ boolean_abbrev ]
| ( sequence_expr {, sequence_match_item} ) [ sequence_abbrev ]
...
sequence_match_item ::=
operator_assignment
| inc_or_dec_expression
…
| subroutine_call
]
Syntax 17-13 -- Variable assignment syntax (excerpt from Annex A)
[Note to
editor: all subsequent syntax box
numbers in Section 17 must be adjusted.]
One or more local variables can be assigned at the end point of a syntactic subsequence by placing the subsequence, comma separated from the list of local variable assignments, in parentheses. At the end of any non-empty match of the subsequence, the local variable assignments are performed in the order that they appear in the list. For example, if in
a
##1 b[->1] ##1 c[*2]
it is desired to assign x = e and then y = x && f at the match of b[->1], the sequence can be rewritten as
a
##1 (b[->1], x = e, y = x && f) ##1 c[*2]
A local variable can be reassigned later in the sequence, as in
a ##1 (b[->1], x = e, y = x &&
f) ##1 (c[*2], x &= g)
The subsequence to which a local variable assignment is attached must not admit an empty match. For example, the sequence
a ##1 (b[*0:1], x = e) ##1 c[*2] // illegal
is illegal because the subsequence b[*0:1] can match the empty word. The sequence
(a ##1 b[*0:1], x = e) ##1 c[*2] // legal
is legal because the concatenated subsequence a ##1 b[*0:1] cannot match the empty word.
A local variable can be referenced within the sequence or property in which it is declared. The structure of the sequence or property must guarantee that the local variable has been assigned a value prior to the point at which the reference is made. The prior assignment can be a declaration assignment or an assignment attached to a subsequence. There is an implicit reference associated with the use of an inc_or_dec_operator or an assignment operator other than “=”. Therefore, a local variable must have been assigned a value prior to being updated with an inc_or_dec_operator or with an assignment operator other than “=”.
Under certain circumstances, a local variable that is assigned can later become unassigned. If a local variable does not flow out of a subsequence (see below), then the local variable is unassigned at the end of that subsequence, regardless of whether it was assigned a value prior to that point. The local variable cannot be referenced after the point from which it does not flow until after it has again been assigned a value. See Annex E for precise conditions defining local variable flow.
Hierarchical references to a local variable are not allowed.
Section 17.8, p.
260. REPLACE
Local variables can be written on repeated sequences and accomplish accumulation of values.
sequence rep_v;
int
x;
`true,x
= 0 ##0
(!a [*0:$] ##1 a, x = x+data)[*4] ##1 b
##1 c && (data_out == x);
endsequence
WITH
Local variable assignments can be attached to the operand sequence of a repetition and accomplish accumulation of values.
sequence rep_v;
int
x = 0;
(a[->1], x += data)[*4] ##1 b ##1 c && (data_out == x);
endsequence
An accumulating local variable can be used to count the number of times a condition is repeated, as in the following example:
sequence count_a_cycles;
int
x;
($rose(a), x = 1)
##1 (a, x++)[*0:$] ##1 $fell(a) && (x <=
MAX);
endsequence
RATIONALE: The original rep_v example showed how to work around lack of local variable declaration assignments and is awkward with the feature added. Also, the idiom !a[*0:$] ##1 a is more compactly written as a[->1]. The second example shows a useful idiom and illustrates the use of an inc_or_dec_expression to update a local variable.
Section 17.8, p.
260. REPLACE
The local variables declared in one sequence are not visible in the sequence where it gets instantiated.
WITH
The local variables declared within a sequence or property are not visible in the context where the sequence or property is instantiated.
RATIONALE: The beginning of the proposal discusses local variables for both sequences and properties.
Section 17.8, p. 262. CHANGE
If these conditions are satisfied, then the local variable is said to flow out of the composite sequence. An intuitive description of the conditions for local variable flow follows:
TO
If these conditions are satisfied, then the local variable is said to flow out of the composite sequence. Otherwise, the local variable is unassigned at the end of the composite sequence. An intuitive description of the conditions for local variable flow follows:
RATIONALE: To complete the correlation of the concepts of “not flowing” and “becoming unassigned”.
Syntax 17-4, p.
240. CHANGE
assertion_variable_declaration ::=
var_data_type list_of_variable_identifiers ;
TO
assertion_variable_declaration ::=
var_data_type
list_of_variable_identifiers
list_of_variable_decl_assignments ;
Syntax 17-14, p. 265. CHANGE
assertion_variable_declaration ::=
var_data_type list_of_variable_identifiers ;
TO
assertion_variable_declaration ::=
var_data_type
list_of_variable_identifiers
list_of_variable_decl_assignments ;
A.2.10, p. 526. CHANGE
assertion_variable_declaration ::=
var_data_type list_of_variable_identifiers ;
TO
assertion_variable_declaration ::=
var_data_type
list_of_variable_identifiers
list_of_variable_decl_assignments ;
This archive was generated by hypermail 2.1.8 : Sun Feb 18 2007 - 08:59:02 PST