1 /* Common declarations for all of libgfor.
2 Copyright (C) 2002, 2003, 2004 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. */
31 #define M_PI 3.14159265358979323846264338327
35 #include "c99_protos.h"
40 #define complex __complex__
55 #if !defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H) && defined(TARGET_ILP32)
57 typedef short int16_t;
59 typedef long long int64_t;
60 typedef unsigned char uint8_t;
61 typedef unsigned short uint16_t;
62 typedef unsigned int uint32_t;
63 typedef unsigned long long uint64_t;
67 #include <sys/types.h>
69 typedef off_t gfc_offset;
72 #define NULL (void *) 0
76 #define __attribute__(x)
79 /* For a library, a standard prefix is a requirement in order to
80 partition the namespace. It's ugly to look at and a pain to type,
81 so we hide it behind macros. */
82 #define prefix(x) _gfortran_ ## x
84 /* The only reliable way to get the offset of a field in a struct
85 in a system independent way is via this macro. */
87 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
90 /* The isfinite macro is only available with C99, but some non-C99
91 systems still provide fpclassify, and there is a `finite' function
92 in BSD. When isfinite is not available, try to use one of the
93 alternatives, or bail out. */
94 #if !defined(isfinite)
98 #if defined(fpclassify)
99 return (fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE);
100 #elif defined(HAVE_FINITE)
103 #error "libgfortran needs isfinite, fpclassify, or finite"
106 #endif /* !defined(isfinite) */
108 /* TODO: find the C99 version of these an move into above ifdef. */
109 #define REALPART(z) (__real__(z))
110 #define IMAGPART(z) (__imag__(z))
111 #define COMPLEX_ASSIGN(z_, r_, i_) {__real__(z_) = (r_); __imag__(z_) = (i_);}
113 typedef int32_t GFC_INTEGER_4;
114 typedef int64_t GFC_INTEGER_8;
115 typedef uint32_t GFC_UINTEGER_4;
116 typedef uint64_t GFC_UINTEGER_8;
117 typedef GFC_INTEGER_4 GFC_LOGICAL_4;
118 typedef GFC_INTEGER_8 GFC_LOGICAL_8;
119 typedef float GFC_REAL_4;
120 typedef double GFC_REAL_8;
121 typedef complex float GFC_COMPLEX_4;
122 typedef complex double GFC_COMPLEX_8;
124 /* The following two definitions must be consistent with the types used
126 /* The type used of array indices, amongst other things. */
127 typedef size_t index_type;
128 /* The type used for the lengths of character variables. */
129 typedef GFC_INTEGER_4 gfc_charlen_type;
131 /* This will be 0 on little-endian machines and one on big-endian machines. */
132 #define l8_to_l4_offset prefix(l8_to_l4_offset)
133 extern int l8_to_l4_offset;
135 #define GFOR_POINTER_L8_TO_L4(p8) \
136 (l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))
138 #define GFC_INTEGER_4_HUGE \
139 (GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
140 #define GFC_INTEGER_8_HUGE \
141 (GFC_INTEGER_8)((((GFC_UINTEGER_8)1) << 63) - 1)
142 #define GFC_REAL_4_HUGE FLT_MAX
143 #define GFC_REAL_8_HUGE DBL_MAX
145 #ifndef GFC_MAX_DIMENSIONS
146 #define GFC_MAX_DIMENSIONS 7
149 typedef struct descriptor_dimension
155 descriptor_dimension;
157 #define GFC_ARRAY_DESCRIPTOR(r, type) \
162 descriptor_dimension dim[r];\
165 /* Commonly used array descriptor types. */
166 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void;
167 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char;
168 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_array_i4;
169 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_8) gfc_array_i8;
170 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_4) gfc_array_r4;
171 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_8) gfc_array_r8;
172 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_4) gfc_array_c4;
173 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_8) gfc_array_c8;
174 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_4) gfc_array_l4;
175 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_8) gfc_array_l8;
177 #define GFC_DTYPE_RANK_MASK 0x07
178 #define GFC_DTYPE_TYPE_SHIFT 3
179 #define GFC_DTYPE_TYPE_MASK 0x38
180 #define GFC_DTYPE_SIZE_SHIFT 6
184 GFC_DTYPE_UNKNOWN = 0,
186 /* TODO: recognize logical types. */
194 #define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
195 #define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
196 >> GFC_DTYPE_TYPE_SHIFT)
197 #define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
198 #define GFC_DESCRIPTOR_DATA(desc) ((desc)->data)
199 #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype)
201 /* Runtime library include. */
202 #define stringize(x) expand_macro(x)
203 #define expand_macro(x) # x
205 /* Runtime options structure. */
209 int stdin_unit, stdout_unit, optional_plus;
210 int allocate_init_flag, allocate_init_value;
214 const char *separator;
217 int use_stderr, all_unbuffered, default_recl;
219 int fpu_round, fpu_precision, fpu_invalid, fpu_denormal, fpu_zerodiv,
220 fpu_overflow, fpu_underflow, fpu_precision_loss;
227 #define options prefix(options)
228 extern options_t options;
231 /* Structure for statement options. */
240 /* Runtime errors. The EOR and EOF errors are required to be negative. */
244 ERROR_FIRST = -3, /* Marker for the first error. */
247 ERROR_OK = 0, /* Indicates success, must be zero. */
248 ERROR_OS, /* Operating system error, more info in errno. */
249 ERROR_OPTION_CONFLICT,
251 ERROR_MISSING_OPTION,
260 ERROR_LAST /* Not a real error, the last error # + 1. */
265 /* The filename and line number don't go inside the globals structure.
266 They are set by the rest of the program and must be linked to. */
268 #define line prefix(line)
269 extern unsigned line; /* Location of the current libray call (optional). */
271 #define filename prefix(filename)
272 extern char *filename;
274 /* Avoid conflicting prototypes of alloca() in system headers by using
275 GCC's builtin alloca(). */
277 #define gfc_alloca(x) __builtin_alloca(x)
282 #define library_start prefix(library_start)
283 void library_start (void);
285 #define library_end prefix(library_end)
286 void library_end (void);
288 #define set_args prefix(set_args)
289 void set_args (int, char **);
291 #define get_args prefix(get_args)
292 void get_args (int *, char ***);
296 #define itoa prefix(itoa)
297 char *itoa (int64_t);
299 #define xtoa prefix(xtoa)
300 char *xtoa (uint64_t);
302 #define os_error prefix(os_error)
303 void os_error (const char *) __attribute__ ((noreturn));
305 #define show_locus prefix(show_locus)
306 void show_locus (void);
308 #define runtime_error prefix(runtime_error)
309 void runtime_error (const char *) __attribute__ ((noreturn));
311 #define internal_error prefix(internal_error)
312 void internal_error (const char *) __attribute__ ((noreturn));
314 #define get_oserror prefix(get_oserror)
315 const char *get_oserror (void);
317 #define write_error prefix(write_error)
318 void write_error (const char *);
320 #define sys_exit prefix(sys_exit)
321 void sys_exit (int) __attribute__ ((noreturn));
323 #define st_printf prefix(st_printf)
324 int st_printf (const char *, ...) __attribute__ ((format (printf, 1, 2)));
326 #define st_sprintf prefix(st_sprintf)
327 void st_sprintf (char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
329 #define translate_error prefix(translate_error)
330 const char *translate_error (int);
332 #define generate_error prefix(generate_error)
333 void generate_error (int, const char *);
338 #define memory_init prefix(memory_init)
339 void memory_init (void);
341 #define runtime_cleanup prefix(runtime_cleanup)
342 void runtime_cleanup (void);
344 #define get_mem prefix(get_mem)
345 void *get_mem (size_t) __attribute__ ((malloc));
347 #define free_mem prefix(free_mem)
348 void free_mem (void *);
350 #define internal_malloc_size prefix(internal_malloc_size)
351 void *internal_malloc_size (size_t);
353 #define internal_malloc prefix(internal_malloc)
354 void *internal_malloc (GFC_INTEGER_4);
356 #define internal_malloc64 prefix(internal_malloc64)
357 void *internal_malloc64 (GFC_INTEGER_8);
359 #define internal_free prefix(internal_free)
360 void internal_free (void *);
362 #define allocate prefix(allocate)
363 void allocate (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
365 #define allocate64 prefix(allocate64)
366 void allocate64 (void **, GFC_INTEGER_8, GFC_INTEGER_4 *);
368 #define deallocate prefix(deallocate)
369 void deallocate (void **, GFC_INTEGER_4 *);
374 #define check_buffered prefix(check_buffered)
375 int check_buffered (int);
377 #define init_variables prefix(init_variables)
378 void init_variables (void);
380 #define show_variables prefix(show_variables)
381 void show_variables (void);
386 #define find_option prefix(find_option)
387 int find_option (const char *, int, st_option *, const char *);
389 #define fstrlen prefix(fstrlen)
390 int fstrlen (const char *, int);
392 #define fstrcpy prefix(fstrcpy)
393 void fstrcpy (char *, int, const char *, int);
395 #define cf_strcpy prefix(cf_strcpy)
396 void cf_strcpy (char *, int, const char *);
400 #define init_units prefix(init_units)
401 void init_units (void);
403 #define close_units prefix(close_units)
404 void close_units (void);
407 #define stop_numeric prefix(stop_numeric)
408 void stop_numeric (GFC_INTEGER_4);
410 /* reshape_packed.c */
411 #define reshape_packed prefix(reshape_packed)
412 void reshape_packed (char *, index_type, const char *, index_type,
413 const char *, index_type);
415 /* Repacking functions. */
416 #define internal_pack prefix(internal_pack)
417 void *internal_pack (gfc_array_char *);
419 #define internal_unpack prefix(internal_unpack)
420 void internal_unpack (gfc_array_char *, const void *);
422 #define internal_pack_4 prefix(internal_pack_4)
423 GFC_INTEGER_4 *internal_pack_4 (gfc_array_i4 *);
425 #define internal_pack_8 prefix(internal_pack_8)
426 GFC_INTEGER_8 *internal_pack_8 (gfc_array_i8 *);
428 #define internal_unpack_4 prefix(internal_unpack_4)
429 void internal_unpack_4 (gfc_array_i4 *, const GFC_INTEGER_4 *);
431 #define internal_unpack_8 prefix(internal_unpack_8)
432 void internal_unpack_8 (gfc_array_i8 *, const GFC_INTEGER_8 *);
434 /* date_and_time.c */
436 #define date_and_time prefix(date_and_time)
437 void date_and_time (char *, char *, char *, gfc_array_i4 *,
438 GFC_INTEGER_4, GFC_INTEGER_4, GFC_INTEGER_4);
440 /* string_intrinsics.c */
442 #define compare_string prefix(compare_string)
443 GFC_INTEGER_4 compare_string (GFC_INTEGER_4, const char *,
444 GFC_INTEGER_4, const char *);
448 #define random_seed prefix(random_seed)
449 void random_seed (GFC_INTEGER_4 * size, gfc_array_i4 * put,
454 #define normalize_r4_i4 prefix(normalize_r4_i4)
455 GFC_REAL_4 normalize_r4_i4 (GFC_UINTEGER_4, GFC_UINTEGER_4);
457 #define normalize_r8_i8 prefix(normalize_r8_i8)
458 GFC_REAL_8 normalize_r8_i8 (GFC_UINTEGER_8, GFC_UINTEGER_8);
462 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) array_t;
464 #define size0 prefix(size0)
465 index_type size0 (const array_t * array);
467 #endif /* LIBGFOR_H */