1 /****************************************************************
2 Copyright 1990 by AT&T Bell Laboratories and Bellcore.
4 Permission to use, copy, modify, and distribute this software
5 and its documentation for any purpose and without fee is hereby
6 granted, provided that the above copyright notice appear in all
7 copies and that both that the copyright notice and this
8 permission notice and warranty disclaimer appear in supporting
9 documentation, and that the names of AT&T Bell Laboratories or
10 Bellcore or any of their entities not be used in advertising or
11 publicity pertaining to distribution of the software without
12 specific, written prior permission.
14 AT&T and Bellcore disclaim all warranties with regard to this
15 software, including all implied warranties of merchantability
16 and fitness. In no event shall AT&T or Bellcore be liable for
17 any special, indirect or consequential damages or any damages
18 whatsoever resulting from loss of use, data or profits, whether
19 in an action of contract, negligence or other tortious action,
20 arising out of or in connection with the use or performance of
22 ****************************************************************/
28 /* State required for the C output */
29 char *fl_fmt_string; /* Float format string */
30 char *db_fmt_string; /* Double format string */
31 char *cm_fmt_string; /* Complex format string */
32 char *dcm_fmt_string; /* Double complex format string */
34 chainp new_vars = CHNULL; /* List of newly created locals in this
35 function. These may have identifiers
36 which have underscores and more than VL
38 chainp used_builtins = CHNULL; /* List of builtins used by this function.
39 These are all Addrps with UNAM_EXTERN
41 chainp assigned_fmts = CHNULL; /* assigned formats */
42 chainp allargs; /* union of args in all entry points */
43 chainp earlylabs; /* labels seen before enddcl() */
44 char main_alias[52]; /* PROGRAM name, if any is given */
57 char token[MAXTOKENLEN];
59 long lineno; /* Current line in the input file, NOT the
60 Fortran statement label number */
63 struct Labelblock *thislabel = NULL;
69 int parstate = OUTSIDE;
78 int tylogical = TYLONG;
79 int typesize[NTYPES] = {
80 1, SZADDR, SZSHORT, SZLONG, SZLONG, 2*SZLONG,
81 2*SZLONG, 4*SZLONG, SZLONG, 1, 1, 0,
82 4*SZLONG + SZADDR, /* sizeof(cilist) */
83 4*SZLONG + 2*SZADDR, /* sizeof(icilist) */
84 4*SZLONG + 5*SZADDR, /* sizeof(olist) */
85 2*SZLONG + SZADDR, /* sizeof(cllist) */
86 2*SZLONG, /* sizeof(alist) */
87 11*SZLONG + 15*SZADDR /* sizeof(inlist) */
90 int typealign[NTYPES] = {
91 1, ALIADDR, ALISHORT, ALILONG, ALILONG, ALIDOUBLE,
92 ALILONG, ALIDOUBLE, ALILONG, 1, 1, 1,
93 ALILONG, ALILONG, ALILONG, ALILONG, ALILONG, ALILONG};
95 int type_choice[4] = { TYDREAL, TYSHORT, TYLONG, TYSHORT };
107 "char" /* character */
110 int type_pref[NTYPES] = { 0, 0, 2, 4, 5, 7, 6, 8, 3, 1 };
112 char *protorettypes[] = {
113 "?", "??", "shortint", "integer", "real", "doublereal",
114 "C_f", "Z_f", "logical", "H_f", "int"
117 char *casttypes[TYSUBR+1] = {
119 "J_fp", "I_fp", "R_fp",
120 "D_fp", "C_fp", "Z_fp",
121 "L_fp", "H_fp", "S_fp"
123 char *usedcasts[TYSUBR+1];
127 "(shortint *)0", "(integer *)0", "(real *)0",
128 "(doublereal *)0", "(complex *)0", "(doublecomplex *)0",
129 "(logical *)0", "(char *)0"
132 static char *dflt0proc[] = {
134 "(shortint (*)())0", "(integer (*)())0", "(real (*)())0",
135 "(doublereal (*)())0", "(complex (*)())0", "(doublecomplex (*)())0",
136 "(logical (*)())0", "(char (*)())0", "(int (*)())0"
139 char *dflt1proc[] = { "(U_fp)0", "(??bug??)0",
140 "(J_fp)0", "(I_fp)0", "(R_fp)0",
141 "(D_fp)0", "(C_fp)0", "(Z_fp)0",
142 "(L_fp)0", "(H_fp)0", "(S_fp)0"
145 char **dfltproc = dflt0proc;
147 static char Bug[] = "bug";
149 char *ftn_types[] = { "external", "??",
150 "integer*2", "integer", "real",
151 "double precision", "complex", "double complex",
152 "logical", "character", "subroutine",
153 Bug,Bug,Bug,Bug,Bug,Bug,Bug,Bug,Bug, "ftnlen"
156 int init_ac[TYSUBR+1] = { 0,0,0,0,0,0, 1, 1, 0, 2};
158 int proctype = TYUNKNOWN;
160 int rtvlabel[NTYPES0];
161 Addrp retslot; /* Holds automatic variable which was
162 allocated the function return value
164 Addrp xretslot[NTYPES0]; /* for multiple entry points */
168 int procclass = CLUNKNOWN;
179 char *av_pfix[TYVOID] = {"??TYUNKNOWN??", "a","s","i","r","d","q","z","L","ch",
180 "??TYSUBR??", "??TYERROR??","ci", "ici",
181 "o", "cl", "al", "ioin" };
184 struct Ctlframe *ctls;
185 struct Ctlframe *ctlstack;
186 struct Ctlframe *lastctl;
188 Namep regnamep[MAXREGVAR];
198 struct Equivblock *eqvclass;
201 struct Hashentry *hashtab;
202 struct Hashentry *lasthash;
204 extern int maxstno; /* Maximum number of statement labels */
205 struct Labelblock *labeltab;
206 struct Labelblock *labtabend;
207 struct Labelblock *highlabtab;
210 struct Rplblock *rpllist = NULL;
211 struct Chain *curdtp = NULL;
214 chainp templist[TYVOID];
217 struct Entrypoint *entries = NULL;
219 chainp chains = NULL;
228 struct Literal *litpool;
232 char hextoi_tab[Table_size], Letters[Table_size];
233 char *ei_first, *ei_next, *ei_last;
234 char *wh_first, *wh_next, *wh_last;
236 #define ALLOCN(n,x) (struct x *) ckalloc((n)*sizeof(struct x))
242 extern void fmt_init(), mem_init(), np_init();
244 lastiolabno = 100000;
252 memset(dflttype, tyreal, 26);
253 memset(dflttype + 'i' - 'a', tyint, 6);
254 memset(hextoi_tab, 16, sizeof(hextoi_tab));
255 for(i = 0, s = "0123456789abcdef"; *s; i++, s++)
257 for(i = 10, s = "ABCDEF"; *s; i++, s++)
259 for(j = 0, s = "abcdefghijklmnopqrstuvwxyz"; i = *s++; j++)
260 Letters[i] = Letters[i+'A'-'a'] = j;
262 ctls = ALLOCN(maxctl+1, Ctlframe);
263 extsymtab = ALLOCN(maxext, Extsym);
264 eqvclass = ALLOCN(maxequiv, Equivblock);
265 hashtab = ALLOCN(maxhash, Hashentry);
266 labeltab = ALLOCN(maxstno, Labelblock);
267 litpool = ALLOCN(maxliterals, Literal);
273 lastctl = ctls + maxctl;
275 lastext = extsymtab + maxext;
276 lasthash = hashtab + maxhash;
277 labtabend = labeltab + maxstno;
278 highlabtab = labeltab;
279 main_alias[0] = '\0';
281 dfltproc[TYREAL] = dfltproc[TYDREAL];
283 /* Initialize the routines for providing C output */
288 hashclear() /* clear hash table */
290 register struct Hashentry *hp;
292 register struct Dimblock *q;
295 for(hp = hashtab ; hp < lasthash ; ++hp)
301 for(i = 0 ; i < q->ndim ; ++i)
303 frexpr(q->dims[i].dimsize);
304 frexpr(q->dims[i].dimexpr);
307 frexpr(q->baseoffset);
311 if(p->vclass == CLNAMELIST)
312 frchain( &(p->varxptr.namelist) );
320 register struct Labelblock *lp;
323 extern struct memblock *curmemblock, *firstmemblock;
324 extern char *mem_first, *mem_next, *mem_last, *mem0_last;
325 extern void frexchain();
327 curmemblock = firstmemblock;
328 mem_next = mem_first;
329 mem_last = mem0_last;
330 ei_next = ei_first = ei_last = 0;
331 wh_next = wh_first = wh_last = 0;
333 for(i = 0; i < 9; i++)
345 proctype = TYUNKNOWN;
347 procclass = CLUNKNOWN;
349 nallargs = nallchargs = 0;
352 for(i = 0; i < NTYPES0; i++) {
353 frexpr((expptr)xretslot[i]);
363 for(lp = labeltab ; lp < labtabend ; ++lp)
368 /* Clear the list of newly generated identifiers from the previous
371 frexchain(&new_vars);
372 frexchain(&used_builtins);
373 frchain(&assigned_fmts);
378 highlabtab = labeltab;
381 for(i = TYADDR; i < TYVOID; i++) {
382 for(cp = templist[i]; cp ; cp = cp->nextp)
383 free( (charptr) (cp->datap) );
384 frchain(templist + i);
398 for(i = 0 ; i<NTYPES0 ; ++i)
402 setimpl(TYUNKNOWN, (ftnint) 0, 'a', 'z');
405 setimpl(tyreal, (ftnint) 0, 'a', 'z');
406 setimpl(tyint, (ftnint) 0, 'i', 'n');
408 setimpl(-STGBSS, (ftnint) 0, 'a', 'z'); /* set class */
415 setimpl(type, length, c1, c2)
427 sprintf(buff, "characters out of order in implicit:%c-%c", c1, c2);
434 for(i = c1 ; i<=c2 ; ++i)
437 type = lengtype(type, length);
440 for(i = c1 ; i<=c2 ; ++i) {
442 implleng[i] = length;