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 char *ftn_types[] = { "external", "??",
148 "integer*2", "integer", "real",
149 "double precision", "complex", "double complex",
150 "logical", "character", "subroutine"
153 int proctype = TYUNKNOWN;
155 int rtvlabel[NTYPES0];
156 Addrp retslot; /* Holds automatic variable which was
157 allocated the function return value
159 Addrp xretslot[NTYPES0]; /* for multiple entry points */
163 int procclass = CLUNKNOWN;
174 char *av_pfix[TYVOID] = {"??TYUNKNOWN??", "a","s","i","r","d","q","z","L","ch",
175 "??TYSUBR??", "??TYERROR??","ci", "ici",
176 "o", "cl", "al", "ioin" };
179 struct Ctlframe *ctls;
180 struct Ctlframe *ctlstack;
181 struct Ctlframe *lastctl;
183 Namep regnamep[MAXREGVAR];
193 struct Equivblock *eqvclass;
196 struct Hashentry *hashtab;
197 struct Hashentry *lasthash;
199 extern int maxstno; /* Maximum number of statement labels */
200 struct Labelblock *labeltab;
201 struct Labelblock *labtabend;
202 struct Labelblock *highlabtab;
205 struct Rplblock *rpllist = NULL;
206 struct Chain *curdtp = NULL;
209 chainp templist[TYVOID];
212 struct Entrypoint *entries = NULL;
214 chainp chains = NULL;
223 struct Literal litpool[MAXLITERALS];
227 char hextoi_tab[256], Letters[256];
228 char *wh_first, *wh_next, *wh_last;
230 #define ALLOCN(n,x) (struct x *) ckalloc((n)*sizeof(struct x))
237 lastiolabno = 100000;
245 memset(dflttype, tyreal, 26);
246 memset(dflttype + 'i' - 'a', tyint, 6);
247 memset(hextoi_tab, 16, sizeof(hextoi_tab));
248 for(i = 0, s = "0123456789abcdef"; *s; i++, s++)
250 for(i = 10, s = "ABCDEF"; *s; i++, s++)
252 for(j = 0, s = "abcdefghijklmnopqrstuvwxyz"; i = *s++; j++)
253 Letters[i] = Letters[i+'A'-'a'] = j;
255 ctls = ALLOCN(maxctl+1, Ctlframe);
256 extsymtab = ALLOCN(maxext, Extsym);
257 eqvclass = ALLOCN(maxequiv, Equivblock);
258 hashtab = ALLOCN(maxhash, Hashentry);
259 labeltab = ALLOCN(maxstno, Labelblock);
262 lastctl = ctls + maxctl;
264 lastext = extsymtab + maxext;
265 lasthash = hashtab + maxhash;
266 labtabend = labeltab + maxstno;
267 highlabtab = labeltab;
268 main_alias[0] = '\0';
270 dfltproc[TYREAL] = dfltproc[TYDREAL];
272 /* Initialize the routines for providing C output */
277 hashclear() /* clear hash table */
279 register struct Hashentry *hp;
281 register struct Dimblock *q;
284 for(hp = hashtab ; hp < lasthash ; ++hp)
290 for(i = 0 ; i < q->ndim ; ++i)
292 frexpr(q->dims[i].dimsize);
293 frexpr(q->dims[i].dimexpr);
296 frexpr(q->baseoffset);
300 if(p->vclass == CLNAMELIST)
301 frchain( &(p->varxptr.namelist) );
309 register struct Labelblock *lp;
312 extern struct memblock *curmemblock, *firstmemblock;
313 extern char *mem_first, *mem_next, *mem_last, *mem0_last;
314 extern void frexchain();
316 curmemblock = firstmemblock;
317 mem_next = mem_first;
318 mem_last = mem0_last;
319 wh_next = wh_first = wh_last = 0;
321 for(i = 0; i < 9; i++)
333 proctype = TYUNKNOWN;
335 procclass = CLUNKNOWN;
337 nallargs = nallchargs = 0;
340 for(i = 0; i < NTYPES0; i++) {
341 frexpr((expptr)xretslot[i]);
351 for(lp = labeltab ; lp < labtabend ; ++lp)
356 /* Clear the list of newly generated identifiers from the previous
359 frexchain(&new_vars);
360 frexchain(&used_builtins);
361 frchain(&assigned_fmts);
366 highlabtab = labeltab;
369 for(i = TYADDR; i < TYVOID; i++) {
370 for(cp = templist[i]; cp ; cp = cp->nextp)
371 free( (charptr) (cp->datap) );
372 frchain(templist + i);
386 for(i = 0 ; i<NTYPES0 ; ++i)
390 setimpl(TYUNKNOWN, (ftnint) 0, 'a', 'z');
393 setimpl(tyreal, (ftnint) 0, 'a', 'z');
394 setimpl(tyint, (ftnint) 0, 'i', 'n');
396 setimpl(-STGBSS, (ftnint) 0, 'a', 'z'); /* set class */
403 setimpl(type, length, c1, c2)
415 sprintf(buff, "characters out of order in implicit:%c-%c", c1, c2);
422 for(i = c1 ; i<=c2 ; ++i)
425 type = lengtype(type, length);
428 for(i = c1 ; i<=c2 ; ++i) {
430 implleng[i] = length;