]> git.proxmox.com Git - rustc.git/blame - src/llvm/lib/ExecutionEngine/MCJIT/MCJIT.h
Imported Upstream version 0.6
[rustc.git] / src / llvm / lib / ExecutionEngine / MCJIT / MCJIT.h
CommitLineData
223e47cc
LB
1//===-- MCJIT.h - Class definition for the MCJIT ----------------*- C++ -*-===//
2//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9
10#ifndef LLVM_LIB_EXECUTIONENGINE_MCJIT_H
11#define LLVM_LIB_EXECUTIONENGINE_MCJIT_H
12
13#include "llvm/PassManager.h"
14#include "llvm/ExecutionEngine/ExecutionEngine.h"
15#include "llvm/ExecutionEngine/RuntimeDyld.h"
16#include "llvm/ADT/SmallVector.h"
17#include "llvm/Support/raw_ostream.h"
18
19namespace llvm {
20
21// FIXME: This makes all kinds of horrible assumptions for the time being,
22// like only having one module, not needing to worry about multi-threading,
23// blah blah. Purely in get-it-up-and-limping mode for now.
24
25class MCJIT : public ExecutionEngine {
26 MCJIT(Module *M, TargetMachine *tm, RTDyldMemoryManager *MemMgr,
27 bool AllocateGVsWithCode);
28
29 TargetMachine *TM;
30 MCContext *Ctx;
31 RTDyldMemoryManager *MemMgr;
32 RuntimeDyld Dyld;
33
34 // FIXME: Add support for multiple modules
35 bool isCompiled;
36 Module *M;
37
38 // FIXME: Move these to a single container which manages JITed objects
39 SmallVector<char, 4096> Buffer; // Working buffer into which we JIT.
40 raw_svector_ostream OS;
41
42public:
43 ~MCJIT();
44
45 /// @name ExecutionEngine interface implementation
46 /// @{
47
48 virtual void *getPointerToBasicBlock(BasicBlock *BB);
49
50 virtual void *getPointerToFunction(Function *F);
51
52 virtual void *recompileAndRelinkFunction(Function *F);
53
54 virtual void freeMachineCodeForFunction(Function *F);
55
56 virtual GenericValue runFunction(Function *F,
57 const std::vector<GenericValue> &ArgValues);
58
59 /// getPointerToNamedFunction - This method returns the address of the
60 /// specified function by using the dlsym function call. As such it is only
61 /// useful for resolving library symbols, not code generated symbols.
62 ///
63 /// If AbortOnFailure is false and no function with the given name is
64 /// found, this function silently returns a null pointer. Otherwise,
65 /// it prints a message to stderr and aborts.
66 ///
67 virtual void *getPointerToNamedFunction(const std::string &Name,
68 bool AbortOnFailure = true);
69
70 /// mapSectionAddress - map a section to its target address space value.
71 /// Map the address of a JIT section as returned from the memory manager
72 /// to the address in the target process as the running code will see it.
73 /// This is the address which will be used for relocation resolution.
74 virtual void mapSectionAddress(const void *LocalAddress,
75 uint64_t TargetAddress) {
76 Dyld.mapSectionAddress(LocalAddress, TargetAddress);
77 }
78
79 /// @}
80 /// @name (Private) Registration Interfaces
81 /// @{
82
83 static void Register() {
84 MCJITCtor = createJIT;
85 }
86
87 static ExecutionEngine *createJIT(Module *M,
88 std::string *ErrorStr,
89 JITMemoryManager *JMM,
90 bool GVsWithCode,
91 TargetMachine *TM);
92
93 // @}
94
95protected:
96 /// emitObject -- Generate a JITed object in memory from the specified module
97 /// Currently, MCJIT only supports a single module and the module passed to
98 /// this function call is expected to be the contained module. The module
99 /// is passed as a parameter here to prepare for multiple module support in
100 /// the future.
101 void emitObject(Module *M);
102};
103
104} // End llvm namespace
105
106#endif