* src/SDCCasm.[ch]: renamed from asm[ch], use dbuf_getline(), ...
[fw/sdcc] / src / ds390 / gen.c
index 5e0e63d824ed7f5d42110ed183d8444fb035be09..d8ff7c5134fda48e6110705b4d27511bc5de1802 100644 (file)
@@ -26,7 +26,7 @@
 -------------------------------------------------------------------------*/
 
 //#define D(x)
-#define D(x) x
+#define D(x) do if (options.verboseAsm) {x;} while(0)
 
 #include <stdio.h>
 #include <stdlib.h>
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #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;
 }
 
 /*-----------------------------------------------------------------*/
@@ -3349,12 +3356,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   */
 /*-----------------------------------------------------------------*/
@@ -3396,6 +3397,7 @@ genFunction (iCode * ic)
   emitcode (";", "-----------------------------------------");
 
   emitcode ("", "%s:", sym->rname);
+  lineCurr->isLabel = 1;
   ftype = operandType (IC_LEFT (ic));
   _G.currentFunc = sym;
 
@@ -4144,7 +4146,7 @@ genLabel (iCode * ic)
 
   D (emitcode (";", "genLabel"));
 
-  emitcode ("", "!tlabeldef", (IC_LABEL (ic)->key + 100));
+  emitLabel (IC_LABEL (ic));
 }
 
 /*-----------------------------------------------------------------*/
@@ -4208,7 +4210,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)) &&
@@ -4664,7 +4666,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 {
@@ -4729,7 +4731,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));
             }
@@ -4869,7 +4871,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)) &&
@@ -5114,7 +5116,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;
     }
 
@@ -5291,7 +5293,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;
         }
@@ -5305,7 +5307,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;
         }
@@ -5326,7 +5328,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);
@@ -5352,7 +5354,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);
@@ -5441,7 +5443,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;
@@ -5632,7 +5634,7 @@ genDivbits (operand * left,
   char *l;
   bool pushedB;
 
-  D(emitcode (";     genDivbits",""));
+  D(emitcode (";", "genDivbits"));
 
   pushedB = pushB ();
 
@@ -5662,7 +5664,7 @@ genDivOneByte (operand * left,
   symbol *lbl;
   int size, offset;
 
-  D(emitcode (";     genDivOneByte",""));
+  D(emitcode (";", "genDivOneByte"));
 
   offset = 1;
   lUnsigned = SPEC_USIGN (getSpec (operandType (left)));
@@ -5706,7 +5708,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;
         }
@@ -5720,7 +5722,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;
         }
@@ -5741,7 +5743,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);
@@ -5767,7 +5769,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);
@@ -5883,7 +5885,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);
@@ -6076,7 +6078,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);
@@ -6108,7 +6110,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)
         {
@@ -6229,7 +6231,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;
                         }
@@ -6406,7 +6408,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)
                 {
@@ -6450,8 +6452,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));
@@ -6587,7 +6588,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))
     {
@@ -6702,7 +6703,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);
@@ -6773,7 +6774,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);
@@ -7141,10 +7142,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
@@ -7178,7 +7179,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);
 
@@ -7576,10 +7577,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
@@ -7613,7 +7614,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);
 
@@ -7967,10 +7968,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
@@ -8005,7 +8006,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);
 
@@ -8297,40 +8298,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);
 }
 
@@ -8478,7 +8490,7 @@ genSwap (iCode * ic)
 {
   operand *left, *result;
 
-  D(emitcode (";     genSwap",""));
+  D(emitcode (";", "genSwap"));
 
   left = IC_LEFT (ic);
   result = IC_RESULT (ic);
@@ -9470,7 +9482,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));
@@ -9610,7 +9622,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
   {
@@ -9866,7 +9878,7 @@ genrshFour (operand * result, operand * left,
       _startLazyDPSEvaluation();
       if (shCount == 1)
         {
-            shiftRLong (left, MSB16, result, sign);
+          shiftRLong (left, MSB16, result, sign);
         }
       else if (shCount == 0)
         {
@@ -9914,7 +9926,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));
@@ -10035,7 +10047,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
   {
@@ -10183,7 +10195,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
   {
@@ -10362,7 +10374,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));
@@ -10904,7 +10916,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)) {
 
@@ -10995,8 +11008,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
@@ -11118,7 +11131,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);
@@ -11133,7 +11146,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);
@@ -11204,7 +11217,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);
@@ -11578,7 +11591,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)) {
 
@@ -12242,7 +12256,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) &&
@@ -12610,7 +12624,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");
@@ -12626,7 +12640,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");
@@ -12645,7 +12659,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;
@@ -12726,7 +12740,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");
@@ -12745,7 +12759,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");
@@ -12768,9 +12782,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);
@@ -12857,12 +12871,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 */
@@ -12877,7 +12891,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");
@@ -12895,7 +12909,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;
@@ -12978,11 +12992,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 */
@@ -12998,7 +13012,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 */
@@ -13014,7 +13028,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;
@@ -13112,11 +13126,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);
@@ -13125,7 +13139,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");
@@ -13139,7 +13153,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);
@@ -13325,7 +13339,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);
 }
 
@@ -13372,7 +13386,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) {
@@ -14032,7 +14046,7 @@ genCritical (iCode *ic)
 static void
 genEndCritical (iCode *ic)
 {
-  D(emitcode(";     genEndCritical",""));
+  D(emitcode(";", "genEndCritical"));
 
   if (IC_RIGHT (ic))
     {
@@ -14195,7 +14209,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)
@@ -14220,13 +14234,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
@@ -14449,7 +14465,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;
         }
     }
 
@@ -14460,6 +14479,6 @@ gen390Code (iCode * lic)
     peepHole (&lineHead);
 
   /* now do the actual printing */
-  printLine (lineHead, codeOutFile);
+  printLine (lineHead, codeOutBuf);
   return;
 }