Skip to content

Commit

Permalink
Dispatch without hash table lookup.
Browse files Browse the repository at this point in the history
Cmd used to be the single central place to dispatch. It is not longer
the case because we have a logic for readProvideOrAssignment().
This patch removes the hash table so that evrything is in a single
function. This is slightly verbose but should improve readability.

Differential Revision: https://reviews.llvm.org/D24200

llvm-svn: 280524
  • Loading branch information
rui314 committed Sep 2, 2016
1 parent cd6b12b commit a27eecc
Showing 1 changed file with 25 additions and 19 deletions.
44 changes: 25 additions & 19 deletions lld/ELF/LinkerScript.cpp
Expand Up @@ -620,7 +620,6 @@ class elf::ScriptParser : public ScriptParserBase {
void readExtern();
void readGroup();
void readInclude();
void readNothing() {}
void readOutput();
void readOutputArch();
void readOutputFormat();
Expand Down Expand Up @@ -656,27 +655,11 @@ class elf::ScriptParser : public ScriptParserBase {
void readGlobal(StringRef VerStr);
void readLocal();

const static StringMap<Handler> Cmd;
ScriptConfiguration &Opt = *ScriptConfig;
StringSaver Saver = {ScriptConfig->Alloc};
bool IsUnderSysroot;
};

const StringMap<elf::ScriptParser::Handler> elf::ScriptParser::Cmd = {
{"ENTRY", &ScriptParser::readEntry},
{"EXTERN", &ScriptParser::readExtern},
{"GROUP", &ScriptParser::readGroup},
{"INCLUDE", &ScriptParser::readInclude},
{"INPUT", &ScriptParser::readGroup},
{"OUTPUT", &ScriptParser::readOutput},
{"OUTPUT_ARCH", &ScriptParser::readOutputArch},
{"OUTPUT_FORMAT", &ScriptParser::readOutputFormat},
{"PHDRS", &ScriptParser::readPhdrs},
{"SEARCH_DIR", &ScriptParser::readSearchDir},
{"SECTIONS", &ScriptParser::readSections},
{"VERSION", &ScriptParser::readVersion},
{";", &ScriptParser::readNothing}};

void ScriptParser::readVersionScript() {
readVersionScriptCommand();
if (!atEOF())
Expand Down Expand Up @@ -710,8 +693,31 @@ void ScriptParser::readVersion() {
void ScriptParser::readLinkerScript() {
while (!atEOF()) {
StringRef Tok = next();
if (Handler Fn = Cmd.lookup(Tok)) {
(this->*Fn)();
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 == "PHDRS") {
readPhdrs();
} else if (Tok == "SEARCH_DIR") {
readSearchDir();
} else if (Tok == "SECTIONS") {
readSections();
} else if (Tok == "VERSION") {
readVersion();
} else if (SymbolAssignment *Cmd = readProvideOrAssignment(Tok)) {
if (Opt.HasContents)
Opt.Commands.emplace_back(Cmd);
Expand Down

0 comments on commit a27eecc

Please sign in to comment.