diff options
author | Chris Lattner <sabre@nondot.org> | 2009-09-27 21:16:52 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2009-09-27 21:16:52 +0000 |
commit | ebb89b418676e5790cb0f385bb6159dd234542ce (patch) | |
tree | 66ead7ba974b9ac8f3ecd4045da041299a85d5fa /tools/llvm-mc/AsmParser.cpp | |
parent | e4172f48cc58bbad6a90325d14ce2497e1aa3c6c (diff) |
add a new DirectiveMap stringmap, which allows more efficient dispatching
to directive handlers and allows for easier extensibility.
I only switched a few over for now.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@82926 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'tools/llvm-mc/AsmParser.cpp')
-rw-r--r-- | tools/llvm-mc/AsmParser.cpp | 32 |
1 files changed, 20 insertions, 12 deletions
diff --git a/tools/llvm-mc/AsmParser.cpp b/tools/llvm-mc/AsmParser.cpp index 1f59e74342..aae27f5d76 100644 --- a/tools/llvm-mc/AsmParser.cpp +++ b/tools/llvm-mc/AsmParser.cpp @@ -32,6 +32,18 @@ using namespace llvm; // TargetLoweringObjectFile. typedef StringMap<const MCSectionMachO*> MachOUniqueMapTy; +AsmParser::AsmParser(SourceMgr &_SM, MCContext &_Ctx, MCStreamer &_Out, + const MCAsmInfo &_MAI) + : Lexer(_SM, _MAI), Ctx(_Ctx), Out(_Out), TargetParser(0), + SectionUniquingMap(0) { + // Debugging directives. + AddDirectiveHandler(".file", &AsmParser::ParseDirectiveFile); + AddDirectiveHandler(".line", &AsmParser::ParseDirectiveLine); + AddDirectiveHandler(".loc", &AsmParser::ParseDirectiveLoc); +} + + + AsmParser::~AsmParser() { // If we have the MachO uniquing map, free it. delete (MachOUniqueMapTy*)SectionUniquingMap; @@ -672,15 +684,11 @@ bool AsmParser::ParseStatement() { if (IDVal == ".load") return ParseDirectiveDarwinDumpOrLoad(IDLoc, /*IsLoad=*/false); - // Debugging directives - - if (IDVal == ".file") - return ParseDirectiveFile(IDLoc); - if (IDVal == ".line") - return ParseDirectiveLine(IDLoc); - if (IDVal == ".loc") - return ParseDirectiveLoc(IDLoc); - + // Look up the handler in the handler table, + bool(AsmParser::*Handler)(StringRef, SMLoc) = DirectiveMap[IDVal]; + if (Handler) + return (this->*Handler)(IDVal, IDLoc); + // Target hook for parsing target specific directives. if (!getTargetParser().ParseDirective(ID)) return false; @@ -1587,7 +1595,7 @@ bool AsmParser::ParseDirectiveEndIf(SMLoc DirectiveLoc) { /// ParseDirectiveFile /// ::= .file [number] string -bool AsmParser::ParseDirectiveFile(SMLoc DirectiveLoc) { +bool AsmParser::ParseDirectiveFile(StringRef, SMLoc DirectiveLoc) { // FIXME: I'm not sure what this is. int64_t FileNumber = -1; if (Lexer.is(AsmToken::Integer)) { @@ -1614,7 +1622,7 @@ bool AsmParser::ParseDirectiveFile(SMLoc DirectiveLoc) { /// ParseDirectiveLine /// ::= .line [number] -bool AsmParser::ParseDirectiveLine(SMLoc DirectiveLoc) { +bool AsmParser::ParseDirectiveLine(StringRef, SMLoc DirectiveLoc) { if (Lexer.isNot(AsmToken::EndOfStatement)) { if (Lexer.isNot(AsmToken::Integer)) return TokError("unexpected token in '.line' directive"); @@ -1635,7 +1643,7 @@ bool AsmParser::ParseDirectiveLine(SMLoc DirectiveLoc) { /// ParseDirectiveLoc /// ::= .loc number [number [number]] -bool AsmParser::ParseDirectiveLoc(SMLoc DirectiveLoc) { +bool AsmParser::ParseDirectiveLoc(StringRef, SMLoc DirectiveLoc) { if (Lexer.isNot(AsmToken::Integer)) return TokError("unexpected token in '.loc' directive"); |