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