17 #ifndef MLIR_TOOLS_MLIRQUERY_MATCHER_MARSHALLERS_H
18 #define MLIR_TOOLS_MLIRQUERY_MATCHER_MARSHALLERS_H
22 #include "llvm/ADT/ArrayRef.h"
23 #include "llvm/ADT/StringRef.h"
87 std::vector<ArgKind> &argKinds)
const = 0;
93 llvm::StringRef matcherName,
102 void (*matcherFunc)(),
103 llvm::StringRef matcherName,
105 : marshaller(marshaller), matcherFunc(matcherFunc),
106 matcherName(matcherName), argKinds(argKinds.begin(), argKinds.end()) {}
110 return marshaller(matcherFunc, matcherName, nameRange, args, error);
113 unsigned getNumArgs()
const override {
return argKinds.size(); }
115 void getArgKinds(
unsigned argNo, std::vector<ArgKind> &kinds)
const override {
116 kinds.push_back(argKinds[argNo]);
121 void (*
const matcherFunc)();
122 const llvm::StringRef matcherName;
123 const std::vector<ArgKind> argKinds;
130 if (args.size() != expectedArgCount) {
132 {llvm::Twine(expectedArgCount), llvm::Twine(args.size())});
139 template <
typename ArgType,
size_t Index>
145 {llvm::Twine(matcherName), llvm::Twine(Index + 1)});
152 template <
typename ReturnType,
typename... ArgTypes,
size_t... Is>
157 std::index_sequence<Is...>) {
158 using FuncType = ReturnType (*)(ArgTypes...);
161 if (!
checkArgCount(nameRange,
sizeof...(ArgTypes), args, error))
165 if ((... && checkArgTypeAtIndex<ArgTypes, Is>(matcherName, args, error))) {
166 ReturnType fnPointer =
reinterpret_cast<FuncType
>(matcherFunc)(
175 template <
typename ReturnType,
typename... ArgTypes>
181 matcherFunc, matcherName, nameRange, args, error,
182 std::index_sequence_for<ArgTypes...>{});
186 template <
typename ReturnType,
typename... ArgTypes>
187 std::unique_ptr<MatcherDescriptor>
189 llvm::StringRef matcherName) {
192 return std::make_unique<FixedArgCountMatcherDescriptor>(
193 matcherMarshallFixed<ReturnType, ArgTypes...>,
194 reinterpret_cast<void (*)()
>(matcherFunc), matcherName, argKinds);
static std::unique_ptr< DynMatcher > constructDynMatcherFromMatcherFn(MatcherFn &matcherFn)
static VariantMatcher SingleMatcher(DynMatcher matcher)
std::optional< DynMatcher > getDynMatcher() const
const VariantMatcher & getMatcher() const
const llvm::StringRef & getString() const
void getArgKinds(unsigned argNo, std::vector< ArgKind > &kinds) const override
VariantMatcher create(SourceRange nameRange, llvm::ArrayRef< ParserValue > args, Diagnostics *error) const override
FixedArgCountMatcherDescriptor(MarshallerType marshaller, void(*matcherFunc)(), llvm::StringRef matcherName, llvm::ArrayRef< ArgKind > argKinds)
unsigned getNumArgs() const override
VariantMatcher(*)(void(*matcherFunc)(), llvm::StringRef matcherName, SourceRange nameRange, llvm::ArrayRef< ParserValue > args, Diagnostics *error) MarshallerType
virtual VariantMatcher create(SourceRange nameRange, const llvm::ArrayRef< ParserValue > args, Diagnostics *error) const =0
virtual ~MatcherDescriptor()=default
virtual void getArgKinds(unsigned argNo, std::vector< ArgKind > &argKinds) const =0
virtual unsigned getNumArgs() const =0
The OpAsmOpInterface, see OpAsmInterface.td for more details.
static VariantMatcher matcherMarshallFixedImpl(void(*matcherFunc)(), llvm::StringRef matcherName, SourceRange nameRange, llvm::ArrayRef< ParserValue > args, Diagnostics *error, std::index_sequence< Is... >)
void addError(Diagnostics *error, SourceRange range, ErrorType errorType, std::initializer_list< llvm::Twine > errorTexts)
static VariantMatcher matcherMarshallFixed(void(*matcherFunc)(), llvm::StringRef matcherName, SourceRange nameRange, llvm::ArrayRef< ParserValue > args, Diagnostics *error)
bool checkArgTypeAtIndex(llvm::StringRef matcherName, llvm::ArrayRef< ParserValue > args, Diagnostics *error)
bool checkArgCount(SourceRange nameRange, size_t expectedArgCount, llvm::ArrayRef< ParserValue > args, Diagnostics *error)
std::unique_ptr< MatcherDescriptor > makeMatcherAutoMarshall(ReturnType(*matcherFunc)(ArgTypes...), llvm::StringRef matcherName)
static bool hasCorrectType(const VariantValue &value)
static DynMatcher get(const VariantValue &value)
static std::optional< std::string > getBestGuess(const VariantValue &)
static std::optional< std::string > getBestGuess(const VariantValue &)
static bool hasCorrectType(const VariantValue &value)
static const llvm::StringRef & get(const VariantValue &value)