From 11caebaa32bb885af8467f8afda829c88304b646 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Sat, 22 Jun 2013 01:03:35 +0000 Subject: [PATCH] [yaml2obj][ELF] Make this "type switch" actually readable. llvm-svn: 184623 --- llvm/tools/yaml2obj/yaml2elf.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) diff --git a/llvm/tools/yaml2obj/yaml2elf.cpp b/llvm/tools/yaml2obj/yaml2elf.cpp index ad7dd1f99e11..3ac50334a226 100644 --- a/llvm/tools/yaml2obj/yaml2elf.cpp +++ b/llvm/tools/yaml2obj/yaml2elf.cpp @@ -361,6 +361,14 @@ static int writeELF(raw_ostream &OS, const ELFYAML::Object &Doc) { 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, llvm::MemoryBuffer *Buf) { 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 >(outs(), Doc); + using object::ELFType; + typedef ELFType LE64; + typedef ELFType BE64; + typedef ELFType LE32; + typedef ELFType BE32; + if (is64Bit(Doc)) { + if (isLittleEndian(Doc)) + return writeELF(outs(), Doc); else - return writeELF >(outs(), Doc); + return writeELF(outs(), Doc); } else { - if (Doc.Header.Data == ELFYAML::ELF_ELFDATA(ELF::ELFDATA2LSB)) - return writeELF >(outs(), Doc); + if (isLittleEndian(Doc)) + return writeELF(outs(), Doc); else - return writeELF >(outs(), Doc); + return writeELF(outs(), Doc); } }