From b39b9a851fa0122a6fb71bb1e40badc28f6192f0 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Sat, 30 Sep 2006 17:03:45 +0000 Subject: [PATCH] * device/lib/libsdcc.lib: added module rand * src/ds390/ralloc.c (rematStr), * src/hc08/ralloc.c (rematStr), * src/mcs51/ralloc.c (rematStr), * src/z80/ralloc.c (rematStr): made output more consistent * src/mcs51/gen.c: cosmetic changes git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4392 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 9 ++++++++ device/lib/libsdcc.lib | 1 + src/ds390/ralloc.c | 34 +++++++++++++++++++---------- src/hc08/ralloc.c | 49 +++++++++++++++++++++++++----------------- src/mcs51/gen.c | 17 +++++++-------- src/mcs51/ralloc.c | 34 +++++++++++++++++++---------- src/z80/ralloc.c | 38 +++++++++++++++++++++++++------- 7 files changed, 123 insertions(+), 59 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4f910616..89225abc 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2006-09-30 Maarten Brock + + * device/lib/libsdcc.lib: added module rand + * src/ds390/ralloc.c (rematStr), + * src/hc08/ralloc.c (rematStr), + * src/mcs51/ralloc.c (rematStr), + * src/z80/ralloc.c (rematStr): made output more consistent + * src/mcs51/gen.c: cosmetic changes + 2006-09-30 Maarten Brock * src/port.h: added mem.cabs_name to PORT diff --git a/device/lib/libsdcc.lib b/device/lib/libsdcc.lib index 89ee78ca..eaad6ac5 100644 --- a/device/lib/libsdcc.lib +++ b/device/lib/libsdcc.lib @@ -36,6 +36,7 @@ _bp _spx abs labs +rand _atoi _atol calloc diff --git a/src/ds390/ralloc.c b/src/ds390/ralloc.c index a6dfae4c..3db3a848 100644 --- a/src/ds390/ralloc.c +++ b/src/ds390/ralloc.c @@ -1934,21 +1934,23 @@ createRegMask (eBBlock ** ebbs, int count) static char * rematStr (symbol * sym) { - char *s = buffer; iCode *ic = sym->rematiCode; - - *s = 0; + int offset = 0; while (1) { + /* if plus adjust offset to right hand side */ + if (ic->op == '+') + { + offset += (int) operandLitValue (IC_RIGHT (ic)); + ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; + continue; + } - /* if plus or minus print the right hand side */ - if (ic->op == '+' || ic->op == '-') + /* if minus adjust offset to right hand side */ + if (ic->op == '-') { - SNPRINTF (s, sizeof(buffer) - strlen(buffer), - "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)), - ic->op); - s += strlen (s); + offset -= (int) operandLitValue (IC_RIGHT (ic)); ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; continue; } @@ -1959,11 +1961,21 @@ rematStr (symbol * sym) continue; } /* we reached the end */ - SNPRINTF (s, sizeof(buffer) - strlen(buffer), - "%s", OP_SYMBOL (IC_LEFT (ic))->rname); break; } + if (offset) + { + SNPRINTF (buffer, sizeof(buffer), + "(%s %c 0x%04x)", + OP_SYMBOL (IC_LEFT (ic))->rname, + offset >= 0 ? '+' : '-', + abs (offset) & 0xffff); + } + else + { + strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer)); + } return buffer; } diff --git a/src/hc08/ralloc.c b/src/hc08/ralloc.c index 995b7876..11680433 100644 --- a/src/hc08/ralloc.c +++ b/src/hc08/ralloc.c @@ -1671,49 +1671,58 @@ createRegMask (eBBlock ** ebbs, int count) static char * rematStr (symbol * sym) { - char *s = buffer; iCode *ic = sym->rematiCode; -// int offset = 0; + int offset = 0; while (1) { - /* if plus or minus print the right hand side */ - if (ic->op == '+' || ic->op == '-') - { - sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)), - ic->op); - s += strlen (s); - ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; - continue; - } - -/* + /* if plus adjust offset to right hand side */ if (ic->op == '+') { - offset += operandLitValue (IC_RIGHT (ic)); + offset += (int) operandLitValue (IC_RIGHT (ic)); ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; continue; } + + /* if minus adjust offset to right hand side */ if (ic->op == '-') { - offset -= operandLitValue (IC_RIGHT (ic)); + offset -= (int) operandLitValue (IC_RIGHT (ic)); ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; continue; } -*/ + /* cast then continue */ if (IS_CAST_ICODE(ic)) { ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; continue; } /* we reached the end */ - if (ic->op == ADDRESS_OF) - sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname); - else if (ic->op == '=') - sprintf (s, "0x%04x", (int) operandLitValue (IC_RIGHT (ic)) ); break; } + if (ic->op == ADDRESS_OF) + { + if (offset) + { + SNPRINTF (buffer, sizeof(buffer), + "(%s %c 0x%04x)", + OP_SYMBOL (IC_LEFT (ic))->rname, + offset >= 0 ? '+' : '-', + abs (offset) & 0xffff); + } + else + { + strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer)); + } + } + else if (ic->op == '=') + { + offset += (int) operandLitValue (IC_RIGHT (ic)); + SNPRINTF (buffer, sizeof(buffer), + "0x%04x", + offset & 0xffff); + } return buffer; } diff --git a/src/mcs51/gen.c b/src/mcs51/gen.c index 7f091dae..1f010705 100644 --- a/src/mcs51/gen.c +++ b/src/mcs51/gen.c @@ -967,8 +967,7 @@ aopOp (operand * op, iCode * ic, bool result) /* rematerialize it NOW */ if (sym->remat) { - sym->aop = op->aop = aop = - aopForRemat (sym); + sym->aop = op->aop = aop = aopForRemat (sym); aop->size = getSize (sym->type); return; } @@ -4082,7 +4081,7 @@ genPlusIncr (iCode * ic) icount = (unsigned int) floatFromVal (AOP (IC_RIGHT (ic))->aopu.aop_lit); - D(emitcode ("; genPlusIncr","")); + D(emitcode (";","genPlusIncr")); /* if increment >=16 bits in register or direct space */ if (( AOP_TYPE(IC_LEFT(ic)) == AOP_REG || @@ -9738,18 +9737,17 @@ genDataPointerGet (operand * left, /* get the string representation of the name */ l = aopGet (left, 0, FALSE, TRUE); + l++; // remove # size = AOP_SIZE (result); while (size--) { if (offset) { - SNPRINTF (buffer, sizeof(buffer), - "(%s + %d)", l + 1, offset); + SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l, offset); } else { - SNPRINTF (buffer, sizeof(buffer), - "%s", l + 1); + SNPRINTF (buffer, sizeof(buffer), "%s", l); } aopPut (result, buffer, offset++); } @@ -10434,13 +10432,14 @@ genDataPointerSet (operand * right, aopOp (right, ic, FALSE); l = aopGet (result, 0, FALSE, TRUE); + l++; //remove # size = AOP_SIZE (right); while (size--) { if (offset) - SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l + 1, offset); + SNPRINTF (buffer, sizeof(buffer), "(%s + %d)", l, offset); else - SNPRINTF (buffer, sizeof(buffer), "%s", l + 1); + SNPRINTF (buffer, sizeof(buffer), "%s", l); emitcode ("mov", "%s,%s", buffer, aopGet (right, offset++, FALSE, FALSE)); } diff --git a/src/mcs51/ralloc.c b/src/mcs51/ralloc.c index 972925da..832a203c 100644 --- a/src/mcs51/ralloc.c +++ b/src/mcs51/ralloc.c @@ -1831,21 +1831,23 @@ createRegMask (eBBlock ** ebbs, int count) static char * rematStr (symbol * sym) { - char *s = buffer; iCode *ic = sym->rematiCode; - - *s = 0; + int offset = 0; while (1) { + /* if plus adjust offset to right hand side */ + if (ic->op == '+') + { + offset += (int) operandLitValue (IC_RIGHT (ic)); + ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; + continue; + } - /* if plus or minus print the right hand side */ - if (ic->op == '+' || ic->op == '-') + /* if minus adjust offset to right hand side */ + if (ic->op == '-') { - SNPRINTF (s, sizeof(buffer) - strlen(buffer), - "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)), - ic->op); - s += strlen (s); + offset -= (int) operandLitValue (IC_RIGHT (ic)); ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; continue; } @@ -1856,11 +1858,21 @@ rematStr (symbol * sym) continue; } /* we reached the end */ - SNPRINTF (s, sizeof(buffer) - strlen(buffer), - "%s", OP_SYMBOL (IC_LEFT (ic))->rname); break; } + if (offset) + { + SNPRINTF (buffer, sizeof(buffer), + "(%s %c 0x%04x)", + OP_SYMBOL (IC_LEFT (ic))->rname, + offset >= 0 ? '+' : '-', + abs (offset) & 0xffff); + } + else + { + strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer)); + } return buffer; } diff --git a/src/z80/ralloc.c b/src/z80/ralloc.c index 28a18be1..18e3d77e 100644 --- a/src/z80/ralloc.c +++ b/src/z80/ralloc.c @@ -1540,29 +1540,51 @@ createRegMask (eBBlock ** ebbs, int count) /** Returns the rematerialized string for a remat var. */ -char * +static char * rematStr (symbol * sym) { - char *s = buffer; iCode *ic = sym->rematiCode; + int offset = 0; while (1) { + /* if plus adjust offset to right hand side */ + if (ic->op == '+') + { + offset += (int) operandLitValue (IC_RIGHT (ic)); + ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; + continue; + } - /* if plus or minus print the right hand side */ - if (ic->op == '+' || ic->op == '-') + /* if minus adjust offset to right hand side */ + if (ic->op == '-') { - sprintf (s, "0x%04x %c ", (int) operandLitValue (IC_RIGHT (ic)), - ic->op); - s += strlen (s); + offset -= (int) operandLitValue (IC_RIGHT (ic)); ic = OP_SYMBOL (IC_LEFT (ic))->rematiCode; continue; } + + /* cast then continue */ + if (IS_CAST_ICODE(ic)) { + ic = OP_SYMBOL (IC_RIGHT (ic))->rematiCode; + continue; + } /* we reached the end */ - sprintf (s, "%s", OP_SYMBOL (IC_LEFT (ic))->rname); break; } + if (offset) + { + SNPRINTF (buffer, sizeof(buffer), + "(%s %c 0x%04x)", + OP_SYMBOL (IC_LEFT (ic))->rname, + offset >= 0 ? '+' : '-', + abs (offset) & 0xffff); + } + else + { + strncpyz (buffer, OP_SYMBOL (IC_LEFT (ic))->rname, sizeof(buffer)); + } return buffer; } -- 2.30.2