Add a directory forgotten in merge.
[official-gcc.git] / libgfortran / libgfortran.h
blob468776c802ff69a7fb92641a8928db6b61db8b17
1 /* Common declarations for all of libgfor.
2 Copyright 2002, 2003 Free Software Foundation, Inc.
3 Contributed by Paul Brook <paul@nowt.org>, and
4 Andy Vaught <andy@xena.eas.asu.edu>
6 This file is part of the GNU Fortran 95 runtime library (libgfor).
8 Libgfor is free software; you can redistribute it and/or
9 modify it under the terms of the GNU Lesser General Public
10 License as published by the Free Software Foundation; either
11 version 2.1 of the License, or (at your option) any later version.
13 Libgfor is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU Lesser General Public License for more details.
18 You should have received a copy of the GNU Lesser General Public
19 License along with libgfor; see the file COPYING.LIB. If not,
20 write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21 Boston, MA 02111-1307, USA. */
24 #ifndef LIBGFOR_H
25 #define LIBGFOR_H
27 #include <math.h>
28 #include <stddef.h>
30 #ifndef M_PI
31 #define M_PI 3.14159265358979323846264338327
32 #endif
34 #include "config.h"
36 #if HAVE_COMPLEX_H
37 # include <complex.h>
38 #else
39 #define complex __complex__
40 #endif
42 #if HAVE_STDINT_H
43 #include <stdint.h>
44 #endif
46 #if HAVE_SYS_TYPES_H
47 #include <sys/types.h>
48 #endif
49 typedef off_t offset_t;
51 #ifndef NULL
52 #define NULL (void *) 0
53 #endif
55 #ifndef __GNUC__
56 #define __attribute__(x)
57 #endif
59 /* For a library, a standard prefix is a requirement in order to
60 partition the namespace. It's ugly to look at and a pain to type,
61 so we hide it behind macros. */
62 #define prefix(x) _gfortran_ ## x
64 /* The only reliable way to get the offset of a field in a struct
65 in a system independent way is via this macro. */
66 #ifndef offsetof
67 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
68 #endif
70 /* TODO: find the C99 version of these an move into above ifdef. */
71 #define REALPART(z) (__real__(z))
72 #define IMAGPART(z) (__imag__(z))
73 #define COMPLEX_ASSIGN(z_, r_, i_) {__real__(z_) = (r_); __imag__(z_) = (i_);}
75 typedef int32_t GFC_INTEGER_4;
76 typedef int64_t GFC_INTEGER_8;
77 typedef uint32_t GFC_UINTEGER_4;
78 typedef uint64_t GFC_UINTEGER_8;
79 typedef GFC_INTEGER_4 GFC_LOGICAL_4;
80 typedef GFC_INTEGER_8 GFC_LOGICAL_8;
81 typedef float GFC_REAL_4;
82 typedef double GFC_REAL_8;
83 typedef complex float GFC_COMPLEX_4;
84 typedef complex double GFC_COMPLEX_8;
86 typedef size_t index_type;
88 /* This will be 0 on little-endian machines and one on big-endian machines. */
89 #define l8_to_l4_offset prefix(l8_to_l4_offset)
90 extern int l8_to_l4_offset;
92 #define GFOR_POINTER_L8_TO_L4(p8) \
93 (l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))
95 #define GFC_INTEGER_4_HUGE \
96 (GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
97 #define GFC_INTEGER_8_HUGE \
98 (GFC_INTEGER_8)((((GFC_UINTEGER_8)1) << 63) - 1)
99 #define GFC_REAL_4_HUGE FLT_MAX
100 #define GFC_REAL_8_HUGE DBL_MAX
102 #ifndef GFC_MAX_DIMENSIONS
103 #define GFC_MAX_DIMENSIONS 7
104 #endif
106 typedef struct descriptor_dimension
108 index_type stride;
109 index_type lbound;
110 index_type ubound;
112 descriptor_dimension;
114 #define GFC_ARRAY_DESCRIPTOR(r, type) \
115 struct {\
116 type *data;\
117 type *base;\
118 index_type dtype;\
119 descriptor_dimension dim[r];\
122 /* Commonly used array descriptor types. */
123 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void;
124 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char;
125 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_array_i4;
126 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_8) gfc_array_i8;
127 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_4) gfc_array_r4;
128 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_8) gfc_array_r8;
129 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_4) gfc_array_c4;
130 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_8) gfc_array_c8;
131 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_4) gfc_array_l4;
132 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_8) gfc_array_l8;
134 #define GFC_DTYPE_RANK_MASK 0x07
135 #define GFC_DTYPE_TYPE_SHIFT 3
136 #define GFC_DTYPE_TYPE_MASK 0x38
137 #define GFC_DTYPE_SIZE_SHIFT 6
139 enum
141 GFC_DTYPE_UNKNOWN = 0,
142 GFC_DTYPE_INTEGER,
143 /* TODO: recognize logical types. */
144 GFC_DTYPE_LOGICAL,
145 GFC_DTYPE_REAL,
146 GFC_DTYPE_COMPLEX,
147 GFC_DTYPE_DERIVED,
148 GFC_DTYPE_CHARACTER
151 #define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
152 #define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
153 >> GFC_DTYPE_TYPE_SHIFT)
154 #define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
155 #define GFC_DESCRIPTOR_DATA(desc) ((desc)->data)
156 #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype)
158 /* Runtime library include. */
159 #define stringize(x) expand_macro(x)
160 #define expand_macro(x) # x
162 /* Runtime options structure. */
164 typedef struct
166 int stdin_unit, stdout_unit, optional_plus;
167 int allocate_init_flag, allocate_init_value;
168 int locus;
170 int separator_len;
171 const char *separator;
173 int mem_check;
174 int use_stderr, all_unbuffered, default_recl;
176 int fpu_round, fpu_precision, fpu_invalid, fpu_denormal, fpu_zerodiv,
177 fpu_overflow, fpu_underflow, fpu_precision_loss;
179 int sighup, sigint;
181 options_t;
184 #define options prefix(options)
185 extern options_t options;
188 /* Structure for statement options. */
190 typedef struct
192 const char *name;
193 int value;
195 st_option;
197 /* Runtime errors. The EOR and EOF errors are required to be negative. */
199 typedef enum
201 ERROR_FIRST = -3, /* Marker for the first error. */
202 ERROR_EOR = -2,
203 ERROR_END = -1,
204 ERROR_OK = 0, /* Indicates success, must be zero. */
205 ERROR_OS, /* Operating system error, more info in errno. */
206 ERROR_OPTION_CONFLICT,
207 ERROR_BAD_OPTION,
208 ERROR_MISSING_OPTION,
209 ERROR_ALREADY_OPEN,
210 ERROR_BAD_UNIT,
211 ERROR_FORMAT,
212 ERROR_BAD_ACTION,
213 ERROR_ENDFILE,
214 ERROR_BAD_US,
215 ERROR_READ_VALUE,
216 ERROR_READ_OVERFLOW,
217 ERROR_LAST /* Not a real error, the last error # + 1. */
219 error_codes;
222 /* The filename and line number don't go inside the globals structure.
223 They are set by the rest of the program and must be linked to. */
225 #define line prefix(line)
226 extern unsigned line; /* Location of the current libray call (optional). */
228 #define filename prefix(filename)
229 extern char *filename;
232 /* main.c */
234 #define library_start prefix(library_start)
235 void library_start (void);
237 #define library_end prefix(library_end)
238 void library_end (void);
240 #define set_args prefix(set_args)
241 void set_args (int, char **);
243 #define get_args prefix(get_args)
244 void get_args (int *, char ***);
247 /* error.c */
248 #define rtoa prefix(rtoa)
249 char *rtoa (double f, int length, int oprec);
251 #define itoa prefix(itoa)
252 char *itoa (int64_t);
254 #define xtoa prefix(xtoa)
255 char *xtoa (uint64_t);
257 #define os_error prefix(os_error)
258 void os_error (const char *) __attribute__ ((noreturn));
260 #define show_locus prefix(show_locus)
261 void show_locus (void);
263 #define runtime_error prefix(runtime_error)
264 void runtime_error (const char *) __attribute__ ((noreturn));
266 #define internal_error prefix(internal_error)
267 void internal_error (const char *) __attribute__ ((noreturn));
269 #define get_oserror prefix(get_oserror)
270 const char *get_oserror (void);
272 #define write_error prefix(write_error)
273 void write_error (const char *);
275 #define sys_exit prefix(sys_exit)
276 void sys_exit (int) __attribute__ ((noreturn));
278 #define st_printf prefix(st_printf)
279 int st_printf (const char *, ...) __attribute__ ((format (printf, 1, 2)));
281 #define st_sprintf prefix(st_sprintf)
282 void st_sprintf (char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
284 #define translate_error prefix(translate_error)
285 const char *translate_error (int);
287 #define generate_error prefix(generate_error)
288 void generate_error (int, const char *);
291 /* memory.c */
293 #define memory_init prefix(memory_init)
294 void memory_init (void);
296 #define runtime_cleanup prefix(runtime_cleanup)
297 void runtime_cleanup (void);
299 #define get_mem prefix(get_mem)
300 void *get_mem (size_t) __attribute__ ((malloc));
302 #define free_mem prefix(free_mem)
303 void free_mem (void *);
305 #define internal_malloc_size prefix(internal_malloc_size)
306 void internal_malloc_size (void **, size_t);
308 #define internal_malloc prefix(internal_malloc)
309 void internal_malloc (void **, GFC_INTEGER_4);
311 #define internal_malloc64 prefix(internal_malloc64)
312 void internal_malloc64 (void **, GFC_INTEGER_8);
314 #define internal_free prefix(internal_free)
315 void internal_free (void **);
317 #define push_context prefix(push_context)
318 void push_context (void);
320 #define pop_context prefix(pop_context)
321 void pop_context (void);
323 #define allocate prefix(allocate)
324 void allocate (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
326 #define allocate64 prefix(allocate64)
327 void allocate64 (void **, GFC_INTEGER_8, GFC_INTEGER_4 *);
329 #define deallocate prefix(deallocate)
330 void deallocate (void **, GFC_INTEGER_4 *);
333 /* environ.c */
335 #define check_buffered prefix(check_buffered)
336 int check_buffered (int);
338 #define init_variables prefix(init_variables)
339 void init_variables (void);
341 #define show_variables prefix(show_variables)
342 void show_variables (void);
345 /* string.c */
347 #define find_option prefix(find_option)
348 int find_option (const char *, int, st_option *, const char *);
350 #define fstrlen prefix(fstrlen)
351 int fstrlen (const char *, int);
353 #define fstrcpy prefix(fstrcpy)
354 void fstrcpy (char *, int, const char *, int);
356 #define cf_strcpy prefix(cf_strcpy)
357 void cf_strcpy (char *, int, const char *);
359 /* io.c */
361 #define init_units prefix(init_units)
362 void init_units (void);
364 #define close_units prefix(close_units)
365 void close_units (void);
367 /* stop.c */
368 #define stop_numeric prefix(stop_numeric)
369 void stop_numeric (GFC_INTEGER_4);
371 /* reshape_packed.c */
372 #define reshape_packed prefix(reshape_packed)
373 void reshape_packed (char *, index_type, const char *, index_type,
374 const char *, index_type);
376 /* Repacking functions. */
377 #define internal_pack prefix(internal_pack)
378 void *internal_pack (gfc_array_char *);
380 #define internal_unpack prefix(internal_unpack)
381 void internal_unpack (gfc_array_char *, const void *);
383 #define internal_pack_4 prefix(internal_pack_4)
384 GFC_INTEGER_4 *internal_pack_4 (gfc_array_i4 *);
386 #define internal_pack_8 prefix(internal_pack_8)
387 GFC_INTEGER_8 *internal_pack_8 (gfc_array_i8 *);
389 #define internal_unpack_4 prefix(internal_unpack_4)
390 void internal_unpack_4 (gfc_array_i4 *, const GFC_INTEGER_4 *);
392 #define internal_unpack_8 prefix(internal_unpack_8)
393 void internal_unpack_8 (gfc_array_i8 *, const GFC_INTEGER_8 *);
395 /* string_intrinsics.c */
397 #define compare_string prefix(compare_string)
398 GFC_INTEGER_4 compare_string (GFC_INTEGER_4, const char *,
399 GFC_INTEGER_4, const char *);
401 #endif