* as/hc08/lkaomf51.c (OutputName): made name unsigned char,
[fw/sdcc] / src / pic / pcodepeep.c
index 7b0d7c801d1b3768cdca87edca13b0e688f72e0c..6c6c47205bbd4629a713997338cb6da3dfcf2482 100644 (file)
@@ -259,7 +259,7 @@ static int cvt_extract_destination(parsedPattern *pp)
                
                // just check first letter for now
                
-               if(toupper(*pp->pct[0].tok.s) == 'F')
+               if(toupper((unsigned char)*pp->pct[0].tok.s) == 'F')
                        return 1;
                
        } else if (pp->pct[0].tt == PCT_NUMBER) {
@@ -290,14 +290,14 @@ static pCodeOp *cvt_extract_status(char *reg, char *bit)
        
        if(len == 1) {
                // check C,Z
-               if(toupper(*bit) == 'C')
+               if(toupper((unsigned char)*bit) == 'C')
                        return PCOP(popCopyGPR2Bit(&pc_status,PIC_C_BIT));
-               if(toupper(*bit) == 'Z')
+               if(toupper((unsigned char)*bit) == 'Z')
                        return PCOP(popCopyGPR2Bit(&pc_status,PIC_Z_BIT));
        }
        
        // Check DC
-       if(len ==2 && toupper(bit[0]) == 'D' && toupper(bit[1]) == 'C')
+       if(len ==2 && toupper((unsigned char)bit[0]) == 'D' && toupper((unsigned char)bit[1]) == 'C')
                return PCOP(popCopyGPR2Bit(&pc_status,PIC_DC_BIT));
        
        return NULL;
@@ -745,15 +745,15 @@ static void tokenizeLineNode(char *ln)
        
        while(*ln) {
                
-               if(isspace(*ln)) {
+               if(isspace((unsigned char)*ln)) {
                        // add a SPACE token and eat the extra spaces.
                        tokArr[tokIdx++].tt = PCT_SPACE;
-                       while (isspace (*ln))
+                       while (isspace ((unsigned char)*ln))
                                ln++;
                        continue;
                }
                
-               if(isdigit(*ln)) {
+               if(isdigit((unsigned char)*ln)) {
                        
                        tokArr[tokIdx].tt = PCT_NUMBER;
                        tokArr[tokIdx++].tok.n = strtol(ln, &ln, 0);
@@ -786,11 +786,11 @@ static void tokenizeLineNode(char *ln)
                        
                        
                default:
-                       if(isalpha(*ln) || (*ln == '_') ) {
+                       if(isalpha((unsigned char)*ln) || (*ln == '_') ) {
                                char buffer[50];
                                int i=0;
                                
-                               while( (isalpha(*ln)  ||  isdigit(*ln) || (*ln == '_')) && i<49)
+                               while( (isalpha((unsigned char)*ln) || isdigit((unsigned char)*ln) || (*ln == '_')) && i<49)
                                        buffer[i++] = *ln++;
                                
                                ln--;
@@ -1491,7 +1491,7 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond, int contIfSkip)
                        if(PCI(pc)->inCond & cond) {
                                if (contIfSkip) {
                                        /* If previous instruction is a skip then continue search as condiction is not certain */
-                                       pCode *pcp = findPrevInstruction(pc);
+                                       pCode *pcp = findPrevInstruction(pc->prev);
                                        if (pcp && !isPCI_SKIP(pcp)) {
                                                return 1;
                                        }
@@ -1502,7 +1502,7 @@ int pCodeSearchCondition(pCode *pc, unsigned int cond, int contIfSkip)
                        if(PCI(pc)->outCond & cond) {
                                if (contIfSkip) {
                                        /* If previous instruction is a skip then continue search as condiction is not certain */
-                                       pCode *pcp = findPrevInstruction(pc);
+                                       pCode *pcp = findPrevInstruction(pc->prev);
                                        if (pcp && !isPCI_SKIP(pcp)) {
                                                return -1;
                                        }
@@ -1993,7 +1993,7 @@ int pCodePeepMatchRule(pCode *pc)
                if(matched) {
                        
                        pCode *pcprev;
-                       pCode *pcr;
+                       pCode *pcr, *pcout;
                        
                        
                        /* We matched a rule! Now we have to go through and remove the
@@ -2011,6 +2011,7 @@ int pCodePeepMatchRule(pCode *pc)
                        
                        
                        /* Unlink the original code */
+                       pcout = pc;
                        pcprev = pc->prev;
                        pcprev->next = pcin;
                        if(pcin) 
@@ -2087,8 +2088,7 @@ int pCodePeepMatchRule(pCode *pc)
                                } else if (pcr->type == PC_COMMENT) {
                                        pCodeInsertAfter(pc, newpCodeCharP( ((pCodeComment *)(pcr))->comment));
                                }
-                               
-                               
+
                                pc = pc->next;
 #ifdef PCODE_DEBUG
                                DFPRINTF((stderr,"  NEW Code:"));
@@ -2108,12 +2108,27 @@ int pCodePeepMatchRule(pCode *pc)
                                
                        }
                        
+                       /* Copy C code comments to new code. */
+                       pc = pcprev->next;
+                       if (pc) {
+                               for (; pcout!=pcin; pcout=pcout->next) {
+                                       if (pcout->type==PC_OPCODE && PCI(pcout)->cline) {
+                                               while (pc->type!=PC_OPCODE || PCI(pc)->cline) {
+                                                       pc = pc->next;
+                                                       if (!pc)
+                                                               break;
+                                               }
+                                               PCI(pc)->cline = PCI(pcout)->cline;
+                                       }
+                               }
+                       }
+                               
                        return 1;
-       }
+               }
 next_rule:
-       peeprules = peeprules->next;
-  }
-  DFPRINTF((stderr," no rule matched\n"));
+               peeprules = peeprules->next;
+       }
+       DFPRINTF((stderr," no rule matched\n"));
 
-  return 0;
+       return 0;
 }