X-Git-Url: http://plrg.eecs.uci.edu/git/?p=c11tester.git;a=blobdiff_plain;f=main.cc;h=dc3f6f4dca002d6e763e5bbf25068260d3edc828;hp=f6ab259a64bb1ddfe85ec092518fdb091f23849a;hb=25728e9ac2afc0ecfb23259a6cee27a309027f4f;hpb=d6aa3d792529d617999cf63ae68463c9c6be0fa1 diff --git a/main.cc b/main.cc index f6ab259a..dc3f6f4d 100644 --- a/main.cc +++ b/main.cc @@ -4,9 +4,7 @@ #include -#include #include "common.h" -#include "threads-model.h" #include "output.h" #include "datarace.h" @@ -15,7 +13,8 @@ #include "model.h" #include "snapshot-interface.h" -static void param_defaults(struct model_params * params) { +static void param_defaults(struct model_params *params) +{ params->maxreads = 0; params->maxfuturedelay = 100; params->fairwindow = 0; @@ -26,7 +25,8 @@ static void param_defaults(struct model_params * params) { params->verbose = 0; } -static void print_usage(struct model_params *params) { +static void print_usage(struct model_params *params) +{ /* Reset defaults before printing */ param_defaults(params); @@ -54,11 +54,12 @@ params->maxreads, params->maxfuturevalues, params->maxfuturedelay, params->expir exit(EXIT_SUCCESS); } -static void parse_options(struct model_params *params, int *argc, char ***argv) { +static void parse_options(struct model_params *params, int argc, char **argv) +{ const char *shortopts = "hm:M:s:S:f:e:b:v"; int opt; bool error = false; - while (!error && (opt = getopt(*argc, *argv, shortopts)) != -1) { + while (!error && (opt = getopt(argc, argv, shortopts)) != -1) { switch (opt) { case 'h': print_usage(params); @@ -92,9 +93,15 @@ static void parse_options(struct model_params *params, int *argc, char ***argv) break; } } - (*argv)[optind - 1] = (*argv)[0]; - (*argc) -= (optind - 1); - (*argv) += (optind - 1); + + /* Pass remaining arguments to user program */ + params->argc = argc - (optind - 1); + params->argv = argv + (optind - 1); + + /* Reset program name */ + params->argv[0] = argv[0]; + + /* Reset (global) optind for potential use by user program */ optind = 1; if (error) @@ -104,40 +111,23 @@ static void parse_options(struct model_params *params, int *argc, char ***argv) int main_argc; char **main_argv; -/** Wrapper to run the user's main function, with appropriate arguments */ -void wrapper_user_main(void *) -{ - user_main(main_argc, main_argv); -} - /** The model_main function contains the main model checking loop. */ -static void model_main() { - thrd_t user_thread; +static void model_main() +{ struct model_params params; param_defaults(¶ms); - parse_options(¶ms, &main_argc, &main_argv); + parse_options(¶ms, main_argc, main_argv); //Initialize race detector initRaceDetector(); - //Create the singleton SnapshotStack object - snapshotObject = new SnapshotStack(); + snapshot_stack_init(); model = new ModelChecker(params); - - snapshotObject->snapshotStep(0); - do { - /* Start user program */ - model->add_thread(new Thread(&user_thread, &wrapper_user_main, NULL)); - - /* Wait for all threads to complete */ - model->finish_execution(); - } while (model->next_execution()); - - model->print_stats(); - + snapshot_record(0); + model->run(); delete model; DEBUG("Exiting\n"); @@ -147,7 +137,8 @@ static void model_main() { * Main function. Just initializes snapshotting library and the * snapshotting library calls the model_main function. */ -int main(int argc, char ** argv) { +int main(int argc, char **argv) +{ main_argc = argc; main_argv = argv; @@ -155,5 +146,5 @@ int main(int argc, char ** argv) { redirect_output(); /* Let's jump in quickly and start running stuff */ - initSnapshotLibrary(10000, 1024, 1024, 4000, &model_main); + snapshot_system_init(10000, 1024, 1024, 4000, &model_main); }