From e93c1add9ea908ee46f4683e7344705ff9fd0d40 Mon Sep 17 00:00:00 2001 From: Bob Wilson Date: Wed, 26 Jan 2011 21:43:46 +0000 Subject: [PATCH] Add a MnemonicIsValid method to the asm matcher. Patch by Bill Wendling. llvm-svn: 124328 --- utils/TableGen/AsmMatcherEmitter.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index 97cc3ff3db6..a04428c4c60 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -1897,6 +1897,7 @@ void AsmMatcherEmitter::run(raw_ostream &OS) { OS << " Match_Success, Match_MnemonicFail, Match_InvalidOperand,\n"; OS << " Match_MissingFeature\n"; OS << " };\n"; + OS << " bool MnemonicIsValid(StringRef Mnemonic);\n"; OS << " MatchResultTy MatchInstructionImpl(\n"; OS << " const SmallVectorImpl &Operands,\n"; OS << " MCInst &Inst, unsigned &ErrorInfo);\n\n"; @@ -2013,6 +2014,16 @@ void AsmMatcherEmitter::run(raw_ostream &OS) { OS << "};\n\n"; + // A method to determine if a mnemonic is in the list. + OS << "bool " << Target.getName() << ClassName << "::\n" + << "MnemonicIsValid(StringRef Mnemonic) {\n"; + OS << " // Search the table.\n"; + OS << " std::pair MnemonicRange =\n"; + OS << " std::equal_range(MatchTable, MatchTable+" + << Info.Matchables.size() << ", Mnemonic, LessOpcode());\n"; + OS << " return MnemonicRange.first != MnemonicRange.second;\n"; + OS << "}\n\n"; + // Finally, build the match function. OS << Target.getName() << ClassName << "::MatchResultTy " << Target.getName() << ClassName << "::\n"