catched symbol abuse
[fw/sdcc] / src / SDCCglue.c
index 13b5a8dd624a0d1d820eca6886d89e95a2901f5c..5e1d084d98ccddca5d4fd5a8514aa787eaa36977 100644 (file)
@@ -46,9 +46,26 @@ unsigned maxInterrupts = 6;
 int allocInfo = 1;
 symbol *mainf;
 extern char *VersionString;
+set *pipeSet = NULL;            /* set of pipes */
 set *tmpfileSet = NULL;                /* set of tmp file created by the compiler */
 set *tmpfileNameSet = NULL;    /* All are unlinked at close. */
 
+/*-----------------------------------------------------------------*/
+/* closePipes - closes all pipes created by the compiler           */
+/*-----------------------------------------------------------------*/
+DEFSETFUNC (closePipes)
+{
+  FILE *pfile = item;
+  int ret;
+
+  if (pfile) {
+    ret = pclose (pfile);
+    assert(ret != -1);
+  }
+
+  return 0;
+}
+
 /*-----------------------------------------------------------------*/
 /* closeTmpFiles - closes all tmp files created by the compiler    */
 /*                 because of BRAIN DEAD MS/DOS & CYGNUS Libraries */
@@ -56,9 +73,12 @@ set *tmpfileNameSet = NULL;  /* All are unlinked at close. */
 DEFSETFUNC (closeTmpFiles)
 {
   FILE *tfile = item;
+  int ret;
 
-  if (tfile)
-    fclose (tfile);
+  if (tfile) {
+    ret = fclose (tfile);
+    assert(ret == 0);
+  }
 
   return 0;
 }
@@ -70,12 +90,14 @@ DEFSETFUNC (closeTmpFiles)
 DEFSETFUNC (rmTmpFiles)
 {
   char *name = item;
+  int ret;
 
-  if (name)
-    {
-      unlink (name);
+  if (name) {
+      ret = unlink (name);
+      assert(ret == 0);
       Safe_free (name);
-    }
+  }
+
   return 0;
 }
 
@@ -86,6 +108,10 @@ void
 rm_tmpfiles (void)
 {
   /* close temporary files */
+  applyToSet (pipeSet, closePipes);
+  /* close temporary files */
+  deleteSet (&pipeSet);
+
   applyToSet (tmpfileSet, closeTmpFiles);
   /* remove temporary files */
   applyToSet (tmpfileNameSet, rmTmpFiles);
@@ -237,18 +263,22 @@ emitRegularMap (memmap * map, bool addPublics, bool arFlag)
        continue;
 
       /* print extra debug info if required */
-      if (options.debug) {
-       cdbSymbol (sym, cdbFile, FALSE, FALSE);
-       if (!sym->level) /* global */
-         if (IS_STATIC (sym->etype))
-           fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
+      if (options.debug)
+       {
+         if (!sym->level) /* global */
+           {
+             if (IS_STATIC (sym->etype))
+               fprintf (map->oFile, "F%s$", moduleName); /* scope is file */
+             else
+               fprintf (map->oFile, "G$");     /* scope is global */
+           }
          else
-           fprintf (map->oFile, "G$"); /* scope is global */
-       else
-         /* symbol is local */
-         fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
-       fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block);
-      }
+           {
+             /* symbol is local */
+             fprintf (map->oFile, "L%s$", (sym->localof ? sym->localof->name : "-null-"));
+           }
+         fprintf (map->oFile, "%s$%d$%d", sym->name, sym->level, sym->block);
+       }
       
       /* if it has an initial value then do it only if
          it is a global variable */
@@ -379,7 +409,7 @@ initPointer (initList * ilist, sym_link *toType)
                /* address of symbol */
                if (IS_AST_SYM_VALUE (expr->left)) {
                        val = copyValue (AST_VALUE (expr->left));
-                       val->type = newLink ();
+                       val->type = newLink (DECLARATOR);
                        if (SPEC_SCLS (expr->left->etype) == S_CODE) {
                                DCL_TYPE (val->type) = CPOINTER;
                                DCL_PTR_CONST (val->type) = port->mem.code_ro;
@@ -438,7 +468,7 @@ initPointer (initList * ilist, sym_link *toType)
            IS_ARRAY(expr->right->ftype)) {
 
                val = copyValue (AST_VALUE (expr->right));
-               val->type = newLink ();
+               val->type = newLink (DECLARATOR);
                if (SPEC_SCLS (expr->right->etype) == S_CODE) {
                        DCL_TYPE (val->type) = CPOINTER;
                        DCL_PTR_CONST (val->type) = port->mem.code_ro;
@@ -784,8 +814,11 @@ printIvalArray (symbol * sym, sym_link * type, initList * ilist,
 
   iloop = ilist->init.deep;
   lcnt = DCL_ELEM (type);
-  for (last_type = type->next; last_type && DCL_ELEM (last_type); last_type = last_type->next)
+  for (last_type = type->next; 
+       last_type && IS_DECL(last_type) && DCL_ELEM (last_type); 
+       last_type = last_type->next) {
     lcnt *= DCL_ELEM (last_type);
+  }
 
   for (;;)
     {
@@ -1121,7 +1154,7 @@ emitStaticSeg (memmap * map, FILE * out)
 
       /* print extra debug info if required */
       if (options.debug) {
-       cdbSymbol (sym, cdbFile, FALSE, FALSE);
+
        if (!sym->level)
          {                     /* global */
            if (IS_STATIC (sym->etype))
@@ -1159,8 +1192,10 @@ 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)) &&
+             /* if sym is a simple string and sym->ival is a string, 
+                WE don't need it anymore */
+             if (IS_ARRAY(sym->type) && IS_CHAR(sym->type->next) &&
+                 IS_AST_SYM_VALUE(list2expr(sym->ival)) &&
                  list2val(sym->ival)->sym->isstrlit) {
                freeStringSymbol(list2val(sym->ival)->sym);
              }
@@ -1389,8 +1424,6 @@ emitOverlay (FILE * afile)
          /* print extra debug info if required */
          if (options.debug)
            {
-             cdbSymbol (sym, cdbFile, FALSE, FALSE);
-
              if (!sym->level)
                {               /* global */
                  if (IS_STATIC (sym->etype))
@@ -1448,7 +1481,7 @@ glue (void)
   addSetHead (&tmpfileSet, ovrFile);
   /* print the global struct definitions */
   if (options.debug)
-    cdbStructBlock (0, cdbFile);
+    cdbStructBlock (0);
 
   vFile = tempfile ();
   /* PENDING: this isnt the best place but it will do */
@@ -1465,6 +1498,8 @@ glue (void)
   /* do the overlay segments */
   emitOverlay (ovrFile);
 
+  outputDebugSymbols();
+
   /* now put it all together into the assembler file */
   /* create the assembler file name */
 
@@ -1837,7 +1872,7 @@ tempfile(void)
   char fnamebuf[PATH_MAX];
 
   if ((fd = tempfileandname(fnamebuf, sizeof fnamebuf)) == -1) {
-    fprintf(stderr, "Can't create temporary file name!");
+    fprintf(stderr, "Can't create temporary file!");
     exit(1);
   }
 
@@ -1846,7 +1881,7 @@ tempfile(void)
     addSetHead(&tmpfileNameSet, tmp);
 
   if ((fp = fdopen(fd, "w+b")) == NULL) {
-      perror("Can't create temporary file name!");
+      perror("Can't create temporary file!");
       exit(1);
   }