From efc78986b3bf51572e013bfdf8cbb9e06a47c788 Mon Sep 17 00:00:00 2001 From: Sean Silva Date: Sat, 22 Jun 2013 01:03:35 +0000 Subject: [yaml2obj][ELF] Make this "type switch" actually readable. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@184623 91177308-0d34-0410-b5e6-96231b3b80d8 --- tools/yaml2obj/yaml2elf.cpp | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'tools/yaml2obj/yaml2elf.cpp') diff --git a/tools/yaml2obj/yaml2elf.cpp b/tools/yaml2obj/yaml2elf.cpp index ad7dd1f99e..3ac50334a2 100644 --- a/tools/yaml2obj/yaml2elf.cpp +++ b/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); } } -- cgit v1.2.3