OSDN Git Service

* configure.ac: Check for ieeefp.h. Check for fabsf in libm.
[pf3gnuchains/gcc-fork.git] / libgfortran / libgfortran.h
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>
5
6 This file is part of the GNU Fortran 95 runtime library (libgfor).
7
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.
12
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.
17
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.  */
22
23
24 #ifndef LIBGFOR_H
25 #define LIBGFOR_H
26
27 #include <math.h>
28 #include <stddef.h>
29
30 #ifndef M_PI
31 #define M_PI 3.14159265358979323846264338327
32 #endif
33
34 #include "config.h"
35 #include "c99_protos.h"
36
37 #if HAVE_COMPLEX_H
38 # include <complex.h>
39 #else
40 #define complex __complex__
41 #endif
42
43 #if HAVE_IEEEFP_H
44 #include <ieeefp.h>
45 #endif
46
47 #if HAVE_STDINT_H
48 #include <stdint.h>
49 #endif
50
51 #if HAVE_INTTYPES_H
52 #include <inttypes.h>
53 #endif
54
55 #if !defined(HAVE_STDINT_H) && !defined(HAVE_INTTYPES_H) && defined(TARGET_ILP32)
56 typedef char int8_t;
57 typedef short int16_t;
58 typedef int int32_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;
64 #endif
65
66 #if HAVE_SYS_TYPES_H
67 #include <sys/types.h>
68 #endif
69 typedef off_t gfc_offset;
70
71 #ifndef NULL
72 #define NULL (void *) 0
73 #endif
74
75 #ifndef __GNUC__
76 #define __attribute__(x)
77 #endif
78
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
83
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.  */
86 #ifndef offsetof
87 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *) 0)->MEMBER)
88 #endif
89
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)
95 static inline int
96 isfinite (double x)
97 {
98 #if defined(fpclassify)
99   return (fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE);
100 #elif defined(HAVE_FINITE)
101   return finite (x);
102 #else
103 #error "libgfortran needs isfinite, fpclassify, or finite"
104 #endif
105 }
106 #endif /* !defined(isfinite)  */
107
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_);}
112
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;
123
124 /* The following two definitions must be consistent with the types used
125    by the compiler.  */
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;
130
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;
134
135 #define GFOR_POINTER_L8_TO_L4(p8) \
136   (l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))
137
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
144
145 #ifndef GFC_MAX_DIMENSIONS
146 #define GFC_MAX_DIMENSIONS 7
147 #endif
148
149 typedef struct descriptor_dimension
150 {
151   index_type stride;
152   index_type lbound;
153   index_type ubound;
154 }
155 descriptor_dimension;
156
157 #define GFC_ARRAY_DESCRIPTOR(r, type) \
158 struct {\
159   type *data;\
160   type *base;\
161   index_type dtype;\
162   descriptor_dimension dim[r];\
163 }
164
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;
176
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
181
182 enum
183 {
184   GFC_DTYPE_UNKNOWN = 0,
185   GFC_DTYPE_INTEGER,
186   /* TODO: recognize logical types.  */
187   GFC_DTYPE_LOGICAL,
188   GFC_DTYPE_REAL,
189   GFC_DTYPE_COMPLEX,
190   GFC_DTYPE_DERIVED,
191   GFC_DTYPE_CHARACTER
192 };
193
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)
200
201 /* Runtime library include.  */
202 #define stringize(x) expand_macro(x)
203 #define expand_macro(x) # x
204
205 /* Runtime options structure.  */
206
207 typedef struct
208 {
209   int stdin_unit, stdout_unit, optional_plus;
210   int allocate_init_flag, allocate_init_value;
211   int locus;
212
213   int separator_len;
214   const char *separator;
215
216   int mem_check;
217   int use_stderr, all_unbuffered, default_recl;
218
219   int fpu_round, fpu_precision, fpu_invalid, fpu_denormal, fpu_zerodiv,
220     fpu_overflow, fpu_underflow, fpu_precision_loss;
221
222   int sighup, sigint;
223 }
224 options_t;
225
226
227 #define options prefix(options)
228 extern options_t options;
229
230
231 /* Structure for statement options.  */
232
233 typedef struct
234 {
235   const char *name;
236   int value;
237 }
238 st_option;
239
240 /* Runtime errors.  The EOR and EOF errors are required to be negative.  */
241
242 typedef enum
243 {
244   ERROR_FIRST = -3,             /* Marker for the first error.  */
245   ERROR_EOR = -2,
246   ERROR_END = -1,
247   ERROR_OK = 0,                 /* Indicates success, must be zero.  */
248   ERROR_OS,                     /* Operating system error, more info in errno.  */
249   ERROR_OPTION_CONFLICT,
250   ERROR_BAD_OPTION,
251   ERROR_MISSING_OPTION,
252   ERROR_ALREADY_OPEN,
253   ERROR_BAD_UNIT,
254   ERROR_FORMAT,
255   ERROR_BAD_ACTION,
256   ERROR_ENDFILE,
257   ERROR_BAD_US,
258   ERROR_READ_VALUE,
259   ERROR_READ_OVERFLOW,
260   ERROR_LAST                    /* Not a real error, the last error # + 1.  */
261 }
262 error_codes;
263
264
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.  */
267
268 #define line prefix(line)
269 extern unsigned line;           /* Location of the current libray call (optional).  */
270
271 #define filename prefix(filename)
272 extern char *filename;
273
274 /* Avoid conflicting prototypes of alloca() in system headers by using 
275    GCC's builtin alloca().  */
276
277 #define gfc_alloca(x)  __builtin_alloca(x)
278
279
280 /* main.c */
281
282 #define library_start prefix(library_start)
283 void library_start (void);
284
285 #define library_end prefix(library_end)
286 void library_end (void);
287
288 #define set_args prefix(set_args)
289 void set_args (int, char **);
290
291 #define get_args prefix(get_args)
292 void get_args (int *, char ***);
293
294
295 /* error.c */
296 #define itoa prefix(itoa)
297 char *itoa (int64_t);
298
299 #define xtoa prefix(xtoa)
300 char *xtoa (uint64_t);
301
302 #define os_error prefix(os_error)
303 void os_error (const char *) __attribute__ ((noreturn));
304
305 #define show_locus prefix(show_locus)
306 void show_locus (void);
307
308 #define runtime_error prefix(runtime_error)
309 void runtime_error (const char *) __attribute__ ((noreturn));
310
311 #define internal_error prefix(internal_error)
312 void internal_error (const char *) __attribute__ ((noreturn));
313
314 #define get_oserror prefix(get_oserror)
315 const char *get_oserror (void);
316
317 #define write_error prefix(write_error)
318 void write_error (const char *);
319
320 #define sys_exit prefix(sys_exit)
321 void sys_exit (int) __attribute__ ((noreturn));
322
323 #define st_printf prefix(st_printf)
324 int st_printf (const char *, ...) __attribute__ ((format (printf, 1, 2)));
325
326 #define st_sprintf prefix(st_sprintf)
327 void st_sprintf (char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
328
329 #define translate_error prefix(translate_error)
330 const char *translate_error (int);
331
332 #define generate_error prefix(generate_error)
333 void generate_error (int, const char *);
334
335
336 /* memory.c */
337
338 #define memory_init     prefix(memory_init)
339 void memory_init (void);
340
341 #define runtime_cleanup prefix(runtime_cleanup)
342 void runtime_cleanup (void);
343
344 #define get_mem         prefix(get_mem)
345 void *get_mem (size_t) __attribute__ ((malloc));
346
347 #define free_mem        prefix(free_mem)
348 void free_mem (void *);
349
350 #define internal_malloc_size    prefix(internal_malloc_size)
351 void *internal_malloc_size (size_t);
352
353 #define internal_malloc prefix(internal_malloc)
354 void *internal_malloc (GFC_INTEGER_4);
355
356 #define internal_malloc64 prefix(internal_malloc64)
357 void *internal_malloc64 (GFC_INTEGER_8);
358
359 #define internal_free   prefix(internal_free)
360 void internal_free (void *);
361
362 #define allocate        prefix(allocate)
363 void allocate (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
364
365 #define allocate64      prefix(allocate64)
366 void allocate64 (void **, GFC_INTEGER_8, GFC_INTEGER_4 *);
367
368 #define deallocate      prefix(deallocate)
369 void deallocate (void **, GFC_INTEGER_4 *);
370
371
372 /* environ.c */
373
374 #define check_buffered prefix(check_buffered)
375 int check_buffered (int);
376
377 #define init_variables prefix(init_variables)
378 void init_variables (void);
379
380 #define show_variables prefix(show_variables)
381 void show_variables (void);
382
383
384 /* string.c */
385
386 #define find_option prefix(find_option)
387 int find_option (const char *, int, st_option *, const char *);
388
389 #define fstrlen prefix(fstrlen)
390 int fstrlen (const char *, int);
391
392 #define fstrcpy prefix(fstrcpy)
393 void fstrcpy (char *, int, const char *, int);
394
395 #define cf_strcpy prefix(cf_strcpy)
396 void cf_strcpy (char *, int, const char *);
397
398 /* io.c */
399
400 #define init_units prefix(init_units)
401 void init_units (void);
402
403 #define close_units prefix(close_units)
404 void close_units (void);
405
406 /* stop.c */
407 #define stop_numeric prefix(stop_numeric)
408 void stop_numeric (GFC_INTEGER_4);
409
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);
414
415 /* Repacking functions.  */
416 #define internal_pack prefix(internal_pack)
417 void *internal_pack (gfc_array_char *);
418
419 #define internal_unpack prefix(internal_unpack)
420 void internal_unpack (gfc_array_char *, const void *);
421
422 #define internal_pack_4 prefix(internal_pack_4)
423 GFC_INTEGER_4 *internal_pack_4 (gfc_array_i4 *);
424
425 #define internal_pack_8 prefix(internal_pack_8)
426 GFC_INTEGER_8 *internal_pack_8 (gfc_array_i8 *);
427
428 #define internal_unpack_4 prefix(internal_unpack_4)
429 void internal_unpack_4 (gfc_array_i4 *, const GFC_INTEGER_4 *);
430
431 #define internal_unpack_8 prefix(internal_unpack_8)
432 void internal_unpack_8 (gfc_array_i8 *, const GFC_INTEGER_8 *);
433
434 /* date_and_time.c */
435
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);
439
440 /* string_intrinsics.c */
441
442 #define compare_string prefix(compare_string)
443 GFC_INTEGER_4 compare_string (GFC_INTEGER_4, const char *,
444                               GFC_INTEGER_4, const char *);
445
446 /* random.c */
447
448 #define random_seed prefix(random_seed)
449 void random_seed (GFC_INTEGER_4 * size, gfc_array_i4 * put,
450                   gfc_array_i4 * get);
451
452 /* normalize.c */
453
454 #define normalize_r4_i4 prefix(normalize_r4_i4)
455 GFC_REAL_4 normalize_r4_i4 (GFC_UINTEGER_4, GFC_UINTEGER_4);
456
457 #define normalize_r8_i8 prefix(normalize_r8_i8)
458 GFC_REAL_8 normalize_r8_i8 (GFC_UINTEGER_8, GFC_UINTEGER_8);
459
460 /* size.c */
461
462 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) array_t;
463
464 #define size0 prefix(size0)
465 index_type size0 (const array_t * array); 
466
467 #endif  /* LIBGFOR_H  */
468