[lld] r265757 - Define a helper function to simplify. NFC.
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 7 17:14:55 PDT 2016
Author: ruiu
Date: Thu Apr 7 19:14:55 2016
New Revision: 265757
URL: http://llvm.org/viewvc/llvm-project?rev=265757&view=rev
Log:
Define a helper function to simplify. NFC.
Modified:
lld/trunk/ELF/InputFiles.cpp
Modified: lld/trunk/ELF/InputFiles.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/InputFiles.cpp?rev=265757&r1=265756&r2=265757&view=diff
==============================================================================
--- lld/trunk/ELF/InputFiles.cpp (original)
+++ lld/trunk/ELF/InputFiles.cpp Thu Apr 7 19:14:55 2016
@@ -553,11 +553,15 @@ static std::unique_ptr<InputFile> create
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<InputFile> elf::createObjectFile(MemoryBufferRef MB,
StringRef ArchiveName) {
- using namespace sys::fs;
std::unique_ptr<InputFile> F;
- if (identify_magic(MB.getBuffer()) == file_magic::bitcode)
+ if (isBitcode(MB))
F.reset(new BitcodeFile(MB));
else
F = createELFFile<ObjectFile>(MB);
@@ -612,19 +616,18 @@ std::vector<StringRef> LazyObjectFile::g
// Returns a vector of globally-visible symbol names.
std::vector<StringRef> 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<unsigned char, unsigned char> 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<ELF32LE>();
return getElfSymbols<ELF32BE>();
}
- if (Type.second == ELF::ELFDATA2LSB)
+ if (Endian == ELFDATA2LSB)
return getElfSymbols<ELF64LE>();
return getElfSymbols<ELF64BE>();
}
More information about the llvm-commits
mailing list