JIT.h revision 82d8277ad5862b54341808812bb4016e52347060
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 14class Function; 15class GlobalValue; 16class Constant; 17class TargetMachine; 18class MachineCodeEmitter; 19 20class VM : public ExecutionEngine { 21 TargetMachine &TM; // The current target we are compiling to 22 FunctionPassManager PM; // Passes to compile a function 23 MachineCodeEmitter *MCE; // MCE object 24 25public: 26 VM(Module *M, TargetMachine *tm); 27 ~VM(); 28 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 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 const char ** envp); 39 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 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(); 50 51 /// runAtExitHandlers - Before exiting the program, at_exit functions must be 52 /// called. This method calls them. 53 /// 54 static void runAtExitHandlers(); 55 56 /// getPointerToFunction - This returns the address of the specified function, 57 /// compiling it if necessary. 58 void *getPointerToFunction(Function *F); 59 60private: 61 static MachineCodeEmitter *createEmitter(VM &V); 62 void setupPassManager(); 63}; 64 65#endif 66