klee
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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"
14 #include "klee/Interpreter.h"
15 
16 #include <map>
17 #include <set>
18 #include <vector>
19 
20 namespace llvm {
21  class BasicBlock;
22  class Constant;
23  class Function;
24  class Instruction;
25  class Module;
26 #if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1)
27  class TargetData;
28 #else
29  class DataLayout;
30 #endif
31 }
32 
33 namespace klee {
34  struct Cell;
35  class Executor;
36  class Expr;
37  class InterpreterHandler;
38  class InstructionInfoTable;
39  struct KInstruction;
40  class KModule;
41  template<class T> class ref;
42 
43  struct KFunction {
44  llvm::Function *function;
45 
46  unsigned numArgs, numRegisters;
47 
48  unsigned numInstructions;
50 
51  std::map<llvm::BasicBlock*, unsigned> basicBlockEntry;
52 
56 
57  private:
58  KFunction(const KFunction&);
59  KFunction &operator=(const KFunction&);
60 
61  public:
62  explicit KFunction(llvm::Function*, KModule *);
63  ~KFunction();
64 
65  unsigned getArgRegister(unsigned index) { return index; }
66  };
67 
68 
69  class KConstant {
70  public:
72  llvm::Constant* ct;
73 
75  unsigned id;
76 
80 
81  KConstant(llvm::Constant*, unsigned, KInstruction*);
82  };
83 
84 
85  class KModule {
86  public:
87  llvm::Module *module;
88 #if LLVM_VERSION_CODE <= LLVM_VERSION(3, 1)
89  llvm::TargetData *targetData;
90 #else
91  llvm::DataLayout *targetData;
92 #endif
93 
94  // Some useful functions to know the address of
95  llvm::Function *dbgStopPointFn, *kleeMergeFn;
96 
97  // Our shadow versions of LLVM structures.
98  std::vector<KFunction*> functions;
99  std::map<llvm::Function*, KFunction*> functionMap;
100 
101  // Functions which escape (may be called indirectly)
102  // XXX change to KFunction
103  std::set<llvm::Function*> escapingFunctions;
104 
106 
107  std::vector<llvm::Constant*> constants;
108  std::map<llvm::Constant*, KConstant*> constantMap;
109  KConstant* getKConstant(llvm::Constant *c);
110 
112 
113  // Functions which are part of KLEE runtime
114  std::set<const llvm::Function*> internalFunctions;
115 
116  private:
117  // Mark function with functionName as part of the KLEE runtime
118  void addInternalFunction(const char* functionName);
119 
120  public:
121  KModule(llvm::Module *_module);
122  ~KModule();
123 
125  //
126  // FIXME: ihandler should not be here
127  void prepare(const Interpreter::ModuleOptions &opts,
128  InterpreterHandler *ihandler);
129 
131  unsigned getConstantID(llvm::Constant *c, KInstruction* ki);
132  };
133 } // End klee namespace
134 
135 #endif
InstructionInfoTable * infos
Definition: KModule.h:105
Cell * constantTable
Definition: KModule.h:111
#define Expr
Definition: STPBuilder.h:19
unsigned getArgRegister(unsigned index)
Definition: KModule.h:65
std::set< llvm::Function * > escapingFunctions
Definition: KModule.h:103
KFunction & operator=(const KFunction &)
std::map< llvm::BasicBlock *, unsigned > basicBlockEntry
Definition: KModule.h:51
unsigned numArgs
Definition: KModule.h:46
KConstant * getKConstant(llvm::Constant *c)
Definition: KModule.cpp:514
std::set< const llvm::Function * > internalFunctions
Definition: KModule.h:114
KInstruction * ki
Definition: KModule.h:79
llvm::Function * kleeMergeFn
Definition: KModule.h:95
void addInternalFunction(const char *functionName)
Definition: KModule.cpp:270
llvm::Function * dbgStopPointFn
Definition: KModule.h:95
KInstruction ** instructions
Definition: KModule.h:49
unsigned id
The constant ID.
Definition: KModule.h:75
std::vector< KFunction * > functions
Definition: KModule.h:98
unsigned numInstructions
Definition: KModule.h:48
KFunction(const KFunction &)
KModule(llvm::Module *_module)
Definition: KModule.cpp:101
std::vector< llvm::Constant * > constants
Definition: KModule.h:107
unsigned getConstantID(llvm::Constant *c, KInstruction *ki)
Return an id for the given constant, creating a new one if necessary.
Definition: KModule.cpp:521
bool trackCoverage
Definition: KModule.h:55
unsigned numRegisters
Definition: KModule.h:46
llvm::Constant * ct
Actual LLVM constant this represents.
Definition: KModule.h:72
void prepare(const Interpreter::ModuleOptions &opts, InterpreterHandler *ihandler)
Initialize local data structures.
Definition: KModule.cpp:281
KConstant(llvm::Constant *, unsigned, KInstruction *)
Definition: KModule.cpp:535
llvm::Module * module
Definition: KModule.h:87
std::map< llvm::Constant *, KConstant * > constantMap
Definition: KModule.h:108
std::map< llvm::Function *, KFunction * > functionMap
Definition: KModule.h:99
llvm::TargetData * targetData
Definition: KModule.h:89