* src/ds390/gen.c (pushSide, genPcall),
[fw/sdcc] / src / mcs51 / gen.c
index 005e6c1e2cd91f77fe5bcf25bd1eb29982836dcf..9db691c3917305b244b58a6d05f6645a4393de48 100644 (file)
@@ -1006,8 +1006,7 @@ aopOp (operand * op, iCode * ic, bool result)
               oldAsmOp = sym->usl.spillLoc->aop;
               sym->usl.spillLoc->aop = NULL;
             }
-          sym->aop = op->aop = aop =
-                     aopForSym (ic, sym->usl.spillLoc, result);
+          sym->aop = op->aop = aop = aopForSym (ic, sym->usl.spillLoc, result);
           if (getSize(sym->type) != getSize(sym->usl.spillLoc->type))
             {
               /* Don't reuse the new aop, go with the last one */
@@ -1042,7 +1041,7 @@ aopOp (operand * op, iCode * ic, bool result)
 
 /*-----------------------------------------------------------------*/
 /* freeAsmop - free up the asmop given to an operand               */
-/*----------------------------------------------------------------*/
+/*-----------------------------------------------------------------*/
 static void
 freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop)
 {
@@ -2420,9 +2419,29 @@ unsaveRegisters (iCode * ic)
 /* pushSide -                                                      */
 /*-----------------------------------------------------------------*/
 static void
-pushSide (operand * oper, int size)
+pushSide (operand * oper, int size, iCode * ic)
 {
   int offset = 0;
+  int nPushed = _G.r0Pushed + _G.r1Pushed;
+
+  aopOp (oper, ic, FALSE);
+
+  if (nPushed != _G.r0Pushed + _G.r1Pushed)
+    {
+      while (offset < size)
+        {
+          char *l = aopGet (oper, offset, FALSE, TRUE);
+          emitcode ("mov", "%s,%s", fReturn[offset++], l);
+        }
+      freeAsmop (oper, NULL, ic, TRUE);
+      offset = 0;
+      while (offset < size)
+        {
+          emitcode ("push", "%s", fReturn[offset++]);
+        }
+      return;
+    }
+
   while (size--)
     {
       char *l = aopGet (oper, offset++, FALSE, TRUE);
@@ -2438,6 +2457,8 @@ pushSide (operand * oper, int size)
           emitcode ("push", "%s", l);
         }
     }
+
+  freeAsmop (oper, NULL, ic, TRUE);
 }
 
 /*-----------------------------------------------------------------*/
@@ -3147,14 +3168,10 @@ genPcall (iCode * ic)
           emitcode ("mov", "a,#(%05d$ >> 8)", (rlbl->key + 100));
           emitcode ("push", "acc");
 
-          /* now push the calling address */
-          aopOp (IC_LEFT (ic), ic, FALSE);
-
-          pushSide (IC_LEFT (ic), FPTRSIZE);
-
-          freeAsmop (IC_LEFT (ic), NULL, ic, TRUE);
+          /* now push the function address */
+          pushSide (IC_LEFT (ic), FPTRSIZE, ic);
 
-          /* if send set is not empty the assign */
+          /* if send set is not empty then assign */
           if (_G.sendSet)
             {
               genSend(reverseSet(_G.sendSet));