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
39 #define complex __complex__
50 #if !defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H) && defined(TARGET_ILP32)
52 typedef short int16_t;
54 typedef long long int64_t;
55 typedef unsigned char uint8_t;
56 typedef unsigned short uint16_t;
57 typedef unsigned int uint32_t;
58 typedef unsigned long long uint64_t;
62 #include <sys/types.h>
64 typedef off_t gfc_offset;
67 #define NULL (void *) 0
71 #define __attribute__(x)
74 /* For a library, a standard prefix is a requirement in order to
75 partition the namespace. It's ugly to look at and a pain to type,
76 so we hide it behind macros. */
77 #define prefix(x) _gfortran_ ## x
79 /* The only reliable way to get the offset of a field in a struct
80 in a system independent way is via this macro. */
82 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
85 /* The isfinite macro is only available with C99, but some non-C99
86 systems still provide fpclassify, and there is a `finite' function
87 in BSD. When isfinite is not available, try to use one of the
88 alternatives, or bail out. */
89 #if !defined(isfinite)
93 #if defined(fpclassify)
94 return (fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE);
95 #elif defined(HAVE_FINITE)
98 #error "libgfortran needs isfinite, fpclassify, or finite"
101 #endif /* !defined(isfinite) */
103 /* TODO: find the C99 version of these an move into above ifdef. */
104 #define REALPART(z) (__real__(z))
105 #define IMAGPART(z) (__imag__(z))
106 #define COMPLEX_ASSIGN(z_, r_, i_) {__real__(z_) = (r_); __imag__(z_) = (i_);}
108 typedef int32_t GFC_INTEGER_4;
109 typedef int64_t GFC_INTEGER_8;
110 typedef uint32_t GFC_UINTEGER_4;
111 typedef uint64_t GFC_UINTEGER_8;
112 typedef GFC_INTEGER_4 GFC_LOGICAL_4;
113 typedef GFC_INTEGER_8 GFC_LOGICAL_8;
114 typedef float GFC_REAL_4;
115 typedef double GFC_REAL_8;
116 typedef complex float GFC_COMPLEX_4;
117 typedef complex double GFC_COMPLEX_8;
119 /* The following two definitions must be consistent with the types used
121 /* The type used of array indices, amongst other things. */
122 typedef size_t index_type;
123 /* The type used for the lengths of character variables. */
124 typedef GFC_INTEGER_4 gfc_charlen_type;
126 /* This will be 0 on little-endian machines and one on big-endian machines. */
127 #define l8_to_l4_offset prefix(l8_to_l4_offset)
128 extern int l8_to_l4_offset;
130 #define GFOR_POINTER_L8_TO_L4(p8) \
131 (l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))
133 #define GFC_INTEGER_4_HUGE \
134 (GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
135 #define GFC_INTEGER_8_HUGE \
136 (GFC_INTEGER_8)((((GFC_UINTEGER_8)1) << 63) - 1)
137 #define GFC_REAL_4_HUGE FLT_MAX
138 #define GFC_REAL_8_HUGE DBL_MAX
140 #ifndef GFC_MAX_DIMENSIONS
141 #define GFC_MAX_DIMENSIONS 7
144 typedef struct descriptor_dimension
150 descriptor_dimension;
152 #define GFC_ARRAY_DESCRIPTOR(r, type) \
157 descriptor_dimension dim[r];\
160 /* Commonly used array descriptor types. */
161 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void;
162 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char;
163 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_array_i4;
164 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_8) gfc_array_i8;
165 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_4) gfc_array_r4;
166 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_8) gfc_array_r8;
167 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_4) gfc_array_c4;
168 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_8) gfc_array_c8;
169 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_4) gfc_array_l4;
170 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_8) gfc_array_l8;
172 #define GFC_DTYPE_RANK_MASK 0x07
173 #define GFC_DTYPE_TYPE_SHIFT 3
174 #define GFC_DTYPE_TYPE_MASK 0x38
175 #define GFC_DTYPE_SIZE_SHIFT 6
179 GFC_DTYPE_UNKNOWN = 0,
181 /* TODO: recognize logical types. */
189 #define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
190 #define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
191 >> GFC_DTYPE_TYPE_SHIFT)
192 #define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
193 #define GFC_DESCRIPTOR_DATA(desc) ((desc)->data)
194 #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype)
196 /* Runtime library include. */
197 #define stringize(x) expand_macro(x)
198 #define expand_macro(x) # x
200 /* Runtime options structure. */
204 int stdin_unit, stdout_unit, optional_plus;
205 int allocate_init_flag, allocate_init_value;
209 const char *separator;
212 int use_stderr, all_unbuffered, default_recl;
214 int fpu_round, fpu_precision, fpu_invalid, fpu_denormal, fpu_zerodiv,
215 fpu_overflow, fpu_underflow, fpu_precision_loss;
222 #define options prefix(options)
223 extern options_t options;
226 /* Structure for statement options. */
235 /* Runtime errors. The EOR and EOF errors are required to be negative. */
239 ERROR_FIRST = -3, /* Marker for the first error. */
242 ERROR_OK = 0, /* Indicates success, must be zero. */
243 ERROR_OS, /* Operating system error, more info in errno. */
244 ERROR_OPTION_CONFLICT,
246 ERROR_MISSING_OPTION,
255 ERROR_LAST /* Not a real error, the last error # + 1. */
260 /* The filename and line number don't go inside the globals structure.
261 They are set by the rest of the program and must be linked to. */
263 #define line prefix(line)
264 extern unsigned line; /* Location of the current libray call (optional). */
266 #define filename prefix(filename)
267 extern char *filename;
269 /* Avoid conflicting prototypes of alloca() in system headers by using
270 GCC's builtin alloca(). */
272 #define gfc_alloca(x) __builtin_alloca(x)
277 #define library_start prefix(library_start)
278 void library_start (void);
280 #define library_end prefix(library_end)
281 void library_end (void);
283 #define set_args prefix(set_args)
284 void set_args (int, char **);
286 #define get_args prefix(get_args)
287 void get_args (int *, char ***);
291 #define itoa prefix(itoa)
292 char *itoa (int64_t);
294 #define xtoa prefix(xtoa)
295 char *xtoa (uint64_t);
297 #define os_error prefix(os_error)
298 void os_error (const char *) __attribute__ ((noreturn));
300 #define show_locus prefix(show_locus)
301 void show_locus (void);
303 #define runtime_error prefix(runtime_error)
304 void runtime_error (const char *) __attribute__ ((noreturn));
306 #define internal_error prefix(internal_error)
307 void internal_error (const char *) __attribute__ ((noreturn));
309 #define get_oserror prefix(get_oserror)
310 const char *get_oserror (void);
312 #define write_error prefix(write_error)
313 void write_error (const char *);
315 #define sys_exit prefix(sys_exit)
316 void sys_exit (int) __attribute__ ((noreturn));
318 #define st_printf prefix(st_printf)
319 int st_printf (const char *, ...) __attribute__ ((format (printf, 1, 2)));
321 #define st_sprintf prefix(st_sprintf)
322 void st_sprintf (char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
324 #define translate_error prefix(translate_error)
325 const char *translate_error (int);
327 #define generate_error prefix(generate_error)
328 void generate_error (int, const char *);
333 #define memory_init prefix(memory_init)
334 void memory_init (void);
336 #define runtime_cleanup prefix(runtime_cleanup)
337 void runtime_cleanup (void);
339 #define get_mem prefix(get_mem)
340 void *get_mem (size_t) __attribute__ ((malloc));
342 #define free_mem prefix(free_mem)
343 void free_mem (void *);
345 #define internal_malloc_size prefix(internal_malloc_size)
346 void *internal_malloc_size (size_t);
348 #define internal_malloc prefix(internal_malloc)
349 void *internal_malloc (GFC_INTEGER_4);
351 #define internal_malloc64 prefix(internal_malloc64)
352 void *internal_malloc64 (GFC_INTEGER_8);
354 #define internal_free prefix(internal_free)
355 void internal_free (void *);
357 #define allocate prefix(allocate)
358 void allocate (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
360 #define allocate64 prefix(allocate64)
361 void allocate64 (void **, GFC_INTEGER_8, GFC_INTEGER_4 *);
363 #define deallocate prefix(deallocate)
364 void deallocate (void **, GFC_INTEGER_4 *);
369 #define check_buffered prefix(check_buffered)
370 int check_buffered (int);
372 #define init_variables prefix(init_variables)
373 void init_variables (void);
375 #define show_variables prefix(show_variables)
376 void show_variables (void);
381 #define find_option prefix(find_option)
382 int find_option (const char *, int, st_option *, const char *);
384 #define fstrlen prefix(fstrlen)
385 int fstrlen (const char *, int);
387 #define fstrcpy prefix(fstrcpy)
388 void fstrcpy (char *, int, const char *, int);
390 #define cf_strcpy prefix(cf_strcpy)
391 void cf_strcpy (char *, int, const char *);
395 #define init_units prefix(init_units)
396 void init_units (void);
398 #define close_units prefix(close_units)
399 void close_units (void);
402 #define stop_numeric prefix(stop_numeric)
403 void stop_numeric (GFC_INTEGER_4);
405 /* reshape_packed.c */
406 #define reshape_packed prefix(reshape_packed)
407 void reshape_packed (char *, index_type, const char *, index_type,
408 const char *, index_type);
410 /* Repacking functions. */
411 #define internal_pack prefix(internal_pack)
412 void *internal_pack (gfc_array_char *);
414 #define internal_unpack prefix(internal_unpack)
415 void internal_unpack (gfc_array_char *, const void *);
417 #define internal_pack_4 prefix(internal_pack_4)
418 GFC_INTEGER_4 *internal_pack_4 (gfc_array_i4 *);
420 #define internal_pack_8 prefix(internal_pack_8)
421 GFC_INTEGER_8 *internal_pack_8 (gfc_array_i8 *);
423 #define internal_unpack_4 prefix(internal_unpack_4)
424 void internal_unpack_4 (gfc_array_i4 *, const GFC_INTEGER_4 *);
426 #define internal_unpack_8 prefix(internal_unpack_8)
427 void internal_unpack_8 (gfc_array_i8 *, const GFC_INTEGER_8 *);
429 /* date_and_time.c */
431 #define date_and_time prefix(date_and_time)
432 void date_and_time (char *, char *, char *, gfc_array_i4 *,
433 GFC_INTEGER_4, GFC_INTEGER_4, GFC_INTEGER_4);
435 /* string_intrinsics.c */
437 #define compare_string prefix(compare_string)
438 GFC_INTEGER_4 compare_string (GFC_INTEGER_4, const char *,
439 GFC_INTEGER_4, const char *);
443 #define random_seed prefix(random_seed)
444 void random_seed (GFC_INTEGER_4 * size, gfc_array_i4 * put,
449 #define normalize_r4_i4 prefix(normalize_r4_i4)
450 GFC_REAL_4 normalize_r4_i4 (GFC_UINTEGER_4, GFC_UINTEGER_4);
452 #define normalize_r8_i8 prefix(normalize_r8_i8)
453 GFC_REAL_8 normalize_r8_i8 (GFC_UINTEGER_8, GFC_UINTEGER_8);
457 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) array_t;
459 #define size0 prefix(size0)
460 index_type size0 (const array_t * array);
462 #endif /* LIBGFOR_H */