]> CyberLeo.Net >> Repos - FreeBSD/releng/9.0.git/blob - contrib/llvm/include/llvm/ExecutionEngine/RuntimeDyld.h
Copy stable/9 to releng/9.0 as part of the FreeBSD 9.0-RELEASE release
[FreeBSD/releng/9.0.git] / contrib / llvm / 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   virtual ~RTDyldMemoryManager();
37
38   // Allocate ActualSize bytes, or more, for the named function. Return
39   // a pointer to the allocated memory and update Size to reflect how much
40   // memory was acutally allocated.
41   virtual uint8_t *startFunctionBody(const char *Name, uintptr_t &Size) = 0;
42
43   // Mark the end of the function, including how much of the allocated
44   // memory was actually used.
45   virtual void endFunctionBody(const char *Name, uint8_t *FunctionStart,
46                                uint8_t *FunctionEnd) = 0;
47 };
48
49 class RuntimeDyld {
50   RuntimeDyld(const RuntimeDyld &);     // DO NOT IMPLEMENT
51   void operator=(const RuntimeDyld &);  // DO NOT IMPLEMENT
52
53   // RuntimeDyldImpl is the actual class. RuntimeDyld is just the public
54   // interface.
55   RuntimeDyldImpl *Dyld;
56   RTDyldMemoryManager *MM;
57 public:
58   RuntimeDyld(RTDyldMemoryManager*);
59   ~RuntimeDyld();
60
61   bool loadObject(MemoryBuffer *InputBuffer);
62   // Get the address of our local copy of the symbol. This may or may not
63   // be the address used for relocation (clients can copy the data around
64   // and resolve relocatons based on where they put it).
65   void *getSymbolAddress(StringRef Name);
66   // Resolve the relocations for all symbols we currently know about.
67   void resolveRelocations();
68   // Change the address associated with a symbol when resolving relocations.
69   // Any relocations already associated with the symbol will be re-resolved.
70   void reassignSymbolAddress(StringRef Name, uint8_t *Addr);
71   StringRef getErrorString();
72 };
73
74 } // end namespace llvm
75
76 #endif