+static void parse_options(struct model_params *params, int argc, char **argv)
+{
+ const char *shortopts = "hyYt:o:m:M:s:S:f:e:b:u:v::";
+ const struct option longopts[] = {
+ {"help", no_argument, NULL, 'h'},
+ {"liveness", required_argument, NULL, 'm'},
+ {"maxfv", required_argument, NULL, 'M'},
+ {"maxfvdelay", required_argument, NULL, 's'},
+ {"fvslop", required_argument, NULL, 'S'},
+ {"fairness", required_argument, NULL, 'f'},
+ {"yield", no_argument, NULL, 'y'},
+ {"yieldblock", no_argument, NULL, 'Y'},
+ {"enabled", required_argument, NULL, 'e'},
+ {"bound", required_argument, NULL, 'b'},
+ {"verbose", optional_argument, NULL, 'v'},
+ {"uninitialized", optional_argument, NULL, 'u'},
+ {"analysis", optional_argument, NULL, 't'},
+ {"options", optional_argument, NULL, 'o'},
+ {0, 0, 0, 0} /* Terminator */
+ };
+ int opt, longindex;
+ bool error = false;
+ while (!error && (opt = getopt_long(argc, argv, shortopts, longopts, &longindex)) != -1) {
+ switch (opt) {
+ case 'h':
+ print_usage(argv[0], params);
+ break;
+ case 's':
+ params->maxfuturedelay = atoi(optarg);
+ break;
+ case 'S':
+ params->expireslop = atoi(optarg);
+ break;
+ case 'f':
+ params->fairwindow = atoi(optarg);
+ break;
+ case 'e':
+ params->enabledcount = atoi(optarg);
+ break;
+ case 'b':
+ params->bound = atoi(optarg);
+ break;
+ case 'm':
+ params->maxreads = atoi(optarg);
+ break;
+ case 'M':
+ params->maxfuturevalues = atoi(optarg);
+ break;
+ case 'v':
+ params->verbose = optarg ? atoi(optarg) : 1;
+ break;
+ case 'u':
+ params->uninitvalue = atoi(optarg);
+ break;
+ case 'y':
+ params->yieldon = true;
+ break;
+ case 't':
+ if (install_plugin(optarg))
+ error = true;
+ break;
+ case 'o':
+ {
+ ModelVector<TraceAnalysis *> * analyses = getInstalledTraceAnalysis();
+ if ( analyses->size() == 0 || (*analyses)[analyses->size()-1]->option(optarg))
+ error = true;
+ }
+ break;
+ case 'Y':
+ params->yieldblock = true;
+ break;
+ default: /* '?' */
+ error = true;
+ break;
+ }
+ }
+
+ /* 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)
+ print_usage(argv[0], params);
+}
+
+int main_argc;
+char **main_argv;
+
+static void install_trace_analyses(ModelExecution *execution)
+{
+ ModelVector<TraceAnalysis *> * installedanalysis=getInstalledTraceAnalysis();
+ for(unsigned int i=0;i<installedanalysis->size();i++) {
+ TraceAnalysis * ta=(*installedanalysis)[i];
+ ta->setExecution(execution);
+ model->add_trace_analysis(ta);
+ }
+}
+
+/** The model_main function contains the main model checking loop. */
+static void model_main()
+{
+ struct model_params params;
+
+ param_defaults(¶ms);
+ register_plugins();
+
+ parse_options(¶ms, main_argc, main_argv);
+
+ //Initialize race detector
+ initRaceDetector();
+
+ snapshot_stack_init();
+
+ model = new ModelChecker(params);
+ install_trace_analyses(model->get_execution());
+
+ snapshot_record(0);
+ model->run();