Lines Matching refs:OS

1952                  raw_ostream &OS) {  in emitConvertFuncs()  argument
2284 OS << "enum {\n"; in emitConvertFuncs()
2286 OS << " " << KV.second << ",\n"; in emitConvertFuncs()
2288 OS << "};\n\n"; in emitConvertFuncs()
2290 OS << "static const uint8_t TiedAsmOperandTable[][3] = {\n"; in emitConvertFuncs()
2292 OS << " /* " << KV.second << " */ { " in emitConvertFuncs()
2297 OS << "};\n\n"; in emitConvertFuncs()
2299 OS << "static const uint8_t TiedAsmOperandTable[][3] = " in emitConvertFuncs()
2302 OS << "namespace {\n"; in emitConvertFuncs()
2305 OS << "enum OperatorConversionKind {\n"; in emitConvertFuncs()
2307 OS << " " << Converter << ",\n"; in emitConvertFuncs()
2308 OS << " CVT_NUM_CONVERTERS\n"; in emitConvertFuncs()
2309 OS << "};\n\n"; in emitConvertFuncs()
2312 OS << "enum InstructionConversionKind {\n"; in emitConvertFuncs()
2314 OS << " " << Signature << ",\n"; in emitConvertFuncs()
2315 OS << " CVT_NUM_SIGNATURES\n"; in emitConvertFuncs()
2316 OS << "};\n\n"; in emitConvertFuncs()
2318 OS << "} // end anonymous namespace\n\n"; in emitConvertFuncs()
2321 OS << "static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][" in emitConvertFuncs()
2326 OS << " // " << InstructionConversionKinds[Row] << "\n"; in emitConvertFuncs()
2327 OS << " { "; in emitConvertFuncs()
2329 OS << OperandConversionKinds[ConversionTable[Row][i]] << ", "; in emitConvertFuncs()
2332 OS << (unsigned)(ConversionTable[Row][i + 1]) << ", "; in emitConvertFuncs()
2345 OS << TiedOpndEnum->second << ", "; in emitConvertFuncs()
2348 OS << "CVT_Done },\n"; in emitConvertFuncs()
2351 OS << "};\n\n"; in emitConvertFuncs()
2354 OS << CvtOS.str(); in emitConvertFuncs()
2357 OS << OpOS.str(); in emitConvertFuncs()
2365 raw_ostream &OS) { in emitMatchClassEnumeration() argument
2366 OS << "namespace {\n\n"; in emitMatchClassEnumeration()
2368 OS << "/// MatchClassKind - The kinds of classes which participate in\n" in emitMatchClassEnumeration()
2370 OS << "enum MatchClassKind {\n"; in emitMatchClassEnumeration()
2371 OS << " InvalidMatchClass = 0,\n"; in emitMatchClassEnumeration()
2372 OS << " OptionalMatchClass = 1,\n"; in emitMatchClassEnumeration()
2377 OS << " MCK_LAST_TOKEN = " << LastName << ",\n"; in emitMatchClassEnumeration()
2380 OS << " MCK_LAST_REGISTER = " << LastName << ",\n"; in emitMatchClassEnumeration()
2385 OS << " " << CI.Name << ", // "; in emitMatchClassEnumeration()
2387 OS << "'" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2390 OS << "register class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2392 OS << "derived register class\n"; in emitMatchClassEnumeration()
2394 OS << "user defined class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2397 OS << " NumMatchClassKinds\n"; in emitMatchClassEnumeration()
2398 OS << "};\n\n"; in emitMatchClassEnumeration()
2400 OS << "} // end anonymous namespace\n\n"; in emitMatchClassEnumeration()
2405 static void emitOperandMatchErrorDiagStrings(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandMatchErrorDiagStrings() argument
2413 OS << "static const char *getMatchKindDiag(" << Info.Target.getName() in emitOperandMatchErrorDiagStrings()
2416 OS << " switch (MatchResult) {\n"; in emitOperandMatchErrorDiagStrings()
2422 OS << " case " << Info.Target.getName() in emitOperandMatchErrorDiagStrings()
2424 OS << " return \"" << CI.DiagnosticString << "\";\n"; in emitOperandMatchErrorDiagStrings()
2428 OS << " default:\n"; in emitOperandMatchErrorDiagStrings()
2429 OS << " return nullptr;\n"; in emitOperandMatchErrorDiagStrings()
2431 OS << " }\n"; in emitOperandMatchErrorDiagStrings()
2432 OS << "}\n\n"; in emitOperandMatchErrorDiagStrings()
2435 static void emitRegisterMatchErrorFunc(AsmMatcherInfo &Info, raw_ostream &OS) { in emitRegisterMatchErrorFunc() argument
2436 OS << "static unsigned getDiagKindFromRegisterClass(MatchClassKind " in emitRegisterMatchErrorFunc()
2441 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2443 OS << " switch (RegisterClass) {\n"; in emitRegisterMatchErrorFunc()
2446 OS << " case " << CI.Name << ":\n"; in emitRegisterMatchErrorFunc()
2447 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitRegisterMatchErrorFunc()
2452 OS << " default:\n"; in emitRegisterMatchErrorFunc()
2453 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2455 OS << " }\n"; in emitRegisterMatchErrorFunc()
2457 OS << "}\n\n"; in emitRegisterMatchErrorFunc()
2462 raw_ostream &OS) { in emitValidateOperandClass() argument
2463 OS << "static unsigned validateOperandClass(MCParsedAsmOperand &GOp, " in emitValidateOperandClass()
2465 OS << " " << Info.Target.getName() << "Operand &Operand = (" in emitValidateOperandClass()
2469 OS << " if (Kind == InvalidMatchClass)\n"; in emitValidateOperandClass()
2470 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n\n"; in emitValidateOperandClass()
2474 OS << " if (Operand.isToken() && Kind <= MCK_LAST_TOKEN)\n"; in emitValidateOperandClass()
2475 OS << " return isSubclass(matchTokenString(Operand.getToken()), Kind) ?\n" in emitValidateOperandClass()
2481 OS << " switch (Kind) {\n" in emitValidateOperandClass()
2487 OS << " // '" << CI.ClassName << "' class\n"; in emitValidateOperandClass()
2488 OS << " case " << CI.Name << ": {\n"; in emitValidateOperandClass()
2489 OS << " DiagnosticPredicate DP(Operand." << CI.PredicateMethod in emitValidateOperandClass()
2491 OS << " if (DP.isMatch())\n"; in emitValidateOperandClass()
2492 OS << " return MCTargetAsmParser::Match_Success;\n"; in emitValidateOperandClass()
2494 OS << " if (DP.isNearMatch())\n"; in emitValidateOperandClass()
2495 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitValidateOperandClass()
2497 OS << " break;\n"; in emitValidateOperandClass()
2500 OS << " break;\n"; in emitValidateOperandClass()
2501 OS << " }\n"; in emitValidateOperandClass()
2503 OS << " } // end switch (Kind)\n\n"; in emitValidateOperandClass()
2506 OS << " if (Operand.isReg()) {\n"; in emitValidateOperandClass()
2507 OS << " MatchClassKind OpKind;\n"; in emitValidateOperandClass()
2508 OS << " switch (Operand.getReg()) {\n"; in emitValidateOperandClass()
2509 OS << " default: OpKind = InvalidMatchClass; break;\n"; in emitValidateOperandClass()
2511 OS << " case " << RC.first->getValueAsString("Namespace") << "::" in emitValidateOperandClass()
2514 OS << " }\n"; in emitValidateOperandClass()
2515 OS << " return isSubclass(OpKind, Kind) ? " in emitValidateOperandClass()
2520 OS << " if (Kind > MCK_LAST_TOKEN && Kind <= MCK_LAST_REGISTER)\n"; in emitValidateOperandClass()
2521 OS << " return getDiagKindFromRegisterClass(Kind);\n\n"; in emitValidateOperandClass()
2525 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitValidateOperandClass()
2526 OS << "}\n\n"; in emitValidateOperandClass()
2532 raw_ostream &OS) { in emitIsSubclass() argument
2533 OS << "/// isSubclass - Compute whether \\p A is a subclass of \\p B.\n"; in emitIsSubclass()
2534 OS << "static bool isSubclass(MatchClassKind A, MatchClassKind B) {\n"; in emitIsSubclass()
2535 OS << " if (A == B)\n"; in emitIsSubclass()
2536 OS << " return true;\n\n"; in emitIsSubclass()
2553 OS << " switch (A) {\n"; in emitIsSubclass()
2554 OS << " default:\n"; in emitIsSubclass()
2555 OS << " return false;\n"; in emitIsSubclass()
2559 OS << "\n case " << A.Name << ":\n"; in emitIsSubclass()
2562 OS << " return B == " << SuperClasses.back() << ";\n"; in emitIsSubclass()
2567 OS << " switch (B) {\n"; in emitIsSubclass()
2568 OS << " default: return false;\n"; in emitIsSubclass()
2570 OS << " case " << SC << ": return true;\n"; in emitIsSubclass()
2571 OS << " }\n"; in emitIsSubclass()
2574 OS << " return false;\n"; in emitIsSubclass()
2581 OS << " }\n"; in emitIsSubclass()
2583 OS << " return false;\n"; in emitIsSubclass()
2585 OS << "}\n\n"; in emitIsSubclass()
2592 raw_ostream &OS) { in emitMatchTokenString() argument
2600 OS << "static MatchClassKind matchTokenString(StringRef Name) {\n"; in emitMatchTokenString()
2602 StringMatcher("Name", Matches, OS).Emit(); in emitMatchTokenString()
2604 OS << " return InvalidMatchClass;\n"; in emitMatchTokenString()
2605 OS << "}\n\n"; in emitMatchTokenString()
2611 raw_ostream &OS) { in emitMatchRegisterName() argument
2623 OS << "static unsigned MatchRegisterName(StringRef Name) {\n"; in emitMatchRegisterName()
2627 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterName()
2629 OS << " return 0;\n"; in emitMatchRegisterName()
2630 OS << "}\n\n"; in emitMatchRegisterName()
2636 raw_ostream &OS) { in emitMatchRegisterAltName() argument
2656 OS << "static unsigned MatchRegisterAltName(StringRef Name) {\n"; in emitMatchRegisterAltName()
2660 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterAltName()
2662 OS << " return 0;\n"; in emitMatchRegisterAltName()
2663 OS << "}\n\n"; in emitMatchRegisterAltName()
2667 static void emitOperandDiagnosticTypes(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandDiagnosticTypes() argument
2683 OS << " Match_" << Type << ",\n"; in emitOperandDiagnosticTypes()
2684 OS << " END_OPERAND_DIAGNOSTIC_TYPES\n"; in emitOperandDiagnosticTypes()
2689 static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) { in emitGetSubtargetFeatureName() argument
2690 OS << "// User-level names for subtarget features that participate in\n" in emitGetSubtargetFeatureName()
2694 OS << " switch(Val) {\n"; in emitGetSubtargetFeatureName()
2698 OS << " case " << SFI.getEnumBitName() << ": return \"" in emitGetSubtargetFeatureName()
2701 OS << " default: return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2702 OS << " }\n"; in emitGetSubtargetFeatureName()
2705 OS << " return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2707 OS << "}\n\n"; in emitGetSubtargetFeatureName()
2734 static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info, in emitMnemonicAliasVariant() argument
2810 StringMatcher("Mnemonic", Cases, OS).Emit(Indent); in emitMnemonicAliasVariant()
2815 static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info, in emitMnemonicAliases() argument
2825 OS << "static void applyMnemonicAliases(StringRef &Mnemonic, " in emitMnemonicAliases()
2827 OS << " switch (VariantID) {\n"; in emitMnemonicAliases()
2833 OS << " case " << AsmParserVariantNo << ":\n"; in emitMnemonicAliases()
2834 emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2, in emitMnemonicAliases()
2836 OS << " break;\n"; in emitMnemonicAliases()
2838 OS << " }\n"; in emitMnemonicAliases()
2841 emitMnemonicAliasVariant(OS, Info, Aliases); in emitMnemonicAliases()
2843 OS << "}\n\n"; in emitMnemonicAliases()
2849 emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, in emitCustomOperandParsing() argument
2860 OS << "namespace {\n"; in emitCustomOperandParsing()
2861 OS << " struct OperandMatchEntry {\n"; in emitCustomOperandParsing()
2862 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in emitCustomOperandParsing()
2864 OS << " " << getMinimalTypeForRange(MaxMask) in emitCustomOperandParsing()
2866 OS << " " << getMinimalTypeForRange(std::distance( in emitCustomOperandParsing()
2868 OS << " " << getMinimalTypeForRange(MaxFeaturesIndex) in emitCustomOperandParsing()
2870 OS << " StringRef getMnemonic() const {\n"; in emitCustomOperandParsing()
2871 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in emitCustomOperandParsing()
2872 OS << " MnemonicTable[Mnemonic]);\n"; in emitCustomOperandParsing()
2873 OS << " }\n"; in emitCustomOperandParsing()
2874 OS << " };\n\n"; in emitCustomOperandParsing()
2876 OS << " // Predicate for searching for an opcode.\n"; in emitCustomOperandParsing()
2877 OS << " struct LessOpcodeOperand {\n"; in emitCustomOperandParsing()
2878 OS << " bool operator()(const OperandMatchEntry &LHS, StringRef RHS) {\n"; in emitCustomOperandParsing()
2879 OS << " return LHS.getMnemonic() < RHS;\n"; in emitCustomOperandParsing()
2880 OS << " }\n"; in emitCustomOperandParsing()
2881 OS << " bool operator()(StringRef LHS, const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2882 OS << " return LHS < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2883 OS << " }\n"; in emitCustomOperandParsing()
2884 OS << " bool operator()(const OperandMatchEntry &LHS,"; in emitCustomOperandParsing()
2885 OS << " const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2886 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2887 OS << " }\n"; in emitCustomOperandParsing()
2888 OS << " };\n"; in emitCustomOperandParsing()
2890 OS << "} // end anonymous namespace\n\n"; in emitCustomOperandParsing()
2892 OS << "static const OperandMatchEntry OperandMatchTable[" in emitCustomOperandParsing()
2895 OS << " /* Operand List Mnemonic, Mask, Operand Class, Features */\n"; in emitCustomOperandParsing()
2899 OS << " { "; in emitCustomOperandParsing()
2903 OS << StringTable.GetOrAddStringOffset(LenMnemonic, false) in emitCustomOperandParsing()
2906 OS << OMI.OperandMask; in emitCustomOperandParsing()
2907 OS << " /* "; in emitCustomOperandParsing()
2911 OS << LS << i; in emitCustomOperandParsing()
2912 OS << " */, "; in emitCustomOperandParsing()
2914 OS << OMI.CI->Name; in emitCustomOperandParsing()
2917 OS << ", AMFBS"; in emitCustomOperandParsing()
2919 OS << "_None"; in emitCustomOperandParsing()
2922 OS << '_' << II.RequiredFeatures[i]->TheDef->getName(); in emitCustomOperandParsing()
2924 OS << " },\n"; in emitCustomOperandParsing()
2926 OS << "};\n\n"; in emitCustomOperandParsing()
2930 OS << "ParseStatus " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2938 OS << " case " << CI.Name << ":\n" in emitCustomOperandParsing()
2942 OS << " default:\n"; in emitCustomOperandParsing()
2943 OS << " return ParseStatus::NoMatch;\n"; in emitCustomOperandParsing()
2944 OS << " }\n"; in emitCustomOperandParsing()
2945 OS << " return ParseStatus::NoMatch;\n"; in emitCustomOperandParsing()
2946 OS << "}\n\n"; in emitCustomOperandParsing()
2951 OS << "ParseStatus " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2957 OS << " // Get the current feature set.\n"; in emitCustomOperandParsing()
2958 OS << " const FeatureBitset &AvailableFeatures = getAvailableFeatures();\n\n"; in emitCustomOperandParsing()
2960 OS << " // Get the next operand index.\n"; in emitCustomOperandParsing()
2961 OS << " unsigned NextOpNum = Operands.size()" in emitCustomOperandParsing()
2965 OS << " // Search the table.\n"; in emitCustomOperandParsing()
2967 OS << " auto MnemonicRange =\n"; in emitCustomOperandParsing()
2968 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2970 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2972 OS << " auto MnemonicRange = std::make_pair(std::begin(OperandMatchTable)," in emitCustomOperandParsing()
2974 OS << " if (!Mnemonic.empty())\n"; in emitCustomOperandParsing()
2975 OS << " MnemonicRange =\n"; in emitCustomOperandParsing()
2976 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2978 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2981 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitCustomOperandParsing()
2982 OS << " return ParseStatus::NoMatch;\n\n"; in emitCustomOperandParsing()
2984 OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n" in emitCustomOperandParsing()
2987 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in emitCustomOperandParsing()
2988 OS << " assert(Mnemonic == it->getMnemonic());\n\n"; in emitCustomOperandParsing()
2991 OS << " // check if the available features match\n"; in emitCustomOperandParsing()
2992 OS << " const FeatureBitset &RequiredFeatures = " in emitCustomOperandParsing()
2994 OS << " if (!ParseForAllFeatures && (AvailableFeatures & " in emitCustomOperandParsing()
2996 OS << " continue;\n\n"; in emitCustomOperandParsing()
2999 OS << " // check if the operand in question has a custom parser.\n"; in emitCustomOperandParsing()
3000 OS << " if (!(it->OperandMask & (1 << NextOpNum)))\n"; in emitCustomOperandParsing()
3001 OS << " continue;\n\n"; in emitCustomOperandParsing()
3007 OS << " // call custom parse method to handle the operand\n"; in emitCustomOperandParsing()
3008 OS << " ParseStatus Result = " << ParserName << "(Operands, it->Class);\n"; in emitCustomOperandParsing()
3009 OS << " if (!Result.isNoMatch())\n"; in emitCustomOperandParsing()
3010 OS << " return Result;\n"; in emitCustomOperandParsing()
3011 OS << " }\n\n"; in emitCustomOperandParsing()
3013 OS << " // Okay, we had no match.\n"; in emitCustomOperandParsing()
3014 OS << " return ParseStatus::NoMatch;\n"; in emitCustomOperandParsing()
3015 OS << "}\n\n"; in emitCustomOperandParsing()
3020 raw_ostream &OS) { in emitAsmTiedOperandConstraints() argument
3023 OS << "static bool "; in emitAsmTiedOperandConstraints()
3024 OS << "checkAsmTiedOperandConstraints(const " << Target.getName() in emitAsmTiedOperandConstraints()
3026 OS << " unsigned Kind,\n"; in emitAsmTiedOperandConstraints()
3027 OS << " const OperandVector &Operands,\n"; in emitAsmTiedOperandConstraints()
3028 OS << " uint64_t &ErrorInfo) {\n"; in emitAsmTiedOperandConstraints()
3029 OS << " assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n"; in emitAsmTiedOperandConstraints()
3030 OS << " const uint8_t *Converter = ConversionTable[Kind];\n"; in emitAsmTiedOperandConstraints()
3031 OS << " for (const uint8_t *p = Converter; *p; p += 2) {\n"; in emitAsmTiedOperandConstraints()
3032 OS << " switch (*p) {\n"; in emitAsmTiedOperandConstraints()
3033 OS << " case CVT_Tied: {\n"; in emitAsmTiedOperandConstraints()
3034 OS << " unsigned OpIdx = *(p + 1);\n"; in emitAsmTiedOperandConstraints()
3035 OS << " assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -\n"; in emitAsmTiedOperandConstraints()
3036 OS << " std::begin(TiedAsmOperandTable)) &&\n"; in emitAsmTiedOperandConstraints()
3037 OS << " \"Tied operand not found\");\n"; in emitAsmTiedOperandConstraints()
3038 OS << " unsigned OpndNum1 = TiedAsmOperandTable[OpIdx][1];\n"; in emitAsmTiedOperandConstraints()
3039 OS << " unsigned OpndNum2 = TiedAsmOperandTable[OpIdx][2];\n"; in emitAsmTiedOperandConstraints()
3040 OS << " if (OpndNum1 != OpndNum2) {\n"; in emitAsmTiedOperandConstraints()
3041 OS << " auto &SrcOp1 = Operands[OpndNum1];\n"; in emitAsmTiedOperandConstraints()
3042 OS << " auto &SrcOp2 = Operands[OpndNum2];\n"; in emitAsmTiedOperandConstraints()
3043 OS << " if (!AsmParser.areEqualRegs(*SrcOp1, *SrcOp2)) {\n"; in emitAsmTiedOperandConstraints()
3044 OS << " ErrorInfo = OpndNum2;\n"; in emitAsmTiedOperandConstraints()
3045 OS << " return false;\n"; in emitAsmTiedOperandConstraints()
3046 OS << " }\n"; in emitAsmTiedOperandConstraints()
3047 OS << " }\n"; in emitAsmTiedOperandConstraints()
3048 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3049 OS << " }\n"; in emitAsmTiedOperandConstraints()
3050 OS << " default:\n"; in emitAsmTiedOperandConstraints()
3051 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3052 OS << " }\n"; in emitAsmTiedOperandConstraints()
3053 OS << " }\n"; in emitAsmTiedOperandConstraints()
3054 OS << " return true;\n"; in emitAsmTiedOperandConstraints()
3055 OS << "}\n\n"; in emitAsmTiedOperandConstraints()
3058 static void emitMnemonicSpellChecker(raw_ostream &OS, CodeGenTarget &Target, in emitMnemonicSpellChecker() argument
3060 OS << "static std::string " << Target.getName() in emitMnemonicSpellChecker()
3064 OS << " return \"\";"; in emitMnemonicSpellChecker()
3066 OS << " const unsigned MaxEditDist = 2;\n"; in emitMnemonicSpellChecker()
3067 OS << " std::vector<StringRef> Candidates;\n"; in emitMnemonicSpellChecker()
3068 OS << " StringRef Prev = \"\";\n\n"; in emitMnemonicSpellChecker()
3070 OS << " // Find the appropriate table for this asm variant.\n"; in emitMnemonicSpellChecker()
3071 OS << " const MatchEntry *Start, *End;\n"; in emitMnemonicSpellChecker()
3072 OS << " switch (VariantID) {\n"; in emitMnemonicSpellChecker()
3073 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in emitMnemonicSpellChecker()
3077 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in emitMnemonicSpellChecker()
3080 OS << " }\n\n"; in emitMnemonicSpellChecker()
3081 OS << " for (auto I = Start; I < End; I++) {\n"; in emitMnemonicSpellChecker()
3082 OS << " // Ignore unsupported instructions.\n"; in emitMnemonicSpellChecker()
3083 OS << " const FeatureBitset &RequiredFeatures = " in emitMnemonicSpellChecker()
3085 OS << " if ((FBS & RequiredFeatures) != RequiredFeatures)\n"; in emitMnemonicSpellChecker()
3086 OS << " continue;\n"; in emitMnemonicSpellChecker()
3087 OS << "\n"; in emitMnemonicSpellChecker()
3088 OS << " StringRef T = I->getMnemonic();\n"; in emitMnemonicSpellChecker()
3089 OS << " // Avoid recomputing the edit distance for the same string.\n"; in emitMnemonicSpellChecker()
3090 OS << " if (T.equals(Prev))\n"; in emitMnemonicSpellChecker()
3091 OS << " continue;\n"; in emitMnemonicSpellChecker()
3092 OS << "\n"; in emitMnemonicSpellChecker()
3093 OS << " Prev = T;\n"; in emitMnemonicSpellChecker()
3094 OS << " unsigned Dist = S.edit_distance(T, false, MaxEditDist);\n"; in emitMnemonicSpellChecker()
3095 OS << " if (Dist <= MaxEditDist)\n"; in emitMnemonicSpellChecker()
3096 OS << " Candidates.push_back(T);\n"; in emitMnemonicSpellChecker()
3097 OS << " }\n"; in emitMnemonicSpellChecker()
3098 OS << "\n"; in emitMnemonicSpellChecker()
3099 OS << " if (Candidates.empty())\n"; in emitMnemonicSpellChecker()
3100 OS << " return \"\";\n"; in emitMnemonicSpellChecker()
3101 OS << "\n"; in emitMnemonicSpellChecker()
3102 OS << " std::string Res = \", did you mean: \";\n"; in emitMnemonicSpellChecker()
3103 OS << " unsigned i = 0;\n"; in emitMnemonicSpellChecker()
3104 OS << " for (; i < Candidates.size() - 1; i++)\n"; in emitMnemonicSpellChecker()
3105 OS << " Res += Candidates[i].str() + \", \";\n"; in emitMnemonicSpellChecker()
3106 OS << " return Res + Candidates[i].str() + \"?\";\n"; in emitMnemonicSpellChecker()
3108 OS << "}\n"; in emitMnemonicSpellChecker()
3109 OS << "\n"; in emitMnemonicSpellChecker()
3112 static void emitMnemonicChecker(raw_ostream &OS, in emitMnemonicChecker() argument
3117 OS << "static bool " << Target.getName() in emitMnemonicChecker()
3119 OS << " " in emitMnemonicChecker()
3121 OS << " " in emitMnemonicChecker()
3125 OS << " return false;\n"; in emitMnemonicChecker()
3128 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in emitMnemonicChecker()
3129 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);"; in emitMnemonicChecker()
3130 OS << "\n\n"; in emitMnemonicChecker()
3132 OS << " // Find the appropriate table for this asm variant.\n"; in emitMnemonicChecker()
3133 OS << " const MatchEntry *Start, *End;\n"; in emitMnemonicChecker()
3134 OS << " switch (VariantID) {\n"; in emitMnemonicChecker()
3135 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in emitMnemonicChecker()
3139 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in emitMnemonicChecker()
3142 OS << " }\n\n"; in emitMnemonicChecker()
3144 OS << " // Search the table.\n"; in emitMnemonicChecker()
3146 OS << " auto MnemonicRange = " in emitMnemonicChecker()
3149 OS << " auto MnemonicRange = std::make_pair(Start, End);\n"; in emitMnemonicChecker()
3150 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in emitMnemonicChecker()
3151 OS << " if (!Mnemonic.empty())\n"; in emitMnemonicChecker()
3152 OS << " MnemonicRange = " in emitMnemonicChecker()
3156 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitMnemonicChecker()
3157 OS << " return false;\n\n"; in emitMnemonicChecker()
3159 OS << " for (const MatchEntry *it = MnemonicRange.first, " in emitMnemonicChecker()
3161 OS << " it != ie; ++it) {\n"; in emitMnemonicChecker()
3162 OS << " const FeatureBitset &RequiredFeatures =\n"; in emitMnemonicChecker()
3163 OS << " FeatureBitsets[it->RequiredFeaturesIdx];\n"; in emitMnemonicChecker()
3164 OS << " if ((AvailableFeatures & RequiredFeatures) == "; in emitMnemonicChecker()
3165 OS << "RequiredFeatures)\n"; in emitMnemonicChecker()
3166 OS << " return true;\n"; in emitMnemonicChecker()
3167 OS << " }\n"; in emitMnemonicChecker()
3168 OS << " return false;\n"; in emitMnemonicChecker()
3170 OS << "}\n"; in emitMnemonicChecker()
3171 OS << "\n"; in emitMnemonicChecker()
3176 raw_ostream &OS) { in emitMatchClassKindNames() argument
3177 OS << "#ifndef NDEBUG\n"; in emitMatchClassKindNames()
3178 OS << "const char *getMatchClassName(MatchClassKind Kind) {\n"; in emitMatchClassKindNames()
3179 OS << " switch (Kind) {\n"; in emitMatchClassKindNames()
3181 OS << " case InvalidMatchClass: return \"InvalidMatchClass\";\n"; in emitMatchClassKindNames()
3182 OS << " case OptionalMatchClass: return \"OptionalMatchClass\";\n"; in emitMatchClassKindNames()
3184 OS << " case " << CI.Name << ": return \"" << CI.Name << "\";\n"; in emitMatchClassKindNames()
3186 OS << " case NumMatchClassKinds: return \"NumMatchClassKinds\";\n"; in emitMatchClassKindNames()
3188 OS << " }\n"; in emitMatchClassKindNames()
3189 OS << " llvm_unreachable(\"unhandled MatchClassKind!\");\n"; in emitMatchClassKindNames()
3190 OS << "}\n\n"; in emitMatchClassKindNames()
3191 OS << "#endif // NDEBUG\n"; in emitMatchClassKindNames()
3202 void AsmMatcherEmitter::run(raw_ostream &OS) { in run() argument
3207 emitSourceFileHeader("Assembly Matcher Source Fragment", OS, Records); in run()
3271 OS << "\n#ifdef GET_ASSEMBLER_HEADER\n"; in run()
3272 OS << "#undef GET_ASSEMBLER_HEADER\n"; in run()
3273 OS << " // This should be included into the middle of the declaration of\n"; in run()
3274 OS << " // your subclasses implementation of MCTargetAsmParser.\n"; in run()
3275 OS << " FeatureBitset ComputeAvailableFeatures(const FeatureBitset &FB) const;\n"; in run()
3277 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3282 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3286 OS << " void convertToMapAndConstraints(unsigned Kind,\n "; in run()
3287 OS << " const OperandVector &Operands) override;\n"; in run()
3288 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
3291 OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n"; in run()
3293 OS << " uint64_t &ErrorInfo,\n" in run()
3295 OS << " bool matchingInlineAsm,\n" in run()
3298 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
3310 OS << " ParseStatus MatchOperandParserImpl(\n"; in run()
3311 OS << " OperandVector &Operands,\n"; in run()
3312 OS << " StringRef Mnemonic,\n"; in run()
3313 OS << " bool ParseForAllFeatures = false);\n"; in run()
3315 OS << " ParseStatus tryCustomParseOperand(\n"; in run()
3316 OS << " OperandVector &Operands,\n"; in run()
3317 OS << " unsigned MCK);\n\n"; in run()
3320 OS << "#endif // GET_ASSEMBLER_HEADER\n\n"; in run()
3323 OS << "\n#ifdef GET_OPERAND_DIAGNOSTIC_TYPES\n"; in run()
3324 OS << "#undef GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3325 emitOperandDiagnosticTypes(Info, OS); in run()
3326 OS << "#endif // GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3328 OS << "\n#ifdef GET_REGISTER_MATCHER\n"; in run()
3329 OS << "#undef GET_REGISTER_MATCHER\n\n"; in run()
3333 Info.SubtargetFeatures, OS); in run()
3338 emitMatchRegisterName(Target, AsmParser, OS); in run()
3341 emitMatchRegisterAltName(Target, AsmParser, OS); in run()
3343 OS << "#endif // GET_REGISTER_MATCHER\n\n"; in run()
3345 OS << "\n#ifdef GET_SUBTARGET_FEATURE_NAME\n"; in run()
3346 OS << "#undef GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3349 emitGetSubtargetFeatureName(Info, OS); in run()
3351 OS << "#endif // GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3353 OS << "\n#ifdef GET_MATCHER_IMPLEMENTATION\n"; in run()
3354 OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3357 bool HasMnemonicAliases = emitMnemonicAliases(OS, Info, Target); in run()
3364 HasOptionalOperands, OS); in run()
3367 emitMatchClassEnumeration(Target, Info.Classes, OS); in run()
3371 emitOperandMatchErrorDiagStrings(Info, OS); in run()
3374 emitRegisterMatchErrorFunc(Info, OS); in run()
3377 emitMatchTokenString(Target, Info.Classes, OS); in run()
3380 emitIsSubclass(Target, Info.Classes, OS); in run()
3383 emitValidateOperandClass(Info, OS); in run()
3385 emitMatchClassKindNames(Info.Classes, OS); in run()
3390 Info.SubtargetFeatures, OS); in run()
3393 emitAsmTiedOperandConstraints(Target, Info, OS); in run()
3410 OS << "static const char MnemonicTable[] =\n"; in run()
3411 StringTable.EmitString(OS); in run()
3412 OS << ";\n\n"; in run()
3440 OS << "// Feature bitsets.\n" in run()
3446 OS << " " << getNameForFeatureBitset(FeatureBitset) << ",\n"; in run()
3448 OS << "};\n\n" in run()
3454 OS << " {"; in run()
3458 OS << I->second.getEnumBitName() << ", "; in run()
3460 OS << "},\n"; in run()
3462 OS << "};\n\n"; in run()
3474 OS << "namespace {\n"; in run()
3475 OS << " struct MatchEntry {\n"; in run()
3476 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in run()
3478 OS << " uint16_t Opcode;\n"; in run()
3479 OS << " " << getMinimalTypeForRange(NumConverters) in run()
3481 OS << " " << getMinimalTypeForRange(FeatureBitsets.size()) in run()
3483 OS << " " << getMinimalTypeForRange( in run()
3486 OS << " StringRef getMnemonic() const {\n"; in run()
3487 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in run()
3488 OS << " MnemonicTable[Mnemonic]);\n"; in run()
3489 OS << " }\n"; in run()
3490 OS << " };\n\n"; in run()
3492 OS << " // Predicate for searching for an opcode.\n"; in run()
3493 OS << " struct LessOpcode {\n"; in run()
3494 OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n"; in run()
3495 OS << " return LHS.getMnemonic() < RHS;\n"; in run()
3496 OS << " }\n"; in run()
3497 OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n"; in run()
3498 OS << " return LHS < RHS.getMnemonic();\n"; in run()
3499 OS << " }\n"; in run()
3500 OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n"; in run()
3501 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in run()
3502 OS << " }\n"; in run()
3503 OS << " };\n"; in run()
3505 OS << "} // end anonymous namespace\n\n"; in run()
3512 OS << "static const MatchEntry MatchTable" << VC << "[] = {\n"; in run()
3521 OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in run()
3528 OS << "AMFBS"; in run()
3530 OS << "_None"; in run()
3533 OS << '_' << MI->RequiredFeatures[i]->TheDef->getName(); in run()
3535 OS << ", { "; in run()
3538 OS << LS << Op.Class->Name; in run()
3539 OS << " }, },\n"; in run()
3542 OS << "};\n\n"; in run()
3545 OS << "#include \"llvm/Support/Debug.h\"\n"; in run()
3546 OS << "#include \"llvm/Support/Format.h\"\n\n"; in run()
3549 OS << "unsigned " << Target.getName() << ClassName << "::\n" in run()
3551 OS << " MCInst &Inst,\n"; in run()
3553 OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n"; in run()
3555 OS << " uint64_t &ErrorInfo,\n" in run()
3557 OS << " bool matchingInlineAsm, unsigned VariantID) {\n"; in run()
3560 OS << " // Eliminate obvious mismatches.\n"; in run()
3561 OS << " if (Operands.size() > " in run()
3563 OS << " ErrorInfo = " in run()
3565 OS << " return Match_InvalidOperand;\n"; in run()
3566 OS << " }\n\n"; in run()
3570 OS << " // Get the current feature set.\n"; in run()
3571 OS << " const FeatureBitset &AvailableFeatures = getAvailableFeatures();\n\n"; in run()
3573 OS << " // Get the instruction mnemonic, which is the first token.\n"; in run()
3575 OS << " StringRef Mnemonic = ((" << Target.getName() in run()
3578 OS << " StringRef Mnemonic;\n"; in run()
3579 OS << " if (Operands[0]->isToken())\n"; in run()
3580 OS << " Mnemonic = ((" << Target.getName() in run()
3585 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in run()
3586 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);\n\n"; in run()
3591 OS << " // Some state to try to produce better error messages.\n"; in run()
3592 OS << " bool HadMatchOtherThanFeatures = false;\n"; in run()
3593 OS << " bool HadMatchOtherThanPredicate = false;\n"; in run()
3594 OS << " unsigned RetCode = Match_InvalidOperand;\n"; in run()
3595 OS << " MissingFeatures.set();\n"; in run()
3596 OS << " // Set ErrorInfo to the operand that mismatches if it is\n"; in run()
3597 OS << " // wrong for all instances of the instruction.\n"; in run()
3598 OS << " ErrorInfo = ~0ULL;\n"; in run()
3602 OS << " SmallBitVector OptionalOperandsMask(" << MaxNumOperands << ");\n"; in run()
3606 OS << " // Find the appropriate table for this asm variant.\n"; in run()
3607 OS << " const MatchEntry *Start, *End;\n"; in run()
3608 OS << " switch (VariantID) {\n"; in run()
3609 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in run()
3613 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in run()
3616 OS << " }\n"; in run()
3618 OS << " // Search the table.\n"; in run()
3620 OS << " auto MnemonicRange = " in run()
3623 OS << " auto MnemonicRange = std::make_pair(Start, End);\n"; in run()
3624 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in run()
3625 OS << " if (!Mnemonic.empty())\n"; in run()
3626 OS << " MnemonicRange = " in run()
3630 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"AsmMatcher: found \" <<\n" in run()
3634 OS << " // Return a more specific error code if no mnemonics match.\n"; in run()
3635 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in run()
3636 OS << " return Match_MnemonicFail;\n\n"; in run()
3638 OS << " for (const MatchEntry *it = MnemonicRange.first, " in run()
3640 OS << " it != ie; ++it) {\n"; in run()
3641 OS << " const FeatureBitset &RequiredFeatures = " in run()
3643 OS << " bool HasRequiredFeatures =\n"; in run()
3644 OS << " (AvailableFeatures & RequiredFeatures) == RequiredFeatures;\n"; in run()
3645 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Trying to match opcode \"\n"; in run()
3646 OS << " << MII.getName(it->Opcode) << \"\\n\");\n"; in run()
3649 OS << " // Some state to record ways in which this instruction did not match.\n"; in run()
3650 OS << " NearMissInfo OperandNearMiss = NearMissInfo::getSuccess();\n"; in run()
3651 OS << " NearMissInfo FeaturesNearMiss = NearMissInfo::getSuccess();\n"; in run()
3652 OS << " NearMissInfo EarlyPredicateNearMiss = NearMissInfo::getSuccess();\n"; in run()
3653 OS << " NearMissInfo LatePredicateNearMiss = NearMissInfo::getSuccess();\n"; in run()
3654 OS << " bool MultipleInvalidOperands = false;\n"; in run()
3658 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in run()
3659 OS << " assert(Mnemonic == it->getMnemonic());\n"; in run()
3664 OS << " bool OperandsValid = true;\n"; in run()
3666 OS << " OptionalOperandsMask.reset(0, " << MaxNumOperands << ");\n"; in run()
3668 OS << " for (unsigned FormalIdx = " << (HasMnemonicFirst ? "0" : "SIndex") in run()
3671 OS << " auto Formal = " in run()
3673 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3674OS << " dbgs() << \" Matching formal operand class \" << getMatchClassName(F… in run()
3675 OS << " << \" against actual operand at index \" << ActualIdx);\n"; in run()
3676 OS << " if (ActualIdx < Operands.size())\n"; in run()
3677 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \" (\";\n"; in run()
3678 OS << " Operands[ActualIdx]->print(dbgs()); dbgs() << \"): \");\n"; in run()
3679 OS << " else\n"; in run()
3680 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \": \");\n"; in run()
3681 OS << " if (ActualIdx >= Operands.size()) {\n"; in run()
3682 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"actual operand " in run()
3685 OS << " bool ThisOperandValid = (Formal == " <<"InvalidMatchClass) || " in run()
3687 OS << " if (!ThisOperandValid) {\n"; in run()
3688 OS << " if (!OperandNearMiss) {\n"; in run()
3689 OS << " // Record info about match failure for later use.\n"; in run()
3690OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"recording too-few-operands near mi… in run()
3691 OS << " OperandNearMiss =\n"; in run()
3692 OS << " NearMissInfo::getTooFewOperands(Formal, it->Opcode);\n"; in run()
3693OS << " } else if (OperandNearMiss.getKind() != NearMissInfo::NearMissTooFewOperands) {\n… in run()
3694 OS << " // If more than one operand is invalid, give up on this match entry.\n"; in run()
3695 OS << " DEBUG_WITH_TYPE(\n"; in run()
3696 OS << " \"asm-matcher\",\n"; in run()
3697 OS << " dbgs() << \"second invalid operand, giving up on this opcode\\n\");\n"; in run()
3698 OS << " MultipleInvalidOperands = true;\n"; in run()
3699 OS << " break;\n"; in run()
3700 OS << " }\n"; in run()
3701 OS << " } else {\n"; in run()
3702 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"but formal " in run()
3704 OS << " }\n"; in run()
3705 OS << " continue;\n"; in run()
3707 OS << " if (Formal == InvalidMatchClass) {\n"; in run()
3709 OS << " OptionalOperandsMask.set(FormalIdx, " << MaxNumOperands in run()
3712 OS << " break;\n"; in run()
3713 OS << " }\n"; in run()
3714 OS << " if (isSubclass(Formal, OptionalMatchClass)) {\n"; in run()
3716 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3718 OS << " continue;\n"; in run()
3719 OS << " }\n"; in run()
3720 OS << " OperandsValid = false;\n"; in run()
3721 OS << " ErrorInfo = ActualIdx;\n"; in run()
3722 OS << " break;\n"; in run()
3724 OS << " }\n"; in run()
3725 OS << " MCParsedAsmOperand &Actual = *Operands[ActualIdx];\n"; in run()
3726 OS << " unsigned Diag = validateOperandClass(Actual, Formal);\n"; in run()
3727 OS << " if (Diag == Match_Success) {\n"; in run()
3728 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3729 OS << " dbgs() << \"match success using generic matcher\\n\");\n"; in run()
3730 OS << " ++ActualIdx;\n"; in run()
3731 OS << " continue;\n"; in run()
3732 OS << " }\n"; in run()
3733 OS << " // If the generic handler indicates an invalid operand\n"; in run()
3734 OS << " // failure, check for a special case.\n"; in run()
3735 OS << " if (Diag != Match_Success) {\n"; in run()
3736 OS << " unsigned TargetDiag = validateTargetOperandClass(Actual, Formal);\n"; in run()
3737 OS << " if (TargetDiag == Match_Success) {\n"; in run()
3738 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3739 OS << " dbgs() << \"match success using target matcher\\n\");\n"; in run()
3740 OS << " ++ActualIdx;\n"; in run()
3741 OS << " continue;\n"; in run()
3742 OS << " }\n"; in run()
3743 OS << " // If the target matcher returned a specific error code use\n"; in run()
3744 OS << " // that, else use the one from the generic matcher.\n"; in run()
3745 OS << " if (TargetDiag != Match_InvalidOperand && " in run()
3747 OS << " Diag = TargetDiag;\n"; in run()
3748 OS << " }\n"; in run()
3749 OS << " // If current formal operand wasn't matched and it is optional\n" in run()
3751 OS << " if (Diag == Match_InvalidOperand " in run()
3754 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3756 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"ignoring optional operand\\n\");\n"; in run()
3757 OS << " continue;\n"; in run()
3758 OS << " }\n"; in run()
3761 OS << " if (!OperandNearMiss) {\n"; in run()
3762 OS << " // If this is the first invalid operand we have seen, record some\n"; in run()
3763 OS << " // information about it.\n"; in run()
3764 OS << " DEBUG_WITH_TYPE(\n"; in run()
3765 OS << " \"asm-matcher\",\n"; in run()
3766 OS << " dbgs()\n"; in run()
3767 OS << " << \"operand match failed, recording near-miss with diag code \"\n"; in run()
3768 OS << " << Diag << \"\\n\");\n"; in run()
3769 OS << " OperandNearMiss =\n"; in run()
3770 OS << " NearMissInfo::getMissedOperand(Diag, Formal, it->Opcode, ActualIdx);\n"; in run()
3771 OS << " ++ActualIdx;\n"; in run()
3772 OS << " } else {\n"; in run()
3773 OS << " // If more than one operand is invalid, give up on this match entry.\n"; in run()
3774 OS << " DEBUG_WITH_TYPE(\n"; in run()
3775 OS << " \"asm-matcher\",\n"; in run()
3776 OS << " dbgs() << \"second operand mismatch, skipping this opcode\\n\");\n"; in run()
3777 OS << " MultipleInvalidOperands = true;\n"; in run()
3778 OS << " break;\n"; in run()
3779 OS << " }\n"; in run()
3780 OS << " }\n\n"; in run()
3782 OS << " // If this operand is broken for all of the instances of this\n"; in run()
3783 OS << " // mnemonic, keep track of it so we can report loc info.\n"; in run()
3784 OS << " // If we already had a match that only failed due to a\n"; in run()
3785 OS << " // target predicate, that diagnostic is preferred.\n"; in run()
3786 OS << " if (!HadMatchOtherThanPredicate &&\n"; in run()
3787 OS << " (it == MnemonicRange.first || ErrorInfo <= ActualIdx)) {\n"; in run()
3788 OS << " if (HasRequiredFeatures && (ErrorInfo != ActualIdx || Diag " in run()
3790 OS << " RetCode = Diag;\n"; in run()
3791 OS << " ErrorInfo = ActualIdx;\n"; in run()
3792 OS << " }\n"; in run()
3793 OS << " // Otherwise, just reject this instance of the mnemonic.\n"; in run()
3794 OS << " OperandsValid = false;\n"; in run()
3795 OS << " break;\n"; in run()
3796 OS << " }\n\n"; in run()
3800 OS << " if (MultipleInvalidOperands) {\n"; in run()
3802 OS << " if (!OperandsValid) {\n"; in run()
3803 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3804 OS << " \"operand mismatches, ignoring \"\n"; in run()
3805 OS << " \"this opcode\\n\");\n"; in run()
3806 OS << " continue;\n"; in run()
3807 OS << " }\n"; in run()
3810 OS << " if (!HasRequiredFeatures) {\n"; in run()
3812 OS << " HadMatchOtherThanFeatures = true;\n"; in run()
3813 OS << " FeatureBitset NewMissingFeatures = RequiredFeatures & " in run()
3815 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Missing target features:\";\n"; in run()
3816 OS << " for (unsigned I = 0, E = NewMissingFeatures.size(); I != E; ++I)\n"; in run()
3817 OS << " if (NewMissingFeatures[I])\n"; in run()
3818 OS << " dbgs() << ' ' << I;\n"; in run()
3819 OS << " dbgs() << \"\\n\");\n"; in run()
3821 OS << " FeaturesNearMiss = NearMissInfo::getMissedFeature(NewMissingFeatures);\n"; in run()
3823 OS << " if (NewMissingFeatures.count() <=\n" in run()
3825 OS << " MissingFeatures = NewMissingFeatures;\n"; in run()
3826 OS << " continue;\n"; in run()
3828 OS << " }\n"; in run()
3829 OS << "\n"; in run()
3830 OS << " Inst.clear();\n\n"; in run()
3831 OS << " Inst.setOpcode(it->Opcode);\n"; in run()
3833 OS << " // We have a potential match but have not rendered the operands.\n" in run()
3844 OS << " DEBUG_WITH_TYPE(\n"; in run()
3845 OS << " \"asm-matcher\",\n"; in run()
3846 OS << " dbgs() << \"Early target match predicate failed with diag code \"\n"; in run()
3847 OS << " << MatchResult << \"\\n\");\n"; in run()
3849 OS << " EarlyPredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n"; in run()
3851 OS << " RetCode = MatchResult;\n" in run()
3855 OS << " }\n\n"; in run()
3858 OS << " // If we did not successfully match the operands, then we can't convert to\n"; in run()
3859 OS << " // an MCInst, so bail out on this instruction variant now.\n"; in run()
3860 OS << " if (OperandNearMiss) {\n"; in run()
3861 OS << " // If the operand mismatch was the only problem, reprrt it as a near-miss.\n"; in run()
3862 OS << " if (NearMisses && !FeaturesNearMiss && !EarlyPredicateNearMiss) {\n"; in run()
3863 OS << " DEBUG_WITH_TYPE(\n"; in run()
3864 OS << " \"asm-matcher\",\n"; in run()
3865 OS << " dbgs()\n"; in run()
3866 OS << " << \"Opcode result: one mismatched operand, adding near-miss\\n\");\n"; in run()
3867 OS << " NearMisses->push_back(OperandNearMiss);\n"; in run()
3868 OS << " } else {\n"; in run()
3869 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3870 OS << " \"types of mismatch, so not \"\n"; in run()
3871 OS << " \"reporting near-miss\\n\");\n"; in run()
3872 OS << " }\n"; in run()
3873 OS << " continue;\n"; in run()
3874 OS << " }\n\n"; in run()
3877 OS << " if (matchingInlineAsm) {\n"; in run()
3878 OS << " convertToMapAndConstraints(it->ConvertFn, Operands);\n"; in run()
3880 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3882 OS << " return Match_InvalidTiedOperand;\n"; in run()
3883 OS << "\n"; in run()
3885 OS << " return Match_Success;\n"; in run()
3886 OS << " }\n\n"; in run()
3887 OS << " // We have selected a definite instruction, convert the parsed\n" in run()
3890 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands,\n" in run()
3893 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n"; in run()
3895 OS << "\n"; in run()
3898 OS << " // We have a potential match. Check the target predicate to\n" in run()
3907 OS << " LatePredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n"; in run()
3909 OS << " RetCode = MatchResult;\n" in run()
3913 OS << " }\n\n"; in run()
3916 OS << " int NumNearMisses = ((int)(bool)OperandNearMiss +\n"; in run()
3917 OS << " (int)(bool)FeaturesNearMiss +\n"; in run()
3918 OS << " (int)(bool)EarlyPredicateNearMiss +\n"; in run()
3919 OS << " (int)(bool)LatePredicateNearMiss);\n"; in run()
3920 OS << " if (NumNearMisses == 1) {\n"; in run()
3921 OS << " // We had exactly one type of near-miss, so add that to the list.\n"; in run()
3922 OS << " assert(!OperandNearMiss && \"OperandNearMiss was handled earlier\");\n"; in run()
3923OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: found one type of \"\n"; in run()
3924 OS << " \"mismatch, so reporting a \"\n"; in run()
3925 OS << " \"near-miss\\n\");\n"; in run()
3926 OS << " if (NearMisses && FeaturesNearMiss)\n"; in run()
3927 OS << " NearMisses->push_back(FeaturesNearMiss);\n"; in run()
3928 OS << " else if (NearMisses && EarlyPredicateNearMiss)\n"; in run()
3929 OS << " NearMisses->push_back(EarlyPredicateNearMiss);\n"; in run()
3930 OS << " else if (NearMisses && LatePredicateNearMiss)\n"; in run()
3931 OS << " NearMisses->push_back(LatePredicateNearMiss);\n"; in run()
3932 OS << "\n"; in run()
3933 OS << " continue;\n"; in run()
3934 OS << " } else if (NumNearMisses > 1) {\n"; in run()
3935 OS << " // This instruction missed in more than one way, so ignore it.\n"; in run()
3936 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3937 OS << " \"types of mismatch, so not \"\n"; in run()
3938 OS << " \"reporting near-miss\\n\");\n"; in run()
3939 OS << " continue;\n"; in run()
3940 OS << " }\n"; in run()
3946 OS << " " << InsnCleanupFn << "(Inst);\n"; in run()
3949 OS << " std::string Info;\n"; in run()
3950 OS << " if (!getParser().getTargetParser().getTargetOptions().MCNoDeprecatedWarn &&\n"; in run()
3951 OS << " MII.getDeprecatedInfo(Inst, getSTI(), Info)) {\n"; in run()
3952 OS << " SMLoc Loc = ((" << Target.getName() in run()
3954 OS << " getParser().Warning(Loc, Info, std::nullopt);\n"; in run()
3955 OS << " }\n"; in run()
3959 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3961 OS << " return Match_InvalidTiedOperand;\n"; in run()
3962 OS << "\n"; in run()
3965 OS << " DEBUG_WITH_TYPE(\n"; in run()
3966 OS << " \"asm-matcher\",\n"; in run()
3967 OS << " dbgs() << \"Opcode result: complete match, selecting this opcode\\n\");\n"; in run()
3968 OS << " return Match_Success;\n"; in run()
3969 OS << " }\n\n"; in run()
3972 OS << " // No instruction variants matched exactly.\n"; in run()
3973 OS << " return Match_NearMisses;\n"; in run()
3975 OS << " // Okay, we had no match. Try to return a useful error code.\n"; in run()
3976 OS << " if (HadMatchOtherThanPredicate || !HadMatchOtherThanFeatures)\n"; in run()
3977 OS << " return RetCode;\n\n"; in run()
3978 OS << " ErrorInfo = 0;\n"; in run()
3979 OS << " return Match_MissingFeature;\n"; in run()
3981 OS << "}\n\n"; in run()
3984 emitCustomOperandParsing(OS, Target, Info, ClassName, StringTable, in run()
3988 OS << "#endif // GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3990 OS << "\n#ifdef GET_MNEMONIC_SPELL_CHECKER\n"; in run()
3991 OS << "#undef GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
3993 emitMnemonicSpellChecker(OS, Target, VariantCount); in run()
3995 OS << "#endif // GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
3997 OS << "\n#ifdef GET_MNEMONIC_CHECKER\n"; in run()
3998 OS << "#undef GET_MNEMONIC_CHECKER\n\n"; in run()
4000 emitMnemonicChecker(OS, Target, VariantCount, in run()
4003 OS << "#endif // GET_MNEMONIC_CHECKER\n\n"; in run()