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 |
Brian Gaeke | c227c1f | 2003-08-13 18:16:50 +0000 | [diff] [blame] | 22 | FunctionPassManager PM; // Passes to compile a function |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 23 | MachineCodeEmitter *MCE; // MCE object |
| 24 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 25 | public: |
| 26 | VM(Module *M, TargetMachine *tm); |
| 27 | ~VM(); |
| 28 | |
Brian Gaeke | 82d8277 | 2003-09-03 20:34:19 +0000 | [diff] [blame^] | 29 | /// create - Create an return a new JIT compiler if there is one available |
| 30 | /// for the current target. Otherwise, return null. |
| 31 | /// |
| 32 | static ExecutionEngine *create(Module *M); |
| 33 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 34 | /// run - Start execution with the specified function and arguments. |
| 35 | /// |
| 36 | virtual int run(const std::string &FnName, |
John Criswell | 69582b3 | 2003-08-21 21:12:30 +0000 | [diff] [blame] | 37 | const std::vector<std::string> &Args, |
| 38 | const char ** envp); |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 39 | |
Chris Lattner | 0d448c0 | 2003-01-13 01:00:48 +0000 | [diff] [blame] | 40 | /// getPointerToNamedFunction - This method returns the address of the |
| 41 | /// specified function by using the dlsym function call. As such it is only |
| 42 | /// useful for resolving library symbols, not code generated symbols. |
| 43 | /// |
| 44 | void *getPointerToNamedFunction(const std::string &Name); |
| 45 | |
Chris Lattner | c309a76 | 2003-05-08 21:34:11 +0000 | [diff] [blame] | 46 | // CompilationCallback - Invoked the first time that a call site is found, |
| 47 | // which causes lazy compilation of the target function. |
| 48 | // |
| 49 | static void CompilationCallback(); |
Chris Lattner | 22080f9 | 2003-05-14 13:53:40 +0000 | [diff] [blame] | 50 | |
| 51 | /// runAtExitHandlers - Before exiting the program, at_exit functions must be |
| 52 | /// called. This method calls them. |
| 53 | /// |
| 54 | static void runAtExitHandlers(); |
| 55 | |
Chris Lattner | bba1b6d | 2003-06-01 23:24:36 +0000 | [diff] [blame] | 56 | /// getPointerToFunction - This returns the address of the specified function, |
| 57 | /// compiling it if necessary. |
Brian Gaeke | c227c1f | 2003-08-13 18:16:50 +0000 | [diff] [blame] | 58 | void *getPointerToFunction(Function *F); |
Chris Lattner | bba1b6d | 2003-06-01 23:24:36 +0000 | [diff] [blame] | 59 | |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 60 | private: |
Misha Brukman | 906f5fa | 2003-06-02 03:23:16 +0000 | [diff] [blame] | 61 | static MachineCodeEmitter *createEmitter(VM &V); |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 62 | void setupPassManager(); |
Chris Lattner | 836f675 | 2002-12-24 00:01:22 +0000 | [diff] [blame] | 63 | }; |
| 64 | |
| 65 | #endif |