X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fxa51%2Fgen.c;h=8653e54a282f65dbdf2818d965450b95d9093c2a;hb=8b92dd26778ce77e3ad9dbf7e868acd9faca00d4;hp=181c64e484d7bac534394fe0bbf547b3cac503f5;hpb=cc52c980cc1e1f44c892b2e4bc7c1132cbd09488;p=fw%2Fsdcc diff --git a/src/xa51/gen.c b/src/xa51/gen.c index 181c64e4..8653e54a 100755 --- a/src/xa51/gen.c +++ b/src/xa51/gen.c @@ -102,6 +102,11 @@ static lineNode *lineCurr = NULL; #define MSB24 2 #define MSB32 3 +static char *MOVB="mov.b"; +static char *MOVW="mov.w"; +static char *MOVCB="movc.b"; +static char *MOVCW="movc.w"; + void bailOut (char *mesg) { fprintf (stderr, "%s: bailing out\n", mesg); exit (1); @@ -142,7 +147,8 @@ static void emitcode (char *inst, char *fmt,...) { char *getStackOffset(int stack) { static char gsoBuf[1024]; - sprintf (gsoBuf, "r7%+d+0%+d%+d", stack, + // dit slaat natuurlijk nergens op + sprintf (gsoBuf, "r7+(%+d+0%+d%+d)", stack, FUNC_ISISR(currFunc->type) ? port->stack.isr_overhead : port->stack.call_overhead, _G.nRegsSaved); @@ -470,7 +476,7 @@ void printIc (char *op, iCode * ic, bool result, bool left, bool right) { } /*-----------------------------------------------------------------*/ -/* toBoolean - return bit for operand!=0 */ +/* toBoolean - return carry for operand!=0 */ /*-----------------------------------------------------------------*/ static char *toBoolean (operand * op) { switch (AOP_SIZE(op)) @@ -478,7 +484,8 @@ static char *toBoolean (operand * op) { case 1: case 2: emitcode ("cmp", "%s,#0", AOP_NAME(op)); - return "z"; + emitcode ("mov", "c,z"); + return "c"; } bailOut("toBoolean: unknown size"); @@ -673,11 +680,11 @@ static void genLabel (iCode * ic) { } /*-----------------------------------------------------------------*/ -/* genGoto - generates a ljmp */ +/* genGoto - generates a jmp */ /*-----------------------------------------------------------------*/ static void genGoto (iCode * ic) { emitcode (";", "genGoto %s", IC_LABEL(ic)->name); - emitcode ("ljmp", "%05d$", (IC_LABEL (ic)->key + 100)); + emitcode ("jmp", "%05d$", (IC_LABEL (ic)->key + 100)); } /*-----------------------------------------------------------------*/ @@ -889,7 +896,7 @@ static void genRightShift (iCode * ic) { /* genPointerGet - generate code for pointer get */ /*-----------------------------------------------------------------*/ static void genPointerGet (iCode * ic, iCode *pi) { - char *instr="mov"; + char *instr; operand *result=IC_RESULT(ic), *left=IC_LEFT(ic); @@ -903,7 +910,7 @@ static void genPointerGet (iCode * ic, iCode *pi) { aopOp(result,TRUE); if (IS_GENPTR(operandType(left))) { - emitcode ("INLINE", "_gptrget %s %s = [%s %s]", + emitcode (";", "INLINE\t_gptrget ; %s %s = [%s %s]", AOP_NAME(result)[0], AOP_NAME(result)[1], AOP_NAME(left)[0], AOP_NAME(left)[1]); return; @@ -912,30 +919,107 @@ static void genPointerGet (iCode * ic, iCode *pi) { switch (AOP_TYPE(left)) { case AOP_CODE: - instr="movc"; - // fall through + if (AOP_SIZE(result)==1) { + instr=MOVCB; + } else { + instr=MOVCW; + } + emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]); + if (AOP_SIZE(result) > 2) { + if (AOP_SIZE(result)==3) { + instr=MOVCB; + } else { + instr=MOVCW; + } + emitcode (instr, "%s,[%s+2]", AOP_NAME(result)[1], AOP_NAME(left)[0]); + } + return; case AOP_FAR: + if (AOP_SIZE(result)==1) { + instr=MOVB; + } else { + instr=MOVW; + } emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]); if (AOP_SIZE(result) > 2) { + if (AOP_SIZE(result)==3) { + instr=MOVB; + } else { + instr=MOVW; + } emitcode (instr, "%s,[%s+2]", AOP_NAME(result)[1], AOP_NAME(left)[0]); } return; case AOP_DIR: + if (AOP_SIZE(result)==1) { + instr=MOVB; + } else { + instr=MOVW; + } emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]); if (AOP_SIZE(result) > 2) { + if (AOP_SIZE(result)==3) { + instr=MOVB; + } else { + instr=MOVW; + } emitcode (instr, "%s,%s+2", AOP_NAME(result)[1], AOP_NAME(left)[0]); } return; case AOP_REG: - emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]); + if (AOP_SIZE(result)==1) { + instr=MOVB; + } else { + instr=MOVW; + } + // if result=onstack + if (AOP_TYPE(result)==AOP_STK) { + emitcode (instr, "r0,[%s]", AOP_NAME(left)[0]); + emitcode (instr, "%s,r0", AOP_NAME(result)[0]); + } else { + emitcode (instr, "%s,[%s]", AOP_NAME(result)[0], AOP_NAME(left)[0]); + } if (AOP_SIZE(result) > 2) { - emitcode (instr, "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]); + // result is generic pointer + sym_link *optype=operandType(left); + sym_link *opetype=getSpec(optype); + if (IS_PTR(optype) && !IS_GENPTR(optype)) { + emitcode ("mov.b", "%s,#0x%02x", AOP_NAME(result)[1], + PTR_TYPE(SPEC_OCLS(opetype))); + } else { + emitcode ("mov.b", "%s,[%s]", AOP_NAME(result)[1], AOP_NAME(left)[1]); + } } return; case AOP_STK: - emitcode (instr, "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]); + // if both on stack + if (AOP_TYPE(result)==AOP_STK) { + if (AOP_SIZE(result)==1) { + emitcode ("mov", "r0l,%s", AOP_NAME(left)[0]); + emitcode ("mov", "%s,r0l", AOP_NAME(result)[0]); + } else { + emitcode ("mov", "r0,%s", AOP_NAME(left)[0]); + emitcode ("mov", "%s,r0", AOP_NAME(result)[0]); + } + } else { + if (AOP_SIZE(result)==1) { + emitcode ("mov.b", "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]); + } else { + emitcode ("mov.w", "%s,%s", AOP_NAME(result)[0], AOP_NAME(left)[0]); + } + } if (AOP_SIZE(result) > 2) { - emitcode (instr, "%s,%s", AOP_NAME(result)[1], AOP_NAME(left)[1]); + if (AOP_TYPE(result)==AOP_STK) { + if (AOP_SIZE(result)==3) { + emitcode ("mov", "r0l,%s", AOP_NAME(left)[1]); + emitcode ("mov", "%s,r0l", AOP_NAME(result)[1]); + } else { + emitcode ("mov", "r0,%s", AOP_NAME(left)[1]); + emitcode ("mov", "%s,r0", AOP_NAME(result)[1]); + } + } else { + emitcode ("mov", "%s,%s", AOP_NAME(result)[1], AOP_NAME(left)[1]); + } } return; } @@ -946,7 +1030,7 @@ static void genPointerGet (iCode * ic, iCode *pi) { /* genPointerSet - stores the value into a pointer location */ /*-----------------------------------------------------------------*/ static void genPointerSet (iCode * ic, iCode *pi) { - char *instr="mov"; + char *instr; operand *result=IC_RESULT(ic), *right=IC_RIGHT(ic); @@ -960,7 +1044,7 @@ static void genPointerSet (iCode * ic, iCode *pi) { aopOp(result,TRUE); if (IS_GENPTR(operandType(result))) { - emitcode ("INLINE", "_gptrset [%s %s]= %s %s", + emitcode (";", "INLINE _gptrset ; [%s %s]= %s %s", AOP_NAME(result)[0], AOP_NAME(result)[1], AOP_NAME(right)[0], AOP_NAME(right)[1]); return; @@ -968,19 +1052,25 @@ static void genPointerSet (iCode * ic, iCode *pi) { switch (AOP_TYPE(result)) { - case AOP_CODE: - instr="movc"; - // fall through case AOP_REG: case AOP_DIR: case AOP_FAR: case AOP_STK: + if (AOP_SIZE(result)==1) { + instr=MOVB; + } else { + instr=MOVW; + } emitcode (instr, "[%s],%s", AOP_NAME(result)[0], AOP_NAME(right)[0]); if (AOP_SIZE(result) > 2) { + if (AOP_SIZE(result)==3) { + instr=MOVB; + } else { + instr=MOVW; + } emitcode (instr, "[%s],%s", AOP_NAME(result)[1], AOP_NAME(right)[1]); } return; - case AOP_GPTR: } bailOut ("genPointerSet: unknown pointer"); } @@ -989,6 +1079,7 @@ static void genPointerSet (iCode * ic, iCode *pi) { /* genIfx - generate code for Ifx statement */ /*-----------------------------------------------------------------*/ static void genIfx (iCode * ic, iCode * popIc) { + char *instr; bool trueOrFalse; symbol *jlbl, *tlbl; operand *cond=IC_COND(ic); @@ -1019,10 +1110,20 @@ static void genIfx (iCode * ic, iCode * popIc) { case AOP_FAR: case AOP_STK: tlbl=newiTempLabel(NULL); - emitcode ("cmp", "%s,#0", AOP_NAME(cond)[0]); + if (AOP_SIZE(cond)==1) { + instr="cmp.b"; + } else { + instr="cmp.w"; + } + emitcode (instr, "%s,#0", AOP_NAME(cond)[0]); emitcode (trueOrFalse ? "beq" : "bne", "%05d$", tlbl->key+100); if (AOP_SIZE(cond) > 2) { - emitcode ("cmp", "%s,#0", AOP_NAME(cond)[1]); + if (AOP_SIZE(cond)==3) { + instr="cmp.b"; + } else { + instr="cmp.w"; + } + emitcode (instr, "%s,#0", AOP_NAME(cond)[1]); emitcode (trueOrFalse ? "beq" : "bne", "%05d$", tlbl->key+100); } emitcode ("jmp", "%05d$", jlbl->key+100); @@ -1043,9 +1144,8 @@ static void genAddrOf (iCode * ic) { aopOp (IC_RESULT(ic),TRUE); if (isOperandOnStack(left)) { - aopOp (IC_LEFT(ic),FALSE); emitcode ("lea", "%s,%s", AOP_NAME(IC_RESULT(ic))[0], - AOP_NAME(IC_LEFT(ic))[0]); + getStackOffset(OP_SYMBOL(left)->stack)); if (AOP_SIZE(IC_RESULT(ic)) > 2) { // this must be a generic pointer emitcode ("mov", "%s,#0x01", AOP_NAME(IC_RESULT(ic))[1]); @@ -1079,6 +1179,8 @@ static void genAddrOf (iCode * ic) { /*-----------------------------------------------------------------*/ static void genAssign (iCode * ic) { operand *result=IC_RESULT(ic), *right=IC_RIGHT(ic); + int size; + char *instr; printIc ("genAssign", ic, 1,0,1); @@ -1088,6 +1190,7 @@ static void genAssign (iCode * ic) { aopOp(right, FALSE); aopOp(result, TRUE); + size=AOP_SIZE(result); if (result->aop->type==AOP_REG || right->aop->type==AOP_REG || @@ -1127,13 +1230,38 @@ static void genAssign (iCode * ic) { } /* general case */ - emitcode ("mov", "%s,%s", - result->aop->name[0], right->aop->name[0]); + if (size==1) { + instr=MOVB; + } else { + instr=MOVW; + } + if (AOP_TYPE(right)==AOP_STK && AOP_TYPE(result)==AOP_STK) { + emitcode (instr, "%s,%s", size==1 ? "r0l":"r0", right->aop->name[0]); + emitcode (instr, "%s,%s", AOP_NAME(result)[0], size==1 ? "r0l":"r0"); + } else { + emitcode (instr, "%s,%s", + result->aop->name[0], right->aop->name[0]); + } if (AOP_SIZE(result) > 2) { - emitcode ("mov", "%s,%s", - result->aop->name[1], right->aop->name[1]); + if (AOP_TYPE(right)==AOP_LIT) { + emitcode (instr, "%s,%s", result->aop->name[1], + *AOP_NAME(right)[1] ? AOP_NAME(right)[1] : "#0x00"); + return; + } + if (size==3) { + instr=MOVB; + } else { + instr=MOVW; + } + if (AOP_TYPE(right)==AOP_STK && AOP_TYPE(result)==AOP_STK) { + emitcode (instr, "%s,%s", size==1 ? "r0l":"r0", right->aop->name[1]); + emitcode (instr, "%s,%s", AOP_NAME(result)[1], size==1 ? "r0l":"r0"); + } else { + emitcode (instr, "%s,%s", + result->aop->name[1], right->aop->name[1]); + } + return; } - } /*-----------------------------------------------------------------*/