X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fhc08%2Fgen.c;h=fde9e310f45178a5c44da5cb522946045cc97543;hb=c34cf61917860a821a4631edda334443633805e7;hp=04dafb2e6a94a6cd2fa08cdd33593f6bdcbb6114;hpb=9a62abdbae6dc14565e2d8b593f6716a90d08119;p=fw%2Fsdcc diff --git a/src/hc08/gen.c b/src/hc08/gen.c index 04dafb2e..fde9e310 100644 --- a/src/hc08/gen.c +++ b/src/hc08/gen.c @@ -1352,7 +1352,7 @@ static asmop * aopForRemat (symbol * sym) { iCode *ic = sym->rematiCode; - asmop *aop = newAsmop (AOP_IMMD); + asmop *aop = NULL; int ptr_type=0; int val = 0; @@ -1377,22 +1377,40 @@ aopForRemat (symbol * sym) ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; } - if (val) - sprintf (buffer, "(%s %c 0x%04x)", - OP_SYMBOL (IC_LEFT (ic))->rname, - val >= 0 ? '+' : '-', - abs (val) & 0xffff); - else - strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname); + if (ic->op == ADDRESS_OF) + { + if (val) + sprintf (buffer, "(%s %c 0x%04x)", + OP_SYMBOL (IC_LEFT (ic))->rname, + val >= 0 ? '+' : '-', + abs (val) & 0xffff); + else + strcpy (buffer, OP_SYMBOL (IC_LEFT (ic))->rname); - aop->aopu.aop_immd.aop_immd1 = Safe_calloc (1, strlen (buffer) + 1); - strcpy (aop->aopu.aop_immd.aop_immd1, buffer); - /* set immd2 field if required */ - if (aop->aopu.aop_immd.from_cast_remat) { + aop = newAsmop (AOP_IMMD); + aop->aopu.aop_immd.aop_immd1 = Safe_calloc (1, strlen (buffer) + 1); + strcpy (aop->aopu.aop_immd.aop_immd1, buffer); + /* set immd2 field if required */ + if (aop->aopu.aop_immd.from_cast_remat) + { sprintf(buffer,"#0x%02x",ptr_type); aop->aopu.aop_immd.aop_immd2 = Safe_calloc (1, strlen (buffer) + 1); strcpy (aop->aopu.aop_immd.aop_immd2, buffer); - } + } + } + else if (ic->op == '=') + { + val += (int) operandLitValue (IC_RIGHT (ic)); + val &= 0xffff; + sprintf (buffer, "0x%04x", val); + aop = newAsmop (AOP_LIT); + aop->aopu.aop_lit = constVal (buffer); + } + else + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "unexpected rematerialization"); + + return aop; } @@ -2080,9 +2098,12 @@ asmopToBool (asmop *aop, bool resultInA) emitcode ("", "%05d$:", (tlbl->key + 100)); } else - werror (E_INTERNAL_ERROR, __FILE__, __LINE__, - "Bad rIdx in asmToBool"); - return; + { + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "Bad rIdx in asmToBool"); + return; + } + break; case AOP_EXT: if (resultInA) needpula = FALSE; @@ -4965,7 +4986,55 @@ genGetHbit (iCode * ic) emitcode ("rola", ""); hc08_dirtyReg (hc08_reg_a, FALSE); storeRegToFullAop (hc08_reg_a, AOP (result), FALSE); + hc08_freeReg (hc08_reg_a); + + freeAsmop (left, NULL, ic, TRUE); + freeAsmop (result, NULL, ic, TRUE); +} + +/*-----------------------------------------------------------------*/ +/* genSwap - generates code to swap nibbles or bytes */ +/*-----------------------------------------------------------------*/ +static void +genSwap (iCode * ic) +{ + operand *left, *result; + + D(emitcode ("; genSwap","")); + + left = IC_LEFT (ic); + result = IC_RESULT (ic); + aopOp (left, ic, FALSE); + aopOp (result, ic, FALSE); + switch (AOP_SIZE (left)) + { + case 1: /* swap nibbles in byte */ + loadRegFromAop (hc08_reg_a, AOP (left), 0); + emitcode ("nsa", ""); + hc08_dirtyReg (hc08_reg_a, FALSE); + storeRegToAop (hc08_reg_a, AOP (result), 0); + hc08_freeReg (hc08_reg_a); + break; + case 2: /* swap bytes in a word */ + if (operandsEqu (left, result)) + { + loadRegFromAop (hc08_reg_a, AOP (left), 0); + hc08_useReg (hc08_reg_a); + transferAopAop (AOP (left), 1, AOP (result), 0); + storeRegToAop (hc08_reg_a, AOP (result), 1); + hc08_freeReg (hc08_reg_a); + } + else + { + transferAopAop (AOP (left), 0, AOP (result), 1); + transferAopAop (AOP (left), 1, AOP (result), 0); + } + break; + default: + wassertl(FALSE, "unsupported SWAP operand size"); + } + freeAsmop (left, NULL, ic, TRUE); freeAsmop (result, NULL, ic, TRUE); } @@ -6440,7 +6509,7 @@ genPointerGet (iCode * ic, iCode *pi) } /* special case when cast remat */ - if (p_type == GPOINTER && OP_SYMBOL(left)->remat && + if (p_type == GPOINTER && IS_SYMOP(left) && OP_SYMBOL(left)->remat && IS_CAST_ICODE(OP_SYMBOL(left)->rematiCode)) { left = IC_RIGHT(OP_SYMBOL(left)->rematiCode); type = operandType (left); @@ -6582,6 +6651,7 @@ genPackBits (sym_link * etype, emitcode ("and", "#0x%02x", mask); emitcode ("ora", "1,s"); emitcode ("sta", ",x"); + pullReg (hc08_reg_a); } hc08_freeReg (hc08_reg_a); @@ -7169,6 +7239,10 @@ genDjnz (iCode * ic, iCode * ifx) if (operandLitValue (IC_RIGHT (ic)) != 1) return 0; + /* dbnz doesn't support extended mode */ + if (isOperandInFarSpace (IC_RESULT (ic))) + return 0; + /* if the size of this greater than one then no saving */ // if (getSize (operandType (IC_RESULT (ic))) > 1) @@ -7626,6 +7700,10 @@ genhc08Code (iCode * lic) case ENDCRITICAL: genEndCritical (ic); break; + + case SWAP: + genSwap (ic); + break; default: ic = ic;