From: Wolfgang (Blub) Bumiller Date: Sun, 19 Aug 2012 13:19:43 +0000 (+0200) Subject: qcvm: -trace flag X-Git-Tag: 0.1-rc1~171 X-Git-Url: https://de.git.xonotic.org/?a=commitdiff_plain;h=dc5555e084423ef101049fb9aa1dc785ef1478f1;p=xonotic%2Fgmqcc.git qcvm: -trace flag --- diff --git a/exec.c b/exec.c index 66095f5..7f5c971 100644 --- a/exec.c +++ b/exec.c @@ -636,17 +636,42 @@ static prog_builtin qc_builtins[] = { }; static size_t qc_builtins_count = sizeof(qc_builtins) / sizeof(qc_builtins[0]); +static const char *arg0 = NULL; + +void usage() +{ + printf("usage: [-debug] %s file\n", arg0); + exit(1); +} + int main(int argc, char **argv) { size_t i; qcint fnmain = -1; qc_program *prog; + size_t xflags = VMXF_DEFAULT; - if (argc != 2) { - printf("usage: %s file\n", argv[0]); - exit(1); + arg0 = argv[0]; + + if (argc < 2) + usage(); + + while (argc > 2) { + if (!strcmp(argv[1], "-trace")) { + --argc; + ++argv; + xflags |= VMXF_TRACE; + } + else if (!strcmp(argv[1], "-profile")) { + --argc; + ++argv; + xflags |= VMXF_PROFILE; + } + else + usage(); } + prog = prog_load(argv[1]); if (!prog) { printf("failed to load program '%s'\n", argv[1]); @@ -659,14 +684,14 @@ int main(int argc, char **argv) for (i = 1; i < prog->functions_count; ++i) { const char *name = prog_getstring(prog, prog->functions[i].name); - printf("Found function: %s\n", name); + /* printf("Found function: %s\n", name); */ if (!strcmp(name, "main")) fnmain = (qcint)i; } printf("Entity field space: %i\n", (int)prog->entityfields); if (fnmain > 0) { - prog_exec(prog, &prog->functions[fnmain], VMXF_TRACE, VM_JUMPS_DEFAULT); + prog_exec(prog, &prog->functions[fnmain], xflags, VM_JUMPS_DEFAULT); } else printf("No main function found\n");