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) {
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 and arguments.
46 virtual int run(const std::string &FnName,
47 const std::vector<std::string> &Args) = 0;
49 /// createJIT - Create an return a new JIT compiler if there is one available
50 /// for the current target. Otherwise it returns null.
52 static ExecutionEngine *createJIT(Module *M, unsigned Config);
54 /// createInterpreter - Create a new interpreter object. This can never fail.
56 static ExecutionEngine *createInterpreter(Module *M, unsigned Config,
57 bool DebugMode, bool TraceMode);
59 void addGlobalMapping(const Function *F, void *Addr) {
60 void *&CurVal = GlobalAddress[(const GlobalValue*)F];
61 assert(CurVal == 0 && "GlobalMapping already established!");
65 // getPointerToGlobal - This returns the address of the specified global
66 // value. This may involve code generation if it's a function.
68 void *getPointerToGlobal(const GlobalValue *GV);
70 // getPointerToFunction - The different EE's represent function bodies in
71 // different ways. They should each implement this to say what a function
72 // pointer should look like.
74 virtual void *getPointerToFunction(const Function *F) = 0;
79 public: // FIXME: protected: // API shared among subclasses
80 GenericValue getConstantValue(const Constant *C);
81 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
82 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);
83 void *CreateArgv(const std::vector<std::string> &InputArgv);
84 void InitializeMemory(const Constant *Init, void *Addr);