* src/mcs51/gen.c (genCpl): quick fix for bug #974835
[fw/sdcc] / src / mcs51 / gen.c
index 0fb8581b8f4e987ba01af7300448a49c6ade7d4b..ecd3bf860305d963f9ca599b1542dcedb369bd9b 100644 (file)
@@ -150,6 +150,18 @@ emitcode (char *inst, const char *fmt,...)
   va_end (ap);
 }
 
+/*-----------------------------------------------------------------*/
+/* mcs51_emitDebuggerSymbol - associate the current code location  */
+/*   with a debugger symbol                                        */
+/*-----------------------------------------------------------------*/
+void
+mcs51_emitDebuggerSymbol (char * debugSym)
+{
+  _G.debugLine = 1;
+  emitcode ("", "%s ==.", debugSym);
+  _G.debugLine = 0;
+}
+
 /*-----------------------------------------------------------------*/
 /* mova - moves specified value into accumulator                   */
 /*-----------------------------------------------------------------*/
@@ -638,10 +650,10 @@ operandsEqu (operand * op1, operand * op2)
   if (sym1 == sym2)
     return TRUE;
 
-  if (strcmp (sym1->rname, sym2->rname) == 0)
+  if (sym1->rname[0] && sym2->rname[0]
+      && strcmp (sym1->rname, sym2->rname) == 0)
     return TRUE;
 
-
   /* if left is a tmp & right is not */
   if (IS_ITEMP (op1) &&
       !IS_ITEMP (op2) &&
@@ -1599,9 +1611,8 @@ genCpl (iCode * ic)
     {
       if (AOP_TYPE (IC_LEFT (ic)) == AOP_CRY)
        {
-         emitcode ("mov", "c,%s", IC_LEFT (ic)->aop->aopu.aop_dir);
-         emitcode ("cpl", "c");
-         emitcode ("mov", "%s,c", IC_RESULT (ic)->aop->aopu.aop_dir);
+         /* promotion rules are responsible for this strange result: */
+         emitcode ("setb", "%s", IC_RESULT (ic)->aop->aopu.aop_dir);
          goto release;
        }
 
@@ -2864,6 +2875,8 @@ genEndFunction (iCode * ic)
   if (IFFUNC_ISNAKED(sym->type))
   {
       emitcode(";", "naked function: no epilogue.");
+      if (options.debug && currFunc)
+       debugFile->writeEndFunction (currFunc, ic, 0);
       return;
   }
 
@@ -2997,15 +3010,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", "");
@@ -3038,21 +3043,13 @@ 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 ("ret", "");
     }
 
-  if (!port->peep.getRegsRead || !port->peep.getRegsWritten)
+  if (!port->peep.getRegsRead || !port->peep.getRegsWritten || options.nopeep)
     return;
   
   /* If this was an interrupt handler using bank 0 that called another */
@@ -3092,8 +3089,8 @@ genEndFunction (iCode * ic)
       && !bitVectBitValue (regsUsed, CND_IDX))
     {
       regsUsed = bitVectUnion (regsUsed, regsUsedPrologue);
-      if (IFFUNC_ISISR (sym->type) && !FUNC_REGBANK(sym->type)
-          && !sym->stack)
+      if (IFFUNC_ISISR (sym->type) && !FUNC_REGBANK (sym->type)
+          && !sym->stack && !FUNC_ISCRITICAL (sym->type))
         bitVectUnSetBit (regsUsed, CND_IDX);
     }
   else
@@ -4779,6 +4776,9 @@ genCmp (operand * left, operand * right,
                      if (!(AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) && ifx)
                        {
                          genIfxJump (ifx, "acc.7", left, right, result);
+                         freeAsmop (right, NULL, ic, TRUE);
+                         freeAsmop (left, NULL, ic, TRUE);
+
                          return;
                        }
                      else
@@ -9892,13 +9892,7 @@ gen51Code (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)
@@ -9915,11 +9909,7 @@ gen51Code (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 ("", ";%s:%d: %s", ic->filename, ic->lineno,