fixed bug #458177, global vars are always .global
[fw/sdcc] / src / SDCCglue.c
index f378ab1af21b51a0091d0704ed3e2228fe7fc3fa..252e0669fa7862c0323bbcc87346cc8e34538735 100644 (file)
@@ -149,8 +149,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)
     {
@@ -191,7 +192,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);
        }
@@ -244,7 +245,6 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
          it is a global variable */
       if (sym->ival && sym->level == 0)
        {
-
          if (IS_AGGREGATE (sym->type))
            ival = initAggregates (sym, sym->ival, NULL);
          else
@@ -258,6 +258,12 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
 
          eBBlockFromiCode (iCodeFromAst (ival));
          allocInfo = 1;
+
+         /* if the ival was a symbol, delete it from its segment */
+         if ((symIval=AST_SYMBOL(sym->ival->init.node))) {
+           segment = SPEC_OCLS (symIval->etype);
+           deleteSetItem (&segment->syms, symIval);
+         }
          sym->ival = NULL;
        }
     }
@@ -459,7 +465,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);
     }