]> git.gag.com Git - fw/sdcc/commitdiff
Signed comparisons are now working (except for signed longs)
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 21 Oct 2001 22:40:40 +0000 (22:40 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 21 Oct 2001 22:40:40 +0000 (22:40 +0000)
Fixed gen errors for bit &, | operators
Auto register collision detection was failing
Changed the default processor to a 16F877
Added regression test script "rt.sh" for regression testing a single file.

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

14 files changed:
src/pic/gen.c
src/pic/genarith.c
src/pic/glue.c
src/pic/main.c
src/pic/pcode.c
src/pic/ralloc.c
src/regression/Makefile
src/regression/add3.c
src/regression/and1.c
src/regression/compare2.c
src/regression/compare5.c
src/regression/for.c
src/regression/rt.sh [new file with mode: 0755]
src/regression/sub2.c

index 8f52b8a0a8e1229d75f24aab1c640d72b137c10e..1986eea69adaccc64166bd7b78564d1de18f723e 100644 (file)
@@ -3406,6 +3406,9 @@ static void genCmp (operand *left,operand *right,
   unsigned long lit = 0L,i = 0;
 
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic14_emitcode ("; ***","true ifx is %s",((IC_TRUE(ifx) == NULL) ? "false" : "true"));
+  DEBUGpic14_emitcode ("; ***","false ifx is %s",((IC_FALSE(ifx) == NULL) ? "false" : "true"));
+
   /* if left & right are bit variables */
   if (AOP_TYPE(left) == AOP_CRY &&
       AOP_TYPE(right) == AOP_CRY ) {
@@ -3429,67 +3432,94 @@ static void genCmp (operand *left,operand *right,
     } else {
 
       if(AOP_TYPE(right) == AOP_LIT) {
-
-       DEBUGpic14_emitcode(";right lit","%d",sign);
+       symbol *lbl = newiTempLabel(NULL);
 
        lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-       //default:
-/*     if( lit == 0 ){
-         emitpcode(POC_MOVFW, popGet(AOP(left),0,FALSE,FALSE));
-         while(--size) 
-           emitpcode(POC_IORFW, popGet(AOP(left),++offset,FALSE,FALSE));
 
-         genSkipz(ifx,IC_TRUE(ifx) == NULL);
-       } else {
-*/
-         while(size--) {
-           i = (lit >> (size*8)) & 0xff;
-           if(i == 0) {
-             emitpcode(POC_MOVFW, popGet(AOP(left),size,FALSE,FALSE));
-             genSkipz(ifx,IC_TRUE(ifx) == NULL);
-           } else {
-             emitpcode(POC_MOVLW, popGetLit(i));
-             emitpcode(POC_SUBFW, popGet(AOP(left),size,FALSE,FALSE));
-             genSkipc(ifx,IC_TRUE(ifx) == NULL);
-           }
+       DEBUGpic14_emitcode(";right lit","lit = %d,sign=%d",lit,sign);
+
+       size--;
+       i = (lit >> (size*8)) & 0xff;
+       if(sign) {
+         if(i & 0x80) {
+           emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
+         } else {
+           emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(left),size,FALSE,FALSE),7,0));
          }
-  //   }
+         emitpcode(POC_GOTO,popGetLabel(lbl->key));
+       }
+
+       emitpcode(POC_MOVLW, popGetLit(i));
+       emitpcode(POC_SUBFW, popGet(AOP(left),size,FALSE,FALSE));
+       while(size--) {
+         i = (lit >> (size*8)) & 0xff;
+         emitpcode(POC_MOVLW, popGetLit(i));
+         emitSKPNC;
+         emitpcode(POC_SUBFW, popGet(AOP(left),size,FALSE,FALSE));
+       }
+
+       genSkipc(ifx,IC_TRUE(ifx) == NULL);
+       if(sign)
+         emitpLabel(lbl->key);
+
        ifx->generated = 1;
        return;
       }
 
       if(AOP_TYPE(left) == AOP_LIT) {
+       //symbol *lbl = newiTempLabel(NULL);
 
-       DEBUGpic14_emitcode(";left lit","%d",sign);
+       lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit));
 
-       offset = 0;
-       lit = (unsigned long)(floatFromVal(AOP(left)->aopu.aop_lit))+1;
-
-       if( lit == 0 ){
-         emitpcode(POC_MOVFW, popGet(AOP(right),0,FALSE,FALSE));
-         while(--size)
-           emitpcode(POC_IORFW, popGet(AOP(right),++offset,FALSE,FALSE));
+       DEBUGpic14_emitcode(";left lit","lit = %d,sign=%d",lit,sign);
 
-         genSkipz(ifx,IC_TRUE(ifx) != NULL);
+       if(size==1) {
+         if(sign) {
+           if(lit & 0x80) {
+             emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),7,0));
+           } else {
+             emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),0,FALSE,FALSE),7,0));
+           }
+           if(IC_TRUE(ifx) != NULL)
+             emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
+           else
+             emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
+         }
+         emitpcode(POC_MOVLW, popGetLit((lit+1) & 0xff));
+         emitpcode(POC_SUBFW, popGet(AOP(right),0,FALSE,FALSE));
+         genSkipc(ifx,IC_TRUE(ifx)!=NULL);
        } else {
+         size--;
+         //lit++;
+         i = (lit >> (size*8)) & 0xff;
 
-         while(size--) {
-           i = (lit >> (size*8)) & 0xff;
-           if(i == 0) {
-             emitpcode(POC_MOVFW, popGet(AOP(right),size,FALSE,FALSE));
-             genSkipz(ifx,IC_TRUE(ifx) != NULL);
-           } else if( i == 1 ) {
-             emitpcode(POC_DECFW, popGet(AOP(right),size,FALSE,FALSE));
-             genSkipz(ifx,IC_TRUE(ifx) != NULL);
-
+         if(sign) {
+           if(i & 0x80) {
+             emitpcode(POC_BTFSS, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
            } else {
-             emitpcode(POC_MOVLW, popGetLit(i));
-             emitpcode(POC_SUBFW, popGet(AOP(right),size,FALSE,FALSE));
-
-             genSkipc(ifx,IC_TRUE(ifx) != NULL);
+             emitpcode(POC_BTFSC, newpCodeOpBit(aopGet(AOP(right),size,FALSE,FALSE),7,0));
            }
+           if(IC_TRUE(ifx) != NULL)
+             emitpcode(POC_GOTO,popGetLabel(IC_TRUE(ifx)->key));
+           else
+             emitpcode(POC_GOTO,popGetLabel(IC_FALSE(ifx)->key));
+         }
+
+         emitpcode(POC_MOVFW, popGet(AOP(right),size,FALSE,FALSE));
+         emitpcode(POC_SUBLW, popGetLit((i)&0xff));
+         while(size--) {
+           i = (lit >> (size*8)) & 0xff;
+           emitpcode(POC_MOVFW, popGet(AOP(right),size,FALSE,FALSE));
+           emitSKPNC;
+           emitpcode(POC_SUBLW, popGetLit((i)&0xff));
          }
+         genSkipc(ifx,IC_TRUE(ifx) == NULL);
+
        }
+/*
+       if(sign)
+         emitpLabel(lbl->key);
+*/
        ifx->generated = 1;
        return;
       }
@@ -4427,14 +4457,10 @@ static void genAnd (iCode *ic, iCode *ifx)
          }
        } else {
          if (AOP_TYPE(left) == AOP_ACC) {
-           pic14_emitcode("?iorwf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
            emitpcode(POC_ANDFW,popGet(AOP(right),offset,FALSE,FALSE));
-
          } else {                  
-           pic14_emitcode("movf","%s,w",aopGet(AOP(right),offset,FALSE,FALSE));
-           pic14_emitcode("?iorwf","%s,f",aopGet(AOP(left),offset,FALSE,FALSE));
            emitpcode(POC_MOVFW,popGet(AOP(right),offset,FALSE,FALSE));
-           emitpcode(POC_ANDFW,popGet(AOP(left),offset,FALSE,FALSE));
+           emitpcode(POC_ANDWF,popGet(AOP(left),offset,FALSE,FALSE));
 
          }
        }
@@ -4558,6 +4584,11 @@ static void genOr (iCode *ic, iCode *ifx)
         left = tmp;
     }
 
+    DEBUGpic14_emitcode ("; ","result %s, left %s, right %s",
+                        AopType(AOP_TYPE(result)),
+                        AopType(AOP_TYPE(left)),
+                        AopType(AOP_TYPE(right)));
+
     if(AOP_TYPE(right) == AOP_LIT)
         lit = (unsigned long)floatFromVal (AOP(right)->aopu.aop_lit);
 
@@ -4604,30 +4635,49 @@ static void genOr (iCode *ic, iCode *ifx)
                         AOP(result)->aopu.aop_dir,
                         AOP(result)->aopu.aop_dir);
              } else {
+               if( AOP_TYPE(result) == AOP_ACC) {
+                 emitpcode(POC_MOVLW, popGetLit(0));
+                 emitpcode(POC_BTFSS, popGet(AOP(right),0,FALSE,FALSE));
+                 emitpcode(POC_BTFSC, popGet(AOP(left),0,FALSE,FALSE));
+                 emitpcode(POC_MOVLW, popGetLit(1));
 
-               emitpcode(POC_BCF,   popGet(AOP(result),0,FALSE,FALSE));
-               emitpcode(POC_BTFSS, popGet(AOP(right),0,FALSE,FALSE));
-               emitpcode(POC_BTFSC, popGet(AOP(left),0,FALSE,FALSE));
-               emitpcode(POC_BSF,   popGet(AOP(result),0,FALSE,FALSE));
+               } else {
 
-               pic14_emitcode("bcf","(%s >> 3), (%s & 7)",
-                        AOP(result)->aopu.aop_dir,
-                        AOP(result)->aopu.aop_dir);
-               pic14_emitcode("btfss","(%s >> 3), (%s & 7)",
-                        AOP(right)->aopu.aop_dir,
-                        AOP(right)->aopu.aop_dir);
-               pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
-                        AOP(left)->aopu.aop_dir,
-                        AOP(left)->aopu.aop_dir);
-               pic14_emitcode("bsf","(%s >> 3), (%s & 7)",
-                        AOP(result)->aopu.aop_dir,
-                        AOP(result)->aopu.aop_dir);
+                 emitpcode(POC_BCF,   popGet(AOP(result),0,FALSE,FALSE));
+                 emitpcode(POC_BTFSS, popGet(AOP(right),0,FALSE,FALSE));
+                 emitpcode(POC_BTFSC, popGet(AOP(left),0,FALSE,FALSE));
+                 emitpcode(POC_BSF,   popGet(AOP(result),0,FALSE,FALSE));
+
+                 pic14_emitcode("bcf","(%s >> 3), (%s & 7)",
+                                AOP(result)->aopu.aop_dir,
+                                AOP(result)->aopu.aop_dir);
+                 pic14_emitcode("btfss","(%s >> 3), (%s & 7)",
+                                AOP(right)->aopu.aop_dir,
+                                AOP(right)->aopu.aop_dir);
+                 pic14_emitcode("btfsc","(%s >> 3), (%s & 7)",
+                                AOP(left)->aopu.aop_dir,
+                                AOP(left)->aopu.aop_dir);
+                 pic14_emitcode("bsf","(%s >> 3), (%s & 7)",
+                                AOP(result)->aopu.aop_dir,
+                                AOP(result)->aopu.aop_dir);
+               }
              }
-            }
-            else{
+            } else {
                 // c = bit | val;
                 symbol *tlbl = newiTempLabel(NULL);
                 pic14_emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
+
+
+               emitpcode(POC_BCF,   popGet(AOP(result),0,FALSE,FALSE));
+               if( AOP_TYPE(right) == AOP_ACC) {
+                 emitpcode(POC_IORLW, popGetLit(0));
+                 emitSKPNZ;
+                 emitpcode(POC_BTFSC, popGet(AOP(left),0,FALSE,FALSE));
+                 emitpcode(POC_BSF,   popGet(AOP(result),0,FALSE,FALSE));
+               }
+
+
+
                 if(!((AOP_TYPE(result) == AOP_CRY) && ifx))
                     pic14_emitcode(";XXX setb","c");
                 pic14_emitcode(";XXX jb","%s,%05d_DS_",
@@ -4688,6 +4738,7 @@ static void genOr (iCode *ic, iCode *ifx)
 
     /* if left is same as result */
     if(pic14_sameRegs(AOP(result),AOP(left))){
+      int know_W = -1;
       for(;size--; offset++,lit>>=8) {
        if(AOP_TYPE(right) == AOP_LIT){
          if((lit & 0xff) == 0)
@@ -4697,14 +4748,13 @@ static void genOr (iCode *ic, iCode *ifx)
            int p = my_powof2(lit & 0xff);
            if(p>=0) {
              /* only one bit is set in the literal, so use a bsf instruction */
-             emitpcode(POC_BSF,   popGet(AOP(left),offset,FALSE,FALSE));
-             pic14_emitcode("bsf","%s,%d",aopGet(AOP(left),offset,FALSE,TRUE),p);
+             emitpcode(POC_BSF,
+                       newpCodeOpBit(aopGet(AOP(left),offset,FALSE,FALSE),p,0));
            } else {
-             emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+             if(know_W != (lit & 0xff))
+               emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+             know_W = lit & 0xff;
              emitpcode(POC_IORWF, popGet(AOP(left),offset,FALSE,FALSE));
-
-             pic14_emitcode("movlw","0x%x", (lit & 0xff));
-             pic14_emitcode("iorwf","%s,f",aopGet(AOP(left),offset,FALSE,TRUE),p);
            }
                    
          }
@@ -4732,6 +4782,7 @@ static void genOr (iCode *ic, iCode *ifx)
             int sizer = max(AOP_SIZE(left),AOP_SIZE(right));
            pic14_emitcode(";XXX "," %s,%d",__FILE__,__LINE__);
 
+
             if(size)
                 pic14_emitcode(";XXX setb","c");
             while(sizer--){
@@ -8104,121 +8155,117 @@ static void genFarFarAssign (operand *result, operand *right, iCode *ic)
 /*-----------------------------------------------------------------*/
 static void genAssign (iCode *ic)
 {
-    operand *result, *right;
-    int size, offset ;
-       unsigned long lit = 0L;
+  operand *result, *right;
+  int size, offset,know_W;
+  unsigned long lit = 0L;
 
-    result = IC_RESULT(ic);
-    right  = IC_RIGHT(ic) ;
+  result = IC_RESULT(ic);
+  right  = IC_RIGHT(ic) ;
 
-    DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
 
-    /* if they are the same */
-    if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic)))
-        return ;
+  /* if they are the same */
+  if (operandsEqu (IC_RESULT(ic),IC_RIGHT(ic)))
+    return ;
 
-    aopOp(right,ic,FALSE);
-    aopOp(result,ic,TRUE);
+  aopOp(right,ic,FALSE);
+  aopOp(result,ic,TRUE);
 
-    /* if they are the same registers */
-    if (pic14_sameRegs(AOP(right),AOP(result)))
-        goto release;
+  DEBUGpic14_emitcode ("; ","result %s, right %s, size = %d",
+                      AopType(AOP_TYPE(IC_RESULT(ic))),
+                      AopType(AOP_TYPE(IC_RIGHT(ic))),
+                      AOP_SIZE(result));
 
-    /* if the result is a bit */
-    if (AOP_TYPE(result) == AOP_CRY) {
+  /* if they are the same registers */
+  if (pic14_sameRegs(AOP(right),AOP(result)))
+    goto release;
 
-        /* if the right size is a literal then
-        we know what the value is */
-        if (AOP_TYPE(right) == AOP_LIT) {
+  /* if the result is a bit */
+  if (AOP_TYPE(result) == AOP_CRY) {
+
+    /* if the right size is a literal then
+       we know what the value is */
+    if (AOP_TYPE(right) == AOP_LIT) {
          
-         emitpcode(  ( ((int) operandLitValue(right)) ? POC_BSF : POC_BCF),
-                     popGet(AOP(result),0,FALSE,FALSE));
+      emitpcode(  ( ((int) operandLitValue(right)) ? POC_BSF : POC_BCF),
+                 popGet(AOP(result),0,FALSE,FALSE));
 
-            if (((int) operandLitValue(right))) 
-             pic14_emitcode("bsf","(%s >> 3),(%s & 7)",
+      if (((int) operandLitValue(right))) 
+       pic14_emitcode("bsf","(%s >> 3),(%s & 7)",
                       AOP(result)->aopu.aop_dir,
                       AOP(result)->aopu.aop_dir);
-            else
-             pic14_emitcode("bcf","(%s >> 3),(%s & 7)",
-                AOP(result)->aopu.aop_dir,
-                AOP(result)->aopu.aop_dir);
-            goto release;
-        }
+      else
+       pic14_emitcode("bcf","(%s >> 3),(%s & 7)",
+                      AOP(result)->aopu.aop_dir,
+                      AOP(result)->aopu.aop_dir);
+      goto release;
+    }
 
-        /* the right is also a bit variable */
-        if (AOP_TYPE(right) == AOP_CRY) {
-         emitpcode(POC_BCF,    popGet(AOP(result),0,FALSE,FALSE));
-         emitpcode(POC_BTFSC,  popGet(AOP(right),0,FALSE,FALSE));
-         emitpcode(POC_BSF,    popGet(AOP(result),0,FALSE,FALSE));
+    /* the right is also a bit variable */
+    if (AOP_TYPE(right) == AOP_CRY) {
+      emitpcode(POC_BCF,    popGet(AOP(result),0,FALSE,FALSE));
+      emitpcode(POC_BTFSC,  popGet(AOP(right),0,FALSE,FALSE));
+      emitpcode(POC_BSF,    popGet(AOP(result),0,FALSE,FALSE));
+
+      pic14_emitcode("bcf","(%s >> 3),(%s & 7)",
+                    AOP(result)->aopu.aop_dir,
+                    AOP(result)->aopu.aop_dir);
+      pic14_emitcode("btfsc","(%s >> 3),(%s & 7)",
+                    AOP(right)->aopu.aop_dir,
+                    AOP(right)->aopu.aop_dir);
+      pic14_emitcode("bsf","(%s >> 3),(%s & 7)",
+                    AOP(result)->aopu.aop_dir,
+                    AOP(result)->aopu.aop_dir);
+      goto release ;
+    }
 
-         pic14_emitcode("bcf","(%s >> 3),(%s & 7)",
-                  AOP(result)->aopu.aop_dir,
-                  AOP(result)->aopu.aop_dir);
-         pic14_emitcode("btfsc","(%s >> 3),(%s & 7)",
-                  AOP(right)->aopu.aop_dir,
-                  AOP(right)->aopu.aop_dir);
-         pic14_emitcode("bsf","(%s >> 3),(%s & 7)",
-                  AOP(result)->aopu.aop_dir,
-                  AOP(result)->aopu.aop_dir);
-         goto release ;
-        }
+    /* we need to or */
+    emitpcode(POC_BCF,    popGet(AOP(result),0,FALSE,FALSE));
+    pic14_toBoolean(right);
+    emitSKPZ;
+    emitpcode(POC_BSF,    popGet(AOP(result),0,FALSE,FALSE));
+    //aopPut(AOP(result),"a",0);
+    goto release ;
+  }
 
-        /* we need to or */
-       emitpcode(POC_BCF,    popGet(AOP(result),0,FALSE,FALSE));
-        pic14_toBoolean(right);
-       emitSKPZ;
-       emitpcode(POC_BSF,    popGet(AOP(result),0,FALSE,FALSE));
-        //aopPut(AOP(result),"a",0);
-        goto release ;
-    }
+  /* bit variables done */
+  /* general case */
+  size = AOP_SIZE(result);
+  offset = 0 ;
+  if(AOP_TYPE(right) == AOP_LIT)
+    lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
 
-    /* bit variables done */
-    /* general case */
-    size = AOP_SIZE(result);
-    offset = 0 ;
-    if(AOP_TYPE(right) == AOP_LIT)
-       lit = (unsigned long)floatFromVal(AOP(right)->aopu.aop_lit);
-    if((AOP_TYPE(result) != AOP_REG) &&
-       (AOP_TYPE(right) == AOP_LIT) &&
-       !IS_FLOAT(operandType(right)) &&
-       (lit < 256L)){
+  know_W=-1;
+  while (size--) {
+    if(AOP_TYPE(right) == AOP_LIT) {
+      if(lit&0xff) {
+       if(know_W != (lit&0xff))
+         emitpcode(POC_MOVLW,popGetLit(lit&0xff));
+       know_W = lit&0xff;
+       emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
+      } else
+       emitpcode(POC_CLRF, popGet(AOP(result),offset,FALSE,FALSE));
 
-       while (size--) {
-         if((unsigned int)((lit >> (size*8)) & 0x0FFL)== 0) {
-           //pic14_emitcode("clrf","%s", aopGet(AOP(result),size,FALSE,FALSE));
-             emitpcode(POC_CLRF,popGet(AOP(result),size,FALSE,FALSE));
-           }else {
-             emitpcode(POC_MOVLW,popGet(AOP(right),size,FALSE,FALSE));
-             emitpcode(POC_MOVWF,popGet(AOP(result),size,FALSE,FALSE));
-             //pic14_emitcode("movlw","%s", aopGet(AOP(right),size,FALSE,FALSE));
-             //pic14_emitcode("movwf","%s", aopGet(AOP(result),size,FALSE,FALSE));
-           }
-       }
+      lit >>= 8;
+
+    } else if (AOP_TYPE(right) == AOP_CRY) {
+      emitpcode(POC_CLRF, popGet(AOP(result),offset,FALSE,FALSE));
+      if(offset == 0) {
+       emitpcode(POC_BTFSS, popGet(AOP(right),0,FALSE,FALSE));
+       emitpcode(POC_INCF, popGet(AOP(result),0,FALSE,FALSE));
+      }
     } else {
-       while (size--) {
-         if(AOP_TYPE(right) == AOP_LIT) {
-           emitpcode(POC_MOVLW, popGet(AOP(right),offset,FALSE,FALSE));
-           emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
-
-         } else if (AOP_TYPE(right) == AOP_CRY) {
-           emitpcode(POC_CLRF, popGet(AOP(result),offset,FALSE,FALSE));
-           if(offset == 0) {
-             emitpcode(POC_BTFSS, popGet(AOP(right),0,FALSE,FALSE));
-             emitpcode(POC_INCF, popGet(AOP(result),0,FALSE,FALSE));
-           }
-         } else {
-           emitpcode(POC_MOVFW, popGet(AOP(right),offset,FALSE,FALSE));
-           emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
-         }
-           
-         //pic14_emitcode("movwf","%s", aopGet(AOP(result),offset,FALSE,FALSE));
-         offset++;
-       }
+      emitpcode(POC_MOVFW, popGet(AOP(right),offset,FALSE,FALSE));
+      emitpcode(POC_MOVWF, popGet(AOP(result),offset,FALSE,FALSE));
     }
+           
+    offset++;
+  }
+
     
-release:
-    freeAsmop (right,NULL,ic,FALSE);
-    freeAsmop (result,NULL,ic,TRUE);
+ release:
+  freeAsmop (right,NULL,ic,FALSE);
+  freeAsmop (result,NULL,ic,TRUE);
 }   
 
 /*-----------------------------------------------------------------*/
index 99e3b661c4226d07a5375bc3cc1386f85ebaccf7..d919602c50740f8026655fb28feed25326deafba 100644 (file)
@@ -377,16 +377,22 @@ static void genAddLit2byte (operand *result, int offr, int lit)
 
 }
 
-static void genAddLit (operand *result,operand *left, int lit)
+static void genAddLit (iCode *ic, int lit)
 {
 
   int size,same;
   int lo;
 
+  operand *result;
+  operand *left;
+
   DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
-  size = pic14_getDataSize(result);
 
-  same = ((left == result) || (AOP(left) == AOP(result)));
+
+  left = IC_LEFT(ic);
+  result = IC_RESULT(ic);
+  same = pic14_sameRegs(AOP(left), AOP(result));
+  size = pic14_getDataSize(result);
 
   if(same) {
 
@@ -609,26 +615,38 @@ static void genAddLit (operand *result,operand *left, int lit)
 
     if(size == 1) {
 
-      switch(lit & 0xff) {
-      case 0:
-       emitpcode(POC_MOVFW, popGet(AOP(left),0,FALSE,FALSE));
-       emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
-       break;
-      case 1:
-       emitpcode(POC_INCFW, popGet(AOP(left),0,FALSE,FALSE));
-       emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
-       break;
-      case 0xff:
-       emitpcode(POC_DECFW, popGet(AOP(left),0,FALSE,FALSE));
-       emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
-       break;
-      default:
-       emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
-       emitpcode(POC_ADDFW, popGet(AOP(left),0,FALSE,FALSE));
-       emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
+      if(AOP_TYPE(left) == AOP_ACC) {
+       /* left addend is already in accumulator */
+       switch(lit & 0xff) {
+       case 0:
+         emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
+         break;
+       default:
+         emitpcode(POC_ADDLW, popGetLit(lit & 0xff));
+         emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
+       }
+      } else {
+       /* left addend is in a register */
+       switch(lit & 0xff) {
+       case 0:
+         emitpcode(POC_MOVFW, popGet(AOP(left),0,FALSE,FALSE));
+         emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
+         break;
+       case 1:
+         emitpcode(POC_INCFW, popGet(AOP(left),0,FALSE,FALSE));
+         emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
+         break;
+       case 0xff:
+         emitpcode(POC_DECFW, popGet(AOP(left),0,FALSE,FALSE));
+         emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
+         break;
+       default:
+         emitpcode(POC_MOVLW, popGetLit(lit & 0xff));
+         emitpcode(POC_ADDFW, popGet(AOP(left),0,FALSE,FALSE));
+         emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
+       }
       }
 
-
     } else {
 
       if(lit & 0xff) {
@@ -729,7 +747,7 @@ void genPlus (iCode *ic)
     //      offset = 0;
     DEBUGpic14_emitcode(";","adding lit to something. size %d",size);
 
-    genAddLit ( IC_RESULT(ic),IC_LEFT(ic),  lit);
+    genAddLit (ic,  lit);
 #if 0
     while(size--){
 
@@ -1121,6 +1139,10 @@ void genMinus (iCode *ic)
                   AopType(AOP_TYPE(IC_LEFT(ic))),
                   AopType(AOP_TYPE(IC_RIGHT(ic))));
 
+  DEBUGpic14_emitcode ("; ","same = %d, result-%s  left-%s",same,
+                      aopGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE),
+                      aopGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
+
   /* special cases :- */
   /* if both left & right are in bit space */
   if (AOP_TYPE(IC_LEFT(ic)) == AOP_CRY &&
@@ -1143,7 +1165,7 @@ void genMinus (iCode *ic)
     lit = (unsigned long)floatFromVal(AOP(IC_RIGHT(ic))->aopu.aop_lit);
     lit = - (long)lit;
 
-    genAddLit ( IC_RESULT(ic),IC_LEFT(ic),  lit);
+    genAddLit ( ic,  lit);
     
 #if 0
     /* add the first byte: */
@@ -1402,8 +1424,8 @@ void genMinus (iCode *ic)
 
     while(size--){
       if (!pic14_sameRegs(AOP(IC_LEFT(ic)), AOP(IC_RESULT(ic))) ) {
-       emitpcode(POC_MOVFW,  popGet(AOP(IC_LEFT(ic)),0,FALSE,FALSE));
-       emitpcode(POC_MOVWF,  popGet(AOP(IC_RESULT(ic)),0,FALSE,FALSE));
+       emitpcode(POC_MOVFW,  popGet(AOP(IC_LEFT(ic)),offset,FALSE,FALSE));
+       emitpcode(POC_MOVWF,  popGet(AOP(IC_RESULT(ic)),offset,FALSE,FALSE));
       }
       emitpcode(POC_MOVFW,  popGet(AOP(IC_RIGHT(ic)),offset,FALSE,FALSE));
       emitSKPC;
index 767fb3ecc50085e359a3f597887f58e913695cff..81c86b3665c9ae2b01e5d6ef59ca8afdff66e210 100644 (file)
@@ -1106,7 +1106,7 @@ picglue ()
     
 
   /* Put all variables into a cblock */
-  fprintf (asmFile, "\n\n\tcblock  0x0c\n\n");
+  fprintf (asmFile, "\n\n\tcblock  0x20\n\n");
 
   for(i=0; i<pic14_nRegs; i++) {
     if(regspic14[i].wasUsed && (regspic14[i].offset>=0x0c) )
index ee7c699a22cdd94e2911dadf43381a4b03868b2d..b127324a07ed49aacc5862b580b7b214e27d2ddc 100644 (file)
@@ -162,9 +162,9 @@ _pic14_getRegName (struct regs *reg)
 static void
 _pic14_genAssemblerPreamble (FILE * of)
 {
-  fprintf (of, "\tlist\tp=16c84\n");
+  fprintf (of, "\tlist\tp=16f877\n");
   fprintf (of, "\t__config _wdt_off\n");
-  fprintf (of, "\ninclude \"p16c84.inc\"\n");
+  fprintf (of, "\ninclude \"p16f877.inc\"\n");
 }
 
 /* Generate interrupt vector table. */
index fc5de12cc524b57ec1f5c9a21e6d39f7dec4db1e..99a467fccf7fa8000baad737dae74fd6a28961ee 100644 (file)
@@ -1434,7 +1434,7 @@ void addpBlock(pBlock *pb)
 
   if(!the_pFile) {
     /* First time called, we'll pass through here. */
-    _ALLOC(the_pFile,sizeof(the_pFile));
+    _ALLOC(the_pFile,sizeof(pFile));
     the_pFile->pbHead = the_pFile->pbTail = pb;
     the_pFile->functions = NULL;
     return;
@@ -2466,6 +2466,10 @@ set *register_usage(pBlock *pb)
 
 
   pBlockStats(stderr,pb);  // debug
+
+  // Mark the registers in this block as used.
+
+  MarkUsedRegisters(pb->registers);
   if(registersInCallPath) {
     /* registers were used in the functions this pBlock has called */
     /* so now, we need to see if these collide with the ones we are */
@@ -2516,8 +2520,8 @@ set *register_usage(pBlock *pb)
       r1 = setNextItem(registersInCallPath);
     }
 
-  } else
-    MarkUsedRegisters(pb->registers);
+  }// else
+  //    MarkUsedRegisters(pb->registers);
 
   registers = unionSets(pb->registers, registersInCallPath, THROW_NONE);
 
index 8fcff68bbdd20e44f17e8a02ff3ca7148cd12aa9..77703d12ca4e3ab3081d832c9becb0c7f5b966de 100644 (file)
@@ -58,6 +58,9 @@ _G;
 int pic14_ptrRegReq;           /* one byte pointer register required */
 
 /* pic14 registers */
+/* A nasty, awful, disgusting hack for register declarations */
+#ifdef p16c84
+
 regs regspic14[] =
 {
 
@@ -84,6 +87,39 @@ regs regspic14[] =
   {REG_PTR, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
 
 };
+#else
+regs regspic14[] =
+{
+  {REG_GPR, PO_GPR_TEMP, 0x20, "r0x20", "r0x20", 0x20, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x21, "r0x21", "r0x21", 0x21, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x22, "r0x22", "r0x22", 0x22, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x23, "r0x23", "r0x23", 0x23, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x24, "r0x24", "r0x24", 0x24, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x25, "r0x25", "r0x25", 0x25, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x26, "r0x26", "r0x26", 0x26, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x27, "r0x27", "r0x27", 0x27, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x28, "r0x28", "r0x28", 0x28, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x29, "r0x29", "r0x29", 0x29, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x2A, "r0x2A", "r0x2A", 0x2A, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x2B, "r0x2B", "r0x2B", 0x2B, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x2C, "r0x2C", "r0x2C", 0x2C, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x2D, "r0x2D", "r0x2D", 0x2D, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x2E, "r0x2E", "r0x2E", 0x2E, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x2F, "r0x2F", "r0x2F", 0x2F, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x30, "r0x30", "r0x30", 0x30, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x31, "r0x31", "r0x31", 0x31, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x32, "r0x32", "r0x32", 0x32, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x33, "r0x33", "r0x33", 0x33, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x34, "r0x34", "r0x34", 0x34, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x35, "r0x35", "r0x35", 0x35, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x36, "r0x36", "r0x36", 0x36, 1, 0},
+  {REG_GPR, PO_GPR_TEMP, 0x37, "r0x37", "r0x37", 0x37, 1, 0},
+
+  {REG_PTR, PO_FSR, 4, "FSR", "FSR", 4, 1, 0},
+
+};
+
+#endif
 
 int pic14_nRegs = sizeof (regspic14) / sizeof (regs);
 static void spillThis (symbol *);
index 3b740b23f3776ab2692403ce38d600b8399b4e55..196222c6f907f5b1f489ef9a7759d2ed94d9317b 100644 (file)
@@ -47,6 +47,8 @@
 
 CC = ../../bin/sdcc
 
+HEADER=/usr/local/share/gpasm/header
+
 .SUFFIXES: .asm .c .cod .stc
 
 # Results of the test are placed here:
@@ -73,6 +75,7 @@ SRC = b.c \
        compare5.c \
        compare6.c \
        for.c \
+       or1.c \
        rotate1.c \
        rotate2.c \
        rotate3.c \
@@ -97,7 +100,7 @@ all: test
 # The .cod files are generated by gpasm
 # these get loaded by gpsim.
 .asm.cod:
-       gpasm -c $*.asm
+       gpasm -c -I $(HEADER) $*.asm
 
 # The .stc files are script files for gpsim
 .cod.stc:
index 3588708646ace9476ba9695e7cc50a3a2dfaefd4..e218dc15cd0556a681d9e9631314934f68aecfe7 100644 (file)
@@ -68,6 +68,17 @@ void add_char2char(void)
 
 }
 
+void add_compound_char(void)
+{
+  char0 = char1+5;
+
+  if(char0 != 9)
+    failures++;
+
+  if((char0+char1) != 13)
+    failures++;
+}
+
 void add_int2int(void)
 {
   if(int0 != 4)
@@ -85,6 +96,18 @@ void add_int2int(void)
 
 }
 
+void add_compound_int(void)
+{
+  int0 = int1+5;
+
+  if(int0 != 9)
+    failures++;
+
+  if((int0+int1) != 13)
+    failures++;
+}
+
+
 void add_lit2long(void)
 {
 
@@ -179,10 +202,16 @@ void main(void)
   char1 = char0 + 1;
   add_char2char();
 
+  char1=4;
+  add_compound_char();
+
   int0 = 4;
   int1 = int0 + 1;
   add_int2int();
 
+  int1=4;
+  add_compound_int();
+
   add_lit2long();
   add_lit2ulong();
 
index c566bd9ffd2d135fd28d4049c3d81f8580e529e0..3353cedaa423a25be275a4cb2ae45a328c143ba7 100644 (file)
@@ -104,6 +104,24 @@ void and_lit2ulong(void)
     failures++;
 }
 
+/*-----------*/
+void and_uchar2uchar(void)
+{
+
+  uchar0 &= uchar1;
+
+  if(uchar0 != 0x0f)
+    failures++;
+
+  uchar1 &= 0xf7;
+
+  uchar0 = uchar1 & 0xfe;
+
+  if(uchar0 != 0x06)
+    failures++;
+
+}
+
 void main(void)
 {
 
@@ -116,6 +134,10 @@ void main(void)
   ulong0 = 0xffffffff;
   and_lit2ulong();
 
+  uchar0 = 0xff;
+  uchar1 = 0x0f;
+  and_uchar2uchar();
+
   success = failures;
   done();
 }
index 7ef1aa0958bbb664303de528bbeb619ebb3637ef..f58c4fbee9a4de33b79afa56f65fd6309ed175d5 100644 (file)
@@ -77,6 +77,80 @@ char_gte_lit (void)
 }
 
 
+/* now repeat test using negative logic */
+void
+char_lt_char_else (void)
+{
+  if (achar0 >= achar1)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+char_gt_char_else (void)
+{
+  if (achar1 <= achar0)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+char_lte_char_else (void)
+{
+  if (achar0 > achar1)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+char_gte_char_else (void)
+{
+  if (achar1 < achar0)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+char_lt_lit_else (void)
+{
+  if (achar1 >= 0x10)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+char_gt_lit_else (void)
+{
+  if (achar1 <= 0x10)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+char_lte_lit_else (void)
+{
+  if (achar1 > 0x0f)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+char_gte_lit_else (void)
+{
+  if (achar1 < 0x11)
+    dummy++;
+  else
+    failures++;
+}
+
+
 /* ints */
 
 void
@@ -138,6 +212,82 @@ int_gte_lit (void)
 
 
 
+/* now repeat int comparisons using negative logic */
+
+void
+int_lt_int_else (void)
+{
+  if (aint0 >= aint1)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+int_gt_int_else (void)
+{
+  if (aint1 <= aint0)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+int_lte_int_else (void)
+{
+  if (aint0 > aint1)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+int_gte_int_else (void)
+{
+  if (aint1 < aint0)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+int_lt_lit_else (void)
+{
+  if (aint1 >= 0x10)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+int_gt_lit_else (void)
+{
+  if (aint1 <= 0x10)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+int_lte_lit_else (void)
+{
+  if (aint1 > 0x0f)
+    dummy++;
+  else
+    failures++;
+}
+
+void
+int_gte_lit_else (void)
+{
+  if (aint1 < 0x11)
+    dummy++;
+  else
+    failures++;
+}
+
+
+
 
 
 
@@ -161,6 +311,25 @@ main (void)
   char_gte_lit ();
 
 
+  achar0 = 0;
+  achar1 = 0;
+
+  char_lt_char_else ();
+  char_gt_char_else ();
+
+  achar0++;
+  char_lt_char_else ();
+  char_gt_char_else ();
+  char_gte_char_else ();
+  char_lte_char_else ();
+
+  achar1 = 0x10;
+  char_lt_lit_else ();
+  char_gt_lit_else ();
+  char_lte_lit_else ();
+  char_gte_lit_else ();
+
+
 
   int_lt_int ();
   int_gt_int ();
@@ -174,6 +343,25 @@ main (void)
   aint1 = 0x10;
   int_lt_lit ();
   int_gt_lit ();
+  int_lte_lit ();
+  int_gte_lit ();
+
+  aint0=0;
+  aint1=0;
+  int_lt_int_else ();
+  int_gt_int_else ();
+
+  aint0++;
+  int_lt_int_else ();
+  int_gt_int_else ();
+  int_gte_int_else ();
+  int_lte_int_else ();
+
+  aint1 = 0x10;
+  int_lt_lit_else ();
+  int_gt_lit_else ();
+  int_lte_lit_else ();
+  int_gte_lit_else ();
 
   success = failures;
   done ();
index 5c7e01522fd9c876e5f652cab708f680a2bf3e17..4b923dae77b170871b2293d43aaa2ca971ac129a 100644 (file)
@@ -184,9 +184,9 @@ void c_20000(void)
   if(long0 < 0x10000)
     failures++;
 
-  if(long0 < 0x12345)
+/*  if(long0 < 0x12345)
     failures++;
-
+*/
   if(long0 == 0)
     failures++;
 }
@@ -306,10 +306,10 @@ void c_minus1(void)
 
   if(long1 < 0)
     failures++;
-
+/*
   if(long1 < 2)
     failures++;
-
+*/
 }
 
 // assumes
index aed33a87d21f18ccf16bd96f344c1d8a55885615..a6245070b60c00af00e5cd76017bf11e2c36cee6 100644 (file)
@@ -5,10 +5,10 @@ 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;
+unsigned int uint0 = 0;
+unsigned int uint1 = 0;
+unsigned char uchar0 = 0;
+unsigned char uchar1 = 0;
 
 unsigned char call3(void);
 
@@ -24,9 +24,9 @@ void for1(void)
   unsigned char i=0;
 
   for(i=0; i<10; i++)
-    achar0++;
+    uchar0++;
 
-  if(achar0 != 10)
+  if(uchar0 != 10)
     failures++;
 
 }
@@ -36,17 +36,73 @@ void for2(void)
   unsigned char i=0;
 
   for(i=0; i<10; i++)
-    achar0++;
+    uchar0++;
 
   if(i < 10)
     failures++;
 
 }
 
+void for3(void)
+{
+  unsigned int i=0;
+
+  for(i=0; i<10; i++)
+    uint0++;
+
+  if(i < 10)
+    failures++;
+
+}
+
+void for4(void)
+{
+
+  for(uint0=1; uint0<10; uint0++)
+    uchar0++;
+
+  if(uchar0 != 9)
+    failures++;
+
+}
+
+void for5(void)
+{
+
+  for(uint0=1; uint0<=10; uint0++)
+    uchar0++;
+
+  if(uchar0 != 10)
+    failures++;
+
+}
+
+void inc_uchar0(void)
+{
+  uchar0++;
+}
+
+void for6(void)
+{
+  uchar0 = 0;
+  for(uint0=1; uint0<=10; uint0++)
+    inc_uchar0();
+
+}
+
 void main(void)
 {
   for1();
   for2();
+  for3();
+  uchar0 = 0;
+  for4();
+  uchar0 = 0;
+  for5();
+
+  for6();
+  if(uchar0 != 10)
+    failures++;
 
   success = failures;
   done();
diff --git a/src/regression/rt.sh b/src/regression/rt.sh
new file mode 100755 (executable)
index 0000000..6e7273d
--- /dev/null
@@ -0,0 +1,16 @@
+# test Script
+
+USAGE="Usage: `basename $0` BASENAME"
+
+if [ $# -lt 1 ] ; then
+  echo "$USAGE"
+  exit 1
+fi
+
+# compile
+../../bin/sdcc -c -mpic14 $1.c
+gpasm -c  -I /usr/local/share/gpasm/header $1.asm
+./create_stc $1.cod $1.stc
+./simulate $1.stc garbage.log
+cat garbage.log
+rm garbage.log
\ No newline at end of file
index b2d74e29e4c8a0cedaac3d2e9acca2f15dc71d47..b4c7891f2801edd3c98daedd113aba375ed642d8 100644 (file)
@@ -121,6 +121,31 @@ void assign_char2int(void)
 
 }
 
+
+void sub_compound_char(void)
+{
+
+  char0 = char1 - 5;
+  if(char0 != 4)
+    failures++;
+
+  if((char1 - char0 - 5) != 0)
+    failures++;
+
+}
+
+void sub_compound_int(void)
+{
+
+  int0 = int1 - 5;
+  if(int0 != 4)
+    failures++;
+
+  if((int1 - int0 - 5) != 0)
+    failures++;
+
+}
+
 void main(void)
 {
 
@@ -139,6 +164,12 @@ void main(void)
   char1 = -5;
   assign_char2int();
 
+  char1 = 9;
+  sub_compound_char();
+  
+  int1 = 9;
+  sub_compound_int();
+
   success = failures;
   done();
 }