Subject: DirectC memory ownership - proposed rules
From: Joao Geada (Joao.Geada@synopsys.com)
Date: Sat Dec 14 2002 - 08:24:22 PST
In general the rule is very simple: C code owns all the memory it creates,
SystemVerilog owns all its own memory.
Details:
strings:
on input ports:
Verilog owns and manages the string (char*). Users C code can read
the string but must not maintain a reference to this reference as the
validity of the pointer is not guaranteed beyond the end of this DirecC
call
on output ports:
Verilog passes a reference to a NULL pointer. User code is expected
to change this reference to a pointer to a valid string (or leave the
reference alone if no output string is to be passed to Verilog).
C code owns any memory it may allocate to represent this string.
SystemVerilog will copy this string out (if non-NULL) on exit of the
DirectC function. SystemVerilog must not make any assumptions about the
validity of this pointer across any other DirectC calls. SystemVerilog
must never make any changes to the string passed by C (though it can
make changes to its own copy of this string).
[This last rule because SystemVerilog must not assume that it has been
given a pointer to a writable string]
on inout ports:
Verilog passes a reference to a valid string pointer. User code can
read this string but must never make any changes to this string. User
can change the string by the same means, and following same rules and
restrictions, as per output ports.
NOTE: according to sv-ec, strings are a SystemVerilog 3.1 class type. You cannot
nest strings (or any other class) inside a SystemVerilog structure. This implies
that strings can only be passed directly to a DirectC function, never indirectly.
Because of this the specific layout used to represent the string class does not
need to be described for the DirectC interface (ie implicit conversion in both
directions across the interface).
NOTE: no classes other than strings can cross the DirectC interface.
pointers:
SystemVerilog cannot perform any operations on the opaque pointers, so nothing
extra needs to be said than the general rule.
Joao
==============================================================================
Joao Geada, PhD Principal Engineer Verif Tech Group
Synopsys, Inc TEL: (508) 263-8083
154 Crane Meadow Road, Suite 300, FAX: (508) 263-8069
Marlboro, MA 01752, USA
==============================================================================
This archive was generated by hypermail 2b28 : Sat Dec 14 2002 - 08:50:00 PST