X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fgen.c;h=e2252b7e5bd8d835668edfdce20c9c7a1ed86a1d;hb=4db4740164fed3cb25145cfdaadb986fc0690507;hp=5cea9722c0c00d082e9a0eaec04ce094afcbee9e;hpb=d2da99feec099aa224e1db53bc5a1ed42ed51ec9;p=fw%2Fsdcc diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 5cea9722..e2252b7e 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -64,6 +64,27 @@ static char *accUse[] = static unsigned short rbank = -1; +#define AOP(op) op->aop +#define AOP_TYPE(op) AOP(op)->type +#define AOP_SIZE(op) AOP(op)->size +#define IS_AOP_PREG(x) (AOP(x) && (AOP_TYPE(x) == AOP_R1 || \ + AOP_TYPE(x) == AOP_R0)) + +#define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || \ + AOP_TYPE(x) == AOP_DPTR || AOP(x)->paged)) + +#define AOP_INPREG(x) (x && (x->type == AOP_REG && \ + (x->aopu.aop_reg[0] == mcs51_regWithIdx(R0_IDX) || \ + x->aopu.aop_reg[0] == mcs51_regWithIdx(R1_IDX) ))) + + +#define SYM_BP(sym) (SPEC_OCLS (sym->etype)->paged ? "_bpx" : "_bp") + +#define R0INB _G.bu.bs.r0InB +#define R1INB _G.bu.bs.r1InB +#define OPINB _G.bu.bs.OpInB +#define BINUSE _G.bu.BInUse + static struct { short r0Pushed; @@ -75,9 +96,9 @@ static struct short r0InB : 2;//2 so we can see it overflow short r1InB : 2;//2 so we can see it overflow short OpInB : 2;//2 so we can see it overflow - } ; + } bs; short BInUse; - } ; + } bu; short accInUse; short inLine; short debugLine; @@ -190,7 +211,7 @@ pushB (void) { bool pushedB = FALSE; - if (_G.BInUse) + if (BINUSE) { emitcode ("push", "b"); // printf("B was in use !\n"); @@ -198,7 +219,7 @@ pushB (void) } else { - _G.OpInB++; + OPINB++; } return pushedB; } @@ -215,7 +236,7 @@ popB (bool pushedB) } else { - _G.OpInB--; + OPINB--; } } @@ -269,7 +290,7 @@ getFreePtr (iCode * ic, asmop ** aopp, bool result) { emitcode ("mov", "b,%s", mcs51_regWithIdx (R0_IDX)->dname); - _G.r0InB++; + R0INB++; } else if (!_G.r0Pushed) { @@ -293,7 +314,7 @@ getFreePtr (iCode * ic, asmop ** aopp, bool result) { emitcode ("mov", "b,%s", mcs51_regWithIdx (R1_IDX)->dname); - _G.r1InB++; + R1INB++; } else if (!_G.r1Pushed) { @@ -509,19 +530,36 @@ aopForSym (iCode * ic, symbol * sym, bool result) if (sym->onStack) { - if (_G.accInUse || leftRightUseAcc (ic)) - emitcode ("push", "acc"); - - emitcode ("mov", "a,_bp"); - emitcode ("add", "a,#0x%02x", - ((sym->stack < 0) ? + char offset = ((sym->stack < 0) ? ((char) (sym->stack - _G.nRegsSaved)) : - ((char) sym->stack)) & 0xff); - emitcode ("mov", "%s,a", - aop->aopu.aop_ptr->name); + ((char) sym->stack)) & 0xff; - if (_G.accInUse || leftRightUseAcc (ic)) - emitcode ("pop", "acc"); + if ((offset >= -3) && (offset <= 3)) + { + emitcode ("mov", "%s,%s", + aop->aopu.aop_ptr->name, SYM_BP (sym)); + while (offset < 0) + { + emitcode ("dec", aop->aopu.aop_ptr->name); + offset++; + } + while (offset > 0) + { + emitcode ("inc", aop->aopu.aop_ptr->name); + offset--; + } + } + else + { + if (_G.accInUse || leftRightUseAcc (ic)) + emitcode ("push", "acc"); + emitcode ("mov", "a,%s", SYM_BP (sym)); + emitcode ("add", "a,#0x%02x", offset); + emitcode ("mov", "%s,a", + aop->aopu.aop_ptr->name); + if (_G.accInUse || leftRightUseAcc (ic)) + emitcode ("pop", "acc"); + } } else emitcode ("mov", "%s,#%s", @@ -598,11 +636,7 @@ aopForRemat (symbol * sym) sym_link *from_type = operandType(IC_RIGHT(ic)); aop->aopu.aop_immd.from_cast_remat = 1; ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; - ptr_type = DCL_TYPE(from_type); - if (ptr_type == IPOINTER) { - // bug #481053 - ptr_type = POINTER; - } + ptr_type = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL); continue ; } else break; @@ -781,7 +815,7 @@ aopOp (operand * op, iCode * ic, bool result) } /* this is a temporary : this has - only four choices : + only five choices : a) register b) spillocation c) rematerialize @@ -886,10 +920,10 @@ freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop) switch (aop->type) { case AOP_R0: - if (_G.r0InB) + if (R0INB) { emitcode ("mov", "r0,b"); - _G.r0InB--; + R0INB--; } else if (_G.r0Pushed) { @@ -903,10 +937,10 @@ freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop) break; case AOP_R1: - if (_G.r1InB) + if (R1INB) { emitcode ("mov", "r1,b"); - _G.r1InB--; + R1INB--; } if (_G.r1Pushed) { @@ -1001,7 +1035,7 @@ freeForBranchAsmop (operand * op) switch (aop->type) { case AOP_R0: - if (_G.r0InB) + if (R0INB) { emitcode ("mov", "r0,b"); } @@ -1012,7 +1046,7 @@ freeForBranchAsmop (operand * op) break; case AOP_R1: - if (_G.r1InB) + if (R1INB) { emitcode ("mov", "r1,b"); } @@ -1058,8 +1092,10 @@ freeForBranchAsmop (operand * op) /* clobber the accumulator */ /*-----------------------------------------------------------------*/ static bool -aopGetUsesAcc (asmop *aop, int offset) +aopGetUsesAcc (operand * oper, int offset) { + asmop * aop = AOP (oper); + if (offset > (aop->size - 1)) return FALSE; @@ -1083,6 +1119,8 @@ aopGetUsesAcc (asmop *aop, int offset) case AOP_CRY: return TRUE; case AOP_ACC: + if (offset) + return FALSE; return TRUE; case AOP_LIT: return FALSE; @@ -1103,10 +1141,11 @@ aopGetUsesAcc (asmop *aop, int offset) /* aopGet - for fetching value of the aop */ /*-----------------------------------------------------------------*/ static char * -aopGet (asmop * aop, int offset, bool bit16, bool dname) +aopGet (operand * oper, int offset, bool bit16, bool dname) { char *s = buffer; char *rs; + asmop * aop = AOP (oper); /* offset is greater than size then zero */ @@ -1195,7 +1234,10 @@ aopGet (asmop * aop, int offset, bool bit16, bool dname) return rs; case AOP_DIR: - if (offset) + if (SPEC_SCLS (getSpec (operandType (oper))) == S_SFR && offset) + sprintf (s, "(%s >> %d)", + aop->aopu.aop_dir, offset * 8); + else if (offset) sprintf (s, "(%s + %d)", aop->aopu.aop_dir, offset); @@ -1240,12 +1282,14 @@ aopGet (asmop * aop, int offset, bool bit16, bool dname) exit (1); } /*-----------------------------------------------------------------*/ -/* aopPut - puts a string for a aop */ +/* aopPut - puts a string for a aop and indicates if acc is in use */ /*-----------------------------------------------------------------*/ -static void -aopPut (asmop * aop, const char *s, int offset, bool bvolatile) +static bool +aopPut (operand * result, const char *s, int offset, bool bvolatile) { char *d = buffer; + bool accuse = FALSE; + asmop * aop = AOP (result); if (aop->size && offset > (aop->size - 1)) { @@ -1260,10 +1304,14 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) { case AOP_DUMMY: MOVA (s); /* read s in case it was volatile */ + accuse = TRUE; break; case AOP_DIR: - if (offset) + if (SPEC_SCLS (getSpec (operandType (result))) == S_SFR && offset) + sprintf (d, "(%s >> %d)", + aop->aopu.aop_dir, offset * 8); + else if (offset) sprintf (d, "(%s + %d)", aop->aopu.aop_dir, offset); else @@ -1272,6 +1320,8 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) if (strcmp (d, s) || bvolatile) emitcode ("mov", "%s,%s", d, s); + if (!strcmp (d, "acc")) + accuse = TRUE; break; @@ -1318,7 +1368,7 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) aop->coff = offset; - /* if not in accumulater */ + /* if not in accumulator */ MOVA (s); emitcode ("movx", "@dptr,a"); @@ -1382,11 +1432,13 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) break; case AOP_CRY: - /* if bit variable */ + /* if not bit variable */ if (!aop->aopu.aop_dir) { + /* inefficient: move carry into A and use jz/jnz */ emitcode ("clr", "a"); emitcode ("rlc", "a"); + accuse = TRUE; } else { @@ -1398,15 +1450,10 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) emitcode ("mov", "%s,c", aop->aopu.aop_dir); else { - if (strcmp (s, "a")) - { - MOVA (s); - } - { - /* set C, if a >= 1 */ - emitcode ("add", "a,#0xff"); - emitcode ("mov", "%s,c", aop->aopu.aop_dir); - } + MOVA (s); + /* set C, if a >= 1 */ + emitcode ("add", "a,#0xff"); + emitcode ("mov", "%s,c", aop->aopu.aop_dir); } } break; @@ -1419,6 +1466,7 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) break; case AOP_ACC: + accuse = TRUE; aop->coff = offset; if (!offset && (strcmp (s, "acc") == 0) && !bvolatile) @@ -1435,6 +1483,7 @@ aopPut (asmop * aop, const char *s, int offset, bool bvolatile) exit (1); } + return accuse; } @@ -1492,20 +1541,6 @@ reAdjustPreg (asmop * aop) aop->coff = 0; } -#define AOP(op) op->aop -#define AOP_TYPE(op) AOP(op)->type -#define AOP_SIZE(op) AOP(op)->size -#define IS_AOP_PREG(x) (AOP(x) && (AOP_TYPE(x) == AOP_R1 || \ - AOP_TYPE(x) == AOP_R0)) - -#define AOP_NEEDSACC(x) (AOP(x) && (AOP_TYPE(x) == AOP_CRY || \ - AOP_TYPE(x) == AOP_DPTR || AOP(x)->paged)) - -#define AOP_INPREG(x) (x && (x->type == AOP_REG && \ - (x->aopu.aop_reg[0] == mcs51_regWithIdx(R0_IDX) || \ - x->aopu.aop_reg[0] == mcs51_regWithIdx(R1_IDX) ))) - - /*-----------------------------------------------------------------*/ /* opIsGptr: returns non-zero if the passed operand is */ /* a generic pointer type. */ @@ -1554,13 +1589,13 @@ outAcc (operand * result) size = getDataSize (result); if (size) { - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); size--; offset = 1; /* unsigned or positive */ while (size--) { - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); } } } @@ -1573,7 +1608,7 @@ outBitC (operand * result) { /* if the result is bit */ if (AOP_TYPE (result) == AOP_CRY) - aopPut (AOP (result), "c", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "c", 0, isOperandVolatile (result, FALSE)); else { emitcode ("clr", "a"); @@ -1590,31 +1625,35 @@ toBoolean (operand * oper) { int size = AOP_SIZE (oper) - 1; int offset = 1; - char *l = aopGet (AOP (oper), 0, FALSE, FALSE); + bool AccUsed = FALSE; bool pushedB; - if (!strncmp (l, "a", 2) || !strncmp (l, "acc", 4)) + while (!AccUsed && size--) + { + AccUsed |= aopGetUsesAcc(oper, offset++); + } + + size = AOP_SIZE (oper) - 1; + offset = 1; + MOVA (aopGet (oper, 0, FALSE, FALSE)); + if (size && AccUsed && (AOP (oper)->type != AOP_ACC)) { - if (size--) + pushedB = pushB (); + emitcode("mov", "b,a"); + while (--size) { - pushedB = pushB (); - emitcode("mov", "b,a"); - while (size--) - { - MOVA (aopGet (AOP (oper), offset++, FALSE, FALSE)); - emitcode ("orl", "b,a"); - } - MOVA (aopGet (AOP (oper), offset, FALSE, FALSE)); - emitcode ("orl", "a,b"); - popB (pushedB); + MOVA (aopGet (oper, offset++, FALSE, FALSE)); + emitcode ("orl", "b,a"); } + MOVA (aopGet (oper, offset++, FALSE, FALSE)); + emitcode ("orl", "a,b"); + popB (pushedB); } else { - MOVA (l); while (size--) { - emitcode ("orl", "a,%s", aopGet (AOP (oper), offset++, FALSE, FALSE)); + emitcode ("orl", "a,%s", aopGet (oper, offset++, FALSE, FALSE)); } } } @@ -1666,8 +1705,9 @@ genCpl (iCode * ic) int offset = 0; int size; symbol *tlbl; + sym_link *letype = getSpec (operandType (IC_LEFT (ic))); - D(emitcode ("; genCpl","")); + D(emitcode (";", "genCpl")); /* assign asmOps to operand & result */ aopOp (IC_LEFT (ic), ic, FALSE); @@ -1676,27 +1716,32 @@ genCpl (iCode * ic) /* special case if in bit space */ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY) { - if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY) + char *l; + + if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY || + (SPEC_USIGN (letype) && IS_CHAR (letype))) { - /* promotion rules are responsible for this strange result: */ + /* promotion rules are responsible for this strange result: + bit -> int -> ~int -> bit + uchar -> int -> ~int -> bit + */ + werror(W_COMPLEMENT); emitcode ("setb", "%s", IC_RESULT (ic)->aop->aopu.aop_dir); goto release; } tlbl=newiTempLabel(NULL); - if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC || + l = aopGet (IC_LEFT (ic), offset++, FALSE, FALSE); + if ((AOP_TYPE (IC_LEFT (ic)) == AOP_ACC && offset == 0) || AOP_TYPE (IC_LEFT (ic)) == AOP_REG || IS_AOP_PREG (IC_LEFT (ic))) { - emitcode ("cjne", "%s,#0x01,%05d$", - aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE), - tlbl->key + 100); + emitcode ("cjne", "%s,#0xFF,%05d$", l, tlbl->key + 100); } else { - char *l = aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE); MOVA (l); - emitcode ("cjne", "a,#0x01,%05d$", tlbl->key + 100); + emitcode ("cjne", "a,#0xFF,%05d$", tlbl->key + 100); } emitcode ("", "%05d$:", tlbl->key + 100); outBitC (IC_RESULT(ic)); @@ -1706,10 +1751,10 @@ genCpl (iCode * ic) size = AOP_SIZE (IC_RESULT (ic)); while (size--) { - char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE); + char *l = aopGet (IC_LEFT (ic), offset, FALSE, FALSE); MOVA (l); emitcode ("cpl", "a"); - aopPut (AOP (IC_RESULT (ic)), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } @@ -1736,19 +1781,19 @@ genUminusFloat (operand * op, operand * result) while (size--) { - aopPut (AOP (result), - aopGet (AOP (op), offset, FALSE, FALSE), + aopPut (result, + aopGet (op, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); offset++; } - l = aopGet (AOP (op), offset, FALSE, FALSE); + l = aopGet (op, offset, FALSE, FALSE); MOVA (l); emitcode ("cpl", "acc.7"); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -1795,7 +1840,7 @@ genUminus (iCode * ic) //CLRC ; while (size--) { - char *l = aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE); + char *l = aopGet (IC_LEFT (ic), offset, FALSE, FALSE); if (!strcmp (l, "a")) { if (offset == 0) @@ -1810,7 +1855,7 @@ genUminus (iCode * ic) emitcode ("clr", "a"); emitcode ("subb", "a,%s", l); } - aopPut (AOP (IC_RESULT (ic)), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } /* if any remaining bytes in the result */ @@ -1820,7 +1865,7 @@ genUminus (iCode * ic) emitcode ("rlc", "a"); emitcode ("subb", "a,acc"); while (size--) - aopPut (AOP (IC_RESULT (ic)), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } release: @@ -1867,26 +1912,52 @@ saveRegisters (iCode * lic) ic->regsSaved = 1; if (options.useXstack) { - if (bitVectBitValue (rsave, R0_IDX)) + int count = bitVectnBitsOn (rsave); + + if (count == 1) { - emitcode ("mov", "a,r0"); - emitcode ("push", "%s", mcs51_regWithIdx (R0_IDX)->dname); + i = bitVectFirstBit (rsave); + emitcode ("mov", "a,%s", mcs51_regWithIdx (i)->name); + emitcode ("mov", "r0,%s", spname); + emitcode ("inc", "%s", spname);// allocate before use + emitcode ("movx", "@r0,a"); + if (bitVectBitValue (rsave, R0_IDX)) + emitcode ("mov", "r0,a"); } - emitcode ("mov", "r0,%s", spname); - for (i = 0; i < mcs51_nRegs; i++) + else if (count != 0) { - if (bitVectBitValue (rsave, i)) + if (bitVectBitValue (rsave, R0_IDX)) { - if (i != R0_IDX) - emitcode ("mov", "a,%s", mcs51_regWithIdx (i)->name); - emitcode ("movx", "@r0,a"); - emitcode ("inc", "r0"); + emitcode ("push", "%s", mcs51_regWithIdx (R0_IDX)->dname); + } + emitcode ("mov", "r0,%s", spname); + MOVA ("r0"); + emitcode ("add", "a,#%d", count); + emitcode ("mov", "%s,a", spname); + for (i = 0; i < mcs51_nRegs; i++) + { + if (bitVectBitValue (rsave, i)) + { + if (i == R0_IDX) + { + emitcode ("pop", "acc"); + emitcode ("push", "acc"); + } + else + { + emitcode ("mov", "a,%s", mcs51_regWithIdx (i)->name); + } + emitcode ("movx", "@r0,a"); + if (--count) + { + emitcode ("inc", "r0"); + } + } + } + if (bitVectBitValue (rsave, R0_IDX)) + { + emitcode ("pop", "%s", mcs51_regWithIdx (R0_IDX)->dname); } - } - emitcode ("mov", "%s,r0", spname); - if (bitVectBitValue (rsave, R0_IDX)) - { - emitcode ("pop", "%s", mcs51_regWithIdx (R0_IDX)->dname); } } else @@ -1913,22 +1984,37 @@ unsaveRegisters (iCode * ic) if (options.useXstack) { - emitcode ("mov", "r0,%s", spname); - for (i = mcs51_nRegs; i >= 0; i--) - { - if (bitVectBitValue (rsave, i)) - { - emitcode ("dec", "r0"); - emitcode ("movx", "a,@r0"); - if (i != R0_IDX) - emitcode ("mov", "%s,a", mcs51_regWithIdx (i)->name); - } + int count = bitVectnBitsOn (rsave); + if (count == 1) + { + emitcode ("mov", "r0,%s", spname); + emitcode ("dec", "r0"); + emitcode ("movx", "a,@r0"); + i = bitVectFirstBit (rsave); + emitcode ("mov", "%s,a", mcs51_regWithIdx (i)->name); + emitcode ("dec", "%s", spname); } - emitcode ("mov", "%s,r0", spname); - if (bitVectBitValue (rsave, R0_IDX)) + else if (count != 0) { - emitcode ("mov", "r0,a"); + emitcode ("mov", "r0,%s", spname); + for (i = mcs51_nRegs; i >= 0; i--) + { + if (bitVectBitValue (rsave, i)) + { + emitcode ("dec", "r0"); + emitcode ("movx", "a,@r0"); + if (i != R0_IDX) + emitcode ("mov", "%s,a", mcs51_regWithIdx (i)->name); + else + emitcode ("push", "acc"); + } + } + emitcode ("mov", "%s,r0", spname); + if (bitVectBitValue (rsave, R0_IDX)) + { + emitcode ("pop", "ar0"); + } } } else @@ -1937,7 +2023,6 @@ unsaveRegisters (iCode * ic) if (bitVectBitValue (rsave, i)) emitcode ("pop", "%s", mcs51_regWithIdx (i)->dname); } - } @@ -1950,7 +2035,7 @@ pushSide (operand * oper, int size) int offset = 0; while (size--) { - char *l = aopGet (AOP (oper), offset++, FALSE, TRUE); + char *l = aopGet (oper, offset++, FALSE, TRUE); if (AOP_TYPE (oper) != AOP_REG && AOP_TYPE (oper) != AOP_DIR && strcmp (l, "a")) @@ -1964,18 +2049,21 @@ pushSide (operand * oper, int size) } /*-----------------------------------------------------------------*/ -/* assignResultValue - */ +/* assignResultValue - also indicates if acc is in use afterwards */ /*-----------------------------------------------------------------*/ -static void +static bool assignResultValue (operand * oper) { int offset = 0; int size = AOP_SIZE (oper); + bool accuse = FALSE; + while (size--) { - aopPut (AOP (oper), fReturn[offset], offset, isOperandVolatile (oper, FALSE)); + accuse |= aopPut (oper, fReturn[offset], offset, isOperandVolatile (oper, FALSE)); offset++; } + return accuse; } @@ -1994,30 +2082,37 @@ genXpush (iCode * ic) aopOp (IC_LEFT (ic), ic, FALSE); r = getFreePtr (ic, &aop, FALSE); - - emitcode ("mov", "%s,_spx", r->name); - size = AOP_SIZE (IC_LEFT (ic)); - while (size--) - { - char *l = aopGet (AOP (IC_LEFT (ic)), - offset++, FALSE, FALSE); - MOVA (l); + if (size == 1) + { + MOVA (aopGet (IC_LEFT (ic), 0, FALSE, FALSE)); + emitcode ("mov", "%s,%s", r->name, spname); + emitcode ("inc", "%s", spname); // allocate space first emitcode ("movx", "@%s,a", r->name); - emitcode ("inc", "%s", r->name); - } + else + { + // allocate space first + emitcode ("mov", "%s,%s", r->name, spname); + MOVA (r->name); + emitcode ("add", "a,#%d", size); + emitcode ("mov", "%s,a", spname); - - emitcode ("mov", "_spx,%s", r->name); + while (size--) + { + MOVA (aopGet (IC_LEFT (ic), offset++, FALSE, FALSE)); + emitcode ("movx", "@%s,a", r->name); + emitcode ("inc", "%s", r->name); + } + } freeAsmop (NULL, aop, ic, TRUE); freeAsmop (IC_LEFT (ic), NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ -/* genIpush - genrate code for pushing this gets a little complex */ +/* genIpush - generate code for pushing this gets a little complex */ /*-----------------------------------------------------------------*/ static void genIpush (iCode * ic) @@ -2041,7 +2136,7 @@ genIpush (iCode * ic) /* push it on the stack */ while (size--) { - l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE); + l = aopGet (IC_LEFT (ic), offset++, FALSE, TRUE); if (*l == '#') { MOVA (l); @@ -2068,13 +2163,12 @@ genIpush (iCode * ic) /* then do the push */ aopOp (IC_LEFT (ic), ic, FALSE); - // pushSide(IC_LEFT(ic), AOP_SIZE(IC_LEFT(ic))); size = AOP_SIZE (IC_LEFT (ic)); while (size--) { - l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, TRUE); + l = aopGet (IC_LEFT (ic), offset++, FALSE, TRUE); if (AOP_TYPE (IC_LEFT (ic)) != AOP_REG && AOP_TYPE (IC_LEFT (ic)) != AOP_DIR && strcmp (l, "a")) @@ -2084,7 +2178,7 @@ genIpush (iCode * ic) } else emitcode ("push", "%s", l); - } + } freeAsmop (IC_LEFT (ic), NULL, ic, TRUE); } @@ -2107,24 +2201,25 @@ genIpop (iCode * ic) size = AOP_SIZE (IC_LEFT (ic)); offset = (size - 1); while (size--) - emitcode ("pop", "%s", aopGet (AOP (IC_LEFT (ic)), offset--, + emitcode ("pop", "%s", aopGet (IC_LEFT (ic), offset--, FALSE, TRUE)); freeAsmop (IC_LEFT (ic), NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ -/* unsaveRBank - restores the resgister bank from stack */ +/* saveRBank - saves an entire register bank on the stack */ /*-----------------------------------------------------------------*/ static void -unsaveRBank (int bank, iCode * ic, bool popPsw) +saveRBank (int bank, iCode * ic, bool pushPsw) { int i; + int count = mcs51_nRegs + (pushPsw ? 1 : 0); asmop *aop = NULL; regs *r = NULL; if (options.useXstack) - { + { if (!ic) { /* Assume r0 is available for use. */ @@ -2135,54 +2230,60 @@ unsaveRBank (int bank, iCode * ic, bool popPsw) aop = newAsmop (0); r = getFreePtr (ic, &aop, FALSE); } - emitcode ("mov", "%s,_spx", r->name); - } + // allocate space first + emitcode ("mov", "%s,%s", r->name, spname); + MOVA (r->name); + emitcode ("add", "a,#%d", count); + emitcode ("mov", "%s,a", spname); + } - if (popPsw) + for (i = 0; i < mcs51_nRegs; i++) { if (options.useXstack) - { - emitcode ("movx", "a,@%s", r->name); - emitcode ("mov", "psw,a"); - emitcode ("dec", "%s", r->name); + { + emitcode ("mov", "a,(%s+%d)", + regs8051[i].base, 8 * bank + regs8051[i].offset); + emitcode ("movx", "@%s,a", r->name); + if (--count) + emitcode ("inc", "%s", r->name); } else - { - emitcode ("pop", "psw"); - } + emitcode ("push", "(%s+%d)", + regs8051[i].base, 8 * bank + regs8051[i].offset); } - for (i = (mcs51_nRegs - 1); i >= 0; i--) + if (pushPsw) { if (options.useXstack) { - emitcode ("movx", "a,@%s", r->name); - emitcode ("mov", "(%s+%d),a", - regs8051[i].base, 8 * bank + regs8051[i].offset); - emitcode ("dec", "%s", r->name); + emitcode ("mov", "a,psw"); + emitcode ("movx", "@%s,a", r->name); } else - emitcode ("pop", "(%s+%d)", - regs8051[i].base, 8 * bank + regs8051[i].offset); + { + emitcode ("push", "psw"); + } + + emitcode ("mov", "psw,#0x%02x", (bank << 3) & 0x00ff); } - if (options.useXstack) + if (aop) { - emitcode ("mov", "_spx,%s", r->name); + freeAsmop (NULL, aop, ic, TRUE); } - if (aop) + if (ic) { - freeAsmop (NULL, aop, ic, TRUE); + ic->bankSaved = 1; } } /*-----------------------------------------------------------------*/ -/* saveRBank - saves an entire register bank on the stack */ +/* unsaveRBank - restores the register bank from stack */ /*-----------------------------------------------------------------*/ static void -saveRBank (int bank, iCode * ic, bool pushPsw) +unsaveRBank (int bank, iCode * ic, bool popPsw) { int i; asmop *aop = NULL; @@ -2191,59 +2292,57 @@ saveRBank (int bank, iCode * ic, bool pushPsw) if (options.useXstack) { if (!ic) - { + { /* Assume r0 is available for use. */ r = mcs51_regWithIdx (R0_IDX);; - } + } else - { + { aop = newAsmop (0); r = getFreePtr (ic, &aop, FALSE); - } - emitcode ("mov", "%s,_spx", r->name); + } + emitcode ("mov", "%s,%s", r->name, spname); } - for (i = 0; i < mcs51_nRegs; i++) + if (popPsw) { if (options.useXstack) { - emitcode ("inc", "%s", r->name); - emitcode ("mov", "a,(%s+%d)", - regs8051[i].base, 8 * bank + regs8051[i].offset); - emitcode ("movx", "@%s,a", r->name); + emitcode ("dec", "%s", r->name); + emitcode ("movx", "a,@%s", r->name); + emitcode ("mov", "psw,a"); } else - emitcode ("push", "(%s+%d)", - regs8051[i].base, 8 * bank + regs8051[i].offset); + { + emitcode ("pop", "psw"); + } } - if (pushPsw) + for (i = (mcs51_nRegs - 1); i >= 0; i--) { if (options.useXstack) { - emitcode ("mov", "a,psw"); - emitcode ("movx", "@%s,a", r->name); - emitcode ("inc", "%s", r->name); - emitcode ("mov", "_spx,%s", r->name); - + emitcode ("dec", "%s", r->name); + emitcode ("movx", "a,@%s", r->name); + emitcode ("mov", "(%s+%d),a", + regs8051[i].base, 8 * bank + regs8051[i].offset); } else - { - emitcode ("push", "psw"); - } + { + emitcode ("pop", "(%s+%d)", + regs8051[i].base, 8 * bank + regs8051[i].offset); + } + } - emitcode ("mov", "psw,#0x%02x", (bank << 3) & 0x00ff); + if (options.useXstack) + { + emitcode ("mov", "%s,%s", spname, r->name); } if (aop) { freeAsmop (NULL, aop, ic, TRUE); } - - if (ic) - { - ic->bankSaved = 1; - } } /*-----------------------------------------------------------------*/ @@ -2262,7 +2361,7 @@ static void genSend(set *sendSet) if (sic->argreg == 1) { while (size--) { - char *l = aopGet (AOP (IC_LEFT (sic)), offset, + char *l = aopGet (IC_LEFT (sic), offset, FALSE, FALSE); if (strcmp (l, fReturn[offset])) emitcode ("mov", "%s,%s", fReturn[offset], l); @@ -2272,7 +2371,7 @@ static void genSend(set *sendSet) } else { while (size--) { emitcode ("mov","b1_%d,%s",rb1_count++, - aopGet (AOP (IC_LEFT (sic)), offset++,FALSE, FALSE)); + aopGet (IC_LEFT (sic), offset++,FALSE, FALSE)); } } freeAsmop (IC_LEFT (sic), NULL, sic, TRUE); @@ -2288,6 +2387,8 @@ genCall (iCode * ic) sym_link *dtype; // bool restoreBank = FALSE; bool swapBanks = FALSE; + bool accuse = FALSE; + bool accPushed = FALSE; D(emitcode("; genCall","")); @@ -2348,21 +2449,34 @@ genCall (iCode * ic) aopOp (IC_RESULT (ic), ic, FALSE); _G.accInUse--; - assignResultValue (IC_RESULT (ic)); + accuse = assignResultValue (IC_RESULT (ic)); freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); } - /* adjust the stack for parameters if - required */ + /* adjust the stack for parameters if required */ if (ic->parmBytes) { int i; if (ic->parmBytes > 3) { + if (accuse) + { + emitcode ("push", "acc"); + accPushed = TRUE; + } + emitcode ("mov", "a,%s", spname); emitcode ("add", "a,#0x%02x", (-ic->parmBytes) & 0xff); emitcode ("mov", "%s,a", spname); + + /* unsaveRegisters from xstack needs acc, but */ + /* unsaveRegisters from stack needs this popped */ + if (accPushed && !options.useXstack) + { + emitcode ("pop", "acc"); + accPushed = FALSE; + } } else for (i = 0; i < ic->parmBytes; i++) @@ -2371,11 +2485,22 @@ genCall (iCode * ic) /* if we hade saved some registers then unsave them */ if (ic->regsSaved && !IFFUNC_CALLEESAVES(dtype)) - unsaveRegisters (ic); + { + if (accuse && !accPushed && options.useXstack) + { + /* xstack needs acc, but doesn't touch normal stack */ + emitcode ("push", "acc"); + accPushed = TRUE; + } + unsaveRegisters (ic); + } // /* if register bank was saved then pop them */ // if (restoreBank) // unsaveRBank (FUNC_REGBANK (dtype), ic, FALSE); + + if (accPushed) + emitcode ("pop", "acc"); } /*-----------------------------------------------------------------*/ @@ -2541,13 +2666,14 @@ inExcludeList (char *s) static void genFunction (iCode * ic) { - symbol *sym = OP_SYMBOL (IC_LEFT (ic)); + symbol *sym = OP_SYMBOL (IC_LEFT (ic)); sym_link *ftype; - bool switchedPSW = FALSE; - int calleesaves_saved_register = -1; - int stackAdjust = sym->stack; - int accIsFree = sym->recvSize < 4; - iCode * ric = (ic->next && ic->next->op == RECEIVE) ? ic->next : NULL; + bool switchedPSW = FALSE; + int calleesaves_saved_register = -1; + int stackAdjust = sym->stack; + int accIsFree = sym->recvSize < 4; + iCode *ric = (ic->next && ic->next->op == RECEIVE) ? ic->next : NULL; + bool fReentrant = (IFFUNC_ISREENT (sym->type) || options.stackAuto); _G.nRegsSaved = 0; /* create the function header */ @@ -2768,26 +2894,35 @@ genFunction (iCode * ic) } - if (IFFUNC_ISREENT (sym->type) || options.stackAuto) + if (fReentrant) { - if (options.useXstack) { - if (!accIsFree) - emitcode ("push", "acc"); - emitcode ("mov", "r0,%s", spname); - emitcode ("mov", "a,_bp"); - emitcode ("movx", "@r0,a"); - emitcode ("inc", "%s", spname); - if (!accIsFree) - emitcode ("pop", "acc"); + if (sym->xstack || FUNC_HASSTACKPARM(sym->type)) + { + emitcode ("mov", "r0,%s", spname); + emitcode ("inc", "%s", spname); + emitcode ("xch", "a,_bpx"); + emitcode ("movx", "@r0,a"); + emitcode ("inc", "r0"); + emitcode ("mov", "a,r0"); + emitcode ("xch", "a,_bpx"); + } + if (sym->stack) + { + emitcode ("push", "_bp"); /* save the callers stack */ + emitcode ("mov", "_bp,sp"); + } } else { - /* set up the stack */ - emitcode ("push", "_bp"); /* save the callers stack */ + if (sym->stack || FUNC_HASSTACKPARM(sym->type)) + { + /* set up the stack */ + emitcode ("push", "_bp"); /* save the callers stack */ + emitcode ("mov", "_bp,sp"); + } } - emitcode ("mov", "_bp,%s", spname); } /* For some cases it is worthwhile to perform a RECEIVE iCode */ @@ -2853,18 +2988,15 @@ genFunction (iCode * ic) /* adjust the stack for the function */ if (stackAdjust) { - int i = stackAdjust; if (i > 256) werror (W_STACK_OVERFLOW, sym->name); if (i > 3 && accIsFree) { - emitcode ("mov", "a,sp"); emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff)); emitcode ("mov", "sp,a"); - } else if (i > 5) { @@ -2906,14 +3038,27 @@ genFunction (iCode * ic) if (sym->xstack) { + char i = ((char) sym->xstack & 0xff); - if (!accIsFree) - emitcode ("push", "acc"); - emitcode ("mov", "a,_spx"); - emitcode ("add", "a,#0x%02x", ((char) sym->xstack & 0xff)); - emitcode ("mov", "_spx,a"); - if (!accIsFree) - emitcode ("pop", "acc"); + if (i > 3 && accIsFree) + { + emitcode ("mov", "a,_spx"); + emitcode ("add", "a,#0x%02x", i); + emitcode ("mov", "_spx,a"); + } + else if (i > 5) + { + emitcode ("push", "acc"); + emitcode ("mov", "a,_spx"); + emitcode ("add", "a,#0x%02x", i); + emitcode ("mov", "_spx,a"); + emitcode ("pop", "acc"); + } + else + { + while (i--) + emitcode ("inc", "_spx"); + } } /* if critical function then turn interrupts off */ @@ -2934,12 +3079,12 @@ genFunction (iCode * ic) static void genEndFunction (iCode * ic) { - symbol *sym = OP_SYMBOL (IC_LEFT (ic)); + symbol *sym = OP_SYMBOL (IC_LEFT (ic)); lineNode *lnp = lineCurr; - bitVect *regsUsed; - bitVect *regsUsedPrologue; - bitVect *regsUnneeded; - int idx; + bitVect *regsUsed; + bitVect *regsUsedPrologue; + bitVect *regsUnneeded; + int idx; _G.currentFunc = NULL; if (IFFUNC_ISNAKED(sym->type)) @@ -2956,33 +3101,28 @@ genEndFunction (iCode * ic) emitcode ("mov", "ea,c"); } - if (IFFUNC_ISREENT (sym->type) || options.stackAuto) - { - emitcode ("mov", "%s,_bp", spname); - } - - /* if use external stack but some variables were - added to the local stack then decrement the - local stack */ - if (options.useXstack && sym->stack) - { - emitcode ("mov", "a,sp"); - emitcode ("add", "a,#0x%02x", ((char) -sym->stack) & 0xff); - emitcode ("mov", "sp,a"); - } - - if ((IFFUNC_ISREENT (sym->type) || options.stackAuto)) { if (options.useXstack) { - emitcode ("mov", "r0,%s", spname); - emitcode ("movx", "a,@r0"); - emitcode ("mov", "_bp,a"); - emitcode ("dec", "%s", spname); + if (sym->stack) + { + emitcode ("mov", "sp,_bp"); + emitcode ("pop", "_bp"); + } + if (sym->xstack || FUNC_HASSTACKPARM(sym->type)) + { + emitcode ("xch", "a,_bpx"); + emitcode ("mov", "r0,a"); + emitcode ("dec", "r0"); + emitcode ("movx", "a,@r0"); + emitcode ("xch", "a,_bpx"); + emitcode ("mov", "%s,r0", spname); //read before freeing stack space (interrupts) + } } - else + else if (sym->stack || FUNC_HASSTACKPARM(sym->type)) { + emitcode ("mov", "sp,_bp"); emitcode ("pop", "_bp"); } } @@ -3240,14 +3380,14 @@ genRet (iCode * ic) if (AOP_TYPE (IC_LEFT (ic)) == AOP_DPTR) { /* #NOCHANGE */ - l = aopGet (AOP (IC_LEFT (ic)), offset++, + l = aopGet (IC_LEFT (ic), offset++, FALSE, TRUE); emitcode ("push", "%s", l); pushed++; } else { - l = aopGet (AOP (IC_LEFT (ic)), offset, + l = aopGet (IC_LEFT (ic), offset, FALSE, FALSE); if (strcmp (fReturn[offset], l)) emitcode ("mov", "%s,%s", fReturn[offset++], l); @@ -3380,49 +3520,49 @@ genPlusIncr (iCode * ic) tlbl = newiTempLabel (NULL); emitTlbl = 1; } - emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE)); + emitcode ("inc", "%s", aopGet (IC_RESULT (ic), LSB, FALSE, FALSE)); if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG || IS_AOP_PREG (IC_RESULT (ic))) emitcode ("cjne", "%s,#0x00,%05d$", - aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE), + aopGet (IC_RESULT (ic), LSB, FALSE, FALSE), tlbl->key + 100); else { emitcode ("clr", "a"); emitcode ("cjne", "a,%s,%05d$", - aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE), + aopGet (IC_RESULT (ic), LSB, FALSE, FALSE), tlbl->key + 100); } - emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE)); + emitcode ("inc", "%s", aopGet (IC_RESULT (ic), MSB16, FALSE, FALSE)); if (size > 2) { if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG || IS_AOP_PREG (IC_RESULT (ic))) emitcode ("cjne", "%s,#0x00,%05d$", - aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE), + aopGet (IC_RESULT (ic), MSB16, FALSE, FALSE), tlbl->key + 100); else emitcode ("cjne", "a,%s,%05d$", - aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE), + aopGet (IC_RESULT (ic), MSB16, FALSE, FALSE), tlbl->key + 100); - emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE)); + emitcode ("inc", "%s", aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE)); } if (size > 3) { if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG || IS_AOP_PREG (IC_RESULT (ic))) emitcode ("cjne", "%s,#0x00,%05d$", - aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE), + aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE), tlbl->key + 100); else { emitcode ("cjne", "a,%s,%05d$", - aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE), + aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE), tlbl->key + 100); } - emitcode ("inc", "%s", aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE)); + emitcode ("inc", "%s", aopGet (IC_RESULT (ic), MSB32, FALSE, FALSE)); } if (emitTlbl) @@ -3445,15 +3585,15 @@ genPlusIncr (iCode * ic) if (icount > 3) { - MOVA (aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE)); + MOVA (aopGet (IC_LEFT (ic), 0, FALSE, FALSE)); emitcode ("add", "a,#0x%02x", ((char) icount) & 0xff); - aopPut (AOP (IC_RESULT (ic)), "a", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); } else { while (icount--) - emitcode ("inc", "%s", aopGet (AOP (IC_LEFT (ic)), 0, FALSE, FALSE)); + emitcode ("inc", "%s", aopGet (IC_LEFT (ic), 0, FALSE, FALSE)); } return TRUE; @@ -3472,7 +3612,7 @@ outBitAcc (operand * result) /* if the result is a bit */ if (AOP_TYPE (result) == AOP_CRY) { - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); } else { @@ -3523,16 +3663,16 @@ adjustArithmeticResult (iCode * ic) if (AOP_SIZE (IC_RESULT (ic)) == 3 && AOP_SIZE (IC_LEFT (ic)) == 3 && !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)))) - aopPut (AOP (IC_RESULT (ic)), - aopGet (AOP (IC_LEFT (ic)), 2, FALSE, FALSE), + aopPut (IC_RESULT (ic), + aopGet (IC_LEFT (ic)), 2, FALSE, FALSE), 2, isOperandVolatile (IC_RESULT (ic), FALSE)); if (AOP_SIZE (IC_RESULT (ic)) == 3 && AOP_SIZE (IC_RIGHT (ic)) == 3 && !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) - aopPut (AOP (IC_RESULT (ic)), - aopGet (AOP (IC_RIGHT (ic)), 2, FALSE, FALSE), + aopPut (IC_RESULT (ic), + aopGet (IC_RIGHT (ic)), 2, FALSE, FALSE), 2, isOperandVolatile (IC_RESULT (ic), FALSE)); @@ -3543,8 +3683,8 @@ adjustArithmeticResult (iCode * ic) !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) { char buffer[5]; - sprintf (buffer, "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic))))); - aopPut (AOP (IC_RESULT (ic)), buffer, 2, isOperandVolatile (IC_RESULT (ic), FALSE)); + sprintf (buffer, "#%d", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL)); + aopPut (IC_RESULT (ic), buffer, 2, isOperandVolatile (IC_RESULT (ic), FALSE)); } } #else @@ -3559,8 +3699,8 @@ adjustArithmeticResult (iCode * ic) opIsGptr (IC_LEFT (ic)) && !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_LEFT (ic)))) { - aopPut (AOP (IC_RESULT (ic)), - aopGet (AOP (IC_LEFT (ic)), GPTRSIZE - 1, FALSE, FALSE), + aopPut (IC_RESULT (ic), + aopGet (IC_LEFT (ic), GPTRSIZE - 1, FALSE, FALSE), GPTRSIZE - 1, isOperandVolatile (IC_RESULT (ic), FALSE)); } @@ -3569,8 +3709,8 @@ adjustArithmeticResult (iCode * ic) opIsGptr (IC_RIGHT (ic)) && !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) { - aopPut (AOP (IC_RESULT (ic)), - aopGet (AOP (IC_RIGHT (ic)), GPTRSIZE - 1, FALSE, FALSE), + aopPut (IC_RESULT (ic), + aopGet (IC_RIGHT (ic), GPTRSIZE - 1, FALSE, FALSE), GPTRSIZE - 1, isOperandVolatile (IC_RESULT (ic), FALSE)); } @@ -3582,8 +3722,8 @@ adjustArithmeticResult (iCode * ic) !sameRegs (AOP (IC_RESULT (ic)), AOP (IC_RIGHT (ic)))) { char buffer[5]; - sprintf (buffer, "#%d", pointerCode (getSpec (operandType (IC_LEFT (ic))))); - aopPut (AOP (IC_RESULT (ic)), buffer, GPTRSIZE - 1, isOperandVolatile (IC_RESULT (ic), FALSE)); + sprintf (buffer, "#%d", pointerTypeToGPByte (pointerCode (getSpec (operandType (IC_LEFT (ic)))), NULL, NULL)); + aopPut (IC_RESULT (ic), buffer, GPTRSIZE - 1, isOperandVolatile (IC_RESULT (ic), FALSE)); } } #endif @@ -3597,7 +3737,7 @@ genPlus (iCode * ic) int size, offset = 0; int skip_bytes = 0; char *add = "add"; - asmop *leftOp, *rightOp; + operand *leftOp, *rightOp; operand * op; /* special cases :- */ @@ -3646,9 +3786,9 @@ genPlus (iCode * ic) size = getDataSize (IC_RESULT (ic)); while (size--) { - MOVA (aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE)); + MOVA (aopGet (IC_RIGHT (ic), offset, FALSE, FALSE)); emitcode ("addc", "a,#00"); - aopPut (AOP (IC_RESULT (ic)), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } } goto release; @@ -3660,8 +3800,8 @@ genPlus (iCode * ic) goto release; size = getDataSize (IC_RESULT (ic)); - leftOp = AOP(IC_LEFT(ic)); - rightOp = AOP(IC_RIGHT(ic)); + leftOp = IC_LEFT(ic); + rightOp = IC_RIGHT(ic); op=IC_LEFT(ic); /* if this is an add for an array access @@ -3675,23 +3815,23 @@ genPlus (iCode * ic) ) { D(emitcode ("; genPlus aligned array","")); - aopPut (AOP (IC_RESULT (ic)), + aopPut (IC_RESULT (ic), aopGet (rightOp, 0, FALSE, FALSE), 0, isOperandVolatile (IC_RESULT (ic), FALSE)); if( 1 == getDataSize (IC_RIGHT (ic)) ) { - aopPut (AOP (IC_RESULT (ic)), + aopPut (IC_RESULT (ic), aopGet (leftOp, 1, FALSE, FALSE), 1, isOperandVolatile (IC_RESULT (ic), FALSE)); } else { - MOVA (aopGet (AOP (IC_LEFT (ic)), 1, FALSE, FALSE)); + MOVA (aopGet (IC_LEFT (ic), 1, FALSE, FALSE)); emitcode ("add", "a,%s", aopGet (rightOp, 1, FALSE, FALSE)); - aopPut (AOP (IC_RESULT (ic)), "a", 1, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", 1, isOperandVolatile (IC_RESULT (ic), FALSE)); } goto release; } @@ -3732,7 +3872,7 @@ genPlus (iCode * ic) MOVA (aopGet (rightOp, offset, FALSE, TRUE)); emitcode (add, "a,%s", aopGet (leftOp, offset, FALSE, TRUE)); } - aopPut (AOP (IC_RESULT (ic)), "a", offset, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset, isOperandVolatile (IC_RESULT (ic), FALSE)); add = "addc"; /* further adds must propagate carry */ } else @@ -3741,7 +3881,7 @@ genPlus (iCode * ic) isOperandVolatile (IC_RESULT (ic), FALSE)) { /* just move */ - aopPut (AOP (IC_RESULT (ic)), + aopPut (IC_RESULT (ic), aopGet (leftOp, offset, FALSE, FALSE), offset, isOperandVolatile (IC_RESULT (ic), FALSE)); @@ -3808,49 +3948,49 @@ genMinusDec (iCode * ic) emitTlbl = 1; } - emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE)); + emitcode ("dec", "%s", aopGet (IC_RESULT (ic), LSB, FALSE, FALSE)); if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG || IS_AOP_PREG (IC_RESULT (ic))) emitcode ("cjne", "%s,#0xff,%05d$" - ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE) + ,aopGet (IC_RESULT (ic), LSB, FALSE, FALSE) ,tlbl->key + 100); else { emitcode ("mov", "a,#0xff"); emitcode ("cjne", "a,%s,%05d$" - ,aopGet (AOP (IC_RESULT (ic)), LSB, FALSE, FALSE) + ,aopGet (IC_RESULT (ic), LSB, FALSE, FALSE) ,tlbl->key + 100); } - emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE)); + emitcode ("dec", "%s", aopGet (IC_RESULT (ic), MSB16, FALSE, FALSE)); if (size > 2) { if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG || IS_AOP_PREG (IC_RESULT (ic))) emitcode ("cjne", "%s,#0xff,%05d$" - ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE) + ,aopGet (IC_RESULT (ic), MSB16, FALSE, FALSE) ,tlbl->key + 100); else { emitcode ("cjne", "a,%s,%05d$" - ,aopGet (AOP (IC_RESULT (ic)), MSB16, FALSE, FALSE) + ,aopGet (IC_RESULT (ic), MSB16, FALSE, FALSE) ,tlbl->key + 100); } - emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE)); + emitcode ("dec", "%s", aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE)); } if (size > 3) { if (AOP_TYPE (IC_RESULT (ic)) == AOP_REG || IS_AOP_PREG (IC_RESULT (ic))) emitcode ("cjne", "%s,#0xff,%05d$" - ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE) + ,aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE) ,tlbl->key + 100); else { emitcode ("cjne", "a,%s,%05d$" - ,aopGet (AOP (IC_RESULT (ic)), MSB24, FALSE, FALSE) + ,aopGet (IC_RESULT (ic), MSB24, FALSE, FALSE) ,tlbl->key + 100); } - emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), MSB32, FALSE, FALSE)); + emitcode ("dec", "%s", aopGet (IC_RESULT (ic), MSB32, FALSE, FALSE)); } if (emitTlbl) { @@ -3871,7 +4011,7 @@ genMinusDec (iCode * ic) { while (icount--) - emitcode ("dec", "%s", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE)); + emitcode ("dec", "%s", aopGet (IC_RESULT (ic), 0, FALSE, FALSE)); return TRUE; } @@ -3893,11 +4033,11 @@ addSign (operand * result, int offset, int sign) emitcode ("rlc", "a"); emitcode ("subb", "a,acc"); while (size--) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } else while (size--) - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); } } @@ -3926,7 +4066,7 @@ genMinusBits (iCode * ic) emitcode ("jnb", "%s,%05d$", AOP (IC_LEFT (ic))->aopu.aop_dir, (lbl->key + 100)); emitcode ("inc", "a"); emitcode ("", "%05d$:", (lbl->key + 100)); - aopPut (AOP (IC_RESULT (ic)), "a", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); addSign (IC_RESULT (ic), MSB16, SPEC_USIGN (getSpec (operandType (IC_RESULT (ic))))); } } @@ -3965,34 +4105,39 @@ genMinus (iCode * ic) if (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT) { unsigned long lit = 0L; + bool useCarry = FALSE; lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); lit = -(long) lit; while (size--) { - MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE)); - /* first add without previous c */ - if (!offset) { - if (!size && lit== (unsigned long) -1) { + if (useCarry || ((lit >> (offset * 8)) & 0x0FFL)) { + MOVA (aopGet (IC_LEFT (ic), offset, FALSE, FALSE)); + if (!offset && !size && lit== (unsigned long) -1) { emitcode ("dec", "a"); - } else { + } else if (!useCarry) { + /* first add without previous c */ emitcode ("add", "a,#0x%02x", - (unsigned int) (lit & 0x0FFL)); - } + (unsigned int) ((lit >> (offset * 8)) & 0x0FFL)); + useCarry = TRUE; } else { emitcode ("addc", "a,#0x%02x", (unsigned int) ((lit >> (offset * 8)) & 0x0FFL)); } - aopPut (AOP (IC_RESULT (ic)), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + } else { + /* no need to add zeroes */ + offset++; + } } } else { - asmop *leftOp, *rightOp; + operand *leftOp, *rightOp; - leftOp = AOP(IC_LEFT(ic)); - rightOp = AOP(IC_RIGHT(ic)); + leftOp = IC_LEFT(ic); + rightOp = IC_RIGHT(ic); while (size--) { @@ -4025,7 +4170,7 @@ genMinus (iCode * ic) aopGet(rightOp, offset, FALSE, TRUE)); } - aopPut (AOP (IC_RESULT (ic)), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } } @@ -4112,19 +4257,19 @@ genMultOneByte (operand * left, if (AOP_TYPE (right) == AOP_LIT) { /* moving to accumulator first helps peepholes */ - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); } else { - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); } emitcode ("mul", "ab"); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); if (size == 2) - aopPut (AOP (result), "b", 1, isOperandVolatile (result, FALSE)); + aopPut (result, "b", 1, isOperandVolatile (result, FALSE)); popB (pushedB); return; @@ -4192,10 +4337,10 @@ genMultOneByte (operand * left, { if (rUnsigned) /* emitcode (";", "signed"); */ - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); else { - MOVA (aopGet (AOP (right), 0, FALSE, FALSE)); + MOVA (aopGet (right, 0, FALSE, FALSE)); lbl = newiTempLabel (NULL); emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100)); emitcode ("cpl", "F0"); /* complement sign flag */ @@ -4217,7 +4362,7 @@ genMultOneByte (operand * left, } else /* ! literal */ { - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); if (!lUnsigned) { @@ -4250,9 +4395,9 @@ genMultOneByte (operand * left, } emitcode ("", "%05d$:", (lbl->key + 100)); } - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); if (size == 2) - aopPut (AOP (result), "b", 1, isOperandVolatile (result, FALSE)); + aopPut (result, "b", 1, isOperandVolatile (result, FALSE)); popB (pushedB); } @@ -4322,8 +4467,8 @@ genDivbits (operand * left, pushedB = pushB (); /* the result must be bit */ - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); - l = aopGet (AOP (left), 0, FALSE, FALSE); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); + l = aopGet (left, 0, FALSE, FALSE); MOVA (l); @@ -4332,7 +4477,7 @@ genDivbits (operand * left, popB (pushedB); - aopPut (AOP (result), "c", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "c", 0, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -4387,12 +4532,12 @@ genDivOneByte (operand * left, if (lUnsigned && rUnsigned) { /* unsigned is easy */ - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); emitcode ("div", "ab"); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); while (size--) - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); popB (pushedB); return; @@ -4458,10 +4603,10 @@ genDivOneByte (operand * left, else /* ! literal */ { if (rUnsigned) - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); else { - MOVA (aopGet (AOP (right), 0, FALSE, FALSE)); + MOVA (aopGet (right, 0, FALSE, FALSE)); lbl = newiTempLabel (NULL); emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100)); emitcode ("cpl", "F0"); /* complement sign flag */ @@ -4483,7 +4628,7 @@ genDivOneByte (operand * left, } else /* ! literal */ { - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); if (!lUnsigned) { @@ -4508,7 +4653,7 @@ genDivOneByte (operand * left, emitcode ("inc", "a"); emitcode ("", "%05d$:", (lbl->key + 100)); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); if (size > 0) { /* msb is 0x00 or 0xff depending on the sign */ @@ -4517,18 +4662,18 @@ genDivOneByte (operand * left, emitcode ("mov", "c,F0"); emitcode ("subb", "a,acc"); while (size--) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } else /* compiletimeSign */ while (size--) - aopPut (AOP (result), "#0xff", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "#0xff", offset++, isOperandVolatile (result, FALSE)); } } else { - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); while (size--) - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); } popB (pushedB); @@ -4592,8 +4737,8 @@ genModbits (operand * left, pushedB = pushB (); /* the result must be bit */ - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); - l = aopGet (AOP (left), 0, FALSE, FALSE); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); + l = aopGet (left, 0, FALSE, FALSE); MOVA (l); @@ -4603,7 +4748,7 @@ genModbits (operand * left, popB (pushedB); - aopPut (AOP (result), "c", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "c", 0, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -4626,18 +4771,73 @@ genModOneByte (operand * left, lUnsigned = SPEC_USIGN (getSpec (operandType (left))); rUnsigned = SPEC_USIGN (getSpec (operandType (right))); + /* if right is a literal, check it for 2^n */ + if (AOP_TYPE(right) == AOP_LIT) + { + unsigned char val = abs((int) operandLitValue(right)); + symbol *lbl2 = NULL; + + switch (val) + { + case 1: /* sometimes it makes sense (on tricky code and hardware)... */ + case 2: + case 4: + case 8: + case 16: + case 32: + case 64: + case 128: + if (lUnsigned) + werror (E_INTERNAL_ERROR, __FILE__, __LINE__, + "modulus of unsigned char by 2^n literal shouldn't be processed here"); + /* because iCode should have been changed to genAnd */ + /* see file "SDCCopt.c", function "convertToFcall()" */ + + MOVA (aopGet (left, 0, FALSE, FALSE)); + emitcode ("mov", "c,acc.7"); + emitcode ("anl", "a,#0x%02x", val - 1); + lbl = newiTempLabel (NULL); + emitcode ("jz", "%05d$", (lbl->key + 100)); + emitcode ("jnc", "%05d$", (lbl->key + 100)); + emitcode ("orl", "a,#0x%02x", 0xff ^ (val - 1)); + if (size) + { + int size2 = size; + int offs2 = offset; + + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); + while (size2--) + aopPut (result, "#0xff", offs2++, isOperandVolatile (result, FALSE)); + lbl2 = newiTempLabel (NULL); + emitcode ("sjmp", "%05d$", (lbl2->key + 100)); + } + emitcode ("", "%05d$:", (lbl->key + 100)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); + while (size--) + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); + if (lbl2) + { + emitcode ("", "%05d$:", (lbl2->key + 100)); + } + return; + + default: + break; + } + } + pushedB = pushB (); /* signed or unsigned */ if (lUnsigned && rUnsigned) { /* unsigned is easy */ - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); emitcode ("div", "ab"); - aopPut (AOP (result), "b", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "b", 0, isOperandVolatile (result, FALSE)); while (size--) - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); popB (pushedB); return; @@ -4650,7 +4850,7 @@ genModOneByte (operand * left, /* modulus: sign of the right operand has no influence on the result! */ if (AOP_TYPE(right) == AOP_LIT) { - signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit); + signed char val = (char) operandLitValue(right); if (!rUnsigned && val < 0) emitcode ("mov", "b,#0x%02x", -val); @@ -4660,10 +4860,10 @@ genModOneByte (operand * left, else /* not literal */ { if (rUnsigned) - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); else { - MOVA (aopGet (AOP (right), 0, FALSE, FALSE)); + MOVA (aopGet (right, 0, FALSE, FALSE)); lbl = newiTempLabel (NULL); emitcode ("jnb", "acc.7,%05d$", (lbl->key + 100)); emitcode ("cpl", "a"); /* 2's complement */ @@ -4694,7 +4894,7 @@ genModOneByte (operand * left, } else /* ! literal */ { - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); if (!lUnsigned) { @@ -4723,7 +4923,7 @@ genModOneByte (operand * left, emitcode ("inc", "a"); emitcode ("", "%05d$:", (lbl->key + 100)); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); if (size > 0) { /* msb is 0x00 or 0xff depending on the sign */ @@ -4732,18 +4932,18 @@ genModOneByte (operand * left, emitcode ("mov", "c,F0"); emitcode ("subb", "a,acc"); while (size--) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } else /* compiletimeSign */ while (size--) - aopPut (AOP (result), "#0xff", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "#0xff", offset++, isOperandVolatile (result, FALSE)); } } else { - aopPut (AOP (result), "b", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "b", 0, isOperandVolatile (result, FALSE)); while (size--) - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); } popB (pushedB); @@ -4761,7 +4961,7 @@ genMod (iCode * ic) D(emitcode ("; genMod","")); - /* assign the amsops */ + /* assign the asmops */ aopOp (left, ic, FALSE); aopOp (right, ic, FALSE); aopOp (result, ic, TRUE); @@ -4866,8 +5066,8 @@ genCmp (operand * left, operand * right, { symbol *lbl = newiTempLabel (NULL); emitcode ("cjne", "%s,%s,%05d$", - aopGet (AOP (left), offset, FALSE, FALSE), - aopGet (AOP (right), offset, FALSE, FALSE), + aopGet (left, offset, FALSE, FALSE), + aopGet (right, offset, FALSE, FALSE), lbl->key + 100); emitcode ("", "%05d$:", lbl->key + 100); } @@ -4885,7 +5085,7 @@ genCmp (operand * left, operand * right, } else { - MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE)); + MOVA (aopGet (left, AOP_SIZE (left) - 1, FALSE, FALSE)); if (!(AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) && ifx) { genIfxJump (ifx, "acc.7", left, right, result); @@ -4904,13 +5104,13 @@ genCmp (operand * left, operand * right, while (size--) { bool pushedB = FALSE; - rightInB = aopGetUsesAcc(AOP (right), offset); + rightInB = aopGetUsesAcc(right, offset); if (rightInB) { pushedB = pushB (); - emitcode ("mov", "b,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, offset, FALSE, FALSE)); } - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); if (sign && size == 0) { emitcode ("xrl", "a,#0x80"); @@ -4927,7 +5127,7 @@ genCmp (operand * left, operand * right, { pushedB = pushB (); rightInB++; - emitcode ("mov", "b,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, offset, FALSE, FALSE)); } emitcode ("xrl", "b,#0x80"); emitcode ("subb", "a,b"); @@ -4938,7 +5138,7 @@ genCmp (operand * left, operand * right, if (rightInB) emitcode ("subb", "a,b"); else - emitcode ("subb", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + emitcode ("subb", "a,%s", aopGet (right, offset, FALSE, FALSE)); } if (rightInB) popB (pushedB); @@ -4992,7 +5192,7 @@ genCmpGt (iCode * ic, iCode * ifx) aopOp (right, ic, FALSE); aopOp (result, ic, TRUE); - genCmp (right, left, result, ifx, sign,ic); + genCmp (right, left, result, ifx, sign, ic); freeAsmop (result, NULL, ic, TRUE); } @@ -5060,8 +5260,8 @@ gencjneshort (operand * left, operand * right, symbol * lbl) while (size--) { emitcode ("cjne", "%s,%s,%05d$", - aopGet (AOP (left), offset, FALSE, FALSE), - aopGet (AOP (right), offset, FALSE, FALSE), + aopGet (left, offset, FALSE, FALSE), + aopGet (right, offset, FALSE, FALSE), lbl->key + 100); offset++; } @@ -5078,13 +5278,13 @@ gencjneshort (operand * left, operand * right, symbol * lbl) { while (size--) { - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); if ((AOP_TYPE (left) == AOP_DIR && AOP_TYPE (right) == AOP_LIT) && ((unsigned int) ((lit >> (offset * 8)) & 0x0FFL) == 0)) emitcode ("jnz", "%05d$", lbl->key + 100); else emitcode ("cjne", "a,%s,%05d$", - aopGet (AOP (right), offset, FALSE, TRUE), + aopGet (right, offset, FALSE, TRUE), lbl->key + 100); offset++; } @@ -5096,11 +5296,11 @@ gencjneshort (operand * left, operand * right, symbol * lbl) { char *l; //if B in use: push B; mov B,left; mov A,right; clrc; subb A,B; pop B; jnz - wassertl(!_G.BInUse, "B was in use"); - l = aopGet (AOP (left), offset, FALSE, FALSE); + wassertl(!BINUSE, "B was in use"); + l = aopGet (left, offset, FALSE, FALSE); if (strcmp (l, "b")) emitcode ("mov", "b,%s", l); - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode ("cjne", "a,b,%05d$", lbl->key + 100); offset++; } @@ -5282,7 +5482,7 @@ genCmpEq (iCode * ic, iCode * ifx) gencjne (left, right, newiTempLabel (NULL)); if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) { - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); goto release; } if (ifx) @@ -5616,7 +5816,7 @@ genAnd (iCode * ic, iCode * ifx) else { // c = bit & val; - MOVA (aopGet (AOP (right), 0, FALSE, FALSE)); + MOVA (aopGet (right, 0, FALSE, FALSE)); // c = lsb emitcode ("rrc", "a"); emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir); @@ -5643,10 +5843,20 @@ genAnd (iCode * ic, iCode * ifx) if (posbit) { posbit--; - MOVA (aopGet (AOP (left), posbit >> 3, FALSE, FALSE)); + MOVA (aopGet (left, posbit >> 3, FALSE, FALSE)); // bit = left & 2^n if (size) - emitcode ("mov", "c,acc.%d", posbit & 0x07); + { + switch (posbit & 0x07) + { + case 0: emitcode ("rrc", "a"); + break; + case 7: emitcode ("rlc", "a"); + break; + default: emitcode ("mov", "c,acc.%d", posbit & 0x07); + break; + } + } // if(left & 2^n) else { @@ -5673,7 +5883,7 @@ genAnd (iCode * ic, iCode * ifx) { if ((bytelit = ((lit >> (offset * 8)) & 0x0FFL)) != 0x0L) { - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); // byte == 2^n ? if ((posbit = isLiteralBit (bytelit)) != 0) emitcode ("jb", "acc.%d,%05d$", (posbit - 1) & 0x07, tlbl->key + 100); @@ -5681,7 +5891,7 @@ genAnd (iCode * ic, iCode * ifx) { if (bytelit != 0x0FFL) emitcode ("anl", "a,%s", - aopGet (AOP (right), offset, FALSE, TRUE)); + aopGet (right, offset, FALSE, TRUE)); emitcode ("jnz", "%05d$", tlbl->key + 100); } } @@ -5719,40 +5929,42 @@ genAnd (iCode * ic, iCode * ifx) { /* dummy read of volatile operand */ if (isOperandVolatile (left, FALSE)) - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); else continue; } else if (bytelit == 0) { - aopPut (AOP (result), zero, offset, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset, isOperandVolatile (result, FALSE)); } else if (IS_AOP_PREG (result)) { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); - emitcode ("anl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, offset, FALSE, TRUE)); + emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else emitcode ("anl", "%s,%s", - aopGet (AOP (left), offset, FALSE, TRUE), - aopGet (AOP (right), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, TRUE), + aopGet (right, offset, FALSE, FALSE)); } else { - if (AOP_TYPE (left) == AOP_ACC) - emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + if (AOP_TYPE (left) == AOP_ACC && offset == 0) + { + emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); if (IS_AOP_PREG (result)) { - emitcode ("anl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + emitcode ("anl", "a,%s", aopGet (left, offset, FALSE, TRUE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else emitcode ("anl", "%s,a", - aopGet (AOP (left), offset, FALSE, TRUE)); + aopGet (left, offset, FALSE, TRUE)); } } } @@ -5771,20 +5983,33 @@ genAnd (iCode * ic, iCode * ifx) emitcode ("setb", "c"); while (sizer--) { - if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) { - emitcode ("anl", "a,%s", - aopGet (AOP (right), offset, FALSE, FALSE)); - } else { - if (AOP_TYPE(left)==AOP_ACC) { - bool pushedB = pushB (); - emitcode("mov", "b,a"); - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); - emitcode("anl", "a,b"); - popB (pushedB); - }else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + if ((AOP_TYPE(right)==AOP_REG || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR) + && AOP_TYPE(left)==AOP_ACC) + { + if (offset) + emitcode("mov", "a,b"); + emitcode ("anl", "a,%s", + aopGet (right, offset, FALSE, FALSE)); + } else { + if (AOP_TYPE(left)==AOP_ACC) + { + if (!offset) + { + bool pushedB = pushB (); + emitcode("mov", "b,a"); + MOVA (aopGet (right, offset, FALSE, FALSE)); + emitcode("anl", "a,b"); + popB (pushedB); + } + else + { + MOVA (aopGet (right, offset, FALSE, FALSE)); + emitcode("anl", "a,b"); + } + } else { + MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode ("anl", "a,%s", - aopGet (AOP (left), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, FALSE)); } } emitcode ("jnz", "%05d$", tlbl->key + 100); @@ -5812,8 +6037,8 @@ genAnd (iCode * ic, iCode * ifx) bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL); if (bytelit == 0x0FF) { - aopPut (AOP (result), - aopGet (AOP (left), offset, FALSE, FALSE), + aopPut (result, + aopGet (left, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); continue; @@ -5822,22 +6047,41 @@ genAnd (iCode * ic, iCode * ifx) { /* dummy read of volatile operand */ if (isOperandVolatile (left, FALSE)) - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); - aopPut (AOP (result), zero, offset, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); + aopPut (result, zero, offset, isOperandVolatile (result, FALSE)); continue; } + else if (AOP_TYPE (left) == AOP_ACC) + { + if (!offset) + { + emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); + continue; + } + else + { + emitcode ("anl", "b,%s", aopGet (right, offset, FALSE, FALSE)); + aopPut (result, "b", offset, isOperandVolatile (result, FALSE)); + continue; + } + } } // faster than result <- left, anl result,right // and better if result is SFR if (AOP_TYPE (left) == AOP_ACC) - emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + { + if (offset) + emitcode("mov", "a,b"); + emitcode ("anl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode ("anl", "a,%s", - aopGet (AOP (left), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, FALSE)); } - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } } } @@ -6022,43 +6266,47 @@ genOr (iCode * ic, iCode * ifx) { /* dummy read of volatile operand */ if (isOperandVolatile (left, FALSE)) - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); else continue; } else if (bytelit == 0x0FF) { - aopPut (AOP (result), "#0xFF", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "#0xFF", offset, isOperandVolatile (result, FALSE)); } else if (IS_AOP_PREG (left)) { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); - emitcode ("orl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, offset, FALSE, TRUE)); + emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else { emitcode ("orl", "%s,%s", - aopGet (AOP (left), offset, FALSE, TRUE), - aopGet (AOP (right), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, TRUE), + aopGet (right, offset, FALSE, FALSE)); } } else { if (AOP_TYPE (left) == AOP_ACC) - emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + { + if (offset) + emitcode("mov", "a,b"); + emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); if (IS_AOP_PREG (left)) { - emitcode ("orl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + emitcode ("orl", "a,%s", aopGet (left, offset, FALSE, TRUE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else { emitcode ("orl", "%s,a", - aopGet (AOP (left), offset, FALSE, TRUE)); + aopGet (left, offset, FALSE, TRUE)); } } } @@ -6079,12 +6327,14 @@ genOr (iCode * ic, iCode * ifx) while (sizer--) { if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) { + if (offset) + emitcode("mov", "a,b"); emitcode ("orl", "a,%s", - aopGet (AOP (right), offset, FALSE, FALSE)); + aopGet (right, offset, FALSE, FALSE)); } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode ("orl", "a,%s", - aopGet (AOP (left), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, FALSE)); } emitcode ("jnz", "%05d$", tlbl->key + 100); offset++; @@ -6111,8 +6361,8 @@ genOr (iCode * ic, iCode * ifx) bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL); if (bytelit == 0) { - aopPut (AOP (result), - aopGet (AOP (left), offset, FALSE, FALSE), + aopPut (result, + aopGet (left, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); continue; @@ -6121,22 +6371,26 @@ genOr (iCode * ic, iCode * ifx) { /* dummy read of volatile operand */ if (isOperandVolatile (left, FALSE)) - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); - aopPut (AOP (result), "#0xFF", offset, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); + aopPut (result, "#0xFF", offset, isOperandVolatile (result, FALSE)); continue; } } // faster than result <- left, anl result,right // and better if result is SFR if (AOP_TYPE (left) == AOP_ACC) - emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + { + if (offset) + emitcode("mov", "a,b"); + emitcode ("orl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode ("orl", "a,%s", - aopGet (AOP (left), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, FALSE)); } - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } } } @@ -6268,7 +6522,7 @@ genXor (iCode * ic, iCode * ifx) emitcode ("setb", "c"); while (sizer) { - MOVA (aopGet (AOP (right), sizer - 1, FALSE, FALSE)); + MOVA (aopGet (right, sizer - 1, FALSE, FALSE)); if (sizer == 1) // test the msb of the lsb emitcode ("anl", "a,#0xfe"); @@ -6304,38 +6558,42 @@ genXor (iCode * ic, iCode * ifx) { /* dummy read of volatile operand */ if (isOperandVolatile (left, FALSE)) - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); else continue; } else if (IS_AOP_PREG (left)) { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); - emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, offset, FALSE, TRUE)); + emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else { emitcode ("xrl", "%s,%s", - aopGet (AOP (left), offset, FALSE, TRUE), - aopGet (AOP (right), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, TRUE), + aopGet (right, offset, FALSE, FALSE)); } } else { if (AOP_TYPE (left) == AOP_ACC) - emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + { + if (offset) + emitcode("mov", "a,b"); + emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); if (IS_AOP_PREG (left)) { - emitcode ("xrl", "a,%s", aopGet (AOP (left), offset, FALSE, TRUE)); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + emitcode ("xrl", "a,%s", aopGet (left, offset, FALSE, TRUE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else emitcode ("xrl", "%s,a", - aopGet (AOP (left), offset, FALSE, TRUE)); + aopGet (left, offset, FALSE, TRUE)); } } } @@ -6357,17 +6615,19 @@ genXor (iCode * ic, iCode * ifx) if ((AOP_TYPE (right) == AOP_LIT) && (((lit >> (offset * 8)) & 0x0FFL) == 0x00L)) { - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); } else { if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) { + if (offset) + emitcode("mov", "a,b"); emitcode ("xrl", "a,%s", - aopGet (AOP (right), offset, FALSE, FALSE)); + aopGet (right, offset, FALSE, FALSE)); } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode ("xrl", "a,%s", - aopGet (AOP (left), offset, FALSE, FALSE)); + aopGet (left, offset, FALSE, FALSE)); } } emitcode ("jnz", "%05d$", tlbl->key + 100); @@ -6393,8 +6653,8 @@ genXor (iCode * ic, iCode * ifx) bytelit = (int) ((lit >> (offset * 8)) & 0x0FFL); if (bytelit == 0) { - aopPut (AOP (result), - aopGet (AOP (left), offset, FALSE, FALSE), + aopPut (result, + aopGet (left, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); continue; @@ -6403,14 +6663,18 @@ genXor (iCode * ic, iCode * ifx) // faster than result <- left, anl result,right // and better if result is SFR if (AOP_TYPE (left) == AOP_ACC) - emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE)); + { + if (offset) + emitcode("mov", "a,b"); + emitcode ("xrl", "a,%s", aopGet (right, offset, FALSE, FALSE)); + } else { - MOVA (aopGet (AOP (right), offset, FALSE, FALSE)); + MOVA (aopGet (right, offset, FALSE, FALSE)); emitcode ("xrl", "a,%s", - aopGet (AOP (left), offset, FALSE, TRUE)); + aopGet (left, offset, FALSE, TRUE)); } - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } } } @@ -6488,30 +6752,30 @@ genRRC (iCode * ic) size = AOP_SIZE (result); offset = size - 1; if (size == 1) { /* special case for 1 byte */ - l = aopGet (AOP (left), offset, FALSE, FALSE); + l = aopGet (left, offset, FALSE, FALSE); MOVA (l); emitcode ("rr", "a"); goto release; } - CLRC; + /* no need to clear carry, bit7 will be written later */ while (size--) { - l = aopGet (AOP (left), offset, FALSE, FALSE); + l = aopGet (left, offset, FALSE, FALSE); MOVA (l); emitcode ("rrc", "a"); if (AOP_SIZE (result) > 1) - aopPut (AOP (result), "a", offset--, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset--, isOperandVolatile (result, FALSE)); } /* now we need to put the carry into the highest order byte of the result */ if (AOP_SIZE (result) > 1) { - l = aopGet (AOP (result), AOP_SIZE (result) - 1, FALSE, FALSE); + l = aopGet (result, AOP_SIZE (result) - 1, FALSE, FALSE); MOVA (l); } emitcode ("mov", "acc.7,c"); release: - aopPut (AOP (result), "a", AOP_SIZE (result) - 1, isOperandVolatile (result, FALSE)); + aopPut (result, "a", AOP_SIZE (result) - 1, isOperandVolatile (result, FALSE)); freeAsmop (left, NULL, ic, TRUE); freeAsmop (result, NULL, ic, TRUE); } @@ -6539,34 +6803,34 @@ genRLC (iCode * ic) offset = 0; if (size--) { - l = aopGet (AOP (left), offset, FALSE, FALSE); + l = aopGet (left, offset, FALSE, FALSE); MOVA (l); if (size == 0) { /* special case for 1 byte */ emitcode("rl","a"); goto release; } - emitcode ("add", "a,acc"); + emitcode("rlc","a"); /* bit0 will be written later */ if (AOP_SIZE (result) > 1) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); while (size--) { - l = aopGet (AOP (left), offset, FALSE, FALSE); + l = aopGet (left, offset, FALSE, FALSE); MOVA (l); emitcode ("rlc", "a"); if (AOP_SIZE (result) > 1) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } } /* now we need to put the carry into the highest order byte of the result */ if (AOP_SIZE (result) > 1) { - l = aopGet (AOP (result), 0, FALSE, FALSE); + l = aopGet (result, 0, FALSE, FALSE); MOVA (l); } emitcode ("mov", "acc.0,c"); release: - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); freeAsmop (left, NULL, ic, TRUE); freeAsmop (result, NULL, ic, TRUE); } @@ -6587,7 +6851,7 @@ genGetHbit (iCode * ic) aopOp (result, ic, FALSE); /* get the highest order byte into a */ - MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE)); + MOVA (aopGet (left, AOP_SIZE (left) - 1, FALSE, FALSE)); if (AOP_TYPE (result) == AOP_CRY) { emitcode ("rlc", "a"); @@ -6623,43 +6887,43 @@ genSwap (iCode * ic) switch (AOP_SIZE (left)) { case 1: /* swap nibbles in byte */ - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); + MOVA (aopGet (left, 0, FALSE, FALSE)); emitcode ("swap", "a"); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); break; case 2: /* swap bytes in word */ if (AOP_TYPE(left) == AOP_REG && sameRegs(AOP(left), AOP(result))) { - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); - aopPut (AOP (result), aopGet (AOP (left), 1, FALSE, FALSE), + MOVA (aopGet (left, 0, FALSE, FALSE)); + aopPut (result, aopGet (left, 1, FALSE, FALSE), 0, isOperandVolatile (result, FALSE)); - aopPut (AOP (result), "a", 1, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 1, isOperandVolatile (result, FALSE)); } else if (operandsEqu (left, result)) { char * reg = "a"; bool pushedB = FALSE, leftInB = FALSE; - MOVA (aopGet (AOP (left), 0, FALSE, FALSE)); - if (aopGetUsesAcc(AOP (left), 1) || aopGetUsesAcc(AOP (result), 0)) + MOVA (aopGet (left, 0, FALSE, FALSE)); + if (aopGetUsesAcc(left, 1) || aopGetUsesAcc(result, 0)) { pushedB = pushB (); emitcode ("mov", "b,a"); reg = "b"; leftInB = TRUE; } - aopPut (AOP (result), aopGet (AOP (left), 1, FALSE, FALSE), + aopPut (result, aopGet (left, 1, FALSE, FALSE), 0, isOperandVolatile (result, FALSE)); - aopPut (AOP (result), reg, 1, isOperandVolatile (result, FALSE)); + aopPut (result, reg, 1, isOperandVolatile (result, FALSE)); if (leftInB) popB (pushedB); } else { - aopPut (AOP (result), aopGet (AOP (left), 1, FALSE, FALSE), + aopPut (result, aopGet (left, 1, FALSE, FALSE), 0, isOperandVolatile (result, FALSE)); - aopPut (AOP (result), aopGet (AOP (left), 0, FALSE, FALSE), + aopPut (result, aopGet (left, 0, FALSE, FALSE), 1, isOperandVolatile (result, FALSE)); } break; @@ -6804,13 +7068,13 @@ shiftR1Left2Result (operand * left, int offl, operand * result, int offr, int shCount, int sign) { - MOVA (aopGet (AOP (left), offl, FALSE, FALSE)); + MOVA (aopGet (left, offl, FALSE, FALSE)); /* shift right accumulator */ if (sign) AccSRsh (shCount); else AccRsh (shCount); - aopPut (AOP (result), "a", offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offr, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -6821,11 +7085,11 @@ shiftL1Left2Result (operand * left, int offl, operand * result, int offr, int shCount) { char *l; - l = aopGet (AOP (left), offl, FALSE, FALSE); + l = aopGet (left, offl, FALSE, FALSE); MOVA (l); /* shift left accumulator */ AccLsh (shCount); - aopPut (AOP (result), "a", offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offr, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -6838,24 +7102,24 @@ movLeft2Result (operand * left, int offl, char *l; if (!sameRegs (AOP (left), AOP (result)) || (offl != offr)) { - l = aopGet (AOP (left), offl, FALSE, FALSE); + l = aopGet (left, offl, FALSE, FALSE); if (*l == '@' && (IS_AOP_PREG (result))) { emitcode ("mov", "a,%s", l); - aopPut (AOP (result), "a", offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offr, isOperandVolatile (result, FALSE)); } else { if (!sign) - aopPut (AOP (result), l, offr, isOperandVolatile (result, FALSE)); + aopPut (result, l, offr, isOperandVolatile (result, FALSE)); else { /* MSB sign in acc.7 ! */ if (getDataSize (left) == offl + 1) { emitcode ("mov", "a,%s", l); - aopPut (AOP (result), "a", offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offr, isOperandVolatile (result, FALSE)); } } } @@ -7173,17 +7437,17 @@ shiftL2Left2Result (operand * left, int offl, ((offl + MSB16) == offr)) { /* don't crash result[offr] */ - MOVA (aopGet (AOP (left), offl, FALSE, FALSE)); - emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE)); + MOVA (aopGet (left, offl, FALSE, FALSE)); + emitcode ("xch", "a,%s", aopGet (left, offl + MSB16, FALSE, FALSE)); } else { movLeft2Result (left, offl, result, offr, 0); - MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE)); + MOVA (aopGet (left, offl + MSB16, FALSE, FALSE)); } /* ax << shCount (x = lsb(result)) */ - AccAXLsh (aopGet (AOP (result), offr, FALSE, FALSE), shCount); - aopPut (AOP (result), "a", offr + MSB16, isOperandVolatile (result, FALSE)); + AccAXLsh (aopGet (result, offr, FALSE, FALSE), shCount); + aopPut (result, "a", offr + MSB16, isOperandVolatile (result, FALSE)); } @@ -7199,21 +7463,21 @@ shiftR2Left2Result (operand * left, int offl, ((offl + MSB16) == offr)) { /* don't crash result[offr] */ - MOVA (aopGet (AOP (left), offl, FALSE, FALSE)); - emitcode ("xch", "a,%s", aopGet (AOP (left), offl + MSB16, FALSE, FALSE)); + MOVA (aopGet (left, offl, FALSE, FALSE)); + emitcode ("xch", "a,%s", aopGet (left, offl + MSB16, FALSE, FALSE)); } else { movLeft2Result (left, offl, result, offr, 0); - MOVA (aopGet (AOP (left), offl + MSB16, FALSE, FALSE)); + MOVA (aopGet (left, offl + MSB16, FALSE, FALSE)); } /* a:x >> shCount (x = lsb(result)) */ if (sign) - AccAXRshS (aopGet (AOP (result), offr, FALSE, FALSE), shCount); + AccAXRshS (aopGet (result, offr, FALSE, FALSE), shCount); else - AccAXRsh (aopGet (AOP (result), offr, FALSE, FALSE), shCount); + AccAXRsh (aopGet (result, offr, FALSE, FALSE), shCount); if (getDataSize (result) > 1) - aopPut (AOP (result), "a", offr + MSB16, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offr + MSB16, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -7223,13 +7487,13 @@ static void shiftLLeftOrResult (operand * left, int offl, operand * result, int offr, int shCount) { - MOVA (aopGet (AOP (left), offl, FALSE, FALSE)); + MOVA (aopGet (left, offl, FALSE, FALSE)); /* shift left accumulator */ AccLsh (shCount); /* or with result */ - emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE)); + emitcode ("orl", "a,%s", aopGet (result, offr, FALSE, FALSE)); /* back to result */ - aopPut (AOP (result), "a", offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offr, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -7239,13 +7503,13 @@ static void shiftRLeftOrResult (operand * left, int offl, operand * result, int offr, int shCount) { - MOVA (aopGet (AOP (left), offl, FALSE, FALSE)); + MOVA (aopGet (left, offl, FALSE, FALSE)); /* shift right accumulator */ AccRsh (shCount); /* or with result */ - emitcode ("orl", "a,%s", aopGet (AOP (result), offr, FALSE, FALSE)); + emitcode ("orl", "a,%s", aopGet (result, offr, FALSE, FALSE)); /* back to result */ - aopPut (AOP (result), "a", offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offr, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -7283,7 +7547,7 @@ genlshTwo (operand * result, operand * left, int shCount) else movLeft2Result (left, LSB, result, MSB16, 0); } - aopPut (AOP (result), zero, LSB, isOperandVolatile (result, FALSE)); + aopPut (result, zero, LSB, isOperandVolatile (result, FALSE)); } /* 1 <= shCount <= 7 */ @@ -7308,61 +7572,61 @@ shiftLLong (operand * left, operand * result, int offr) if (size >= LSB + offr) { - l = aopGet (AOP (left), LSB, FALSE, FALSE); + l = aopGet (left, LSB, FALSE, FALSE); MOVA (l); emitcode ("add", "a,acc"); if (sameRegs (AOP (left), AOP (result)) && size >= MSB16 + offr && offr != LSB) emitcode ("xch", "a,%s", - aopGet (AOP (left), LSB + offr, FALSE, FALSE)); + aopGet (left, LSB + offr, FALSE, FALSE)); else - aopPut (AOP (result), "a", LSB + offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", LSB + offr, isOperandVolatile (result, FALSE)); } if (size >= MSB16 + offr) { if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB16 + offr && offr != LSB)) { - l = aopGet (AOP (left), MSB16, FALSE, FALSE); + l = aopGet (left, MSB16, FALSE, FALSE); MOVA (l); } emitcode ("rlc", "a"); if (sameRegs (AOP (left), AOP (result)) && size >= MSB24 + offr && offr != LSB) emitcode ("xch", "a,%s", - aopGet (AOP (left), MSB16 + offr, FALSE, FALSE)); + aopGet (left, MSB16 + offr, FALSE, FALSE)); else - aopPut (AOP (result), "a", MSB16 + offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", MSB16 + offr, isOperandVolatile (result, FALSE)); } if (size >= MSB24 + offr) { - if (!(sameRegs (AOP (left), AOP (left)) && size >= MSB24 + offr && offr != LSB)) + if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB24 + offr && offr != LSB)) { - l = aopGet (AOP (left), MSB24, FALSE, FALSE); + l = aopGet (left, MSB24, FALSE, FALSE); MOVA (l); } emitcode ("rlc", "a"); if (sameRegs (AOP (left), AOP (result)) && size >= MSB32 + offr && offr != LSB) emitcode ("xch", "a,%s", - aopGet (AOP (left), MSB24 + offr, FALSE, FALSE)); + aopGet (left, MSB24 + offr, FALSE, FALSE)); else - aopPut (AOP (result), "a", MSB24 + offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", MSB24 + offr, isOperandVolatile (result, FALSE)); } if (size > MSB32 + offr) { if (!(sameRegs (AOP (result), AOP (left)) && size >= MSB32 + offr && offr != LSB)) { - l = aopGet (AOP (left), MSB32, FALSE, FALSE); + l = aopGet (left, MSB32, FALSE, FALSE); MOVA (l); } emitcode ("rlc", "a"); - aopPut (AOP (result), "a", MSB32 + offr, isOperandVolatile (result, FALSE)); + aopPut (result, "a", MSB32 + offr, isOperandVolatile (result, FALSE)); } if (offr != LSB) - aopPut (AOP (result), zero, LSB, isOperandVolatile (result, FALSE)); + aopPut (result, zero, LSB, isOperandVolatile (result, FALSE)); } /*-----------------------------------------------------------------*/ @@ -7387,9 +7651,9 @@ genlshFour (operand * result, operand * left, int shCount) shiftL1Left2Result (left, LSB, result, MSB32, shCount); else movLeft2Result (left, LSB, result, MSB32, 0); - aopPut (AOP (result), zero, LSB, isOperandVolatile (result, FALSE)); - aopPut (AOP (result), zero, MSB16, isOperandVolatile (result, FALSE)); - aopPut (AOP (result), zero, MSB24, isOperandVolatile (result, FALSE)); + aopPut (result, zero, LSB, isOperandVolatile (result, FALSE)); + aopPut (result, zero, MSB16, isOperandVolatile (result, FALSE)); + aopPut (result, zero, MSB24, isOperandVolatile (result, FALSE)); return; } @@ -7406,8 +7670,8 @@ genlshFour (operand * result, operand * left, int shCount) movLeft2Result (left, MSB16, result, MSB32, 0); movLeft2Result (left, LSB, result, MSB24, 0); } - aopPut (AOP (result), zero, MSB16, isOperandVolatile (result, FALSE)); - aopPut (AOP (result), zero, LSB, isOperandVolatile (result, FALSE)); + aopPut (result, zero, MSB16, isOperandVolatile (result, FALSE)); + aopPut (result, zero, LSB, isOperandVolatile (result, FALSE)); return; } @@ -7430,7 +7694,7 @@ genlshFour (operand * result, operand * left, int shCount) movLeft2Result (left, MSB24, result, MSB32, 0); movLeft2Result (left, MSB16, result, MSB24, 0); movLeft2Result (left, LSB, result, MSB16, 0); - aopPut (AOP (result), zero, LSB, isOperandVolatile (result, FALSE)); + aopPut (result, zero, LSB, isOperandVolatile (result, FALSE)); } else if (shCount == 1) shiftLLong (left, result, MSB16); @@ -7439,7 +7703,7 @@ genlshFour (operand * result, operand * left, int shCount) shiftL2Left2Result (left, MSB16, result, MSB24, shCount); shiftL1Left2Result (left, LSB, result, MSB16, shCount); shiftRLeftOrResult (left, LSB, result, MSB24, 8 - shCount); - aopPut (AOP (result), zero, LSB, isOperandVolatile (result, FALSE)); + aopPut (result, zero, LSB, isOperandVolatile (result, FALSE)); } } } @@ -7497,7 +7761,7 @@ genLeftShiftLiteral (operand * left, else if (shCount >= (size * 8)) while (size--) - aopPut (AOP (result), zero, size, isOperandVolatile (result, FALSE)); + aopPut (result, zero, size, isOperandVolatile (result, FALSE)); else { switch (size) @@ -7558,7 +7822,7 @@ genLeftShift (iCode * ic) largest size of an object can be only 32 bits ) */ pushedB = pushB (); - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); emitcode ("inc", "b"); freeAsmop (right, NULL, ic, TRUE); aopOp (left, ic, FALSE); @@ -7573,15 +7837,15 @@ genLeftShift (iCode * ic) offset = 0; while (size--) { - l = aopGet (AOP (left), offset, FALSE, TRUE); + l = aopGet (left, offset, FALSE, TRUE); if (*l == '@' && (IS_AOP_PREG (result))) { emitcode ("mov", "a,%s", l); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else - aopPut (AOP (result), l, offset, isOperandVolatile (result, FALSE)); + aopPut (result, l, offset, isOperandVolatile (result, FALSE)); offset++; } } @@ -7596,7 +7860,7 @@ genLeftShift (iCode * ic) { symbol *tlbl1 = newiTempLabel (NULL); - l = aopGet (AOP (left), 0, FALSE, FALSE); + l = aopGet (left, 0, FALSE, FALSE); MOVA (l); emitcode ("sjmp", "%05d$", tlbl1->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); @@ -7604,7 +7868,7 @@ genLeftShift (iCode * ic) emitcode ("", "%05d$:", tlbl1->key + 100); emitcode ("djnz", "b,%05d$", tlbl->key + 100); popB (pushedB); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); goto release; } @@ -7612,16 +7876,16 @@ genLeftShift (iCode * ic) emitcode ("sjmp", "%05d$", tlbl1->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); - l = aopGet (AOP (result), offset, FALSE, FALSE); + l = aopGet (result, offset, FALSE, FALSE); MOVA (l); emitcode ("add", "a,acc"); - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); while (--size) { - l = aopGet (AOP (result), offset, FALSE, FALSE); + l = aopGet (result, offset, FALSE, FALSE); MOVA (l); emitcode ("rlc", "a"); - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } reAdjustPreg (AOP (result)); @@ -7686,7 +7950,7 @@ shiftRLong (operand * left, int offl, werror(E_INTERNAL_ERROR, __FILE__, __LINE__); } - MOVA (aopGet (AOP (left), MSB32, FALSE, FALSE)); + MOVA (aopGet (left, MSB32, FALSE, FALSE)); if (offl==MSB16) { // shift is > 8 @@ -7694,13 +7958,13 @@ shiftRLong (operand * left, int offl, emitcode ("rlc", "a"); emitcode ("subb", "a,acc"); if (isSameRegs) - emitcode ("xch", "a,%s", aopGet(AOP(left), MSB32, FALSE, FALSE)); + emitcode ("xch", "a,%s", aopGet (left, MSB32, FALSE, FALSE)); else { - aopPut (AOP (result), "a", MSB32, isOperandVolatile (result, FALSE)); - MOVA (aopGet (AOP (left), MSB32, FALSE, FALSE)); + aopPut (result, "a", MSB32, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, MSB32, FALSE, FALSE)); } } else { - aopPut (AOP(result), zero, MSB32, isOperandVolatile (result, FALSE)); + aopPut (result, zero, MSB32, isOperandVolatile (result, FALSE)); } } @@ -7713,27 +7977,27 @@ shiftRLong (operand * left, int offl, emitcode ("rrc", "a"); if (isSameRegs && offl==MSB16) { - emitcode ("xch", "a,%s",aopGet (AOP (left), MSB24, FALSE, FALSE)); + emitcode ("xch", "a,%s",aopGet (left, MSB24, FALSE, FALSE)); } else { - aopPut (AOP (result), "a", MSB32-offl, isOperandVolatile (result, FALSE)); - MOVA (aopGet (AOP (left), MSB24, FALSE, FALSE)); + aopPut (result, "a", MSB32-offl, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, MSB24, FALSE, FALSE)); } emitcode ("rrc", "a"); if (isSameRegs && offl==1) { - emitcode ("xch", "a,%s",aopGet (AOP (left), MSB16, FALSE, FALSE)); + emitcode ("xch", "a,%s",aopGet (left, MSB16, FALSE, FALSE)); } else { - aopPut (AOP (result), "a", MSB24-offl, isOperandVolatile (result, FALSE)); - MOVA (aopGet (AOP (left), MSB16, FALSE, FALSE)); + aopPut (result, "a", MSB24-offl, isOperandVolatile (result, FALSE)); + MOVA (aopGet (left, MSB16, FALSE, FALSE)); } emitcode ("rrc", "a"); - aopPut (AOP (result), "a", MSB16 - offl, isOperandVolatile (result, FALSE)); + aopPut (result, "a", MSB16 - offl, isOperandVolatile (result, FALSE)); if (offl == LSB) { - MOVA (aopGet (AOP (left), LSB, FALSE, FALSE)); + MOVA (aopGet (left, LSB, FALSE, FALSE)); emitcode ("rrc", "a"); - aopPut (AOP (result), "a", LSB, isOperandVolatile (result, FALSE)); + aopPut (result, "a", LSB, isOperandVolatile (result, FALSE)); } } @@ -7846,7 +8110,7 @@ genRightShiftLiteral (operand * left, { if (sign) { /* get sign in acc.7 */ - MOVA (aopGet (AOP (left), size - 1, FALSE, FALSE)); + MOVA (aopGet (left, size - 1, FALSE, FALSE)); } addSign (result, LSB, sign); } @@ -7909,7 +8173,7 @@ genSignedRightShift (iCode * ic) largest size of an object can be only 32 bits ) */ pushedB = pushB (); - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); emitcode ("inc", "b"); freeAsmop (right, NULL, ic, TRUE); aopOp (left, ic, FALSE); @@ -7925,15 +8189,15 @@ genSignedRightShift (iCode * ic) offset = 0; while (size--) { - l = aopGet (AOP (left), offset, FALSE, TRUE); + l = aopGet (left, offset, FALSE, TRUE); if (*l == '@' && IS_AOP_PREG (result)) { emitcode ("mov", "a,%s", l); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else - aopPut (AOP (result), l, offset, isOperandVolatile (result, FALSE)); + aopPut (result, l, offset, isOperandVolatile (result, FALSE)); offset++; } } @@ -7944,13 +8208,13 @@ genSignedRightShift (iCode * ic) size = AOP_SIZE (result); offset = size - 1; - MOVA (aopGet (AOP (left), offset, FALSE, FALSE)); + MOVA (aopGet (left, offset, FALSE, FALSE)); emitcode ("rlc", "a"); emitcode ("mov", "ov,c"); /* if it is only one byte then */ if (size == 1) { - l = aopGet (AOP (left), 0, FALSE, FALSE); + l = aopGet (left, 0, FALSE, FALSE); MOVA (l); emitcode ("sjmp", "%05d$", tlbl1->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); @@ -7959,7 +8223,7 @@ genSignedRightShift (iCode * ic) emitcode ("", "%05d$:", tlbl1->key + 100); emitcode ("djnz", "b,%05d$", tlbl->key + 100); popB (pushedB); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); goto release; } @@ -7969,10 +8233,10 @@ genSignedRightShift (iCode * ic) emitcode ("mov", "c,ov"); while (size--) { - l = aopGet (AOP (result), offset, FALSE, FALSE); + l = aopGet (result, offset, FALSE, FALSE); MOVA (l); emitcode ("rrc", "a"); - aopPut (AOP (result), "a", offset--, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset--, isOperandVolatile (result, FALSE)); } reAdjustPreg (AOP (result)); emitcode ("", "%05d$:", tlbl1->key + 100); @@ -8037,7 +8301,7 @@ genRightShift (iCode * ic) largest size of an object can be only 32 bits ) */ pushedB = pushB (); - emitcode ("mov", "b,%s", aopGet (AOP (right), 0, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (right, 0, FALSE, FALSE)); emitcode ("inc", "b"); freeAsmop (right, NULL, ic, TRUE); aopOp (left, ic, FALSE); @@ -8053,15 +8317,15 @@ genRightShift (iCode * ic) offset = 0; while (size--) { - l = aopGet (AOP (left), offset, FALSE, TRUE); + l = aopGet (left, offset, FALSE, TRUE); if (*l == '@' && IS_AOP_PREG (result)) { emitcode ("mov", "a,%s", l); - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else - aopPut (AOP (result), l, offset, isOperandVolatile (result, FALSE)); + aopPut (result, l, offset, isOperandVolatile (result, FALSE)); offset++; } } @@ -8074,7 +8338,7 @@ genRightShift (iCode * ic) /* if it is only one byte then */ if (size == 1) { - l = aopGet (AOP (left), 0, FALSE, FALSE); + l = aopGet (left, 0, FALSE, FALSE); MOVA (l); emitcode ("sjmp", "%05d$", tlbl1->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); @@ -8083,7 +8347,7 @@ genRightShift (iCode * ic) emitcode ("", "%05d$:", tlbl1->key + 100); emitcode ("djnz", "b,%05d$", tlbl->key + 100); popB (pushedB); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); goto release; } @@ -8093,10 +8357,10 @@ genRightShift (iCode * ic) CLRC; while (size--) { - l = aopGet (AOP (result), offset, FALSE, FALSE); + l = aopGet (result, offset, FALSE, FALSE); MOVA (l); emitcode ("rrc", "a"); - aopPut (AOP (result), "a", offset--, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset--, isOperandVolatile (result, FALSE)); } reAdjustPreg (AOP (result)); @@ -8242,7 +8506,7 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx) emitPtrByteGet (rname, ptype, FALSE); AccRsh (bstr); emitcode ("anl", "a,#0x%02x", ((unsigned char) -1) >> (8 - blen)); - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); goto finish; } @@ -8251,7 +8515,7 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx) for (rlen=blen;rlen>=8;rlen-=8) { emitPtrByteGet (rname, ptype, FALSE); - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); if (rlen>8) emitcode ("inc", "%s", rname); } @@ -8261,7 +8525,7 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx) { emitPtrByteGet (rname, ptype, FALSE); emitcode ("anl", "a,#0x%02x", ((unsigned char) -1) >> (8-rlen)); - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } finish: @@ -8269,7 +8533,7 @@ finish: { rsize -= offset; while (rsize--) - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); } } @@ -8291,7 +8555,7 @@ genDataPointerGet (operand * left, aopOp (result, ic, TRUE); /* get the string representation of the name */ - l = aopGet (AOP (left), 0, FALSE, TRUE); + l = aopGet (left, 0, FALSE, TRUE); size = AOP_SIZE (result); while (size--) { @@ -8299,7 +8563,7 @@ genDataPointerGet (operand * left, sprintf (buffer, "(%s + %d)", l + 1, offset); else sprintf (buffer, "%s", l + 1); - aopPut (AOP (result), buffer, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, buffer, offset++, isOperandVolatile (result, FALSE)); } freeAsmop (left, NULL, ic, TRUE); @@ -8349,7 +8613,7 @@ genNearPointerGet (operand * left, if (IS_AOP_PREG (left)) { // Aha, it is a pointer, just in disguise. - rname = aopGet (AOP (left), 0, FALSE, FALSE); + rname = aopGet (left, 0, FALSE, FALSE); if (*rname != '@') { fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", @@ -8369,12 +8633,12 @@ genNearPointerGet (operand * left, preg = getFreePtr (ic, &aop, FALSE); emitcode ("mov", "%s,%s", preg->name, - aopGet (AOP (left), 0, FALSE, TRUE)); + aopGet (left, 0, FALSE, TRUE)); rname = preg->name; } } else - rname = aopGet (AOP (left), 0, FALSE, FALSE); + rname = aopGet (left, 0, FALSE, FALSE); //aopOp (result, ic, FALSE); aopOp (result, ic, result?TRUE:FALSE); @@ -8395,12 +8659,12 @@ genNearPointerGet (operand * left, emitcode ("mov", "a,@%s", rname); if (!ifx) - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); } else { sprintf (buffer, "@%s", rname); - aopPut (AOP (result), buffer, offset, isOperandVolatile (result, FALSE)); + aopPut (result, buffer, offset, isOperandVolatile (result, FALSE)); } offset++; if (size || pi) @@ -8412,7 +8676,7 @@ genNearPointerGet (operand * left, if (aop) /* we had to allocate for this iCode */ { if (pi) { /* post increment present */ - aopPut(AOP ( left ),rname,0, isOperandVolatile (left, FALSE)); + aopPut (left, rname, 0, isOperandVolatile (left, FALSE)); } freeAsmop (NULL, aop, ic, RESULTONSTACK (ic) ? FALSE : TRUE); } @@ -8477,11 +8741,11 @@ genPagedPointerGet (operand * left, preg = getFreePtr (ic, &aop, FALSE); emitcode ("mov", "%s,%s", preg->name, - aopGet (AOP (left), 0, FALSE, TRUE)); + aopGet (left, 0, FALSE, TRUE)); rname = preg->name; } else - rname = aopGet (AOP (left), 0, FALSE, FALSE); + rname = aopGet (left, 0, FALSE, FALSE); aopOp (result, ic, FALSE); @@ -8499,7 +8763,7 @@ genPagedPointerGet (operand * left, emitcode ("movx", "a,@%s", rname); if (!ifx) - aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); offset++; @@ -8511,7 +8775,7 @@ genPagedPointerGet (operand * left, /* now some housekeeping stuff */ if (aop) /* we had to allocate for this iCode */ { - if (pi) aopPut ( AOP (left), rname, 0, isOperandVolatile (left, FALSE)); + if (pi) aopPut (left, rname, 0, isOperandVolatile (left, FALSE)); freeAsmop (NULL, aop, ic, TRUE); } else @@ -8556,11 +8820,11 @@ loadDptrFromOperand (operand *op, bool loadBToo) /* if this is rematerializable */ if (AOP_TYPE (op) == AOP_IMMD) { - emitcode ("mov", "dptr,%s", aopGet (AOP (op), 0, TRUE, FALSE)); + emitcode ("mov", "dptr,%s", aopGet (op, 0, TRUE, FALSE)); if (loadBToo) { if (AOP(op)->aopu.aop_immd.from_cast_remat) - emitcode ("mov", "b,%s",aopGet(AOP (op), AOP_SIZE(op)-1, FALSE, FALSE)); + emitcode ("mov", "b,%s",aopGet (op, AOP_SIZE(op)-1, FALSE, FALSE)); else { wassertl(FALSE, "need pointerCode"); @@ -8570,7 +8834,7 @@ loadDptrFromOperand (operand *op, bool loadBToo) ** from genPointerGet: ** emitcode ("mov", "b,#%d", pointerCode (retype)); ** from genPointerSet: - ** emitcode ("mov", "b,%s + 1", aopGet (AOP (result), 0, TRUE, FALSE)); + ** emitcode ("mov", "b,%s + 1", aopGet (result, 0, TRUE, FALSE)); */ } } @@ -8579,28 +8843,28 @@ loadDptrFromOperand (operand *op, bool loadBToo) { if (loadBToo) { - MOVA (aopGet (AOP (op), 0, FALSE, FALSE)); + MOVA (aopGet (op, 0, FALSE, FALSE)); emitcode ("push", "acc"); - MOVA (aopGet (AOP (op), 1, FALSE, FALSE)); + MOVA (aopGet (op, 1, FALSE, FALSE)); emitcode ("push", "acc"); - emitcode ("mov", "b,%s", aopGet (AOP (op), 2, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (op, 2, FALSE, FALSE)); emitcode ("pop", "dph"); emitcode ("pop", "dpl"); } else { - MOVA (aopGet (AOP (op), 0, FALSE, FALSE)); + MOVA (aopGet (op, 0, FALSE, FALSE)); emitcode ("push", "acc"); - emitcode ("mov", "dph,%s", aopGet (AOP (op), 1, FALSE, FALSE)); + emitcode ("mov", "dph,%s", aopGet (op, 1, FALSE, FALSE)); emitcode ("pop", "dpl"); } } else { /* we need to get it byte by byte */ - emitcode ("mov", "dpl,%s", aopGet (AOP (op), 0, FALSE, FALSE)); - emitcode ("mov", "dph,%s", aopGet (AOP (op), 1, FALSE, FALSE)); + emitcode ("mov", "dpl,%s", aopGet (op, 0, FALSE, FALSE)); + emitcode ("mov", "dph,%s", aopGet (op, 1, FALSE, FALSE)); if (loadBToo) - emitcode ("mov", "b,%s", aopGet (AOP (op), 2, FALSE, FALSE)); + emitcode ("mov", "b,%s", aopGet (op, 2, FALSE, FALSE)); } } } @@ -8635,7 +8899,7 @@ genFarPointerGet (operand * left, { emitcode ("movx", "a,@dptr"); if (!ifx) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); if (size || pi) emitcode ("inc", "dptr"); } @@ -8643,8 +8907,8 @@ genFarPointerGet (operand * left, if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) { - aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE)); - aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE)); + aopPut (left, "dpl", 0, isOperandVolatile (left, FALSE)); + aopPut (left, "dph", 1, isOperandVolatile (left, FALSE)); pi->generated = 1; } @@ -8690,7 +8954,7 @@ genCodePointerGet (operand * left, emitcode ("clr", "a"); emitcode ("movc", "a,@a+dptr"); if (!ifx) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); emitcode ("inc", "dptr"); } else @@ -8698,15 +8962,15 @@ genCodePointerGet (operand * left, emitcode ("mov", "a,#0x%02x", offset); emitcode ("movc", "a,@a+dptr"); if (!ifx) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } } } if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) { - aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE)); - aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE)); + aopPut (left, "dpl", 0, isOperandVolatile (left, FALSE)); + aopPut (left, "dph", 1, isOperandVolatile (left, FALSE)); pi->generated = 1; } @@ -8749,7 +9013,7 @@ genGenPointerGet (operand * left, { emitcode ("lcall", "__gptrget"); if (!ifx) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); if (size || pi) emitcode ("inc", "dptr"); } @@ -8757,8 +9021,8 @@ genGenPointerGet (operand * left, if (pi && AOP_TYPE (left) != AOP_IMMD && AOP_TYPE (left) != AOP_STR) { - aopPut ( AOP (left), "dpl", 0, isOperandVolatile (left, FALSE)); - aopPut ( AOP (left), "dph", 1, isOperandVolatile (left, FALSE)); + aopPut (left, "dpl", 0, isOperandVolatile (left, FALSE)); + aopPut (left, "dph", 1, isOperandVolatile (left, FALSE)); pi->generated = 1; } @@ -8890,7 +9154,7 @@ genPackBits (sym_link * etype, emitcode ("mov", "c,%s", AOP(right)->aopu.aop_dir); else { - MOVA (aopGet (AOP (right), 0, FALSE, FALSE)); + MOVA (aopGet (right, 0, FALSE, FALSE)); emitcode ("rrc","a"); } emitPtrByteGet (rname, p_type, FALSE); @@ -8901,7 +9165,7 @@ genPackBits (sym_link * etype, bool pushedB; /* Case with a bitfield length < 8 and arbitrary source */ - MOVA (aopGet (AOP (right), 0, FALSE, FALSE)); + MOVA (aopGet (right, 0, FALSE, FALSE)); /* shift and mask source value */ AccLsh (bstr); emitcode ("anl", "a,#0x%02x", (~mask) & 0xff); @@ -8928,7 +9192,7 @@ genPackBits (sym_link * etype, for (rlen=blen;rlen>=8;rlen-=8) { emitPtrByteSet (rname, p_type, - aopGet (AOP (right), offset++, FALSE, TRUE) ); + aopGet (right, offset++, FALSE, TRUE) ); if (rlen>8) emitcode ("inc", "%s", rname); } @@ -8956,7 +9220,7 @@ genPackBits (sym_link * etype, bool pushedB; /* Case with partial byte and arbitrary source */ - MOVA (aopGet (AOP (right), offset++, FALSE, FALSE)); + MOVA (aopGet (right, offset++, FALSE, FALSE)); emitcode ("anl", "a,#0x%02x", (~mask) & 0xff); pushedB = pushB (); @@ -8991,7 +9255,7 @@ genDataPointerSet (operand * right, aopOp (right, ic, FALSE); - l = aopGet (AOP (result), 0, FALSE, TRUE); + l = aopGet (result, 0, FALSE, TRUE); size = AOP_SIZE (right); while (size--) { @@ -9000,7 +9264,7 @@ genDataPointerSet (operand * right, else sprintf (buffer, "%s", l + 1); emitcode ("mov", "%s,%s", buffer, - aopGet (AOP (right), offset++, FALSE, FALSE)); + aopGet (right, offset++, FALSE, FALSE)); } freeAsmop (right, NULL, ic, TRUE); @@ -9049,7 +9313,7 @@ genNearPointerSet (operand * right, ) { // Aha, it is a pointer, just in disguise. - rname = aopGet (AOP (result), 0, FALSE, FALSE); + rname = aopGet (result, 0, FALSE, FALSE); if (*rname != '@') { fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", @@ -9069,13 +9333,13 @@ genNearPointerSet (operand * right, preg = getFreePtr (ic, &aop, FALSE); emitcode ("mov", "%s,%s", preg->name, - aopGet (AOP (result), 0, FALSE, TRUE)); + aopGet (result, 0, FALSE, TRUE)); rname = preg->name; } } else { - rname = aopGet (AOP (result), 0, FALSE, FALSE); + rname = aopGet (result, 0, FALSE, FALSE); } aopOp (right, ic, FALSE); @@ -9091,7 +9355,7 @@ genNearPointerSet (operand * right, while (size--) { - l = aopGet (AOP (right), offset, FALSE, TRUE); + l = aopGet (right, offset, FALSE, TRUE); if (*l == '@') { MOVA (l); @@ -9109,7 +9373,7 @@ genNearPointerSet (operand * right, if (aop) /* we had to allocate for this iCode */ { if (pi) - aopPut (AOP (result), rname, 0, isOperandVolatile (result, FALSE)); + aopPut (result, rname, 0, isOperandVolatile (result, FALSE)); freeAsmop (NULL, aop, ic, TRUE); } else @@ -9167,11 +9431,11 @@ genPagedPointerSet (operand * right, preg = getFreePtr (ic, &aop, FALSE); emitcode ("mov", "%s,%s", preg->name, - aopGet (AOP (result), 0, FALSE, TRUE)); + aopGet (result, 0, FALSE, TRUE)); rname = preg->name; } else - rname = aopGet (AOP (result), 0, FALSE, FALSE); + rname = aopGet (result, 0, FALSE, FALSE); aopOp (right, ic, FALSE); @@ -9186,7 +9450,7 @@ genPagedPointerSet (operand * right, while (size--) { - l = aopGet (AOP (right), offset, FALSE, TRUE); + l = aopGet (right, offset, FALSE, TRUE); MOVA (l); emitcode ("movx", "@%s,a", rname); @@ -9202,7 +9466,7 @@ genPagedPointerSet (operand * right, if (aop) /* we had to allocate for this iCode */ { if (pi) - aopPut (AOP (result), rname, 0, isOperandVolatile (result, FALSE)); + aopPut (result, rname, 0, isOperandVolatile (result, FALSE)); freeAsmop (NULL, aop, ic, TRUE); } else @@ -9260,7 +9524,7 @@ genFarPointerSet (operand * right, while (size--) { - char *l = aopGet (AOP (right), offset++, FALSE, FALSE); + char *l = aopGet (right, offset++, FALSE, FALSE); MOVA (l); emitcode ("movx", "@dptr,a"); if (size || pi) @@ -9268,8 +9532,8 @@ genFarPointerSet (operand * right, } } if (pi && AOP_TYPE (result) != AOP_STR && AOP_TYPE (result) != AOP_IMMD) { - aopPut (AOP(result), "dpl", 0, isOperandVolatile (result, FALSE)); - aopPut (AOP(result), "dph", 1, isOperandVolatile (result, FALSE)); + aopPut (result, "dpl", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "dph", 1, isOperandVolatile (result, FALSE)); pi->generated=1; } freeAsmop (result, NULL, ic, TRUE); @@ -9305,7 +9569,7 @@ genGenPointerSet (operand * right, while (size--) { - char *l = aopGet (AOP (right), offset++, FALSE, FALSE); + char *l = aopGet (right, offset++, FALSE, FALSE); MOVA (l); emitcode ("lcall", "__gptrput"); if (size || pi) @@ -9314,8 +9578,8 @@ genGenPointerSet (operand * right, } if (pi && AOP_TYPE (result) != AOP_STR && AOP_TYPE (result) != AOP_IMMD) { - aopPut (AOP(result), "dpl", 0, isOperandVolatile (result, FALSE)); - aopPut (AOP(result), "dph", 1, isOperandVolatile (result, FALSE)); + aopPut (result, "dpl", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "dph", 1, isOperandVolatile (result, FALSE)); pi->generated=1; } freeAsmop (result, NULL, ic, TRUE); @@ -9414,8 +9678,7 @@ genIfx (iCode * ic, iCode * popIc) genIpop (popIc); /* if the condition is a bit variable */ - if (isbit && IS_ITEMP (cond) && - SPIL_LOC (cond)) + if (isbit && IS_ITEMP (cond) && SPIL_LOC (cond)) genIfxJump (ic, SPIL_LOC (cond)->rname, NULL, NULL, NULL); else if (isbit && !IS_ITEMP (cond)) genIfxJump (ic, OP_SYMBOL (cond)->rname, NULL, NULL, NULL); @@ -9447,16 +9710,16 @@ genAddrOf (iCode * ic) it */ if (sym->stack) { - emitcode ("mov", "a,_bp"); + emitcode ("mov", "a,%s", SYM_BP (sym)); emitcode ("add", "a,#0x%02x", ((sym->stack < 0) ? ((char) (sym->stack - _G.nRegsSaved)) : ((char) sym->stack)) & 0xff); - aopPut (AOP (IC_RESULT (ic)), "a", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); } else { /* we can just move _bp */ - aopPut (AOP (IC_RESULT (ic)), "_bp", 0, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), SYM_BP (sym), 0, isOperandVolatile (IC_RESULT (ic), FALSE)); } /* fill the result with zero */ size = AOP_SIZE (IC_RESULT (ic)) - 1; @@ -9464,7 +9727,7 @@ genAddrOf (iCode * ic) offset = 1; while (size--) { - aopPut (AOP (IC_RESULT (ic)), zero, offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), zero, offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } goto release; @@ -9483,7 +9746,7 @@ genAddrOf (iCode * ic) offset * 8); else sprintf (s, "#%s", sym->rname); - aopPut (AOP (IC_RESULT (ic)), s, offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), s, offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } release: @@ -9506,7 +9769,7 @@ genFarFarAssign (operand * result, operand * right, iCode * ic) /* first push the right side on to the stack */ while (size--) { - l = aopGet (AOP (right), offset++, FALSE, FALSE); + l = aopGet (right, offset++, FALSE, FALSE); MOVA (l); emitcode ("push", "acc"); } @@ -9518,7 +9781,7 @@ genFarFarAssign (operand * result, operand * right, iCode * ic) while (size--) { emitcode ("pop", "acc"); - aopPut (AOP (result), "a", --offset, isOperandVolatile (result, FALSE)); + aopPut (result, "a", --offset, isOperandVolatile (result, FALSE)); } freeAsmop (result, NULL, ic, FALSE); @@ -9574,9 +9837,9 @@ genAssign (iCode * ic) if (AOP_TYPE (right) == AOP_LIT) { if (((int) operandLitValue (right))) - aopPut (AOP (result), one, 0, isOperandVolatile (result, FALSE)); + aopPut (result, one, 0, isOperandVolatile (result, FALSE)); else - aopPut (AOP (result), zero, 0, isOperandVolatile (result, FALSE)); + aopPut (result, zero, 0, isOperandVolatile (result, FALSE)); goto release; } @@ -9584,13 +9847,13 @@ genAssign (iCode * ic) if (AOP_TYPE (right) == AOP_CRY) { emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); - aopPut (AOP (result), "c", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "c", 0, isOperandVolatile (result, FALSE)); goto release; } /* we need to or */ toBoolean (right); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); goto release; } @@ -9606,24 +9869,29 @@ genAssign (iCode * ic) !IS_FLOAT (operandType (right)) && (lit < 256L)) { + while ((size) && (lit)) + { + aopPut (result, + aopGet (right, offset, FALSE, FALSE), + offset, + isOperandVolatile (result, FALSE)); + lit >>= 8; + offset++; + size--; + } emitcode ("clr", "a"); while (size--) { - if ((unsigned int) ((lit >> (size * 8)) & 0x0FFL) == 0) - aopPut (AOP (result), "a", size, isOperandVolatile (result, FALSE)); - else - aopPut (AOP (result), - aopGet (AOP (right), size, FALSE, FALSE), - size, - isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset, isOperandVolatile (result, FALSE)); + offset++; } } else { while (size--) { - aopPut (AOP (result), - aopGet (AOP (right), offset, FALSE, FALSE), + aopPut (result, + aopGet (right, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); offset++; @@ -9636,7 +9904,7 @@ release: } /*-----------------------------------------------------------------*/ -/* genJumpTab - genrates code for jump table */ +/* genJumpTab - generates code for jump table */ /*-----------------------------------------------------------------*/ static void genJumpTab (iCode * ic) @@ -9658,11 +9926,11 @@ genJumpTab (iCode * ic) How will multiply by three be updated ???*/ aopOp (IC_JTCOND (ic), ic, FALSE); /* get the condition into accumulator */ - l = aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE); + l = aopGet (IC_JTCOND (ic), 0, FALSE, FALSE); MOVA (l); /* multiply by three */ emitcode ("add", "a,acc"); - emitcode ("add", "a,%s", aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE)); + emitcode ("add", "a,%s", aopGet (IC_JTCOND (ic), 0, FALSE, FALSE)); freeAsmop (IC_JTCOND (ic), NULL, ic, TRUE); jtab = newiTempLabel (NULL); @@ -9685,12 +9953,12 @@ genJumpTab (iCode * ic) /* get the condition into accumulator. Using b as temporary storage, if register push/pop is needed */ aopOp (IC_JTCOND (ic), ic, FALSE); - l = aopGet (AOP (IC_JTCOND (ic)), 0, FALSE, FALSE); + l = aopGet (IC_JTCOND (ic), 0, FALSE, FALSE); if ((AOP_TYPE (IC_JTCOND (ic)) == AOP_R0 && _G.r0Pushed) || (AOP_TYPE (IC_JTCOND (ic)) == AOP_R1 && _G.r1Pushed)) { // (MB) what if B is in use??? - wassertl(!_G.BInUse, "B was in use"); + wassertl(!BINUSE, "B was in use"); emitcode ("mov", "b,%s", l); l = "b"; } @@ -9768,9 +10036,9 @@ genCast (iCode * ic) if (AOP_TYPE (right) == AOP_LIT) { if (((int) operandLitValue (right))) - aopPut (AOP (result), one, 0, isOperandVolatile (result, FALSE)); + aopPut (result, one, 0, isOperandVolatile (result, FALSE)); else - aopPut (AOP (result), zero, 0, isOperandVolatile (result, FALSE)); + aopPut (result, zero, 0, isOperandVolatile (result, FALSE)); goto release; } @@ -9779,13 +10047,13 @@ genCast (iCode * ic) if (AOP_TYPE (right) == AOP_CRY) { emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); - aopPut (AOP (result), "c", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "c", 0, isOperandVolatile (result, FALSE)); goto release; } /* we need to or */ toBoolean (right); - aopPut (AOP (result), "a", 0, isOperandVolatile (result, FALSE)); + aopPut (result, "a", 0, isOperandVolatile (result, FALSE)); goto release; } @@ -9803,8 +10071,8 @@ genCast (iCode * ic) offset = 0; while (size--) { - aopPut (AOP (result), - aopGet (AOP (right), offset, FALSE, FALSE), + aopPut (result, + aopGet (right, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); offset++; @@ -9842,8 +10110,8 @@ genCast (iCode * ic) offset = 0; while (size--) { - aopPut (AOP (result), - aopGet (AOP (right), offset, FALSE, FALSE), + aopPut (result, + aopGet (right, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); offset++; @@ -9859,8 +10127,8 @@ genCast (iCode * ic) exit(1); } - sprintf(gpValStr, "#0x%d", gpVal); - aopPut (AOP (result), gpValStr, GPTRSIZE - 1, isOperandVolatile (result, FALSE)); + sprintf(gpValStr, "#0x%x", gpVal); + aopPut (result, gpValStr, GPTRSIZE - 1, isOperandVolatile (result, FALSE)); } goto release; } @@ -9870,8 +10138,8 @@ genCast (iCode * ic) offset = 0; while (size--) { - aopPut (AOP (result), - aopGet (AOP (right), offset, FALSE, FALSE), + aopPut (result, + aopGet (right, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); offset++; @@ -9886,8 +10154,8 @@ genCast (iCode * ic) offset = 0; while (size--) { - aopPut (AOP (result), - aopGet (AOP (right), offset, FALSE, FALSE), + aopPut (result, + aopGet (right, offset, FALSE, FALSE), offset, isOperandVolatile (result, FALSE)); offset++; @@ -9899,18 +10167,18 @@ genCast (iCode * ic) if (!IS_SPEC (rtype) || SPEC_USIGN (rtype) || AOP_TYPE(right)==AOP_CRY) { while (size--) - aopPut (AOP (result), zero, offset++, isOperandVolatile (result, FALSE)); + aopPut (result, zero, offset++, isOperandVolatile (result, FALSE)); } else { /* we need to extend the sign :{ */ - char *l = aopGet (AOP (right), AOP_SIZE (right) - 1, + char *l = aopGet (right, AOP_SIZE (right) - 1, FALSE, FALSE); MOVA (l); emitcode ("rlc", "a"); emitcode ("subb", "a,acc"); while (size--) - aopPut (AOP (result), "a", offset++, isOperandVolatile (result, FALSE)); + aopPut (result, "a", offset++, isOperandVolatile (result, FALSE)); } /* we are done hurray !!!! */ @@ -9964,7 +10232,7 @@ genDjnz (iCode * ic, iCode * ifx) * the accumulator, we must explicitly write * it back after the decrement. */ - char *rByte = aopGet(AOP(IC_RESULT(ic)), 0, FALSE, FALSE); + char *rByte = aopGet (IC_RESULT(ic), 0, FALSE, FALSE); if (strcmp(rByte, "a")) { @@ -9978,19 +10246,19 @@ genDjnz (iCode * ic, iCode * ifx) return 0; } emitcode ("dec", "%s", rByte); - aopPut(AOP(IC_RESULT(ic)), rByte, 0, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), rByte, 0, isOperandVolatile (IC_RESULT (ic), FALSE)); emitcode ("jnz", "%05d$", lbl->key + 100); } else if (IS_AOP_PREG (IC_RESULT (ic))) { emitcode ("dec", "%s", - aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE)); - MOVA (aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE)); + aopGet (IC_RESULT (ic), 0, FALSE, FALSE)); + MOVA (aopGet (IC_RESULT (ic), 0, FALSE, FALSE)); emitcode ("jnz", "%05d$", lbl->key + 100); } else { - emitcode ("djnz", "%s,%05d$", aopGet (AOP (IC_RESULT (ic)), 0, FALSE, FALSE), + emitcode ("djnz", "%s,%05d$", aopGet (IC_RESULT (ic), 0, FALSE, FALSE), lbl->key + 100); } emitcode ("sjmp", "%05d$", lbl1->key + 100); @@ -10036,10 +10304,10 @@ genReceive (iCode * ic) _G.accInUse++; aopOp (IC_RESULT (ic), ic, FALSE); _G.accInUse--; - aopPut (AOP (IC_RESULT (ic)), "a", offset, + aopPut (IC_RESULT (ic), "a", offset, isOperandVolatile (IC_RESULT (ic), FALSE)); for (offset = 1; offsetname, offset, + aopPut (IC_RESULT (ic), tempRegs[--roffset]->name, offset, isOperandVolatile (IC_RESULT (ic), FALSE)); goto release; } @@ -10052,7 +10320,7 @@ genReceive (iCode * ic) emitcode("mov","%s,%s", tempRegs[offset]->name, fReturn[offset]); aopOp (IC_RESULT (ic), ic, FALSE); for (offset = 0; offsetname, offset, + aopPut (IC_RESULT (ic), tempRegs[offset]->name, offset, isOperandVolatile (IC_RESULT (ic), FALSE)); goto release; } @@ -10069,7 +10337,7 @@ genReceive (iCode * ic) offset = 0; while (size--) { emitcode ("pop", "acc"); - aopPut (AOP (IC_RESULT (ic)), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), "a", offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } } else { @@ -10083,7 +10351,7 @@ genReceive (iCode * ic) aopOp (IC_RESULT (ic), ic, FALSE); rb1off = ic->argreg; while (size--) { - aopPut (AOP (IC_RESULT (ic)), rb1regs[rb1off++ -5], offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); + aopPut (IC_RESULT (ic), rb1regs[rb1off++ -5], offset++, isOperandVolatile (IC_RESULT (ic), FALSE)); } } @@ -10118,7 +10386,7 @@ genDummyRead (iCode * ic) offset = 0; while (size--) { - MOVA (aopGet (AOP (op), offset, FALSE, FALSE)); + MOVA (aopGet (op, offset, FALSE, FALSE)); offset++; } } @@ -10142,7 +10410,7 @@ genDummyRead (iCode * ic) offset = 0; while (size--) { - MOVA (aopGet (AOP (op), offset, FALSE, FALSE)); + MOVA (aopGet (op, offset, FALSE, FALSE)); offset++; } } @@ -10162,20 +10430,22 @@ genCritical (iCode *ic) D(emitcode("; genCritical","")); if (IC_RESULT (ic)) - aopOp (IC_RESULT (ic), ic, TRUE); - - emitcode ("setb", "c"); - emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */ - emitcode ("clr", "c"); - emitcode ("", "%05d$:", (tlbl->key + 100)); - - if (IC_RESULT (ic)) - outBitC (IC_RESULT (ic)); /* save old ea in an operand */ + { + aopOp (IC_RESULT (ic), ic, TRUE); + aopPut (IC_RESULT (ic), one, 0, 0); + emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */ + aopPut (IC_RESULT (ic), zero, 0, 0); + emitcode ("", "%05d$:", (tlbl->key + 100)); + freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); + } else - emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/ - - if (IC_RESULT (ic)) - freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); + { + emitcode ("setb", "c"); + emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */ + emitcode ("clr", "c"); + emitcode ("", "%05d$:", (tlbl->key + 100)); + emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/ + } } /*-----------------------------------------------------------------*/ @@ -10196,7 +10466,8 @@ genEndCritical (iCode *ic) } else { - MOVA (aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE)); + if (AOP_TYPE (IC_RIGHT (ic)) != AOP_DUMMY) + MOVA (aopGet (IC_RIGHT (ic), 0, FALSE, FALSE)); emitcode ("rrc", "a"); emitcode ("mov", "ea,c"); }