OSDN Git Service

* include/ffi.h.in: Removed PACKAGE and VERSION defines and
[pf3gnuchains/gcc-fork.git] / libffi / include / ffi.h.in
1 /* -----------------------------------------------------------------*-C-*-
2    libffi @VERSION@ - Copyright (c) 1996-1999  Cygnus Solutions
3
4    $Id: ffi.h.in,v 1.2 1999/08/09 02:52:58 green Exp $
5
6    Permission is hereby granted, free of charge, to any person obtaining
7    a copy of this software and associated documentation files (the
8    ``Software''), to deal in the Software without restriction, including
9    without limitation the rights to use, copy, modify, merge, publish,
10    distribute, sublicense, and/or sell copies of the Software, and to
11    permit persons to whom the Software is furnished to do so, subject to
12    the following conditions:
13
14    The above copyright notice and this permission notice shall be included
15    in all copies or substantial portions of the Software.
16
17    THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
18    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19    MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
20    IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21    OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22    ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23    OTHER DEALINGS IN THE SOFTWARE.
24
25    ----------------------------------------------------------------------- */
26
27 #ifndef LIBFFI_H
28 #define LIBFFI_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 /* Specify which architecture libffi is configured for. */
35 #define @TARGET@
36
37 /* ---- System configuration information --------------------------------- */
38
39 #include <fficonfig.h>
40
41 #if !defined(LIBFFI_ASM)
42 #include <stddef.h>
43 #if defined(FFI_DEBUG) 
44 #include <stdio.h>
45 #endif
46 #endif
47
48 /* ---- Generic type definitions ----------------------------------------- */
49
50 #define FLOAT32 float
51 #define FLOAT64 double
52 #define FLOAT80 long double
53
54 #define UINT8   unsigned char
55 #define SINT8   signed char
56
57 #if SIZEOF_INT == 2
58
59 #define UINT16  unsigned int
60 #define SINT16  int
61 #define ffi_type_uint ffi_type_uint16
62 #define ffi_type_sint ffi_type_sint16
63
64 #else 
65 #if SIZEOF_SHORT == 2
66
67 #define UINT16  unsigned short
68 #define SINT16  short
69 #define ffi_type_ushort ffi_type_uint16
70 #define ffi_type_sshort ffi_type_sint16
71
72 #endif
73 #endif
74
75 #if SIZEOF_INT == 4
76
77 #define UINT32  unsigned int
78 #define SINT32  int
79 #define ffi_type_uint ffi_type_uint32
80 #define ffi_type_sint ffi_type_sint32
81
82 #else 
83 #if SIZEOF_SHORT == 4
84
85 #define UINT32  unsigned short
86 #define SINT32  short
87 #define ffi_type_ushort ffi_type_uint32
88 #define ffi_type_sshort ffi_type_sint32
89
90 #else
91 #if SIZEOF_LONG == 4
92
93 #define UINT32  unsigned long
94 #define SINT32  long
95 #define ffi_type_ulong ffi_type_uint32
96 #define ffi_type_slong ffi_type_sint32
97
98 #endif
99 #endif
100 #endif
101
102 #if SIZEOF_INT == 8
103
104 #define UINT64  unsigned int
105 #define SINT64  int
106 #define ffi_type_uint ffi_type_uint64
107 #define ffi_type_sint ffi_type_sint64
108
109 #else
110 #if SIZEOF_LONG == 8
111
112 #define UINT64  unsigned long
113 #define SINT64  long
114 #define ffi_type_ulong ffi_type_uint64
115 #define ffi_type_slong ffi_type_sint64
116
117 #else
118 #if SIZEOF_LONG_LONG == 8
119
120 #define UINT64  unsigned long long
121 #define SINT64  long long
122 #define ffi_type_ulong ffi_type_uint64
123 #define ffi_type_slong ffi_type_sint64
124
125 #endif
126 #endif
127 #endif
128
129 /* ---- System specific configurations ----------------------------------- */
130
131 #ifdef MIPS
132 #include <ffi_mips.h>
133 #else
134 #define SIZEOF_ARG SIZEOF_VOID_P
135 #endif
136
137 #ifndef LIBFFI_ASM
138
139 /* ---- Generic type definitions ----------------------------------------- */
140
141 #define ALIGN(v, a)  (((((unsigned) (v))-1) | ((a)-1))+1)
142
143 typedef enum ffi_abi {
144
145   /* Leave this for debugging purposes */
146   FFI_FIRST_ABI = 0,
147
148   /* ---- Sparc -------------------- */
149 #ifdef SPARC
150   FFI_V8,
151   FFI_DEFAULT_ABI = FFI_V8,
152   FFI_V8PLUS,
153   FFI_V9,
154 #endif
155
156   /* ---- Intel x86 ---------------- */
157 #ifdef X86
158   FFI_SYSV,
159   FFI_DEFAULT_ABI = FFI_SYSV,
160 #endif
161
162   /* ---- Mips --------------------- */
163 #ifdef MIPS
164   FFI_O32,
165   FFI_N32,
166   FFI_N64,
167 #endif
168
169   /* ---- Alpha -------------------- */
170 #ifdef ALPHA
171   FFI_OSF,
172   FFI_DEFAULT_ABI = FFI_OSF,
173 #endif
174
175   /* ---- Motorola m68k ------------ */
176 #ifdef M68K
177   FFI_SYSV,
178   FFI_DEFAULT_ABI = FFI_SYSV,
179 #endif
180
181   /* ---- PowerPC ------------------ */
182 #ifdef POWERPC
183   FFI_SYSV,
184   FFI_GCC_SYSV,
185   FFI_DEFAULT_ABI = FFI_GCC_SYSV,
186 #endif
187
188   /* ---- ARM  --------------------- */
189 #ifdef ARM
190   FFI_SYSV,
191   FFI_DEFAULT_ABI = FFI_SYSV,
192 #endif
193
194   /* Leave this for debugging purposes */
195   FFI_LAST_ABI
196
197 } ffi_abi;
198
199 typedef struct _ffi_type
200 {
201   size_t size;
202   unsigned short alignment;
203   unsigned short type;
204   /*@null@*/ struct _ffi_type **elements;
205 } ffi_type;
206
207 /* These are defined in ffi.c */
208 extern ffi_type ffi_type_void;
209 extern ffi_type ffi_type_uint8;
210 extern ffi_type ffi_type_sint8;
211 extern ffi_type ffi_type_uint16;
212 extern ffi_type ffi_type_sint16;
213 extern ffi_type ffi_type_uint32;
214 extern ffi_type ffi_type_sint32;
215 extern ffi_type ffi_type_uint64;
216 extern ffi_type ffi_type_sint64;
217 extern ffi_type ffi_type_float;
218 extern ffi_type ffi_type_double;
219 extern ffi_type ffi_type_longdouble;
220 extern ffi_type ffi_type_pointer;
221
222 /* Characters are 8 bit integral types */
223 #define ffi_type_schar ffi_type_sint8
224 #define ffi_type_uchar ffi_type_uint8
225
226 typedef enum {
227   FFI_OK = 0,
228   FFI_BAD_TYPEDEF,
229   FFI_BAD_ABI 
230 } ffi_status;
231
232 typedef unsigned FFI_TYPE;
233
234 typedef struct {
235   ffi_abi abi;
236   unsigned nargs;
237   /*@dependent@*/ ffi_type **arg_types;
238   /*@dependent@*/ ffi_type *rtype;
239   unsigned bytes;
240   unsigned flags;
241
242 #ifdef MIPS
243 #if _MIPS_SIM == _ABIN32
244   unsigned rstruct_flag;
245 #endif
246 #endif
247
248 } ffi_cif;
249
250 /* ---- Definitions for the raw API -------------------------------------- */
251
252 #if !FFI_NO_RAW_API
253
254 #if SIZEOF_ARG == 4
255
256 #define UINT_ARG UINT32
257 #define SINT_ARG SINT32
258
259 #endif
260
261 #if SIZEOF_ARG == 8
262
263 #define UINT_ARG UINT64
264 #define SINT_ARG SINT64
265
266 #endif
267
268 typedef union {
269   SINT_ARG sint;
270   UINT_ARG uint;
271   char     data[SIZEOF_ARG];
272   void*    ptr;
273 } ffi_raw;
274
275 void ffi_raw_call (/*@dependent@*/ ffi_cif *cif, 
276                    void (*fn)(), 
277                    /*@out@*/ void *rvalue, 
278                    /*@dependent@*/ ffi_raw *avalue);
279
280 void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
281 void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
282 size_t ffi_raw_size (ffi_cif *cif);
283
284
285
286
287 #endif /* !FFI_NO_RAW_API */
288
289 /* ---- Definitions for closures ----------------------------------------- */
290
291 #ifdef X86
292
293 #define FFI_CLOSURES 1          /* x86 supports closures */
294 #define FFI_TRAMPOLINE_SIZE 10
295 #define FFI_NATIVE_RAW_API 1    /* and has native raw api support */
296
297 #else 
298
299 #define FFI_CLOSURES 0
300 #define FFI_NATIVE_RAW_API 0
301
302 #endif
303
304
305
306 #if FFI_CLOSURES
307
308 typedef struct {
309   char tramp[FFI_TRAMPOLINE_SIZE];
310   ffi_cif   *cif;
311   void     (*fun)(ffi_cif*,void*,void**,void*);
312   void      *user_data;
313 } ffi_closure;
314
315 ffi_status
316 ffi_prep_closure (ffi_closure*,
317                   ffi_cif *,
318                   void (*fun)(ffi_cif*,void*,void**,void*),
319                   void *user_data);
320
321 #if !FFI_NO_RAW_API
322
323 typedef struct {
324   char tramp[FFI_TRAMPOLINE_SIZE];
325
326   ffi_cif   *cif;
327
328 #if !FFI_NATIVE_RAW_API
329
330   /* if this is enabled, then a raw closure has the same layout 
331      as a regular closure.  We use this to install an intermediate 
332      handler to do the transaltion, void** -> ffi_raw*. */
333
334   void     (*translate_args)(ffi_cif*,void*,void**,void*);
335   void      *this_closure;
336
337 #endif
338
339   void     (*fun)(ffi_cif*,void*,ffi_raw*,void*);
340   void      *user_data;
341
342 } ffi_raw_closure;
343
344 ffi_status
345 ffi_prep_raw_closure (ffi_raw_closure*,
346                       ffi_cif *cif,
347                       void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
348                       void *user_data);
349
350 #endif /* !FFI_NO_RAW_API */
351 #endif /* FFI_CLOSURES */
352
353 /* ---- Public interface definition -------------------------------------- */
354
355 ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif, 
356                         ffi_abi abi,
357                         unsigned int nargs, 
358                         /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype, 
359                         /*@dependent@*/ ffi_type **atypes);
360
361 void ffi_call(/*@dependent@*/ ffi_cif *cif, 
362               void (*fn)(), 
363               /*@out@*/ void *rvalue, 
364               /*@dependent@*/ void **avalue);
365
366 /* Useful for eliminating compiler warnings */
367 #define FFI_FN(f) ((void (*)())f)
368
369 /* ---- Definitions shared with assembly code ---------------------------- */
370
371 #endif
372
373 #define FFI_TYPE_VOID       0    
374 #define FFI_TYPE_INT        1
375 #define FFI_TYPE_FLOAT      2    
376 #define FFI_TYPE_DOUBLE     3
377 #if SIZEOF_LONG_DOUBLE == SIZEOF_DOUBLE
378 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
379 #else
380 #define FFI_TYPE_LONGDOUBLE 4
381 #endif
382
383 #define FFI_TYPE_UINT8      5   /* If this changes, update ffi_mips.h. */
384 #define FFI_TYPE_SINT8      6   /* If this changes, update ffi_mips.h. */
385 #define FFI_TYPE_UINT16     7 
386 #define FFI_TYPE_SINT16     8
387 #define FFI_TYPE_UINT32     9
388 #define FFI_TYPE_SINT32     10
389 #define FFI_TYPE_UINT64     11
390 #define FFI_TYPE_SINT64     12
391 #define FFI_TYPE_STRUCT     13  /* If this changes, update ffi_mips.h. */
392 #define FFI_TYPE_POINTER    14
393
394 /* This should always refer to the last type code (for sanity checks) */
395 #define FFI_TYPE_LAST       FFI_TYPE_POINTER
396
397 #ifdef __cplusplus
398 }
399 #endif
400
401 #endif
402