X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fmcs51%2Fgen.c;h=e4c6e5f85d4c588f3476abe7b73479e97fb5ac92;hb=3deeed761a1da5128e841a85bf4773a8a48e15b4;hp=a36937f2b817765617bed83f1104f2b910f8858e;hpb=f54be5445d7869a9aac7ebfcc83ce1713aee5c1d;p=fw%2Fsdcc diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index a36937f2..e4c6e5f8 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -28,7 +28,7 @@ Made everything static -------------------------------------------------------------------------*/ -#define D(x) do if (!options.noGenComments) {x;} while(0) +#define D(x) do if (options.verboseAsm) {x;} while(0) #include #include @@ -181,19 +181,20 @@ emitcode (const char *inst, const char *fmt,...) lbp++; } - if (lbp && *lbp) + if (lbp) { rtrackUpdate (lbp); lineCurr = (lineCurr ? connectLine (lineCurr, newLineNode (lb)) : (lineHead = newLineNode (lb))); + + lineCurr->isInline = _G.inLine; + lineCurr->isDebug = _G.debugLine; + lineCurr->ic = _G.current_iCode; + lineCurr->isComment = (*lbp==';'); } - lineCurr->isInline = _G.inLine; - lineCurr->isDebug = _G.debugLine; - lineCurr->ic = _G.current_iCode; - lineCurr->isComment = (*lbp==';'); va_end (ap); dbuf_destroy(&dbuf); @@ -542,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); @@ -553,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); @@ -564,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); @@ -572,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); @@ -968,7 +969,7 @@ aopOp (operand * op, iCode * ic, bool result) if (sym->remat) { sym->aop = op->aop = aop = aopForRemat (sym); - aop->size = getSize (sym->type); + aop->size = operandSize (op); return; } @@ -1491,6 +1492,7 @@ aopPut (operand * result, const char *s, int offset) bool bvolatile = isOperandVolatile (result, FALSE); bool accuse = FALSE; asmop * aop = AOP (result); + const char *d = NULL; if (aop->size && offset > (aop->size - 1)) { @@ -1666,28 +1668,40 @@ aopPut (operand * result, const char *s, int offset) break; case AOP_CRY: - /* if result no bit variable */ - if (!aop->aopu.aop_dir) - { - assert (!strcmp (s, "c")); - /* inefficient: move carry into A and use jz/jnz */ - emitcode ("clr", "a"); - emitcode ("rlc", "a"); - accuse = TRUE; - } - else if (s == zero) - emitcode ("clr", "%s", aop->aopu.aop_dir); - else if (s == one) - emitcode ("setb", "%s", aop->aopu.aop_dir); - else if (!strcmp (s, "c")) - emitcode ("mov", "%s,c", aop->aopu.aop_dir); - else if (strcmp (s, aop->aopu.aop_dir)) + // destination is carry for return-use-only + d = (IS_OP_RUONLY (result)) ? "c" : aop->aopu.aop_dir; + // source is no literal and not in carry + if ((s != zero) && (s != one) && strcmp (s, "c")) { MOVA (s); /* set C, if a >= 1 */ emitcode ("add", "a,#0xff"); - emitcode ("mov", "%s,c", aop->aopu.aop_dir); + s = "c"; + } + // now source is zero, one or carry + + /* if result no bit variable */ + if (!d) + { + if (!strcmp (s, "c")) + { + /* inefficient: move carry into A and use jz/jnz */ + emitcode ("clr", "a"); + emitcode ("rlc", "a"); + accuse = TRUE; + } + else + { + MOVA (s); + accuse = TRUE; + } } + else if (s == zero) + emitcode ("clr", "%s", d); + else if (s == one) + emitcode ("setb", "%s", d); + else if (strcmp (s, d)) + emitcode ("mov", "%s,c", d); break; case AOP_STR: @@ -1838,7 +1852,7 @@ outBitC (operand * result) /* if the result is bit */ if (AOP_TYPE (result) == AOP_CRY) { - if (!OP_SYMBOL (result)->ruonly) + if (!IS_OP_RUONLY (result)) aopPut (result, "c", 0); } else @@ -1992,7 +2006,7 @@ genNot (iCode * ic) } else { - emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir); + toCarry (IC_LEFT (ic)); emitcode ("cpl", "c"); outBitC (IC_RESULT (ic)); } @@ -2669,9 +2683,9 @@ saveRBank (int bank, iCode * ic, bool pushPsw) } if (ic) - { - ic->bankSaved = 1; - } + { + ic->bankSaved = 1; + } } /*-----------------------------------------------------------------*/ @@ -3405,7 +3419,7 @@ genFunction (iCode * ic) } } } - else + else { /* This ISR uses a non-zero bank. * @@ -3590,7 +3604,7 @@ genFunction (iCode * ic) int ofs; _G.current_iCode = ric; - D(emitcode ("; genReceive","")); + D(emitcode (";", "genReceive")); for (ofs=0; ofs < sym->recvSize; ofs++) { if (!strcmp (fReturn[ofs], "a")) @@ -3615,7 +3629,7 @@ genFunction (iCode * ic) int ofs; _G.current_iCode = ric; - D(emitcode ("; genReceive","")); + D(emitcode (";", "genReceive")); for (ofs=0; ofs < sym->recvSize; ofs++) { emitcode ("mov", "%s,%s", rsym->regs[ofs]->name, fReturn[ofs]); @@ -4039,7 +4053,7 @@ genRet (iCode * ic) if (IS_BIT(_G.currentFunc->etype)) { - if (!OP_SYMBOL (IC_LEFT (ic))->ruonly) + if (!IS_OP_RUONLY (IC_LEFT (ic))) toCarry (IC_LEFT (ic)); } else @@ -4152,12 +4166,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))) && @@ -4477,7 +4491,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)); } @@ -4514,7 +4528,7 @@ genPlus (iCode * ic) && (SPEC_ADDR (OP_SYM_ETYPE (op)) & 0xff) == 0 ) { - D(emitcode ("; genPlus aligned array","")); + D(emitcode (";", "genPlus aligned array")); aopPut (IC_RESULT (ic), aopGet (rightOp, 0, FALSE, FALSE), 0); @@ -4537,13 +4551,13 @@ 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++; } if (skip_bytes) - D(emitcode ("; genPlus shortcut","")); + D(emitcode (";", "genPlus shortcut")); } while (size--) @@ -4620,13 +4634,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))) && @@ -4844,7 +4858,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--) @@ -5044,7 +5058,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; } @@ -5058,7 +5072,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; } @@ -5079,7 +5093,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); @@ -5105,7 +5119,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); @@ -5214,7 +5228,7 @@ genDivbits (operand * left, char *l; bool pushedB; - D(emitcode ("; genDivbits","")); + D(emitcode (";", "genDivbits")); pushedB = pushB (); @@ -5247,7 +5261,7 @@ genDivOneByte (operand * left, symbol *lbl; int size, offset; - D(emitcode ("; genDivOneByte","")); + D(emitcode (";", "genDivOneByte")); /* Why is it necessary that genDivOneByte() can return an int result? Have a look at: @@ -5312,7 +5326,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; } @@ -5326,7 +5340,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; } @@ -5347,7 +5361,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); @@ -5373,7 +5387,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); @@ -5459,7 +5473,7 @@ genDiv (iCode * ic) D (emitcode (";", "genDiv")); - /* assign the amsops */ + /* assign the asmops */ aopOp (left, ic, FALSE); aopOp (right, ic, FALSE); aopOp (result, ic, TRUE); @@ -5650,7 +5664,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) { @@ -5843,7 +5857,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) { @@ -5978,7 +5992,7 @@ genCmpGt (iCode * ic, iCode * ifx) retype = getSpec (operandType (right)); sign = !((SPEC_USIGN (letype) && !(IS_CHAR (letype) && IS_LITERAL (letype))) || (SPEC_USIGN (retype) && !(IS_CHAR (retype) && IS_LITERAL (retype)))); - /* assign the amsops */ + /* assign the asmops */ aopOp (result, ic, TRUE); aopOp (left, ic, FALSE); aopOp (right, ic, FALSE); @@ -6008,7 +6022,7 @@ genCmpLt (iCode * ic, iCode * ifx) retype = getSpec (operandType (right)); sign = !((SPEC_USIGN (letype) && !(IS_CHAR (letype) && IS_LITERAL (letype))) || (SPEC_USIGN (retype) && !(IS_CHAR (retype) && IS_LITERAL (retype)))); - /* assign the amsops */ + /* assign the asmops */ aopOp (result, ic, TRUE); aopOp (left, ic, FALSE); aopOp (right, ic, FALSE); @@ -6033,8 +6047,9 @@ gencjneshort (operand * left, operand * right, symbol * lbl) /* if the left side is a literal or if the right is in a pointer register and left is not */ - if ((AOP_TYPE (left) == AOP_LIT) || + if ((AOP_TYPE (left) == AOP_LIT) || (AOP_TYPE (left) == AOP_IMMD) || + (AOP_TYPE (left) == AOP_DIR) || (IS_AOP_PREG (right) && !IS_AOP_PREG (left))) { operand *t = right; @@ -6043,7 +6058,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 && @@ -6101,7 +6116,7 @@ gencjneshort (operand * left, operand * right, symbol * lbl) /* gencjne - compare and jump if not equal */ /*-----------------------------------------------------------------*/ static void -gencjne (operand * left, operand * right, symbol * lbl) +gencjne (operand * left, operand * right, symbol * lbl, bool useCarry) { symbol *tlbl = newiTempLabel (NULL); @@ -6109,10 +6124,16 @@ gencjne (operand * left, operand * right, symbol * lbl) gencjneshort (left, right, lbl); - emitcode ("mov", "a,%s", one); + if (useCarry) + SETC; + else + MOVA (one); emitcode ("sjmp", "%05d$", tlbl->key + 100); emitLabel (lbl); - emitcode ("clr", "a"); + if (useCarry) + CLRC; + else + MOVA (zero); emitLabel (tlbl); } @@ -6152,7 +6173,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); @@ -6232,7 +6253,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); @@ -6273,12 +6294,13 @@ genCmpEq (iCode * ic, iCode * ifx) } else { - gencjne (left, right, newiTempLabel (NULL)); if (AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) { - aopPut (result, "a", 0); + gencjne (left, right, newiTempLabel (NULL), TRUE); + aopPut (result, "c", 0); goto release; } + gencjne (left, right, newiTempLabel (NULL), FALSE); if (ifx) { genIfxJump (ifx, "a", left, right, result); @@ -6539,10 +6561,10 @@ genAnd (iCode * ic, iCode * ifx) aopOp ((result = IC_RESULT (ic)), ic, TRUE); #ifdef DEBUG_TYPE - emitcode ("", "; Type res[%d] = l[%d]&r[%d]", + emitcode (";", "Type res[%d] = l[%d]&r[%d]", AOP_TYPE (result), AOP_TYPE (left), AOP_TYPE (right)); - emitcode ("", "; Size res[%d] = l[%d]&r[%d]", + emitcode (";", "Size res[%d] = l[%d]&r[%d]", AOP_SIZE (result), AOP_SIZE (left), AOP_SIZE (right)); #endif @@ -6573,7 +6595,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); @@ -6612,8 +6634,15 @@ genAnd (iCode * ic, iCode * ifx) if (AOP_TYPE (right) == AOP_CRY) { // c = bit & bit; - emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); - emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir); + if (IS_OP_ACCUSE (left)) + { + emitcode ("anl", "c,%s", AOP (right)->aopu.aop_dir); + } + else + { + emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); + emitcode ("anl", "c,%s", AOP (left)->aopu.aop_dir); + } } else { @@ -6963,10 +6992,10 @@ genOr (iCode * ic, iCode * ifx) aopOp ((result = IC_RESULT (ic)), ic, TRUE); #ifdef DEBUG_TYPE - emitcode ("", "; Type res[%d] = l[%d]&r[%d]", + emitcode (";", "Type res[%d] = l[%d]&r[%d]", AOP_TYPE (result), AOP_TYPE (left), AOP_TYPE (right)); - emitcode ("", "; Size res[%d] = l[%d]&r[%d]", + emitcode (";", "Size res[%d] = l[%d]&r[%d]", AOP_SIZE (result), AOP_SIZE (left), AOP_SIZE (right)); #endif @@ -6997,7 +7026,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); @@ -7034,28 +7063,33 @@ genOr (iCode * ic, iCode * ifx) if (AOP_TYPE (right) == AOP_CRY) { // c = bit | bit; - emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); - emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir); + if (IS_OP_ACCUSE (left)) + { + emitcode ("orl", "c,%s", AOP (right)->aopu.aop_dir); + } + else + { + emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); + emitcode ("orl", "c,%s", AOP (left)->aopu.aop_dir); + } } 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); } } } @@ -7340,10 +7374,10 @@ genXor (iCode * ic, iCode * ifx) aopOp ((result = IC_RESULT (ic)), ic, TRUE); #ifdef DEBUG_TYPE - emitcode ("", "; Type res[%d] = l[%d]&r[%d]", + emitcode (";", "Type res[%d] = l[%d]&r[%d]", AOP_TYPE (result), AOP_TYPE (left), AOP_TYPE (right)); - emitcode ("", "; Size res[%d] = l[%d]&r[%d]", + emitcode (";", "Size res[%d] = l[%d]&r[%d]", AOP_SIZE (result), AOP_SIZE (left), AOP_SIZE (right)); #endif @@ -7374,8 +7408,9 @@ genXor (iCode * ic, iCode * ifx) right = left; 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); @@ -7432,25 +7467,21 @@ genXor (iCode * ic, iCode * ifx) if (AOP_TYPE (right) == AOP_CRY) { // c = bit ^ bit; - emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir); + if (IS_OP_ACCUSE (left)) + {// left already is in the carry + operand *tmp = right; + right = left; + left = tmp; + } + else + { + toCarry (right); + } } else { - int sizer = AOP_SIZE (right); // c = bit ^ val - // if val>>1 != 0, result = 1 - emitcode ("setb", "c"); - while (sizer) - { - MOVA (aopGet (right, sizer - 1, FALSE, FALSE)); - if (sizer == 1) - // test the msb of the lsb - emitcode ("anl", "a,#0xfe"); - emitcode ("jnz", "%05d$", tlbl->key + 100); - sizer--; - } - // val = (0,1) - emitcode ("rrc", "a"); + toCarry (right); } emitcode ("jnb", "%s,%05d$", AOP (left)->aopu.aop_dir, (tlbl->key + 100)); emitcode ("cpl", "c"); @@ -7678,40 +7709,51 @@ static void genInline (iCode * ic) { char *buffer, *bp, *bp1; + bool inComment = FALSE; D (emitcode (";", "genInline")); _G.inLine += (!options.asmpeep); - buffer = bp = bp1 = Safe_strdup(IC_INLINE(ic)); + buffer = bp = bp1 = Safe_strdup (IC_INLINE (ic)); /* emit each line as a code */ while (*bp) { - if (*bp == '\n') + switch (*bp) { + case ';': + inComment = TRUE; + ++bp; + break; + + case '\n': + inComment = FALSE; *bp++ = '\0'; emitcode (bp1, ""); bp1 = bp; - } - else - { + break; + + default: /* Add \n for labels, not dirs such as c:\mydir */ - if ( (*bp == ':') && (isspace((unsigned char)bp[1])) ) + if (!inComment && (*bp == ':') && (isspace((unsigned char)bp[1]))) { - bp++; + ++bp; *bp = '\0'; - bp++; + ++bp; emitcode (bp1, ""); bp1 = bp; } else - bp++; + ++bp; + break; } } if (bp1 != bp) emitcode (bp1, ""); - /* emitcode("",buffer); */ + + Safe_free (buffer); + _G.inLine -= (!options.asmpeep); } @@ -7874,7 +7916,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)); @@ -7946,7 +7988,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); @@ -7974,7 +8016,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); @@ -7995,7 +8037,7 @@ genSwap (iCode * ic) { operand *left, *result; - D(emitcode ("; genSwap","")); + D(emitcode (";", "genSwap")); left = IC_LEFT (ic); result = IC_RESULT (ic); @@ -8911,7 +8953,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")); @@ -9303,7 +9345,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")); @@ -9696,7 +9738,7 @@ genUnpackBits (operand * result, char *rname, int ptype, iCode *ifx) int bstr; /* bitfield starting bit within byte */ char buffer[10]; - D(emitcode ("; genUnpackBits","")); + D(emitcode (";", "genUnpackBits")); etype = getSpec (operandType (result)); rsize = getSize (operandType (result)); @@ -10086,7 +10128,7 @@ loadDptrFromOperand (operand *op, bool loadBToo) else { wassertl(FALSE, "need pointerCode"); - emitcode ("", "; mov b,???"); + emitcode (";", "mov b,???"); /* genPointerGet and genPointerSet originally did different ** things for this case. Both seem wrong. ** from genPointerGet: @@ -10369,7 +10411,7 @@ genPackBits (sym_link * etype, int litval; /* source literal value (if AOP_LIT) */ unsigned char mask; /* bitmask within current byte */ - D(emitcode ("; genPackBits","")); + D(emitcode (";", "genPackBits")); blen = SPEC_BLEN (etype); bstr = SPEC_BSTR (etype); @@ -10384,7 +10426,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); @@ -10455,7 +10497,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); @@ -10505,7 +10547,7 @@ genDataPointerSet (operand * right, l = aopGet (result, 0, FALSE, TRUE); l++; //remove # - size = AOP_SIZE (right); + size = max (AOP_SIZE (right), AOP_SIZE (result)); while (size--) { if (offset) @@ -10516,12 +10558,12 @@ genDataPointerSet (operand * right, aopGet (right, offset++, FALSE, FALSE)); } - freeAsmop (result, NULL, ic, TRUE); freeAsmop (right, NULL, ic, TRUE); + freeAsmop (result, NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ -/* genNearPointerSet - emitcode for near pointer put */ +/* genNearPointerSet - emitcode for near pointer put */ /*-----------------------------------------------------------------*/ static void genNearPointerSet (operand * right, @@ -10646,9 +10688,10 @@ genNearPointerSet (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); } /*-----------------------------------------------------------------*/ @@ -10753,7 +10796,7 @@ genFarPointerSet (operand * right, sym_link *retype = getSpec (operandType (right)); sym_link *letype = getSpec (operandType (result)); - D(emitcode ("; genFarPointerSet","")); + D(emitcode (";", "genFarPointerSet")); aopOp (result, ic, FALSE); loadDptrFromOperand (result, FALSE); @@ -11109,7 +11152,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) && @@ -11585,7 +11628,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]); @@ -11702,7 +11748,7 @@ genCritical (iCode *ic) static void genEndCritical (iCode *ic) { - D(emitcode("; genEndCritical","")); + D(emitcode(";", "genEndCritical")); if (IC_RIGHT (ic)) { @@ -11767,7 +11813,7 @@ gen51Code (iCode * lic) debugFile->writeCLine (ic); } if (!options.noCcodeInAsm) { - emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno, + emitcode (";", "%s:%d: %s", ic->filename, ic->lineno, printCLine(ic->filename, ic->lineno)); } cln = ic->lineno; @@ -11775,7 +11821,7 @@ gen51Code (iCode * lic) #if 0 if (ic->seqPoint && ic->seqPoint != cseq) { - emitcode ("", "; sequence point %d", ic->seqPoint); + emitcode (";", "sequence point %d", ic->seqPoint); cseq = ic->seqPoint; } #endif @@ -11800,7 +11846,7 @@ gen51Code (iCode * lic) #endif } iLine = printILine(ic); - emitcode("", "; [%s] ic:%d: %s", regsInUse, ic->seq, printILine(ic)); + emitcode(";", "[%s] ic:%d: %s", regsInUse, ic->seq, iLine); dbuf_free(iLine); } /* if the result is marked as