From 4655ea3ff8e5529d3f25473901b7abff7b487396 Mon Sep 17 00:00:00 2001 From: Rui Ueyama Date: Fri, 8 Apr 2016 00:14:55 +0000 Subject: [PATCH] Define a helper function to simplify. NFC. llvm-svn: 265757 --- lld/ELF/InputFiles.cpp | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/lld/ELF/InputFiles.cpp b/lld/ELF/InputFiles.cpp index 1aa03189dcc0..cbade03cf70d 100644 --- a/lld/ELF/InputFiles.cpp +++ b/lld/ELF/InputFiles.cpp @@ -553,11 +553,15 @@ static std::unique_ptr createELFFile(MemoryBufferRef MB) { fatal("invalid file class: " + MB.getBufferIdentifier()); } +static bool isBitcode(MemoryBufferRef MB) { + using namespace sys::fs; + return identify_magic(MB.getBuffer()) == file_magic::bitcode; +} + std::unique_ptr elf::createObjectFile(MemoryBufferRef MB, StringRef ArchiveName) { - using namespace sys::fs; std::unique_ptr F; - if (identify_magic(MB.getBuffer()) == file_magic::bitcode) + if (isBitcode(MB)) F.reset(new BitcodeFile(MB)); else F = createELFFile(MB); @@ -612,19 +616,18 @@ std::vector LazyObjectFile::getBitcodeSymbols() { // Returns a vector of globally-visible symbol names. std::vector LazyObjectFile::getSymbols() { - using namespace sys::fs; - - StringRef Buf = this->MB.getBuffer(); - if (identify_magic(Buf) == file_magic::bitcode) + if (isBitcode(this->MB)) return getBitcodeSymbols(); - std::pair Type = getElfArchType(Buf); - if (Type.first == ELF::ELFCLASS32) { - if (Type.second == ELF::ELFDATA2LSB) + unsigned char Size; + unsigned char Endian; + std::tie(Size, Endian) = getElfArchType(this->MB.getBuffer()); + if (Size == ELFCLASS32) { + if (Endian == ELFDATA2LSB) return getElfSymbols(); return getElfSymbols(); } - if (Type.second == ELF::ELFDATA2LSB) + if (Endian == ELFDATA2LSB) return getElfSymbols(); return getElfSymbols(); }