xref: /csrg-svn/usr.bin/f77/pass1.tahoe/init.c (revision 37425)
1*37425Sbostic /*
2*37425Sbostic  * Copyright (c) 1980 Regents of the University of California.
3*37425Sbostic  * All rights reserved.  The Berkeley software License Agreement
4*37425Sbostic  * specifies the terms and conditions for redistribution.
5*37425Sbostic  */
6*37425Sbostic 
7*37425Sbostic #ifndef lint
8*37425Sbostic static	char *sccsid = "@(#)init.c	5.1 (Berkeley) 85/06/07";
9*37425Sbostic #endif
10*37425Sbostic 
11*37425Sbostic /*
12*37425Sbostic  * init.c
13*37425Sbostic  *
14*37425Sbostic  * Initializations for f77 compiler, pass 1.
15*37425Sbostic  *
16*37425Sbostic  * University of Utah CS Dept modification history:
17*37425Sbostic  *
18*37425Sbostic  * $Header: init.c,v 2.1 84/07/19 12:03:26 donn Exp $
19*37425Sbostic  * $Log:	init.c,v $
20*37425Sbostic  * Revision 2.1  84/07/19  12:03:26  donn
21*37425Sbostic  * Changed comment headers for UofU.
22*37425Sbostic  *
23*37425Sbostic  * Revision 1.3  84/02/28  21:07:53  donn
24*37425Sbostic  * Added Berkeley changes for call argument temporaries fix.
25*37425Sbostic  *
26*37425Sbostic  * Fixed incorrect check of 'cdatafile' when 'cchkfile' is opened. -- Donn
27*37425Sbostic  */
28*37425Sbostic 
29*37425Sbostic #include "defs.h"
30*37425Sbostic #include "io.h"
31*37425Sbostic #include <sys/file.h>
32*37425Sbostic 
33*37425Sbostic 
34*37425Sbostic FILEP infile	= { stdin };
35*37425Sbostic FILEP diagfile	= { stderr };
36*37425Sbostic 
37*37425Sbostic FILEP textfile;
38*37425Sbostic FILEP asmfile;
39*37425Sbostic FILEP initfile;
40*37425Sbostic long int headoffset;
41*37425Sbostic 
42*37425Sbostic char token[1321];
43*37425Sbostic int toklen;
44*37425Sbostic int lineno;
45*37425Sbostic char *infname;
46*37425Sbostic int needkwd;
47*37425Sbostic struct Labelblock *thislabel	= NULL;
48*37425Sbostic flag nowarnflag	= NO;
49*37425Sbostic flag ftn66flag	= NO;
50*37425Sbostic flag no66flag	= NO;
51*37425Sbostic flag noextflag	= NO;
52*37425Sbostic flag profileflag	= NO;
53*37425Sbostic flag optimflag	= NO;
54*37425Sbostic flag shiftcase	= YES;
55*37425Sbostic flag undeftype	= NO;
56*37425Sbostic flag shortsubs	= YES;
57*37425Sbostic flag onetripflag	= NO;
58*37425Sbostic flag checksubs	= NO;
59*37425Sbostic flag debugflag [MAXDEBUGFLAG] = { NO };
60*37425Sbostic flag equivdcl 	= NO;
61*37425Sbostic int nerr;
62*37425Sbostic int nwarn;
63*37425Sbostic int ndata;
64*37425Sbostic 
65*37425Sbostic flag saveall;
66*37425Sbostic flag substars;
67*37425Sbostic int parstate	= OUTSIDE;
68*37425Sbostic flag headerdone	= NO;
69*37425Sbostic int blklevel;
70*37425Sbostic int impltype[26];
71*37425Sbostic int implleng[26];
72*37425Sbostic int implstg[26];
73*37425Sbostic 
74*37425Sbostic int tyint	= TYLONG ;
75*37425Sbostic int tylogical	= TYLONG;
76*37425Sbostic ftnint typesize[NTYPES]
77*37425Sbostic 	= { 1, SZADDR, SZSHORT, SZLONG, SZLONG, 2*SZLONG,
78*37425Sbostic 	    2*SZLONG, 4*SZLONG, SZLONG, 1, 1, 1};
79*37425Sbostic int typealign[NTYPES]
80*37425Sbostic 	= { 1, ALIADDR, ALISHORT, ALILONG, ALILONG, ALIDOUBLE,
81*37425Sbostic 	    ALILONG, ALIDOUBLE, ALILONG, 1, 1, 1};
82*37425Sbostic int procno;
83*37425Sbostic int lwmno;
84*37425Sbostic int proctype	= TYUNKNOWN;
85*37425Sbostic char *procname;
86*37425Sbostic int rtvlabel[NTYPES];
87*37425Sbostic int fudgelabel;
88*37425Sbostic Addrp typeaddr;
89*37425Sbostic Addrp retslot;
90*37425Sbostic int cxslot	= -1;
91*37425Sbostic int chslot	= -1;
92*37425Sbostic int chlgslot	= -1;
93*37425Sbostic int procclass	= CLUNKNOWN;
94*37425Sbostic int nentry;
95*37425Sbostic flag multitype;
96*37425Sbostic ftnint procleng;
97*37425Sbostic int lastlabno	= 10;
98*37425Sbostic int lastvarno;
99*37425Sbostic int lastargslot;
100*37425Sbostic int argloc;
101*37425Sbostic ftnint autoleng;
102*37425Sbostic ftnint bssleng	= 0;
103*37425Sbostic int retlabel;
104*37425Sbostic int ret0label;
105*37425Sbostic int lowbss = 0;
106*37425Sbostic int highbss = 0;
107*37425Sbostic int bsslabel;
108*37425Sbostic flag anyinits = NO;
109*37425Sbostic flag anylocals = NO;
110*37425Sbostic 
111*37425Sbostic int maxctl	= MAXCTL;
112*37425Sbostic struct Ctlframe *ctls;
113*37425Sbostic struct Ctlframe *ctlstack;
114*37425Sbostic struct Ctlframe *lastctl;
115*37425Sbostic 
116*37425Sbostic Namep regnamep[MAXREGVAR];
117*37425Sbostic int highregvar;
118*37425Sbostic int nregvar;
119*37425Sbostic 
120*37425Sbostic int maxext	= MAXEXT;
121*37425Sbostic struct Extsym *extsymtab;
122*37425Sbostic struct Extsym *nextext;
123*37425Sbostic struct Extsym *lastext;
124*37425Sbostic 
125*37425Sbostic int maxequiv	= MAXEQUIV;
126*37425Sbostic struct Equivblock *eqvclass;
127*37425Sbostic 
128*37425Sbostic int maxhash	= MAXHASH;
129*37425Sbostic struct Hashentry *hashtab;
130*37425Sbostic struct Hashentry *lasthash;
131*37425Sbostic 
132*37425Sbostic int maxstno	= MAXSTNO;
133*37425Sbostic struct Labelblock *labeltab;
134*37425Sbostic struct Labelblock *labtabend;
135*37425Sbostic struct Labelblock *highlabtab;
136*37425Sbostic 
137*37425Sbostic int maxdim	= MAXDIM;
138*37425Sbostic struct Rplblock *rpllist	= NULL;
139*37425Sbostic struct Chain *curdtp	= NULL;
140*37425Sbostic flag toomanyinit;
141*37425Sbostic ftnint curdtelt;
142*37425Sbostic chainp templist	= NULL;
143*37425Sbostic chainp argtemplist = CHNULL;
144*37425Sbostic chainp activearglist = CHNULL;
145*37425Sbostic chainp holdtemps	= NULL;
146*37425Sbostic int dorange	= 0;
147*37425Sbostic struct Entrypoint *entries	= NULL;
148*37425Sbostic 
149*37425Sbostic chainp chains	= NULL;
150*37425Sbostic 
151*37425Sbostic flag inioctl;
152*37425Sbostic Addrp ioblkp;
153*37425Sbostic int iostmt;
154*37425Sbostic int nioctl;
155*37425Sbostic int nequiv	= 0;
156*37425Sbostic int eqvstart	= 0;
157*37425Sbostic int nintnames	= 0;
158*37425Sbostic 
159*37425Sbostic #ifdef SDB
160*37425Sbostic int dbglabel	= 0;
161*37425Sbostic flag sdbflag	= NO;
162*37425Sbostic #endif
163*37425Sbostic 
164*37425Sbostic struct Literal litpool[MAXLITERALS];
165*37425Sbostic int nliterals;
166*37425Sbostic 
167*37425Sbostic int cdatafile;
168*37425Sbostic int cchkfile;
169*37425Sbostic int vdatafile;
170*37425Sbostic int vchkfile;
171*37425Sbostic 
172*37425Sbostic char cdatafname[44] = "";
173*37425Sbostic char cchkfname[44] = "";
174*37425Sbostic char vdatafname[44] = "";
175*37425Sbostic char vchkfname[44] = "";
176*37425Sbostic 
177*37425Sbostic long cdatahwm = 0;
178*37425Sbostic long vdatahwm = 0;
179*37425Sbostic 
180*37425Sbostic ioblock *iodata = NULL;
181*37425Sbostic 
182*37425Sbostic 
183*37425Sbostic 
184*37425Sbostic fileinit()
185*37425Sbostic {
186*37425Sbostic int pid;
187*37425Sbostic 
188*37425Sbostic pid = getpid();
189*37425Sbostic sprintf(cdatafname, "/tmp/fortcd.%d", pid);
190*37425Sbostic sprintf(cchkfname, "/tmp/fortcc.%d", pid);
191*37425Sbostic sprintf(vdatafname, "/tmp/fortvd.%d", pid);
192*37425Sbostic sprintf(vchkfname, "/tmp/fortvc.%d", pid);
193*37425Sbostic 
194*37425Sbostic cdatafile = open(cdatafname, O_CREAT | O_RDWR, 0600);
195*37425Sbostic if (cdatafile < 0)
196*37425Sbostic   fatalstr("cannot open tmp file %s", cdatafname);
197*37425Sbostic 
198*37425Sbostic cchkfile = open(cchkfname, O_CREAT | O_RDWR, 0600);
199*37425Sbostic if (cchkfile < 0)
200*37425Sbostic   fatalstr("cannot open tmp file %s", cchkfname);
201*37425Sbostic 
202*37425Sbostic pruse(initfile, USEINIT);
203*37425Sbostic 
204*37425Sbostic procno = 0;
205*37425Sbostic lwmno = 0;
206*37425Sbostic lastlabno = 10;
207*37425Sbostic lastvarno = 0;
208*37425Sbostic nliterals = 0;
209*37425Sbostic nerr = 0;
210*37425Sbostic ndata = 0;
211*37425Sbostic 
212*37425Sbostic ctls = ALLOCN(maxctl, Ctlframe);
213*37425Sbostic extsymtab = ALLOCN(maxext, Extsym);
214*37425Sbostic eqvclass = ALLOCN(maxequiv, Equivblock);
215*37425Sbostic hashtab = ALLOCN(maxhash, Hashentry);
216*37425Sbostic labeltab = ALLOCN(maxstno, Labelblock);
217*37425Sbostic 
218*37425Sbostic ctlstack = ctls - 1;
219*37425Sbostic lastctl = ctls + maxctl;
220*37425Sbostic nextext = extsymtab;
221*37425Sbostic lastext = extsymtab + maxext;
222*37425Sbostic lasthash = hashtab + maxhash;
223*37425Sbostic labtabend = labeltab + maxstno;
224*37425Sbostic highlabtab = labeltab;
225*37425Sbostic }
226*37425Sbostic 
227*37425Sbostic 
228*37425Sbostic 
229*37425Sbostic 
230*37425Sbostic 
231*37425Sbostic procinit()
232*37425Sbostic {
233*37425Sbostic register Namep p;
234*37425Sbostic register struct Dimblock *q;
235*37425Sbostic register struct Hashentry *hp;
236*37425Sbostic register struct Labelblock *lp;
237*37425Sbostic struct Chain *cp;
238*37425Sbostic int i;
239*37425Sbostic 
240*37425Sbostic vdatafile = open(vdatafname, O_CREAT | O_RDWR, 0600);
241*37425Sbostic if (vdatafile < 0)
242*37425Sbostic   fatalstr("cannot open tmp file %s", vdatafname);
243*37425Sbostic 
244*37425Sbostic vchkfile = open(vchkfname, O_CREAT | O_RDWR, 0600);
245*37425Sbostic if (vchkfile < 0)
246*37425Sbostic   fatalstr("cannot open tmp file %s", vchkfname);
247*37425Sbostic 
248*37425Sbostic pruse(asmfile, USECONST);
249*37425Sbostic #if FAMILY == PCC
250*37425Sbostic 	p2pass(USETEXT);
251*37425Sbostic #endif
252*37425Sbostic parstate = OUTSIDE;
253*37425Sbostic headerdone = NO;
254*37425Sbostic blklevel = 1;
255*37425Sbostic saveall = NO;
256*37425Sbostic substars = NO;
257*37425Sbostic nwarn = 0;
258*37425Sbostic thislabel = NULL;
259*37425Sbostic needkwd = 0;
260*37425Sbostic 
261*37425Sbostic ++procno;
262*37425Sbostic proctype = TYUNKNOWN;
263*37425Sbostic procname = "MAIN     ";
264*37425Sbostic procclass = CLUNKNOWN;
265*37425Sbostic nentry = 0;
266*37425Sbostic multitype = NO;
267*37425Sbostic typeaddr = NULL;
268*37425Sbostic retslot = NULL;
269*37425Sbostic cxslot = -1;
270*37425Sbostic chslot = -1;
271*37425Sbostic chlgslot = -1;
272*37425Sbostic procleng = 0;
273*37425Sbostic blklevel = 1;
274*37425Sbostic lastargslot = 0;
275*37425Sbostic #if TARGET==PDP11
276*37425Sbostic 	autoleng = 6;
277*37425Sbostic #else
278*37425Sbostic #if TARGET==TAHOE
279*37425Sbostic 	autoleng = 52;
280*37425Sbostic #else
281*37425Sbostic 	autoleng = 0;
282*37425Sbostic #endif
283*37425Sbostic #endif
284*37425Sbostic for(lp = labeltab ; lp < labtabend ; ++lp)
285*37425Sbostic 	lp->stateno = 0;
286*37425Sbostic 
287*37425Sbostic for(hp = hashtab ; hp < lasthash ; ++hp)
288*37425Sbostic 	if(p = hp->varp)
289*37425Sbostic 		{
290*37425Sbostic 		frexpr(p->vleng);
291*37425Sbostic 		if(q = p->vdim)
292*37425Sbostic 			{
293*37425Sbostic 			for(i = 0 ; i < q->ndim ; ++i)
294*37425Sbostic 				{
295*37425Sbostic 				frexpr(q->dims[i].dimsize);
296*37425Sbostic 				frexpr(q->dims[i].dimexpr);
297*37425Sbostic 				}
298*37425Sbostic 			frexpr(q->nelt);
299*37425Sbostic 			frexpr(q->baseoffset);
300*37425Sbostic 			frexpr(q->basexpr);
301*37425Sbostic 			free( (charptr) q);
302*37425Sbostic 			}
303*37425Sbostic 		if(p->vclass == CLNAMELIST)
304*37425Sbostic 			frchain( &(p->varxptr.namelist) );
305*37425Sbostic 		free( (charptr) p);
306*37425Sbostic 		hp->varp = NULL;
307*37425Sbostic 		}
308*37425Sbostic nintnames = 0;
309*37425Sbostic highlabtab = labeltab;
310*37425Sbostic 
311*37425Sbostic ctlstack = ctls - 1;
312*37425Sbostic for(cp = templist ; cp ; cp = cp->nextp)
313*37425Sbostic 	free( (charptr) (cp->datap) );
314*37425Sbostic frchain(&templist);
315*37425Sbostic for (cp = argtemplist; cp; cp = cp->nextp)
316*37425Sbostic   free((char *) (cp->datap));
317*37425Sbostic frchain(&argtemplist);
318*37425Sbostic holdtemps = NULL;
319*37425Sbostic dorange = 0;
320*37425Sbostic nregvar = 0;
321*37425Sbostic highregvar = 0;
322*37425Sbostic entries = NULL;
323*37425Sbostic rpllist = NULL;
324*37425Sbostic inioctl = NO;
325*37425Sbostic ioblkp = NULL;
326*37425Sbostic eqvstart += nequiv;
327*37425Sbostic nequiv = 0;
328*37425Sbostic 
329*37425Sbostic for(i = 0 ; i<NTYPES ; ++i)
330*37425Sbostic 	rtvlabel[i] = 0;
331*37425Sbostic fudgelabel = 0;
332*37425Sbostic 
333*37425Sbostic if(undeftype)
334*37425Sbostic 	setimpl(TYUNKNOWN, (ftnint) 0, 'a', 'z');
335*37425Sbostic else
336*37425Sbostic 	{
337*37425Sbostic 	setimpl(TYREAL, (ftnint) 0, 'a', 'z');
338*37425Sbostic 	setimpl(tyint,  (ftnint) 0, 'i', 'n');
339*37425Sbostic 	}
340*37425Sbostic setimpl(-STGBSS, (ftnint) 0, 'a', 'z');	/* set class */
341*37425Sbostic setlog();
342*37425Sbostic setopt();
343*37425Sbostic 
344*37425Sbostic bsslabel = ++lastvarno;
345*37425Sbostic anylocals = NO;
346*37425Sbostic anyinits = NO;
347*37425Sbostic }
348*37425Sbostic 
349*37425Sbostic 
350*37425Sbostic 
351*37425Sbostic 
352*37425Sbostic setimpl(type, length, c1, c2)
353*37425Sbostic int type;
354*37425Sbostic ftnint length;
355*37425Sbostic int c1, c2;
356*37425Sbostic {
357*37425Sbostic int i;
358*37425Sbostic char buff[100];
359*37425Sbostic 
360*37425Sbostic if(c1==0 || c2==0)
361*37425Sbostic 	return;
362*37425Sbostic 
363*37425Sbostic if(c1 > c2)
364*37425Sbostic 	{
365*37425Sbostic 	sprintf(buff, "characters out of order in implicit:%c-%c", c1, c2);
366*37425Sbostic 	err(buff);
367*37425Sbostic 	}
368*37425Sbostic else
369*37425Sbostic 	if(type < 0)
370*37425Sbostic 		for(i = c1 ; i<=c2 ; ++i)
371*37425Sbostic 			implstg[i-'a'] = - type;
372*37425Sbostic 	else
373*37425Sbostic 		{
374*37425Sbostic 		type = lengtype(type, (int) length);
375*37425Sbostic 		if((type != TYCHAR) && (tyint !=TYSHORT))
376*37425Sbostic 			length = 0;
377*37425Sbostic 		for(i = c1 ; i<=c2 ; ++i)
378*37425Sbostic 			{
379*37425Sbostic 			impltype[i-'a'] = type;
380*37425Sbostic 			implleng[i-'a'] = length;
381*37425Sbostic 			}
382*37425Sbostic 		}
383*37425Sbostic }
384