aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Object/Binary.cpp
diff options
context:
space:
mode:
authorStephen Hines <srhines@google.com>2014-12-04 19:51:48 +0000
committerAndroid Git Automerger <android-git-automerger@android.com>2014-12-04 19:51:48 +0000
commita21bbdfad461e957fa42ac9d6860ddc9de2da3e9 (patch)
tree8d32ff2094b47e15a8def30d62fd7dee6e009de3 /lib/Object/Binary.cpp
parent6b8c6a5088c221af2b25065b8b6b8b0fec8a116f (diff)
parent876d6995443e99d13696f3941c3a789a4daa7c7a (diff)
downloadexternal_llvm-a21bbdfad461e957fa42ac9d6860ddc9de2da3e9.zip
external_llvm-a21bbdfad461e957fa42ac9d6860ddc9de2da3e9.tar.gz
external_llvm-a21bbdfad461e957fa42ac9d6860ddc9de2da3e9.tar.bz2
am 876d6995: Merge "Update aosp/master LLVM for rebase to r222494."
* commit '876d6995443e99d13696f3941c3a789a4daa7c7a': Update aosp/master LLVM for rebase to r222494.
Diffstat (limited to 'lib/Object/Binary.cpp')
-rw-r--r--lib/Object/Binary.cpp37
1 files changed, 22 insertions, 15 deletions
diff --git a/lib/Object/Binary.cpp b/lib/Object/Binary.cpp
index 9f6a685..c56eeb1 100644
--- a/lib/Object/Binary.cpp
+++ b/lib/Object/Binary.cpp
@@ -27,24 +27,23 @@ using namespace object;
Binary::~Binary() {}
-Binary::Binary(unsigned int Type, std::unique_ptr<MemoryBuffer> Source)
- : TypeID(Type), Data(std::move(Source)) {}
+Binary::Binary(unsigned int Type, MemoryBufferRef Source)
+ : TypeID(Type), Data(Source) {}
-StringRef Binary::getData() const {
- return Data->getBuffer();
-}
+StringRef Binary::getData() const { return Data.getBuffer(); }
-StringRef Binary::getFileName() const {
- return Data->getBufferIdentifier();
-}
+StringRef Binary::getFileName() const { return Data.getBufferIdentifier(); }
+
+MemoryBufferRef Binary::getMemoryBufferRef() const { return Data; }
-ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> &Buffer,
- LLVMContext *Context) {
- sys::fs::file_magic Type = sys::fs::identify_magic(Buffer->getBuffer());
+ErrorOr<std::unique_ptr<Binary>> object::createBinary(MemoryBufferRef Buffer,
+ LLVMContext *Context) {
+ sys::fs::file_magic Type = sys::fs::identify_magic(Buffer.getBuffer());
switch (Type) {
case sys::fs::file_magic::archive:
- return Archive::create(std::move(Buffer));
+ return Archive::create(Buffer);
+ case sys::fs::file_magic::elf:
case sys::fs::file_magic::elf_relocatable:
case sys::fs::file_magic::elf_executable:
case sys::fs::file_magic::elf_shared_object:
@@ -65,7 +64,7 @@ ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> &Buffer,
case sys::fs::file_magic::bitcode:
return ObjectFile::createSymbolicFile(Buffer, Type, Context);
case sys::fs::file_magic::macho_universal_binary:
- return MachOUniversalBinary::create(std::move(Buffer));
+ return MachOUniversalBinary::create(Buffer);
case sys::fs::file_magic::unknown:
case sys::fs::file_magic::windows_resource:
// Unrecognized object file format.
@@ -74,10 +73,18 @@ ErrorOr<Binary *> object::createBinary(std::unique_ptr<MemoryBuffer> &Buffer,
llvm_unreachable("Unexpected Binary File Type");
}
-ErrorOr<Binary *> object::createBinary(StringRef Path) {
+ErrorOr<OwningBinary<Binary>> object::createBinary(StringRef Path) {
ErrorOr<std::unique_ptr<MemoryBuffer>> FileOrErr =
MemoryBuffer::getFileOrSTDIN(Path);
if (std::error_code EC = FileOrErr.getError())
return EC;
- return createBinary(FileOrErr.get());
+ std::unique_ptr<MemoryBuffer> &Buffer = FileOrErr.get();
+
+ ErrorOr<std::unique_ptr<Binary>> BinOrErr =
+ createBinary(Buffer->getMemBufferRef());
+ if (std::error_code EC = BinOrErr.getError())
+ return EC;
+ std::unique_ptr<Binary> &Bin = BinOrErr.get();
+
+ return OwningBinary<Binary>(std::move(Bin), std::move(Buffer));
}