* src/SDCC.lex (check_type),
[fw/sdcc] / src / SDCCpeeph.c
index 0359d8946bf23d1622925f96d8f554a7395fc201..075cad2abc12af5ba428411386de4a84553bac5b 100644 (file)
@@ -61,7 +61,7 @@ void pic16_peepRules2pCode(peepRule *);
 #endif
 
 /*-----------------------------------------------------------------*/
-/* pcDistance - afinds a label back ward or forward                */
+/* pcDistance - finds a label backward or forward                  */
 /*-----------------------------------------------------------------*/
 
 static int
@@ -74,16 +74,19 @@ pcDistance (lineNode * cpos, char *lbl, bool back)
   SNPRINTF (buff, sizeof(buff), "%s:", lbl);
   while (pl)
     {
-
       if (pl->line &&
           !pl->isComment &&
           !pl->isLabel &&
-          !pl->isDebug) {
-                if (port->peep.getSize) {
-                        dist += port->peep.getSize(pl);
-                } else {
-                        dist += 3;
-                }
+          !pl->isDebug)
+        {
+          if (port->peep.getSize)
+            {
+              dist += port->peep.getSize(pl);
+            }
+          else
+            {
+              dist += 3;
+            }
         }
 
       if (strncmp (pl->line, buff, strlen (buff)) == 0)
@@ -155,7 +158,7 @@ FBYNAME (labelInRange)
     return FALSE;
 
   /* calculate the label distance : the jump for reladdr can be
-     +/- 127 bytes, here Iam assuming that an average 8051
+     +/- 127 bytes, here I am assuming that an average 8051
      instruction is 2 bytes long, so if the label is more than
      63 intructions away, the label is considered out of range
      for a relative jump. we could get more precise this will
@@ -399,6 +402,28 @@ FBYNAME (deadMove)
   return FALSE;
 }
 
+/*-----------------------------------------------------------------*/
+/* notUsed - Check, if value in register is not read again         */
+/*-----------------------------------------------------------------*/
+FBYNAME (notUsed)
+{
+  const char *what;
+
+  if(cmdLine[0] != '\'')
+    what = hTabItemWithKey (vars, 1);
+  else
+  {
+    cmdLine[strlen(cmdLine) - 1] = 0;
+    what = cmdLine + 1;
+  }
+
+  if (port->peep.notUsed)
+    return port->peep.notUsed (what, endPl, head);
+
+  fprintf (stderr, "Function notUsed not initialized in port structure\n");
+  return FALSE;
+}
+
 /*-----------------------------------------------------------------*/
 /* operandsNotSame - check if %1 & %2 are the same                 */
 /*-----------------------------------------------------------------*/
@@ -821,7 +846,9 @@ notVolatileVariable(char *var, lineNode *currPl, lineNode *endPl)
             op = IC_COND (cl->ic);
             if (IS_SYMOP (op) &&
                 ( !strcmp(OP_SYMBOL (op)->rname, symname) ||
-                  (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) ))
+                  (OP_SYMBOL (op)->isspilt &&
+                   SPIL_LOC (op) &&
+                   !strcmp(SPIL_LOC (op)->rname, symname)) ))
               {
                 return !op->isvolatile;
               }
@@ -829,7 +856,9 @@ notVolatileVariable(char *var, lineNode *currPl, lineNode *endPl)
             op = IC_JTCOND (cl->ic);
             if (IS_SYMOP (op) &&
                 ( !strcmp(OP_SYMBOL (op)->rname, symname) ||
-                  (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) ))
+                  (OP_SYMBOL (op)->isspilt &&
+                   SPIL_LOC (op) &&
+                   !strcmp(SPIL_LOC (op)->rname, symname)) ))
               {
                 return !op->isvolatile;
               }
@@ -837,21 +866,27 @@ notVolatileVariable(char *var, lineNode *currPl, lineNode *endPl)
             op = IC_LEFT (cl->ic);
             if (IS_SYMOP (op) &&
                 ( !strcmp(OP_SYMBOL (op)->rname, symname) ||
-                  (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) ))
+                  (OP_SYMBOL (op)->isspilt &&
+                   SPIL_LOC (op) &&
+                   !strcmp(SPIL_LOC (op)->rname, symname)) ))
               {
                 return !op->isvolatile;
               }
             op = IC_RIGHT (cl->ic);
             if (IS_SYMOP (op) &&
                 ( !strcmp(OP_SYMBOL (op)->rname, symname) ||
-                  (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) ))
+                  (OP_SYMBOL (op)->isspilt &&
+                   SPIL_LOC (op) &&
+                   !strcmp(SPIL_LOC (op)->rname, symname)) ))
               {
                 return !op->isvolatile;
               }
             op = IC_RESULT (cl->ic);
             if (IS_SYMOP (op) &&
                 ( !strcmp(OP_SYMBOL (op)->rname, symname) ||
-                  (OP_SYMBOL (op)->isspilt && !strcmp(SPIL_LOC (op)->rname, symname)) ))
+                  (OP_SYMBOL (op)->isspilt &&
+                   SPIL_LOC (op) &&
+                   !strcmp(SPIL_LOC (op)->rname, symname)) ))
               {
                 return !op->isvolatile;
               }
@@ -1035,6 +1070,9 @@ operandBaseName (const char *op)
         return "a";
       if (!strncmp (op, "ar", 2) && ISCHARDIGIT(*(op+2)) && !*(op+3))
         return op+1;
+      // bug 1739475, temp fix
+      if (op[0] == '@')
+        return operandBaseName(op+1);
     }
 
   return op;
@@ -1184,6 +1222,9 @@ ftab[] =                                // sorted on the number of times used
   },
   {
     "useAcallAjmp", useAcallAjmp
+  },
+  {
+    "notUsed", notUsed
   }
 };
 /*-----------------------------------------------------------------*/
@@ -1192,8 +1233,8 @@ ftab[] =                                // sorted on the number of times used
 static int
 callFuncByName (char *fname,
                 hTab * vars,
-                lineNode * currPl,
-                lineNode * endPl,
+                lineNode * currPl, /* first source line matched */
+                lineNode * endPl,  /* last source line matched */
                 lineNode * head)
 {
   int   i;