[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

llvm-svn: 261317
This commit is contained in:
George Rimar 2016-02-19 10:45:45 +00:00
parent 31088a9d58
commit f23b23200d
1 changed files with 20 additions and 23 deletions

View File

@ -85,7 +85,20 @@ template <class ELFT> bool SectionRule::match(InputSectionBase<ELFT> *S) {
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;
}
}
}