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