fixed bug #700797
[fw/sdcc] / src / SDCCmain.c
index 1763c15baea83c7be46d8f81a159d06f6a95c597..308175e216eb28a4500b6d638e7e0b7e29ae43a6 100644 (file)
@@ -76,7 +76,6 @@ char *libPaths[128];
 int nlibPaths = 0;
 char *relFiles[128];
 int nrelFiles = 0;
-static char *preOutName;
 
 /* uncomment JAMIN_DS390 to always override and use ds390 port
   for mcs51 work.  This is temporary, for compatibility testing. */
@@ -115,6 +114,7 @@ char DefaultExePath[128];
 #define OPTION_DATA_LOC                "--data-loc"
 #define OPTION_CODE_LOC                "--code-loc"
 #define OPTION_IDATA_LOC       "--idata-loc"
+#define OPTION_NO_LABEL_OPT     "--nolabelopt"
 #define OPTION_NO_LOOP_INV     "--noinvariant"
 #define OPTION_NO_LOOP_IND     "--noinduction"
 #define OPTION_LESS_PEDANTIC   "--lesspedantic"
@@ -152,6 +152,7 @@ optionsTable[] = {
     { 0,    "--stack-10bit",        &options.stack10bit, "use the 10bit stack for ds390 (default)" },
     { 0,    "--xstack",             &options.useXstack, "Use external stack" },
     { 0,    OPTION_NO_GCSE,         NULL, "Disable the GCSE optimisation" },
+    { 0,    OPTION_NO_LABEL_OPT,    NULL, "Disable label optimisation" },
     { 0,    OPTION_NO_LOOP_INV,     NULL, "Disable optimisation of invariants" },
     { 0,    OPTION_NO_LOOP_IND,     NULL, NULL },
     { 0,    "--nojtbound",          &optimize.noJTabBoundary, "Don't generate boundary check for jump tables" },
@@ -955,6 +956,12 @@ parseCmdLine (int argc, char **argv)
              continue;
            }
 
+         if (strcmp (argv[i], OPTION_NO_LABEL_OPT) == 0)
+           {
+             optimize.label4 = 0;
+             continue;
+           }
+
          if (strcmp (argv[i], OPTION_NO_LOOP_IND) == 0)
            {
              optimize.loopInduction = 0;
@@ -1598,40 +1605,36 @@ preProcess (char **envp)
 
       setMainValue ("cppextraopts", join(preArgv));
 
-      if (preProcOnly)
-        {
-          if (fullDstFileName)
-           {
-              preOutName = Safe_strdup (fullDstFileName);
-           }
-        }
+      if (preProcOnly && fullDstFileName)
+       {
+         /* -E and -o given */
+         setMainValue ("cppoutfilename", fullDstFileName);
+       }
       else
-          preOutName = Safe_strdup (tempfilename ());
-
-      /* Have to set cppoutfilename to something, even if just pre-processing. */
-      setMainValue ("cppoutfilename", preOutName ? preOutName : "");
-      addSetHead (&tmpfileNameSet, preOutName);
+       {
+         /* Have to set cppoutfilename to something, even if piping */
+         setMainValue ("cppoutfilename", "");
+       }
 
       if (options.verbose)
        printf ("sdcc: Calling preprocessor...\n");
 
       buildCmdLine2 (buffer, _preCmd, sizeof(buffer));
 
-      if (my_system (buffer))
-       {
+      if (preProcOnly) {
+        if (my_system (buffer)) {
          exit (1);
        }
-      if (preProcOnly)
-        {
-         exit (0);
-        }
-      yyin = fopen (preOutName, "r");
-      if (yyin == NULL)
-        {
-          perror ("Preproc file not found\n");
+
+        exit (0);
+      }
+
+      yyin = my_popen (buffer);
+      if (yyin == NULL) {
+          perror ("Preproc file not found");
           exit (1);
-        }
-      addSetHead (&tmpfileSet, yyin);
+      }
+      addSetHead (&pipeSet, yyin);
     }
 
   return 0;
@@ -1921,6 +1924,10 @@ main (int argc, char **argv, char **envp)
        printf ("sdcc: Generating code...\n");
 
       yyparse ();
+
+      pclose(yyin);
+      deleteSetItem(&pipeSet, yyin);
+
       if (fatalError) {
         exit (1);
       }