]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - exec.c
moving -Olocal-temps to -O4 until the issues are solved
[xonotic/gmqcc.git] / exec.c
diff --git a/exec.c b/exec.c
index 8fe29434107ef1b67bc3dfea2704e7a4b3079ea0..2383ad70e5bf23827dae59e657b7877252745d3e 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2012
+ * Copyright (C) 2012, 2013
  *     Wolfgang Bumiller
  *     Dale Weiler
  *
@@ -359,7 +359,7 @@ static void trace_print_global(qc_program *prog, unsigned int glob, int vtype)
 done:
     if (len < (int)sizeof(spaces)-1) {
         spaces[sizeof(spaces)-1-len] = 0;
-        printf(spaces);
+        file_puts(stdout, spaces);
         spaces[sizeof(spaces)-1-len] = ' ';
     }
 }
@@ -475,7 +475,8 @@ static qcint prog_enterfunction(qc_program *prog, prog_section_function *func)
     st.function = func;
 
     if (prog->xflags & VMXF_TRACE) {
-        vec_push(prog->function_stack, prog_getstring(prog, func->name));
+        const char *str = prog_getstring(prog, func->name);
+        vec_push(prog->function_stack, str);
     }
 
 #ifdef QCVM_BACKUP_STRATEGY_CALLER_VARS
@@ -832,7 +833,9 @@ static void usage()
            "  -disasm-func func  disassemble and exit\n"
            "  -printdefs         list the defs section\n"
            "  -printfields       list the field section\n"
-           "  -printfuns         list functions information\n");
+           "  -printfuns         list functions information\n"
+           "  -v                 be verbose\n"
+           "  -vv                be even more verbose\n");
     printf("parameters:\n");
     printf("  -vector <V>   pass a vector parameter to main()\n"
            "  -float  <f>   pass a float parameter to main()\n"
@@ -891,6 +894,7 @@ int main(int argc, char **argv)
     bool        noexec           = false;
     const char *progsfile        = NULL;
     const char **dis_list        = NULL;
+    int         opts_v           = 0;
 
     arg0 = argv[0];
 
@@ -907,8 +911,25 @@ int main(int argc, char **argv)
             usage();
             exit(0);
         }
-        else if (!strcmp(argv[1], "-v") ||
-                 !strcmp(argv[1], "-version") ||
+        else if (!strcmp(argv[1], "-v")) {
+            ++opts_v;
+            --argc;
+            ++argv;
+        }
+        else if (!strncmp(argv[1], "-vv", 3)) {
+            const char *av = argv[1]+1;
+            for (; *av; ++av) {
+                if (*av == 'v')
+                    ++opts_v;
+                else {
+                    usage();
+                    exit(1);
+                }
+            }
+            --argc;
+            ++argv;
+        }
+        else if (!strcmp(argv[1], "-version") ||
                  !strcmp(argv[1], "--version"))
         {
             version();
@@ -980,7 +1001,7 @@ int main(int argc, char **argv)
 
             --argc;
             ++argv;
-            if (argc < 3) {
+            if (argc < 2) {
                 usage();
                 exit(1);
             }
@@ -1007,27 +1028,20 @@ int main(int argc, char **argv)
         }
         else
         {
+            printf("unknown parameter: %s\n", argv[1]);
             usage();
             exit(1);
         }
     }
 
-    if (argc > 2) {
-        usage();
-        exit(1);
-    }
-    if (argc > 1) {
-        if (progsfile) {
-            printf("only 1 program file may be specified\n");
-            usage();
-            exit(1);
-        }
+    if (argc == 2 && !progsfile) {
         progsfile = argv[1];
         --argc;
         ++argv;
     }
 
     if (!progsfile) {
+        printf("must specify a program to execute\n");
         usage();
         exit(1);
     }
@@ -1105,9 +1119,32 @@ int main(int argc, char **argv)
             for (a = 0; a < prog->functions[i].nargs; ++a) {
                 printf(" %i", prog->functions[i].argsize[a]);
             }
-            printf(") locals: %i + %i\n",
-                   prog->functions[i].firstlocal,
-                   prog->functions[i].locals);
+            if (opts_v > 1) {
+                int32_t start = prog->functions[i].entry;
+                if (start < 0)
+                    printf(") builtin %i\n", (int)-start);
+                else {
+                    size_t funsize = 0;
+                    prog_section_statement *st = prog->code + start;
+                    for (;st->opcode != INSTR_DONE; ++st)
+                        ++funsize;
+                    printf(") - %lu instructions", (unsigned long)funsize);
+                    if (opts_v > 2) {
+                        printf(" - locals: %i + %i\n",
+                               prog->functions[i].firstlocal,
+                               prog->functions[i].locals);
+                    }
+                    else
+                        printf("\n");
+                }
+            }
+            else if (opts_v) {
+                printf(") locals: %i + %i\n",
+                       prog->functions[i].firstlocal,
+                       prog->functions[i].locals);
+            }
+            else
+                printf(")\n");
         }
     }
     if (!noexec) {