1 //===- ExecutionEngine.h - Abstract Execution Engine Interface --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
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.
8 //===----------------------------------------------------------------------===//
10 // This file defines the abstract interface that implements execution support
13 //===----------------------------------------------------------------------===//
15 #ifndef EXECUTION_ENGINE_H
16 #define EXECUTION_ENGINE_H
31 class ExecutionEngine {
37 // GlobalAddress - A mapping between LLVM global values and their actualized
39 std::map<const GlobalValue*, void *> GlobalAddress;
41 void setTargetData(const TargetData &td) {
46 ExecutionEngine(ModuleProvider *P);
47 ExecutionEngine(Module *M);
48 virtual ~ExecutionEngine();
50 Module &getModule() const { return CurMod; }
51 const TargetData &getTargetData() const { return *TD; }
53 /// run - Start execution with the specified function, arguments, and
56 virtual GenericValue run(Function *F,
57 const std::vector<GenericValue> &ArgValues) = 0;
59 static ExecutionEngine *create(ModuleProvider *MP, bool ForceInterpreter,
62 void addGlobalMapping(const Function *F, void *Addr) {
63 void *&CurVal = GlobalAddress[(const GlobalValue*)F];
64 assert(CurVal == 0 && "GlobalMapping already established!");
68 // getPointerToGlobalIfAvailable - This returns the address of the specified
69 // global value if it is available, otherwise it returns null.
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;
76 // getPointerToGlobal - This returns the address of the specified global
77 // value. This may involve code generation if it's a function.
79 void *getPointerToGlobal(const GlobalValue *GV);
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.
85 virtual void *getPointerToFunction(Function *F) = 0;
87 void StoreValueToMemory(GenericValue Val, GenericValue *Ptr, const Type *Ty);
88 void InitializeMemory(const Constant *Init, void *Addr);
92 GenericValue getConstantValue(const Constant *C);
93 GenericValue LoadValueFromMemory(GenericValue *Ptr, const Type *Ty);