mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
Make ObjectFile and BitcodeReader always own the MemoryBuffer.
This allows us to just use a std::unique_ptr to store the pointer to the buffer. The flip side is that they have to support releasing the buffer back to the caller. Overall this looks like a more efficient and less brittle api. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@211542 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -19,15 +19,13 @@
|
||||
using namespace llvm;
|
||||
using namespace object;
|
||||
|
||||
SymbolicFile::SymbolicFile(unsigned int Type, MemoryBuffer *Source,
|
||||
bool BufferOwned)
|
||||
: Binary(Type, Source, BufferOwned) {}
|
||||
SymbolicFile::SymbolicFile(unsigned int Type, MemoryBuffer *Source)
|
||||
: Binary(Type, Source) {}
|
||||
|
||||
SymbolicFile::~SymbolicFile() {}
|
||||
|
||||
ErrorOr<SymbolicFile *>
|
||||
SymbolicFile::createSymbolicFile(MemoryBuffer *Object, bool BufferOwned,
|
||||
sys::fs::file_magic Type,
|
||||
SymbolicFile::createSymbolicFile(MemoryBuffer *Object, sys::fs::file_magic Type,
|
||||
LLVMContext *Context) {
|
||||
if (Type == sys::fs::file_magic::unknown)
|
||||
Type = sys::fs::identify_magic(Object->getBuffer());
|
||||
@@ -35,14 +33,12 @@ SymbolicFile::createSymbolicFile(MemoryBuffer *Object, bool BufferOwned,
|
||||
switch (Type) {
|
||||
case sys::fs::file_magic::bitcode:
|
||||
if (Context)
|
||||
return IRObjectFile::createIRObjectFile(Object, *Context, BufferOwned);
|
||||
return IRObjectFile::createIRObjectFile(Object, *Context);
|
||||
// Fallthrough
|
||||
case sys::fs::file_magic::unknown:
|
||||
case sys::fs::file_magic::archive:
|
||||
case sys::fs::file_magic::macho_universal_binary:
|
||||
case sys::fs::file_magic::windows_resource:
|
||||
if (BufferOwned)
|
||||
delete Object;
|
||||
return object_error::invalid_file_type;
|
||||
case sys::fs::file_magic::elf_relocatable:
|
||||
case sys::fs::file_magic::elf_executable:
|
||||
@@ -61,7 +57,7 @@ SymbolicFile::createSymbolicFile(MemoryBuffer *Object, bool BufferOwned,
|
||||
case sys::fs::file_magic::coff_object:
|
||||
case sys::fs::file_magic::coff_import_library:
|
||||
case sys::fs::file_magic::pecoff_executable:
|
||||
return ObjectFile::createObjectFile(Object, BufferOwned, Type);
|
||||
return ObjectFile::createObjectFile(Object, Type);
|
||||
}
|
||||
llvm_unreachable("Unexpected Binary File Type");
|
||||
}
|
||||
|
Reference in New Issue
Block a user