Fixed up s51 autodetect
[fw/sdcc] / src / SDCCglue.c
index 4352a468388b973e5111c9ad8e4cf95bb9682641..209f5d8fa2ff7dbefe1c7cf6491e1f3cdb78ab1a 100644 (file)
@@ -70,7 +70,7 @@ DEFSETFUNC (rmTmpFiles)
   if (name)
     {
       unlink (name);
-      free (name);
+      Safe_free (name);
     }
   return 0;
 }
@@ -186,18 +186,25 @@ 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 (arFlag && !IS_AGGREGATE (sym->type) &&
          !(sym->_isparm && !IS_REGPARM (sym->etype)) &&
          !sym->allocreq && sym->level)
        continue;
 
+      /* for bitvar locals and parameters */
+      if (!arFlag && !sym->allocreq && sym->level 
+         && !SPEC_ABSA (sym->etype)) {
+       continue;
+      }
+
       /* if global variable & not static or extern
          and addPublics allowed then add it to the public set */
       if ((sym->level == 0 ||
           (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);
        }
@@ -253,6 +260,10 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          if (IS_AGGREGATE (sym->type)) {
            ival = initAggregates (sym, sym->ival, NULL);
          } else {
+           if (getNelements(sym->type, sym->ival)>1) {
+             werror (W_EXCESS_INITIALIZERS, "scalar", 
+                     sym->name, sym->lineDef);
+           }
            ival = newNode ('=', newAst_VALUE (symbolVal (sym)),
                     decorateType (resolveSymbols (list2expr (sym->ival))));
          }
@@ -267,7 +278,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);
@@ -511,7 +523,7 @@ printGPointerType (FILE * oFile, const char *iname, const char *oname,
 /* printIvalType - generates ival for int/char                     */
 /*-----------------------------------------------------------------*/
 void 
-printIvalType (sym_link * type, initList * ilist, FILE * oFile)
+printIvalType (symbol *sym, sym_link * type, initList * ilist, FILE * oFile)
 {
        value *val;
 
@@ -519,6 +531,10 @@ printIvalType (sym_link * type, initList * ilist, FILE * oFile)
        if (ilist->type == INIT_DEEP)
                ilist = ilist->init.deep;
 
+       if (!IS_AGGREGATE(sym->type) && getNelements(type, ilist)>1) {
+         werror (W_EXCESS_INITIALIZERS, "scalar", sym->name, sym->lineDef);
+       }
+
        val = list2val (ilist);
        switch (getSize (type)) {
        case 1:
@@ -621,9 +637,12 @@ printIvalStruct (symbol * sym, sym_link * type,
                if (IS_BITFIELD(sflds->type)) {
                        printIvalBitFields(&sflds,&iloop,oFile);
                } else {
-                       printIval (sflds, sflds->type, iloop, oFile);
+                       printIval (sym, sflds->type, iloop, oFile);
                }
        }
+       if (iloop) {
+         werror (W_EXCESS_INITIALIZERS, "struct", sym->name, sym->lineDef);
+       }
        return;
 }
 
@@ -708,7 +727,7 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
       if (!--lcnt) {
        /* if initializers left */
        if (iloop) {
-         werror (W_EXESS_ARRAY_INITIALIZERS, sym->name, sym->lineDef);
+         werror (W_EXCESS_INITIALIZERS, "array", sym->name, sym->lineDef);
        }
        break;
       }
@@ -956,7 +975,7 @@ printIval (symbol * sym, sym_link * type, initList * ilist, FILE * oFile)
   /* if type is SPECIFIER */
   if (IS_SPEC (type))
     {
-      printIvalType (type, ilist, oFile);
+      printIvalType (sym, type, ilist, oFile);
       return;
     }
 }
@@ -1097,7 +1116,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)
@@ -1381,7 +1400,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");
@@ -1403,7 +1422,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");
@@ -1420,7 +1439,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");
@@ -1443,7 +1462,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
@@ -1461,7 +1480,7 @@ glue ()
       /* initialise the stack pointer */
       /* if the user specified a value then use it */
       if (options.stack_loc)
-       fprintf (asmFile, "\tmov\tsp,#%d\n", options.stack_loc);
+       fprintf (asmFile, "\tmov\tsp,#%d\n", options.stack_loc & 0xff);
       else
        /* no: we have to compute it */
       if (!options.stackOnData && maxRegBank <= 3)
@@ -1478,7 +1497,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
@@ -1500,7 +1519,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 */
@@ -1538,6 +1557,33 @@ rm_tmpfiles (void)
 }
 #endif
 
+/** Creates a temporary file name a'la tmpnam which avoids the bugs
+    in cygwin wrt c:\tmp.
+    Scans, in order: TMP, TEMP, TMPDIR, else uses tmpfile().
+*/
+char *
+tempfilename (void)
+{
+#if !defined(_MSC_VER)
+  const char *tmpdir = NULL;
+  if (getenv ("TMP"))
+    tmpdir = getenv ("TMP");
+  else if (getenv ("TEMP"))
+    tmpdir = getenv ("TEMP");
+  else if (getenv ("TMPDIR"))
+    tmpdir = getenv ("TMPDIR");
+  if (tmpdir)
+    {
+      char *name = tempnam (tmpdir, "sdcc");
+      if (name)
+       {
+          return name;
+        }
+    }
+#endif
+  return tmpnam (NULL);
+}
+
 /** 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,7 +1601,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");
@@ -1571,11 +1617,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;
-}