mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-10-02 21:17:17 +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:
@@ -17,8 +17,7 @@
|
||||
namespace llvm {
|
||||
using namespace object;
|
||||
|
||||
static ErrorOr<ObjectFile *> createELFObjectFileAux(MemoryBuffer *Obj,
|
||||
bool BufferOwned) {
|
||||
ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj) {
|
||||
std::pair<unsigned char, unsigned char> Ident = getElfArchType(Obj);
|
||||
std::size_t MaxAlignment =
|
||||
1ULL << countTrailingZeros(uintptr_t(Obj->getBufferStart()));
|
||||
@@ -28,49 +27,41 @@ static ErrorOr<ObjectFile *> createELFObjectFileAux(MemoryBuffer *Obj,
|
||||
if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2LSB)
|
||||
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
||||
if (MaxAlignment >= 4)
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 4, false> >(
|
||||
Obj, EC, BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 4, false>>(Obj, EC));
|
||||
else
|
||||
#endif
|
||||
if (MaxAlignment >= 2)
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 2, false> >(
|
||||
Obj, EC, BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 2, false>>(Obj, EC));
|
||||
else
|
||||
return object_error::parse_failed;
|
||||
else if (Ident.first == ELF::ELFCLASS32 && Ident.second == ELF::ELFDATA2MSB)
|
||||
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
||||
if (MaxAlignment >= 4)
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 4, false> >(Obj, EC,
|
||||
BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 4, false>>(Obj, EC));
|
||||
else
|
||||
#endif
|
||||
if (MaxAlignment >= 2)
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 2, false> >(Obj, EC,
|
||||
BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 2, false>>(Obj, EC));
|
||||
else
|
||||
return object_error::parse_failed;
|
||||
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2MSB)
|
||||
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
||||
if (MaxAlignment >= 8)
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 8, true> >(Obj, EC,
|
||||
BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 8, true>>(Obj, EC));
|
||||
else
|
||||
#endif
|
||||
if (MaxAlignment >= 2)
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 2, true> >(Obj, EC,
|
||||
BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::big, 2, true>>(Obj, EC));
|
||||
else
|
||||
return object_error::parse_failed;
|
||||
else if (Ident.first == ELF::ELFCLASS64 && Ident.second == ELF::ELFDATA2LSB) {
|
||||
#if !LLVM_IS_UNALIGNED_ACCESS_FAST
|
||||
if (MaxAlignment >= 8)
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 8, true> >(
|
||||
Obj, EC, BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 8, true>>(Obj, EC));
|
||||
else
|
||||
#endif
|
||||
if (MaxAlignment >= 2)
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 2, true> >(
|
||||
Obj, EC, BufferOwned));
|
||||
R.reset(new ELFObjectFile<ELFType<support::little, 2, true>>(Obj, EC));
|
||||
else
|
||||
return object_error::parse_failed;
|
||||
}
|
||||
@@ -82,12 +73,4 @@ static ErrorOr<ObjectFile *> createELFObjectFileAux(MemoryBuffer *Obj,
|
||||
return R.release();
|
||||
}
|
||||
|
||||
ErrorOr<ObjectFile *> ObjectFile::createELFObjectFile(MemoryBuffer *Obj,
|
||||
bool BufferOwned) {
|
||||
ErrorOr<ObjectFile *> Ret = createELFObjectFileAux(Obj, BufferOwned);
|
||||
if (BufferOwned && Ret.getError())
|
||||
delete Obj;
|
||||
return Ret;
|
||||
}
|
||||
|
||||
} // end namespace llvm
|
||||
|
Reference in New Issue
Block a user