Added regression tests for compound comparisons.
authorsdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 7 Aug 2002 13:13:47 +0000 (13:13 +0000)
committersdattalo <sdattalo@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Wed, 7 Aug 2002 13:13:47 +0000 (13:13 +0000)
-- 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
src/pic/device.c
src/pic/gen.c
src/pic/genarith.c
src/pic/pcode.c
src/pic/pcodepeep.c
src/pic/ralloc.c
src/regression/Makefile
src/regression/bool2.c [new file with mode: 0644]
src/regression/bool3.c [new file with mode: 0644]
src/regression/string1.c

index b19179fca66aaf588d4ee5af978c3b5c703a68ff..2721c1d8d9f3c00269ad959f24f960a65457469f 100644 (file)
@@ -1173,10 +1173,17 @@ checkSClass (symbol * sym, int isProto)
     }
   
   /* if absolute address given then it mark it as
     }
   
   /* 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 &&
   /* global variables declared const put into code */
   /* if no other storage class specified */
   if (sym->level == 0 &&
index ad21be45cb51a52689ec38f4bb0bc5a954e986c3..ee12eb5dd8a97b488d939fee5ffdf36cdff51b17 100644 (file)
@@ -484,7 +484,7 @@ int assignRegister(regs *reg, int start_address)
   if(reg->isFixed) {
 
     if (validAddress(reg->address,reg->size)) {
   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;
     }
       mapRegister(reg);
       return reg->address;
     }
@@ -493,8 +493,9 @@ int assignRegister(regs *reg, int start_address)
       mapRegister(reg);
       return reg->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 {
 
 
   } else {
 
index 0df7a930dbbcc249d223c1cb5a312d455afbb377..3cdfcfb5f0d3b9622f44150d0200e3461cfcc6a5 100644 (file)
@@ -1112,11 +1112,11 @@ char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
        return rs;
        
     case AOP_STR:
        return rs;
        
     case AOP_STR:
-        DEBUGpic14_emitcode(";","%d",__LINE__);
        aop->coff = offset ;
        if (strcmp(aop->aopu.aop_str[offset],"a") == 0 &&
            dname)
            return "acc";
        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];
        
        
        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_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);
        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);
   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 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__);
   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);
 
   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++;
        emitSKPNZ;
        emitpcode(POC_GOTO,popGetLabel(lbl->key));
        offset++;
+       if(res_offset < res_size-1)
+         res_offset++;
        lit >>= 8;
       }
       break;
        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))) {
           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 {
        } 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){
 
   } 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++;
        emitSKPZ;
       emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
       offset++;
+      if(res_offset < res_size-1)
+       res_offset++;
     }
       
   }else{
     }
       
   }else{
@@ -4676,8 +4702,15 @@ static void gencjne(operand *left, operand *right, operand *result, iCode *ifx)
       offset++;
     }
   }
       offset++;
     }
   }
+
+  emitpcode(POC_INCF,popGet(AOP(result),res_offset));
+  if(!rIfx.condition)
+    emitpcode(POC_GOTO,popGetLabel(rIfx.lbl->key));
+
   emitpLabel(lbl->key);
 
   emitpLabel(lbl->key);
 
+  DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
+
   if(ifx)
     ifx->generated = 1;
 }
   if(ifx)
     ifx->generated = 1;
 }
@@ -4964,6 +4997,7 @@ static void genCmpEq (iCode *ic, iCode *ifx)
         pic14_outBitC(result);
     } else {
       
         pic14_outBitC(result);
     } else {
       
+      DEBUGpic14_emitcode ("; ***","%s  %d",__FUNCTION__,__LINE__);
       gencjne(left,right,result,ifx);
 /*
       if(ifx) 
       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;
 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
 
     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);
 
     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 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));
 
     freeAsmop(left,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
     freeAsmop(right,NULL,ic,(RESULTONSTACK(ic) ? FALSE : TRUE));
index 9bdf0bd306d6e7d55fce645b7fa6779fa15015d1..241ca2f3171b244374aec5ded7dd7d65ec5b15e4 100644 (file)
@@ -738,34 +738,50 @@ static void genAddLit (iCode *ic, int lit)
       }
 
     } else {
       }
 
     } 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));
 
       /* 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));
        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);
       //emitpcode(POC_MOVWF, popGet(AOP(result),0,FALSE,FALSE));
       emitMOVWF(result,0);
-      lit >>= 8;
       while(--size) {
       
       while(--size) {
       
+       lit >>= 8;
        if(lit & 0xff) {
        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));
        }
        } 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++;
       }
     }
   }
       }
     }
   }
index 066ad6335f129a99699af531e381b724e37bb5b4..83f9737be2b05bd5f7dd20f590323a846c035307 100644 (file)
@@ -1931,7 +1931,7 @@ pCode *newpCodeLabel(char *name, int key)
   if(s)
     pcl->label = Safe_strdup(s);
 
   if(s)
     pcl->label = Safe_strdup(s);
 
-
+  //fprintf(stderr,"newpCodeLabel: key=%d, name=%s\n",key, ((s)?s:""));
   return ( (pCode *)pcl);
 
 }
   return ( (pCode *)pcl);
 
 }
@@ -2007,6 +2007,7 @@ pCodeOp *newpCodeOpLabel(char *name, int key)
 
   ((pCodeOpLabel *)pcop)->key = key;
 
 
   ((pCodeOpLabel *)pcop)->key = key;
 
+  //fprintf(stderr,"newpCodeOpLabel: key=%d, name=%s\n",key,((s)?s:""));
   return pcop;
 }
 
   return pcop;
 }
 
@@ -3690,7 +3691,9 @@ void LinkFlow(pBlock *pb)
       if( (pct = findLabelinpBlock(pb,pcol)) != NULL)
        LinkFlow_pCode(PCI(pc),PCI(pct));
       else
       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;
     }
 
       continue;
     }
@@ -3875,7 +3878,6 @@ void FixRegisterBankingInFlow(pCodeFlow *pcfl, int cur_bank)
 
   while(isPCinFlow(pc,PCODE(pcfl))) {
 
 
   while(isPCinFlow(pc,PCODE(pcfl))) {
 
-
     reg = getRegFromInstruction(pc);
 #if 0
     if(reg) {
     reg = getRegFromInstruction(pc);
 #if 0
     if(reg) {
@@ -3885,15 +3887,23 @@ void FixRegisterBankingInFlow(pCodeFlow *pcfl, int cur_bank)
     }
 #endif
 
     }
 #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);
       /* 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))) {
       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");
 
        //fprintf(stderr, "Cool! can switch banks\n");
-       cur_bank = REG_BANK(reg);
+       cur_bank = reg_bank;
        switch(b & 3) {
        case 0:
          break;
        switch(b & 3) {
        case 0:
          break;
@@ -3911,20 +3921,6 @@ void FixRegisterBankingInFlow(pCodeFlow *pcfl, int cur_bank)
          } else
            insertBankSwitch(0, pc, -1, -1);
          break;
          } 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)
 {
 
 void exchangeLabels(pCodeLabel *pcl, pCode *pc)
 {
 
+  char *s=NULL;
+
   if(isPCI(pc) && 
      (PCI(pc)->pcop) && 
      (PCI(pc)->pcop->type == PO_LABEL)) {
   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);
 
     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);
 
     pcol->key = pcl->key;
     //pc->print(stderr,pc);
 
@@ -4537,16 +4545,23 @@ void FixRegisterBanking(pBlock *pb)
 
        }
 #endif
 
        }
 #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);
          /* 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))) {
          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;
            switch(b & 3) {
            case 0:
              break;
@@ -4567,7 +4582,6 @@ void FixRegisterBanking(pBlock *pb)
 
            }
 
 
            }
 
-
          }else {
            //fprintf(stderr, "Bummer can't switch banks\n");
            ;
          }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)
 {
 
 void pBlockDestruct(pBlock *pb)
 {
 
index 81aabf13eca49699879a0b1b2db08da6e67a0e00..e6eea82256cf4ad87a8b60c6d9f5e940915a7515 100644 (file)
@@ -35,7 +35,7 @@
 #endif
 
 pCodeOp *popCopyGPR2Bit(pCodeOpReg *pc, int bitval);
 #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);
 
 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)
 {
 /*-----------------------------------------------------------------*/
 static void * cvt_altpat_mnem2(void *pp,pCodeWildBlock *pcwb)
 {
index 787b1b73f4c980fe94941e5b64af9f9a1deb1d97..a920ac09cc3e2759e19410c8732dcd1e4d86f99a 100644 (file)
@@ -73,6 +73,7 @@ set *dynDirectBitRegs=NULL;
 set *dynInternalRegs=NULL;
 
 static hTab  *dynDirectRegNames= 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;
 
 static int dynrIdx=0x20;
 static int rDirectIdx=0;
@@ -661,7 +662,7 @@ allocDirReg (operand *op )
              name, SPEC_ADDR ( OP_SYM_ETYPE(op)));
 */
   } else {
              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);
   }
     
     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));
     /* 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
     }
 
     /* 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                                      */
 /*-----------------------------------------------------------------*/
 /* 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))) {
   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))
 
       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);
     }
 
       printSymType("   ", OP_SYMBOL(IC_LEFT(ic))->type);
     }
index ecce4316f90a26dcf2be0cfae662420629a948fd..8cfaabf0e8edaa5153d6fe3fd968e9d8d2b01828 100644 (file)
@@ -67,6 +67,8 @@ SRC = b.c \
        add3.c \
        and1.c \
        bool1.c \
        add3.c \
        and1.c \
        bool1.c \
+       bool2.c \
+       bool3.c \
        call1.c \
        compare.c \
        compare2.c \
        call1.c \
        compare.c \
        compare2.c \
diff --git a/src/regression/bool2.c b/src/regression/bool2.c
new file mode 100644 (file)
index 0000000..e1062c2
--- /dev/null
@@ -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 (file)
index 0000000..4c3e358
--- /dev/null
@@ -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();
+}
index 3f169c300aedbd3d2529a54ad829323e44e6ffd3..51d547629db43f4f54b9c1bbbacd95a569454496 100644 (file)
@@ -31,7 +31,7 @@ void  isr(void) interrupt 1 using 1
 
 void lcd1(const unsigned char *str)
 {
 
 void lcd1(const unsigned char *str)
 {
-  const char *p = "hellow world!\r\n";
+  const char *p = "hello world!\r\n";
 
   if(!str)
     failures++;
 
   if(!str)
     failures++;