Added LLVM copyright header (for lack of a better term).
[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 <string>
20 #include <map>
21 #include <cassert>
22 class Constant;
23 class Function;
24 union GenericValue;
25 class GlobalValue;
26 class Module;
27 class ModuleProvider;
28 class TargetData;
29 class Type;
30
31 class ExecutionEngine {
32   Module &CurMod;
33   const TargetData *TD;
34
35 protected:
36   ModuleProvider *MP;
37   // GlobalAddress - A mapping between LLVM global values and their actualized
38   // version...
39   std::map<const GlobalValue*, void *> GlobalAddress;
40
41   void setTargetData(const TargetData &td) {
42     TD = &td;
43   }
44
45 public:
46   ExecutionEngine(ModuleProvider *P);
47   ExecutionEngine(Module *M);
48   virtual ~ExecutionEngine();
49   
50   Module &getModule() const { return CurMod; }
51   const TargetData &getTargetData() const { return *TD; }
52
53   /// run - Start execution with the specified function, arguments, and
54   ///       environment.
55   ///
56   virtual GenericValue run(Function *F,
57                            const std::vector<GenericValue> &ArgValues) = 0;
58
59   static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter,
60                                  bool TraceMode);
61
62   void addGlobalMapping(const Function *F, void *Addr) {
63     void *&CurVal = GlobalAddress[(const GlobalValue*)F];
64     assert(CurVal == 0 && "GlobalMapping already established!");
65     CurVal = Addr;
66   }
67
68   // getPointerToGlobalIfAvailable - This returns the address of the specified
69   // global value if it is available, otherwise it returns null.
70   //
71   void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
72     std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
73     return I != GlobalAddress.end() ? I->second : 0;
74   }
75
76   // getPointerToGlobal - This returns the address of the specified global
77   // value.  This may involve code generation if it's a function.
78   //
79   void *getPointerToGlobal(const GlobalValue *GV);
80
81   // getPointerToFunction - The different EE's represent function bodies in
82   // different ways.  They should each implement this to say what a function
83   // pointer should look like.
84   //
85   virtual void *getPointerToFunction(Function *F) = 0;
86
87   void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
88   void InitializeMemory(const Constant *Init, void *Addr);
89
90 protected:
91   void emitGlobals();
92   GenericValue getConstantValue(const Constant *C);
93   GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
94 };
95
96 #endif