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

1.1       root        1: /*
                      2:  * C compiler - intermediate file printer.
                      3:  *     machine and assembly format dependent output routines.
                      4:  */
                      5: #ifdef vax
                      6: #include "INC$LIB:cc3.h"
                      7: #else
                      8: #include "cc3.h"
                      9: #endif
                     10: 
                     11: /*
                     12:  * How to enter or leave a segment.
                     13:  */
                     14: char   *seg_enter[] = {
                     15: #if AS_FORMAT
                     16:        ".shri",
                     17:        ".prvi",
                     18:        ".shrd",
                     19:        ".strn",
                     20:        ".prvd",
                     21:        ".bssd"
                     22: #else
                     23:        "code",
                     24:        "linkage",
                     25:        "pure",
                     26:        "strings",
                     27:        "impure",
                     28:        "bss"
                     29: #endif
                     30: };
                     31: 
                     32: char   *seg_leave[] = {
                     33:        NULL,
                     34:        NULL,
                     35:        NULL,
                     36:        NULL,
                     37:        NULL,
                     38:        NULL
                     39: };
                     40: 
                     41: /*
                     42:  * Process AUTOS items.
                     43:  * The opcode byte has been read.
                     44:  * Read in whatever operands are used by the
                     45:  * target machine and print them out in a nice
                     46:  * way. The registers on the 8086 are named.
                     47:  */
                     48: genautos()
                     49: {
                     50:        register int    numauto;
                     51:        register int    regmask;
                     52:        register int    reg;
                     53:        register int    sepchar;
                     54: 
                     55:        numauto = iget();
                     56:        regmask = iget();
                     57:        fprintf(ofp, "\tautos\t%d", numauto);
                     58:        sepchar = '\t';
                     59:        for (reg=AX; reg<=DS; ++reg) {
                     60:                if ((regmask&01) != 0) {
                     61:                        fprintf(ofp, "%c%s", sepchar, regnames[reg]);
                     62:                        sepchar = ' ';
                     63:                }
                     64:                regmask >>= 1;
                     65:        }
                     66:        fprintf(ofp, "\n");
                     67: }
                     68: 
                     69: /*
                     70:  * Output a double value.
                     71:  */
                     72: gendval(dp)
                     73: register dval_t        dp;
                     74: {
                     75:        register int i;
                     76: 
                     77:        for (i = 0; i < sizeof(dval_t); i += 1)
                     78:                fprintf(ofp, "%02x", dp[i] & 0377);
                     79: }
                     80: 
                     81: /*
                     82:  * Generate a machine dependent leaf node.
                     83:  */
                     84: genmdl(op)
                     85: {
                     86:        cbotch("bad mdl: %d", op);
                     87: }
                     88: 
                     89: /*
                     90:  * Generate a machine dependent operator node.
                     91:  */
                     92: genmdo(op)
                     93: {
                     94:        cbotch("bad mdo: %d", op);
                     95: }
                     96: 
                     97: /*
                     98:  * Generat a .comm record.
                     99:  * The operands must be read.
                    100:  */
                    101: gencomm()
                    102: {
                    103:        sget(id, NCSYMB);
                    104:        if (isvariant(VASM))
                    105: #if AS_FORMAT
                    106:                fprintf(ofp, "\t.comm\t");
                    107: #else
                    108:                fprintf(ofp, "%s\tcommon\t", CMTSTR);
                    109: #endif
                    110:        else
                    111:                fprintf(ofp, "common\t");
                    112:        fprintf(ofp, "%s\t%ld\n", id, (long)zget());
                    113: }
                    114: 
                    115: /*
                    116:  * Generate an assembly operator involving a name.
                    117:  */
                    118: genname(op, id)
                    119: char *id;
                    120: {
                    121:        switch (op) {
                    122:        case FNAME:
                    123:                fprintf(ofp, "%s\tfile name %s\n", CMTSTR, id);
                    124:                break;
                    125:        case MNAME:
                    126: #if AS_FORMAT
                    127:                fprintf(ofp, "%s\tmodule name %s\n", CMTSTR, id);
                    128: #else
                    129:                fprintf(ofp, "\tname %s\n", id);
                    130: #endif
                    131:                break;
                    132:        case GLABEL:
                    133: #if AS_FORMAT
                    134:                fprintf(ofp, "\t.globl %s\n%s:\n", id, id);
                    135: #else
                    136:                fprintf(ofp, "\tpublic %s\n%s:\n", id, id);
                    137: #endif
                    138:                break;
                    139:        case SLABEL:
                    140:                fprintf(ofp, "%s:\n", id);
                    141:                break;
                    142: #ifdef UREFER
                    143:        case UREFER:
                    144:                fprintf(ofp, "%s\tundefined reference %s\n", CMTSTR, id);
                    145:                break;
                    146: #endif
                    147:        default:
                    148:                cbotch("genname: bad op: %d", op);
                    149:        }
                    150: }
                    151: 
                    152: /*
                    153:  * Generate an assembly operator involving an integer value.
                    154:  */
                    155: genival(op, i)
                    156: long i;
                    157: {
                    158:        register char *s;
                    159: 
                    160:        switch (op) {
                    161:        case LINE:
                    162:                fprintf(ofp, "%s\tline number %ld\n", CMTSTR, i);
                    163:                break;
                    164:        case BLOCK:
                    165: #if AS_FORMAT
                    166:                fprintf(ofp, "\t.blkb\t0x%lx\n", i);
                    167: #else
                    168:                fprintf(ofp, "\tdb\t0%lxh dup(0)\n", i);
                    169: #endif
                    170:                break;
                    171:        case ALIGN:
                    172: #if AS_FORMAT
                    173:                fprintf(ofp, "\t.even\n");
                    174: #else
                    175:                fprintf(ofp, "\teven\n");
                    176: #endif
                    177:                break;
                    178:        case ENTER:
                    179:                if (dotseg >= 0 && (s=seg_leave[dotseg]) != NULL)
                    180:                        fprintf(ofp, "\n\t%s\n\n", s);
                    181:                dotseg = i;
                    182:                if (dotseg >= 0 && (s=seg_enter[dotseg]) != NULL)
                    183:                        fprintf(ofp, "\n\t%s\n\n", s);
                    184:                break;
                    185:        case LLABEL:
                    186:                fprintf(ofp, "L%ld:\n", i);
                    187:                break;
                    188:        default:
                    189:                cbotch("genival: bad op: %d", op);
                    190:        }
                    191: }

unix.superglobalmegacorp.com

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