int main(int argc, char *argv[]) { MVMInstance *instance; const char *input_file; int dump = 0; int argi = 1; int flag; for (; (flag = parse_flag(argv[argi])) != NOT_A_FLAG; ++argi) { switch (flag) { case FLAG_CRASH: MVM_crash_on_error(); continue; case FLAG_DUMP: dump = 1; continue; case FLAG_HELP: puts(USAGE); return EXIT_SUCCESS; #if MVM_TRACING case FLAG_TRACING: MVM_interp_enable_tracing(); continue; #endif default: fprintf(stderr, "ERROR: Unknown flag %s.\n\n%s\n", argv[argi], USAGE); return EXIT_FAILURE; } } if (argi >= argc) { fprintf(stderr, "ERROR: Missing input file.\n\n%s\n", USAGE); return EXIT_FAILURE; } instance = MVM_vm_create_instance(); input_file = argv[argi++]; /* stash the rest of the raw command line args in the instance */ instance->num_clargs = argc - argi; instance->raw_clargs = argv + argi; instance->prog_name = input_file; if (dump) MVM_vm_dump_file(instance, input_file); else MVM_vm_run_file(instance, input_file); MVM_vm_destroy_instance(instance); return EXIT_SUCCESS; }
int main(int argc, char *argv[]) { MVMInstance *instance; const char *input_file; const char *executable_name = NULL; const char *lib_path[8]; int dump = 0; int full_cleanup = 0; int argi = 1; int lib_path_i = 0; int flag; for (; (flag = parse_flag(argv[argi])) != NOT_A_FLAG; ++argi) { switch (flag) { case FLAG_CRASH: MVM_crash_on_error(); continue; case FLAG_DUMP: dump = 1; continue; case FLAG_FULL_CLEANUP: full_cleanup = 1; continue; case FLAG_HELP: puts(USAGE); return EXIT_SUCCESS; #if MVM_TRACING case FLAG_TRACING: MVM_interp_enable_tracing(); continue; #endif case OPT_EXECNAME: executable_name = argv[argi] + strlen("--execname="); continue; case OPT_LIBPATH: if (lib_path_i == 7) { /* 0..7 == 8 */ fprintf(stderr, "ERROR: Only up to eight --libpath options are allowed.\n"); return EXIT_FAILURE; } lib_path[lib_path_i++] = argv[argi] + strlen("--libpath="); continue; case FLAG_VERSION: { char *spesh_disable; char *jit_disable; printf("This is MoarVM version %s", MVM_VERSION); if (MVM_jit_support()) { printf(" built with JIT support"); spesh_disable = getenv("MVM_SPESH_DISABLE"); jit_disable = getenv("MVM_JIT_DISABLE"); if (spesh_disable && strlen(spesh_disable) != 0) { printf(" (disabled via MVM_SPESH_DISABLE)"); } else if (jit_disable && strlen(jit_disable) != 0) { printf(" (disabled via MVM_JIT_DISABLE)"); } } printf("\n"); return EXIT_SUCCESS; } default: fprintf(stderr, "ERROR: Unknown flag %s.\n\n%s\n", argv[argi], USAGE); return EXIT_FAILURE; } } lib_path[lib_path_i] = NULL; if (argi >= argc) { fprintf(stderr, "ERROR: Missing input file.\n\n%s\n", USAGE); return EXIT_FAILURE; } instance = MVM_vm_create_instance(); input_file = argv[argi++]; /* stash the rest of the raw command line args in the instance */ MVM_vm_set_clargs(instance, argc - argi, argv + argi); MVM_vm_set_prog_name(instance, input_file); MVM_vm_set_exec_name(instance, executable_name); MVM_vm_set_lib_path(instance, lib_path_i, lib_path); if (dump) MVM_vm_dump_file(instance, input_file); else MVM_vm_run_file(instance, input_file); if (full_cleanup) { MVM_vm_destroy_instance(instance); return EXIT_SUCCESS; } else { MVM_vm_exit(instance); } }