# 2.11BSD#431 - /usr/src/lib/mip/common.c

##### Functions

    caloff            X
    cerror            X
    errprep           X
    fwalk             X
    mkdope            X
    talloc            X
    tcheck            X
    tfree             X
    tfree1            X
    tinit             X
    tprint            X
    tstr              X
    uerror            X
    walkf             X
    werror            X

##### Variables

    Wflag             X
    curtstr           X
    dope              X
    indope            X
    itstrbuf          X
    lastfree          X
    nerrors           X
    opst              X
    tstrbuf           X
    tstrused          X

##### Macros

    NR                X
    NTSTRBUF          X
    POP               X
    PUSH              X
    TNEXT             X
    TSTRSZ            X

##### struct's

    dopest            X

       1: /*	common.c	4.2.1	95/01/17	*/
       2:
       3: static  char    *StringFile = STRINGFILE; /* From Makefile -DSTRINGFILE= ... */
       4:
       5: #ifdef PASS1COMMON
       6: #include "pass1.h"
       7: #else
       8: #ifdef PASS2COMMON
       9: #include "pass2.h"
      10: #endif
      11: #endif
      12: #include <sys/file.h>
      13:
      14: #ifdef FORT
      15: #undef BUFSTDERR
      16: #endif
      17: #ifndef ONEPASS
      18: #undef BUFSTDERR
      19: #endif
      20:
      21: int nerrors = 0;  /* number of errors */
      22:
      23: extern OFFSZ offsz;
      24:
      25: /*
      26:  * this strangeness is due to offsets being measured in terms of bits
      27:  * rather than bytes.  normally "i=16" and "off=0100000" are returned,
      28:  * but this is not enough to measure structures/arrays greater than
      29:  * 32k bits (4kb).
      30: */
      31:
      32: OFFSZ caloff(){
      33:     register i;
      34:     OFFSZ temp;
      35:     OFFSZ off;
      36: #ifndef pdp11
      37:     temp = 1;
      38:     i = 0;
      39:     do {
      40:         temp <<= 1;
      41:         ++i;
      42:         } while( temp != 0 );
      43:     off = 1 << (i-1);
      44: #else
      45:     off = 02000000L;        /* enough for 64kb */
      46: #endif
      47:     return (off);
      48:     }
      49:
      50: NODE *lastfree;  /* pointer to last free node; (for allocator) */
      51:
      52:     /* VARARGS1 */
      53: uerror(s, a )
      54:     unsigned short s;
      55:     void *a;
      56:     { /* nonfatal error message */
      57:     char    msg[256];
      58:
      59:     /* the routine 'where' is different for pass 1 and pass 2;
      60: 	/*  it tells where the error took place */
      61:
      62:     ++nerrors;
      63:     where('u');
      64:     errprep(s, msg);
      65:     fprintf(stderr, msg, a );
      66:     fprintf(stderr, "\n" );
      67: #ifdef BUFSTDERR
      68:     fflush(stderr);
      69: #endif
      70:     if (nerrors > 30) cerror("too many errors");
      71:     }
      72:
      73:     /* VARARGS1 */
      74: cerror(s, a, b, c )
      75:     unsigned short s;   /* stringfile offset */
      76:     void *a, *b, *c;
      77:     { /* compiler error: die */
      78:     char    msg[256];
      79:
      80:     where('c');
      81:     errprep(s, msg);
      82:     fprintf(stderr, "compiler error: " );
      83:     fprintf(stderr, msg, a, b, c );
      84:     fprintf(stderr, "\n" );
      85: /* give the compiler the benefit of the doubt */
      86:     if (nerrors && nerrors <= 30)
      87:        fprintf(stderr,"cannot recover from earlier errors: goodbye!\n");
      88: #ifdef BUFSTDERR
      89:     fflush(stderr);
      90: #endif
      91:     exit(1);
      92:     }
      93:
      94: int Wflag = 0; /* Non-zero means do not print warnings */
      95:
      96:     /* VARARGS1 */
      97: werror(s, a, b )
      98:     unsigned short s;
      99:     void *a, *b;
     100:     {  /* warning */
     101:     char    msg[256];
     102:
     103:     if (Wflag) return;
     104:     where('w');
     105:     errprep(s, msg);
     106:     fprintf(stderr, "warning: " );
     107:     fprintf(stderr, msg, a, b );
     108:     fprintf(stderr, "\n" );
     109: #ifdef BUFSTDERR
     110:     fflush(stderr);
     111: #endif
     112:     }
     113:
     114: errprep(soff, buf)
     115:     unsigned short soff;
     116:     char    *buf;
     117:     {
     118:     static  int errfd = -1;
     119:
     120:     if  (errfd < 0)
     121:         {
     122:         errfd = open(StringFile, O_RDONLY, 0);
     123:         if  (errfd < 0)
     124:             {
     125:             fprintf(stderr, "can't open %s\n", StringFile);
     126:             fflush(stderr);
     127:             exit(1);
     128:             }
     129:         }
     130:     (void)lseek(errfd, (long)soff, L_SET);
     131:     (void)read(errfd, buf, 256);
     132:     }
     133:
     134: tinit(){ /* initialize expression tree search */
     135:
     136:     register NODE *p;
     137:
     138:     for( p=node; p<= &node[TREESZ-1]; ++p ) p->in.op = FREE;
     139:     lastfree = node;
     140:
     141:     }
     142:
     143: # define TNEXT(p) (p== &node[TREESZ-1]?node:p+1)
     144:
     145: NODE *
     146: talloc(){
     147:     register NODE *p, *q;
     148:
     149:     q = lastfree;
     150:     for( p = TNEXT(q); p!=q; p= TNEXT(p))
     151:         if( p->in.op ==FREE ) return(lastfree=p);
     152:
     153:     cerror("out of tree space; simplify expression");
     154:     /* NOTREACHED */
     155:     }
     156:
     157: tcheck(){ /* ensure that all nodes have been freed */
     158:
     159:     register NODE *p;
     160:
     161:     if( !nerrors )
     162:         for( p=node; p<= &node[TREESZ-1]; ++p )
     163:             if( p->in.op != FREE ) cerror("wasted space: %o", p );
     164:     tinit();
     165: #ifdef FLEXNAMES
     166:     freetstr();
     167: #endif
     168:     }
     169: tfree( p )  NODE *p; {
     170:     /* free the tree p */
     171:     extern tfree1();
     172:
     173:     if( p->in.op != FREE ) walkf( p, tfree1 );
     174:
     175:     }
     176:
     177: tfree1(p)  NODE *p; {
     178:     if( p == 0 ) cerror("freeing blank tree!");
     179:     else p->in.op = FREE;
     180:     }
     181:
     182: fwalk( t, f, down ) register NODE *t; int (*f)(); {
     183:
     184:     int down1, down2;
     185:
     186:     more:
     187:     down1 = down2 = 0;
     188:
     189:     (*f)( t, down, &down1, &down2 );
     190:
     191:     switch( optype( t->in.op ) ){
     192:
     193:     case BITYPE:
     194:         fwalk( t->in.left, f, down1 );
     195:         t = t->in.right;
     196:         down = down2;
     197:         goto more;
     198:
     199:     case UTYPE:
     200:         t = t->in.left;
     201:         down = down1;
     202:         goto more;
     203:
     204:         }
     205:     }
     206:
     207: #ifndef vax
     208: walkf( t, f ) register NODE *t;  int (*f)(); {
     209:     register opty;
     210:
     211:     opty = optype(t->in.op);
     212:
     213:     if( opty != LTYPE ) walkf( t->in.left, f );
     214:     if( opty == BITYPE ) walkf( t->in.right, f );
     215:     (*f)( t );
     216:     }
     217: #else
     218: #define NR  100
     219:
     220: /*
     221:  * Deliberately avoids recursion -- use this version on machines with
     222:  * expensive procedure calls.
     223:  */
     224: walkf(t, f)
     225:     register NODE *t;
     226:     register int (*f)();
     227: {
     228:     register int i = 1;
     229:     register int opty = optype(t->in.op);
     230:     static NODE *at[NR];
     231:     static int ao[NR];
     232:
     233: #define PUSH(dir, state) \
     234:     (ao[i] = state, at[i++] = t, t = t->in.dir, opty = optype(t->in.op))
     235: #define POP() \
     236:     (opty = ao[--i], t = at[i])
     237:
     238:     do {
     239:         switch (opty) {
     240:         case LTYPE: (*f)(t); POP(); break;
     241:         case UTYPE: PUSH(left, LTYPE); break;
     242:         case BITYPE:    PUSH(left, BITYPE+1); break;
     243:         case BITYPE+1:  PUSH(right, LTYPE); break;
     244:         default:
     245:             cerror("bad op type in walkf");
     246:         }
     247:         if (i >= NR) {
     248:             walkf(t, f);
     249:             POP();
     250:         }
     251:     } while (i > 0);
     252: }
     253: #undef NR
     254: #undef PUSH
     255: #undef POP
     256: #endif
     257:
     258:
     259:
     260: int dope[ DSIZE ];
     261: char *opst[DSIZE];
     262:
     263: struct dopest { int dopeop; char *opst; int dopeval; } indope[] = {
     264:
     265:     NAME, "NAME", LTYPE,
     266:     STRING, "STRING", LTYPE,
     267:     REG, "REG", LTYPE,
     268:     OREG, "OREG", LTYPE,
     269:     ICON, "ICON", LTYPE,
     270:     FCON, "FCON", LTYPE,
     271:     DCON, "DCON", LTYPE,
     272:     CCODES, "CCODES", LTYPE,
     273:     UNARY MINUS, "U-", UTYPE,
     274:     UNARY MUL, "U*", UTYPE,
     275:     UNARY AND, "U&", UTYPE,
     276:     UNARY CALL, "UCALL", UTYPE|CALLFLG,
     277:     UNARY FORTCALL, "UFCALL", UTYPE|CALLFLG,
     278:     NOT, "!", UTYPE|LOGFLG,
     279:     COMPL, "~", UTYPE,
     280:     FORCE, "FORCE", UTYPE,
     281:     INIT, "INIT", UTYPE,
     282:     SCONV, "SCONV", UTYPE,
     283:     PCONV, "PCONV", UTYPE,
     284:     PLUS, "+", BITYPE|FLOFLG|SIMPFLG|COMMFLG,
     285:     ASG PLUS, "+=", BITYPE|ASGFLG|ASGOPFLG|FLOFLG|SIMPFLG|COMMFLG,
     286:     MINUS, "-", BITYPE|FLOFLG|SIMPFLG,
     287:     ASG MINUS, "-=", BITYPE|FLOFLG|SIMPFLG|ASGFLG|ASGOPFLG,
     288:     MUL, "*", BITYPE|FLOFLG|MULFLG,
     289:     ASG MUL, "*=", BITYPE|FLOFLG|MULFLG|ASGFLG|ASGOPFLG,
     290:     AND, "&", BITYPE|SIMPFLG|COMMFLG,
     291:     ASG AND, "&=", BITYPE|SIMPFLG|COMMFLG|ASGFLG|ASGOPFLG,
     292:     QUEST, "?", BITYPE,
     293:     COLON, ":", BITYPE,
     294:     ANDAND, "&&", BITYPE|LOGFLG,
     295:     OROR, "||", BITYPE|LOGFLG,
     296:     CM, ",", BITYPE,
     297:     COMOP, ",OP", BITYPE,
     298:     ASSIGN, "=", BITYPE|ASGFLG,
     299:     DIV, "/", BITYPE|FLOFLG|MULFLG|DIVFLG,
     300:     ASG DIV, "/=", BITYPE|FLOFLG|MULFLG|DIVFLG|ASGFLG|ASGOPFLG,
     301:     MOD, "%", BITYPE|DIVFLG,
     302:     ASG MOD, "%=", BITYPE|DIVFLG|ASGFLG|ASGOPFLG,
     303:     LS, "<<", BITYPE|SHFFLG,
     304:     ASG LS, "<<=", BITYPE|SHFFLG|ASGFLG|ASGOPFLG,
     305:     RS, ">>", BITYPE|SHFFLG,
     306:     ASG RS, ">>=", BITYPE|SHFFLG|ASGFLG|ASGOPFLG,
     307:     OR, "|", BITYPE|COMMFLG|SIMPFLG,
     308:     ASG OR, "|=", BITYPE|COMMFLG|SIMPFLG|ASGFLG|ASGOPFLG,
     309:     ER, "^", BITYPE|COMMFLG|SIMPFLG,
     310:     ASG ER, "^=", BITYPE|COMMFLG|SIMPFLG|ASGFLG|ASGOPFLG,
     311:     INCR, "++", BITYPE|ASGFLG,
     312:     DECR, "--", BITYPE|ASGFLG,
     313:     STREF, "->", BITYPE,
     314:     CALL, "CALL", BITYPE|CALLFLG,
     315:     FORTCALL, "FCALL", BITYPE|CALLFLG,
     316:     EQ, "==", BITYPE|LOGFLG,
     317:     NE, "!=", BITYPE|LOGFLG,
     318:     LE, "<=", BITYPE|LOGFLG,
     319:     LT, "<", BITYPE|LOGFLG,
     320:     GE, ">", BITYPE|LOGFLG,
     321:     GT, ">", BITYPE|LOGFLG,
     322:     UGT, "UGT", BITYPE|LOGFLG,
     323:     UGE, "UGE", BITYPE|LOGFLG,
     324:     ULT, "ULT", BITYPE|LOGFLG,
     325:     ULE, "ULE", BITYPE|LOGFLG,
     326: #ifdef ARS
     327:     ARS, "A>>", BITYPE,
     328: #endif
     329:     TYPE, "TYPE", LTYPE,
     330:     LB, "[", BITYPE,
     331:     CBRANCH, "CBRANCH", BITYPE,
     332:     FLD, "FLD", UTYPE,
     333:     PMCONV, "PMCONV", BITYPE,
     334:     PVCONV, "PVCONV", BITYPE,
     335:     RETURN, "RETURN", BITYPE|ASGFLG|ASGOPFLG,
     336:     CAST, "CAST", BITYPE|ASGFLG|ASGOPFLG,
     337:     GOTO, "GOTO", UTYPE,
     338:     STASG, "STASG", BITYPE|ASGFLG,
     339:     STARG, "STARG", UTYPE,
     340:     STCALL, "STCALL", BITYPE|CALLFLG,
     341:     UNARY STCALL, "USTCALL", UTYPE|CALLFLG,
     342:
     343:     -1, "", 0
     344: };
     345:
     346: mkdope(){
     347:     register struct dopest *q;
     348:
     349:     for( q = indope; q->dopeop >= 0; ++q ){
     350:         dope[q->dopeop] = q->dopeval;
     351:         opst[q->dopeop] = q->opst;
     352:         }
     353:     }
     354: # ifndef BUG4
     355: tprint( t )  TWORD t; { /* output a nice description of the type of t */
     356:
     357:     static char * tnames[] = {
     358:         "undef",
     359:         "farg",
     360:         "char",
     361:         "short",
     362:         "int",
     363:         "long",
     364:         "float",
     365:         "double",
     366:         "strty",
     367:         "unionty",
     368:         "enumty",
     369:         "moety",
     370:         "uchar",
     371:         "ushort",
     372:         "unsigned",
     373:         "ulong",
     374:         "?", "?"
     375:         };
     376:
     377:     for(;; t = DECREF(t) ){
     378:
     379:         if( ISPTR(t) ) printf( "PTR " );
     380:         else if( ISFTN(t) ) printf( "FTN " );
     381:         else if( ISARY(t) ) printf( "ARY " );
     382:         else {
     383:             printf( "%s", tnames[t] );
     384:             return;
     385:             }
     386:         }
     387:     }
     388: # endif
     389:
     390: #ifdef FLEXNAMES
     391: #define NTSTRBUF    25      /* was 40 */
     392: #define TSTRSZ      512     /* was 2048 */
     393: char    itstrbuf[TSTRSZ];
     394: char    *tstrbuf[NTSTRBUF] = { itstrbuf };
     395: char    **curtstr = tstrbuf;
     396: int tstrused;
     397:
     398: char *
     399: tstr(cp)
     400:     register char *cp;
     401: {
     402:     register int i = strlen(cp);
     403:     register char *dp;
     404:
     405:     if (tstrused + i >= TSTRSZ) {
     406:         if (++curtstr >= &tstrbuf[NTSTRBUF])
     407:             cerror("out of temporary string space");
     408:         tstrused = 0;
     409:         if (*curtstr == 0) {
     410:             dp = (char *)malloc(TSTRSZ);
     411:             if (dp == 0)
     412:                 cerror("out of memory (tstr)");
     413:             *curtstr = dp;
     414:         }
     415:     }
     416:     strcpy(dp = *curtstr+tstrused, cp);
     417:     tstrused += i + 1;
     418:     return (dp);
     419: }
     420: #endif

#### Defined functions

caloff defined in line 32; used 6 times

- in /usr/src/lib/mip/fort.c line 114, 120
- in /usr/src/lib/mip/reader.c line 127, 136
- in /usr/src/lib/mip/scan.c line 73, 85

cerror defined in line 74; used 95 times

- in line 70, 153, 163, 178, 245, 407-412(2)
- in /usr/src/lib/mip/allo.c line 138, 149, 194, 311-318(4), 339-341(2), 436, 452, 499, 509-514(2), 584
- in /usr/src/lib/mip/cgram.y line 83, 401, 816, 824, 831, 861, 884
- in /usr/src/lib/mip/fort.c line 52-57(2), 67, 77, 86, 96-100(3)
- in /usr/src/lib/mip/match.c line 232, 441, 494, 515, 595, 619
- in /usr/src/lib/mip/pftn.c line 48-52(2), 380, 400, 416-418(3), 585, 710, 759, 789, 817, 932, 1237-1238(2), 1254, 1352, 1363, 1380, 1489, 1697, 1718, 1800, 1818-1827(4), 1870, 1917, 1933, 1980
- in /usr/src/lib/mip/reader.c line 112, 165, 184, 215, 560, 1036, 1117, 1156, 1169-1174(2)
- in /usr/src/lib/mip/scan.c line 818-823(2), 986, 1073, 1127, 1154
- in /usr/src/lib/mip/trees.c line 407, 551, 572, 622, 1006

errprep defined in line 114; used 3 times

- in line 64, 81, 105

fwalk defined in line 182; used 12 times

- in line 194
- in /usr/src/lib/mip/fort.c line 257
- in /usr/src/lib/mip/pftn.c line 1493
- in /usr/src/lib/mip/reader.c line 199, 235, 387, 499, 701, 1324
- in /usr/src/lib/mip/trees.c line 64, 560, 1555

mkdope defined in line 346; used 2 times

- in /usr/src/lib/mip/reader.c line 119
- in /usr/src/lib/mip/scan.c line 160

talloc defined in line 145; used 14 times

- in /usr/src/lib/mip/allo.c line 552
- in /usr/src/lib/mip/fort.c line 182, 208, 222, 236, 294, 300
- in /usr/src/lib/mip/pass1.h line 191
- in /usr/src/lib/mip/pass2.h line 173
- in /usr/src/lib/mip/reader.c line 1102, 1209, 1226-1231(2)
- in /usr/src/lib/mip/trees.c line 1236

tcheck defined in line 157; used 3 times

- in /usr/src/lib/mip/fort.c line 267
- in /usr/src/lib/mip/pftn.c line 411
- in /usr/src/lib/mip/reader.c line 211

tfree defined in line 169; used 14 times

- in /usr/src/lib/mip/allo.c line 410, 418, 462
- in /usr/src/lib/mip/cgram.y line 550, 866
- in /usr/src/lib/mip/pftn.c line 981, 1130
- in /usr/src/lib/mip/reader.c line 598, 1311
- in /usr/src/lib/mip/trees.c line 128-132(2), 1258, 1505, 1565

tfree1 defined in line 177; used 2 times

- in line 171-173(2)

tinit defined in line 134; used 4 times

- in line 164
- in /usr/src/lib/mip/fort.c line 122
- in /usr/src/lib/mip/reader.c line 138
- in /usr/src/lib/mip/scan.c line 159

tprint defined in line 355; used 6 times

- in /usr/src/lib/mip/pftn.c line 62, 78-81(2), 445
- in /usr/src/lib/mip/reader.c line 1076
- in /usr/src/lib/mip/trees.c line 1528

tstr defined in line 398; used 5 times

- in /usr/src/lib/mip/fort.c line 59
- in /usr/src/lib/mip/manifest.h line 93
- in /usr/src/lib/mip/reader.c line 1132
- in /usr/src/lib/mip/trees.c line 1660, 1669

uerror defined in line 53; used 105 times

- in /usr/src/lib/mip/cgram.y line 234-236(2), 244, 283, 327, 454, 461, 478, 708, 853-857(2), 871-875(2), 926
- in /usr/src/lib/mip/fort.c line 177, 204, 253, 318
- in /usr/src/lib/mip/optim.c line 207, 223
- in /usr/src/lib/mip/pftn.c line 93-95(2), 271, 286-288(2), 298, 628, 657, 673-675(2), 773-775(2), 915, 926, 1020, 1030, 1056, 1074-1079(2), 1112, 1123, 1184, 1329, 1339, 1345, 1441, 1536, 1559-1563(2), 1589, 1621, 1636, 1643-1655(4), 1663-1667(2), 1675-1679(2), 1688, 1875-1877(2)
- in /usr/src/lib/mip/reader.c line 629
- in /usr/src/lib/mip/scan.c line 328-332(2), 428-430(2), 443, 518, 553, 668, 674-679(2), 798, 805, 982
- in /usr/src/lib/mip/trees.c line 211, 218, 241, 287-289(2), 350, 393-395(2), 403, 425, 474, 499, 522, 528-530(2), 618, 677-682(2), 772, 921, 1039-1044(2), 1102, 1251-1256(2), 1318, 1458-1460(2)

walkf defined in line 224; used 8 times

- in line 173, 213-214(2), 248
- in /usr/src/lib/mip/allo.c line 402
- in /usr/src/lib/mip/reader.c line 1326-1330(2)
- in /usr/src/lib/mip/trees.c line 1562

werror defined in line 97; used 35 times

- in /usr/src/lib/mip/cgram.y line 217, 264, 360, 470, 523, 545, 556, 579, 608, 661, 674, 720-722(2)
- in /usr/src/lib/mip/pftn.c line 602-604(2), 1021, 1582, 1940-1942(2)
- in /usr/src/lib/mip/scan.c line 406, 767
- in /usr/src/lib/mip/trees.c line 105, 158, 405-412(3), 633, 776, 785, 795, 802, 812, 1220, 1506, 1558

#### Defined variables

StringFile defined in line 3; used 2 times

- in line 122-125(2)

Wflag defined in line 94; used 2 times

- in line 103
- in /usr/src/lib/mip/reader.c line 102

curtstr defined in line 395; used 5 times

- in line 406-416(4)
- in /usr/src/lib/mip/manifest.h line 97

dope defined in line 260; used 9 times

- in line 350
- in /usr/src/lib/mip/manifest.h line 82-85(4)
- in /usr/src/lib/mip/match.c line 237, 258, 292, 581

indope defined in line 263; used 1 times

- in line 349

itstrbuf defined in line 393; used 1 times

- in line 394

lastfree defined in line 50; used 3 times

- in line 139, 149-151(2)

nerrors defined in line 21; used 10 times

- in line 62, 70, 86(2), 161
- in /usr/src/lib/mip/pftn.c line 415
- in /usr/src/lib/mip/reader.c line 146, 221
- in /usr/src/lib/mip/scan.c line 185-186(2)

opst defined in line 261; used 14 times

- in line 263, 351(2)
- in /usr/src/lib/mip/match.c line 55
- in /usr/src/lib/mip/reader.c line 554, 560, 1052
- in /usr/src/lib/mip/trees.c line 94, 776, 786, 1160, 1458-1460(2), 1523

tstrbuf defined in line 394; used 3 times

- in line 395, 406
- in /usr/src/lib/mip/manifest.h line 97

tstrused defined in line 396; used 5 times

- in line 405-408(2), 416-417(2)
- in /usr/src/lib/mip/manifest.h line 97

#### Defined struct's

dopest defined in line 263; used 2 times

- in line 347(2)

#### Defined macros

NR defined in line 218; used 4 times

- in line 230-231(2), 247, 253

NTSTRBUF defined in line 391; used 2 times

- in line 394, 406

POP defined in line 235; used 3 times

- in line 240, 249, 255

PUSH defined in line 233; used 4 times

- in line 241-243(3), 254

TNEXT defined in line 143; used 2 times

- in line 150(2)

TSTRSZ defined in line 392; used 3 times

- in line 393, 405-410(2)

Last modified: 1995-01-18 Generated: 2016-12-26 | Generated by src2html V0.67 page hit count: 1765 |