Annotation of researchv10no/cmd/ccom/common/pjw.c, revision 1.1

1.1     ! root        1: #include "mfile2.h"
        !             2: extern struct symtab { /* ripped untimely from mfile1.h */
        !             3:        char *sname;
        !             4:        TWORD stype;  /* type word */
        !             5: 
        !             6:        char sclass;  /* storage class */
        !             7:        char slevel;  /* scope level */
        !             8:        char sflags;  /* flags for set, use, hidden, mos, etc. */
        !             9:        int offset;  /* offset or value */
        !            10:        short dimoff; /* offset into the dimension table */
        !            11:        short sizoff; /* offset into the size table */
        !            12:        short suse;  /* line number of last use of the variable */
        !            13:        struct symtab *scopelink;       /* chain of symbols at same level */
        !            14: } stab[];
        !            15: 
        !            16: #define BINOP 1000
        !            17: #define ARG 1001
        !            18: #define UCALL 1002
        !            19: #define BINARY 1003
        !            20: #define COPY 1004
        !            21: #define ENTRY 1005
        !            22: #define LOCCTR 1006
        !            23: #define LXINFO 1008
        !            24: #define URETURN 1010
        !            25: #define USTCALL 1011
        !            26: #define STRANGE 1012
        !            27: struct init {
        !            28:        int op;
        !            29:        int type;
        !            30:        char *name;
        !            31: } ar[] = {
        !            32:        {1, 0, "???"},
        !            33:        {AND, BINOP, "and"},
        !            34:        {ANDAND, BINOP, "andand"},
        !            35:        {ASG AND, BINOP, "asgand"},
        !            36:        {UNARY AND, UNOP, "unaryand"},
        !            37:        {ARG, ARG, "arg"},
        !            38:        {ARS, BINOP, "ars"},
        !            39:        {ASSIGN, BINOP, "assign"},
        !            40:        {CALL, CALL, "call"},
        !            41:        {FORTCALL, CALL, "fortcall"},
        !            42:        {UNARY CALL, UCALL, "unarycall"},
        !            43:        {UNARY FORTCALL, UNOP, "unaryfortcall"},
        !            44:        {CBRANCH, BINARY, "cbranch "},
        !            45:        {CM, BINARY, "cm "},
        !            46:        {CMP, BINARY, "cmp "},
        !            47:        {COLON, BINOP, "colon"},
        !            48:        {COMOP, BINOP, "comop"},
        !            49:        {COMPL, UNOP, "compl"},
        !            50:        {CONV, UNOP, "conv"},
        !            51:        {COPY, COPY, "copy"},
        !            52:        {DECR, BINOP, "decr"},
        !            53:        {DIV, BINOP, "div"},
        !            54:        {ASG DIV, BINOP, "asgdiv"},
        !            55:        {ENTRY, ENTRY, "entry"},
        !            56:        {EPILOG, EPILOG, "epilog"},
        !            57:        {ER, BINOP, "er"},
        !            58:        {ASG ER, BINOP, "asger"},
        !            59:        {FCON, FCON, "fcon"},
        !            60:        {FLD, FLD, "fld"},
        !            61:        {FUNARG, UNOP, "funarg"},
        !            62:        {FREE, FREE, "free"},
        !            63:        {GENBR, GENBR, "genbr"},
        !            64:        {GENLAB, GENLAB, "genlab"},
        !            65:        {GENUBR, GENLAB, "genubr"},
        !            66:        {GOTO, GOTO, "goto"},
        !            67:        {ICON, ICON, "icon"},
        !            68:        {INCR, BINOP, "incr"},
        !            69:        {INIT, UNOP, "init"},
        !            70:        {LABELPT, GOTO, "labelpt"},
        !            71:        {LOCCTR, LOCCTR, "locctr"},
        !            72:        {LS, BINOP, "ls"},
        !            73:        {ASG LS, BINOP, "asgls"},
        !            74:        {LXINFO, LXINFO, "lxinfo"},
        !            75:        {MINUS, BINOP, "minus"},
        !            76:        {ASG MINUS, BINOP, "asgminus"},
        !            77:        {UNARY MINUS, UNOP, "unaryminus"},
        !            78:        {MOD, BINOP, "mod"},
        !            79:        {ASG MOD, BINOP, "asgmod"},
        !            80:        {MUL, BINOP, "mul"},
        !            81:        {ASG MUL, BINOP, "asgmul"},
        !            82:        {NAME, NAME, "name"},
        !            83:        {NOT, UNOP, "not"},
        !            84:        {OR, BINOP, "or"},
        !            85:        {ASG OR, BINOP, "asgor"},
        !            86:        {OROR, BINARY, "oror "},
        !            87:        {PLUS, BINOP, "plus"},
        !            88:        {ASG PLUS, BINOP, "asgplus"},
        !            89:        {PROLOG, PROLOG, "prolog"},
        !            90:        {QUEST, BINARY, "quest"},
        !            91:        {REG, REG, "reg"},
        !            92:        {EQ, BINOP, "eql"},
        !            93:        {NE, BINOP, "neq"},
        !            94:        {GT, BINOP, "gtr"},
        !            95:        {GE, BINOP, "geq"},
        !            96:        {LT, BINOP, "lss"},
        !            97:        {LE, BINOP, "leq"},
        !            98:        {UGT, BINOP, "gtru"},
        !            99:        {UGE, BINOP, "gequ"},
        !           100:        {ULT, BINOP, "lssu"},
        !           101:        {ULE, BINOP, "lequ"},
        !           102:        {RETURN, RETURN, "return"},
        !           103:        {UNARY RETURN, URETURN, "unaryreturn"},
        !           104:        {RNODE, STRANGE, "rnode"},
        !           105:        {QNODE, STRANGE, "qnode"},
        !           106:        {SNODE, STRANGE, "snode"},
        !           107:        {RS, BINOP, "rs"},
        !           108:        {ASG RS, BINOP, "asgrs"},
        !           109:        {STAR, UNOP, "star"},
        !           110:        {UNARY MUL, UNOP, "star"},
        !           111:        {STARG, STARG, "starg"},
        !           112:        {STASG, STASG, "stasg"},
        !           113:        {STREF, STASG, "stref"},
        !           114:        {STCALL, STCALL, "stcall"},
        !           115:        {UNARY STCALL, USTCALL, "unarystcall"},
        !           116:        {SWBEG, SWBEG, "swbeg"},
        !           117:        {SWCASE, SWCASE, "swcase"},
        !           118:        {SWDEF, SWDEF, "swdef"},
        !           119:        {SWEND, SWEND, "swend"},
        !           120:        {TEMP, TEMP, "temp"},
        !           121:        {VAUTO, VAUTO, "vauto"},
        !           122:        {VPARAM, VAUTO, "vparam"},
        !           123:        {0, 0, 0}
        !           124: };
        !           125: int opindex[256];
        !           126: int bothdebug;
        !           127: FILE *fd;
        !           128: pjwreader(p)
        !           129: NODE *p;
        !           130: {      int n;
        !           131:        if(bothdebug) {
        !           132:                printf("#tree ", p);
        !           133:                prtree(p);
        !           134:                putchar('\n');
        !           135:                gencode(p);
        !           136:                tfree(p);
        !           137:        }
        !           138:        else {
        !           139:                gencode(p);
        !           140:                tfree(p);
        !           141:        }
        !           142: }
        !           143: prtree(p)
        !           144: NODE *p;
        !           145: {      int i, n;
        !           146:        static init = 0;
        !           147:        if(!init++)
        !           148:                myinit();
        !           149:        if(p == 0) {    
        !           150:                printf("???");
        !           151:                return;
        !           152:        }
        !           153:        i = opindex[p->in.op];
        !           154:        if(i == 0) {
        !           155:                printf("(unk op %d ???) ", p->in.op);
        !           156:                return;
        !           157:        }
        !           158:        printf("(%s", ar[i].name);
        !           159:        switch(ar[i].type) {
        !           160:        default:
        !           161:                printf("%d???) ", ar[i].type);
        !           162:                return;
        !           163:        case STRANGE:
        !           164:                printf(") ");
        !           165:                return;
        !           166:        case BINOP:
        !           167:                prtype(p->in.type);
        !           168:        case BINARY:
        !           169:                prtree(p->in.left);
        !           170:                prtree(p->in.right);
        !           171:                printf(") ");
        !           172:                return;
        !           173:        case UNOP:
        !           174:                prtype(p->in.type);
        !           175:                prtree(p->in.left);
        !           176:                printf(") ");
        !           177:                return;
        !           178:        case ARG:
        !           179:                prtree(p->in.left);
        !           180:                printf("%d) ", p->tn.rval);
        !           181:                return;
        !           182:        case EPILOG:
        !           183:                printf(" %d %d) ", p->tn.lval, p->tn.rval);
        !           184:                return;
        !           185:        case FLD:
        !           186:                printf(" %d %d ", p->tn.rval % 64, p->tn.rval / 64);
        !           187:                prtree(p->in.left);
        !           188:                printf(") ");
        !           189:                return;
        !           190:        case CALL:
        !           191:                prtype(p->in.type);
        !           192:                printf("%d ", p->stn.argsize/32);
        !           193:                prtree(p->in.left);
        !           194:                prtree(p->in.right);
        !           195:                printf(") ");
        !           196:                return;
        !           197:        case UCALL:
        !           198:                prtype(p->in.type);
        !           199:                prtree(p->in.left);
        !           200:                printf(") ");
        !           201:                return;
        !           202:        case FCON:
        !           203:                prtype(p->in.type);
        !           204:                printf("%g) ", p->fpn.dval);
        !           205:                return;
        !           206:        case GENBR:
        !           207:                printf(" %s L%d ", ar[opindex[p->bn.lop]].name, p->bn.label);
        !           208:                prtree(p->in.left);
        !           209:                printf(") ");
        !           210:                return;
        !           211:        case GENLAB:
        !           212:                prtype(p->in.type);
        !           213:                printf(" L%d ", p->bn.label);
        !           214:                prtree(p->in.left);
        !           215:                printf(") ");
        !           216:                return;
        !           217:        case GOTO:
        !           218:                printf(" L%d ", p->bn.label);
        !           219:                printf(") ");
        !           220:                return;
        !           221:        case ICON:
        !           222:                prtype(p->in.type);
        !           223:                if(p->tn.name)
        !           224:                        if(p->tn.lval)
        !           225:                                printf("%s+%d) ", p->tn.name, p->tn.lval);
        !           226:                        else
        !           227:                                printf("%s) ", p->tn.name);
        !           228:                else
        !           229:                        printf("%d) ", p->tn.lval);
        !           230:                return;
        !           231:        case VAUTO:
        !           232:                prtype(p->in.type);
        !           233:                printf("%d) ", p->tn.lval);
        !           234:                return;
        !           235:        case NAME:
        !           236:                prtype(p->in.type);
        !           237:                if(p->tn.lval)
        !           238:                        printf("%s+%d) ", p->tn.name, p->tn.lval);
        !           239:                else if(p->tn.name)
        !           240:                        printf("%s) ", p->tn.name);
        !           241:                else    if(p->tn.rval >= 0)
        !           242:                        printf("%s) ", stab[p->tn.rval].sname);
        !           243:                else
        !           244:                        printf("L%d) ", -p->tn.rval);
        !           245:                return;
        !           246:        case PROLOG:
        !           247:                prtype(p->in.type);
        !           248:                printf("%s %d) ", p->tn.name, p->tn.lval);
        !           249:                return;
        !           250:        case RETURN:
        !           251:                printf("%s) ", p->tn.name);
        !           252:                return;
        !           253:        case URETURN:
        !           254:                prtype(p->in.type);
        !           255:                printf("%s ", p->tn.name);
        !           256:                prtree(p->in.left);
        !           257:                return;
        !           258:        case SWCASE:
        !           259:                printf(" %d L%d) ", p->tn.lval, p->tn.rval);
        !           260:                return;
        !           261:        case SWDEF:
        !           262:                printf(" L%d) ", p->tn.rval);
        !           263:                return;
        !           264:        case SWEND:
        !           265:                printf(" %d %d) ", p->tn.lval, p->tn.rval);
        !           266:                return;
        !           267:        case STARG:
        !           268:                printf(" %d %d ", p->tn.rval, p->stn.stsize);
        !           269:                prtree(p->in.left);
        !           270:                printf(") ");
        !           271:                return;
        !           272:        case STASG:
        !           273:                printf(" %d ", p->stn.stsize);
        !           274:                prtree(p->in.left);
        !           275:                prtree(p->in.right);
        !           276:                printf(") ");
        !           277:                return;
        !           278:        case STCALL:
        !           279:                printf(" %d %d ", p->stn.stsize, p->stn.argsize);
        !           280:                prtree(p->in.left);
        !           281:                prtree(p->in.right);
        !           282:                printf(") ");
        !           283:                return;
        !           284:        case USTCALL:
        !           285:                printf("%d ", p->stn.stsize);
        !           286:                prtree(p->in.left);
        !           287:                printf(") ");
        !           288:                return;
        !           289:        case REG:
        !           290:                prtype(p->in.type);
        !           291:                printf("%d) ", p->tn.rval, p->tn.lval);
        !           292:                return;
        !           293:        }
        !           294: }
        !           295: prtype(n)
        !           296: {      char *s;
        !           297:        switch(n) {
        !           298:        default:
        !           299:                cerror("prtype(#%x)\n", n);
        !           300:        case TCHAR:     s = "C"; break;
        !           301:        case TUCHAR:    s = "UC"; break;
        !           302:        case TSHORT:    s = "S"; break;
        !           303:        case TUSHORT:   s = "US"; break;
        !           304:        case TINT:      s = "I"; break;
        !           305:        case TUNSIGNED: s = "U"; break;
        !           306:        case TLONG:     s = "L"; break;
        !           307:        case TULONG:    s = "UL"; break;
        !           308:        case TFLOAT:    s = "F"; break;
        !           309:        case TDOUBLE:   s = "D"; break;
        !           310:        case TSTRUCT:   s = "St"; break;
        !           311:        case TPOINT:    s = "P"; break;
        !           312:        }
        !           313:        printf("%s ", s);
        !           314: }
        !           315: myinit()
        !           316: {      int i;
        !           317:        for(i = 0; ar[i].name; i++)
        !           318:                opindex[ar[i].op] = i;
        !           319: }
        !           320: pjwend(p)
        !           321: NODE *p;
        !           322: {
        !           323:        if(bothdebug)
        !           324:                printf("#treeend\n");
        !           325: }

unix.superglobalmegacorp.com

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