]> git.ipfire.org Git - thirdparty/gcc.git/blame - libffi/src/types.c
libffi: Sync with libffi 3.4.2
[thirdparty/gcc.git] / libffi / src / types.c
CommitLineData
63e5e3e0 1/* -----------------------------------------------------------------------
1450eb7a 2 types.c - Copyright (c) 1996, 1998 Red Hat, Inc.
63e5e3e0
AG
3
4 Predefined ffi_types needed by libffi.
5
63e5e3e0
AG
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
5f933ef0
AH
17 THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
18 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
19 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
20 NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
21 HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
22 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
23 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 DEALINGS IN THE SOFTWARE.
63e5e3e0
AG
25 ----------------------------------------------------------------------- */
26
bf8da5fc
RH
27/* Hide the basic type definitions from the header file, so that we
28 can redefine them here as "const". */
29#define LIBFFI_HIDE_BASIC_TYPES
30
63e5e3e0
AG
31#include <ffi.h>
32#include <ffi_common.h>
33
34/* Type definitions */
35
b1760f7f 36#define FFI_TYPEDEF(name, type, id, maybe_const)\
5df07255
RH
37struct struct_align_##name { \
38 char c; \
39 type x; \
40}; \
92456a4e 41FFI_EXTERN \
b1760f7f 42maybe_const ffi_type ffi_type_##name = { \
5df07255
RH
43 sizeof(type), \
44 offsetof(struct struct_align_##name, x), \
45 id, NULL \
46}
63e5e3e0 47
b1760f7f
RH
48#define FFI_COMPLEX_TYPEDEF(name, type, maybe_const) \
49static ffi_type *ffi_elements_complex_##name [2] = { \
50 (ffi_type *)(&ffi_type_##name), NULL \
51}; \
52struct struct_align_complex_##name { \
53 char c; \
54 _Complex type x; \
55}; \
92456a4e 56FFI_EXTERN \
b1760f7f
RH
57maybe_const ffi_type ffi_type_complex_##name = { \
58 sizeof(_Complex type), \
59 offsetof(struct struct_align_complex_##name, x), \
60 FFI_TYPE_COMPLEX, \
61 (ffi_type **)ffi_elements_complex_##name \
e73d2479
AM
62}
63
63e5e3e0 64/* Size and alignment are fake here. They must not be 0. */
92456a4e 65FFI_EXTERN const ffi_type ffi_type_void = {
5df07255
RH
66 1, 1, FFI_TYPE_VOID, NULL
67};
68
b1760f7f
RH
69FFI_TYPEDEF(uint8, UINT8, FFI_TYPE_UINT8, const);
70FFI_TYPEDEF(sint8, SINT8, FFI_TYPE_SINT8, const);
71FFI_TYPEDEF(uint16, UINT16, FFI_TYPE_UINT16, const);
72FFI_TYPEDEF(sint16, SINT16, FFI_TYPE_SINT16, const);
73FFI_TYPEDEF(uint32, UINT32, FFI_TYPE_UINT32, const);
74FFI_TYPEDEF(sint32, SINT32, FFI_TYPE_SINT32, const);
75FFI_TYPEDEF(uint64, UINT64, FFI_TYPE_UINT64, const);
76FFI_TYPEDEF(sint64, SINT64, FFI_TYPE_SINT64, const);
5df07255 77
b1760f7f 78FFI_TYPEDEF(pointer, void*, FFI_TYPE_POINTER, const);
5df07255 79
b1760f7f
RH
80FFI_TYPEDEF(float, float, FFI_TYPE_FLOAT, const);
81FFI_TYPEDEF(double, double, FFI_TYPE_DOUBLE, const);
82
83#if !defined HAVE_LONG_DOUBLE_VARIANT || defined __alpha__
84#define FFI_LDBL_CONST const
85#else
86#define FFI_LDBL_CONST
87#endif
bf8da5fc
RH
88
89#ifdef __alpha__
90/* Even if we're not configured to default to 128-bit long double,
91 maintain binary compatibility, as -mlong-double-128 can be used
92 at any time. */
93/* Validate the hard-coded number below. */
94# if defined(__LONG_DOUBLE_128__) && FFI_TYPE_LONGDOUBLE != 4
95# error FFI_TYPE_LONGDOUBLE out of date
96# endif
97const ffi_type ffi_type_longdouble = { 16, 16, 4, NULL };
98#elif FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
b1760f7f
RH
99FFI_TYPEDEF(longdouble, long double, FFI_TYPE_LONGDOUBLE, FFI_LDBL_CONST);
100#endif
101
102#ifdef FFI_TARGET_HAS_COMPLEX_TYPE
103FFI_COMPLEX_TYPEDEF(float, float, const);
104FFI_COMPLEX_TYPEDEF(double, double, const);
105#if FFI_TYPE_LONGDOUBLE != FFI_TYPE_DOUBLE
106FFI_COMPLEX_TYPEDEF(longdouble, long double, FFI_LDBL_CONST);
107#endif
bf8da5fc 108#endif