add start of flat24 support
[fw/sdcc] / src / SDCCmain.c
index 2dfaf68513f5aca524b760f9568fd5e257010842..6f7f2edc6797fb33f5eb1565865f70d241332e15 100644 (file)
@@ -131,7 +131,7 @@ optionsTable[] = {
     { 'C',  NULL,                   NULL, "Preprocessor option" },
     { 'M',  NULL,                   NULL, "Preprocessor option" },
     { 'V',  NULL,                   &verboseExec, "Execute verbosely.  Show sub commands as they are run" },
-    { 'S',  NULL,                   &noAssemble, "Assemble only" },
+    { 'S',  NULL,                   &noAssemble, "Compile only; do not assemble or link" },
     { 'W',  NULL,                   NULL, "Pass through options to the assembler (a) or linker (l)" },
     { 'L',  NULL,                   NULL, "Add the next field to the library search path" },
     { 'l',  NULL,                   NULL, "Include the given library in the link" },
@@ -149,7 +149,7 @@ optionsTable[] = {
     { 0,    OPTION_NO_LOOP_IND,     NULL, NULL },
     { 0,    "--nojtbound",          &optimize.noJTabBoundary, "Don't generate boundary check for jump tables" },
     { 0,    "--noloopreverse",      &optimize.noLoopReverse, "Disable the loop reverse optimisation" },
-    { 'c',  "--compile-only",       &options.cc_only, "Compile only, do not assemble or link" },
+    { 'c',  "--compile-only",       &options.cc_only, "Compile and assemble, but do not link" },
     { 0,    "--dumpraw",            &options.dump_raw, "Dump the internal structure after the initial parse" },
     { 0,    "--dumpgcse",           &options.dump_gcse, NULL },
     { 0,    "--dumploop",           &options.dump_loop, NULL },
@@ -188,7 +188,8 @@ optionsTable[] = {
     { 0,    "--nostdinc",           &options.nostdinc, "Do not include the standard include directory in the search path" },
     { 0,    "--verbose",            &options.verbose, "Trace calls to the preprocessor, assembler, and linker" },
     { 0,    OPTION_LESS_PEDANTIC,   NULL, "Disable some of the more pedantic warnings" },
-    { 0,    OPTION_SHORT_IS_8BITS,   NULL, "Make short 8bits (for old times sake)" }
+    { 0,    OPTION_SHORT_IS_8BITS,   NULL, "Make short 8bits (for old times sake)" },
+    { 0,    "--profile",            &options.profile, "On supported ports, generate extra profiling information" }
 };
 
 /** Table of all unsupported options and help text to display when one
@@ -311,8 +312,8 @@ printVersionInfo ()
 #ifdef SDCC_SUB_VERSION_STR
           "/" SDCC_SUB_VERSION_STR
 #endif
-#ifdef __CYGWIN32__
-          " (CYGWIN32)\n"
+#ifdef __CYGWIN__
+          " (CYGWIN)\n"
 #else
 #ifdef __DJGPP__
           " (DJGPP) \n"
@@ -361,7 +362,7 @@ parseWithComma (char **dest, char *src)
 {
   int i = 0;
 
-  strtok (src, "\n \t");
+  strtok (src, "\r\n \t");
   /* skip the initial white spaces */
   while (isspace (*src))
     src++;
@@ -406,7 +407,7 @@ setDefaultOptions ()
   options.nostdlib = 0;
   options.nostdinc = 0;
   options.verbose = 0;
-  options.shortis8bits = 1;
+  options.shortis8bits = 0;
 
   options.stack10bit=0;
 
@@ -585,6 +586,15 @@ getIntArg(const char *szStart, char **argv, int *pi, int argc)
     return (int)floatFromVal(constVal(getStringArg(szStart, argv, pi, argc)));
 }
 
+static void
+verifyShortOption(const char *opt)
+{
+  if (strlen(opt) != 2)
+    {
+      werror (W_EXCESS_SHORT_OPTIONS, opt);
+    }
+}
+
 static bool
 tryHandleUnsupportedOpt(char **argv, int *pi)
 {
@@ -644,22 +654,29 @@ tryHandleSimpleOpt(char **argv, int *pi)
                 }
 
             for (i = 0; i < LENGTH(optionsTable); i++) 
-                {
-                    if (optionsTable[i].shortOpt == shortOpt || 
-                        (longOpt && optionsTable[i].longOpt && strcmp(optionsTable[i].longOpt, longOpt) == 0))
-                        {
-                            // If it is a flag then we can handle it here
-                            if (optionsTable[i].pparameter != NULL) 
-                                {
-                                    (*optionsTable[i].pparameter)++;
-                                    return 1;
-                                }
-                            else {
-                                // Not a flag.  Handled manually later.
-                                return 0;
-                            }
-                        }
-                }
+              {
+                if (optionsTable[i].shortOpt == shortOpt ||
+                    (longOpt && optionsTable[i].longOpt && 
+                     strcmp(optionsTable[i].longOpt, longOpt) == 0))
+                  {
+
+                    // If it is a flag then we can handle it here
+                    if (optionsTable[i].pparameter != NULL) 
+                      {
+                        if (optionsTable[i].shortOpt == shortOpt)
+                          {
+                            verifyShortOption(argv[*pi]);
+                          }
+
+                        (*optionsTable[i].pparameter)++;
+                        return 1;
+                      }
+                    else {
+                      // Not a flag.  Handled manually later.
+                      return 0;
+                    }
+                  }
+              }
             // Didn't find in the table
             return 0;
         }
@@ -864,6 +881,8 @@ parseCmdLine (int argc, char **argv)
          switch (argv[i][1])
            {
            case 'h':
+              verifyShortOption(argv[i]);
+
              printUsage ();
              exit (0);
              break;
@@ -874,6 +893,8 @@ parseCmdLine (int argc, char **argv)
              break;
 
            case 'c':
+              verifyShortOption(argv[i]);
+
              options.cc_only = 1;
              break;
 
@@ -906,6 +927,8 @@ parseCmdLine (int argc, char **argv)
              break;
 
            case 'v':
+              verifyShortOption(argv[i]);
+
              printVersionInfo ();
              exit (0);
              break;
@@ -1055,11 +1078,13 @@ linkEdit (char **envp)
   /* standard library path */
   if (!options.nostdlib)
     {
+/****
       if (TARGET_IS_DS390)
        {
          c = "ds390";
        }
       else
+*****/
        {
          switch (options.model)
            {
@@ -1070,7 +1095,8 @@ linkEdit (char **envp)
              c = "large";
              break;
            case MODEL_FLAT24:
-             c = "flat24";
+             /* c = "flat24"; */
+             c = "ds390";
              break;
            default:
              werror (W_UNKNOWN_MODEL, __FILE__, __LINE__);
@@ -1081,7 +1107,8 @@ linkEdit (char **envp)
       fprintf (lnkfile, "-k %s/%s\n", SDCC_LIB_DIR /*STD_LIB_PATH */ , c);
 
       /* standard library files */
-      if (strcmp (port->target, "ds390") == 0)
+      /* if (strcmp (port->target, "ds390") == 0) */
+      if (options.model == MODEL_FLAT24)
        {
          fprintf (lnkfile, "-l %s\n", STD_DS390_LIB);
        }
@@ -1296,10 +1323,11 @@ main (int argc, char **argv, char **envp)
   setDefaultOptions ();
   parseCmdLine (argc, argv);
 
-  initMem ();
-
-  port->finaliseOptions ();
-
+  if (getenv("SDCPP"))
+  {
+    _preCmd[0] = getenv("SDCPP");
+  }
+    
   /* if no input then printUsage & exit */
   if ((!options.c1mode && !srcFileName && !nrelFiles) || 
       (options.c1mode && !srcFileName && !options.out_name))
@@ -1312,6 +1340,10 @@ main (int argc, char **argv, char **envp)
     {
       preProcess (envp);
 
+      initMem ();
+
+      port->finaliseOptions ();
+
       initSymt ();
       initiCode ();
       initCSupport ();
@@ -1368,6 +1400,9 @@ main (int argc, char **argv, char **envp)
               free (preOutName);
             }
           // EndFix
+          #if defined (__MINGW32__) || defined (__CYGWIN__) || defined (_MSC_VER)
+          rm_tmpfiles();
+          #endif
          return 1;
        }
 
@@ -1378,6 +1413,12 @@ main (int argc, char **argv, char **envp)
   if (cdbFile)
     fclose (cdbFile);
 
+  if (preOutName && !options.c1mode)
+    {
+      unlink (preOutName);
+      free (preOutName);
+    }
+
   if (!options.cc_only &&
       !fatalError &&
       !noAssemble &&
@@ -1393,12 +1434,6 @@ main (int argc, char **argv, char **envp)
   if (yyin && yyin != stdin)
     fclose (yyin);
 
-  if (preOutName && !options.c1mode)
-    {
-      unlink (preOutName);
-      free (preOutName);
-    }
-
   return 0;
 
 }