klee
Solver.h
Go to the documentation of this file.
1//===-- Solver.h ------------------------------------------------*- C++ -*-===//
2//
3// The KLEE Symbolic Virtual Machine
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef KLEE_SOLVER_H
11#define KLEE_SOLVER_H
12
13#include "klee/Expr/Expr.h"
14#include "klee/System/Time.h"
16
17#include <vector>
18
19namespace klee {
20 class ConstraintSet;
21 class Expr;
22 class SolverImpl;
23
30 };
31
32 struct Query {
33 public:
36
37 Query(const ConstraintSet& _constraints, ref<Expr> _expr)
38 : constraints(_constraints), expr(_expr) {
39 }
40
42 Query withExpr(ref<Expr> _expr) const {
43 return Query(constraints, _expr);
44 }
45
47 Query withFalse() const {
49 }
50
52 Query negateExpr() const {
54 }
55
57 void dump() const ;
58 };
59
60 class Solver {
61 // DO NOT IMPLEMENT.
62 Solver(const Solver&);
63 void operator=(const Solver&);
64
65 public:
66 enum Validity {
67 True = 1,
68 False = -1,
69 Unknown = 0
70 };
71
72 public:
74 static const char *validity_to_str(Validity v);
75
76 public:
78
79 public:
80 Solver(SolverImpl *_impl) : impl(_impl) {}
81 virtual ~Solver();
82
96 bool evaluate(const Query&, Validity &result);
97
114 bool mustBeTrue(const Query&, bool &result);
115
132 bool mustBeFalse(const Query&, bool &result);
133
151 bool mayBeTrue(const Query&, bool &result);
152
170 bool mayBeFalse(const Query&, bool &result);
171
178 bool getValue(const Query&, ref<ConstantExpr> &result);
179
191 //
192 // FIXME: This API is lame. We should probably just provide an API which
193 // returns an Assignment object, then clients can get out whatever values
194 // they want. This also allows us to optimize the representation.
195 bool getInitialValues(const Query&,
196 const std::vector<const Array*> &objects,
197 std::vector< std::vector<unsigned char> > &result);
198
207 //
208 // FIXME: This should go into a helper class, and should handle failure.
209 virtual std::pair< ref<Expr>, ref<Expr> > getRange(const Query&);
210
211 virtual char *getConstraintLog(const Query& query);
212 virtual void setCoreSolverTimeout(time::Span timeout);
213 };
214
215 /* *** */
216
224 Solver *createValidatingSolver(Solver *s, Solver *oracle);
225
230 Solver *createAssignmentValidatingSolver(Solver *s);
231
236 Solver *createCachingSolver(Solver *s);
237
244 Solver *createCexCachingSolver(Solver *s);
245
251 Solver *createFastCexSolver(Solver *s);
252
258 Solver *createIndependentSolver(Solver *s);
259
262 Solver *createKQueryLoggingSolver(Solver *s, std::string path,
263 time::Span minQueryTimeToLog,
264 bool logTimedOut);
265
268 Solver *createSMTLIBLoggingSolver(Solver *s, std::string path,
269 time::Span minQueryTimeToLog,
270 bool logTimedOut);
271
272
275 Solver *createDummySolver();
276
277 // Create a solver based on the supplied ``CoreSolverType``.
278 Solver *createCoreSolver(CoreSolverType cst);
279}
280
281#endif /* KLEE_SOLVER_H */
#define Expr
Definition: STPBuilder.h:19
static ref< ConstantExpr > alloc(const llvm::APInt &v)
Definition: Expr.h:1065
static ref< Expr > createIsZero(ref< Expr > e)
Definition: Expr.cpp:322
static const Width Bool
Definition: Expr.h:100
SolverImpl - Abstract base clase for solver implementations.
Definition: SolverImpl.h:25
bool evaluate(const Query &, Validity &result)
Definition: Solver.cpp:37
bool mayBeTrue(const Query &, bool &result)
Definition: Solver.cpp:65
Solver(const Solver &)
bool mustBeTrue(const Query &, bool &result)
Definition: Solver.cpp:49
bool getValue(const Query &, ref< ConstantExpr > &result)
Definition: Solver.cpp:81
static const char * validity_to_str(Validity v)
validity_to_str - Return the name of given Validity enum value.
Definition: Solver.cpp:17
SolverImpl * impl
Definition: Solver.h:77
bool mayBeFalse(const Query &, bool &result)
Definition: Solver.cpp:73
bool getInitialValues(const Query &, const std::vector< const Array * > &objects, std::vector< std::vector< unsigned char > > &result)
Definition: Solver.cpp:98
bool mustBeFalse(const Query &, bool &result)
Definition: Solver.cpp:61
virtual ~Solver()
Definition: Solver.cpp:25
virtual void setCoreSolverTimeout(time::Span timeout)
Definition: Solver.cpp:33
virtual std::pair< ref< Expr >, ref< Expr > > getRange(const Query &)
Definition: Solver.cpp:111
void operator=(const Solver &)
virtual char * getConstraintLog(const Query &query)
Definition: Solver.cpp:29
Solver(SolverImpl *_impl)
Definition: Solver.h:80
Definition: main.cpp:291
Solver * createCachingSolver(Solver *s)
Solver * createValidatingSolver(Solver *s, Solver *oracle)
Solver * createKQueryLoggingSolver(Solver *s, std::string path, time::Span minQueryTimeToLog, bool logTimedOut)
Solver * createDummySolver()
Definition: DummySolver.cpp:62
Solver * createAssignmentValidatingSolver(Solver *s)
Solver * createCexCachingSolver(Solver *s)
Solver * createFastCexSolver(Solver *s)
Solver * createCoreSolver(CoreSolverType cst)
Definition: CoreSolver.cpp:25
CoreSolverType
Definition: SolverCmdLine.h:57
Solver * createIndependentSolver(Solver *s)
Solver * createSMTLIBLoggingSolver(Solver *s, std::string path, time::Span minQueryTimeToLog, bool logTimedOut)
ref< Expr > expr
Definition: Solver.h:35
Query withExpr(ref< Expr > _expr) const
withExpr - Return a copy of the query with the given expression.
Definition: Solver.h:42
Query(const ConstraintSet &_constraints, ref< Expr > _expr)
Definition: Solver.h:37
const ConstraintSet & constraints
Definition: Solver.h:34
void dump() const
Dump query.
Definition: Solver.cpp:224
Query withFalse() const
withFalse - Return a copy of the query with a false expression.
Definition: Solver.h:47
Query negateExpr() const
negateExpr - Return a copy of the query with the expression negated.
Definition: Solver.h:52
time::Span queryCost
Costs for all queries issued for this state.
Definition: Solver.h:29