1*43214Sbostic /* 2*43214Sbostic * Copyright (c) 1980 Regents of the University of California. 3*43214Sbostic * All rights reserved. The Berkeley software License Agreement 4*43214Sbostic * specifies the terms and conditions for redistribution. 5*43214Sbostic */ 6*43214Sbostic 7*43214Sbostic #ifndef lint 8*43214Sbostic char copyright[] = 9*43214Sbostic "@(#) Copyright (c) 1980 Regents of the University of California.\n\ 10*43214Sbostic All rights reserved.\n"; 11*43214Sbostic #endif not lint 12*43214Sbostic 13*43214Sbostic #ifndef lint 14*43214Sbostic static char sccsid[] = "@(#)main.c 5.1 (Berkeley) 6/7/85"; 15*43214Sbostic #endif not lint 16*43214Sbostic 17*43214Sbostic /* 18*43214Sbostic * main.c 19*43214Sbostic * 20*43214Sbostic * Main routine for the f77 compiler, pass 1, 4.2 BSD. 21*43214Sbostic * 22*43214Sbostic * University of Utah CS Dept modification history: 23*43214Sbostic * 24*43214Sbostic * $Log: main.c,v $ 25*43214Sbostic * Revision 3.2 85/01/14 04:21:31 donn 26*43214Sbostic * Added changes to implement Jerry's '-q' option. 27*43214Sbostic * 28*43214Sbostic * Revision 3.1 84/10/29 05:47:03 donn 29*43214Sbostic * Added Jerry Berkman's change to line buffer stderr. 30*43214Sbostic * 31*43214Sbostic */ 32*43214Sbostic 33*43214Sbostic char *xxxvers[] = "\n@(#) FORTRAN 77 PASS 1, VERSION 2.10, 16 AUGUST 1980\n"; 34*43214Sbostic 35*43214Sbostic #include "defs.h" 36*43214Sbostic #include <signal.h> 37*43214Sbostic 38*43214Sbostic #ifdef SDB 39*43214Sbostic # include <a.out.h> 40*43214Sbostic # ifndef N_SO 41*43214Sbostic # include <stab.h> 42*43214Sbostic # endif 43*43214Sbostic #endif 44*43214Sbostic 45*43214Sbostic 46*43214Sbostic LOCAL char *textname = ""; 47*43214Sbostic LOCAL char *asmname = ""; 48*43214Sbostic LOCAL char *initname = ""; 49*43214Sbostic 50*43214Sbostic 51*43214Sbostic extern intexit(); 52*43214Sbostic 53*43214Sbostic flag namesflag = YES; 54*43214Sbostic 55*43214Sbostic 56*43214Sbostic 57*43214Sbostic main(argc, argv) 58*43214Sbostic int argc; 59*43214Sbostic char **argv; 60*43214Sbostic { 61*43214Sbostic char *s; 62*43214Sbostic int k, retcode, *ip; 63*43214Sbostic FILEP opf(); 64*43214Sbostic int flovflo(); 65*43214Sbostic 66*43214Sbostic #define DONE(c) { retcode = c; goto finis; } 67*43214Sbostic 68*43214Sbostic signal(SIGFPE, flovflo); /* catch overflows */ 69*43214Sbostic signal(SIGINT, intexit); 70*43214Sbostic 71*43214Sbostic #if HERE == PDP11 72*43214Sbostic ldfps(01200); /* trap on overflow */ 73*43214Sbostic #endif 74*43214Sbostic 75*43214Sbostic 76*43214Sbostic setlinebuf(diagfile); 77*43214Sbostic 78*43214Sbostic --argc; 79*43214Sbostic ++argv; 80*43214Sbostic 81*43214Sbostic while(argc>0 && argv[0][0]=='-') 82*43214Sbostic { 83*43214Sbostic for(s = argv[0]+1 ; *s ; ++s) switch(*s) 84*43214Sbostic { 85*43214Sbostic case 'w': 86*43214Sbostic if(s[1]=='6' && s[2]=='6') 87*43214Sbostic { 88*43214Sbostic ftn66flag = YES; 89*43214Sbostic s += 2; 90*43214Sbostic } 91*43214Sbostic else 92*43214Sbostic nowarnflag = YES; 93*43214Sbostic break; 94*43214Sbostic 95*43214Sbostic case 'U': 96*43214Sbostic shiftcase = NO; 97*43214Sbostic break; 98*43214Sbostic 99*43214Sbostic case 'u': 100*43214Sbostic undeftype = YES; 101*43214Sbostic break; 102*43214Sbostic 103*43214Sbostic case 'O': 104*43214Sbostic optimflag = YES; 105*43214Sbostic break; 106*43214Sbostic 107*43214Sbostic case 'd': 108*43214Sbostic debugflag[0] = YES; 109*43214Sbostic 110*43214Sbostic while (*s == 'd' || *s == ',') 111*43214Sbostic { 112*43214Sbostic k = 0; 113*43214Sbostic while( isdigit(*++s) ) 114*43214Sbostic k = 10*k + (*s - '0'); 115*43214Sbostic if(k < 0 || k >= MAXDEBUGFLAG) 116*43214Sbostic fatali("bad debug number %d",k); 117*43214Sbostic debugflag[k] = YES; 118*43214Sbostic } 119*43214Sbostic break; 120*43214Sbostic 121*43214Sbostic case 'p': 122*43214Sbostic profileflag = YES; 123*43214Sbostic break; 124*43214Sbostic 125*43214Sbostic case 'C': 126*43214Sbostic checksubs = YES; 127*43214Sbostic break; 128*43214Sbostic 129*43214Sbostic case '6': 130*43214Sbostic no66flag = YES; 131*43214Sbostic noextflag = YES; 132*43214Sbostic break; 133*43214Sbostic 134*43214Sbostic case '1': 135*43214Sbostic onetripflag = YES; 136*43214Sbostic break; 137*43214Sbostic 138*43214Sbostic #ifdef SDB 139*43214Sbostic case 'g': 140*43214Sbostic sdbflag = YES; 141*43214Sbostic break; 142*43214Sbostic #endif 143*43214Sbostic 144*43214Sbostic case 'q': 145*43214Sbostic namesflag = NO; 146*43214Sbostic break; 147*43214Sbostic 148*43214Sbostic case 'N': 149*43214Sbostic switch(*++s) 150*43214Sbostic { 151*43214Sbostic case 'q': 152*43214Sbostic ip = &maxequiv; goto getnum; 153*43214Sbostic case 'x': 154*43214Sbostic ip = &maxext; goto getnum; 155*43214Sbostic case 's': 156*43214Sbostic ip = &maxstno; goto getnum; 157*43214Sbostic case 'c': 158*43214Sbostic ip = &maxctl; goto getnum; 159*43214Sbostic case 'n': 160*43214Sbostic ip = &maxhash; goto getnum; 161*43214Sbostic 162*43214Sbostic default: 163*43214Sbostic fatali("invalid flag -N%c", *s); 164*43214Sbostic } 165*43214Sbostic getnum: 166*43214Sbostic k = 0; 167*43214Sbostic while( isdigit(*++s) ) 168*43214Sbostic k = 10*k + (*s - '0'); 169*43214Sbostic if(k <= 0) 170*43214Sbostic fatal("Table size too small"); 171*43214Sbostic *ip = k; 172*43214Sbostic break; 173*43214Sbostic 174*43214Sbostic case 'i': 175*43214Sbostic if(*++s == '2') 176*43214Sbostic tyint = TYSHORT; 177*43214Sbostic else if(*s == '4') 178*43214Sbostic { 179*43214Sbostic shortsubs = NO; 180*43214Sbostic tyint = TYLONG; 181*43214Sbostic } 182*43214Sbostic else if(*s == 's') 183*43214Sbostic shortsubs = YES; 184*43214Sbostic else 185*43214Sbostic fatali("invalid flag -i%c\n", *s); 186*43214Sbostic tylogical = tyint; 187*43214Sbostic break; 188*43214Sbostic 189*43214Sbostic default: 190*43214Sbostic fatali("invalid flag %c\n", *s); 191*43214Sbostic } 192*43214Sbostic --argc; 193*43214Sbostic ++argv; 194*43214Sbostic } 195*43214Sbostic 196*43214Sbostic if(argc != 4) 197*43214Sbostic fatali("arg count %d", argc); 198*43214Sbostic textname = argv[3]; 199*43214Sbostic initname = argv[2]; 200*43214Sbostic asmname = argv[1]; 201*43214Sbostic asmfile = opf(argv[1]); 202*43214Sbostic initfile = opf(argv[2]); 203*43214Sbostic textfile = opf(argv[3]); 204*43214Sbostic 205*43214Sbostic initkey(); 206*43214Sbostic if(inilex( copys(argv[0]) )) 207*43214Sbostic DONE(1); 208*43214Sbostic if(namesflag == YES) 209*43214Sbostic fprintf(diagfile, "%s:\n", argv[0]); 210*43214Sbostic 211*43214Sbostic #ifdef SDB 212*43214Sbostic filenamestab(argv[0]); 213*43214Sbostic #endif 214*43214Sbostic 215*43214Sbostic fileinit(); 216*43214Sbostic procinit(); 217*43214Sbostic if(k = yyparse()) 218*43214Sbostic { 219*43214Sbostic fprintf(diagfile, "Bad parse, return code %d\n", k); 220*43214Sbostic DONE(1); 221*43214Sbostic } 222*43214Sbostic if(nerr > 0) 223*43214Sbostic DONE(1); 224*43214Sbostic if(parstate != OUTSIDE) 225*43214Sbostic { 226*43214Sbostic warn("missing END statement"); 227*43214Sbostic endproc(); 228*43214Sbostic } 229*43214Sbostic doext(); 230*43214Sbostic preven(ALIDOUBLE); 231*43214Sbostic prtail(); 232*43214Sbostic #if FAMILY==PCC 233*43214Sbostic puteof(); 234*43214Sbostic #endif 235*43214Sbostic 236*43214Sbostic if(nerr > 0) 237*43214Sbostic DONE(1); 238*43214Sbostic DONE(0); 239*43214Sbostic 240*43214Sbostic 241*43214Sbostic finis: 242*43214Sbostic done(retcode); 243*43214Sbostic } 244*43214Sbostic 245*43214Sbostic 246*43214Sbostic 247*43214Sbostic done(k) 248*43214Sbostic int k; 249*43214Sbostic { 250*43214Sbostic static char *ioerror = "i/o error on intermediate file %s\n"; 251*43214Sbostic 252*43214Sbostic if (textfile != NULL && textfile != stdout) 253*43214Sbostic { 254*43214Sbostic if (ferror(textfile)) 255*43214Sbostic { 256*43214Sbostic fprintf(diagfile, ioerror, textname); 257*43214Sbostic k = 3; 258*43214Sbostic } 259*43214Sbostic fclose(textfile); 260*43214Sbostic } 261*43214Sbostic 262*43214Sbostic if (asmfile != NULL && asmfile != stdout) 263*43214Sbostic { 264*43214Sbostic if (ferror(asmfile)) 265*43214Sbostic { 266*43214Sbostic fprintf(diagfile, ioerror, asmname); 267*43214Sbostic k = 3; 268*43214Sbostic } 269*43214Sbostic fclose(asmfile); 270*43214Sbostic } 271*43214Sbostic 272*43214Sbostic if (initfile != NULL && initfile != stdout) 273*43214Sbostic { 274*43214Sbostic if (ferror(initfile)) 275*43214Sbostic { 276*43214Sbostic fprintf(diagfile, ioerror, initname); 277*43214Sbostic k = 3; 278*43214Sbostic } 279*43214Sbostic fclose(initfile); 280*43214Sbostic } 281*43214Sbostic 282*43214Sbostic rmtmpfiles(); 283*43214Sbostic 284*43214Sbostic exit(k); 285*43214Sbostic } 286*43214Sbostic 287*43214Sbostic 288*43214Sbostic LOCAL FILEP opf(fn) 289*43214Sbostic char *fn; 290*43214Sbostic { 291*43214Sbostic FILEP fp; 292*43214Sbostic if( fp = fopen(fn, "w") ) 293*43214Sbostic return(fp); 294*43214Sbostic 295*43214Sbostic fatalstr("cannot open intermediate file %s", fn); 296*43214Sbostic /* NOTREACHED */ 297*43214Sbostic } 298*43214Sbostic 299*43214Sbostic 300*43214Sbostic 301*43214Sbostic clf(p) 302*43214Sbostic FILEP *p; 303*43214Sbostic { 304*43214Sbostic if(p!=NULL && *p!=NULL && *p!=stdout) 305*43214Sbostic { 306*43214Sbostic if(ferror(*p)) 307*43214Sbostic fatal("writing error"); 308*43214Sbostic fclose(*p); 309*43214Sbostic } 310*43214Sbostic *p = NULL; 311*43214Sbostic } 312*43214Sbostic 313*43214Sbostic 314*43214Sbostic 315*43214Sbostic 316*43214Sbostic flovflo() 317*43214Sbostic { 318*43214Sbostic err("floating exception during constant evaluation"); 319*43214Sbostic #if HERE == VAX 320*43214Sbostic fatal("vax cannot recover from floating exception"); 321*43214Sbostic rmtmpfiles(); 322*43214Sbostic /* vax returns a reserved operand that generates 323*43214Sbostic an illegal operand fault on next instruction, 324*43214Sbostic which if ignored causes an infinite loop. 325*43214Sbostic */ 326*43214Sbostic #endif 327*43214Sbostic signal(SIGFPE, flovflo); 328*43214Sbostic } 329*43214Sbostic 330*43214Sbostic 331*43214Sbostic 332*43214Sbostic rmtmpfiles() 333*43214Sbostic { 334*43214Sbostic close(vdatafile); 335*43214Sbostic unlink(vdatafname); 336*43214Sbostic close(vchkfile); 337*43214Sbostic unlink(vchkfname); 338*43214Sbostic close(cdatafile); 339*43214Sbostic unlink(cdatafname); 340*43214Sbostic close(cchkfile); 341*43214Sbostic unlink(cchkfname); 342*43214Sbostic } 343*43214Sbostic 344*43214Sbostic 345*43214Sbostic 346*43214Sbostic intexit() 347*43214Sbostic { 348*43214Sbostic done(1); 349*43214Sbostic } 350