15797Srrh /* 25797Srrh * Copyright (c) 1982 Regents of the University of California 35797Srrh */ 45797Srrh #ifndef lint 5*13807Srrh static char sccsid[] = "@(#)asscan1.c 4.6 07/06/83"; 65797Srrh #endif not lint 75797Srrh 85797Srrh #include "asscanl.h" 95797Srrh 1013515Srrh inittokfile() 115797Srrh { 125797Srrh if (passno == 1){ 135797Srrh if (useVM){ 145797Srrh bufstart = &tokbuf[0]; 155797Srrh buftail = &tokbuf[1]; 165797Srrh bufstart->tok_next = buftail; 175797Srrh buftail->tok_next = 0; 185797Srrh } 195797Srrh tokbuf[0].tok_count = -1; 205797Srrh tokbuf[1].tok_count = -1; 215797Srrh } 225797Srrh tok_temp = 0; 235797Srrh tok_free = 0; 245797Srrh bufno = 0; 255797Srrh emptybuf = &tokbuf[bufno]; 265797Srrh tokptr = 0; 275797Srrh tokub = 0; 285797Srrh } 295797Srrh 3013515Srrh closetokfile() 315797Srrh { 325797Srrh if (passno == 1){ 335797Srrh if (useVM){ 345797Srrh emptybuf->toks[emptybuf->tok_count++] = PARSEEOF; 355797Srrh } else { 365797Srrh /* 375797Srrh * Clean up the buffers that haven't been 385797Srrh * written out yet 395797Srrh */ 405797Srrh if (tokbuf[bufno ^ 1].tok_count >= 0){ 4113515Srrh if (writeTEST((char *)&tokbuf[bufno ^ 1], sizeof *emptybuf, 1, tokfile)){ 425797Srrh badwrite: 435797Srrh yyerror("Unexpected end of file writing the interpass tmp file"); 445797Srrh exit(2); 455797Srrh } 465797Srrh } 475797Srrh /* 485797Srrh * Ensure that we will read an End of file, 495797Srrh * if there are more than one file names 505797Srrh * in the argument list 515797Srrh */ 525797Srrh tokbuf[bufno].toks[tokbuf[bufno].tok_count++] = PARSEEOF; 5313515Srrh if (writeTEST((char *)&tokbuf[bufno], sizeof *emptybuf, 1, tokfile)) 545797Srrh goto badwrite; 555797Srrh } 565797Srrh } /*end of being pass 1*/ 575797Srrh } 585797Srrh 595797Srrh inttoktype yylex() 605797Srrh { 615797Srrh register ptrall bufptr; 625797Srrh register inttoktype val; 635797Srrh register struct exp *locxp; 645797Srrh /* 655797Srrh * No local variables to be allocated; this saves 665797Srrh * one piddling instruction.. 675797Srrh */ 685797Srrh static int Lastjxxx; 695797Srrh 705797Srrh bufptr = tokptr; /*copy in the global value*/ 715797Srrh top: 725797Srrh if (bufptr < tokub){ 735797Srrh gtoken(val, bufptr); 745797Srrh switch(yylval = val){ 755797Srrh case PARSEEOF: 765797Srrh yylval = val = PARSEEOF; 775797Srrh break; 785797Srrh case BFINT: 795797Srrh case INT: 805797Srrh if (xp >= &explist[NEXP]) 815797Srrh yyerror("Too many expressions; try simplyfing"); 825797Srrh else 835797Srrh locxp = xp++; 845797Srrh locxp->e_number = Znumber; 855797Srrh locxp->e_number.num_tag = TYPL; 865797Srrh glong(locxp->e_xvalue, bufptr); 875797Srrh makevalue: 885797Srrh locxp->e_xtype = XABS; 895797Srrh locxp->e_xloc = 0; 905797Srrh locxp->e_xname = NULL; 915797Srrh yylval = (int)locxp; 925797Srrh break; 935797Srrh case BIGNUM: 945797Srrh if (xp >= &explist[NEXP]) 955797Srrh yyerror("Too many expressions; try simplyfing"); 965797Srrh else 975797Srrh locxp = xp++; 985797Srrh gnumber(locxp->e_number, bufptr); 995797Srrh goto makevalue; 1005797Srrh case NAME: 1015797Srrh gptr(yylval, bufptr); 1025797Srrh lastnam = (struct symtab *)yylval; 1035797Srrh break; 1045797Srrh case SIZESPEC: 1055797Srrh case REG: 1065797Srrh gchar(yylval, bufptr); 1075797Srrh break; 1085797Srrh case INSTn: 1095797Srrh case INST0: 1105797Srrh gopcode(yyopcode, bufptr); 1115797Srrh break; 1125797Srrh case IJXXX: 1135797Srrh gopcode(yyopcode, bufptr); 1145797Srrh /* We can't cast Lastjxxx into (int *) here.. */ 1155797Srrh gptr(Lastjxxx, bufptr); 1165797Srrh lastjxxx = (struct symtab *)Lastjxxx; 1175797Srrh break; 1185797Srrh case ILINESKIP: 1195797Srrh gint(yylval, bufptr); 1205797Srrh lineno += yylval; 1215797Srrh goto top; 1225797Srrh case SKIP: 1235797Srrh eatskiplg(bufptr); 1245797Srrh goto top; 1255797Srrh case VOID: 1265797Srrh goto top; 1275797Srrh case STRING: 1285797Srrh case ISTAB: 1295797Srrh case ISTABSTR: 1305797Srrh case ISTABNONE: 1315797Srrh case ISTABDOT: 1325797Srrh case IALIGN: 1335797Srrh gptr(yylval, bufptr); 1345797Srrh break; 1355797Srrh } 1365797Srrh #ifdef DEBUG 1375797Srrh if (toktrace){ 1385797Srrh char *tok_to_name(); 1395797Srrh printf("P: %d T#: %4d, %s ", 1405797Srrh passno, bufptr - firsttoken, tok_to_name(val)); 1415797Srrh switch(val){ 1425797Srrh case INT: printf("val %d", 1435797Srrh ((struct exp *)yylval)->e_xvalue); 1445797Srrh break; 1455797Srrh case BFINT: printf("val %d", 1465797Srrh ((struct exp *)yylval)->e_xvalue); 1475797Srrh break; 1485797Srrh case BIGNUM: bignumprint(((struct exp*)yylval)->e_number); 1495797Srrh break; 1505797Srrh case NAME: printf("\"%.8s\"", 15113515Srrh FETCHNAME((struct symtab *)yylval)); 1525797Srrh break; 1535797Srrh case REG: printf(" r%d", 1545797Srrh yylval); 1555797Srrh break; 1565797Srrh case IJXXX: 1575797Srrh case INST0: 1585797Srrh case INSTn: if (ITABCHECK(yyopcode)) 15913515Srrh printf("%.8s", 16013515Srrh FETCHNAME(ITABFETCH(yyopcode))); 1615797Srrh else 1625797Srrh printf("IJXXX or INST0 or INSTn can't get into the itab\n"); 1635797Srrh break; 164*13807Srrh case STRING: 165*13807Srrh printf("length %d, seekoffset %d, place 0%o ", 166*13807Srrh ((struct strdesc *)yylval)->sd_strlen, 167*13807Srrh ((struct strdesc *)yylval)->sd_stroff, 168*13807Srrh ((struct strdesc *)yylval)->sd_place 169*13807Srrh ); 170*13807Srrh if (((struct strdesc *)yylval)->sd_place & STR_CORE) 17113448Srrh printf("value\"%*s\"", 172*13807Srrh ((struct strdesc *)yylval)->sd_strlen, 173*13807Srrh ((struct strdesc *)yylval)->sd_string); 174*13807Srrh break; 1755797Srrh } /*end of the debug switch*/ 1765797Srrh printf("\n"); 1775797Srrh } 1785797Srrh #endif DEBUG 1795797Srrh 1805797Srrh } else { /* start a new buffer */ 1815797Srrh if (useVM){ 1825797Srrh if (passno == 2){ 1835797Srrh tok_temp = emptybuf->tok_next; 1845797Srrh emptybuf->tok_next = tok_free; 1855797Srrh tok_free = emptybuf; 1865797Srrh emptybuf = tok_temp; 1875797Srrh } else { 1885797Srrh emptybuf = emptybuf->tok_next; 1895797Srrh } 1905797Srrh bufno += 1; 1915797Srrh if (emptybuf == 0){ 1925797Srrh struct tokbufdesc *newdallop; 1935797Srrh int i; 1945797Srrh if (passno == 2) 1955797Srrh goto badread; 1965797Srrh emptybuf = newdallop = (struct tokbufdesc *) 1975797Srrh Calloc(TOKDALLOP, sizeof (struct tokbufdesc)); 1985797Srrh for (i=0; i < TOKDALLOP; i++){ 1995797Srrh buftail->tok_next = newdallop; 2005797Srrh buftail = newdallop; 2015797Srrh newdallop += 1; 2025797Srrh } 2035797Srrh buftail->tok_next = 0; 2045797Srrh } /*end of need to get more buffers*/ 2055797Srrh (bytetoktype *)bufptr = &(emptybuf->toks[0]); 2065797Srrh if (passno == 1) 2075797Srrh scan_dot_s(emptybuf); 2085797Srrh } else { /*don't use VM*/ 2095797Srrh bufno ^= 1; 2105797Srrh emptybuf = &tokbuf[bufno]; 2115797Srrh ((bytetoktype *)bufptr) = &(emptybuf->toks[0]); 2125797Srrh if (passno == 1){ 2135797Srrh /* 2145797Srrh * First check if there are things to write 2155797Srrh * out at all 2165797Srrh */ 2175797Srrh if (emptybuf->tok_count >= 0){ 21813515Srrh if (writeTEST((char *)emptybuf, sizeof *emptybuf, 1, tokfile)){ 2195797Srrh yyerror("Unexpected end of file writing the interpass tmp file"); 2205797Srrh exit(2); 2215797Srrh } 2225797Srrh } 2235797Srrh scan_dot_s(emptybuf); 2245797Srrh } else { /*pass 2*/ 22513515Srrh if (readTEST((char *)emptybuf, sizeof *emptybuf, 1, tokfile)){ 2265797Srrh badread: 2275797Srrh yyerror("Unexpected end of file while reading the interpass tmp file"); 2285797Srrh exit(1); 2295797Srrh } 2305797Srrh } 2315797Srrh } /*end of using a real live file*/ 2325797Srrh (char *)tokub = (char *)bufptr + emptybuf->tok_count; 2335797Srrh #ifdef DEBUG 2345797Srrh firsttoken = bufptr; 2355797Srrh if (debug) 2365797Srrh printf("created buffernumber %d with %d tokens\n", 2375797Srrh bufno, emptybuf->tok_count); 2385797Srrh #endif DEBUG 2395797Srrh goto top; 2405797Srrh } /*end of reading/creating a new buffer*/ 2415797Srrh tokptr = bufptr; /*copy back the global value*/ 2425797Srrh return(val); 2435797Srrh } /*end of yylex*/ 2445797Srrh 2455797Srrh 2465797Srrh buildskip(from, to) 2475797Srrh register ptrall from, to; 2485797Srrh { 2495797Srrh int diff; 2505797Srrh register struct tokbufdesc *middlebuf; 2515797Srrh /* 2525797Srrh * check if from and to are in the same buffer 2535797Srrh * from and to DIFFER BY AT MOST 1 buffer and to is 2545797Srrh * always ahead of from, with to being in the buffer emptybuf 2555797Srrh * points to. 2565797Srrh * The hard part here is accounting for the case where the 2575797Srrh * skip is to cross a buffer boundary; we must construct 2585797Srrh * two skips. 2595797Srrh * 2605797Srrh * Figure out where the buffer boundary between from and to is 2615797Srrh * It's easy in VM, as buffers increase to high memory, but 2625797Srrh * w/o VM, we alternate between two buffers, and want 2635797Srrh * to look at the exact middle of the contiguous buffer region. 2645797Srrh */ 2655797Srrh middlebuf = useVM ? emptybuf : &tokbuf[1]; 2665797Srrh if ( ( (bytetoktype *)from > (bytetoktype *)middlebuf) 2675797Srrh ^ ( (bytetoktype *)to > (bytetoktype *)middlebuf) 2685797Srrh ){ /*split across a buffer boundary*/ 2695797Srrh ptoken(from, SKIP); 2705797Srrh /* 2715797Srrh * Set the skip so it lands someplace beyond 2725797Srrh * the end of this buffer. 2735797Srrh * When we pull this skip out in the second pass, 2745797Srrh * we will temporarily move the current pointer 2755797Srrh * out beyond the end of the buffer, but immediately 2765797Srrh * do a compare and fail the compare, and then reset 2775797Srrh * all the pointers correctly to point into the next buffer. 2785797Srrh */ 2795797Srrh bskiplg(from, TOKBUFLG + 1); 2805797Srrh /* 2815797Srrh * Now, force from to be in the same buffer as to 2825797Srrh */ 2835797Srrh (bytetoktype *)from = (bytetoktype *)&(emptybuf->toks[0]); 2845797Srrh } 2855797Srrh /* 2865797Srrh * Now, to and from are in the same buffer 2875797Srrh */ 2885797Srrh if (from > to) 2895797Srrh yyerror("Internal error: bad skip construction"); 2905797Srrh else { 2915797Srrh if ( (diff = (bytetoktype *)to - (bytetoktype *)from) >= 2925797Srrh (sizeof(bytetoktype) + sizeof(lgtype) + 1)) { 2935797Srrh ptoken(from, SKIP); 2945797Srrh bskipfromto(from, to); 2955797Srrh } else { 2965797Srrh for ( ; diff > 0; --diff) 2975797Srrh ptoken(from, VOID); 2985797Srrh } 2995797Srrh } 3005797Srrh } 3015797Srrh 3025797Srrh movestr(to, from, lg) 30313448Srrh char *to; /* 4(ap) */ 30413448Srrh char *from; /* 8(ap) */ 30513448Srrh int lg; /* 12(ap) */ 3065797Srrh { 30713448Srrh if (lg <= 0) 30813448Srrh return; 30913448Srrh ; 31013448Srrh asm("movc3 12(ap),*8(ap),*4(ap)"); 31113448Srrh ; 3125797Srrh } 3135797Srrh 3145797Srrh new_dot_s(namep) 3155797Srrh char *namep; 3165797Srrh { 3175797Srrh newfflag = 1; 3185797Srrh newfname = namep; 3195797Srrh dotsname = namep; 3205797Srrh lineno = 1; 3215797Srrh scanlineno = 1; 3225797Srrh } 32313448Srrh 32413448Srrh min(a, b) 32513448Srrh { 32613448Srrh return(a < b ? a : b); 32713448Srrh } 328