]> git.sur5r.net Git - cc65/blobdiff - src/cc65/main.c
Avoid a copy of the line contents
[cc65] / src / cc65 / main.c
index 73f8382c9d2cd9740122f94095e660e3186879cc..32adcb7251229b565cfbdacba061c771a496c3c8 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
+/* (C) 2000-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
 /* cc65 */
 #include "asmcode.h"
 #include "compile.h"
+#include "codeopt.h"
 #include "cpu.h"
 #include "error.h"
 #include "global.h"
 #include "incpath.h"
 #include "input.h"
 #include "macrotab.h"
-#include "optimize.h"
 #include "scanner.h"
-#include "segname.h"
+#include "segments.h"
 
 
 
@@ -97,11 +97,15 @@ static void Usage (void)
             "Long options:\n"
                     "  --ansi\t\tStrict ANSI mode\n"
             "  --bss-name seg\tSet the name of the BSS segment\n"
+                    "  --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"
                     "  --data-name seg\tSet the name of the DATA segment\n"
                     "  --debug\t\tDebug mode\n"
                     "  --debug-info\t\tAdd debug info to object file\n"
+            "  --disable-opt name\tDisable an optimization step\n"
+                    "  --enable-opt name\tEnable an optimization step\n"
             "  --help\t\tHelp (this text)\n"
                     "  --include-dir dir\tSet an include directory search path\n"
                     "  --rodata-name seg\tSet the name of the RODATA segment\n"
@@ -239,7 +243,7 @@ static void DefineSym (const char* Def)
                 */
        char* Q;
        unsigned Len = strlen (Def)+1;
-       char* S = xmalloc (Len);
+       char* S = (char*) xmalloc (Len);
        memcpy (S, Def, Len);
        Q = S + (P - Def);
        *Q++ = '\0';
@@ -293,6 +297,14 @@ static void OptBssName (const char* Opt, const char* Arg)
 
 
 
+static void OptCheckStack (const char* Opt, const char* Arg)
+/* Handle the --check-stack option */
+{
+    CheckStack = 1;
+}
+
+
+
 static void OptCodeName (const char* Opt, const char* Arg)
 /* Handle the --code-name option */
 {
@@ -305,6 +317,19 @@ static void OptCodeName (const char* Opt, const char* Arg)
 
 
 
+static void OptCodeSize (const char* Opt, const char* Arg)
+/* Handle the --codesize option */
+{
+    /* Numeric argument expected */
+    if (sscanf (Arg, "%u", &CodeSizeFactor) != 1 ||
+       CodeSizeFactor < 100 ||
+               CodeSizeFactor > 1000) {
+       AbEnd ("Argument for %s is invalid", Opt);
+    }
+}
+
+
+
 static void OptCreateDep (const char* Opt, const char* Arg)
 /* Handle the --create-dep option */
 {
@@ -355,6 +380,22 @@ static void OptDebugInfo (const char* Opt, const char* Arg)
 
 
 
+static void OptDisableOpt (const char* Opt, const char* Arg)
+/* Disable an optimization step */
+{
+    DisableOpt (Arg);
+}
+
+
+
+static void OptEnableOpt (const char* Opt, const char* Arg)
+/* Enable an optimization step */
+{
+    EnableOpt (Arg);
+}
+
+
+
 static void OptHelp (const char* Opt, const char* Arg)
 /* Print usage information and exit */
 {
@@ -430,23 +471,27 @@ int main (int argc, char* argv[])
 {
     /* Program long options */
     static const LongOpt OptTab[] = {
-       { "--add-source",       0,      OptAddSource            },
-       { "--ansi",             0,      OptAnsi                 },
-       { "--bss-name",         1,      OptBssName              },
-       { "--code-name",        1,      OptCodeName             },
-       { "--create-dep",       0,      OptCreateDep            },
-        { "--cpu",                     1,      OptCPU                  },
-       { "--data-name",        1,      OptDataName             },
-               { "--debug",            0,      OptDebug                },
-       { "--debug-info",       0,      OptDebugInfo            },
-       { "--help",             0,      OptHelp                 },
+       { "--add-source",       0,      OptAddSource            },
+       { "--ansi",             0,      OptAnsi                 },
+       { "--bss-name",         1,      OptBssName              },
+               { "--check-stack",      0,      OptCheckStack           },
+       { "--code-name",        1,      OptCodeName             },
+       { "--codesize",         1,      OptCodeSize             },
+       { "--create-dep",       0,      OptCreateDep            },
+        { "--cpu",                     1,      OptCPU                  },
+       { "--data-name",        1,      OptDataName             },
+               { "--debug",            0,      OptDebug                },
+       { "--debug-info",       0,      OptDebugInfo            },
+       { "--disable-opt",      1,      OptDisableOpt           },
+       { "--enable-opt",       1,      OptEnableOpt,           },
+       { "--help",             0,      OptHelp                 },
        { "--include-dir",      1,      OptIncludeDir           },
        { "--rodata-name",      1,      OptRodataName           },
-       { "--signed-chars",     0,      OptSignedChars          },
-               { "--static-locals",    0,      OptStaticLocals         },
-       { "--target",           1,      OptTarget               },
-       { "--verbose",          0,      OptVerbose              },
-       { "--version",          0,      OptVersion              },
+       { "--signed-chars",     0,      OptSignedChars          },
+               { "--static-locals",    0,      OptStaticLocals         },
+       { "--target",           1,      OptTarget               },
+       { "--verbose",          0,      OptVerbose              },
+       { "--version",          0,      OptVersion              },
     };
 
     int I;
@@ -463,7 +508,7 @@ int main (int argc, char* argv[])
 
     /* Parse the command line */
     I = 1;
-    while (I < ArgCount) {
+    while (I < (int)ArgCount) {
 
        const char* P;
 
@@ -543,18 +588,19 @@ int main (int argc, char* argv[])
                    P = Arg + 2;
                    while (*P) {
                        switch (*P++) {
-                           case 'f':
-                               sscanf (P, "%lx", (long*) &OptDisable);
+                           case 'f':
+                               sscanf (P, "%lx", (long*) &OptDisable);
                                break;
                            case 'i':
                                FavourSize = 0;
+                               CodeSizeFactor = 200;
                                break;
                            case 'r':
-                               EnableRegVars = 1;
+                               EnableRegVars = 1;
                                break;
                            case 's':
                                InlineStdFuncs = 1;
-                               break;
+                               break;
                        }
                    }
                    break;
@@ -592,26 +638,25 @@ int main (int argc, char* argv[])
        AbEnd ("No input files");
     }
 
-    /* Open the input file */
-    OpenMainFile (InputFile);
-
     /* Create the output file name if it was not explicitly given */
     if (OutputFile == 0) {
        OutputFile = MakeFilename (InputFile, ".s");
     }
 
     /* Go! */
-    Compile ();
+    Compile (InputFile);
 
     /* Create the output file if we didn't had any errors */
     if (ErrorCount == 0 || Debug) {
 
        FILE* F;
 
-       /* Optimize the output if requested */
-       if (Optimize) {
-           OptDoOpt ();
-       }
+#if 0
+       /* Optimize the output if requested */
+       if (Optimize) {
+           OptDoOpt ();
+       }
+#endif
 
        /* Open the file */
        F = fopen (OutputFile, "w");