From f777652340e669c48be15debfc44598751dbe7f9 Mon Sep 17 00:00:00 2001 From: johanknol Date: Sun, 26 Jan 2003 21:47:36 +0000 Subject: [PATCH] See Changelog 1.163 git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2183 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- src/SDCCast.c | 39 +++++++++++++++++++++++++++++++++------ src/SDCCast.h | 1 + src/SDCCglue.c | 5 +++++ src/SDCClrange.c | 2 +- src/SDCCsymt.h | 2 +- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/src/SDCCast.c b/src/SDCCast.c index c92f179b..64dc380d 100644 --- a/src/SDCCast.c +++ b/src/SDCCast.c @@ -966,12 +966,9 @@ createIvalCharPtr (ast * sym, sym_link * type, ast * iexpr) newAst_VALUE (valueFromLit ((float) i))), newAst_VALUE (valueFromLit (*s)))); - // now we don't need iexpr's symbol anymore - { - symbol *sym=AST_SYMBOL(iexpr); - memmap *segment=SPEC_OCLS(sym->etype); - deleteSetItem(&segment->syms, sym); - } + // now WE don't need iexpr's symbol anymore + freeStringSymbol(AST_SYMBOL(iexpr)); + return decorateType (resolveSymbols (rast)); } @@ -1135,6 +1132,20 @@ gatherAutoInit (symbol * autoChain) return init; } +/*-----------------------------------------------------------------*/ +/* freeStringSymbol - delete a literal string if no more usage */ +/*-----------------------------------------------------------------*/ +void freeStringSymbol(symbol *sym) { + /* make sure this is a literal string */ + assert (sym->isstrlit); + if (--sym->isstrlit == 0) { // lower the usage count + memmap *segment=SPEC_OCLS(sym->etype); + if (segment) { + deleteSetItem(&segment->syms, sym); + } + } +} + /*-----------------------------------------------------------------*/ /* stringToSymbol - creates a symbol from a literal string */ /*-----------------------------------------------------------------*/ @@ -1144,6 +1155,18 @@ stringToSymbol (value * val) char name[SDCC_NAME_MAX + 1]; static int charLbl = 0; symbol *sym; + set *sp; + + // have we heard this before? + for (sp=statsg->syms; sp; sp=sp->next) { + sym=sp->item; + if (sym->isstrlit && + !strcmp(SPEC_CVAL(sym->etype).v_char, SPEC_CVAL(val->etype).v_char)) { + // yes, this is old news. Don't publish it again. + sym->isstrlit++; // but raise the usage count + return symbolVal(sym); + } + } sprintf (name, "_str_%d", charLbl++); sym = newSymbol (name, 0); /* make it @ level 0 */ @@ -1229,6 +1252,10 @@ bool constExprTree (ast *cexpr) { // a function's address will never change return TRUE; } + if (IS_AST_SYM_VALUE(cexpr) && IS_ARRAY(AST_SYMBOL(cexpr)->type)) { + // an array's address will never change + return TRUE; + } if (IS_AST_SYM_VALUE(cexpr) && IN_CODESPACE(SPEC_OCLS(AST_SYMBOL(cexpr)->etype))) { // a symbol in code space will never change diff --git a/src/SDCCast.h b/src/SDCCast.h index fa0b6231..8b3ba3db 100644 --- a/src/SDCCast.h +++ b/src/SDCCast.h @@ -208,6 +208,7 @@ symbol * funcOfTypeVarg (char *, char * , int , char **); ast *initAggregates (symbol *, initList *, ast *); bool hasSEFcalls (ast *); void addSymToBlock (symbol *, ast *); +void freeStringSymbol(symbol *); // exported variables extern set *operKeyReset; diff --git a/src/SDCCglue.c b/src/SDCCglue.c index 59f82998..dbe42484 100644 --- a/src/SDCCglue.c +++ b/src/SDCCglue.c @@ -1154,6 +1154,11 @@ emitStaticSeg (memmap * map, FILE * out) resolveIvalSym (sym->ival); printIval (sym, sym->type, sym->ival, out); noAlloc--; + // if sym->ival is a string, WE don't need it anymore + if (IS_AST_SYM_VALUE(list2expr(sym->ival)) && + list2val(sym->ival)->sym->isstrlit) { + freeStringSymbol(list2val(sym->ival)->sym); + } } else { /* allocate space */ diff --git a/src/SDCClrange.c b/src/SDCClrange.c index 6c77fd3a..33dddbad 100644 --- a/src/SDCClrange.c +++ b/src/SDCClrange.c @@ -344,7 +344,7 @@ operandLUse (operand * op, eBBlock ** ebbs, !IS_STATIC (etype)) { - if (bitVectIsZero (op->usesDefs)) + if (bitVectIsZero (op->usesDefs) && OP_SYMBOL(op)->ival==NULL) { OP_SYMBOL (op)->isspilt = 1; diff --git a/src/SDCCsymt.h b/src/SDCCsymt.h index e6737a56..9522a9ab 100644 --- a/src/SDCCsymt.h +++ b/src/SDCCsymt.h @@ -241,7 +241,6 @@ typedef struct symbol unsigned isref:1; /* has been referenced */ unsigned isind:1; /* is a induction variable */ unsigned isinvariant:1; /* is a loop invariant */ - unsigned isstrlit:1; /* is a string literal */ unsigned cdef:1; /* compiler defined symbol */ unsigned addrtaken:1; /* address of the symbol was taken */ unsigned isreqv:1; /* is the register quivalent of a symbol */ @@ -267,6 +266,7 @@ typedef struct symbol unsigned spildir:1; /* spilt in direct space */ unsigned ptrreg:1; /* this symbol assigned to a ptr reg */ unsigned noSpilLoc:1; /* cannot be assigned a spil location */ + unsigned isstrlit; /* is a string literal and it's usage count */ unsigned accuse; /* can be left in the accumulator On the Z80 accuse is devided into ACCUSE_A and ACCUSE_HL as the idea -- 2.47.2