aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRui Ueyama <ruiu@google.com>2016-07-20 19:36:38 +0000
committerRui Ueyama <ruiu@google.com>2016-07-20 19:36:38 +0000
commite54af4a94dea3a1f2e84de337f96d8356e1fdc22 (patch)
tree01fe0bff4875bfc2be262bae03f4d6c704aa5ded
parentf4d0622c083023b91b9926b945c80b7986502bc7 (diff)
Replace parallel arrays with a StringSwitch.
git-svn-id: https://llvm.org/svn/llvm-project/lld/trunk@276163 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--ELF/LinkerScript.cpp33
1 files changed, 18 insertions, 15 deletions
diff --git a/ELF/LinkerScript.cpp b/ELF/LinkerScript.cpp
index a846797e5..1b913680d 100644
--- a/ELF/LinkerScript.cpp
+++ b/ELF/LinkerScript.cpp
@@ -783,23 +783,26 @@ std::vector<StringRef> ScriptParser::readOutputSectionPhdrs() {
}
unsigned ScriptParser::readPhdrType() {
- static const char *typeNames[] = {
- "PT_NULL", "PT_LOAD", "PT_DYNAMIC", "PT_INTERP",
- "PT_NOTE", "PT_SHLIB", "PT_PHDR", "PT_TLS",
- "PT_GNU_EH_FRAME", "PT_GNU_STACK", "PT_GNU_RELRO"};
- static unsigned typeCodes[] = {
- PT_NULL, PT_LOAD, PT_DYNAMIC, PT_INTERP, PT_NOTE, PT_SHLIB,
- PT_PHDR, PT_TLS, PT_GNU_EH_FRAME, PT_GNU_STACK, PT_GNU_RELRO};
-
- unsigned PhdrType = PT_NULL;
StringRef Tok = next();
- auto It = std::find(std::begin(typeNames), std::end(typeNames), Tok);
- if (It != std::end(typeNames))
- PhdrType = typeCodes[std::distance(std::begin(typeNames), It)];
- else
- setError("invalid program header type");
+ unsigned Ret = StringSwitch<unsigned>(Tok)
+ .Case("PT_NULL", PT_NULL)
+ .Case("PT_LOAD", PT_LOAD)
+ .Case("PT_DYNAMIC", PT_DYNAMIC)
+ .Case("PT_INTERP", PT_INTERP)
+ .Case("PT_NOTE", PT_NOTE)
+ .Case("PT_SHLIB", PT_SHLIB)
+ .Case("PT_PHDR", PT_PHDR)
+ .Case("PT_TLS", PT_TLS)
+ .Case("PT_GNU_EH_FRAME", PT_GNU_EH_FRAME)
+ .Case("PT_GNU_STACK", PT_GNU_STACK)
+ .Case("PT_GNU_RELRO", PT_GNU_RELRO)
+ .Default(-1);
- return PhdrType;
+ if (Ret == (unsigned)-1) {
+ setError("invalid program header type: " + Tok);
+ return PT_NULL;
+ }
+ return Ret;
}
static bool isUnderSysroot(StringRef Path) {