Took away some dead code & added checking with port->cseOk if ok to replace
[fw/sdcc] / src / SDCCglue.c
index 39c5579827c067f199c32ac512e1ff9cb6e48d18..55487f379a1f6eb8939a46db25137c7f9423230a 100644 (file)
 #include <unistd.h>
 #endif
 
-#if defined (__MINGW32__)
-#include <windows.h>    // let's see if it win32api is available
-#endif
-
 symbol *interrupts[256];
 
 void printIval (symbol *, sym_link *, initList *, FILE *);
@@ -74,7 +70,7 @@ DEFSETFUNC (rmTmpFiles)
   if (name)
     {
       unlink (name);
-      free (name);
+      Safe_free (name);
     }
   return 0;
 }
@@ -208,7 +204,7 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
           (sym->_isparm && !IS_REGPARM (sym->etype))) &&
          addPublics &&
          !IS_STATIC (sym->etype) &&
-          (IS_FUNC(sym->type) ? (sym->used || sym->fbody) : 1))
+          (IS_FUNC(sym->type) ? (sym->used || IFFUNC_HASBODY(sym->type)) : 1))
        {
          addSetHead (&publics, sym);
        }
@@ -278,7 +274,8 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          /* 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) &&
+         if (sym->ival->type == INIT_NODE &&
+             IS_AST_SYM_VALUE(sym->ival->init.node) &&
              IS_AGGREGATE (sym->type) ) {
            symIval=AST_SYMBOL(sym->ival->init.node);
            segment = SPEC_OCLS (symIval->etype);
@@ -1108,7 +1105,7 @@ createInterruptVect (FILE * vFile)
     }
 
   /* if the main is only a prototype ie. no body then do nothing */
-  if (!mainf->fbody)
+  if (!IFFUNC_HASBODY(mainf->type))
     {
       /* if ! compile only then main function should be present */
       if (!options.cc_only && !noAssemble)
@@ -1392,7 +1389,7 @@ glue ()
   copyFile (asmFile, ovrFile);
 
   /* create the stack segment MOF */
-  if (mainf && mainf->fbody)
+  if (mainf && IFFUNC_HASBODY(mainf->type))
     {
       fprintf (asmFile, "%s", iComments2);
       fprintf (asmFile, "; Stack segment in internal ram \n");
@@ -1414,7 +1411,7 @@ glue ()
   copyFile (asmFile, bit->oFile);
 
   /* if external stack then reserve space of it */
-  if (mainf && mainf->fbody && options.useXstack)
+  if (mainf && IFFUNC_HASBODY(mainf->type) && options.useXstack)
     {
       fprintf (asmFile, "%s", iComments2);
       fprintf (asmFile, "; external stack \n");
@@ -1431,7 +1428,7 @@ glue ()
   copyFile (asmFile, xdata->oFile);
 
   /* copy the interrupt vector table */
-  if (mainf && mainf->fbody)
+  if (mainf && IFFUNC_HASBODY(mainf->type))
     {
       fprintf (asmFile, "%s", iComments2);
       fprintf (asmFile, "; interrupt vector \n");
@@ -1454,7 +1451,7 @@ glue ()
   tfprintf (asmFile, "\t!area\n", port->mem.post_static_name);
   tfprintf (asmFile, "\t!area\n", port->mem.static_name);
 
-  if (mainf && mainf->fbody)
+  if (mainf && IFFUNC_HASBODY(mainf->type))
     {
       fprintf (asmFile, "__sdcc_gsinit_startup:\n");
       /* if external stack is specified then the
@@ -1489,7 +1486,7 @@ glue ()
     }
   copyFile (asmFile, statsg->oFile);
 
-  if (port->general.glue_up_main && mainf && mainf->fbody)
+  if (port->general.glue_up_main && mainf && IFFUNC_HASBODY(mainf->type))
     {
       /* This code is generated in the post-static area.
        * This area is guaranteed to follow the static area
@@ -1511,7 +1508,7 @@ glue ()
   fprintf (asmFile, "; code\n");
   fprintf (asmFile, "%s", iComments2);
   tfprintf (asmFile, "\t!areacode\n", CODE_NAME);
-  if (mainf && mainf->fbody)
+  if (mainf && IFFUNC_HASBODY(mainf->type))
     {
 
       /* entry point @ start of CSEG */
@@ -1593,7 +1590,7 @@ tempfile (void)
     tmpdir = getenv ("TMPDIR");
   if (tmpdir)
     {
-      char *name = tempnam (tmpdir, "sdcc");
+      char *name = Safe_strdup( tempnam (tmpdir, "sdcc"));
       if (name)
        {
          FILE *fp = fopen (name, "w+b");