model: remove redundant code (is_enabled)
[model-checker.git] / model.cc
index 48fa28acb71cf1b8d49112df717d2ac460dc2e9b..5625f30ca8b637e362ebe49203394e52fe9d9e11 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -16,8 +16,6 @@
 #include "execution.h"
 #include "bugmessage.h"
 
-#define INITIAL_THREAD_ID      0
-
 ModelChecker *model;
 
 /** @brief Constructor */
@@ -26,7 +24,8 @@ ModelChecker::ModelChecker(struct model_params params) :
        params(params),
        scheduler(new Scheduler()),
        node_stack(new NodeStack()),
-       execution(new ModelExecution(&params, scheduler, node_stack)),
+       execution(new ModelExecution(this, &this->params, scheduler, node_stack)),
+       execution_number(1),
        diverge(NULL),
        earliest_diverge(NULL),
        trace_analyses()
@@ -37,8 +36,6 @@ ModelChecker::ModelChecker(struct model_params params) :
 ModelChecker::~ModelChecker()
 {
        delete node_stack;
-       for (unsigned int i = 0; i < trace_analyses.size(); i++)
-               delete trace_analyses[i];
        delete scheduler;
 }
 
@@ -200,15 +197,13 @@ void ModelChecker::assert_user_bug(const char *msg)
 /** @brief Print bug report listing for this execution (if any bugs exist) */
 void ModelChecker::print_bugs() const
 {
-       if (execution->have_bug_reports()) {
-               SnapVector<bug_message *> *bugs = execution->get_bugs();
-
-               model_print("Bug report: %zu bug%s detected\n",
-                               bugs->size(),
-                               bugs->size() > 1 ? "s" : "");
-               for (unsigned int i = 0; i < bugs->size(); i++)
-                       (*bugs)[i]->print();
-       }
+       SnapVector<bug_message *> *bugs = execution->get_bugs();
+
+       model_print("Bug report: %zu bug%s detected\n",
+                       bugs->size(),
+                       bugs->size() > 1 ? "s" : "");
+       for (unsigned int i = 0; i < bugs->size(); i++)
+               (*bugs)[i]->print();
 }
 
 /**
@@ -255,10 +250,12 @@ void ModelChecker::print_stats() const
  */
 void ModelChecker::print_execution(bool printbugs) const
 {
+       model_print("Program output from execution %d:\n",
+                       get_execution_number());
        print_program_output();
 
-       if (params.verbose) {
-               model_print("Earliest divergence point since last feasible execution:\n");
+       if (params.verbose >= 2) {
+               model_print("\nEarliest divergence point since last feasible execution:\n");
                if (earliest_diverge)
                        earliest_diverge->print();
                else
@@ -269,8 +266,10 @@ void ModelChecker::print_execution(bool printbugs) const
        }
 
        /* Don't print invalid bugs */
-       if (printbugs)
+       if (printbugs && execution->have_bug_reports()) {
+               model_print("\n");
                print_bugs();
+       }
 
        model_print("\n");
        execution->print_summary();
@@ -319,7 +318,8 @@ bool ModelChecker::next_execution()
                diverge->print();
        }
 
-       execution->increment_execution_number();
+       execution_number++;
+
        reset_to_initial_state();
        return true;
 }
@@ -350,26 +350,6 @@ Thread * ModelChecker::get_thread(const ModelAction *act) const
        return execution->get_thread(act);
 }
 
-/**
- * @brief Check if a Thread is currently enabled
- * @param t The Thread to check
- * @return True if the Thread is currently enabled
- */
-bool ModelChecker::is_enabled(Thread *t) const
-{
-       return scheduler->is_enabled(t);
-}
-
-/**
- * @brief Check if a Thread is currently enabled
- * @param tid The ID of the Thread to check
- * @return True if the Thread is currently enabled
- */
-bool ModelChecker::is_enabled(thread_id_t tid) const
-{
-       return scheduler->is_enabled(tid);
-}
-
 /**
  * Switch from a model-checker context to a user-thread context. This is the
  * complement of ModelChecker::switch_to_master and must be called from the
@@ -444,7 +424,7 @@ void ModelChecker::run()
                         * thread which just took a step--plus the first step
                         * for any newly-created thread
                         */
-                       for (unsigned int i = 0; i < execution->get_num_threads(); i++) {
+                       for (unsigned int i = 0; i < get_num_threads(); i++) {
                                thread_id_t tid = int_to_id(i);
                                Thread *thr = get_thread(tid);
                                if (!thr->is_model_thread() && !thr->is_complete() && !thr->get_pending()) {
@@ -458,7 +438,7 @@ void ModelChecker::run()
                        for (unsigned int i = 0; i < get_num_threads(); i++) {
                                Thread *th = get_thread(int_to_id(i));
                                ModelAction *act = th->get_pending();
-                               if (act && is_enabled(th) && !execution->check_action_enabled(act)) {
+                               if (act && execution->is_enabled(th) && !execution->check_action_enabled(act)) {
                                        scheduler->sleep(th);
                                }
                        }
@@ -485,4 +465,8 @@ void ModelChecker::run()
 
        model_print("******* Model-checking complete: *******\n");
        print_stats();
+
+       /* Have the trace analyses dump their output. */
+       for (unsigned int i = 0; i < trace_analyses.size(); i++)
+               trace_analyses[i]->finish();
 }