[llvm] r184623 - [yaml2obj][ELF] Make this "type switch" actually readable.
Sean Silva
silvas at purdue.edu
Fri Jun 21 18:03:35 PDT 2013
Author: silvas
Date: Fri Jun 21 20:03:35 2013
New Revision: 184623
URL: http://llvm.org/viewvc/llvm-project?rev=184623&view=rev
Log:
[yaml2obj][ELF] Make this "type switch" actually readable.
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=184623&r1=184622&r2=184623&view=diff
==============================================================================
--- llvm/trunk/tools/yaml2obj/yaml2elf.cpp (original)
+++ llvm/trunk/tools/yaml2obj/yaml2elf.cpp Fri Jun 21 20:03:35 2013
@@ -361,6 +361,14 @@ static int writeELF(raw_ostream &OS, con
return 0;
}
+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::raw_ostream &Out, llvm::MemoryBuffer *Buf) {
yaml::Input YIn(Buf->getBuffer());
ELFYAML::Object Doc;
@@ -369,15 +377,20 @@ int yaml2elf(llvm::raw_ostream &Out, llv
errs() << "yaml2obj: Failed to parse YAML file!\n";
return 1;
}
- if (Doc.Header.Class == ELFYAML::ELF_ELFCLASS(ELF::ELFCLASS64)) {
- if (Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB))
- return writeELF<object::ELFType<support::little, 8, true> >(outs(), Doc);
+ using object::ELFType;
+ typedef ELFType<support::little, 8, true> LE64;
+ typedef ELFType<support::big, 8, true> BE64;
+ typedef ELFType<support::little, 4, false> LE32;
+ typedef ELFType<support::big, 4, false> BE32;
+ if (is64Bit(Doc)) {
+ if (isLittleEndian(Doc))
+ return writeELF<LE64>(outs(), Doc);
else
- return writeELF<object::ELFType<support::big, 8, true> >(outs(), Doc);
+ return writeELF<BE64>(outs(), Doc);
} else {
- if (Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB))
- return writeELF<object::ELFType<support::little, 4, false> >(outs(), Doc);
+ if (isLittleEndian(Doc))
+ return writeELF<LE32>(outs(), Doc);
else
- return writeELF<object::ELFType<support::big, 4, false> >(outs(), Doc);
+ return writeELF<BE32>(outs(), Doc);
}
}
More information about the llvm-commits
mailing list