Subject: [sv-cc] [sv-ec] [Opaque] Pointers
From: Kevin Cameron x3251 (Kevin.Cameron@nsc.com)
Date: Tue Feb 11 2003 - 10:16:56 PST
[The proposal I sent out a while ago is below. I think the link is missing
on the EC web page.]
The aim of this approach is too minimize the syntactic differences between
C and SV so that interfacing C routines is simple - i.e. the majority of
C function prototypes can be used directly in SV (post cpp). It also
allows type-checking of routine parameters so that you don't accidently
pass a pointer to an object of type "foo" when type "bar" was expected.
You should be able to do something like the following in a C header -
#ifdef SYSTEM_VERILOG
extern pure /* preamble */
#endif
#ifdef __CPLUSPLUS
extern "C"
#endif
int write(int fd, const void *buf, int count);
- and you can use it directly in C/C++ or in SV after pushing it through
cpp (-DSYSTEM_VERILOG).
Regards,
Kev.
----- Begin Included Message -----
http://www.eda.org/sv-ec/hm/0420.html
From: "Kevin Cameron x3251" <Kevin.Cameron@nsc.com>
We seem to be missing an "opaque pointer" proposal in the extensions list (EXT-18). Since
I seem to have been tasked with the problem from the CC/BC here's my proposed text for
addition:
Pointers
Pointers in SystemVerilog can be declared as in C by prepending "*" to a declaration e.g.:
int a, // value
*ap, // pointer to an int
*argv[5]; // array of pointers
These pointers cannot be dereferenced within SystemVerilog i.e. "*ap" has no valid meaning
in an expression. Pointers in SystemVerilog are the same size as they are for C on the simulation
host and can be included in unions. Their primary purpose is to pass data from one external C
function to another. Pointers can be assigned a value from a pointer of the same type or by casting
a scalar value to the same type as the pointer, but no other operations can modify the value e.g.:
ap = (int *)'32'h100fffed;
ap = (int *)'$data_address("gen_packet"); // User PLI
ap = argv[0];
Similarly the value of a pointer can be read by casting it to a scalar type:
a = int'ap;
Pointers can also be tested for equality if they are of the same type with == and != but no other
comparisons are allowed. Pointers are initially 0 and can be tested against 0 or null directly:
if (ap != null) ...
--I think this is an easy-to-implement minimum that won't interfere with future enhancements, and fits with using C syntax for external function declarations (direct inclusion of headers). It violates requirement 2.h and 3, but it's not clear to me that those requirements are necessary since the pointer value is never dereferenced inside SV, and req. 3 precludes using predefined C structures that do make unions of pointers and integers.
Regards, Kev.
-- National Semiconductor, Tel: (408) 721 3251 2900 Semiconductor Drive, Mail Stop D3-500, Santa Clara, CA 95052-8090
----- End Included Message -----
This archive was generated by hypermail 2b28 : Tue Feb 11 2003 - 10:17:47 PST