[lld] r261317 - [ELF] - Minor refactor of LinkerScript file
George Rimar via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 19 02:45:45 PST 2016
Author: grimar
Date: Fri Feb 19 04:45:45 2016
New Revision: 261317
URL: http://llvm.org/viewvc/llvm-project?rev=261317&view=rev
Log:
[ELF] - Minor refactor of LinkerScript file
* Else-ifs in ScriptParser::run() replaced with std::function + map
* Reordered members of ScriptParser
Differential revision: http://reviews.llvm.org/D17256
Modified:
lld/trunk/ELF/LinkerScript.cpp
Modified: lld/trunk/ELF/LinkerScript.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/ELF/LinkerScript.cpp?rev=261317&r1=261316&r2=261317&view=diff
==============================================================================
--- lld/trunk/ELF/LinkerScript.cpp (original)
+++ lld/trunk/ELF/LinkerScript.cpp Fri Feb 19 04:45:45 2016
@@ -85,7 +85,20 @@ template <class ELFT> bool SectionRule::
class elf2::ScriptParser {
public:
ScriptParser(BumpPtrAllocator *A, StringRef S, bool B)
- : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {}
+ : Saver(*A), Tokens(tokenize(S)), IsUnderSysroot(B) {
+ Cmd["ENTRY"] = &ScriptParser::readEntry;
+ Cmd["EXTERN"] = &ScriptParser::readExtern;
+ Cmd["GROUP"] = &ScriptParser::readGroup;
+ Cmd["INCLUDE"] = &ScriptParser::readInclude;
+ Cmd["INPUT"] = &ScriptParser::readGroup;
+ Cmd["OUTPUT"] = &ScriptParser::readOutput;
+ Cmd["OUTPUT_ARCH"] = &ScriptParser::readOutputArch;
+ Cmd["OUTPUT_FORMAT"] = &ScriptParser::readOutputFormat;
+ Cmd["SEARCH_DIR"] = &ScriptParser::readSearchDir;
+ Cmd["SECTIONS"] = &ScriptParser::readSections;
+ Cmd[";"] = [](ScriptParser &) {};
+ }
+
void run();
private:
@@ -114,37 +127,21 @@ private:
StringSaver Saver;
std::vector<StringRef> Tokens;
- bool Error = false;
+ llvm::StringMap<std::function<void(ScriptParser &)>> Cmd;
size_t Pos = 0;
bool IsUnderSysroot;
+ bool Error = false;
};
void ScriptParser::run() {
while (!atEOF()) {
StringRef Tok = next();
- if (Tok == ";")
- continue;
- if (Tok == "ENTRY") {
- readEntry();
- } else if (Tok == "EXTERN") {
- readExtern();
- } else if (Tok == "GROUP" || Tok == "INPUT") {
- readGroup();
- } else if (Tok == "INCLUDE") {
- readInclude();
- } else if (Tok == "OUTPUT") {
- readOutput();
- } else if (Tok == "OUTPUT_ARCH") {
- readOutputArch();
- } else if (Tok == "OUTPUT_FORMAT") {
- readOutputFormat();
- } else if (Tok == "SEARCH_DIR") {
- readSearchDir();
- } else if (Tok == "SECTIONS") {
- readSections();
+ auto It = Cmd.find(Tok);
+ if (It != Cmd.end()) {
+ std::function<void(ScriptParser &)> &Handler = It->second;
+ Handler(*this);
} else {
setError("unknown directive: " + Tok);
- return;
}
}
}
More information about the llvm-commits
mailing list