X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fds390%2Fgen.c;h=da277d24b43a9004356acdc23e97ed772eb39fad;hb=c93cc0d6022434546bf3144906e471a87cfd73d1;hp=6cd8f3dc5948f58684f305633c7b03721aa4f6b2;hpb=a1eaead7297d95b9829ebb6cb304cec6ad27fba9;p=fw%2Fsdcc diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 6cd8f3dc..da277d24 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -26,7 +26,7 @@ -------------------------------------------------------------------------*/ //#define D(x) -#define D(x) x +#define D(x) do if (options.verboseAsm) {x;} while(0) #include #include @@ -34,6 +34,7 @@ #include #include "SDCCglobl.h" #include "newalloc.h" +#include "dbuf_string.h" #include "common.h" #include "main.h" @@ -191,7 +192,7 @@ static unsigned char SRMask[] = emitcode ("setb","F1"); \ emitcode ("jbc","EA,!tlabel",lbl->key+100); \ emitcode ("clr","F1"); \ - emitcode ("","!tlabeldef",lbl->key+100); \ + emitLabel (lbl); \ }} #define UNPROTECT_SP { if (options.protect_sp_update) { \ emitcode ("mov","EA,F1"); \ @@ -205,55 +206,61 @@ static int _lazyDPS = 0; /* if non-zero, we are doing lazy evaluation of /* emitcode - writes the code into a file : for now it is simple */ /*-----------------------------------------------------------------*/ static void -emitcode (char *inst, const char *fmt,...) +emitcode (const char *inst, const char *fmt,...) { va_list ap; - char lb[INITIAL_INLINEASM]; - char *lbp = lb; + struct dbuf_s dbuf; + const char *lbp, *lb; + + dbuf_init (&dbuf, INITIAL_INLINEASM); va_start (ap, fmt); if (inst && *inst) { + dbuf_append_str (&dbuf, inst); + if (fmt && *fmt) { - SNPRINTF (lb, sizeof(lb), "%s\t", inst); - } - else - { - SNPRINTF (lb, sizeof(lb), "%s", inst); - } - - tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), fmt, ap); + dbuf_append_char (&dbuf, '\t'); + dbuf_tvprintf (&dbuf, fmt, ap); + } } else { - tvsprintf (lb, sizeof(lb), fmt, ap); + dbuf_tvprintf (&dbuf, fmt, ap); } + lbp = lb = dbuf_c_str(&dbuf); + while (isspace ((unsigned char)*lbp)) { lbp++; } - if (lbp && *lbp) + if (lbp) { lineCurr = (lineCurr ? connectLine (lineCurr, newLineNode (lb)) : (lineHead = newLineNode (lb))); + + lineCurr->isInline = _G.inLine; + lineCurr->isDebug = _G.debugLine; + lineCurr->ic = _G.current_iCode; + lineCurr->aln = ds390newAsmLineNode(_currentDPS); + lineCurr->isComment = (*lbp == ';'); } - lineCurr->isInline = _G.inLine; - lineCurr->isDebug = _G.debugLine; - lineCurr->ic = _G.current_iCode; - lineCurr->aln = ds390newAsmLineNode(_currentDPS); va_end (ap); + + dbuf_destroy(&dbuf); } static void emitLabel (symbol *tlbl) { emitcode ("", "!tlabeldef", tlbl->key + 100); + lineCurr->isLabel = 1; } /*-----------------------------------------------------------------*/ @@ -1408,6 +1415,8 @@ aopGetUsesAcc (operand * oper, int offset) return TRUE; return FALSE; case AOP_DPTR: + case AOP_DPTR2: + case AOP_DPTRn: return TRUE; case AOP_IMMD: return FALSE; @@ -2446,12 +2455,32 @@ unsaveRegisters (iCode * ic) /*-----------------------------------------------------------------*/ -/* pushSide - */ +/* 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, FALSE); + + if (nPushed != _G.r0Pushed + _G.r1Pushed) + { + while (offset < size) + { + char *l = aopGet (oper, offset, FALSE, TRUE, NULL); + emitcode ("mov", "%s,%s", fReturn[offset++], l); + } + freeAsmop (oper, NULL, ic, TRUE); + offset = 0; + while (offset < size) + { + emitcode ("push", "%s", fReturn[offset++]); + } + return; + } + _startLazyDPSEvaluation (); while (size--) { @@ -2469,6 +2498,7 @@ pushSide (operand * oper, int size) } } _endLazyDPSEvaluation (); + freeAsmop (oper, NULL, ic, TRUE); } /*-----------------------------------------------------------------*/ @@ -3226,14 +3256,10 @@ genPcall (iCode * ic) emitcode ("push", "acc"); } - /* now push the calling address */ - aopOp (IC_LEFT (ic), ic, FALSE, FALSE); - - pushSide (IC_LEFT (ic), FPTRSIZE); - - freeAsmop (IC_LEFT (ic), NULL, ic, TRUE); + /* now push the function address */ + pushSide (IC_LEFT (ic), FPTRSIZE, ic); - /* if send set is not empty the assign */ + /* if send set is not empty then assign */ if (_G.sendSet) { genSend(reverseSet(_G.sendSet)); @@ -3347,12 +3373,6 @@ resultRemat (iCode * ic) return 0; } -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - /*-----------------------------------------------------------------*/ /* inExcludeList - return 1 if the string is in exclude Reg list */ /*-----------------------------------------------------------------*/ @@ -3394,6 +3414,7 @@ genFunction (iCode * ic) emitcode (";", "-----------------------------------------"); emitcode ("", "%s:", sym->rname); + lineCurr->isLabel = 1; ftype = operandType (IC_LEFT (ic)); _G.currentFunc = sym; @@ -4142,7 +4163,7 @@ genLabel (iCode * ic) D (emitcode (";", "genLabel")); - emitcode ("", "!tlabeldef", (IC_LABEL (ic)->key + 100)); + emitLabel (IC_LABEL (ic)); } /*-----------------------------------------------------------------*/ @@ -4206,7 +4227,7 @@ genPlusIncr (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; if (size == 1 && AOP(IC_LEFT(ic)) == AOP(IC_RESULT(ic)) && @@ -4662,7 +4683,7 @@ genPlus (iCode * ic) if ( AOP_IS_STR (IC_LEFT (ic)) && isOperandLiteral (IC_RIGHT (ic)) && OP_SYMBOL (IC_RESULT (ic))->ruonly) { aopOp (IC_RIGHT (ic), ic, TRUE, FALSE); - size = (int)floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); + size = (int) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); if (size <= 9) { while (size--) emitcode ("inc","dptr"); } else { @@ -4727,7 +4748,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)); } @@ -4867,7 +4888,7 @@ 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; if (size == 1 && AOP(IC_LEFT(ic)) == AOP(IC_RESULT(ic)) && @@ -5112,7 +5133,7 @@ genMinus (iCode * ic) } else { - lit = (long) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); + lit = (long) ulFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); lit = -lit; } @@ -5289,7 +5310,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; } @@ -5303,7 +5324,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; } @@ -5324,7 +5345,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,#!constbyte", -val); @@ -5350,7 +5371,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,#!constbyte", -val); @@ -5439,7 +5460,7 @@ static void genMultTwoByte (operand *left, operand *right, if (!umult) { emitcode("clr","F0"); if (AOP_TYPE(right) == AOP_LIT) { - int val=(int)floatFromVal (AOP (right)->aopu.aop_lit); + int val=(int) ulFromVal (AOP (right)->aopu.aop_lit); if (val < 0) { emitcode("setb","F0"); val = -val; @@ -5630,7 +5651,7 @@ genDivbits (operand * left, char *l; bool pushedB; - D(emitcode ("; genDivbits","")); + D(emitcode (";", "genDivbits")); pushedB = pushB (); @@ -5660,7 +5681,7 @@ genDivOneByte (operand * left, symbol *lbl; int size, offset; - D(emitcode ("; genDivOneByte","")); + D(emitcode (";", "genDivOneByte")); offset = 1; lUnsigned = SPEC_USIGN (getSpec (operandType (left))); @@ -5704,7 +5725,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; } @@ -5718,7 +5739,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; } @@ -5739,7 +5760,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); @@ -5765,7 +5786,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); @@ -5881,7 +5902,7 @@ static void genDivTwoByte (operand *left, operand *right, /* load up MB with right */ if (!umult) { if (AOP_TYPE(right) == AOP_LIT) { - int val=(int)floatFromVal (AOP (right)->aopu.aop_lit); + int val=(int) ulFromVal (AOP (right)->aopu.aop_lit); if (val < 0) { lbl = newiTempLabel(NULL); emitcode ("jbc","F0,!tlabel",lbl->key+100); @@ -6074,7 +6095,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) ulFromVal (AOP (right)->aopu.aop_lit); if (!rUnsigned && val < 0) emitcode ("mov", "b,#0x%02x", -val); @@ -6106,7 +6127,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) { @@ -6227,7 +6248,7 @@ static void genModTwoByte (operand *left, operand *right, /* load up MB with right */ if (!umult) { if (AOP_TYPE(right) == AOP_LIT) { - int val=(int)floatFromVal (AOP (right)->aopu.aop_lit); + int val=(int) ulFromVal (AOP (right)->aopu.aop_lit); if (val < 0) { val = -val; } @@ -6404,7 +6425,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) { @@ -6448,8 +6469,7 @@ genCmp (operand * left, operand * right, emitcode ("xrl", "a,#!constbyte",0x80); if (AOP_TYPE (right) == AOP_LIT) { - unsigned long lit = (unsigned long) - floatFromVal (AOP (right)->aopu.aop_lit); + unsigned long lit = ulFromVal (AOP (right)->aopu.aop_lit); // emitcode (";", "genCmp #3.1"); emitcode ("subb", "a,#!constbyte", 0x80 ^ (unsigned int) ((lit >> (offset * 8)) & 0x0FFL)); @@ -6585,7 +6605,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 (opIsGptr (left) || opIsGptr (right)) { @@ -6700,7 +6720,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); @@ -6771,7 +6791,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); @@ -7139,10 +7159,10 @@ genAnd (iCode * ic, iCode * ifx) } #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 @@ -7176,7 +7196,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); @@ -7574,10 +7594,10 @@ genOr (iCode * ic, iCode * ifx) #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 @@ -7611,7 +7631,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); @@ -7965,10 +7985,10 @@ genXor (iCode * ic, iCode * ifx) } #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 @@ -8003,7 +8023,7 @@ genXor (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); @@ -8295,40 +8315,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); } @@ -8476,7 +8507,7 @@ genSwap (iCode * ic) { operand *left, *result; - D(emitcode ("; genSwap","")); + D(emitcode (";", "genSwap")); left = IC_LEFT (ic); result = IC_RESULT (ic); @@ -9468,7 +9499,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; size = getSize (operandType (result)); @@ -9608,7 +9639,7 @@ genLeftShift (iCode * ic) * some small improvement. */ emitcode("mov", "b,#!constbyte", - ((int) floatFromVal (AOP (right)->aopu.aop_lit)) + 1); + ((int) ulFromVal (AOP (right)->aopu.aop_lit)) + 1); } else { @@ -9864,7 +9895,7 @@ genrshFour (operand * result, operand * left, _startLazyDPSEvaluation(); if (shCount == 1) { - shiftRLong (left, MSB16, result, sign); + shiftRLong (left, MSB16, result, sign); } else if (shCount == 0) { @@ -9912,7 +9943,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; size = getSize (operandType (result)); @@ -10033,7 +10064,7 @@ genSignedRightShift (iCode * ic) * some small improvement. */ emitcode("mov", "b,#!constbyte", - ((int) floatFromVal (AOP (right)->aopu.aop_lit)) + 1); + ((int) ulFromVal (AOP (right)->aopu.aop_lit)) + 1); } else { @@ -10181,7 +10212,7 @@ genRightShift (iCode * ic) * some small improvement. */ emitcode("mov", "b,#!constbyte", - ((int) floatFromVal (AOP (right)->aopu.aop_lit)) + 1); + ((int) ulFromVal (AOP (right)->aopu.aop_lit)) + 1); } else { @@ -10360,7 +10391,7 @@ genUnpackBits (operand * result, char *rname, int ptype) int blen; /* bitfield length */ int bstr; /* bitfield starting bit within byte */ - D(emitcode ("; genUnpackBits","")); + D(emitcode (";", "genUnpackBits")); etype = getSpec (operandType (result)); rsize = getSize (operandType (result)); @@ -10902,7 +10933,8 @@ genCodePointerGet (operand * left, _endLazyDPSEvaluation (); } pi->generated = 1; - } else if ((OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) && + } else if (IS_SYMOP(left) && + (OP_SYMBOL(left)->ruonly || AOP_INDPTRn(left)) && AOP_SIZE(result) > 1 && (OP_SYMBOL (left)->liveTo > ic->seq || ic->depth)) { @@ -10993,8 +11025,8 @@ genGenPointerGet (operand * left, // with the implementation of __gptrgetWord // in device/lib/_gptrget.c emitcode ("lcall", "__gptrgetWord"); - aopPut (result, DP2_RESULT_REG, offset++); aopPut (result, "a", offset++); + aopPut (result, DP2_RESULT_REG, offset++); size--; } else @@ -11116,7 +11148,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); @@ -11131,7 +11163,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); @@ -11202,7 +11234,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); @@ -11576,7 +11608,8 @@ genFarPointerSet (operand * right, _endLazyDPSEvaluation (); } pi->generated=1; - } else if ((OP_SYMBOL(result)->ruonly || AOP_INDPTRn(result)) && + } else if (IS_SYMOP (result) && + (OP_SYMBOL(result)->ruonly || AOP_INDPTRn(result)) && AOP_SIZE(right) > 1 && (OP_SYMBOL (result)->liveTo > ic->seq || ic->depth)) { @@ -12240,7 +12273,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) && @@ -12608,7 +12641,7 @@ static void genMemcpyX2X( iCode *ic, int nparms, operand **parms, int fromc) /* now for the actual copy */ if (AOP_TYPE(count) == AOP_LIT && - (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) { + (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) { emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL)); if (fromc) { emitcode ("lcall","__bi_memcpyc2x_s"); @@ -12624,7 +12657,7 @@ static void genMemcpyX2X( iCode *ic, int nparms, operand **parms, int fromc) emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL)); freeAsmop (count, NULL, ic, FALSE); emitcode ("mov", "dps,#!constbyte",0x21); /* Select DPTR2 & auto-toggle. */ - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); if (fromc) { emitcode ("clr","a"); emitcode ("movc", "a,@a+dptr"); @@ -12643,7 +12676,7 @@ static void genMemcpyX2X( iCode *ic, int nparms, operand **parms, int fromc) emitcode ("addc","a,#!constbyte",0xFF); emitcode ("mov","b,a"); emitcode ("sjmp","!tlabel",lbl->key+100); - emitcode ("","!tlabeldef",lbl1->key+100); + emitLabel (lbl1); } emitcode ("mov", "dps,#0"); _G.dptrInUse = _G.dptr1InUse = 0; @@ -12724,7 +12757,7 @@ static void genMemcmpX2X( iCode *ic, int nparms, operand **parms, int fromc) /* now for the actual compare */ if (AOP_TYPE(count) == AOP_LIT && - (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) { + (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) { emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL)); if (fromc) emitcode("lcall","__bi_memcmpc2x_s"); @@ -12743,7 +12776,7 @@ static void genMemcmpX2X( iCode *ic, int nparms, operand **parms, int fromc) emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL)); freeAsmop (count, NULL, ic, FALSE); emitcode ("mov", "dps,#!constbyte",0x21); /* Select DPTR2 & auto-toggle. */ - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); if (fromc) { emitcode ("clr","a"); emitcode ("movc", "a,@a+dptr"); @@ -12766,9 +12799,9 @@ static void genMemcmpX2X( iCode *ic, int nparms, operand **parms, int fromc) emitcode ("addc","a,#!constbyte",0xFF); emitcode ("mov","b,a"); emitcode ("sjmp","!tlabel",lbl->key+100); - emitcode ("","!tlabeldef",lbl1->key+100); + emitLabel (lbl1); emitcode ("clr","a"); - emitcode ("","!tlabeldef",lbl2->key+100); + emitLabel (lbl2); aopOp (IC_RESULT(ic), ic, FALSE,FALSE); aopPut(IC_RESULT(ic),"a",0); freeAsmop (IC_RESULT(ic), NULL, ic, FALSE); @@ -12855,12 +12888,12 @@ static void genInp( iCode *ic, int nparms, operand **parms) /* now for the actual copy */ if (AOP_TYPE(count) == AOP_LIT && - (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) { + (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) { emitcode (";","OH JOY auto increment with djnz (very fast)"); emitcode ("mov", "dps,#!constbyte",0x1); /* Select DPTR2 */ emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL)); freeAsmop (count, NULL, ic, FALSE); - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); emitcode ("movx", "a,@dptr"); /* read data from port */ emitcode ("dec","dps"); /* switch to DPTR */ emitcode ("movx", "@dptr,a"); /* save into location */ @@ -12875,7 +12908,7 @@ static void genInp( iCode *ic, int nparms, operand **parms) emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL)); freeAsmop (count, NULL, ic, FALSE); emitcode ("mov", "dps,#!constbyte",0x1); /* Select DPTR2 */ - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); emitcode ("movx", "a,@dptr"); emitcode ("dec","dps"); /* switch to DPTR */ emitcode ("movx", "@dptr,a"); @@ -12893,7 +12926,7 @@ static void genInp( iCode *ic, int nparms, operand **parms) emitcode ("addc","a,#!constbyte",0xFF); emitcode ("mov","b,a"); emitcode ("sjmp","!tlabel",lbl->key+100); - emitcode ("","!tlabeldef",lbl1->key+100); + emitLabel (lbl1); } emitcode ("mov", "dps,#0"); _G.dptrInUse = _G.dptr1InUse = 0; @@ -12976,11 +13009,11 @@ static void genOutp( iCode *ic, int nparms, operand **parms) /* now for the actual copy */ if (AOP_TYPE(count) == AOP_LIT && - (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) { + (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) { emitcode (";","OH JOY auto increment with djnz (very fast)"); emitcode ("mov", "dps,#!constbyte",0x0); /* Select DPTR */ emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL)); - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); emitcode ("movx", "a,@dptr"); /* read data from port */ emitcode ("inc","dps"); /* switch to DPTR2 */ emitcode ("movx", "@dptr,a"); /* save into location */ @@ -12996,7 +13029,7 @@ static void genOutp( iCode *ic, int nparms, operand **parms) emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL)); freeAsmop (count, NULL, ic, FALSE); emitcode ("mov", "dps,#!constbyte",0x0); /* Select DPTR */ - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); emitcode ("movx", "a,@dptr"); emitcode ("inc", "dptr"); emitcode ("inc","dps"); /* switch to DPTR2 */ @@ -13012,7 +13045,7 @@ static void genOutp( iCode *ic, int nparms, operand **parms) emitcode ("addc","a,#!constbyte",0xFF); emitcode ("mov","b,a"); emitcode ("sjmp","!tlabel",lbl->key+100); - emitcode ("","!tlabeldef",lbl1->key+100); + emitLabel (lbl1); } emitcode ("mov", "dps,#0"); _G.dptrInUse = _G.dptr1InUse = 0; @@ -13110,11 +13143,11 @@ static void genMemsetX(iCode *ic, int nparms, operand **parms) lbl =newiTempLabel(NULL); /* now for the actual copy */ if (AOP_TYPE(count) == AOP_LIT && - (int)floatFromVal (AOP(count)->aopu.aop_lit) <= 256) { + (int) ulFromVal (AOP(count)->aopu.aop_lit) <= 256) { l = aopGet(val, 0, FALSE, FALSE, NULL); emitcode ("mov", "b,%s",aopGet(count,0,FALSE,FALSE,NULL)); MOVA(l); - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); emitcode ("movx", "@dptr,a"); emitcode ("inc", "dptr"); emitcode ("djnz","b,!tlabel",lbl->key+100); @@ -13123,7 +13156,7 @@ static void genMemsetX(iCode *ic, int nparms, operand **parms) emitcode ("mov","_ap,%s",aopGet (count, 0, FALSE, TRUE, NULL)); emitcode ("mov","b,%s",aopGet (count, 1, FALSE, TRUE, NULL)); - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); MOVA (aopGet(val, 0, FALSE, FALSE, NULL)); emitcode ("movx", "@dptr,a"); emitcode ("inc", "dptr"); @@ -13137,7 +13170,7 @@ static void genMemsetX(iCode *ic, int nparms, operand **parms) emitcode ("addc","a,#!constbyte",0xFF); emitcode ("mov","b,a"); emitcode ("sjmp","!tlabel",lbl->key+100); - emitcode ("","!tlabeldef",lbl1->key+100); + emitLabel (lbl1); } freeAsmop (count, NULL, ic, FALSE); unsavermask(rsave); @@ -13323,7 +13356,7 @@ static void genNatLibGetStateBlock(iCode *ic,int nparms, aopPut(IC_RESULT(ic),"r3",1); } freeAsmop (IC_RESULT(ic), NULL, ic, FALSE); - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); unsavermask(rsave); } @@ -13370,7 +13403,7 @@ static void genMMMalloc (iCode *ic,int nparms, operand **parms, emitcode ("jz","!tlabel",lbl->key+100); emitcode ("mov","r2,#!constbyte",0xff); emitcode ("mov","r3,#!constbyte",0xff); - emitcode ("","!tlabeldef",lbl->key+100); + emitLabel (lbl); /* we don't care about the pointer : we just save the handle */ rsym = OP_SYMBOL(IC_RESULT(ic)); if (rsym->liveFrom != rsym->liveTo) { @@ -14030,7 +14063,7 @@ genCritical (iCode *ic) static void genEndCritical (iCode *ic) { - D(emitcode("; genEndCritical","")); + D(emitcode(";", "genEndCritical")); if (IC_RIGHT (ic)) { @@ -14193,7 +14226,7 @@ gen390Code (iCode * lic) #if 1 /* print the allocation information */ if (allocInfo && currFunc) - printAllocInfo (currFunc, codeOutFile); + printAllocInfo (currFunc, codeOutBuf); #endif /* if debug information required */ if (options.debug && currFunc) @@ -14218,13 +14251,15 @@ gen390Code (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; } if (options.iCodeInAsm) { - emitcode("", ";ic:%d: %s", ic->key, printILine(ic)); + const char *iLine = printILine(ic); + emitcode(";", "ic:%d: %s", ic->key, iLine); + dbuf_free(iLine); } /* if the result is marked as spilt and rematerializable or code for @@ -14447,7 +14482,10 @@ gen390Code (iCode * lic) #endif default: - ic = ic; + /* This should never happen, right? */ + fprintf(stderr, "*** Probable error: unsupported op 0x%x (%c) in %s @ %d\n", + ic->op, ic->op, __FILE__, __LINE__); + ic = ic; } } @@ -14458,6 +14496,6 @@ gen390Code (iCode * lic) peepHole (&lineHead); /* now do the actual printing */ - printLine (lineHead, codeOutFile); + printLine (lineHead, codeOutBuf); return; }