From: Daniel Dunbar Date: Thu, 18 Mar 2010 20:05:56 +0000 (+0000) Subject: MC/AsmMatcher: Add support for target specific "instruction cleanup" functions, X-Git-Url: http://plrg.eecs.uci.edu/git/?a=commitdiff_plain;h=8cc9c0c487128c4d675d45803a0711c3e43534af;p=oota-llvm.git MC/AsmMatcher: Add support for target specific "instruction cleanup" functions, to allow custom post-processing of matched instructions. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@98857 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/llvm/Target/Target.td b/include/llvm/Target/Target.td index 0cffffb88af..c80faf83afd 100644 --- a/include/llvm/Target/Target.td +++ b/include/llvm/Target/Target.td @@ -491,6 +491,11 @@ class AsmParser { // class. Generated AsmParser classes are always prefixed with the target // name. string AsmParserClassName = "AsmParser"; + + // AsmParserInstCleanup - If non-empty, this is the name of a custom function on the + // AsmParser class to call on every matched instruction. This can be used to + // perform target specific instruction post-processing. + string AsmParserInstCleanup = ""; // Variant - AsmParsers can be of multiple different variants. Variants are // used to support targets that need to parser multiple formats for the diff --git a/utils/TableGen/AsmMatcherEmitter.cpp b/utils/TableGen/AsmMatcherEmitter.cpp index b823e57b377..7446ba0efde 100644 --- a/utils/TableGen/AsmMatcherEmitter.cpp +++ b/utils/TableGen/AsmMatcherEmitter.cpp @@ -998,7 +998,7 @@ static void EmitConvertToMCInst(CodeGenTarget &Target, // Start the unified conversion function. - CvtOS << "static bool ConvertToMCInst(ConversionKind Kind, MCInst &Inst, " + CvtOS << "static void ConvertToMCInst(ConversionKind Kind, MCInst &Inst, " << "unsigned Opcode,\n" << " const SmallVectorImpl &Operands) {\n"; @@ -1155,13 +1155,12 @@ static void EmitConvertToMCInst(CodeGenTarget &Target, } } - CvtOS << " break;\n"; + CvtOS << " return;\n"; } // Finish the convert function. CvtOS << " }\n"; - CvtOS << " return false;\n"; CvtOS << "}\n\n"; // Finish the enum, and drop the convert function after it. @@ -1634,8 +1633,15 @@ void AsmMatcherEmitter::run(raw_ostream &OS) { OS << " continue;\n"; } OS << "\n"; - OS << " return ConvertToMCInst(it->ConvertFn, Inst, " - << "it->Opcode, Operands);\n"; + OS << " ConvertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n"; + + // Call the post-processing function, if used. + std::string InsnCleanupFn = + AsmParser->getValueAsString("AsmParserInstCleanup"); + if (!InsnCleanupFn.empty()) + OS << " " << InsnCleanupFn << "(Inst);\n"; + + OS << " return false;\n"; OS << " }\n\n"; OS << " return true;\n";