xref: /csrg-svn/usr.bin/f77/pass1.vax/init.c (revision 33255)
122832Smckusick /*
222832Smckusick  * Copyright (c) 1980 Regents of the University of California.
322832Smckusick  * All rights reserved.  The Berkeley software License Agreement
422832Smckusick  * specifies the terms and conditions for redistribution.
522832Smckusick  */
622832Smckusick 
722832Smckusick #ifndef lint
8*33255Sbostic static	char *sccsid = "@(#)init.c	5.3 (Berkeley) 01/03/88";
922832Smckusick #endif
1022832Smckusick 
1122832Smckusick /*
1222832Smckusick  * init.c
1322832Smckusick  *
1422832Smckusick  * Initializations for f77 compiler, pass 1.
1522832Smckusick  *
1622832Smckusick  * University of Utah CS Dept modification history:
1722832Smckusick  *
1824479Sdonn  * $Header: init.c,v 5.2 85/08/10 04:30:57 donn Exp $
1922832Smckusick  * $Log:	init.c,v $
2024479Sdonn  * Revision 5.2  85/08/10  04:30:57  donn
2124479Sdonn  * Jerry Berkman's changes to ifdef 66 code and handle -r8/double flag.
2224479Sdonn  *
2324479Sdonn  * Revision 5.1  85/08/10  03:47:33  donn
2424479Sdonn  * 4.3 alpha
2524479Sdonn  *
2622832Smckusick  * Revision 2.1  84/07/19  12:03:26  donn
2722832Smckusick  * Changed comment headers for UofU.
2822832Smckusick  *
2922832Smckusick  * Revision 1.3  84/02/28  21:07:53  donn
3022832Smckusick  * Added Berkeley changes for call argument temporaries fix.
3122832Smckusick  *
3222832Smckusick  * Fixed incorrect check of 'cdatafile' when 'cchkfile' is opened. -- Donn
3322832Smckusick  */
3422832Smckusick 
3522832Smckusick #include "defs.h"
3622832Smckusick #include "io.h"
3722832Smckusick #include <sys/file.h>
3822832Smckusick 
3922832Smckusick 
4022832Smckusick FILEP infile	= { stdin };
4122832Smckusick FILEP diagfile	= { stderr };
4222832Smckusick 
4322832Smckusick FILEP textfile;
4422832Smckusick FILEP asmfile;
4522832Smckusick FILEP initfile;
4622832Smckusick long int headoffset;
4722832Smckusick 
4822832Smckusick char token[1321];
4922832Smckusick int toklen;
5022832Smckusick int lineno;
5122832Smckusick char *infname;
5222832Smckusick int needkwd;
5322832Smckusick struct Labelblock *thislabel	= NULL;
5422832Smckusick flag nowarnflag	= NO;
5522832Smckusick flag ftn66flag	= NO;
5624479Sdonn #ifdef ONLY66
5722832Smckusick flag no66flag	= NO;
5822832Smckusick flag noextflag	= NO;
5924479Sdonn #endif
6024479Sdonn flag dblflag	= NO;
6122832Smckusick flag profileflag	= NO;
6222832Smckusick flag optimflag	= NO;
6322832Smckusick flag shiftcase	= YES;
6422832Smckusick flag undeftype	= NO;
6522832Smckusick flag shortsubs	= YES;
6622832Smckusick flag onetripflag	= NO;
6722832Smckusick flag checksubs	= NO;
6822832Smckusick flag debugflag [MAXDEBUGFLAG] = { NO };
6922832Smckusick flag equivdcl 	= NO;
7022832Smckusick int nerr;
7122832Smckusick int nwarn;
7222832Smckusick int ndata;
7322832Smckusick 
7422832Smckusick flag saveall;
7522832Smckusick flag substars;
7622832Smckusick int parstate	= OUTSIDE;
7722832Smckusick flag headerdone	= NO;
7822832Smckusick int blklevel;
7922832Smckusick int impltype[26];
8022832Smckusick int implleng[26];
8122832Smckusick int implstg[26];
8222832Smckusick 
8322832Smckusick int tyint	= TYLONG ;
8422832Smckusick int tylogical	= TYLONG;
8522832Smckusick ftnint typesize[NTYPES]
8622832Smckusick 	= { 1, SZADDR, SZSHORT, SZLONG, SZLONG, 2*SZLONG,
8722832Smckusick 	    2*SZLONG, 4*SZLONG, SZLONG, 1, 1, 1};
8822832Smckusick int typealign[NTYPES]
8922832Smckusick 	= { 1, ALIADDR, ALISHORT, ALILONG, ALILONG, ALIDOUBLE,
9022832Smckusick 	    ALILONG, ALIDOUBLE, ALILONG, 1, 1, 1};
9122832Smckusick int procno;
9222832Smckusick int lwmno;
9322832Smckusick int proctype	= TYUNKNOWN;
9422832Smckusick char *procname;
9522832Smckusick int rtvlabel[NTYPES];
9622832Smckusick int fudgelabel;
9722832Smckusick Addrp typeaddr;
9822832Smckusick Addrp retslot;
9922832Smckusick int cxslot	= -1;
10022832Smckusick int chslot	= -1;
10122832Smckusick int chlgslot	= -1;
10222832Smckusick int procclass	= CLUNKNOWN;
10322832Smckusick int nentry;
10422832Smckusick flag multitype;
10522832Smckusick ftnint procleng;
10622832Smckusick int lastlabno	= 10;
10722832Smckusick int lastvarno;
10822832Smckusick int lastargslot;
10922832Smckusick int argloc;
11022832Smckusick ftnint autoleng;
11122832Smckusick ftnint bssleng	= 0;
11222832Smckusick int retlabel;
11322832Smckusick int ret0label;
114*33255Sbostic ftnint lowbss = 0;
115*33255Sbostic ftnint highbss = 0;
11622832Smckusick int bsslabel;
11722832Smckusick flag anyinits = NO;
11822832Smckusick flag anylocals = NO;
11922832Smckusick 
12022832Smckusick int maxctl	= MAXCTL;
12122832Smckusick struct Ctlframe *ctls;
12222832Smckusick struct Ctlframe *ctlstack;
12322832Smckusick struct Ctlframe *lastctl;
12422832Smckusick 
12522832Smckusick Namep regnamep[MAXREGVAR];
12622832Smckusick int highregvar;
12722832Smckusick int nregvar;
12822832Smckusick 
12922832Smckusick int maxext	= MAXEXT;
13022832Smckusick struct Extsym *extsymtab;
13122832Smckusick struct Extsym *nextext;
13222832Smckusick struct Extsym *lastext;
13322832Smckusick 
13422832Smckusick int maxequiv	= MAXEQUIV;
13522832Smckusick struct Equivblock *eqvclass;
13622832Smckusick 
13722832Smckusick int maxhash	= MAXHASH;
13822832Smckusick struct Hashentry *hashtab;
13922832Smckusick struct Hashentry *lasthash;
14022832Smckusick 
14122832Smckusick int maxstno	= MAXSTNO;
14222832Smckusick struct Labelblock *labeltab;
14322832Smckusick struct Labelblock *labtabend;
14422832Smckusick struct Labelblock *highlabtab;
14522832Smckusick 
14622832Smckusick int maxdim	= MAXDIM;
14722832Smckusick struct Rplblock *rpllist	= NULL;
14822832Smckusick struct Chain *curdtp	= NULL;
14922832Smckusick flag toomanyinit;
15022832Smckusick ftnint curdtelt;
15122832Smckusick chainp templist	= NULL;
15222832Smckusick chainp argtemplist = CHNULL;
15322832Smckusick chainp activearglist = CHNULL;
15422832Smckusick chainp holdtemps	= NULL;
15522832Smckusick int dorange	= 0;
15622832Smckusick struct Entrypoint *entries	= NULL;
15722832Smckusick 
15822832Smckusick chainp chains	= NULL;
15922832Smckusick 
16022832Smckusick flag inioctl;
16122832Smckusick Addrp ioblkp;
16222832Smckusick int iostmt;
16322832Smckusick int nioctl;
16422832Smckusick int nequiv	= 0;
16522832Smckusick int eqvstart	= 0;
16622832Smckusick int nintnames	= 0;
16722832Smckusick 
16822832Smckusick #ifdef SDB
16922832Smckusick int dbglabel	= 0;
17022832Smckusick flag sdbflag	= NO;
17122832Smckusick #endif
17222832Smckusick 
17322832Smckusick struct Literal litpool[MAXLITERALS];
17422832Smckusick int nliterals;
17522832Smckusick 
17622832Smckusick int cdatafile;
17722832Smckusick int cchkfile;
17822832Smckusick int vdatafile;
17922832Smckusick int vchkfile;
18022832Smckusick 
18122832Smckusick char cdatafname[44] = "";
18222832Smckusick char cchkfname[44] = "";
18322832Smckusick char vdatafname[44] = "";
18422832Smckusick char vchkfname[44] = "";
18522832Smckusick 
18622832Smckusick long cdatahwm = 0;
18722832Smckusick long vdatahwm = 0;
18822832Smckusick 
18922832Smckusick ioblock *iodata = NULL;
19022832Smckusick 
19122832Smckusick 
19222832Smckusick 
19322832Smckusick fileinit()
19422832Smckusick {
19522832Smckusick int pid;
19622832Smckusick 
19722832Smckusick pid = getpid();
19822832Smckusick sprintf(cdatafname, "/tmp/fortcd.%d", pid);
19922832Smckusick sprintf(cchkfname, "/tmp/fortcc.%d", pid);
20022832Smckusick sprintf(vdatafname, "/tmp/fortvd.%d", pid);
20122832Smckusick sprintf(vchkfname, "/tmp/fortvc.%d", pid);
20222832Smckusick 
20322832Smckusick cdatafile = open(cdatafname, O_CREAT | O_RDWR, 0600);
20422832Smckusick if (cdatafile < 0)
20522832Smckusick   fatalstr("cannot open tmp file %s", cdatafname);
20622832Smckusick 
20722832Smckusick cchkfile = open(cchkfname, O_CREAT | O_RDWR, 0600);
20822832Smckusick if (cchkfile < 0)
20922832Smckusick   fatalstr("cannot open tmp file %s", cchkfname);
21022832Smckusick 
21122832Smckusick pruse(initfile, USEINIT);
21222832Smckusick 
21322832Smckusick procno = 0;
21422832Smckusick lwmno = 0;
21522832Smckusick lastlabno = 10;
21622832Smckusick lastvarno = 0;
21722832Smckusick nliterals = 0;
21822832Smckusick nerr = 0;
21922832Smckusick ndata = 0;
22022832Smckusick 
22122832Smckusick ctls = ALLOCN(maxctl, Ctlframe);
22222832Smckusick extsymtab = ALLOCN(maxext, Extsym);
22322832Smckusick eqvclass = ALLOCN(maxequiv, Equivblock);
22422832Smckusick hashtab = ALLOCN(maxhash, Hashentry);
22522832Smckusick labeltab = ALLOCN(maxstno, Labelblock);
22622832Smckusick 
22722832Smckusick ctlstack = ctls - 1;
22822832Smckusick lastctl = ctls + maxctl;
22922832Smckusick nextext = extsymtab;
23022832Smckusick lastext = extsymtab + maxext;
23122832Smckusick lasthash = hashtab + maxhash;
23222832Smckusick labtabend = labeltab + maxstno;
23322832Smckusick highlabtab = labeltab;
23422832Smckusick }
23522832Smckusick 
23622832Smckusick 
23722832Smckusick 
23822832Smckusick 
23922832Smckusick 
24022832Smckusick procinit()
24122832Smckusick {
24222832Smckusick register Namep p;
24322832Smckusick register struct Dimblock *q;
24422832Smckusick register struct Hashentry *hp;
24522832Smckusick register struct Labelblock *lp;
24622832Smckusick struct Chain *cp;
24722832Smckusick int i;
24822832Smckusick 
24922832Smckusick vdatafile = open(vdatafname, O_CREAT | O_RDWR, 0600);
25022832Smckusick if (vdatafile < 0)
25122832Smckusick   fatalstr("cannot open tmp file %s", vdatafname);
25222832Smckusick 
25322832Smckusick vchkfile = open(vchkfname, O_CREAT | O_RDWR, 0600);
25422832Smckusick if (vchkfile < 0)
25522832Smckusick   fatalstr("cannot open tmp file %s", vchkfname);
25622832Smckusick 
25722832Smckusick pruse(asmfile, USECONST);
25822832Smckusick #if FAMILY == PCC
25922832Smckusick 	p2pass(USETEXT);
26022832Smckusick #endif
26122832Smckusick parstate = OUTSIDE;
26222832Smckusick headerdone = NO;
26322832Smckusick blklevel = 1;
26422832Smckusick saveall = NO;
26522832Smckusick substars = NO;
26622832Smckusick nwarn = 0;
26722832Smckusick thislabel = NULL;
26822832Smckusick needkwd = 0;
26922832Smckusick 
27022832Smckusick ++procno;
27122832Smckusick proctype = TYUNKNOWN;
27222832Smckusick procname = "MAIN     ";
27322832Smckusick procclass = CLUNKNOWN;
27422832Smckusick nentry = 0;
27522832Smckusick multitype = NO;
27622832Smckusick typeaddr = NULL;
27722832Smckusick retslot = NULL;
27822832Smckusick cxslot = -1;
27922832Smckusick chslot = -1;
28022832Smckusick chlgslot = -1;
28122832Smckusick procleng = 0;
28222832Smckusick blklevel = 1;
28322832Smckusick lastargslot = 0;
28422832Smckusick #if TARGET==PDP11
28522832Smckusick 	autoleng = 6;
28622832Smckusick #else
28722832Smckusick 	autoleng = 0;
28822832Smckusick #endif
28922832Smckusick 
29022832Smckusick for(lp = labeltab ; lp < labtabend ; ++lp)
29122832Smckusick 	lp->stateno = 0;
29222832Smckusick 
29322832Smckusick for(hp = hashtab ; hp < lasthash ; ++hp)
29422832Smckusick 	if(p = hp->varp)
29522832Smckusick 		{
29622832Smckusick 		frexpr(p->vleng);
29722832Smckusick 		if(q = p->vdim)
29822832Smckusick 			{
29922832Smckusick 			for(i = 0 ; i < q->ndim ; ++i)
30022832Smckusick 				{
30122832Smckusick 				frexpr(q->dims[i].dimsize);
30222832Smckusick 				frexpr(q->dims[i].dimexpr);
30322832Smckusick 				}
30422832Smckusick 			frexpr(q->nelt);
30522832Smckusick 			frexpr(q->baseoffset);
30622832Smckusick 			frexpr(q->basexpr);
30722832Smckusick 			free( (charptr) q);
30822832Smckusick 			}
30922832Smckusick 		if(p->vclass == CLNAMELIST)
31022832Smckusick 			frchain( &(p->varxptr.namelist) );
31122832Smckusick 		free( (charptr) p);
31222832Smckusick 		hp->varp = NULL;
31322832Smckusick 		}
31422832Smckusick nintnames = 0;
31522832Smckusick highlabtab = labeltab;
31622832Smckusick 
31722832Smckusick ctlstack = ctls - 1;
31822832Smckusick for(cp = templist ; cp ; cp = cp->nextp)
31922832Smckusick 	free( (charptr) (cp->datap) );
32022832Smckusick frchain(&templist);
32122832Smckusick for (cp = argtemplist; cp; cp = cp->nextp)
32222832Smckusick   free((char *) (cp->datap));
32322832Smckusick frchain(&argtemplist);
32422832Smckusick holdtemps = NULL;
32522832Smckusick dorange = 0;
32622832Smckusick nregvar = 0;
32722832Smckusick highregvar = 0;
32822832Smckusick entries = NULL;
32922832Smckusick rpllist = NULL;
33022832Smckusick inioctl = NO;
33122832Smckusick ioblkp = NULL;
33222832Smckusick eqvstart += nequiv;
33322832Smckusick nequiv = 0;
33422832Smckusick 
33522832Smckusick for(i = 0 ; i<NTYPES ; ++i)
33622832Smckusick 	rtvlabel[i] = 0;
33722832Smckusick fudgelabel = 0;
33822832Smckusick 
33922832Smckusick if(undeftype)
34022832Smckusick 	setimpl(TYUNKNOWN, (ftnint) 0, 'a', 'z');
34122832Smckusick else
34222832Smckusick 	{
34324479Sdonn 	setimpl(dblflag ? TYDREAL : TYREAL, (ftnint) 0, 'a', 'z');
34422832Smckusick 	setimpl(tyint,  (ftnint) 0, 'i', 'n');
34522832Smckusick 	}
34622832Smckusick setimpl(-STGBSS, (ftnint) 0, 'a', 'z');	/* set class */
34722832Smckusick setlog();
34822832Smckusick setopt();
34922832Smckusick 
35022832Smckusick bsslabel = ++lastvarno;
35122832Smckusick anylocals = NO;
35222832Smckusick anyinits = NO;
35322832Smckusick }
35422832Smckusick 
35522832Smckusick 
35622832Smckusick 
35722832Smckusick 
35822832Smckusick setimpl(type, length, c1, c2)
35922832Smckusick int type;
36022832Smckusick ftnint length;
36122832Smckusick int c1, c2;
36222832Smckusick {
36322832Smckusick int i;
36422832Smckusick char buff[100];
36522832Smckusick 
36622832Smckusick if(c1==0 || c2==0)
36722832Smckusick 	return;
36822832Smckusick 
36922832Smckusick if(c1 > c2)
37022832Smckusick 	{
37122832Smckusick 	sprintf(buff, "characters out of order in implicit:%c-%c", c1, c2);
37222832Smckusick 	err(buff);
37322832Smckusick 	}
37422832Smckusick else
37522832Smckusick 	if(type < 0)
37622832Smckusick 		for(i = c1 ; i<=c2 ; ++i)
37722832Smckusick 			implstg[i-'a'] = - type;
37822832Smckusick 	else
37922832Smckusick 		{
38022832Smckusick 		type = lengtype(type, (int) length);
38122832Smckusick 		if(type != TYCHAR)
38222832Smckusick 			length = 0;
38322832Smckusick 		for(i = c1 ; i<=c2 ; ++i)
38422832Smckusick 			{
38522832Smckusick 			impltype[i-'a'] = type;
38622832Smckusick 			implleng[i-'a'] = length;
38722832Smckusick 			}
38822832Smckusick 		}
38922832Smckusick }
390