Annotation of cci/usr/src/usr.bin/f77/f77pass2/fort.c, revision 1.1.1.1

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

unix.superglobalmegacorp.com

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