e886a1941223ee5adfff88490d6f85b7c30895f5
[oota-llvm.git] / lib / ExecutionEngine / JIT / VM.h
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   FunctionPassManager PM;  // Passes to compile a function
23   MachineCodeEmitter *MCE; // MCE object
24
25 public:
26   VM(Module *M, TargetMachine *tm);
27   ~VM();
28
29   /// run - Start execution with the specified function and arguments.
30   ///
31   virtual int run(const std::string &FnName,
32                   const std::vector<std::string> &Args,
33                   const char ** envp);
34
35   /// getPointerToNamedFunction - This method returns the address of the
36   /// specified function by using the dlsym function call.  As such it is only
37   /// useful for resolving library symbols, not code generated symbols.
38   ///
39   void *getPointerToNamedFunction(const std::string &Name);
40
41   // CompilationCallback - Invoked the first time that a call site is found,
42   // which causes lazy compilation of the target function.
43   // 
44   static void CompilationCallback();
45
46   /// runAtExitHandlers - Before exiting the program, at_exit functions must be
47   /// called.  This method calls them.
48   ///
49   static void runAtExitHandlers();
50
51   /// getPointerToFunction - This returns the address of the specified function,
52   /// compiling it if necessary.
53   void *getPointerToFunction(Function *F);
54
55 private:
56   static MachineCodeEmitter *createEmitter(VM &V);
57   void setupPassManager();
58 };
59
60 #endif