From: epetrich Date: Fri, 16 Apr 2004 05:19:09 +0000 (+0000) Subject: * doc/sdccman.lyx: removed the ANSI-C noncompliance note regarding X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=ee3a71190fbc9ac9a200946da894a07b198d8186;p=fw%2Fsdcc * doc/sdccman.lyx: removed the ANSI-C noncompliance note regarding function pointers; we have been compliant for several months now. * src/mcs51/ralloc.c (serialRegAssign): enabled part of my 2004-04-13 change that was accidently commented out * src/mcs51/gen.c (freeAsmop, getFreePtr, freeForBranchAsmop, genIfxJump, genCmpEq, jmpTrueOrFalse, genCmp, genAnd, genOr, genXor, genIfx): fixed bug #922319 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3289 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 2ea5689b..daa3f42c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2004-04-16 Erik Petrich + + * doc/sdccman.lyx: removed the ANSI-C noncompliance note regarding + function pointers; we have been compliant for several months now. + * src/mcs51/ralloc.c (serialRegAssign): enabled part of my 2004-04-13 + change that was accidently commented out + * src/mcs51/gen.c (freeAsmop, getFreePtr, freeForBranchAsmop, genIfxJump, + genCmpEq, jmpTrueOrFalse, genCmp, genAnd, genOr, genXor, genIfx): fixed + bug #922319 + 2004-04-15 Erik Petrich * src/hc08/gen.c: output of all of the internal debugging information diff --git a/doc/sdccman.lyx b/doc/sdccman.lyx index 6a0af25e..5e093fb8 100644 --- a/doc/sdccman.lyx +++ b/doc/sdccman.lyx @@ -20582,33 +20582,6 @@ int i,j; /* are valid in ANSI but not valid in SDCC */ \newline } \end_deeper -\layout Itemize - -functions declared as pointers -\begin_inset LatexCommand \index{Pointer (to function)} - -\end_inset - - -\begin_inset LatexCommand \index{function pointers} - -\end_inset - - must be dereferenced during the call. -\begin_deeper -\layout Verse - - -\family typewriter -int (*foo)(); -\newline -... - -\newline -/* has to be called like this */ -\newline -(*foo)(); /* ANSI standard allows calls to be made like 'foo()' */ -\end_deeper \layout Section Cyclomatic Complexity diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 7e61b9de..0fb8581b 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -68,6 +68,8 @@ static struct { short r0Pushed; short r1Pushed; + short r0InB; + short r1InB; short accInUse; short inLine; short debugLine; @@ -207,7 +209,13 @@ getFreePtr (iCode * ic, asmop ** aopp, bool result) if (!r0iu) { /* push it if not already pushed */ - if (!_G.r0Pushed) + if (ic->op == IPUSH) + { + emitcode ("mov", "b,%s", + mcs51_regWithIdx (R0_IDX)->dname); + _G.r0InB++; + } + else if (!_G.r0Pushed) { emitcode ("push", "%s", mcs51_regWithIdx (R0_IDX)->dname); @@ -225,7 +233,13 @@ getFreePtr (iCode * ic, asmop ** aopp, bool result) if (!r1iu) { /* push it if not already pushed */ - if (!_G.r1Pushed) + if (ic->op == IPUSH) + { + emitcode ("mov", "b,%s", + mcs51_regWithIdx (R1_IDX)->dname); + _G.r1InB++; + } + else if (!_G.r1Pushed) { emitcode ("push", "%s", mcs51_regWithIdx (R1_IDX)->dname); @@ -817,7 +831,12 @@ freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop) switch (aop->type) { case AOP_R0: - if (_G.r0Pushed) + if (_G.r0InB) + { + emitcode ("mov", "r0,b"); + _G.r0InB--; + } + else if (_G.r0Pushed) { if (pop) { @@ -829,6 +848,11 @@ freeAsmop (operand * op, asmop * aaop, iCode * ic, bool pop) break; case AOP_R1: + if (_G.r1InB) + { + emitcode ("mov", "r1,b"); + _G.r1InB--; + } if (_G.r1Pushed) { if (pop) @@ -899,6 +923,81 @@ dealloc: } } +/*------------------------------------------------------------------*/ +/* freeForBranchAsmop - partial free up of Asmop for a branch; just */ +/* pop r0 or r1 off stack if pushed */ +/*------------------------------------------------------------------*/ +static void +freeForBranchAsmop (operand * op) +{ + asmop *aop; + + if (!op) + return; + + aop = op->aop; + + if (!aop) + return; + + if (aop->freed) + return; + + switch (aop->type) + { + case AOP_R0: + if (_G.r0InB) + { + emitcode ("mov", "r0,b"); + } + else if (_G.r0Pushed) + { + emitcode ("pop", "ar0"); + } + break; + + case AOP_R1: + if (_G.r1InB) + { + emitcode ("mov", "r1,b"); + } + else if (_G.r1Pushed) + { + emitcode ("pop", "ar1"); + } + break; + + case AOP_STK: + { + int sz = aop->size; + int stk = aop->aopu.aop_stk + aop->size - 1; + + emitcode ("mov", "b,r0"); + if (stk) + { + emitcode ("mov", "a,_bp"); + emitcode ("add", "a,#0x%02x", ((char) stk) & 0xff); + emitcode ("mov", "r0,a"); + } + else + { + emitcode ("mov", "r0,_bp"); + } + + while (sz--) + { + emitcode ("pop", "acc"); + emitcode ("mov", "@r0,a"); + if (!sz) + break; + emitcode ("dec", "r0"); + } + emitcode ("mov", "r0,b"); + } + } + +} + /*-----------------------------------------------------------------*/ /* aopGetUsesAcc - indicates ahead of time whether aopGet() will */ /* clobber the accumulator */ @@ -4587,7 +4686,7 @@ release: /* genIfxJump :- will create a jump depending on the ifx */ /*-----------------------------------------------------------------*/ static void -genIfxJump (iCode * ic, char *jval) +genIfxJump (iCode * ic, char *jval, operand *left, operand *right, operand *result) { symbol *jlbl; symbol *tlbl = newiTempLabel (NULL); @@ -4614,6 +4713,9 @@ genIfxJump (iCode * ic, char *jval) emitcode (inst, "%s,%05d$", jval, (tlbl->key + 100)); else emitcode (inst, "%05d$", tlbl->key + 100); + freeForBranchAsmop (result); + freeForBranchAsmop (right); + freeForBranchAsmop (left); emitcode ("ljmp", "%05d$", jlbl->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); @@ -4676,7 +4778,7 @@ genCmp (operand * left, operand * right, MOVA (aopGet (AOP (left), AOP_SIZE (left) - 1, FALSE, FALSE)); if (!(AOP_TYPE (result) == AOP_CRY && AOP_SIZE (result)) && ifx) { - genIfxJump (ifx, "acc.7"); + genIfxJump (ifx, "acc.7", left, right, result); return; } else @@ -4735,7 +4837,7 @@ release: ifx conditional branch then generate code a little differently */ if (ifx) - genIfxJump (ifx, "c"); + genIfxJump (ifx, "c", NULL, NULL, result); else outBitC (result); /* leave the result in acc */ @@ -4960,11 +5062,17 @@ genCmpEq (iCode * ic, iCode * ifx) if (IC_TRUE (ifx)) { emitcode ("jnc", "%05d$", tlbl->key + 100); + freeForBranchAsmop (result); + freeForBranchAsmop (right); + freeForBranchAsmop (left); emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100); } else { emitcode ("jc", "%05d$", tlbl->key + 100); + freeForBranchAsmop (result); + freeForBranchAsmop (right); + freeForBranchAsmop (left); emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100); } emitcode ("", "%05d$:", tlbl->key + 100); @@ -4975,6 +5083,9 @@ genCmpEq (iCode * ic, iCode * ifx) gencjneshort (left, right, tlbl); if (IC_TRUE (ifx)) { + freeForBranchAsmop (result); + freeForBranchAsmop (right); + freeForBranchAsmop (left); emitcode ("ljmp", "%05d$", IC_TRUE (ifx)->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); } @@ -4983,6 +5094,9 @@ genCmpEq (iCode * ic, iCode * ifx) symbol *lbl = newiTempLabel (NULL); emitcode ("sjmp", "%05d$", lbl->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); + freeForBranchAsmop (result); + freeForBranchAsmop (right); + freeForBranchAsmop (left); emitcode ("ljmp", "%05d$", IC_FALSE (ifx)->key + 100); emitcode ("", "%05d$:", lbl->key + 100); } @@ -5030,7 +5144,7 @@ genCmpEq (iCode * ic, iCode * ifx) } if (ifx) { - genIfxJump (ifx, "c"); + genIfxJump (ifx, "c", left, right, result); goto release; } /* if the result is used in an arithmetic operation @@ -5047,7 +5161,7 @@ genCmpEq (iCode * ic, iCode * ifx) } if (ifx) { - genIfxJump (ifx, "a"); + genIfxJump (ifx, "a", left, right, result); goto release; } /* if the result is used in an arithmetic operation @@ -5253,7 +5367,7 @@ jumpIfTrue (iCode * ic) /* jmpTrueOrFalse - */ /*-----------------------------------------------------------------*/ static void -jmpTrueOrFalse (iCode * ic, symbol * tlbl) +jmpTrueOrFalse (iCode * ic, symbol * tlbl, operand *left, operand *right, operand *result) { // ugly but optimized by peephole if (IC_TRUE (ic)) @@ -5261,11 +5375,17 @@ jmpTrueOrFalse (iCode * ic, symbol * tlbl) symbol *nlbl = newiTempLabel (NULL); emitcode ("sjmp", "%05d$", nlbl->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); + freeForBranchAsmop (result); + freeForBranchAsmop (right); + freeForBranchAsmop (left); emitcode ("ljmp", "%05d$", IC_TRUE (ic)->key + 100); emitcode ("", "%05d$:", nlbl->key + 100); } else { + freeForBranchAsmop (result); + freeForBranchAsmop (right); + freeForBranchAsmop (left); emitcode ("ljmp", "%05d$", IC_FALSE (ic)->key + 100); emitcode ("", "%05d$:", tlbl->key + 100); } @@ -5382,7 +5502,7 @@ genAnd (iCode * ic, iCode * ifx) outBitC (result); // if(bit & ...) else if ((AOP_TYPE (result) == AOP_CRY) && ifx) - genIfxJump (ifx, "c"); + genIfxJump (ifx, "c", left, right, result); goto release; } @@ -5407,7 +5527,7 @@ genAnd (iCode * ic, iCode * ifx) if (ifx) { sprintf (buffer, "acc.%d", posbit & 0x07); - genIfxJump (ifx, buffer); + genIfxJump (ifx, buffer, left, right, result); } goto release; } @@ -5446,7 +5566,7 @@ genAnd (iCode * ic, iCode * ifx) else { if (ifx) - jmpTrueOrFalse (ifx, tlbl); + jmpTrueOrFalse (ifx, tlbl, left, right, result); else emitcode ("", "%05d$:", tlbl->key + 100); goto release; @@ -5538,7 +5658,7 @@ genAnd (iCode * ic, iCode * ifx) outBitC (result); } else if (ifx) - jmpTrueOrFalse (ifx, tlbl); + jmpTrueOrFalse (ifx, tlbl, left, right, result); else emitcode ("", "%05d$:", tlbl->key + 100); } @@ -5691,7 +5811,7 @@ genOr (iCode * ic, iCode * ifx) emitcode ("jnz", "%05d$", tlbl->key + 100); if ((AOP_TYPE (result) == AOP_CRY) && ifx) { - jmpTrueOrFalse (ifx, tlbl); + jmpTrueOrFalse (ifx, tlbl, left, right, result); goto release; } else @@ -5707,7 +5827,7 @@ genOr (iCode * ic, iCode * ifx) outBitC (result); // if(bit | ...) else if ((AOP_TYPE (result) == AOP_CRY) && ifx) - genIfxJump (ifx, "c"); + genIfxJump (ifx, "c", left, right, result); goto release; } @@ -5741,7 +5861,7 @@ genOr (iCode * ic, iCode * ifx) } else { - genIfxJump (ifx, "a"); + genIfxJump (ifx, "a", left, right, result); goto release; } } @@ -5826,7 +5946,7 @@ genOr (iCode * ic, iCode * ifx) outBitC (result); } else if (ifx) - jmpTrueOrFalse (ifx, tlbl); + jmpTrueOrFalse (ifx, tlbl, left, right, result); else emitcode ("", "%05d$:", tlbl->key + 100); } @@ -6006,7 +6126,7 @@ genXor (iCode * ic, iCode * ifx) outBitC (result); // if(bit | ...) else if ((AOP_TYPE (result) == AOP_CRY) && ifx) - genIfxJump (ifx, "c"); + genIfxJump (ifx, "c", left, right, result); goto release; } @@ -6089,7 +6209,7 @@ genXor (iCode * ic, iCode * ifx) outBitC (result); } else if (ifx) - jmpTrueOrFalse (ifx, tlbl); + jmpTrueOrFalse (ifx, tlbl, left, right, result); } else for (; (size--); offset++) @@ -9031,11 +9151,11 @@ genIfx (iCode * ic, iCode * popIc) /* if the condition is a bit variable */ if (isbit && IS_ITEMP (cond) && SPIL_LOC (cond)) - genIfxJump (ic, SPIL_LOC (cond)->rname); + genIfxJump (ic, SPIL_LOC (cond)->rname, NULL, NULL, NULL); else if (isbit && !IS_ITEMP (cond)) - genIfxJump (ic, OP_SYMBOL (cond)->rname); + genIfxJump (ic, OP_SYMBOL (cond)->rname, NULL, NULL, NULL); else - genIfxJump (ic, "a"); + genIfxJump (ic, "a", NULL, NULL, NULL); ic->generated = 1; } diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index d7708eae..919ded65 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1287,7 +1287,7 @@ serialRegAssign (eBBlock ** ebbs, int count) if (sym->regType == REG_PTR) sym->regs[j] = getRegPtr (ic, ebbs[i], sym); else - { /* + { if (ic->op == CAST && IS_SYMOP (IC_RIGHT (ic))) { symbol * right = OP_SYMBOL (IC_RIGHT (ic)); @@ -1295,7 +1295,7 @@ serialRegAssign (eBBlock ** ebbs, int count) if (right->regs[j]) sym->regs[j] = allocThisReg (right->regs[j]); } - if (!sym->regs[j]) */ + if (!sym->regs[j]) sym->regs[j] = getRegGpr (ic, ebbs[i], sym); }