OSDN Git Service

* libgfortran.h (array_t, size0) New declarations.
[pf3gnuchains/gcc-fork.git] / libgfortran / libgfortran.h
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>
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
36 #if HAVE_COMPLEX_H
37 # include <complex.h>
38 #else
39 #define complex __complex__
40 #endif
41
42 #if HAVE_STDINT_H
43 #include <stdint.h>
44 #endif
45
46 #if HAVE_INTTYPES_H
47 #include <inttypes.h>
48 #endif
49
50 #if HAVE_SYS_TYPES_H
51 #include <sys/types.h>
52 #endif
53 typedef off_t gfc_offset;
54
55 #ifndef NULL
56 #define NULL (void *) 0
57 #endif
58
59 #ifndef __GNUC__
60 #define __attribute__(x)
61 #endif
62
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
67
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.  */
70 #ifndef offsetof
71 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *) 0)->MEMBER)
72 #endif
73
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_);}
78
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;
89
90 typedef size_t index_type;
91 typedef GFC_INTEGER_4 gfc_strlen_type;
92
93 /* This will be 0 on little-endian machines and one on big-endian machines.  */
94 #define l8_to_l4_offset prefix(l8_to_l4_offset)
95 extern int l8_to_l4_offset;
96
97 #define GFOR_POINTER_L8_TO_L4(p8) \
98   (l8_to_l4_offset + (GFC_LOGICAL_4 *)(p8))
99
100 #define GFC_INTEGER_4_HUGE \
101   (GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
102 #define GFC_INTEGER_8_HUGE \
103   (GFC_INTEGER_8)((((GFC_UINTEGER_8)1) << 63) - 1)
104 #define GFC_REAL_4_HUGE FLT_MAX
105 #define GFC_REAL_8_HUGE DBL_MAX
106
107 #ifndef GFC_MAX_DIMENSIONS
108 #define GFC_MAX_DIMENSIONS 7
109 #endif
110
111 typedef struct descriptor_dimension
112 {
113   index_type stride;
114   index_type lbound;
115   index_type ubound;
116 }
117 descriptor_dimension;
118
119 #define GFC_ARRAY_DESCRIPTOR(r, type) \
120 struct {\
121   type *data;\
122   type *base;\
123   index_type dtype;\
124   descriptor_dimension dim[r];\
125 }
126
127 /* Commonly used array descriptor types.  */
128 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void;
129 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char;
130 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_array_i4;
131 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_8) gfc_array_i8;
132 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_4) gfc_array_r4;
133 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_8) gfc_array_r8;
134 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_4) gfc_array_c4;
135 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_8) gfc_array_c8;
136 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_4) gfc_array_l4;
137 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_8) gfc_array_l8;
138
139 #define GFC_DTYPE_RANK_MASK 0x07
140 #define GFC_DTYPE_TYPE_SHIFT 3
141 #define GFC_DTYPE_TYPE_MASK 0x38
142 #define GFC_DTYPE_SIZE_SHIFT 6
143
144 enum
145 {
146   GFC_DTYPE_UNKNOWN = 0,
147   GFC_DTYPE_INTEGER,
148   /* TODO: recognize logical types.  */
149   GFC_DTYPE_LOGICAL,
150   GFC_DTYPE_REAL,
151   GFC_DTYPE_COMPLEX,
152   GFC_DTYPE_DERIVED,
153   GFC_DTYPE_CHARACTER
154 };
155
156 #define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
157 #define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
158                                    >> GFC_DTYPE_TYPE_SHIFT)
159 #define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
160 #define GFC_DESCRIPTOR_DATA(desc) ((desc)->data)
161 #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype)
162
163 /* Runtime library include.  */
164 #define stringize(x) expand_macro(x)
165 #define expand_macro(x) # x
166
167 /* Runtime options structure.  */
168
169 typedef struct
170 {
171   int stdin_unit, stdout_unit, optional_plus;
172   int allocate_init_flag, allocate_init_value;
173   int locus;
174
175   int separator_len;
176   const char *separator;
177
178   int mem_check;
179   int use_stderr, all_unbuffered, default_recl;
180
181   int fpu_round, fpu_precision, fpu_invalid, fpu_denormal, fpu_zerodiv,
182     fpu_overflow, fpu_underflow, fpu_precision_loss;
183
184   int sighup, sigint;
185 }
186 options_t;
187
188
189 #define options prefix(options)
190 extern options_t options;
191
192
193 /* Structure for statement options.  */
194
195 typedef struct
196 {
197   const char *name;
198   int value;
199 }
200 st_option;
201
202 /* Runtime errors.  The EOR and EOF errors are required to be negative.  */
203
204 typedef enum
205 {
206   ERROR_FIRST = -3,             /* Marker for the first error.  */
207   ERROR_EOR = -2,
208   ERROR_END = -1,
209   ERROR_OK = 0,                 /* Indicates success, must be zero.  */
210   ERROR_OS,                     /* Operating system error, more info in errno.  */
211   ERROR_OPTION_CONFLICT,
212   ERROR_BAD_OPTION,
213   ERROR_MISSING_OPTION,
214   ERROR_ALREADY_OPEN,
215   ERROR_BAD_UNIT,
216   ERROR_FORMAT,
217   ERROR_BAD_ACTION,
218   ERROR_ENDFILE,
219   ERROR_BAD_US,
220   ERROR_READ_VALUE,
221   ERROR_READ_OVERFLOW,
222   ERROR_LAST                    /* Not a real error, the last error # + 1.  */
223 }
224 error_codes;
225
226
227 /* The filename and line number don't go inside the globals structure.
228    They are set by the rest of the program and must be linked to.  */
229
230 #define line prefix(line)
231 extern unsigned line;           /* Location of the current libray call (optional).  */
232
233 #define filename prefix(filename)
234 extern char *filename;
235
236
237 /* main.c */
238
239 #define library_start prefix(library_start)
240 void library_start (void);
241
242 #define library_end prefix(library_end)
243 void library_end (void);
244
245 #define set_args prefix(set_args)
246 void set_args (int, char **);
247
248 #define get_args prefix(get_args)
249 void get_args (int *, char ***);
250
251
252 /* error.c */
253 #define rtoa prefix(rtoa)
254 char *rtoa (double f, int length, int oprec);
255
256 #define itoa prefix(itoa)
257 char *itoa (int64_t);
258
259 #define xtoa prefix(xtoa)
260 char *xtoa (uint64_t);
261
262 #define os_error prefix(os_error)
263 void os_error (const char *) __attribute__ ((noreturn));
264
265 #define show_locus prefix(show_locus)
266 void show_locus (void);
267
268 #define runtime_error prefix(runtime_error)
269 void runtime_error (const char *) __attribute__ ((noreturn));
270
271 #define internal_error prefix(internal_error)
272 void internal_error (const char *) __attribute__ ((noreturn));
273
274 #define get_oserror prefix(get_oserror)
275 const char *get_oserror (void);
276
277 #define write_error prefix(write_error)
278 void write_error (const char *);
279
280 #define sys_exit prefix(sys_exit)
281 void sys_exit (int) __attribute__ ((noreturn));
282
283 #define st_printf prefix(st_printf)
284 int st_printf (const char *, ...) __attribute__ ((format (printf, 1, 2)));
285
286 #define st_sprintf prefix(st_sprintf)
287 void st_sprintf (char *, const char *, ...) __attribute__ ((format (printf, 2, 3)));
288
289 #define translate_error prefix(translate_error)
290 const char *translate_error (int);
291
292 #define generate_error prefix(generate_error)
293 void generate_error (int, const char *);
294
295
296 /* memory.c */
297
298 #define memory_init     prefix(memory_init)
299 void memory_init (void);
300
301 #define runtime_cleanup prefix(runtime_cleanup)
302 void runtime_cleanup (void);
303
304 #define get_mem         prefix(get_mem)
305 void *get_mem (size_t) __attribute__ ((malloc));
306
307 #define free_mem        prefix(free_mem)
308 void free_mem (void *);
309
310 #define internal_malloc_size    prefix(internal_malloc_size)
311 void *internal_malloc_size (size_t);
312
313 #define internal_malloc prefix(internal_malloc)
314 void *internal_malloc (GFC_INTEGER_4);
315
316 #define internal_malloc64 prefix(internal_malloc64)
317 void *internal_malloc64 (GFC_INTEGER_8);
318
319 #define internal_free   prefix(internal_free)
320 void internal_free (void *);
321
322 #define allocate        prefix(allocate)
323 void allocate (void **, GFC_INTEGER_4, GFC_INTEGER_4 *);
324
325 #define allocate64      prefix(allocate64)
326 void allocate64 (void **, GFC_INTEGER_8, GFC_INTEGER_4 *);
327
328 #define deallocate      prefix(deallocate)
329 void deallocate (void **, GFC_INTEGER_4 *);
330
331
332 /* environ.c */
333
334 #define check_buffered prefix(check_buffered)
335 int check_buffered (int);
336
337 #define init_variables prefix(init_variables)
338 void init_variables (void);
339
340 #define show_variables prefix(show_variables)
341 void show_variables (void);
342
343
344 /* string.c */
345
346 #define find_option prefix(find_option)
347 int find_option (const char *, int, st_option *, const char *);
348
349 #define fstrlen prefix(fstrlen)
350 int fstrlen (const char *, int);
351
352 #define fstrcpy prefix(fstrcpy)
353 void fstrcpy (char *, int, const char *, int);
354
355 #define cf_strcpy prefix(cf_strcpy)
356 void cf_strcpy (char *, int, const char *);
357
358 /* io.c */
359
360 #define init_units prefix(init_units)
361 void init_units (void);
362
363 #define close_units prefix(close_units)
364 void close_units (void);
365
366 /* stop.c */
367 #define stop_numeric prefix(stop_numeric)
368 void stop_numeric (GFC_INTEGER_4);
369
370 /* reshape_packed.c */
371 #define reshape_packed prefix(reshape_packed)
372 void reshape_packed (char *, index_type, const char *, index_type,
373                      const char *, index_type);
374
375 /* Repacking functions.  */
376 #define internal_pack prefix(internal_pack)
377 void *internal_pack (gfc_array_char *);
378
379 #define internal_unpack prefix(internal_unpack)
380 void internal_unpack (gfc_array_char *, const void *);
381
382 #define internal_pack_4 prefix(internal_pack_4)
383 GFC_INTEGER_4 *internal_pack_4 (gfc_array_i4 *);
384
385 #define internal_pack_8 prefix(internal_pack_8)
386 GFC_INTEGER_8 *internal_pack_8 (gfc_array_i8 *);
387
388 #define internal_unpack_4 prefix(internal_unpack_4)
389 void internal_unpack_4 (gfc_array_i4 *, const GFC_INTEGER_4 *);
390
391 #define internal_unpack_8 prefix(internal_unpack_8)
392 void internal_unpack_8 (gfc_array_i8 *, const GFC_INTEGER_8 *);
393
394 /* date_and_time.c */
395
396 #define date_and_time prefix(date_and_time)
397 void date_and_time (char *, char *, char *, gfc_array_i4 *,
398                    GFC_INTEGER_4, GFC_INTEGER_4, GFC_INTEGER_4);
399
400 /* string_intrinsics.c */
401
402 #define compare_string prefix(compare_string)
403 GFC_INTEGER_4 compare_string (GFC_INTEGER_4, const char *,
404                               GFC_INTEGER_4, const char *);
405
406 /* random.c */
407
408 #define random_seed prefix(random_seed)
409 void random_seed (GFC_INTEGER_4 * size, gfc_array_i4 * put,
410                   gfc_array_i4 * get);
411
412 /* normalize.c */
413
414 #define normalize_r4_i4 prefix(normalize_r4_i4)
415 GFC_REAL_4 normalize_r4_i4 (GFC_UINTEGER_4, GFC_UINTEGER_4);
416
417 #define normalize_r8_i8 prefix(normalize_r8_i8)
418 GFC_REAL_8 normalize_r8_i8 (GFC_UINTEGER_8, GFC_UINTEGER_8);
419
420 /* size.c */
421
422 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) array_t;
423
424 #define size0 prefix(size0)
425 index_type size0 (const array_t * array); 
426
427 #endif
428