(genFunction): avoid excess "inc sp"
[fw/sdcc] / src / mcs51 / gen.c
index 29d1711565a8d20a59fc955718ad481a8ae58c47..d91f0d4c205b7719bfe38176ed57b333aca7cd70 100644 (file)
@@ -554,7 +554,7 @@ aopOp (operand * op, iCode * ic, bool result)
     }
 
   /* if already has a asmop then continue */
-  if (op->aop && aop->size == getSize(sym->type))
+  if (op->aop )
     return;
 
   /* if the underlying symbol has a aop */
@@ -626,6 +626,10 @@ aopOp (operand * op, iCode * ic, bool result)
        }
 
       /* 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);
       aop->size = getSize (sym->type);
@@ -1921,7 +1925,7 @@ genCall (iCode * ic)
      the same register bank then we need to save the
      destination registers on the stack */
   dtype = operandType (IC_LEFT (ic));
-  if (dtype && !IFFUNC_ISNAKED(dtype) &&
+  if (currFunc && dtype && !IFFUNC_ISNAKED(dtype) &&
       (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype)) &&
       IFFUNC_ISISR (currFunc->type))
   {
@@ -2019,7 +2023,7 @@ genPcall (iCode * ic)
      the same register bank then we need to save the
      destination registers on the stack */
   dtype = operandType (IC_LEFT (ic));
-  if (dtype && !FUNC_ISNAKED(dtype) &&
+  if (currFunc && dtype && !FUNC_ISNAKED(dtype) &&
       IFFUNC_ISISR (currFunc->type) &&
       (FUNC_REGBANK (currFunc->type) != FUNC_REGBANK (dtype))) {
     saveRBank (FUNC_REGBANK (dtype), ic, TRUE);
@@ -2412,6 +2416,18 @@ genFunction (iCode * ic)
          emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
          emitcode ("mov", "sp,a");
 
+       }
+      else if (i > 5)
+       {
+
+         /* ISRs will be handled by the code above, because they
+            can't have parameters. Therefore it's save to use r0 */
+         emitcode ("mov", "r0,a");
+         emitcode ("mov", "a,sp");
+         emitcode ("add", "a,#0x%02x", ((char) sym->stack & 0xff));
+         emitcode ("mov", "sp,a");
+         emitcode ("mov", "a,r0");
+
        }
       else
        while (i--)
@@ -2564,7 +2580,6 @@ genEndFunction (iCode * ic)
        emitcode ("setb", "ea");
 
       /* if debug then send end of function */
-      /*  if (options.debug && currFunc)  */
       if (options.debug && currFunc)
        {
          _G.debugLine = 1;
@@ -8784,7 +8799,6 @@ gen51Code (iCode * lic)
   if (allocInfo)
     printAllocInfo (currFunc, codeOutFile);
   /* if debug information required */
-  /*     if (options.debug && currFunc) { */
   if (options.debug && currFunc)
     {
       cdbSymbol (currFunc, cdbFile, FALSE, TRUE);