Annotation of researchv10no/cmd/PDP11/11c/tpr.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Interpret a C intermediate file.
        !             3:  */
        !             4: #include <stdio.h>
        !             5: #include "c1.h"
        !             6: 
        !             7: extern opdope[1];
        !             8: extern char    *opntab[1];
        !             9: 
        !            10: struct table cctab[1], efftab[1], regtab[1], sptab[1];
        !            11: char   maprel[1], notrel[1];
        !            12: char   *outname();
        !            13: 
        !            14: main()
        !            15: {
        !            16:        register t, op;
        !            17:        static char s[9];
        !            18:        register char *tp;
        !            19:        double atof();
        !            20:        char numbuf[64];
        !            21:        int lbl, cond;
        !            22:        int sdep;
        !            23: 
        !            24:        sdep = 0;
        !            25:        for (;;) {
        !            26:                op = getw(stdin);
        !            27:                if ((op&0177400) != 0177000) {
        !            28:                        error("Intermediate file error");
        !            29:                        exit(1);
        !            30:                }
        !            31:                lbl = 0;
        !            32:                switch(op &= 0377) {
        !            33: 
        !            34:        case SINIT:
        !            35:                printf("init %d\n", getw(stdin));
        !            36:                break;
        !            37: 
        !            38:        case EOFC:
        !            39:                printf("eof\n");
        !            40:                exit(0);
        !            41: 
        !            42:        case BDATA:
        !            43:                if (getw(stdin) == 1) {
        !            44:                        printf(".byte ");
        !            45:                        for (;;)  {
        !            46:                                printf("%d", getw(stdin));
        !            47:                                if (getw(stdin) != 1)
        !            48:                                        break;
        !            49:                                printf(",");
        !            50:                        }
        !            51:                        printf("\n");
        !            52:                }
        !            53:                break;
        !            54: 
        !            55:        case PROG:
        !            56:                printf("prog\n");
        !            57:                break;
        !            58: 
        !            59:        case DATA:
        !            60:                printf("data\n");
        !            61:                break;
        !            62: 
        !            63:        case BSS:
        !            64:                printf("bss\n");
        !            65:                break;
        !            66: 
        !            67:        case SYMDEF:
        !            68:                printf("symdef ");
        !            69:                outname(s);
        !            70:                printf("%s\n", s);
        !            71:                break;
        !            72: 
        !            73:        case RETRN:
        !            74:                printf("return\n");
        !            75:                break;
        !            76: 
        !            77:        case CSPACE:
        !            78:                tp = outname(s);
        !            79:                printf("comm %s,%d\n", tp, getw(stdin));
        !            80:                break;
        !            81: 
        !            82:        case SSPACE:
        !            83:                printf("space %d\n", getw(stdin));
        !            84:                break;
        !            85: 
        !            86:        case EVEN:
        !            87:                printf("even\n");
        !            88:                break;
        !            89: 
        !            90:        case SAVE:
        !            91:                printf("save\n");
        !            92:                break;
        !            93: 
        !            94:        case SETSTK:
        !            95:                t = getw(stdin)-6;
        !            96:                printf("setstack %d\n", t);
        !            97:                break;
        !            98: 
        !            99:        case PROFIL:
        !           100:                t = getw(stdin);
        !           101:                printf("profil %d\n", t);
        !           102:                break;
        !           103: 
        !           104:        case SNAME:
        !           105:                tp = outname(s);
        !           106:                printf("sname %s s%d\n", tp, getw(stdin));
        !           107:                break;
        !           108: 
        !           109:        case ANAME:
        !           110:                tp = outname(s);
        !           111:                printf("aname %s a%d\n", tp, getw(stdin));
        !           112:                break;
        !           113: 
        !           114:        case RNAME:
        !           115:                tp = outname(s);
        !           116:                printf("rname %s r%d\n", tp, getw(stdin));
        !           117:                break;
        !           118: 
        !           119:        case SWIT:
        !           120:                t = getw(stdin);
        !           121:                line = getw(stdin);
        !           122:                printf("switch line %d def %d\n", line, t);
        !           123:                while (t = getw(stdin)) {
        !           124:                        printf("   %d %d\n", t, getw(stdin));
        !           125:                }
        !           126:                break;
        !           127: 
        !           128:        case CBRANCH:
        !           129:                lbl = getw(stdin);
        !           130:                cond = getw(stdin);
        !           131:        case EXPR:
        !           132:                line = getw(stdin);
        !           133:                if (sdep != 1) {
        !           134:                        error("Expression input botch");
        !           135:                        exit(1);
        !           136:                }
        !           137:                sdep = 0;
        !           138:                if (lbl)
        !           139:                        printf("cbranch %d line %d\n", lbl, line);
        !           140:                else
        !           141:                        printf("expr line %d\n", line);
        !           142:                break;
        !           143: 
        !           144:        case NAME:
        !           145:                t = getw(stdin);
        !           146:                if (t==EXTERN) {
        !           147:                        t = getw(stdin);
        !           148:                        printf("name %o, %s\n", t, outname(s));
        !           149:                } else if (t==AUTO) {
        !           150:                        t = getw(stdin);
        !           151:                        printf("name %o a%d\n", t, getw(stdin));
        !           152:                } else if (t==STATIC) {
        !           153:                        t = getw(stdin);
        !           154:                        printf("name %o s%d\n", t, getw(stdin));
        !           155:                } else if (t==REG) {
        !           156:                        t = getw(stdin);
        !           157:                        printf("name %o r%d\n", t, getw(stdin));
        !           158:                } else
        !           159:                        printf("name botch\n");
        !           160:                sdep++;
        !           161:                break;
        !           162: 
        !           163:        case CON:
        !           164:                t = getw(stdin);
        !           165:                printf("const %d %d\n", t, getw(stdin));
        !           166:                sdep++;
        !           167:                break;
        !           168: 
        !           169:        case LCON:
        !           170:                getw(stdin);    /* ignore type, assume long */
        !           171:                t = getw(stdin);
        !           172:                op = getw(stdin);
        !           173:                printf("lconst %D\n", (((long)t<<16) | (unsigned)op));
        !           174:                sdep++;
        !           175:                break;
        !           176: 
        !           177:        case FCON:
        !           178:                t = getw(stdin);
        !           179:                printf("fcon %s\n", outname(numbuf));
        !           180:                sdep++;
        !           181:                break;
        !           182: 
        !           183:        case FSEL:
        !           184:                printf("fsel %o ", getw(stdin));
        !           185:                printf("%d ", getw(stdin));
        !           186:                printf("%d\n", getw(stdin));
        !           187:                break;
        !           188: 
        !           189:        case STRASG:
        !           190:                t = getw(stdin);
        !           191:                printf("strasg %o ", getw(stdin));
        !           192:                printf("%d\n", getw(stdin));
        !           193:                break;
        !           194: 
        !           195:        case NULLOP:
        !           196:                printf("null\n");
        !           197:                sdep++;
        !           198:                break;
        !           199: 
        !           200:        case LABEL:
        !           201:                printf("label %d\n", getw(stdin));
        !           202:                break;
        !           203: 
        !           204:        case NLABEL:
        !           205:                tp = outname(s);
        !           206:                printf("nlabel %s\n", tp);
        !           207:                break;
        !           208: 
        !           209:        case RLABEL:
        !           210:                tp = outname(s);
        !           211:                printf("rlabel %s\n", tp);
        !           212:                break;
        !           213: 
        !           214:        case BRANCH:
        !           215:                printf("branch %d\n", getw(stdin));
        !           216:                break;
        !           217: 
        !           218:        case SETREG:
        !           219:                printf("nreg %d\n", getw(stdin));
        !           220:                break;
        !           221: 
        !           222:        default:
        !           223:                t = getw(stdin);
        !           224:                if (op <=0 || op >=120) {
        !           225:                        printf("Unknown op %d\n", op);
        !           226:                        exit(1);
        !           227:                }
        !           228:                if (opdope[op]&BINARY)
        !           229:                        sdep--;
        !           230:                if (sdep<=0)
        !           231:                        printf("Binary expression botch\n");
        !           232:                if (opntab[op] == 0)
        !           233:                        printf("op %d %o\n", op, t);
        !           234:                else
        !           235:                        printf("%s %o\n", opntab[op], t);
        !           236:                break;
        !           237:        }
        !           238:        }
        !           239: }
        !           240: 
        !           241: char *
        !           242: outname(s)
        !           243: char *s;
        !           244: {
        !           245:        register char *p, c;
        !           246:        register n;
        !           247: 
        !           248:        p = s;
        !           249:        n = 0;
        !           250:        while (c = getc(stdin)) {
        !           251:                *p++ = c;
        !           252:                n++;
        !           253:        }
        !           254:        do {
        !           255:                *p++ = 0;
        !           256:        } while (n++ < 8);
        !           257:        return(s);
        !           258: }
        !           259: 
        !           260: error(s)
        !           261: char *s;
        !           262: {
        !           263:        printf("%s\n", s);
        !           264:        exit(1);
        !           265: }
        !           266: 
        !           267: getw(f)
        !           268: FILE *f;
        !           269: {
        !           270:        register x;
        !           271:        x = getc(f);
        !           272:        x |= getc(f)<<8;
        !           273:        return(x);
        !           274: }
        !           275: 

unix.superglobalmegacorp.com

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