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.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@108661 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/MC/MCParser/ELFAsmParser.cpp b/lib/MC/MCParser/ELFAsmParser.cpp
index 6b9a672..b8103d1 100644
--- a/lib/MC/MCParser/ELFAsmParser.cpp
+++ b/lib/MC/MCParser/ELFAsmParser.cpp
@@ -20,6 +20,12 @@
namespace {
class ELFAsmParser : public MCAsmParserExtension {
+ template<bool (ELFAsmParser::*Handler)(StringRef, SMLoc)>
+ void AddDirectiveHandler(StringRef Directive) {
+ getParser().AddDirectiveHandler(this, Directive,
+ HandleDirective<ELFAsmParser, Handler>);
+ }
+
bool ParseSectionSwitch(StringRef Section, unsigned Type,
unsigned Flags, SectionKind Kind);
@@ -30,18 +36,12 @@
// Call the base implementation.
this->MCAsmParserExtension::Initialize(Parser);
- Parser.AddDirectiveHandler(this, ".data", MCAsmParser::DirectiveHandler(
- &ELFAsmParser::ParseSectionDirectiveData));
- Parser.AddDirectiveHandler(this, ".text", MCAsmParser::DirectiveHandler(
- &ELFAsmParser::ParseSectionDirectiveText));
- Parser.AddDirectiveHandler(this, ".section", MCAsmParser::DirectiveHandler(
- &ELFAsmParser::ParseDirectiveSection));
- Parser.AddDirectiveHandler(this, ".size", MCAsmParser::DirectiveHandler(
- &ELFAsmParser::ParseDirectiveSize));
- Parser.AddDirectiveHandler(this, ".sleb128", MCAsmParser::DirectiveHandler(
- &ELFAsmParser::ParseDirectiveLEB128));
- Parser.AddDirectiveHandler(this, ".uleb128", MCAsmParser::DirectiveHandler(
- &ELFAsmParser::ParseDirectiveLEB128));
+ AddDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveData>(".data");
+ AddDirectiveHandler<&ELFAsmParser::ParseSectionDirectiveText>(".text");
+ AddDirectiveHandler<&ELFAsmParser::ParseDirectiveSection>(".section");
+ AddDirectiveHandler<&ELFAsmParser::ParseDirectiveSize>(".size");
+ AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".sleb128");
+ AddDirectiveHandler<&ELFAsmParser::ParseDirectiveLEB128>(".uleb128");
}
bool ParseSectionDirectiveData(StringRef, SMLoc) {