Added regression testing files that should've been added a long time ago.
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 24 Nov 2001 06:04:01 +0000 (06:04 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 24 Nov 2001 06:04:01 +0000 (06:04 +0000)
Fixed ptr gen bugs. (need to dive into ralloc... ptrs are generated poorly)

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1638 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/pic/gen.c
src/pic/pcode.c
src/pic/pcodepeep.c
src/pic/ralloc.c
src/regression/or1.c [new file with mode: 0644]
src/regression/rotate4.c [new file with mode: 0644]
src/regression/switch1.c [new file with mode: 0644]

index d3ba5a18a1a61f576baa51fd56433f66cda23835..afc8beb38496c320ab3613bd8cedf6d0490d0b5d 100644 (file)
@@ -1066,6 +1066,7 @@ pCodeOp *popCopyReg(pCodeOpReg *pc)
   pcor->r = pc->r;
   pcor->rIdx = pc->rIdx;
 
+  //DEBUGpic14_emitcode ("; ***","%s  , copying %s, rIdx=%d",__FUNCTION__,pc->pcop.name,pc->rIdx);
 
   return PCOP(pcor);
 }
@@ -1228,6 +1229,7 @@ pCodeOp *popGet (asmop *aop, int offset) //, bool bit16, bool dname)
        PCOR(pcop)->r = pic14_regWithIdx(rIdx);
        pcop->type = PCOR(pcop)->r->pc_type;
        rs = aop->aopu.aop_reg[offset]->name;
+       //DEBUGpic14_emitcode(";","%d regiser idx = %d name =%s",__LINE__,rIdx,rs);
        return pcop;
       }
 
@@ -1652,7 +1654,6 @@ void pic14_toBoolean(operand *oper)
 
     if ( AOP_TYPE(oper) != AOP_ACC) {
       emitpcode(POC_MOVFW,popGet(AOP(oper),0));
-      pic14_emitcode("movf","%s,w",aopGet(AOP(oper),0,FALSE,FALSE));
     }
     while (size--) {
       emitpcode(POC_IORFW, popGet(AOP(oper),offset++));
@@ -7384,6 +7385,9 @@ static void genGenPointerGet (operand *left,
     }
     else { /* we need to get it byte by byte */
 
+      emitpcode(POC_MOVFW,popGet(AOP(left),0));
+      emitpcode(POC_MOVWF,popCopyReg(&pc_fsr));
+
       size = AOP_SIZE(result);
       offset = 0 ;
 
@@ -7969,13 +7973,15 @@ static void genGenPointerSet (operand *right,
       /* hack hack! see if this the FSR. If so don't load W */
       if(AOP_TYPE(right) != AOP_ACC) {
 
-       if(size==2)
-         emitpcode(POC_DECF,popCopyReg(&pc_fsr));
+       emitpcode(POC_MOVFW,popGet(AOP(result),0));
+       emitpcode(POC_MOVWF,popCopyReg(&pc_fsr));
 
-       if(size==4) {
-         emitpcode(POC_MOVLW,popGetLit(0xfd));
-         emitpcode(POC_ADDWF,popCopyReg(&pc_fsr));
-       }
+       //if(size==2)
+       //emitpcode(POC_DECF,popCopyReg(&pc_fsr));
+       //if(size==4) {
+       //  emitpcode(POC_MOVLW,popGetLit(0xfd));
+       //  emitpcode(POC_ADDWF,popCopyReg(&pc_fsr));
+       //}
 
        while(size--) {
          emitpcode(POC_MOVFW,popGet(AOP(right),offset++));
@@ -8293,7 +8299,9 @@ static void genAssign (iCode *ic)
     lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
 
   if( AOP_TYPE(right) == AOP_DIR  && (AOP_TYPE(result) == AOP_REG) && size==1)  {
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     if(aopIdx(AOP(result),0) == 4) {
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
       emitpcode(POC_MOVFW, popGet(AOP(right),offset));
       emitpcode(POC_MOVWF, popGet(AOP(result),offset));
       goto release;
@@ -8303,6 +8311,7 @@ static void genAssign (iCode *ic)
 
   know_W=-1;
   while (size--) {
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
     if(AOP_TYPE(right) == AOP_LIT) {
       if(lit&0xff) {
        if(know_W != (lit&0xff))
@@ -8321,6 +8330,7 @@ static void genAssign (iCode *ic)
        emitpcode(POC_INCF, popGet(AOP(result),0));
       }
     } else {
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
       emitpcode(POC_MOVFW, popGet(AOP(right),offset));
       emitpcode(POC_MOVWF, popGet(AOP(result),offset));
     }
index 03ab39ad954e8cf26cba52fd6380af9da7c960ac..04744116156dab934da3623bd6db45f88ebaf28c 100644 (file)
@@ -48,7 +48,7 @@ static hTab *pic14MnemonicsHash = NULL;
 
 
 static pFile *the_pFile = NULL;
-static int peepOptimizing = 1;
+static int peepOptimizing = 0;
 static int GpCodeSequenceNumber = 1;
 
 /****************************************************************/
@@ -776,6 +776,9 @@ void  pCodeInitRegisters(void)
   pc_fsr.rIdx = 4;
   pc_fsr.r = pic14_regWithIdx(4);
 
+  pc_indf.rIdx = 0;
+  pc_indf.r = pic14_regWithIdx(0);
+
 }
 
 /*-----------------------------------------------------------------*/
@@ -1553,8 +1556,9 @@ static char *get_op( pCodeInstruction *pcc)
 
 
     switch(pcc->pcop->type) {
-
+    case PO_INDF:
     case PO_FSR:
+      //fprintf(stderr,"get_op getting register name rIdx=%d\n",PCOR(pcc->pcop)->rIdx);
       r = pic14_regWithIdx(PCOR(pcc->pcop)->rIdx);
       return r->name;
       break;
index 80cb0ceb563a07c1d0d04d4d3b3025937e91f1ff..0465edb61f76b27e01ee03f2b58e2a57da1bd3ec 100644 (file)
@@ -1360,12 +1360,16 @@ int pCodePeepMatchLine(pCodePeep *peepBlock, pCode *pcs, pCode *pcd)
          {
            char *n;
 
+             fprintf(stderr,"line %d\n",__LINE__);
            switch(PCI(pcs)->pcop->type) {
            case PO_GPR_TEMP:
            case PO_FSR:
+             //case PO_INDF:
              n = PCOR(PCI(pcs)->pcop)->r->name;
+
              break;
            default:
+             fprintf(stderr,"line %d\n",__LINE__);
              n = PCI(pcs)->pcop->name;
            }
 
@@ -1522,6 +1526,8 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop)
   case PO_GPR_REGISTER:
   case PO_GPR_TEMP:
   case PO_GPR_BIT:
+  case PO_FSR:
+  case PO_INDF:
     fprintf(stderr,"pCodeOpCopy GPR register\n");
     pcopnew = Safe_calloc(1,sizeof(pCodeOpReg) );
     PCOR(pcopnew)->r = PCOR(pcop)->r;
@@ -1536,8 +1542,6 @@ static pCodeOp *pCodeOpCopy(pCodeOp *pcop)
   case PO_NONE:
   case PO_W:
   case PO_STATUS:
-  case PO_FSR:
-  case PO_INDF:
   case PO_PCL:
   case PO_PCLATH:
 
index d4c62894012ffdfeeed72cf4f33057dca88a0971..5135db54c7ac7c1c56dfcf0b56251b1d1d3de1c6 100644 (file)
@@ -134,7 +134,8 @@ regs regspic14[] =
   {REG_STK, PO_GPR_TEMP, 0x46, "r0x46", "r0x46", 0x46, 1, 0},
   {REG_STK, PO_GPR_TEMP, 0x47, "r0x47", "r0x47", 0x47, 1, 0},
 
-  {REG_PTR, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
+  {REG_STK, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
+  {REG_STK, PO_INDF, 0, "INDF", "INDF", 0, 1, 0},
 
 };
 
diff --git a/src/regression/or1.c b/src/regression/or1.c
new file mode 100644 (file)
index 0000000..b17834e
--- /dev/null
@@ -0,0 +1,191 @@
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+bit bit1 = 0;
+bit bit2 = 0;
+
+unsigned int uint0 = 0;
+unsigned int uint1 = 0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
+unsigned long ulong0 = 0;
+unsigned long ulong1 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+// uchar0 = 0;
+void or_lit2uchar(void)
+{
+
+  if(uchar0)
+    failures++;
+
+  uchar0 |= 1;
+
+  if(uchar0 != 1)
+    failures++;
+
+  uchar0 |= 2;
+
+  if(uchar0 != 3)
+    failures++;
+
+  uchar0 |= 0x0e;
+
+  if(uchar0 != 0x0f)
+    failures++;
+
+}
+
+
+void or_lit2uint(void)
+{
+
+  if(uint0)
+    failures++;
+
+  uint0 |= 1;
+  if(uint0 != 1) 
+    failures++;
+
+  uint0 |= 2;
+  if(uint0 != 3) 
+    failures++;
+
+  uint0 |= 0x100;
+  if(uint0 != 0x103) 
+    failures++;
+
+  uint0 |= 0x102;
+  if(uint0 != 0x103) 
+    failures++;
+
+  uint0 |= 0x303;
+  if(uint0 != 0x303) 
+    failures++;
+
+}
+
+void or_lit2ulong(void)
+{
+
+  if(ulong0)
+    failures++;
+
+  ulong0 |= 1;
+  if(ulong0 != 1) 
+    failures++;
+
+  ulong0 |= 2;
+  if(ulong0 != 3) 
+    failures++;
+
+  ulong0 |= 0x100;
+  if(ulong0 != 0x103) 
+    failures++;
+
+  ulong0 |= 0x102;
+  if(ulong0 != 0x103) 
+    failures++;
+
+  ulong0 |= 0x303;
+  if(ulong0 != 0x303) 
+    failures++;
+
+  ulong0 |= 0x80000000;
+  if(ulong0 != 0x80000303) 
+    failures++;
+
+}
+
+/*-----------*/
+void or_uchar2uchar(void)
+{
+
+  uchar0 |= uchar1;
+
+  if(uchar0 != 1)
+    failures++;
+
+  uchar1 |= 0x0f;
+
+  uchar0 = uchar1 | 0x10;
+
+  if(uchar0 != 0x1f)
+    failures++;
+}
+
+void or_uint2uint(void)
+{
+  uint0 |= uint1;
+
+  if(uint0 != 1)
+    failures++;
+
+  uint1 |= 0x0f;
+
+  uint0 = uint1 | 0x10;
+
+  if(uint0 != 0x1f)
+    failures++;
+
+}
+
+void or_bits1(void)
+{
+
+  bit0 = bit0 | bit1 | bit2;
+
+}
+
+void or_bits2(void)
+{
+
+  bit0 = bit1 | bit2;
+
+}
+
+void main(void)
+{
+
+  or_lit2uchar();
+  or_lit2uint();
+  or_lit2ulong();
+
+  uchar0=0;
+  uchar1=1;
+  or_uchar2uchar();
+
+  uint0=0;
+  uint1=1;
+  or_uint2uint();
+
+  or_bits1();
+  if(bit0)
+    failures++;
+
+  or_bits2();
+  if(bit0)
+    failures++;
+
+  bit1=1;
+  or_bits1();
+  if(!bit0)
+    failures++;
+
+  or_bits2();
+  if(!bit0)
+    failures++;
+
+
+  success = failures;
+  done();
+}
diff --git a/src/regression/rotate4.c b/src/regression/rotate4.c
new file mode 100644 (file)
index 0000000..358dfe9
--- /dev/null
@@ -0,0 +1,226 @@
+// rotate bytes left and right by a constant.
+
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int uint0 = 0;
+unsigned int uint1 = 0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
+unsigned char uchar2 = 0;
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void check(void)
+{
+  if(uchar0 != uchar1)
+    failures++;
+}
+
+void rotate_left_1(void)
+{
+
+  uchar0 = (uchar0<<1) | (uchar0>>7);
+
+  check();
+}
+
+void rotate_left_2(void)
+{
+
+  uchar0 = (uchar0<<2) | (uchar0>>6);
+
+  check();
+}
+
+
+void rotate_left_3(void)
+{
+
+  uchar0 <<= 3;
+
+  if(uchar0 != uchar1)
+    failures++;
+}
+
+void rotate_left_4(void)
+{
+
+  uchar0 <<= 4;
+
+  if(uchar0 != uchar1)
+    failures++;
+}
+
+void rotate_left_5(void)
+{
+
+  uchar0 <<= 5;
+
+  if(uchar0 != uchar1)
+    failures++;
+}
+
+void rotate_left_6(void)
+{
+
+  uchar0 <<= 6;
+
+  if(uchar0 != uchar1)
+    failures++;
+}
+
+void rotate_left_7(void)
+{
+
+  uchar0 <<= 7;
+
+  if(uchar0 != uchar1)
+    failures++;
+}
+
+void rotate_right_1(void)
+{
+
+  uchar0 = (uchar0>>1) | (uchar0<<7);
+
+  check();
+
+}
+
+void rotate_right_2(void)
+{
+
+  uchar0 = (uchar0>>2) | (uchar0<<6);
+
+  check();
+}
+
+void rotate_right_3(void)
+{
+
+  uchar0 >>= 3;
+
+  check();
+}
+
+void rotate_right_4(void)
+{
+
+  uchar0 >>= 4;
+
+  check();
+}
+
+void rotate_right_5(void)
+{
+
+  uchar0 >>= 5;
+
+  check();
+}
+
+void rotate_right_6(void)
+{
+
+  uchar0 >>= 6;
+
+  check();
+}
+
+void rotate_right_7(void)
+{
+
+  uchar0 >>= 7;
+
+  check();
+}
+
+
+void main(void)
+{
+
+  // call with both values zero
+  rotate_left_1();
+
+  uchar0 = 1;
+  uchar1 = 2;
+
+  rotate_left_1();
+
+  uchar0 = 0x80;
+  uchar1 = 1;
+
+  rotate_left_1();
+
+  uchar1 = 2;
+  for(uchar2=0; uchar2<6; uchar2++) {
+    rotate_left_1();
+    uchar1 <<=1;
+  }
+
+
+  uchar0 = 1;
+  uchar1 = 4;
+  rotate_left_2();
+
+  uchar0 = 1;
+  uchar1 = 8;
+  rotate_left_3();
+
+  uchar0 = 1;
+  uchar1 = 0x10;
+  rotate_left_4();
+
+  uchar0 = 1;
+  uchar1 = 0x20;
+  rotate_left_5();
+
+  uchar0 = 1;
+  uchar1 = 0x40;
+  rotate_left_6();
+
+  uchar0 = 1;
+  uchar1 = 0x80;
+  rotate_left_7();
+
+
+
+
+  uchar0 = 2;
+  uchar1 = 1;
+  rotate_right_1();
+
+  uchar0 = 1;
+  uchar1 = 0x80;
+  rotate_right_1();
+
+  uchar0 = 4;
+  uchar1 = 1;
+  rotate_right_2();
+
+  uchar0 = 8;
+  rotate_right_3();
+
+  uchar0 = 0x10;
+  rotate_right_4();
+
+  uchar0 = 0x20;
+  rotate_right_5();
+
+  uchar0 = 0x40;
+  rotate_right_6();
+
+  uchar0 = 0x80;
+  rotate_right_7();
+
+  success=failures;
+  done();
+}
diff --git a/src/regression/switch1.c b/src/regression/switch1.c
new file mode 100644 (file)
index 0000000..0d966df
--- /dev/null
@@ -0,0 +1,87 @@
+unsigned char success=0;
+unsigned char failures=0;
+unsigned char dummy=0;
+
+bit bit0 = 0;
+unsigned int aint0 = 0;
+unsigned int aint1 = 0;
+unsigned char achar0 = 0;
+unsigned char achar1 = 0;
+
+
+void done()
+{
+
+  dummy++;
+
+}
+
+void switch1(void)
+{
+
+
+  switch(achar0) {
+  case 0:
+    achar0 = 9;
+    break;
+  case 1:
+    achar0 = 18;
+    break;
+
+  default:
+    achar0 = 0;
+  }
+
+
+}
+
+void switch2(void)
+{
+
+  switch(achar1) {
+  case 0:    achar0 = 9;    break;
+  case 1:    achar0 = 8;    break;
+  case 2:    achar0 = 7;    break;
+  case 3:    achar0 = 6;    break;
+  case 4:    achar0 = 5;    break;
+  case 5:    achar0 = 4;    break;
+  case 6:    achar0 = 3;    break;
+  case 7:    achar0 = 2;    break;
+  case 8:    achar0 = 1;    break;
+  case 9:    achar0 = 0;    break;
+  case 10:    achar0 = 9;    break;
+  case 11:    achar0 = 8;    break;
+  case 12:    achar0 = 7;    break;
+  default:    achar0 = 0xff;    break;
+  }
+
+}
+
+main(void)
+{
+
+  achar0 = 0;
+  switch1();
+  if(achar0 != 9)
+    failures++;
+
+  switch1();
+  if(achar0 != 0)
+    failures++;
+
+  achar0++;
+
+  switch1();
+  if(achar0 != 18)
+    failures++;
+
+  for(achar1=0; achar1<10;achar1++){
+    switch2();
+    if(achar0 != (9-achar1))
+      failures++;
+
+  }
+
+  success=failures;
+  done();
+}