* combine.c (simplify_and_const_int): Simplify (AND (PLUS X Y) C)
[official-gcc.git] / libffi / include / ffi.h.in
blob275bd032ca0f60688da43bff0798ea8fba271958
1 /* -----------------------------------------------------------------*-C-*-
2 libffi @VERSION@ - Copyright (c) 1996-1999 Cygnus Solutions
4 Permission is hereby granted, free of charge, to any person obtaining
5 a copy of this software and associated documentation files (the
6 ``Software''), to deal in the Software without restriction, including
7 without limitation the rights to use, copy, modify, merge, publish,
8 distribute, sublicense, and/or sell copies of the Software, and to
9 permit persons to whom the Software is furnished to do so, subject to
10 the following conditions:
12 The above copyright notice and this permission notice shall be included
13 in all copies or substantial portions of the Software.
15 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 IN NO EVENT SHALL CYGNUS SOLUTIONS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 OTHER DEALINGS IN THE SOFTWARE.
23 ----------------------------------------------------------------------- */
25 /* -------------------------------------------------------------------
26 The basic API is described in the README file.
28 The raw API is designed to bypass some of the argument packing
29 and unpacking on architectures for which it can be avoided.
31 The closure API allows interpreted functions to be packaged up
32 inside a C function pointer, so that they can be called as C functions,
33 with no understanding on the client side that they are interpreted.
34 It can also be used in other cases in which it is necessary to package
35 up a user specified parameter and a function pointer as a single
36 function pointer.
38 The closure API must be implemented in order to get its functionality,
39 e.g. for use by gij. Routines are provided to emulate the raw API
40 if the underlying platform doesn't allow faster implementation.
42 More details on the raw and cloure API can be found in:
44 http://gcc.gnu.org/ml/java/1999-q3/msg00138.html
46 and
48 http://gcc.gnu.org/ml/java/1999-q3/msg00174.html
49 -------------------------------------------------------------------- */
51 #ifndef LIBFFI_H
52 #define LIBFFI_H
54 #ifdef __cplusplus
55 extern "C" {
56 #endif
58 /* Specify which architecture libffi is configured for. */
59 #define @TARGET@
61 /* ---- System configuration information --------------------------------- */
63 #include <fficonfig.h>
65 #if !defined(LIBFFI_ASM)
66 #include <stddef.h>
67 #if defined(FFI_DEBUG)
68 #include <stdio.h>
69 #endif
70 #endif
72 /* ---- Generic type definitions ----------------------------------------- */
74 #define FLOAT32 float
75 #define FLOAT64 double
76 #define FLOAT80 long double
78 #define UINT8 unsigned char
79 #define SINT8 signed char
81 #if SIZEOF_INT == 2
83 #define UINT16 unsigned int
84 #define SINT16 int
85 #define ffi_type_uint ffi_type_uint16
86 #define ffi_type_sint ffi_type_sint16
88 #else
89 #if SIZEOF_SHORT == 2
91 #define UINT16 unsigned short
92 #define SINT16 short
93 #define ffi_type_ushort ffi_type_uint16
94 #define ffi_type_sshort ffi_type_sint16
96 #endif
97 #endif
99 #if SIZEOF_INT == 4
101 #define UINT32 unsigned int
102 #define SINT32 int
103 #define ffi_type_uint ffi_type_uint32
104 #define ffi_type_sint ffi_type_sint32
106 #else
107 #if SIZEOF_SHORT == 4
109 #define UINT32 unsigned short
110 #define SINT32 short
111 #define ffi_type_ushort ffi_type_uint32
112 #define ffi_type_sshort ffi_type_sint32
114 #else
115 #if SIZEOF_LONG == 4
117 #define UINT32 unsigned long
118 #define SINT32 long
119 #define ffi_type_ulong ffi_type_uint32
120 #define ffi_type_slong ffi_type_sint32
122 #endif
123 #endif
124 #endif
126 #if SIZEOF_INT == 8
128 #define UINT64 unsigned int
129 #define SINT64 int
130 #define ffi_type_uint ffi_type_uint64
131 #define ffi_type_sint ffi_type_sint64
133 #else
134 #if SIZEOF_LONG == 8
136 #define UINT64 unsigned long
137 #define SINT64 long
138 #define ffi_type_ulong ffi_type_uint64
139 #define ffi_type_slong ffi_type_sint64
141 #else
142 #if SIZEOF_LONG_LONG == 8
144 #define UINT64 unsigned long long
145 #define SINT64 long long
146 #define ffi_type_ulong ffi_type_uint64
147 #define ffi_type_slong ffi_type_sint64
149 #endif
150 #endif
151 #endif
153 /* ---- System specific configurations ----------------------------------- */
155 #ifdef MIPS
156 #include <ffi_mips.h>
157 #else
158 #define SIZEOF_ARG SIZEOF_VOID_P
159 #endif
161 #ifdef SPARC
162 #if defined(__arch64__) || defined(__sparcv9)
163 #define SPARC64
164 #endif
165 #endif
167 #ifndef LIBFFI_ASM
169 /* ---- Generic type definitions ----------------------------------------- */
171 #define ALIGN(v, a) (((((size_t) (v))-1) | ((a)-1))+1)
172 /* The closure code assumes that this works on pointers, i.e. a size_t */
173 /* can hold a pointer. */
175 typedef enum ffi_abi {
177 /* Leave this for debugging purposes */
178 FFI_FIRST_ABI = 0,
180 /* ---- Sparc -------------------- */
181 #ifdef SPARC
182 FFI_V8,
183 FFI_V8PLUS,
184 FFI_V9,
185 #ifdef SPARC64
186 FFI_DEFAULT_ABI = FFI_V9,
187 #else
188 FFI_DEFAULT_ABI = FFI_V8,
189 #endif
190 #endif
192 /* ---- Intel x86 ---------------- */
193 #ifdef X86
194 FFI_SYSV,
195 FFI_DEFAULT_ABI = FFI_SYSV,
196 #endif
198 /* ---- Intel x86 Win32 ---------- */
199 #ifdef X86_WIN32
200 FFI_SYSV,
201 FFI_DEFAULT_ABI = FFI_SYSV,
202 #endif
204 /* ---- Intel ia64 ---------------- */
205 #ifdef IA64
206 FFI_UNIX, /* Linux and all Unix variants use the same conventions */
207 FFI_DEFAULT_ABI = FFI_UNIX,
208 #endif
210 /* ---- Mips --------------------- */
211 #ifdef MIPS
212 FFI_O32,
213 FFI_N32,
214 FFI_N64,
215 #endif
217 /* ---- Alpha -------------------- */
218 #ifdef ALPHA
219 FFI_OSF,
220 FFI_DEFAULT_ABI = FFI_OSF,
221 #endif
223 /* ---- Motorola m68k ------------ */
224 #ifdef M68K
225 FFI_SYSV,
226 FFI_DEFAULT_ABI = FFI_SYSV,
227 #endif
229 /* ---- PowerPC ------------------ */
230 #ifdef POWERPC
231 FFI_SYSV,
232 FFI_GCC_SYSV,
233 FFI_DEFAULT_ABI = FFI_GCC_SYSV,
234 #endif
236 #ifdef POWERPC_DARWIN
237 FFI_DARWIN,
238 FFI_DEFAULT_ABI = FFI_DARWIN,
239 #endif
241 /* ---- ARM --------------------- */
242 #ifdef ARM
243 FFI_SYSV,
244 FFI_DEFAULT_ABI = FFI_SYSV,
245 #endif
247 /* Leave this for debugging purposes */
248 FFI_LAST_ABI
250 } ffi_abi;
252 typedef struct _ffi_type
254 size_t size;
255 unsigned short alignment;
256 unsigned short type;
257 /*@null@*/ struct _ffi_type **elements;
258 } ffi_type;
260 /* These are defined in ffi.c */
261 extern ffi_type ffi_type_void;
262 extern ffi_type ffi_type_uint8;
263 extern ffi_type ffi_type_sint8;
264 extern ffi_type ffi_type_uint16;
265 extern ffi_type ffi_type_sint16;
266 extern ffi_type ffi_type_uint32;
267 extern ffi_type ffi_type_sint32;
268 extern ffi_type ffi_type_uint64;
269 extern ffi_type ffi_type_sint64;
270 extern ffi_type ffi_type_float;
271 extern ffi_type ffi_type_double;
272 extern ffi_type ffi_type_longdouble;
273 extern ffi_type ffi_type_pointer;
275 /* Characters are 8 bit integral types */
276 #define ffi_type_schar ffi_type_sint8
277 #define ffi_type_uchar ffi_type_uint8
279 typedef enum {
280 FFI_OK = 0,
281 FFI_BAD_TYPEDEF,
282 FFI_BAD_ABI
283 } ffi_status;
285 typedef unsigned FFI_TYPE;
287 typedef struct {
288 ffi_abi abi;
289 unsigned nargs;
290 /*@dependent@*/ ffi_type **arg_types;
291 /*@dependent@*/ ffi_type *rtype;
292 unsigned bytes;
293 unsigned flags;
295 #ifdef MIPS
296 #if _MIPS_SIM == _ABIN32
297 unsigned rstruct_flag;
298 #endif
299 #endif
301 } ffi_cif;
303 /* ---- Definitions for the raw API -------------------------------------- */
305 #if !FFI_NO_RAW_API
307 #if SIZEOF_ARG == 4
309 #define UINT_ARG UINT32
310 #define SINT_ARG SINT32
312 #endif
314 #if SIZEOF_ARG == 8
316 #define UINT_ARG UINT64
317 #define SINT_ARG SINT64
319 #endif
321 typedef union {
322 SINT_ARG sint;
323 UINT_ARG uint;
324 float flt;
325 char data[SIZEOF_ARG];
326 void* ptr;
327 } ffi_raw;
329 void ffi_raw_call (/*@dependent@*/ ffi_cif *cif,
330 void (*fn)(),
331 /*@out@*/ void *rvalue,
332 /*@dependent@*/ ffi_raw *avalue);
334 void ffi_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
335 void ffi_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
336 size_t ffi_raw_size (ffi_cif *cif);
338 #if !NO_JAVA_RAW_API
340 /* This is analogous to the raw API, except it uses Java parameter */
341 /* packing, even on 64-bit machines. I.e. on 64-bit machines */
342 /* longs and doubles are followed by an empty 64-bit word. */
344 void ffi_java_raw_call (/*@dependent@*/ ffi_cif *cif,
345 void (*fn)(),
346 /*@out@*/ void *rvalue,
347 /*@dependent@*/ ffi_raw *avalue);
349 void ffi_java_ptrarray_to_raw (ffi_cif *cif, void **args, ffi_raw *raw);
350 void ffi_java_raw_to_ptrarray (ffi_cif *cif, ffi_raw *raw, void **args);
351 size_t ffi_java_raw_size (ffi_cif *cif);
353 #endif /* !NO_JAVA_RAW_API */
355 #endif /* !FFI_NO_RAW_API */
357 /* ---- Definitions for closures ----------------------------------------- */
359 #ifdef X86
361 #define FFI_CLOSURES 1 /* x86 supports closures */
362 #define FFI_TRAMPOLINE_SIZE 10
363 #define FFI_NATIVE_RAW_API 1 /* and has native raw api support */
365 #elif defined(X86_WIN32)
367 #define FFI_CLOSURES 1 /* x86 supports closures */
368 #define FFI_TRAMPOLINE_SIZE 10
369 #define FFI_NATIVE_RAW_API 1 /* and has native raw api support */
371 #elif defined(IA64)
373 #define FFI_CLOSURES 1
374 #define FFI_TRAMPOLINE_SIZE 24 /* Really the following struct, which */
375 /* can be interpreted as a C function */
376 /* decriptor: */
378 struct ffi_ia64_trampoline_struct {
379 void * code_pointer; /* Pointer to ffi_closure_UNIX */
380 void * fake_gp; /* Pointer to closure, installed as gp */
381 void * real_gp; /* Real gp value, reinstalled by */
382 /* ffi_closure_UNIX. */
384 #define FFI_NATIVE_RAW_API 0
386 #elif defined(ALPHA)
388 #define FFI_CLOSURES 1
389 #define FFI_TRAMPOLINE_SIZE 24
390 #define FFI_NATIVE_RAW_API 0
392 #elif defined(POWERPC)
394 #define FFI_CLOSURES 1
395 #define FFI_TRAMPOLINE_SIZE 40
396 #define FFI_NATIVE_RAW_API 0
398 #else
400 #define FFI_CLOSURES 0
401 #define FFI_NATIVE_RAW_API 0
403 #endif
407 #if FFI_CLOSURES
409 typedef struct {
410 char tramp[FFI_TRAMPOLINE_SIZE];
411 ffi_cif *cif;
412 void (*fun)(ffi_cif*,void*,void**,void*);
413 void *user_data;
414 } ffi_closure;
416 ffi_status
417 ffi_prep_closure (ffi_closure*,
418 ffi_cif *,
419 void (*fun)(ffi_cif*,void*,void**,void*),
420 void *user_data);
422 #if !FFI_NO_RAW_API
424 typedef struct {
425 char tramp[FFI_TRAMPOLINE_SIZE];
427 ffi_cif *cif;
429 #if !FFI_NATIVE_RAW_API
431 /* if this is enabled, then a raw closure has the same layout
432 as a regular closure. We use this to install an intermediate
433 handler to do the transaltion, void** -> ffi_raw*. */
435 void (*translate_args)(ffi_cif*,void*,void**,void*);
436 void *this_closure;
438 #endif
440 void (*fun)(ffi_cif*,void*,ffi_raw*,void*);
441 void *user_data;
443 } ffi_raw_closure;
445 ffi_status
446 ffi_prep_raw_closure (ffi_raw_closure*,
447 ffi_cif *cif,
448 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
449 void *user_data);
451 #ifndef NO_JAVA_RAW_API
452 ffi_status
453 ffi_prep_java_raw_closure (ffi_raw_closure*,
454 ffi_cif *cif,
455 void (*fun)(ffi_cif*,void*,ffi_raw*,void*),
456 void *user_data);
457 #endif
459 #endif /* !FFI_NO_RAW_API */
460 #endif /* FFI_CLOSURES */
462 /* ---- Public interface definition -------------------------------------- */
464 ffi_status ffi_prep_cif(/*@out@*/ /*@partial@*/ ffi_cif *cif,
465 ffi_abi abi,
466 unsigned int nargs,
467 /*@dependent@*/ /*@out@*/ /*@partial@*/ ffi_type *rtype,
468 /*@dependent@*/ ffi_type **atypes);
470 void ffi_call(/*@dependent@*/ ffi_cif *cif,
471 void (*fn)(),
472 /*@out@*/ void *rvalue,
473 /*@dependent@*/ void **avalue);
475 /* Useful for eliminating compiler warnings */
476 #define FFI_FN(f) ((void (*)())f)
478 /* ---- Definitions shared with assembly code ---------------------------- */
480 #endif
482 #define FFI_TYPE_VOID 0
483 #define FFI_TYPE_INT 1
484 #define FFI_TYPE_FLOAT 2
485 #define FFI_TYPE_DOUBLE 3
486 #if SIZEOF_LONG_DOUBLE == SIZEOF_DOUBLE
487 #define FFI_TYPE_LONGDOUBLE FFI_TYPE_DOUBLE
488 #else
489 #define FFI_TYPE_LONGDOUBLE 4
490 #endif
492 #define FFI_TYPE_UINT8 5 /* If this changes, update ffi_mips.h. */
493 #define FFI_TYPE_SINT8 6 /* If this changes, update ffi_mips.h. */
494 #define FFI_TYPE_UINT16 7
495 #define FFI_TYPE_SINT16 8
496 #define FFI_TYPE_UINT32 9
497 #define FFI_TYPE_SINT32 10
498 #define FFI_TYPE_UINT64 11
499 #define FFI_TYPE_SINT64 12
500 #define FFI_TYPE_STRUCT 13 /* If this changes, update ffi_mips.h. */
501 #define FFI_TYPE_POINTER 14
503 /* This should always refer to the last type code (for sanity checks) */
504 #define FFI_TYPE_LAST FFI_TYPE_POINTER
506 #ifdef __cplusplus
508 #endif
510 #endif