]> git.sur5r.net Git - cc65/blobdiff - src/cc65/main.c
Working on the new backend
[cc65] / src / cc65 / main.c
index 0b2e0e709288729bec65f071a79fe8a2f3455a01..6f3d0bbcfb009daf2802c8dba25aa046d455f8a3 100644 (file)
@@ -6,7 +6,7 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
+/* (C) 2000-2001 Ullrich von Bassewitz                                       */
 /*               Wacholderweg 14                                             */
 /*               D-70597 Stuttgart                                           */
 /* EMail:        uz@musoftware.de                                            */
 #include <stdio.h>
 #include <string.h>
 #include <stdlib.h>
-#include <ctype.h>
 #include <errno.h>
 
 /* common */
 #include "abend.h"
+#include "chartype.h"
 #include "cmdline.h"
 #include "fname.h"
+#include "print.h"
 #include "target.h"
 #include "tgttrans.h"
 #include "version.h"
@@ -57,7 +58,6 @@
 #include "incpath.h"
 #include "input.h"
 #include "macrotab.h"
-#include "optimize.h"
 #include "scanner.h"
 #include "segname.h"
 
@@ -96,7 +96,9 @@ 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\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"
@@ -159,8 +161,8 @@ static void SetSys (const char* Sys)
            cbmsys ("__PET__");
            break;
 
-       case TGT_NES:
-           AddNumericMacro ("__NES__", 1);
+       case TGT_BBC:
+           AddNumericMacro ("__BBC__", 1);
            break;
 
        case TGT_APPLE2:
@@ -174,7 +176,7 @@ static void SetSys (const char* Sys)
 
        default:
                    AbEnd ("Unknown target system type");
-    }      
+    }
 
     /* Initialize the translation tables for the target system */
     TgtTranslateInit ();
@@ -191,7 +193,7 @@ static void DoCreateDep (const char* OutputName)
     /* Open the file */
     FILE* F = fopen (DepName, "w");
     if (F == 0) {
-       Fatal (FAT_CANNOT_OPEN_OUTPUT, strerror (errno));
+       Fatal ("Cannot open dependency file `%s': %s", DepName, strerror (errno));
     }
 
     /* Write the dependencies to the file */
@@ -200,7 +202,7 @@ static void DoCreateDep (const char* OutputName)
     /* Close the file, check for errors */
     if (fclose (F) != 0) {
        remove (DepName);
-       Fatal (FAT_CANNOT_WRITE_OUTPUT);
+       Fatal ("Cannot write to dependeny file (disk full?)");
     }
 
     /* Free the name */
@@ -215,12 +217,12 @@ static void DefineSym (const char* Def)
     const char* P = Def;
 
     /* The symbol must start with a character or underline */
-    if (Def [0] != '_' && !isalpha (Def [0])) {
+    if (Def [0] != '_' && !IsAlpha (Def [0])) {
        InvDef (Def);
     }
 
     /* Check the symbol name */
-    while (isalnum (*P) || *P == '_') {
+    while (IsAlNum (*P) || *P == '_') {
        ++P;
     }
 
@@ -238,7 +240,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';
@@ -292,6 +294,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 */
 {
@@ -304,6 +314,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 */
 {
@@ -410,7 +433,7 @@ static void OptTarget (const char* Opt, const char* Arg)
 static void OptVerbose (const char* Opt, const char* Arg)
 /* Increase verbosity */
 {
-    ++Verbose;
+    ++Verbosity;
 }
 
 
@@ -429,23 +452,25 @@ 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            },
+       { "--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;
@@ -455,19 +480,19 @@ int main (int argc, char* argv[])
     const char* InputFile  = 0;
 
     /* Initialize the cmdline module */
-    InitCmdLine (argc, argv, "cc65");
+    InitCmdLine (&argc, &argv, "cc65");
 
     /* Initialize the default segment names */
     InitSegNames ();
 
     /* Parse the command line */
     I = 1;
-    while (I < argc) {
+    while (I < (int)ArgCount) {
 
        const char* P;
 
                /* Get the argument */
-               const char* Arg = argv [I];
+               const char* Arg = ArgVec[I];
 
                /* Check for an option */
                if (Arg [0] == '-') {
@@ -542,11 +567,12 @@ 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;
@@ -599,6 +625,9 @@ int main (int argc, char* argv[])
        OutputFile = MakeFilename (InputFile, ".s");
     }
 
+
+
+
     /* Go! */
     Compile ();
 
@@ -607,15 +636,17 @@ int main (int argc, char* argv[])
 
        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");
        if (F == 0) {
-           Fatal (FAT_CANNOT_OPEN_OUTPUT, strerror (errno));
+           Fatal ("Cannot open output file `%s': %s", OutputFile, strerror (errno));
        }
 
        /* Write the output to the file */
@@ -624,7 +655,7 @@ int main (int argc, char* argv[])
        /* Close the file, check for errors */
        if (fclose (F) != 0) {
            remove (OutputFile);
-           Fatal (FAT_CANNOT_WRITE_OUTPUT);
+           Fatal ("Cannot write to output file (disk full?)");
        }
 
        /* Create dependencies if requested */