+ char *op1 = hTabItemWithKey (vars, 1);
+ char *op2 = hTabItemWithKey (vars, 2);
+ char *op3 = hTabItemWithKey (vars, 3);
+ char *op4 = hTabItemWithKey (vars, 4);
+ char *op5 = hTabItemWithKey (vars, 5);
+ char *op6 = hTabItemWithKey (vars, 6);
+ char *op7 = hTabItemWithKey (vars, 7);
+ char *op8 = hTabItemWithKey (vars, 8);
+
+ if ( (strcmp (op1, op2) == 0) ||
+ (strcmp (op1, op3) == 0) ||
+ (strcmp (op1, op4) == 0) ||
+ (strcmp (op1, op5) == 0) ||
+ (strcmp (op1, op6) == 0) ||
+ (strcmp (op1, op7) == 0) ||
+ (strcmp (op1, op8) == 0) ||
+ (strcmp (op2, op3) == 0) ||
+ (strcmp (op2, op4) == 0) ||
+ (strcmp (op2, op5) == 0) ||
+ (strcmp (op2, op6) == 0) ||
+ (strcmp (op2, op7) == 0) ||
+ (strcmp (op2, op8) == 0) ||
+ (strcmp (op3, op4) == 0) ||
+ (strcmp (op3, op5) == 0) ||
+ (strcmp (op3, op6) == 0) ||
+ (strcmp (op3, op7) == 0) ||
+ (strcmp (op3, op8) == 0) ||
+ (strcmp (op4, op5) == 0) ||
+ (strcmp (op4, op6) == 0) ||
+ (strcmp (op4, op7) == 0) ||
+ (strcmp (op4, op8) == 0) ||
+ (strcmp (op5, op6) == 0) ||
+ (strcmp (op5, op7) == 0) ||
+ (strcmp (op5, op8) == 0) ||
+ (strcmp (op6, op7) == 0) ||
+ (strcmp (op6, op8) == 0) ||
+ (strcmp (op7, op8) == 0) )
+ return FALSE;
+ else
+ return TRUE;
+}
+
+
+/* labelRefCount:
+
+ * takes two parameters: a variable (bound to a label name)
+ * and an expected reference count.
+ *
+ * Returns TRUE if that label is defined and referenced exactly
+ * the given number of times.
+ */
+FBYNAME (labelRefCount)
+{
+ int varNumber, expectedRefCount;
+ bool rc = FALSE;
+
+ /* If we don't have the label hash table yet, build it. */
+ if (!labelHash)
+ {
+ buildLabelRefCountHash (head);
+ }
+
+ if (sscanf (cmdLine, "%*[ \t%]%d %d", &varNumber, &expectedRefCount) == 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
+ /* debug spew. */
+ fprintf (stderr, "labelRefCount: %s has refCount %d, want %d\n",
+ label, entry->refCount, expectedRefCount);
+#endif
+
+ rc = (expectedRefCount == entry->refCount);
+ }
+ else
+ {
+ fprintf (stderr, "*** internal error: no label has entry for"
+ " %s in labelRefCount peephole.\n",
+ label);
+ }
+ }
+ else
+ {
+ fprintf (stderr, "*** internal error: var %d not bound"
+ " in peephole labelRefCount rule.\n",
+ varNumber);
+ }
+
+ }
+ else
+ {
+ fprintf (stderr,
+ "*** internal error: labelRefCount peephole restriction"
+ " malformed: %s\n", cmdLine);
+ }
+ return rc;
+}
+
+/*-----------------------------------------------------------------*/
+/* callFuncByName - calls a function as defined in the table */
+/*-----------------------------------------------------------------*/
+int
+callFuncByName (char *fname,
+ hTab * vars,
+ lineNode * currPl,
+ lineNode * endPl,
+ lineNode * head)
+{
+ struct ftab
+ {
+ char *fname;
+ int (*func) (hTab *, lineNode *, lineNode *, lineNode *, const char *);
+ }
+ ftab[] =
+ {
+ {
+ "labelInRange", labelInRange
+ }
+ ,
+ {
+ "operandsNotSame", operandsNotSame
+ }
+ ,
+ {
+ "operandsNotSame3", operandsNotSame3
+ }
+ ,
+ {
+ "operandsNotSame4", operandsNotSame4
+ }
+ ,
+ {
+ "operandsNotSame5", operandsNotSame5
+ }
+ ,
+ {
+ "operandsNotSame6", operandsNotSame6
+ }
+ ,
+ {
+ "operandsNotSame7", operandsNotSame7
+ }
+ ,
+ {
+ "operandsNotSame8", operandsNotSame8
+ }
+ ,
+ {
+ "24bitMode", flat24bitMode
+ }
+ ,
+ {
+ "xramMovcOption", xramMovcOption
+ }
+ ,
+ {
+ "labelRefCount", labelRefCount
+ }
+ ,
+ {
+ "portIsDS390", portIsDS390
+ },
+ {
+ "labelIsReturnOnly", labelIsReturnOnly
+ },
+ {
+ "okToRemoveSLOC", okToRemoveSLOC
+ },
+ {
+ "24bitModeAndPortDS390", flat24bitModeAndPortDS390
+ }
+ };
+ int i;
+ char *cmdCopy, *funcName, *funcArgs;
+ int rc = -1;
+
+ /* Isolate the function name part (we are passed the full condition
+ * string including arguments)
+ */
+ cmdCopy = Safe_strdup(fname);
+ funcName = strtok(cmdCopy, " \t");
+ funcArgs = strtok(NULL, "");
+
+ for (i = 0; i < ((sizeof (ftab)) / (sizeof (struct ftab))); i++)
+ {
+ if (strcmp (ftab[i].fname, funcName) == 0)
+ {
+ rc = (*ftab[i].func) (vars, currPl, endPl, head,
+ funcArgs);
+ }
+ }
+
+ Safe_free(cmdCopy);
+
+ if (rc == -1)
+ {
+ fprintf (stderr,
+ "could not find named function \"%s\" in "
+ "peephole function table\n",
+ funcName);
+ // If the function couldn't be found, let's assume it's
+ // a bad rule and refuse it.
+ rc = FALSE;
+ }
+
+ return rc;
+}