]> git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - main.c
-fcorrect-ternary; by default -std=fteqcc now uses fteqcc's wrong ternary precedence...
[xonotic/gmqcc.git] / main.c
diff --git a/main.c b/main.c
index db9f2b81806b848826b985d329a0ab770e8cc82b..220a2e390b85803daed1c2efcbbdd3e96e347598 100644 (file)
--- a/main.c
+++ b/main.c
@@ -39,7 +39,7 @@ bool        opts_dumpfin  = false;
 bool        opts_dump     = false;
 bool        opts_forcecrc = false;
 bool        opts_pp_only  = false;
-size_t      opts_max_array_size = 1024;
+size_t      opts_max_array_size = (1024 << 3);
 
 uint16_t    opts_forced_crc;
 
@@ -221,6 +221,8 @@ static bool options_parse(int argc, char **argv) {
                     options_set(opts_flags, TRANSLATABLE_STRINGS, true);
                     options_set(opts_flags, ADJUST_VECTOR_FIELDS, false);
                     options_set(opts_flags, ASSIGN_FUNCTION_TYPES, true);
+                    options_set(opts_warn, WARN_TERNARY_PRECEDENCE, true);
+                    options_set(opts_flags, CORRECT_TERNARY, false);
                     opts_standard = COMPILER_FTEQCC;
                 } else if (!strcmp(argarg, "qccx")) {
                     options_set(opts_flags, ADJUST_VECTOR_FIELDS, false);
@@ -489,6 +491,7 @@ int main(int argc, char **argv) {
     size_t itr;
     int retval = 0;
     bool opts_output_free = false;
+    bool operators_free = false;
     bool progs_src = false;
     FILE *outfile = NULL;
 
@@ -519,6 +522,7 @@ int main(int argc, char **argv) {
 
     options_set(opts_flags, ADJUST_VECTOR_FIELDS, true);
     options_set(opts_flags, FTEPP, false);
+    options_set(opts_flags, CORRECT_TERNARY, true);
 
     if (!options_parse(argc, argv)) {
         return usage();
@@ -536,6 +540,26 @@ int main(int argc, char **argv) {
         operator_count = qcc_operator_count;
     }
 
+    if (operators == fte_operators) {
+        /* fix ternary? */
+        if (OPTS_FLAG(CORRECT_TERNARY)) {
+            oper_info *newops;
+            if (operators[operator_count-2].id != opid1(',') ||
+                operators[operator_count-1].id != opid2(':','?'))
+            {
+                con_err("internal error: operator precedence table wasn't updated correctly!\n");
+                exit(1);
+            }
+            operators_free = true;
+            newops = mem_a(sizeof(operators[0]) * operator_count);
+            memcpy(newops, operators, sizeof(operators[0]) * operator_count);
+            memcpy(&newops[operator_count-2], &operators[operator_count-1], sizeof(newops[0]));
+            memcpy(&newops[operator_count-1], &operators[operator_count-2], sizeof(newops[0]));
+            newops[operator_count-2].prec = newops[operator_count-1].prec+1;
+            operators = newops;
+        }
+    }
+
     if (opts_dump) {
         for (itr = 0; itr < COUNT_FLAGS; ++itr) {
             con_out("Flag %s = %i\n", opts_flag_list[itr].name, OPTS_FLAG(itr));
@@ -655,9 +679,11 @@ srcdone:
                         goto cleanup;
                     }
                     data = ftepp_get();
-                    if (!parser_compile_string_len(items[itr].filename, data, vec_size(data)-1)) {
-                        retval = 1;
-                        goto cleanup;
+                    if (vec_size(data)) {
+                        if (!parser_compile_string_len(items[itr].filename, data, vec_size(data))) {
+                            retval = 1;
+                            goto cleanup;
+                        }
                     }
                     ftepp_flush();
                 }
@@ -686,6 +712,14 @@ srcdone:
 
     /* stuff */
 
+    if (!opts_pp_only) {
+        for (itr = 0; itr < COUNT_OPTIMIZATIONS; ++itr) {
+            if (optimization_count[itr]) {
+                con_out("%s: %u\n", opts_opt_list[itr].name, (unsigned int)optimization_count[itr]);
+            }
+        }
+    }
+
 cleanup:
     util_debug("COM", "cleaning ...\n");
     ftepp_finish();
@@ -696,6 +730,8 @@ cleanup:
         parser_cleanup();
     if (opts_output_free)
         mem_d((char*)opts_output);
+    if (operators_free)
+        mem_d((void*)operators);
 
     lex_cleanup();
     util_meminfo();