* support/regression/tests/bug1185672.c: added
authormaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 26 Apr 2005 10:14:27 +0000 (10:14 +0000)
committermaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 26 Apr 2005 10:14:27 +0000 (10:14 +0000)
* src/mcs51/gen.c (aopGetUsesAcc, genCpl, genAnd, genOr, genXor): fixed
  bug 1185672
* src/mcs51/gen.c (genCall): added comments, made it look safer
* src/mcs51/gen.c (genEndFunction): simplified

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3742 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/mcs51/gen.c
support/regression/tests/bug1185672.c [new file with mode: 0644]

index 86e94a24c0731db32dc6fa62ee22d590d6dce06d..efb8523b0636bdb0c299999b1a3c2b572124d339 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2005-04-26 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * support/regression/tests/bug1185672.c: added
+       * src/mcs51/gen.c (aopGetUsesAcc, genCpl, genAnd, genOr, genXor): fixed
+         bug 1185672
+       * src/mcs51/gen.c (genCall): added comments, made it look safer
+       * src/mcs51/gen.c (genEndFunction): simplified
+
 2005-04-25 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * src/mcs51/ralloc.c (serialRegAssign): fixed bug 1189609
index 2a20db2bd9a4010b44860e8817f2379101b85e77..e7e31c824ae56e1c3af628e5202afc105f9d7436 100644 (file)
@@ -1107,6 +1107,8 @@ aopGetUsesAcc (asmop *aop, int offset)
     case AOP_CRY:
       return TRUE;
     case AOP_ACC:
+      if (offset)
+        return FALSE;
       return TRUE;
     case AOP_LIT:
       return FALSE;
@@ -1724,7 +1726,7 @@ genCpl (iCode * ic)
 
       tlbl=newiTempLabel(NULL);
       l = aopGet (AOP (IC_LEFT (ic)), offset++, FALSE, FALSE);
-      if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC ||
+      if ((AOP_TYPE (IC_LEFT (ic)) == AOP_ACC && offset == 0) ||
           AOP_TYPE (IC_LEFT (ic)) == AOP_REG ||
           IS_AOP_PREG (IC_LEFT (ic)))
         {
@@ -2446,8 +2448,7 @@ genCall (iCode * ic)
       freeAsmop (IC_RESULT (ic), NULL, ic, TRUE);
     }
 
-  /* adjust the stack for parameters if
-     required */
+  /* adjust the stack for parameters if required */
   if (ic->parmBytes)
     {
       int i;
@@ -2458,9 +2459,18 @@ genCall (iCode * ic)
               emitcode ("push", "acc");
               accPushed = TRUE;
             }
+
           emitcode ("mov", "a,%s", spname);
           emitcode ("add", "a,#0x%02x", (-ic->parmBytes) & 0xff);
           emitcode ("mov", "%s,a", spname);
+
+          /* unsaveRegisters from xstack needs acc, but */
+          /* unsaveRegisters from stack needs this popped */
+          if (accPushed && !options.useXstack)
+            {
+              emitcode ("pop", "acc");
+              accPushed = FALSE;
+            }
         }
       else
         for (i = 0; i < ic->parmBytes; i++)
@@ -2472,6 +2482,7 @@ genCall (iCode * ic)
     {
       if (accuse && !accPushed && options.useXstack)
         {
+          /* xstack needs acc, but doesn't touch normal stack */
           emitcode ("push", "acc");
           accPushed = TRUE;
         }
@@ -3075,15 +3086,13 @@ genEndFunction (iCode * ic)
       emitcode ("mov", "ea,c");
     }
 
-  if ((IFFUNC_ISREENT (sym->type) || options.stackAuto))// && !options.useXstack)
-    {
-      emitcode ("mov", "sp,_bp");
-    }
   if ((IFFUNC_ISREENT (sym->type) || options.stackAuto))
     {
+      emitcode ("mov", "sp,_bp");
+      emitcode ("pop", "_bp");
+
       if (options.useXstack)
         {
-          emitcode ("pop", "_bp");
           emitcode ("xch", "a,_bpx");
           emitcode ("mov", "r0,a");
           emitcode ("dec", "r0");
@@ -3091,10 +3100,6 @@ genEndFunction (iCode * ic)
           emitcode ("xch", "a,_bpx");
           emitcode ("mov", "%s,r0", spname); //read before freeing stack space (interrupts)
         }
-      else
-        {
-          emitcode ("pop", "_bp");
-        }
     }
 
   /* restore the register bank  */
@@ -5915,8 +5920,10 @@ genAnd (iCode * ic, iCode * ifx)
             }
           else
             {
-              if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+              if (AOP_TYPE (left) == AOP_ACC && offset == 0)
+                {
+                  emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                }
               else
                 {
                   MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
@@ -5946,17 +5953,30 @@ genAnd (iCode * ic, iCode * ifx)
             emitcode ("setb", "c");
           while (sizer--)
             {
-              if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
-                emitcode ("anl", "a,%s",
-                          aopGet (AOP (right), offset, FALSE, FALSE));
-              } else {
-                if (AOP_TYPE(left)==AOP_ACC) {
-                  bool pushedB = pushB ();
-                  emitcode("mov", "b,a");
-                  MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
-                  emitcode("anl", "a,b");
-                  popB (pushedB);
-                }else {
+              if ((AOP_TYPE(right)==AOP_REG  || IS_AOP_PREG(right) || AOP_TYPE(right)==AOP_DIR)
+                  && AOP_TYPE(left)==AOP_ACC)
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("anl", "a,%s",
+                            aopGet (AOP (right), offset, FALSE, FALSE));
+                } else {
+                  if (AOP_TYPE(left)==AOP_ACC)
+                    {
+                      if (!offset)
+                        {
+                          bool pushedB = pushB ();
+                          emitcode("mov", "b,a");
+                          MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+                          emitcode("anl", "a,b");
+                          popB (pushedB);
+                        }
+                      else
+                        {
+                          MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
+                          emitcode("anl", "a,b");
+                        }
+                } else {
                   MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
                   emitcode ("anl", "a,%s",
                             aopGet (AOP (left), offset, FALSE, FALSE));
@@ -6001,11 +6021,30 @@ genAnd (iCode * ic, iCode * ifx)
                       aopPut (AOP (result), zero, offset, isOperandVolatile (result, FALSE));
                       continue;
                     }
+                  else if (AOP_TYPE (left) == AOP_ACC)
+                    {
+                      if (!offset)
+                        {
+                          emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                          aopPut (AOP (result), "a", offset, isOperandVolatile (result, FALSE));
+                          continue;
+                        }
+                      else
+                        {
+                          emitcode ("anl", "b,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                          aopPut (AOP (result), "b", offset, isOperandVolatile (result, FALSE));
+                          continue;
+                        }
+                    }
                 }
               // faster than result <- left, anl result,right
               // and better if result is SFR
               if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("anl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                }
               else
                 {
                   MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
@@ -6221,7 +6260,11 @@ genOr (iCode * ic, iCode * ifx)
           else
             {
               if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                }
               else
                 {
                   MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
@@ -6254,6 +6297,8 @@ genOr (iCode * ic, iCode * ifx)
           while (sizer--)
             {
               if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
+                if (offset)
+                  emitcode("mov", "a,b");
                 emitcode ("orl", "a,%s",
                           aopGet (AOP (right), offset, FALSE, FALSE));
               } else {
@@ -6304,7 +6349,11 @@ genOr (iCode * ic, iCode * ifx)
               // faster than result <- left, anl result,right
               // and better if result is SFR
               if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("orl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                }
               else
                 {
                   MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
@@ -6499,7 +6548,11 @@ genXor (iCode * ic, iCode * ifx)
           else
             {
               if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                }
               else
                 {
                   MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
@@ -6537,6 +6590,8 @@ genXor (iCode * ic, iCode * ifx)
               else
                 {
                   if (AOP_TYPE(right)==AOP_REG && AOP_TYPE(left)==AOP_ACC) {
+                    if (offset)
+                      emitcode("mov", "a,b");
                     emitcode ("xrl", "a,%s",
                               aopGet (AOP (right), offset, FALSE, FALSE));
                   } else {
@@ -6578,7 +6633,11 @@ genXor (iCode * ic, iCode * ifx)
               // faster than result <- left, anl result,right
               // and better if result is SFR
               if (AOP_TYPE (left) == AOP_ACC)
-                emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                {
+                  if (offset)
+                    emitcode("mov", "a,b");
+                  emitcode ("xrl", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE));
+                }
               else
                 {
                   MOVA (aopGet (AOP (right), offset, FALSE, FALSE));
diff --git a/support/regression/tests/bug1185672.c b/support/regression/tests/bug1185672.c
new file mode 100644 (file)
index 0000000..7d0bfb2
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+   bug1057979.c
+*/
+
+#include <testfwk.h>
+
+int srlen;
+
+int l_regrd(int ad)
+{
+  return ad;
+}
+
+void head_send(int i)
+{
+  srlen= i;
+  if ((l_regrd(0x1234) & 0x0200) == 0)
+  {
+    srlen= 0;
+  }
+}
+
+void
+test_1185672(void)
+{
+  head_send(1);
+  ASSERT( srlen == 1 );
+}