* .version: Updated to 2.3.1
[fw/sdcc] / src / SDCCglue.c
index 8524d1838305698c8d5f0750b079d3430f931c6d..d74a0f3bea06d25dc9d449303768cd12e470b5e7 100644 (file)
 #include "newalloc.h"
 
 #if !defined(__BORLANDC__) && !defined(_MSC_VER)
-#if 0                          /* This should no longer be necessary. */
-// This is a bit messy because we define link ourself
-#define link NoLiNk
-#include <unistd.h>
-#undef link
-#else
-
 #include <unistd.h>
 #endif
-#else
-// No unistd.h in Borland C++
-#endif
 
 symbol *interrupts[256];
 
@@ -109,6 +99,11 @@ aopLiteralLong (value * val, int offset, int size)
        }
        fl;
 
+       if (!val) {
+         // assuming we have been warned before
+         val=constVal("0");
+       }
+
        /* if it is a float then it gets tricky */
        /* otherwise it is fairly simple */
        if (!IS_FLOAT (val->type)) {
@@ -159,8 +154,9 @@ aopLiteral (value * val, int offset)
 static void 
 emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 {
-  symbol *sym;
+  symbol *sym, *symIval;
   ast *ival = NULL;
+  memmap *segment;
 
   if (addPublics)
     {
@@ -190,6 +186,8 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
       /* if allocation required check is needed
          then check if the symbol really requires
          allocation only for local variables */
+      if (!sym->allocreq) continue;
+
       if (arFlag && !IS_AGGREGATE (sym->type) &&
          !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
          !sym->allocreq && sym->level)
@@ -201,7 +199,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
           (sym->_isparm && !IS_REGPARM (sym->etype))) &&
          addPublics &&
          !IS_STATIC (sym->etype) &&
-         (sym->used || sym->fbody))
+          (IS_FUNC(sym->type) ? (sym->used || sym->fbody) : 1))
        {
          addSetHead (&publics, sym);
        }
@@ -254,20 +252,30 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          it is a global variable */
       if (sym->ival && sym->level == 0)
        {
-
-         if (IS_AGGREGATE (sym->type))
+         if (IS_AGGREGATE (sym->type)) {
            ival = initAggregates (sym, sym->ival, NULL);
-         else
+         } else {
            ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
                     decorateType (resolveSymbols (list2expr (sym->ival))));
+         }
          codeOutFile = statsg->oFile;
          allocInfo = 0;
 
          // set ival's lineno to where the symbol was defined
-         ival->lineno=sym->lineDef;
-
+         if (ival) ival->lineno=sym->lineDef;
          eBBlockFromiCode (iCodeFromAst (ival));
          allocInfo = 1;
+
+         /* if the ival is a symbol assigned to an aggregate,
+            (bug #458099 -> #462479)
+            we don't need it anymore, so delete it from its segment */
+         if (IS_AST_SYM_VALUE(sym->ival->init.node) &&
+             IS_AGGREGATE (sym->type) ) {
+           symIval=AST_SYMBOL(sym->ival->init.node);
+           segment = SPEC_OCLS (symIval->etype);
+           deleteSetItem (&segment->syms, symIval);
+         }
+
          sym->ival = NULL;
        }
     }
@@ -376,7 +384,7 @@ initPointer (initList * ilist)
                return val;
        }
  wrong:
-       werror (E_INIT_WRONG);
+       werror (W_INIT_WRONG);
        return NULL;
 
 }
@@ -469,7 +477,8 @@ pointerTypeToGPByte (const int p_type, const char *iname, const char *oname)
 void 
 _printPointerType (FILE * oFile, const char *name)
 {
-  if (TARGET_IS_DS390)
+  /* if (TARGET_IS_DS390) */
+  if (options.model == MODEL_FLAT24)
     {
       fprintf (oFile, "\t.byte %s,(%s >> 8),(%s >> 16)", name, name, name);
     }
@@ -869,7 +878,7 @@ printIvalPtr (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
 
   /* check the type      */
   if (compareType (type, val->type) == 0)
-    werror (E_INIT_WRONG);
+    werror (W_INIT_WRONG);
 
   /* if val is literal */
   if (IS_LITERAL (val->etype))
@@ -1522,6 +1531,15 @@ glue ()
   applyToSet (tmpfileNameSet, rmTmpFiles);
 }
 
+#if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
+void
+rm_tmpfiles (void)
+{
+  applyToSet (tmpfileSet, closeTmpFiles);
+  applyToSet (tmpfileNameSet, rmTmpFiles);
+}
+#endif
+
 /** Creates a temporary file a'la tmpfile which avoids the bugs
     in cygwin wrt c:\tmp.
     Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
@@ -1555,11 +1573,3 @@ tempfile (void)
   return tmpfile ();
 }
 
-char *
-gc_strdup (const char *s)
-{
-  char *ret;
-  ret = Safe_calloc (1, strlen (s) + 1);
-  strcpy (ret, s);
-  return ret;
-}