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