From d7e7311293ec997e4d6cdf4d05bb91100458d460 Mon Sep 17 00:00:00 2001 From: sdattalo Date: Wed, 7 Aug 2002 13:13:47 +0000 Subject: [PATCH] Added regression tests for compound comparisons. -- Fixed several bugs associated with compound compares: e.g. x = (a != b); (At least 4 people reported this) -- Fixed bug associated with an empty main block (Reported by Ralf Forsberg) -- Bank selection was handled improperly for CALL's (Reported by Matt W. at solid-state-logic) -- For the PIC port, declaring variables at absolute addresses no longer automatically makes the variable volatile. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2052 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCsymt.c | 13 ++- src/pic/device.c | 7 +- src/pic/gen.c | 192 +++++++++++++++++++++++---------------- src/pic/genarith.c | 38 +++++--- src/pic/pcode.c | 108 ++++++++++++++++------ src/pic/pcodepeep.c | 8 +- src/pic/ralloc.c | 52 ++++++++++- src/regression/Makefile | 2 + src/regression/bool2.c | 51 +++++++++++ src/regression/bool3.c | 73 +++++++++++++++ src/regression/string1.c | 2 +- 11 files changed, 420 insertions(+), 126 deletions(-) create mode 100644 src/regression/bool2.c create mode 100644 src/regression/bool3.c diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index b19179fc..2721c1d8 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -1173,10 +1173,17 @@ checkSClass (symbol * sym, int isProto) } /* if absolute address given then it mark it as - volatile */ - if (IS_ABSOLUTE (sym->etype)) - SPEC_VOLATILE (sym->etype) = 1; + volatile -- except in the PIC port */ + +#if !OPT_DISABLE_PIC + /* The PIC port uses a different peep hole optimizer based on "pCode" */ + if (!TARGET_IS_PIC) +#endif + + if (IS_ABSOLUTE (sym->etype)) + SPEC_VOLATILE (sym->etype) = 1; + /* global variables declared const put into code */ /* if no other storage class specified */ if (sym->level == 0 && diff --git a/src/pic/device.c b/src/pic/device.c index ad21be45..ee12eb5d 100644 --- a/src/pic/device.c +++ b/src/pic/device.c @@ -484,7 +484,7 @@ int assignRegister(regs *reg, int start_address) if(reg->isFixed) { if (validAddress(reg->address,reg->size)) { - fprintf(stderr,"%s - %s address = 0x%03x\n",__FUNCTION__,reg->name, reg->address); + //fprintf(stderr,"%s - %s address = 0x%03x\n",__FUNCTION__,reg->name, reg->address); mapRegister(reg); return reg->address; } @@ -493,8 +493,9 @@ int assignRegister(regs *reg, int start_address) mapRegister(reg); return reg->address; } - fprintf(stderr, "WARNING: Ignoring Out of Range register assignment at fixed address %d, %s\n", - reg->address, reg->name); + + //fprintf(stderr, "WARNING: Ignoring Out of Range register assignment at fixed address %d, %s\n", + // reg->address, reg->name); } else { diff --git a/src/pic/gen.c b/src/pic/gen.c index 0df7a930..3cdfcfb5 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -1112,11 +1112,11 @@ char *aopGet (asmop *aop, int offset, bool bit16, bool dname) return rs; case AOP_STR: - DEBUGpic14_emitcode(";","%d",__LINE__); aop->coff = offset ; if (strcmp(aop->aopu.aop_str[offset],"a") == 0 && dname) return "acc"; + DEBUGpic14_emitcode(";","%d - %s",__LINE__, aop->aopu.aop_str[offset]); return aop->aopu.aop_str[offset]; @@ -2951,7 +2951,7 @@ static void genEndFunction (iCode *ic) emitpcode(POC_SWAPFW, popCopyReg(&pc_ssave)); emitpcode(POC_MOVWF, popCopyReg(&pc_status)); emitpcode(POC_SWAPF, popCopyReg(&pc_wsave)); - emitpcode(POC_MOVFW, popCopyReg(&pc_wsave)); + emitpcode(POC_SWAPFW, popCopyReg(&pc_wsave)); addpCode2pBlock(pb,newpCodeLabel("END_OF_INTERRUPT",-1)); emitpcodeNULLop(POC_RETFIE); @@ -4394,7 +4394,7 @@ static void genCmp (operand *left,operand *right, } - check_carry: + // check_carry: if (AOP_TYPE(result) == AOP_CRY && AOP_SIZE(result)) { DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); pic14_outBitC(result); @@ -4529,13 +4529,16 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) { int size = max(AOP_SIZE(left),AOP_SIZE(right)); int offset = 0; + int res_offset = 0; /* the result may be a different size then left or right */ + int res_size = AOP_SIZE(result); resolvedIfx rIfx; symbol *lbl; unsigned long lit = 0L; DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - DEBUGpic14_AopType(__LINE__,left,right,NULL); - + DEBUGpic14_AopType(__LINE__,left,right,result); + if(result) + DEBUGpic14_emitcode ("; ***","%s %d result is not null",__FUNCTION__,__LINE__); resolveIfx(&rIfx,ifx); lbl = newiTempLabel(NULL); @@ -4573,6 +4576,8 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) emitSKPNZ; emitpcode(POC_GOTO,popGetLabel(lbl->key)); offset++; + if(res_offset < res_size-1) + res_offset++; lit >>= 8; } break; @@ -4585,71 +4590,90 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) AOP_TYPE(right) == AOP_DIR || (AOP_TYPE(left) == AOP_DIR && AOP_TYPE(right) == AOP_LIT) || (IS_AOP_PREG(left) && !IS_AOP_PREG(right))) { - switch(size) { - case 2: - genc16bit2lit(left, lit, 0); - emitSKPNZ; - emitpcode(POC_GOTO,popGetLabel(lbl->key)); - break; - default: - while (size--) { - int emit_skip=1; - if((AOP_TYPE(left) == AOP_DIR) && - ((AOP_TYPE(right) == AOP_REG) || (AOP_TYPE(right) == AOP_DIR))) { + //int lbl_key = (rIfx.condition) ? rIfx.lbl->key : lbl->key; + int lbl_key = lbl->key; + + if(result) { + emitpcode(POC_CLRF,popGet(AOP(result),res_offset)); + //emitpcode(POC_INCF,popGet(AOP(result),res_offset)); + }else { + DEBUGpic14_emitcode ("; ***","%s %d -- ERROR",__FUNCTION__,__LINE__); + fprintf(stderr, "%s %d error - expecting result to be non_null\n", + __FUNCTION__,__LINE__); + return; + } - emitpcode(POC_MOVFW,popGet(AOP(left),offset)); - emitpcode(POC_XORFW,popGet(AOP(right),offset)); +/* switch(size) { */ +/* case 2: */ +/* genc16bit2lit(left, lit, 0); */ +/* emitSKPNZ; */ +/* emitpcode(POC_GOTO,popGetLabel(lbl->key)); */ +/* break; */ +/* default: */ + while (size--) { + int emit_skip=1; + if((AOP_TYPE(left) == AOP_DIR) && + ((AOP_TYPE(right) == AOP_REG) || (AOP_TYPE(right) == AOP_DIR))) { - } else if((AOP_TYPE(left) == AOP_DIR) && (AOP_TYPE(right) == AOP_LIT)){ + emitpcode(POC_MOVFW,popGet(AOP(left),offset)); + emitpcode(POC_XORFW,popGet(AOP(right),offset)); + + } else if((AOP_TYPE(left) == AOP_DIR) && (AOP_TYPE(right) == AOP_LIT)){ - switch (lit & 0xff) { - case 0: - emitpcode(POC_MOVFW,popGet(AOP(left),offset)); - break; - case 1: - emitpcode(POC_DECFSZ,popGet(AOP(left),offset)); - emitpcode(POC_GOTO,popGetLabel(lbl->key)); - emit_skip=0; - break; - case 0xff: - emitpcode(POC_INCFSZ,popGet(AOP(left),offset)); - emitpcode(POC_GOTO,popGetLabel(lbl->key)); - emit_skip=0; - break; - default: - emitpcode(POC_MOVFW,popGet(AOP(left),offset)); - emitpcode(POC_XORLW,popGetLit(lit & 0xff)); - } - lit >>= 8; + switch (lit & 0xff) { + case 0: + emitpcode(POC_MOVFW,popGet(AOP(left),offset)); + break; + case 1: + emitpcode(POC_DECFSZW,popGet(AOP(left),offset)); + emitpcode(POC_INCF,popGet(AOP(result),res_offset)); + //emitpcode(POC_GOTO,popGetLabel(lbl->key)); + emit_skip=0; + break; + case 0xff: + emitpcode(POC_INCFSZW,popGet(AOP(left),offset)); + //emitpcode(POC_INCF,popGet(AOP(result),res_offset)); + //emitpcode(POC_INCFSZW,popGet(AOP(left),offset)); + emitpcode(POC_GOTO,popGetLabel(lbl_key)); + emit_skip=0; + break; + default: + emitpcode(POC_MOVFW,popGet(AOP(left),offset)); + emitpcode(POC_XORLW,popGetLit(lit & 0xff)); + } + lit >>= 8; + } else { + emitpcode(POC_MOVF,popGet(AOP(left),offset)); + } + if(emit_skip) { + if(AOP_TYPE(result) == AOP_CRY) { + pic14_emitcode(";***","%s %d",__FUNCTION__,__LINE__); + if(rIfx.condition) + emitSKPNZ; + else + emitSKPZ; + emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key)); } else { - emitpcode(POC_MOVF,popGet(AOP(left),offset)); - } - if(emit_skip) { - if(AOP_TYPE(result) == AOP_CRY) { - pic14_emitcode(";***","%s %d",__FUNCTION__,__LINE__); - if(rIfx.condition) - emitSKPNZ; - else - emitSKPZ; - emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key)); - } else { - /* fix me. probably need to check result size too */ - emitpcode(POC_CLRF,popGet(AOP(result),0)); - if(rIfx.condition) - emitSKPNZ; - else - emitSKPZ; - emitpcode(POC_INCF,popGet(AOP(result),0)); - } - if(ifx) - ifx->generated=1; + /* fix me. probably need to check result size too */ + //emitpcode(POC_CLRF,popGet(AOP(result),0)); + if(rIfx.condition) + emitSKPZ; + else + emitSKPNZ; + emitpcode(POC_GOTO,popGetLabel(lbl_key)); + //emitpcode(POC_INCF,popGet(AOP(result),res_offset)); } - emit_skip++; - offset++; + if(ifx) + ifx->generated=1; } - break; + emit_skip++; + offset++; + if(res_offset < res_size-1) + res_offset++; } +/* break; */ +/* } */ } else if(AOP_TYPE(right) == AOP_REG && AOP_TYPE(left) != AOP_DIR){ @@ -4663,6 +4687,8 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) emitSKPZ; emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key)); offset++; + if(res_offset < res_size-1) + res_offset++; } }else{ @@ -4676,8 +4702,15 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx) offset++; } } + + emitpcode(POC_INCF,popGet(AOP(result),res_offset)); + if(!rIfx.condition) + emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key)); + emitpLabel(lbl->key); + DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); + if(ifx) ifx->generated = 1; } @@ -4964,6 +4997,7 @@ static void genCmpEq (iCode *ic, iCode *ifx) pic14_outBitC(result); } else { + DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); gencjne(left,right,result,ifx); /* if(ifx) @@ -5050,7 +5084,7 @@ static iCode *ifxForOp ( operand *op, iCode *ic ) static void genAndOp (iCode *ic) { operand *left,*right, *result; - symbol *tlbl; +/* symbol *tlbl; */ DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); /* note here that && operations that are in an @@ -5060,20 +5094,26 @@ static void genAndOp (iCode *ic) aopOp((right=IC_RIGHT(ic)),ic,FALSE); aopOp((result=IC_RESULT(ic)),ic,FALSE); + DEBUGpic14_AopType(__LINE__,left,right,result); + + emitpcode(POC_MOVFW,popGet(AOP(left),0)); + emitpcode(POC_ANDFW,popGet(AOP(right),0)); + emitpcode(POC_MOVWF,popGet(AOP(result),0)); + /* if both are bit variables */ - if (AOP_TYPE(left) == AOP_CRY && - AOP_TYPE(right) == AOP_CRY ) { - pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir); - pic14_emitcode("anl","c,%s",AOP(right)->aopu.aop_dir); - pic14_outBitC(result); - } else { - tlbl = newiTempLabel(NULL); - pic14_toBoolean(left); - pic14_emitcode("jz","%05d_DS_",tlbl->key+100); - pic14_toBoolean(right); - pic14_emitcode("","%05d_DS_:",tlbl->key+100); - pic14_outBitAcc(result); - } +/* if (AOP_TYPE(left) == AOP_CRY && */ +/* AOP_TYPE(right) == AOP_CRY ) { */ +/* pic14_emitcode("mov","c,%s",AOP(left)->aopu.aop_dir); */ +/* pic14_emitcode("anl","c,%s",AOP(right)->aopu.aop_dir); */ +/* pic14_outBitC(result); */ +/* } else { */ +/* tlbl = newiTempLabel(NULL); */ +/* pic14_toBoolean(left); */ +/* pic14_emitcode("jz","%05d_DS_",tlbl->key+100); */ +/* pic14_toBoolean(right); */ +/* pic14_emitcode("","%05d_DS_:",tlbl->key+100); */ +/* pic14_outBitAcc(result); */ +/* } */ freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE)); freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE)); diff --git a/src/pic/genarith.c b/src/pic/genarith.c index 9bdf0bd3..241ca2f3 100644 --- a/src/pic/genarith.c +++ b/src/pic/genarith.c @@ -738,34 +738,50 @@ static void genAddLit (iCode *ic, int lit) } } else { + int clear_carry=0; /* left is not the accumulator */ if(lit & 0xff) { emitpcode(POC_MOVLW, popGetLit(lit & 0xff)); emitpcode(POC_ADDFW, popGet(AOP(left),0)); - } else + } else { emitpcode(POC_MOVFW, popGet(AOP(left),0)); - + /* We don't know the state of the carry bit at this point */ + clear_carry = 1; + } //emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE)); emitMOVWF(result,0); - lit >>= 8; while(--size) { + lit >>= 8; if(lit & 0xff) { - emitpcode(POC_MOVLW, popGetLit(lit & 0xff)); - //emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE)); - emitMOVWF(result,offset); - emitpcode(POC_MOVFW, popGet(AOP(left),offset)); - emitSKPNC; - emitpcode(POC_INCFSZW,popGet(AOP(left),offset)); - emitpcode(POC_ADDWF, popGet(AOP(result),offset)); + if(clear_carry) { + /* The ls byte of the lit must've been zero - that + means we don't have to deal with carry */ + + emitpcode(POC_MOVLW, popGetLit(lit & 0xff)); + emitpcode(POC_ADDFW, popGet(AOP(left),offset)); + emitpcode(POC_MOVWF, popGet(AOP(left),offset)); + + clear_carry = 0; + + } else { + emitpcode(POC_MOVLW, popGetLit(lit & 0xff)); + //emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE)); + emitMOVWF(result,offset); + emitpcode(POC_MOVFW, popGet(AOP(left),offset)); + emitSKPNC; + emitpcode(POC_INCFSZW,popGet(AOP(left),offset)); + emitpcode(POC_ADDWF, popGet(AOP(result),offset)); + } + } else { emitpcode(POC_CLRF, popGet(AOP(result),offset)); emitpcode(POC_RLF, popGet(AOP(result),offset)); emitpcode(POC_MOVFW, popGet(AOP(left),offset)); emitpcode(POC_ADDWF, popGet(AOP(result),offset)); } - offset++; + offset++; } } } diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 066ad633..83f9737b 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -1931,7 +1931,7 @@ pCode *newpCodeLabel(char *name, int key) if(s) pcl->label = Safe_strdup(s); - + //fprintf(stderr,"newpCodeLabel: key=%d, name=%s\n",key, ((s)?s:"")); return ( (pCode *)pcl); } @@ -2007,6 +2007,7 @@ pCodeOp *newpCodeOpLabel(char *name, int key) ((pCodeOpLabel *)pcop)->key = key; + //fprintf(stderr,"newpCodeOpLabel: key=%d, name=%s\n",key,((s)?s:"")); return pcop; } @@ -3690,7 +3691,9 @@ void LinkFlow(pBlock *pb) if( (pct = findLabelinpBlock(pb,pcol)) != NULL) LinkFlow_pCode(PCI(pc),PCI(pct)); else - fprintf(stderr, "ERROR: %s, couldn't find label\n",__FUNCTION__); + fprintf(stderr, "ERROR: %s, couldn't find label. key=%d,lab=%s\n", + __FUNCTION__,pcol->key,((PCOP(pcol)->name)?PCOP(pcol)->name:"-")); + //fprintf(stderr,"newpCodeOpLabel: key=%d, name=%s\n",key,((s)?s:"")); continue; } @@ -3875,7 +3878,6 @@ void FixRegisterBankingInFlow(pCodeFlow *pcfl, int cur_bank) while(isPCinFlow(pc,PCODE(pcfl))) { - reg = getRegFromInstruction(pc); #if 0 if(reg) { @@ -3885,15 +3887,23 @@ void FixRegisterBankingInFlow(pCodeFlow *pcfl, int cur_bank) } #endif - if(reg && REG_BANK(reg)!=cur_bank) { + if((reg && REG_BANK(reg)!=cur_bank) || + ((PCI(pc)->op == POC_CALL) && (cur_bank != 0) )) { + /* Examine the instruction before this one to make sure it is * not a skip type instruction */ pcprev = findPrevpCode(pc->prev, PC_OPCODE); + if(!pcprev || (pcprev && !isPCI_SKIP(pcprev))) { - int b = cur_bank ^ REG_BANK(reg); + int b; + int reg_bank; + + reg_bank = (reg) ? REG_BANK(reg) : 0; + + b = cur_bank ^ reg_bank; //fprintf(stderr, "Cool! can switch banks\n"); - cur_bank = REG_BANK(reg); + cur_bank = reg_bank; switch(b & 3) { case 0: break; @@ -3911,20 +3921,6 @@ void FixRegisterBankingInFlow(pCodeFlow *pcfl, int cur_bank) } else insertBankSwitch(0, pc, -1, -1); break; - /* - new_pc = newpCode(((cur_bank&1) ? POC_BSF : POC_BCF), - popCopyGPR2Bit(PCOP(&pc_status),PIC_RP0_BIT)); - pCodeInsertAfter(pc->prev, new_pc); - if(PCI(pc)->label) { - PCI(new_pc)->label = PCI(pc)->label; - PCI(pc)->label = NULL; - } - */ - /* - new_pc = newpCode(((cur_bank&1) ? POC_BCF : POC_BSF), - popCopyGPR2Bit(PCOP(&pc_status),PIC_RP0_BIT)); - pCodeInsertAfter(pc, new_pc); - */ } @@ -4270,6 +4266,8 @@ pCode * findInstructionUsingLabel(pCodeLabel *pcl, pCode *pcs) void exchangeLabels(pCodeLabel *pcl, pCode *pc) { + char *s=NULL; + if(isPCI(pc) && (PCI(pc)->pcop) && (PCI(pc)->pcop->type == PO_LABEL)) { @@ -4280,9 +4278,19 @@ void exchangeLabels(pCodeLabel *pcl, pCode *pc) if(pcol->pcop.name) free(pcol->pcop.name); - sprintf(buffer,"_%05d_DS_",pcl->key); - - pcol->pcop.name = Safe_strdup(buffer); + /* If the key is negative, then we (probably) have a label to + * a function and the name is already defined */ + + if(pcl->key>0) + sprintf(s=buffer,"_%05d_DS_",pcl->key); + else + s = pcl->label; + + //sprintf(buffer,"_%05d_DS_",pcl->key); + if(!s) { + fprintf(stderr, "ERROR %s:%d function label is null\n",__FUNCTION__,__LINE__); + } + pcol->pcop.name = Safe_strdup(s); pcol->key = pcl->key; //pc->print(stderr,pc); @@ -4537,16 +4545,23 @@ void FixRegisterBanking(pBlock *pb) } #endif - if(reg && REG_BANK(reg)!=cur_bank) { - //fprintf(stderr,"need to switch banks\n"); + + if((reg && REG_BANK(reg)!=cur_bank) || + ((PCI(pc)->op == POC_CALL) && (cur_bank != 0) )) { + /* Examine the instruction before this one to make sure it is * not a skip type instruction */ pcprev = findPrevpCode(pc->prev, PC_OPCODE); + if(!pcprev || (pcprev && !isPCI_SKIP(pcprev))) { - int b = cur_bank ^ REG_BANK(reg); + int b; + int reg_bank; - cur_bank = REG_BANK(reg); + reg_bank = (reg) ? REG_BANK(reg) : 0; + + b = cur_bank ^ reg_bank; + cur_bank = reg_bank; switch(b & 3) { case 0: break; @@ -4567,7 +4582,6 @@ void FixRegisterBanking(pBlock *pb) } - }else { //fprintf(stderr, "Bummer can't switch banks\n"); ; @@ -4628,6 +4642,44 @@ void FixRegisterBanking(pBlock *pb) } + + + +#if 0 + if(reg && REG_BANK(reg)!=cur_bank) { + //fprintf(stderr,"need to switch banks\n"); + /* Examine the instruction before this one to make sure it is + * not a skip type instruction */ + pcprev = findPrevpCode(pc->prev, PC_OPCODE); + if(!pcprev || (pcprev && !isPCI_SKIP(pcprev))) { + int b = cur_bank ^ REG_BANK(reg); + + cur_bank = REG_BANK(reg); + + switch(b & 3) { + case 0: + break; + case 1: + insertBankSwitch(0, pc, cur_bank&1, PIC_RP0_BIT); + break; + case 2: + insertBankSwitch(0, pc, cur_bank&2, PIC_RP1_BIT); + insertBankSwitch(0, pc, cur_bank&2, PIC_RP1_BIT); + break; + case 3: + if(cur_bank & 3) { + insertBankSwitch(0, pc, cur_bank&1, PIC_RP0_BIT); + insertBankSwitch(0, pc, cur_bank&2, PIC_RP1_BIT); + } else + insertBankSwitch(0, pc, -1, -1); + break; + + } +#endif + + + + void pBlockDestruct(pBlock *pb) { diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index 81aabf13..e6eea822 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -35,7 +35,7 @@ #endif pCodeOp *popCopyGPR2Bit(pCodeOpReg *pc, int bitval); - +pCodeOp *popRegFromString(char *str, int size, int offset); pCodeOp *newpCodeOpWild(int id, pCodeWildBlock *pcwb, pCodeOp *subtype); pCode *newpCodeWild(int pCodeID, pCodeOp *optional_operand, pCodeOp *optional_label); @@ -542,6 +542,12 @@ static void * cvt_altpat_mnem1b(void *pp,pCodeWildBlock *pcwb) } /*-----------------------------------------------------------------*/ +/* cvt_altpat_mnem2 */ +/* */ +/* pp[0] - mnem */ +/* pp[1] - var */ +/* pp[2] - comma */ +/* pp[3] - destination */ /*-----------------------------------------------------------------*/ static void * cvt_altpat_mnem2(void *pp,pCodeWildBlock *pcwb) { diff --git a/src/pic/ralloc.c b/src/pic/ralloc.c index 787b1b73..a920ac09 100644 --- a/src/pic/ralloc.c +++ b/src/pic/ralloc.c @@ -73,6 +73,7 @@ set *dynDirectBitRegs=NULL; set *dynInternalRegs=NULL; static hTab *dynDirectRegNames= NULL; +static hTab *regHash = NULL; /* a hash table containing ALL registers */ static int dynrIdx=0x20; static int rDirectIdx=0; @@ -661,7 +662,7 @@ allocDirReg (operand *op ) name, SPEC_ADDR ( OP_SYM_ETYPE(op))); */ } else { - //fprintf(stderr,"ralloc %s \n", name); + //fprintf(stderr,"ralloc:%d %s \n", __LINE__,name); reg = dirregWithName(name); } @@ -672,6 +673,7 @@ allocDirReg (operand *op ) /* if this is at an absolute address, then get the address. */ if (SPEC_ABSA ( OP_SYM_ETYPE(op)) ) { address = SPEC_ADDR ( OP_SYM_ETYPE(op)); + //fprintf(stderr,"reg %s is at an absolute address: 0x%03x\n",name,address); } /* Register wasn't found in hash, so let's create @@ -3390,6 +3392,45 @@ void printSymType(char * str, sym_link *sl) } +/*-----------------------------------------------------------------*/ +/* some debug code to print the symbol S_TYPE. Note that + * the function checkSClass in src/SDCCsymt.c dinks with + * the S_TYPE in ways the PIC port doesn't fully like...*/ +/*-----------------------------------------------------------------*/ +void isData(sym_link *sl) +{ + FILE *of = stderr; + + if(!sl) + return; + + if(debugF) + of = debugF; + + for ( ; sl; sl=sl->next) { + if(!IS_DECL(sl) ) { + switch (SPEC_SCLS(sl)) { + + case S_DATA: fprintf (of, "data "); break; + case S_XDATA: fprintf (of, "xdata "); break; + case S_SFR: fprintf (of, "sfr "); break; + case S_SBIT: fprintf (of, "sbit "); break; + case S_CODE: fprintf (of, "code "); break; + case S_IDATA: fprintf (of, "idata "); break; + case S_PDATA: fprintf (of, "pdata "); break; + case S_LITERAL: fprintf (of, "literal "); break; + case S_STACK: fprintf (of, "stack "); break; + case S_XSTACK: fprintf (of, "xstack "); break; + case S_BIT: fprintf (of, "bit "); break; + case S_EEPROM: fprintf (of, "eeprom "); break; + default: break; + } + + } + + } + +} /*-----------------------------------------------------------------*/ /* packRegisters - does some transformations to reduce register */ /* pressure */ @@ -3435,11 +3476,16 @@ packRegisters (eBBlock * ebp) for (ic = ebp->sch; ic; ic = ic->next) { if(IS_SYMOP ( IC_LEFT(ic))) { - //sym_link *etype = getSpec (operandType (IC_LEFT (ic))); + sym_link *etype = getSpec (operandType (IC_LEFT (ic))); debugAopGet (" left:", IC_LEFT (ic)); if(IS_PTR_CONST(OP_SYMBOL(IC_LEFT(ic))->type)) - debugLog (" is a pointer"); + debugLog (" is a pointer\n"); + + if(IS_OP_VOLATILE(IC_LEFT(ic))) + debugLog (" is volatile\n"); + + isData(etype); printSymType(" ", OP_SYMBOL(IC_LEFT(ic))->type); } diff --git a/src/regression/Makefile b/src/regression/Makefile index ecce4316..8cfaabf0 100644 --- a/src/regression/Makefile +++ b/src/regression/Makefile @@ -67,6 +67,8 @@ SRC = b.c \ add3.c \ and1.c \ bool1.c \ + bool2.c \ + bool3.c \ call1.c \ compare.c \ compare2.c \ diff --git a/src/regression/bool2.c b/src/regression/bool2.c new file mode 100644 index 00000000..e1062c20 --- /dev/null +++ b/src/regression/bool2.c @@ -0,0 +1,51 @@ +#define __16F873 +#include "p16f873.h" +//#include "p16c84.h" + +unsigned char success=0; +unsigned char failures=0; +unsigned char dummy=0; + +bit bit0 = 0; +bit bit1 = 0; +unsigned int aint0 = 0; +unsigned int aint1 = 0; +unsigned char achar0 = 0; +unsigned char achar1 = 0; + +void done() +{ + + dummy++; + +} + + + +void bit_invert(void) +{ + + bit0 = !bit0; + bit1 = !bit1; + + if((bit0 != bit1) || (bit0 == 0)) + failures++; + +} + +void bit_copy(void) +{ + + bit0 = !bit0; + bit1 = bit0; +} + +void main(void) +{ + + bit_invert(); + bit_copy(); + + success = failures; + done(); +} diff --git a/src/regression/bool3.c b/src/regression/bool3.c new file mode 100644 index 00000000..4c3e358b --- /dev/null +++ b/src/regression/bool3.c @@ -0,0 +1,73 @@ +#define __16F873 +#include "p16f873.h" + + +/* Compound comparisons */ + + +unsigned char success=0; +unsigned char failures=0; +unsigned char dummy=0; + +bit bit0 = 0; +bit bit1 = 0; +unsigned int ui0 = 0; +unsigned int ui1 = 0; +unsigned char uc0 = 0; +unsigned char uc1 = 0; +unsigned long uL0 = 0; +unsigned long uL1 = 0; + +void done() +{ + + dummy++; + +} + + + +void compound_compare_uc(void) +{ + + failures += (uc0 != uc1); + +} + + +void compound_compare_ui(void) +{ + + failures += (ui0 != ui1); + +} + +void compound_compare_ul(void) +{ + + failures += (uL0 != uL1); + +} + +void compound_compare_uc_lit(void) +{ + + failures += (uc0 != 0xff); + failures += (uc0 != 0xff); + failures += (uc0 == 0); + +} + +void main(void) +{ + + compound_compare_uc(); + compound_compare_ui(); + compound_compare_ul(); + + uc0 = 0xff; + compound_compare_uc_lit(); + + success = failures; + done(); +} diff --git a/src/regression/string1.c b/src/regression/string1.c index 3f169c30..51d54762 100644 --- a/src/regression/string1.c +++ b/src/regression/string1.c @@ -31,7 +31,7 @@ void isr(void) interrupt 1 using 1 void lcd1(const unsigned char *str) { - const char *p = "hellow world!\r\n"; + const char *p = "hello world!\r\n"; if(!str) failures++; -- 2.30.2