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
23 class ExecutionEngine {
28 // GlobalAddress - A mapping between LLVM global values and their actualized
30 std::map<const GlobalValue*, void *> GlobalAddress;
32 void setTargetData(const TargetData &td) {
36 ExecutionEngine(Module *M) : CurMod(*M) {
37 assert(M && "Module is null?");
39 virtual ~ExecutionEngine();
41 Module &getModule() const { return CurMod; }
42 const TargetData &getTargetData() const { return *TD; }
44 /// run - Start execution with the specified function, arguments, and
47 virtual int run(const std::string &FnName,
48 const std::vector<std::string> &Args,
49 const char ** envp) = 0;
51 static ExecutionEngine *create (Module *M, bool ForceInterpreter,
54 void addGlobalMapping(const Function *F, void *Addr) {
55 void *&CurVal = GlobalAddress[(const GlobalValue*)F];
56 assert(CurVal == 0 && "GlobalMapping already established!");
60 // getPointerToGlobalIfAvailable - This returns the address of the specified
61 // global value if it is available, otherwise it returns null.
63 void *getPointerToGlobalIfAvailable(const GlobalValue *GV) {
64 std::map<const GlobalValue*, void*>::iterator I = GlobalAddress.find(GV);
65 return I != GlobalAddress.end() ? I->second : 0;
68 // getPointerToGlobal - This returns the address of the specified global
69 // value. This may involve code generation if it's a function.
71 void *getPointerToGlobal(const GlobalValue *GV);
73 // getPointerToFunction - The different EE's represent function bodies in
74 // different ways. They should each implement this to say what a function
75 // pointer should look like.
77 virtual void *getPointerToFunction(Function *F) = 0;
82 public: // FIXME: protected: // API shared among subclasses
83 GenericValue getConstantValue(const Constant *C);
84 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
85 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
86 void *CreateArgv(const std::vector<std::string> &InputArgv);
87 void InitializeMemory(const Constant *Init, void *Addr);