* src/z80/gen.h,
[fw/sdcc] / src / ds390 / gen.c
index 419896b1231fb2cea4226063e72446138dfbcde6..99dba5b475767aa9516308518a7a4564bd8d78f1 100644 (file)
@@ -438,6 +438,72 @@ pointerCode (sym_link * etype)
 
 }
 
+/*-----------------------------------------------------------------*/
+/* leftRightUseAcc - returns size of accumulator use by operands   */
+/*-----------------------------------------------------------------*/
+static int
+leftRightUseAcc(iCode *ic)
+{
+  operand *op;
+  int size;
+  int accuseSize = 0;
+  int accuse = 0;
+  
+  if (!ic)
+    {
+      werror (E_INTERNAL_ERROR, __FILE__, __LINE__,
+             "null iCode pointer");
+      return 0;
+    }
+
+  if (ic->op == IFX)
+    {
+      op = IC_COND (ic);
+      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+        {
+          accuse = 1;
+          size = getSize (OP_SYMBOL (op)->type);
+          if (size>accuseSize)
+            accuseSize = size;
+        }
+    }
+  else if (ic->op == JUMPTABLE)
+    {
+      op = IC_JTCOND (ic);
+      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+        {
+          accuse = 1;
+          size = getSize (OP_SYMBOL (op)->type);
+          if (size>accuseSize)
+            accuseSize = size;
+        }
+    }
+  else
+    {
+      op = IC_LEFT (ic);
+      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+        {
+          accuse = 1;
+          size = getSize (OP_SYMBOL (op)->type);
+          if (size>accuseSize)
+            accuseSize = size;
+        }
+      op = IC_RIGHT (ic);
+      if (IS_SYMOP (op) && OP_SYMBOL (op) && OP_SYMBOL (op)->accuse)
+        {
+          accuse = 1;
+          size = getSize (OP_SYMBOL (op)->type);
+          if (size>accuseSize)
+            accuseSize = size;
+        }
+    }
+  
+  if (accuseSize)
+    return accuseSize;
+  else
+    return accuse;
+}
+
 /*-----------------------------------------------------------------*/
 /* aopForSym - for a true symbol                                   */
 /*-----------------------------------------------------------------*/
@@ -446,6 +512,7 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
 {
   asmop *aop;
   memmap *space = SPEC_OCLS (sym->etype);
+  int accuse = leftRightUseAcc (ic);
 
   /* if already has one */
   if (sym->aop)
@@ -467,10 +534,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
 
          if (sym->onStack)
            {
-             if (_G.accInUse)
+             if (_G.accInUse || accuse)
                emitcode ("push", "acc");
 
-             if (_G.bInUse)
+             if (_G.bInUse || (accuse>1))
                emitcode ("push", "b");
 
              emitcode ("mov", "a,_bp");
@@ -481,10 +548,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
              emitcode ("mov", "%s,a",
                        aop->aopu.aop_ptr->name);
 
-             if (_G.bInUse)
+             if (_G.bInUse || (accuse>1))
                emitcode ("pop", "b");
 
-             if (_G.accInUse)
+             if (_G.accInUse || accuse)
                emitcode ("pop", "acc");
            }
          else
@@ -543,10 +610,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
                emitcode("mov","dps,#0");
            }
        }  else {
-           if (_G.accInUse)
+           if (_G.accInUse || accuse)
                emitcode ("push", "acc");
            
-           if (_G.bInUse)
+           if (_G.bInUse || (accuse>1))
                emitcode ("push", "b");
        
            emitcode ("mov", "a,_bpx");
@@ -573,10 +640,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2)
                emitcode ("mov", "dpl,b");
            }
            
-           if (_G.bInUse)
+           if (_G.bInUse || (accuse>1))
                emitcode ("pop", "b");
            
-           if (_G.accInUse)
+           if (_G.accInUse || accuse)
                emitcode ("pop", "acc");
        }
        sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR));
@@ -939,13 +1006,22 @@ aopOp (operand * op, iCode * ic, bool result, bool useDP2)
          aop->aopu.dptr = sym->dptr;
          return ;
       }
-      /* else spill location  */
-      if (sym->usl.spillLoc && getSize(sym->type) != getSize(sym->usl.spillLoc->type)) {
-         /* force a new aop if sizes differ */
-         sym->usl.spillLoc->aop = NULL;
-      }
-      sym->aop = op->aop = aop =
-       aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+      
+      if (sym->usl.spillLoc)
+        {
+          if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
+            {
+             /* force a new aop if sizes differ */
+             sym->usl.spillLoc->aop = NULL;
+           }
+         sym->aop = op->aop = aop =
+                    aopForSym (ic, sym->usl.spillLoc, result, useDP2);
+         aop->size = getSize (sym->type);
+         return;
+        }
+      
+      /* else must be a dummy iTemp */
+      sym->aop = op->aop = aop = newAsmop (AOP_DUMMY);
       aop->size = getSize (sym->type);
       return;
     }
@@ -1115,6 +1191,8 @@ aopGet (asmop *aop,
   /* depending on type */
   switch (aop->type)
     {
+    case AOP_DUMMY:
+      return zero;
 
     case AOP_R0:
     case AOP_R1:
@@ -1316,6 +1394,10 @@ aopPut (asmop * aop, char *s, int offset)
   /* depending on where it is ofcourse */
   switch (aop->type)
     {
+    case AOP_DUMMY:
+      MOVA (s);                /* read s in case it was volatile */
+      break;
+      
     case AOP_DIR:
         if (offset)
        {
@@ -1607,47 +1689,6 @@ reAdjustPreg (asmop * aop)
       emitcode("nop", "; workaround for DS80C390 div bug.");  \
     }
 
-/*-----------------------------------------------------------------*/
-/* genNotFloat - generates not for float operations              */
-/*-----------------------------------------------------------------*/
-static void
-genNotFloat (operand * op, operand * res)
-{
-  int size, offset;
-  symbol *tlbl;
-
-  D (emitcode (";", "genNotFloat "););
-
-  /* we will put 127 in the first byte of
-     the result */
-  aopPut (AOP (res), "#127", 0);
-  size = AOP_SIZE (op) - 1;
-  offset = 1;
-
-  _startLazyDPSEvaluation ();
-  MOVA(aopGet(op->aop, offset++, FALSE, FALSE, NULL));
-
-  while (size--)
-    {
-      emitcode ("orl", "a,%s",
-               aopGet (op->aop,
-                       offset++, FALSE, FALSE,
-                       DP2_RESULT_REG));
-    }
-  _endLazyDPSEvaluation ();
-
-  tlbl = newiTempLabel (NULL);
-  aopPut (res->aop, one, 1);
-  emitcode ("jz", "!tlabel", (tlbl->key + 100));
-  aopPut (res->aop, zero, 1);
-  emitcode ("", "!tlabeldef", (tlbl->key + 100));
-
-  size = res->aop->size - 2;
-  offset = 2;
-  /* put zeros in the rest */
-  while (size--)
-    aopPut (res->aop, zero, offset++);
-}
 
 /*-----------------------------------------------------------------*/
 /* opIsGptr: returns non-zero if the passed operand is       */
@@ -1797,7 +1838,6 @@ static void
 genNot (iCode * ic)
 {
   symbol *tlbl;
-  sym_link *optype = operandType (IC_LEFT (ic));
 
   D (emitcode (";", "genNot "););
 
@@ -1814,13 +1854,6 @@ genNot (iCode * ic)
       goto release;
     }
 
-  /* if type float then do float */
-  if (IS_FLOAT (optype))
-    {
-      genNotFloat (IC_LEFT (ic), IC_RESULT (ic));
-      goto release;
-    }
-
   toBoolean (IC_LEFT (ic));
 
   tlbl = newiTempLabel (NULL);
@@ -2879,9 +2912,6 @@ genFunction (iCode * ic)
   
   if (options.stack_probe) 
       emitcode ("lcall","__stack_probe");
-  /* if critical function then turn interrupts off */
-  if (IFFUNC_ISCRITICAL (ftype))
-    emitcode ("clr", "ea");
 
   /* here we need to generate the equates for the
      register bank if required */
@@ -3160,6 +3190,14 @@ genFunction (iCode * ic)
       emitcode ("add", "a,#!constbyte", ((char) sym->xstack & 0xff));
       emitcode ("mov", "_spx,a");
     }
+  
+  /* if critical function then turn interrupts off */
+  if (IFFUNC_ISCRITICAL (ftype))
+    {
+      emitcode ("mov", "c,ea");
+      emitcode ("push", "psw"); /* save old ea via c in psw */
+      emitcode ("clr", "ea");
+    }
 
 }
 
@@ -3179,6 +3217,12 @@ genEndFunction (iCode * ic)
       return;
   }
 
+  if (IFFUNC_ISCRITICAL (sym->type))
+    {
+      emitcode ("pop", "psw"); /* restore ea via c in psw */
+      emitcode ("mov", "ea,c");
+    }
+  
   if ((IFFUNC_ISREENT (sym->type) || options.stackAuto) &&
        (sym->stack || FUNC_HASSTACKPARM(sym->type))) {
 
@@ -3323,9 +3367,6 @@ genEndFunction (iCode * ic)
       if (!inExcludeList ("acc"))
        emitcode ("pop", "acc");
 
-      if (IFFUNC_ISCRITICAL (sym->type))
-       emitcode ("setb", "ea");
-
       /* if debug then send end of function */
       if (options.debug && currFunc) {
          _G.debugLine = 1;
@@ -3343,9 +3384,6 @@ genEndFunction (iCode * ic)
     }
   else
     {
-      if (IFFUNC_ISCRITICAL (sym->type))
-       emitcode ("setb", "ea");
-
       if (IFFUNC_CALLEESAVES(sym->type))
        {
          int i;
@@ -12627,7 +12665,7 @@ genDummyRead (iCode * ic)
   offset = 0;
   while (size--)
     {
-      emitcode ("mov", "a,%s", aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
+      MOVA (aopGet (AOP (right), offset, FALSE, FALSE, FALSE));
       offset++;
     }