about summary refs log tree commit diff homepage
path: root/lib/Solver/ConstructSolverChain.cpp
blob: 9109fe1d2e0f164e653f437db19ff6347ac857a4 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
//===-- ConstructSolverChain.cpp ------------------------------------++ -*-===//
//
//                     The KLEE Symbolic Virtual Machine
//
// This file is distributed under the University of Illinois Open Source
// License. See LICENSE.TXT for details.
//
//===----------------------------------------------------------------------===//

/*
 * This file groups declarations that are common to both KLEE and Kleaver.
 */

#include "klee/Solver/Common.h"
#include "klee/Solver/SolverCmdLine.h"
#include "klee/Support/ErrorHandling.h"
#include "klee/System/Time.h"

#include "llvm/Support/raw_ostream.h"

#include <memory>
#include <utility>

namespace klee {
std::unique_ptr<Solver> constructSolverChain(
    std::unique_ptr<Solver> coreSolver, std::string querySMT2LogPath,
    std::string baseSolverQuerySMT2LogPath, std::string queryKQueryLogPath,
    std::string baseSolverQueryKQueryLogPath) {
  Solver *rawCoreSolver = coreSolver.get();
  std::unique_ptr<Solver> solver = std::move(coreSolver);
  const time::Span minQueryTimeToLog(MinQueryTimeToLog);

  if (QueryLoggingOptions.isSet(SOLVER_KQUERY)) {
    solver = createKQueryLoggingSolver(std::move(solver),
                                       baseSolverQueryKQueryLogPath,
                                       minQueryTimeToLog, LogTimedOutQueries);
    klee_message("Logging queries that reach solver in .kquery format to %s\n",
                 baseSolverQueryKQueryLogPath.c_str());
  }

  if (QueryLoggingOptions.isSet(SOLVER_SMTLIB)) {
    solver =
        createSMTLIBLoggingSolver(std::move(solver), baseSolverQuerySMT2LogPath,
                                  minQueryTimeToLog, LogTimedOutQueries);
    klee_message("Logging queries that reach solver in .smt2 format to %s\n",
                 baseSolverQuerySMT2LogPath.c_str());
  }

  if (UseAssignmentValidatingSolver)
    solver = createAssignmentValidatingSolver(std::move(solver));

  if (UseFastCexSolver)
    solver = createFastCexSolver(std::move(solver));

  if (UseCexCache)
    solver = createCexCachingSolver(std::move(solver));

  if (UseBranchCache)
    solver = createCachingSolver(std::move(solver));

  if (UseIndependentSolver)
    solver = createIndependentSolver(std::move(solver));

  if (DebugValidateSolver)
    solver = createValidatingSolver(std::move(solver), rawCoreSolver, false);

  if (QueryLoggingOptions.isSet(ALL_KQUERY)) {
    solver = createKQueryLoggingSolver(std::move(solver), queryKQueryLogPath,
                                       minQueryTimeToLog, LogTimedOutQueries);
    klee_message("Logging all queries in .kquery format to %s\n",
                 queryKQueryLogPath.c_str());
  }

  if (QueryLoggingOptions.isSet(ALL_SMTLIB)) {
    solver = createSMTLIBLoggingSolver(std::move(solver), querySMT2LogPath,
                                       minQueryTimeToLog, LogTimedOutQueries);
    klee_message("Logging all queries in .smt2 format to %s\n",
                 querySMT2LogPath.c_str());
  }
  if (DebugCrossCheckCoreSolverWith != NO_SOLVER) {
    std::unique_ptr<Solver> oracleSolver =
        createCoreSolver(DebugCrossCheckCoreSolverWith);
    solver =
        createValidatingSolver(std::move(solver), oracleSolver.release(), true);
  }

  return solver;
}
} // namespace klee