]> git.sur5r.net Git - cc65/blobdiff - src/cc65/main.c
Added the io module
[cc65] / src / cc65 / main.c
index 134ae7e8f66db24122392fa282e33fa132349a45..3072cdb5743255935463c221366484df60486a0a 100644 (file)
@@ -42,6 +42,7 @@
 #include "../common/cmdline.h"
 #include "../common/fname.h"
 #include "../common/version.h"
+#include "../common/xmalloc.h"
 
 #include "asmcode.h"
 #include "compile.h"
@@ -49,9 +50,8 @@
 #include "error.h"
 #include "global.h"
 #include "incpath.h"
-#include "io.h"
+#include "input.h"
 #include "macrotab.h"
-#include "mem.h"
 #include "optimize.h"
 #include "scanner.h"
 
@@ -93,7 +93,7 @@ static void Usage (void)
             "Short options:\n"
                     "  -d\t\t\tDebug mode\n"
                     "  -g\t\t\tAdd debug info to object file\n"
-                    "  -h\t\t\tPrint this help\n"
+                    "  -h\t\t\tHelp (this text)\n"
                     "  -j\t\t\tDefault characters are signed\n"
                     "  -o name\t\tName the output file\n"
                     "  -t sys\t\tSet the target system\n"
@@ -101,7 +101,7 @@ static void Usage (void)
                     "  -A\t\t\tStrict ANSI mode\n"
                     "  -Cl\t\t\tMake local variables static\n"
                     "  -Dsym[=defn]\t\tDefine a symbol\n"
-                    "  -I path\t\tSet an include directory search path\n"
+                    "  -I dir\t\tSet an include directory search path\n"
                     "  -O\t\t\tOptimize code\n"
                     "  -Oi\t\t\tOptimize code, inline more code\n"
                     "  -Or\t\t\tEnable register variables\n"
@@ -113,10 +113,12 @@ static void Usage (void)
             "Long options:\n"
                     "  --ansi\t\tStrict ANSI mode\n"
                     "  --cpu type\t\tSet cpu type\n"
+                    "  --debug\t\tDebug mode\n"
                     "  --debug-info\t\tAdd debug info to object file\n"
             "  --help\t\tHelp (this text)\n"
                     "  --include-dir dir\tSet an include directory search path\n"
                     "  --signed-chars\tDefault characters are signed\n"
+                    "  --static-locals\tMake local variables static\n"
                     "  --target sys\t\tSet the target system\n"
                     "  --verbose\t\tIncrease verbosity\n"
                     "  --version\t\tPrint the compiler version number\n",
@@ -260,6 +262,14 @@ static void DefineSym (const char* Def)
 
 
 
+static void OptAddSource (const char* Opt, const char* Arg)
+/* Add source lines as comments in generated assembler file */
+{
+    AddSource = 1;
+}
+
+
+
 static void OptAnsi (const char* Opt, const char* Arg)
 /* Compile in strict ANSI mode */
 {
@@ -286,6 +296,14 @@ static void OptCPU (const char* Opt, const char* Arg)
 
 
 
+static void OptDebug (const char* Opt, const char* Arg)
+/* Compiler debug mode */
+{
+    Debug = 1;
+}
+
+
+
 static void OptDebugInfo (const char* Opt, const char* Arg)
 /* Add debug info to the object file */
 {
@@ -322,6 +340,14 @@ static void OptSignedChars (const char* Opt, const char* Arg)
 
 
 
+static void OptStaticLocals (const char* Opt, const char* Arg)
+/* Place local variables in static storage */
+{
+    StaticLocals = 1;
+}
+
+
+
 static void OptTarget (const char* Opt, const char* Arg)
 /* Set the target system */
 {
@@ -355,12 +381,15 @@ int main (int argc, char* argv[])
 {
     /* Program long options */
     static const LongOpt OptTab[] = {
+       { "--add-source",       0,      OptAddSource            },
        { "--ansi",             0,      OptAnsi                 },
         { "--cpu",                     1,      OptCPU                  },
+               { "--debug",            0,      OptDebug                },
        { "--debug-info",       0,      OptDebugInfo            },
        { "--help",             0,      OptHelp                 },
        { "--include-dir",      1,      OptIncludeDir           },
        { "--signed-chars",     0,      OptSignedChars          },
+               { "--static-locals",    0,      OptStaticLocals         },
        { "--target",           1,      OptTarget               },
        { "--verbose",          0,      OptVerbose              },
        { "--version",          0,      OptVersion              },
@@ -370,8 +399,7 @@ int main (int argc, char* argv[])
 
     /* Initialize the output file name */
     const char* OutputFile = 0;
-
-    fin = NULL;
+    const char* InputFile  = 0;
 
     /* Initialize the cmdline module */
     InitCmdLine (argc, argv, "cc65");
@@ -392,15 +420,15 @@ int main (int argc, char* argv[])
 
                case '-':
                    LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
-                   break;
+                   break;
 
-               case 'd':       /* debug mode */
-                   Debug = 1;
+               case 'd':
+                   OptDebug (Arg, 0);
                    break;
 
                case 'h':
                case '?':
-                   OptHelp (Arg, 0);
+                   OptHelp (Arg, 0);
                    break;
 
                case 'g':
@@ -409,7 +437,7 @@ int main (int argc, char* argv[])
 
                case 'j':
                    OptSignedChars (Arg, 0);
-                   break;
+                   break;
 
                case 'o':
                    OutputFile = GetArg (&I, 2);
@@ -432,8 +460,11 @@ int main (int argc, char* argv[])
                    while (*P) {
                        switch (*P++) {
                            case 'l':
-                               LocalsAreStatic = 1;
-                               break;
+                               OptStaticLocals (Arg, 0);
+                               break;
+                           default:
+                               UnknownOption (Arg);
+                               break;
                        }
                    }
                    break;
@@ -442,7 +473,7 @@ int main (int argc, char* argv[])
                    DefineSym (GetArg (&I, 2));
                    break;
 
-               case 'I':
+                       case 'I':
                    OptIncludeDir (Arg, GetArg (&I, 2));
                    break;
 
@@ -454,44 +485,40 @@ int main (int argc, char* argv[])
                            case 'f':
                                sscanf (P, "%lx", (long*) &OptDisable);
                                break;
-                           case 'i':
-                               FavourSize = 0;
-                               break;
-                           case 'r':
-                               EnableRegVars = 1;
-                               break;
-                           case 's':
-                               InlineStdFuncs = 1;
-                               break;
-                       }
-                   }
-                   break;
-
-               case 'T':
-                   IncSource = 1;
-                   break;
-
-               case 'V':
-                   OptVersion (Arg, 0);
-                   break;
-
-               case 'W':
-                   NoWarn = 1;
-                   break;
-
-               default:
+                           case 'i':
+                               FavourSize = 0;
+                               break;
+                           case 'r':
+                               EnableRegVars = 1;
+                               break;
+                           case 's':
+                               InlineStdFuncs = 1;
+                               break;
+                       }
+                   }
+                   break;
+
+               case 'T':
+                           OptAddSource (Arg, 0);
+                           break;
+
+                       case 'V':
+                           OptVersion (Arg, 0);
+                           break;
+
+                       case 'W':
+                           NoWarn = 1;
+                           break;
+
+                       default:
                            UnknownOption (Arg);
-                   break;
-           }
-       } else {
-           if (fin) {
-               fprintf (stderr, "additional file specs ignored\n");
-           } else {
-               fin = xstrdup (Arg);
-               inp = fopen (fin, "r");
-               if (inp == 0) {
-                   Fatal (FAT_CANNOT_OPEN_INPUT, strerror (errno));
-               }
+                           break;
+                   }
+               } else {
+                   if (InputFile) {
+                       fprintf (stderr, "additional file specs ignored\n");
+                   } else {
+                       InputFile = Arg;
            }
        }
 
@@ -500,14 +527,17 @@ int main (int argc, char* argv[])
     }
 
     /* Did we have a file spec on the command line? */
-    if (!fin) {
+    if (InputFile == 0) {
        fprintf (stderr, "%s: No input files\n", argv [0]);
        exit (EXIT_FAILURE);
     }
 
+    /* Open the input file */
+    OpenMainFile (InputFile);
+
     /* Create the output file name if it was not explicitly given */
     if (OutputFile == 0) {
-       OutputFile = MakeFilename (fin, ".s");
+       OutputFile = MakeFilename (InputFile, ".s");
     }
 
     /* Go! */