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;
31 VM(Module *M, TargetMachine *tm);
34 /// run - Start execution with the specified function and arguments.
36 virtual int run(const std::string &FnName,
37 const std::vector<std::string> &Args);
39 void addFunctionRef(void *Ref, Function *F) {
40 FunctionRefs[Ref] = F;
43 const std::string &getFunctionReferencedName(void *RefAddr);
45 void *resolveFunctionReference(void *RefAddr);
47 /// 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.
51 void *getPointerToNamedFunction(const std::string &Name);
54 static MachineCodeEmitter *createEmitter(VM &V);
55 void setupPassManager();
56 void *getPointerToFunction(const Function *F);
57 void registerCallback();