1 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
3 // This file defines the abstract interface that implements execution support
6 //===----------------------------------------------------------------------===//
8 #ifndef EXECUTION_ENGINE_H
9 #define EXECUTION_ENGINE_H
11 #include "llvm/ModuleProvider.h"
24 class ExecutionEngine {
30 // GlobalAddress - A mapping between LLVM global values and their actualized
32 std::map<const GlobalValue*, void *> GlobalAddress;
34 void setTargetData(const TargetData &td) {
39 ExecutionEngine(ModuleProvider *P) : CurMod(*(P->getModule())), MP(P) {
40 assert(P && "ModuleProvider is null?");
42 ExecutionEngine(Module *M) : CurMod(*M), MP(0) {
43 assert(M && "Module is null?");
45 virtual ~ExecutionEngine();
47 Module &getModule() const { return CurMod; }
48 const TargetData &getTargetData() const { return *TD; }
50 /// run - Start execution with the specified function, arguments, and
53 virtual GenericValue run(Function *F,
54 const std::vector<GenericValue> &ArgValues) = 0;
56 static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter,
59 void addGlobalMapping(const Function *F, void *Addr) {
60 void *&CurVal = GlobalAddress[(const GlobalValue*)F];
61 assert(CurVal == 0 && "GlobalMapping already established!");
65 // getPointerToGlobalIfAvailable - This returns the address of the specified
66 // global value if it is available, otherwise it returns null.
68 void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
69 std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
70 return I != GlobalAddress.end() ? I->second : 0;
73 // getPointerToGlobal - This returns the address of the specified global
74 // value. This may involve code generation if it's a function.
76 void *getPointerToGlobal(const GlobalValue *GV);
78 // getPointerToFunction - The different EE's represent function bodies in
79 // different ways. They should each implement this to say what a function
80 // pointer should look like.
82 virtual void *getPointerToFunction(Function *F) = 0;
84 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
85 void InitializeMemory(const Constant *Init, void *Addr);
89 GenericValue getConstantValue(const Constant *C);
90 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);