klee
Interpreter.h
Go to the documentation of this file.
1//===-- Interpreter.h - Abstract Execution Engine Interface -----*- 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#ifndef KLEE_INTERPRETER_H
10#define KLEE_INTERPRETER_H
11
12#include <map>
13#include <memory>
14#include <set>
15#include <string>
16#include <vector>
17
18struct KTest;
19
20namespace llvm {
21class Function;
22class LLVMContext;
23class Module;
24class raw_ostream;
25class raw_fd_ostream;
26}
27
28namespace klee {
29class ExecutionState;
30class Interpreter;
31class TreeStreamWriter;
32
34public:
37
38 virtual llvm::raw_ostream &getInfoStream() const = 0;
39
40 virtual std::string getOutputFilename(const std::string &filename) = 0;
41 virtual std::unique_ptr<llvm::raw_fd_ostream> openOutputFile(const std::string &filename) = 0;
42
43 virtual void incPathsCompleted() = 0;
44 virtual void incPathsExplored(std::uint32_t num = 1) = 0;
45
46 virtual void processTestCase(const ExecutionState &state,
47 const char *err,
48 const char *suffix) = 0;
49};
50
52public:
56 std::string LibraryDir;
57 std::string EntryPoint;
58 std::string OptSuffix;
62
63 ModuleOptions(const std::string &_LibraryDir,
64 const std::string &_EntryPoint, const std::string &_OptSuffix,
65 bool _Optimize, bool _CheckDivZero, bool _CheckOvershift)
66 : LibraryDir(_LibraryDir), EntryPoint(_EntryPoint),
67 OptSuffix(_OptSuffix), Optimize(_Optimize),
68 CheckDivZero(_CheckDivZero), CheckOvershift(_CheckOvershift) {}
69 };
70
72 {
73 STP, //.CVC (STP's native language)
74 KQUERY, //.KQUERY files (kQuery native language)
75 SMTLIB2 //.SMT2 files (SMTLIB version 2 files)
76 };
77
85
88 {}
89 };
90
91protected:
93
94 Interpreter(const InterpreterOptions &_interpreterOpts)
95 : interpreterOpts(_interpreterOpts)
96 {}
97
98public:
99 virtual ~Interpreter() {}
100
101 static Interpreter *create(llvm::LLVMContext &ctx,
102 const InterpreterOptions &_interpreterOpts,
104
110 virtual llvm::Module *
111 setModule(std::vector<std::unique_ptr<llvm::Module>> &modules,
112 const ModuleOptions &opts) = 0;
113
114 // supply a tree stream writer which the interpreter will use
115 // to record the concrete path (as a stream of '0' and '1' bytes).
116 virtual void setPathWriter(TreeStreamWriter *tsw) = 0;
117
118 // supply a tree stream writer which the interpreter will use
119 // to record the symbolic path (as a stream of '0' and '1' bytes).
121
122 // supply a test case to replay from. this can be used to drive the
123 // interpretation down a user specified path. use null to reset.
124 virtual void setReplayKTest(const struct KTest *out) = 0;
125
126 // supply a list of branch decisions specifying which direction to
127 // take on forks. this can be used to drive the interpretation down
128 // a user specified path. use null to reset.
129 virtual void setReplayPath(const std::vector<bool> *path) = 0;
130
131 // supply a set of symbolic bindings that will be used as "seeds"
132 // for the search. use null to reset.
133 virtual void useSeeds(const std::vector<struct KTest *> *seeds) = 0;
134
135 virtual void runFunctionAsMain(llvm::Function *f,
136 int argc,
137 char **argv,
138 char **envp) = 0;
139
140 /*** Runtime options ***/
141
142 virtual void setHaltExecution(bool value) = 0;
143
144 virtual void setInhibitForking(bool value) = 0;
145
146 virtual void prepareForEarlyExit() = 0;
147
148 /*** State accessor methods ***/
149
150 virtual unsigned getPathStreamID(const ExecutionState &state) = 0;
151
152 virtual unsigned getSymbolicPathStreamID(const ExecutionState &state) = 0;
153
154 virtual void getConstraintLog(const ExecutionState &state,
155 std::string &res,
156 LogType logFormat = STP) = 0;
157
158 virtual bool getSymbolicSolution(const ExecutionState &state,
159 std::vector<
160 std::pair<std::string,
161 std::vector<unsigned char> > >
162 &res) = 0;
163
164 virtual void getCoveredLines(const ExecutionState &state,
165 std::map<const std::string*, std::set<unsigned> > &res) = 0;
166};
167
168} // End klee namespace
169
170#endif /* KLEE_INTERPRETER_H */
ExecutionState representing a path under exploration.
virtual ~InterpreterHandler()
Definition: Interpreter.h:36
virtual std::string getOutputFilename(const std::string &filename)=0
virtual void incPathsExplored(std::uint32_t num=1)=0
virtual llvm::raw_ostream & getInfoStream() const =0
virtual std::unique_ptr< llvm::raw_fd_ostream > openOutputFile(const std::string &filename)=0
virtual void processTestCase(const ExecutionState &state, const char *err, const char *suffix)=0
virtual void incPathsCompleted()=0
virtual void setReplayKTest(const struct KTest *out)=0
virtual void setSymbolicPathWriter(TreeStreamWriter *tsw)=0
virtual void prepareForEarlyExit()=0
virtual ~Interpreter()
Definition: Interpreter.h:99
virtual void getCoveredLines(const ExecutionState &state, std::map< const std::string *, std::set< unsigned > > &res)=0
virtual void runFunctionAsMain(llvm::Function *f, int argc, char **argv, char **envp)=0
virtual llvm::Module * setModule(std::vector< std::unique_ptr< llvm::Module > > &modules, const ModuleOptions &opts)=0
const InterpreterOptions interpreterOpts
Definition: Interpreter.h:92
static Interpreter * create(llvm::LLVMContext &ctx, const InterpreterOptions &_interpreterOpts, InterpreterHandler *ih)
Definition: Executor.cpp:4738
Interpreter(const InterpreterOptions &_interpreterOpts)
Definition: Interpreter.h:94
virtual void setHaltExecution(bool value)=0
virtual unsigned getPathStreamID(const ExecutionState &state)=0
virtual void setReplayPath(const std::vector< bool > *path)=0
virtual void setInhibitForking(bool value)=0
virtual void setPathWriter(TreeStreamWriter *tsw)=0
virtual void getConstraintLog(const ExecutionState &state, std::string &res, LogType logFormat=STP)=0
virtual unsigned getSymbolicPathStreamID(const ExecutionState &state)=0
virtual bool getSymbolicSolution(const ExecutionState &state, std::vector< std::pair< std::string, std::vector< unsigned char > > > &res)=0
virtual void useSeeds(const std::vector< struct KTest * > *seeds)=0
int const char const char * suffix
Definition: klee.h:76
Definition: main.cpp:291
Definition: KTest.h:25
ModuleOptions(const std::string &_LibraryDir, const std::string &_EntryPoint, const std::string &_OptSuffix, bool _Optimize, bool _CheckDivZero, bool _CheckOvershift)
Definition: Interpreter.h:63