Make ObjectFile ownership of the MemoryBuffer optional.

This allows llvm-ar to mmap the input files only once.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@200040 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Rafael Espindola
2014-01-24 21:32:21 +00:00
parent 0078935812
commit 584fe2db6a
11 changed files with 98 additions and 85 deletions

View File

@ -270,7 +270,7 @@ class ObjectFile : public Binary {
ObjectFile(const ObjectFile &other) LLVM_DELETED_FUNCTION;
protected:
ObjectFile(unsigned int Type, MemoryBuffer *source);
ObjectFile(unsigned int Type, MemoryBuffer *Source, bool BufferOwned = true);
const uint8_t *base() const {
return reinterpret_cast<const uint8_t *>(Data->getBufferStart());
@ -379,7 +379,7 @@ public:
/// @brief Create ObjectFile from path.
static ErrorOr<ObjectFile *> createObjectFile(StringRef ObjectPath);
static ErrorOr<ObjectFile *>
createObjectFile(MemoryBuffer *Object,
createObjectFile(MemoryBuffer *Object, bool BufferOwned = true,
sys::fs::file_magic Type = sys::fs::file_magic::unknown);
static inline bool classof(const Binary *v) {
@ -387,9 +387,12 @@ public:
}
public:
static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object);
static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object);
static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object);
static ErrorOr<ObjectFile *> createCOFFObjectFile(MemoryBuffer *Object,
bool BufferOwned = true);
static ErrorOr<ObjectFile *> createELFObjectFile(MemoryBuffer *Object,
bool BufferOwned = true);
static ErrorOr<ObjectFile *> createMachOObjectFile(MemoryBuffer *Object,
bool BufferOwned = true);
};
// Inline function definitions.