From e7b6b3330abd8c5e8f8f4e6297ebdfdd9ab14aa2 Mon Sep 17 00:00:00 2001 From: sandeep Date: Thu, 23 Mar 2000 17:57:56 +0000 Subject: [PATCH] more remat problems fixed. git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@198 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/mcs51/gen.c | 39 ++++++++++++++++++++------------------- src/mcs51/ralloc.c | 13 ++++--------- 2 files changed, 24 insertions(+), 28 deletions(-) diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index fc09590c..1b99d94b 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -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)", diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 66cf8a47..4440eb05 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -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 */ -- 2.47.2