* use dynamic memory buffers instead temporary files
[fw/sdcc] / src / ds390 / gen.c
index b82bdbec4380b6f8af99ead35b02194b603117b6..0c4517c2ba2752e36a0680eb01c8184e3e473dd3 100644 (file)
@@ -34,6 +34,7 @@
 #include <ctype.h>
 #include "SDCCglobl.h"
 #include "newalloc.h"
+#include "dbuf_string.h"
 
 #include "common.h"
 #include "main.h"
@@ -205,32 +206,33 @@ static int _lazyDPS = 0;        /* if non-zero, we are doing lazy evaluation of
 /* emitcode - writes the code into a file : for now it is simple    */
 /*-----------------------------------------------------------------*/
 static void
-emitcode (char *inst, const char *fmt,...)
+emitcode (const char *inst, const char *fmt,...)
 {
   va_list ap;
-  char lb[INITIAL_INLINEASM];
-  char *lbp = lb;
+  struct dbuf_s dbuf;
+  const char *lbp, *lb;
+
+  dbuf_init (&dbuf, INITIAL_INLINEASM);
 
   va_start (ap, fmt);
 
   if (inst && *inst)
     {
+      dbuf_append_str (&dbuf, inst);
+
       if (fmt && *fmt)
         {
-          SNPRINTF (lb, sizeof(lb), "%s\t", inst);
-        }
-      else
-        {
-          SNPRINTF (lb, sizeof(lb), "%s", inst);
-        }
-
-      tvsprintf (lb + strlen(lb), sizeof(lb) - strlen(lb), fmt, ap);
+          dbuf_append_char (&dbuf, '\t');
+          dbuf_tvprintf (&dbuf, fmt, ap);
+      }
     }
   else
     {
-      tvsprintf (lb, sizeof(lb), fmt, ap);
+      dbuf_tvprintf (&dbuf, fmt, ap);
     }
 
+  lbp = lb = dbuf_c_str(&dbuf);
+
   while (isspace ((unsigned char)*lbp))
     {
       lbp++;
@@ -249,6 +251,8 @@ emitcode (char *inst, const char *fmt,...)
   lineCurr->aln = ds390newAsmLineNode(_currentDPS);
   lineCurr->isComment = (*lbp == ';');
   va_end (ap);
+
+  dbuf_destroy(&dbuf);
 }
 
 static void
@@ -14199,7 +14203,7 @@ gen390Code (iCode * lic)
 #if 1
   /* print the allocation information */
   if (allocInfo && currFunc)
-    printAllocInfo (currFunc, codeOutFile);
+    printAllocInfo (currFunc, codeOutBuf);
 #endif
   /* if debug information required */
   if (options.debug && currFunc)
@@ -14230,7 +14234,9 @@ gen390Code (iCode * lic)
           cln = ic->lineno;
         }
       if (options.iCodeInAsm) {
-        emitcode("", ";ic:%d: %s", ic->key, printILine(ic));
+        char *iLine = printILine(ic);
+        emitcode("", ";ic:%d: %s", ic->key, iLine);
+        dbuf_free(iLine);
       }
       /* if the result is marked as
          spilt and rematerializable or code for
@@ -14464,6 +14470,6 @@ gen390Code (iCode * lic)
     peepHole (&lineHead);
 
   /* now do the actual printing */
-  printLine (lineHead, codeOutFile);
+  printLine (lineHead, codeOutBuf);
   return;
 }