FINAL PROPOSAL, 21-JAN-2004

SVA 3.1A PROPOSAL 19:  ATTACHING SUBROUTINE CALLS TO A SEQUENCE
---------------------------------------------------------------

DISCUSSION:

Because local variables cannot be referenced in the action blocks of
3.1 assertions, the action blocks are inadequate for error reporting
or other post-evaluation processing of an assertion.  This situation
leaves open a serious hole in the usability features of the language.

It has been a goal of the 3.1a effort for some time to find a way to
access local variables from a property in its associated action
blocks.  We have been unable to find a good solution to this problem
becuase of the multiple threading in a single assertion attempt and
the fact that distinct threads evolve to acquire distinct local
variable contexts.

This proposal compensates for the inability to reference local
variables in the action blocks by allowing tasks, task methods, void
functions, void function methods, and system tasks to be called at the
end of successful match of a sequence.  The syntax is to put the
subroutine calls in the comma-separated list along with local variable
assignments.  Such a subroutine call can be passed local variables
that flow out of the match of the sequence as well as any local
variables assigned in the comma-separated list prior to the subroutine
call.  If an actual argument expression to such a subroutine call
depends on a local variable, then the argument must be passed by
value.

By encapsulating within a subroutine the code that would have been put
in the action blocks, much of the desired capability for the action
blocks is achieved on the match of the sequence.


PROPOSED CHANGES TO THE BNF:
----------------------------

Section 17-5.  Box 17-2.  Change

     sequence_expr ::=                                    // from Annex A.2.10
          cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | sequence_expr cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | expression_or_dist [ boolean_abbrev ] 
        | ( expression_or_dist {, variable_assignment } ) [ boolean_abbrev ] 
        | sequence_instance [ sequence_abbrev ] 
        | ( sequence_expr {, variable_assignment } ) [ sequence_abbrev ] 
        | sequence_expr and sequence_expr 
        | sequence_expr intersect sequence_expr 
        | sequence_expr or sequence_expr 
        | first_match ( sequence_expr ) 
        | expression throughout sequence_expr 
        | sequence_expr within sequence_expr 

   to

     sequence_expr ::=                                    // from Annex A.2.10
          cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | sequence_expr cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | expression_or_dist [ boolean_abbrev ] 
        | ( expression_or_dist {, sequence_match_item } ) [ boolean_abbrev ] 
        | sequence_instance [ sequence_abbrev ] 
        | ( sequence_expr {, sequence_match_item } ) [ sequence_abbrev ] 
        | sequence_expr and sequence_expr 
        | sequence_expr intersect sequence_expr 
        | sequence_expr or sequence_expr 
        | first_match ( sequence_expr ) 
        | expression throughout sequence_expr 
        | sequence_expr within sequence_expr 

     sequence_match_item ::=
          variable_assignment
        | subroutine_call
        

Section 17.7.2.  Box 17-5.  Change


     sequence_expr ::=                                    // from Annex A.2.10
        ...
        | expression_or_dist [ boolean_abbrev ] 
        | ( expression_or_dist {, variable_assignment } ) [ boolean_abbrev ] 
        | sequence_instance [ sequence_abbrev ] 
        | ( sequence_expr {, variable_assignment } ) [ sequence_abbrev ] 
        ...

   to

     sequence_expr ::=                                    // from Annex A.2.10
        ...
        | expression_or_dist [ boolean_abbrev ] 
        | ( expression_or_dist {, sequence_match_item } ) [ boolean_abbrev ] 
        | sequence_instance [ sequence_abbrev ] 
        | ( sequence_expr { , sequence_match_item } ) [ sequence_abbrev ] 
        ...

Section 17.8.  Box 17-13.  Change


     sequence_expr ::=                                    // from Annex A.2.10
        ...
        | ( expression_or_dist { , variable_assignment } ) [ boolean_abbrev ] 
        | ( sequence_expr {, variable_assignment } ) [ sequence_abbrev ] 

   to

     sequence_expr ::=                                    // from Annex A.2.10
        ...
        | ( expression_or_dist {, sequence_match_item } ) [ boolean_abbrev ] 
        | ( sequence_expr { , sequence_match_item } ) [ sequence_abbrev ] 
        ...

Annex A.  Change

     sequence_expr ::=                                    // from Annex A.2.10
          cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | sequence_expr cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | expression_or_dist [ boolean_abbrev ] 
        | ( expression_or_dist {, variable_assignment } ) [ boolean_abbrev ] 
        | sequence_instance [ sequence_abbrev ] 
        | ( sequence_expr {, variable_assignment } ) [ sequence_abbrev ] 
        | sequence_expr and sequence_expr 
        | sequence_expr intersect sequence_expr 
        | sequence_expr or sequence_expr 
        | first_match ( sequence_expr ) 
        | expression throughout sequence_expr 
        | sequence_expr within sequence_expr 

   to

     sequence_expr ::=                                    // from Annex A.2.10
          cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | sequence_expr cycle_delay_range sequence_expr { cycle_delay_range sequence_expr } 
        | expression_or_dist [ boolean_abbrev ] 
        | ( expression_or_dist {, sequence_match_item } ) [ boolean_abbrev ] 
        | sequence_instance [ sequence_abbrev ] 
        | ( sequence_expr {, sequence_match_item } ) [ sequence_abbrev ] 
        | sequence_expr and sequence_expr 
        | sequence_expr intersect sequence_expr 
        | sequence_expr or sequence_expr 
        | first_match ( sequence_expr ) 
        | expression throughout sequence_expr 
        | sequence_expr within sequence_expr 

     sequence_match_item ::=
          variable_assignment
        | subroutine_call


PROPOSED CHANGES TO THE LRM TEXT:
---------------------------------

Add the following section between sections 17.8 and 17.9.
Sections 17.9 and later therefore also need to be renumbered.

17.?  Calling subroutines on match of a sequence

Tasks, task methods, void functions, void function methods, and system
tasks can be called at the end of successful match of a sequence.  The
subroutine calls, like local variable assignments, appear in the
comma-separated list that follows the sequence.  The subroutine calls
are said to be _attached_ to the sequence.  The sequence and the list
that follows are enclosed in parentheses.


[begin syntax box]

     sequence_expr ::=                                    // from Annex A.2.10
        ...
        | ( expression_or_dist {, sequence_match_item } ) [ boolean_abbrev ] 
        | ( sequence_expr { , sequence_match_item } ) [ sequence_abbrev ] 
        ...

     sequence_match_item ::=
          variable_assignment
        | subroutine_call

[end syntax box]


For example, 

   sequence s1;
      logic v, w;
      (a, v = e) ##1 
      (b[*->1], w = f, $display("b after a with v = %h, w = %h\n", v, w));
   endsequence

defines a sequence s1 that matches at the first occurrence of b
strictly after an occurrence of a.  At the match, the system task
$display is executed to write a message that announces the match and
shows the values assigned to the local variables v and w.

All subroutine calls attached to a sequence are executed at every
successful match of the sequence.  For each successful match, the
attached calls are executed in the order they appear in the list.  The
subroutines are scheduled in the Reactive region, like an action
block.

Each argument of a subroutine call attached to a sequence must either
be passed by value as an input or be passed by reference (either ref
or const ref; see Section 10.4.2).  Actual argument expressions that
are passed by value use sampled values of the underlying variables and
are consistent with the variable values used to evaluate the sequence
match.

Local variables can be passed into subroutine calls attached to a
sequence.  Any local variable that flows out of the sequence or that
is assigned in the list following the sequence, but before the
subroutine call, can be used in an actual argument expression for the
call.  If a local variable appears in an actual argument expression,
then that argument must be passed by value.


PROPOSED CHANGES TO THE FORMAL SEMANTICS:
-----------------------------------------

None.  The subroutine calls do not affect the formal semantics
of the sequence.
