From: epetrich Date: Wed, 20 Aug 2003 23:17:13 +0000 (+0000) Subject: fixed bug #741761 X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=b6c0151e015f3c55ea21b03a752ea2183dfa682f;p=fw%2Fsdcc fixed bug #741761 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2841 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- diff --git a/ChangeLog b/ChangeLog index 8e9ca1c3..cf24b5de 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2003-08-20 Erik Petrich + + Fixed bug #741761 + + * src/mcs51/gen.c (aopForSym, leftRightUseAcc), + * src/ds390/gen.c (aopForSym, leftRightUseAcc): preserve A and B + if the left or right operand symbols have the accuse flag set. + 2003-08-20 Erik Petrich Changed the type of the result of the ! (NOT) operator to char; diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 4deb61a2..2b93fa27 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -438,6 +438,27 @@ pointerCode (sym_link * etype) } +/*-----------------------------------------------------------------*/ +/* leftRightUseAcc - returns size of accumulator use by operands */ +/*-----------------------------------------------------------------*/ +static int +leftRightUseAcc(iCode *ic) +{ + int accuse = 0; + + if (ic && IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) + && OP_SYMBOL (IC_LEFT (ic)) && OP_SYMBOL (IC_LEFT (ic))->accuse) + accuse = (accuse < OP_SYMBOL (IC_LEFT (ic))->nRegs) + ? OP_SYMBOL (IC_LEFT (ic))->nRegs : accuse; + + if (ic && IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) + && OP_SYMBOL (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->accuse) + accuse = (accuse < OP_SYMBOL (IC_RIGHT (ic))->nRegs) + ? OP_SYMBOL (IC_RIGHT (ic))->nRegs : accuse; + + return accuse; +} + /*-----------------------------------------------------------------*/ /* aopForSym - for a true symbol */ /*-----------------------------------------------------------------*/ @@ -446,6 +467,7 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) { asmop *aop; memmap *space = SPEC_OCLS (sym->etype); + int accuse = leftRightUseAcc (ic); /* if already has one */ if (sym->aop) @@ -467,10 +489,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) if (sym->onStack) { - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("push", "acc"); - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("push", "b"); emitcode ("mov", "a,_bp"); @@ -481,10 +503,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name); - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("pop", "b"); - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("pop", "acc"); } else @@ -543,10 +565,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) emitcode("mov","dps,#0"); } } else { - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("push", "acc"); - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("push", "b"); emitcode ("mov", "a,_bpx"); @@ -573,10 +595,10 @@ aopForSym (iCode * ic, symbol * sym, bool result, bool useDP2) emitcode ("mov", "dpl,b"); } - if (_G.bInUse) + if (_G.bInUse || (accuse>1)) emitcode ("pop", "b"); - if (_G.accInUse) + if (_G.accInUse || accuse) emitcode ("pop", "acc"); } sym->aop = aop = newAsmop ((short) (useDP2 ? AOP_DPTR2 : AOP_DPTR)); diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 0a5e3598..a9d6e638 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -280,6 +280,29 @@ pointerCode (sym_link * etype) } + +/*-----------------------------------------------------------------*/ +/* leftRightUseAcc - returns size of accumulator use by operands */ +/*-----------------------------------------------------------------*/ +static int +leftRightUseAcc(iCode *ic) +{ + int accuse = 0; + + if (ic && IC_LEFT (ic) && IS_SYMOP (IC_LEFT (ic)) + && OP_SYMBOL (IC_LEFT (ic)) && OP_SYMBOL (IC_LEFT (ic))->accuse) + accuse = (accuse < OP_SYMBOL (IC_LEFT (ic))->nRegs) + ? OP_SYMBOL (IC_LEFT (ic))->nRegs : accuse; + + if (ic && IC_RIGHT (ic) && IS_SYMOP (IC_RIGHT (ic)) + && OP_SYMBOL (IC_RIGHT (ic)) && OP_SYMBOL (IC_RIGHT (ic))->accuse) + accuse = (accuse < OP_SYMBOL (IC_RIGHT (ic))->nRegs) + ? OP_SYMBOL (IC_RIGHT (ic))->nRegs : accuse; + + return accuse; +} + + /*-----------------------------------------------------------------*/ /* aopForSym - for a true symbol */ /*-----------------------------------------------------------------*/ @@ -314,7 +337,7 @@ aopForSym (iCode * ic, symbol * sym, bool result) if (sym->onStack) { - if (_G.accInUse) + if (_G.accInUse || leftRightUseAcc (ic)) emitcode ("push", "acc"); emitcode ("mov", "a,_bp"); @@ -325,7 +348,7 @@ aopForSym (iCode * ic, symbol * sym, bool result) emitcode ("mov", "%s,a", aop->aopu.aop_ptr->name); - if (_G.accInUse) + if (_G.accInUse || leftRightUseAcc (ic)) emitcode ("pop", "acc"); } else