Add support for 32-bit hppa targets in muldi3 expander
[official-gcc.git] / libgfortran / ISO_Fortran_binding.h
blobd431d09e61ba9f297b812df7d359d6bca35668cd
1 /* Declarations for ISO Fortran binding.
2 Copyright (C) 2018-2021 Free Software Foundation, Inc.
3 Contributed by Daniel Celis Garza <celisdanieljr@gmail.com>
5 This file is part of the GNU Fortran runtime library (libgfortran).
7 Libgfortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3, or (at your option)
10 any later version.
12 Libgfortran is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
26 #ifndef ISO_FORTRAN_BINDING_H
27 #define ISO_FORTRAN_BINDING_H
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #include <stddef.h> /* Standard ptrdiff_t tand size_t. */
34 #include <stdint.h> /* Integer types. */
36 /* Constants, defined as macros. */
37 #define CFI_VERSION 1
38 #define CFI_MAX_RANK 15
40 /* Attributes. */
41 #define CFI_attribute_pointer 0
42 #define CFI_attribute_allocatable 1
43 #define CFI_attribute_other 2
45 /* Error codes.
46 Note that CFI_FAILURE and CFI_INVALID_STRIDE are specific to GCC
47 and not part of the Fortran standard */
48 #define CFI_SUCCESS 0
49 #define CFI_FAILURE 1
50 #define CFI_ERROR_BASE_ADDR_NULL 2
51 #define CFI_ERROR_BASE_ADDR_NOT_NULL 3
52 #define CFI_INVALID_ELEM_LEN 4
53 #define CFI_INVALID_RANK 5
54 #define CFI_INVALID_TYPE 6
55 #define CFI_INVALID_ATTRIBUTE 7
56 #define CFI_INVALID_EXTENT 8
57 #define CFI_INVALID_STRIDE 9
58 #define CFI_INVALID_DESCRIPTOR 10
59 #define CFI_ERROR_MEM_ALLOCATION 11
60 #define CFI_ERROR_OUT_OF_BOUNDS 12
62 /* CFI type definitions. */
63 typedef ptrdiff_t CFI_index_t;
64 typedef int8_t CFI_rank_t;
65 typedef int8_t CFI_attribute_t;
66 typedef int16_t CFI_type_t;
68 /* CFI_dim_t. */
69 typedef struct CFI_dim_t
71 CFI_index_t lower_bound;
72 CFI_index_t extent;
73 CFI_index_t sm;
75 CFI_dim_t;
77 /* CFI_cdesc_t, C descriptors are cast to this structure as follows:
78 CFI_CDESC_T(CFI_MAX_RANK) foo;
79 CFI_cdesc_t * bar = (CFI_cdesc_t *) &foo;
81 typedef struct CFI_cdesc_t
83 void *base_addr;
84 size_t elem_len;
85 int version;
86 CFI_rank_t rank;
87 CFI_attribute_t attribute;
88 CFI_type_t type;
89 CFI_dim_t dim[];
91 CFI_cdesc_t;
93 /* CFI_CDESC_T with an explicit type. */
94 #define CFI_CDESC_TYPE_T(r, base_type) \
95 struct { \
96 base_type *base_addr; \
97 size_t elem_len; \
98 int version; \
99 CFI_rank_t rank; \
100 CFI_attribute_t attribute; \
101 CFI_type_t type; \
102 CFI_dim_t dim[r]; \
104 #define CFI_CDESC_T(r) CFI_CDESC_TYPE_T (r, void)
106 /* CFI function declarations. */
107 extern void *CFI_address (const CFI_cdesc_t *, const CFI_index_t []);
108 extern int CFI_allocate (CFI_cdesc_t *, const CFI_index_t [], const CFI_index_t [],
109 size_t);
110 extern int CFI_deallocate (CFI_cdesc_t *);
111 extern int CFI_establish (CFI_cdesc_t *, void *, CFI_attribute_t, CFI_type_t, size_t,
112 CFI_rank_t, const CFI_index_t []);
113 extern int CFI_is_contiguous (const CFI_cdesc_t *);
114 extern int CFI_section (CFI_cdesc_t *, const CFI_cdesc_t *, const CFI_index_t [],
115 const CFI_index_t [], const CFI_index_t []);
116 extern int CFI_select_part (CFI_cdesc_t *, const CFI_cdesc_t *, size_t, size_t);
117 extern int CFI_setpointer (CFI_cdesc_t *, CFI_cdesc_t *, const CFI_index_t []);
119 /* Types and kind numbers. Allows bitwise and to reveal the intrinsic type of a kind type. It also allows us to find the kind parameter by inverting the bit-shift equation.
120 CFI_type_kind_shift = 8
121 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
122 CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0
123 CFI_type_example = CFI_intrinsic_type + (CFI_type_kind << CFI_type_kind_shift)
124 Defining the CFI_type_example.
125 CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0 << CFI_type_kind_shift
126 -------------------------
127 1 0 0 0 0 0 0 0 0 0 0 0 +
128 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
129 -------------------------
130 CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0
131 Finding the intrinsic type with the logical mask.
132 CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 &
133 CFI_type_mask = 0 0 0 0 1 1 1 1 1 1 1 1
134 -------------------------
135 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
136 Using the intrinsic type and kind shift to find the kind value of the type.
137 CFI_type_kind = (CFI_type_example - CFI_intrinsic_type) >> CFI_type_kind_shift
138 CFI_type_example = 1 0 0 0 0 0 0 0 0 0 1 0 -
139 CFI_intrinsic_type = 0 0 0 0 0 0 0 0 0 0 1 0
140 -------------------------
141 1 0 0 0 0 0 0 0 0 0 0 0 >> CFI_type_kind_shift
142 -------------------------
143 CFI_type_kind = 0 0 0 0 0 0 0 0 1 0 0 0
145 #define CFI_type_mask 0xFF
146 #define CFI_type_kind_shift 8
148 /* Intrinsic types. Their kind number defines their storage size. */
149 #define CFI_type_Integer 1
150 #define CFI_type_Logical 2
151 #define CFI_type_Real 3
152 #define CFI_type_Complex 4
153 #define CFI_type_Character 5
155 /* Types with no kind. FIXME: GFC descriptors currently use BT_VOID for
156 both C_PTR and C_FUNPTR, so we have no choice but to make them
157 identical here too. That can potentially break on targets where
158 function and data pointers have different sizes/representations.
159 See PR 100915. */
160 #define CFI_type_struct 6
161 #define CFI_type_cptr 7
162 #define CFI_type_cfunptr CFI_type_cptr
163 #define CFI_type_other -1
165 /* Types with kind parameter.
166 The kind parameter represents the type's byte size. The exception is
167 real kind = 10, which has byte size of 128 bits but 80 bit precision.
168 Complex variables are double the byte size of their real counterparts.
169 The ucs4_char matches wchar_t if sizeof (wchar_t) == 4.
171 #define CFI_type_char (CFI_type_Character + (1 << CFI_type_kind_shift))
172 #define CFI_type_ucs4_char (CFI_type_Character + (4 << CFI_type_kind_shift))
174 /* C-Fortran Interoperability types. */
175 #define CFI_type_signed_char (CFI_type_Integer + (sizeof (char) << CFI_type_kind_shift))
176 #define CFI_type_short (CFI_type_Integer + (sizeof (short) << CFI_type_kind_shift))
177 #define CFI_type_int (CFI_type_Integer + (sizeof (int) << CFI_type_kind_shift))
178 #define CFI_type_long (CFI_type_Integer + (sizeof (long) << CFI_type_kind_shift))
179 #define CFI_type_long_long (CFI_type_Integer + (sizeof (long long) << CFI_type_kind_shift))
180 #define CFI_type_size_t (CFI_type_Integer + (sizeof (size_t) << CFI_type_kind_shift))
181 #define CFI_type_int8_t (CFI_type_Integer + (sizeof (int8_t) << CFI_type_kind_shift))
182 #define CFI_type_int16_t (CFI_type_Integer + (sizeof (int16_t) << CFI_type_kind_shift))
183 #define CFI_type_int32_t (CFI_type_Integer + (sizeof (int32_t) << CFI_type_kind_shift))
184 #define CFI_type_int64_t (CFI_type_Integer + (sizeof (int64_t) << CFI_type_kind_shift))
185 #define CFI_type_int_least8_t (CFI_type_Integer + (sizeof (int_least8_t) << CFI_type_kind_shift))
186 #define CFI_type_int_least16_t (CFI_type_Integer + (sizeof (int_least16_t) << CFI_type_kind_shift))
187 #define CFI_type_int_least32_t (CFI_type_Integer + (sizeof (int_least32_t) << CFI_type_kind_shift))
188 #define CFI_type_int_least64_t (CFI_type_Integer + (sizeof (int_least64_t) << CFI_type_kind_shift))
189 #define CFI_type_int_fast8_t (CFI_type_Integer + (sizeof (int_fast8_t) << CFI_type_kind_shift))
190 #define CFI_type_int_fast16_t (CFI_type_Integer + (sizeof (int_fast16_t) << CFI_type_kind_shift))
191 #define CFI_type_int_fast32_t (CFI_type_Integer + (sizeof (int_fast32_t) << CFI_type_kind_shift))
192 #define CFI_type_int_fast64_t (CFI_type_Integer + (sizeof (int_fast64_t) << CFI_type_kind_shift))
193 #define CFI_type_intmax_t (CFI_type_Integer + (sizeof (intmax_t) << CFI_type_kind_shift))
194 #define CFI_type_intptr_t (CFI_type_Integer + (sizeof (intptr_t) << CFI_type_kind_shift))
195 #define CFI_type_ptrdiff_t (CFI_type_Integer + (sizeof (ptrdiff_t) << CFI_type_kind_shift))
196 #define CFI_type_Bool (CFI_type_Logical + (sizeof (_Bool) << CFI_type_kind_shift))
197 #define CFI_type_float (CFI_type_Real + (sizeof (float) << CFI_type_kind_shift))
198 #define CFI_type_double (CFI_type_Real + (sizeof (double) << CFI_type_kind_shift))
199 #define CFI_type_float_Complex (CFI_type_Complex + (sizeof (float) << CFI_type_kind_shift))
200 #define CFI_type_double_Complex (CFI_type_Complex + (sizeof (double) << CFI_type_kind_shift))
202 /* If GCC supports int128_t on this target, it predefines
203 __SIZEOF_INT128__ to 16. */
204 #if defined(__SIZEOF_INT128__)
205 #if (__SIZEOF_INT128__ == 16)
206 #define CFI_type_int128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
207 #define CFI_type_int_least128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
208 #define CFI_type_int_fast128_t (CFI_type_Integer + (16 << CFI_type_kind_shift))
209 #else
210 #error "Can't determine kind of int128_t"
211 #endif
212 #else
213 #define CFI_type_int128_t -2
214 #define CFI_type_int_least128_t -2
215 #define CFI_type_int_fast128_t -2
216 #endif
218 /* The situation with long double support is more complicated; we need to
219 examine the type in more detail to figure out its kind.
220 GCC and some other compilers predefine the __LDBL* macros; otherwise
221 get the parameters we need from float.h. */
223 #if (defined (__LDBL_MANT_DIG__) \
224 && defined (__LDBL_MIN_EXP__) \
225 && defined (__LDBL_MAX_EXP__) \
226 && defined (__DBL_MANT_DIG__) \
227 && defined (__DBL_MIN_EXP__) \
228 && defined (__DBL_MAX_EXP__))
229 #define __CFI_LDBL_MANT_DIG__ __LDBL_MANT_DIG__
230 #define __CFI_LDBL_MIN_EXP__ __LDBL_MIN_EXP__
231 #define __CFI_LDBL_MAX_EXP__ __LDBL_MAX_EXP__
232 #define __CFI_DBL_MANT_DIG__ __DBL_MANT_DIG__
233 #define __CFI_DBL_MIN_EXP__ __DBL_MIN_EXP__
234 #define __CFI_DBL_MAX_EXP__ __DBL_MAX_EXP__
236 #else
237 #include <float.h>
239 #if (defined (LDBL_MANT_DIG) \
240 && defined (LDBL_MIN_EXP) \
241 && defined (LDBL_MAX_EXP) \
242 && defined (DBL_MANT_DIG) \
243 && defined (DBL_MIN_EXP) \
244 && defined (DBL_MAX_EXP))
245 #define __CFI_LDBL_MANT_DIG__ LDBL_MANT_DIG
246 #define __CFI_LDBL_MIN_EXP__ LDBL_MIN_EXP
247 #define __CFI_LDBL_MAX_EXP__ LDBL_MAX_EXP
248 #define __CFI_DBL_MANT_DIG__ DBL_MANT_DIG
249 #define __CFI_DBL_MIN_EXP__ DBL_MIN_EXP
250 #define __CFI_DBL_MAX_EXP__ DBL_MAX_EXP
252 #else
253 #define CFI_no_long_double 1
255 #endif /* Definitions from float.h. */
256 #endif /* Definitions from compiler builtins. */
258 /* Can't determine anything about long double support? */
259 #if (defined (CFI_no_long_double))
260 #define CFI_type_long_double -2
261 #define CFI_type_long_double_Complex -2
263 /* Long double is the same kind as double. */
264 #elif (__CFI_LDBL_MANT_DIG__ == __CFI_DBL_MANT_DIG__ \
265 && __CFI_LDBL_MIN_EXP__ == __CFI_DBL_MIN_EXP__ \
266 && __CFI_LDBL_MAX_EXP__ == __CFI_DBL_MAX_EXP__)
267 #define CFI_type_long_double CFI_type_double
268 #define CFI_type_long_double_Complex CFI_type_double_Complex
270 /* This is the 80-bit encoding on x86; Fortran assigns it kind 10. */
271 #elif ((__CFI_LDBL_MANT_DIG__ == 64 || __CFI_LDBL_MANT_DIG__ == 53) \
272 && __CFI_LDBL_MIN_EXP__ == -16381 \
273 && __CFI_LDBL_MAX_EXP__ == 16384)
274 #define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift))
275 #define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift))
277 /* This is the 96-bit encoding on m68k; Fortran assigns it kind 10. */
278 #elif (__CFI_LDBL_MANT_DIG__ == 64 \
279 && __CFI_LDBL_MIN_EXP__ == -16382 \
280 && __CFI_LDBL_MAX_EXP__ == 16384)
281 #define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift))
282 #define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift))
284 /* This is the IEEE 128-bit encoding, same as _Float128. */
285 #elif (__CFI_LDBL_MANT_DIG__ == 113 \
286 && __CFI_LDBL_MIN_EXP__ == -16381 \
287 && __CFI_LDBL_MAX_EXP__ == 16384)
288 #define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift))
289 #define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
291 /* This is the IBM128 encoding used on PowerPC; also assigned kind 16. */
292 #elif (__CFI_LDBL_MANT_DIG__ == 106 \
293 && __CFI_LDBL_MIN_EXP__ == -968 \
294 && __CFI_LDBL_MAX_EXP__ == 1024)
295 #define CFI_type_long_double (CFI_type_Real + (16 << CFI_type_kind_shift))
296 #define CFI_type_long_double_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
297 #define CFI_no_float128 1
299 /* It's a bug if we get here. If you've got a target that has some other
300 long double encoding, you need add something here for Fortran to
301 recognize it. */
302 #else
303 #error "Can't determine kind of long double"
304 #endif
306 /* Similarly for _Float128. This always refers to the IEEE encoding
307 and not some other 128-bit representation, so if we already used
308 kind 16 for a non-IEEE representation, this one must be unsupported
309 in Fortran even if it's available in C. */
310 #if (!defined (CFI_no_float128) \
311 && defined(__FLT128_MANT_DIG__) && __FLT128_MANT_DIG__ == 113 \
312 && defined(__FLT128_MIN_EXP__) && __FLT128_MIN_EXP__ == -16381 \
313 && defined(__FLT128_MAX_EXP__) && __FLT128_MAX_EXP__ == 16384)
314 #define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift))
315 #define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift))
316 #else
317 #define CFI_type_float128 -2
318 #define CFI_type_float128_Complex -2
319 #endif
321 #ifdef __cplusplus
323 #endif
325 #endif /* ISO_FORTRAN_BINDING_H */