klee
KModule.h
Go to the documentation of this file.
1//===-- KModule.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_KMODULE_H
11#define KLEE_KMODULE_H
12
13#include "klee/Config/Version.h"
15
16#include "llvm/ADT/ArrayRef.h"
17
18#include <map>
19#include <memory>
20#include <set>
21#include <vector>
22
23namespace llvm {
24 class BasicBlock;
25 class Constant;
26 class Function;
27 class Instruction;
28 class Module;
29 class DataLayout;
30}
31
32namespace klee {
33 struct Cell;
34 class Executor;
35 class Expr;
36 class InterpreterHandler;
37 class InstructionInfoTable;
38 struct KInstruction;
39 class KModule;
40 template<class T> class ref;
41
42 struct KFunction {
43 llvm::Function *function;
44
46
49
50 std::map<llvm::BasicBlock*, unsigned> basicBlockEntry;
51
55
56 public:
57 explicit KFunction(llvm::Function*, KModule *);
58 KFunction(const KFunction &) = delete;
59 KFunction &operator=(const KFunction &) = delete;
60
61 ~KFunction();
62
63 unsigned getArgRegister(unsigned index) { return index; }
64 };
65
66
67 class KConstant {
68 public:
70 llvm::Constant* ct;
71
73 unsigned id;
74
78
79 KConstant(llvm::Constant*, unsigned, KInstruction*);
80 };
81
82
83 class KModule {
84 public:
85 std::unique_ptr<llvm::Module> module;
86 std::unique_ptr<llvm::DataLayout> targetData;
87
88 // Our shadow versions of LLVM structures.
89 std::vector<std::unique_ptr<KFunction>> functions;
90 std::map<llvm::Function*, KFunction*> functionMap;
91
92 // Functions which escape (may be called indirectly)
93 // XXX change to KFunction
94 std::set<llvm::Function*> escapingFunctions;
95
96 std::unique_ptr<InstructionInfoTable> infos;
97
98 std::vector<llvm::Constant*> constants;
99 std::map<const llvm::Constant *, std::unique_ptr<KConstant>> constantMap;
100 KConstant* getKConstant(const llvm::Constant *c);
101
102 std::unique_ptr<Cell[]> constantTable;
103
104 // Functions which are part of KLEE runtime
105 std::set<const llvm::Function*> internalFunctions;
106
107 private:
108 // Mark function with functionName as part of the KLEE runtime
109 void addInternalFunction(const char* functionName);
110
111 public:
112 KModule() = default;
113
115 //
117 llvm::ArrayRef<const char *>);
118
125 // FIXME: ihandler should not be here
126 void manifest(InterpreterHandler *ih, bool forceSourceOutput);
127
139 bool link(std::vector<std::unique_ptr<llvm::Module>> &modules,
140 const std::string &entryPoint);
141
142 void instrument(const Interpreter::ModuleOptions &opts);
143
145 unsigned getConstantID(llvm::Constant *c, KInstruction* ki);
146
149 void checkModule();
150 };
151} // End klee namespace
152
153#endif /* KLEE_KMODULE_H */
#define Expr
Definition: STPBuilder.h:19
KInstruction * ki
Definition: KModule.h:77
KConstant(llvm::Constant *, unsigned, KInstruction *)
Definition: KModule.cpp:398
unsigned id
The constant ID.
Definition: KModule.h:73
llvm::Constant * ct
Actual LLVM constant this represents.
Definition: KModule.h:70
void checkModule()
Definition: KModule.cpp:360
unsigned getConstantID(llvm::Constant *c, KInstruction *ki)
Return an id for the given constant, creating a new one if necessary.
Definition: KModule.cpp:385
KModule()=default
void optimiseAndPrepare(const Interpreter::ModuleOptions &opts, llvm::ArrayRef< const char * >)
Optimise and prepare module such that KLEE can execute it.
Definition: KModule.cpp:252
void addInternalFunction(const char *functionName)
Definition: KModule.cpp:199
KConstant * getKConstant(const llvm::Constant *c)
Definition: KModule.cpp:378
std::map< const llvm::Constant *, std::unique_ptr< KConstant > > constantMap
Definition: KModule.h:99
void instrument(const Interpreter::ModuleOptions &opts)
Definition: KModule.cpp:227
void manifest(InterpreterHandler *ih, bool forceSourceOutput)
Definition: KModule.cpp:297
bool link(std::vector< std::unique_ptr< llvm::Module > > &modules, const std::string &entryPoint)
Definition: KModule.cpp:210
std::set< const llvm::Function * > internalFunctions
Definition: KModule.h:105
std::unique_ptr< llvm::DataLayout > targetData
Definition: KModule.h:86
std::unique_ptr< InstructionInfoTable > infos
Definition: KModule.h:96
std::set< llvm::Function * > escapingFunctions
Definition: KModule.h:94
std::vector< std::unique_ptr< KFunction > > functions
Definition: KModule.h:89
std::vector< llvm::Constant * > constants
Definition: KModule.h:98
std::unique_ptr< llvm::Module > module
Definition: KModule.h:85
std::unique_ptr< Cell[]> constantTable
Definition: KModule.h:102
std::map< llvm::Function *, KFunction * > functionMap
Definition: KModule.h:90
Definition: main.cpp:291
unsigned getArgRegister(unsigned index)
Definition: KModule.h:63
std::map< llvm::BasicBlock *, unsigned > basicBlockEntry
Definition: KModule.h:50
llvm::Function * function
Definition: KModule.h:43
unsigned numArgs
Definition: KModule.h:45
bool trackCoverage
Definition: KModule.h:54
unsigned numRegisters
Definition: KModule.h:45
KInstruction ** instructions
Definition: KModule.h:48
KFunction(const KFunction &)=delete
unsigned numInstructions
Definition: KModule.h:47
KFunction & operator=(const KFunction &)=delete
KFunction(llvm::Function *, KModule *)
Definition: KModule.cpp:424