14 #ifndef MLIR_IR_DIALECTIMPLEMENTATION_H
15 #define MLIR_IR_DIALECTIMPLEMENTATION_H
18 #include <type_traits>
23 template <
typename T,
typename =
void>
24 struct HasStaticDialectName : std::false_type {};
27 struct HasStaticDialectName<
28 T, typename std::enable_if<
29 std::is_same<::llvm::StringLiteral,
30 std::decay_t<decltype(T::dialectName)>>::value,
31 void>::type> : std::true_type {};
73 template <
typename T,
typename = T>
77 template <
typename AttributeT>
79 AttributeT, std::enable_if_t<std::is_base_of<Attribute, AttributeT>::value,
82 if constexpr (HasStaticDialectName<AttributeT>::value) {
93 template <
typename TypeT>
95 TypeT, std::enable_if_t<std::is_base_of<Type, TypeT>::value, TypeT>> {
105 template <
typename IntT>
107 std::enable_if_t<std::is_integral<IntT>::value, IntT>> {
128 template <
typename AttributeT>
130 std::optional<AttributeT>,
131 std::enable_if_t<std::is_base_of<Attribute, AttributeT>::value,
132 std::optional<AttributeT>>> {
134 if constexpr (HasStaticDialectName<AttributeT>::value) {
140 if (succeeded(*result))
141 return {std::optional<AttributeT>(attr)};
144 return {std::nullopt};
149 template <
typename IntT>
152 std::enable_if_t<std::is_integral<IntT>::value, std::optional<IntT>>> {
157 if (succeeded(*result))
158 return {std::optional<IntT>(value)};
161 return {std::nullopt};
166 template <
typename T>
168 std::declval<typename T::value_type &&>()));
172 template <
typename ContainerT>
174 std::enable_if_t<llvm::is_detected<detail::has_push_back_t,
180 auto elementParser = [&]() {
184 elements.push_back(std::move(*element));
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
This base class exposes generic asm parser hooks, usable across the various derived parsers.
virtual OptionalParseResult parseOptionalInteger(APInt &result)=0
Parse an optional integer value from the stream.
virtual ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())=0
Parse a list of comma-separated items with an optional delimiter.
MLIRContext * getContext() const
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
virtual ParseResult parseAffineMap(AffineMap &map)=0
Parse an affine map instance into 'map'.
virtual ParseResult parseCustomAttributeWithFallback(Attribute &result, Type type, function_ref< ParseResult(Attribute &result, Type type)> parseAttribute)=0
Parse a custom attribute with the provided callback, unless the next token is #, in which case the ge...
ParseResult parseString(std::string *string)
Parse a quoted string token.
virtual ParseResult parseCustomTypeWithFallback(Type &result, function_ref< ParseResult(Type &result)> parseType)=0
Parse a custom type with the provided callback, unless the next token is #, in which case the generic...
virtual OptionalParseResult parseOptionalAttribute(Attribute &result, Type type={})=0
Parse an arbitrary optional attribute of a given type and return it in result.
This base class exposes generic asm printer hooks, usable across the various derived printers.
AsmPrinter()=default
Initialize the printer with no internal implementation.
The DialectAsmParser has methods for interacting with the asm parser when parsing attributes and type...
virtual StringRef getFullSymbolSpec() const =0
Returns the full specification of the symbol being parsed.
~DialectAsmParser() override
This is a pure-virtual base class that exposes the asmprinter hooks necessary to implement a custom p...
~DialectAsmPrinter() override
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
This class implements Optional functionality for ParseResult.
bool has_value() const
Returns true if we contain a valid ParseResult value.
decltype(std::declval< T >().push_back(std::declval< typename T::value_type && >())) has_push_back_t
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
static FailureOr< AffineMap > parse(AsmParser &parser)
static FailureOr< AttributeT > parse(AsmParser &parser)
typename ContainerT::value_type ElementT
static FailureOr< ContainerT > parse(AsmParser &parser)
static FailureOr< IntT > parse(AsmParser &parser)
static FailureOr< TypeT > parse(AsmParser &parser)
static FailureOr< std::optional< AttributeT > > parse(AsmParser &parser)
static FailureOr< std::optional< IntT > > parse(AsmParser &parser)
static FailureOr< std::string > parse(AsmParser &parser)
Provide a template class that can be specialized by users to dispatch to parsers.