From f16c49a6cfb8c57d8b8ca9174a2b5256bcae07f1 Mon Sep 17 00:00:00 2001 From: sandeep Date: Fri, 9 Nov 2001 20:53:41 +0000 Subject: [PATCH] some more progress git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1546 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/avr/gen.c | 94 ++++++++++++++++++++++++++++++------------------ src/avr/ralloc.c | 7 ++-- 2 files changed, 64 insertions(+), 37 deletions(-) diff --git a/src/avr/gen.c b/src/avr/gen.c index c113eeea..7a453019 100644 --- a/src/avr/gen.c +++ b/src/avr/gen.c @@ -68,20 +68,7 @@ static char *spname; char *fReturnAVR[] = { "r16", "r17", "r18", "r19" }; unsigned fAVRReturnSize = 4; /* shared with ralloc.c */ char **fAVRReturn = fReturnAVR; -static char *larray[4] = { "lo8", "hi8", "hlo8", "hhi8" }; - -#if 0 -// PENDING: Unused -static short rbank = -1; -static char *tscr[4] = { "r0", "r1", "r24", "r25" }; -static unsigned char SLMask[] = { 0xFF, 0xFE, 0xFC, 0xF8, 0xF0, - 0xE0, 0xC0, 0x80, 0x00 -}; -static unsigned char SRMask[] = { 0xFF, 0x7F, 0x3F, 0x1F, 0x0F, - 0x07, 0x03, 0x01, 0x00 -}; - -#endif +static char *larray[4] = { ">", "<", "hlo8", "hhi8" }; static struct { short xPushed; @@ -699,6 +686,22 @@ isRegPair (asmop * aop) return 0; } +/*-----------------------------------------------------------------*/ +/* allHigh - all registers are high registers */ +/*-----------------------------------------------------------------*/ +static int allHigh (asmop * aop) +{ + int i; + + if (aop->type == AOP_X || aop->type == AOP_Z) + return 1; + if (aop->type != AOP_REG) + return 0; + for (i=0; i < aop->size ; i++ ) + if (aop->aopu.aop_reg[i]->rIdx < R16_IDX) return 0; + return 1; +} + /*-----------------------------------------------------------------*/ /* aopOp - allocates an asmop for an operand : */ /*-----------------------------------------------------------------*/ @@ -2110,7 +2113,7 @@ genMinusDec (iCode * ic) /* if the sizes are greater than 2 or they are not the same regs then we cannot */ - if (!sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RIGHT (ic)))) + if (!sameRegs (AOP (IC_LEFT (ic)), AOP (IC_RESULT (ic)))) return FALSE; /* so we know LEFT & RESULT in the same registers and add @@ -4616,23 +4619,17 @@ genIfx (iCode * ic, iCode * popIc) lbl = newiTempLabel(NULL); if (IC_TRUE(ic)) { - if (tob) - emitcode ("breq","L%05d",lbl->key); - else - emitcode ("brne","L%05d",lbl->key); + emitcode ("breq","L%05d",lbl->key); emitcode ("jmp","L%05d",IC_TRUE(ic)->key); emitcode ("","L%05d:",lbl->key); } else { - if (tob) - emitcode ("brne","L%05d",lbl->key); - else - emitcode ("breq","L%05d",lbl->key); + emitcode ("brne","L%05d",lbl->key); emitcode ("jmp","L%05d",IC_FALSE(ic)->key); emitcode ("","L%05d:",lbl->key); } ic->generated = 1; } -/* here */ + /*-----------------------------------------------------------------*/ /* genAddrOf - generates code for address of */ /*-----------------------------------------------------------------*/ @@ -4650,15 +4647,44 @@ genAddrOf (iCode * ic) if (sym->onStack) { /* if it has an offset then we need to compute it */ if (sym->stack) { -#if 0 - if (AOP_ISHIGHREG(AOP( - ((char) sym->stack & 0xff)); -#endif - aopPut (AOP (IC_RESULT (ic)), "a", 0); + if (allHigh(AOP(IC_RESULT(ic)))) { + if (isRegPair (AOP(IC_RESULT(ic)))) { + emitcode ("movw","%s,r28",aopGet(AOP(IC_RESULT(ic)),0)); + } else { + emitcode ("mov","%s,r28",aopGet(AOP(IC_RESULT(ic)),0)); + emitcode ("mov","%s,r29",aopGet(AOP(IC_RESULT(ic)),1)); + } + if (sym->stack < 0) { + emitcode("subi","%s,<(%d)",aopGet(AOP(IC_RESULT(ic)),0),-sym->stack); + emitcode("sbci","%s,>(%d)",aopGet(AOP(IC_RESULT(ic)),1),-sym->stack); + } else { + emitcode("subi","%s,<(-%d)",aopGet(AOP(IC_RESULT(ic)),0),sym->stack); + emitcode("sbci","%s,>(-%d)",aopGet(AOP(IC_RESULT(ic)),1),sym->stack); + } + } else { + emitcode("movw","r24,r28"); + if (sym->stack > -63 && sym->stack < 63) { + if (sym->stack < 0) + emitcode("sbiw","r24,%d",-sym->stack); + else + emitcode("sbiw","r24,%d",sym->stack); + } else { + if (sym->stack < 0) { + emitcode("subi","r24,<(%d)",-sym->stack); + emitcode("sbci","r25,>(%d)",-sym->stack); + } else { + emitcode("subi","r24,<(-%d)",sym->stack); + emitcode("sbci","r25,>(-%d)",sym->stack); + } + } + + aopPut(AOP(IC_RESULT(ic)),"r24",0); + aopPut(AOP(IC_RESULT(ic)),"r25",1); + } } else { - /* we can just move _bp */ - aopPut (AOP (IC_RESULT (ic)), "_bp", 0); + aopPut(AOP(IC_RESULT(ic)),"r28",0); + aopPut(AOP(IC_RESULT(ic)),"r29",1); } /* fill the result with zero */ size = AOP_SIZE (IC_RESULT (ic)) - 2; @@ -4673,13 +4699,13 @@ genAddrOf (iCode * ic) /* object not on stack then we need the name */ size = AOP_SIZE (IC_RESULT (ic)); offset = 0; - + assert(size<=2); while (size--) { char s[SDCC_NAME_MAX]; if (offset) - sprintf (s, "(%s >> %d)", sym->rname, offset * 8); + sprintf (s, ">(%s)", sym->rname); else - sprintf (s, "%s", sym->rname); + sprintf (s, "<(%s)", sym->rname); aopPut (AOP (IC_RESULT (ic)), s, offset++); } diff --git a/src/avr/ralloc.c b/src/avr/ralloc.c index 134f6806..6ff00088 100644 --- a/src/avr/ralloc.c +++ b/src/avr/ralloc.c @@ -1617,11 +1617,12 @@ createRegMask (eBBlock ** ebbs, int count) /* for all the registers allocated to it */ for (k = 0; k < sym->nRegs; k++) { if (sym->regs[k]) { - ic->rMask = bitVectSetBit (ic-> rMask, sym->regs[k]->rIdx); + int rIdx = sym->regs[k]->rIdx; + ic->rMask = bitVectSetBit (ic-> rMask,rIdx); /* special case for X & Z registers */ - if (k == R26_IDX || k == R27_IDX) + if (rIdx == R26_IDX || rIdx == R27_IDX) ic->rMask = bitVectSetBit (ic->rMask, X_IDX); - if (k == R30_IDX || k == R31_IDX) + if (rIdx == R30_IDX || rIdx == R31_IDX) ic->rMask = bitVectSetBit (ic->rMask, Z_IDX); } } -- 2.30.2