Doxygenify comments, remove extraneous #include
[oota-llvm.git] / include / llvm / ExecutionEngine / ExecutionEngine.h
1 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
2 // 
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file was developed by the LLVM research group and is distributed under
6 // the University of Illinois Open Source License. See LICENSE.TXT for details.
7 // 
8 //===----------------------------------------------------------------------===//
9 //
10 // This file defines the abstract interface that implements execution support
11 // for LLVM.
12 //
13 //===----------------------------------------------------------------------===//
14
15 #ifndef EXECUTION_ENGINE_H
16 #define EXECUTION_ENGINE_H
17
18 #include <vector>
19 #include <map>
20 #include <cassert>
21
22 namespace llvm {
23
24 class Constant;
25 class Function;
26 union GenericValue;
27 class GlobalValue;
28 class Module;
29 class ModuleProvider;
30 class TargetData;
31 class Type;
32
33 class ExecutionEngine {
34   Module &CurMod;
35   const TargetData *TD;
36
37 protected:
38   ModuleProvider *MP;
39   // GlobalAddress - A mapping between LLVM global values and their actualized
40   // version...
41   std::map<const GlobalValue*, void *> GlobalAddress;
42
43   void setTargetData(const TargetData &td) {
44     TD = &td;
45   }
46
47 public:
48   ExecutionEngine(ModuleProvider *P);
49   ExecutionEngine(Module *M);
50   virtual ~ExecutionEngine();
51   
52   Module &getModule() const { return CurMod; }
53   const TargetData &getTargetData() const { return *TD; }
54
55   /// run - Start execution with the specified function, arguments, and
56   ///       environment.
57   ///
58   virtual GenericValue run(Function *F,
59                            const std::vector<GenericValue> &ArgValues) = 0;
60
61   static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter);
62
63   void addGlobalMapping(const Function *F, void *Addr) {
64     void *&CurVal = GlobalAddress[(const GlobalValue*)F];
65     assert(CurVal == 0 && "GlobalMapping already established!");
66     CurVal = Addr;
67   }
68
69   /// getPointerToGlobalIfAvailable - This returns the address of the specified
70   /// global value if it is available, otherwise it returns null.
71   ///
72   void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
73     std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
74     return I != GlobalAddress.end() ? I->second : 0;
75   }
76
77   /// getPointerToGlobal - This returns the address of the specified global
78   /// value.  This may involve code generation if it's a function.
79   ///
80   void *getPointerToGlobal(const GlobalValue *GV);
81
82   /// getPointerToFunction - The different EE's represent function bodies in
83   /// different ways.  They should each implement this to say what a function
84   /// pointer should look like.
85   ///
86   virtual void *getPointerToFunction(Function *F) = 0;
87
88   /// getPointerToFunctionOrStub - If the specified function has been
89   /// code-gen'd, return a pointer to the function.  If not, compile it, or use
90   /// a stub to implement lazy compilation if available.
91   ///
92   virtual void *getPointerToFunctionOrStub(Function *F) {
93     // Default implementation, just codegen the function.
94     return getPointerToFunction(F);
95   }
96
97   void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
98   void InitializeMemory(const Constant *Init, void *Addr);
99
100   /// recompileAndRelinkFunction - This method is used to force a function
101   /// which has already been compiled to be compiled again, possibly
102   /// after it has been modified. Then the entry to the old copy is overwritten
103   /// with a branch to the new copy. If there was no old copy, this acts
104   /// just like VM::getPointerToFunction().
105   ///
106   virtual void *recompileAndRelinkFunction(Function *F) = 0;
107
108 protected:
109   void emitGlobals();
110   GenericValue getConstantValue(const Constant *C);
111   GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
112 };
113
114 } // End llvm namespace
115
116 #endif