Annotation of MiNT/src/trans.c, revision 1.1.1.2

1.1       root        1: /*
                      2: 
                      3:  * translation routines; sometimes we pass data on
                      4: 
                      5:  * through directly (asm syntax->asm syntax, with
                      6: 
                      7:  * some macro expansion), and other times we also
                      8: 
                      9:  * do asm syntax->gas syntax translation
                     10: 
                     11:  */
                     12: 
                     13: 
                     14: 
                     15: #include "asmtrans.h"
                     16: 
                     17: 
                     18: 
                     19: int syntax = GAS;
                     20: 
                     21: 
                     22: 
                     23: char *
                     24: 
                     25: immediate(op)
                     26: 
                     27:        char *op;
                     28: 
                     29: {
                     30: 
                     31:        return concat("#", op);
                     32: 
                     33: }
                     34: 
                     35: 
                     36: 
                     37: char *
                     38: 
                     39: indirect(op)
                     40: 
                     41:        char *op;
                     42: 
                     43: {
                     44: 
                     45:        if (syntax == GAS) {
                     46: 
                     47:                return concat(op, "@");
                     48: 
                     49:        } else {
                     50: 
                     51:                return concat3("(", op, ")");
                     52: 
                     53:        }
                     54: 
                     55: }
                     56: 
                     57: 
                     58: 
                     59: char *
                     60: 
                     61: postinc(op)
                     62: 
                     63:        char *op;
                     64: 
                     65: {
                     66: 
                     67:        if (syntax == GAS) {
                     68: 
                     69:                return concat(op, "@+");
                     70: 
                     71:        } else {
                     72: 
                     73:                return concat3("(", op, ")+");
                     74: 
                     75:        }
                     76: 
                     77: }
                     78: 
                     79: 
                     80: 
                     81: char *
                     82: 
                     83: predec(op)
                     84: 
                     85:        char *op;
                     86: 
                     87: {
                     88: 
                     89:        if (syntax == GAS) {
                     90: 
                     91:                return concat(op, "@-");
                     92: 
                     93:        } else {
                     94: 
                     95:                return concat3("-(", op, ")");
                     96: 
                     97:        }
                     98: 
                     99: }
                    100: 
                    101: 
                    102: 
                    103: char *
                    104: 
                    105: indexed(op1, op2)
                    106: 
                    107:        char *op1, *op2;
                    108: 
                    109: {
                    110: 
                    111:        if (syntax == GAS) {
                    112: 
                    113:                return concat4(op2, "@(", op1, ")");
                    114: 
                    115:        } else {
                    116: 
                    117:                return concat4(op1, "(", op2, ")");
                    118: 
                    119:        }
                    120: 
                    121: }
                    122: 
                    123: 
                    124: 
                    125: char *
                    126: 
                    127: sizedop(op, size)
                    128: 
                    129:        char *op, *size;
                    130: 
                    131: {
                    132: 
                    133:        if (syntax == GAS) {
                    134: 
                    135:                return changesiz(concat(op, size));
                    136: 
                    137:        } else {
                    138: 
                    139:                return concat4("(", op, ")", size);
                    140: 
                    141:        }
                    142: 
                    143: }
                    144: 
                    145: 
                    146: 
                    147: char *
                    148: 
                    149: twoindex(disp, base, index)
                    150: 
                    151:        char *disp, *base, *index;
                    152: 
                    153: {
                    154: 
                    155:        if (syntax == GAS) {
                    156: 
1.1.1.2 ! root      157:                return concat6(base, "@(", disp, ",", changesiz2(index), ")");
1.1       root      158: 
                    159:        } else {
                    160: 
                    161:                return concat6(disp, "(", base, ",", index, ")");
                    162: 
                    163:        }
                    164: 
                    165: }
                    166: 
                    167: 
                    168: 
                    169: char *
                    170: 
                    171: bitfield(op1, op2, op3)
                    172: 
                    173:        char *op1, *op2, *op3;
                    174: 
                    175: {
                    176: 
                    177:        if (syntax == GAS) {
                    178: 
                    179:                return concat6(op1, "{#", op2, ":#", op3, "}");
                    180: 
                    181:        } else {
                    182: 
                    183:                return concat6(op1, "{", op2, ":", op3, "}");
                    184: 
                    185:        }
                    186: 
                    187: }
                    188: 
                    189: 
                    190: 
                    191: char *
                    192: 
1.1.1.2 ! root      193: postindex(bd, an , index, od)
        !           194: 
        !           195:        char *bd, *an, *index , *od;
        !           196: 
        !           197: {
        !           198: 
        !           199:        if (syntax == GAS) {
        !           200: 
        !           201:                return concat8(an, "@(", bd, ")@(", od, ",", changesiz2(index), ")");
        !           202: 
        !           203:        } else {
        !           204: 
        !           205:                return concat9("([",an, ",", bd, "],", index, ",", od ,")");
        !           206: 
        !           207:        }
        !           208: 
        !           209: }
        !           210: 
        !           211: 
        !           212: 
        !           213: char *
        !           214: 
        !           215: postindex0(bd)
        !           216: 
        !           217:        char *bd;
        !           218: 
        !           219: {
        !           220: 
        !           221:        if (syntax == GAS) {
        !           222: 
        !           223:                return concat3("@(", bd, ")");
        !           224: 
        !           225:        } else {
        !           226: 
        !           227:                return concat3("([", bd, "])");
        !           228: 
        !           229:        }
        !           230: 
        !           231: }
        !           232: 
        !           233: 
        !           234: 
        !           235: char *
        !           236: 
        !           237: postindex1(bd,od)
        !           238: 
        !           239:        char *bd, *od;
        !           240: 
        !           241: {
        !           242: 
        !           243:        if (syntax == GAS) {
        !           244: 
        !           245:                return concat5("@(", bd, ")@(", od, ")");
        !           246: 
        !           247:        } else {
        !           248: 
        !           249:                return concat5("([", bd, "],", od, ")");
        !           250: 
        !           251:        }
        !           252: 
        !           253: }
        !           254: 
        !           255: 
        !           256: 
        !           257: char *
        !           258: 
        !           259: preindex(bd, an , index, od)
        !           260: 
        !           261:        char *bd, *an, *index , *od;
        !           262: 
        !           263: {
        !           264: 
        !           265:        if (syntax == GAS) {
        !           266: 
        !           267:                return concat8(an, "@(", bd, ",", changesiz2(index), ")@(", od, ")");
        !           268: 
        !           269:        } else {
        !           270: 
        !           271:                return concat9("([",an, ",", bd, ",", index, "],", od, ")");
        !           272: 
        !           273:        }
        !           274: 
        !           275: }
        !           276: 
        !           277: 
        !           278: 
        !           279: char *
        !           280: 
1.1       root      281: do_ops(label, opcode, space, operand)
                    282: 
                    283:        char *label, *opcode, *space, *operand;
                    284: 
                    285: {
                    286: 
                    287:        static char temp[LINSIZ];
                    288: 
                    289:        static char optemp[40];
                    290: 
                    291:        char *to, *from;
                    292: 
                    293:        char c;
                    294: 
                    295: 
                    296: 
                    297:        if (syntax == GAS) {
                    298: 
                    299:            if (!strcmp(opcode, "ds.l")) {
                    300: 
                    301:                strcpy(temp, "\t.even\n\t.comm");
                    302: 
                    303:                strcat(temp, space);
                    304: 
                    305:                strcat(temp, label);
                    306: 
                    307:                strcat(temp, ",");
                    308: 
                    309:                strcat(temp, "4*");
                    310: 
                    311:                strcat(temp, operand);
                    312: 
                    313:                return strdup(temp);
                    314: 
                    315:            } else if (!strcmp(opcode, "ds.w")) {
                    316: 
                    317:                strcpy(temp, "\t.even\n\t.comm");
                    318: 
                    319:                strcat(temp, space);
                    320: 
                    321:                strcat(temp, label);
                    322: 
                    323:                strcat(temp, ",");
                    324: 
                    325:                strcat(temp, "2*");
                    326: 
                    327:                strcat(temp, operand);
                    328: 
                    329:                return strdup(temp);
                    330: 
                    331:            } else if (!strcmp(opcode, "ds.b")) {
                    332: 
                    333:                strcpy(temp, "\t.comm");
                    334: 
                    335:                strcat(temp, space);
                    336: 
                    337:                strcat(temp, label);
                    338: 
                    339:                strcat(temp, ",");
                    340: 
                    341:                strcat(temp, operand);
                    342: 
                    343:                return strdup(temp);
                    344: 
                    345:            } else {
                    346: 
                    347:                to = optemp;
                    348: 
                    349:                from = opcode;
                    350: 
                    351:                for(;;) {
                    352: 
                    353:                        c = *from++;
                    354: 
                    355:                        if (!c) break;
                    356: 
                    357:        /* change 'foo.b' -> 'foob' */
                    358: 
                    359:        /* special case: bra.s -> 'bra', since gas automatically
                    360: 
                    361:         * selects offset sizes and since some gas's actually
                    362: 
                    363:         * mess up if an explicit '.s' is given
                    364: 
                    365:         */
                    366: 
                    367:                        if (c == '.' && *from && from[1] == 0) {
                    368: 
                    369:                                if (*from == 's') from++;
                    370: 
                    371:                                continue;
                    372: 
                    373:                        }
                    374: 
                    375:                        *to++ = c;
                    376: 
                    377:                }
                    378: 
                    379:                *to = 0;
                    380: 
                    381:                opcode = optemp;
                    382: 
                    383:            }
                    384: 
                    385:        }
                    386: 
                    387: 
                    388: 
                    389:        to = temp;
                    390: 
                    391: 
                    392: 
                    393:        if (*label) {
                    394: 
                    395:                int colonseen = 0;
                    396: 
                    397:                char c;
                    398: 
                    399: 
                    400: 
                    401:                for (from = label; (c = *from++) != 0;) {
                    402: 
                    403:                        if (c == ':') colonseen = 1;
                    404: 
                    405:                        *to++ = c;
                    406: 
                    407:                }
                    408: 
                    409: /* gas labels must have a ':' after them */
                    410: 
                    411:                if (!colonseen && syntax == GAS)
                    412: 
                    413:                        *to++ = ':';
                    414: 
                    415:        }
                    416: 
                    417: 
                    418: 
                    419:        *to++ = '\t';
                    420: 
                    421:        strcpy(to, opcode);
                    422: 
                    423:        strcat(temp, space);
                    424: 
                    425:        strcat(temp, operand);
                    426: 
                    427:        return strdup(temp);
                    428: 
                    429: }
                    430: 
                    431: 
                    432: 
                    433: char *
                    434: 
                    435: changesiz(op)
                    436: 
                    437:        char *op;
                    438: 
                    439: {
                    440: 
                    441:        char *r = op;
                    442: 
                    443: 
                    444: 
                    445:        if (syntax != GAS) return op;
                    446: 
                    447: 
                    448: 
                    449:        while (*op) {
                    450: 
                    451:                if (*op == '.') *op = ':';
                    452: 
                    453:                op++;
                    454: 
                    455:        }
                    456: 
                    457:        return r;
                    458: 
                    459: }
                    460: 
                    461: 
                    462: 
                    463: char *
                    464: 
1.1.1.2 ! root      465: changesiz2(op)         /* rw: hack for scaled index    */
        !           466: 
        !           467:        char *op;
        !           468: 
        !           469: {
        !           470: 
        !           471:        char *r = op;
        !           472: 
        !           473: 
        !           474: 
        !           475:        if (syntax != GAS) return op;
        !           476: 
        !           477: 
        !           478: 
        !           479:        while (*op) {
        !           480: 
        !           481:                if (*op == '.' || *op == '*' ) *op = ':';
        !           482: 
        !           483:                op++;
        !           484: 
        !           485:        }
        !           486: 
        !           487:        return r;
        !           488: 
        !           489: }
        !           490: 
        !           491: 
        !           492: 
        !           493: char *
        !           494: 
1.1       root      495: hexop(op)
                    496: 
                    497:        char *op;
                    498: 
                    499: {
                    500: 
                    501:        if (syntax == GAS)
                    502: 
                    503:                return concat("0x", op);
                    504: 
                    505:        else
                    506: 
                    507:                return concat("$", op);
                    508: 
                    509: }
                    510: 

unix.superglobalmegacorp.com

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