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
This commit is contained in:
Daniel Dunbar 2010-03-18 20:05:56 +00:00
parent 618d0ed4bc
commit 8cc9c0c487
2 changed files with 16 additions and 5 deletions

View File

@ -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

View File

@ -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<MCParsedAsmOperand*"
<< "> &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";