unique_ptrify a bunch of stuff through RuntimeDyld::loadObject
[oota-llvm.git] / include / llvm / ExecutionEngine / ObjectImage.h
1 //===---- ObjectImage.h - Format independent executuable object image -----===//
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 // This file declares a file format independent ObjectImage class.
11 //
12 //===----------------------------------------------------------------------===//
13
14 #ifndef LLVM_EXECUTIONENGINE_OBJECTIMAGE_H
15 #define LLVM_EXECUTIONENGINE_OBJECTIMAGE_H
16
17 #include "llvm/ExecutionEngine/ObjectBuffer.h"
18 #include "llvm/Object/ObjectFile.h"
19
20 namespace llvm {
21
22
23 /// ObjectImage - A container class that represents an ObjectFile that has been
24 /// or is in the process of being loaded into memory for execution.
25 class ObjectImage {
26   ObjectImage() LLVM_DELETED_FUNCTION;
27   ObjectImage(const ObjectImage &other) LLVM_DELETED_FUNCTION;
28   virtual void anchor();
29
30 protected:
31   std::unique_ptr<ObjectBuffer> Buffer;
32
33 public:
34   ObjectImage(std::unique_ptr<ObjectBuffer> Input) : Buffer(std::move(Input)) {}
35   virtual ~ObjectImage() {}
36
37   virtual object::symbol_iterator begin_symbols() const = 0;
38   virtual object::symbol_iterator end_symbols() const = 0;
39   iterator_range<object::symbol_iterator> symbols() const {
40     return iterator_range<object::symbol_iterator>(begin_symbols(),
41                                                    end_symbols());
42   }
43
44   virtual object::section_iterator begin_sections() const = 0;
45   virtual object::section_iterator end_sections() const  = 0;
46   iterator_range<object::section_iterator> sections() const {
47     return iterator_range<object::section_iterator>(begin_sections(),
48                                                     end_sections());
49   }
50
51   virtual /* Triple::ArchType */ unsigned getArch() const = 0;
52
53   // Return the name associated with this ObjectImage.
54   // This is usually the name of the file or MemoryBuffer that the the
55   // ObjectBuffer was constructed from.
56   StringRef getImageName() const { return Buffer->getBufferIdentifier(); }
57
58   // Subclasses can override these methods to update the image with loaded
59   // addresses for sections and common symbols
60   virtual void updateSectionAddress(const object::SectionRef &Sec,
61                                     uint64_t Addr) = 0;
62   virtual void updateSymbolAddress(const object::SymbolRef &Sym,
63                                    uint64_t Addr) = 0;
64
65   virtual StringRef getData() const = 0;
66
67   virtual object::ObjectFile* getObjectFile() const = 0;
68
69   // Subclasses can override these methods to provide JIT debugging support
70   virtual void registerWithDebugger() = 0;
71   virtual void deregisterWithDebugger() = 0;
72 };
73
74 } // end namespace llvm
75
76 #endif // LLVM_EXECUTIONENGINE_OBJECTIMAGE_H