diff options
author | Daniel Dunbar <daniel@zuster.org> | 2010-07-18 22:22:07 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2010-07-18 22:22:07 +0000 |
commit | 8897d479b58228e86c5bc59a1f16edcbc5765141 (patch) | |
tree | 8166e46517cc778453d19a00457d3fb53e7ffbd8 /llvm/lib/MC/MCParser/AsmParser.cpp | |
parent | 76614362206597cd74337812964df3bacf99489d (diff) | |
download | bcm5719-llvm-8897d479b58228e86c5bc59a1f16edcbc5765141.tar.gz bcm5719-llvm-8897d479b58228e86c5bc59a1f16edcbc5765141.zip |
MC/AsmParser: Stop playing unsafe member function pointer calls, this isn't
portable enough.
- Downside is we now double dispatch through a stub function, but this isn't
performance critical.
llvm-svn: 108661
Diffstat (limited to 'llvm/lib/MC/MCParser/AsmParser.cpp')
-rw-r--r-- | llvm/lib/MC/MCParser/AsmParser.cpp | 36 |
1 files changed, 17 insertions, 19 deletions
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp index 1e8f05f1c24..66f46a877d1 100644 --- a/llvm/lib/MC/MCParser/AsmParser.cpp +++ b/llvm/lib/MC/MCParser/AsmParser.cpp @@ -202,6 +202,12 @@ private: /// \brief Generic implementations of directive handling, etc. which is shared /// (or the default, at least) for all assembler parser. class GenericAsmParser : public MCAsmParserExtension { + template<bool (GenericAsmParser::*Handler)(StringRef, SMLoc)> + void AddDirectiveHandler(StringRef Directive) { + getParser().AddDirectiveHandler(this, Directive, + HandleDirective<GenericAsmParser, Handler>); + } + public: GenericAsmParser() {} @@ -214,26 +220,18 @@ public: this->MCAsmParserExtension::Initialize(Parser); // Debugging directives. - Parser.AddDirectiveHandler(this, ".file", MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveFile)); - Parser.AddDirectiveHandler(this, ".line", MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveLine)); - Parser.AddDirectiveHandler(this, ".loc", MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveLoc)); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveFile>(".file"); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveLine>(".line"); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveLoc>(".loc"); // Macro directives. - Parser.AddDirectiveHandler(this, ".macros_on", - MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveMacrosOnOff)); - Parser.AddDirectiveHandler(this, ".macros_off", - MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveMacrosOnOff)); - Parser.AddDirectiveHandler(this, ".macro", MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveMacro)); - Parser.AddDirectiveHandler(this, ".endm", MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveEndMacro)); - Parser.AddDirectiveHandler(this, ".endmacro", MCAsmParser::DirectiveHandler( - &GenericAsmParser::ParseDirectiveEndMacro)); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveMacrosOnOff>( + ".macros_on"); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveMacrosOnOff>( + ".macros_off"); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveMacro>(".macro"); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveEndMacro>(".endm"); + AddDirectiveHandler<&GenericAsmParser::ParseDirectiveEndMacro>(".endmacro"); } bool ParseDirectiveFile(StringRef, SMLoc DirectiveLoc); @@ -875,7 +873,7 @@ bool AsmParser::ParseStatement() { std::pair<MCAsmParserExtension*, DirectiveHandler> Handler = DirectiveMap.lookup(IDVal); if (Handler.first) - return (Handler.first->*Handler.second)(IDVal, IDLoc); + return (*Handler.second)(Handler.first, IDVal, IDLoc); // Target hook for parsing target specific directives. if (!getTargetParser().ParseDirective(ID)) |