* device/include/mcs51reg.h: fixed bug 842007
[fw/sdcc] / src / SDCCpeeph.c
index 2311c2c3b68ce85b931568c200af30356ea216ce..269465814a99369fce1e1c27a89101bd6c96f32f 100644 (file)
@@ -572,6 +572,84 @@ FBYNAME (labelRefCount)
   return rc;
 }
 
+
+/* labelRefCountChange:
+ * takes two parameters: a variable (bound to a label name)
+ * and a signed int for changing the reference count.
+ *
+ * Please note, this function is not a conditional. It unconditionally
+ * changes the label. It should be passed as the 'last' function
+ * so it only is applied if all other conditions have been met.
+ *
+ * should always return TRUE
+ */
+FBYNAME (labelRefCountChange)
+{
+  int varNumber, RefCountDelta;
+  bool rc = FALSE;
+
+  /* If we don't have the label hash table yet, build it. */
+  if (!labelHash)
+    {
+      buildLabelRefCountHash (head);
+    }
+
+  if (sscanf (cmdLine, "%*[ \t%]%d %i", &varNumber, &RefCountDelta) == 2)
+    {
+      char *label = hTabItemWithKey (vars, varNumber);
+
+      if (label)
+        {
+          labelHashEntry *entry;
+
+          entry = hTabFirstItemWK (labelHash, hashSymbolName (label));
+
+          while (entry)
+            {
+              if (!strcmp (label, entry->name))
+                {
+                  break;
+                }
+              entry = hTabNextItemWK (labelHash);
+            }
+          if (entry)
+            {
+              if (0 <= entry->refCount + RefCountDelta)
+                {
+                  entry->refCount += RefCountDelta;
+                  rc = TRUE;
+                }
+              else
+                {
+                  fprintf (stderr, "*** internal error: label %s may not get"
+                          " negative refCount in %s peephole.\n",
+                           label, __FUNCTION__);
+                }
+            }
+            else
+            {
+              fprintf (stderr, "*** internal error: no label has entry for"
+                       " %s in %s peephole.\n",
+                       label, __FUNCTION__);
+            }
+        }
+      else
+        {
+          fprintf (stderr, "*** internal error: var %d not bound"
+                   " in peephole %s rule.\n", 
+                   varNumber, __FUNCTION__);
+        }
+    }
+  else
+    {
+      fprintf (stderr,
+               "*** internal error: labelRefCount peephole restriction"
+               " malformed: %s\n", cmdLine);
+    }
+  return rc;
+}
+
+
 /* Within the context of the lines currPl through endPl, determine
 ** if the variable var contains a symbol that is volatile. Returns
 ** TRUE only if it is certain that this was not volatile (the symbol
@@ -762,8 +840,8 @@ error:
 /*------------------------------------------------------------------*/
 /* setFromConditionArgs - parse a peephole condition's arguments    */
 /* to produce a set of strings, one per argument. Variables %x will */
-/* be replaced with their values. String literals (in single or     */
-/* double quotes) are accepted an return in unquoted form.          */
+/* be replaced with their values. String literals (in single quotes)*/
+/* are accepted and return in unquoted form.                         */
 /*------------------------------------------------------------------*/
 static set *
 setFromConditionArgs (char *cmdLine, hTab * vars)
@@ -798,7 +876,7 @@ setFromConditionArgs (char *cmdLine, hTab * vars)
           else
             goto error;
         }
-      else if (*cmdLine == '"' || *cmdLine == '\'' )
+      else if (*cmdLine == '\'' )
         {
           char quote = *cmdLine;
           
@@ -855,7 +933,7 @@ FBYNAME (operandsNotRelated)
   if (!operands)
     {
       fprintf (stderr,
-               "*** internal error: operandsUnrelated peephole restriction"
+               "*** internal error: operandsNotRelated peephole restriction"
                " malformed: %s\n", cmdLine);
       return FALSE;
     }  
@@ -963,6 +1041,9 @@ callFuncByName (char *fname,
     },
     {
       "operandsNotRelated", operandsNotRelated
+    },
+    {
+      "labelRefCountChange", labelRefCountChange
     }
   };
   int  i;