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