]>
Commit | Line | Data |
---|---|---|
bbf18dc5 | 1 | /* Declarations for ISO Fortran binding. |
99dee823 | 2 | Copyright (C) 2018-2021 Free Software Foundation, Inc. |
bbf18dc5 PT |
3 | Contributed by Daniel Celis Garza <celisdanieljr@gmail.com> |
4 | ||
5 | This file is part of the GNU Fortran runtime library (libgfortran). | |
6 | ||
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. | |
11 | ||
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. | |
16 | ||
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. | |
20 | ||
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/>. */ | |
25 | ||
26 | #ifndef ISO_FORTRAN_BINDING_H | |
27 | #define ISO_FORTRAN_BINDING_H | |
28 | ||
29 | #ifdef __cplusplus | |
30 | extern "C" { | |
31 | #endif | |
32 | ||
33 | #include <stddef.h> /* Standard ptrdiff_t tand size_t. */ | |
34 | #include <stdint.h> /* Integer types. */ | |
35 | ||
36 | /* Constants, defined as macros. */ | |
37 | #define CFI_VERSION 1 | |
38 | #define CFI_MAX_RANK 15 | |
39 | ||
40 | /* Attributes. */ | |
41 | #define CFI_attribute_pointer 0 | |
42 | #define CFI_attribute_allocatable 1 | |
43 | #define CFI_attribute_other 2 | |
44 | ||
45 | /* Error codes. | |
46 | CFI_INVALID_STRIDE should be defined in the standard because they are useful to the implementation of the functions. | |
47 | */ | |
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 | |
61 | ||
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; | |
67 | ||
68 | /* CFI_dim_t. */ | |
69 | typedef struct CFI_dim_t | |
70 | { | |
71 | CFI_index_t lower_bound; | |
72 | CFI_index_t extent; | |
73 | CFI_index_t sm; | |
74 | } | |
75 | CFI_dim_t; | |
76 | ||
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; | |
80 | */ | |
81 | typedef struct CFI_cdesc_t | |
82 | { | |
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[]; | |
90 | } | |
91 | CFI_cdesc_t; | |
92 | ||
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]; \ | |
103 | } | |
104 | #define CFI_CDESC_T(r) CFI_CDESC_TYPE_T (r, void) | |
105 | ||
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 []); | |
118 | ||
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 | |
144 | */ | |
145 | #define CFI_type_mask 0xFF | |
146 | #define CFI_type_kind_shift 8 | |
147 | ||
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 | |
154 | ||
155 | /* Types with no kind. */ | |
156 | #define CFI_type_struct 6 | |
157 | #define CFI_type_cptr 7 | |
158 | #define CFI_type_cfunptr 8 | |
159 | #define CFI_type_other -1 | |
160 | ||
161 | /* Types with kind parameter. | |
162 | The kind parameter represents the type's byte size. The exception is kind = 10, which has byte size of 64 but 80 bit precision. Complex variables are double the byte size of their real counterparts. The ucs4_char matches wchar_t if sizeof (wchar_t) == 4. | |
163 | */ | |
164 | #define CFI_type_char (CFI_type_Character + (1 << CFI_type_kind_shift)) | |
165 | #define CFI_type_ucs4_char (CFI_type_Character + (4 << CFI_type_kind_shift)) | |
166 | ||
167 | /* C-Fortran Interoperability types. */ | |
168 | #define CFI_type_signed_char (CFI_type_Integer + (1 << CFI_type_kind_shift)) | |
169 | #define CFI_type_short (CFI_type_Integer + (2 << CFI_type_kind_shift)) | |
170 | #define CFI_type_int (CFI_type_Integer + (4 << CFI_type_kind_shift)) | |
171 | #define CFI_type_long (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
172 | #define CFI_type_long_long (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
173 | #define CFI_type_size_t (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
174 | #define CFI_type_int8_t (CFI_type_Integer + (1 << CFI_type_kind_shift)) | |
175 | #define CFI_type_int16_t (CFI_type_Integer + (2 << CFI_type_kind_shift)) | |
176 | #define CFI_type_int32_t (CFI_type_Integer + (4 << CFI_type_kind_shift)) | |
177 | #define CFI_type_int64_t (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
178 | #define CFI_type_int_least8_t (CFI_type_Integer + (1 << CFI_type_kind_shift)) | |
179 | #define CFI_type_int_least16_t (CFI_type_Integer + (2 << CFI_type_kind_shift)) | |
180 | #define CFI_type_int_least32_t (CFI_type_Integer + (4 << CFI_type_kind_shift)) | |
181 | #define CFI_type_int_least64_t (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
182 | #define CFI_type_int_fast8_t (CFI_type_Integer + (1 << CFI_type_kind_shift)) | |
183 | #define CFI_type_int_fast16_t (CFI_type_Integer + (2 << CFI_type_kind_shift)) | |
184 | #define CFI_type_int_fast32_t (CFI_type_Integer + (4 << CFI_type_kind_shift)) | |
185 | #define CFI_type_int_fast64_t (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
186 | #define CFI_type_intmax_t (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
187 | #define CFI_type_intptr_t (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
188 | #define CFI_type_ptrdiff_t (CFI_type_Integer + (8 << CFI_type_kind_shift)) | |
189 | #define CFI_type_int128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) | |
190 | #define CFI_type_int_least128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) | |
191 | #define CFI_type_int_fast128_t (CFI_type_Integer + (16 << CFI_type_kind_shift)) | |
192 | #define CFI_type_Bool (CFI_type_Logical + (1 << CFI_type_kind_shift)) | |
193 | #define CFI_type_float (CFI_type_Real + (4 << CFI_type_kind_shift)) | |
194 | #define CFI_type_double (CFI_type_Real + (8 << CFI_type_kind_shift)) | |
195 | #define CFI_type_long_double (CFI_type_Real + (10 << CFI_type_kind_shift)) | |
196 | #define CFI_type_float128 (CFI_type_Real + (16 << CFI_type_kind_shift)) | |
197 | #define CFI_type_float_Complex (CFI_type_Complex + (4 << CFI_type_kind_shift)) | |
198 | #define CFI_type_double_Complex (CFI_type_Complex + (8 << CFI_type_kind_shift)) | |
199 | #define CFI_type_long_double_Complex (CFI_type_Complex + (10 << CFI_type_kind_shift)) | |
200 | #define CFI_type_float128_Complex (CFI_type_Complex + (16 << CFI_type_kind_shift)) | |
201 | ||
202 | #ifdef __cplusplus | |
203 | } | |
204 | #endif | |
205 | ||
206 | #endif /* ISO_FORTRAN_BINDING_H */ |