Annotation of 41BSD/cmd/mip/fort.c, revision 1.1.1.1

1.1       root        1: static char *sccsid ="%W% (Berkeley) %G%";
                      2: # define FORT
                      3: /* this forces larger trees, etc. */
                      4: # include "mfile2"
                      5: # include "fort.h"
                      6: 
                      7: /*     masks for unpacking longs */
                      8: 
                      9: # ifndef FOP
                     10: # define FOP(x) (int)((x)&0377)
                     11: # endif
                     12: 
                     13: # ifndef VAL
                     14: # define VAL(x) (int)(((x)>>8)&0377)
                     15: # endif
                     16: 
                     17: # ifndef REST
                     18: # define REST(x) (((x)>>16)&0177777)
                     19: # endif
                     20: 
                     21: FILE * lrd;  /* for default reading routines */
                     22: 
                     23: # ifndef NOLNREAD
                     24: #ifdef FLEXNAMES
                     25: char *
                     26: lnread()
                     27: {
                     28:        char buf[BUFSIZ];
                     29:        register char *cp = buf;
                     30:        register char *limit = &buf[BUFSIZ];
                     31: 
                     32:        for (;;) {
                     33:                if (fread(cp, sizeof (long), 1, lrd) !=  1)
                     34:                        cerror("intermediate file read error");
                     35:                cp += sizeof (long);
                     36:                if (cp[-1] == 0)
                     37:                        break;
                     38:                if (cp >= limit)
                     39:                        cerror("lnread overran string buffer");
                     40:        }
                     41:        return (tstr(buf));
                     42: }
                     43: # endif NOLNREAD
                     44: 
                     45: # ifndef NOLREAD
                     46: long lread(){
                     47:        static long x;
                     48:        if( fread( (char *) &x, 4, 1, lrd ) <= 0 ) cerror( "intermediate file read error" );
                     49:        return( x );
                     50:        }
                     51: # endif
                     52: 
                     53: # ifndef NOLOPEN
                     54: lopen( s ) char *s; {
                     55:        /* if null, opens the standard input */
                     56:        if( *s ){
                     57:                lrd = fopen( s, "r" );
                     58:                if( lrd == NULL ) cerror( "cannot open intermediate file %s", s );
                     59:                }
                     60:        else  lrd = stdin;
                     61:        }
                     62: # endif
                     63: 
                     64: # ifndef NOLCREAD
                     65: lcread( cp, n ) char *cp; {
                     66:        if( n > 0 ){
                     67:                if( fread( cp, 4, n, lrd ) != n ) cerror( "intermediate file read error" );
                     68:                }
                     69:        }
                     70: # endif
                     71: 
                     72: # ifndef NOLCCOPY
                     73: lccopy( n ) register n; {
                     74:        register i;
                     75:        static char fbuf[128];
                     76:        if( n > 0 ){
                     77:                if( n > 32 ) cerror( "lccopy asked to copy too much" );
                     78:                if( fread( fbuf, 4, n, lrd ) != n ) cerror( "intermediate file read error" );
                     79:                for( i=4*n; fbuf[i-1] == '\0' && i>0; --i ) { /* VOID */ }
                     80:                if( i ) {
                     81:                        if( fwrite( fbuf, 1, i, stdout ) != i ) cerror( "output file error" );
                     82:                        }
                     83:                }
                     84:        }
                     85: # endif
                     86: 
                     87: /*     new opcode definitions */
                     88: 
                     89: # define FORTOPS 200
                     90: # define FTEXT 200
                     91: # define FEXPR 201
                     92: # define FSWITCH 202
                     93: # define FLBRAC 203
                     94: # define FRBRAC 204
                     95: # define FEOF 205
                     96: # define FARIF 206
                     97: # define LABEL 207
                     98: 
                     99: /*     stack for reading nodes in postfix form */
                    100: 
                    101: # define NSTACKSZ 250
                    102: 
                    103: NODE * fstack[NSTACKSZ];
                    104: NODE ** fsp;  /* points to next free position on the stack */
                    105: 
                    106: unsigned int offsz;
                    107: unsigned int caloff();
                    108: mainp2( argc, argv ) char *argv[]; {
                    109:        int files;
                    110:        register long x;
                    111:        register NODE *p;
                    112: 
                    113:        offsz = caloff();
                    114:        files = p2init( argc, argv );
                    115:        tinit();
                    116: 
                    117:                
                    118:        if( files ){
                    119:                while( files < argc && argv[files][0] == '-' ) {
                    120:                        ++files;
                    121:                        }
                    122:                if( files > argc ) return( nerrors );
                    123:                lopen( argv[files] );
                    124:                }
                    125:        else lopen( "" );
                    126: 
                    127:        fsp = fstack;
                    128: 
                    129:        for(;;){
                    130:                /* read nodes, and go to work... */
                    131:                x = lread();
                    132: 
                    133:        if( xdebug ) fprintf( stderr, "op=%d, val = %d, rest = 0%o\n", FOP(x), VAL(x), (int)REST(x) );
                    134:                switch( (int)FOP(x) ){  /* switch on opcode */
                    135: 
                    136:                case 0:
                    137:                        fprintf( stderr, "null opcode ignored\n" );
                    138:                        continue;
                    139:                case FTEXT:
                    140:                        lccopy( VAL(x) );
                    141:                        printf( "\n" );
                    142:                        continue;
                    143: 
                    144:                case FLBRAC:
                    145:                        tmpoff = baseoff = lread();
                    146:                        maxtreg = VAL(x);
                    147:                        if( ftnno != REST(x) ){
                    148:                                /* beginning of function */
                    149:                                maxoff = baseoff;
                    150:                                ftnno = REST(x);
                    151:                                maxtemp = 0;
                    152:                                }
                    153:                        else {
                    154:                                if( baseoff > maxoff ) maxoff = baseoff;
                    155:                                /* maxoff at end of ftn is max of autos and temps 
                    156:                                   over all blocks in the function */
                    157:                                }
                    158:                        setregs();
                    159:                        continue;
                    160: 
                    161:                case FRBRAC:
                    162:                        SETOFF( maxoff, ALSTACK );
                    163:                        eobl2();
                    164:                        continue;
                    165: 
                    166:                case FEOF:
                    167:                        return( nerrors );
                    168: 
                    169:                case FSWITCH:
                    170:                        uerror( "switch not yet done" );
                    171:                        for( x=VAL(x); x>0; --x ) lread();
                    172:                        continue;
                    173: 
                    174:                case ICON:
                    175:                        p = talloc();
                    176:                        p->in.op = ICON;
                    177:                        p->in.type = REST(x);
                    178:                        p->tn.rval = 0;
                    179:                        p->tn.lval = lread();
                    180:                        if( VAL(x) ){
                    181: #ifndef FLEXNAMES
                    182:                                lcread( p->in.name, 2 );
                    183: #else
                    184:                                p->in.name = lnread();
                    185: #endif
                    186:                                }
                    187: #ifndef FLEXNAMES
                    188:                        else p->in.name[0] = '\0';
                    189: #else
                    190:                        else p->in.name = "";
                    191: #endif
                    192: 
                    193:                bump:
                    194:                        p->in.su = 0;
                    195:                        p->in.rall = NOPREF;
                    196:                        *fsp++ = p;
                    197:                        if( fsp >= &fstack[NSTACKSZ] ) uerror( "expression depth exceeded" );
                    198:                        continue;
                    199: 
                    200:                case NAME:
                    201:                        p = talloc();
                    202:                        p->in.op = NAME;
                    203:                        p->in.type = REST(x);
                    204:                        p->tn.rval = 0;
                    205:                        if( VAL(x) ) p->tn.lval = lread();
                    206:                        else p->tn.lval = 0;
                    207: #ifndef FLEXNAMES
                    208:                        lcread( p->in.name, 2 );
                    209: #else
                    210:                        p->in.name = lnread();
                    211: #endif
                    212:                        goto bump;
                    213: 
                    214:                case OREG:
                    215:                        p = talloc();
                    216:                        p->in.op = OREG;
                    217:                        p->in.type = REST(x);
                    218:                        p->tn.rval = VAL(x);
                    219:                        p->tn.lval = lread();
                    220: #ifndef FLEXNAMES
                    221:                        lcread( p->in.name, 2 );
                    222: #else
                    223:                        p->in.name = lnread();
                    224: #endif
                    225:                        goto bump;
                    226: 
                    227:                case REG:
                    228:                        p = talloc();
                    229:                        p->in.op = REG;
                    230:                        p->in.type = REST(x);
                    231:                        p->tn.rval = VAL(x);
                    232:                        rbusy( p->tn.rval, p->in.type );
                    233:                        p->tn.lval = 0;
                    234: #ifndef FLEXNAMES
                    235:                        p->in.name[0] = '\0';
                    236: #else
                    237:                        p->in.name = "";
                    238: #endif
                    239:                        goto bump;
                    240: 
                    241:                case FEXPR:
                    242:                        lineno = REST(x);
                    243:                        if( VAL(x) ) lcread( filename, VAL(x) );
                    244:                        if( fsp == fstack ) continue;  /* filename only */
                    245:                        if( --fsp != fstack ) uerror( "expression poorly formed" );
                    246:                        if( lflag ) lineid( lineno, filename );
                    247:                        tmpoff = baseoff;
                    248:                        p = fstack[0];
                    249:                        if( edebug ) fwalk( p, eprint, 0 );
                    250: # ifdef MYREADER
                    251:                        MYREADER(p);
                    252: # endif
                    253: 
                    254:                        nrecur = 0;
                    255:                        delay( p );
                    256:                        reclaim( p, RNULL, 0 );
                    257: 
                    258:                        allchk();
                    259:                        tcheck();
                    260:                        continue;
                    261: 
                    262:                case LABEL:
                    263:                        if( VAL(x) ){
                    264:                                tlabel();
                    265:                                }
                    266:                        else {
                    267:                                label( (int) REST(x) );
                    268:                                }
                    269:                        continue;
                    270: 
                    271:                case GOTO:
                    272:                        if( VAL(x) ) {
                    273:                                cbgen( 0, (int) REST(x), 'I' );  /* unconditional branch */
                    274:                                continue;
                    275:                                }
                    276:                        /* otherwise, treat as unary */
                    277:                        goto def;
                    278: 
                    279:                case STASG:
                    280:                case STARG:
                    281:                case STCALL:
                    282:                case UNARY STCALL:
                    283:                            /*
                    284:                             * size and alignment come from next long words
                    285:                             */
                    286:                        p = talloc();
                    287:                        p -> stn.stsize = lread();
                    288:                        p -> stn.stalign = lread();
                    289:                        goto defa;
                    290:                default:
                    291:                def:
                    292:                        p = talloc();
                    293:                defa:
                    294:                        p->in.op = FOP(x);
                    295:                        p->in.type = REST(x);
                    296: 
                    297:                        switch( optype( p->in.op ) ){
                    298: 
                    299:                        case BITYPE:
                    300:                                p->in.right = *--fsp;
                    301:                                p->in.left = *--fsp;
                    302:                                goto bump;
                    303: 
                    304:                        case UTYPE:
                    305:                                p->in.left = *--fsp;
                    306:                                p->tn.rval = 0;
                    307:                                goto bump;
                    308: 
                    309:                        case LTYPE:
                    310:                                uerror( "illegal leaf node: %d", p->in.op );
                    311:                                exit( 1 );
                    312:                                }
                    313:                        }
                    314:                }
                    315:        }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.