From: sdattalo Date: Tue, 9 Oct 2001 05:56:40 +0000 (+0000) Subject: Added more PIC regression testing. X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=773c6338a70b9cd56d206cf4d7994142889970ca;p=fw%2Fsdcc Added more PIC regression testing. Signed casting is now working. Signed addition and subtraction now working. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1379 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/src/pic/gen.c b/src/pic/gen.c index 73f965e2..fcff2474 100644 --- a/src/pic/gen.c +++ b/src/pic/gen.c @@ -63,7 +63,13 @@ static int labelOffset=0; static int debug_verbose=1; static int optimized_for_speed = 0; +/* max_key keeps track of the largest label number used in + a function. This is then used to adjust the label offset + for the next function. +*/ +static int max_key=0; unsigned int pic14aopLiteral (value *val, int offset); +const char *AopType(short type); /* this is the down and dirty file with all kinds of kludgy & hacky stuff. This is what it is all about @@ -133,26 +139,15 @@ static int my_powof2 (unsigned long num) return -1; } -static void emitpLabel(int key) -{ - addpCode2pBlock(pb,newpCodeLabel(key)); -} - -void emitpcode(PIC_OPCODE poc, pCodeOp *pcop) -{ - - addpCode2pBlock(pb,newpCode(poc,pcop)); - -} -/*-----------------------------------------------------------------*/ -/* pic14_emitcode - writes the code into a file : for now it is simple */ -/*-----------------------------------------------------------------*/ -void pic14_emitcode (char *inst,char *fmt, ...) +void DEBUGpic14_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; char *lbp = lb; + if(!debug_verbose) + return; + va_start(ap,fmt); if (inst && *inst) { @@ -173,21 +168,42 @@ void pic14_emitcode (char *inst,char *fmt, ...) lineCurr->isInline = _G.inLine; lineCurr->isDebug = _G.debugLine; - if(debug_verbose) - addpCode2pBlock(pb,newpCodeCharP(lb)); + addpCode2pBlock(pb,newpCodeCharP(lb)); va_end(ap); } -void DEBUGpic14_emitcode (char *inst,char *fmt, ...) + +static void emitpLabel(int key) +{ + addpCode2pBlock(pb,newpCodeLabel(key)); +} + +void emitpcode(PIC_OPCODE poc, pCodeOp *pcop) +{ + + if(pcop) + addpCode2pBlock(pb,newpCode(poc,pcop)); + else + DEBUGpic14_emitcode(";","%s ignoring NULL pcop",__FUNCTION__); +} + +void emitpcodeNULLop(PIC_OPCODE poc) +{ + + addpCode2pBlock(pb,newpCode(poc,NULL)); + +} + +/*-----------------------------------------------------------------*/ +/* pic14_emitcode - writes the code into a file : for now it is simple */ +/*-----------------------------------------------------------------*/ +void pic14_emitcode (char *inst,char *fmt, ...) { va_list ap; char lb[INITIAL_INLINEASM]; char *lbp = lb; - if(!debug_verbose) - return; - va_start(ap,fmt); if (inst && *inst) { @@ -208,7 +224,8 @@ void DEBUGpic14_emitcode (char *inst,char *fmt, ...) lineCurr->isInline = _G.inLine; lineCurr->isDebug = _G.debugLine; - addpCode2pBlock(pb,newpCodeCharP(lb)); + if(debug_verbose) + addpCode2pBlock(pb,newpCodeCharP(lb)); va_end(ap); } @@ -960,6 +977,12 @@ char *aopGet (asmop *aop, int offset, bool bit16, bool dname) /*-----------------------------------------------------------------*/ pCodeOp *popGetLabel(unsigned int key) { + + DEBUGpic14_emitcode ("; ***","%s key=%d, label offset %d",__FUNCTION__,key, labelOffset); + + if(key>max_key) + max_key = key; + return newpCodeOpLabel(key+100+labelOffset); } @@ -1068,17 +1091,17 @@ pCodeOp *popGet (asmop *aop, int offset, bool bit16, bool dname) case AOP_DPTR: case AOP_DPTR2: case AOP_ACC: - DEBUGpic14_emitcode(";8051 legacy","%d",__LINE__); - pcop = Safe_calloc(1,sizeof(pCodeOpReg) ); - pcop->type = PO_SFR_REGISTER; + DEBUGpic14_emitcode(";8051 legacy","%d type = %s",__LINE__,AopType(aop->type)); + //pcop = Safe_calloc(1,sizeof(pCodeOpReg) ); + //pcop->type = PO_SFR_REGISTER; - PCOR(pcop)->rIdx = -1; - PCOR(pcop)->r = NULL; + //PCOR(pcop)->rIdx = -1; + //PCOR(pcop)->r = NULL; // Really nasty hack to check for temporary registers - pcop->name = Safe_strdup("BAD_REGISTER"); + //pcop->name = Safe_strdup("BAD_REGISTER"); - return pcop; + return NULL; case AOP_IMMD: DEBUGpic14_emitcode(";","%d",__LINE__); @@ -2367,8 +2390,10 @@ static void genFunction (iCode *ic) symbol *sym; sym_link *fetype; - DEBUGpic14_emitcode ("; ***","%s %d",__FUNCTION__,__LINE__); - labelOffset += FUNCTION_LABEL_INC; + DEBUGpic14_emitcode ("; ***","%s %d previous max_key=%d ",__FUNCTION__,__LINE__,max_key); + + labelOffset += (max_key+1); + max_key=0; _G.nRegsSaved = 0; /* create the function header */ @@ -2675,7 +2700,7 @@ static void genEndFunction (iCode *ic) } pic14_emitcode ("return",""); - emitpcode(POC_RETURN,NULL); + emitpcodeNULLop(POC_RETURN); /* Mark the end of a function */ addpCode2pBlock(pb,newpCodeFunction(NULL,NULL)); @@ -8540,10 +8565,12 @@ static void genCast (iCode *ic) offset = 0 ; while (size--) { pic14_emitcode(";","%d",__LINE__); - aopPut(AOP(result), - aopGet(AOP(right),offset,FALSE,FALSE), - offset); - offset++; + /* aopPut(AOP(result), + aopGet(AOP(right),offset,FALSE,FALSE), + offset); */ + emitpcode(POC_MOVFW, popGet(AOP(right),offset,FALSE,FALSE)); + emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE)); + offset++; } /* now depending on the sign of the destination */ @@ -8557,11 +8584,14 @@ static void genCast (iCode *ic) } } else { /* we need to extend the sign :{ */ - //char *l = aopGet(AOP(right),AOP_SIZE(right) - 1,FALSE,FALSE); - //MOVA(l); - emitpcode(POC_CLRW, NULL); - emitpcode(POC_BTFSC, popGet(AOP(right),0,FALSE,FALSE)); + emitpcodeNULLop(POC_CLRW); + + if(offset) + emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),offset-1,FALSE,FALSE),7,0)); + else + emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),offset,FALSE,FALSE),7,0)); + emitpcode(POC_MOVLW, popGetLit(0xff)); pic14_emitcode("clrw",""); diff --git a/src/pic/gen.h b/src/pic/gen.h index 8a17d33b..2989b734 100644 --- a/src/pic/gen.h +++ b/src/pic/gen.h @@ -113,7 +113,7 @@ extern unsigned fReturnSizePic; #define MSB32 3 -#define FUNCTION_LABEL_INC 20 +#define FUNCTION_LABEL_INC 40 /*-----------------------------------------------------------------*/ /* Macros for emitting skip instructions */ diff --git a/src/pic/pcode.c b/src/pic/pcode.c index 062fac95..fc5de12c 100644 --- a/src/pic/pcode.c +++ b/src/pic/pcode.c @@ -1130,7 +1130,10 @@ pCode *newpCodeCharP(char *cP) pcc->pc.destruct = genericDestruct; pcc->pc.print = genericPrint; - pcc->comment = Safe_strdup(cP); + if(cP) + pcc->comment = Safe_strdup(cP); + else + pcc->comment = NULL; return ( (pCode *)pcc); @@ -1206,11 +1209,13 @@ pCode *newpCodeLabel(int key) pcl->key = key; + pcl->label = NULL; if(key>0) { sprintf(s,"_%05d_DS_",key); - pcl->label = Safe_strdup(s); - } else - pcl->label = NULL; + if(s) + pcl->label = Safe_strdup(s); + } + return ( (pCode *)pcl); @@ -1219,7 +1224,10 @@ pCode *newpCodeLabelStr(char *str) { pCode *pc = newpCodeLabel(-1); - PCL(pc)->label = Safe_strdup(str); + if(str) + PCL(pc)->label = Safe_strdup(str); + else + PCL(pc)->label = NULL; return pc; } @@ -1279,11 +1287,13 @@ pCodeOp *newpCodeOpLabel(int key) pcop = Safe_calloc(1,sizeof(pCodeOpLabel) ); pcop->type = PO_LABEL; + pcop->name = NULL; if(key>0) { sprintf(s,"_%05d_DS_",key); - pcop->name = Safe_strdup(s); - } else - pcop->name = NULL; + if(s) + pcop->name = Safe_strdup(s); + } + ((pCodeOpLabel *)pcop)->key = key; @@ -1298,11 +1308,13 @@ pCodeOp *newpCodeOpLit(int lit) pcop = Safe_calloc(1,sizeof(pCodeOpLit) ); pcop->type = PO_LITERAL; + pcop->name = NULL; if(lit>=0) { sprintf(s,"0x%02x",lit); - pcop->name = Safe_strdup(s); - } else - pcop->name = NULL; + if(s) + pcop->name = Safe_strdup(s); + } + ((pCodeOpLit *)pcop)->lit = lit; @@ -1339,7 +1351,10 @@ pCodeOp *newpCodeOpBit(char *s, int bit, int inBitSpace) pcop = Safe_calloc(1,sizeof(pCodeOpBit) ); pcop->type = PO_BIT; - pcop->name = Safe_strdup(s); + if(s) + pcop->name = Safe_strdup(s); + else + pcop->name = NULL; PCOB(pcop)->bit = bit; PCOB(pcop)->inBitSpace = inBitSpace; @@ -1383,7 +1398,10 @@ pCodeOp *newpCodeOp(char *name, PIC_OPTYPE type) default: pcop = Safe_calloc(1,sizeof(pCodeOp) ); pcop->type = type; - pcop->name = Safe_strdup(name); + if(name) + pcop->name = Safe_strdup(name); + else + pcop->name = NULL; } return pcop; @@ -2477,7 +2495,10 @@ set *register_usage(pBlock *pb) r1->rIdx, newreg->rIdx); r2->rIdx = newreg->rIdx; //if(r2->name) free(r2->name); - r2->name = Safe_strdup(newreg->name); + if(newreg->name) + r2->name = Safe_strdup(newreg->name); + else + r2->name = NULL; newreg->isFree = 0; newreg->wasUsed = 1; } @@ -2593,7 +2614,10 @@ void pct2(FILE *of,pBlock *pb,int indent) r1->rIdx, newreg->rIdx); r2->rIdx = newreg->rIdx; //if(r2->name) free(r2->name); - r2->name = Safe_strdup(newreg->name); + if(newreg->name) + r2->name = Safe_strdup(newreg->name); + else + r2->name = NULL; newreg->isFree = 0; newreg->wasUsed = 1; } diff --git a/src/pic/pcodepeep.c b/src/pic/pcodepeep.c index 3a8d5265..c97802df 100644 --- a/src/pic/pcodepeep.c +++ b/src/pic/pcodepeep.c @@ -1763,7 +1763,10 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop) } pcopnew->type = pcop->type; - pcopnew->name = Safe_strdup(pcop->name); + if(pcop->name) + pcopnew->name = Safe_strdup(pcop->name); + else + pcopnew->name = NULL; return pcopnew; } diff --git a/src/regression/Makefile b/src/regression/Makefile index 680eaf76..eb40eaa0 100644 --- a/src/regression/Makefile +++ b/src/regression/Makefile @@ -57,17 +57,20 @@ SIMULATE = simulate SRC = b.c \ add.c \ add2.c \ + add3.c \ bool1.c \ call1.c \ compare.c \ compare2.c \ compare3.c \ + compare4.c \ for.c \ rotate1.c \ rotate2.c \ rotate3.c \ struct1.c \ sub.c \ + sub2.c \ switch1.c \ while.c \ xor.c diff --git a/src/regression/add2.c b/src/regression/add2.c index 020ed2d3..56808385 100644 --- a/src/regression/add2.c +++ b/src/regression/add2.c @@ -104,17 +104,34 @@ void add_uint2uint2(void) failures++; aint1 += aint0; - if(aint1 != 39) + if(aint1 != 0x27) failures++; aint2 = aint1 + aint0; - if(aint2 != 46) + if(aint2 != 0x2e) failures++; aint3 = aint2 + aint1 + aint0; - if(aint3 != 92) + if(aint3 != 0x5c) failures++; + aint3 += 0xa0; + if(aint3 != 0xfc) + failures++; + + aint3 += aint0; + if(aint3 != 0x103) + failures++; + + aint1 += 0xffc0; + if(aint1 != 0xffe7) + failures++; + + aint3 = aint2 + aint1 + aint0; + if(aint3 != 0x1c) + failures++; + + } #if SUPPORT_BIT_TYPES @@ -282,18 +299,23 @@ void main(void) aint0=16; aint1=0; - // add_uint2uint(); + add_uint2uint(); aint0 = 0; aint1 = 32; - // add_uint2uint2(); + aint2 = 0; + add_uint2uint2(); #if SUPPORT_BIT_TYPES - // add_bits(); + add_bits(); - // add_bit2uchar(); - // add_bit2uint(); + achar0 = 7; + add_bit2uchar(); + + aint0 = 0; + bit0 = 1; + add_bit2uint(); #endif aint0 = 0; diff --git a/src/regression/add3.c b/src/regression/add3.c new file mode 100644 index 00000000..c1d8fa78 --- /dev/null +++ b/src/regression/add3.c @@ -0,0 +1,74 @@ + +// Addition tests - mostly int's + +/* bit types are not ANSI - so provide a way of disabling bit types + * if this file is used to test other compilers besides SDCC */ +#define SUPPORT_BIT_TYPES 1 + + +unsigned char success=0; +unsigned char failures=0; +unsigned char dummy=0; + + +char char0 = 0; +char char1 = 0; +char char2 = 0; + +#if SUPPORT_BIT_TYPES + +bit bit0 = 0; +bit bit1 = 0; +bit bit2 = 0; +bit bit3 = 0; +bit bit4 = 0; +bit bit5 = 0; +bit bit6 = 0; +bit bit7 = 0; +bit bit8 = 0; +bit bit9 = 0; +bit bit10 = 0; +bit bit11 = 0; + +#endif + + +void done() +{ + + dummy++; + +} + +void add_char2char(void) +{ + if(char0 != 4) + failures++; + if(char1 != 5) + failures++; + + char0 = char0 + char1; + + if(char0 != 9) + failures++; + + char0 += 127; + if(char0 > 0) + failures++; + + if(char0 != -0x78) + failures++; + + +} + + +void main(void) +{ + char0=4; + char1 = char0 + 1; + add_char2char(); + + success = failures; + done(); +} diff --git a/src/regression/compare4.c b/src/regression/compare4.c new file mode 100644 index 00000000..41e0b9c0 --- /dev/null +++ b/src/regression/compare4.c @@ -0,0 +1,303 @@ +// +// compare4.c +// regression testing program for comparing signed chars and ints +// + +#define COMPARE_OUT_OF_RANGE 1 + +unsigned char success = 0; +unsigned char failures = 0; +unsigned char dummy = 0; + +bit bit0 = 0; +int int0 = 0; +int int1 = 0; +char char0 = 0; +char char1 = 0; + +void +done () +{ + + dummy++; + +} + +// compare to 0 +// assumes +// char0 == 0 +// char1 != 0 +// int0 == 0 +// int1 != 0 + +void c_0(void) +{ + + if(char0 != 0) + failures++; + + if(char0) + failures++; + + if(char1 == 0) + failures++; + + if(!char1) + failures++; + + if(int0 != 0) + failures++; + + if(int0) + failures++; + + if(int1 == 0) + failures++; + + if(!int1) + failures++; + + if(char0>0) + failures++; + + if(int0>0) + failures++; + + if(char0<0) + failures++; + + if(int0<0) + failures++; + +} + +// compare to 1 +// assumes +// char0 != 1 +// char1 == 1 +// int0 != 1 +// int1 == 1 + +void c_1(void) +{ + + if(char0 == 1) + failures++; + + if(char1 != 1) + failures++; + + if(int0 == 1) + failures++; + + if(int1 != 1) + failures++; + + if(char0 < 0) + failures++; + + if(int0 < 0) + failures++; + +} + +// compare to 2 +// assumes +// achar0 == 2 +// aint0 == 2 + +void c_2(void) +{ + + if(char0 != 2) + failures++; + + if(int0 != 2) + failures++; + +} + +// compare to 0xff +// assumes +// achar0 == 0xff +// aint0 == 0xff + +void c_ff(void) +{ + + if(char0 != 0xff) + failures++; + + if(int0 != 0xff) + failures++; + + if(int0 == 0xfe) + failures++; + + if(int0 == 0xff00) + failures++; + +} + + +// compare to 0x00a5 +// assumes +// char0 == 0xa5 +// int0 == 0x00a5 + +void c_a5(void) +{ + + if(char0 != 0xa5) + failures++; + + if(int0 != 0xa5) + failures++; + + if(int0 == 0xa4) + failures++; + + if(int0 == 0xa500) + failures++; + +} + +// compare to 0xa500 +// assumes +// char0 == 0xa5 +// int0 == 0xa500 + +void c_a500(void) +{ + +#ifdef COMPARE_OUT_OF_RANGE + if(char0 == 0xa500) + failures++; +#endif + + if(int0 != 0xa500) + failures++; + + if(int0 == 0xa400) + failures++; + + if(int0 == 0x00a5) + failures++; + +} + +// compare to 0xabcd +// assumes +// char0 == 0xa5 +// int0 == 0xabcd + +void c_abcd(void) +{ +#ifdef COMPARE_OUT_OF_RANGE + if(char0 == 0xabcd) + failures++; +#endif + + if(int0 != 0xabcd) + failures++; + + if(int0 == 0xab00) + failures++; + + if(int0 == 0x00cd) + failures++; + + if(int0 == 0x05cd) + failures++; + + if(int0 == 0xab05) + failures++; + + if(int0 == 0xab01) + failures++; + + if(int0 == 0x01cd) + failures++; + + if(int0 > 0) + failures++; + +#ifdef COMPARE_OUT_OF_RANGE + if(int0 == 0x1234abcd) + failures++; +#endif + +} + +// assumes char1 == 0 +void c_ifelse1(void) +{ + + if(char0) + char0 = char1; + else + char0 = 0; + + if(char0) + failures++; +} + +// assumes char0 = -1 +// assumes int0 = -1 + +void c_minus1(void) +{ + if(char0 != -1) + failures++; + + if(int0 != -1) + failures++; + + if(char0 != int0) + failures++; + + if(char0>0) + failures++; + + if(int0>0) + failures++; +} + +void +main (void) +{ + + int1 = 1; + char1 = 1; + c_0(); + c_1(); + + int0 = 2; + char0 = 2; + c_2(); + + int0 = 0xff; + char0 = 0xff; + c_ff(); + + int0 = 0xa5; + char0 = 0xa5; + c_a5(); + + int0 = 0xabcd; + c_abcd(); + + char0 = 0; + char1 = 0; + c_ifelse1(); + + char0 = 1; + c_ifelse1(); + + char0 = -1; + int0 = -1; + c_minus1(); + + success = failures; + done (); +} diff --git a/src/regression/sub2.c b/src/regression/sub2.c new file mode 100644 index 00000000..b2d74e29 --- /dev/null +++ b/src/regression/sub2.c @@ -0,0 +1,144 @@ +//#include "p16c84.h" +// Addition tests + +/* bit types are not ANSI - so provide a way of disabling bit types + * if this file is used to test other compilers besides SDCC */ +#define SUPPORT_BIT_TYPES 1 + +/* Some compilers that support bit types do not support bit arithmetic + * (like bitx = bity + bitz;) */ +#define SUPPORT_BIT_ARITHMETIC 1 + +unsigned char success=0; +unsigned char failures=0; +unsigned char dummy=0; + +#if SUPPORT_BIT_TYPES + +bit bit0 = 0; +bit bit1 = 0; +bit bit2 = 0; +bit bit3 = 0; +bit bit4 = 0; +bit bit5 = 0; +bit bit6 = 0; +bit bit7 = 0; +bit bit8 = 0; +bit bit9 = 0; +bit bit10 = 0; +bit bit11 = 0; + +#endif + +int int0 = 0; +int int1 = 0; +char char0 = 0; +char char1 = 0; +char char2 = 0; + + +void done() +{ + + dummy++; + +} + +void sub_int1(void) +{ + if(int0 != 5) + failures++; + + if(int1 != 4) + failures++; + + int0 = int0 - int1; + + if(int0 != 1) + failures++; + + int0 = 4 - int0; + if(int0 != 3) + failures++; + + int0 = int0 - int1; + + if(int0 != -1) + failures++; + + int0 = int0 - 0xff; + + if(int0 != -0x100) + failures++; + + int0 = 0xff - int0; + + if(int0 != 0x1ff) + failures++; + + +} + +void sub_char_int(void) +{ + + int0 = int0 - char0; + + if(int0 != 3) + failures++; + + if(int0 < char0) + failures++; + + int0 = int0 - char0; + + if(int0 != 1) + failures++; + + if(int0 > char0) + failures++; + + + int0 = int0 - char0; + if(int0 != -1) + failures++; + + if(int0>0) + failures++; + +} + +void assign_char2int(void) +{ + + int0 = char0; + if(int0 != 0x7f) + failures++; + + int1 = char1; + if(int1 != -5) + failures++; + +} + +void main(void) +{ + + int0 = 5; + int1 = 4; + + sub_int1(); + + int0 = 5; + int1 = 4; + char0 = 2; + + sub_char_int(); + + char0 = 0x7f; + char1 = -5; + assign_char2int(); + + success = failures; + done(); +}