xref: /csrg-svn/usr.bin/f77/pass1.tahoe/init.c (revision 47951)
1*47951Sbostic /*-
2*47951Sbostic  * Copyright (c) 1980 The Regents of the University of California.
3*47951Sbostic  * All rights reserved.
4*47951Sbostic  *
5*47951Sbostic  * %sccs.include.proprietary.c%
637425Sbostic  */
737425Sbostic 
837425Sbostic #ifndef lint
9*47951Sbostic static char sccsid[] = "@(#)init.c	5.4 (Berkeley) 04/12/91";
10*47951Sbostic #endif /* not lint */
1137425Sbostic 
1237425Sbostic /*
1337425Sbostic  * init.c
1437425Sbostic  *
1537425Sbostic  * Initializations for f77 compiler, pass 1.
1637425Sbostic  *
1737425Sbostic  * University of Utah CS Dept modification history:
1837425Sbostic  *
1937425Sbostic  * $Header: init.c,v 2.1 84/07/19 12:03:26 donn Exp $
2037425Sbostic  * $Log:	init.c,v $
2137425Sbostic  * Revision 2.1  84/07/19  12:03:26  donn
2237425Sbostic  * Changed comment headers for UofU.
2337425Sbostic  *
2437425Sbostic  * Revision 1.3  84/02/28  21:07:53  donn
2537425Sbostic  * Added Berkeley changes for call argument temporaries fix.
2637425Sbostic  *
2737425Sbostic  * Fixed incorrect check of 'cdatafile' when 'cchkfile' is opened. -- Donn
2837425Sbostic  */
2937425Sbostic 
3037425Sbostic #include "defs.h"
3137425Sbostic #include "io.h"
3237425Sbostic #include <sys/file.h>
3337793Sbostic #include "pathnames.h"
3437425Sbostic 
3537425Sbostic 
3637425Sbostic FILEP infile	= { stdin };
3737425Sbostic FILEP diagfile	= { stderr };
3837425Sbostic 
3937425Sbostic FILEP textfile;
4037425Sbostic FILEP asmfile;
4137425Sbostic FILEP initfile;
4237425Sbostic long int headoffset;
4337425Sbostic 
4437425Sbostic char token[1321];
4537425Sbostic int toklen;
4637425Sbostic int lineno;
4737425Sbostic char *infname;
4837425Sbostic int needkwd;
4937425Sbostic struct Labelblock *thislabel	= NULL;
5037425Sbostic flag nowarnflag	= NO;
5137425Sbostic flag ftn66flag	= NO;
5237425Sbostic flag no66flag	= NO;
5337425Sbostic flag noextflag	= NO;
5437425Sbostic flag profileflag	= NO;
5537425Sbostic flag optimflag	= NO;
5637425Sbostic flag shiftcase	= YES;
5737425Sbostic flag undeftype	= NO;
5837425Sbostic flag shortsubs	= YES;
5937425Sbostic flag onetripflag	= NO;
6037425Sbostic flag checksubs	= NO;
6137425Sbostic flag debugflag [MAXDEBUGFLAG] = { NO };
6237425Sbostic flag equivdcl 	= NO;
6337425Sbostic int nerr;
6437425Sbostic int nwarn;
6537425Sbostic int ndata;
6637425Sbostic 
6737425Sbostic flag saveall;
6837425Sbostic flag substars;
6937425Sbostic int parstate	= OUTSIDE;
7037425Sbostic flag headerdone	= NO;
7137425Sbostic int blklevel;
7237425Sbostic int impltype[26];
7337425Sbostic int implleng[26];
7437425Sbostic int implstg[26];
7537425Sbostic 
7637425Sbostic int tyint	= TYLONG ;
7737425Sbostic int tylogical	= TYLONG;
7837425Sbostic ftnint typesize[NTYPES]
7937425Sbostic 	= { 1, SZADDR, SZSHORT, SZLONG, SZLONG, 2*SZLONG,
8037425Sbostic 	    2*SZLONG, 4*SZLONG, SZLONG, 1, 1, 1};
8137425Sbostic int typealign[NTYPES]
8237425Sbostic 	= { 1, ALIADDR, ALISHORT, ALILONG, ALILONG, ALIDOUBLE,
8337425Sbostic 	    ALILONG, ALIDOUBLE, ALILONG, 1, 1, 1};
8437425Sbostic int procno;
8537425Sbostic int lwmno;
8637425Sbostic int proctype	= TYUNKNOWN;
8737425Sbostic char *procname;
8837425Sbostic int rtvlabel[NTYPES];
8937425Sbostic int fudgelabel;
9037425Sbostic Addrp typeaddr;
9137425Sbostic Addrp retslot;
9237425Sbostic int cxslot	= -1;
9337425Sbostic int chslot	= -1;
9437425Sbostic int chlgslot	= -1;
9537425Sbostic int procclass	= CLUNKNOWN;
9637425Sbostic int nentry;
9737425Sbostic flag multitype;
9837425Sbostic ftnint procleng;
9937425Sbostic int lastlabno	= 10;
10037425Sbostic int lastvarno;
10137425Sbostic int lastargslot;
10237425Sbostic int argloc;
10337425Sbostic ftnint autoleng;
10437425Sbostic ftnint bssleng	= 0;
10537425Sbostic int retlabel;
10637425Sbostic int ret0label;
10740232Sdonn ftnint lowbss = 0;
10840232Sdonn ftnint highbss = 0;
10937425Sbostic int bsslabel;
11037425Sbostic flag anyinits = NO;
11137425Sbostic flag anylocals = NO;
11237425Sbostic 
11337425Sbostic int maxctl	= MAXCTL;
11437425Sbostic struct Ctlframe *ctls;
11537425Sbostic struct Ctlframe *ctlstack;
11637425Sbostic struct Ctlframe *lastctl;
11737425Sbostic 
11837425Sbostic Namep regnamep[MAXREGVAR];
11937425Sbostic int highregvar;
12037425Sbostic int nregvar;
12137425Sbostic 
12237425Sbostic int maxext	= MAXEXT;
12337425Sbostic struct Extsym *extsymtab;
12437425Sbostic struct Extsym *nextext;
12537425Sbostic struct Extsym *lastext;
12637425Sbostic 
12737425Sbostic int maxequiv	= MAXEQUIV;
12837425Sbostic struct Equivblock *eqvclass;
12937425Sbostic 
13037425Sbostic int maxhash	= MAXHASH;
13137425Sbostic struct Hashentry *hashtab;
13237425Sbostic struct Hashentry *lasthash;
13337425Sbostic 
13437425Sbostic int maxstno	= MAXSTNO;
13537425Sbostic struct Labelblock *labeltab;
13637425Sbostic struct Labelblock *labtabend;
13737425Sbostic struct Labelblock *highlabtab;
13837425Sbostic 
13937425Sbostic int maxdim	= MAXDIM;
14037425Sbostic struct Rplblock *rpllist	= NULL;
14137425Sbostic struct Chain *curdtp	= NULL;
14237425Sbostic flag toomanyinit;
14337425Sbostic ftnint curdtelt;
14437425Sbostic chainp templist	= NULL;
14537425Sbostic chainp argtemplist = CHNULL;
14637425Sbostic chainp activearglist = CHNULL;
14737425Sbostic chainp holdtemps	= NULL;
14837425Sbostic int dorange	= 0;
14937425Sbostic struct Entrypoint *entries	= NULL;
15037425Sbostic 
15137425Sbostic chainp chains	= NULL;
15237425Sbostic 
15337425Sbostic flag inioctl;
15437425Sbostic Addrp ioblkp;
15537425Sbostic int iostmt;
15637425Sbostic int nioctl;
15737425Sbostic int nequiv	= 0;
15837425Sbostic int eqvstart	= 0;
15937425Sbostic int nintnames	= 0;
16037425Sbostic 
16137425Sbostic #ifdef SDB
16237425Sbostic int dbglabel	= 0;
16337425Sbostic flag sdbflag	= NO;
16437425Sbostic #endif
16537425Sbostic 
16637425Sbostic struct Literal litpool[MAXLITERALS];
16737425Sbostic int nliterals;
16837425Sbostic 
16937425Sbostic int cdatafile;
17037425Sbostic int cchkfile;
17137425Sbostic int vdatafile;
17237425Sbostic int vchkfile;
17337425Sbostic 
17437425Sbostic char cdatafname[44] = "";
17537425Sbostic char cchkfname[44] = "";
17637425Sbostic char vdatafname[44] = "";
17737425Sbostic char vchkfname[44] = "";
17837425Sbostic 
17937425Sbostic long cdatahwm = 0;
18037425Sbostic long vdatahwm = 0;
18137425Sbostic 
18237425Sbostic ioblock *iodata = NULL;
18337425Sbostic 
18437425Sbostic 
18537425Sbostic 
fileinit()18637425Sbostic fileinit()
18737425Sbostic {
18837425Sbostic int pid;
18937425Sbostic 
19037425Sbostic pid = getpid();
19137793Sbostic sprintf(cdatafname, "%s/fortcd.%d", _PATH_TMP, pid);
19237793Sbostic sprintf(cchkfname, "%s/fortcc.%d", _PATH_TMP, pid);
19337793Sbostic sprintf(vdatafname, "%s/fortvd.%d", _PATH_TMP, pid);
19437793Sbostic sprintf(vchkfname, "%s/fortvc.%d", _PATH_TMP, pid);
19537425Sbostic 
19637425Sbostic cdatafile = open(cdatafname, O_CREAT | O_RDWR, 0600);
19737425Sbostic if (cdatafile < 0)
19837425Sbostic   fatalstr("cannot open tmp file %s", cdatafname);
19937425Sbostic 
20037425Sbostic cchkfile = open(cchkfname, O_CREAT | O_RDWR, 0600);
20137425Sbostic if (cchkfile < 0)
20237425Sbostic   fatalstr("cannot open tmp file %s", cchkfname);
20337425Sbostic 
20437425Sbostic pruse(initfile, USEINIT);
20537425Sbostic 
20637425Sbostic procno = 0;
20737425Sbostic lwmno = 0;
20837425Sbostic lastlabno = 10;
20937425Sbostic lastvarno = 0;
21037425Sbostic nliterals = 0;
21137425Sbostic nerr = 0;
21237425Sbostic ndata = 0;
21337425Sbostic 
21437425Sbostic ctls = ALLOCN(maxctl, Ctlframe);
21537425Sbostic extsymtab = ALLOCN(maxext, Extsym);
21637425Sbostic eqvclass = ALLOCN(maxequiv, Equivblock);
21737425Sbostic hashtab = ALLOCN(maxhash, Hashentry);
21837425Sbostic labeltab = ALLOCN(maxstno, Labelblock);
21937425Sbostic 
22037425Sbostic ctlstack = ctls - 1;
22137425Sbostic lastctl = ctls + maxctl;
22237425Sbostic nextext = extsymtab;
22337425Sbostic lastext = extsymtab + maxext;
22437425Sbostic lasthash = hashtab + maxhash;
22537425Sbostic labtabend = labeltab + maxstno;
22637425Sbostic highlabtab = labeltab;
22737425Sbostic }
22837425Sbostic 
22937425Sbostic 
23037425Sbostic 
23137425Sbostic 
23237425Sbostic 
procinit()23337425Sbostic procinit()
23437425Sbostic {
23537425Sbostic register Namep p;
23637425Sbostic register struct Dimblock *q;
23737425Sbostic register struct Hashentry *hp;
23837425Sbostic register struct Labelblock *lp;
23937425Sbostic struct Chain *cp;
24037425Sbostic int i;
24137425Sbostic 
24237425Sbostic vdatafile = open(vdatafname, O_CREAT | O_RDWR, 0600);
24337425Sbostic if (vdatafile < 0)
24437425Sbostic   fatalstr("cannot open tmp file %s", vdatafname);
24537425Sbostic 
24637425Sbostic vchkfile = open(vchkfname, O_CREAT | O_RDWR, 0600);
24737425Sbostic if (vchkfile < 0)
24837425Sbostic   fatalstr("cannot open tmp file %s", vchkfname);
24937425Sbostic 
25037425Sbostic pruse(asmfile, USECONST);
25137425Sbostic #if FAMILY == PCC
25237425Sbostic 	p2pass(USETEXT);
25337425Sbostic #endif
25437425Sbostic parstate = OUTSIDE;
25537425Sbostic headerdone = NO;
25637425Sbostic blklevel = 1;
25737425Sbostic saveall = NO;
25837425Sbostic substars = NO;
25937425Sbostic nwarn = 0;
26037425Sbostic thislabel = NULL;
26137425Sbostic needkwd = 0;
26237425Sbostic 
26337425Sbostic ++procno;
26437425Sbostic proctype = TYUNKNOWN;
26537425Sbostic procname = "MAIN     ";
26637425Sbostic procclass = CLUNKNOWN;
26737425Sbostic nentry = 0;
26837425Sbostic multitype = NO;
26937425Sbostic typeaddr = NULL;
27037425Sbostic retslot = NULL;
27137425Sbostic cxslot = -1;
27237425Sbostic chslot = -1;
27337425Sbostic chlgslot = -1;
27437425Sbostic procleng = 0;
27537425Sbostic blklevel = 1;
27637425Sbostic lastargslot = 0;
27737425Sbostic #if TARGET==PDP11
27837425Sbostic 	autoleng = 6;
27937425Sbostic #else
28037425Sbostic #if TARGET==TAHOE
28137425Sbostic 	autoleng = 52;
28237425Sbostic #else
28337425Sbostic 	autoleng = 0;
28437425Sbostic #endif
28537425Sbostic #endif
28637425Sbostic for(lp = labeltab ; lp < labtabend ; ++lp)
28737425Sbostic 	lp->stateno = 0;
28837425Sbostic 
28937425Sbostic for(hp = hashtab ; hp < lasthash ; ++hp)
29037425Sbostic 	if(p = hp->varp)
29137425Sbostic 		{
29237425Sbostic 		frexpr(p->vleng);
29337425Sbostic 		if(q = p->vdim)
29437425Sbostic 			{
29537425Sbostic 			for(i = 0 ; i < q->ndim ; ++i)
29637425Sbostic 				{
29737425Sbostic 				frexpr(q->dims[i].dimsize);
29837425Sbostic 				frexpr(q->dims[i].dimexpr);
29937425Sbostic 				}
30037425Sbostic 			frexpr(q->nelt);
30137425Sbostic 			frexpr(q->baseoffset);
30237425Sbostic 			frexpr(q->basexpr);
30337425Sbostic 			free( (charptr) q);
30437425Sbostic 			}
30537425Sbostic 		if(p->vclass == CLNAMELIST)
30637425Sbostic 			frchain( &(p->varxptr.namelist) );
30737425Sbostic 		free( (charptr) p);
30837425Sbostic 		hp->varp = NULL;
30937425Sbostic 		}
31037425Sbostic nintnames = 0;
31137425Sbostic highlabtab = labeltab;
31237425Sbostic 
31337425Sbostic ctlstack = ctls - 1;
31437425Sbostic for(cp = templist ; cp ; cp = cp->nextp)
31537425Sbostic 	free( (charptr) (cp->datap) );
31637425Sbostic frchain(&templist);
31737425Sbostic for (cp = argtemplist; cp; cp = cp->nextp)
31837425Sbostic   free((char *) (cp->datap));
31937425Sbostic frchain(&argtemplist);
32037425Sbostic holdtemps = NULL;
32137425Sbostic dorange = 0;
32237425Sbostic nregvar = 0;
32337425Sbostic highregvar = 0;
32437425Sbostic entries = NULL;
32537425Sbostic rpllist = NULL;
32637425Sbostic inioctl = NO;
32737425Sbostic ioblkp = NULL;
32837425Sbostic eqvstart += nequiv;
32937425Sbostic nequiv = 0;
33037425Sbostic 
33137425Sbostic for(i = 0 ; i<NTYPES ; ++i)
33237425Sbostic 	rtvlabel[i] = 0;
33337425Sbostic fudgelabel = 0;
33437425Sbostic 
33537425Sbostic if(undeftype)
33637425Sbostic 	setimpl(TYUNKNOWN, (ftnint) 0, 'a', 'z');
33737425Sbostic else
33837425Sbostic 	{
33937425Sbostic 	setimpl(TYREAL, (ftnint) 0, 'a', 'z');
34037425Sbostic 	setimpl(tyint,  (ftnint) 0, 'i', 'n');
34137425Sbostic 	}
34237425Sbostic setimpl(-STGBSS, (ftnint) 0, 'a', 'z');	/* set class */
34337425Sbostic setlog();
34437425Sbostic setopt();
34537425Sbostic 
34637425Sbostic bsslabel = ++lastvarno;
34737425Sbostic anylocals = NO;
34837425Sbostic anyinits = NO;
34937425Sbostic }
35037425Sbostic 
35137425Sbostic 
35237425Sbostic 
35337425Sbostic 
setimpl(type,length,c1,c2)35437425Sbostic setimpl(type, length, c1, c2)
35537425Sbostic int type;
35637425Sbostic ftnint length;
35737425Sbostic int c1, c2;
35837425Sbostic {
35937425Sbostic int i;
36037425Sbostic char buff[100];
36137425Sbostic 
36237425Sbostic if(c1==0 || c2==0)
36337425Sbostic 	return;
36437425Sbostic 
36537425Sbostic if(c1 > c2)
36637425Sbostic 	{
36737425Sbostic 	sprintf(buff, "characters out of order in implicit:%c-%c", c1, c2);
36837425Sbostic 	err(buff);
36937425Sbostic 	}
37037425Sbostic else
37137425Sbostic 	if(type < 0)
37237425Sbostic 		for(i = c1 ; i<=c2 ; ++i)
37337425Sbostic 			implstg[i-'a'] = - type;
37437425Sbostic 	else
37537425Sbostic 		{
37637425Sbostic 		type = lengtype(type, (int) length);
37737425Sbostic 		if((type != TYCHAR) && (tyint !=TYSHORT))
37837425Sbostic 			length = 0;
37937425Sbostic 		for(i = c1 ; i<=c2 ; ++i)
38037425Sbostic 			{
38137425Sbostic 			impltype[i-'a'] = type;
38237425Sbostic 			implleng[i-'a'] = length;
38337425Sbostic 			}
38437425Sbostic 		}
38537425Sbostic }
386