]> git.gag.com Git - fw/sdcc/commitdiff
See Changelog 1.163
authorjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 26 Jan 2003 21:47:36 +0000 (21:47 +0000)
committerjohanknol <johanknol@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Sun, 26 Jan 2003 21:47:36 +0000 (21:47 +0000)
git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@2183 4a8a32a2-be11-0410-ad9d-d568d2c75423

src/SDCCast.c
src/SDCCast.h
src/SDCCglue.c
src/SDCClrange.c
src/SDCCsymt.h

index c92f179b3b1aeb2086d18e374432f25a505db952..64dc380d458246d7f2b178962627d5213d1a9db7 100644 (file)
@@ -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
index fa0b62314c2c74f9f150e2d1402587a4efbef983..8b3ba3dbc1b459e9020f0ebd53f2e08e86799bfc 100644 (file)
@@ -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;
index 59f82998c0ae74494db1f6ab87f58f442fff2a36..dbe42484362bdc2b8f5de107e05a6e5d3ba297d6 100644 (file)
@@ -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 */
index 6c77fd3a42dc8671b396887b098ce803fd5ac555..33dddbad685b58a07415ef32de55c4a457d7ce7a 100644 (file)
@@ -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;
 
index e6737a566503cdd2600307e36284e75a009a8041..9522a9ab6fa2c644d175f40c6d446393194eab9a 100644 (file)
@@ -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