Mantis 1602

P1800-2008/D3a, 13.5.3

Clarify subroutine inout argument behavior with defaults,

Allow output argument defaults.

In Section 13.5.3

CHANGE

The syntax to declare a default argument in a subroutine is as follows:

subroutine( [ direction ] [ type ] argument = default_value );

 

The optional direction can be input, inout, or ref (output ports cannot specify defaults).

 

The default_value is an expression. The expression is evaluated in the scope containing the subroutine

declaration each time a call using the default is made. If the default_value is not used, the expression is

not evaluated. The use of default values shall only be allowed with the ANSI style declarations.

 

When the subroutine is called, arguments with default values can be omitted from the call, and the compiler

shall insert their corresponding values. Unspecified (or empty) arguments can be used as placeholders for

default arguments, allowing the use of nonconsecutive default arguments. If an unspecified argument is used

for an argument that does not have a default value, a compiler error shall be issued.

 

...

 

read( ); // error; k has no default value

 

 

TO

 

 

The syntax to declare a default argument in a subroutine is as follows:

subroutine( [ direction ] [ type ] argument = default_valueexpression );

 

The optional direction can be input, inout, output, or ref (output ports cannot specify defaults).

 

The default_value is an expression. The expression default_expression is evaluated in the scope containing the subroutine declaration each time a call using the default is made. If the default_value is not used, the expression is not evaluated. If the default is not used, the default expression is not evaluated. The use of defaults shall only be allowed with ANSI style declarations.

 

When the subroutine is called, arguments with default values defaults can be omitted from the call, and the compiler shall insert their corresponding values. Unspecified (or empty) arguments can be used as placeholders for default arguments, allowing the use of nonconsecutive default arguments. If an unspecified argument is used for an argument that does not have a default value, a compiler error shall be issued.

 

...

read( );        // error; k has no default value

read( 1, , 7 ); // error; k has no default value

 

The following example shows an output argument with a default expression.

 

module m;

logic a, w;

 

task t1 (output o = a) ; // default binds to m.a

...

endtask :t1

 

task t2 (output o = b) ; // illegal, b cannot be resolved

...

endtask :t2

 

task t3 (inout io = w) ; // default binds to m.w

...

endtask :t1

 

endmodule :m

 

 

module n;

logic a;

initial

  begin

    m.t1(); // same as m.t1(m.a), not m.t1(n.a);

            // at end of task, value of t1.o is copied to m.a

    m.t3(); // same as m.t3(m.w)

            // value of m.w is copied to t3.io at start of task and

            // value of t3.io is copied to m.w at end of task

  end

endmodule :n