some -xstack related stuff
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 11 Nov 2000 02:13:58 +0000 (02:13 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sat, 11 Nov 2000 02:13:58 +0000 (02:13 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@495 4a8a32a2-be11-0410-ad9d-d568d2c75423

device/lib/_spx.c
src/SDCCicode.c
src/SDCCicode.h
src/SDCClrange.c
src/avr/gen.c
src/avr/ralloc.c
src/mcs51/gen.c
src/mcs51/ralloc.c

index 07a61e7e2ca747d62793b56b3817248fc76fd04f..50e67c30d8b096c7c3cedf9ca8f6f6e0c8075b7e 100644 (file)
@@ -24,3 +24,4 @@
 -------------------------------------------------------------------------*/
 
 data unsigned char spx ;
+data unsigned char _page_no__;
index 941cbb78b833907bbb76b49a5d64a8b233ad2aa1..36410ad3328e43e1ecbfaffd1e6f4283e8316393 100644 (file)
@@ -756,6 +756,24 @@ bool isOperandInFarSpace (operand *op)
     return (IN_FARSPACE(SPEC_OCLS(etype)) ? TRUE : FALSE);
 }
 
+/*-----------------------------------------------------------------*/
+/* isOperandOnStack - will return true if operand is on stack      */
+/*-----------------------------------------------------------------*/
+bool isOperandOnStack(operand *op)
+{
+    link *etype;
+
+    if (!op)
+       return FALSE;
+
+    if (!IS_SYMOP(op))
+       return FALSE ;
+
+    etype = getSpec(operandType(op));
+
+    return ((IN_STACK(etype)) ? TRUE : FALSE);
+}
+
 /*-----------------------------------------------------------------*/
 /* operandLitValue - literal value of an operand                   */
 /*-----------------------------------------------------------------*/
@@ -2307,7 +2325,7 @@ static void geniCodeSEParms (ast *parms)
 /*-----------------------------------------------------------------*/
 /* geniCodeParms - generates parameters                            */
 /*-----------------------------------------------------------------*/
-static void geniCodeParms ( ast *parms , int *stack, link *fetype)
+static void geniCodeParms ( ast *parms , int *stack, link *fetype, symbol *func)
 {
     iCode *ic ;
     operand *pval ; 
@@ -2317,8 +2335,8 @@ static void geniCodeParms ( ast *parms , int *stack, link *fetype)
     
     /* if this is a param node then do the left & right */
     if (parms->type == EX_OP && parms->opval.op == PARAM) {
-       geniCodeParms (parms->left, stack,fetype) ;
-       geniCodeParms (parms->right, stack,fetype);
+       geniCodeParms (parms->left, stack,fetype,func) ;
+       geniCodeParms (parms->right, stack,fetype,func);
        return ;
     }
     
@@ -2342,8 +2360,7 @@ static void geniCodeParms ( ast *parms , int *stack, link *fetype)
 
     /* if register parm then make it a send */
     if (((parms->argSym && IS_REGPARM(parms->argSym->etype)) ||
-       IS_REGPARM(parms->etype)) && 
-       !IS_RENT(fetype)) {
+       IS_REGPARM(parms->etype)) && !func->hasVargs ) {
        ic = newiCode(SEND,pval,NULL);
        ADDTOCHAIN(ic);
     } else {
@@ -2383,7 +2400,7 @@ operand *geniCodeCall (operand *left, ast *parms)
     geniCodeSEParms ( parms );
 
     /* first the parameters */
-    geniCodeParms ( parms , &stack , getSpec(operandType(left)));
+    geniCodeParms ( parms , &stack , getSpec(operandType(left)), OP_SYMBOL(left));
     
     /* now call : if symbol then pcall */
     if (IS_ITEMP(left)) 
index 259cef8a17c5dcc24f390936100dea7792879ae9..b394c56d0db5694af82f9b034ba5c85f42684d7c 100644 (file)
@@ -245,6 +245,7 @@ typedef struct icodeFuncTable
 /* forward references for functions                                */
 /*-----------------------------------------------------------------*/
 iCode   *reverseiCChain     (      );
+bool     isOperandOnStack   (operand *);
 int      isOperandVolatile  (operand *,bool);
 int      isOperandGlobal    (operand *);
 void     printiCChain    ( iCode * , FILE *);
index bba270ef3f4e9788f3da3041eee9655212dfe02c..7e6ea7c05afe8ec004928f42e02704c3da15316b 100644 (file)
@@ -517,7 +517,7 @@ void rlivePoint (eBBlock **ebbs, int count)
                    /* if it is live then add the lrange to ic->rlive */
                if (lrange->liveFrom <= ic->seq &&
                    lrange->liveTo   >= ic->seq ) {
-                       lrange->isLiveFcall = (ic->op == CALL || ic->op == PCALL);
+                       lrange->isLiveFcall |= (ic->op == CALL || ic->op == PCALL || ic->op == SEND);
                        ic->rlive = bitVectSetBit(ic->rlive,lrange->key);
                }
            }
index bea96d6f92645786af9ee1155485efc505ad233e..3f53aebd84c4c5d85e8064544be5b2ef196e4704 100644 (file)
@@ -63,7 +63,6 @@ static char *spname ;
 char *fReturnAVR[] = {"r16","r17","r18","r19" };
 unsigned fAVRReturnSize = 4; /* shared with ralloc.c */
 char **fAVRReturn = fReturnAVR;
-
 static short rbank = -1;
 static char *larray[4] = {"lo8","hi8","hlo8","hhi8"};
 static char *tscr[4] = {"r0","r1","r24","r25"};
@@ -1303,7 +1302,7 @@ static void genCall (iCode *ic)
        /* if send set is not empty the assign */
        if (_G.sendSet) {
                iCode *sic ;
-
+               int rnum = 16;
                for (sic = setFirstItem(_G.sendSet) ; sic ; 
                     sic = setNextItem(_G.sendSet)) {
                        int size, offset = 0;
@@ -1311,10 +1310,10 @@ static void genCall (iCode *ic)
                        size = AOP_SIZE(IC_LEFT(sic));
                        while (size--) {
                                char *l = aopGet(AOP(IC_LEFT(sic)),offset);
-                               if (strcmp(l,fAVRReturn[offset]))
-                                       emitcode("mov","%s,%s",
-                                                fAVRReturn[offset],
-                                                l);
+                               char *b = buffer;
+                               sprintf(buffer,"r%d",rnum++);
+                               if (strcmp(l,b))
+                                       emitcode("mov","%s,%s",b,l);
                                offset++;
                        }
                        freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
@@ -1365,7 +1364,7 @@ static void genPcall (iCode *ic)
        /* if send set is not empty the assign */
        if (_G.sendSet) {
                iCode *sic ;
-
+               int rnum = 16;
                for (sic = setFirstItem(_G.sendSet) ; sic ; 
                     sic = setNextItem(_G.sendSet)) {
                        int size, offset = 0;
@@ -1373,10 +1372,10 @@ static void genPcall (iCode *ic)
                        size = AOP_SIZE(IC_LEFT(sic));
                        while (size--) {
                                char *l = aopGet(AOP(IC_LEFT(sic)),offset);
-                               if (strcmp(l,fAVRReturn[offset]))
-                                       emitcode("mov","%s,%s",
-                                                fAVRReturn[offset],
-                                                l);
+                               char *b = buffer;
+                               sprintf(b,"r%d",rnum++);
+                               if (strcmp(l,b))
+                                       emitcode("mov","%s,%s",b,l);
                                offset++;
                        }
                        freeAsmop (IC_LEFT(sic),NULL,sic,TRUE);
@@ -2064,6 +2063,7 @@ static int revavrcnd(int type)
                if (rar[i].rtype== type) return rar[i].type;
        }
        assert(1); /* cannot happen */
+       return 0;  /* makes the compiler happy */
 }
 
 static char *br_name[4] = {"breq","brne","brlt","brge"};
@@ -2487,6 +2487,20 @@ static void genBitWise(iCode *ic, iCode *ifx, int bitop)
        samerl = sameRegs(AOP(IC_RESULT(ic)),AOP(IC_LEFT(ic)));
        samerr = sameRegs(AOP(IC_RESULT(ic)),AOP(IC_RIGHT(ic)));
        while (size--) {
+               if (AOP_TYPE(right) == AOP_LIT) {
+                       unsigned int lit = (int) floatFromVal (AOP(right)->aopu.aop_lit);
+                       if (((lit >> (8*offset)) & 0xff) == 0) {
+                               if (bitop == AVR_AND) {
+                                       aopPut(AOP(result),zero,offset++);
+                                       continue;
+                               } else if (bitop == AVR_OR) {
+                                       if (!samerl)
+                                               aopPut(AOP(result),aopGet(AOP(left),offset),offset);
+                                       offset++;
+                                       continue;
+                               }
+                       }
+               }
                if (samerl) {
                        if (AOP_TYPE(IC_RIGHT(ic)) == AOP_LIT && (bitop == AVR_AND || bitop == AVR_OR)) {
                                emitcode(bopnames_lit[bitop],"%s,%s(%d)",aopGet(AOP(IC_LEFT(ic)),offset),
@@ -2577,7 +2591,6 @@ static void genRotC (iCode *ic, int lr)
 {
        operand *left , *result ;
        int size, offset = 0;
-       char *l;    
 
        /* rotate right with carry */
        left = IC_LEFT(ic);
@@ -2717,46 +2730,21 @@ static void genShiftLeftLit (iCode *ic)
                        lByteZ = 1;
                }
                if (shCount >= 4) {
-                       if (lByteZ) {
-                               emitcode("swap","%s",aopGet(AOP(result),1));
-                               emitcode("andi","%s,0xf0",aopGet(AOP(result),1));
-                               shCount -= 4;                           
-                       } else {
-                               int ssh;
-                               shCount -= 4;
-                               ssh = shCount;
-                               if (sameRegs(AOP(left),AOP(result))) {
-                                       emitcode("mov","r1,%s",aopGet(AOP(left),0));
-                                       emitcode("swap","%s",aopGet(AOP(left),0));
-                                       emitcode("andi","%s,0xf0",aopGet(AOP(left),0));
-                                       emitcode("andi","r1,0x0f");
-                                       while(shCount--) {
-                                               emitcode("lsl","%s",aopGet(AOP(left),0));
-                                               emitcode("lsl","r1");
-                                       }
-                                       emitcode("swap","%s",aopGet(AOP(result),1));
-                                       emitcode("andi","%s,0xf0",aopGet(AOP(result),1));
-                                       while (ssh--) emitcode("lsl","%s",aopGet(AOP(result),1));
-                                       emitcode("or","%s,r1",aopGet(AOP(result),1));
-                                       shCount =0;
-                               } else {
-                                       MOVR0(aopGet(AOP(left),0));
-                                       emitcode("mov","r1,r0");
-                                       emitcode("swap","r0");
-                                       emitcode("andi","r0,0xf0");
-                                       emitcode("andi","r1,0x0f");
-                                       while(shCount--) {
-                                               emitcode("lsl","r0");
-                                               emitcode("lsl","r1");
-                                       }
-                                       aopPut(AOP(result),"r0",0);
-                                       aopPut(AOP(result),aopGet(AOP(left),1),1);
-                                       emitcode("swap","%s",aopGet(AOP(result),1));
-                                       emitcode("andi","%s,0xf0",aopGet(AOP(result),1));
-                                       while (ssh--) emitcode("lsl","%s",aopGet(AOP(result),1));
-                                       emitcode("or","%s,r1",aopGet(AOP(result),1));
-                                       shCount =0;
-                               }
+                       shCount -= 4;
+                       if (!sameRegs(AOP(left),AOP(result))) {
+                               aopPut(AOP(result),aopGet(AOP(left),0),0);
+                               aopPut(AOP(result),aopGet(AOP(left),1),1);                                      
+                       }
+                       emitcode("mov","r1,%s",aopGet(AOP(result),0));
+                       emitcode("swap","%s",aopGet(AOP(result),0));
+                       emitcode("andi","%s,0xf0",aopGet(AOP(result),0));
+                       emitcode("andi","r1,0x0f");
+                       emitcode("swap","%s",aopGet(AOP(result),1));
+                       emitcode("andi","%s,0xf0",aopGet(AOP(result),1));
+                       emitcode("or","%s,r1",aopGet(AOP(result),1));
+                       while(shCount--) {
+                               emitcode("lsl","%s",aopGet(AOP(result),0));
+                               emitcode("rol","%s",aopGet(AOP(result),1));
                        }
                }
                if (!lByteZ && !sameRegs(AOP(result),AOP(left)) && shCount) {
@@ -2843,7 +2831,6 @@ static void genShiftLeftLit (iCode *ic)
                                break;
                        }
                }
-
        }
 
  release:      
@@ -2859,8 +2846,7 @@ static void genLeftShift (iCode *ic)
 {
        operand *left,*right, *result;
        int size, offset;
-       char *l;
-       symbol *tlbl , *tlbl1;
+       symbol *tlbl;
 
        right = IC_RIGHT(ic);
        left  = IC_LEFT(ic);
@@ -2907,6 +2893,210 @@ static void genLeftShift (iCode *ic)
        else emitcode("dec","r24");
        emitcode("brne","L%05d",tlbl->key);
        
+       freeAsmop(left,NULL,ic,TRUE);
+       freeAsmop(right,NULL,ic,TRUE);
+       freeAsmop(result,NULL,ic,TRUE);
+}
+
+/*-----------------------------------------------------------------*/
+/* genShiftRightLit - generate for right shift with known count    */
+/*-----------------------------------------------------------------*/
+static void genShiftRightLit (iCode *ic)
+{
+       operand *left = IC_LEFT(ic)
+               ,*right= IC_RIGHT(ic)
+               ,*result=IC_RESULT(ic);
+       int size , shCount, offset =0;
+       int hByteZ=0;
+       link *letype = getSpec(operandType(left));
+       int sign = !SPEC_USIGN(letype);
+
+       right = IC_RIGHT(ic);
+       left  = IC_LEFT(ic);
+       result = IC_RESULT(ic);
+
+       aopOp(left,ic,FALSE);
+       aopOp(result,ic,FALSE);
+       size = AOP_SIZE(result);
+       shCount = (int)floatFromVal (AOP(right)->aopu.aop_lit);
+
+       /* if signed then give up and use a loop to shift */    
+       if (sign) {
+               symbol *tlbl ;
+               if (!sameRegs(AOP(left),AOP(result))) {
+                       while (size--) {
+                               aopPut(AOP(result),aopGet(AOP(left),offset),offset);
+                               offset++;
+                       }
+                       size =  size = AOP_SIZE(result);
+                       offset = 0;
+               }                               
+               /* be as economical as possible */
+               if (shCount <= 4) {
+                       offset = size -1;
+                       while (shCount--) {
+                               offset = size -1;
+                               size = AOP_SIZE(result);
+                               while (size--) {
+                                       if (offset == (size-1))
+                                               emitcode("asr","%s",aopGet(AOP(result),offset));
+                                       else
+                                               emitcode("lsr","%s",aopGet(AOP(result),offset));
+                                       offset--;
+                               }
+                       }
+               } else {
+                       emitcode("ldi","r24,lo8(%d)",shCount);
+                       tlbl = newiTempLabel(NULL);
+                       emitcode("","L%05d:",tlbl->key);
+                       offset = size -1;
+                       while (size--) {
+                               if (offset == (size-1)) emitcode("asr","%s",aopGet(AOP(result),offset));
+                               else emitcode("lsr","%s",aopGet(AOP(result),offset));
+                               offset--;
+                       }
+                       emitcode("dec","r24");
+                       emitcode("brne","L%05d",tlbl->key);
+               }
+               goto release;
+       }
+       if (shCount > (size*8 -1)) {
+               while (size--) aopPut(AOP(result),zero,offset++);
+               goto release;
+       }
+       /* for unsigned we can much more efficient */
+       switch (size) {
+       case 1:
+               if (!sameRegs(AOP(left),AOP(result)))
+                       aopPut(AOP(result),aopGet(AOP(left),0),0);
+               if (shCount >= 4) {
+                       emitcode("swap","%s",aopGet(AOP(result),0));
+                       emitcode("andi","%s,0x0f");
+                       shCount -= 4;
+               }
+               while (shCount--)
+                       emitcode("lsr","%s",aopGet(AOP(result),0));
+               break;
+       case 2:
+               if (shCount >= 12) {
+                       aopPut(AOP(result),aopGet(AOP(left),1),0);
+                       aopPut(AOP(result),zero,1);
+                       emitcode("swap","%s",aopGet(AOP(result),0));
+                       emitcode("andi","%s,0x0f",aopGet(AOP(result),0));
+                       shCount -= 12;
+                       hByteZ = 1;
+               }
+               if (shCount >= 8) {
+                       aopPut(AOP(result),aopGet(AOP(left),1),0);
+                       aopPut(AOP(result),zero,1);
+                       shCount -= 8;
+                       hByteZ = 1;
+               }
+               if (shCount >= 4) {
+                       shCount -= 4;
+                       if (!sameRegs(AOP(left),AOP(result))) {
+                               aopPut(AOP(result),aopGet(AOP(left),0),0);
+                               aopPut(AOP(result),aopGet(AOP(left),1),1);                                      
+                       }
+                       emitcode("mov","r1,%s",aopGet(AOP(result),1));
+                       emitcode("swap","%s",aopGet(AOP(result),0));
+                       emitcode("andi","%s,0x0f",aopGet(AOP(result),0));
+                       emitcode("andi","r1,0xf0");
+                       emitcode("or","%s,r1",aopGet(AOP(result),0));
+                       emitcode("swap","%s",aopGet(AOP(result),1));
+                       emitcode("andi","%s,0x0f",aopGet(AOP(result),1));
+                       while(shCount--) {
+                               emitcode("lsr","%s",aopGet(AOP(result),1));
+                               emitcode("ror","%s",aopGet(AOP(result),0));
+                       }
+                       
+               }
+               if (!hByteZ && !sameRegs(AOP(result),AOP(left)) && shCount) {
+                       offset = 0;
+                       while(size--) {
+                               aopPut(AOP(result),aopGet(AOP(left),offset),offset);
+                               offset++;
+                       }
+               }
+               while (shCount--) {
+                       if (hByteZ) {
+                               emitcode("lsr","%s",aopGet(AOP(result),0));
+                       } else {
+                               emitcode("lsr","%s",aopGet(AOP(result),1));
+                               emitcode("ror","%s",aopGet(AOP(result),0));
+                       }
+               }
+               break;
+               
+       case 3:
+               assert("shifting generic pointer ?\n");
+               break;
+       case 4:
+               /* 32 bits we do only byte boundaries */
+               if (shCount >= 24) {
+                       aopPut(AOP(result),aopGet(AOP(left),3),0);
+                       aopPut(AOP(result),zero,1);
+                       aopPut(AOP(result),zero,2);
+                       aopPut(AOP(result),zero,3);
+                       hByteZ = 3;
+                       shCount -= 24;
+               }
+               if (shCount >= 16) {
+                       aopPut(AOP(result),aopGet(AOP(left),3),1);
+                       aopPut(AOP(result),aopGet(AOP(left),2),0);
+                       aopPut(AOP(result),zero,2);
+                       aopPut(AOP(result),zero,3);
+                       hByteZ = 2;
+                       shCount -= 16;
+               }
+               if (shCount >= 8) {
+                       aopPut(AOP(result),aopGet(AOP(left),1),0);
+                       aopPut(AOP(result),aopGet(AOP(left),2),1);
+                       aopPut(AOP(result),aopGet(AOP(left),3),2);
+                       aopPut(AOP(result),zero,3);
+                       shCount -= 8;
+                       hByteZ = 1;
+               }
+               if (!hByteZ && !sameRegs(AOP(left),AOP(right))) {
+                       offset = 0;
+                       while (size--) {
+                               aopPut(AOP(result),aopGet(AOP(left),offset),offset);
+                               offset++;
+                       }
+                       offset = 0;
+                       size = AOP_SIZE(result);
+               }
+               if (shCount) {
+                       switch (hByteZ) {
+                       case 0:
+                               while (shCount--) {
+                                       emitcode("lsr","%s",aopGet(AOP(result),3));
+                                       emitcode("ror","%s",aopGet(AOP(result),2));
+                                       emitcode("ror","%s",aopGet(AOP(result),1));
+                                       emitcode("ror","%s",aopGet(AOP(result),0));
+                               }
+                               break;
+                       case 1:
+                               while (shCount--) {
+                                       emitcode("lsr","%s",aopGet(AOP(result),2));
+                                       emitcode("ror","%s",aopGet(AOP(result),1));
+                                       emitcode("ror","%s",aopGet(AOP(result),0));
+                               }
+                               break;
+                       case 2:
+                               while (shCount--) {
+                                       emitcode("lsr","%s",aopGet(AOP(result),1));
+                                       emitcode("ror","%s",aopGet(AOP(result),0));
+                               }
+                               break;
+                       case 3:
+                               while (shCount--) {
+                                       emitcode("lsr","%s",aopGet(AOP(result),0));
+                               }
+                               break;
+                       }
+               }
+       }               
  release:
        freeAsmop(left,NULL,ic,TRUE);
        freeAsmop(right,NULL,ic,TRUE);
@@ -2919,17 +3109,101 @@ static void genLeftShift (iCode *ic)
 static void genRightShift (iCode *ic)
 {
        operand *right, *left, *result;
-       link *retype ;
+       link *letype ;
        int size, offset;
-       char *l;
-       symbol *tlbl, *tlbl1 ;
-
+       int sign = 0, first =1;
+       symbol *tlbl;
 
- release:
+       aopOp(right=IC_RIGHT(ic),ic,FALSE);
+       if (AOP_TYPE(right) == AOP_LIT) {
+               genShiftRightLit(ic);
+               return ;
+       }
+       /* unknown count */
+       if (AOP_SIZE(right) > 1) {
+               if (isRegPair(AOP(right))) {
+                       emitcode("movw","r24,%s",aopGet(AOP(right),0));
+               } else {
+                       emitcode("mov","r24,%s",aopGet(AOP(right),0));
+                       emitcode("mov","r25,%s",aopGet(AOP(right),1));
+               }
+       } else {
+               emitcode("mov","r24,%s",aopGet(AOP(right),0));
+       }
+       aopOp(left=IC_LEFT(ic),ic,FALSE);
+       aopOp(result=IC_RESULT(ic),ic,FALSE);
+       size = AOP_SIZE(result);
+       tlbl = newiTempLabel(NULL);
+       emitcode("","L%05d:",tlbl->key);
+       offset = size -1;
+       letype = getSpec(operandType(left));
+       sign = !SPEC_USIGN(letype);
+       if (!sameRegs(AOP(left),AOP(result))) {
+               while (size--) {
+                       aopPut(AOP(result),aopGet(AOP(left),offset),offset);
+                       offset++;
+               }
+               size = AOP_SIZE(result);
+       }
+       size = AOP_SIZE(result);
+       while (size--) {
+               if (first) {
+                       if (sign) emitcode("asr","%s",aopGet(AOP(result),offset));
+                       else emitcode("lsr","%s",aopGet(AOP(result),offset));
+                       first = 0;
+               }
+               else emitcode("ror","%s",aopGet(AOP(result),offset));
+               offset--;
+       }
+       if (AOP_SIZE(right) > 1) emitcode("sbiw","r24,1");
+       else emitcode("dec","r24");
+       emitcode("brne","L%05d",tlbl->key);
+       
        freeAsmop(left,NULL,ic,TRUE);
        freeAsmop(result,NULL,ic,TRUE);
 }
 
+/*-----------------------------------------------------------------*/
+/* R0Rsh - shift right r0 by known count                           */
+/*-----------------------------------------------------------------*/
+static void R0Rsh (int shCount)
+{
+       shCount &= 0x0007;              // shCount : 0..7
+       switch(shCount){
+        case 0 :
+               break;
+        case 1 :
+               emitcode("lsr","r0");
+               break;
+        case 2 :
+               emitcode("lsr","r0");
+               emitcode("lsr","r0");
+               break;
+        case 3 :
+               emitcode("swap","r0");      
+               emitcode("lsl","r0");
+               break;
+        case 4 :
+               emitcode("swap","r0");
+               break;
+        case 5 :
+               emitcode("swap","r0");
+               emitcode("lsr","r0");
+               break;
+        case 6 :
+               emitcode("swap","r0");
+               emitcode("lsr","r0");
+               emitcode("lsr","r0");
+               break;
+        case 7 :
+               emitcode("swap","r0");
+               emitcode("lsr","r0");
+               emitcode("lsr","r0");
+               emitcode("lsr","r0");
+               break;
+       }
+}
+
 /*-----------------------------------------------------------------*/
 /* genUnpackBits - generates code for unpacking bits               */
 /*-----------------------------------------------------------------*/
@@ -2947,39 +3221,31 @@ static void genUnpackBits (operand *result, char *rname, int ptype)
 
        case POINTER:
        case IPOINTER:
-               emitcode("mov","a,@%s",rname);
-               break;
-       
        case PPOINTER:
-               emitcode("movx","a,@%s",rname);
-               break;
-       
        case FPOINTER:
-               emitcode("movx","a,@dptr");
+               emitcode("ld","r0,%s+",rname);
                break;
 
        case CPOINTER:
-               emitcode("clr","a");
-               emitcode("movc","a","@a+dptr");
+               emitcode("ldm","r0,%s+",rname);
                break;
 
        case GPOINTER:
-               emitcode("lcall","__gptrget");
+               emitcode("call","__gptrget_pi");
                break;
        }
 
        /* if we have bitdisplacement then it fits   */
        /* into this byte completely or if length is */
        /* less than a byte                          */
-       if ((shCnt = SPEC_BSTR(etype)) || 
-           (SPEC_BLEN(etype) <= 8))  {
-
-                               /* shift right acc */
-               //              AccRsh(shCnt);
-
-               emitcode("anl","a,#0x%02x",
+       if ((shCnt = SPEC_BSTR(etype)) || (SPEC_BLEN(etype) <= 8))  {
+               
+               /* shift right r0 */
+               R0Rsh(shCnt);
+               emitcode("andi","r0,0x%02x",
                         ((unsigned char) -1)>>(8 - SPEC_BLEN(etype)));
-               aopPut(AOP(result),"a",offset);
+
+               aopPut(AOP(result),"r0",offset);
                return ;
        }
 
@@ -2992,29 +3258,17 @@ static void genUnpackBits (operand *result, char *rname, int ptype)
                switch (ptype) {
                case POINTER:
                case IPOINTER:
-                       emitcode("inc","%s",rname);
-                       emitcode("mov","a,@%s",rname);
-                       break;
-           
                case PPOINTER:
-                       emitcode("inc","%s",rname);
-                       emitcode("movx","a,@%s",rname);
-                       break;
-
                case FPOINTER:
-                       emitcode("inc","dptr");
-                       emitcode("movx","a,@dptr");
+                       emitcode("ld","r0,%s+",rname);
                        break;
            
                case CPOINTER:
-                       emitcode("clr","a");
-                       emitcode("inc","dptr");
-                       emitcode("movc","a","@a+dptr");
+                       emitcode("ldm","r0,%s+",rname);
                        break;
            
                case GPOINTER:
-                       emitcode("inc","dptr");
-                       emitcode("lcall","__gptrget");
+                       emitcode("lcall","__gptrget_pi");
                        break;
                }
 
@@ -3023,13 +3277,13 @@ static void genUnpackBits (operand *result, char *rname, int ptype)
                if ( rlen <= 0 )
                        break ;
        
-               aopPut(AOP(result),"a",offset++);
+               aopPut(AOP(result),"r0",offset++);
                                      
        }
     
        if (rlen) {
-               emitcode("anl","a,#0x%02x",((unsigned char)-1)>>(-rlen));
-               aopPut(AOP(result),"a",offset);        
+               emitcode("andi","r0,#0x%02x",((unsigned char)-1)>>(-rlen));
+               aopPut(AOP(result),"r0",offset);               
        }
     
        return ;
@@ -3056,7 +3310,7 @@ static void genDataPointerGet (operand *left,
                        sprintf(buffer,"(%s + %d)",l+1,offset);
                else
                        sprintf(buffer,"%s",l+1);
-               aopPut(AOP(result),buffer,offset++);
+               emitcode("lds","%s,%s",aopGet(AOP(result),offset++),buffer);
        }
 
        freeAsmop(left,NULL,ic,TRUE);
index c039267511bdf1045d597f060146c190a158aa85..b4ce4512f45f822c0e1d3e3b138b4dcf231cc60f 100644 (file)
@@ -1704,12 +1704,8 @@ static iCode *packRegsForOneuse (iCode *ic, operand *op , eBBlock *ebp)
     if (!IS_SYMOP(op))
        return NULL;
     
-    /* only upto 2 bytes since we cannot predict
-       the usage of b, & acc */
-    if (getSize(operandType(op)) > fAVRReturnSize  &&
-       ic->op != RETURN             &&
-       ic->op != SEND)
-       return NULL;
+    /* returns only */
+    if (ic->op != RETURN) return NULL;
 
     /* this routine will mark the a symbol as used in one 
        instruction use only && if the defintion is local 
@@ -1837,138 +1833,6 @@ static bool isBitwiseOptimizable (iCode *ic)
        return FALSE ;    
 }
 
-/*-----------------------------------------------------------------*/
-/* packRegsForAccUse - pack registers for acc use                  */
-/*-----------------------------------------------------------------*/
-static void packRegsForAccUse (iCode *ic)
-{
-    iCode *uic;
-    
-    /* if + or - then it has to be one byte result */
-    if ((ic->op == '+' || ic->op == '-')
-       && getSize(operandType(IC_RESULT(ic))) > 1)
-       return ;
-    
-    /* if shift operation make sure right side is not a literal */
-    if (ic->op == RIGHT_OP  &&
-       ( isOperandLiteral(IC_RIGHT(ic)) ||
-         getSize(operandType(IC_RESULT(ic))) > 1))
-       return ;
-       
-    if (ic->op == LEFT_OP &&        
-       ( isOperandLiteral(IC_RIGHT(ic)) ||
-         getSize(operandType(IC_RESULT(ic))) > 1))
-       return ;
-       
-    if (IS_BITWISE_OP(ic) &&
-       getSize(operandType(IC_RESULT(ic))) > 1)
-       return ;
-           
-       
-    /* has only one definition */
-    if (bitVectnBitsOn(OP_DEFS(IC_RESULT(ic))) > 1)
-       return ;
-
-    /* has only one use */
-    if (bitVectnBitsOn(OP_USES(IC_RESULT(ic))) > 1)
-       return ;
-
-    /* and the usage immediately follows this iCode */
-    if (!(uic = hTabItemWithKey(iCodehTab,
-                               bitVectFirstBit(OP_USES(IC_RESULT(ic))))))
-       return ;
-
-    if (ic->next != uic)
-       return ;
-    
-    /* if it is a conditional branch then we definitely can */
-    if (uic->op == IFX  ) 
-       goto accuse;
-
-    if ( uic->op == JUMPTABLE )
-       return ;
-
-    /* if the usage is not is an assignment
-       or an arithmetic / bitwise / shift operation then not */
-    if (POINTER_SET(uic) && 
-       getSize(aggrToPtr(operandType(IC_RESULT(uic)),FALSE)) > 1)
-       return;
-
-    if (uic->op != '=' && 
-       !IS_ARITHMETIC_OP(uic) &&
-       !IS_BITWISE_OP(uic)    &&
-       uic->op != LEFT_OP &&
-       uic->op != RIGHT_OP )
-       return;
-
-    /* if used in ^ operation then make sure right is not a 
-       literl */
-    if (uic->op == '^' && isOperandLiteral(IC_RIGHT(uic)))
-       return ;
-
-    /* if shift operation make sure right side is not a literal */
-    if (uic->op == RIGHT_OP  &&
-       ( isOperandLiteral(IC_RIGHT(uic)) ||
-         getSize(operandType(IC_RESULT(uic))) > 1))
-       return ;
-
-    if (uic->op == LEFT_OP &&        
-       ( isOperandLiteral(IC_RIGHT(uic)) ||
-         getSize(operandType(IC_RESULT(uic))) > 1))
-       return ;
-           
-    /* make sure that the result of this icode is not on the
-       stack, since acc is used to compute stack offset */
-    if (IS_TRUE_SYMOP(IC_RESULT(uic)) &&
-       OP_SYMBOL(IC_RESULT(uic))->onStack)
-       return ;
-
-    /* if either one of them in far space then we cannot */
-    if ((IS_TRUE_SYMOP(IC_LEFT(uic)) &&
-        isOperandInFarSpace(IC_LEFT(uic))) ||
-       (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
-        isOperandInFarSpace(IC_RIGHT(uic))))
-       return ;
-
-    /* if the usage has only one operand then we can */
-    if (IC_LEFT(uic) == NULL ||
-       IC_RIGHT(uic) == NULL) 
-       goto accuse;
-
-    /* make sure this is on the left side if not
-       a '+' since '+' is commutative */
-    if (ic->op != '+' &&
-       IC_LEFT(uic)->key != IC_RESULT(ic)->key)
-       return;
-
-    /* if one of them is a literal then we can */
-    if ((IC_LEFT(uic) && IS_OP_LITERAL(IC_LEFT(uic))) ||
-       (IC_RIGHT(uic) && IS_OP_LITERAL(IC_RIGHT(uic)))) {
-       OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
-       return ;
-    }
-
-    /* if the other one is not on stack then we can */
-    if (IC_LEFT(uic)->key == IC_RESULT(ic)->key &&
-       (IS_ITEMP(IC_RIGHT(uic)) ||
-        (IS_TRUE_SYMOP(IC_RIGHT(uic)) &&
-         !OP_SYMBOL(IC_RIGHT(uic))->onStack))) 
-       goto accuse;
-    
-    if (IC_RIGHT(uic)->key == IC_RESULT(ic)->key &&
-       (IS_ITEMP(IC_LEFT(uic)) ||
-        (IS_TRUE_SYMOP(IC_LEFT(uic)) &&
-         !OP_SYMBOL(IC_LEFT(uic))->onStack))) 
-       goto accuse ;
-
-    return ;
-
- accuse:
-    OP_SYMBOL(IC_RESULT(ic))->accuse = 1;
-    
-        
-}
-
 /*-----------------------------------------------------------------*/
 /* packForPush - hueristics to reduce iCode for pushing            */
 /*-----------------------------------------------------------------*/
@@ -2102,35 +1966,11 @@ static void packRegisters (eBBlock *ebp)
            continue ;
        }
        
-       /* reduce for support function calls */
-/*     if (ic->supportRtn || ic->op == '+' || ic->op == '-' ) */
-/*         packRegsForSupport (ic,ebp);         */
-       
        /* some cases the redundant moves can
           can be eliminated for return statements */
        if ((ic->op == RETURN || ic->op == SEND))
            packRegsForOneuse (ic,IC_LEFT(ic),ebp);     
 
-       /* if pointer set & left has a size more than
-          one and right is not in far space */
-/*     if (POINTER_SET(ic)                    && */
-/*         !isOperandInFarSpace(IC_RIGHT(ic)) && */
-/*         !OP_SYMBOL(IC_RESULT(ic))->remat   && */
-/*         !IS_OP_RUONLY(IC_RIGHT(ic))        && */
-/*         getSize(aggrToPtr(operandType(IC_RESULT(ic)),FALSE)) > 1 ) */
-
-/*         packRegsForOneuse (ic,IC_RESULT(ic),ebp); */
-
-       /* if pointer get */
-/*     if (POINTER_GET(ic)                    && */
-/*         !isOperandInFarSpace(IC_RESULT(ic))&& */
-/*         !OP_SYMBOL(IC_LEFT(ic))->remat     && */
-/*         !IS_OP_RUONLY(IC_RESULT(ic))         && */
-/*         getSize(aggrToPtr(operandType(IC_LEFT(ic)),FALSE)) > 1 ) */
-
-/*         packRegsForOneuse (ic,IC_LEFT(ic),ebp); */
-
-
        /* if this is cast for intergral promotion then
           check if only use of  the definition of the 
           operand being casted/ if yes then replace
@@ -2170,38 +2010,6 @@ static void packRegisters (eBBlock *ebp)
                }
            }
        }
-       
-       /* pack for PUSH 
-          iTempNN := (some variable in farspace) V1
-          push iTempNN ;
-          -------------
-          push V1
-       */
-/*     if (ic->op == IPUSH ) { */
-/*         packForPush(ic,ebp); */
-/*     } */
-         
-       
-       /* pack registers for accumulator use, when the
-          result of an arithmetic or bit wise operation
-          has only one use, that use is immediately following
-          the defintion and the using iCode has only one
-          operand or has two operands but one is literal &
-          the result of that operation is not on stack then
-          we can leave the result of this operation in acc:b
-          combination */
-/*     if ((IS_ARITHMETIC_OP(ic)  */
-            
-/*          || IS_BITWISE_OP(ic)  */
-            
-/*          || ic->op == LEFT_OP || ic->op == RIGHT_OP */
-            
-/*          ) && */
-/*         IS_ITEMP(IC_RESULT(ic)) && */
-/*         getSize(operandType(IC_RESULT(ic))) <= 2) */
-
-/*         packRegsForAccUse (ic); */
-
     }
 }
 
index b468463f063591aa51e55c198ee777c4cdb7b163..a960c041a885466b338f4ae27bdc34ed7829b1ed 100644 (file)
@@ -2106,6 +2106,17 @@ static void genFunction (iCode *ic)
     if (IS_RENT(sym->etype) || options.stackAuto) {
 
        if (options.useXstack) {
+               /* set up the PAGE for the xternal stack */
+               if (sym->args) {
+                       emitcode("push","dph");
+                       emitcode("push","acc");
+               }
+               emitcode("mov","dph,__page_no__");
+               emitcode("movx","a,@dptr");
+               if (sym->args) {
+                       emitcode("pop","acc");
+                       emitcode("pop","dph");
+               }               
            emitcode("mov","r0,%s",spname);
            emitcode("mov","a,_bp");
            emitcode("movx","@r0,a");
index cf088764cb47bace9002844f69fe6ec854d8b9c9..1648fdd5ca76d01677be44b77933d9ecb662165d 100644 (file)
@@ -2241,12 +2241,10 @@ static void packRegisters (eBBlock *ebp)
           the result of that operation is not on stack then
           we can leave the result of this operation in acc:b
           combination */
-       if ((IS_ARITHMETIC_OP(ic) 
-            
-            || IS_BITWISE_OP(ic) 
-            
+       if ((IS_ARITHMETIC_OP(ic)            
+            || IS_BITWISE_OP(ic)            
             || ic->op == LEFT_OP || ic->op == RIGHT_OP
-            
+            || (ic->op == ADDRESS_OF && isOperandOnStack(IC_LEFT(ic)))
             ) &&
            IS_ITEMP(IC_RESULT(ic)) &&
            getSize(operandType(IC_RESULT(ic))) <= 2)