blob: 17c4ddd3dce85ba18b4fbd7099f1ff5ab5ad7921 [file] [log] [blame]
Chris Lattner836f6752002-12-24 00:01:22 +00001//===-- 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 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;
30public:
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
Chris Lattner0d448c02003-01-13 01:00:48 +000047 /// getPointerToNamedFunction - This method returns the address of the
48 /// specified function by using the dlsym function call. As such it is only
49 /// useful for resolving library symbols, not code generated symbols.
50 ///
51 void *getPointerToNamedFunction(const std::string &Name);
52
Chris Lattnerc309a762003-05-08 21:34:11 +000053 // CompilationCallback - Invoked the first time that a call site is found,
54 // which causes lazy compilation of the target function.
55 //
56 static void CompilationCallback();
Chris Lattner836f6752002-12-24 00:01:22 +000057private:
58 static MachineCodeEmitter *createEmitter(VM &V);
59 void setupPassManager();
60 void *getPointerToFunction(const Function *F);
Chris Lattnerc309a762003-05-08 21:34:11 +000061
Chris Lattner836f6752002-12-24 00:01:22 +000062 void registerCallback();
Chris Lattner6125fdd2003-05-09 03:30:07 +000063
64 /// emitStubForFunction - This method is used by the JIT when it needs to emit
65 /// the address of a function for a function whose code has not yet been
66 /// generated. In order to do this, it generates a stub which jumps to the
67 /// lazy function compiler, which will eventually get fixed to call the
68 /// function directly.
69 ///
70 void *emitStubForFunction(const Function &F);
Chris Lattner836f6752002-12-24 00:01:22 +000071};
72
73#endif