X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fpic%2Fpcodepeep.c;h=f041796a8831bfe6c60219dff63b8ee535e0a84e;hb=d9a3555b8dd102f049b6a3ce6b06150d6e4a3f79;hp=7b0d7c801d1b3768cdca87edca13b0e688f72e0c;hpb=08dd337046c6cfa728572976d1a23d3ea5654da6;p=fw%2Fsdcc diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index 7b0d7c80..f041796a 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -28,12 +28,6 @@ #include "pcodeflow.h" #include "ralloc.h" -#if defined(__BORLANDC__) || defined(_MSC_VER) -#define STRCASECMP stricmp -#else -#define STRCASECMP strcasecmp -#endif - pCodeOp *popCopyGPR2Bit(pCodeOpReg *pc, int bitval); pCodeOp *popRegFromString(char *str, int size, int offset); @@ -259,7 +253,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 +284,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 +739,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 +780,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 +1485,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 +1496,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 +1987,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 +2005,7 @@ int pCodePeepMatchRule(pCode *pc) /* Unlink the original code */ + pcout = pc; pcprev = pc->prev; pcprev->next = pcin; if(pcin) @@ -2087,8 +2082,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:")); @@ -2100,20 +2094,37 @@ int pCodePeepMatchRule(pCode *pc) /* We have just replaced the inefficient code with the rule. * Now, we need to re-add the C-source symbols if there are any */ pc = pcprev; - while(pc_cline ) { + while(pc && pc_cline ) { pc = findNextInstruction(pc->next); + if (!pc) break; PCI(pc)->cline = pc_cline; pc_cline = PCCS(pc_cline->pc.next); } + /* Copy C code comments to new code. */ + pc = pcprev->next; + if (pc) { + for (; pc && 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; + } + 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; }