[llvm] r359445 - [yaml2obj] - Simplify and reduce the code. NFC.
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Mon Apr 29 05:25:02 PDT 2019
Author: grimar
Date: Mon Apr 29 05:25:01 2019
New Revision: 359445
URL: http://llvm.org/viewvc/llvm-project?rev=359445&view=rev
Log:
[yaml2obj] - Simplify and reduce the code. NFC.
This inlines 2 single line static methods
and simplifies the code.
It is also possible to remove the `Is64Bit`
variable since it is used only once,
but I am not sure it will be better for readability.
Modified:
llvm/trunk/tools/yaml2obj/yaml2elf.cpp
Modified: llvm/trunk/tools/yaml2obj/yaml2elf.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/yaml2obj/yaml2elf.cpp?rev=359445&r1=359444&r2=359445&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Mon Apr 29 05:25:01 2019
@@ -933,24 +933,15 @@ std::vector<StringRef> ELFState<ELFT>::i
return {".symtab", ".strtab", ".shstrtab", ".dynsym", ".dynstr"};
}
-static bool is64Bit(const ELFYAML::Object &Doc) {
- return Doc.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
-}
-
-static bool isLittleEndian(const ELFYAML::Object &Doc) {
- return Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
-}
-
int yaml2elf(llvm::ELFYAML::Object &Doc, raw_ostream &Out) {
- if (is64Bit(Doc)) {
- if (isLittleEndian(Doc))
+ bool IsLE = Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB);
+ bool Is64Bit = Doc.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64);
+ if (Is64Bit) {
+ if (IsLE)
return ELFState<object::ELF64LE>::writeELF(Out, Doc);
- else
- return ELFState<object::ELF64BE>::writeELF(Out, Doc);
- } else {
- if (isLittleEndian(Doc))
- return ELFState<object::ELF32LE>::writeELF(Out, Doc);
- else
- return ELFState<object::ELF32BE>::writeELF(Out, Doc);
+ return ELFState<object::ELF64BE>::writeELF(Out, Doc);
}
+ if (IsLE)
+ return ELFState<object::ELF32LE>::writeELF(Out, Doc);
+ return ELFState<object::ELF32BE>::writeELF(Out, Doc);
}
More information about the llvm-commits
mailing list