Layer the memory manager between the JIT and the runtime Dyld.
[oota-llvm.git] / include / llvm / ExecutionEngine / RuntimeDyld.h
1 //===-- RuntimeDyld.h - Run-time dynamic linker for MC-JIT ------*- 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 // Interface for the runtime dynamic linker facilities of the MC-JIT.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_RUNTIME_DYLD_H
15 #define LLVM_RUNTIME_DYLD_H
16
17 #include "llvm/ADT/StringRef.h"
18 #include "llvm/Support/Memory.h"
19
20 namespace llvm {
21
22 class RuntimeDyldImpl;
23 class MemoryBuffer;
24
25 // RuntimeDyld clients often want to handle the memory management of
26 // what gets placed where. For JIT clients, this is an abstraction layer
27 // over the JITMemoryManager, which references objects by their source
28 // representations in LLVM IR.
29 // FIXME: As the RuntimeDyld fills out, additional routines will be needed
30 //        for the varying types of objects to be allocated.
31 class RTDyldMemoryManager {
32   RTDyldMemoryManager(const RTDyldMemoryManager&);  // DO NOT IMPLEMENT
33   void operator=(const RTDyldMemoryManager&);       // DO NOT IMPLEMENT
34 public:
35   RTDyldMemoryManager() {}
36
37   // Allocate ActualSize bytes, or more, for the named function. Return
38   // a pointer to the allocated memory and update Size to reflect how much
39   // memory was acutally allocated.
40   virtual uint64_t startFunctionBody(const char *Name, uintptr_t &Size) = 0;
41
42   // Mark the end of the function, including how much of the allocated
43   // memory was actually used.
44   virtual void endFunctionBody(const char *Name, uint64_t FunctionStart,
45                                uint64_t FunctionEnd) = 0;
46 };
47
48 class RuntimeDyld {
49   RuntimeDyld(const RuntimeDyld &);     // DO NOT IMPLEMENT
50   void operator=(const RuntimeDyld &);  // DO NOT IMPLEMENT
51
52   // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
53   // interface.
54   RuntimeDyldImpl *Dyld;
55 public:
56   RuntimeDyld(RTDyldMemoryManager*);
57   ~RuntimeDyld();
58
59   bool loadObject(MemoryBuffer *InputBuffer);
60   uint64_t getSymbolAddress(StringRef Name);
61   void reassignSymbolAddress(StringRef Name, uint64_t Addr);
62   // FIXME: Should be parameterized to get the memory block associated with
63   // a particular loaded object.
64   sys::MemoryBlock getMemoryBlock();
65   StringRef getErrorString();
66 };
67
68 } // end namespace llvm
69
70 #endif