#include #include #include #include #include #include "fault.h" #include "sim.h" static void help(void) { printf("usage: msim [options] executable\n\n"); printf("options:\n"); printf("\t-h\t\tprints this help messaage\n"); printf("\t-c\t\tdisable runtime memory checks (allows segfault)\n"); printf("\t-d\t\truns the debugger\n"); } int main(int argc, char **argv) { struct simulator sim; struct simulator_args args = { .executable = NULL, .debug = false, .memchk = true, }; int c; while ((c = getopt(argc, argv, "hcd")) != 1) { switch (c) { case 'h': help(); return M_SUCCESS; case 'c': args.memchk = false; break; case 'd': args.debug = true; break; case '?': return M_ERROR; default: goto next; } } next: if (optind < argc - 1) { ERROR("too many executables passed"); return M_ERROR; } if (optind >= argc) { ERROR("no executable passed"); return M_ERROR; } /// set file name args.executable = argv[optind]; /// create handlers init_handlers(&sim); /// init if (sim_init(&sim, &args)) return M_ERROR; /* _Noreturn */ if (args.debug) sim_debug(&sim); else sim_run(&sim); }