[lld] r272030 - Use StringSwitch. NFC.

Rui Ueyama via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 7 10:55:06 PDT 2016


Author: ruiu
Date: Tue Jun  7 12:55:05 2016
New Revision: 272030

URL: http://llvm.org/viewvc/llvm-project?rev=272030&view=rev
Log:
Use StringSwitch. NFC.

Modified:
    lld/trunk/ELF/Driver.cpp

Modified: lld/trunk/ELF/Driver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/Driver.cpp?rev=272030&r1=272029&r2=272030&view=diff
==============================================================================
--- lld/trunk/ELF/Driver.cpp (original)
+++ lld/trunk/ELF/Driver.cpp Tue Jun  7 12:55:05 2016
@@ -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 *> Ar
   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.




More information about the llvm-commits mailing list