Subject: Re: [sv-cc] another directC question - defaults for args, passing by name
From: Francoise Martinolle (fm@cadence.com)
Date: Wed Feb 12 2003 - 08:53:52 PST
Andrzej,
I am catching up with my sv-cc email and here is the response to your
questions.
At 07:30 PM 2/11/2003 -0500, Andrzej Litwiniuk wrote:
> > > Please correct me if I'm wrong.
> >
> > You can skip arguments and use named arguments in general in SV, you
> > just can't mix the two after you use a named binding (I would rather not
> > mix them at all).
> >
> > SV Draft 2 covers this etc in section 10.5.3.
> >
> > Kev.
>
>Thanks Kevin & Francoise for pointing this!
>My appologies: I didn't know about those changes,
>
>Apparently DirectC needs proofreading against LRM 3.0.
This is why it helps to attend all 3 committees!
>I was amazed - I'm kind of digressing now - by the sub-chapter 10.5.
>It uses the term "subroutine" while everywhere else it is function/task.
I sent an email to Dave Smith and asked him to correct this for consistency
in the draft.
>Then, default values for arguments. Pls. notice the absence of any
>restrictions!
>So, I guess, literal aggregates (structs, arrays) are allowed for default
>values of arguments? And what about default values for arguments passed
>by reference ('var')?
>What it would mean to have: 'task foo(var int i = 10);' ?
It does not make much sense.
>Well, it ain't my problem, sv-bc guys surely will take care of it.
This default argument value and passing by reference was added by the
extension committee. So I mention this to Dave Smith too. I think also we
changed the var keyword to
be ref as of last meeting vote.
>Talking about =our= problems, it shouldn't be a big deal to allow
>the default values for arguments of external functions.
agreed with you, if no actual arguments are passed in the directC call, then
we use the default provided values.
>It shouldn't be permitted, however, for exported SV functions called from C.
>(Kevin may comment that it would be a different story had we built the
>interface
>upon C++.)
Correct C function calls do not allow to use default argument values in the
function call.
>I see, however, some issues with passing by name.
>
>Again, it shouldn't be permitted for exported SV functions called from C.
Correct, neither a mix of named/position when called from C.
>For external functions the names of formal arguments are optional (while they
>are obligatory for native subroutines - let me enjoy this long forgotten
>term).
I do not understand: in C it is not possible to call a C function with
argument name passing,
everything is by position even for varargs.
this brings another issue, do we allow directC function to take varargs?
>It won't make any sense to have the names of formal arguments only for some
>of them and still use passing by name.
not understanding
>We may propose all-or-none approach, or require that passing by name is
>allowed
>only if all formal args have names.
>There is a more serious issue with argument passing by reference ('var').
>I'm afraid we'll have to do something.
>Until now, the actual passing mode for DirectC was transparent to Verilog;
>it would matter only for the C code whether the argument is passed by value
>or by reference, and it would be automatically inferred from the type of
>value.
Yes but now we also have to also infer it from the var qualifier. Every
Verilog parameter
which is qualified by "var" indicates pass by reference. You cannot use
both var and input
and var and output.
Let's say I have a directC function:
void swap(int *a, int *b) {
/* swaps the values of a and b */
int temp;
temp = *a;
*a = *b;
*b = temp;
}
I can provide an extern declaration in Verilog using var qualifier or inout
extern void swap(inout int x, inout y);
or
extern void swap (var int x, var int y); /* this one is more intuitive */
reg y = 1;
reg x = 0;
always @clk
begin
display ("y = %d, x = %d\n", y, x);
// should print y = 1, x = 0
swap(.b(y), .a(x)); /* call to swap y and x contents */
display ("y = %d, x = %d\n", y, x);
end
>One of requirements for DirectC was to keep it similar to native
>'subroutines'.
>Does it mean that DirectC should allow for explicit specification of argument
>passing by referense vs. by value?
I think the only thing we have to add is rules for the case where the
external declaration of the
C function uses var which explicitly means pass by reference.
>If so, then we may have to rework everything ...
>
>Andrzej
>
> > > > Francoise Martinolle wrote:
> > > > > I am digging more in the directC document and I found something
> which needs
> > > > > to be specified:
> > > > > directC functions which are called from within Verilog must have
> all the
> > > > > parameters specified on the call either by position or by name.
> We should
> > > > > not allow to skip to provide a parameter if a default value is
> provided in the function
> > > > > declaration for that argument.
> > > > >
> > > > > Francoise
> > >
> > >
> >
> >
This archive was generated by hypermail 2b28 : Wed Feb 12 2003 - 09:31:12 PST