* src/ds390/gen.c (genCall): fixed a double use of acc and b after
[fw/sdcc] / src / ds390 / gen.c
index 8a55bcd48a28acfc369a97e779ea3a537a78e460..979d993e9373525f442027e43f4c535d761dc278 100644 (file)
@@ -516,7 +516,13 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
 
   /* if already has one */
   if (sym->aop)
-    return sym->aop;
+    {
+      if ((sym->aop->type == AOP_DPTR && useDP2)
+          || (sym->aop->type == AOP_DPTR2 && !useDP2))
+       sym->aop = NULL;
+      else
+        return sym->aop;
+    }
 
   /* assign depending on the storage class */
   /* if it is on the stack or indirectly addressable */
@@ -862,6 +868,14 @@ operandsEqu (operand * op1, operand * op2)
       (sym2->usl.spillLoc == sym1))
     return TRUE;
 
+  /* are they spilt to the same location */
+  if (IS_ITEMP (op2) &&
+      IS_ITEMP (op1) &&
+      sym2->isspilt &&
+      sym1->isspilt &&
+      (sym1->usl.spillLoc == sym2->usl.spillLoc))
+    return TRUE;
+    
   return FALSE;
 }
 
@@ -921,13 +935,23 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2)
 
   /* if already has a asmop then continue */
   if (op->aop)
-    return;
+    {
+      if ((op->aop->type == AOP_DPTR && useDP2)
+          || (op->aop->type == AOP_DPTR2 && !useDP2))
+       op->aop = NULL;
+      else
+        return;
+    }
 
   /* if the underlying symbol has a aop */
   if (IS_SYMOP (op) && OP_SYMBOL (op)->aop)
     {
       op->aop = OP_SYMBOL (op)->aop;
-      return;
+      if ((op->aop->type == AOP_DPTR && useDP2)
+          || (op->aop->type == AOP_DPTR2 && !useDP2))
+       op->aop = NULL;
+      else
+        return;
     }
 
   /* if this is a true symbol */
@@ -2651,9 +2675,16 @@ genCall (iCode * ic)
          if (size > 1)
            {
              emitcode ("mov", "b,%s", fReturn[1]);
+             _G.bInUse++;
            }
 
+         _G.accInUse++;
          aopOp (IC_RESULT (ic), ic, FALSE, FALSE);
+         _G.accInUse--;
+         
+         if (size > 1)
+           _G.bInUse--;
+
          aopPut (AOP (IC_RESULT (ic)), "a", 0);
 
          if (size > 1)
@@ -3919,7 +3950,8 @@ bool aopOp3(iCode * ic)
     }
 
     aopOp(IC_LEFT(ic), ic, FALSE, useDp2);
-    
+
+        
     // We've op'd the left & right. So, if left or right are the same operand as result, 
     // we know aopOp will succeed, and we can just do it & bail.
     if (isOperandEqual(IC_LEFT(ic),IC_RESULT(ic)) ||
@@ -3930,6 +3962,19 @@ bool aopOp3(iCode * ic)
        return TRUE;
     }
     
+    // Operands may be equivalent (but not equal) if they share a spill location. If
+    // so, use the same DPTR or DPTR2.
+    if (operandsEqu (IC_LEFT(ic), IC_RESULT(ic)))
+      {
+        aopOp (IC_RESULT (ic), ic, TRUE, AOP_USESDPTR2 (IC_LEFT (ic)));
+       return TRUE;
+      }
+    if (operandsEqu (IC_RIGHT(ic), IC_RESULT(ic)))
+      {
+        aopOp (IC_RESULT (ic), ic, TRUE, AOP_USESDPTR2 (IC_RIGHT (ic)));
+       return TRUE;
+      }
+    
     // Note which dptrs are currently in use.
     dp1InUse = AOP_USESDPTR(IC_LEFT(ic)) || AOP_USESDPTR(IC_RIGHT(ic));
     dp2InUse = AOP_USESDPTR2(IC_LEFT(ic)) || AOP_USESDPTR2(IC_RIGHT(ic));
@@ -6387,6 +6432,8 @@ genAnd (iCode * ic, iCode * ifx)
            {
              if (ifx)
                jmpTrueOrFalse (ifx, tlbl);
+              else
+               emitcode ("", "!tlabeldef", tlbl->key + 100);
              goto release;
            }
        }
@@ -6477,6 +6524,8 @@ genAnd (iCode * ic, iCode * ifx)
            }
          else if (ifx)
            jmpTrueOrFalse (ifx, tlbl);
+          else
+           emitcode ("", "!tlabeldef", tlbl->key + 100);
        }
       else
        {
@@ -6795,6 +6844,8 @@ genOr (iCode * ic, iCode * ifx)
            }
          else if (ifx)
            jmpTrueOrFalse (ifx, tlbl);
+          else
+           emitcode ("", "!tlabeldef", tlbl->key + 100);
        }
       else
        {
@@ -8749,7 +8800,7 @@ genRightShiftLiteral (operand * left,
    && (size != 2)
    && (size != 4))
   {
-      D(emitcode (";", "genRightShiftLiteral wimping out"););  
+      D(emitcode (";", "genRightShiftLiteral wimping out"););
       return FALSE;
   }
 
@@ -8943,7 +8994,7 @@ static void
 genRightShift (iCode * ic)
 {
   operand *right, *left, *result;
-  sym_link *retype;
+  sym_link *letype;
   int size, offset;
   char *l;
   symbol *tlbl, *tlbl1;
@@ -8952,9 +9003,9 @@ genRightShift (iCode * ic)
 
   /* if signed then we do it the hard way preserve the
      sign bit moving it inwards */
-  retype = getSpec (operandType (IC_RESULT (ic)));
+  letype = getSpec (operandType (IC_LEFT (ic)));
 
-  if (!SPEC_USIGN (retype))
+  if (!SPEC_USIGN (letype))
     {
       genSignedRightShift (ic);
       return;
@@ -12708,34 +12759,59 @@ static void genSystemGetCurrentID(iCode *ic,int nparms, operand **parms,char *na
 static void
 genDummyRead (iCode * ic)
 {
-  operand *right;
+  operand *op;
   int size, offset;
 
   D(emitcode(";     genDummyRead",""));
 
-  right = IC_RIGHT (ic);
+  op = IC_RIGHT (ic);
+  if (op && IS_SYMOP (op))
+    {
+      aopOp (op, ic, FALSE, FALSE);
 
-  aopOp (right, ic, FALSE, FALSE);
+      /* if the result is a bit */
+      if (AOP_TYPE (op) == AOP_CRY)
+        emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+      else
+       {
+         /* bit variables done */
+         /* general case */
+         size = AOP_SIZE (op);
+         offset = 0;
+         while (size--)
+         {
+           MOVA (aopGet (AOP (op), offset, FALSE, FALSE, FALSE));
+           offset++;
+         }
+       }
 
-  /* if the result is a bit */
-  if (AOP_TYPE (right) == AOP_CRY)
-    {
-      emitcode ("mov", "c,%s", AOP (right)->aopu.aop_dir);
-      goto release;
+      freeAsmop (op, NULL, ic, TRUE);
     }
 
-  /* bit variables done */
-  /* general case */
-  size = AOP_SIZE (right);
-  offset = 0;
-  while (size--)
+  op = IC_LEFT (ic);
+  if (op && IS_SYMOP (op))
     {
-      MOVA (aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
-      offset++;
-    }
+      aopOp (op, ic, FALSE, FALSE);
 
-release:
-  freeAsmop (right, NULL, ic, TRUE);
+      /* if the result is a bit */
+      if (AOP_TYPE (op) == AOP_CRY)
+        emitcode ("mov", "c,%s", AOP (op)->aopu.aop_dir);
+      else
+       {
+         /* bit variables done */
+         /* general case */
+         size = AOP_SIZE (op);
+         offset = 0;
+         while (size--)
+         {
+           MOVA (aopGet (AOP (op), offset, FALSE, FALSE, FALSE));
+           offset++;
+         }
+       }
+
+      freeAsmop (op, NULL, ic, TRUE);
+    }
+    
 }
 
 /*-----------------------------------------------------------------*/