Lines Matching refs:OS
1833 raw_ostream &OS) { in emitConvertFuncs() argument
2122 OS << "namespace {\n"; in emitConvertFuncs()
2125 OS << "enum OperatorConversionKind {\n"; in emitConvertFuncs()
2127 OS << " " << Converter << ",\n"; in emitConvertFuncs()
2128 OS << " CVT_NUM_CONVERTERS\n"; in emitConvertFuncs()
2129 OS << "};\n\n"; in emitConvertFuncs()
2132 OS << "enum InstructionConversionKind {\n"; in emitConvertFuncs()
2134 OS << " " << Signature << ",\n"; in emitConvertFuncs()
2135 OS << " CVT_NUM_SIGNATURES\n"; in emitConvertFuncs()
2136 OS << "};\n\n"; in emitConvertFuncs()
2138 OS << "} // end anonymous namespace\n\n"; in emitConvertFuncs()
2141 OS << "static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][" in emitConvertFuncs()
2146 OS << " // " << InstructionConversionKinds[Row] << "\n"; in emitConvertFuncs()
2147 OS << " { "; in emitConvertFuncs()
2149 OS << OperandConversionKinds[ConversionTable[Row][i]] << ", " in emitConvertFuncs()
2151 OS << "CVT_Done },\n"; in emitConvertFuncs()
2154 OS << "};\n\n"; in emitConvertFuncs()
2157 OS << CvtOS.str(); in emitConvertFuncs()
2160 OS << OpOS.str(); in emitConvertFuncs()
2166 raw_ostream &OS) { in emitMatchClassEnumeration() argument
2167 OS << "namespace {\n\n"; in emitMatchClassEnumeration()
2169 OS << "/// MatchClassKind - The kinds of classes which participate in\n" in emitMatchClassEnumeration()
2171 OS << "enum MatchClassKind {\n"; in emitMatchClassEnumeration()
2172 OS << " InvalidMatchClass = 0,\n"; in emitMatchClassEnumeration()
2173 OS << " OptionalMatchClass = 1,\n"; in emitMatchClassEnumeration()
2175 OS << " " << CI.Name << ", // "; in emitMatchClassEnumeration()
2177 OS << "'" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2180 OS << "register class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2182 OS << "derived register class\n"; in emitMatchClassEnumeration()
2184 OS << "user defined class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
2187 OS << " NumMatchClassKinds\n"; in emitMatchClassEnumeration()
2188 OS << "};\n\n"; in emitMatchClassEnumeration()
2190 OS << "}\n\n"; in emitMatchClassEnumeration()
2195 raw_ostream &OS) { in emitValidateOperandClass() argument
2196 OS << "static unsigned validateOperandClass(MCParsedAsmOperand &GOp, " in emitValidateOperandClass()
2198 OS << " " << Info.Target.getName() << "Operand &Operand = (" in emitValidateOperandClass()
2202 OS << " if (Kind == InvalidMatchClass)\n"; in emitValidateOperandClass()
2203 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n\n"; in emitValidateOperandClass()
2207 OS << " if (Operand.isToken())\n"; in emitValidateOperandClass()
2208 OS << " return isSubclass(matchTokenString(Operand.getToken()), Kind) ?\n" in emitValidateOperandClass()
2214 OS << " switch (Kind) {\n" in emitValidateOperandClass()
2220 OS << " // '" << CI.ClassName << "' class\n"; in emitValidateOperandClass()
2221 OS << " case " << CI.Name << ":\n"; in emitValidateOperandClass()
2222 OS << " if (Operand." << CI.PredicateMethod << "())\n"; in emitValidateOperandClass()
2223 OS << " return MCTargetAsmParser::Match_Success;\n"; in emitValidateOperandClass()
2225 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitValidateOperandClass()
2228 OS << " break;\n"; in emitValidateOperandClass()
2230 OS << " } // end switch (Kind)\n\n"; in emitValidateOperandClass()
2233 OS << " if (Operand.isReg()) {\n"; in emitValidateOperandClass()
2234 OS << " MatchClassKind OpKind;\n"; in emitValidateOperandClass()
2235 OS << " switch (Operand.getReg()) {\n"; in emitValidateOperandClass()
2236 OS << " default: OpKind = InvalidMatchClass; break;\n"; in emitValidateOperandClass()
2238 OS << " case " << Info.Target.getName() << "::" in emitValidateOperandClass()
2241 OS << " }\n"; in emitValidateOperandClass()
2242 OS << " return isSubclass(OpKind, Kind) ? " in emitValidateOperandClass()
2248 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitValidateOperandClass()
2249 OS << "}\n\n"; in emitValidateOperandClass()
2255 raw_ostream &OS) { in emitIsSubclass() argument
2256 OS << "/// isSubclass - Compute whether \\p A is a subclass of \\p B.\n"; in emitIsSubclass()
2257 OS << "static bool isSubclass(MatchClassKind A, MatchClassKind B) {\n"; in emitIsSubclass()
2258 OS << " if (A == B)\n"; in emitIsSubclass()
2259 OS << " return true;\n\n"; in emitIsSubclass()
2276 OS << " switch (A) {\n"; in emitIsSubclass()
2277 OS << " default:\n"; in emitIsSubclass()
2278 OS << " return false;\n"; in emitIsSubclass()
2282 OS << "\n case " << A.Name << ":\n"; in emitIsSubclass()
2285 OS << " return B == " << SuperClasses.back() << ";\n"; in emitIsSubclass()
2290 OS << " switch (B) {\n"; in emitIsSubclass()
2291 OS << " default: return false;\n"; in emitIsSubclass()
2293 OS << " case " << SC << ": return true;\n"; in emitIsSubclass()
2294 OS << " }\n"; in emitIsSubclass()
2297 OS << " return false;\n"; in emitIsSubclass()
2304 OS << " }\n"; in emitIsSubclass()
2306 OS << " return false;\n"; in emitIsSubclass()
2308 OS << "}\n\n"; in emitIsSubclass()
2315 raw_ostream &OS) { in emitMatchTokenString() argument
2323 OS << "static MatchClassKind matchTokenString(StringRef Name) {\n"; in emitMatchTokenString()
2325 StringMatcher("Name", Matches, OS).Emit(); in emitMatchTokenString()
2327 OS << " return InvalidMatchClass;\n"; in emitMatchTokenString()
2328 OS << "}\n\n"; in emitMatchTokenString()
2334 raw_ostream &OS) { in emitMatchRegisterName() argument
2346 OS << "static unsigned MatchRegisterName(StringRef Name) {\n"; in emitMatchRegisterName()
2348 StringMatcher("Name", Matches, OS).Emit(); in emitMatchRegisterName()
2350 OS << " return 0;\n"; in emitMatchRegisterName()
2351 OS << "}\n\n"; in emitMatchRegisterName()
2357 raw_ostream &OS) { in emitMatchRegisterAltName() argument
2377 OS << "static unsigned MatchRegisterAltName(StringRef Name) {\n"; in emitMatchRegisterAltName()
2379 StringMatcher("Name", Matches, OS).Emit(); in emitMatchRegisterAltName()
2381 OS << " return 0;\n"; in emitMatchRegisterAltName()
2382 OS << "}\n\n"; in emitMatchRegisterAltName()
2406 raw_ostream &OS) { in emitSubtargetFeatureFlagEnumeration() argument
2407 OS << "// Flags for subtarget features that participate in " in emitSubtargetFeatureFlagEnumeration()
2409 OS << "enum SubtargetFeatureFlag : " << getMinimalRequiredFeaturesType(Info) in emitSubtargetFeatureFlagEnumeration()
2413 OS << " " << SFI.getEnumName() << " = (1ULL << " << SFI.Index << "),\n"; in emitSubtargetFeatureFlagEnumeration()
2415 OS << " Feature_None = 0\n"; in emitSubtargetFeatureFlagEnumeration()
2416 OS << "};\n\n"; in emitSubtargetFeatureFlagEnumeration()
2420 static void emitOperandDiagnosticTypes(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandDiagnosticTypes() argument
2432 OS << " Match_" << Type << ",\n"; in emitOperandDiagnosticTypes()
2433 OS << " END_OPERAND_DIAGNOSTIC_TYPES\n"; in emitOperandDiagnosticTypes()
2438 static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) { in emitGetSubtargetFeatureName() argument
2439 OS << "// User-level names for subtarget features that participate in\n" in emitGetSubtargetFeatureName()
2443 OS << " switch(Val) {\n"; in emitGetSubtargetFeatureName()
2447 OS << " case " << SFI.getEnumName() << ": return \"" in emitGetSubtargetFeatureName()
2450 OS << " default: return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2451 OS << " }\n"; in emitGetSubtargetFeatureName()
2454 OS << " return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2456 OS << "}\n\n"; in emitGetSubtargetFeatureName()
2462 raw_ostream &OS) { in emitComputeAvailableFeatures() argument
2466 OS << "uint64_t " << Info.Target.getName() << ClassName << "::\n" in emitComputeAvailableFeatures()
2468 OS << " uint64_t Features = 0;\n"; in emitComputeAvailableFeatures()
2472 OS << " if ("; in emitComputeAvailableFeatures()
2480 OS << " && "; in emitComputeAvailableFeatures()
2489 OS << "("; in emitComputeAvailableFeatures()
2491 OS << "!"; in emitComputeAvailableFeatures()
2492 OS << "FB[" << Info.Target.getName() << "::" << Cond << "])"; in emitComputeAvailableFeatures()
2501 OS << ")\n"; in emitComputeAvailableFeatures()
2502 OS << " Features |= " << SFI.getEnumName() << ";\n"; in emitComputeAvailableFeatures()
2504 OS << " return Features;\n"; in emitComputeAvailableFeatures()
2505 OS << "}\n\n"; in emitComputeAvailableFeatures()
2532 static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info, in emitMnemonicAliasVariant() argument
2599 StringMatcher("Mnemonic", Cases, OS).Emit(Indent); in emitMnemonicAliasVariant()
2604 static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info, in emitMnemonicAliases() argument
2614 OS << "static void applyMnemonicAliases(StringRef &Mnemonic, " in emitMnemonicAliases()
2616 OS << " switch (VariantID) {\n"; in emitMnemonicAliases()
2622 OS << " case " << AsmParserVariantNo << ":\n"; in emitMnemonicAliases()
2623 emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2, in emitMnemonicAliases()
2625 OS << " break;\n"; in emitMnemonicAliases()
2627 OS << " }\n"; in emitMnemonicAliases()
2630 emitMnemonicAliasVariant(OS, Info, Aliases); in emitMnemonicAliases()
2632 OS << "}\n\n"; in emitMnemonicAliases()
2637 static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, in emitCustomOperandParsing() argument
2647 OS << "namespace {\n"; in emitCustomOperandParsing()
2648 OS << " struct OperandMatchEntry {\n"; in emitCustomOperandParsing()
2649 OS << " " << getMinimalRequiredFeaturesType(Info) in emitCustomOperandParsing()
2651 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in emitCustomOperandParsing()
2653 OS << " " << getMinimalTypeForRange(std::distance( in emitCustomOperandParsing()
2655 OS << " " << getMinimalTypeForRange(MaxMask) in emitCustomOperandParsing()
2657 OS << " StringRef getMnemonic() const {\n"; in emitCustomOperandParsing()
2658 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in emitCustomOperandParsing()
2659 OS << " MnemonicTable[Mnemonic]);\n"; in emitCustomOperandParsing()
2660 OS << " }\n"; in emitCustomOperandParsing()
2661 OS << " };\n\n"; in emitCustomOperandParsing()
2663 OS << " // Predicate for searching for an opcode.\n"; in emitCustomOperandParsing()
2664 OS << " struct LessOpcodeOperand {\n"; in emitCustomOperandParsing()
2665 OS << " bool operator()(const OperandMatchEntry &LHS, StringRef RHS) {\n"; in emitCustomOperandParsing()
2666 OS << " return LHS.getMnemonic() < RHS;\n"; in emitCustomOperandParsing()
2667 OS << " }\n"; in emitCustomOperandParsing()
2668 OS << " bool operator()(StringRef LHS, const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2669 OS << " return LHS < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2670 OS << " }\n"; in emitCustomOperandParsing()
2671 OS << " bool operator()(const OperandMatchEntry &LHS,"; in emitCustomOperandParsing()
2672 OS << " const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2673 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2674 OS << " }\n"; in emitCustomOperandParsing()
2675 OS << " };\n"; in emitCustomOperandParsing()
2677 OS << "} // end anonymous namespace.\n\n"; in emitCustomOperandParsing()
2679 OS << "static const OperandMatchEntry OperandMatchTable[" in emitCustomOperandParsing()
2682 OS << " /* Operand List Mask, Mnemonic, Operand Class, Features */\n"; in emitCustomOperandParsing()
2686 OS << " { "; in emitCustomOperandParsing()
2691 if (i) OS << "|"; in emitCustomOperandParsing()
2692 OS << II.RequiredFeatures[i]->getEnumName(); in emitCustomOperandParsing()
2695 OS << "0"; in emitCustomOperandParsing()
2699 OS << ", " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in emitCustomOperandParsing()
2702 OS << OMI.CI->Name; in emitCustomOperandParsing()
2704 OS << ", " << OMI.OperandMask; in emitCustomOperandParsing()
2705 OS << " /* "; in emitCustomOperandParsing()
2710 OS << ", "; in emitCustomOperandParsing()
2711 OS << i; in emitCustomOperandParsing()
2714 OS << " */"; in emitCustomOperandParsing()
2716 OS << " },\n"; in emitCustomOperandParsing()
2718 OS << "};\n\n"; in emitCustomOperandParsing()
2722 OS << Target.getName() << ClassName << "::OperandMatchResultTy " in emitCustomOperandParsing()
2731 OS << " case " << CI.Name << ":\n" in emitCustomOperandParsing()
2735 OS << " default:\n"; in emitCustomOperandParsing()
2736 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2737 OS << " }\n"; in emitCustomOperandParsing()
2738 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2739 OS << "}\n\n"; in emitCustomOperandParsing()
2744 OS << Target.getName() << ClassName << "::OperandMatchResultTy " in emitCustomOperandParsing()
2750 OS << " // Get the current feature set.\n"; in emitCustomOperandParsing()
2751 OS << " uint64_t AvailableFeatures = getAvailableFeatures();\n\n"; in emitCustomOperandParsing()
2753 OS << " // Get the next operand index.\n"; in emitCustomOperandParsing()
2754 OS << " unsigned NextOpNum = Operands.size()" in emitCustomOperandParsing()
2758 OS << " // Search the table.\n"; in emitCustomOperandParsing()
2760 OS << " auto MnemonicRange =\n"; in emitCustomOperandParsing()
2761 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2763 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2765 OS << " auto MnemonicRange = std::make_pair(std::begin(OperandMatchTable)," in emitCustomOperandParsing()
2767 OS << " if (!Mnemonic.empty())\n"; in emitCustomOperandParsing()
2768 OS << " MnemonicRange =\n"; in emitCustomOperandParsing()
2769 OS << " std::equal_range(std::begin(OperandMatchTable), " in emitCustomOperandParsing()
2771 OS << " Mnemonic, LessOpcodeOperand());\n\n"; in emitCustomOperandParsing()
2774 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitCustomOperandParsing()
2775 OS << " return MatchOperand_NoMatch;\n\n"; in emitCustomOperandParsing()
2777 OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n" in emitCustomOperandParsing()
2780 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in emitCustomOperandParsing()
2781 OS << " assert(Mnemonic == it->getMnemonic());\n\n"; in emitCustomOperandParsing()
2784 OS << " // check if the available features match\n"; in emitCustomOperandParsing()
2785 OS << " if ((AvailableFeatures & it->RequiredFeatures) " in emitCustomOperandParsing()
2787 OS << " continue;\n"; in emitCustomOperandParsing()
2788 OS << " }\n\n"; in emitCustomOperandParsing()
2791 OS << " // check if the operand in question has a custom parser.\n"; in emitCustomOperandParsing()
2792 OS << " if (!(it->OperandMask & (1 << NextOpNum)))\n"; in emitCustomOperandParsing()
2793 OS << " continue;\n\n"; in emitCustomOperandParsing()
2796 OS << " // call custom parse method to handle the operand\n"; in emitCustomOperandParsing()
2797 OS << " OperandMatchResultTy Result = "; in emitCustomOperandParsing()
2798 OS << "tryCustomParseOperand(Operands, it->Class);\n"; in emitCustomOperandParsing()
2799 OS << " if (Result != MatchOperand_NoMatch)\n"; in emitCustomOperandParsing()
2800 OS << " return Result;\n"; in emitCustomOperandParsing()
2801 OS << " }\n\n"; in emitCustomOperandParsing()
2803 OS << " // Okay, we had no match.\n"; in emitCustomOperandParsing()
2804 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2805 OS << "}\n\n"; in emitCustomOperandParsing()
2808 void AsmMatcherEmitter::run(raw_ostream &OS) { in run() argument
2873 OS << "\n#ifdef GET_ASSEMBLER_HEADER\n"; in run()
2874 OS << "#undef GET_ASSEMBLER_HEADER\n"; in run()
2875 OS << " // This should be included into the middle of the declaration of\n"; in run()
2876 OS << " // your subclasses implementation of MCTargetAsmParser.\n"; in run()
2877 OS << " uint64_t ComputeAvailableFeatures(const FeatureBitset& FB) const;\n"; in run()
2879 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
2884 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
2888 OS << " void convertToMapAndConstraints(unsigned Kind,\n "; in run()
2889 OS << " const OperandVector &Operands) override;\n"; in run()
2891 OS << " bool mnemonicIsValid(StringRef Mnemonic, unsigned VariantID);\n"; in run()
2892 OS << " unsigned MatchInstructionImpl(const OperandVector &Operands,\n" in run()
2899 OS << "\n enum OperandMatchResultTy {\n"; in run()
2900 OS << " MatchOperand_Success, // operand matched successfully\n"; in run()
2901 OS << " MatchOperand_NoMatch, // operand did not match\n"; in run()
2902 OS << " MatchOperand_ParseFail // operand matched but had errors\n"; in run()
2903 OS << " };\n"; in run()
2904 OS << " OperandMatchResultTy MatchOperandParserImpl(\n"; in run()
2905 OS << " OperandVector &Operands,\n"; in run()
2906 OS << " StringRef Mnemonic);\n"; in run()
2908 OS << " OperandMatchResultTy tryCustomParseOperand(\n"; in run()
2909 OS << " OperandVector &Operands,\n"; in run()
2910 OS << " unsigned MCK);\n\n"; in run()
2913 OS << "#endif // GET_ASSEMBLER_HEADER_INFO\n\n"; in run()
2916 OS << "\n#ifdef GET_OPERAND_DIAGNOSTIC_TYPES\n"; in run()
2917 OS << "#undef GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
2918 emitOperandDiagnosticTypes(Info, OS); in run()
2919 OS << "#endif // GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
2921 OS << "\n#ifdef GET_REGISTER_MATCHER\n"; in run()
2922 OS << "#undef GET_REGISTER_MATCHER\n\n"; in run()
2925 emitSubtargetFeatureFlagEnumeration(Info, OS); in run()
2930 emitMatchRegisterName(Target, AsmParser, OS); in run()
2933 emitMatchRegisterAltName(Target, AsmParser, OS); in run()
2935 OS << "#endif // GET_REGISTER_MATCHER\n\n"; in run()
2937 OS << "\n#ifdef GET_SUBTARGET_FEATURE_NAME\n"; in run()
2938 OS << "#undef GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
2941 emitGetSubtargetFeatureName(Info, OS); in run()
2943 OS << "#endif // GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
2945 OS << "\n#ifdef GET_MATCHER_IMPLEMENTATION\n"; in run()
2946 OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n"; in run()
2949 bool HasMnemonicAliases = emitMnemonicAliases(OS, Info, Target); in run()
2955 HasOptionalOperands, OS); in run()
2958 emitMatchClassEnumeration(Target, Info.Classes, OS); in run()
2961 emitMatchTokenString(Target, Info.Classes, OS); in run()
2964 emitIsSubclass(Target, Info.Classes, OS); in run()
2967 emitValidateOperandClass(Info, OS); in run()
2970 emitComputeAvailableFeatures(Info, OS); in run()
2987 OS << "static const char *const MnemonicTable =\n"; in run()
2988 StringTable.EmitString(OS); in run()
2989 OS << ";\n\n"; in run()
3001 OS << "namespace {\n"; in run()
3002 OS << " struct MatchEntry {\n"; in run()
3003 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in run()
3005 OS << " uint16_t Opcode;\n"; in run()
3006 OS << " " << getMinimalTypeForRange(Info.Matchables.size()) in run()
3008 OS << " " << getMinimalRequiredFeaturesType(Info) in run()
3010 OS << " " << getMinimalTypeForRange( in run()
3013 OS << " StringRef getMnemonic() const {\n"; in run()
3014 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in run()
3015 OS << " MnemonicTable[Mnemonic]);\n"; in run()
3016 OS << " }\n"; in run()
3017 OS << " };\n\n"; in run()
3019 OS << " // Predicate for searching for an opcode.\n"; in run()
3020 OS << " struct LessOpcode {\n"; in run()
3021 OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n"; in run()
3022 OS << " return LHS.getMnemonic() < RHS;\n"; in run()
3023 OS << " }\n"; in run()
3024 OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n"; in run()
3025 OS << " return LHS < RHS.getMnemonic();\n"; in run()
3026 OS << " }\n"; in run()
3027 OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n"; in run()
3028 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in run()
3029 OS << " }\n"; in run()
3030 OS << " };\n"; in run()
3032 OS << "} // end anonymous namespace.\n\n"; in run()
3039 OS << "static const MatchEntry MatchTable" << VC << "[] = {\n"; in run()
3047 OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in run()
3056 if (i) OS << "|"; in run()
3057 OS << MI->RequiredFeatures[i]->getEnumName(); in run()
3060 OS << "0"; in run()
3062 OS << ", { "; in run()
3066 if (i) OS << ", "; in run()
3067 OS << Op.Class->Name; in run()
3069 OS << " }, },\n"; in run()
3072 OS << "};\n\n"; in run()
3077 OS << "bool " << Target.getName() << ClassName << "::\n" in run()
3079 OS << " // Find the appropriate table for this asm variant.\n"; in run()
3080 OS << " const MatchEntry *Start, *End;\n"; in run()
3081 OS << " switch (VariantID) {\n"; in run()
3082 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in run()
3086 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in run()
3089 OS << " }\n"; in run()
3090 OS << " // Search the table.\n"; in run()
3091 OS << " auto MnemonicRange = "; in run()
3092 OS << "std::equal_range(Start, End, Mnemonic, LessOpcode());\n"; in run()
3093 OS << " return MnemonicRange.first != MnemonicRange.second;\n"; in run()
3094 OS << "}\n\n"; in run()
3098 OS << "unsigned " << Target.getName() << ClassName << "::\n" in run()
3100 OS << " MCInst &Inst, uint64_t &ErrorInfo,\n" in run()
3103 OS << " // Eliminate obvious mismatches.\n"; in run()
3104 OS << " if (Operands.size() > " in run()
3106 OS << " ErrorInfo = " in run()
3108 OS << " return Match_InvalidOperand;\n"; in run()
3109 OS << " }\n\n"; in run()
3112 OS << " // Get the current feature set.\n"; in run()
3113 OS << " uint64_t AvailableFeatures = getAvailableFeatures();\n\n"; in run()
3115 OS << " // Get the instruction mnemonic, which is the first token.\n"; in run()
3117 OS << " StringRef Mnemonic = ((" << Target.getName() in run()
3120 OS << " StringRef Mnemonic;\n"; in run()
3121 OS << " if (Operands[0]->isToken())\n"; in run()
3122 OS << " Mnemonic = ((" << Target.getName() in run()
3127 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in run()
3128 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);\n\n"; in run()
3132 OS << " // Some state to try to produce better error messages.\n"; in run()
3133 OS << " bool HadMatchOtherThanFeatures = false;\n"; in run()
3134 OS << " bool HadMatchOtherThanPredicate = false;\n"; in run()
3135 OS << " unsigned RetCode = Match_InvalidOperand;\n"; in run()
3136 OS << " uint64_t MissingFeatures = ~0ULL;\n"; in run()
3138 OS << " SmallBitVector OptionalOperandsMask(" << MaxNumOperands << ");\n"; in run()
3140 OS << " // Set ErrorInfo to the operand that mismatches if it is\n"; in run()
3141 OS << " // wrong for all instances of the instruction.\n"; in run()
3142 OS << " ErrorInfo = ~0ULL;\n"; in run()
3145 OS << " // Find the appropriate table for this asm variant.\n"; in run()
3146 OS << " const MatchEntry *Start, *End;\n"; in run()
3147 OS << " switch (VariantID) {\n"; in run()
3148 OS << " default: llvm_unreachable(\"invalid variant!\");\n"; in run()
3152 OS << " case " << AsmVariantNo << ": Start = std::begin(MatchTable" << VC in run()
3155 OS << " }\n"; in run()
3157 OS << " // Search the table.\n"; in run()
3159 OS << " auto MnemonicRange = " in run()
3162 OS << " auto MnemonicRange = std::make_pair(Start, End);\n"; in run()
3163 OS << " unsigned SIndex = Mnemonic.empty() ? 0 : 1;\n"; in run()
3164 OS << " if (!Mnemonic.empty())\n"; in run()
3165 OS << " MnemonicRange = " in run()
3169 OS << " // Return a more specific error code if no mnemonics match.\n"; in run()
3170 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in run()
3171 OS << " return Match_MnemonicFail;\n\n"; in run()
3173 OS << " for (const MatchEntry *it = MnemonicRange.first, " in run()
3175 OS << " it != ie; ++it) {\n"; in run()
3178 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in run()
3179 OS << " assert(Mnemonic == it->getMnemonic());\n"; in run()
3183 OS << " bool OperandsValid = true;\n"; in run()
3185 OS << " OptionalOperandsMask.reset(0, " << MaxNumOperands << ");\n"; in run()
3187 OS << " for (unsigned FormalIdx = " << (HasMnemonicFirst ? "0" : "SIndex") in run()
3190 OS << " auto Formal = " in run()
3192 OS << " if (ActualIdx >= Operands.size()) {\n"; in run()
3193 OS << " OperandsValid = (Formal == " <<"InvalidMatchClass) || " in run()
3195 OS << " if (!OperandsValid) ErrorInfo = ActualIdx;\n"; in run()
3197 OS << " OptionalOperandsMask.set(FormalIdx, " << MaxNumOperands in run()
3200 OS << " break;\n"; in run()
3201 OS << " }\n"; in run()
3202 OS << " MCParsedAsmOperand &Actual = *Operands[ActualIdx];\n"; in run()
3203 OS << " unsigned Diag = validateOperandClass(Actual, Formal);\n"; in run()
3204 OS << " if (Diag == Match_Success) {\n"; in run()
3205 OS << " ++ActualIdx;\n"; in run()
3206 OS << " continue;\n"; in run()
3207 OS << " }\n"; in run()
3208 OS << " // If the generic handler indicates an invalid operand\n"; in run()
3209 OS << " // failure, check for a special case.\n"; in run()
3210 OS << " if (Diag == Match_InvalidOperand) {\n"; in run()
3211 OS << " Diag = validateTargetOperandClass(Actual, Formal);\n"; in run()
3212 OS << " if (Diag == Match_Success) {\n"; in run()
3213 OS << " ++ActualIdx;\n"; in run()
3214 OS << " continue;\n"; in run()
3215 OS << " }\n"; in run()
3216 OS << " }\n"; in run()
3217 OS << " // If current formal operand wasn't matched and it is optional\n" in run()
3219 OS << " if (Diag == Match_InvalidOperand " in run()
3222 OS << " OptionalOperandsMask.set(FormalIdx);\n"; in run()
3224 OS << " continue;\n"; in run()
3225 OS << " }\n"; in run()
3226 OS << " // If this operand is broken for all of the instances of this\n"; in run()
3227 OS << " // mnemonic, keep track of it so we can report loc info.\n"; in run()
3228 OS << " // If we already had a match that only failed due to a\n"; in run()
3229 OS << " // target predicate, that diagnostic is preferred.\n"; in run()
3230 OS << " if (!HadMatchOtherThanPredicate &&\n"; in run()
3231 OS << " (it == MnemonicRange.first || ErrorInfo <= ActualIdx)) {\n"; in run()
3232 OS << " ErrorInfo = ActualIdx;\n"; in run()
3233 OS << " // InvalidOperand is the default. Prefer specificity.\n"; in run()
3234 OS << " if (Diag != Match_InvalidOperand)\n"; in run()
3235 OS << " RetCode = Diag;\n"; in run()
3236 OS << " }\n"; in run()
3237 OS << " // Otherwise, just reject this instance of the mnemonic.\n"; in run()
3238 OS << " OperandsValid = false;\n"; in run()
3239 OS << " break;\n"; in run()
3240 OS << " }\n\n"; in run()
3242 OS << " if (!OperandsValid) continue;\n"; in run()
3245 OS << " if ((AvailableFeatures & it->RequiredFeatures) " in run()
3247 OS << " HadMatchOtherThanFeatures = true;\n"; in run()
3248 OS << " uint64_t NewMissingFeatures = it->RequiredFeatures & " in run()
3250 OS << " if (countPopulation(NewMissingFeatures) <=\n" in run()
3252 OS << " MissingFeatures = NewMissingFeatures;\n"; in run()
3253 OS << " continue;\n"; in run()
3254 OS << " }\n"; in run()
3255 OS << "\n"; in run()
3256 OS << " Inst.clear();\n\n"; in run()
3257 OS << " if (matchingInlineAsm) {\n"; in run()
3258 OS << " Inst.setOpcode(it->Opcode);\n"; in run()
3259 OS << " convertToMapAndConstraints(it->ConvertFn, Operands);\n"; in run()
3260 OS << " return Match_Success;\n"; in run()
3261 OS << " }\n\n"; in run()
3262 OS << " // We have selected a definite instruction, convert the parsed\n" in run()
3265 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands,\n" in run()
3268 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n"; in run()
3270 OS << "\n"; in run()
3273 OS << " // We have a potential match. Check the target predicate to\n" in run()
3288 OS << " " << InsnCleanupFn << "(Inst);\n"; in run()
3291 OS << " std::string Info;\n"; in run()
3292 OS << " if (MII.get(Inst.getOpcode()).getDeprecatedInfo(Inst, getSTI(), Info)) {\n"; in run()
3293 OS << " SMLoc Loc = ((" << Target.getName() in run()
3295 OS << " getParser().Warning(Loc, Info, None);\n"; in run()
3296 OS << " }\n"; in run()
3299 OS << " return Match_Success;\n"; in run()
3300 OS << " }\n\n"; in run()
3302 OS << " // Okay, we had no match. Try to return a useful error code.\n"; in run()
3303 OS << " if (HadMatchOtherThanPredicate || !HadMatchOtherThanFeatures)\n"; in run()
3304 OS << " return RetCode;\n\n"; in run()
3305 OS << " // Missing feature matches return which features were missing\n"; in run()
3306 OS << " ErrorInfo = MissingFeatures;\n"; in run()
3307 OS << " return Match_MissingFeature;\n"; in run()
3308 OS << "}\n\n"; in run()
3311 emitCustomOperandParsing(OS, Target, Info, ClassName, StringTable, in run()
3314 OS << "#endif // GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3319 void EmitAsmMatcher(RecordKeeper &RK, raw_ostream &OS) { in EmitAsmMatcher() argument
3320 emitSourceFileHeader("Assembly Matcher Source Fragment", OS); in EmitAsmMatcher()
3321 AsmMatcherEmitter(RK).run(OS); in EmitAsmMatcher()