[sv-ac] proposal for mantis 1668 (finally)

From: John Havlicek <john.havlicek_at_.....>
Date: Mon Feb 12 2007 - 18:33:39 PST
All:

I have uploaded (and attached for convenience) a proposal
for mantis 1668:  local variable initializers.

Please review it and send comments.

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

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.

 

 

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.  A local variable without a declaration assignment remains 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 remains 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]

 

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]

 

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.  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 variables can be written on repeated sequences and accomplish accumulation of values.

 

sequence rep_v;

   int x = 0;

   (a[->1], x += data)[*4] ##1 b ##1 c && (data_out == x);

endsequence

 

RATIONALE:  This example shows 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].

 

 

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.

 

 

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 ;

 

Received on Mon Feb 12 18:34:27 2007

This archive was generated by hypermail 2.1.8 : Mon Feb 12 2007 - 18:35:00 PST