• Home
  • Raw
  • Download

Lines Matching refs:OS

1674                              raw_ostream &OS) {  in emitConvertFuncs()  argument
1928 OS << "namespace {\n"; in emitConvertFuncs()
1931 OS << "enum OperatorConversionKind {\n"; in emitConvertFuncs()
1933 OS << " " << OperandConversionKinds[i] << ",\n"; in emitConvertFuncs()
1934 OS << " CVT_NUM_CONVERTERS\n"; in emitConvertFuncs()
1935 OS << "};\n\n"; in emitConvertFuncs()
1938 OS << "enum InstructionConversionKind {\n"; in emitConvertFuncs()
1942 OS << " " << *i << ",\n"; in emitConvertFuncs()
1943 OS << " CVT_NUM_SIGNATURES\n"; in emitConvertFuncs()
1944 OS << "};\n\n"; in emitConvertFuncs()
1947 OS << "} // end anonymous namespace\n\n"; in emitConvertFuncs()
1950 OS << "static const uint8_t ConversionTable[CVT_NUM_SIGNATURES][" in emitConvertFuncs()
1955 OS << " // " << InstructionConversionKinds[Row] << "\n"; in emitConvertFuncs()
1956 OS << " { "; in emitConvertFuncs()
1958 OS << OperandConversionKinds[ConversionTable[Row][i]] << ", " in emitConvertFuncs()
1960 OS << "CVT_Done },\n"; in emitConvertFuncs()
1963 OS << "};\n\n"; in emitConvertFuncs()
1966 OS << CvtOS.str(); in emitConvertFuncs()
1969 OS << OpOS.str(); in emitConvertFuncs()
1975 raw_ostream &OS) { in emitMatchClassEnumeration() argument
1976 OS << "namespace {\n\n"; in emitMatchClassEnumeration()
1978 OS << "/// MatchClassKind - The kinds of classes which participate in\n" in emitMatchClassEnumeration()
1980 OS << "enum MatchClassKind {\n"; in emitMatchClassEnumeration()
1981 OS << " InvalidMatchClass = 0,\n"; in emitMatchClassEnumeration()
1985 OS << " " << CI.Name << ", // "; in emitMatchClassEnumeration()
1987 OS << "'" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
1990 OS << "register class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
1992 OS << "derived register class\n"; in emitMatchClassEnumeration()
1994 OS << "user defined class '" << CI.ValueName << "'\n"; in emitMatchClassEnumeration()
1997 OS << " NumMatchClassKinds\n"; in emitMatchClassEnumeration()
1998 OS << "};\n\n"; in emitMatchClassEnumeration()
2000 OS << "}\n\n"; in emitMatchClassEnumeration()
2005 raw_ostream &OS) { in emitValidateOperandClass() argument
2006 OS << "static unsigned validateOperandClass(MCParsedAsmOperand *GOp, " in emitValidateOperandClass()
2008 OS << " " << Info.Target.getName() << "Operand &Operand = *(" in emitValidateOperandClass()
2012 OS << " if (Kind == InvalidMatchClass)\n"; in emitValidateOperandClass()
2013 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n\n"; in emitValidateOperandClass()
2017 OS << " if (Operand.isToken())\n"; in emitValidateOperandClass()
2018 OS << " return isSubclass(matchTokenString(Operand.getToken()), Kind) ?\n" in emitValidateOperandClass()
2031 OS << " // '" << CI.ClassName << "' class\n"; in emitValidateOperandClass()
2032 OS << " if (Kind == " << CI.Name << ") {\n"; in emitValidateOperandClass()
2033 OS << " if (Operand." << CI.PredicateMethod << "())\n"; in emitValidateOperandClass()
2034 OS << " return MCTargetAsmParser::Match_Success;\n"; in emitValidateOperandClass()
2036 OS << " return " << Info.Target.getName() << "AsmParser::Match_" in emitValidateOperandClass()
2038 OS << " }\n\n"; in emitValidateOperandClass()
2042 OS << " if (Operand.isReg()) {\n"; in emitValidateOperandClass()
2043 OS << " MatchClassKind OpKind;\n"; in emitValidateOperandClass()
2044 OS << " switch (Operand.getReg()) {\n"; in emitValidateOperandClass()
2045 OS << " default: OpKind = InvalidMatchClass; break;\n"; in emitValidateOperandClass()
2049 OS << " case " << Info.Target.getName() << "::" in emitValidateOperandClass()
2052 OS << " }\n"; in emitValidateOperandClass()
2053 OS << " return isSubclass(OpKind, Kind) ? " in emitValidateOperandClass()
2059 OS << " return MCTargetAsmParser::Match_InvalidOperand;\n"; in emitValidateOperandClass()
2060 OS << "}\n\n"; in emitValidateOperandClass()
2066 raw_ostream &OS) { in emitIsSubclass() argument
2067 OS << "/// isSubclass - Compute whether \\p A is a subclass of \\p B.\n"; in emitIsSubclass()
2068 OS << "static bool isSubclass(MatchClassKind A, MatchClassKind B) {\n"; in emitIsSubclass()
2069 OS << " if (A == B)\n"; in emitIsSubclass()
2070 OS << " return true;\n\n"; in emitIsSubclass()
2118 OS << SS.str(); in emitIsSubclass()
2120 OS << " return false;\n"; in emitIsSubclass()
2122 OS << "}\n\n"; in emitIsSubclass()
2129 raw_ostream &OS) { in emitMatchTokenString() argument
2141 OS << "static MatchClassKind matchTokenString(StringRef Name) {\n"; in emitMatchTokenString()
2143 StringMatcher("Name", Matches, OS).Emit(); in emitMatchTokenString()
2145 OS << " return InvalidMatchClass;\n"; in emitMatchTokenString()
2146 OS << "}\n\n"; in emitMatchTokenString()
2152 raw_ostream &OS) { in emitMatchRegisterName() argument
2167 OS << "static unsigned MatchRegisterName(StringRef Name) {\n"; in emitMatchRegisterName()
2169 StringMatcher("Name", Matches, OS).Emit(); in emitMatchRegisterName()
2171 OS << " return 0;\n"; in emitMatchRegisterName()
2172 OS << "}\n\n"; in emitMatchRegisterName()
2178 raw_ostream &OS) { in emitSubtargetFeatureFlagEnumeration() argument
2179 OS << "// Flags for subtarget features that participate in " in emitSubtargetFeatureFlagEnumeration()
2181 OS << "enum SubtargetFeatureFlag {\n"; in emitSubtargetFeatureFlagEnumeration()
2186 OS << " " << SFI.getEnumName() << " = (1 << " << SFI.Index << "),\n"; in emitSubtargetFeatureFlagEnumeration()
2188 OS << " Feature_None = 0\n"; in emitSubtargetFeatureFlagEnumeration()
2189 OS << "};\n\n"; in emitSubtargetFeatureFlagEnumeration()
2193 static void emitOperandDiagnosticTypes(AsmMatcherInfo &Info, raw_ostream &OS) { in emitOperandDiagnosticTypes() argument
2208 OS << " Match_" << *I << ",\n"; in emitOperandDiagnosticTypes()
2209 OS << " END_OPERAND_DIAGNOSTIC_TYPES\n"; in emitOperandDiagnosticTypes()
2214 static void emitGetSubtargetFeatureName(AsmMatcherInfo &Info, raw_ostream &OS) { in emitGetSubtargetFeatureName() argument
2215 OS << "// User-level names for subtarget features that participate in\n" in emitGetSubtargetFeatureName()
2219 OS << " switch(Val) {\n"; in emitGetSubtargetFeatureName()
2225 OS << " case " << SFI.getEnumName() << ": return \"" in emitGetSubtargetFeatureName()
2228 OS << " default: return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2229 OS << " }\n"; in emitGetSubtargetFeatureName()
2232 OS << " return \"(unknown)\";\n"; in emitGetSubtargetFeatureName()
2234 OS << "}\n\n"; in emitGetSubtargetFeatureName()
2240 raw_ostream &OS) { in emitComputeAvailableFeatures() argument
2244 OS << "unsigned " << Info.Target.getName() << ClassName << "::\n" in emitComputeAvailableFeatures()
2246 OS << " unsigned Features = 0;\n"; in emitComputeAvailableFeatures()
2252 OS << " if ("; in emitComputeAvailableFeatures()
2260 OS << " && "; in emitComputeAvailableFeatures()
2269 OS << "((FB & " << Info.Target.getName() << "::" << Cond << ")"; in emitComputeAvailableFeatures()
2271 OS << " == 0"; in emitComputeAvailableFeatures()
2273 OS << " != 0"; in emitComputeAvailableFeatures()
2274 OS << ")"; in emitComputeAvailableFeatures()
2283 OS << ")\n"; in emitComputeAvailableFeatures()
2284 OS << " Features |= " << SFI.getEnumName() << ";\n"; in emitComputeAvailableFeatures()
2286 OS << " return Features;\n"; in emitComputeAvailableFeatures()
2287 OS << "}\n\n"; in emitComputeAvailableFeatures()
2314 static void emitMnemonicAliasVariant(raw_ostream &OS,const AsmMatcherInfo &Info, in emitMnemonicAliasVariant() argument
2384 StringMatcher("Mnemonic", Cases, OS).Emit(Indent); in emitMnemonicAliasVariant()
2389 static bool emitMnemonicAliases(raw_ostream &OS, const AsmMatcherInfo &Info, in emitMnemonicAliases() argument
2399 OS << "static void applyMnemonicAliases(StringRef &Mnemonic, " in emitMnemonicAliases()
2401 OS << " switch (VariantID) {\n"; in emitMnemonicAliases()
2407 OS << " case " << AsmParserVariantNo << ":\n"; in emitMnemonicAliases()
2408 emitMnemonicAliasVariant(OS, Info, Aliases, /*Indent=*/2, in emitMnemonicAliases()
2410 OS << " break;\n"; in emitMnemonicAliases()
2412 OS << " }\n"; in emitMnemonicAliases()
2415 emitMnemonicAliasVariant(OS, Info, Aliases); in emitMnemonicAliases()
2417 OS << "}\n\n"; in emitMnemonicAliases()
2431 static void emitCustomOperandParsing(raw_ostream &OS, CodeGenTarget &Target, in emitCustomOperandParsing() argument
2443 OS << "namespace {\n"; in emitCustomOperandParsing()
2444 OS << " struct OperandMatchEntry {\n"; in emitCustomOperandParsing()
2445 OS << " " << getMinimalTypeForRange(1ULL << Info.SubtargetFeatures.size()) in emitCustomOperandParsing()
2447 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in emitCustomOperandParsing()
2449 OS << " " << getMinimalTypeForRange(Info.Classes.size()) in emitCustomOperandParsing()
2451 OS << " " << getMinimalTypeForRange(MaxMask) in emitCustomOperandParsing()
2453 OS << " StringRef getMnemonic() const {\n"; in emitCustomOperandParsing()
2454 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in emitCustomOperandParsing()
2455 OS << " MnemonicTable[Mnemonic]);\n"; in emitCustomOperandParsing()
2456 OS << " }\n"; in emitCustomOperandParsing()
2457 OS << " };\n\n"; in emitCustomOperandParsing()
2459 OS << " // Predicate for searching for an opcode.\n"; in emitCustomOperandParsing()
2460 OS << " struct LessOpcodeOperand {\n"; in emitCustomOperandParsing()
2461 OS << " bool operator()(const OperandMatchEntry &LHS, StringRef RHS) {\n"; in emitCustomOperandParsing()
2462 OS << " return LHS.getMnemonic() < RHS;\n"; in emitCustomOperandParsing()
2463 OS << " }\n"; in emitCustomOperandParsing()
2464 OS << " bool operator()(StringRef LHS, const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2465 OS << " return LHS < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2466 OS << " }\n"; in emitCustomOperandParsing()
2467 OS << " bool operator()(const OperandMatchEntry &LHS,"; in emitCustomOperandParsing()
2468 OS << " const OperandMatchEntry &RHS) {\n"; in emitCustomOperandParsing()
2469 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in emitCustomOperandParsing()
2470 OS << " }\n"; in emitCustomOperandParsing()
2471 OS << " };\n"; in emitCustomOperandParsing()
2473 OS << "} // end anonymous namespace.\n\n"; in emitCustomOperandParsing()
2475 OS << "static const OperandMatchEntry OperandMatchTable[" in emitCustomOperandParsing()
2478 OS << " /* Operand List Mask, Mnemonic, Operand Class, Features */\n"; in emitCustomOperandParsing()
2485 OS << " { "; in emitCustomOperandParsing()
2490 if (i) OS << "|"; in emitCustomOperandParsing()
2491 OS << II.RequiredFeatures[i]->getEnumName(); in emitCustomOperandParsing()
2494 OS << "0"; in emitCustomOperandParsing()
2498 OS << ", " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in emitCustomOperandParsing()
2501 OS << OMI.CI->Name; in emitCustomOperandParsing()
2503 OS << ", " << OMI.OperandMask; in emitCustomOperandParsing()
2504 OS << " /* "; in emitCustomOperandParsing()
2509 OS << ", "; in emitCustomOperandParsing()
2510 OS << i; in emitCustomOperandParsing()
2513 OS << " */"; in emitCustomOperandParsing()
2515 OS << " },\n"; in emitCustomOperandParsing()
2517 OS << "};\n\n"; in emitCustomOperandParsing()
2521 OS << Target.getName() << ClassName << "::OperandMatchResultTy " in emitCustomOperandParsing()
2532 OS << " case " << CI->Name << ":\n" in emitCustomOperandParsing()
2536 OS << " default:\n"; in emitCustomOperandParsing()
2537 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2538 OS << " }\n"; in emitCustomOperandParsing()
2539 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2540 OS << "}\n\n"; in emitCustomOperandParsing()
2545 OS << Target.getName() << ClassName << "::OperandMatchResultTy " in emitCustomOperandParsing()
2551 OS << " // Get the current feature set.\n"; in emitCustomOperandParsing()
2552 OS << " unsigned AvailableFeatures = getAvailableFeatures();\n\n"; in emitCustomOperandParsing()
2554 OS << " // Get the next operand index.\n"; in emitCustomOperandParsing()
2555 OS << " unsigned NextOpNum = Operands.size()-1;\n"; in emitCustomOperandParsing()
2558 OS << " // Search the table.\n"; in emitCustomOperandParsing()
2559 OS << " std::pair<const OperandMatchEntry*, const OperandMatchEntry*>"; in emitCustomOperandParsing()
2560 OS << " MnemonicRange =\n"; in emitCustomOperandParsing()
2561 OS << " std::equal_range(OperandMatchTable, OperandMatchTable+" in emitCustomOperandParsing()
2565 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in emitCustomOperandParsing()
2566 OS << " return MatchOperand_NoMatch;\n\n"; in emitCustomOperandParsing()
2568 OS << " for (const OperandMatchEntry *it = MnemonicRange.first,\n" in emitCustomOperandParsing()
2571 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in emitCustomOperandParsing()
2572 OS << " assert(Mnemonic == it->getMnemonic());\n\n"; in emitCustomOperandParsing()
2575 OS << " // check if the available features match\n"; in emitCustomOperandParsing()
2576 OS << " if ((AvailableFeatures & it->RequiredFeatures) " in emitCustomOperandParsing()
2578 OS << " continue;\n"; in emitCustomOperandParsing()
2579 OS << " }\n\n"; in emitCustomOperandParsing()
2582 OS << " // check if the operand in question has a custom parser.\n"; in emitCustomOperandParsing()
2583 OS << " if (!(it->OperandMask & (1 << NextOpNum)))\n"; in emitCustomOperandParsing()
2584 OS << " continue;\n\n"; in emitCustomOperandParsing()
2587 OS << " // call custom parse method to handle the operand\n"; in emitCustomOperandParsing()
2588 OS << " OperandMatchResultTy Result = "; in emitCustomOperandParsing()
2589 OS << "tryCustomParseOperand(Operands, it->Class);\n"; in emitCustomOperandParsing()
2590 OS << " if (Result != MatchOperand_NoMatch)\n"; in emitCustomOperandParsing()
2591 OS << " return Result;\n"; in emitCustomOperandParsing()
2592 OS << " }\n\n"; in emitCustomOperandParsing()
2594 OS << " // Okay, we had no match.\n"; in emitCustomOperandParsing()
2595 OS << " return MatchOperand_NoMatch;\n"; in emitCustomOperandParsing()
2596 OS << "}\n\n"; in emitCustomOperandParsing()
2599 void AsmMatcherEmitter::run(raw_ostream &OS) { in run() argument
2650 OS << "\n#ifdef GET_ASSEMBLER_HEADER\n"; in run()
2651 OS << "#undef GET_ASSEMBLER_HEADER\n"; in run()
2652 OS << " // This should be included into the middle of the declaration of\n"; in run()
2653 OS << " // your subclasses implementation of MCTargetAsmParser.\n"; in run()
2654 OS << " unsigned ComputeAvailableFeatures(uint64_t FeatureBits) const;\n"; in run()
2655 OS << " void convertToMCInst(unsigned Kind, MCInst &Inst, " in run()
2659 OS << " void convertToMapAndConstraints(unsigned Kind,\n "; in run()
2660 OS << " const SmallVectorImpl<MCParsedAsmOperand*> &Operands);\n"; in run()
2661 OS << " bool mnemonicIsValid(StringRef Mnemonic, unsigned VariantID);\n"; in run()
2662 OS << " unsigned MatchInstructionImpl(\n"; in run()
2663 OS.indent(27); in run()
2664 OS << "const SmallVectorImpl<MCParsedAsmOperand*> &Operands,\n" in run()
2671 OS << "\n enum OperandMatchResultTy {\n"; in run()
2672 OS << " MatchOperand_Success, // operand matched successfully\n"; in run()
2673 OS << " MatchOperand_NoMatch, // operand did not match\n"; in run()
2674 OS << " MatchOperand_ParseFail // operand matched but had errors\n"; in run()
2675 OS << " };\n"; in run()
2676 OS << " OperandMatchResultTy MatchOperandParserImpl(\n"; in run()
2677 OS << " SmallVectorImpl<MCParsedAsmOperand*> &Operands,\n"; in run()
2678 OS << " StringRef Mnemonic);\n"; in run()
2680 OS << " OperandMatchResultTy tryCustomParseOperand(\n"; in run()
2681 OS << " SmallVectorImpl<MCParsedAsmOperand*> &Operands,\n"; in run()
2682 OS << " unsigned MCK);\n\n"; in run()
2685 OS << "#endif // GET_ASSEMBLER_HEADER_INFO\n\n"; in run()
2688 OS << "\n#ifdef GET_OPERAND_DIAGNOSTIC_TYPES\n"; in run()
2689 OS << "#undef GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
2690 emitOperandDiagnosticTypes(Info, OS); in run()
2691 OS << "#endif // GET_OPERAND_DIAGNOSTIC_TYPES\n\n"; in run()
2694 OS << "\n#ifdef GET_REGISTER_MATCHER\n"; in run()
2695 OS << "#undef GET_REGISTER_MATCHER\n\n"; in run()
2698 emitSubtargetFeatureFlagEnumeration(Info, OS); in run()
2703 emitMatchRegisterName(Target, AsmParser, OS); in run()
2705 OS << "#endif // GET_REGISTER_MATCHER\n\n"; in run()
2707 OS << "\n#ifdef GET_SUBTARGET_FEATURE_NAME\n"; in run()
2708 OS << "#undef GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
2711 emitGetSubtargetFeatureName(Info, OS); in run()
2713 OS << "#endif // GET_SUBTARGET_FEATURE_NAME\n\n"; in run()
2715 OS << "\n#ifdef GET_MATCHER_IMPLEMENTATION\n"; in run()
2716 OS << "#undef GET_MATCHER_IMPLEMENTATION\n\n"; in run()
2719 bool HasMnemonicAliases = emitMnemonicAliases(OS, Info, Target); in run()
2724 emitConvertFuncs(Target, ClassName, Info.Matchables, OS); in run()
2727 emitMatchClassEnumeration(Target, Info.Classes, OS); in run()
2730 emitMatchTokenString(Target, Info.Classes, OS); in run()
2733 emitIsSubclass(Target, Info.Classes, OS); in run()
2736 emitValidateOperandClass(Info, OS); in run()
2739 emitComputeAvailableFeatures(Info, OS); in run()
2758 OS << "static const char *const MnemonicTable =\n"; in run()
2759 StringTable.EmitString(OS); in run()
2760 OS << ";\n\n"; in run()
2772 OS << "namespace {\n"; in run()
2773 OS << " struct MatchEntry {\n"; in run()
2774 OS << " " << getMinimalTypeForRange(MaxMnemonicIndex) in run()
2776 OS << " uint16_t Opcode;\n"; in run()
2777 OS << " " << getMinimalTypeForRange(Info.Matchables.size()) in run()
2779 OS << " " << getMinimalTypeForRange(1ULL << Info.SubtargetFeatures.size()) in run()
2781 OS << " " << getMinimalTypeForRange(Info.Classes.size()) in run()
2783 OS << " StringRef getMnemonic() const {\n"; in run()
2784 OS << " return StringRef(MnemonicTable + Mnemonic + 1,\n"; in run()
2785 OS << " MnemonicTable[Mnemonic]);\n"; in run()
2786 OS << " }\n"; in run()
2787 OS << " };\n\n"; in run()
2789 OS << " // Predicate for searching for an opcode.\n"; in run()
2790 OS << " struct LessOpcode {\n"; in run()
2791 OS << " bool operator()(const MatchEntry &LHS, StringRef RHS) {\n"; in run()
2792 OS << " return LHS.getMnemonic() < RHS;\n"; in run()
2793 OS << " }\n"; in run()
2794 OS << " bool operator()(StringRef LHS, const MatchEntry &RHS) {\n"; in run()
2795 OS << " return LHS < RHS.getMnemonic();\n"; in run()
2796 OS << " }\n"; in run()
2797 OS << " bool operator()(const MatchEntry &LHS, const MatchEntry &RHS) {\n"; in run()
2798 OS << " return LHS.getMnemonic() < RHS.getMnemonic();\n"; in run()
2799 OS << " }\n"; in run()
2800 OS << " };\n"; in run()
2802 OS << "} // end anonymous namespace.\n\n"; in run()
2812 OS << "static const MatchEntry MatchTable" << VC << "[] = {\n"; in run()
2823 OS << " { " << StringTable.GetOrAddStringOffset(LenMnemonic, false) in run()
2832 if (i) OS << "|"; in run()
2833 OS << II.RequiredFeatures[i]->getEnumName(); in run()
2836 OS << "0"; in run()
2838 OS << ", { "; in run()
2842 if (i) OS << ", "; in run()
2843 OS << Op.Class->Name; in run()
2845 OS << " }, },\n"; in run()
2848 OS << "};\n\n"; in run()
2852 OS << "bool " << Target.getName() << ClassName << "::\n" in run()
2854 OS << " // Find the appropriate table for this asm variant.\n"; in run()
2855 OS << " const MatchEntry *Start, *End;\n"; in run()
2856 OS << " switch (VariantID) {\n"; in run()
2857 OS << " default: // unreachable\n"; in run()
2864 OS << " case " << AsmVariantNo << ": Start = MatchTable" << VC in run()
2867 OS << " }\n"; in run()
2868 OS << " // Search the table.\n"; in run()
2869 OS << " std::pair<const MatchEntry*, const MatchEntry*> MnemonicRange =\n"; in run()
2870 OS << " std::equal_range(Start, End, Mnemonic, LessOpcode());\n"; in run()
2871 OS << " return MnemonicRange.first != MnemonicRange.second;\n"; in run()
2872 OS << "}\n\n"; in run()
2875 OS << "unsigned " in run()
2879 OS << " MCInst &Inst,\n" in run()
2882 OS << " // Eliminate obvious mismatches.\n"; in run()
2883 OS << " if (Operands.size() > " << (MaxNumOperands+1) << ") {\n"; in run()
2884 OS << " ErrorInfo = " << (MaxNumOperands+1) << ";\n"; in run()
2885 OS << " return Match_InvalidOperand;\n"; in run()
2886 OS << " }\n\n"; in run()
2889 OS << " // Get the current feature set.\n"; in run()
2890 OS << " unsigned AvailableFeatures = getAvailableFeatures();\n\n"; in run()
2892 OS << " // Get the instruction mnemonic, which is the first token.\n"; in run()
2893 OS << " StringRef Mnemonic = ((" << Target.getName() in run()
2897 OS << " // Process all MnemonicAliases to remap the mnemonic.\n"; in run()
2898 OS << " applyMnemonicAliases(Mnemonic, AvailableFeatures, VariantID);\n\n"; in run()
2902 OS << " // Some state to try to produce better error messages.\n"; in run()
2903 OS << " bool HadMatchOtherThanFeatures = false;\n"; in run()
2904 OS << " bool HadMatchOtherThanPredicate = false;\n"; in run()
2905 OS << " unsigned RetCode = Match_InvalidOperand;\n"; in run()
2906 OS << " unsigned MissingFeatures = ~0U;\n"; in run()
2907 OS << " // Set ErrorInfo to the operand that mismatches if it is\n"; in run()
2908 OS << " // wrong for all instances of the instruction.\n"; in run()
2909 OS << " ErrorInfo = ~0U;\n"; in run()
2912 OS << " // Find the appropriate table for this asm variant.\n"; in run()
2913 OS << " const MatchEntry *Start, *End;\n"; in run()
2914 OS << " switch (VariantID) {\n"; in run()
2915 OS << " default: // unreachable\n"; in run()
2922 OS << " case " << AsmVariantNo << ": Start = MatchTable" << VC in run()
2925 OS << " }\n"; in run()
2926 OS << " // Search the table.\n"; in run()
2927 OS << " std::pair<const MatchEntry*, const MatchEntry*> MnemonicRange =\n"; in run()
2928 OS << " std::equal_range(Start, End, Mnemonic, LessOpcode());\n\n"; in run()
2930 OS << " // Return a more specific error code if no mnemonics match.\n"; in run()
2931 OS << " if (MnemonicRange.first == MnemonicRange.second)\n"; in run()
2932 OS << " return Match_MnemonicFail;\n\n"; in run()
2934 OS << " for (const MatchEntry *it = MnemonicRange.first, " in run()
2936 OS << " it != ie; ++it) {\n"; in run()
2938 OS << " // equal_range guarantees that instruction mnemonic matches.\n"; in run()
2939 OS << " assert(Mnemonic == it->getMnemonic());\n"; in run()
2942 OS << " bool OperandsValid = true;\n"; in run()
2943 OS << " for (unsigned i = 0; i != " << MaxNumOperands << "; ++i) {\n"; in run()
2944 OS << " if (i + 1 >= Operands.size()) {\n"; in run()
2945 OS << " OperandsValid = (it->Classes[i] == " <<"InvalidMatchClass);\n"; in run()
2946 OS << " if (!OperandsValid) ErrorInfo = i + 1;\n"; in run()
2947 OS << " break;\n"; in run()
2948 OS << " }\n"; in run()
2949 OS << " unsigned Diag = validateOperandClass(Operands[i+1],\n"; in run()
2950 OS.indent(43); in run()
2951 OS << "(MatchClassKind)it->Classes[i]);\n"; in run()
2952 OS << " if (Diag == Match_Success)\n"; in run()
2953 OS << " continue;\n"; in run()
2954 OS << " // If the generic handler indicates an invalid operand\n"; in run()
2955 OS << " // failure, check for a special case.\n"; in run()
2956 OS << " if (Diag == Match_InvalidOperand) {\n"; in run()
2957 OS << " Diag = validateTargetOperandClass(Operands[i+1],\n"; in run()
2958 OS.indent(43); in run()
2959 OS << "(MatchClassKind)it->Classes[i]);\n"; in run()
2960 OS << " if (Diag == Match_Success)\n"; in run()
2961 OS << " continue;\n"; in run()
2962 OS << " }\n"; in run()
2963 OS << " // If this operand is broken for all of the instances of this\n"; in run()
2964 OS << " // mnemonic, keep track of it so we can report loc info.\n"; in run()
2965 OS << " // If we already had a match that only failed due to a\n"; in run()
2966 OS << " // target predicate, that diagnostic is preferred.\n"; in run()
2967 OS << " if (!HadMatchOtherThanPredicate &&\n"; in run()
2968 OS << " (it == MnemonicRange.first || ErrorInfo <= i+1)) {\n"; in run()
2969 OS << " ErrorInfo = i+1;\n"; in run()
2970 OS << " // InvalidOperand is the default. Prefer specificity.\n"; in run()
2971 OS << " if (Diag != Match_InvalidOperand)\n"; in run()
2972 OS << " RetCode = Diag;\n"; in run()
2973 OS << " }\n"; in run()
2974 OS << " // Otherwise, just reject this instance of the mnemonic.\n"; in run()
2975 OS << " OperandsValid = false;\n"; in run()
2976 OS << " break;\n"; in run()
2977 OS << " }\n\n"; in run()
2979 OS << " if (!OperandsValid) continue;\n"; in run()
2982 OS << " if ((AvailableFeatures & it->RequiredFeatures) " in run()
2984 OS << " HadMatchOtherThanFeatures = true;\n"; in run()
2985 OS << " unsigned NewMissingFeatures = it->RequiredFeatures & " in run()
2987 OS << " if (CountPopulation_32(NewMissingFeatures) <=\n" in run()
2989 OS << " MissingFeatures = NewMissingFeatures;\n"; in run()
2990 OS << " continue;\n"; in run()
2991 OS << " }\n"; in run()
2992 OS << "\n"; in run()
2993 OS << " if (matchingInlineAsm) {\n"; in run()
2994 OS << " Inst.setOpcode(it->Opcode);\n"; in run()
2995 OS << " convertToMapAndConstraints(it->ConvertFn, Operands);\n"; in run()
2996 OS << " return Match_Success;\n"; in run()
2997 OS << " }\n\n"; in run()
2998 OS << " // We have selected a definite instruction, convert the parsed\n" in run()
3000 OS << " convertToMCInst(it->ConvertFn, Inst, it->Opcode, Operands);\n"; in run()
3001 OS << "\n"; in run()
3004 OS << " // We have a potential match. Check the target predicate to\n" in run()
3019 OS << " " << InsnCleanupFn << "(Inst);\n"; in run()
3021 OS << " return Match_Success;\n"; in run()
3022 OS << " }\n\n"; in run()
3024 OS << " // Okay, we had no match. Try to return a useful error code.\n"; in run()
3025 OS << " if (HadMatchOtherThanPredicate || !HadMatchOtherThanFeatures)\n"; in run()
3026 OS << " return RetCode;\n\n"; in run()
3027 OS << " // Missing feature matches return which features were missing\n"; in run()
3028 OS << " ErrorInfo = MissingFeatures;\n"; in run()
3029 OS << " return Match_MissingFeature;\n"; in run()
3030 OS << "}\n\n"; in run()
3033 emitCustomOperandParsing(OS, Target, Info, ClassName, StringTable, in run()
3036 OS << "#endif // GET_MATCHER_IMPLEMENTATION\n\n"; in run()
3041 void EmitAsmMatcher(RecordKeeper &RK, raw_ostream &OS) { in EmitAsmMatcher() argument
3042 emitSourceFileHeader("Assembly Matcher Source Fragment", OS); in EmitAsmMatcher()
3043 AsmMatcherEmitter(RK).run(OS); in EmitAsmMatcher()