X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fgen.c;h=68f8524cc0b5d1c7ddf5f5d951c501d324d32082;hb=eaa91096bbf4af190d0da62f7d85b353d6f67e67;hp=e9f0df3c3907375972af4590d50cd15bb25af35b;hpb=2b986bde11505c465b28ead0d89722ed55979cf3;p=fw%2Fsdcc diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index e9f0df3c..68f8524c 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -543,7 +543,7 @@ leftRightUseAcc(iCode *ic) if (ic->op == IFX) { op = IC_COND (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); @@ -554,7 +554,7 @@ leftRightUseAcc(iCode *ic) else if (ic->op == JUMPTABLE) { op = IC_JTCOND (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); @@ -565,7 +565,7 @@ leftRightUseAcc(iCode *ic) else { op = IC_LEFT (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); @@ -573,7 +573,7 @@ leftRightUseAcc(iCode *ic) accuseSize = size; } op = IC_RIGHT (ic); - if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse) + if (IS_OP_ACCUSE (op)) { accuse = 1; size = getSize (OP_SYMBOL (op)->type); @@ -712,7 +712,7 @@ aopForSym (iCode * ic, symbol * sym, bool result) } /*-----------------------------------------------------------------*/ -/* aopForRemat - rematerialzes an object */ +/* aopForRemat - rematerializes an object */ /*-----------------------------------------------------------------*/ static asmop * aopForRemat (symbol * sym) @@ -728,13 +728,15 @@ aopForRemat (symbol * sym) val += (int) operandLitValue (IC_RIGHT (ic)); else if (ic->op == '-') val -= (int) operandLitValue (IC_RIGHT (ic)); - else if (IS_CAST_ICODE(ic)) { - 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 = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL); - continue; - } else break; + else if (IS_CAST_ICODE(ic)) + { + 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 = pointerTypeToGPByte (DCL_TYPE(from_type), NULL, NULL); + continue; + } + else break; ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; } @@ -1040,7 +1042,7 @@ aopOp (operand * op, iCode * ic, bool result) /*-----------------------------------------------------------------*/ /* freeAsmop - free up the asmop given to an operand */ -/*----------------------------------------------------------------*/ +/*-----------------------------------------------------------------*/ static void freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop) { @@ -1855,7 +1857,7 @@ outBitC (operand * result) if (!IS_OP_RUONLY (result)) aopPut (result, "c", 0); } - else + else if (AOP_TYPE (result) != AOP_DUMMY) { emitcode ("clr", "a"); emitcode ("rlc", "a"); @@ -2418,9 +2420,29 @@ unsaveRegisters (iCode * ic) /* pushSide - */ /*-----------------------------------------------------------------*/ static void -pushSide (operand * oper, int size) +pushSide (operand * oper, int size, iCode * ic) { int offset = 0; + int nPushed = _G.r0Pushed + _G.r1Pushed; + + aopOp (oper, ic, FALSE); + + if (nPushed != _G.r0Pushed + _G.r1Pushed) + { + while (offset < size) + { + char *l = aopGet (oper, offset, FALSE, TRUE); + emitcode ("mov", "%s,%s", fReturn[offset++], l); + } + freeAsmop (oper, NULL, ic, TRUE); + offset = 0; + while (offset < size) + { + emitcode ("push", "%s", fReturn[offset++]); + } + return; + } + while (size--) { char *l = aopGet (oper, offset++, FALSE, TRUE); @@ -2436,6 +2458,8 @@ pushSide (operand * oper, int size) emitcode ("push", "%s", l); } } + + freeAsmop (oper, NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ @@ -3146,13 +3170,9 @@ genPcall (iCode * ic) emitcode ("push", "acc"); /* now push the calling address */ - aopOp (IC_LEFT (ic), ic, FALSE); - - pushSide (IC_LEFT (ic), FPTRSIZE); + pushSide (IC_LEFT (ic), FPTRSIZE, ic); - freeAsmop (IC_LEFT (ic), NULL, ic, TRUE); - - /* if send set is not empty the assign */ + /* if send set is not empty then assign */ if (_G.sendSet) { genSend(reverseSet(_G.sendSet)); @@ -4166,12 +4186,12 @@ genPlusIncr (iCode * ic) if (AOP_TYPE (IC_RIGHT (ic)) != AOP_LIT) return FALSE; - icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); + icount = (unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); D(emitcode (";","genPlusIncr")); /* if increment >=16 bits in register or direct space */ - if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || + if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR || (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) && sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && @@ -4491,7 +4511,7 @@ genPlus (iCode * ic) /* if result in bit space */ if (AOP_TYPE (IC_RESULT (ic)) == AOP_CRY) { - if ((unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) != 0L) + if (ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) != 0L) emitcode ("cpl", "c"); outBitC (IC_RESULT (ic)); } @@ -4551,7 +4571,7 @@ genPlus (iCode * ic) /* if the lower bytes of a literal are zero skip the addition */ if (AOP_TYPE (IC_RIGHT (ic)) == AOP_LIT ) { - while ((0 == ((unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) & (0xff << skip_bytes*8))) && + while ((0 == ((unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit) & (0xff << skip_bytes*8))) && (skip_bytes+1 < size)) { skip_bytes++; @@ -4634,13 +4654,13 @@ genMinusDec (iCode * ic) /* if the literal value of the right hand side is greater than 4 then it is not worth it */ - if ((icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4) + if ((icount = (unsigned int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit)) > 4) return FALSE; D (emitcode (";", "genMinusDec")); /* if decrement >=16 bits in register or direct space */ - if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || + if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR || (IS_AOP_PREG (IC_LEFT(ic)) && !AOP_NEEDSACC (IC_LEFT(ic))) ) && sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && @@ -4858,7 +4878,7 @@ genMinus (iCode * ic) unsigned long lit = 0L; bool useCarry = FALSE; - lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); + lit = ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); lit = -(long) lit; while (size--) @@ -5058,7 +5078,7 @@ genMultOneByte (operand * left, if (AOP_TYPE(left) == AOP_LIT) { /* signed literal */ - signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit); if (val < 0) compiletimeSign = TRUE; } @@ -5072,7 +5092,7 @@ genMultOneByte (operand * left, if (AOP_TYPE(right) == AOP_LIT) { /* signed literal */ - signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit); if (val < 0) compiletimeSign ^= TRUE; } @@ -5093,7 +5113,7 @@ genMultOneByte (operand * left, /* save the signs of the operands */ if (AOP_TYPE(right) == AOP_LIT) { - signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit); if (!rUnsigned && val < 0) emitcode ("mov", "b,#0x%02x", -val); @@ -5119,7 +5139,7 @@ genMultOneByte (operand * left, if (AOP_TYPE(left) == AOP_LIT) { - signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit); if (!lUnsigned && val < 0) emitcode ("mov", "a,#0x%02x", -val); @@ -5326,7 +5346,7 @@ genDivOneByte (operand * left, if (AOP_TYPE(left) == AOP_LIT) { /* signed literal */ - signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit); if (val < 0) compiletimeSign = TRUE; } @@ -5340,7 +5360,7 @@ genDivOneByte (operand * left, if (AOP_TYPE(right) == AOP_LIT) { /* signed literal */ - signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit); if (val < 0) compiletimeSign ^= TRUE; } @@ -5361,7 +5381,7 @@ genDivOneByte (operand * left, /* save the signs of the operands */ if (AOP_TYPE(right) == AOP_LIT) { - signed char val = (char) floatFromVal (AOP (right)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (right)->aopu.aop_lit); if (!rUnsigned && val < 0) emitcode ("mov", "b,#0x%02x", -val); @@ -5387,7 +5407,7 @@ genDivOneByte (operand * left, if (AOP_TYPE(left) == AOP_LIT) { - signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit); if (!lUnsigned && val < 0) emitcode ("mov", "a,#0x%02x", -val); @@ -5664,7 +5684,7 @@ genModOneByte (operand * left, /* sign adjust left side */ if (AOP_TYPE(left) == AOP_LIT) { - signed char val = (char) floatFromVal (AOP (left)->aopu.aop_lit); + signed char val = (char) ulFromVal (AOP (left)->aopu.aop_lit); if (!lUnsigned && val < 0) { @@ -5857,7 +5877,7 @@ genCmp (operand * left, operand * right, { if (AOP_TYPE (right) == AOP_LIT) { - lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit); + lit = ulFromVal (AOP (right)->aopu.aop_lit); /* optimize if(x < 0) or if(x >= 0) */ if (lit == 0L) { @@ -6058,7 +6078,7 @@ gencjneshort (operand * left, operand * right, symbol * lbl) } if (AOP_TYPE (right) == AOP_LIT) - lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit); + lit = ulFromVal (AOP (right)->aopu.aop_lit); /* if the right side is a literal then anything goes */ if (AOP_TYPE (right) == AOP_LIT && @@ -6173,7 +6193,7 @@ genCmpEq (iCode * ic, iCode * ifx) { if (AOP_TYPE (right) == AOP_LIT) { - unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); + unsigned long lit = ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); if (lit == 0L) { emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir); @@ -6253,7 +6273,7 @@ genCmpEq (iCode * ic, iCode * ifx) { if (AOP_TYPE (right) == AOP_LIT) { - unsigned long lit = (unsigned long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); + unsigned long lit = ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); if (lit == 0L) { emitcode ("mov", "c,%s", AOP (left)->aopu.aop_dir); @@ -6595,7 +6615,7 @@ genAnd (iCode * ic, iCode * ifx) left = tmp; } if (AOP_TYPE (right) == AOP_LIT) - lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit); + lit = ulFromVal (AOP (right)->aopu.aop_lit); size = AOP_SIZE (result); @@ -6638,7 +6658,7 @@ genAnd (iCode * ic, iCode * ifx) { emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir); } - else + else { emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir); @@ -7026,7 +7046,7 @@ genOr (iCode * ic, iCode * ifx) left = tmp; } if (AOP_TYPE (right) == AOP_LIT) - lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit); + lit = ulFromVal (AOP (right)->aopu.aop_lit); size = AOP_SIZE (result); @@ -7067,7 +7087,7 @@ genOr (iCode * ic, iCode * ifx) { emitcode ("orl", "c,%s", AOP (right)->aopu.aop_dir); } - else + else { emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir); @@ -7076,22 +7096,20 @@ genOr (iCode * ic, iCode * ifx) else { // c = bit | val; - symbol *tlbl = newiTempLabel (NULL); - if (!((AOP_TYPE (result) == AOP_CRY) && ifx)) - emitcode ("setb", "c"); - emitcode ("jb", "%s,%05d$", - AOP (left)->aopu.aop_dir, tlbl->key + 100); - toBoolean (right); - emitcode ("jnz", "%05d$", tlbl->key + 100); if ((AOP_TYPE (result) == AOP_CRY) && ifx) { + symbol *tlbl = newiTempLabel (NULL); + emitcode ("jb", "%s,%05d$", + AOP (left)->aopu.aop_dir, tlbl->key + 100); + toBoolean (right); + emitcode ("jnz", "%05d$", tlbl->key + 100); jmpTrueOrFalse (ifx, tlbl, left, right, result); goto release; } else { - CLRC; - emitLabel (tlbl); + toCarry (right); + emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir); } } } @@ -7412,7 +7430,7 @@ genXor (iCode * ic, iCode * ifx) } if (AOP_TYPE (right) == AOP_LIT) - lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit); + lit = ulFromVal (AOP (right)->aopu.aop_lit); size = AOP_SIZE (result); @@ -7918,7 +7936,7 @@ genGetAbit (iCode * ic) aopOp (right, ic, FALSE); aopOp (result, ic, FALSE); - shCount = (int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); + shCount = (int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); /* get the needed byte into a */ MOVA (aopGet (left, shCount / 8, FALSE, FALSE)); @@ -7990,7 +8008,7 @@ genGetByte (iCode * ic) aopOp (right, ic, FALSE); aopOp (result, ic, FALSE); - offset = (int)floatFromVal (AOP (right)->aopu.aop_lit) / 8; + offset = (int) ulFromVal (AOP (right)->aopu.aop_lit) / 8; aopPut (result, aopGet (left, offset, FALSE, FALSE), 0); @@ -8018,7 +8036,7 @@ genGetWord (iCode * ic) aopOp (right, ic, FALSE); aopOp (result, ic, FALSE); - offset = (int)floatFromVal (AOP (right)->aopu.aop_lit) / 8; + offset = (int) ulFromVal (AOP (right)->aopu.aop_lit) / 8; aopPut (result, aopGet (left, offset, FALSE, FALSE), 0); @@ -8955,7 +8973,7 @@ genLeftShiftLiteral (operand * left, operand * result, iCode * ic) { - int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit); + int shCount = (int) ulFromVal (AOP (right)->aopu.aop_lit); int size; D (emitcode (";", "genLeftShiftLiteral")); @@ -9347,7 +9365,7 @@ genRightShiftLiteral (operand * left, iCode * ic, int sign) { - int shCount = (int) floatFromVal (AOP (right)->aopu.aop_lit); + int shCount = (int) ulFromVal (AOP (right)->aopu.aop_lit); int size; D (emitcode (";", "genRightShiftLiteral")); @@ -9729,7 +9747,7 @@ emitPtrByteSet (char *rname, int p_type, char *src) /*-----------------------------------------------------------------*/ /* genUnpackBits - generates code for unpacking bits */ /*-----------------------------------------------------------------*/ -static void +static char* genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx) { int offset = 0; /* result byte offset */ @@ -9738,7 +9756,8 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx) sym_link *etype; /* bitfield type information */ int blen; /* bitfield length */ int bstr; /* bitfield starting bit within byte */ - char buffer[10]; + static char* const accBits[] = {"acc.0", "acc.1", "acc.2", "acc.3", + "acc.4", "acc.5", "acc.6", "acc.7"}; D(emitcode (";", "genUnpackBits")); @@ -9752,18 +9771,15 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx) emitPtrByteGet (rname, ptype, FALSE); if (blen == 1) { - SNPRINTF (buffer, sizeof(buffer), - "acc.%d", bstr); - genIfxJump (ifx, buffer, NULL, NULL, NULL); + return accBits[bstr];; } else { if (blen < 8) emitcode ("anl", "a,#0x%02x", (((unsigned char) -1) >> (8 - blen)) << bstr); - genIfxJump (ifx, "a", NULL, NULL, NULL); + return "a"; } - return; } wassert (!ifx); @@ -9832,6 +9848,7 @@ finish: while (rsize--) aopPut (result, source, offset++); } + return NULL; } @@ -9885,9 +9902,9 @@ genNearPointerGet (operand * left, asmop *aop = NULL; regs *preg = NULL; char *rname; + char *ifxCond = "a"; sym_link *rtype, *retype; sym_link *ltype = operandType (left); - char buffer[80]; D (emitcode (";", "genNearPointerGet")); @@ -9908,6 +9925,9 @@ genNearPointerGet (operand * left, return; } + //aopOp (result, ic, FALSE); + aopOp (result, ic, result?TRUE:FALSE); + /* if the value is already in a pointer register then don't need anything more */ if (!AOP_INPREG (AOP (left))) @@ -9942,12 +9962,9 @@ genNearPointerGet (operand * left, else rname = aopGet (left, 0, FALSE, FALSE); - //aopOp (result, ic, FALSE); - aopOp (result, ic, result?TRUE:FALSE); - /* if bitfield then unpack the bits */ if (IS_BITFIELD (retype)) - genUnpackBits (result, rname, POINTER, ifx); + ifxCond = genUnpackBits (result, rname, POINTER, ifx); else { /* we have can just get the values */ @@ -9965,6 +9982,8 @@ genNearPointerGet (operand * left, } else { + char buffer[80]; + SNPRINTF (buffer, sizeof(buffer), "@%s", rname); aopPut (result, buffer, offset); } @@ -10003,7 +10022,7 @@ genNearPointerGet (operand * left, if (ifx && !ifx->generated) { - genIfxJump (ifx, "a", left, NULL, result); + genIfxJump (ifx, ifxCond, left, NULL, result); } /* done */ @@ -10025,6 +10044,7 @@ genPagedPointerGet (operand * left, asmop *aop = NULL; regs *preg = NULL; char *rname; + char *ifxCond = "a"; sym_link *rtype, *retype; D (emitcode (";", "genPagedPointerGet")); @@ -10034,6 +10054,8 @@ genPagedPointerGet (operand * left, aopOp (left, ic, FALSE); + aopOp (result, ic, FALSE); + /* if the value is already in a pointer register then don't need anything more */ if (!AOP_INPREG (AOP (left))) @@ -10049,11 +10071,9 @@ genPagedPointerGet (operand * left, else rname = aopGet (left, 0, FALSE, FALSE); - aopOp (result, ic, FALSE); - /* if bitfield then unpack the bits */ if (IS_BITFIELD (retype)) - genUnpackBits (result, rname, PPOINTER, ifx); + ifxCond = genUnpackBits (result, rname, PPOINTER, ifx); else { /* we have can just get the values */ @@ -10102,7 +10122,7 @@ genPagedPointerGet (operand * left, if (ifx && !ifx->generated) { - genIfxJump (ifx, "a", left, NULL, result); + genIfxJump (ifx, ifxCond, left, NULL, result); } /* done */ @@ -10179,6 +10199,7 @@ genFarPointerGet (operand * left, operand * result, iCode * ic, iCode * pi, iCode * ifx) { int size, offset; + char *ifxCond = "a"; sym_link *retype = getSpec (operandType (result)); D (emitcode (";", "genFarPointerGet")); @@ -10191,7 +10212,7 @@ genFarPointerGet (operand * left, /* if bit then unpack */ if (IS_BITFIELD (retype)) - genUnpackBits (result, "dptr", FPOINTER, ifx); + ifxCond = genUnpackBits (result, "dptr", FPOINTER, ifx); else { size = AOP_SIZE (result); @@ -10216,7 +10237,7 @@ genFarPointerGet (operand * left, if (ifx && !ifx->generated) { - genIfxJump (ifx, "a", left, NULL, result); + genIfxJump (ifx, ifxCond, left, NULL, result); } freeAsmop (result, NULL, ic, TRUE); @@ -10231,6 +10252,7 @@ genCodePointerGet (operand * left, operand * result, iCode * ic, iCode *pi, iCode *ifx) { int size, offset; + char *ifxCond = "a"; sym_link *retype = getSpec (operandType (result)); D (emitcode (";", "genCodePointerGet")); @@ -10243,7 +10265,7 @@ genCodePointerGet (operand * left, /* if bit then unpack */ if (IS_BITFIELD (retype)) - genUnpackBits (result, "dptr", CPOINTER, ifx); + ifxCond = genUnpackBits (result, "dptr", CPOINTER, ifx); else { size = AOP_SIZE (result); @@ -10269,7 +10291,7 @@ genCodePointerGet (operand * left, if (ifx && !ifx->generated) { - genIfxJump (ifx, "a", left, NULL, result); + genIfxJump (ifx, ifxCond, left, NULL, result); } freeAsmop (result, NULL, ic, TRUE); @@ -10284,6 +10306,7 @@ genGenPointerGet (operand * left, operand * result, iCode * ic, iCode *pi, iCode *ifx) { int size, offset; + char *ifxCond = "a"; sym_link *retype = getSpec (operandType (result)); D (emitcode (";", "genGenPointerGet")); @@ -10297,7 +10320,7 @@ genGenPointerGet (operand * left, /* if bit then unpack */ if (IS_BITFIELD (retype)) { - genUnpackBits (result, "dptr", GPOINTER, ifx); + ifxCond = genUnpackBits (result, "dptr", GPOINTER, ifx); } else { @@ -10323,7 +10346,7 @@ genGenPointerGet (operand * left, if (ifx && !ifx->generated) { - genIfxJump (ifx, "a", left, NULL, result); + genIfxJump (ifx, ifxCond, left, NULL, result); } freeAsmop (result, NULL, ic, TRUE); @@ -10354,7 +10377,9 @@ genPointerGet (iCode * ic, iCode *pi, iCode *ifx) etype = getSpec (type); /* if left is of type of pointer then it is simple */ if (IS_PTR (type) && !IS_FUNC (type->next)) - p_type = DCL_TYPE (type); + { + p_type = DCL_TYPE (type); + } else { /* we have to go by the storage class */ @@ -10428,7 +10453,7 @@ genPackBits (sym_link * etype, { /* Case with a bitfield length <8 and literal source */ - litval = (int) floatFromVal (AOP (right)->aopu.aop_lit); + litval = (int) ulFromVal (AOP (right)->aopu.aop_lit); litval <<= bstr; litval &= (~mask) & 0xff; emitPtrByteGet (rname, p_type, FALSE); @@ -10499,7 +10524,7 @@ genPackBits (sym_link * etype, { /* Case with partial byte and literal source */ - litval = (int) floatFromVal (AOP (right)->aopu.aop_lit); + litval = (int) ulFromVal (AOP (right)->aopu.aop_lit); litval >>= (blen-rlen); litval &= (~mask) & 0xff; emitPtrByteGet (rname, p_type, FALSE); @@ -10601,39 +10626,36 @@ genNearPointerSet (operand * right, then don't need anything more */ if (!AOP_INPREG (AOP (result))) { - if ( - //AOP_TYPE (result) == AOP_STK - IS_AOP_PREG(result) - ) + if (IS_AOP_PREG (result)) { - // Aha, it is a pointer, just in disguise. - rname = aopGet (result, 0, FALSE, FALSE); - if (*rname != '@') + // Aha, it is a pointer, just in disguise. + rname = aopGet (result, 0, FALSE, FALSE); + if (*rname != '@') { - fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", - __FILE__, __LINE__); + fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", + __FILE__, __LINE__); } - else + else { - // Expected case. - emitcode ("mov", "a%s,%s", rname + 1, rname); - rname++; // skip the '@'. + // Expected case. + emitcode ("mov", "a%s,%s", rname + 1, rname); + rname++; // skip the '@'. } } - else + else { - /* otherwise get a free pointer register */ - aop = newAsmop (0); - preg = getFreePtr (ic, &aop, FALSE); - emitcode ("mov", "%s,%s", - preg->name, - aopGet (result, 0, FALSE, TRUE)); - rname = preg->name; + /* otherwise get a free pointer register */ + aop = newAsmop (0); + preg = getFreePtr (ic, &aop, FALSE); + emitcode ("mov", "%s,%s", + preg->name, + aopGet (result, 0, FALSE, TRUE)); + rname = preg->name; } } - else + else { - rname = aopGet (result, 0, FALSE, FALSE); + rname = aopGet (result, 0, FALSE, FALSE); } aopOp (right, ic, FALSE); @@ -10721,16 +10743,37 @@ genPagedPointerSet (operand * right, then don't need anything more */ if (!AOP_INPREG (AOP (result))) { - /* otherwise get a free pointer register */ - aop = newAsmop (0); - preg = getFreePtr (ic, &aop, FALSE); - emitcode ("mov", "%s,%s", - preg->name, - aopGet (result, 0, FALSE, TRUE)); - rname = preg->name; + if (IS_AOP_PREG (result)) + { + // Aha, it is a pointer, just in disguise. + rname = aopGet (result, 0, FALSE, FALSE); + if (*rname != '@') + { + fprintf(stderr, "probable internal error: unexpected rname @ %s:%d\n", + __FILE__, __LINE__); + } + else + { + // Expected case. + emitcode ("mov", "a%s,%s", rname + 1, rname); + rname++; // skip the '@'. + } + } + else + { + /* otherwise get a free pointer register */ + aop = newAsmop (0); + preg = getFreePtr (ic, &aop, FALSE); + emitcode ("mov", "%s,%s", + preg->name, + aopGet (result, 0, FALSE, TRUE)); + rname = preg->name; + } } else - rname = aopGet (result, 0, FALSE, FALSE); + { + rname = aopGet (result, 0, FALSE, FALSE); + } aopOp (right, ic, FALSE); @@ -10739,7 +10782,7 @@ genPagedPointerSet (operand * right, genPackBits ((IS_BITFIELD (retype) ? retype : letype), right, rname, PPOINTER); else { - /* we have can just get the values */ + /* we can just get the values */ int size = AOP_SIZE (right); int offset = 0; @@ -10748,10 +10791,8 @@ genPagedPointerSet (operand * right, l = aopGet (right, offset, FALSE, TRUE); MOVA (l); emitcode ("movx", "@%s,a", rname); - if (size || pi) emitcode ("inc", "%s", rname); - offset++; } } @@ -10772,8 +10813,8 @@ genPagedPointerSet (operand * right, belongs */ if (AOP_SIZE (right) > 1 && !OP_SYMBOL (result)->remat && - (OP_SYMBOL (result)->liveTo > ic->seq || - ic->depth)) + (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth) && + !pi) { int size = AOP_SIZE (right) - 1; while (size--) @@ -10782,9 +10823,10 @@ genPagedPointerSet (operand * right, } /* done */ - if (pi) pi->generated = 1; - freeAsmop (result, NULL, ic, TRUE); + if (pi) + pi->generated = 1; freeAsmop (right, NULL, ic, TRUE); + freeAsmop (result, NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ @@ -11154,7 +11196,7 @@ genAssign (iCode * ic) size = AOP_SIZE (result); offset = 0; if (AOP_TYPE (right) == AOP_LIT) - lit = (unsigned long) floatFromVal (AOP (right)->aopu.aop_lit); + lit = ulFromVal (AOP (right)->aopu.aop_lit); if ((size > 1) && (AOP_TYPE (result) != AOP_REG) && @@ -11630,7 +11672,10 @@ genReceive (iCode * ic) } else if (ic->argreg > 12) { /* bit parameters */ - if (OP_SYMBOL (IC_RESULT (ic))->regs[0]->rIdx != ic->argreg-5) + regs *reg = OP_SYMBOL (IC_RESULT (ic))->regs[0]; + + BitBankUsed = 1; + if (!reg || reg->rIdx != ic->argreg-5) { aopOp (IC_RESULT (ic), ic, FALSE); emitcode ("mov", "c,%s", rb1regs[ic->argreg-5]); @@ -11827,7 +11872,7 @@ gen51Code (iCode * lic) if (options.iCodeInAsm) { char regsInUse[80]; int i; - char *iLine; + const char *iLine; #if 0 for (i=0; i<8; i++) {