* src/hc08/gen.c (hc08_emitDebuggerSymbol),
[fw/sdcc] / src / ds390 / gen.c
index c052d8a93aea618207bca4e5bb5f70ae53add513..0e077df19c4891b5118e7dec75a454f30cd16bfb 100644 (file)
@@ -31,6 +31,7 @@
 #include <ctype.h>
 
 #include "common.h"
+#include "main.h"
 #include "ralloc.h"
 #include "gen.h"
 #include "SDCCglobl.h"
@@ -186,6 +187,18 @@ emitcode (char *inst, char *fmt,...)
     va_end (ap);
 }
 
+/*-----------------------------------------------------------------*/
+/* ds390_emitDebuggerSymbol - associate the current code location  */
+/*   with a debugger symbol                                        */
+/*-----------------------------------------------------------------*/
+void
+ds390_emitDebuggerSymbol (char * debugSym)
+{
+  _G.debugLine = 1;
+  emitcode ("", "%s ==.", debugSym);
+  _G.debugLine = 0;
+}
+
 //
 // Move the passed value into A unless it is already there.
 // 
@@ -3016,17 +3029,10 @@ genFunction (iCode * ic)
                  /* save the registers used */
                  for (i = 0; i < sym->regsUsed->size; i++)
                    {
-                     if (bitVectBitValue (sym->regsUsed, i) ||
-                         (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+                     if (bitVectBitValue (sym->regsUsed, i))
                        emitcode ("push", "%s", ds390_regWithIdx (i)->dname);
                    }
                }
-             else if (ds390_ptrRegReq)
-               {
-                 emitcode ("push", "%s", ds390_regWithIdx (R0_IDX)->dname);
-                 emitcode ("push", "%s", ds390_regWithIdx (R1_IDX)->dname);
-               }
-
            }
          else
            {
@@ -3146,20 +3152,13 @@ genFunction (iCode * ic)
              /* save the registers used */
              for (i = 0; i < sym->regsUsed->size; i++)
                {
-                 if (bitVectBitValue (sym->regsUsed, i) ||
-                     (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+                 if (bitVectBitValue (sym->regsUsed, i))
                    {
                      emitcode ("push", "%s", ds390_regWithIdx (i)->dname);
                      _G.nRegsSaved++;
                    }
                }
            }
-         else if (ds390_ptrRegReq)
-           {
-             emitcode ("push", "%s", ds390_regWithIdx (R0_IDX)->dname);
-             emitcode ("push", "%s", ds390_regWithIdx (R1_IDX)->dname);
-             _G.nRegsSaved += 2;
-           }
        }
     }
 
@@ -3267,6 +3266,8 @@ genEndFunction (iCode * ic)
   if (IFFUNC_ISNAKED(sym->type))
   {
       emitcode(";", "naked function: no epilogue.");
+      if (options.debug && currFunc)
+       debugFile->writeEndFunction (currFunc, ic, 0);
       return;
   }
 
@@ -3352,17 +3353,10 @@ genEndFunction (iCode * ic)
                  /* save the registers used */
                  for (i = sym->regsUsed->size; i >= 0; i--)
                    {
-                     if (bitVectBitValue (sym->regsUsed, i) ||
-                         (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+                     if (bitVectBitValue (sym->regsUsed, i))
                        emitcode ("pop", "%s", ds390_regWithIdx (i)->dname);
                    }
                }
-             else if (ds390_ptrRegReq)
-               {
-                 emitcode ("pop", "%s", ds390_regWithIdx (R1_IDX)->dname);
-                 emitcode ("pop", "%s", ds390_regWithIdx (R0_IDX)->dname);
-               }
-
            }
          else
            {
@@ -3427,15 +3421,7 @@ genEndFunction (iCode * ic)
 
       /* if debug then send end of function */
       if (options.debug && currFunc) {
-         _G.debugLine = 1;
-         emitcode ("", "C$%s$%d$%d$%d ==.",
-                   FileBaseName (ic->filename), currFunc->lastLine,
-                   ic->level, ic->block);
-         if (IS_STATIC (currFunc->etype))
-           emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
-         else
-           emitcode ("", "XG$%s$0$0 ==.", currFunc->name);
-         _G.debugLine = 0;
+         debugFile->writeEndFunction (currFunc, ic, 1);
        }
 
       emitcode ("reti", "");
@@ -3452,31 +3438,16 @@ genEndFunction (iCode * ic)
              /* save the registers used */
              for (i = sym->regsUsed->size; i >= 0; i--)
                {
-                 if (bitVectBitValue (sym->regsUsed, i) ||
-                     (ds390_ptrRegReq && (i == R0_IDX || i == R1_IDX)))
+                 if (bitVectBitValue (sym->regsUsed, i))
                    emitcode ("pop", "%s", ds390_regWithIdx (i)->dname);
                }
            }
-         else if (ds390_ptrRegReq)
-           {
-              emitcode ("pop", "%s", ds390_regWithIdx (R1_IDX)->dname);
-              emitcode ("pop", "%s", ds390_regWithIdx (R0_IDX)->dname);
-           }
-
        }
 
       /* if debug then send end of function */
       if (options.debug && currFunc)
        {
-         _G.debugLine = 1;
-         emitcode ("", "C$%s$%d$%d$%d ==.",
-                   FileBaseName (ic->filename), currFunc->lastLine,
-                   ic->level, ic->block);
-         if (IS_STATIC (currFunc->etype))
-           emitcode ("", "XF%s$%s$0$0 ==.", moduleName, currFunc->name);
-         else
-           emitcode ("", "XG$%s$0$0 ==.", currFunc->name);
-         _G.debugLine = 0;
+         debugFile->writeEndFunction (currFunc, ic, 1);
        }
 
       emitcode ("ret", "");
@@ -3491,6 +3462,15 @@ genEndFunction (iCode * ic)
       && !FUNC_REGBANK(sym->type))
     return;
     
+  /* There are no push/pops to optimize if not callee-saves or ISR */
+  if (!(FUNC_CALLEESAVES (sym->type) || FUNC_ISISR (sym->type)))
+    return;
+  
+  /* If there were stack parameters, we cannot optimize without also    */
+  /* fixing all of the stack offsets; this is too dificult to consider. */
+  if (FUNC_HASSTACKPARM(sym->type))
+    return;
+  
   /* Compute the registers actually used */
   regsUsed = newBitVect (ds390_nRegs);
   regsUsedPrologue = newBitVect (ds390_nRegs);
@@ -3502,7 +3482,7 @@ genEndFunction (iCode * ic)
         regsUsed = bitVectUnion (regsUsed, port->peep.getRegsWritten(lnp));
       
       if (lnp->ic && lnp->ic->op == FUNCTION && lnp->prev
-          && lnp->prev->ic && lnp->prev->ic->op != FUNCTION)
+          && lnp->prev->ic && lnp->prev->ic->op == ENDFUNCTION)
        break;
       if (!lnp->prev)
         break;
@@ -13401,13 +13381,7 @@ gen390Code (iCode * lic)
   /* if debug information required */
   if (options.debug && currFunc)
     {
-      debugFile->writeFunction(currFunc);
-      _G.debugLine = 1;
-      if (IS_STATIC (currFunc->etype))
-       emitcode ("", "F%s$%s$0$0 ==.", moduleName, currFunc->name);
-      else
-       emitcode ("", "G$%s$0$0 ==.", currFunc->name);
-      _G.debugLine = 0;
+      debugFile->writeFunction (currFunc, lic);
     }
   /* stack pointer name */
   if (options.useXstack)
@@ -13425,11 +13399,7 @@ gen390Code (iCode * lic)
        {
          if (options.debug)
            {
-             _G.debugLine = 1;
-             emitcode ("", "C$%s$%d$%d$%d ==.",
-                       FileBaseName (ic->filename), ic->lineno,
-                       ic->level, ic->block);
-             _G.debugLine = 0;
+             debugFile->writeCLine (ic);
            }
          if (!options.noCcodeInAsm) {
            emitcode ("", ";\t%s:%d: %s", ic->filename, ic->lineno,