pCode peep rule comparison was ignoring labels when operands were wild cards. (Report...
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 3 Oct 2001 08:04:13 +0000 (08:04 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 3 Oct 2001 08:04:13 +0000 (08:04 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1346 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/pcodepeep.c

index e23e667c712b5bc5cc9a53aeb1d25f57ae7f7056..2f1fd188bd1f07c57117b28d4fb692e275a923d0 100644 (file)
@@ -1474,6 +1474,45 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond)
 
   return 0;
 }
+
+int pCodePeepMatchLabels(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
+{
+  int labindex;
+
+  /* Check for a label associated with this wild pCode */
+  // If the wild card has a label, make sure the source code does too.
+  if(pcd->label) {
+    pCode *pcl;
+
+    if(!pcs->label)
+      return 0;
+
+    pcl = pcd->label->pc;
+    //labindex = PCOW(pcl)->id;
+    labindex = -PCL(pcl)->key;
+    fprintf(stderr,"label id = %d (labindex = %d)\n",PCL(pcl)->key,labindex);
+    if(peepBlock->vars[labindex] == NULL) {
+      // First time to encounter this label
+      peepBlock->vars[labindex] = PCL(pcs->label->pc)->label;
+      fprintf(stderr,"first time for a label: %d %s\n",labindex, peepBlock->vars[labindex]);
+    } else {
+      if(strcmp(peepBlock->vars[labindex],PCL(pcs->label->pc)->label) != 0) {
+       fprintf(stderr,"labels don't match\n");
+       return 0;
+      }
+      fprintf(stderr,"matched a label\n");
+    }
+  } else {
+    fprintf(stderr,"destination doesn't have a label\n");
+
+    if(pcs->label)
+      return 0;
+  }
+
+  return 1;
+    
+}
+
 /*-----------------------------------------------------------------*/
 /* pCodePeepMatchLine - Compare source and destination pCodes to   */
 /*                      see they're the same.                      */
@@ -1517,6 +1556,9 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
       pcs->print(stderr,pcs);
       pcd->print(stderr,pcd);
 
+      if(!pCodePeepMatchLabels(peepBlock, pcs, pcd))
+       return 0;
+
       /* Compare the operands */
       if(PCI(pcd)->pcop) {
        if (PCI(pcd)->pcop->type == PO_WILD) {
@@ -1564,7 +1606,6 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 
   if((pcd->type == PC_WILD) && (pcs->type == PC_OPCODE)) {
 
-    int labindex;
 
     index = PCW(pcd)->id;
 
@@ -1574,31 +1615,8 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
 
     peepBlock->wildpCodes[PCW(pcd)->id] = pcs;
 
-    /* Check for a label associated with this wild pCode */
-    // If the wild card has a label, make sure the source code does too.
-    if(pcd->label) {
-      pCode *pcl;
-
-      if(!pcs->label)
-       return 0;
-
-      pcl = pcd->label->pc;
-      //labindex = PCOW(pcl)->id;
-      labindex = -PCL(pcl)->key;
-      fprintf(stderr,"label id = %d (labindex = %d)\n",PCL(pcl)->key,labindex);
-      if(peepBlock->vars[labindex] == NULL) {
-       // First time to encounter this label
-       peepBlock->vars[labindex] = PCL(pcs->label->pc)->label;
-       fprintf(stderr,"first time for a label: %d %s\n",labindex, peepBlock->vars[labindex]);
-      } else {
-       if(strcmp(peepBlock->vars[labindex],PCL(pcs->label->pc)->label) != 0) {
-         fprintf(stderr,"labels don't match\n");
-         return 0;
-       }
-       fprintf(stderr,"matched a label\n");
-      }
-    } else 
-      fprintf(stderr,"wild card doesn't have a label\n");
+    if(!pCodePeepMatchLabels(peepBlock, pcs, pcd))
+      return 0;
 
     if(PCW(pcd)->operand) {
       PCOW(PCI(pcd)->pcop)->matched = PCI(pcs)->pcop;