Subject: [sv-cc] DirectC: defaults for args, passing by name
From: Andrzej Litwiniuk (Andrzej.Litwiniuk@synopsys.com)
Date: Tue Feb 18 2003 - 08:48:01 PST
Hi all,
DirectC had been developed partly out of sync with other committees.
In particular, default argument values and argument passing by name which have
been added to SV, are not addressed in DirectC (thanks Francoise for drawing
our attention to it!). Another newly added feature not addressed in DirectC
is the ability to pass arguments by reference ('var') in addition to formerly
sole mode of passing by value. (We are not talking about the C Layer here!)
Shortly speaking, the mechanism for binding the actual arguments to formal
arguments 'by name' has been extended from module instantiating to all
function and task calls. This allowed for optional default argument values:
if not all arguments are actually passed, the default values may be used.
Should this be extended also for DirectC?
My recomendations is:
do not support default values and argument passing by name for DirectC calls.
My reasoning goes as follows:
1. Neither default values nor passing by name can be supported for calling
the exported SV functions from C code. The syntax of C cannot be changed.
2. Please recall that currently the names of formal arguments are optional
in the external declarations. Those optional names are ignored in checks
for consistency of multiple external declarations.
For example, the following declarations are all equivalent and legal:
extern void foo(int count, bit status);
extern void foo(int i, bit b); // different names
extern void foo(int , bit b); // not all names specified
extern void foo(int i, bit );
extern void foo(int , bit ); // no names at all
If we decide to support argument passing by name for external function
calls (in SV only!), then some rectrictions will have to be added:
a) passing by name is legal only for the external functions with
all formal arguments named (i.e such that that every formal
argument has its name specified in the external declaration)
b) multiple external declarations must use same names of formal
arguments, i.e. if a name is provided for an argument, the same name
must be used in every declaration for that function, that provides
a name for that argument. For example, the first two declarations
of 'foo' break that rule.
Supporting the default values (in SV only!) seems relatively easy.
They can be supported with or without supporting argument passing by name.
If we decide to support default values, then an issue of the equivalence of
multiple external declarations will immediately arise. (Same value for same
arguments must be provided, what if there is no default value and yet the
actual arg. is missing, etc.)
I'm not sure, however, whether we should be bothered with the default values
at all. Francoise checked that:
=> While looking more closely at the bnf for function prototype, I dont see
=> that the bnf allows to provide default values for the formal arguments of
=> a function prototype. It allows it only for the function declaration.
=> [...]
=> Therefore for a extern directC function declaration in the Verilog code,
=> you cannot provide default values for formals.
=> Ex: you cannot write:
=> extern myCfunction (int i = 0);
The syntax can be, of course, extended, but do we want this?
I don't have a clear and strong opinion how to address the issue of formal
arguments passed by var. I lean to think that we should not support this feature
in DirectC.
Regards,
Andrzej
This archive was generated by hypermail 2b28 : Tue Feb 18 2003 - 08:49:02 PST