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
22 class ExecutionEngine {
27 // GlobalAddress - A mapping between LLVM global values and their actualized
29 std::map<const GlobalValue*, void *> GlobalAddress;
31 void setTargetData(const TargetData &td) {
35 ExecutionEngine(Module *M) : CurMod(*M) {
36 assert(M && "Module is null?");
38 virtual ~ExecutionEngine();
40 Module &getModule() const { return CurMod; }
41 const TargetData &getTargetData() const { return *TD; }
43 /// run - Start execution with the specified function and arguments.
45 virtual int run(const std::string &FnName,
46 const std::vector<std::string> &Args) = 0;
48 /// createJIT - Create an return a new JIT compiler if there is one available
49 /// for the current target. Otherwise it returns null.
51 static ExecutionEngine *createJIT(Module *M, unsigned Config);
53 /// createInterpreter - Create a new interpreter object. This can never fail.
55 static ExecutionEngine *createInterpreter(Module *M, unsigned Config,
56 bool DebugMode, bool TraceMode);
58 void addGlobalMapping(const Function *F, void *Addr) {
59 void *&CurVal = GlobalAddress[(const GlobalValue*)F];
60 assert(CurVal == 0 && "GlobalMapping already established!");
64 // getPointerToGlobalIfAvailable - This returns the address of the specified
65 // global value if it is available, otherwise it returns null.
67 void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
68 std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
69 return I != GlobalAddress.end() ? I->second : 0;
72 // getPointerToGlobal - This returns the address of the specified global
73 // value. This may involve code generation if it's a function.
75 void *getPointerToGlobal(const GlobalValue *GV);
77 // getPointerToFunction - The different EE's represent function bodies in
78 // different ways. They should each implement this to say what a function
79 // pointer should look like.
81 virtual void *getPointerToFunction(const Function *F) = 0;
86 public: // FIXME: protected: // API shared among subclasses
87 GenericValue getConstantValue(const Constant *C);
88 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
89 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
90 void *CreateArgv(const std::vector<std::string> &InputArgv);
91 void InitializeMemory(const Constant *Init, void *Addr);