OSDN Git Service

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