Annotation of coherent/b/bin/c/n3/cc3.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * n3/cc3.c
                      3:  * Print out C compiler intermediate language files.
                      4:  * It is a machine dependent program,
                      5:  * but most, if not all, of the machine dependencies are in tables.
                      6:  * It understands all favours of intermediate files;
                      7:  * that is, it understands both trees and CODE nodes!
                      8:  */
                      9: 
                     10: #ifdef vax
                     11: #include "INC$LIB:cc3.h"
                     12: #else
                     13: #include "cc3.h"
                     14: #endif
                     15: 
                     16: /*
                     17:  * Possibly impure areas.
                     18:  * All external impure data is here
                     19:  * and is reinitialized by the overlaid version of the mainline.
                     20:  * This permits the compiler to be called many times if loaded
                     21:  * as one big block.
                     22:  */
                     23: #if    !OVERLAID
                     24: int    line;           /* Source line */
                     25: int    dotseg;         /* Current segment */
                     26: char   file[NFNAME];   /* Source file name */
                     27: char   id[NCSYMB];     /* Identifier buffer */
                     28: FILE   *ifp;           /* Input file pointer */
                     29: FILE   *ofp;           /* Output file pointer */
                     30: VARIANT        variant;        /* Variant template */
                     31: #endif
                     32: 
                     33: extern char    *segnames[];
                     34: /*
                     35:  * Temp. file opcodes.
                     36:  */
                     37: char   *ilonames[] = {
                     38:        0,
                     39:        "file name",
                     40:        0,
                     41:        0,
                     42:        "global label",
                     43:        "static label",
                     44:        "block",
                     45:        "prolog",
                     46:        "epilog",
                     47:        0,
                     48:        0,
                     49:        0,
                     50:        0,
                     51:        "line number",
                     52:        "return expression",
                     53:        "effect expression",
                     54:        "switch expression",
                     55:        "switch body",
                     56:        "initialization expression",
                     57:        "initialize absolute block",
                     58:        0,
                     59:        "jump if true",
                     60:        "jump if false",
                     61:        0,      /* ENTER */
                     62:        "module name",
                     63:        0,      /* COMM */
                     64:        "",     /* DLOCAT */
                     65:        "",     /* DLABEL */
                     66:        "segment guess",
                     67:        "undefined reference"
                     68: };
                     69: 
                     70: #if    !OVERLAID
                     71: main(argc, argv)
                     72: char   *argv[];
                     73: {
                     74:        passname = "cc3";
                     75:        if (argc < 3)
                     76:                usage();
                     77:        getvariant(argv[1]);
                     78: #if GEMDOS
                     79:        {
                     80:                extern long gemdos();
                     81:                extern char *lmalloc();
                     82:                free(lmalloc((gemdos(0x48,-1L)-4096) & ~1023L));
                     83:        }
                     84: #endif
                     85:        if ((ifp=fopen(argv[2], SRMODE)) == NULL) {
                     86:                fprintf(stderr, "%s: cannot open.\n", argv[2]);
                     87:                exit(BAD);
                     88:        }
                     89:        if (argc == 4) {
                     90:                if ((ofp=fopen(argv[3], "w")) == NULL) {
                     91:                        fprintf(stderr, "%s: cannot create.\n", argv[3]);
                     92:                        exit(BAD);
                     93:                }
                     94:        } else {
                     95:                ofp = stdout;
                     96:        }
                     97:        dotseg = -1;
                     98:        exit(work3());
                     99: }
                    100: 
                    101: usage()
                    102: {
                    103:        fprintf(stderr, "Usage: cc3 variant input [output]\n");
                    104:        exit(BAD);
                    105: }
                    106: 
                    107: #else
                    108: /*
                    109:  * This is the mainline of the intermediate interpreter
                    110:  * if the compiler is being run as an overlay job.
                    111:  * The impure area must be reinitialized if monolithic
                    112:  * because the code can be called over and over again.
                    113:  */
                    114: cc3()
                    115: {
                    116:        passname = "cc3";
                    117:        if (setjmp(death) != 0) {
                    118:                return (ABORT);
                    119:        }
                    120:        dotseg = -1;
                    121: #if    MONOLITHIC
                    122:        line = 0;
                    123: #endif
                    124:        return (work3());
                    125: }
                    126: #endif
                    127: 
                    128: /*
                    129:  * This is the nuts and bolts of the operation.
                    130:  */
                    131: work3()
                    132: {
                    133:        register int    op;
                    134:        register long   ifseek;
                    135: 
                    136:        cc3init();
                    137:        for (;;) {
                    138: #if    TEMPBUF
                    139:                ifseek = (ifp == NULL) ? inbufp - inbuf : ftell(ifp);
                    140: #else
                    141:                ifseek = ftell(ifp);
                    142: #endif
                    143:                if ((op=bget())==EOF || op==FINISH) {
                    144:                        cc3close();
                    145:                        break;
                    146:                }
                    147:                if (notvariant(VASM))
                    148:                        fprintf(ofp, "%ld:\t", ifseek);
                    149:                switch (op) {
                    150: 
                    151:                case FNAME:
                    152:                case MNAME:
                    153:                case GLABEL:
                    154:                case SLABEL:
                    155:                case UREFER:
                    156:                        sget(id, NCSYMB);
                    157:                        if (isvariant(VASM))
                    158:                                genname(op, id);
                    159:                        else {
                    160:                                fprintf(ofp, "\t%s\t%s\n", ilonames[op], id);
                    161:                                if (op==GLABEL || op==SLABEL)
                    162:                                        fprintf(ofp, "\t%s:\n", id);
                    163:                        }
                    164:                        break;
                    165: 
                    166:                case LLABEL:
                    167:                        if (isvariant(VASM))
                    168:                                genival(op, (long)iget());
                    169:                        else
                    170:                                fprintf(ofp, "L" I_FMT ":\n", iget());
                    171:                        break;
                    172: 
                    173:                case LINE:
                    174:                        line = iget();
                    175:                        if (isvariant(VASM))
                    176:                                genival(op, (long)line);
                    177:                        else
                    178:                                fprintf(ofp, "\t%s\t%d\n", ilonames[op], line);
                    179:                        break;
                    180: 
                    181:                case BLOCK:
                    182:                        if (isvariant(VASM))
                    183:                                genival(op, (long)zget());
                    184:                        else
                    185:                                fprintf(ofp, "%s\t%ld\n",
                    186:                                        ilonames[op], (long)zget());
                    187:                        break;
                    188: 
                    189:                case DLOCAT:
                    190:                        cc3dloc();
                    191:                        break;
                    192:                case DLABEL:
                    193:                        cc3dbug(1);
                    194:                        break;
                    195: 
                    196:                case PROLOG:
                    197:                case EPILOG:
                    198:                        fprintf(ofp, "\t%s\n", ilonames[op]);
                    199:                        break;
                    200: 
                    201:                case AUTOS:
                    202:                        genautos();
                    203:                        break;
                    204: 
                    205:                case JUMP:
                    206:                        fprintf(ofp, "\tjump\tL" I_FMT "\n", iget());
                    207:                        break;
                    208: 
                    209:                case COMM:
                    210:                        gencomm();
                    211:                        break;
                    212: 
                    213:                case ENTER:
                    214:                        if (isvariant(VASM))
                    215:                                genival(op, (long)bget());
                    216:                        else
                    217:                                fprintf(ofp, "\tenter %s\n", segnames[bget()]);
                    218:                        break;
                    219: 
                    220:                case ALIGN:
                    221:                        if (isvariant(VASM))
                    222:                                genival(op, (long)bget());
                    223:                        else
                    224:                                fprintf(ofp, "\talign %d\n", bget());
                    225:                        break;
                    226: 
                    227:                case SBODY:
                    228:                {
                    229:                        register ival_t deflab, ncases, cvalue, clabel;
                    230: 
                    231:                        deflab = iget();
                    232:                        ncases = iget();
                    233:                        fprintf(ofp, "%s\n", ilonames[op]);
                    234:                        while (ncases--) {
                    235:                                cvalue = iget();
                    236:                                clabel = iget();
                    237:                                fprintf(ofp, "\t\t" I_FMT "\tL" I_FMT "\n", cvalue, clabel);
                    238:                        }
                    239:                        fprintf(ofp, "\t\tdef\tL" I_FMT "\n", deflab);
                    240:                        break;
                    241:                }
                    242: 
                    243:                case IBLOCK:
                    244:                {
                    245:                        register int firstb, nitems;
                    246: 
                    247:                        fprintf(ofp, "byte block\t");
                    248:                        nitems = bget();
                    249:                        firstb = 0;
                    250:                        while (nitems--) {
                    251:                                if (firstb++ != 0)
                    252:                                        fprintf(ofp, " ");
                    253:                                fprintf(ofp, "%d", bget());
                    254:                        }
                    255:                        fprintf(ofp, "\n");
                    256:                        break;
                    257:                }
                    258: 
                    259:                case REXPR:
                    260:                case SEXPR:
                    261:                case TEXPR:
                    262:                case FEXPR:
                    263:                case IEXPR:
                    264:                case EEXPR:
                    265:                        itree(op);
                    266:                        break;
                    267: 
                    268:                case CODE:
                    269:                        icode();
                    270:                        break;
                    271: 
                    272:                case EOF:
                    273:                        cfatal("unexpected EOF");
                    274: 
                    275:                default:
                    276:                        cbotch("bad temporary file opcode %d", op);
                    277:                }
                    278:        }
                    279:        if (op != FINISH)
                    280:                cfatal("unexpected EOF");
                    281:        return (OK);
                    282: }
                    283: 
                    284: /* end of n3/cc3.c */

unix.superglobalmegacorp.com

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