⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 outi.c

📁 CC386 is a general-purpose 32-bit C compiler. It is not an optimizing compiler but given that the co
💻 C
📖 第 1 页 / 共 3 页
字号:

static void op_block(QUAD *q)
{
    oprintf(outputFile, "\tBLOCK\t%d", q->dc.label + 1);
}

//-------------------------------------------------------------------------

static void op_livein(QUAD *q)
{
    DIAG("op_livein: propogated live-in node");
}

//-------------------------------------------------------------------------

static void op_icon(QUAD *q)
{
    fputc('\t', outputFile);
    putamode(q->ans);
    oprintf(outputFile, " = #%lX", q->dc.v.i);
}

//-------------------------------------------------------------------------

static void op_fcon(QUAD *q)
{
    fputc('\t', outputFile);
    putamode(q->ans);
    oprintf(outputFile, " = #%f", q->dc.v.f);
}

/* List of opcodes
 * This list MUST be in the same order as the op_ enums 
 */
static void(*oplst[])() = 
{
     /* NOPROTO */
    op_line, op_passthrough, op_label, op_goto, op_gosub, op_trap, op_int,
        op_ret, op_rett, op_add, op_sub, op_udiv, op_umod, op_sdiv, op_smod,
        op_umul, op_smul, op_lsl, op_lsr, op_asl, op_asr, op_neg, op_not,
        op_and, op_or, op_eor, op_setne, op_sete, op_setc, op_seta, op_setnc,
        op_setbe, op_setl, op_setg, op_setle, op_setge, op_assn, op_genword,
        op_coswitch, op_dc, op_assnblock, op_jc, op_ja, op_je, op_jnc, op_jbe,
        op_jne, op_jl, op_jg, op_jle, op_jge, op_parm, op_parmadj, op_parmblock,
        op_cppini, op_block, op_livein, op_icon, op_fcon 

};
void putsym(char *buf, SYM *sp, char *p)
{
    int done = 0;
    if (!p)
    {
        buf[0] = 0;
        return ;
    }
    if (sp->staticlabel)
        sprintf(buf, "L_%d", sp->value.i);
    else if (sp->alias)
        strcpy(buf, sp->alias);
    else
    {
        if (sp->pascaldefn)
        {
            char *q = buf;
            if (prm_cmangle)
                p++;
            while (*p)
                *q++ = toupper(*p++);
            *q = 0;
        }
        else if (sp->isstdcall)
        {
            if (prm_cmangle)
                p++;
            strcpy(buf, p);
        }
        else
        {
            char *q;
            if (sp->mangled && !(sp->tp->type == bt_func || sp->tp->type ==
                bt_ifunc))
            {
                q = dumpns(sp->value.classdata.parentns, buf, &done);
                if (done)
                {
                    *q++ = '@';
                    strcpy(q, p + prm_cmangle);
                }
                else
                    strcpy(q, p);
            }
            else
                strcpy(buf, p);
            if (prm_cplusplus && prm_asmfile && !prm_nasm)
            {
                // problematic for compiling templates via ASM and TASM
                q = buf;
                while (q = strchr(q, '#'))
                    *q = '%';
            }
        }
    }
}

//-------------------------------------------------------------------------

void putconst(ENODE *offset)
/*
 *      put a constant to the outputFile file.
 */
{
    switch (offset->nodetype)
    {
        case en_icon:
        case en_lcon:
        case en_iucon:
        case en_lucon:
        case en_ccon:
        case en_boolcon:
        case en_cucon:
            oprintf(outputFile, "%lX", offset->v.i);
            break;
        case en_llcon:
        case en_llucon:
            oprintf(outputFile, "%llX", offset->v.i);
            break;
        case en_fcon:
        case en_rcon:
        case en_lrcon:
        case en_fimaginarycon:
        case en_rimaginarycon:
        case en_lrimaginarycon:
            oprintf(outputFile, "%e", offset->v.f);
			break;
        case en_tempref:
            oprintf(outputFile, "TEMP%d", ((SYM*)offset->v.p[0])->value.i);
            break;
        case en_autoreg:
            oprintf(outputFile, "%s:REG", ((SYM*)offset->v.sp)->name);
            break;
        case en_autocon:
            oprintf(outputFile, "%s:LINK", ((SYM*)offset->v.sp)->name);
            break;
        case en_nalabcon:
            oprintf(outputFile, "L_%ld:RAM", offset->v.sp->value.i);
            break;
        case en_labcon:
            oprintf(outputFile, "L_%ld:PC", offset->v.i);
            break;
        case en_napccon:
            oprintf(outputFile, "%s:PC", ((SYM*)offset->v.sp)->name);
            break;
        case en_nacon:
            oprintf(outputFile, "%s:RAM", ((SYM*)offset->v.sp)->name);
            break;
        case en_absacon:
            oprintf(outputFile, "$%lX:ABS", ((SYM*)offset->v.sp)->name);
            break;
        case en_add:
            putconst(offset->v.p[0]);
            oprintf(outputFile, "+");
            putconst(offset->v.p[1]);
            break;
        case en_sub:
            putconst(offset->v.p[0]);
            oprintf(outputFile, "-");
            putconst(offset->v.p[1]);
            break;
        case en_uminus:
            fputc('-', outputFile);
            putconst(offset->v.p[0]);
            break;
        default:
            DIAG("putconst: illegal constant node.");
            break;
    }
}

//-------------------------------------------------------------------------

void putlen(int l)
/*
 *      append the length field to a value
 */
{
    switch (l)
    {
        case BESZ_NONE:
            oprintf(outputFile, ".0");
            break;
		case BESZ_FARPTR:
			oprintf(outputFile, ".FAR");
			break ;
        case BESZ_BOOL:
            oprintf(outputFile, ".BOOL");
            break;
        case BESZ_BYTE:
            oprintf(outputFile, ".UB");
            break;
            case  - BESZ_BYTE: oprintf(outputFile, ".B");
            break;
        case BESZ_SHORT:
            oprintf(outputFile, ".UW");
            break;
            case  - BESZ_SHORT: oprintf(outputFile, ".W");
            break;
        case BESZ_DWORD:
            oprintf(outputFile, ".UL");
            break;
            case  - BESZ_DWORD: oprintf(outputFile, ".L");
            break;
        case BESZ_QWORD:
            oprintf(outputFile, ".ULL");
            break;
        case  - BESZ_QWORD: oprintf(outputFile, ".LL");
            break;
        case BESZ_FLOAT:
            oprintf(outputFile, ".S");
            break;
        case BESZ_DOUBLE:
            oprintf(outputFile, ".D");
            break;
        case BESZ_LDOUBLE:
            oprintf(outputFile, ".X");
            break;
        case BESZ_IFLOAT:
            oprintf(outputFile, ".SI");
            break;
        case BESZ_IDOUBLE:
            oprintf(outputFile, ".DI");
            break;
        case BESZ_ILDOUBLE:
            oprintf(outputFile, ".XI");
            break;
        default:
            DIAG("putlen: illegal length field.");
            break;
    }
}

//-------------------------------------------------------------------------

void putamode(IMODE *ap)
/*
 *      output a general addressing mode.
 */
{
    /* We want to see if the compiler does anything wrong with
     * volatiles
     */
    if (ap->offset && ap->offset->cflags &DF_VOL)
        fputc('%', outputFile);
    switch (ap->mode)
    {
        case i_immed:
            fputc('#', outputFile);
            putconst(ap->offset);
            break;
        case i_ind:
            fputc('*', outputFile);
        case i_direct:
            putconst(ap->offset);
            break;
        case i_rsp:
            oprintf(outputFile, "SP");
            break;
        case i_rret:
            oprintf(outputFile, "RV");
            break;
        case i_rlink:
            oprintf(outputFile, "LINK");
            break;
        case i_rstruct:
            oprintf(outputFile, "STRUCTRET");
            return ;
        case i_rstructstar:
            oprintf(outputFile, "*STRUCTRET");
            return ;
        default:
            DIAG("putamode: illegal address mode.");
            break;
    }
    if (ap->bits)
        oprintf(outputFile, "{%d:%d}", ap->startbit, ap->bits);
    putlen(ap->size);
}

//-------------------------------------------------------------------------

void put_code(QUAD *q)
/*
 *      output a generic instruction.
 */
{
    if (!prm_asmfile)
        return ;
    (*oplst[q->dc.opcode])(q);
    fputc('\n', outputFile);
}

/*
 * Low level routinne to rewrite code for processor and dump it.
 * Here we only need dump
 */
void rewrite_icode(void)
{
    QUAD *q = intermed_head;
    while (q)
    {
        put_code(q);
        q = q->fwd;
    }
    intermed_head = 0;
}

//-------------------------------------------------------------------------

void gen_strlab(SYM *sp)
/*
 *      generate a named label.
 */
{
    char buf[100];
    putsym(buf, sp, sp->name);
    if (prm_asmfile)
        oprintf(outputFile, "%s:\n", buf);
    dataofs = 0;
}

//-------------------------------------------------------------------------

void put_label(int lab)
/*
 *      outputFile a compiler generated label.
 */
{
    sprintf(dataname, "L_%d", lab);
    if (prm_asmfile)
        oprintf(outputFile, "%s:\n", dataname);
    dataofs = 0;
}

//-------------------------------------------------------------------------

void put_staticlabel(long label)
{
    put_label(label);
}

//-------------------------------------------------------------------------

void genfloat(float val)
/*
 * Output a float value
 */
{
    if (prm_asmfile)
    if (gentype == floatgen && outcol < 60)
    {
        oprintf(outputFile, ",%f", val);
        outcol += 8;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.S\t%f", val);
        gentype = floatgen;
        outcol = 19;
    }
    dataofs += 4;
}

//-------------------------------------------------------------------------

void gendouble(double val)
/*
 * Output a double value
 */
{
    if (prm_asmfile)
    if (gentype == doublegen && outcol < 60)
    {
        oprintf(outputFile, ",%f", val);
        outcol += 8;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.D\t%f", val);
        gentype = doublegen;
        outcol = 19;
    }
    dataofs += 8;
}

//-------------------------------------------------------------------------

void genlongdouble(long double val)
/*
 * Output a double value
 */
{
    if (prm_asmfile)
    if (gentype == longdoublegen && outcol < 60)
    {
        oprintf(outputFile, ",%f", val);
        outcol += 8;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.X\t%f", val);
        gentype = longdoublegen;
        outcol = 19;
    }
    dataofs += 8;
}

//-------------------------------------------------------------------------

void genbyte(long val)
/*
 * Output a byte value
 */
{
    if (prm_asmfile)
    if (gentype == bytegen && outcol < 60)
    {
        oprintf(outputFile, ",$%X", val &0x00ff);
        outcol += 4;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.B\t$%X", val &0x00ff);
        gentype = bytegen;
        outcol = 19;
    }
    dataofs += 1;
}

//-------------------------------------------------------------------------

void genword(long val)
/*
 * Output a word value
 */
{
    if (prm_asmfile)
    if (gentype == wordgen && outcol < 58)
    {
        oprintf(outputFile, ",$%X", val &0x0ffff);
        outcol += 6;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.W\t$%X", val &0x0ffff);
        gentype = wordgen;
        outcol = 21;
    }
    dataofs += 2;
}

//-------------------------------------------------------------------------

void genlong(long val)
/*
 * Output a long value
 */
{
    if (prm_asmfile)
    if (gentype == longgen && outcol < 56)
    {
        oprintf(outputFile, ",$%lX", val);
        outcol += 10;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.L\t$%lX", val);
        gentype = longgen;
        outcol = 25;
    }
    dataofs += 4;
}

//-------------------------------------------------------------------------

void genlonglong(LLONG_TYPE val)
/*
 * Output a long value
 */
{
    if (prm_asmfile)
    if (gentype == longgen && outcol < 56)
    {
        #ifdef BCC32
            oprintf(outputFile, "\tDC.L\t0%lXH,0%lXH", val, val < 0 ?  - 1: 0);
        #else 
            oprintf(outputFile, "\tDC.L\t0%lXH,0%lXH", val, val >> 32);
        #endif 
        outcol += 10;
    }
    else
    {
        nl();
        #ifdef BCC32
            oprintf(outputFile, "\tDC.L\t0%lXH,0%lXH", val, val < 0 ?  - 1: 0);
        #else 
            oprintf(outputFile, "\tDC.L\t0%lXH,0%lXH", val, val >> 32);
        #endif 
        gentype = longgen;
        outcol = 25;
    }
}
void genlong(int val)
{
    if (prm_asmfile)
    if (gentype == longgen && outcol < 56)
    {
        oprintf(outputFile, ",$%lX", val);
        outcol += 10;
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.I\t$%lX", val);
        gentype = longgen;
        outcol = 25;
    }
    dataofs += 4;
}
//-------------------------------------------------------------------------

void genaddress(char *string)
/*
 * Output a long value
 */
{
    if (prm_asmfile)
    if (gentype == longgen && outcol < 56)
    {
        oprintf(outputFile, ",%s", string);
        outcol += strlen(string);
    }
    else
    {
        nl();
        oprintf(outputFile, "\tDC.A\t%s", string);
        gentype = longgen;
        outcol = 25;
    }
    dataofs += 4;
}

//-------------------------------------------------------------------------

void gensrref(char *name, int val)
/*
 * Output a startup/rundown reference
 */
{
    if (prm_asmfile)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -