Lines Matching refs:OS

1942                  raw_ostream &OS) {  in emitConvertFuncs()  argument
2274 OS << "enum {\n"; in emitConvertFuncs()
2276 OS << " " << KV.second << ",\n"; in emitConvertFuncs()
2278 OS << "};\n\n"; in emitConvertFuncs()
2280 OS << "static const uint8_t TiedAsmOperandTable[][3] = {\n"; in emitConvertFuncs()
2282 OS << " /* " << KV.second << " */ { " in emitConvertFuncs()
2287 OS << "};\n\n"; in emitConvertFuncs()
2289 OS << "static const uint8_t TiedAsmOperandTable[][3] = " in emitConvertFuncs()
2292 OS << "namespace {\n"; in emitConvertFuncs()
2295 OS << "enum OperatorConversionKind {\n"; in emitConvertFuncs()
2297 OS << " " << Converter << ",\n"; in emitConvertFuncs()
2298 OS << " CVT_NUM_CONVERTERS\n"; in emitConvertFuncs()
2299 OS << "};\n\n"; in emitConvertFuncs()
2302 OS << "enum InstructionConversionKind {\n"; in emitConvertFuncs()
2304 OS << " " << Signature << ",\n"; in emitConvertFuncs()
2305 OS << " CVT_NUM_SIGNATURES\n"; in emitConvertFuncs()
2306 OS << "};\n\n"; in emitConvertFuncs()
2308 OS << "} // end anonymous namespace\n\n"; in emitConvertFuncs()
2311 OS << "static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][" in emitConvertFuncs()
2316 OS << " // " << InstructionConversionKinds[Row] << "\n"; in emitConvertFuncs()
2317 OS << " { "; in emitConvertFuncs()
2319 OS << OperandConversionKinds[ConversionTable[Row][i]] << ", "; in emitConvertFuncs()
2322 OS << (unsigned)(ConversionTable[Row][i + 1]) << ", "; in emitConvertFuncs()
2335 OS << TiedOpndEnum->second << ", "; in emitConvertFuncs()
2338 OS << "CVT_Done },\n"; in emitConvertFuncs()
2341 OS << "};\n\n"; in emitConvertFuncs()
2344 OS << CvtOS.str(); in emitConvertFuncs()
2347 OS << OpOS.str(); in emitConvertFuncs()
2355 raw_ostream &OS) { in emitMatchClassEnumeration() argument
2356 OS << "namespace {\n\n"; in emitMatchClassEnumeration()
2358 OS << "/// MatchClassKind - The kinds of classes which participate in\n" in emitMatchClassEnumeration()
2360 OS << "enum MatchClassKind {\n"; in emitMatchClassEnumeration()
2361 OS << " InvalidMatchClass = 0,\n"; in emitMatchClassEnumeration()
2362 OS << " OptionalMatchClass = 1,\n"; in emitMatchClassEnumeration()
2367 OS << " MCK_LAST_TOKEN = " << LastName << ",\n"; in emitMatchClassEnumeration()
2370 OS << " MCK_LAST_REGISTER = " << LastName << ",\n"; in emitMatchClassEnumeration()
2375 OS << " " << CI.Name << ", // "; in emitMatchClassEnumeration()
2377 OS << "'" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2380 OS << "register class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2382 OS << "derived register class\n"; in emitMatchClassEnumeration()
2384 OS << "user defined class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2387 OS << " NumMatchClassKinds\n"; in emitMatchClassEnumeration()
2388 OS << "};\n\n"; in emitMatchClassEnumeration()
2390 OS << "} // end anonymous namespace\n\n"; in emitMatchClassEnumeration()
2395 static void emitOperandMatchErrorDiagStrings(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandMatchErrorDiagStrings() argument
2403 OS << "static const char *getMatchKindDiag(" << Info.Target.getName() in emitOperandMatchErrorDiagStrings()
2406 OS << " switch (MatchResult) {\n"; in emitOperandMatchErrorDiagStrings()
2412 OS << " case " << Info.Target.getName() in emitOperandMatchErrorDiagStrings()
2414 OS << " return \"" << CI.DiagnosticString << "\";\n"; in emitOperandMatchErrorDiagStrings()
2418 OS << " default:\n"; in emitOperandMatchErrorDiagStrings()
2419 OS << " return nullptr;\n"; in emitOperandMatchErrorDiagStrings()
2421 OS << " }\n"; in emitOperandMatchErrorDiagStrings()
2422 OS << "}\n\n"; in emitOperandMatchErrorDiagStrings()
2425 static void emitRegisterMatchErrorFunc(AsmMatcherInfo &Info, raw_ostream &OS) { in emitRegisterMatchErrorFunc() argument
2426 OS << "static unsigned getDiagKindFromRegisterClass(MatchClassKind " in emitRegisterMatchErrorFunc()
2431 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2433 OS << " switch (RegisterClass) {\n"; in emitRegisterMatchErrorFunc()
2436 OS << " case " << CI.Name << ":\n"; in emitRegisterMatchErrorFunc()
2437 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitRegisterMatchErrorFunc()
2442 OS << " default:\n"; in emitRegisterMatchErrorFunc()
2443 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2445 OS << " }\n"; in emitRegisterMatchErrorFunc()
2447 OS << "}\n\n"; in emitRegisterMatchErrorFunc()
2452 raw_ostream &OS) { in emitValidateOperandClass() argument
2453 OS << "static unsigned validateOperandClass(MCParsedAsmOperand &GOp, " in emitValidateOperandClass()
2455 OS << " " << Info.Target.getName() << "Operand &Operand = (" in emitValidateOperandClass()
2459 OS << " if (Kind == InvalidMatchClass)\n"; in emitValidateOperandClass()
2460 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n\n"; in emitValidateOperandClass()
2464 OS << " if (Operand.isToken() && Kind <= MCK_LAST_TOKEN)\n"; in emitValidateOperandClass()
2465 OS << " return isSubclass(matchTokenString(Operand.getToken()), Kind) ?\n" in emitValidateOperandClass()
2471 OS << " switch (Kind) {\n" in emitValidateOperandClass()
2477 OS << " // '" << CI.ClassName << "' class\n"; in emitValidateOperandClass()
2478 OS << " case " << CI.Name << ": {\n"; in emitValidateOperandClass()
2479 OS << " DiagnosticPredicate DP(Operand." << CI.PredicateMethod in emitValidateOperandClass()
2481 OS << " if (DP.isMatch())\n"; in emitValidateOperandClass()
2482 OS << " return MCTargetAsmParser::Match_Success;\n"; in emitValidateOperandClass()
2484 OS << " if (DP.isNearMatch())\n"; in emitValidateOperandClass()
2485 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitValidateOperandClass()
2487 OS << " break;\n"; in emitValidateOperandClass()
2490 OS << " break;\n"; in emitValidateOperandClass()
2491 OS << " }\n"; in emitValidateOperandClass()
2493 OS << " } // end switch (Kind)\n\n"; in emitValidateOperandClass()
2496 OS << " if (Operand.isReg()) {\n"; in emitValidateOperandClass()
2497 OS << " MatchClassKind OpKind;\n"; in emitValidateOperandClass()
2498 OS << " switch (Operand.getReg()) {\n"; in emitValidateOperandClass()
2499 OS << " default: OpKind = InvalidMatchClass; break;\n"; in emitValidateOperandClass()
2501 OS << " case " << RC.first->getValueAsString("Namespace") << "::" in emitValidateOperandClass()
2504 OS << " }\n"; in emitValidateOperandClass()
2505 OS << " return isSubclass(OpKind, Kind) ? " in emitValidateOperandClass()
2510 OS << " if (Kind > MCK_LAST_TOKEN && Kind <= MCK_LAST_REGISTER)\n"; in emitValidateOperandClass()
2511 OS << " return getDiagKindFromRegisterClass(Kind);\n\n"; in emitValidateOperandClass()
2515 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitValidateOperandClass()
2516 OS << "}\n\n"; in emitValidateOperandClass()
2522 raw_ostream &OS) { in emitIsSubclass() argument
2523 OS << "/// isSubclass - Compute whether \\p A is a subclass of \\p B.\n"; in emitIsSubclass()
2524 OS << "static bool isSubclass(MatchClassKind A, MatchClassKind B) {\n"; in emitIsSubclass()
2525 OS << " if (A == B)\n"; in emitIsSubclass()
2526 OS << " return true;\n\n"; in emitIsSubclass()
2543 OS << " switch (A) {\n"; in emitIsSubclass()
2544 OS << " default:\n"; in emitIsSubclass()
2545 OS << " return false;\n"; in emitIsSubclass()
2549 OS << "\n case " << A.Name << ":\n"; in emitIsSubclass()
2552 OS << " return B == " << SuperClasses.back() << ";\n"; in emitIsSubclass()
2557 OS << " switch (B) {\n"; in emitIsSubclass()
2558 OS << " default: return false;\n"; in emitIsSubclass()
2560 OS << " case " << SC << ": return true;\n"; in emitIsSubclass()
2561 OS << " }\n"; in emitIsSubclass()
2564 OS << " return false;\n"; in emitIsSubclass()
2571 OS << " }\n"; in emitIsSubclass()
2573 OS << " return false;\n"; in emitIsSubclass()
2575 OS << "}\n\n"; in emitIsSubclass()
2582 raw_ostream &OS) { in emitMatchTokenString() argument
2590 OS << "static MatchClassKind matchTokenString(StringRef Name) {\n"; in emitMatchTokenString()
2592 StringMatcher("Name", Matches, OS).Emit(); in emitMatchTokenString()
2594 OS << " return InvalidMatchClass;\n"; in emitMatchTokenString()
2595 OS << "}\n\n"; in emitMatchTokenString()
2601 raw_ostream &OS) { in emitMatchRegisterName() argument
2613 OS << "static unsigned MatchRegisterName(StringRef Name) {\n"; in emitMatchRegisterName()
2617 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterName()
2619 OS << " return 0;\n"; in emitMatchRegisterName()
2620 OS << "}\n\n"; in emitMatchRegisterName()
2626 raw_ostream &OS) { in emitMatchRegisterAltName() argument
2646 OS << "static unsigned MatchRegisterAltName(StringRef Name) {\n"; in emitMatchRegisterAltName()
2650 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterAltName()
2652 OS << " return 0;\n"; in emitMatchRegisterAltName()
2653 OS << "}\n\n"; in emitMatchRegisterAltName()
2657 static void emitOperandDiagnosticTypes(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandDiagnosticTypes() argument
2673 OS << " Match_" << Type << ",\n"; in emitOperandDiagnosticTypes()
2674 OS << " END_OPERAND_DIAGNOSTIC_TYPES\n"; in emitOperandDiagnosticTypes()
2679 static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) { in emitGetSubtargetFeatureName() argument
2680 OS << "// User-level names for subtarget features that participate in\n" in emitGetSubtargetFeatureName()
2684 OS << " switch(Val) {\n"; in emitGetSubtargetFeatureName()
2688 OS << " case " << SFI.getEnumBitName() << ": return \"" in emitGetSubtargetFeatureName()
2691 OS << " default: return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2692 OS << " }\n"; in emitGetSubtargetFeatureName()
2695 OS << " return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2697 OS << "}\n\n"; in emitGetSubtargetFeatureName()
2724 static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info, in emitMnemonicAliasVariant() argument
2800 StringMatcher("Mnemonic", Cases, OS).Emit(Indent); in emitMnemonicAliasVariant()
2805 static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info, in emitMnemonicAliases() argument
2815 OS << "static void applyMnemonicAliases(StringRef &Mnemonic, " in emitMnemonicAliases()
2817 OS << " switch (VariantID) {\n"; in emitMnemonicAliases()
2823 OS << " case " << AsmParserVariantNo << ":\n"; in emitMnemonicAliases()
2824 emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2, in emitMnemonicAliases()
2826 OS << " break;\n"; in emitMnemonicAliases()
2828 OS << " }\n"; in emitMnemonicAliases()
2831 emitMnemonicAliasVariant(OS, Info, Aliases); in emitMnemonicAliases()
2833 OS << "}\n\n"; in emitMnemonicAliases()
2838 static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, in emitCustomOperandParsing() argument
2850 OS << "namespace {\n"; in emitCustomOperandParsing()
2851 OS << " struct OperandMatchEntry {\n"; in emitCustomOperandParsing()
2852 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in emitCustomOperandParsing()
2854 OS << " " << getMinimalTypeForRange(MaxMask) in emitCustomOperandParsing()
2856 OS << " " << getMinimalTypeForRange(std::distance( in emitCustomOperandParsing()
2858 OS << " " << getMinimalTypeForRange(MaxFeaturesIndex) in emitCustomOperandParsing()
2860 OS << " StringRef getMnemonic() const {\n"; in emitCustomOperandParsing()
2861 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in emitCustomOperandParsing()
2862 OS << " MnemonicTable[Mnemonic]);\n"; in emitCustomOperandParsing()
2863 OS << " }\n"; in emitCustomOperandParsing()
2864 OS << " };\n\n"; in emitCustomOperandParsing()
2866 OS << " // Predicate for searching for an opcode.\n"; in emitCustomOperandParsing()
2867 OS << " struct LessOpcodeOperand {\n"; in emitCustomOperandParsing()
2868 OS << " bool operator()(const OperandMatchEntry &LHS, StringRef RHS) {\n"; in emitCustomOperandParsing()
2869 OS << " return LHS.getMnemonic() < RHS;\n"; in emitCustomOperandParsing()
2870 OS << " }\n"; in emitCustomOperandParsing()
2871 OS << " bool operator()(StringRef LHS, const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2872 OS << " return LHS < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2873 OS << " }\n"; in emitCustomOperandParsing()
2874 OS << " bool operator()(const OperandMatchEntry &LHS,"; in emitCustomOperandParsing()
2875 OS << " const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2876 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2877 OS << " }\n"; in emitCustomOperandParsing()
2878 OS << " };\n"; in emitCustomOperandParsing()
2880 OS << "} // end anonymous namespace\n\n"; in emitCustomOperandParsing()
2882 OS << "static const OperandMatchEntry OperandMatchTable[" in emitCustomOperandParsing()
2885 OS << " /* Operand List Mnemonic, Mask, Operand Class, Features */\n"; in emitCustomOperandParsing()
2889 OS << " { "; in emitCustomOperandParsing()
2893 OS << StringTable.GetOrAddStringOffset(LenMnemonic, false) in emitCustomOperandParsing()
2896 OS << OMI.OperandMask; in emitCustomOperandParsing()
2897 OS << " /* "; in emitCustomOperandParsing()
2901 OS << LS << i; in emitCustomOperandParsing()
2902 OS << " */, "; in emitCustomOperandParsing()
2904 OS << OMI.CI->Name; in emitCustomOperandParsing()
2907 OS << ", AMFBS"; in emitCustomOperandParsing()
2909 OS << "_None"; in emitCustomOperandParsing()
2912 OS << '_' << II.RequiredFeatures[i]->TheDef->getName(); in emitCustomOperandParsing()
2914 OS << " },\n"; in emitCustomOperandParsing()
2916 OS << "};\n\n"; in emitCustomOperandParsing()
2920 OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2928 OS << " case " << CI.Name << ":\n" in emitCustomOperandParsing()
2932 OS << " default:\n"; in emitCustomOperandParsing()
2933 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2934 OS << " }\n"; in emitCustomOperandParsing()
2935 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2936 OS << "}\n\n"; in emitCustomOperandParsing()
2941 OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2947 OS << " // Get the current feature set.\n"; in emitCustomOperandParsing()
2948 OS << " const FeatureBitset &AvailableFeatures = getAvailableFeatures();\n\n"; in emitCustomOperandParsing()
2950 OS << " // Get the next operand index.\n"; in emitCustomOperandParsing()
2951 OS << " unsigned NextOpNum = Operands.size()" in emitCustomOperandParsing()
2955 OS << " // Search the table.\n"; in emitCustomOperandParsing()
2957 OS << " auto MnemonicRange =\n"; in emitCustomOperandParsing()
2958 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2960 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2962 OS << " auto MnemonicRange = std::make_pair(std::begin(OperandMatchTable)," in emitCustomOperandParsing()
2964 OS << " if (!Mnemonic.empty())\n"; in emitCustomOperandParsing()
2965 OS << " MnemonicRange =\n"; in emitCustomOperandParsing()
2966 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2968 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2971 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitCustomOperandParsing()
2972 OS << " return MatchOperand_NoMatch;\n\n"; in emitCustomOperandParsing()
2974 OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n" in emitCustomOperandParsing()
2977 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in emitCustomOperandParsing()
2978 OS << " assert(Mnemonic == it->getMnemonic());\n\n"; in emitCustomOperandParsing()
2981 OS << " // check if the available features match\n"; in emitCustomOperandParsing()
2982 OS << " const FeatureBitset &RequiredFeatures = " in emitCustomOperandParsing()
2984 OS << " if (!ParseForAllFeatures && (AvailableFeatures & " in emitCustomOperandParsing()
2986 OS << " continue;\n\n"; in emitCustomOperandParsing()
2989 OS << " // check if the operand in question has a custom parser.\n"; in emitCustomOperandParsing()
2990 OS << " if (!(it->OperandMask & (1 << NextOpNum)))\n"; in emitCustomOperandParsing()
2991 OS << " continue;\n\n"; in emitCustomOperandParsing()
2994 OS << " // call custom parse method to handle the operand\n"; in emitCustomOperandParsing()
2995 OS << " OperandMatchResultTy Result = "; in emitCustomOperandParsing()
2996 OS << "tryCustomParseOperand(Operands, it->Class);\n"; in emitCustomOperandParsing()
2997 OS << " if (Result != MatchOperand_NoMatch)\n"; in emitCustomOperandParsing()
2998 OS << " return Result;\n"; in emitCustomOperandParsing()
2999 OS << " }\n\n"; in emitCustomOperandParsing()
3001 OS << " // Okay, we had no match.\n"; in emitCustomOperandParsing()
3002 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
3003 OS << "}\n\n"; in emitCustomOperandParsing()
3008 raw_ostream &OS) { in emitAsmTiedOperandConstraints() argument
3011 OS << "static bool "; in emitAsmTiedOperandConstraints()
3012 OS << "checkAsmTiedOperandConstraints(const " << Target.getName() in emitAsmTiedOperandConstraints()
3014 OS << " unsigned Kind,\n"; in emitAsmTiedOperandConstraints()
3015 OS << " const OperandVector &Operands,\n"; in emitAsmTiedOperandConstraints()
3016 OS << " uint64_t &ErrorInfo) {\n"; in emitAsmTiedOperandConstraints()
3017 OS << " assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n"; in emitAsmTiedOperandConstraints()
3018 OS << " const uint8_t *Converter = ConversionTable[Kind];\n"; in emitAsmTiedOperandConstraints()
3019 OS << " for (const uint8_t *p = Converter; *p; p += 2) {\n"; in emitAsmTiedOperandConstraints()
3020 OS << " switch (*p) {\n"; in emitAsmTiedOperandConstraints()
3021 OS << " case CVT_Tied: {\n"; in emitAsmTiedOperandConstraints()
3022 OS << " unsigned OpIdx = *(p + 1);\n"; in emitAsmTiedOperandConstraints()
3023 OS << " assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -\n"; in emitAsmTiedOperandConstraints()
3024 OS << " std::begin(TiedAsmOperandTable)) &&\n"; in emitAsmTiedOperandConstraints()
3025 OS << " \"Tied operand not found\");\n"; in emitAsmTiedOperandConstraints()
3026 OS << " unsigned OpndNum1 = TiedAsmOperandTable[OpIdx][1];\n"; in emitAsmTiedOperandConstraints()
3027 OS << " unsigned OpndNum2 = TiedAsmOperandTable[OpIdx][2];\n"; in emitAsmTiedOperandConstraints()
3028 OS << " if (OpndNum1 != OpndNum2) {\n"; in emitAsmTiedOperandConstraints()
3029 OS << " auto &SrcOp1 = Operands[OpndNum1];\n"; in emitAsmTiedOperandConstraints()
3030 OS << " auto &SrcOp2 = Operands[OpndNum2];\n"; in emitAsmTiedOperandConstraints()
3031 OS << " if (SrcOp1->isReg() && SrcOp2->isReg()) {\n"; in emitAsmTiedOperandConstraints()
3032 OS << " if (!AsmParser.regsEqual(*SrcOp1, *SrcOp2)) {\n"; in emitAsmTiedOperandConstraints()
3033 OS << " ErrorInfo = OpndNum2;\n"; in emitAsmTiedOperandConstraints()
3034 OS << " return false;\n"; in emitAsmTiedOperandConstraints()
3035 OS << " }\n"; in emitAsmTiedOperandConstraints()
3036 OS << " }\n"; in emitAsmTiedOperandConstraints()
3037 OS << " }\n"; in emitAsmTiedOperandConstraints()
3038 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3039 OS << " }\n"; in emitAsmTiedOperandConstraints()
3040 OS << " default:\n"; in emitAsmTiedOperandConstraints()
3041 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3042 OS << " }\n"; in emitAsmTiedOperandConstraints()
3043 OS << " }\n"; in emitAsmTiedOperandConstraints()
3044 OS << " return true;\n"; in emitAsmTiedOperandConstraints()
3045 OS << "}\n\n"; in emitAsmTiedOperandConstraints()
3048 static void emitMnemonicSpellChecker(raw_ostream &OS, CodeGenTarget &Target, in emitMnemonicSpellChecker() argument
3050 OS << "static std::string " << Target.getName() in emitMnemonicSpellChecker()
3054 OS << " return \"\";"; in emitMnemonicSpellChecker()
3056 OS << " const unsigned MaxEditDist = 2;\n"; in emitMnemonicSpellChecker()
3057 OS << " std::vector<StringRef> Candidates;\n"; in emitMnemonicSpellChecker()
3058 OS << " StringRef Prev = \"\";\n\n"; in emitMnemonicSpellChecker()
3060 OS << " // Find the appropriate table for this asm variant.\n"; in emitMnemonicSpellChecker()
3061 OS << " const MatchEntry *Start, *End;\n"; in emitMnemonicSpellChecker()
3062 OS << " switch (VariantID) {\n"; in emitMnemonicSpellChecker()
3063 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in emitMnemonicSpellChecker()
3067 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in emitMnemonicSpellChecker()
3070 OS << " }\n\n"; in emitMnemonicSpellChecker()
3071 OS << " for (auto I = Start; I < End; I++) {\n"; in emitMnemonicSpellChecker()
3072 OS << " // Ignore unsupported instructions.\n"; in emitMnemonicSpellChecker()
3073 OS << " const FeatureBitset &RequiredFeatures = " in emitMnemonicSpellChecker()
3075 OS << " if ((FBS & RequiredFeatures) != RequiredFeatures)\n"; in emitMnemonicSpellChecker()
3076 OS << " continue;\n"; in emitMnemonicSpellChecker()
3077 OS << "\n"; in emitMnemonicSpellChecker()
3078 OS << " StringRef T = I->getMnemonic();\n"; in emitMnemonicSpellChecker()
3079 OS << " // Avoid recomputing the edit distance for the same string.\n"; in emitMnemonicSpellChecker()
3080 OS << " if (T.equals(Prev))\n"; in emitMnemonicSpellChecker()
3081 OS << " continue;\n"; in emitMnemonicSpellChecker()
3082 OS << "\n"; in emitMnemonicSpellChecker()
3083 OS << " Prev = T;\n"; in emitMnemonicSpellChecker()
3084 OS << " unsigned Dist = S.edit_distance(T, false, MaxEditDist);\n"; in emitMnemonicSpellChecker()
3085 OS << " if (Dist <= MaxEditDist)\n"; in emitMnemonicSpellChecker()
3086 OS << " Candidates.push_back(T);\n"; in emitMnemonicSpellChecker()
3087 OS << " }\n"; in emitMnemonicSpellChecker()
3088 OS << "\n"; in emitMnemonicSpellChecker()
3089 OS << " if (Candidates.empty())\n"; in emitMnemonicSpellChecker()
3090 OS << " return \"\";\n"; in emitMnemonicSpellChecker()
3091 OS << "\n"; in emitMnemonicSpellChecker()
3092 OS << " std::string Res = \", did you mean: \";\n"; in emitMnemonicSpellChecker()
3093 OS << " unsigned i = 0;\n"; in emitMnemonicSpellChecker()
3094 OS << " for (; i < Candidates.size() - 1; i++)\n"; in emitMnemonicSpellChecker()
3095 OS << " Res += Candidates[i].str() + \", \";\n"; in emitMnemonicSpellChecker()
3096 OS << " return Res + Candidates[i].str() + \"?\";\n"; in emitMnemonicSpellChecker()
3098 OS << "}\n"; in emitMnemonicSpellChecker()
3099 OS << "\n"; in emitMnemonicSpellChecker()
3102 static void emitMnemonicChecker(raw_ostream &OS, in emitMnemonicChecker() argument
3107 OS << "static bool " << Target.getName() in emitMnemonicChecker()
3109 OS << " " in emitMnemonicChecker()
3111 OS << " " in emitMnemonicChecker()
3115 OS << " return false;\n"; in emitMnemonicChecker()
3118 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in emitMnemonicChecker()
3119 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);"; in emitMnemonicChecker()
3120 OS << "\n\n"; in emitMnemonicChecker()
3122 OS << " // Find the appropriate table for this asm variant.\n"; in emitMnemonicChecker()
3123 OS << " const MatchEntry *Start, *End;\n"; in emitMnemonicChecker()
3124 OS << " switch (VariantID) {\n"; in emitMnemonicChecker()
3125 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in emitMnemonicChecker()
3129 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in emitMnemonicChecker()
3132 OS << " }\n\n"; in emitMnemonicChecker()
3134 OS << " // Search the table.\n"; in emitMnemonicChecker()
3136 OS << " auto MnemonicRange = " in emitMnemonicChecker()
3139 OS << " auto MnemonicRange = std::make_pair(Start, End);\n"; in emitMnemonicChecker()
3140 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in emitMnemonicChecker()
3141 OS << " if (!Mnemonic.empty())\n"; in emitMnemonicChecker()
3142 OS << " MnemonicRange = " in emitMnemonicChecker()
3146 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitMnemonicChecker()
3147 OS << " return false;\n\n"; in emitMnemonicChecker()
3149 OS << " for (const MatchEntry *it = MnemonicRange.first, " in emitMnemonicChecker()
3151 OS << " it != ie; ++it) {\n"; in emitMnemonicChecker()
3152 OS << " const FeatureBitset &RequiredFeatures =\n"; in emitMnemonicChecker()
3153 OS << " FeatureBitsets[it->RequiredFeaturesIdx];\n"; in emitMnemonicChecker()
3154 OS << " if ((AvailableFeatures & RequiredFeatures) == "; in emitMnemonicChecker()
3155 OS << "RequiredFeatures)\n"; in emitMnemonicChecker()
3156 OS << " return true;\n"; in emitMnemonicChecker()
3157 OS << " }\n"; in emitMnemonicChecker()
3158 OS << " return false;\n"; in emitMnemonicChecker()
3160 OS << "}\n"; in emitMnemonicChecker()
3161 OS << "\n"; in emitMnemonicChecker()
3166 raw_ostream &OS) { in emitMatchClassKindNames() argument
3167 OS << "#ifndef NDEBUG\n"; in emitMatchClassKindNames()
3168 OS << "const char *getMatchClassName(MatchClassKind Kind) {\n"; in emitMatchClassKindNames()
3169 OS << " switch (Kind) {\n"; in emitMatchClassKindNames()
3171 OS << " case InvalidMatchClass: return \"InvalidMatchClass\";\n"; in emitMatchClassKindNames()
3172 OS << " case OptionalMatchClass: return \"OptionalMatchClass\";\n"; in emitMatchClassKindNames()
3174 OS << " case " << CI.Name << ": return \"" << CI.Name << "\";\n"; in emitMatchClassKindNames()
3176 OS << " case NumMatchClassKinds: return \"NumMatchClassKinds\";\n"; in emitMatchClassKindNames()
3178 OS << " }\n"; in emitMatchClassKindNames()
3179 OS << " llvm_unreachable(\"unhandled MatchClassKind!\");\n"; in emitMatchClassKindNames()
3180 OS << "}\n\n"; in emitMatchClassKindNames()
3181 OS << "#endif // NDEBUG\n"; in emitMatchClassKindNames()
3192 void AsmMatcherEmitter::run(raw_ostream &OS) { in run() argument
3259 OS << "\n#ifdef GET_ASSEMBLER_HEADER\n"; in run()
3260 OS << "#undef GET_ASSEMBLER_HEADER\n"; in run()
3261 OS << " // This should be included into the middle of the declaration of\n"; in run()
3262 OS << " // your subclasses implementation of MCTargetAsmParser.\n"; in run()
3263 OS << " FeatureBitset ComputeAvailableFeatures(const FeatureBitset &FB) const;\n"; in run()
3265 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3270 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3274 OS << " void convertToMapAndConstraints(unsigned Kind,\n "; in run()
3275 OS << " const OperandVector &Operands) override;\n"; in run()
3276 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
3279 OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n"; in run()
3281 OS << " uint64_t &ErrorInfo,\n" in run()
3283 OS << " bool matchingInlineAsm,\n" in run()
3286 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
3298 OS << " OperandMatchResultTy MatchOperandParserImpl(\n"; in run()
3299 OS << " OperandVector &Operands,\n"; in run()
3300 OS << " StringRef Mnemonic,\n"; in run()
3301 OS << " bool ParseForAllFeatures = false);\n"; in run()
3303 OS << " OperandMatchResultTy tryCustomParseOperand(\n"; in run()
3304 OS << " OperandVector &Operands,\n"; in run()
3305 OS << " unsigned MCK);\n\n"; in run()
3308 OS << "#endif // GET_ASSEMBLER_HEADER_INFO\n\n"; in run()
3311 OS << "\n#ifdef GET_OPERAND_DIAGNOSTIC_TYPES\n"; in run()
3312 OS << "#undef GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3313 emitOperandDiagnosticTypes(Info, OS); in run()
3314 OS << "#endif // GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3316 OS << "\n#ifdef GET_REGISTER_MATCHER\n"; in run()
3317 OS << "#undef GET_REGISTER_MATCHER\n\n"; in run()
3321 Info.SubtargetFeatures, OS); in run()
3326 emitMatchRegisterName(Target, AsmParser, OS); in run()
3329 emitMatchRegisterAltName(Target, AsmParser, OS); in run()
3331 OS << "#endif // GET_REGISTER_MATCHER\n\n"; in run()
3333 OS << "\n#ifdef GET_SUBTARGET_FEATURE_NAME\n"; in run()
3334 OS << "#undef GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3337 emitGetSubtargetFeatureName(Info, OS); in run()
3339 OS << "#endif // GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3341 OS << "\n#ifdef GET_MATCHER_IMPLEMENTATION\n"; in run()
3342 OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3345 bool HasMnemonicAliases = emitMnemonicAliases(OS, Info, Target); in run()
3352 HasOptionalOperands, OS); in run()
3355 emitMatchClassEnumeration(Target, Info.Classes, OS); in run()
3359 emitOperandMatchErrorDiagStrings(Info, OS); in run()
3362 emitRegisterMatchErrorFunc(Info, OS); in run()
3365 emitMatchTokenString(Target, Info.Classes, OS); in run()
3368 emitIsSubclass(Target, Info.Classes, OS); in run()
3371 emitValidateOperandClass(Info, OS); in run()
3373 emitMatchClassKindNames(Info.Classes, OS); in run()
3378 Info.SubtargetFeatures, OS); in run()
3381 emitAsmTiedOperandConstraints(Target, Info, OS); in run()
3398 OS << "static const char MnemonicTable[] =\n"; in run()
3399 StringTable.EmitString(OS); in run()
3400 OS << ";\n\n"; in run()
3428 OS << "// Feature bitsets.\n" in run()
3434 OS << " " << getNameForFeatureBitset(FeatureBitset) << ",\n"; in run()
3436 OS << "};\n\n" in run()
3442 OS << " {"; in run()
3446 OS << I->second.getEnumBitName() << ", "; in run()
3448 OS << "},\n"; in run()
3450 OS << "};\n\n"; in run()
3462 OS << "namespace {\n"; in run()
3463 OS << " struct MatchEntry {\n"; in run()
3464 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in run()
3466 OS << " uint16_t Opcode;\n"; in run()
3467 OS << " " << getMinimalTypeForRange(NumConverters) in run()
3469 OS << " " << getMinimalTypeForRange(FeatureBitsets.size()) in run()
3471 OS << " " << getMinimalTypeForRange( in run()
3474 OS << " StringRef getMnemonic() const {\n"; in run()
3475 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in run()
3476 OS << " MnemonicTable[Mnemonic]);\n"; in run()
3477 OS << " }\n"; in run()
3478 OS << " };\n\n"; in run()
3480 OS << " // Predicate for searching for an opcode.\n"; in run()
3481 OS << " struct LessOpcode {\n"; in run()
3482 OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n"; in run()
3483 OS << " return LHS.getMnemonic() < RHS;\n"; in run()
3484 OS << " }\n"; in run()
3485 OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n"; in run()
3486 OS << " return LHS < RHS.getMnemonic();\n"; in run()
3487 OS << " }\n"; in run()
3488 OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n"; in run()
3489 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in run()
3490 OS << " }\n"; in run()
3491 OS << " };\n"; in run()
3493 OS << "} // end anonymous namespace\n\n"; in run()
3500 OS << "static const MatchEntry MatchTable" << VC << "[] = {\n"; in run()
3509 OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in run()
3516 OS << "AMFBS"; in run()
3518 OS << "_None"; in run()
3521 OS << '_' << MI->RequiredFeatures[i]->TheDef->getName(); in run()
3523 OS << ", { "; in run()
3526 OS << LS << Op.Class->Name; in run()
3527 OS << " }, },\n"; in run()
3530 OS << "};\n\n"; in run()
3533 OS << "#include \"llvm/Support/Debug.h\"\n"; in run()
3534 OS << "#include \"llvm/Support/Format.h\"\n\n"; in run()
3537 OS << "unsigned " << Target.getName() << ClassName << "::\n" in run()
3539 OS << " MCInst &Inst,\n"; in run()
3541 OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n"; in run()
3543 OS << " uint64_t &ErrorInfo,\n" in run()
3545 OS << " bool matchingInlineAsm, unsigned VariantID) {\n"; in run()
3548 OS << " // Eliminate obvious mismatches.\n"; in run()
3549 OS << " if (Operands.size() > " in run()
3551 OS << " ErrorInfo = " in run()
3553 OS << " return Match_InvalidOperand;\n"; in run()
3554 OS << " }\n\n"; in run()
3558 OS << " // Get the current feature set.\n"; in run()
3559 OS << " const FeatureBitset &AvailableFeatures = getAvailableFeatures();\n\n"; in run()
3561 OS << " // Get the instruction mnemonic, which is the first token.\n"; in run()
3563 OS << " StringRef Mnemonic = ((" << Target.getName() in run()
3566 OS << " StringRef Mnemonic;\n"; in run()
3567 OS << " if (Operands[0]->isToken())\n"; in run()
3568 OS << " Mnemonic = ((" << Target.getName() in run()
3573 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in run()
3574 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);\n\n"; in run()
3579 OS << " // Some state to try to produce better error messages.\n"; in run()
3580 OS << " bool HadMatchOtherThanFeatures = false;\n"; in run()
3581 OS << " bool HadMatchOtherThanPredicate = false;\n"; in run()
3582 OS << " unsigned RetCode = Match_InvalidOperand;\n"; in run()
3583 OS << " MissingFeatures.set();\n"; in run()
3584 OS << " // Set ErrorInfo to the operand that mismatches if it is\n"; in run()
3585 OS << " // wrong for all instances of the instruction.\n"; in run()
3586 OS << " ErrorInfo = ~0ULL;\n"; in run()
3590 OS << " SmallBitVector OptionalOperandsMask(" << MaxNumOperands << ");\n"; in run()
3594 OS << " // Find the appropriate table for this asm variant.\n"; in run()
3595 OS << " const MatchEntry *Start, *End;\n"; in run()
3596 OS << " switch (VariantID) {\n"; in run()
3597 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in run()
3601 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in run()
3604 OS << " }\n"; in run()
3606 OS << " // Search the table.\n"; in run()
3608 OS << " auto MnemonicRange = " in run()
3611 OS << " auto MnemonicRange = std::make_pair(Start, End);\n"; in run()
3612 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in run()
3613 OS << " if (!Mnemonic.empty())\n"; in run()
3614 OS << " MnemonicRange = " in run()
3618 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"AsmMatcher: found \" <<\n" in run()
3622 OS << " // Return a more specific error code if no mnemonics match.\n"; in run()
3623 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in run()
3624 OS << " return Match_MnemonicFail;\n\n"; in run()
3626 OS << " for (const MatchEntry *it = MnemonicRange.first, " in run()
3628 OS << " it != ie; ++it) {\n"; in run()
3629 OS << " const FeatureBitset &RequiredFeatures = " in run()
3631 OS << " bool HasRequiredFeatures =\n"; in run()
3632 OS << " (AvailableFeatures & RequiredFeatures) == RequiredFeatures;\n"; in run()
3633 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Trying to match opcode \"\n"; in run()
3634 OS << " << MII.getName(it->Opcode) << \"\\n\");\n"; in run()
3637 OS << " // Some state to record ways in which this instruction did not match.\n"; in run()
3638 OS << " NearMissInfo OperandNearMiss = NearMissInfo::getSuccess();\n"; in run()
3639 OS << " NearMissInfo FeaturesNearMiss = NearMissInfo::getSuccess();\n"; in run()
3640 OS << " NearMissInfo EarlyPredicateNearMiss = NearMissInfo::getSuccess();\n"; in run()
3641 OS << " NearMissInfo LatePredicateNearMiss = NearMissInfo::getSuccess();\n"; in run()
3642 OS << " bool MultipleInvalidOperands = false;\n"; in run()
3646 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in run()
3647 OS << " assert(Mnemonic == it->getMnemonic());\n"; in run()
3652 OS << " bool OperandsValid = true;\n"; in run()
3654 OS << " OptionalOperandsMask.reset(0, " << MaxNumOperands << ");\n"; in run()
3656 OS << " for (unsigned FormalIdx = " << (HasMnemonicFirst ? "0" : "SIndex") in run()
3659 OS << " auto Formal = " in run()
3661 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3662OS << " dbgs() << \" Matching formal operand class \" << getMatchClassName(F… in run()
3663 OS << " << \" against actual operand at index \" << ActualIdx);\n"; in run()
3664 OS << " if (ActualIdx < Operands.size())\n"; in run()
3665 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \" (\";\n"; in run()
3666 OS << " Operands[ActualIdx]->print(dbgs()); dbgs() << \"): \");\n"; in run()
3667 OS << " else\n"; in run()
3668 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \": \");\n"; in run()
3669 OS << " if (ActualIdx >= Operands.size()) {\n"; in run()
3670OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"actual operand index out of range \");… in run()
3672 OS << " bool ThisOperandValid = (Formal == " <<"InvalidMatchClass) || " in run()
3674 OS << " if (!ThisOperandValid) {\n"; in run()
3675 OS << " if (!OperandNearMiss) {\n"; in run()
3676 OS << " // Record info about match failure for later use.\n"; in run()
3677OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"recording too-few-operands near mi… in run()
3678 OS << " OperandNearMiss =\n"; in run()
3679 OS << " NearMissInfo::getTooFewOperands(Formal, it->Opcode);\n"; in run()
3680OS << " } else if (OperandNearMiss.getKind() != NearMissInfo::NearMissTooFewOperands) {\n… in run()
3681 OS << " // If more than one operand is invalid, give up on this match entry.\n"; in run()
3682 OS << " DEBUG_WITH_TYPE(\n"; in run()
3683 OS << " \"asm-matcher\",\n"; in run()
3684 OS << " dbgs() << \"second invalid operand, giving up on this opcode\\n\");\n"; in run()
3685 OS << " MultipleInvalidOperands = true;\n"; in run()
3686 OS << " break;\n"; in run()
3687 OS << " }\n"; in run()
3688 OS << " } else {\n"; in run()
3689OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"but formal operand not required\\n\"… in run()
3690 OS << " break;\n"; in run()
3691 OS << " }\n"; in run()
3692 OS << " continue;\n"; in run()
3694OS << " OperandsValid = (Formal == InvalidMatchClass) || isSubclass(Formal, OptionalMatchCl… in run()
3695 OS << " if (!OperandsValid) ErrorInfo = ActualIdx;\n"; in run()
3697 OS << " OptionalOperandsMask.set(FormalIdx, " << MaxNumOperands in run()
3700 OS << " break;\n"; in run()
3702 OS << " }\n"; in run()
3703 OS << " MCParsedAsmOperand &Actual = *Operands[ActualIdx];\n"; in run()
3704 OS << " unsigned Diag = validateOperandClass(Actual, Formal);\n"; in run()
3705 OS << " if (Diag == Match_Success) {\n"; in run()
3706 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3707 OS << " dbgs() << \"match success using generic matcher\\n\");\n"; in run()
3708 OS << " ++ActualIdx;\n"; in run()
3709 OS << " continue;\n"; in run()
3710 OS << " }\n"; in run()
3711 OS << " // If the generic handler indicates an invalid operand\n"; in run()
3712 OS << " // failure, check for a special case.\n"; in run()
3713 OS << " if (Diag != Match_Success) {\n"; in run()
3714 OS << " unsigned TargetDiag = validateTargetOperandClass(Actual, Formal);\n"; in run()
3715 OS << " if (TargetDiag == Match_Success) {\n"; in run()
3716 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3717 OS << " dbgs() << \"match success using target matcher\\n\");\n"; in run()
3718 OS << " ++ActualIdx;\n"; in run()
3719 OS << " continue;\n"; in run()
3720 OS << " }\n"; in run()
3721 OS << " // If the target matcher returned a specific error code use\n"; in run()
3722 OS << " // that, else use the one from the generic matcher.\n"; in run()
3723 OS << " if (TargetDiag != Match_InvalidOperand && " in run()
3725 OS << " Diag = TargetDiag;\n"; in run()
3726 OS << " }\n"; in run()
3727 OS << " // If current formal operand wasn't matched and it is optional\n" in run()
3729 OS << " if (Diag == Match_InvalidOperand " in run()
3732 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3734 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"ignoring optional operand\\n\");\n"; in run()
3735 OS << " continue;\n"; in run()
3736 OS << " }\n"; in run()
3739 OS << " if (!OperandNearMiss) {\n"; in run()
3740 OS << " // If this is the first invalid operand we have seen, record some\n"; in run()
3741 OS << " // information about it.\n"; in run()
3742 OS << " DEBUG_WITH_TYPE(\n"; in run()
3743 OS << " \"asm-matcher\",\n"; in run()
3744 OS << " dbgs()\n"; in run()
3745 OS << " << \"operand match failed, recording near-miss with diag code \"\n"; in run()
3746 OS << " << Diag << \"\\n\");\n"; in run()
3747 OS << " OperandNearMiss =\n"; in run()
3748 OS << " NearMissInfo::getMissedOperand(Diag, Formal, it->Opcode, ActualIdx);\n"; in run()
3749 OS << " ++ActualIdx;\n"; in run()
3750 OS << " } else {\n"; in run()
3751 OS << " // If more than one operand is invalid, give up on this match entry.\n"; in run()
3752 OS << " DEBUG_WITH_TYPE(\n"; in run()
3753 OS << " \"asm-matcher\",\n"; in run()
3754 OS << " dbgs() << \"second operand mismatch, skipping this opcode\\n\");\n"; in run()
3755 OS << " MultipleInvalidOperands = true;\n"; in run()
3756 OS << " break;\n"; in run()
3757 OS << " }\n"; in run()
3758 OS << " }\n\n"; in run()
3760 OS << " // If this operand is broken for all of the instances of this\n"; in run()
3761 OS << " // mnemonic, keep track of it so we can report loc info.\n"; in run()
3762 OS << " // If we already had a match that only failed due to a\n"; in run()
3763 OS << " // target predicate, that diagnostic is preferred.\n"; in run()
3764 OS << " if (!HadMatchOtherThanPredicate &&\n"; in run()
3765 OS << " (it == MnemonicRange.first || ErrorInfo <= ActualIdx)) {\n"; in run()
3766 OS << " if (HasRequiredFeatures && (ErrorInfo != ActualIdx || Diag " in run()
3768 OS << " RetCode = Diag;\n"; in run()
3769 OS << " ErrorInfo = ActualIdx;\n"; in run()
3770 OS << " }\n"; in run()
3771 OS << " // Otherwise, just reject this instance of the mnemonic.\n"; in run()
3772 OS << " OperandsValid = false;\n"; in run()
3773 OS << " break;\n"; in run()
3774 OS << " }\n\n"; in run()
3778 OS << " if (MultipleInvalidOperands) {\n"; in run()
3780 OS << " if (!OperandsValid) {\n"; in run()
3781 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3782 OS << " \"operand mismatches, ignoring \"\n"; in run()
3783 OS << " \"this opcode\\n\");\n"; in run()
3784 OS << " continue;\n"; in run()
3785 OS << " }\n"; in run()
3788 OS << " if (!HasRequiredFeatures) {\n"; in run()
3790 OS << " HadMatchOtherThanFeatures = true;\n"; in run()
3791 OS << " FeatureBitset NewMissingFeatures = RequiredFeatures & " in run()
3793 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Missing target features:\";\n"; in run()
3794 OS << " for (unsigned I = 0, E = NewMissingFeatures.size(); I != E; ++I)\n"; in run()
3795 OS << " if (NewMissingFeatures[I])\n"; in run()
3796 OS << " dbgs() << ' ' << I;\n"; in run()
3797 OS << " dbgs() << \"\\n\");\n"; in run()
3799 OS << " FeaturesNearMiss = NearMissInfo::getMissedFeature(NewMissingFeatures);\n"; in run()
3801 OS << " if (NewMissingFeatures.count() <=\n" in run()
3803 OS << " MissingFeatures = NewMissingFeatures;\n"; in run()
3804 OS << " continue;\n"; in run()
3806 OS << " }\n"; in run()
3807 OS << "\n"; in run()
3808 OS << " Inst.clear();\n\n"; in run()
3809 OS << " Inst.setOpcode(it->Opcode);\n"; in run()
3811 OS << " // We have a potential match but have not rendered the operands.\n" in run()
3822 OS << " DEBUG_WITH_TYPE(\n"; in run()
3823 OS << " \"asm-matcher\",\n"; in run()
3824 OS << " dbgs() << \"Early target match predicate failed with diag code \"\n"; in run()
3825 OS << " << MatchResult << \"\\n\");\n"; in run()
3827 OS << " EarlyPredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n"; in run()
3829 OS << " RetCode = MatchResult;\n" in run()
3833 OS << " }\n\n"; in run()
3836 OS << " // If we did not successfully match the operands, then we can't convert to\n"; in run()
3837 OS << " // an MCInst, so bail out on this instruction variant now.\n"; in run()
3838 OS << " if (OperandNearMiss) {\n"; in run()
3839 OS << " // If the operand mismatch was the only problem, reprrt it as a near-miss.\n"; in run()
3840 OS << " if (NearMisses && !FeaturesNearMiss && !EarlyPredicateNearMiss) {\n"; in run()
3841 OS << " DEBUG_WITH_TYPE(\n"; in run()
3842 OS << " \"asm-matcher\",\n"; in run()
3843 OS << " dbgs()\n"; in run()
3844 OS << " << \"Opcode result: one mismatched operand, adding near-miss\\n\");\n"; in run()
3845 OS << " NearMisses->push_back(OperandNearMiss);\n"; in run()
3846 OS << " } else {\n"; in run()
3847 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3848 OS << " \"types of mismatch, so not \"\n"; in run()
3849 OS << " \"reporting near-miss\\n\");\n"; in run()
3850 OS << " }\n"; in run()
3851 OS << " continue;\n"; in run()
3852 OS << " }\n\n"; in run()
3855 OS << " if (matchingInlineAsm) {\n"; in run()
3856 OS << " convertToMapAndConstraints(it->ConvertFn, Operands);\n"; in run()
3858 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3860 OS << " return Match_InvalidTiedOperand;\n"; in run()
3861 OS << "\n"; in run()
3863 OS << " return Match_Success;\n"; in run()
3864 OS << " }\n\n"; in run()
3865 OS << " // We have selected a definite instruction, convert the parsed\n" in run()
3868 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands,\n" in run()
3871 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n"; in run()
3873 OS << "\n"; in run()
3876 OS << " // We have a potential match. Check the target predicate to\n" in run()
3885 OS << " LatePredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n"; in run()
3887 OS << " RetCode = MatchResult;\n" in run()
3891 OS << " }\n\n"; in run()
3894 OS << " int NumNearMisses = ((int)(bool)OperandNearMiss +\n"; in run()
3895 OS << " (int)(bool)FeaturesNearMiss +\n"; in run()
3896 OS << " (int)(bool)EarlyPredicateNearMiss +\n"; in run()
3897 OS << " (int)(bool)LatePredicateNearMiss);\n"; in run()
3898 OS << " if (NumNearMisses == 1) {\n"; in run()
3899 OS << " // We had exactly one type of near-miss, so add that to the list.\n"; in run()
3900 OS << " assert(!OperandNearMiss && \"OperandNearMiss was handled earlier\");\n"; in run()
3901OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: found one type of \"\n"; in run()
3902 OS << " \"mismatch, so reporting a \"\n"; in run()
3903 OS << " \"near-miss\\n\");\n"; in run()
3904 OS << " if (NearMisses && FeaturesNearMiss)\n"; in run()
3905 OS << " NearMisses->push_back(FeaturesNearMiss);\n"; in run()
3906 OS << " else if (NearMisses && EarlyPredicateNearMiss)\n"; in run()
3907 OS << " NearMisses->push_back(EarlyPredicateNearMiss);\n"; in run()
3908 OS << " else if (NearMisses && LatePredicateNearMiss)\n"; in run()
3909 OS << " NearMisses->push_back(LatePredicateNearMiss);\n"; in run()
3910 OS << "\n"; in run()
3911 OS << " continue;\n"; in run()
3912 OS << " } else if (NumNearMisses > 1) {\n"; in run()
3913 OS << " // This instruction missed in more than one way, so ignore it.\n"; in run()
3914 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3915 OS << " \"types of mismatch, so not \"\n"; in run()
3916 OS << " \"reporting near-miss\\n\");\n"; in run()
3917 OS << " continue;\n"; in run()
3918 OS << " }\n"; in run()
3924 OS << " " << InsnCleanupFn << "(Inst);\n"; in run()
3927 OS << " std::string Info;\n"; in run()
3928 OS << " if (!getParser().getTargetParser().getTargetOptions().MCNoDeprecatedWarn &&\n"; in run()
3929 OS << " MII.getDeprecatedInfo(Inst, getSTI(), Info)) {\n"; in run()
3930 OS << " SMLoc Loc = ((" << Target.getName() in run()
3932 OS << " getParser().Warning(Loc, Info, None);\n"; in run()
3933 OS << " }\n"; in run()
3937 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3939 OS << " return Match_InvalidTiedOperand;\n"; in run()
3940 OS << "\n"; in run()
3943 OS << " DEBUG_WITH_TYPE(\n"; in run()
3944 OS << " \"asm-matcher\",\n"; in run()
3945 OS << " dbgs() << \"Opcode result: complete match, selecting this opcode\\n\");\n"; in run()
3946 OS << " return Match_Success;\n"; in run()
3947 OS << " }\n\n"; in run()
3950 OS << " // No instruction variants matched exactly.\n"; in run()
3951 OS << " return Match_NearMisses;\n"; in run()
3953 OS << " // Okay, we had no match. Try to return a useful error code.\n"; in run()
3954 OS << " if (HadMatchOtherThanPredicate || !HadMatchOtherThanFeatures)\n"; in run()
3955 OS << " return RetCode;\n\n"; in run()
3956 OS << " ErrorInfo = 0;\n"; in run()
3957 OS << " return Match_MissingFeature;\n"; in run()
3959 OS << "}\n\n"; in run()
3962 emitCustomOperandParsing(OS, Target, Info, ClassName, StringTable, in run()
3966 OS << "#endif // GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3968 OS << "\n#ifdef GET_MNEMONIC_SPELL_CHECKER\n"; in run()
3969 OS << "#undef GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
3971 emitMnemonicSpellChecker(OS, Target, VariantCount); in run()
3973 OS << "#endif // GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
3975 OS << "\n#ifdef GET_MNEMONIC_CHECKER\n"; in run()
3976 OS << "#undef GET_MNEMONIC_CHECKER\n\n"; in run()
3978 emitMnemonicChecker(OS, Target, VariantCount, in run()
3981 OS << "#endif // GET_MNEMONIC_CHECKER\n\n"; in run()
3986 void EmitAsmMatcher(RecordKeeper &RK, raw_ostream &OS) { in EmitAsmMatcher() argument
3987 emitSourceFileHeader("Assembly Matcher Source Fragment", OS); in EmitAsmMatcher()
3988 AsmMatcherEmitter(RK).run(OS); in EmitAsmMatcher()