2013-04-01 Tobias Burnus <burnus@net-b.de>
[gcc.git] / libgfortran / ISO_Fortran_binding.h
1 /* ISO_Fortran_binding.h of GCC's GNU Fortran compiler.
2    Copyright (C) 2013 Free Software Foundation, Inc.
3
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.
9
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.
14
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.  */
19
20
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.  */
25
26
27 #ifndef ISO_FORTRAN_BINDING_H
28 #define ISO_FORTRAN_BINDING_H
29
30 #ifdef __cplusplus
31 extern "C" {
32 #endif
33
34 #include <stddef.h>  /* For size_t and ptrdiff_t.  */
35
36
37 /* Constants, defined as macros.  */
38
39 #define CFI_VERSION 1
40 #define CFI_MAX_RANK 15
41
42 #define CFI_attribute_pointer 1
43 #define CFI_attribute_allocatable 2
44 #define CFI_attribute_other 3
45
46
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."
50
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."  */
58
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
92
93 #define CFI_SUCCESS 0
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
104
105
106 /* Types definitions.  */
107
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;
112
113 typedef struct CFI_dim_t
114 {
115   CFI_index_t lower_bound;
116   CFI_index_t extent;
117   CFI_index_t sm;
118 }
119 CFI_dim_t;
120
121 typedef struct CFI_cdesc_t
122 {
123   void *base_addr;
124   size_t elem_len;
125   int version;
126   CFI_rank_t rank;
127   CFI_type_t type;
128   CFI_attribute_t attribute;
129   /*FIXME: corank? Other information? Padding? Or not needed
130     due to "version"?  */
131   CFI_dim_t dim[]; /* Must be last field */
132 }
133 CFI_cdesc_t;
134
135
136 /* gfortran extension: Type-specific array descriptor.
137    FIXME: Shall be the same as CFI_cdesc_t at the end.  */
138
139 #define CFI_GFC_CDESC_T(r, type) \
140 struct {\
141   type *base_addr;\
142   size_t elem_len;\
143   int version; \
144   CFI_rank_t rank; \
145   size_t offset;\
146   CFI_index_t dtype;\
147   CFI_dim_t dim[r];\
148 }
149
150 #define CFI_CDESC_T(r) CFI_GFC_CDESC_T (r, void)
151
152
153 /* Functions. */
154
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[]);
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif  /* ISO_FORTRAN_BINDING_H */