1 /* ISO_Fortran_binding.h of GCC's GNU Fortran compiler.
2 Copyright (C) 2013 Free Software Foundation, Inc.
4 This file is part of the GNU Fortran runtime library (libgfortran)
5 Libgfortran is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Library General Public
7 License as published by the Free Software Foundation; either
8 version 2 of the License, or (at your option) any later version.
10 Libgfortran is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Library General Public License for more details.
15 You should have received a copy of the GNU Library General Public
16 License along with libquadmath; see the file COPYING.LIB. If
17 not, write to the Free Software Foundation, Inc., 51 Franklin Street - Fifth Floor,
18 Boston, MA 02110-1301, USA. */
21 /* Definitions as defined by ISO/IEC Technical Specification TS 29113:2012
22 on Further Interoperability of Fortran with C.
23 Note: The technical specification only mandates the presence of certain
24 members; there might be additional compiler-specific fields. */
27 #ifndef ISO_FORTRAN_BINDING_H
28 #define ISO_FORTRAN_BINDING_H
34 #include <stddef.h> /* For size_t and ptrdiff_t. */
37 /* Constants, defined as macros. */
40 #define CFI_MAX_RANK 15
42 #define CFI_attribute_pointer 1
43 #define CFI_attribute_allocatable 2
44 #define CFI_attribute_other 3
47 /* FIXME: Those values have to match the compiler itself.
48 "NOTE 8.5: The specifiers for two intrinsic types can have the same value.
49 For example, CFI_type_int and CFI_type_int32_t might have the same value."
51 "The value for CFI_type_other shall be negative and distinct from all other
52 type specifiers. CFI_type_struct specifies a C structure that is
53 interoperable with a Fortran derived type; its value shall be positive and
54 distinct from all other type specifiers. If a C type is not interoperable
55 with a Fortran type and kind supported by the Fortran processor, its macro
56 shall evaluate to a negative value. Otherwise, the value for an intrinsic
57 type shall be positive." */
59 #define CFI_type_signed_char 1
60 #define CFI_type_short 2
61 #define CFI_type_int 3
62 #define CFI_type_long 4
63 #define CFI_type_long_long 5
64 #define CFI_type_size_t 6
65 #define CFI_type_int8_t 7
66 #define CFI_type_int16_t 8
67 #define CFI_type_int32_t 9
68 #define CFI_type_int64_t 10
69 #define CFI_type_int_least8_t 11
70 #define CFI_type_int_least16_t 12
71 #define CFI_type_int_least32_t 13
72 #define CFI_type_int_least64_t 14
73 #define CFI_type_int_fast8_t 15
74 #define CFI_type_int_fast16_t 16
75 #define CFI_type_int_fast32_t 17
76 #define CFI_type_int_fast64_t 18
77 #define CFI_type_intmax_t 19
78 #define CFI_type_intptr_t 20
79 #define CFI_type_ptrdiff_t 21
80 #define CFI_type_float 22
81 #define CFI_type_double 23
82 #define CFI_type_long_double 24
83 #define CFI_type_float_Complex 25
84 #define CFI_type_double_Complex 26
85 #define CFI_type_long_double_Complex 27
86 #define CFI_type_Bool 28
87 #define CFI_type_char 29
88 #define CFI_type_cptr 30
89 #define CFI_type_cfunptr 31
90 #define CFI_type_struct 32
91 #define CFI_type_other -5
94 #define CFI_ERROR_BASE_ADDR_NULL 1
95 #define CFI_ERROR_BASE_ADDR_NOT_NULL 2
96 #define CFI_INVALID_ELEM_LEN 3
97 #define CFI_INVALID_RANK 4
98 #define CFI_INVALID_TYPE 5
99 #define CFI_INVALID_ATTRIBUTE 6
100 #define CFI_INVALID_EXTENT 7
101 #define CFI_INVALID_DESCRIPTOR 8
102 #define CFI_ERROR_MEM_ALLOCATION 9
103 #define CFI_ERROR_OUT_OF_BOUNDS 10
106 /* Types definitions. */
108 typedef ptrdiff_t CFI_index_t;
109 typedef int32_t CFI_attribute_t;
110 typedef int32_t CFI_type_t;
111 typedef int CFI_rank_t;
113 typedef struct CFI_dim_t
115 CFI_index_t lower_bound;
121 typedef struct CFI_cdesc_t
128 CFI_attribute_t attribute;
129 /*FIXME: corank? Other information? Padding? Or not needed
131 CFI_dim_t dim[]; /* Must be last field */
136 /* gfortran extension: Type-specific array descriptor.
137 FIXME: Shall be the same as CFI_cdesc_t at the end. */
139 #define CFI_GFC_CDESC_T(r, type) \
150 #define CFI_CDESC_T(r) CFI_GFC_CDESC_T (r, void)
155 void *CFI_address (const CFI_cdesc_t *dv, const CFI_index_t subscripts[]);
156 int CFI_allocate (CFI_cdesc_t *dv, const CFI_index_t lower_bounds[],
157 const CFI_index_t upper_bounds[], size_t elem_len);
158 int CFI_deallocate (CFI_cdesc_t *dv);
159 int CFI_establish (CFI_cdesc_t *dv, void *base_addr, CFI_attribute_t attribute,
160 CFI_type_t type, size_t elem_len, CFI_rank_t rank,
161 const CFI_index_t extents[]);
162 int CFI_is_contiguous (const CFI_cdesc_t *dv);
163 int CFI_section (CFI_cdesc_t *result, const CFI_cdesc_t *source,
164 const CFI_index_t lower_bounds[],
165 const CFI_index_t upper_bounds[],
166 const CFI_index_t strides[]);
167 int CFI_select_part (CFI_cdesc_t *result, const CFI_cdesc_t *source,
168 size_t displacement, size_t elem_len);
169 int CFI_setpointer (CFI_cdesc_t *result, CFI_cdesc_t *source,
170 const CFI_index_t lower_bounds[]);
176 #endif /* ISO_FORTRAN_BINDING_H */