vif.h
1 //! @file vif.h
2 //! @author J. Marcel van der Veer
3 //
4 //! @section Copyright
5 //
6 // This file is part of VIF - vintage FORTRAN compiler.
7 // Copyright 2020-2025 J. Marcel van der Veer <algol68g@xs4all.nl>.
8 //
9 //! @section License
10 //
11 // This program is free software; you can redistribute it and/or modify it
12 // under the terms of the GNU General Public License as published by the
13 // Free Software Foundation; either version 3 of the License, or
14 // (at your option) any later version.
15 //
16 // This program is distributed in the hope that it will be useful, but
17 // WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
18 // or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
19 // more details. You should have received a copy of the GNU General Public
20 // License along with this program. If not, see <http://www.gnu.org/licenses/>.
21
22 //! @section Synopsis
23 //!
24 //! VIF include file.
25
26 // This is a monolithic include file to avoid cluttering the installation directory.
27
28 #if ! defined (__VIF_H__)
29 #define __VIF_H__
30
31 #define _GNU_SOURCE
32
33 #include <complex.h>
34 #include <ctype.h>
35 #include <endian.h>
36 #include <errno.h>
37 #include <float.h>
38 #include <inttypes.h>
39 #include <libgen.h>
40 #include <limits.h>
41 #include <math.h>
42 #include <quadmath.h>
43 #include <signal.h>
44 #include <stdarg.h>
45 #include <stdint.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <string.h>
49 #include <sys/stat.h>
50 #include <sys/time.h>
51 #include <sys/utsname.h>
52 #include <time.h>
53 #include <unistd.h>
54
55 #define prototype
56
57 #define PACKAGE "vif"
58
59 #define NO_IDENT ((IDENT *) NULL)
60 #define NO_LABEL ((LBL *) NULL)
61 #define NO_MODE ((MODE *) NULL)
62 #define NO_TEXT ((char *) NULL)
63 #define NO_FUN NULL
64 #define NO_FTN_LINE ((FTN_LINE *) NULL)
65 #define NO_FILE ((FILE *) NULL)
66 #define NO_REF_INTEGER ((int_4 *) NULL)
67 #define NO_EXPR ((EXPR *) NULL)
68 #define NO_REF_TEXT ((char **) NULL)
69
70 #define STDF_IN 5
71 #define STDF_OUT 6
72 #define STDF_PUN 6
73 #define STDF_ERR 7
74
75 typedef char *FORMAT;
76
77 // Flags for gcc when compiling generated code from FORTRAN.
78
79 #if defined (BOOTSTRAP)
80 #define CFLAGS "-pipe -ggdb -I. -Isrc/include -L. -I../include -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -fdiagnostics-plain-output -fdiagnostics-show-location=once"
81 #define LD_FLAGS "-rdynamic -Lsrc/lib -L../lib -lvif -lquadmath -lm"
82 #else
83 #define CFLAGS "-pipe -ggdb -I. -Isrc/include -L. -I../include -Wno-implicit-function-declaration -Wno-incompatible-pointer-types -fdiagnostics-plain-output -fdiagnostics-show-location=once"
84 #define LD_FLAGS "-rdynamic -L./src/lib -lvif -lquadmath -lm"
85 #endif
86 #define OFLAGS "-O2"
87
88 enum {NOTYPE, ETYPE, INTEGER, LOGICAL, REAL, COMPLEX, CHARACTER};
89 enum {UNFORMATTED = 1, STDFORMAT, FORMATTED };
90 enum {SOURCE = 0, TEMP, MACRO };
91 enum {HEADER = 0, BANNER, LIST, MESSAGES, JCL, SYMBOLS, CONSTANTS, STRINGS, PARAMETERS, TYPEDEF, FREQ, COMMON, PROTOTYPE, STAT, TITLE, PRE, DECL, REFDECL, EQUIV, FMT, DATA, BODY, POST, MAXPHA };
92 enum {EXPR_OTHER = 0, EXPR_VAR, EXPR_CONST, EXPR_SLICE, EXPR_SUBSTR };
93 enum {LEXEME = 0, DECLAR, WORD, LABEL, INT_NUMBER, FLT_NUMBER, TEXT };
94 enum {STATIC = 0, AUTOMATIC };
95
96 // Shorthands to improve code legibility.
97
98 #define int_2 int16_t
99 #define int_4 int32_t
100 #define int_8 int64_t
101
102 #define unt_2 uint16_t
103 #define unt_4 uint32_t
104 #define unt_8 uint64_t
105 #define unt_16 unsigned __int128
106
107 #define logical_4 unsigned
108
109 #define real_4 float
110 #define real_8 double
111 #define real_16 __float128
112
113 #define complex_8 float complex
114 #define complex_16 double complex
115 #define complex_32 __complex128
116
117 // MAX_STRLEN = 2 ** MAX_STRLENS - 1
118 #define MAX_STRLEN 4095
119 #define MAX_STRLENS 12
120 extern logical_4 strlens[MAX_STRLENS];
121
122 #define ERR (-32)
123 #define SKIP //
124 #define TRUE 1
125 #define FALSE 0
126 #define MAX_LRECL 32760
127 #define MAX_NEST 9
128 #define INCREMENT 500
129 #define INDENT 2
130 #define LINES_PER_PAGE 50
131 #define LINE_WIDTH 122
132 #define MAX_ARGS 16
133 #define MAX_COMMONS 100
134 #define MAX_DIMS 6
135 #define MAX_IDENTS 1000
136 #define MAX_LABELS 1000
137 #define MAX_MODULES 5000
138 #define MAX_PRIO 9
139 #define MAX_ERROR 5
140 #define MAX_WARNS MAX_ERROR
141 #define RETURN "goto _l0;\n"
142 #define M_LOG10_2 0.30102999566398119521373889472449q
143
144 #define NOT_LOCAL(idf) ((idf)->common != LOCAL)
145 #define LOCAL 0
146 #define EXTERN 1
147
148 #define WITHIN (curret != END_OF_LINE && curret != END_OF_MODULE)
149
150 #define END_OF_MODULE (-3)
151 #define END_OF_LINE (-2)
152 #define EXPECT_NONE (NULL)
153 #define START_OF_LINE (-1)
154 #define ARG TRUE
155 #define NOARG FALSE
156 #define CONST TRUE
157 #define NOCONST FALSE
158 #define FUN TRUE
159 #define NOFUN FALSE
160 #define UNIQ TRUE
161 #define NOUNIQ FALSE
162 #define NOPATCH 0
163 #define NOTYPE 0
164 #define NOLEN 0
165 #define FORMAL TRUE
166 #define ACTUAL FALSE
167 #define CAST TRUE
168 #define NOCAST FALSE
169 #define PROTEST TRUE
170 #define QUIET FALSE
171
172 #define EXPECT_LABEL "label"
173 #define INTERNAL_CONSISTENCY "internal consistency"
174
175 #define ABS(n) ((n) > 0 ? (n) : -(n))
176 #define MAX(u, v) (((u) > (v) ? (u) : (v)))
177 #define MAXIMISE(u, v) ((u) = MAX (u, v))
178 #define MIN(u, v) (((u) < (v) ? (u) : (v)))
179 #define MINIMISE(u, v) ((u) = MIN (u, v))
180
181 #define IS_JCL(c) (c == '/' || CUR_LIN.jcl)
182 #define IS_COMMENT(c) (strchr ("cd*!#", tolower (c)) != NULL || IS_JCL (c))
183 #define IS_VAR(n) (isalpha(n[0]) || n[0] == '_' || n[0] == '$')
184 #define UNSCAN {curlin = prelin; curcol = precol; strcpy (curlex, prelex); curret = preret;}
185 #define SAVE_POS int_4 _l_ = curlin, _c_ = curcol;
186 #define SAVE_PRE int_4 _l_ = prelin, _c_ = precol;
187 #define RESTORE_POS {curlin = _l_; curcol = _c_;}
188 #define _EXPCHAR(n) (tolower (n) != '\0' && strchr ("edqx", tolower (n)) != NULL)
189 #define _IDFCHAR(n) (tolower (n) != '\0' && strchr ("abcdefghijklmnopqrstuvwxyz0123456789_ $", tolower (n)) != NULL)
190 #define CUR_LIN (source[curlin])
191 #define POS(n) (tolower (CUR_LIN.text[n]))
192 #define EXPONENT(n) _EXPCHAR (POS (n))
193 #define CUR_COL (POS (curcol))
194
195 #define MSG(sev, num, text, info)\
196 if (prelin < 1) {\
197 message (&source[curlin], curcol, (sev), (num), (text), (info));\
198 } else {\
199 message (&source[prelin], precol, (sev), (num), (text), (info));\
200 }
201
202 extern void _vif_backtr(int_4);
203
204 #define ERROR(num, s, t) {MSG ("error", (num), (s), (t));}
205 #define MODE_ERROR(num, s, t) {\
206 RECORD _txt_;\
207 _srecordf(_txt_, "%s to %s", (s), (t));\
208 ERROR (num, "cannot convert", _txt_);\
209 }
210 #define PRECISION_LOSS(num, s, t) {\
211 RECORD _txt_;\
212 _srecordf(_txt_, "%s to %s", (s), (t));\
213 WARNING (num, "possible precision loss", _txt_);\
214 }
215 #define SYNTAX(num, s) {ERROR ((num), "invalid syntax", (s));}
216 #define EXPECT(num, s) {ERROR ((num), "expected", (s));}
217 #define ADJACENT(num, s) {ERROR ((num), "adjacent tokens", (s));}
218 #define WARNING(num, s, t) {MSG ("warning", (num), (s), (t));}
219 #define ECHO(num, s, t) {MSG ("info", (num), (s), (t));}
220 #define SCANER(num, s, t) {MSG ("fatal", (num), (s), (t)); exit (EXIT_FAILURE);}
221 #define FATAL(num, s, t) {message (NULL, ERR, "fatal", (num), (s), (t)); exit (EXIT_FAILURE);}
222 #define OVERFLOW(num, t) {_vif_backtr (0); fprintf (stderr, "\n** exception ** f%d: fatal: overflow, (%s)\n", (num), (t)); exit (EXIT_FAILURE);}
223
224 #define TOKEN(s) EQUAL (curlex, (s))
225 #define CHECKPOINT(num, s) {if (!EQUAL (curlex, (s))) {EXPECT ((num), (s));}}
226 #define CHECKDIGIT(num, s) {if (!isdigit (s)) {EXPECT ((num), "digit");}}
227 #define IS_NUMBER(u) ((u) == INT_NUMBER || (u) == FLT_NUMBER)
228
229 #define FMT_TEXT ((char *) 1)
230 #define FMT_INT ((char *) 2)
231 #define FMT_REAL ((char *) 3)
232 #define FMT_LOGICAL ((char *) 4)
233 #define FMT_CHAR ((char *) 5)
234
235 // REAL*32
236
237 #define FLT128_LEN 7 // Do NOT change this!
238 #define FLT256_LEN 15 // Do NOT change this!
239 #define FLT256_GUARD 2 // Guard digits.
240 #define FLT256_DIG (72 - FLT256_GUARD) // 240 * log10 (2) minus guard digits.
241
242 typedef unt_2 REAL16[8];
243 typedef unt_2 REAL32[FLT256_LEN + 1]; // One for exponent.
244
245 struct __real_32__
246 {
247 REAL32 value;
248 };
249 typedef struct __real_32__ real_32;
250
251 struct __complex_64__
252 {
253 struct __real_32__ re, im;
254 };
255 typedef struct __complex_64__ complex_64;
256
257 #define xsub(a, b) xadd (a, b, 1)
258 #define xsum(a, b) xadd (a, b, 0)
259
260 extern complex_64 cxcos (complex_64);
261 extern complex_64 cxdbl(complex_16);
262 extern complex_64 cxexp (complex_64);
263 extern complex_64 cxlog (complex_64);
264 extern complex_64 cxreal32(real_32);
265 extern complex_64 cxquad(complex_32);
266 extern complex_64 cxsin (complex_64);
267 extern complex_64 cxsqrt (complex_64);
268 extern complex_64 cxtan (complex_64);
269 extern complex_64 _coctotop (complex_64 *, real_32);
270 extern complex_64 _cquadtop (complex_64 *, complex_32);
271 extern int_4 xeq (real_32, real_32);
272 extern int_4 xge (real_32, real_32);
273 extern int_4 xgt (real_32, real_32);
274 extern int_4 xis0 (const real_32 *);
275 extern int_4 xis_minf (const real_32 *);
276 extern int_4 xis_nan (const real_32 *);
277 extern int_4 xis_pinf (const real_32 *);
278 extern int_4 xle (real_32, real_32);
279 extern int_4 xlt (real_32, real_32);
280 extern int_4 xneq (real_32, real_32);
281 extern int_4 xnot0 (const real_32 *);
282 extern int_4 xsgn (const real_32 *);
283 extern real_32 atox (char *);
284 extern real_32 cxim (complex_64);
285 extern real_32 cxre (complex_64);
286 extern complex_64 cxneg (complex_64);
287 extern complex_64 cxsum (complex_64, complex_64);
288 extern complex_64 cxsub (complex_64, complex_64);
289 extern complex_64 cxmul (complex_64, complex_64);
290 extern complex_64 cxdiv (complex_64, complex_64);
291 extern real_32 dbltox (real_8);
292 extern real_32 flttox (real_4);
293 extern real_32 inttox (int_4);
294 extern real_32 strtox (char *, char **);
295 extern real_32 xabs (real_32);
296 extern real_32 xacos (real_32);
297 extern real_32 xacotan (real_32);
298 extern real_32 xadd (real_32, real_32, int_4);
299 extern real_32 xasin (real_32);
300 extern real_32 xatan2 (real_32, real_32);
301 extern real_32 xatan (real_32);
302 extern real_32 xacosh (real_32);
303 extern real_32 xcosh (real_32);
304 extern real_32 xcos (real_32);
305 extern real_32 xcotan (real_32);
306 extern real_32 xdiv (real_32, real_32);
307 extern real_32 xexp (real_32);
308 extern real_32 xlog10 (real_32);
309 extern real_32 xlog (real_32);
310 extern real_32 xmul (real_32, real_32);
311 extern real_32 xneg (real_32);
312 extern real_32 xpwr (real_32, int_4);
313 extern real_32 xround (real_32);
314 extern real_32 xsfmod (real_32, int_4 *);
315 extern real_32 xasinh (real_32);
316 extern real_32 xsinh (real_32);
317 extern real_32 xsin (real_32);
318 extern real_32 xsqrt (real_32);
319 extern real_32 xatanh (real_32);
320 extern real_32 xtanh (real_32);
321 extern real_32 xtan (real_32);
322 extern real_32 xtrunc (real_32);
323 extern real_32 xfrac (real_32);
324 extern real_32 xtenup (int_4);
325 extern real_4 xtoflt (real_32);
326 extern real_8 xtodbl (real_32);
327
328 // In Fortran, only EQUIVALENCE can alias names.
329
330 #define _p_ * restrict
331
332 //
333
334 #define RECLN 4095
335 typedef char RECORD[RECLN + 1];
336 #define RECCLR(z) memset ((z), 0, RECLN + 1)
337
338 typedef struct FTNFILE FTNFILE;
339 struct FTNFILE {
340 FILE *unit;
341 char *name, *form, *action, *disp, *buff;
342 int_4 lrecl, vers, in_stream, record, redirect, buff_init, buff_pos, buff_len;
343 };
344
345 #define NEW_FTN_FILE(fp, fmt, act, recl)\
346 ((FTNFILE) {.unit = fp, .form = fmt, .action = act, .lrecl = recl})
347
348 #define MAX_SOURCE_FILES 1500
349
350 // MAX_FILES should be 100.
351 #define MAX_FILES 100
352
353 extern FTNFILE _ffile[MAX_FILES];
354
355 typedef struct CALLS CALLS;
356 struct CALLS {
357 char *name;
358 int_8 calls;
359 };
360
361 typedef struct C_SRC C_SRC;
362 struct C_SRC
363 {
364 int_4 proc, phase;
365 char *text;
366 };
367 extern C_SRC *object;
368
369 typedef struct FTN_LINE FTN_LINE;
370 struct FTN_LINE
371 {
372 FTN_LINE *file;
373 int_4 num, isn, len, label, jcl, diag, proc, cpp;
374 char *text;
375 };
376 extern FTN_LINE *source, *files;
377 extern int_4 MAX_FTN_LINES;
378
379 typedef struct MODE MODE;
380 struct MODE
381 {
382 int_4 type, len, dim, save, fun;
383 };
384
385 #define PLAIN_MODE(t, l) ((MODE) {.type = type, .len = len, .dim = 0, .fun = FALSE})
386 #define TYPE(z, t, l) ((z)->mode.type == t && (z)->mode.len == l)
387 #define IS_ROW(m) ((m).dim > 0)
388 #define IS_SCALAR(m) ((m).dim == 0)
389
390 typedef struct IDENT IDENT;
391 struct IDENT
392 {
393 char *name, *fname, *parm;
394 int_4 arg, call, common, const_ref, external, intrinsic, line, macro, nest, save, source, used, variable;
395 IDENT *alias, *equiv;
396 MODE mode;
397 int_4 patch1, patch2;
398 char *lwb[MAX_DIMS], *upb[MAX_DIMS], *len[MAX_DIMS];
399 char *size;
400 };
401 #define C_NAME(z) ((z)->name)
402 #define FTN_NAME(z) ((z)->fname)
403
404 typedef struct IMPLICIT IMPLICIT;
405 struct IMPLICIT
406 {
407 MODE mode;
408 };
409
410 typedef struct LBL LBL;
411 struct LBL
412 {
413 int_4 index, num, line, jumped, patch, nonexe, data, format;
414 };
415 extern LBL *lbl;
416
417 typedef struct EXPR EXPR;
418 struct EXPR
419 {
420 RECORD str, elem;
421 int_4 variant, value, opt;
422 IDENT *idf;
423 MODE mode;
424 };
425
426 typedef struct INTRINS INTRINS;
427 struct INTRINS
428 {
429 char *ffun, *cfun;
430 int_4 spec, rtyp, rlen, alen;
431 int_4 anum, atyp;
432 real_32 (*f1) (real_32);
433 real_32 (*f2) (real_32, real_32);
434 complex_64 (*f3) (complex_64);
435 };
436
437 extern char *action_default;
438 extern char *action_read;
439 extern char *action_write;
440 extern char *action_readwrite;
441 extern char *form_formatted;
442 extern char *form_unformatted;
443 extern char *disp_new;
444 extern char *disp_old;
445 extern char *disp_delete;
446 extern char *disp_keep;
447
448 extern IDENT globals[], locals[];
449 extern char *commons[], *modules[];
450 extern IMPLICIT implic[];
451 extern LBL labels[];
452 extern int_4 optimise, keep, pretty;
453 extern int_4 hollerith;
454 extern int_4 end_statements;
455 extern int_4 syntax_only;
456 extern int_4 MAX_C_SRC;
457 extern int_4 macro_nest;
458 extern int_4 lhs_factor;
459 extern int_4 MAX_C_SRC;
460 extern int_4 MAX_FTN_LINES;
461 extern int_4 pnprocs, nprocs, nglobals, nlocals, nlabels, nftnlines, nfiles;
462 extern int_4 nloctmps, nglobtmps, func;
463 extern int_4 prelin, precol;
464 extern int_4 curlin, curcol;
465 extern int_4 jcllin;
466 extern int_4 nerrors, merrors, nwarns;
467 extern int_4 page, line, ncommons, nmodules;
468 extern int_4 n_c_src;
469 extern int_4 indent;
470 extern int_4 curret, preret;
471 extern int_4 abend;
472 extern int_4 compile_only;
473 extern int_4 implicit_r8;
474 extern int_4 f4_do_loops;
475 extern int_4 gcc_ftn_lines;
476 extern int_4 quiet_mode;
477 extern int_4 trace;
478 extern int_4 no_warnings;
479 extern RECORD curlex, prelex;
480 extern RECORD libnam, modnam, procnam;
481 extern RECORD retnam;
482 extern RECORD stat_start;
483 extern RECORD program, block;
484 extern RECORD hmodule, hsection;
485 extern RECORD hdate;
486
487
488 extern char *bufcat (char *, char *, int_4);
489 extern char *bufcpy (char *, char *, int_4);
490 extern char *bufrep (char *, char *);
491 extern char *_bufsub (char *, char *, int_4, int_4);
492 extern char *c_name (char *);
493 extern char *concat (char *, char *, char *);
494 extern char *edit_f (char *);
495 extern char *edit_fmt (int_4);
496 extern char *edit_tmp (int_4);
497 extern char *edit_unit (int_4);
498 extern char *edit_v (char *);
499 extern char *edit_vn (char *, int_4);
500 extern char *encode (char *, char *);
501 extern char *f2c_type (char *, MODE *, int_4, int_4);
502 extern char *get_uniq_str (char *, char *);
503 extern char *idf_full_c_name (RECORD, IDENT *);
504 extern char *intnot (char *, int_8, int_4);
505 extern char *newpage (char *, char *);
506 extern char *pretty_float (char *);
507 extern char *ptr_to_array (IDENT *, int_4, int_4, int_4);
508 extern char *qtype (MODE *);
509 extern char *f_strallocat (char *, char *);
510 extern char *f_stralloc (char *);
511 extern char *strlower (char *);
512 extern char *wtype (MODE *, int_4, int_4);
513 extern char *xfixed (char *, real_32, int_4, int_4, int_4);
514 extern char *xfloat (char *, real_32, int_4, int_4, int_4, int_4, int_4, char);
515 extern char *xsubfixed (char *, real_32, logical_4, int_4);
516 extern char *xtoa (char *, real_32, int_4);
517 extern IDENT *add_local (char *, int_4, int_4, int_4, int_4, int_4, int_4, int_4);
518 extern IDENT *add_nest (char *, int_4, MODE *);
519 extern IDENT *extf_decl (char *, MODE *);
520 extern IDENT *find_local (char *, MODE *);
521 extern IDENT *impl_decl (char *, MODE *);
522 extern IDENT *void_decl (char *, MODE *);
523 extern int_4 accept_mode (int_4, int_4, int_4, int_4);
524 extern int_4 add_block (char *);
525 extern int_4 code (int_4, int_4, char *);
526 extern int_4 code_real_32_const (char *);
527 extern int_4 code_uniq_str (char *);
528 extern int_4 express (EXPR *, int_4, int_4);
529 extern int_4 find_module (char *);
530 extern int_4 fold_expr (EXPR *, int_4);
531 extern int_4 fold_intrinsic (INTRINS *, EXPR *, EXPR *);
532 extern int_4 format_str (char *str);
533 extern int_4 impl_do (void);
534 extern int_4 intrinsic_call (char *, EXPR *);
535 extern int_4 isint_4 (char *, int_4 *);
536 extern int_4 is_intrins (char *);
537 extern int_4 is_specific (char *);
538 extern int_4 mix_len (EXPR *, EXPR *);
539 extern int_4 ord (char);
540 extern int_4 patch (int_4, char *);
541 extern int_4 reserved (char *);
542 extern int_4 same_name (char *, char *);
543 extern int_4 scan (char *);
544 extern int_4 scan_fmt (void);
545 extern int_4 scan_fmt (void);
546 extern int_4 valid_expr (EXPR *);
547 extern int new_charlen (int_4);
548 extern LBL *find_label (char *);
549 extern void banner (int_4, int_4, char *);
550 extern void call (void);
551 extern void code_row_len (IDENT *);
552 extern void code_comment (void);
553 extern void code_common (void);
554 extern void code_exts (IDENT *, int_4, int_4, int_4, int_4);
555 extern void code_idfs (IDENT *, int_4, int_4, int_4, int_4);
556 extern void code_parms (RECORD);
557 extern void common (void);
558 extern void common (void);
559 extern void cpp_direct (int_4, int_4, int_4);
560 extern void decl_autosave (void);
561 extern void decl_data (void);
562 extern void decl_equiv (void);
563 extern void decl_macros (void);
564 extern void default_impl (void);
565 extern void diagnostic (int_4, char *);
566 extern void dimension (void);
567 extern void do_data (int_4 *);
568 extern void do_io (char *, int_4 *);
569 extern void equivalence (void);
570 extern void executable (void);
571 extern void exprio (EXPR *, int_4, logical_4);
572 extern void factor (EXPR *);
573 extern void *f_malloc (size_t);
574 extern void fold_int_4 (char *, char *);
575 extern void format (LBL *);
576 extern void *f_realloc (void *, size_t);
577 extern void factor_function_call (EXPR *, RECORD);
578 extern void gen_statements (LBL *, int_4);
579 extern void get_decls (void);
580 extern void get_dims (IDENT *, int_4);
581 extern void get_impl (void);
582 extern void get_source (char *, int_4);
583 extern void idfs_impl (void);
584 extern void idfs_unused (void);
585 extern void implicit (void);
586 extern void impl_type (char *, MODE *);
587 extern void inline_args (RECORD *, int_4 *);
588 extern void jump (void);
589 extern void macro (EXPR *, IDENT *);
590 extern void merge_commons (void);
591 extern void message (FTN_LINE *, int_4, char *, int_4, char *, char *);
592 extern void norm_mode (MODE *);
593 extern void option (char *);
594 extern void parameter (void);
595 extern void patch_args (void);
596 extern void patch_args (void);
597 extern void assign (EXPR *);
598 extern void proc_listing (int_4);
599 extern void recursion (EXPR *, RECORD, IDENT *);
600 extern void relabel (char *);
601 extern void RTE (const char *, const char *);
602 extern void RTW (const char *, const char *);
603 extern void scan_modules (void);
604 extern void skip_card (int_4);
605 extern void factor_slice_char (EXPR *, IDENT *);
606 extern void factor_slice (EXPR *, IDENT *);
607 extern void subprograms (void);
608 extern void factor_variable (EXPR *, IDENT *, MODE *, RECORD);
609 extern void vif_close (void);
610 extern void vif_open (void);
611 extern void vif_rewind (void);
612 extern void write_object (char *);
613 extern void code_index (RECORD, IDENT *, int_4);
614 extern void vif_jcl (void);
615 extern void compute_row_size (RECORD, IDENT *);
616 extern void factor_integer_number (EXPR *, char *);
617
618 // ++++ MACROS
619
620 #define ln(x) log(x)
621
622 static int_4 EQUAL (char *s, char *t)
623 {
624 if (s == NULL || t == NULL) {
625 return s == t;
626 } else {
627 return strcasecmp (s, t) == 0;
628 }
629 }
630
631 static int_4 LEQUAL (char *s, char *t)
632 {
633 if (s == NULL || t == NULL) {
634 return s == t;
635 } else {
636 return strncasecmp (s, t, strlen (s)) == 0;
637 }
638 }
639
640 static inline void BUG (char *s)
641 {
642 fprintf (stderr, "%d %s\n", curlin, source[curlin].text);
643 message (NULL, ERR, "fatal", 4001, "compiler bug", (s));
644 exit (EXIT_FAILURE);
645 }
646
647 #define _write_err(rc, funit, action)\
648 fflush (_ffile[(funit)].unit);\
649 if ((rc) < 1 || ferror (_ffile[(funit)].unit)) {\
650 action;\
651 }
652
653 #define _read_err(rc, funit, action_end, action_err)\
654 if (feof (_ffile[(funit)].unit)) {\
655 action_end;\
656 }\
657 if ((rc) < 1 || ferror (_ffile[(funit)].unit)) {\
658 action_err;\
659 }
660
661 #define _write_eol(funit) {\
662 (void) _vifprintf ((funit), "\n", NULL, NOTYPE, 0);\
663 fflush (_ffile[(funit)].unit);\
664 }
665
666 #define _read_eol(funit) {\
667 (void) _vifscanf ((funit), NULL, NULL, NOTYPE, 0);\
668 }
669
670 #define _abs(a) ({__typeof__ (a) _u = (a); _u >= 0 ? _u : -_u;})
671 #define _dim(a, b) ({__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a - _b : 0;})
672 #define _max(a, b) ({__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b;})
673 #define _min(a, b) ({__typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b;})
674 #define _mod(a, b) ({__typeof__ (a) _a = (a), _b = (b), _q = (_a / _b); _q = (_q >= 0 ? floor (_q) : -floor (-_q)); _a - _q * _b;})
675 #define _sign(a, b) ({__typeof__ (a) _a = _abs (a); b >= 0 ? _a : -_a;})
676
677 #define _ichar(s) ((int_4) ((s)[0]))
678
679 // AINT
680 static inline real_4 _aintf (real_4 x) {return truncf (x);}
681 static inline real_8 _aintd (real_8 x) {return trunc (x);}
682 static inline real_16 _aintq (real_16 x) {return truncq (x);}
683
684 // NINT
685 static inline int_4 _nintf (real_4 x) {return (int_4) (x) >= 0.0 ? floorf (x + 0.5) : -floorf (0.5 - x);}
686 static inline int_4 _nintd (real_8 x) {return (int_4) (x >= 0.0 ? floor (x + 0.5) : -floor (0.5 - x));}
687 static inline int_4 _nintq (real_16 x) {return (int_4) (x >= 0.0q ? floorq (x + 0.5q) : -floorq (0.5q - x));}
688
689 // ANINT
690 static inline real_4 _anintf (real_4 x) {return (x) >= 0.0 ? floorf (x + 0.5) : -floorf (0.5 - x);}
691 static inline real_8 _anintd (real_8 x) {return (x >= 0.0 ? floor (x + 0.5) : -floor (0.5 - x));}
692 static inline real_16 _anintq (real_8 x) {return (x >= 0.0q ? floor (x + 0.5q) : -floor (0.5q - x));}
693
694 // COMPLEX*32
695
696 static inline complex_32 CMPLXQ (real_16 re, real_16 im) {complex_32 z; __real__ z = re; __imag__ z = im; return z;}
697
698 // COMPLEX*64
699
700 #define CMPLXX(re, im) (complex_64){re, im}
701
702 // RTS
703
704 extern int_4 _str_to_int4 (char *);
705 extern real_8 _str_to_real8 (char *);
706
707 extern char *_char (int);
708 extern char *__strtok_r (char *, const char *, char **);
709 extern char *_strupper (char *);
710 extern char **_vif_jit (char *, char *);
711 extern complex_16 _dcmplxq (complex_32);
712 extern complex_16 _up_complex (complex_16, int_4);
713 extern complex_32 _qcmplxd (complex_16);
714 extern complex_32 _up_complex_32 (complex_32, int_4);
715 extern complex_8 _cmplxd (complex_16);
716 extern complex_8 _up_complex_8 (complex_8, int_4);
717 extern int_4 _i1mach (int_4 *);
718 extern int_4 _srecordf (char *, const char *, ...);
719 extern int_4 _up_int_4 (int_4, int_4);
720 extern int_4 _vifprintf (int_4, char*, void*, int_4, int_4);
721 extern int_4 _vifscanf (int_4, char*, void*, int_4, int_4);
722 extern int_4 _xerclr (void);
723 extern int_4 _xermsg (char *, char *, char *, int_4 *, int_4 *);
724 extern int_4 _xgetf (int_4 *);
725 extern int_4 _xint4 (real_32);
726 extern int_4 _xnint4 (real_32);
727 extern int_4 _xsetf (int_4 *);
728 extern int_8 _up_int_8 (int_8, int_4);
729 extern int_8 _xint8 (real_32);
730 extern int_8 _xnint8 (real_32);
731 extern real_16 _acotanq (real_16);
732 extern real_16 cotanq (real_16);
733 extern real_16 _qext (real_8);
734 extern real_16 _up_real_16 (real_16, int_4);
735 extern real_16 _xtoquad (real_32);
736 extern real_16 _zabs_32 (real_16 re, real_16 im);
737 extern real_32 _quadtox (real_16);
738 extern real_32 _quadtop (real_32 *, real_16);
739 extern real_32 _xerf (real_32);
740 extern real_32 _xint (real_32);
741 extern real_32 _xI (real_32);
742 extern real_32 _xmod (real_32, real_32);
743 extern real_32 _xnint (real_32);
744 extern real_32 _zabs_64 (real_32 re, real_32 im);
745 extern real_4 _acotanf (real_4);
746 extern real_4 cotanf (real_4);
747 extern real_4 _up_real_4 (real_4, int_4);
748 extern real_4 _zabs_8 (real_4 re, real_4 im);
749 extern real_8 _acotan (real_8);
750 extern real_8 cotan (real_8);
751 extern real_8 _drand48 (void);
752 extern real_8 _up_real_8 (real_8, int_4);
753 extern real_8 _zabs_16 (real_8 re, real_8 im);
754 extern void _cputim (real_8 *);
755 extern void _cputyd (int_4 *);
756 extern void _fcheck (char *, int_4, char *, char *);
757 extern void _fclose (int_4);
758 extern void _fprintf_real_32 (char *, char *, real_32, int_4, int_4);
759 extern void _fregister (char *, int_4, int_4, char *, char *, char *, char *);
760 extern void _funregister (char *, int_4);
761 extern void _ioend_read (char *, int_4);
762 extern void _ioerr (char *, int_4);
763 extern void _ioerr_read (char *, int_4);
764 extern void _ioerr_write (char *, int_4);
765 extern void _merfi (real_8 *, real_8 *, int_4 *);
766 extern void _qhex (real_16 *);
767 extern void _skip_eol (FILE *);
768 extern void _srand48 (int_4 *);
769 extern void _vif_exit (void);
770 extern void _vif_freq (CALLS *);
771 extern void _vif_init (void);
772 extern void _xhex (real_32 *);
773
774 // ++++ INTRINSIC functions
775
776 extern complex_16 _cdcos (complex_16 *);
777 extern complex_16 _cdexp (complex_16 *);
778 extern complex_16 _cdlog (complex_16 *);
779 extern complex_16 _cdsin (complex_16 *);
780 extern complex_16 _cdsqrt (complex_16 *);
781 extern complex_16 _cdtan (complex_16 *);
782 extern complex_32 _cqcos (complex_32 *);
783 extern complex_32 _cqexp (complex_32 *);
784 extern complex_32 _cqlog (complex_32 *);
785 extern complex_32 _cqsin (complex_32 *);
786 extern complex_32 _cqsqrt (complex_32 *);
787 extern complex_32 _cqtan (complex_32 *);
788 extern complex_64 _cxcos (complex_64 *);
789 extern complex_64 _cxexp (complex_64 *);
790 extern complex_64 _cxlog (complex_64 *);
791 extern complex_64 _cxsin (complex_64 *);
792 extern complex_64 _cxsqrt (complex_64 *);
793 extern complex_64 _cxtan (complex_64 *);
794 extern complex_8 _ccos (complex_8 *);
795 extern complex_8 _cexp (complex_8 *);
796 extern complex_8 _clog (complex_8 *);
797 extern complex_8 _csin (complex_8 *);
798 extern complex_8 _csqrt (complex_8 *);
799 extern complex_8 _ctan (complex_8 *);
800 extern real_16 _qacos (real_16 *);
801 extern real_16 _qasin (real_16 *);
802 extern real_16 _qatan2 (real_16 *, real_16 *);
803 extern real_16 _qatan (real_16 *);
804 extern real_16 _qcosh (real_16 *);
805 extern real_16 _qcos (real_16 *);
806 extern real_16 _qcotan (real_16 *);
807 extern real_16 _qexp (real_16 *);
808 extern real_16 _qint (real_16);
809 extern real_16 _qlog10 (real_16 *);
810 extern real_16 _qlog (real_16 *);
811 extern real_16 _qnint (real_16);
812 extern real_16 _qsinh (real_16 *);
813 extern real_16 _qsin (real_16 *);
814 extern real_16 _qsqrt (real_16 *);
815 extern real_16 _qtanh (real_16 *);
816 extern real_16 _qtan (real_16 *);
817 extern real_16 _strtoquad (char *, char **);
818 extern real_32 _xacos (real_32 *);
819 extern real_32 _xasin (real_32 *);
820 extern real_32 _xatan2 (real_32 *, real_32 *);
821 extern real_32 _xatan (real_32 *);
822 extern real_32 _xcosh (real_32 *);
823 extern real_32 _xcos (real_32 *);
824 extern real_32 _xcotan (real_32 *);
825 extern real_32 _xexp (real_32 *);
826 extern real_32 _xlog10 (real_32 *);
827 extern real_32 _xlog (real_32 *);
828 extern real_32 _xsinh (real_32 *);
829 extern real_32 _xsin (real_32 *);
830 extern real_32 _xsqrt (real_32 *);
831 extern real_32 _xtanh (real_32 *);
832 extern real_32 _xtan (real_32 *);
833 extern real_4 _acosf (real_4 *);
834 extern real_4 _aint (real_4);
835 extern real_4 _anint (real_4);
836 extern real_4 _atan2f (real_4 *, real_4 *);
837 extern real_4 _atanf (real_4 *);
838 extern real_4 _cosf (real_4 *);
839 extern real_4 _coshf (real_4 *);
840 extern real_4 _cotanf (real_4 *);
841 extern real_4 _expf (real_4 *);
842 extern real_4 _log10f (real_4 *);
843 extern real_4 _logf (real_4 *);
844 extern real_4 _sinf (real_4 *);
845 extern real_4 _sinhf (real_4 *);
846 extern real_4 _sqrtf (real_4 *);
847 extern real_4 _tanf (real_4 *);
848 extern real_4 _tanhf (real_4 *);
849 extern real_8 _dacos (real_8 *);
850 extern real_8 _dasin (real_8 *);
851 extern real_8 _datan2 (real_8 *, real_8 *);
852 extern real_8 _datan (real_8 *);
853 extern real_8 _dcosh (real_8 *);
854 extern real_8 _dcos (real_8 *);
855 extern real_8 _dcotan (real_8 *);
856 extern real_8 _dexp (real_8 *);
857 extern real_8 _dint (real_8);
858 extern real_8 _dlog10 (real_8 *);
859 extern real_8 _dlog (real_8 *);
860 extern real_8 _dnint (real_8);
861 extern real_8 _dsinh (real_8 *);
862 extern real_8 _dsin (real_8 *);
863 extern real_8 _dsqrt (real_8 *);
864 extern real_8 _dtanh (real_8 *);
865 extern real_8 _dtan (real_8 *);
866 extern void _pi16 (real_16 *);
867 extern void _pi32 (real_32 *);
868 extern void _pi4 (real_4 *);
869 extern void _pi8 (real_8 *);
870
871 #endif
© 2002-2025 J.M. van der Veer (jmvdveer@xs4all.nl)
|