14#ifndef MLIR_IR_DIALECTIMPLEMENTATION_H
15#define MLIR_IR_DIALECTIMPLEMENTATION_H
23template <
typename T,
typename =
void>
24struct HasStaticDialectName : std::false_type {};
27struct 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 {};
82template <
typename T,
typename = T>
86template <
typename AttributeT>
88 AttributeT, std::enable_if_t<std::is_base_of<Attribute, AttributeT>::value,
91 if constexpr (HasStaticDialectName<AttributeT>::value) {
102template <
typename TypeT>
104 TypeT, std::enable_if_t<std::is_base_of<Type, TypeT>::value, TypeT>> {
127 return {std::nullopt};
129 return parser.
emitError(loc,
"expected a single character");
130 return {std::optional<char>(str[0])};
144 return parser.
emitError(loc,
"expected a single character");
150template <
typename IntT>
151struct FieldParser<IntT, std::enable_if_t<(std::is_integral<IntT>::value ||
152 std::is_same_v<IntT, llvm::APInt>),
174template <
typename AttributeT>
176 std::optional<AttributeT>,
177 std::enable_if_t<std::is_base_of<Attribute, AttributeT>::value,
178 std::optional<AttributeT>>> {
182 if constexpr (HasStaticDialectName<AttributeT>::value) {
189 return {std::optional<AttributeT>(attr)};
192 return {std::nullopt};
197template <
typename IntT>
200 std::enable_if_t<std::is_integral<IntT>::value, std::optional<IntT>>> {
208 return {std::optional<IntT>(value)};
211 return {std::nullopt};
218 std::declval<typename T::value_type &&>()));
220template <
typename StorageType,
typename =
void>
223template <
typename StorageType>
225 std::void_t<decltype(sizeof(FieldParser<StorageType>)),
226 decltype(FieldParser<StorageType>::parse(
227 std::declval<OpAsmParser &>()))>>
230template <
typename ContainerT,
typename =
void>
233template <
typename ContainerT>
235 std::void_t<has_push_back_t<ContainerT>>>
238template <
typename Parser,
typename =
void>
241template <
typename Parser>
243 Parser, std::void_t<decltype(Parser::isKeyValueCompositional)>>
244 : std::bool_constant<Parser::isKeyValueCompositional> {};
250template <
typename StorageType>
252 : std::conjunction<HasFieldParser<StorageType>,
253 IsKeyValueCompositional<FieldParser<StorageType>>> {};
257template <
typename ContainerT>
260 std::enable_if_t<detail::HasFieldParserContainer<ContainerT>::value,
267 auto elementParser = [&]() {
271 elements.push_back(std::move(*element));
294template <
typename StorageType,
typename ConvertFromAttribute>
302 storage = std::move(*value);
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 parseOptionalKeywordOrString(std::string *result)=0
Parse an optional keyword or string.
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
virtual InFlightDiagnostic emitError(SMLoc loc, const Twine &message={})=0
Emit a diagnostic at the specified location and return failure.
ParseResult parseInteger(IntT &result)
Parse an integer value from the stream.
ParseResult parseKeywordOrString(std::string *result)
Parse a keyword or a quoted string.
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.
virtual SMLoc getCurrentLocation()=0
Get the location of the next token and store it into the argument.
virtual ParseResult parseAttribute(Attribute &result, Type type={})=0
Parse an arbitrary attribute of a given type and return it in result.
AsmPrinter(Impl &impl)
Initialize the printer with the given internal implementation.
Attributes are known-constant values of operations.
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
AsmPrinter(Impl &impl)
Initialize the printer with the given internal implementation.
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
The OpAsmParser has methods for interacting with the asm parser: parsing things from it,...
This class implements Optional functionality for ParseResult.
This class implement support for parsing global entities like attributes and types.
decltype(std::declval< T >().push_back( std::declval< typename T::value_type && >())) has_push_back_t
ParseResult parsePropertyWithFallback(OpAsmParser &parser, StorageType &storage, ConvertFromAttribute convertFromAttribute)
Parse a property with its FieldParser when one is available, otherwise fall back to the property's at...
Include the generated interface declarations.
LogicalResult convertFromAttribute(int64_t &storage, Attribute attr, function_ref< InFlightDiagnostic()> emitError)
Convert an IntegerAttr attribute to an int64_t, or return an error if the attribute isn't an IntegerA...
static FailureOr< AffineMap > parse(AsmParser &parser)
static FailureOr< AttributeT > parse(AsmParser &parser)
static FailureOr< ContainerT > parse(AsmParser &parser)
static constexpr bool isKeyValueCompositional
typename ContainerT::value_type ElementT
static FailureOr< IntT > parse(AsmParser &parser)
static FailureOr< TypeT > parse(AsmParser &parser)
static FailureOr< char > parse(AsmParser &parser)
static FailureOr< std::optional< AttributeT > > parse(AsmParser &parser)
static constexpr bool isKeyValueCompositional
static FailureOr< std::optional< IntT > > parse(AsmParser &parser)
static constexpr bool isKeyValueCompositional
static FailureOr< std::optional< char > > parse(AsmParser &parser)
static constexpr bool isKeyValueCompositional
static FailureOr< std::string > parse(AsmParser &parser)
Provide a template class that can be specialized by users to dispatch to parsers.
Whether the selected FieldParser consumes exactly one value in a keyed property list.