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. */
31 #define M_PI 3.14159265358979323846264338327
39 #define complex __complex__
51 #include <sys/types.h>
53 typedef off_t gfc_offset
;
56 #define NULL (void *) 0
60 #define __attribute__(x)
63 /* For a library, a standard prefix is a requirement in order to
64 partition the namespace. It's ugly to look at and a pain to type,
65 so we hide it behind macros. */
66 #define prefix(x) _gfortran_ ## x
68 /* The only reliable way to get the offset of a field in a struct
69 in a system independent way is via this macro. */
71 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *) 0)->MEMBER)
74 /* TODO: find the C99 version of these an move into above ifdef. */
75 #define REALPART(z) (__real__(z))
76 #define IMAGPART(z) (__imag__(z))
77 #define COMPLEX_ASSIGN(z_, r_, i_) {__real__(z_) = (r_); __imag__(z_) = (i_);}
79 typedef int32_t GFC_INTEGER_4
;
80 typedef int64_t GFC_INTEGER_8
;
81 typedef uint32_t GFC_UINTEGER_4
;
82 typedef uint64_t GFC_UINTEGER_8
;
83 typedef GFC_INTEGER_4 GFC_LOGICAL_4
;
84 typedef GFC_INTEGER_8 GFC_LOGICAL_8
;
85 typedef float GFC_REAL_4
;
86 typedef double GFC_REAL_8
;
87 typedef complex float GFC_COMPLEX_4
;
88 typedef complex double GFC_COMPLEX_8
;
90 /* The following two definitions must be consistent with the types used
92 /* The type used of array indices, amongst other things. */
93 typedef size_t index_type
;
94 /* The type used for the lengths of character variables. */
95 typedef GFC_INTEGER_4 gfc_charlen_type
;
97 /* This will be 0 on little-endian machines and one on big-endian machines. */
98 #define l8_to_l4_offset prefix(l8_to_l4_offset)
99 extern int l8_to_l4_offset
;
101 #define GFOR_POINTER_L8_TO_L4(p8) \
102 (l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))
104 #define GFC_INTEGER_4_HUGE \
105 (GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
106 #define GFC_INTEGER_8_HUGE \
107 (GFC_INTEGER_8)((((GFC_UINTEGER_8)1) << 63) - 1)
108 #define GFC_REAL_4_HUGE FLT_MAX
109 #define GFC_REAL_8_HUGE DBL_MAX
111 #ifndef GFC_MAX_DIMENSIONS
112 #define GFC_MAX_DIMENSIONS 7
115 typedef struct descriptor_dimension
121 descriptor_dimension
;
123 #define GFC_ARRAY_DESCRIPTOR(r, type) \
128 descriptor_dimension dim[r];\
131 /* Commonly used array descriptor types. */
132 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, void) gfc_array_void
;
133 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, char) gfc_array_char
;
134 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_INTEGER_4
) gfc_array_i4
;
135 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_INTEGER_8
) gfc_array_i8
;
136 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_REAL_4
) gfc_array_r4
;
137 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_REAL_8
) gfc_array_r8
;
138 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_COMPLEX_4
) gfc_array_c4
;
139 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_COMPLEX_8
) gfc_array_c8
;
140 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_LOGICAL_4
) gfc_array_l4
;
141 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, GFC_LOGICAL_8
) gfc_array_l8
;
143 #define GFC_DTYPE_RANK_MASK 0x07
144 #define GFC_DTYPE_TYPE_SHIFT 3
145 #define GFC_DTYPE_TYPE_MASK 0x38
146 #define GFC_DTYPE_SIZE_SHIFT 6
150 GFC_DTYPE_UNKNOWN
= 0,
152 /* TODO: recognize logical types. */
160 #define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
161 #define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
162 >> GFC_DTYPE_TYPE_SHIFT)
163 #define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
164 #define GFC_DESCRIPTOR_DATA(desc) ((desc)->data)
165 #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype)
167 /* Runtime library include. */
168 #define stringize(x) expand_macro(x)
169 #define expand_macro(x) # x
171 /* Runtime options structure. */
175 int stdin_unit
, stdout_unit
, optional_plus
;
176 int allocate_init_flag
, allocate_init_value
;
180 const char *separator
;
183 int use_stderr
, all_unbuffered
, default_recl
;
185 int fpu_round
, fpu_precision
, fpu_invalid
, fpu_denormal
, fpu_zerodiv
,
186 fpu_overflow
, fpu_underflow
, fpu_precision_loss
;
193 #define options prefix(options)
194 extern options_t options
;
197 /* Structure for statement options. */
206 /* Runtime errors. The EOR and EOF errors are required to be negative. */
210 ERROR_FIRST
= -3, /* Marker for the first error. */
213 ERROR_OK
= 0, /* Indicates success, must be zero. */
214 ERROR_OS
, /* Operating system error, more info in errno. */
215 ERROR_OPTION_CONFLICT
,
217 ERROR_MISSING_OPTION
,
226 ERROR_LAST
/* Not a real error, the last error # + 1. */
231 /* The filename and line number don't go inside the globals structure.
232 They are set by the rest of the program and must be linked to. */
234 #define line prefix(line)
235 extern unsigned line
; /* Location of the current libray call (optional). */
237 #define filename prefix(filename)
238 extern char *filename
;
243 #define library_start prefix(library_start)
244 void library_start (void);
246 #define library_end prefix(library_end)
247 void library_end (void);
249 #define set_args prefix(set_args)
250 void set_args (int, char **);
252 #define get_args prefix(get_args)
253 void get_args (int *, char ***);
257 #define itoa prefix(itoa)
258 char *itoa (int64_t);
260 #define xtoa prefix(xtoa)
261 char *xtoa (uint64_t);
263 #define os_error prefix(os_error)
264 void os_error (const char *) __attribute__ ((noreturn
));
266 #define show_locus prefix(show_locus)
267 void show_locus (void);
269 #define runtime_error prefix(runtime_error)
270 void runtime_error (const char *) __attribute__ ((noreturn
));
272 #define internal_error prefix(internal_error)
273 void internal_error (const char *) __attribute__ ((noreturn
));
275 #define get_oserror prefix(get_oserror)
276 const char *get_oserror (void);
278 #define write_error prefix(write_error)
279 void write_error (const char *);
281 #define sys_exit prefix(sys_exit)
282 void sys_exit (int) __attribute__ ((noreturn
));
284 #define st_printf prefix(st_printf)
285 int st_printf (const char *, ...) __attribute__ ((format (printf
, 1, 2)));
287 #define st_sprintf prefix(st_sprintf)
288 void st_sprintf (char *, const char *, ...) __attribute__ ((format (printf
, 2, 3)));
290 #define translate_error prefix(translate_error)
291 const char *translate_error (int);
293 #define generate_error prefix(generate_error)
294 void generate_error (int, const char *);
299 #define memory_init prefix(memory_init)
300 void memory_init (void);
302 #define runtime_cleanup prefix(runtime_cleanup)
303 void runtime_cleanup (void);
305 #define get_mem prefix(get_mem)
306 void *get_mem (size_t) __attribute__ ((malloc
));
308 #define free_mem prefix(free_mem)
309 void free_mem (void *);
311 #define internal_malloc_size prefix(internal_malloc_size)
312 void *internal_malloc_size (size_t);
314 #define internal_malloc prefix(internal_malloc)
315 void *internal_malloc (GFC_INTEGER_4
);
317 #define internal_malloc64 prefix(internal_malloc64)
318 void *internal_malloc64 (GFC_INTEGER_8
);
320 #define internal_free prefix(internal_free)
321 void internal_free (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
*);
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);
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 *);
361 #define init_units prefix(init_units)
362 void init_units (void);
364 #define close_units prefix(close_units)
365 void close_units (void);
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 /* date_and_time.c */
397 #define date_and_time prefix(date_and_time)
398 void date_and_time (char *, char *, char *, gfc_array_i4
*,
399 GFC_INTEGER_4
, GFC_INTEGER_4
, GFC_INTEGER_4
);
401 /* string_intrinsics.c */
403 #define compare_string prefix(compare_string)
404 GFC_INTEGER_4
compare_string (GFC_INTEGER_4
, const char *,
405 GFC_INTEGER_4
, const char *);
409 #define random_seed prefix(random_seed)
410 void random_seed (GFC_INTEGER_4
* size
, gfc_array_i4
* put
,
415 #define normalize_r4_i4 prefix(normalize_r4_i4)
416 GFC_REAL_4
normalize_r4_i4 (GFC_UINTEGER_4
, GFC_UINTEGER_4
);
418 #define normalize_r8_i8 prefix(normalize_r8_i8)
419 GFC_REAL_8
normalize_r8_i8 (GFC_UINTEGER_8
, GFC_UINTEGER_8
);
423 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS
, void) array_t
;
425 #define size0 prefix(size0)
426 index_type
size0 (const array_t
* array
);