]> git.sur5r.net Git - cc65/blobdiff - src/cc65/main.c
Fixed several type conversion issues
[cc65] / src / cc65 / main.c
index c79f52acf325d09102b4c7b28e0712dd99032f45..3ed7127e3120c9a31d4f8a0b1e6b7e126256e803 100644 (file)
@@ -6,9 +6,9 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000-2002 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
+/* (C) 2000-2003 Ullrich von Bassewitz                                       */
+/*               Römerstrasse 52                                             */
+/*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 #include "abend.h"
 #include "chartype.h"
 #include "cmdline.h"
+#include "cpu.h"
+#include "debugflag.h"
 #include "fname.h"
 #include "print.h"
+#include "segnames.h"
 #include "target.h"
 #include "tgttrans.h"
 #include "version.h"
@@ -53,7 +56,6 @@
 #include "asmcode.h"
 #include "compile.h"
 #include "codeopt.h"
-#include "cpu.h"
 #include "error.h"
 #include "global.h"
 #include "incpath.h"
@@ -102,7 +104,7 @@ static void Usage (void)
                     "  --check-stack\t\tGenerate stack overflow checks\n"
                     "  --code-name seg\tSet the name of the CODE segment\n"
             "  --codesize x\t\tAccept larger code by factor x\n"
-                    "  --cpu type\t\tSet cpu type\n"
+                    "  --cpu type\t\tSet cpu type (6502, 65c02)\n"
             "  --create-dep\t\tCreate a make dependency file\n"
                     "  --data-name seg\tSet the name of the DATA segment\n"
                     "  --debug\t\tDebug mode\n"
@@ -110,9 +112,11 @@ static void Usage (void)
             "  --debug-opt name\tDebug optimization steps\n"
             "  --disable-opt name\tDisable an optimization step\n"
                     "  --enable-opt name\tEnable an optimization step\n"
+                    "  --forget-inc-paths\tForget include search paths\n"
             "  --help\t\tHelp (this text)\n"
                     "  --include-dir dir\tSet an include directory search path\n"
             "  --list-opt-steps\tList all optimizer steps and exit\n"
+             "  --register-space b\tSet space available for register variables\n"
              "  --register-vars\tEnable register variables\n"
                     "  --rodata-name seg\tSet the name of the RODATA segment\n"
                     "  --signed-chars\tDefault characters are signed\n"
@@ -207,8 +211,12 @@ static void SetSys (const char* Sys)
             DefineNumericMacro ("__ATMOS__", 1);
             break;
 
+        case TGT_NES:
+            DefineNumericMacro ("__NES__", 1);
+            break;
+
        default:
-                   AbEnd ("Unknown target system type");
+                   AbEnd ("Unknown target system type %d", Target);
     }
 
     /* Initialize the translation tables for the target system */
@@ -375,11 +383,9 @@ static void OptCreateDep (const char* Opt attribute ((unused)),
 static void OptCPU (const char* Opt, const char* Arg)
 /* Handle the --cpu option */
 {
-    if (strcmp (Arg, "6502") == 0) {
-               CPU = CPU_6502;
-    } else if (strcmp (Arg, "65C02") == 0) {
-       CPU = CPU_65C02;
-    } else {
+    /* Find the CPU from the given name */
+    CPU = FindCPU (Arg);
+    if (CPU != CPU_6502 && CPU != CPU_65C02) {
                AbEnd ("Invalid argument for %s: `%s'", Opt, Arg);
     }
 }
@@ -399,10 +405,10 @@ static void OptDataName (const char* Opt attribute ((unused)), const char* Arg)
 
 
 static void OptDebug (const char* Opt attribute ((unused)),
-                     const char* Arg attribute ((unused)))
+                     const char* Arg attribute ((unused)))
 /* Compiler debug mode */
 {
-    Debug = 1;
+    ++Debug;
 }
 
 
@@ -499,6 +505,15 @@ static void OptEnableOpt (const char* Opt attribute ((unused)), const char* Arg)
 
 
 
+static void OptForgetIncPaths (const char* Opt attribute ((unused)),
+                               const char* Arg attribute ((unused)))
+/* Forget all currently defined include paths */
+{
+    ForgetAllIncludePaths ();
+}
+
+
+
 static void OptHelp (const char* Opt attribute ((unused)),
                     const char* Arg attribute ((unused)))
 /* Print usage information and exit */
@@ -530,7 +545,18 @@ static void OptListOptSteps (const char* Opt attribute ((unused)),
 
 
 
-static void OptRegisterVars (const char* Opt attribute ((unused)), 
+static void OptRegisterSpace (const char* Opt, const char* Arg)
+/* Handle the --register-space option */
+{
+    /* Numeric argument expected */
+    if (sscanf (Arg, "%u", &RegisterSpace) != 1 || RegisterSpace > 256) {
+               AbEnd ("Argument for option %s is invalid", Opt);
+    }
+}
+
+
+
+static void OptRegisterVars (const char* Opt attribute ((unused)),
                              const char* Arg attribute ((unused)))
 /* Handle the --register-vars option */
 {
@@ -614,10 +640,12 @@ int main (int argc, char* argv[])
        { "--debug-info",       0,      OptDebugInfo            },
         { "--debug-opt",        1,      OptDebugOpt             },
        { "--disable-opt",      1,      OptDisableOpt           },
-       { "--enable-opt",       1,      OptEnableOpt,           },
+       { "--enable-opt",       1,      OptEnableOpt            },
+               { "--forget-inc-paths", 0,      OptForgetIncPaths       },
        { "--help",             0,      OptHelp                 },
        { "--include-dir",      1,      OptIncludeDir           },
        { "--list-opt-steps",   0,      OptListOptSteps         },
+        { "--register-space",   1,      OptRegisterSpace        },
         { "--register-vars",    0,      OptRegisterVars         },
        { "--rodata-name",      1,      OptRodataName           },
        { "--signed-chars",     0,      OptSignedChars          },
@@ -639,6 +667,9 @@ int main (int argc, char* argv[])
     /* Initialize the default segment names */
     InitSegNames ();
 
+    /* Initialize the include search paths */
+    InitIncludePaths ();
+
     /* Parse the command line */
     I = 1;
     while (I < ArgCount) {
@@ -780,23 +811,23 @@ int main (int argc, char* argv[])
        OutputFile = MakeFilename (InputFile, ".s");
     }
 
+    /* If no CPU given, use the default CPU for the target */
+    if (CPU == CPU_UNKNOWN) {
+        if (Target != TGT_UNKNOWN) {
+            CPU = DefaultCPU[Target];
+        } else {
+            CPU = CPU_6502;
+        }
+    }
+
     /* Go! */
     Compile (InputFile);
 
     /* Create the output file if we didn't had any errors */
     if (ErrorCount == 0 || Debug) {
 
-       FILE* F;
-
-#if 0
-       /* Optimize the output if requested */
-       if (Optimize) {
-           OptDoOpt ();
-       }
-#endif
-
        /* Open the file */
-       F = fopen (OutputFile, "w");
+       FILE* F = fopen (OutputFile, "w");
        if (F == 0) {
            Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
        }