Merge branch 'markdown'
[cdsspec-compiler.git] / model.cc
index 55949730f5c2a00428618dd8cfbe8bf65c96747f..16d5db4ab280262d1c4439de6544a413f8ba794e 100644 (file)
--- a/model.cc
+++ b/model.cc
@@ -1,6 +1,5 @@
 #include <stdio.h>
 #include <algorithm>
-#include <mutex>
 #include <new>
 #include <stdarg.h>
 
@@ -17,8 +16,6 @@
 #include "execution.h"
 #include "bugmessage.h"
 
-#define INITIAL_THREAD_ID      0
-
 ModelChecker *model;
 
 /** @brief Constructor */
@@ -27,10 +24,11 @@ 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(new ModelVector<TraceAnalysis *>())
+       trace_analyses()
 {
 }
 
@@ -38,9 +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 trace_analyses;
        delete scheduler;
 }
 
@@ -202,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();
 }
 
 /**
@@ -257,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
@@ -271,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();
@@ -321,15 +318,16 @@ bool ModelChecker::next_execution()
                diverge->print();
        }
 
-       execution->increment_execution_number();
+       execution_number++;
+
        reset_to_initial_state();
        return true;
 }
 
 /** @brief Run trace analyses on complete trace */
 void ModelChecker::run_trace_analyses() {
-       for (unsigned int i = 0; i < trace_analyses->size(); i++)
-               (*trace_analyses)[i]->analyze(execution->get_action_trace());
+       for (unsigned int i = 0; i < trace_analyses.size(); i++)
+               trace_analyses[i]->analyze(execution->get_action_trace());
 }
 
 /**
@@ -436,7 +434,7 @@ void ModelChecker::run()
 {
        do {
                thrd_t user_thread;
-               Thread *t = new Thread(&user_thread, &user_main_wrapper, NULL, NULL);
+               Thread *t = new Thread(execution->get_next_id(), &user_thread, &user_main_wrapper, NULL, NULL);
                execution->add_thread(t);
 
                do {
@@ -446,7 +444,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()) {
@@ -487,4 +485,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();
 }