MC/AsmMatcher: Add support for custom conversion functions.
authorDaniel Dunbar <daniel@zuster.org>
Fri, 4 Feb 2011 17:12:15 +0000 (17:12 +0000)
committerDaniel Dunbar <daniel@zuster.org>
Fri, 4 Feb 2011 17:12:15 +0000 (17:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124870 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Target/Target.td
utils/TableGen/AsmMatcherEmitter.cpp

index 1bc00b610e559e6d39944f10bc670b5b6187e2ab..82628a148b0d708f7cfa47430988bdbc2dcdc3b6 100644 (file)
@@ -248,6 +248,13 @@ class Instruction {
 
   /// Target-specific flags. This becomes the TSFlags field in TargetInstrDesc.
   bits<64> TSFlags = 0;
+
+  ///@name Assembler Parser Support
+  ///@{
+
+  string AsmMatchConverter = "";
+
+  ///@}
 }
 
 /// Predicates - These are extra conditionals which are turned into instruction
index 76904de75137fdcb8c1790af0ef658711025774a..806f5d22246321c878ba7c1b047a52a8a7154073 100644 (file)
@@ -1388,6 +1388,26 @@ static void EmitConvertToMCInst(CodeGenTarget &Target,
          ie = Infos.end(); it != ie; ++it) {
     MatchableInfo &II = **it;
 
+    // Check if we have a custom match function.
+    StringRef AsmMatchConverter = II.getResultInst()->TheDef->getValueAsString(
+      "AsmMatchConverter");
+    if (!AsmMatchConverter.empty()) {
+      std::string Signature = "ConvertCustom_" + AsmMatchConverter.str();
+      II.ConversionFnKind = Signature;
+
+      // Check if we have already generated this signature.
+      if (!GeneratedFns.insert(Signature).second)
+        continue;
+
+      // If not, emit it now.  Add to the enum list.
+      OS << "  " << Signature << ",\n";
+
+      CvtOS << "  case " << Signature << ":\n";
+      CvtOS << "    " << AsmMatchConverter << "(Inst, Opcode, Operands);\n";
+      CvtOS << "    return;\n";
+      continue;
+    }
+
     // Build the conversion function signature.
     std::string Signature = "Convert";
     std::string CaseBody;
@@ -1988,7 +2008,6 @@ void AsmMatcherEmitter::run(raw_ostream &OS) {
        it != ie; ++it) {
     MatchableInfo &II = **it;
 
-
     OS << "  { " << Target.getName() << "::"
        << II.getResultInst()->TheDef->getName() << ", \"" << II.Mnemonic << "\""
        << ", " << II.ConversionFnKind << ", { ";