more remat problems fixed.
authorsandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 23 Mar 2000 17:57:56 +0000 (17:57 +0000)
committersandeep <sandeep@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Thu, 23 Mar 2000 17:57:56 +0000 (17:57 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@198 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/mcs51/gen.c
src/mcs51/ralloc.c

index fc09590c1a7b4d6155458b1cca2cf4aaaf493b5b..1b99d94be5a6f52c197086d45ded8b1bae94108b 100644 (file)
@@ -375,28 +375,29 @@ static asmop *aopForSym (iCode *ic,symbol *sym,bool result)
 /*-----------------------------------------------------------------*/
 static asmop *aopForRemat (symbol *sym)
 {
-    char *s = buffer;   
     iCode *ic = sym->rematiCode;
     asmop *aop = newAsmop(AOP_IMMD);
+    int val = 0;
 
-    while (1) {
-
-        /* if plus or minus print the right hand side */
-        if (ic->op == '+' || ic->op == '-') {
-           if (ic->op == '-')
-               sprintf(s,"-0x%04x + ",(int) operandLitValue(IC_RIGHT(ic))) ;
-           else
-               sprintf(s,"0x%04x + ",(int) operandLitValue(IC_RIGHT(ic)));
-            s += strlen(s);
-            ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
-            continue ;
-        }
-
-        /* we reached the end */
-        sprintf(s,"%s",OP_SYMBOL(IC_LEFT(ic))->rname);
-        break;
+    for (;;) {
+       if (ic->op == '+')
+           val += operandLitValue(IC_RIGHT(ic));
+       else if (ic->op == '-')
+           val -= operandLitValue(IC_RIGHT(ic));
+       else
+           break;
+       
+       ic = OP_SYMBOL(IC_LEFT(ic))->rematiCode;
     }
 
+    if (val)
+       sprintf(buffer,"(%s %c 0x%04x)",
+               OP_SYMBOL(IC_LEFT(ic))->rname, 
+               val >= 0 ? '+' : '-',
+               abs(val) & 0xffff);
+    else
+       strcpy(buffer,OP_SYMBOL(IC_LEFT(ic))->rname);
+
     ALLOC_ATOMIC(aop->aopu.aop_immd,strlen(buffer)+1);
     strcpy(aop->aopu.aop_immd,buffer);    
     return aop;        
@@ -780,12 +781,12 @@ static char *aopGet (asmop *aop, int offset, bool bit16, bool dname)
         genSetDPTR(0);
     }
            
-       return (dname ? "acc" : "a");
+    return (dname ? "acc" : "a");
        
        
     case AOP_IMMD:
        if (bit16) 
-           sprintf (s,"#(%s)",aop->aopu.aop_immd);
+           sprintf (s,"#%s",aop->aopu.aop_immd);
        else
            if (offset) 
                sprintf(s,"#(%s >> %d)",
index 66cf8a47e40c2218fc3f5cb0fae0e9bf2064f6e0..4440eb05cbce34d6a55ca900eddbb08fef9c4f91 100644 (file)
@@ -2086,11 +2086,8 @@ static void packRegisters (eBBlock *ebp)
        }
 
        /* if this is a +/- operation with a rematerizable 
-          then mark this as rematerializable as well only
-          if the literal value is within the range -255 and + 255
-          the assembler cannot handle it other wise */
+          then mark this as rematerializable as well */
        if ((ic->op == '+' || ic->op == '-') &&
-
            (IS_SYMOP(IC_LEFT(ic)) && 
             IS_ITEMP(IC_RESULT(ic)) &&
             OP_SYMBOL(IC_LEFT(ic))->remat &&
@@ -2098,11 +2095,9 @@ static void packRegisters (eBBlock *ebp)
             IS_OP_LITERAL(IC_RIGHT(ic))) ) {
 
            int i = operandLitValue(IC_RIGHT(ic));
-           if ( i < 255 && i > -255) {
-               OP_SYMBOL(IC_RESULT(ic))->remat = 1;
-               OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
-               OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
-           }
+           OP_SYMBOL(IC_RESULT(ic))->remat = 1;
+           OP_SYMBOL(IC_RESULT(ic))->rematiCode = ic;
+           OP_SYMBOL(IC_RESULT(ic))->usl.spillLoc = NULL;
        }
 
        /* mark the pointer usages */