applied inc/dec patch for variables in data space. Mentioned on sdcc-devel 2003-03-01
[fw/sdcc] / src / mcs51 / gen.c
index 0daad8e21d17fdcabd22d9efc3be83d2f62380c6..98b095848c76665b5e2f53d21b7ea572de468d53 100644 (file)
 #include "SDCCglobl.h"
 #include "newalloc.h"
 
-#ifdef HAVE_SYS_ISA_DEFS_H
-#include <sys/isa_defs.h>
-#else
-#ifdef HAVE_MACHINE_ENDIAN_H
-#include <machine/endian.h>
-#else
-#ifdef HAVE_ENDIAN_H
-#include <endian.h>
-#else
-#if !defined(__BORLANDC__) && !defined(_MSC_VER) && !defined(__MINGW32__) && !defined(__CYGWIN__)
-#warning "Cannot determine ENDIANESS of this machine assuming LITTLE_ENDIAN"
-#warning "If you running sdcc on an INTEL 80x86 Platform you are okay"
-#endif
-#endif
-#endif
-#endif
-
 #include "common.h"
 #include "SDCCpeeph.h"
 #include "ralloc.h"
@@ -1444,15 +1427,9 @@ genUminusFloat (operand * op, operand * result)
 
   D(emitcode (";     genUminusFloat",""));
 
-  /* for this we just need to flip the
-     first it then copy the rest in place */
-  size = AOP_SIZE (op) - 1;
-  l = aopGet (AOP (op), 3, FALSE, FALSE);
-
-  MOVA (l);
+  /* for this we just copy and then flip the bit */
 
-  emitcode ("cpl", "acc.7");
-  aopPut (AOP (result), "a", 3);
+  size = AOP_SIZE (op) - 1;
 
   while (size--)
     {
@@ -1461,6 +1438,13 @@ genUminusFloat (operand * op, operand * result)
              offset);
       offset++;
     }
+
+  l = aopGet (AOP (op), offset, FALSE, FALSE);
+
+  MOVA (l);
+
+  emitcode ("cpl", "acc.7");
+  aopPut (AOP (result), "a", offset);
 }
 
 /*-----------------------------------------------------------------*/
@@ -2888,8 +2872,8 @@ genPlusIncr (iCode * ic)
 
   D(emitcode (";     genPlusIncr",""));
 
-  /* if increment 16 bits in register */
-  if (AOP_TYPE(IC_LEFT(ic)) == AOP_REG &&
+  /* if increment >=16 bits in register or direct space */
+  if ((AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR ) &&
       sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) && 
       (size > 1) &&
       (icount == 1))
@@ -3248,8 +3232,8 @@ genMinusDec (iCode * ic)
 
   D(emitcode (";     genMinusDec",""));
 
-  /* if decrement 16 bits in register */
-  if (AOP_TYPE(IC_LEFT(ic)) == AOP_REG &&
+  /* if decrement >=16 bits in register or direct space */
+  if ((AOP_TYPE(IC_LEFT(ic)) == AOP_REG || AOP_TYPE(IC_LEFT(ic)) == AOP_DIR) &&
       sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic))) &&
       (size > 1) &&
       (icount == 1))
@@ -3467,9 +3451,7 @@ genMinus (iCode * ic)
          if (aopGetUsesAcc(rightOp, offset)) {
            wassertl(!aopGetUsesAcc(leftOp, offset), "accumulator clash");
            MOVA (aopGet(rightOp, offset, FALSE, TRUE));
-           if (offset > 0) {
-             emitcode( "cpl", "c");
-           } else {
+           if (offset == 0) {
              emitcode( "setb", "c");
            }
            emitcode("subb", "a,%s", aopGet(leftOp, offset, FALSE, TRUE));
@@ -6519,7 +6501,7 @@ genLeftShift (iCode * ic)
   char *l;
   symbol *tlbl, *tlbl1;
 
-  D(emitcode (";    genLeftShift",""));
+  D(emitcode (";     genLeftShift",""));
 
   right = IC_RIGHT (ic);
   left = IC_LEFT (ic);
@@ -6826,9 +6808,10 @@ genRightShiftLiteral (operand * left,
 
   else if (shCount >= (size * 8))
     {
-      if (sign)
+      if (sign) {
        /* get sign in acc.7 */
        MOVA (aopGet (AOP (left), size - 1, FALSE, FALSE));
+      }
       addSign (result, LSB, sign);
     }
   else
@@ -6849,10 +6832,9 @@ genRightShiftLiteral (operand * left,
        default:
          break;
        }
-
-      freeAsmop (left, NULL, ic, TRUE);
-      freeAsmop (result, NULL, ic, TRUE);
     }
+  freeAsmop (left, NULL, ic, TRUE);
+  freeAsmop (result, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -8449,8 +8431,9 @@ genAssign (iCode * ic)
   right = IC_RIGHT (ic);
 
   /* if they are the same */
-  if (operandsEqu (IC_RESULT (ic), IC_RIGHT (ic)))
+  if (operandsEqu (result, right)) {
     return;
+  }
 
   aopOp (right, ic, FALSE);
 
@@ -8919,10 +8902,15 @@ gen51Code (iCode * lic)
                        ic->level, ic->block);
              _G.debugLine = 0;
            }
-         emitcode ("", "; %s:%d: %s", ic->filename, ic->lineno, 
-                   printCLine(ic->filename, ic->lineno));
+         if (!options.noCcodeInAsm) {
+           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));
+      }
       /* if the result is marked as
          spilt and rematerializable or code for
          this has already been generated then