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