1 //===-- VM.h - Definitions for Virtual Machine ------------------*- C++ -*-===//
3 // This file defines the top-level Virtual Machine data structure.
5 //===----------------------------------------------------------------------===//
10 #include "../ExecutionEngine.h"
11 #include "llvm/PassManager.h"
18 class MachineCodeEmitter;
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
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...
29 std::map<void*, Function*> FunctionRefs;
32 VM(Module *M, TargetMachine *tm);
35 /// run - Start execution with the specified function and arguments.
37 virtual int run(const std::string &FnName,
38 const std::vector<std::string> &Args);
40 void addFunctionRef(void *Ref, Function *F) {
41 FunctionRefs[Ref] = F;
44 const std::string &getFunctionReferencedName(void *RefAddr);
46 void *resolveFunctionReference(void *RefAddr);
48 /// getPointerToNamedFunction - This method returns the address of the
49 /// specified function by using the dlsym function call. As such it is only
50 /// useful for resolving library symbols, not code generated symbols.
52 void *getPointerToNamedFunction(const std::string &Name);
54 // CompilationCallback - Invoked the first time that a call site is found,
55 // which causes lazy compilation of the target function.
57 static void CompilationCallback();
59 /// runAtExitHandlers - Before exiting the program, at_exit functions must be
60 /// called. This method calls them.
62 static void runAtExitHandlers();
65 static MachineCodeEmitter *createX86Emitter(VM &V);
66 static MachineCodeEmitter *createSparcEmitter(VM &V);
67 void setupPassManager();
68 void *getPointerToFunction(const Function *F);
70 void registerCallback();
72 /// emitStubForFunction - This method is used by the JIT when it needs to emit
73 /// the address of a function for a function whose code has not yet been
74 /// generated. In order to do this, it generates a stub which jumps to the
75 /// lazy function compiler, which will eventually get fixed to call the
76 /// function directly.
78 void *emitStubForFunction(const Function &F);