llvm.org GIT mirror llvm / b412915
MC/AsmParser: Add support for allowing the conversion process to fail (via custom conversion functions). git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@124872 91177308-0d34-0410-b5e6-96231b3b80d8 Daniel Dunbar 9 years ago
4 changed file(s) with 23 addition(s) and 8 deletion(s). Raw diff Collapse all Expand all
13921392 }
13931393 case Match_MnemonicFail:
13941394 return Error(IDLoc, "unrecognized instruction mnemonic");
1395 case Match_ConversionFail:
1396 return Error(IDLoc, "unable to convert operands to instruction");
13951397 }
13961398
13971399 llvm_unreachable("Implement any new match types added!");
333333 return Error(IDLoc, "instruction use requires an option to be enabled");
334334 case Match_MnemonicFail:
335335 return Error(IDLoc, "unrecognized instruction mnemonic");
336 case Match_ConversionFail:
337 return Error(IDLoc, "unable to convert operands to instruction");
336338 case Match_InvalidOperand:
337339 ErrorLoc = IDLoc;
338340 if (ErrorInfo != ~0U) {
841841 case Match_MissingFeature:
842842 Error(IDLoc, "instruction requires a CPU feature not currently enabled");
843843 return true;
844 case Match_ConversionFail:
845 return Error(IDLoc, "unable to convert operands to instruction");
844846 case Match_InvalidOperand:
845847 WasOriginallyInvalidOperand = true;
846848 break;
13671367 std::set GeneratedFns;
13681368
13691369 // Start the unified conversion function.
1370 CvtOS << "static void ConvertToMCInst(ConversionKind Kind, MCInst &Inst, "
1370 CvtOS << "static bool ConvertToMCInst(ConversionKind Kind, MCInst &Inst, "
13711371 << "unsigned Opcode,\n"
13721372 << " const SmallVectorImpl
13731373 << "> &Operands) {\n";
14021402 OS << " " << Signature << ",\n";
14031403
14041404 CvtOS << " case " << Signature << ":\n";
1405 CvtOS << " " << AsmMatchConverter << "(Inst, Opcode, Operands);\n";
1406 CvtOS << " return;\n";
1405 CvtOS << " return " << AsmMatchConverter
1406 << "(Inst, Opcode, Operands);\n";
14071407 continue;
14081408 }
14091409
14781478
14791479 CvtOS << " case " << Signature << ":\n";
14801480 CvtOS << CaseOS.str();
1481 CvtOS << " return;\n";
1481 CvtOS << " return true;\n";
14821482 }
14831483
14841484 // Finish the convert function.
14851485
14861486 CvtOS << " }\n";
1487 CvtOS << " return false;\n";
14871488 CvtOS << "}\n\n";
14881489
14891490 // Finish the enum, and drop the convert function after it.
19131914 OS << " unsigned ComputeAvailableFeatures(const " <<
19141915 Target.getName() << "Subtarget *Subtarget) const;\n";
19151916 OS << " enum MatchResultTy {\n";
1916 OS << " Match_Success, Match_MnemonicFail, Match_InvalidOperand,\n";
1917 OS << " Match_MissingFeature\n";
1917 OS << " Match_ConversionFail,\n";
1918 OS << " Match_InvalidOperand,\n";
1919 OS << " Match_MissingFeature,\n";
1920 OS << " Match_MnemonicFail,\n";
1921 OS << " Match_Success\n";
19181922 OS << " };\n";
19191923 OS << " bool MnemonicIsValid(StringRef Mnemonic);\n";
19201924 OS << " MatchResultTy MatchInstructionImpl(\n";
21312135 OS << " HadMatchOtherThanFeatures = true;\n";
21322136 OS << " continue;\n";
21332137 OS << " }\n";
2134
21352138 OS << "\n";
2136 OS << " ConvertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n";
2139 OS << " // We have selected a definite instruction, convert the parsed\n"
2140 << " // operands into the appropriate MCInst.\n";
2141 OS << " if (!ConvertToMCInst(it->ConvertFn, Inst,\n"
2142 << " it->Opcode, Operands))\n";
2143 OS << " return Match_ConversionFail;\n";
2144 OS << "\n";
2145 OS << " return Match_Success;\n";
21372146
21382147 // Call the post-processing function, if used.
21392148 std::string InsnCleanupFn =