Lines Matching refs:OS

1934                              raw_ostream &OS) {  in emitConvertFuncs()  argument
2266 OS << "enum {\n"; in emitConvertFuncs()
2268 OS << " " << KV.second << ",\n"; in emitConvertFuncs()
2270 OS << "};\n\n"; in emitConvertFuncs()
2272 OS << "static const uint8_t TiedAsmOperandTable[][3] = {\n"; in emitConvertFuncs()
2274 OS << " /* " << KV.second << " */ { " in emitConvertFuncs()
2279 OS << "};\n\n"; in emitConvertFuncs()
2281 OS << "static const uint8_t TiedAsmOperandTable[][3] = " in emitConvertFuncs()
2284 OS << "namespace {\n"; in emitConvertFuncs()
2287 OS << "enum OperatorConversionKind {\n"; in emitConvertFuncs()
2289 OS << " " << Converter << ",\n"; in emitConvertFuncs()
2290 OS << " CVT_NUM_CONVERTERS\n"; in emitConvertFuncs()
2291 OS << "};\n\n"; in emitConvertFuncs()
2294 OS << "enum InstructionConversionKind {\n"; in emitConvertFuncs()
2296 OS << " " << Signature << ",\n"; in emitConvertFuncs()
2297 OS << " CVT_NUM_SIGNATURES\n"; in emitConvertFuncs()
2298 OS << "};\n\n"; in emitConvertFuncs()
2300 OS << "} // end anonymous namespace\n\n"; in emitConvertFuncs()
2303 OS << "static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][" in emitConvertFuncs()
2308 OS << " // " << InstructionConversionKinds[Row] << "\n"; in emitConvertFuncs()
2309 OS << " { "; in emitConvertFuncs()
2311 OS << OperandConversionKinds[ConversionTable[Row][i]] << ", "; in emitConvertFuncs()
2314 OS << (unsigned)(ConversionTable[Row][i + 1]) << ", "; in emitConvertFuncs()
2327 OS << TiedOpndEnum->second << ", "; in emitConvertFuncs()
2330 OS << "CVT_Done },\n"; in emitConvertFuncs()
2333 OS << "};\n\n"; in emitConvertFuncs()
2336 OS << CvtOS.str(); in emitConvertFuncs()
2339 OS << OpOS.str(); in emitConvertFuncs()
2345 raw_ostream &OS) { in emitMatchClassEnumeration() argument
2346 OS << "namespace {\n\n"; in emitMatchClassEnumeration()
2348 OS << "/// MatchClassKind - The kinds of classes which participate in\n" in emitMatchClassEnumeration()
2350 OS << "enum MatchClassKind {\n"; in emitMatchClassEnumeration()
2351 OS << " InvalidMatchClass = 0,\n"; in emitMatchClassEnumeration()
2352 OS << " OptionalMatchClass = 1,\n"; in emitMatchClassEnumeration()
2357 OS << " MCK_LAST_TOKEN = " << LastName << ",\n"; in emitMatchClassEnumeration()
2360 OS << " MCK_LAST_REGISTER = " << LastName << ",\n"; in emitMatchClassEnumeration()
2365 OS << " " << CI.Name << ", // "; in emitMatchClassEnumeration()
2367 OS << "'" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2370 OS << "register class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2372 OS << "derived register class\n"; in emitMatchClassEnumeration()
2374 OS << "user defined class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2377 OS << " NumMatchClassKinds\n"; in emitMatchClassEnumeration()
2378 OS << "};\n\n"; in emitMatchClassEnumeration()
2380 OS << "}\n\n"; in emitMatchClassEnumeration()
2385 static void emitOperandMatchErrorDiagStrings(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandMatchErrorDiagStrings() argument
2393 OS << "static const char *getMatchKindDiag(" << Info.Target.getName() in emitOperandMatchErrorDiagStrings()
2396 OS << " switch (MatchResult) {\n"; in emitOperandMatchErrorDiagStrings()
2402 OS << " case " << Info.Target.getName() in emitOperandMatchErrorDiagStrings()
2404 OS << " return \"" << CI.DiagnosticString << "\";\n"; in emitOperandMatchErrorDiagStrings()
2408 OS << " default:\n"; in emitOperandMatchErrorDiagStrings()
2409 OS << " return nullptr;\n"; in emitOperandMatchErrorDiagStrings()
2411 OS << " }\n"; in emitOperandMatchErrorDiagStrings()
2412 OS << "}\n\n"; in emitOperandMatchErrorDiagStrings()
2415 static void emitRegisterMatchErrorFunc(AsmMatcherInfo &Info, raw_ostream &OS) { in emitRegisterMatchErrorFunc() argument
2416 OS << "static unsigned getDiagKindFromRegisterClass(MatchClassKind " in emitRegisterMatchErrorFunc()
2421 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2423 OS << " switch (RegisterClass) {\n"; in emitRegisterMatchErrorFunc()
2426 OS << " case " << CI.Name << ":\n"; in emitRegisterMatchErrorFunc()
2427 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitRegisterMatchErrorFunc()
2432 OS << " default:\n"; in emitRegisterMatchErrorFunc()
2433 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitRegisterMatchErrorFunc()
2435 OS << " }\n"; in emitRegisterMatchErrorFunc()
2437 OS << "}\n\n"; in emitRegisterMatchErrorFunc()
2442 raw_ostream &OS) { in emitValidateOperandClass() argument
2443 OS << "static unsigned validateOperandClass(MCParsedAsmOperand &GOp, " in emitValidateOperandClass()
2445 OS << " " << Info.Target.getName() << "Operand &Operand = (" in emitValidateOperandClass()
2449 OS << " if (Kind == InvalidMatchClass)\n"; in emitValidateOperandClass()
2450 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n\n"; in emitValidateOperandClass()
2454 OS << " if (Operand.isToken() && Kind <= MCK_LAST_TOKEN)\n"; in emitValidateOperandClass()
2455 OS << " return isSubclass(matchTokenString(Operand.getToken()), Kind) ?\n" in emitValidateOperandClass()
2461 OS << " switch (Kind) {\n" in emitValidateOperandClass()
2467 OS << " // '" << CI.ClassName << "' class\n"; in emitValidateOperandClass()
2468 OS << " case " << CI.Name << ": {\n"; in emitValidateOperandClass()
2469 OS << " DiagnosticPredicate DP(Operand." << CI.PredicateMethod in emitValidateOperandClass()
2471 OS << " if (DP.isMatch())\n"; in emitValidateOperandClass()
2472 OS << " return MCTargetAsmParser::Match_Success;\n"; in emitValidateOperandClass()
2474 OS << " if (DP.isNearMatch())\n"; in emitValidateOperandClass()
2475 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitValidateOperandClass()
2477 OS << " break;\n"; in emitValidateOperandClass()
2480 OS << " break;\n"; in emitValidateOperandClass()
2481 OS << " }\n"; in emitValidateOperandClass()
2483 OS << " } // end switch (Kind)\n\n"; in emitValidateOperandClass()
2486 OS << " if (Operand.isReg()) {\n"; in emitValidateOperandClass()
2487 OS << " MatchClassKind OpKind;\n"; in emitValidateOperandClass()
2488 OS << " switch (Operand.getReg()) {\n"; in emitValidateOperandClass()
2489 OS << " default: OpKind = InvalidMatchClass; break;\n"; in emitValidateOperandClass()
2491 OS << " case " << RC.first->getValueAsString("Namespace") << "::" in emitValidateOperandClass()
2494 OS << " }\n"; in emitValidateOperandClass()
2495 OS << " return isSubclass(OpKind, Kind) ? " in emitValidateOperandClass()
2500 OS << " if (Kind > MCK_LAST_TOKEN && Kind <= MCK_LAST_REGISTER)\n"; in emitValidateOperandClass()
2501 OS << " return getDiagKindFromRegisterClass(Kind);\n\n"; in emitValidateOperandClass()
2505 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitValidateOperandClass()
2506 OS << "}\n\n"; in emitValidateOperandClass()
2512 raw_ostream &OS) { in emitIsSubclass() argument
2513 OS << "/// isSubclass - Compute whether \\p A is a subclass of \\p B.\n"; in emitIsSubclass()
2514 OS << "static bool isSubclass(MatchClassKind A, MatchClassKind B) {\n"; in emitIsSubclass()
2515 OS << " if (A == B)\n"; in emitIsSubclass()
2516 OS << " return true;\n\n"; in emitIsSubclass()
2533 OS << " switch (A) {\n"; in emitIsSubclass()
2534 OS << " default:\n"; in emitIsSubclass()
2535 OS << " return false;\n"; in emitIsSubclass()
2539 OS << "\n case " << A.Name << ":\n"; in emitIsSubclass()
2542 OS << " return B == " << SuperClasses.back() << ";\n"; in emitIsSubclass()
2547 OS << " switch (B) {\n"; in emitIsSubclass()
2548 OS << " default: return false;\n"; in emitIsSubclass()
2550 OS << " case " << SC << ": return true;\n"; in emitIsSubclass()
2551 OS << " }\n"; in emitIsSubclass()
2554 OS << " return false;\n"; in emitIsSubclass()
2561 OS << " }\n"; in emitIsSubclass()
2563 OS << " return false;\n"; in emitIsSubclass()
2565 OS << "}\n\n"; in emitIsSubclass()
2572 raw_ostream &OS) { in emitMatchTokenString() argument
2580 OS << "static MatchClassKind matchTokenString(StringRef Name) {\n"; in emitMatchTokenString()
2582 StringMatcher("Name", Matches, OS).Emit(); in emitMatchTokenString()
2584 OS << " return InvalidMatchClass;\n"; in emitMatchTokenString()
2585 OS << "}\n\n"; in emitMatchTokenString()
2591 raw_ostream &OS) { in emitMatchRegisterName() argument
2603 OS << "static unsigned MatchRegisterName(StringRef Name) {\n"; in emitMatchRegisterName()
2607 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterName()
2609 OS << " return 0;\n"; in emitMatchRegisterName()
2610 OS << "}\n\n"; in emitMatchRegisterName()
2616 raw_ostream &OS) { in emitMatchRegisterAltName() argument
2636 OS << "static unsigned MatchRegisterAltName(StringRef Name) {\n"; in emitMatchRegisterAltName()
2640 StringMatcher("Name", Matches, OS).Emit(0, IgnoreDuplicates); in emitMatchRegisterAltName()
2642 OS << " return 0;\n"; in emitMatchRegisterAltName()
2643 OS << "}\n\n"; in emitMatchRegisterAltName()
2647 static void emitOperandDiagnosticTypes(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandDiagnosticTypes() argument
2663 OS << " Match_" << Type << ",\n"; in emitOperandDiagnosticTypes()
2664 OS << " END_OPERAND_DIAGNOSTIC_TYPES\n"; in emitOperandDiagnosticTypes()
2669 static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) { in emitGetSubtargetFeatureName() argument
2670 OS << "// User-level names for subtarget features that participate in\n" in emitGetSubtargetFeatureName()
2674 OS << " switch(Val) {\n"; in emitGetSubtargetFeatureName()
2678 OS << " case " << SFI.getEnumName() << ": return \"" in emitGetSubtargetFeatureName()
2681 OS << " default: return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2682 OS << " }\n"; in emitGetSubtargetFeatureName()
2685 OS << " return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2687 OS << "}\n\n"; in emitGetSubtargetFeatureName()
2714 static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info, in emitMnemonicAliasVariant() argument
2785 StringMatcher("Mnemonic", Cases, OS).Emit(Indent); in emitMnemonicAliasVariant()
2790 static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info, in emitMnemonicAliases() argument
2800 OS << "static void applyMnemonicAliases(StringRef &Mnemonic, " in emitMnemonicAliases()
2802 OS << " switch (VariantID) {\n"; in emitMnemonicAliases()
2808 OS << " case " << AsmParserVariantNo << ":\n"; in emitMnemonicAliases()
2809 emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2, in emitMnemonicAliases()
2811 OS << " break;\n"; in emitMnemonicAliases()
2813 OS << " }\n"; in emitMnemonicAliases()
2816 emitMnemonicAliasVariant(OS, Info, Aliases); in emitMnemonicAliases()
2818 OS << "}\n\n"; in emitMnemonicAliases()
2823 static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, in emitCustomOperandParsing() argument
2833 OS << "namespace {\n"; in emitCustomOperandParsing()
2834 OS << " struct OperandMatchEntry {\n"; in emitCustomOperandParsing()
2835 OS << " " << getMinimalTypeForEnumBitfield(Info.SubtargetFeatures.size()) in emitCustomOperandParsing()
2837 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in emitCustomOperandParsing()
2839 OS << " " << getMinimalTypeForRange(std::distance( in emitCustomOperandParsing()
2841 OS << " " << getMinimalTypeForRange(MaxMask) in emitCustomOperandParsing()
2843 OS << " StringRef getMnemonic() const {\n"; in emitCustomOperandParsing()
2844 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in emitCustomOperandParsing()
2845 OS << " MnemonicTable[Mnemonic]);\n"; in emitCustomOperandParsing()
2846 OS << " }\n"; in emitCustomOperandParsing()
2847 OS << " };\n\n"; in emitCustomOperandParsing()
2849 OS << " // Predicate for searching for an opcode.\n"; in emitCustomOperandParsing()
2850 OS << " struct LessOpcodeOperand {\n"; in emitCustomOperandParsing()
2851 OS << " bool operator()(const OperandMatchEntry &LHS, StringRef RHS) {\n"; in emitCustomOperandParsing()
2852 OS << " return LHS.getMnemonic() < RHS;\n"; in emitCustomOperandParsing()
2853 OS << " }\n"; in emitCustomOperandParsing()
2854 OS << " bool operator()(StringRef LHS, const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2855 OS << " return LHS < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2856 OS << " }\n"; in emitCustomOperandParsing()
2857 OS << " bool operator()(const OperandMatchEntry &LHS,"; in emitCustomOperandParsing()
2858 OS << " const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2859 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2860 OS << " }\n"; in emitCustomOperandParsing()
2861 OS << " };\n"; in emitCustomOperandParsing()
2863 OS << "} // end anonymous namespace.\n\n"; in emitCustomOperandParsing()
2865 OS << "static const OperandMatchEntry OperandMatchTable[" in emitCustomOperandParsing()
2868 OS << " /* Operand List Mask, Mnemonic, Operand Class, Features */\n"; in emitCustomOperandParsing()
2872 OS << " { "; in emitCustomOperandParsing()
2877 if (i) OS << "|"; in emitCustomOperandParsing()
2878 OS << II.RequiredFeatures[i]->getEnumName(); in emitCustomOperandParsing()
2881 OS << "0"; in emitCustomOperandParsing()
2885 OS << ", " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in emitCustomOperandParsing()
2888 OS << OMI.CI->Name; in emitCustomOperandParsing()
2890 OS << ", " << OMI.OperandMask; in emitCustomOperandParsing()
2891 OS << " /* "; in emitCustomOperandParsing()
2896 OS << ", "; in emitCustomOperandParsing()
2897 OS << i; in emitCustomOperandParsing()
2900 OS << " */"; in emitCustomOperandParsing()
2902 OS << " },\n"; in emitCustomOperandParsing()
2904 OS << "};\n\n"; in emitCustomOperandParsing()
2908 OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2916 OS << " case " << CI.Name << ":\n" in emitCustomOperandParsing()
2920 OS << " default:\n"; in emitCustomOperandParsing()
2921 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2922 OS << " }\n"; in emitCustomOperandParsing()
2923 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2924 OS << "}\n\n"; in emitCustomOperandParsing()
2929 OS << "OperandMatchResultTy " << Target.getName() << ClassName << "::\n" in emitCustomOperandParsing()
2935 OS << " // Get the current feature set.\n"; in emitCustomOperandParsing()
2936 OS << " uint64_t AvailableFeatures = getAvailableFeatures();\n\n"; in emitCustomOperandParsing()
2938 OS << " // Get the next operand index.\n"; in emitCustomOperandParsing()
2939 OS << " unsigned NextOpNum = Operands.size()" in emitCustomOperandParsing()
2943 OS << " // Search the table.\n"; in emitCustomOperandParsing()
2945 OS << " auto MnemonicRange =\n"; in emitCustomOperandParsing()
2946 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2948 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2950 OS << " auto MnemonicRange = std::make_pair(std::begin(OperandMatchTable)," in emitCustomOperandParsing()
2952 OS << " if (!Mnemonic.empty())\n"; in emitCustomOperandParsing()
2953 OS << " MnemonicRange =\n"; in emitCustomOperandParsing()
2954 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2956 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2959 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitCustomOperandParsing()
2960 OS << " return MatchOperand_NoMatch;\n\n"; in emitCustomOperandParsing()
2962 OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n" in emitCustomOperandParsing()
2965 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in emitCustomOperandParsing()
2966 OS << " assert(Mnemonic == it->getMnemonic());\n\n"; in emitCustomOperandParsing()
2969 OS << " // check if the available features match\n"; in emitCustomOperandParsing()
2970 OS << " if (!ParseForAllFeatures && (AvailableFeatures & " in emitCustomOperandParsing()
2972 OS << " continue;\n\n"; in emitCustomOperandParsing()
2975 OS << " // check if the operand in question has a custom parser.\n"; in emitCustomOperandParsing()
2976 OS << " if (!(it->OperandMask & (1 << NextOpNum)))\n"; in emitCustomOperandParsing()
2977 OS << " continue;\n\n"; in emitCustomOperandParsing()
2980 OS << " // call custom parse method to handle the operand\n"; in emitCustomOperandParsing()
2981 OS << " OperandMatchResultTy Result = "; in emitCustomOperandParsing()
2982 OS << "tryCustomParseOperand(Operands, it->Class);\n"; in emitCustomOperandParsing()
2983 OS << " if (Result != MatchOperand_NoMatch)\n"; in emitCustomOperandParsing()
2984 OS << " return Result;\n"; in emitCustomOperandParsing()
2985 OS << " }\n\n"; in emitCustomOperandParsing()
2987 OS << " // Okay, we had no match.\n"; in emitCustomOperandParsing()
2988 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2989 OS << "}\n\n"; in emitCustomOperandParsing()
2994 raw_ostream &OS) { in emitAsmTiedOperandConstraints() argument
2997 OS << "static bool "; in emitAsmTiedOperandConstraints()
2998 OS << "checkAsmTiedOperandConstraints(const " << Target.getName() in emitAsmTiedOperandConstraints()
3000 OS << " unsigned Kind,\n"; in emitAsmTiedOperandConstraints()
3001 OS << " const OperandVector &Operands,\n"; in emitAsmTiedOperandConstraints()
3002 OS << " uint64_t &ErrorInfo) {\n"; in emitAsmTiedOperandConstraints()
3003 OS << " assert(Kind < CVT_NUM_SIGNATURES && \"Invalid signature!\");\n"; in emitAsmTiedOperandConstraints()
3004 OS << " const uint8_t *Converter = ConversionTable[Kind];\n"; in emitAsmTiedOperandConstraints()
3005 OS << " for (const uint8_t *p = Converter; *p; p+= 2) {\n"; in emitAsmTiedOperandConstraints()
3006 OS << " switch (*p) {\n"; in emitAsmTiedOperandConstraints()
3007 OS << " case CVT_Tied: {\n"; in emitAsmTiedOperandConstraints()
3008 OS << " unsigned OpIdx = *(p+1);\n"; in emitAsmTiedOperandConstraints()
3009 OS << " assert(OpIdx < (size_t)(std::end(TiedAsmOperandTable) -\n"; in emitAsmTiedOperandConstraints()
3010 OS << " std::begin(TiedAsmOperandTable)) &&\n"; in emitAsmTiedOperandConstraints()
3011 OS << " \"Tied operand not found\");\n"; in emitAsmTiedOperandConstraints()
3012 OS << " unsigned OpndNum1 = TiedAsmOperandTable[OpIdx][1];\n"; in emitAsmTiedOperandConstraints()
3013 OS << " unsigned OpndNum2 = TiedAsmOperandTable[OpIdx][2];\n"; in emitAsmTiedOperandConstraints()
3014 OS << " if (OpndNum1 != OpndNum2) {\n"; in emitAsmTiedOperandConstraints()
3015 OS << " auto &SrcOp1 = Operands[OpndNum1];\n"; in emitAsmTiedOperandConstraints()
3016 OS << " auto &SrcOp2 = Operands[OpndNum2];\n"; in emitAsmTiedOperandConstraints()
3017 OS << " if (SrcOp1->isReg() && SrcOp2->isReg()) {\n"; in emitAsmTiedOperandConstraints()
3018 OS << " if (!AsmParser.regsEqual(*SrcOp1, *SrcOp2)) {\n"; in emitAsmTiedOperandConstraints()
3019 OS << " ErrorInfo = OpndNum2;\n"; in emitAsmTiedOperandConstraints()
3020 OS << " return false;\n"; in emitAsmTiedOperandConstraints()
3021 OS << " }\n"; in emitAsmTiedOperandConstraints()
3022 OS << " }\n"; in emitAsmTiedOperandConstraints()
3023 OS << " }\n"; in emitAsmTiedOperandConstraints()
3024 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3025 OS << " }\n"; in emitAsmTiedOperandConstraints()
3026 OS << " default:\n"; in emitAsmTiedOperandConstraints()
3027 OS << " break;\n"; in emitAsmTiedOperandConstraints()
3028 OS << " }\n"; in emitAsmTiedOperandConstraints()
3029 OS << " }\n"; in emitAsmTiedOperandConstraints()
3030 OS << " return true;\n"; in emitAsmTiedOperandConstraints()
3031 OS << "}\n\n"; in emitAsmTiedOperandConstraints()
3034 static void emitMnemonicSpellChecker(raw_ostream &OS, CodeGenTarget &Target, in emitMnemonicSpellChecker() argument
3036 OS << "static std::string " << Target.getName() in emitMnemonicSpellChecker()
3039 OS << " return \"\";"; in emitMnemonicSpellChecker()
3041 OS << " const unsigned MaxEditDist = 2;\n"; in emitMnemonicSpellChecker()
3042 OS << " std::vector<StringRef> Candidates;\n"; in emitMnemonicSpellChecker()
3043 OS << " StringRef Prev = \"\";\n\n"; in emitMnemonicSpellChecker()
3045 OS << " // Find the appropriate table for this asm variant.\n"; in emitMnemonicSpellChecker()
3046 OS << " const MatchEntry *Start, *End;\n"; in emitMnemonicSpellChecker()
3047 OS << " switch (VariantID) {\n"; in emitMnemonicSpellChecker()
3048 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in emitMnemonicSpellChecker()
3052 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in emitMnemonicSpellChecker()
3055 OS << " }\n\n"; in emitMnemonicSpellChecker()
3056 OS << " for (auto I = Start; I < End; I++) {\n"; in emitMnemonicSpellChecker()
3057 OS << " // Ignore unsupported instructions.\n"; in emitMnemonicSpellChecker()
3058 OS << " if ((FBS & I->RequiredFeatures) != I->RequiredFeatures)\n"; in emitMnemonicSpellChecker()
3059 OS << " continue;\n"; in emitMnemonicSpellChecker()
3060 OS << "\n"; in emitMnemonicSpellChecker()
3061 OS << " StringRef T = I->getMnemonic();\n"; in emitMnemonicSpellChecker()
3062 OS << " // Avoid recomputing the edit distance for the same string.\n"; in emitMnemonicSpellChecker()
3063 OS << " if (T.equals(Prev))\n"; in emitMnemonicSpellChecker()
3064 OS << " continue;\n"; in emitMnemonicSpellChecker()
3065 OS << "\n"; in emitMnemonicSpellChecker()
3066 OS << " Prev = T;\n"; in emitMnemonicSpellChecker()
3067 OS << " unsigned Dist = S.edit_distance(T, false, MaxEditDist);\n"; in emitMnemonicSpellChecker()
3068 OS << " if (Dist <= MaxEditDist)\n"; in emitMnemonicSpellChecker()
3069 OS << " Candidates.push_back(T);\n"; in emitMnemonicSpellChecker()
3070 OS << " }\n"; in emitMnemonicSpellChecker()
3071 OS << "\n"; in emitMnemonicSpellChecker()
3072 OS << " if (Candidates.empty())\n"; in emitMnemonicSpellChecker()
3073 OS << " return \"\";\n"; in emitMnemonicSpellChecker()
3074 OS << "\n"; in emitMnemonicSpellChecker()
3075 OS << " std::string Res = \", did you mean: \";\n"; in emitMnemonicSpellChecker()
3076 OS << " unsigned i = 0;\n"; in emitMnemonicSpellChecker()
3077 OS << " for( ; i < Candidates.size() - 1; i++)\n"; in emitMnemonicSpellChecker()
3078 OS << " Res += Candidates[i].str() + \", \";\n"; in emitMnemonicSpellChecker()
3079 OS << " return Res + Candidates[i].str() + \"?\";\n"; in emitMnemonicSpellChecker()
3081 OS << "}\n"; in emitMnemonicSpellChecker()
3082 OS << "\n"; in emitMnemonicSpellChecker()
3088 raw_ostream &OS) { in emitMatchClassKindNames() argument
3089 OS << "#ifndef NDEBUG\n"; in emitMatchClassKindNames()
3090 OS << "const char *getMatchClassName(MatchClassKind Kind) {\n"; in emitMatchClassKindNames()
3091 OS << " switch (Kind) {\n"; in emitMatchClassKindNames()
3093 OS << " case InvalidMatchClass: return \"InvalidMatchClass\";\n"; in emitMatchClassKindNames()
3094 OS << " case OptionalMatchClass: return \"OptionalMatchClass\";\n"; in emitMatchClassKindNames()
3096 OS << " case " << CI.Name << ": return \"" << CI.Name << "\";\n"; in emitMatchClassKindNames()
3098 OS << " case NumMatchClassKinds: return \"NumMatchClassKinds\";\n"; in emitMatchClassKindNames()
3100 OS << " }\n"; in emitMatchClassKindNames()
3101 OS << " llvm_unreachable(\"unhandled MatchClassKind!\");\n"; in emitMatchClassKindNames()
3102 OS << "}\n\n"; in emitMatchClassKindNames()
3103 OS << "#endif // NDEBUG\n"; in emitMatchClassKindNames()
3106 void AsmMatcherEmitter::run(raw_ostream &OS) { in run() argument
3173 OS << "\n#ifdef GET_ASSEMBLER_HEADER\n"; in run()
3174 OS << "#undef GET_ASSEMBLER_HEADER\n"; in run()
3175 OS << " // This should be included into the middle of the declaration of\n"; in run()
3176 OS << " // your subclasses implementation of MCTargetAsmParser.\n"; in run()
3177 OS << " uint64_t ComputeAvailableFeatures(const FeatureBitset& FB) const;\n"; in run()
3179 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3184 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
3188 OS << " void convertToMapAndConstraints(unsigned Kind,\n "; in run()
3189 OS << " const OperandVector &Operands) override;\n"; in run()
3190 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
3193 OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n"; in run()
3195 OS << " uint64_t &ErrorInfo,\n"; in run()
3196 OS << " bool matchingInlineAsm,\n" in run()
3200 OS << " OperandMatchResultTy MatchOperandParserImpl(\n"; in run()
3201 OS << " OperandVector &Operands,\n"; in run()
3202 OS << " StringRef Mnemonic,\n"; in run()
3203 OS << " bool ParseForAllFeatures = false);\n"; in run()
3205 OS << " OperandMatchResultTy tryCustomParseOperand(\n"; in run()
3206 OS << " OperandVector &Operands,\n"; in run()
3207 OS << " unsigned MCK);\n\n"; in run()
3210 OS << "#endif // GET_ASSEMBLER_HEADER_INFO\n\n"; in run()
3213 OS << "\n#ifdef GET_OPERAND_DIAGNOSTIC_TYPES\n"; in run()
3214 OS << "#undef GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3215 emitOperandDiagnosticTypes(Info, OS); in run()
3216 OS << "#endif // GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
3218 OS << "\n#ifdef GET_REGISTER_MATCHER\n"; in run()
3219 OS << "#undef GET_REGISTER_MATCHER\n\n"; in run()
3223 Info.SubtargetFeatures, OS); in run()
3228 emitMatchRegisterName(Target, AsmParser, OS); in run()
3231 emitMatchRegisterAltName(Target, AsmParser, OS); in run()
3233 OS << "#endif // GET_REGISTER_MATCHER\n\n"; in run()
3235 OS << "\n#ifdef GET_SUBTARGET_FEATURE_NAME\n"; in run()
3236 OS << "#undef GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3239 emitGetSubtargetFeatureName(Info, OS); in run()
3241 OS << "#endif // GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
3243 OS << "\n#ifdef GET_MATCHER_IMPLEMENTATION\n"; in run()
3244 OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3247 bool HasMnemonicAliases = emitMnemonicAliases(OS, Info, Target); in run()
3253 HasOptionalOperands, OS); in run()
3256 emitMatchClassEnumeration(Target, Info.Classes, OS); in run()
3260 emitOperandMatchErrorDiagStrings(Info, OS); in run()
3263 emitRegisterMatchErrorFunc(Info, OS); in run()
3266 emitMatchTokenString(Target, Info.Classes, OS); in run()
3269 emitIsSubclass(Target, Info.Classes, OS); in run()
3272 emitValidateOperandClass(Info, OS); in run()
3274 emitMatchClassKindNames(Info.Classes, OS); in run()
3279 Info.SubtargetFeatures, OS); in run()
3282 emitAsmTiedOperandConstraints(Target, Info, OS); in run()
3299 OS << "static const char *const MnemonicTable =\n"; in run()
3300 StringTable.EmitString(OS); in run()
3301 OS << ";\n\n"; in run()
3313 OS << "namespace {\n"; in run()
3314 OS << " struct MatchEntry {\n"; in run()
3315 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in run()
3317 OS << " uint16_t Opcode;\n"; in run()
3318 OS << " " << getMinimalTypeForRange(Info.Matchables.size()) in run()
3320 OS << " " << getMinimalTypeForEnumBitfield(Info.SubtargetFeatures.size()) in run()
3322 OS << " " << getMinimalTypeForRange( in run()
3325 OS << " StringRef getMnemonic() const {\n"; in run()
3326 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in run()
3327 OS << " MnemonicTable[Mnemonic]);\n"; in run()
3328 OS << " }\n"; in run()
3329 OS << " };\n\n"; in run()
3331 OS << " // Predicate for searching for an opcode.\n"; in run()
3332 OS << " struct LessOpcode {\n"; in run()
3333 OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n"; in run()
3334 OS << " return LHS.getMnemonic() < RHS;\n"; in run()
3335 OS << " }\n"; in run()
3336 OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n"; in run()
3337 OS << " return LHS < RHS.getMnemonic();\n"; in run()
3338 OS << " }\n"; in run()
3339 OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n"; in run()
3340 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in run()
3341 OS << " }\n"; in run()
3342 OS << " };\n"; in run()
3344 OS << "} // end anonymous namespace.\n\n"; in run()
3351 OS << "static const MatchEntry MatchTable" << VC << "[] = {\n"; in run()
3359 OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in run()
3368 if (i) OS << "|"; in run()
3369 OS << MI->RequiredFeatures[i]->getEnumName(); in run()
3372 OS << "0"; in run()
3374 OS << ", { "; in run()
3378 if (i) OS << ", "; in run()
3379 OS << Op.Class->Name; in run()
3381 OS << " }, },\n"; in run()
3384 OS << "};\n\n"; in run()
3387 OS << "#include \"llvm/Support/Debug.h\"\n"; in run()
3388 OS << "#include \"llvm/Support/Format.h\"\n\n"; in run()
3391 OS << "unsigned " << Target.getName() << ClassName << "::\n" in run()
3393 OS << " MCInst &Inst,\n"; in run()
3395 OS << " SmallVectorImpl<NearMissInfo> *NearMisses,\n"; in run()
3397 OS << " uint64_t &ErrorInfo,\n"; in run()
3398 OS << " bool matchingInlineAsm, unsigned VariantID) {\n"; in run()
3401 OS << " // Eliminate obvious mismatches.\n"; in run()
3402 OS << " if (Operands.size() > " in run()
3404 OS << " ErrorInfo = " in run()
3406 OS << " return Match_InvalidOperand;\n"; in run()
3407 OS << " }\n\n"; in run()
3411 OS << " // Get the current feature set.\n"; in run()
3412 OS << " uint64_t AvailableFeatures = getAvailableFeatures();\n\n"; in run()
3414 OS << " // Get the instruction mnemonic, which is the first token.\n"; in run()
3416 OS << " StringRef Mnemonic = ((" << Target.getName() in run()
3419 OS << " StringRef Mnemonic;\n"; in run()
3420 OS << " if (Operands[0]->isToken())\n"; in run()
3421 OS << " Mnemonic = ((" << Target.getName() in run()
3426 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in run()
3427 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);\n\n"; in run()
3432 OS << " // Some state to try to produce better error messages.\n"; in run()
3433 OS << " bool HadMatchOtherThanFeatures = false;\n"; in run()
3434 OS << " bool HadMatchOtherThanPredicate = false;\n"; in run()
3435 OS << " unsigned RetCode = Match_InvalidOperand;\n"; in run()
3436 OS << " uint64_t MissingFeatures = ~0ULL;\n"; in run()
3437 OS << " // Set ErrorInfo to the operand that mismatches if it is\n"; in run()
3438 OS << " // wrong for all instances of the instruction.\n"; in run()
3439 OS << " ErrorInfo = ~0ULL;\n"; in run()
3443 OS << " SmallBitVector OptionalOperandsMask(" << MaxNumOperands << ");\n"; in run()
3447 OS << " // Find the appropriate table for this asm variant.\n"; in run()
3448 OS << " const MatchEntry *Start, *End;\n"; in run()
3449 OS << " switch (VariantID) {\n"; in run()
3450 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in run()
3454 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in run()
3457 OS << " }\n"; in run()
3459 OS << " // Search the table.\n"; in run()
3461 OS << " auto MnemonicRange = " in run()
3464 OS << " auto MnemonicRange = std::make_pair(Start, End);\n"; in run()
3465 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in run()
3466 OS << " if (!Mnemonic.empty())\n"; in run()
3467 OS << " MnemonicRange = " in run()
3471 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"AsmMatcher: found \" <<\n" in run()
3475 OS << " // Return a more specific error code if no mnemonics match.\n"; in run()
3476 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in run()
3477 OS << " return Match_MnemonicFail;\n\n"; in run()
3479 OS << " for (const MatchEntry *it = MnemonicRange.first, " in run()
3481 OS << " it != ie; ++it) {\n"; in run()
3482 OS << " bool HasRequiredFeatures =\n"; in run()
3483 OS << " (AvailableFeatures & it->RequiredFeatures) == " in run()
3485 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Trying to match opcode \"\n"; in run()
3486 OS << " << MII.getName(it->Opcode) << \"\\n\");\n"; in run()
3489 OS << " // Some state to record ways in which this instruction did not match.\n"; in run()
3490 OS << " NearMissInfo OperandNearMiss = NearMissInfo::getSuccess();\n"; in run()
3491 OS << " NearMissInfo FeaturesNearMiss = NearMissInfo::getSuccess();\n"; in run()
3492 OS << " NearMissInfo EarlyPredicateNearMiss = NearMissInfo::getSuccess();\n"; in run()
3493 OS << " NearMissInfo LatePredicateNearMiss = NearMissInfo::getSuccess();\n"; in run()
3494 OS << " bool MultipleInvalidOperands = false;\n"; in run()
3498 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in run()
3499 OS << " assert(Mnemonic == it->getMnemonic());\n"; in run()
3504 OS << " bool OperandsValid = true;\n"; in run()
3506 OS << " OptionalOperandsMask.reset(0, " << MaxNumOperands << ");\n"; in run()
3508 OS << " for (unsigned FormalIdx = " << (HasMnemonicFirst ? "0" : "SIndex") in run()
3511 OS << " auto Formal = " in run()
3513 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3514OS << " dbgs() << \" Matching formal operand class \" << getMatchClassName(F… in run()
3515 OS << " << \" against actual operand at index \" << ActualIdx);\n"; in run()
3516 OS << " if (ActualIdx < Operands.size())\n"; in run()
3517 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \" (\";\n"; in run()
3518 OS << " Operands[ActualIdx]->print(dbgs()); dbgs() << \"): \");\n"; in run()
3519 OS << " else\n"; in run()
3520 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \": \");\n"; in run()
3521 OS << " if (ActualIdx >= Operands.size()) {\n"; in run()
3522OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"actual operand index out of range \");… in run()
3524 OS << " bool ThisOperandValid = (Formal == " <<"InvalidMatchClass) || " in run()
3526 OS << " if (!ThisOperandValid) {\n"; in run()
3527 OS << " if (!OperandNearMiss) {\n"; in run()
3528 OS << " // Record info about match failure for later use.\n"; in run()
3529OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"recording too-few-operands near mi… in run()
3530 OS << " OperandNearMiss =\n"; in run()
3531 OS << " NearMissInfo::getTooFewOperands(Formal, it->Opcode);\n"; in run()
3532OS << " } else if (OperandNearMiss.getKind() != NearMissInfo::NearMissTooFewOperands) {\n… in run()
3533 OS << " // If more than one operand is invalid, give up on this match entry.\n"; in run()
3534 OS << " DEBUG_WITH_TYPE(\n"; in run()
3535 OS << " \"asm-matcher\",\n"; in run()
3536 OS << " dbgs() << \"second invalid operand, giving up on this opcode\\n\");\n"; in run()
3537 OS << " MultipleInvalidOperands = true;\n"; in run()
3538 OS << " break;\n"; in run()
3539 OS << " }\n"; in run()
3540 OS << " } else {\n"; in run()
3541OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"but formal operand not required\\n\"… in run()
3542 OS << " break;\n"; in run()
3543 OS << " }\n"; in run()
3544 OS << " continue;\n"; in run()
3546OS << " OperandsValid = (Formal == InvalidMatchClass) || isSubclass(Formal, OptionalMatchCl… in run()
3547 OS << " if (!OperandsValid) ErrorInfo = ActualIdx;\n"; in run()
3549 OS << " OptionalOperandsMask.set(FormalIdx, " << MaxNumOperands in run()
3552 OS << " break;\n"; in run()
3554 OS << " }\n"; in run()
3555 OS << " MCParsedAsmOperand &Actual = *Operands[ActualIdx];\n"; in run()
3556 OS << " unsigned Diag = validateOperandClass(Actual, Formal);\n"; in run()
3557 OS << " if (Diag == Match_Success) {\n"; in run()
3558 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3559 OS << " dbgs() << \"match success using generic matcher\\n\");\n"; in run()
3560 OS << " ++ActualIdx;\n"; in run()
3561 OS << " continue;\n"; in run()
3562 OS << " }\n"; in run()
3563 OS << " // If the generic handler indicates an invalid operand\n"; in run()
3564 OS << " // failure, check for a special case.\n"; in run()
3565 OS << " if (Diag != Match_Success) {\n"; in run()
3566 OS << " unsigned TargetDiag = validateTargetOperandClass(Actual, Formal);\n"; in run()
3567 OS << " if (TargetDiag == Match_Success) {\n"; in run()
3568 OS << " DEBUG_WITH_TYPE(\"asm-matcher\",\n"; in run()
3569 OS << " dbgs() << \"match success using target matcher\\n\");\n"; in run()
3570 OS << " ++ActualIdx;\n"; in run()
3571 OS << " continue;\n"; in run()
3572 OS << " }\n"; in run()
3573 OS << " // If the target matcher returned a specific error code use\n"; in run()
3574 OS << " // that, else use the one from the generic matcher.\n"; in run()
3575 OS << " if (TargetDiag != Match_InvalidOperand && " in run()
3577 OS << " Diag = TargetDiag;\n"; in run()
3578 OS << " }\n"; in run()
3579 OS << " // If current formal operand wasn't matched and it is optional\n" in run()
3581 OS << " if (Diag == Match_InvalidOperand " in run()
3584 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3586 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"ignoring optional operand\\n\");\n"; in run()
3587 OS << " continue;\n"; in run()
3588 OS << " }\n"; in run()
3591 OS << " if (!OperandNearMiss) {\n"; in run()
3592 OS << " // If this is the first invalid operand we have seen, record some\n"; in run()
3593 OS << " // information about it.\n"; in run()
3594 OS << " DEBUG_WITH_TYPE(\n"; in run()
3595 OS << " \"asm-matcher\",\n"; in run()
3596 OS << " dbgs()\n"; in run()
3597 OS << " << \"operand match failed, recording near-miss with diag code \"\n"; in run()
3598 OS << " << Diag << \"\\n\");\n"; in run()
3599 OS << " OperandNearMiss =\n"; in run()
3600 OS << " NearMissInfo::getMissedOperand(Diag, Formal, it->Opcode, ActualIdx);\n"; in run()
3601 OS << " ++ActualIdx;\n"; in run()
3602 OS << " } else {\n"; in run()
3603 OS << " // If more than one operand is invalid, give up on this match entry.\n"; in run()
3604 OS << " DEBUG_WITH_TYPE(\n"; in run()
3605 OS << " \"asm-matcher\",\n"; in run()
3606 OS << " dbgs() << \"second operand mismatch, skipping this opcode\\n\");\n"; in run()
3607 OS << " MultipleInvalidOperands = true;\n"; in run()
3608 OS << " break;\n"; in run()
3609 OS << " }\n"; in run()
3610 OS << " }\n\n"; in run()
3612 OS << " // If this operand is broken for all of the instances of this\n"; in run()
3613 OS << " // mnemonic, keep track of it so we can report loc info.\n"; in run()
3614 OS << " // If we already had a match that only failed due to a\n"; in run()
3615 OS << " // target predicate, that diagnostic is preferred.\n"; in run()
3616 OS << " if (!HadMatchOtherThanPredicate &&\n"; in run()
3617 OS << " (it == MnemonicRange.first || ErrorInfo <= ActualIdx)) {\n"; in run()
3618 OS << " if (HasRequiredFeatures && (ErrorInfo != ActualIdx || Diag " in run()
3620 OS << " RetCode = Diag;\n"; in run()
3621 OS << " ErrorInfo = ActualIdx;\n"; in run()
3622 OS << " }\n"; in run()
3623 OS << " // Otherwise, just reject this instance of the mnemonic.\n"; in run()
3624 OS << " OperandsValid = false;\n"; in run()
3625 OS << " break;\n"; in run()
3626 OS << " }\n\n"; in run()
3630 OS << " if (MultipleInvalidOperands) {\n"; in run()
3632 OS << " if (!OperandsValid) {\n"; in run()
3633 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3634 OS << " \"operand mismatches, ignoring \"\n"; in run()
3635 OS << " \"this opcode\\n\");\n"; in run()
3636 OS << " continue;\n"; in run()
3637 OS << " }\n"; in run()
3640 OS << " if (!HasRequiredFeatures) {\n"; in run()
3642 OS << " HadMatchOtherThanFeatures = true;\n"; in run()
3643 OS << " uint64_t NewMissingFeatures = it->RequiredFeatures & " in run()
3645 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Missing target features: \"\n"; in run()
3646 OS << " << format_hex(NewMissingFeatures, 18)\n"; in run()
3647 OS << " << \"\\n\");\n"; in run()
3649 OS << " FeaturesNearMiss = NearMissInfo::getMissedFeature(NewMissingFeatures);\n"; in run()
3651 OS << " if (countPopulation(NewMissingFeatures) <=\n" in run()
3653 OS << " MissingFeatures = NewMissingFeatures;\n"; in run()
3654 OS << " continue;\n"; in run()
3656 OS << " }\n"; in run()
3657 OS << "\n"; in run()
3658 OS << " Inst.clear();\n\n"; in run()
3659 OS << " Inst.setOpcode(it->Opcode);\n"; in run()
3661 OS << " // We have a potential match but have not rendered the operands.\n" in run()
3672 OS << " DEBUG_WITH_TYPE(\n"; in run()
3673 OS << " \"asm-matcher\",\n"; in run()
3674 OS << " dbgs() << \"Early target match predicate failed with diag code \"\n"; in run()
3675 OS << " << MatchResult << \"\\n\");\n"; in run()
3677 OS << " EarlyPredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n"; in run()
3679 OS << " RetCode = MatchResult;\n" in run()
3683 OS << " }\n\n"; in run()
3686 OS << " // If we did not successfully match the operands, then we can't convert to\n"; in run()
3687 OS << " // an MCInst, so bail out on this instruction variant now.\n"; in run()
3688 OS << " if (OperandNearMiss) {\n"; in run()
3689 OS << " // If the operand mismatch was the only problem, reprrt it as a near-miss.\n"; in run()
3690 OS << " if (NearMisses && !FeaturesNearMiss && !EarlyPredicateNearMiss) {\n"; in run()
3691 OS << " DEBUG_WITH_TYPE(\n"; in run()
3692 OS << " \"asm-matcher\",\n"; in run()
3693 OS << " dbgs()\n"; in run()
3694 OS << " << \"Opcode result: one mismatched operand, adding near-miss\\n\");\n"; in run()
3695 OS << " NearMisses->push_back(OperandNearMiss);\n"; in run()
3696 OS << " } else {\n"; in run()
3697 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3698 OS << " \"types of mismatch, so not \"\n"; in run()
3699 OS << " \"reporting near-miss\\n\");\n"; in run()
3700 OS << " }\n"; in run()
3701 OS << " continue;\n"; in run()
3702 OS << " }\n\n"; in run()
3705 OS << " if (matchingInlineAsm) {\n"; in run()
3706 OS << " convertToMapAndConstraints(it->ConvertFn, Operands);\n"; in run()
3708 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3710 OS << " return Match_InvalidTiedOperand;\n"; in run()
3711 OS << "\n"; in run()
3713 OS << " return Match_Success;\n"; in run()
3714 OS << " }\n\n"; in run()
3715 OS << " // We have selected a definite instruction, convert the parsed\n" in run()
3718 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands,\n" in run()
3721 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n"; in run()
3723 OS << "\n"; in run()
3726 OS << " // We have a potential match. Check the target predicate to\n" in run()
3735 OS << " LatePredicateNearMiss = NearMissInfo::getMissedPredicate(MatchResult);\n"; in run()
3737 OS << " RetCode = MatchResult;\n" in run()
3741 OS << " }\n\n"; in run()
3744 OS << " int NumNearMisses = ((int)(bool)OperandNearMiss +\n"; in run()
3745 OS << " (int)(bool)FeaturesNearMiss +\n"; in run()
3746 OS << " (int)(bool)EarlyPredicateNearMiss +\n"; in run()
3747 OS << " (int)(bool)LatePredicateNearMiss);\n"; in run()
3748 OS << " if (NumNearMisses == 1) {\n"; in run()
3749 OS << " // We had exactly one type of near-miss, so add that to the list.\n"; in run()
3750 OS << " assert(!OperandNearMiss && \"OperandNearMiss was handled earlier\");\n"; in run()
3751OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: found one type of \"\n"; in run()
3752 OS << " \"mismatch, so reporting a \"\n"; in run()
3753 OS << " \"near-miss\\n\");\n"; in run()
3754 OS << " if (NearMisses && FeaturesNearMiss)\n"; in run()
3755 OS << " NearMisses->push_back(FeaturesNearMiss);\n"; in run()
3756 OS << " else if (NearMisses && EarlyPredicateNearMiss)\n"; in run()
3757 OS << " NearMisses->push_back(EarlyPredicateNearMiss);\n"; in run()
3758 OS << " else if (NearMisses && LatePredicateNearMiss)\n"; in run()
3759 OS << " NearMisses->push_back(LatePredicateNearMiss);\n"; in run()
3760 OS << "\n"; in run()
3761 OS << " continue;\n"; in run()
3762 OS << " } else if (NumNearMisses > 1) {\n"; in run()
3763 OS << " // This instruction missed in more than one way, so ignore it.\n"; in run()
3764 OS << " DEBUG_WITH_TYPE(\"asm-matcher\", dbgs() << \"Opcode result: multiple \"\n"; in run()
3765 OS << " \"types of mismatch, so not \"\n"; in run()
3766 OS << " \"reporting near-miss\\n\");\n"; in run()
3767 OS << " continue;\n"; in run()
3768 OS << " }\n"; in run()
3774 OS << " " << InsnCleanupFn << "(Inst);\n"; in run()
3777 OS << " std::string Info;\n"; in run()
3778 OS << " if (!getParser().getTargetParser().\n"; in run()
3779 OS << " getTargetOptions().MCNoDeprecatedWarn &&\n"; in run()
3780 OS << " MII.get(Inst.getOpcode()).getDeprecatedInfo(Inst, getSTI(), Info)) {\n"; in run()
3781 OS << " SMLoc Loc = ((" << Target.getName() in run()
3783 OS << " getParser().Warning(Loc, Info, None);\n"; in run()
3784 OS << " }\n"; in run()
3788 OS << " if (!checkAsmTiedOperandConstraints(*this, it->ConvertFn, " in run()
3790 OS << " return Match_InvalidTiedOperand;\n"; in run()
3791 OS << "\n"; in run()
3794 OS << " DEBUG_WITH_TYPE(\n"; in run()
3795 OS << " \"asm-matcher\",\n"; in run()
3796 OS << " dbgs() << \"Opcode result: complete match, selecting this opcode\\n\");\n"; in run()
3797 OS << " return Match_Success;\n"; in run()
3798 OS << " }\n\n"; in run()
3801 OS << " // No instruction variants matched exactly.\n"; in run()
3802 OS << " return Match_NearMisses;\n"; in run()
3804 OS << " // Okay, we had no match. Try to return a useful error code.\n"; in run()
3805 OS << " if (HadMatchOtherThanPredicate || !HadMatchOtherThanFeatures)\n"; in run()
3806 OS << " return RetCode;\n\n"; in run()
3807 OS << " // Missing feature matches return which features were missing\n"; in run()
3808 OS << " ErrorInfo = MissingFeatures;\n"; in run()
3809 OS << " return Match_MissingFeature;\n"; in run()
3811 OS << "}\n\n"; in run()
3814 emitCustomOperandParsing(OS, Target, Info, ClassName, StringTable, in run()
3817 OS << "#endif // GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3819 OS << "\n#ifdef GET_MNEMONIC_SPELL_CHECKER\n"; in run()
3820 OS << "#undef GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
3822 emitMnemonicSpellChecker(OS, Target, VariantCount); in run()
3824 OS << "#endif // GET_MNEMONIC_SPELL_CHECKER\n\n"; in run()
3829 void EmitAsmMatcher(RecordKeeper &RK, raw_ostream &OS) { in EmitAsmMatcher() argument
3830 emitSourceFileHeader("Assembly Matcher Source Fragment", OS); in EmitAsmMatcher()
3831 AsmMatcherEmitter(RK).run(OS); in EmitAsmMatcher()