]> git.sur5r.net Git - cc65/blobdiff - src/cc65/main.c
New option and #pragma --local-strings that causes string literals to be
[cc65] / src / cc65 / main.c
index d3ba3e4ac3e4bc48362663ebf99d8c340c5ce06e..ed3c987ab5309417a0bd0a750129406839825654 100644 (file)
@@ -48,6 +48,7 @@
 #include "mmodel.h"
 #include "print.h"
 #include "segnames.h"
+#include "strbuf.h"
 #include "target.h"
 #include "tgttrans.h"
 #include "version.h"
@@ -64,8 +65,9 @@
 #include "macrotab.h"
 #include "output.h"
 #include "scanner.h"
-#include "standard.h"
 #include "segments.h"
+#include "standard.h"
+#include "svnversion.h"
 
 
 
@@ -119,7 +121,8 @@ static void Usage (void)
             "  --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"
-            "  --memory-model model\tSet the memory model\n"
+            "  --local-strings\tEmit string literals immediately\n"
+            "  --memory-model model\tSet the memory model\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"
@@ -176,10 +179,6 @@ static void SetSys (const char* Sys)
            cbmsys ("__C128__");
            break;
 
-       case TGT_ACE:
-           cbmsys ("__ACE__");
-           break;
-
        case TGT_PLUS4:
            cbmsys ("__PLUS4__");
            break;
@@ -558,6 +557,15 @@ static void OptListOptSteps (const char* Opt attribute ((unused)),
 
 
 
+static void OptLocalStrings (const char* Opt attribute ((unused)),
+                            const char* Arg attribute ((unused)))
+/* Emit string literals immediately */
+{
+    IS_Set (&LocalStrings, 1);
+}
+
+
+
 static void OptMemoryModel (const char* Opt, const char* Arg)
 /* Set the memory model */
 {
@@ -666,12 +674,59 @@ static void OptVerbose (const char* Opt attribute ((unused)),
 
 
 static void OptVersion (const char* Opt attribute ((unused)),
-                       const char* Arg attribute ((unused)))
-/* Print the assembler version */
+                       const char* Arg attribute ((unused)))
+/* Print the compiler version */
 {
     fprintf (stderr,
-                    "cc65 V%u.%u.%u\n",
-                    VER_MAJOR, VER_MINOR, VER_PATCH);
+                    "cc65 V%s\nSVN version: %s\n",
+                    GetVersionAsString (), SVNVersion);
+    exit (EXIT_SUCCESS);
+}
+
+
+
+static void OptWarning (const char* Opt attribute ((unused)), const char* Arg)
+/* Handle the -W option */
+{
+    StrBuf W = AUTO_STRBUF_INITIALIZER;
+
+    /* Arg is a list of suboptions, separated by commas */
+    while (Arg) {
+
+        const char* Pos;
+        int         Enabled = 1;
+        IntStack*   S;
+
+        /* The suboption may be prefixed with '-' or '+' */
+        if (*Arg == '-') {
+            Enabled = 0;
+            ++Arg;
+        } else if (*Arg == '+') {
+            /* This is the default */
+            ++Arg;
+        }
+
+        /* Get the next suboption */
+        Pos = strchr (Arg, ',');
+        if (Pos) {
+            SB_CopyBuf (&W, Arg, Pos - Arg);
+            Arg = Pos + 1;
+        } else {
+            SB_CopyStr (&W, Arg);
+            Arg = 0;
+        }
+        SB_Terminate (&W);
+
+        /* Search for the warning */
+        S = FindWarning (SB_GetConstBuf (&W));
+        if (S == 0) {
+            InvArg (Opt, SB_GetConstBuf (&W));
+        }
+        IS_Set (S, Enabled);
+    }
+
+    /* Free allocated memory */
+    SB_Done (&W);
 }
 
 
@@ -706,6 +761,7 @@ int main (int argc, char* argv[])
        { "--help",             0,      OptHelp                 },
        { "--include-dir",      1,      OptIncludeDir           },
        { "--list-opt-steps",   0,      OptListOptSteps         },
+        { "--local-strings",    0,      OptLocalStrings         },
         { "--memory-model",     1,      OptMemoryModel          },
         { "--register-space",   1,      OptRegisterSpace        },
         { "--register-vars",    0,      OptRegisterVars         },
@@ -743,9 +799,9 @@ int main (int argc, char* argv[])
                const char* Arg = ArgVec[I];
 
                /* Check for an option */
-               if (Arg [0] == '-') {
+               if (Arg[0] == '-') {
 
-                   switch (Arg [1]) {
+                   switch (Arg[1]) {
 
                case '-':
                    LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0]));
@@ -798,7 +854,7 @@ int main (int argc, char* argv[])
                            default:
                                UnknownOption (Arg);
                                break;
-                       }
+                       }
                    }
                    break;
 
@@ -841,7 +897,7 @@ int main (int argc, char* argv[])
                            break;
 
                        case 'W':
-                           IS_Set (&WarnDisable, 1);
+                    OptWarning (Arg, GetArg (&I, 2));
                            break;
 
                        default:
@@ -893,10 +949,13 @@ int main (int argc, char* argv[])
     /* Create the output file if we didn't had any errors */
     if (PreprocessOnly == 0 && (ErrorCount == 0 || Debug)) {
 
-       /* Open the file */
+        /* Emit literals, externals, do cleanup and optimizations */
+        FinishCompile ();
+
+       /* Open the file */
         OpenOutputFile ();
 
-       /* Write the output to the file */
+       /* Write the output to the file */
                WriteAsmOutput ();
                Print (stdout, 1, "Wrote output to `%s'\n", OutputFilename);