From 3d52c3ce875275edab67f3ef3e287edc7a58f258 Mon Sep 17 00:00:00 2001 From: sdattalo Date: Wed, 3 Oct 2001 08:04:13 +0000 Subject: [PATCH] pCode peep rule comparison was ignoring labels when operands were wild cards. (Reported by Ralf Forsberg.) git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1346 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/pic/pcodepeep.c | 70 ++++++++++++++++++++++++++++----------------- 1 file changed, 44 insertions(+), 26 deletions(-) diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index e23e667c..2f1fd188 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -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; -- 2.30.2