OSDN Git Service

Remove free_mem
[pf3gnuchains/gcc-fork.git] / libgfortran / libgfortran.h
1 /* Common declarations for all of libgfortran.
2    Copyright (C) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
3    Free Software Foundation, Inc.
4    Contributed by Paul Brook <paul@nowt.org>, and
5    Andy Vaught <andy@xena.eas.asu.edu>
6
7 This file is part of the GNU Fortran runtime library (libgfortran).
8
9 Libgfortran is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3, or (at your option)
12 any later version.
13
14 Libgfortran is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17 GNU General Public License for more details.
18
19 Under Section 7 of GPL version 3, you are granted additional
20 permissions described in the GCC Runtime Library Exception, version
21 3.1, as published by the Free Software Foundation.
22
23 You should have received a copy of the GNU General Public License and
24 a copy of the GCC Runtime Library Exception along with this program;
25 see the files COPYING3 and COPYING.RUNTIME respectively.  If not, see
26 <http://www.gnu.org/licenses/>.  */
27
28 #ifndef LIBGFOR_H
29 #define LIBGFOR_H
30
31 /* Ensure that ANSI conform stdio is used. This needs to be set before
32    any system header file is included.  */
33 #if defined __MINGW32__
34 #  define _POSIX 1
35 #  define gfc_printf gnu_printf
36 #else
37 #  define gfc_printf __printf__
38 #endif
39
40 /* config.h MUST be first because it can affect system headers.  */
41 #include "config.h"
42
43 #include <stdio.h>
44 #include <math.h>
45 #include <stddef.h>
46 #include <float.h>
47 #include <stdarg.h>
48
49 #ifdef __MINGW32__
50 extern float __strtof (const char *, char **);
51 #define gfc_strtof __strtof
52 extern double __strtod (const char *, char **);
53 #define gfc_strtod __strtod
54 extern long double __strtold (const char *, char **);
55 #define gfc_strtold __strtold
56 #else
57 #define gfc_strtof strtof
58 #define gfc_strtod strtod
59 #define gfc_strtold strtold
60 #endif
61
62 #if HAVE_COMPLEX_H
63 # include <complex.h>
64 #else
65 #define complex __complex__
66 #endif
67
68 #include "../gcc/fortran/libgfortran.h"
69
70 #include "c99_protos.h"
71
72 #if HAVE_IEEEFP_H
73 #include <ieeefp.h>
74 #endif
75
76 #include "gstdint.h"
77
78 #if HAVE_SYS_TYPES_H
79 #include <sys/types.h>
80 #endif
81
82 #ifdef __MINGW32__
83 typedef off64_t gfc_offset;
84 #else
85 typedef off_t gfc_offset;
86 #endif
87
88 #ifndef NULL
89 #define NULL (void *) 0
90 #endif
91
92 #ifndef __GNUC__
93 #define __attribute__(x)
94 #define likely(x)       (x)
95 #define unlikely(x)     (x)
96 #else
97 #define likely(x)       __builtin_expect(!!(x), 1)
98 #define unlikely(x)     __builtin_expect(!!(x), 0)
99 #endif
100
101
102 /* We use intptr_t and uintptr_t, which may not be always defined in
103    system headers.  */
104
105 #ifndef HAVE_INTPTR_T
106 #if __SIZEOF_POINTER__ == __SIZEOF_LONG__
107 #define intptr_t long
108 #elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
109 #define intptr_t long long
110 #elif __SIZEOF_POINTER__ == __SIZEOF_INT__
111 #define intptr_t int
112 #elif __SIZEOF_POINTER__ == __SIZEOF_SHORT__
113 #define intptr_t short
114 #else
115 #error "Pointer type with unexpected size"
116 #endif
117 #endif
118
119 #ifndef HAVE_UINTPTR_T
120 #if __SIZEOF_POINTER__ == __SIZEOF_LONG__
121 #define uintptr_t unsigned long
122 #elif __SIZEOF_POINTER__ == __SIZEOF_LONG_LONG__
123 #define uintptr_t unsigned long long
124 #elif __SIZEOF_POINTER__ == __SIZEOF_INT__
125 #define uintptr_t unsigned int
126 #elif __SIZEOF_POINTER__ == __SIZEOF_SHORT__
127 #define uintptr_t unsigned short
128 #else
129 #error "Pointer type with unexpected size"
130 #endif
131 #endif
132
133
134 /* On mingw, work around the buggy Windows snprintf() by using the one
135    mingw provides, __mingw_snprintf().  We also provide a prototype for
136    __mingw_snprintf(), because the mingw headers currently don't have one.  */
137 #if HAVE_MINGW_SNPRINTF
138 extern int __mingw_snprintf (char *, size_t, const char *, ...)
139      __attribute__ ((format (gnu_printf, 3, 4)));
140 #undef snprintf
141 #define snprintf __mingw_snprintf
142 #endif
143
144
145 /* For a library, a standard prefix is a requirement in order to partition
146    the namespace.  IPREFIX is for symbols intended to be internal to the
147    library.  */
148 #define PREFIX(x)       _gfortran_ ## x
149 #define IPREFIX(x)      _gfortrani_ ## x
150
151 /* Magic to rename a symbol at the compiler level.  You continue to refer
152    to the symbol as OLD in the source, but it'll be named NEW in the asm.  */
153 #define sym_rename(old, new) sym_rename1(old, __USER_LABEL_PREFIX__, new)
154 #define sym_rename1(old, ulp, new) sym_rename2(old, ulp, new)
155 #define sym_rename2(old, ulp, new) extern __typeof(old) old __asm__(#ulp #new)
156
157 /* There are several classifications of routines:
158
159      (1) Symbols used only within the library,
160      (2) Symbols to be exported from the library,
161      (3) Symbols to be exported from the library, but
162          also used inside the library.
163
164    By telling the compiler about these different classifications we can
165    tightly control the interface seen by the user, and get better code
166    from the compiler at the same time.
167
168    One of the following should be used immediately after the declaration
169    of each symbol:
170
171      internal_proto     Marks a symbol used only within the library,
172                         and adds IPREFIX to the assembly-level symbol
173                         name.  The later is important for maintaining
174                         the namespace partition for the static library.
175
176      export_proto       Marks a symbol to be exported, and adds PREFIX
177                         to the assembly-level symbol name.
178
179      export_proto_np    Marks a symbol to be exported without adding PREFIX.
180
181      iexport_proto      Marks a function to be exported, but with the 
182                         understanding that it can be used inside as well.
183
184      iexport_data_proto Similarly, marks a data symbol to be exported.
185                         Unfortunately, some systems can't play the hidden
186                         symbol renaming trick on data symbols, thanks to
187                         the horribleness of COPY relocations.
188
189    If iexport_proto or iexport_data_proto is used, you must also use
190    iexport or iexport_data after the *definition* of the symbol.  */
191
192 #if defined(HAVE_ATTRIBUTE_VISIBILITY)
193 # define internal_proto(x) \
194         sym_rename(x, IPREFIX (x)) __attribute__((__visibility__("hidden")))
195 #else
196 # define internal_proto(x)      sym_rename(x, IPREFIX(x))
197 #endif
198
199 #if defined(HAVE_ATTRIBUTE_VISIBILITY) && defined(HAVE_ATTRIBUTE_ALIAS)
200 # define export_proto(x)        sym_rename(x, PREFIX(x))
201 # define export_proto_np(x)     extern char swallow_semicolon
202 # define iexport_proto(x)       internal_proto(x)
203 # define iexport(x)             iexport1(x, IPREFIX(x))
204 # define iexport1(x,y)          iexport2(x,y)
205 # define iexport2(x,y) \
206         extern __typeof(x) PREFIX(x) __attribute__((__alias__(#y)))
207 #else
208 # define export_proto(x)        sym_rename(x, PREFIX(x))
209 # define export_proto_np(x)     extern char swallow_semicolon
210 # define iexport_proto(x)       export_proto(x)
211 # define iexport(x)             extern char swallow_semicolon
212 #endif
213
214 /* TODO: detect the case when we *can* hide the symbol.  */
215 #define iexport_data_proto(x)   export_proto(x)
216 #define iexport_data(x)         extern char swallow_semicolon
217
218 /* The only reliable way to get the offset of a field in a struct
219    in a system independent way is via this macro.  */
220 #ifndef offsetof
221 #define offsetof(TYPE, MEMBER)  ((size_t) &((TYPE *) 0)->MEMBER)
222 #endif
223
224 /* The isfinite macro is only available with C99, but some non-C99
225    systems still provide fpclassify, and there is a `finite' function
226    in BSD.
227
228    Also, isfinite is broken on Cygwin.
229
230    When isfinite is not available, try to use one of the
231    alternatives, or bail out.  */
232
233 #if defined(HAVE_BROKEN_ISFINITE) || defined(__CYGWIN__)
234 #undef isfinite
235 #endif
236
237 #if defined(HAVE_BROKEN_ISNAN)
238 #undef isnan
239 #endif
240
241 #if defined(HAVE_BROKEN_FPCLASSIFY)
242 #undef fpclassify
243 #endif
244
245 #if !defined(isfinite)
246 #if !defined(fpclassify)
247 #define isfinite(x) ((x) - (x) == 0)
248 #else
249 #define isfinite(x) (fpclassify(x) != FP_NAN && fpclassify(x) != FP_INFINITE)
250 #endif /* !defined(fpclassify) */
251 #endif /* !defined(isfinite)  */
252
253 #if !defined(isnan)
254 #if !defined(fpclassify)
255 #define isnan(x) ((x) != (x))
256 #else
257 #define isnan(x) (fpclassify(x) == FP_NAN)
258 #endif /* !defined(fpclassify) */
259 #endif /* !defined(isfinite)  */
260
261 /* TODO: find the C99 version of these an move into above ifdef.  */
262 #define REALPART(z) (__real__(z))
263 #define IMAGPART(z) (__imag__(z))
264 #define COMPLEX_ASSIGN(z_, r_, i_) {__real__(z_) = (r_); __imag__(z_) = (i_);}
265
266 #include "kinds.h"
267
268 /* Define the type used for the current record number for large file I/O.
269    The size must be consistent with the size defined on the compiler side.  */
270 #ifdef HAVE_GFC_INTEGER_8
271 typedef GFC_INTEGER_8 GFC_IO_INT;
272 #else
273 #ifdef HAVE_GFC_INTEGER_4
274 typedef GFC_INTEGER_4 GFC_IO_INT;
275 #else
276 #error "GFC_INTEGER_4 should be available for the library to compile".
277 #endif
278 #endif
279
280 /* The following two definitions must be consistent with the types used
281    by the compiler.  */
282 /* The type used of array indices, amongst other things.  */
283 typedef ssize_t index_type;
284
285 /* The type used for the lengths of character variables.  */
286 typedef GFC_INTEGER_4 gfc_charlen_type;
287
288 /* Definitions of CHARACTER data types:
289      - CHARACTER(KIND=1) corresponds to the C char type,
290      - CHARACTER(KIND=4) corresponds to an unsigned 32-bit integer.  */
291 typedef GFC_UINTEGER_4 gfc_char4_t;
292
293 /* Byte size of character kinds.  For the kinds currently supported, it's
294    simply equal to the kind parameter itself.  */
295 #define GFC_SIZE_OF_CHAR_KIND(kind) (kind)
296
297 /* This will be 0 on little-endian machines and one on big-endian machines.  */
298 extern int big_endian;
299 internal_proto(big_endian);
300
301 #define GFOR_POINTER_TO_L1(p, kind) \
302   (big_endian * (kind - 1) + (GFC_LOGICAL_1 *)(p))
303
304 #define GFC_INTEGER_1_HUGE \
305   (GFC_INTEGER_1)((((GFC_UINTEGER_1)1) << 7) - 1)
306 #define GFC_INTEGER_2_HUGE \
307   (GFC_INTEGER_2)((((GFC_UINTEGER_2)1) << 15) - 1)
308 #define GFC_INTEGER_4_HUGE \
309   (GFC_INTEGER_4)((((GFC_UINTEGER_4)1) << 31) - 1)
310 #define GFC_INTEGER_8_HUGE \
311   (GFC_INTEGER_8)((((GFC_UINTEGER_8)1) << 63) - 1)
312 #ifdef HAVE_GFC_INTEGER_16
313 #define GFC_INTEGER_16_HUGE \
314   (GFC_INTEGER_16)((((GFC_UINTEGER_16)1) << 127) - 1)
315 #endif
316
317 /* M{IN,AX}{LOC,VAL} need also infinities and NaNs if supported.  */
318
319 #ifdef __FLT_HAS_INFINITY__
320 # define GFC_REAL_4_INFINITY __builtin_inff ()
321 #endif
322 #ifdef __DBL_HAS_INFINITY__
323 # define GFC_REAL_8_INFINITY __builtin_inf ()
324 #endif
325 #ifdef __LDBL_HAS_INFINITY__
326 # ifdef HAVE_GFC_REAL_10
327 #  define GFC_REAL_10_INFINITY __builtin_infl ()
328 # endif
329 # ifdef HAVE_GFC_REAL_16
330 #  define GFC_REAL_16_INFINITY __builtin_infl ()
331 # endif
332 #endif
333 #ifdef __FLT_HAS_QUIET_NAN__
334 # define GFC_REAL_4_QUIET_NAN __builtin_nanf ("")
335 #endif
336 #ifdef __DBL_HAS_QUIET_NAN__
337 # define GFC_REAL_8_QUIET_NAN __builtin_nan ("")
338 #endif
339 #ifdef __LDBL_HAS_QUIET_NAN__
340 # ifdef HAVE_GFC_REAL_10
341 #  define GFC_REAL_10_QUIET_NAN __builtin_nanl ("")
342 # endif
343 # ifdef HAVE_GFC_REAL_16
344 #  define GFC_REAL_16_QUIET_NAN __builtin_nanl ("")
345 # endif
346 #endif
347
348 typedef struct descriptor_dimension
349 {
350   index_type _stride;
351   index_type _lbound;
352   index_type _ubound;
353 }
354
355 descriptor_dimension;
356
357 #define GFC_ARRAY_DESCRIPTOR(r, type) \
358 struct {\
359   type *data;\
360   size_t offset;\
361   index_type dtype;\
362   descriptor_dimension dim[r];\
363 }
364
365 /* Commonly used array descriptor types.  */
366 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) gfc_array_void;
367 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, char) gfc_array_char;
368 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_1) gfc_array_i1;
369 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_2) gfc_array_i2;
370 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_4) gfc_array_i4;
371 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_8) gfc_array_i8;
372 #ifdef HAVE_GFC_INTEGER_16
373 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_INTEGER_16) gfc_array_i16;
374 #endif
375 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_4) gfc_array_r4;
376 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_8) gfc_array_r8;
377 #ifdef HAVE_GFC_REAL_10
378 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_10) gfc_array_r10;
379 #endif
380 #ifdef HAVE_GFC_REAL_16
381 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_REAL_16) gfc_array_r16;
382 #endif
383 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_4) gfc_array_c4;
384 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_8) gfc_array_c8;
385 #ifdef HAVE_GFC_COMPLEX_10
386 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_10) gfc_array_c10;
387 #endif
388 #ifdef HAVE_GFC_COMPLEX_16
389 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_COMPLEX_16) gfc_array_c16;
390 #endif
391 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_1) gfc_array_l1;
392 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_2) gfc_array_l2;
393 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_4) gfc_array_l4;
394 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_8) gfc_array_l8;
395 #ifdef HAVE_GFC_LOGICAL_16
396 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, GFC_LOGICAL_16) gfc_array_l16;
397 #endif
398
399
400 #define GFC_DESCRIPTOR_RANK(desc) ((desc)->dtype & GFC_DTYPE_RANK_MASK)
401 #define GFC_DESCRIPTOR_TYPE(desc) (((desc)->dtype & GFC_DTYPE_TYPE_MASK) \
402                                    >> GFC_DTYPE_TYPE_SHIFT)
403 #define GFC_DESCRIPTOR_SIZE(desc) ((desc)->dtype >> GFC_DTYPE_SIZE_SHIFT)
404 #define GFC_DESCRIPTOR_DATA(desc) ((desc)->data)
405 #define GFC_DESCRIPTOR_DTYPE(desc) ((desc)->dtype)
406
407 #define GFC_DIMENSION_LBOUND(dim) ((dim)._lbound)
408 #define GFC_DIMENSION_UBOUND(dim) ((dim)._ubound)
409 #define GFC_DIMENSION_STRIDE(dim) ((dim)._stride)
410 #define GFC_DIMENSION_EXTENT(dim) ((dim)._ubound + 1 - (dim)._lbound)
411 #define GFC_DIMENSION_SET(dim,lb,ub,str) \
412   do \
413     { \
414       (dim)._lbound = lb;                       \
415       (dim)._ubound = ub;                       \
416       (dim)._stride = str;                      \
417     } while (0)
418             
419
420 #define GFC_DESCRIPTOR_LBOUND(desc,i) ((desc)->dim[i]._lbound)
421 #define GFC_DESCRIPTOR_UBOUND(desc,i) ((desc)->dim[i]._ubound)
422 #define GFC_DESCRIPTOR_EXTENT(desc,i) ((desc)->dim[i]._ubound + 1 \
423                                       - (desc)->dim[i]._lbound)
424 #define GFC_DESCRIPTOR_EXTENT_BYTES(desc,i) \
425   (GFC_DESCRIPTOR_EXTENT(desc,i) * GFC_DESCRIPTOR_SIZE(desc))
426
427 #define GFC_DESCRIPTOR_STRIDE(desc,i) ((desc)->dim[i]._stride)
428 #define GFC_DESCRIPTOR_STRIDE_BYTES(desc,i) \
429   (GFC_DESCRIPTOR_STRIDE(desc,i) * GFC_DESCRIPTOR_SIZE(desc))
430
431 /* Macros to get both the size and the type with a single masking operation  */
432
433 #define GFC_DTYPE_SIZE_MASK \
434   ((~((index_type) 0) >> GFC_DTYPE_SIZE_SHIFT) << GFC_DTYPE_SIZE_SHIFT)
435 #define GFC_DTYPE_TYPE_SIZE_MASK (GFC_DTYPE_SIZE_MASK | GFC_DTYPE_TYPE_MASK)
436
437 #define GFC_DTYPE_TYPE_SIZE(desc) ((desc)->dtype & GFC_DTYPE_TYPE_SIZE_MASK)
438
439 #define GFC_DTYPE_INTEGER_1 ((GFC_DTYPE_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
440    | (sizeof(GFC_INTEGER_1) << GFC_DTYPE_SIZE_SHIFT))
441 #define GFC_DTYPE_INTEGER_2 ((GFC_DTYPE_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
442    | (sizeof(GFC_INTEGER_2) << GFC_DTYPE_SIZE_SHIFT))
443 #define GFC_DTYPE_INTEGER_4 ((GFC_DTYPE_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
444    | (sizeof(GFC_INTEGER_4) << GFC_DTYPE_SIZE_SHIFT))
445 #define GFC_DTYPE_INTEGER_8 ((GFC_DTYPE_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
446    | (sizeof(GFC_INTEGER_8) << GFC_DTYPE_SIZE_SHIFT))
447 #ifdef HAVE_GFC_INTEGER_16
448 #define GFC_DTYPE_INTEGER_16 ((GFC_DTYPE_INTEGER << GFC_DTYPE_TYPE_SHIFT) \
449    | (sizeof(GFC_INTEGER_16) << GFC_DTYPE_SIZE_SHIFT))
450 #endif
451
452 #define GFC_DTYPE_LOGICAL_1 ((GFC_DTYPE_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
453    | (sizeof(GFC_LOGICAL_1) << GFC_DTYPE_SIZE_SHIFT))
454 #define GFC_DTYPE_LOGICAL_2 ((GFC_DTYPE_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
455    | (sizeof(GFC_LOGICAL_2) << GFC_DTYPE_SIZE_SHIFT))
456 #define GFC_DTYPE_LOGICAL_4 ((GFC_DTYPE_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
457    | (sizeof(GFC_LOGICAL_4) << GFC_DTYPE_SIZE_SHIFT))
458 #define GFC_DTYPE_LOGICAL_8 ((GFC_DTYPE_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
459    | (sizeof(GFC_LOGICAL_8) << GFC_DTYPE_SIZE_SHIFT))
460 #ifdef HAVE_GFC_LOGICAL_16
461 #define GFC_DTYPE_LOGICAL_16 ((GFC_DTYPE_LOGICAL << GFC_DTYPE_TYPE_SHIFT) \
462    | (sizeof(GFC_LOGICAL_16) << GFC_DTYPE_SIZE_SHIFT))
463 #endif
464
465 #define GFC_DTYPE_REAL_4 ((GFC_DTYPE_REAL << GFC_DTYPE_TYPE_SHIFT) \
466    | (sizeof(GFC_REAL_4) << GFC_DTYPE_SIZE_SHIFT))
467 #define GFC_DTYPE_REAL_8 ((GFC_DTYPE_REAL << GFC_DTYPE_TYPE_SHIFT) \
468    | (sizeof(GFC_REAL_8) << GFC_DTYPE_SIZE_SHIFT))
469 #ifdef HAVE_GFC_REAL_10
470 #define GFC_DTYPE_REAL_10  ((GFC_DTYPE_REAL << GFC_DTYPE_TYPE_SHIFT) \
471    | (sizeof(GFC_REAL_10) << GFC_DTYPE_SIZE_SHIFT))
472 #endif
473 #ifdef HAVE_GFC_REAL_16
474 #define GFC_DTYPE_REAL_16 ((GFC_DTYPE_REAL << GFC_DTYPE_TYPE_SHIFT) \
475    | (sizeof(GFC_REAL_16) << GFC_DTYPE_SIZE_SHIFT))
476 #endif
477
478 #define GFC_DTYPE_COMPLEX_4 ((GFC_DTYPE_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
479    | (sizeof(GFC_COMPLEX_4) << GFC_DTYPE_SIZE_SHIFT))
480 #define GFC_DTYPE_COMPLEX_8 ((GFC_DTYPE_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
481    | (sizeof(GFC_COMPLEX_8) << GFC_DTYPE_SIZE_SHIFT))
482 #ifdef HAVE_GFC_COMPLEX_10
483 #define GFC_DTYPE_COMPLEX_10 ((GFC_DTYPE_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
484    | (sizeof(GFC_COMPLEX_10) << GFC_DTYPE_SIZE_SHIFT))
485 #endif
486 #ifdef HAVE_GFC_COMPLEX_16
487 #define GFC_DTYPE_COMPLEX_16 ((GFC_DTYPE_COMPLEX << GFC_DTYPE_TYPE_SHIFT) \
488    | (sizeof(GFC_COMPLEX_16) << GFC_DTYPE_SIZE_SHIFT))
489 #endif
490
491 #define GFC_DTYPE_DERIVED_1 ((GFC_DTYPE_DERIVED << GFC_DTYPE_TYPE_SHIFT) \
492    | (sizeof(GFC_INTEGER_1) << GFC_DTYPE_SIZE_SHIFT))
493 #define GFC_DTYPE_DERIVED_2 ((GFC_DTYPE_DERIVED << GFC_DTYPE_TYPE_SHIFT) \
494    | (sizeof(GFC_INTEGER_2) << GFC_DTYPE_SIZE_SHIFT))
495 #define GFC_DTYPE_DERIVED_4 ((GFC_DTYPE_DERIVED << GFC_DTYPE_TYPE_SHIFT) \
496    | (sizeof(GFC_INTEGER_4) << GFC_DTYPE_SIZE_SHIFT))
497 #define GFC_DTYPE_DERIVED_8 ((GFC_DTYPE_DERIVED << GFC_DTYPE_TYPE_SHIFT) \
498    | (sizeof(GFC_INTEGER_8) << GFC_DTYPE_SIZE_SHIFT))
499 #ifdef HAVE_GFC_INTEGER_16
500 #define GFC_DTYPE_DERIVED_16 ((GFC_DTYPE_DERIVED << GFC_DTYPE_TYPE_SHIFT) \
501    | (sizeof(GFC_INTEGER_16) << GFC_DTYPE_SIZE_SHIFT))
502 #endif
503
504 /* Macros to determine the alignment of pointers.  */
505
506 #define GFC_UNALIGNED_2(x) (((uintptr_t)(x)) & \
507                             (__alignof__(GFC_INTEGER_2) - 1))
508 #define GFC_UNALIGNED_4(x) (((uintptr_t)(x)) & \
509                             (__alignof__(GFC_INTEGER_4) - 1))
510 #define GFC_UNALIGNED_8(x) (((uintptr_t)(x)) & \
511                             (__alignof__(GFC_INTEGER_8) - 1))
512 #ifdef HAVE_GFC_INTEGER_16
513 #define GFC_UNALIGNED_16(x) (((uintptr_t)(x)) & \
514                              (__alignof__(GFC_INTEGER_16) - 1))
515 #endif
516
517 #define GFC_UNALIGNED_C4(x) (((uintptr_t)(x)) & \
518                              (__alignof__(GFC_COMPLEX_4) - 1))
519
520 #define GFC_UNALIGNED_C8(x) (((uintptr_t)(x)) & \
521                              (__alignof__(GFC_COMPLEX_8) - 1))
522
523 /* Runtime library include.  */
524 #define stringize(x) expand_macro(x)
525 #define expand_macro(x) # x
526
527 /* Runtime options structure.  */
528
529 typedef struct
530 {
531   int stdin_unit, stdout_unit, stderr_unit, optional_plus;
532   int locus;
533
534   int separator_len;
535   const char *separator;
536
537   int use_stderr, all_unbuffered, unbuffered_preconnected, default_recl;
538   int fpe, dump_core, backtrace;
539 }
540 options_t;
541
542 extern options_t options;
543 internal_proto(options);
544
545 extern void handler (int);
546 internal_proto(handler);
547
548
549 /* Compile-time options that will influence the library.  */
550
551 typedef struct
552 {
553   int warn_std;
554   int allow_std;
555   int pedantic;
556   int convert;
557   int dump_core;
558   int backtrace;
559   int sign_zero;
560   size_t record_marker;
561   int max_subrecord_length;
562   int bounds_check;
563   int range_check;
564 }
565 compile_options_t;
566
567 extern compile_options_t compile_options;
568 internal_proto(compile_options);
569
570 extern void init_compile_options (void);
571 internal_proto(init_compile_options);
572
573 #define GFC_MAX_SUBRECORD_LENGTH 2147483639   /* 2**31 - 9 */
574
575 /* Structure for statement options.  */
576
577 typedef struct
578 {
579   const char *name;
580   int value;
581 }
582 st_option;
583
584
585 /* This is returned by notification_std to know if, given the flags
586    that were given (-std=, -pedantic) we should issue an error, a warning
587    or nothing.  */
588 typedef enum
589 { NOTIFICATION_SILENT, NOTIFICATION_WARNING, NOTIFICATION_ERROR }
590 notification;
591
592 /* This is returned by notify_std and several io functions.  */
593 typedef enum
594 { SUCCESS = 1, FAILURE }
595 try;
596
597 /* The filename and line number don't go inside the globals structure.
598    They are set by the rest of the program and must be linked to.  */
599
600 /* Location of the current library call (optional).  */
601 extern unsigned line;
602 iexport_data_proto(line);
603
604 extern char *filename;
605 iexport_data_proto(filename);
606
607 /* Avoid conflicting prototypes of alloca() in system headers by using 
608    GCC's builtin alloca().  */
609 #define gfc_alloca(x)  __builtin_alloca(x)
610
611
612 /* Directory for creating temporary files.  Only used when none of the
613    following environment variables exist: GFORTRAN_TMPDIR, TMP and TEMP.  */
614 #define DEFAULT_TEMPDIR "/tmp"
615
616 /* The default value of record length for preconnected units is defined
617    here. This value can be overriden by an environment variable.
618    Default value is 1 Gb.  */
619 #define DEFAULT_RECL 1073741824
620
621
622 #define CHARACTER2(name) \
623               gfc_charlen_type name ## _len; \
624               char * name
625
626 typedef struct st_parameter_common
627 {
628   GFC_INTEGER_4 flags;
629   GFC_INTEGER_4 unit;
630   const char *filename;
631   GFC_INTEGER_4 line;
632   CHARACTER2 (iomsg);
633   GFC_INTEGER_4 *iostat;
634 }
635 st_parameter_common;
636
637 #undef CHARACTER2
638
639 #define IOPARM_LIBRETURN_MASK           (3 << 0)
640 #define IOPARM_LIBRETURN_OK             (0 << 0)
641 #define IOPARM_LIBRETURN_ERROR          (1 << 0)
642 #define IOPARM_LIBRETURN_END            (2 << 0)
643 #define IOPARM_LIBRETURN_EOR            (3 << 0)
644 #define IOPARM_ERR                      (1 << 2)
645 #define IOPARM_END                      (1 << 3)
646 #define IOPARM_EOR                      (1 << 4)
647 #define IOPARM_HAS_IOSTAT               (1 << 5)
648 #define IOPARM_HAS_IOMSG                (1 << 6)
649
650 #define IOPARM_COMMON_MASK              ((1 << 7) - 1)
651
652 #define IOPARM_OPEN_HAS_RECL_IN         (1 << 7)
653 #define IOPARM_OPEN_HAS_FILE            (1 << 8)
654 #define IOPARM_OPEN_HAS_STATUS          (1 << 9)
655 #define IOPARM_OPEN_HAS_ACCESS          (1 << 10)
656 #define IOPARM_OPEN_HAS_FORM            (1 << 11)
657 #define IOPARM_OPEN_HAS_BLANK           (1 << 12)
658 #define IOPARM_OPEN_HAS_POSITION        (1 << 13)
659 #define IOPARM_OPEN_HAS_ACTION          (1 << 14)
660 #define IOPARM_OPEN_HAS_DELIM           (1 << 15)
661 #define IOPARM_OPEN_HAS_PAD             (1 << 16)
662 #define IOPARM_OPEN_HAS_CONVERT         (1 << 17)
663 #define IOPARM_OPEN_HAS_DECIMAL         (1 << 18)
664 #define IOPARM_OPEN_HAS_ENCODING        (1 << 19)
665 #define IOPARM_OPEN_HAS_ROUND           (1 << 20)
666 #define IOPARM_OPEN_HAS_SIGN            (1 << 21)
667 #define IOPARM_OPEN_HAS_ASYNCHRONOUS    (1 << 22)
668 #define IOPARM_OPEN_HAS_NEWUNIT         (1 << 23)
669
670 /* library start function and end macro.  These can be expanded if needed
671    in the future.  cmp is st_parameter_common *cmp  */
672
673 extern void library_start (st_parameter_common *);
674 internal_proto(library_start);
675
676 #define library_end()
677
678 /* main.c */
679
680 extern void stupid_function_name_for_static_linking (void);
681 internal_proto(stupid_function_name_for_static_linking);
682
683 extern void set_args (int, char **);
684 iexport_proto(set_args);
685
686 extern void get_args (int *, char ***);
687 internal_proto(get_args);
688
689 extern void store_exe_path (const char *);
690 export_proto(store_exe_path);
691
692 extern char * full_exe_path (void);
693 internal_proto(full_exe_path);
694
695 /* backtrace.c */
696
697 extern void show_backtrace (void);
698 internal_proto(show_backtrace);
699
700 /* error.c */
701
702 #if defined(HAVE_GFC_REAL_16)
703 #define GFC_LARGEST_BUF (sizeof (GFC_REAL_16))
704 #elif defined(HAVE_GFC_INTEGER_16)
705 #define GFC_LARGEST_BUF (sizeof (GFC_INTEGER_LARGEST))
706 #elif defined(HAVE_GFC_REAL_10)
707 #define GFC_LARGEST_BUF (sizeof (GFC_REAL_10))
708 #else
709 #define GFC_LARGEST_BUF (sizeof (GFC_INTEGER_LARGEST))
710 #endif
711
712 #define GFC_ITOA_BUF_SIZE (sizeof (GFC_INTEGER_LARGEST) * 3 + 2)
713 #define GFC_XTOA_BUF_SIZE (GFC_LARGEST_BUF * 2 + 1)
714 #define GFC_OTOA_BUF_SIZE (GFC_LARGEST_BUF * 3 + 1)
715 #define GFC_BTOA_BUF_SIZE (GFC_LARGEST_BUF * 8 + 1)
716
717 extern void sys_exit (int) __attribute__ ((noreturn));
718 internal_proto(sys_exit);
719
720 extern const char *gfc_xtoa (GFC_UINTEGER_LARGEST, char *, size_t);
721 internal_proto(gfc_xtoa);
722
723 extern void os_error (const char *) __attribute__ ((noreturn));
724 iexport_proto(os_error);
725
726 extern void show_locus (st_parameter_common *);
727 internal_proto(show_locus);
728
729 extern void runtime_error (const char *, ...)
730      __attribute__ ((noreturn, format (gfc_printf, 1, 2)));
731 iexport_proto(runtime_error);
732
733 extern void runtime_error_at (const char *, const char *, ...)
734      __attribute__ ((noreturn, format (gfc_printf, 2, 3)));
735 iexport_proto(runtime_error_at);
736
737 extern void runtime_warning_at (const char *, const char *, ...)
738      __attribute__ ((format (gfc_printf, 2, 3)));
739 iexport_proto(runtime_warning_at);
740
741 extern void internal_error (st_parameter_common *, const char *)
742   __attribute__ ((noreturn));
743 internal_proto(internal_error);
744
745 extern const char *get_oserror (void);
746 internal_proto(get_oserror);
747
748 extern const char *translate_error (int);
749 internal_proto(translate_error);
750
751 extern void generate_error (st_parameter_common *, int, const char *);
752 iexport_proto(generate_error);
753
754 extern try notify_std (st_parameter_common *, int, const char *);
755 internal_proto(notify_std);
756
757 extern notification notification_std(int);
758 internal_proto(notification_std);
759
760 /* fpu.c */
761
762 extern void set_fpu (void);
763 internal_proto(set_fpu);
764
765 /* memory.c */
766
767 extern void *get_mem (size_t) __attribute__ ((malloc));
768 internal_proto(get_mem);
769
770 extern void *internal_malloc_size (size_t) __attribute__ ((malloc));
771 internal_proto(internal_malloc_size);
772
773 /* environ.c */
774
775 extern int check_buffered (int);
776 internal_proto(check_buffered);
777
778 extern void init_variables (void);
779 internal_proto(init_variables);
780
781 extern void show_variables (void);
782 internal_proto(show_variables);
783
784 unit_convert get_unformatted_convert (int);
785 internal_proto(get_unformatted_convert);
786
787 /* string.c */
788
789 extern int find_option (st_parameter_common *, const char *, gfc_charlen_type,
790                         const st_option *, const char *);
791 internal_proto(find_option);
792
793 extern gfc_charlen_type fstrlen (const char *, gfc_charlen_type);
794 internal_proto(fstrlen);
795
796 extern gfc_charlen_type fstrcpy (char *, gfc_charlen_type, const char *, gfc_charlen_type);
797 internal_proto(fstrcpy);
798
799 extern gfc_charlen_type cf_strcpy (char *, gfc_charlen_type, const char *);
800 internal_proto(cf_strcpy);
801
802 /* io/intrinsics.c */
803
804 extern void flush_all_units (void);
805 internal_proto(flush_all_units);
806
807 /* io.c */
808
809 extern void init_units (void);
810 internal_proto(init_units);
811
812 extern void close_units (void);
813 internal_proto(close_units);
814
815 extern int unit_to_fd (int);
816 internal_proto(unit_to_fd);
817
818 extern int st_printf (const char *, ...)
819   __attribute__ ((format (gfc_printf, 1, 2)));
820 internal_proto(st_printf);
821
822 extern int st_vprintf (const char *, va_list);
823 internal_proto(st_vprintf);
824
825 extern char * filename_from_unit (int);
826 internal_proto(filename_from_unit);
827
828 /* stop.c */
829
830 extern void stop_numeric (GFC_INTEGER_4) __attribute__ ((noreturn));
831 iexport_proto(stop_numeric);
832
833 /* reshape_packed.c */
834
835 extern void reshape_packed (char *, index_type, const char *, index_type,
836                             const char *, index_type);
837 internal_proto(reshape_packed);
838
839 /* Repacking functions.  These are called internally by internal_pack
840    and internal_unpack.  */
841
842 GFC_INTEGER_1 *internal_pack_1 (gfc_array_i1 *);
843 internal_proto(internal_pack_1);
844
845 GFC_INTEGER_2 *internal_pack_2 (gfc_array_i2 *);
846 internal_proto(internal_pack_2);
847
848 GFC_INTEGER_4 *internal_pack_4 (gfc_array_i4 *);
849 internal_proto(internal_pack_4);
850
851 GFC_INTEGER_8 *internal_pack_8 (gfc_array_i8 *);
852 internal_proto(internal_pack_8);
853
854 #if defined HAVE_GFC_INTEGER_16
855 GFC_INTEGER_16 *internal_pack_16 (gfc_array_i16 *);
856 internal_proto(internal_pack_16);
857 #endif
858
859 GFC_REAL_4 *internal_pack_r4 (gfc_array_r4 *);
860 internal_proto(internal_pack_r4);
861
862 GFC_REAL_8 *internal_pack_r8 (gfc_array_r8 *);
863 internal_proto(internal_pack_r8);
864
865 #if defined HAVE_GFC_REAL_10
866 GFC_REAL_10 *internal_pack_r10 (gfc_array_r10 *);
867 internal_proto(internal_pack_r10);
868 #endif
869
870 #if defined HAVE_GFC_REAL_16
871 GFC_REAL_16 *internal_pack_r16 (gfc_array_r16 *);
872 internal_proto(internal_pack_r16);
873 #endif
874
875 GFC_COMPLEX_4 *internal_pack_c4 (gfc_array_c4 *);
876 internal_proto(internal_pack_c4);
877
878 GFC_COMPLEX_8 *internal_pack_c8 (gfc_array_c8 *);
879 internal_proto(internal_pack_c8);
880
881 #if defined HAVE_GFC_COMPLEX_10
882 GFC_COMPLEX_10 *internal_pack_c10 (gfc_array_c10 *);
883 internal_proto(internal_pack_c10);
884 #endif
885
886 #if defined HAVE_GFC_COMPLEX_16
887 GFC_COMPLEX_16 *internal_pack_c16 (gfc_array_c16 *);
888 internal_proto(internal_pack_c16);
889 #endif
890
891 extern void internal_unpack_1 (gfc_array_i1 *, const GFC_INTEGER_1 *);
892 internal_proto(internal_unpack_1);
893
894 extern void internal_unpack_2 (gfc_array_i2 *, const GFC_INTEGER_2 *);
895 internal_proto(internal_unpack_2);
896
897 extern void internal_unpack_4 (gfc_array_i4 *, const GFC_INTEGER_4 *);
898 internal_proto(internal_unpack_4);
899
900 extern void internal_unpack_8 (gfc_array_i8 *, const GFC_INTEGER_8 *);
901 internal_proto(internal_unpack_8);
902
903 #if defined HAVE_GFC_INTEGER_16
904 extern void internal_unpack_16 (gfc_array_i16 *, const GFC_INTEGER_16 *);
905 internal_proto(internal_unpack_16);
906 #endif
907
908 extern void internal_unpack_r4 (gfc_array_r4 *, const GFC_REAL_4 *);
909 internal_proto(internal_unpack_r4);
910
911 extern void internal_unpack_r8 (gfc_array_r8 *, const GFC_REAL_8 *);
912 internal_proto(internal_unpack_r8);
913
914 #if defined HAVE_GFC_REAL_10
915 extern void internal_unpack_r10 (gfc_array_r10 *, const GFC_REAL_10 *);
916 internal_proto(internal_unpack_r10);
917 #endif
918
919 #if defined HAVE_GFC_REAL_16
920 extern void internal_unpack_r16 (gfc_array_r16 *, const GFC_REAL_16 *);
921 internal_proto(internal_unpack_r16);
922 #endif
923
924 extern void internal_unpack_c4 (gfc_array_c4 *, const GFC_COMPLEX_4 *);
925 internal_proto(internal_unpack_c4);
926
927 extern void internal_unpack_c8 (gfc_array_c8 *, const GFC_COMPLEX_8 *);
928 internal_proto(internal_unpack_c8);
929
930 #if defined HAVE_GFC_COMPLEX_10
931 extern void internal_unpack_c10 (gfc_array_c10 *, const GFC_COMPLEX_10 *);
932 internal_proto(internal_unpack_c10);
933 #endif
934
935 #if defined HAVE_GFC_COMPLEX_16
936 extern void internal_unpack_c16 (gfc_array_c16 *, const GFC_COMPLEX_16 *);
937 internal_proto(internal_unpack_c16);
938 #endif
939
940 /* Internal auxiliary functions for the pack intrinsic.  */
941
942 extern void pack_i1 (gfc_array_i1 *, const gfc_array_i1 *,
943                      const gfc_array_l1 *, const gfc_array_i1 *);
944 internal_proto(pack_i1);
945
946 extern void pack_i2 (gfc_array_i2 *, const gfc_array_i2 *,
947                      const gfc_array_l1 *, const gfc_array_i2 *);
948 internal_proto(pack_i2);
949
950 extern void pack_i4 (gfc_array_i4 *, const gfc_array_i4 *,
951                      const gfc_array_l1 *, const gfc_array_i4 *);
952 internal_proto(pack_i4);
953
954 extern void pack_i8 (gfc_array_i8 *, const gfc_array_i8 *,
955                      const gfc_array_l1 *, const gfc_array_i8 *);
956 internal_proto(pack_i8);
957
958 #ifdef HAVE_GFC_INTEGER_16
959 extern void pack_i16 (gfc_array_i16 *, const gfc_array_i16 *,
960                      const gfc_array_l1 *, const gfc_array_i16 *);
961 internal_proto(pack_i16);
962 #endif
963
964 extern void pack_r4 (gfc_array_r4 *, const gfc_array_r4 *,
965                      const gfc_array_l1 *, const gfc_array_r4 *);
966 internal_proto(pack_r4);
967
968 extern void pack_r8 (gfc_array_r8 *, const gfc_array_r8 *,
969                      const gfc_array_l1 *, const gfc_array_r8 *);
970 internal_proto(pack_r8);
971
972 #ifdef HAVE_GFC_REAL_10
973 extern void pack_r10 (gfc_array_r10 *, const gfc_array_r10 *,
974                      const gfc_array_l1 *, const gfc_array_r10 *);
975 internal_proto(pack_r10);
976 #endif
977
978 #ifdef HAVE_GFC_REAL_16
979 extern void pack_r16 (gfc_array_r16 *, const gfc_array_r16 *,
980                      const gfc_array_l1 *, const gfc_array_r16 *);
981 internal_proto(pack_r16);
982 #endif
983
984 extern void pack_c4 (gfc_array_c4 *, const gfc_array_c4 *,
985                      const gfc_array_l1 *, const gfc_array_c4 *);
986 internal_proto(pack_c4);
987
988 extern void pack_c8 (gfc_array_c8 *, const gfc_array_c8 *,
989                      const gfc_array_l1 *, const gfc_array_c8 *);
990 internal_proto(pack_c8);
991
992 #ifdef HAVE_GFC_REAL_10
993 extern void pack_c10 (gfc_array_c10 *, const gfc_array_c10 *,
994                      const gfc_array_l1 *, const gfc_array_c10 *);
995 internal_proto(pack_c10);
996 #endif
997
998 #ifdef HAVE_GFC_REAL_16
999 extern void pack_c16 (gfc_array_c16 *, const gfc_array_c16 *,
1000                      const gfc_array_l1 *, const gfc_array_c16 *);
1001 internal_proto(pack_c16);
1002 #endif
1003
1004 /* Internal auxiliary functions for the unpack intrinsic.  */
1005
1006 extern void unpack0_i1 (gfc_array_i1 *, const gfc_array_i1 *,
1007                         const gfc_array_l1 *, const GFC_INTEGER_1 *);
1008 internal_proto(unpack0_i1);
1009
1010 extern void unpack0_i2 (gfc_array_i2 *, const gfc_array_i2 *,
1011                         const gfc_array_l1 *, const GFC_INTEGER_2 *);
1012 internal_proto(unpack0_i2);
1013
1014 extern void unpack0_i4 (gfc_array_i4 *, const gfc_array_i4 *,
1015                         const gfc_array_l1 *, const GFC_INTEGER_4 *);
1016 internal_proto(unpack0_i4);
1017
1018 extern void unpack0_i8 (gfc_array_i8 *, const gfc_array_i8 *,
1019                         const gfc_array_l1 *, const GFC_INTEGER_8 *);
1020 internal_proto(unpack0_i8);
1021
1022 #ifdef HAVE_GFC_INTEGER_16
1023
1024 extern void unpack0_i16 (gfc_array_i16 *, const gfc_array_i16 *,
1025                          const gfc_array_l1 *, const GFC_INTEGER_16 *);
1026 internal_proto(unpack0_i16);
1027
1028 #endif
1029
1030 extern void unpack0_r4 (gfc_array_r4 *, const gfc_array_r4 *,
1031                         const gfc_array_l1 *, const GFC_REAL_4 *);
1032 internal_proto(unpack0_r4);
1033
1034 extern void unpack0_r8 (gfc_array_r8 *, const gfc_array_r8 *,
1035                         const gfc_array_l1 *, const GFC_REAL_8 *);
1036 internal_proto(unpack0_r8);
1037
1038 #ifdef HAVE_GFC_REAL_10
1039
1040 extern void unpack0_r10 (gfc_array_r10 *, const gfc_array_r10 *,
1041                          const gfc_array_l1 *, const GFC_REAL_10 *);
1042 internal_proto(unpack0_r10);
1043
1044 #endif
1045
1046 #ifdef HAVE_GFC_REAL_16
1047
1048 extern void unpack0_r16 (gfc_array_r16 *, const gfc_array_r16 *,
1049                          const gfc_array_l1 *, const GFC_REAL_16 *);
1050 internal_proto(unpack0_r16);
1051
1052 #endif
1053
1054 extern void unpack0_c4 (gfc_array_c4 *, const gfc_array_c4 *,
1055                         const gfc_array_l1 *, const GFC_COMPLEX_4 *);
1056 internal_proto(unpack0_c4);
1057
1058 extern void unpack0_c8 (gfc_array_c8 *, const gfc_array_c8 *,
1059                         const gfc_array_l1 *, const GFC_COMPLEX_8 *);
1060 internal_proto(unpack0_c8);
1061
1062 #ifdef HAVE_GFC_COMPLEX_10
1063
1064 extern void unpack0_c10 (gfc_array_c10 *, const gfc_array_c10 *,
1065                          const gfc_array_l1 *mask, const GFC_COMPLEX_10 *);
1066 internal_proto(unpack0_c10);
1067
1068 #endif
1069
1070 #ifdef HAVE_GFC_COMPLEX_16
1071
1072 extern void unpack0_c16 (gfc_array_c16 *, const gfc_array_c16 *,
1073                          const gfc_array_l1 *, const GFC_COMPLEX_16 *);
1074 internal_proto(unpack0_c16);
1075
1076 #endif
1077
1078 extern void unpack1_i1 (gfc_array_i1 *, const gfc_array_i1 *,
1079                         const gfc_array_l1 *, const gfc_array_i1 *);
1080 internal_proto(unpack1_i1);
1081
1082 extern void unpack1_i2 (gfc_array_i2 *, const gfc_array_i2 *,
1083                         const gfc_array_l1 *, const gfc_array_i2 *);
1084 internal_proto(unpack1_i2);
1085
1086 extern void unpack1_i4 (gfc_array_i4 *, const gfc_array_i4 *,
1087                         const gfc_array_l1 *, const gfc_array_i4 *);
1088 internal_proto(unpack1_i4);
1089
1090 extern void unpack1_i8 (gfc_array_i8 *, const gfc_array_i8 *,
1091                         const gfc_array_l1 *, const gfc_array_i8 *);
1092 internal_proto(unpack1_i8);
1093
1094 #ifdef HAVE_GFC_INTEGER_16
1095 extern void unpack1_i16 (gfc_array_i16 *, const gfc_array_i16 *,
1096                          const gfc_array_l1 *, const gfc_array_i16 *);
1097 internal_proto(unpack1_i16);
1098 #endif
1099
1100 extern void unpack1_r4 (gfc_array_r4 *, const gfc_array_r4 *,
1101                         const gfc_array_l1 *, const gfc_array_r4 *);
1102 internal_proto(unpack1_r4);
1103
1104 extern void unpack1_r8 (gfc_array_r8 *, const gfc_array_r8 *,
1105                         const gfc_array_l1 *, const gfc_array_r8 *);
1106 internal_proto(unpack1_r8);
1107
1108 #ifdef HAVE_GFC_REAL_10
1109 extern void unpack1_r10 (gfc_array_r10 *, const gfc_array_r10 *,
1110                          const gfc_array_l1 *, const gfc_array_r10 *);
1111 internal_proto(unpack1_r10);
1112 #endif
1113
1114 #ifdef HAVE_GFC_REAL_16
1115 extern void unpack1_r16 (gfc_array_r16 *, const gfc_array_r16 *,
1116                          const gfc_array_l1 *, const gfc_array_r16 *);
1117 internal_proto(unpack1_r16);
1118 #endif
1119
1120 extern void unpack1_c4 (gfc_array_c4 *, const gfc_array_c4 *,
1121                         const gfc_array_l1 *, const gfc_array_c4 *);
1122 internal_proto(unpack1_c4);
1123
1124 extern void unpack1_c8 (gfc_array_c8 *, const gfc_array_c8 *,
1125                         const gfc_array_l1 *, const gfc_array_c8 *);
1126 internal_proto(unpack1_c8);
1127
1128 #ifdef HAVE_GFC_COMPLEX_10
1129 extern void unpack1_c10 (gfc_array_c10 *, const gfc_array_c10 *,
1130                          const gfc_array_l1 *, const gfc_array_c10 *);
1131 internal_proto(unpack1_c10);
1132 #endif
1133
1134 #ifdef HAVE_GFC_COMPLEX_16
1135 extern void unpack1_c16 (gfc_array_c16 *, const gfc_array_c16 *,
1136                          const gfc_array_l1 *, const gfc_array_c16 *);
1137 internal_proto(unpack1_c16);
1138 #endif
1139
1140 /* Helper functions for spread.  */
1141
1142 extern void spread_i1 (gfc_array_i1 *, const gfc_array_i1 *,
1143                        const index_type, const index_type);
1144 internal_proto(spread_i1);
1145
1146 extern void spread_i2 (gfc_array_i2 *, const gfc_array_i2 *,
1147                        const index_type, const index_type);
1148 internal_proto(spread_i2);
1149
1150 extern void spread_i4 (gfc_array_i4 *, const gfc_array_i4 *,
1151                        const index_type, const index_type);
1152 internal_proto(spread_i4);
1153
1154 extern void spread_i8 (gfc_array_i8 *, const gfc_array_i8 *,
1155                        const index_type, const index_type);
1156 internal_proto(spread_i8);
1157
1158 #ifdef HAVE_GFC_INTEGER_16
1159 extern void spread_i16 (gfc_array_i16 *, const gfc_array_i16 *,
1160                        const index_type, const index_type);
1161 internal_proto(spread_i16);
1162
1163 #endif
1164
1165 extern void spread_r4 (gfc_array_r4 *, const gfc_array_r4 *,
1166                        const index_type, const index_type);
1167 internal_proto(spread_r4);
1168
1169 extern void spread_r8 (gfc_array_r8 *, const gfc_array_r8 *,
1170                        const index_type, const index_type);
1171 internal_proto(spread_r8);
1172
1173 #ifdef HAVE_GFC_REAL_10
1174 extern void spread_r10 (gfc_array_r10 *, const gfc_array_r10 *,
1175                        const index_type, const index_type);
1176 internal_proto(spread_r10);
1177
1178 #endif
1179
1180 #ifdef HAVE_GFC_REAL_16
1181 extern void spread_r16 (gfc_array_r16 *, const gfc_array_r16 *,
1182                        const index_type, const index_type);
1183 internal_proto(spread_r16);
1184
1185 #endif
1186
1187 extern void spread_c4 (gfc_array_c4 *, const gfc_array_c4 *,
1188                        const index_type, const index_type);
1189 internal_proto(spread_c4);
1190
1191 extern void spread_c8 (gfc_array_c8 *, const gfc_array_c8 *,
1192                        const index_type, const index_type);
1193 internal_proto(spread_c8);
1194
1195 #ifdef HAVE_GFC_COMPLEX_10
1196 extern void spread_c10 (gfc_array_c10 *, const gfc_array_c10 *,
1197                        const index_type, const index_type);
1198 internal_proto(spread_c10);
1199
1200 #endif
1201
1202 #ifdef HAVE_GFC_COMPLEX_16
1203 extern void spread_c16 (gfc_array_c16 *, const gfc_array_c16 *,
1204                        const index_type, const index_type);
1205 internal_proto(spread_c16);
1206
1207 #endif
1208
1209 extern void spread_scalar_i1 (gfc_array_i1 *, const GFC_INTEGER_1 *,
1210                               const index_type, const index_type);
1211 internal_proto(spread_scalar_i1);
1212
1213 extern void spread_scalar_i2 (gfc_array_i2 *, const GFC_INTEGER_2 *,
1214                               const index_type, const index_type);
1215 internal_proto(spread_scalar_i2);
1216
1217 extern void spread_scalar_i4 (gfc_array_i4 *, const GFC_INTEGER_4 *,
1218                               const index_type, const index_type);
1219 internal_proto(spread_scalar_i4);
1220
1221 extern void spread_scalar_i8 (gfc_array_i8 *, const GFC_INTEGER_8 *,
1222                               const index_type, const index_type);
1223 internal_proto(spread_scalar_i8);
1224
1225 #ifdef HAVE_GFC_INTEGER_16
1226 extern void spread_scalar_i16 (gfc_array_i16 *, const GFC_INTEGER_16 *,
1227                                const index_type, const index_type);
1228 internal_proto(spread_scalar_i16);
1229
1230 #endif
1231
1232 extern void spread_scalar_r4 (gfc_array_r4 *, const GFC_REAL_4 *,
1233                               const index_type, const index_type);
1234 internal_proto(spread_scalar_r4);
1235
1236 extern void spread_scalar_r8 (gfc_array_r8 *, const GFC_REAL_8 *,
1237                               const index_type, const index_type);
1238 internal_proto(spread_scalar_r8);
1239
1240 #ifdef HAVE_GFC_REAL_10
1241 extern void spread_scalar_r10 (gfc_array_r10 *, const GFC_REAL_10 *,
1242                                const index_type, const index_type);
1243 internal_proto(spread_scalar_r10);
1244
1245 #endif
1246
1247 #ifdef HAVE_GFC_REAL_16
1248 extern void spread_scalar_r16 (gfc_array_r16 *, const GFC_REAL_16 *,
1249                                const index_type, const index_type);
1250 internal_proto(spread_scalar_r16);
1251
1252 #endif
1253
1254 extern void spread_scalar_c4 (gfc_array_c4 *, const GFC_COMPLEX_4 *,
1255                               const index_type, const index_type);
1256 internal_proto(spread_scalar_c4);
1257
1258 extern void spread_scalar_c8 (gfc_array_c8 *, const GFC_COMPLEX_8 *,
1259                               const index_type, const index_type);
1260 internal_proto(spread_scalar_c8);
1261
1262 #ifdef HAVE_GFC_COMPLEX_10
1263 extern void spread_scalar_c10 (gfc_array_c10 *, const GFC_COMPLEX_10 *,
1264                                const index_type, const index_type);
1265 internal_proto(spread_scalar_c10);
1266
1267 #endif
1268
1269 #ifdef HAVE_GFC_COMPLEX_16
1270 extern void spread_scalar_c16 (gfc_array_c16 *, const GFC_COMPLEX_16 *,
1271                                const index_type, const index_type);
1272 internal_proto(spread_scalar_c16);
1273
1274 #endif
1275
1276 /* string_intrinsics.c */
1277
1278 extern int compare_string (gfc_charlen_type, const char *,
1279                            gfc_charlen_type, const char *);
1280 iexport_proto(compare_string);
1281
1282 extern int compare_string_char4 (gfc_charlen_type, const gfc_char4_t *,
1283                                  gfc_charlen_type, const gfc_char4_t *);
1284 iexport_proto(compare_string_char4);
1285
1286 /* random.c */
1287
1288 extern void random_seed_i4 (GFC_INTEGER_4 * size, gfc_array_i4 * put,
1289                             gfc_array_i4 * get);
1290 iexport_proto(random_seed_i4);
1291 extern void random_seed_i8 (GFC_INTEGER_8 * size, gfc_array_i8 * put,
1292                             gfc_array_i8 * get);
1293 iexport_proto(random_seed_i8);
1294
1295 /* size.c */
1296
1297 typedef GFC_ARRAY_DESCRIPTOR (GFC_MAX_DIMENSIONS, void) array_t;
1298
1299 extern index_type size0 (const array_t * array); 
1300 iexport_proto(size0);
1301
1302 /* bounds.c */
1303
1304 extern void bounds_equal_extents (array_t *, array_t *, const char *,
1305                                   const char *);
1306 internal_proto(bounds_equal_extents);
1307
1308 extern void bounds_reduced_extents (array_t *, array_t *, int, const char *,
1309                              const char *intrinsic);
1310 internal_proto(bounds_reduced_extents);
1311
1312 extern void bounds_iforeach_return (array_t *, array_t *, const char *);
1313 internal_proto(bounds_iforeach_return);
1314
1315 extern void bounds_ifunction_return (array_t *, const index_type *,
1316                                      const char *, const char *);
1317 internal_proto(bounds_ifunction_return);
1318
1319 extern index_type count_0 (const gfc_array_l1 *);
1320
1321 internal_proto(count_0);
1322
1323 /* Internal auxiliary functions for cshift */
1324
1325 void cshift0_i1 (gfc_array_i1 *, const gfc_array_i1 *, ssize_t, int);
1326 internal_proto(cshift0_i1);
1327
1328 void cshift0_i2 (gfc_array_i2 *, const gfc_array_i2 *, ssize_t, int);
1329 internal_proto(cshift0_i2);
1330
1331 void cshift0_i4 (gfc_array_i4 *, const gfc_array_i4 *, ssize_t, int);
1332 internal_proto(cshift0_i4);
1333
1334 void cshift0_i8 (gfc_array_i8 *, const gfc_array_i8 *, ssize_t, int);
1335 internal_proto(cshift0_i8);
1336
1337 #ifdef HAVE_GFC_INTEGER_16
1338 void cshift0_i16 (gfc_array_i16 *, const gfc_array_i16 *, ssize_t, int);
1339 internal_proto(cshift0_i16);
1340 #endif
1341
1342 void cshift0_r4 (gfc_array_r4 *, const gfc_array_r4 *, ssize_t, int);
1343 internal_proto(cshift0_r4);
1344
1345 void cshift0_r8 (gfc_array_r8 *, const gfc_array_r8 *, ssize_t, int);
1346 internal_proto(cshift0_r8);
1347
1348 #ifdef HAVE_GFC_REAL_10
1349 void cshift0_r10 (gfc_array_r10 *, const gfc_array_r10 *, ssize_t, int);
1350 internal_proto(cshift0_r10);
1351 #endif
1352
1353 #ifdef HAVE_GFC_REAL_16
1354 void cshift0_r16 (gfc_array_r16 *, const gfc_array_r16 *, ssize_t, int);
1355 internal_proto(cshift0_r16);
1356 #endif
1357
1358 void cshift0_c4 (gfc_array_c4 *, const gfc_array_c4 *, ssize_t, int);
1359 internal_proto(cshift0_c4);
1360
1361 void cshift0_c8 (gfc_array_c8 *, const gfc_array_c8 *, ssize_t, int);
1362 internal_proto(cshift0_c8);
1363
1364 #ifdef HAVE_GFC_COMPLEX_10
1365 void cshift0_c10 (gfc_array_c10 *, const gfc_array_c10 *, ssize_t, int);
1366 internal_proto(cshift0_c10);
1367 #endif
1368
1369 #ifdef HAVE_GFC_COMPLEX_16
1370 void cshift0_c16 (gfc_array_c16 *, const gfc_array_c16 *, ssize_t, int);
1371 internal_proto(cshift0_c16);
1372 #endif
1373
1374 #endif  /* LIBGFOR_H  */