]> git.gag.com Git - fw/sdcc/commitdiff
fixed bug #741761
authorepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Aug 2003 23:17:13 +0000 (23:17 +0000)
committerepetrich <epetrich@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 20 Aug 2003 23:17:13 +0000 (23:17 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2841 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/ds390/gen.c
src/mcs51/gen.c

index 8e9ca1c320f6a4b0b3208f846bd38604c89cd91d..cf24b5de3f4fb1916bcd0b6504e7157bba663a20 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2003-08-20  Erik Petrich <epetrich@ivorytower.norman.ok.us>
+
+       Fixed bug #741761
+
+       * src/mcs51/gen.c (aopForSym, leftRightUseAcc),
+       * src/ds390/gen.c (aopForSym, leftRightUseAcc): preserve A and B
+       if the left or right operand symbols have the accuse flag set.
+
 2003-08-20  Erik Petrich <epetrich@ivorytower.norman.ok.us>
 
        Changed the type of the result of the ! (NOT) operator to char;
index 4deb61a2347e11b01fbea99e1d690eaa206e4308..2b93fa27ba9557024eb877c754f332a8a01af07d 100644 (file)
@@ -438,6 +438,27 @@ pointerCode (sym_link * etype)
 
 }
 
+/*-----------------------------------------------------------------*/
+/* leftRightUseAcc - returns size of accumulator use by operands   */
+/*-----------------------------------------------------------------*/
+static int
+leftRightUseAcc(iCode *ic)
+{
+  int accuse = 0;
+  
+  if (ic && IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))
+      && OP_SYMBOL (IC_LEFT (ic)) && OP_SYMBOL (IC_LEFT (ic))->accuse)
+    accuse = (accuse < OP_SYMBOL (IC_LEFT (ic))->nRegs)
+             ? OP_SYMBOL (IC_LEFT (ic))->nRegs : accuse;
+    
+  if (ic && IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))
+      && OP_SYMBOL (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->accuse)
+    accuse = (accuse < OP_SYMBOL (IC_RIGHT (ic))->nRegs)
+             ? OP_SYMBOL (IC_RIGHT (ic))->nRegs : accuse;
+
+  return accuse;
+}
+
 /*-----------------------------------------------------------------*/
 /* aopForSym - for a true symbol                                   */
 /*-----------------------------------------------------------------*/
@@ -446,6 +467,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 +489,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 +503,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 +565,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 +595,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));
index 0a5e3598970ecc4881ad3e96e3e6ec7852d27478..a9d6e638ace43bbf1b93ea630e415d4bcdeef612 100644 (file)
@@ -280,6 +280,29 @@ pointerCode (sym_link * etype)
 
 }
 
+
+/*-----------------------------------------------------------------*/
+/* leftRightUseAcc - returns size of accumulator use by operands   */
+/*-----------------------------------------------------------------*/
+static int
+leftRightUseAcc(iCode *ic)
+{
+  int accuse = 0;
+  
+  if (ic && IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic))
+      && OP_SYMBOL (IC_LEFT (ic)) && OP_SYMBOL (IC_LEFT (ic))->accuse)
+    accuse = (accuse < OP_SYMBOL (IC_LEFT (ic))->nRegs)
+             ? OP_SYMBOL (IC_LEFT (ic))->nRegs : accuse;
+    
+  if (ic && IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic))
+      && OP_SYMBOL (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->accuse)
+    accuse = (accuse < OP_SYMBOL (IC_RIGHT (ic))->nRegs)
+             ? OP_SYMBOL (IC_RIGHT (ic))->nRegs : accuse;
+
+  return accuse;
+}
+
+
 /*-----------------------------------------------------------------*/
 /* aopForSym - for a true symbol                                   */
 /*-----------------------------------------------------------------*/
@@ -314,7 +337,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
 
          if (sym->onStack)
            {
-             if (_G.accInUse)
+             if (_G.accInUse || leftRightUseAcc (ic))
                emitcode ("push", "acc");
 
              emitcode ("mov", "a,_bp");
@@ -325,7 +348,7 @@ aopForSym (iCode * ic, symbol * sym, bool result)
              emitcode ("mov", "%s,a",
                        aop->aopu.aop_ptr->name);
 
-             if (_G.accInUse)
+             if (_G.accInUse || leftRightUseAcc (ic))
                emitcode ("pop", "acc");
            }
          else