Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame^] | 1 | //===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===// |
| 2 | // |
| 3 | // This file defines the top-level Virtual Machine data structure. |
| 4 | // |
| 5 | //===----------------------------------------------------------------------===// |
| 6 | |
| 7 | #ifndef VM_H |
| 8 | #define VM_H |
| 9 | |
| 10 | #include "../ExecutionEngine.h" |
| 11 | #include "llvm/PassManager.h" |
| 12 | #include <map> |
| 13 | |
| 14 | class Function; |
| 15 | class GlobalValue; |
| 16 | class Constant; |
| 17 | class TargetMachine; |
| 18 | class MachineCodeEmitter; |
| 19 | |
| 20 | class VM : public ExecutionEngine { |
| 21 | TargetMachine &TM; // The current target we are compiling to |
| 22 | PassManager PM; // Passes to compile a function |
| 23 | MachineCodeEmitter *MCE; // MCE object |
| 24 | |
| 25 | // FunctionRefs - A mapping between addresses that refer to unresolved |
| 26 | // functions and the LLVM function object itself. This is used by the fault |
| 27 | // handler to lazily patch up references... |
| 28 | // |
| 29 | std::map<void*, Function*> FunctionRefs; |
| 30 | public: |
| 31 | VM(Module *M, TargetMachine *tm); |
| 32 | ~VM(); |
| 33 | |
| 34 | /// run - Start execution with the specified function and arguments. |
| 35 | /// |
| 36 | virtual int run(const std::string &FnName, |
| 37 | const std::vector<std::string> &Args); |
| 38 | |
| 39 | void addFunctionRef(void *Ref, Function *F) { |
| 40 | FunctionRefs[Ref] = F; |
| 41 | } |
| 42 | |
| 43 | const std::string &getFunctionReferencedName(void *RefAddr); |
| 44 | |
| 45 | void *resolveFunctionReference(void *RefAddr); |
| 46 | |
| 47 | private: |
| 48 | static MachineCodeEmitter *createEmitter(VM &V); |
| 49 | void setupPassManager(); |
| 50 | void *getPointerToFunction(const Function *F); |
| 51 | void registerCallback(); |
| 52 | }; |
| 53 | |
| 54 | #endif |