If we move the constructors to the .cpp file, we can drop the #include
[oota-llvm.git] / include / llvm / ExecutionEngine / ExecutionEngine.h
1 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
2 //
3 // This file defines the abstract interface that implements execution support
4 // for LLVM.
5 //
6 //===----------------------------------------------------------------------===//
7
8 #ifndef EXECUTION_ENGINE_H
9 #define EXECUTION_ENGINE_H
10
11 #include <vector>
12 #include <string>
13 #include <map>
14 #include <cassert>
15 class Constant;
16 class Function;
17 union GenericValue;
18 class GlobalValue;
19 class Module;
20 class ModuleProvider;
21 class TargetData;
22 class Type;
23
24 class ExecutionEngine {
25   Module &CurMod;
26   const TargetData *TD;
27
28 protected:
29   ModuleProvider *MP;
30   // GlobalAddress - A mapping between LLVM global values and their actualized
31   // version...
32   std::map<const GlobalValue*, void *> GlobalAddress;
33
34   void setTargetData(const TargetData &td) {
35     TD = &td;
36   }
37
38 public:
39   ExecutionEngine(ModuleProvider *P);
40   ExecutionEngine(Module *M);
41   virtual ~ExecutionEngine();
42   
43   Module &getModule() const { return CurMod; }
44   const TargetData &getTargetData() const { return *TD; }
45
46   /// run - Start execution with the specified function, arguments, and
47   ///       environment.
48   ///
49   virtual GenericValue run(Function *F,
50                            const std::vector<GenericValue> &ArgValues) = 0;
51
52   static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter,
53                                  bool TraceMode);
54
55   void addGlobalMapping(const Function *F, void *Addr) {
56     void *&CurVal = GlobalAddress[(const GlobalValue*)F];
57     assert(CurVal == 0 && "GlobalMapping already established!");
58     CurVal = Addr;
59   }
60
61   // getPointerToGlobalIfAvailable - This returns the address of the specified
62   // global value if it is available, otherwise it returns null.
63   //
64   void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
65     std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
66     return I != GlobalAddress.end() ? I->second : 0;
67   }
68
69   // getPointerToGlobal - This returns the address of the specified global
70   // value.  This may involve code generation if it's a function.
71   //
72   void *getPointerToGlobal(const GlobalValue *GV);
73
74   // getPointerToFunction - The different EE's represent function bodies in
75   // different ways.  They should each implement this to say what a function
76   // pointer should look like.
77   //
78   virtual void *getPointerToFunction(Function *F) = 0;
79
80   void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
81   void InitializeMemory(const Constant *Init, void *Addr);
82
83 protected:
84   void emitGlobals();
85   GenericValue getConstantValue(const Constant *C);
86   GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
87 };
88
89 #endif