]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - main.c
unnamed globals in the trace output use [@addr] now instead of [#addr] since # is...
[xonotic/gmqcc.git] / main.c
diff --git a/main.c b/main.c
index 8b30cfef6b1fd2d7bb3cfbe49d56b16d8c81a23b..6b751e3e03e7048788167dbd2bf4764c65e8505d 100644 (file)
--- a/main.c
+++ b/main.c
  */
 #include "gmqcc.h"
 
-uint32_t    opt_flags[1 + (NUM_F_FLAGS / 32)];
+uint32_t    opts_flags[1 + (COUNT_FLAGS / 32)];
+uint32_t    opts_warn [1 + (COUNT_WARNINGS / 32)];
 
-uint32_t    opt_O        = 1;
-const char *opt_output   = "progs.dat";
-int         opt_standard = STD_DEF;
+uint32_t    opts_O        = 1;
+const char *opts_output   = "progs.dat";
+int         opts_standard = COMPILER_GMQCC;
+bool        opts_debug    = false;
+bool        opts_memchk   = false;
 
 typedef struct { char *filename; int type; } argitem;
 VECTOR_MAKE(argitem, items);
@@ -41,15 +44,20 @@ static int usage() {
     printf("usage: %s [options] [files...]", app_name);
     printf("options:\n"
            "  -h, --help             show this help message\n"
-           "  -o, --output=file      output file, defaults to progs.dat\n"
+           "  -debug                 turns on compiler debug messages\n"
+           "  -memchk                turns on compiler memory leak check\n");
+    printf("  -o, --output=file      output file, defaults to progs.dat\n"
            "  -a filename            add an asm file to be assembled\n"
            "  -s filename            add a progs.src file to be used\n");
-    printf("  -fflag                 enable a flag\n"
-           "  -fno-flag              disable a flag\n"
+    printf("  -f<flag>               enable a flag\n"
+           "  -fno-<flag>            disable a flag\n"
            "  -std standard          select one of the following standards\n"
            "       -std=qcc          original QuakeC\n"
            "       -std=fteqcc       fteqcc QuakeC\n"
            "       -std=gmqcc        this compiler (default)\n");
+    printf("  -W<warning>            enable a warning\n"
+           "  -Wno-<warning>         disable a warning\n"
+           "  -Wall                  enable all warnings\n");
     printf("\n");
     printf("flags:\n"
            "  -fdarkplaces-string-table-bug\n"
@@ -60,28 +68,34 @@ static int usage() {
     return -1;
 }
 
-static bool options_setflag(const char *name, bool on) {
+static bool options_setflag_all(const char *name, bool on, uint32_t *flags, const opts_flag_def *list, size_t listsize) {
     size_t i;
 
-    for (i = 0; i < opt_flag_list_count; ++i) {
-        if (!strcmp(name, opt_flag_list[i].name)) {
-            longbit lb = opt_flag_list[i].bit;
+    for (i = 0; i < listsize; ++i) {
+        if (!strcmp(name, list[i].name)) {
+            longbit lb = list[i].bit;
 #if 0
             if (on)
-                opt_flags[lb.idx] |= (1<<(lb.bit));
+                flags[lb.idx] |= (1<<(lb.bit));
             else
-                opt_flags[lb.idx] &= ~(1<<(lb.bit));
+                flags[lb.idx] &= ~(1<<(lb.bit));
 #else
             if (on)
-                opt_flags[0] |= (1<<lb);
+                flags[0] |= (1<<lb);
             else
-                opt_flags[0] &= ~(1<<(lb));
+                flags[0] &= ~(1<<(lb));
 #endif
             return true;
         }
     }
     return false;
 }
+static bool options_setflag(const char *name, bool on) {
+    return options_setflag_all(name, on, opts_flags, opts_flag_list, COUNT_FLAGS);
+}
+static bool options_setwarn(const char *name, bool on) {
+    return options_setflag_all(name, on, opts_warn, opts_warn_list, COUNT_WARNINGS);
+}
 
 static bool options_witharg(int *argc_, char ***argv_, char **out) {
     int  argc   = *argc_;
@@ -135,6 +149,8 @@ static bool options_long_gcc(const char *optname, int *argc_, char ***argv_, cha
 
 static bool options_parse(int argc, char **argv) {
     bool argend = false;
+    size_t itr;
+    char buffer[1024];
     while (!argend && argc > 1) {
         char *argarg;
         argitem item;
@@ -146,17 +162,27 @@ static bool options_parse(int argc, char **argv) {
     /* All gcc-type long options */
             if (options_long_gcc("std", &argc, &argv, &argarg)) {
                 if      (!strcmp(argarg, "gmqcc") || !strcmp(argarg, "default"))
-                    opt_standard = STD_DEF;
+                    opts_standard = COMPILER_GMQCC;
                 else if (!strcmp(argarg, "qcc"))
-                    opt_standard = STD_QCC;
+                    opts_standard = COMPILER_QCC;
                 else if (!strcmp(argarg, "fte") || !strcmp(argarg, "fteqcc"))
-                    opt_standard = STD_FTE;
+                    opts_standard = COMPILER_FTEQCC;
+                else if (!strcmp(argarg, "qccx"))
+                    opts_standard = COMPILER_QCCX;
                 else {
                     printf("Unknown standard: %s\n", argarg);
                     return false;
                 }
                 continue;
             }
+            if (!strcmp(argv[0]+1, "debug")) {
+                opts_debug = true;
+                continue;
+            }
+            if (!strcmp(argv[0]+1, "memchk")) {
+                opts_memchk = true;
+                continue;
+            }
 
             switch (argv[0][1]) {
                 /* -h, show usage but exit with 0 */
@@ -167,7 +193,16 @@ static bool options_parse(int argc, char **argv) {
 
                 /* handle all -fflags */
                 case 'f':
-                    if (!strncmp(argv[0]+2, "no-", 3)) {
+                    util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
+                    if (!strcmp(argv[0]+2, "HELP")) {
+                        printf("Possible flags:\n");
+                        for (itr = 0; itr < COUNT_FLAGS; ++itr) {
+                            util_strtononcmd(opts_flag_list[itr].name, buffer, sizeof(buffer));
+                            printf(" -f%s\n", buffer);
+                        }
+                        exit(0);
+                    }
+                    else if (!strncmp(argv[0]+2, "NO_", 3)) {
                         if (!options_setflag(argv[0]+5, false)) {
                             printf("unknown flag: %s\n", argv[0]+2);
                             return false;
@@ -178,13 +213,39 @@ static bool options_parse(int argc, char **argv) {
                         return false;
                     }
                     break;
+                case 'W':
+                    util_strtocmd(argv[0]+2, argv[0]+2, strlen(argv[0]+2)+1);
+                    if (!strcmp(argv[0]+2, "HELP")) {
+                        printf("Possible warnings:\n");
+                        for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
+                            util_strtononcmd(opts_warn_list[itr].name, buffer, sizeof(buffer));
+                            printf(" -W%s\n", buffer);
+                        }
+                        exit(0);
+                    }
+                    else if (!strcmp(argv[0]+2, "ALL")) {
+                        for (itr = 0; itr < sizeof(opts_warn)/sizeof(opts_warn[0]); ++itr)
+                            opts_warn[itr] = 0xFFFFFFFFL;
+                        break;
+                    }
+                    if (!strncmp(argv[0]+2, "NO_", 3)) {
+                        if (!options_setwarn(argv[0]+5, false)) {
+                            printf("unknown warning: %s\n", argv[0]+2);
+                            return false;
+                        }
+                    }
+                    else if (!options_setwarn(argv[0]+2, true)) {
+                        printf("unknown warning: %s\n", argv[0]+2);
+                        return false;
+                    }
+                    break;
 
                 case 'O':
                     if (!options_witharg(&argc, &argv, &argarg)) {
                         printf("option -O requires a numerical argument\n");
                         return false;
                     }
-                    opt_O = atoi(argarg);
+                    opts_O = atoi(argarg);
                     break;
 
                 case 'o':
@@ -192,7 +253,7 @@ static bool options_parse(int argc, char **argv) {
                         printf("option -o requires an argument: the output file name\n");
                         return false;
                     }
-                    opt_output = argarg;
+                    opts_output = argarg;
                     break;
 
                 case 'a':
@@ -221,7 +282,7 @@ static bool options_parse(int argc, char **argv) {
                     else {
             /* All long options with arguments */
                         if (options_long_witharg("output", &argc, &argv, &argarg))
-                            opt_output = argarg;
+                            opts_output = argarg;
                         else
                         {
                             printf("Unknown parameter: %s\n", argv[0]);
@@ -255,12 +316,15 @@ int main(int argc, char **argv) {
         return usage();
     }
 
-    for (itr = 0; itr < opt_flag_list_count; ++itr) {
-        printf("Flag %s = %i\n", opt_flag_list[itr].name, OPT_FLAG(itr));
+    for (itr = 0; itr < COUNT_FLAGS; ++itr) {
+        printf("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr));
+    }
+    for (itr = 0; itr < COUNT_WARNINGS; ++itr) {
+        printf("Warning %s = %i\n", opts_warn_list[itr].name, OPTS_WARN(itr));
     }
-    printf("output = %s\n", opt_output);
-    printf("optimization level = %i\n", (int)opt_O);
-    printf("standard = %i\n", opt_standard);
+    printf("output = %s\n", opts_output);
+    printf("optimization level = %i\n", (int)opts_O);
+    printf("standard = %i\n", opts_standard);
 
     if (items_elements) {
         printf("Mode: manual\n");