Skip to content
This repository has been archived by the owner on Apr 23, 2020. It is now read-only.
Permalink
Browse files
Use StringSwitch. NFC.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@272030 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
rui314 committed Jun 7, 2016
1 parent 2681003 commit 6efebfde25df97e3b8f3d4b57dd7a6091c99be24
Showing 1 changed file with 24 additions and 25 deletions.
@@ -20,6 +20,7 @@
#include "Writer.h"
#include "lld/Driver/Driver.h"
#include "llvm/ADT/StringExtras.h"
#include "llvm/ADT/StringSwitch.h"
#include "llvm/Support/TargetSelect.h"
#include "llvm/Support/raw_ostream.h"
#include <utility>
@@ -50,34 +51,32 @@ bool elf::link(ArrayRef<const char *> Args, raw_ostream &Error) {
return !HasError;
}

// Parses a linker -m option.
static std::pair<ELFKind, uint16_t> parseEmulation(StringRef S) {
if (S.endswith("_fbsd"))
S = S.drop_back(5);
if (S == "elf32btsmip")
return {ELF32BEKind, EM_MIPS};
if (S == "elf32ltsmip")
return {ELF32LEKind, EM_MIPS};
if (S == "elf64btsmip")
return {ELF64BEKind, EM_MIPS};
if (S == "elf64ltsmip")
return {ELF64LEKind, EM_MIPS};
if (S == "elf32ppc")
return {ELF32BEKind, EM_PPC};
if (S == "elf64ppc")
return {ELF64BEKind, EM_PPC64};
if (S == "elf_i386")
return {ELF32LEKind, EM_386};
if (S == "elf_x86_64")
return {ELF64LEKind, EM_X86_64};
if (S == "aarch64linux")
return {ELF64LEKind, EM_AARCH64};
if (S == "armelf_linux_eabi")
return {ELF32LEKind, EM_ARM};
if (S == "i386pe" || S == "i386pep" || S == "thumb2pe")
error("Windows targets are not supported on the ELF frontend: " + S);
else
error("unknown emulation: " + S);
return {ELFNoneKind, EM_NONE};

std::pair<ELFKind, uint16_t> Ret =
StringSwitch<std::pair<ELFKind, uint16_t>>(S)
.Case("aarch64linux", {ELF64LEKind, EM_AARCH64})
.Case("armelf_linux_eabi", {ELF32LEKind, EM_ARM})
.Case("elf32btsmip", {ELF32BEKind, EM_MIPS})
.Case("elf32ltsmip", {ELF32LEKind, EM_MIPS})
.Case("elf32ppc", {ELF32BEKind, EM_PPC})
.Case("elf64btsmip", {ELF64BEKind, EM_MIPS})
.Case("elf64ltsmip", {ELF64LEKind, EM_MIPS})
.Case("elf64ppc", {ELF64BEKind, EM_PPC64})
.Case("elf_i386", {ELF32LEKind, EM_386})
.Case("elf_x86_64", {ELF64LEKind, EM_X86_64})
.Default({ELFNoneKind, EM_NONE});

if (Ret.first == ELFNoneKind) {
if (S == "i386pe" || S == "i386pep" || S == "thumb2pe")
error("Windows targets are not supported on the ELF frontend: " + S);
else
error("unknown emulation: " + S);
}
return Ret;
}

// Returns slices of MB by parsing MB as an archive file.

0 comments on commit 6efebfd

Please sign in to comment.