From 90ece3c885427874ac70df65a3969a186f1667bf Mon Sep 17 00:00:00 2001 From: maartenbrock Date: Sun, 14 Nov 2004 11:53:10 +0000 Subject: [PATCH] * src/mcs51/gen.c (toBoolean): fixed bug 1065458 * device/lib/Makefile.in: z80 uses printf_large.c, sprintf.c and vprintf.c now * device/lib/printf_large.c (calculate_digit): fixed bug 1057979 * device/lib/z80/Makefile: don't use printf.c as it fails bug 1057979 WARNING: remove device/lib/build/z80/printf.o by hand when updating from previous build! * device/lib/z80/printf.c: updated comment * support/regression/tests/bug1057979.c: test all ports now * support/regression/tests/bug1065458.c: file added git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3574 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 15 +++- device/lib/Makefile.in | 2 +- device/lib/printf_large.c | 15 +--- device/lib/z80/Makefile | 3 +- device/lib/z80/printf.c | 2 +- src/mcs51/gen.c | 104 ++++++++++++++------------ support/regression/tests/bug1057979.c | 3 - support/regression/tests/bug1065458.c | 21 ++++++ 8 files changed, 95 insertions(+), 70 deletions(-) create mode 100644 support/regression/tests/bug1065458.c diff --git a/ChangeLog b/ChangeLog index acd6c943..8a90d5e2 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,23 @@ +2004-11-11 Maarten Brock + + * src/mcs51/gen.c (toBoolean): fixed bug 1065458 + * device/lib/Makefile.in: z80 uses printf_large.c, sprintf.c and + vprintf.c now + * device/lib/printf_large.c (calculate_digit): fixed bug 1057979 + * device/lib/z80/Makefile: don't use printf.c as it fails bug 1057979 + WARNING: remove device/lib/build/z80/printf.o by hand when + updating from previous build! + * device/lib/z80/printf.c: updated comment + * support/regression/tests/bug1057979.c: test all ports now + * support/regression/tests/bug1065458.c: file added + 2004-11-12 Erik Petrich * src/z80/gen.c (genFunction, genEndFunction): avoided generating *_start and *_end symbols for static functions 2004-11-11 Maarten Brock - + * src/SDCCmain.c (linkEdit): don't suppress crt0 if --nostdlib is used and search crt0.o in all library paths, (setIncludePath): proper handling of --nostdinc, diff --git a/device/lib/Makefile.in b/device/lib/Makefile.in index 447ef06b..7f542c83 100644 --- a/device/lib/Makefile.in +++ b/device/lib/Makefile.in @@ -83,12 +83,12 @@ Z80SOURCES = _atof.c _atoi.c \ _strcspn.c _strlen.c _strncat.c _strncmp.c \ _strncpy.c _strpbrk.c _strrchr.c _strspn.c \ _strstr.c _strtok.c \ - puts.c gets.c \ assert.c \ _modslong.c _modulong.c \ _mullong.c \ _divslong.c _divulong.c \ calloc.c malloc.c realloc.c free.c \ + printf_large.c sprintf.c vprintf.c puts.c gets.c \ _fs2schar.c _fs2sint.c _fs2slong.c \ _fs2uchar.c _fs2uint.c _fs2ulong.c _fsadd.c \ _fsdiv.c _fseq.c _fsgt.c _fslt.c _fsmul.c \ diff --git a/device/lib/printf_large.c b/device/lib/printf_large.c index e2a99447..cad0a047 100644 --- a/device/lib/printf_large.c +++ b/device/lib/printf_large.c @@ -183,7 +183,7 @@ static void calculate_digit( value_t* value, unsigned char radix ) if (radix <= value->byte[4] ) { value->byte[4] -= radix; - value->byte[0]++; + value->ul |= 1; } } } @@ -200,7 +200,7 @@ static void calculate_digit( unsigned char radix ) if (radix <= value.byte[4] ) { value.byte[4] -= radix; - value.byte[0]++; + value.ul |= 1; } } } @@ -648,12 +648,6 @@ get_conversion_spec: if (char_argument) { value.l = va_arg(ap,char); - if (!signed_argument) - { - value.byte[1] = 0x00; - value.byte[2] = 0x00; - value.byte[3] = 0x00; - } } else if (long_argument) { @@ -662,11 +656,6 @@ get_conversion_spec: else // must be int { value.l = va_arg(ap,int); - if (!signed_argument) - { - value.byte[2] = 0x00; - value.byte[3] = 0x00; - } } if ( signed_argument ) diff --git a/device/lib/z80/Makefile b/device/lib/z80/Makefile index ae0e16f4..fad51ae9 100644 --- a/device/lib/z80/Makefile +++ b/device/lib/z80/Makefile @@ -5,8 +5,7 @@ TOPDIR = ../../.. SCC = $(TOPDIR)/bin/sdcc -mz80 SAS = $(TOPDIR)/bin/as-z80 -OBJ = div.o mul.o putchar.o printf.o shift.o stubs.o crt0_rle.o heap.o \ - fstubs.o +OBJ = div.o mul.o putchar.o shift.o stubs.o crt0_rle.o heap.o fstubs.o LIB = z80.lib CC = $(SCC) diff --git a/device/lib/z80/printf.c b/device/lib/z80/printf.c index a81b4e80..65c25b97 100644 --- a/device/lib/z80/printf.c +++ b/device/lib/z80/printf.c @@ -1,5 +1,5 @@ /** Simple printf implementation - Again a stub - will use the std one later... + This stub has been replaced by the std printf_large / sprintf / vprintf */ #include diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 5cea9722..4f0f8054 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -1590,28 +1590,30 @@ toBoolean (operand * oper) { int size = AOP_SIZE (oper) - 1; int offset = 1; - char *l = aopGet (AOP (oper), 0, FALSE, FALSE); + bool AccUsed = FALSE; bool pushedB; - if (!strncmp (l, "a", 2) || !strncmp (l, "acc", 4)) + while (!AccUsed && size--) { - if (size--) + AccUsed |= aopGetUsesAcc(AOP (oper), offset++); + } + + size = AOP_SIZE (oper) - 1; + offset = 1; + MOVA (aopGet (AOP (oper), 0, FALSE, FALSE)); + if (AccUsed && (AOP (oper)->type != AOP_ACC)) + { + pushedB = pushB (); + emitcode("mov", "b,a"); + while (size--) { - pushedB = pushB (); - emitcode("mov", "b,a"); - while (size--) - { - MOVA (aopGet (AOP (oper), offset++, FALSE, FALSE)); - emitcode ("orl", "b,a"); - } - MOVA (aopGet (AOP (oper), offset, FALSE, FALSE)); - emitcode ("orl", "a,b"); - popB (pushedB); + MOVA (aopGet (AOP (oper), offset++, FALSE, FALSE)); + emitcode ("orl", "b,a"); } + popB (pushedB); } else { - MOVA (l); while (size--) { emitcode ("orl", "a,%s", aopGet (AOP (oper), offset++, FALSE, FALSE)); @@ -2768,26 +2770,23 @@ genFunction (iCode * ic) } - if (IFFUNC_ISREENT (sym->type) || options.stackAuto) + if (reentrant) { - if (options.useXstack) { - if (!accIsFree) - emitcode ("push", "acc"); - emitcode ("mov", "r0,%s", spname); - emitcode ("mov", "a,_bp"); - emitcode ("movx", "@r0,a"); - emitcode ("inc", "%s", spname); - if (!accIsFree) - emitcode ("pop", "acc"); + emitcode ("inc", "%s", spname); + emitcode ("mov", "r0,%s", spname); + emitcode ("xch", "a,_bp"); + emitcode ("movx", "@r0,a"); + emitcode ("mov", "a,r0"); + emitcode ("xch", "a,_bp"); } else { /* set up the stack */ emitcode ("push", "_bp"); /* save the callers stack */ + emitcode ("mov", "_bp,%s", spname); } - emitcode ("mov", "_bp,%s", spname); } /* For some cases it is worthwhile to perform a RECEIVE iCode */ @@ -2853,7 +2852,6 @@ genFunction (iCode * ic) /* adjust the stack for the function */ if (stackAdjust) { - int i = stackAdjust; if (i > 256) werror (W_STACK_OVERFLOW, sym->name); @@ -2934,12 +2932,13 @@ genFunction (iCode * ic) static void genEndFunction (iCode * ic) { - symbol *sym = OP_SYMBOL (IC_LEFT (ic)); + symbol *sym = OP_SYMBOL (IC_LEFT (ic)); lineNode *lnp = lineCurr; - bitVect *regsUsed; - bitVect *regsUsedPrologue; - bitVect *regsUnneeded; - int idx; + bitVect *regsUsed; + bitVect *regsUsedPrologue; + bitVect *regsUnneeded; + int accIsFree = sym->recvSize < 4; + int idx; _G.currentFunc = NULL; if (IFFUNC_ISNAKED(sym->type)) @@ -2966,20 +2965,24 @@ genEndFunction (iCode * ic) local stack */ if (options.useXstack && sym->stack) { + if (!accIsFree) + emitcode ("push", "acc"); emitcode ("mov", "a,sp"); emitcode ("add", "a,#0x%02x", ((char) -sym->stack) & 0xff); emitcode ("mov", "sp,a"); + if (!accIsFree) + emitcode ("pop", "acc"); } - if ((IFFUNC_ISREENT (sym->type) || options.stackAuto)) { if (options.useXstack) { + emitcode ("xch", "a,_bp"); emitcode ("mov", "r0,%s", spname); emitcode ("movx", "a,@r0"); - emitcode ("mov", "_bp,a"); - emitcode ("dec", "%s", spname); + emitcode ("xch", "a,_bp"); + emitcode ("dec", "%s", spname); //read before freeing stack space (interrupts) } else { @@ -4992,7 +4995,7 @@ genCmpGt (iCode * ic, iCode * ifx) aopOp (right, ic, FALSE); aopOp (result, ic, TRUE); - genCmp (right, left, result, ifx, sign,ic); + genCmp (right, left, result, ifx, sign, ic); freeAsmop (result, NULL, ic, TRUE); } @@ -10162,20 +10165,22 @@ genCritical (iCode *ic) D(emitcode("; genCritical","")); if (IC_RESULT (ic)) - aopOp (IC_RESULT (ic), ic, TRUE); - - emitcode ("setb", "c"); - emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */ - emitcode ("clr", "c"); - emitcode ("", "%05d$:", (tlbl->key + 100)); - - if (IC_RESULT (ic)) - outBitC (IC_RESULT (ic)); /* save old ea in an operand */ + { + aopOp (IC_RESULT (ic), ic, TRUE); + aopPut (AOP (IC_RESULT (ic)), one, 0, 0); + emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */ + aopPut (AOP (IC_RESULT (ic)), zero, 0, 0); + emitcode ("", "%05d$:", (tlbl->key + 100)); + freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); + } else - emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/ - - if (IC_RESULT (ic)) - freeAsmop (IC_RESULT (ic), NULL, ic, TRUE); + { + emitcode ("setb", "c"); + emitcode ("jbc", "ea,%05d$", (tlbl->key + 100)); /* atomic test & clear */ + emitcode ("clr", "c"); + emitcode ("", "%05d$:", (tlbl->key + 100)); + emitcode ("push", "psw"); /* save old ea via c in psw on top of stack*/ + } } /*-----------------------------------------------------------------*/ @@ -10196,7 +10201,8 @@ genEndCritical (iCode *ic) } else { - MOVA (aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE)); + if (AOP_TYPE (IC_RIGHT (ic)) != AOP_DUMMY) + MOVA (aopGet (AOP (IC_RIGHT (ic)), 0, FALSE, FALSE)); emitcode ("rrc", "a"); emitcode ("mov", "ea,c"); } diff --git a/support/regression/tests/bug1057979.c b/support/regression/tests/bug1057979.c index 202149f5..25877495 100644 --- a/support/regression/tests/bug1057979.c +++ b/support/regression/tests/bug1057979.c @@ -14,8 +14,6 @@ test_sprintf(void) { s[12] = 0x12; -#if defined(SDCC_mcs51) || defined(SDCC_ds390) || defined(PORT_HOST) -//This still fails dramatically for hc08 and z80 sprintf( s, "%d", 99 ); ASSERT( 0 == strcmp( s, "99" ) ); sprintf( s, "%d", 100 ); @@ -24,7 +22,6 @@ test_sprintf(void) ASSERT( 0 == strcmp( s, "2004" ) ); sprintf( s, "%ld", 2147483647L ); ASSERT( 0 == strcmp( s, "2147483647" ) ); -#endif ASSERT( s[12]==0x12 ); } diff --git a/support/regression/tests/bug1065458.c b/support/regression/tests/bug1065458.c new file mode 100644 index 00000000..2495b872 --- /dev/null +++ b/support/regression/tests/bug1065458.c @@ -0,0 +1,21 @@ +/* + bug1065458.c +*/ + +#include + +unsigned short f() +{ + return 0xff00; +} + +unsigned short g() +{ + return f() ? 1 : 0; +} + +void +test_1065458(void) +{ + ASSERT( 1 == g() ); +} -- 2.30.2