X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=src%2Fpic16%2Fpcodepeep.c;h=df2e34a9f4e388784fd86b75783f52a7580595fa;hb=0a72baf80db1e39860360d5ec42c1146c4fe68c5;hp=6660a28efebeb01bb6fb90ca297eb7dddac6d1ee;hpb=4e39e662bca4e52121166ee8f3b8dae33eb568d6;p=fw%2Fsdcc diff --git a/src/pic16/pcodepeep.c b/src/pic16/pcodepeep.c index 6660a28e..df2e34a9 100644 --- a/src/pic16/pcodepeep.c +++ b/src/pic16/pcodepeep.c @@ -276,7 +276,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) { @@ -307,14 +307,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(pic16_popCopyGPR2Bit(&pic16_pc_status,PIC_C_BIT)); - if(toupper(*bit) == 'Z') + if(toupper((unsigned char)*bit) == 'Z') return PCOP(pic16_popCopyGPR2Bit(&pic16_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(pic16_popCopyGPR2Bit(&pic16_pc_status,PIC_DC_BIT)); return NULL; @@ -962,15 +962,15 @@ static void tokenizeLineNode(char *ln) // fprintf(stderr, "%s:%d: processing %s\n", __FILE__, __LINE__, 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); @@ -1003,11 +1003,11 @@ static void tokenizeLineNode(char *ln) default: // hack to allow : goto $ - if(isalpha(*ln) || (*ln == '_') || (!parsing_peeps && (*ln == '$'))) { + if(isalpha((unsigned char)*ln) || (*ln == '_') || (!parsing_peeps && (*ln == '$'))) { char buffer[50]; int i=0; - while( (isalpha(*ln) || isdigit(*ln) || (*ln == '_') || (*ln == '$')) && i<49) + while( (isalpha((unsigned char)*ln) || isdigit((unsigned char)*ln) || (*ln == '_') || (*ln == '$')) && i<49) buffer[i++] = *ln++; ln--; @@ -1739,7 +1739,7 @@ int pic16_pCodeSearchCondition(pCode *pc, unsigned int cond) *-----------------------------------------------------------------*/ static int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) { - char b[50], *n2; + char b[1024], *n2; if(!pcops || !pcopd) return 0; @@ -1765,8 +1765,8 @@ static int pCodeOpCompare(pCodeOp *pcops, pCodeOp *pcopd) return 0; } - b[0]=0; - pic16_get_op(pcops,b,50); + memset(b, 0, sizeof(b) ); //b[0]=0; + pic16_get_op(pcops,b, sizeof(b) ); n2 = pic16_get_op(pcopd,NULL,0); @@ -2181,13 +2181,58 @@ pCodeOp *pic16_pCodeOpCopy(pCodeOp *pcop) return NULL; switch(pcop->type) { + case PO_NONE: + case PO_STR: + case PO_REL_ADDR: + pcopnew = Safe_calloc(1, sizeof (pCodeOp)); + memcpy(pcopnew, pcop, sizeof (pCodeOp)); + break; + + case PO_W: + case PO_WREG: + case PO_STATUS: + case PO_BSR: + case PO_FSR0: + case PO_INDF0: + case PO_INTCON: + case PO_GPR_REGISTER: + case PO_GPR_TEMP: + case PO_SFR_REGISTER: + case PO_PCL: + case PO_PCLATH: + case PO_PCLATU: + case PO_PRODL: + case PO_PRODH: + case PO_DIR: + //DFPRINTF((stderr,"pCodeOpCopy GPR register\n")); + /* XXX: might also be pCodeOpReg2 -- that's why the two structs are identical */ + pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) ); + memcpy (pcopnew, pcop, sizeof(pCodeOpReg)); + break; + + case PO_LITERAL: + //DFPRINTF((stderr,"pCodeOpCopy lit\n")); + /* XXX: might also be pCodeOpLit2, that's why the two structs are identical... */ + pcopnew = Safe_calloc(1,sizeof(pCodeOpLit) ); + memcpy (pcopnew, pcop, sizeof(pCodeOpLit)); + break; + + case PO_IMMEDIATE: + pcopnew = Safe_calloc(1,sizeof(pCodeOpImmd) ); + memcpy (pcopnew, pcop, sizeof(pCodeOpImmd)); + break; + + case PO_GPR_BIT: case PO_CRY: case PO_BIT: - //DFPRINTF((stderr,"pCodeOpCopy bit\n")); - pcopnew = Safe_calloc(1,sizeof(pCodeOpRegBit) ); - PCORB(pcopnew)->bit = PCORB(pcop)->bit; - PCORB(pcopnew)->inBitSpace = PCORB(pcop)->inBitSpace; + pcopnew = Safe_calloc(1, sizeof (pCodeOpRegBit)); + memcpy (pcopnew, pcop, sizeof (pCodeOpRegBit)); + break; + case PO_LABEL: + //DFPRINTF((stderr,"pCodeOpCopy label\n")); + pcopnew = Safe_calloc(1,sizeof(pCodeOpLabel) ); + memcpy (pcopnew, pcop, sizeof (pCodeOpLabel)); break; case PO_WILD: @@ -2202,84 +2247,14 @@ pCodeOp *pic16_pCodeOpCopy(pCodeOp *pcop) pcopnew->name = Safe_strdup(PCOW(pcop)->pcwb->vars[PCOW(pcop)->id]); //DFPRINTF((stderr,"copied a wild op named %s\n",pcopnew->name)); } - - return pcopnew; - break; - - case PO_LABEL: - //DFPRINTF((stderr,"pCodeOpCopy label\n")); - pcopnew = Safe_calloc(1,sizeof(pCodeOpLabel) ); - PCOLAB(pcopnew)->key = PCOLAB(pcop)->key; - break; - - case PO_IMMEDIATE: - pcopnew = Safe_calloc(1,sizeof(pCodeOpImmd) ); - PCOI(pcopnew)->index = PCOI(pcop)->index; - PCOI(pcopnew)->offset = PCOI(pcop)->offset; - PCOI(pcopnew)->_const = PCOI(pcop)->_const; - break; - - case PO_LITERAL: - //DFPRINTF((stderr,"pCodeOpCopy lit\n")); - pcopnew = Safe_calloc(1,sizeof(pCodeOpLit) ); - PCOL(pcopnew)->lit = PCOL(pcop)->lit; - break; - -#if 0 // mdubuc - To add - case PO_REL_ADDR: - break; -#endif - - case PO_GPR_BIT: - - pcopnew = pic16_newpCodeOpBit(pcop->name, PCORB(pcop)->bit,PCORB(pcop)->inBitSpace, PO_GPR_REGISTER); - PCOR(pcopnew)->r = PCOR(pcop)->r; - PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx; - DFPRINTF((stderr," pCodeOpCopy Bit -register index\n")); return pcopnew; break; - case PO_GPR_REGISTER: - case PO_GPR_TEMP: - case PO_FSR0: - case PO_INDF0: - //DFPRINTF((stderr,"pCodeOpCopy GPR register\n")); - pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) ); - PCOR(pcopnew)->r = PCOR(pcop)->r; - PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx; - PCOR(pcopnew)->instance = PCOR(pcop)->instance; - DFPRINTF((stderr," register index %d\n", PCOR(pcop)->r->rIdx)); - break; - - case PO_DIR: - //fprintf(stderr,"pCodeOpCopy PO_DIR\n"); - pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) ); - PCOR(pcopnew)->r = PCOR(pcop)->r; - PCOR(pcopnew)->rIdx = PCOR(pcop)->rIdx; - PCOR(pcopnew)->instance = PCOR(pcop)->instance; - break; - case PO_STATUS: - DFPRINTF((stderr,"pCodeOpCopy PO_STATUS\n")); - case PO_BSR: - DFPRINTF((stderr,"pCodeOpCopy PO_BSR\n")); - case PO_SFR_REGISTER: - case PO_STR: - case PO_NONE: - case PO_W: - case PO_WREG: - case PO_INTCON: - case PO_PCL: - case PO_PCLATH: - case PO_PCLATU: - case PO_PRODL: - case PO_PRODH: - case PO_REL_ADDR: - //DFPRINTF((stderr,"pCodeOpCopy register type %d\n", pcop->type)); - pcopnew = Safe_calloc(1,sizeof(pCodeOp) ); - - } + default: + assert ( !"unhandled pCodeOp type copied" ); + } // switch - pcopnew->type = pcop->type; + /* strdup pcop->name (prevent access to shared but released memory) */ if(pcop->name) pcopnew->name = Safe_strdup(pcop->name); else @@ -2435,16 +2410,16 @@ int pic16_pCodePeepMatchRule(pCode *pc) pcin->prev = pc->prev; -#if 0 +#if 1 { /* DEBUG */ /* Converted the deleted pCodes into comments */ - char buf[256]; + char buf[1024]; pCodeCSource *pc_cline2=NULL; - buf[0] = ';'; - buf[1] = '#'; +// buf[0] = ';'; + buf[0] = '#'; while(pc && pc!=pcin) { @@ -2458,7 +2433,7 @@ int pic16_pCodePeepMatchRule(pCode *pc) } } - pic16_pCode2str(&buf[2], 254, pc); + pic16_pCode2str(&buf[1], sizeof( buf )-1, pc); pic16_pCodeInsertAfter(pcprev, pic16_newpCodeCharP(buf)); pcprev = pcprev->next; pc = pc->next;