From 6f6d22f366e8103adb9a67f24c69ae42644ef937 Mon Sep 17 00:00:00 2001 From: kvigor Date: Thu, 24 May 2001 17:55:18 +0000 Subject: [PATCH] fix genPlus bogus code generation demonstrated by Karl's eth.c git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@851 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/ds390/gen.c | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/src/ds390/gen.c b/src/ds390/gen.c index 006cc10e..0f7c943a 100644 --- a/src/ds390/gen.c +++ b/src/ds390/gen.c @@ -3337,7 +3337,7 @@ genPlus (iCode * ic) _startLazyDPSEvaluation (); while (size--) { - if (AOP_TYPE (IC_LEFT (ic)) == AOP_ACC) + if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC && !AOP_NEEDSACC(IC_RIGHT(ic))) { MOVA (aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, TRUE)); if (offset == 0) @@ -3349,13 +3349,33 @@ genPlus (iCode * ic) } else { + if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC && (offset == 0)) + { + /* right is going to use ACC or we would have taken the + * above branch. + */ + assert(AOP_NEEDSACC(IC_RIGHT(ic))); + D(emitcode(";", "+ AOP_ACC special case.");); + emitcode("xch", "a, %s", DP2_RESULT_REG); + } MOVA (aopGet (AOP (IC_RIGHT (ic)), offset, FALSE, FALSE, TRUE)); if (offset == 0) - emitcode ("add", "a,%s", - aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, FALSE)); + { + if (AOP_TYPE(IC_LEFT(ic)) == AOP_ACC) + { + emitcode("add", "a, %s", DP2_RESULT_REG); + } + else + { + emitcode ("add", "a,%s", + aopGet (AOP(IC_LEFT(ic)), offset, FALSE, FALSE, FALSE)); + } + } else + { emitcode ("addc", "a,%s", aopGet (AOP (IC_LEFT (ic)), offset, FALSE, FALSE, FALSE)); + } } if (!pushResult) { -- 2.47.2