Refactor OptPass5.CC

This commit is contained in:
TomAwezome 2020-07-26 09:24:16 -05:00 committed by VoidNV
parent 844f8f2405
commit eb11ecc6e2
3 changed files with 81 additions and 65 deletions

View file

@ -7,42 +7,52 @@ U0 OptPass5(CCompCtrl *cc)
ps->ptr2 = 0; ps->ptr2 = 0;
tmpi = cc->coc.coc_head.next; tmpi = cc->coc.coc_head.next;
while (code=tmpi->ic_code) { while (code = tmpi->ic_code)
if (code>IC_NOP2) { {
if (code >IC_NOP2)
{
if (tmpi->ic_flags&ICF_PASS_TRACE) { if (tmpi->ic_flags&ICF_PASS_TRACE) {
if (Bt(&cc->saved_pass_trace,5)) { if (Bt(&cc->saved_pass_trace, 5))
{
"%2d:", ps->ptr; "%2d:", ps->ptr;
ICPut(cc, tmpi); ICPut(cc, tmpi);
} }
} }
if (intermediate_code_table[code].arg_count == IS_V_ARG) if (intermediate_code_table[code].arg_count == IS_V_ARG)
ps->ptr -= tmpi->ic_data >> 3; ps->ptr -= tmpi->ic_data >> 3;
if (code==IC_PUSH_REGS) { if (code == IC_PUSH_REGS)
{
for (i = 0; i < REG_REGS_NUM; i++) for (i = 0; i < REG_REGS_NUM; i++)
if (Bt(&tmpi->ic_data, i)) if (Bt(&tmpi->ic_data, i))
ps->ptr++; ps->ptr++;
} else if (code==IC_POP_REGS) { }
else if (code == IC_POP_REGS)
{
for (i = 0; i < REG_REGS_NUM; i++) for (i = 0; i < REG_REGS_NUM; i++)
if (Bt(&tmpi->ic_data, i)) if (Bt(&tmpi->ic_data, i))
ps->ptr--; ps->ptr--;
} }
if (tmpi->arg2.type&MDF_STACK) { if (tmpi->arg2.type & MDF_STACK)
{
tmpi1 = ParsePop(ps); tmpi1 = ParsePop(ps);
if (tmpi1->ic_code==IC_MOV || tmpi1->ic_code==IC_REG) { if (tmpi1->ic_code == IC_MOV || tmpi1->ic_code == IC_REG)
if (tmpi1->ic_flags & ICF_RES_TO_INT) { {
if (tmpi1->ic_flags & ICF_RES_TO_INT)
{
if (tmpi1->arg1.type & MDF_IMM) if (tmpi1->arg1.type & MDF_IMM)
tmpi1->arg1.disp = tmpi1->arg1.disp(F64); tmpi1->arg1.disp = tmpi1->arg1.disp(F64);
else else
tmpi->ic_flags |= ICF_ARG2_TO_INT; tmpi->ic_flags |= ICF_ARG2_TO_INT;
} else if (tmpi1->ic_flags&ICF_RES_TO_F64) { }
else if (tmpi1->ic_flags & ICF_RES_TO_F64)
{
if (tmpi1->arg1.type & MDF_IMM) if (tmpi1->arg1.type & MDF_IMM)
tmpi1->arg1.disp(F64) = tmpi1->arg1.disp; tmpi1->arg1.disp(F64) = tmpi1->arg1.disp;
else else
tmpi->ic_flags |= ICF_ARG2_TO_F64; tmpi->ic_flags |= ICF_ARG2_TO_F64;
} }
tmpi->arg2.type = tmpi1->arg1.type & MDG_MASK + tmpi->arg2.type = tmpi1->arg1.type & MDG_MASK +
MinI64(tmpi->arg2.type.raw_type, MinI64(tmpi->arg2.type.raw_type, MinI64(tmpi1->res.type.raw_type, tmpi1->arg1.type.raw_type));
MinI64(tmpi1->res.type.raw_type,tmpi1->arg1.type.raw_type));
tmpi->arg2.reg = tmpi1->arg1.reg; tmpi->arg2.reg = tmpi1->arg1.reg;
tmpi->arg2.disp = tmpi1->arg1.disp; tmpi->arg2.disp = tmpi1->arg1.disp;
tmpi->ic_flags |= tmpi1->ic_flags & ICG_NO_CONVERT_MASK; tmpi->ic_flags |= tmpi1->ic_flags & ICG_NO_CONVERT_MASK;
@ -50,26 +60,32 @@ U0 OptPass5(CCompCtrl *cc)
} }
} }
if (tmpi->arg1.type&MDF_STACK) { if (tmpi->arg1.type & MDF_STACK)
{
tmpi1 = ParsePop(ps); tmpi1 = ParsePop(ps);
if (tmpi1->ic_code==IC_MOV || tmpi1->ic_code==IC_REG) { if (tmpi1->ic_code == IC_MOV || tmpi1->ic_code == IC_REG)
if (tmpi1->ic_flags & ICF_RES_TO_INT) { {
if (tmpi1->ic_flags & ICF_RES_TO_INT)
{
if (tmpi1->arg1.type & MDF_IMM) if (tmpi1->arg1.type & MDF_IMM)
tmpi1->arg1.disp = tmpi1->arg1.disp(F64); tmpi1->arg1.disp = tmpi1->arg1.disp(F64);
else else
tmpi->ic_flags |= ICF_ARG1_TO_INT; tmpi->ic_flags |= ICF_ARG1_TO_INT;
} else if (tmpi1->ic_flags&ICF_RES_TO_F64) { }
if (tmpi1->arg1.type&MDF_IMM) { else if (tmpi1->ic_flags & ICF_RES_TO_F64)
{
if (tmpi1->arg1.type & MDF_IMM)
{
if (tmpi1->arg1.type & RTF_UNSIGNED) if (tmpi1->arg1.type & RTF_UNSIGNED)
tmpi1->arg1.disp(F64) = tmpi1->arg1.disp(U64); tmpi1->arg1.disp(F64) = tmpi1->arg1.disp(U64);
else else
tmpi1->arg1.disp(F64) = tmpi1->arg1.disp(I64); tmpi1->arg1.disp(F64) = tmpi1->arg1.disp(I64);
} else }
else
tmpi->ic_flags |= ICF_ARG1_TO_F64; tmpi->ic_flags |= ICF_ARG1_TO_F64;
} }
tmpi->arg1.type = tmpi1->arg1.type & MDG_MASK + tmpi->arg1.type = tmpi1->arg1.type & MDG_MASK +
MinI64(tmpi->arg1.type.raw_type, MinI64(tmpi->arg1.type.raw_type, MinI64(tmpi1->res.type.raw_type, tmpi1->arg1.type.raw_type));
MinI64(tmpi1->res.type.raw_type,tmpi1->arg1.type.raw_type));
CompMinTypePointed(tmpi, tmpi1->arg1_type_pointed_to); CompMinTypePointed(tmpi, tmpi1->arg1_type_pointed_to);
tmpi->arg1.reg = tmpi1->arg1.reg; tmpi->arg1.reg = tmpi1->arg1.reg;
tmpi->arg1.disp = tmpi1->arg1.disp; tmpi->arg1.disp = tmpi1->arg1.disp;
@ -77,8 +93,7 @@ U0 OptPass5(CCompCtrl *cc)
OptSetNOP2(tmpi1); OptSetNOP2(tmpi1);
} }
} }
if (tmpi->res.type&MDF_STACK && if (tmpi->res.type & MDF_STACK && !(tmpi->ic_flags & ICF_RES_NOT_USED))
!(tmpi->ic_flags&ICF_RES_NOT_USED))
ParsePush(ps, tmpi); ParsePush(ps, tmpi);
} }
tmpi = tmpi->next; tmpi = tmpi->next;

View file

@ -59,6 +59,7 @@ StartOS.CC
OptPass012.CC OptPass012.CC
OptPass3.CC OptPass3.CC
OptPass4.CC OptPass4.CC
OptPass5.CC
OpCodes.DD OpCodes.DD
CompilerA.HH CompilerA.HH
CompilerB.HH CompilerB.HH