]> git.rm.cloudns.org Git - xonotic/gmqcc.git/commitdiff
option: -force-crc=number, added -info to executor to just show some file info like...
authorWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 22 Aug 2012 12:00:57 +0000 (14:00 +0200)
committerWolfgang (Blub) Bumiller <blub@speed.at>
Wed, 22 Aug 2012 12:00:57 +0000 (14:00 +0200)
code.c
exec.c
gmqcc.h
main.c

diff --git a/code.c b/code.c
index 5c69e8803496775313fd91b3d4e4c54dc8abc312..56d059ffbe49985b4c181745741a31b13689456d 100644 (file)
--- a/code.c
+++ b/code.c
@@ -183,7 +183,10 @@ bool code_write(const char *filename) {
     code_header.strings.offset    = code_header.globals.offset    + (sizeof(int32_t)                * code_globals_elements);
     code_header.strings.length    = code_chars_elements;
     code_header.version           = 6;
-    code_header.crc16             = 0; /* TODO: */
+    if (opts_forcecrc)
+        code_header.crc16         = opts_forced_crc;
+    else
+        code_header.crc16         = 0; /* TODO: */
     code_header.entfield          = code_entfields;
 
     if (OPTS_FLAG(DARKPLACES_STRING_TABLE_BUG)) {
diff --git a/exec.c b/exec.c
index 2e1f58d476baf9f99c622153dcfaa5093b884505..7e9c941b0476bccb34c3a7525a7740117b44d609 100644 (file)
--- a/exec.c
+++ b/exec.c
@@ -80,6 +80,7 @@ qc_program* prog_load(const char *filename)
     memset(prog, 0, sizeof(*prog));
 
     prog->entityfields = header.entfield;
+    prog->crc16 = header.crc16;
 
     prog->filename = util_strdup(filename);
     if (!prog->filename) {
@@ -606,6 +607,21 @@ cleanup:
  */
 
 #if defined(QCVM_EXECUTOR)
+const char *type_name[TYPE_COUNT] = {
+    "void",
+    "string",
+    "float",
+    "vector",
+    "entity",
+    "field",
+    "function",
+    "pointer",
+#if 0
+    "integer",
+#endif
+    "variant"
+};
+
 bool        opts_debug    = false;
 bool        opts_memchk   = false;
 
@@ -686,6 +702,8 @@ int main(int argc, char **argv)
     qcint       fnmain = -1;
     qc_program *prog;
     size_t      xflags = VMXF_DEFAULT;
+    bool        opts_printfields = false;
+    bool        opts_info  = false;
 
     arg0 = argv[0];
 
@@ -703,6 +721,16 @@ int main(int argc, char **argv)
             ++argv;
             xflags |= VMXF_PROFILE;
         }
+        else if (!strcmp(argv[1], "-info")) {
+            --argc;
+            ++argv;
+            opts_info = true;
+        }
+        else if (!strcmp(argv[1], "-printfields")) {
+            --argc;
+            ++argv;
+            opts_printfields = true;
+        }
         else
             usage();
     }
@@ -718,6 +746,8 @@ int main(int argc, char **argv)
     prog->builtins_count = qc_builtins_count;
     prog->builtins_alloc = 0;
 
+    printf("Program's system-checksum = 0x%04x\n", (int)prog->crc16);
+
     for (i = 1; i < prog->functions_count; ++i) {
         const char *name = prog_getstring(prog, prog->functions[i].name);
         /* printf("Found function: %s\n", name); */
@@ -725,12 +755,27 @@ int main(int argc, char **argv)
             fnmain = (qcint)i;
     }
     printf("Entity field space: %i\n", (int)prog->entityfields);
-    if (fnmain > 0)
-    {
-        prog_exec(prog, &prog->functions[fnmain], xflags, VM_JUMPS_DEFAULT);
+    if (opts_info) {
+        prog_delete(prog);
+        return 0;
+    }
+    if (opts_printfields) {
+        for (i = 0; i < prog->fields_count; ++i) {
+            printf("Field: %8s %-16s at %u\n",
+                   type_name[prog->fields[i].type],
+                   prog_getstring(prog, prog->fields[i].name),
+                   (unsigned int)prog->fields[i].offset);
+        }
     }
     else
-        printf("No main function found\n");
+    {
+        if (fnmain > 0)
+        {
+            prog_exec(prog, &prog->functions[fnmain], xflags, VM_JUMPS_DEFAULT);
+        }
+        else
+            printf("No main function found\n");
+    }
 
     prog_delete(prog);
     return 0;
diff --git a/gmqcc.h b/gmqcc.h
index 5b838de2dbf15a5f577e3f3e20f03d9f3f972e57..bb03a9af13b48deff346d61308416da0240a5b4b 100644 (file)
--- a/gmqcc.h
+++ b/gmqcc.h
@@ -860,6 +860,8 @@ typedef struct qc_program_s {
     MEM_VECTOR_MAKE(qcint,                  entitydata);
     MEM_VECTOR_MAKE(bool,                   entitypool);
 
+    uint16_t crc16;
+
     size_t tempstring_start;
     size_t tempstring_at;
 
@@ -994,6 +996,8 @@ extern bool        opts_debug;
 extern bool        opts_memchk;
 extern bool        opts_dump;
 extern bool        opts_werror;
+extern bool        opts_forcecrc;
+extern uint16_t    opts_forced_crc;
 
 /*===================================================================*/
 #define OPTS_FLAG(i) (!! (opts_flags[(i)/32] & (1<< ((i)%32))))
diff --git a/main.c b/main.c
index 13fa575ff715f6e6b7a90d0ef4355769953b1ce3..149ea46ab17681efbc208e7c9806fe986efc7d8c 100644 (file)
--- a/main.c
+++ b/main.c
@@ -33,6 +33,9 @@ bool        opts_debug    = false;
 bool        opts_memchk   = false;
 bool        opts_dump     = false;
 bool        opts_werror   = false;
+bool        opts_forcecrc = false;
+
+uint16_t    opts_forced_crc;
 
 static bool opts_output_wasset = false;
 
@@ -63,6 +66,7 @@ static int usage() {
     printf("  -W<warning>            enable a warning\n"
            "  -Wno-<warning>         disable a warning\n"
            "  -Wall                  enable all warnings\n");
+    printf("  -force-crc=num         force a specific checksum into the header\n");
     printf("\n");
     printf("flags:\n"
            "  -fdarkplaces-string-table-bug\n"
@@ -180,6 +184,11 @@ static bool options_parse(int argc, char **argv) {
                 }
                 continue;
             }
+            if (options_long_gcc("force-crc", &argc, &argv, &argarg)) {
+                opts_forcecrc = true;
+                opts_forced_crc = strtol(argarg, NULL, 0);
+                continue;
+            }
             if (!strcmp(argv[0]+1, "debug")) {
                 opts_debug = true;
                 continue;