MLIR 22.0.0git
mlir::detail::Parser Class Reference

This class implement support for parsing global entities like attributes and types. More...

#include "AsmParser/Parser.h"

Public Types

using Delimiter = OpAsmParser::Delimiter

Public Member Functions

 Parser (ParserState &state)
ParserStategetState () const
MLIRContextgetContext () const
const llvm::SourceMgr & getSourceMgr ()
ParseResult parseCommaSeparatedListUntil (Token::Kind rightToken, function_ref< ParseResult()> parseElement, bool allowEmptyList=true)
 Parse a comma-separated list of elements up until the specified end token.
ParseResult parseCommaSeparatedList (Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())
 Parse a list of comma-separated items with an optional delimiter.
ParseResult parseCommaSeparatedList (function_ref< ParseResult()> parseElementFn)
 Parse a comma separated list of elements that must have at least one entry in it.
ParseResult parseDialectSymbolBody (StringRef &body, bool &isCodeCompletion)
 Parse the body of a dialect symbol, which starts and ends with <>'s, and may be recursive.
ParseResult parseDialectSymbolBody (StringRef &body)
InFlightDiagnostic emitError (const Twine &message={})
 Emit an error and return failure.
InFlightDiagnostic emitError (SMLoc loc, const Twine &message={})
InFlightDiagnostic emitWrongTokenError (const Twine &message={})
 Emit an error about a "wrong token".
Location getEncodedSourceLocation (SMLoc loc)
 Encode the specified source location information into an attribute for attachment to the IR.
const TokengetToken () const
 Return the current token the parser is inspecting.
StringRef getTokenSpelling () const
const TokengetLastToken () const
 Return the last parsed token.
bool consumeIf (Token::Kind kind)
 If the current token has the specified kind, consume it and return true.
void consumeToken ()
 Advance the current lexer onto the next token.
void consumeToken (Token::Kind kind)
 Advance the current lexer onto the next token, asserting what the expected current token is.
void resetToken (const char *tokPos)
 Reset the parser to the given lexer position.
ParseResult parseToken (Token::Kind expectedToken, const Twine &message)
 Consume the specified token if present and return success.
ParseResult parseOptionalString (std::string *string)
 Parses a quoted string token if present.
OptionalParseResult parseOptionalInteger (APInt &result)
 Parse an optional integer value from the stream.
OptionalParseResult parseOptionalDecimalInteger (APInt &result)
 Parse an optional integer value only in decimal format from the stream.
ParseResult parseFloatFromLiteral (std::optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics)
 Parse a floating point value from a literal.
ParseResult parseFloatFromIntegerLiteral (std::optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics)
 Parse a floating point value from an integer literal token.
bool isCurrentTokenAKeyword () const
 Returns true if the current token corresponds to a keyword.
ParseResult parseOptionalKeyword (StringRef *keyword)
 Parse a keyword, if present, into 'keyword'.
ParseResult parseOptionalKeywordOrString (std::string *result)
 Parse an optional keyword or string and set instance into 'result'.`.
FailureOr< AsmDialectResourceHandleparseResourceHandle (const OpAsmDialectInterface *dialect, std::string &name)
 Parse a handle to a dialect resource within the assembly format.
FailureOr< AsmDialectResourceHandleparseResourceHandle (Dialect *dialect)
template<typename T, typename... ParamsT>
getChecked (SMLoc loc, ParamsT &&...params)
 Invoke the getChecked method of the given Attribute or Type class, using the provided location to emit errors in the case of failure. Note that unlike OpBuilder::getType, this method does not implicitly insert a context parameter.
ParseResult parseFunctionResultTypes (SmallVectorImpl< Type > &elements)
 Parse a function result type.
ParseResult parseTypeListNoParens (SmallVectorImpl< Type > &elements)
 Parse a list of types without an enclosing parenthesis.
ParseResult parseTypeListParens (SmallVectorImpl< Type > &elements)
 Parse a parenthesized list of types.
OptionalParseResult parseOptionalType (Type &type)
 Optionally parse a type.
Type parseType ()
 Parse an arbitrary type.
Type parseComplexType ()
 Parse a complex type.
Type parseExtendedType ()
 Parse an extended type.
Type parseFunctionType ()
 Parse a function type.
Type parseMemRefType ()
 Parse a memref type.
Type parseNonFunctionType ()
 Parse a non function type.
Type parseTensorType ()
 Parse a tensor type.
Type parseTupleType ()
 Parse a tuple type.
VectorType parseVectorType ()
 Parse a vector type.
ParseResult parseVectorDimensionList (SmallVectorImpl< int64_t > &dimensions, SmallVectorImpl< bool > &scalableDims)
 Parse a dimension list in a vector type.
ParseResult parseDimensionListRanked (SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)
 Parse a dimension list of a tensor or memref type.
ParseResult parseIntegerInDimensionList (int64_t &value)
ParseResult parseXInDimensionList ()
 Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element type, as in "xf32", leaving the "f32" as the next token.
Attribute parseAttribute (Type type={})
 Parse an arbitrary attribute with an optional type.
OptionalParseResult parseOptionalAttribute (Attribute &attribute, Type type={})
 Parse an optional attribute with the provided type.
OptionalParseResult parseOptionalAttribute (ArrayAttr &attribute, Type type)
OptionalParseResult parseOptionalAttribute (StringAttr &attribute, Type type)
OptionalParseResult parseOptionalAttribute (SymbolRefAttr &result, Type type)
template<typename AttributeT>
OptionalParseResult parseOptionalAttributeWithToken (Token::Kind kind, AttributeT &attr, Type type={})
 Parse an optional attribute that is demarcated by a specific token.
ParseResult parseAttributeDict (NamedAttrList &attributes)
 Parse an attribute dictionary.
Attribute parseDistinctAttr (Type type)
 Parse a distinct attribute.
Attribute parseExtendedAttr (Type type)
 Parse an extended attribute.
Attribute parseFloatAttr (Type type, bool isNegative)
 Parse a float attribute.
Attribute parseDecOrHexAttr (Type type, bool isNegative)
 Parse a decimal or a hexadecimal literal, which can be either an integer or a float attribute.
Attribute parseDenseElementsAttr (Type attrType)
 Parse a dense elements attribute.
ShapedType parseElementsLiteralType (SMLoc loc, Type type)
 Shaped type for elements attribute.
Attribute parseDenseResourceElementsAttr (Type attrType)
 Parse a dense resource elements attribute.
Attribute parseDenseArrayAttr (Type type)
 Parse a DenseArrayAttr.
Attribute parseSparseElementsAttr (Type attrType)
 Parse a sparse elements attribute.
Attribute parseStridedLayoutAttr ()
 Parse a strided layout attribute.
ParseResult parseLocationInstance (LocationAttr &loc)
 Parse a raw location instance.
ParseResult parseCallSiteLocation (LocationAttr &loc)
 Parse a callsite location instance.
ParseResult parseFusedLocation (LocationAttr &loc)
 Parse a fused location instance.
ParseResult parseNameOrFileLineColRange (LocationAttr &loc)
 Parse a name or FileLineCol location instance.
ParseResult parseAffineMapOrIntegerSetReference (AffineMap &map, IntegerSet &set)
 Parse a reference to either an affine map, expr, or an integer set.
ParseResult parseAffineMapReference (AffineMap &map)
ParseResult parseAffineExprReference (ArrayRef< std::pair< StringRef, AffineExpr > > symbolSet, AffineExpr &expr)
ParseResult parseIntegerSetReference (IntegerSet &set)
ParseResult parseAffineMapOfSSAIds (AffineMap &map, function_ref< ParseResult(bool)> parseElement, Delimiter delimiter)
 Parse an AffineMap where the dim and symbol identifiers are SSA ids.
ParseResult parseAffineExprOfSSAIds (AffineExpr &expr, function_ref< ParseResult(bool)> parseElement)
 Parse an AffineExpr where dim and symbol identifiers are SSA ids.
ParseResult codeCompleteDialectName ()
 The set of various code completion methods. Every completion method returns failure to signal that parsing should abort after any desired completions have been enqueued. Note that failure is does not mean completion failed, it's just a signal to the parser to stop.
ParseResult codeCompleteOperationName (StringRef dialectName)
ParseResult codeCompleteDialectOrElidedOpName (SMLoc loc)
ParseResult codeCompleteStringDialectOrOperationName (StringRef name)
ParseResult codeCompleteExpectedTokens (ArrayRef< StringRef > tokens)
ParseResult codeCompleteOptionalTokens (ArrayRef< StringRef > tokens)
Attribute codeCompleteAttribute ()
Type codeCompleteType ()
Attribute codeCompleteDialectSymbol (const llvm::StringMap< Attribute > &aliases)
Type codeCompleteDialectSymbol (const llvm::StringMap< Type > &aliases)

Public Attributes

Builder builder

Protected Attributes

ParserStatestate
 The Parser is subclassed and reinstantiated.

Detailed Description

This class implement support for parsing global entities like attributes and types.

It is intended to be subclassed by specialized subparsers that include state.

Definition at line 27 of file Parser.h.

Member Typedef Documentation

◆ Delimiter

Constructor & Destructor Documentation

◆ Parser()

mlir::detail::Parser::Parser ( ParserState & state)
inline

Definition at line 33 of file Parser.h.

References builder, mlir::config, getContext(), and state.

Member Function Documentation

◆ codeCompleteAttribute()

Attribute Parser::codeCompleteAttribute ( )

Definition at line 544 of file Parser.cpp.

References state.

Referenced by parseAttribute().

◆ codeCompleteDialectName()

LogicalResult Parser::codeCompleteDialectName ( )

The set of various code completion methods. Every completion method returns failure to signal that parsing should abort after any desired completions have been enqueued. Note that failure is does not mean completion failed, it's just a signal to the parser to stop.

Definition at line 484 of file Parser.cpp.

References state.

Referenced by codeCompleteDialectOrElidedOpName(), and codeCompleteStringDialectOrOperationName().

◆ codeCompleteDialectOrElidedOpName()

ParseResult Parser::codeCompleteDialectOrElidedOpName ( SMLoc loc)

Definition at line 499 of file Parser.cpp.

References codeCompleteDialectName(), codeCompleteOperationName(), contains(), and state.

◆ codeCompleteDialectSymbol() [1/2]

Attribute Parser::codeCompleteDialectSymbol ( const llvm::StringMap< Attribute > & aliases)

Definition at line 555 of file Parser.cpp.

References state.

Referenced by parseExtendedSymbol().

◆ codeCompleteDialectSymbol() [2/2]

Type Parser::codeCompleteDialectSymbol ( const llvm::StringMap< Type > & aliases)

Definition at line 559 of file Parser.cpp.

References state.

◆ codeCompleteExpectedTokens()

ParseResult Parser::codeCompleteExpectedTokens ( ArrayRef< StringRef > tokens)

Definition at line 535 of file Parser.cpp.

References state.

◆ codeCompleteOperationName()

LogicalResult Parser::codeCompleteOperationName ( StringRef dialectName)

Definition at line 489 of file Parser.cpp.

References state.

Referenced by codeCompleteDialectOrElidedOpName(), and codeCompleteStringDialectOrOperationName().

◆ codeCompleteOptionalTokens()

ParseResult Parser::codeCompleteOptionalTokens ( ArrayRef< StringRef > tokens)

Definition at line 539 of file Parser.cpp.

References state.

◆ codeCompleteStringDialectOrOperationName()

ParseResult Parser::codeCompleteStringDialectOrOperationName ( StringRef name)

Definition at line 522 of file Parser.cpp.

References codeCompleteDialectName(), and codeCompleteOperationName().

◆ codeCompleteType()

Type Parser::codeCompleteType ( )

Definition at line 549 of file Parser.cpp.

References state.

Referenced by parseNonFunctionType().

◆ consumeIf()

◆ consumeToken() [1/2]

◆ consumeToken() [2/2]

void mlir::detail::Parser::consumeToken ( Token::Kind kind)
inline

Advance the current lexer onto the next token, asserting what the expected current token is.

This is preferred to the above method because it leads to more self-documenting code with better checking.

Definition at line 129 of file Parser.h.

References consumeToken(), and state.

◆ emitError() [1/2]

◆ emitError() [2/2]

InFlightDiagnostic Parser::emitError ( SMLoc loc,
const Twine & message = {} )

Definition at line 201 of file Parser.cpp.

References diag(), mlir::emitError(), getEncodedSourceLocation(), and getToken().

◆ emitWrongTokenError()

InFlightDiagnostic Parser::emitWrongTokenError ( const Twine & message = {})

Emit an error about a "wrong token".

If the current token is at the start of a source line, this will apply heuristics to back up and report the error at the end of the previous line, which is where the expected token is supposed to be.

Definition at line 215 of file Parser.cpp.

References emitError(), and state.

Referenced by parseAttribute(), parseAttributeDict(), parseCallSiteLocation(), parseCommaSeparatedListUntil(), parseExtendedSymbol(), parseLocationInstance(), parseNameOrFileLineColRange(), parseNonFunctionType(), parseStridedLayoutAttr(), parseToken(), parseVectorDimensionList(), and parseXInDimensionList().

◆ getChecked()

template<typename T, typename... ParamsT>
T mlir::detail::Parser::getChecked ( SMLoc loc,
ParamsT &&... params )
inline

Invoke the getChecked method of the given Attribute or Type class, using the provided location to emit errors in the case of failure. Note that unlike OpBuilder::getType, this method does not implicitly insert a context parameter.

Definition at line 198 of file Parser.h.

References emitError().

Referenced by parseMemRefType(), parseSparseElementsAttr(), and parseVectorType().

◆ getContext()

◆ getEncodedSourceLocation()

Location mlir::detail::Parser::getEncodedSourceLocation ( SMLoc loc)
inline

Encode the specified source location information into an attribute for attachment to the IR.

Definition at line 94 of file Parser.h.

References state.

Referenced by emitError().

◆ getLastToken()

const Token & mlir::detail::Parser::getLastToken ( ) const
inline

Return the last parsed token.

Definition at line 107 of file Parser.h.

References state.

◆ getSourceMgr()

const llvm::SourceMgr & mlir::detail::Parser::getSourceMgr ( )
inline

Definition at line 39 of file Parser.h.

References state.

◆ getState()

ParserState & mlir::detail::Parser::getState ( ) const
inline

Definition at line 37 of file Parser.h.

References state.

Referenced by parseResourceHandle().

◆ getToken()

◆ getTokenSpelling()

StringRef mlir::detail::Parser::getTokenSpelling ( ) const
inline

◆ isCurrentTokenAKeyword()

bool mlir::detail::Parser::isCurrentTokenAKeyword ( ) const
inline

Returns true if the current token corresponds to a keyword.

Definition at line 169 of file Parser.h.

References getToken(), mlir::Token::isAny(), and mlir::Token::isKeyword().

Referenced by parseNameOrFileLineColRange(), and parseOptionalKeyword().

◆ parseAffineExprOfSSAIds()

ParseResult Parser::parseAffineExprOfSSAIds ( AffineExpr & expr,
function_ref< ParseResult(bool)> parseElement )

Parse an AffineExpr where dim and symbol identifiers are SSA ids.

Parse an AffineExpr of SSA ids.

The callback parseElement is used to parse SSA value uses encountered while parsing.

Definition at line 756 of file AffineParser.cpp.

References parseAffineExprOfSSAIds(), and state.

Referenced by parseAffineExprOfSSAIds().

◆ parseAffineExprReference()

ParseResult Parser::parseAffineExprReference ( ArrayRef< std::pair< StringRef, AffineExpr > > symbolSet,
AffineExpr & expr )

Definition at line 729 of file AffineParser.cpp.

References parseAffineExprReference(), and state.

Referenced by parseAffineExprReference().

◆ parseAffineMapOfSSAIds()

ParseResult Parser::parseAffineMapOfSSAIds ( AffineMap & map,
function_ref< ParseResult(bool)> parseElement,
OpAsmParser::Delimiter delimiter )

Parse an AffineMap where the dim and symbol identifiers are SSA ids.

Parse an AffineMap of SSA ids.

The callback 'parseElement' is used to parse SSA value uses encountered while parsing affine expressions.

Definition at line 746 of file AffineParser.cpp.

References parseAffineMapOfSSAIds(), and state.

Referenced by parseAffineMapOfSSAIds().

◆ parseAffineMapOrIntegerSetReference()

ParseResult Parser::parseAffineMapOrIntegerSetReference ( AffineMap & map,
IntegerSet & set )

Parse a reference to either an affine map, expr, or an integer set.

Parse an ambiguous reference to either and affine map or an integer set.

Definition at line 716 of file AffineParser.cpp.

References parseAffineMapOrIntegerSetReference(), and state.

Referenced by parseAffineMapOrIntegerSet(), parseAffineMapOrIntegerSetReference(), parseAffineMapReference(), and parseIntegerSetReference().

◆ parseAffineMapReference()

ParseResult Parser::parseAffineMapReference ( AffineMap & map)

◆ parseAttribute()

Attribute Parser::parseAttribute ( Type type = {})

Parse an arbitrary attribute with an optional type.

Parse an arbitrary attribute.

attribute-value ::= unit | bool-literal | integer-literal (: (index-type | integer-type))? | float-literal (: float-type)? | string-literal (: type)? | type | [ : (integer-type | float-type) tensor-literal ] | [ (attribute-value (, attribute-value)*)? ] | { (attribute-entry (, attribute-entry)*)? } | symbol-ref-id (:: symbol-ref-id)* | dense < tensor-literal > : (tensor-type | vector-type) | sparse < attribute-value , attribute-value > : (tensor-type | vector-type) | strided < [ comma-separated-int-or-question ] (, offset : integer-literal)? > | distinct-attribute | extended-attribute

Definition at line 48 of file AttributeParser.cpp.

References builder, codeCompleteAttribute(), consumeIf(), consumeToken(), emitError(), emitWrongTokenError(), getContext(), mlir::NamedAttrList::getDictionary(), mlir::Token::getLoc(), mlir::Token::getStringValue(), mlir::Token::getSymbolReference(), getToken(), parseAffineMapReference(), parseAttribute(), parseAttributeDict(), parseCommaSeparatedListUntil(), parseDecOrHexAttr(), parseDenseArrayAttr(), parseDenseElementsAttr(), parseDenseResourceElementsAttr(), parseDistinctAttr(), parseExtendedAttr(), parseFloatAttr(), parseIntegerSetReference(), parseLocationInstance(), parseOptionalType(), parseSparseElementsAttr(), parseStridedLayoutAttr(), parseToken(), parseType(), result, state, and success().

Referenced by parseAttribute(), parseAttributeDict(), parseDistinctAttr(), parseFusedLocation(), parseMemRefType(), and parseOptionalAttribute().

◆ parseAttributeDict()

ParseResult Parser::parseAttributeDict ( NamedAttrList & attributes)

Parse an attribute dictionary.

Attribute dictionary.

attribute-dict ::= { } | { attribute-entry (, attribute-entry)* } attribute-entry ::= (bare-id | string-literal) = attribute-value

Definition at line 295 of file AttributeParser.cpp.

References builder, consumeIf(), consumeToken(), emitError(), emitWrongTokenError(), getContext(), mlir::MLIRContext::getOrLoadDialect(), getToken(), getTokenSpelling(), parseAttribute(), parseCommaSeparatedList(), mlir::NamedAttrList::push_back(), and success().

Referenced by parseAttribute().

◆ parseCallSiteLocation()

ParseResult Parser::parseCallSiteLocation ( LocationAttr & loc)

Parse a callsite location instance.

Specific location instances.

location-inst ::= filelinecol-location | name-location | callsite-location | fused-location | unknown-location filelinecol-location ::= string-literal ':' integer-literal ':' integer-literal name-location ::= string-literal callsite-location ::= 'callsite' '(' location-inst 'at' location-inst ')' fused-location ::= fused ('<' attribute-value '>')? '[' location-inst (location-inst ',')* ']' unknown-location ::= 'unknown'

Definition at line 35 of file LocationParser.cpp.

References consumeToken(), emitWrongTokenError(), getToken(), parseCallSiteLocation(), parseLocationInstance(), parseToken(), and success().

Referenced by parseCallSiteLocation(), and parseLocationInstance().

◆ parseCommaSeparatedList() [1/2]

ParseResult Parser::parseCommaSeparatedList ( Delimiter delimiter,
function_ref< ParseResult()> parseElementFn,
StringRef contextMessage = StringRef() )

Parse a list of comma-separated items with an optional delimiter.

If a delimiter is provided, then an empty list is allowed. If not, then at least one element will be parsed.

Definition at line 84 of file Parser.cpp.

References consumeIf(), getToken(), parseCommaSeparatedList(), parseToken(), and success().

Referenced by parseAttributeDict(), parseCommaSeparatedList(), parseCommaSeparatedList(), parseCommaSeparatedListUntil(), parseDenseArrayAttr(), parseFusedLocation(), and parseTypeListNoParens().

◆ parseCommaSeparatedList() [2/2]

ParseResult mlir::detail::Parser::parseCommaSeparatedList ( function_ref< ParseResult()> parseElementFn)
inline

Parse a comma separated list of elements that must have at least one entry in it.

Definition at line 58 of file Parser.h.

References parseCommaSeparatedList().

◆ parseCommaSeparatedListUntil()

ParseResult Parser::parseCommaSeparatedListUntil ( Token::Kind rightToken,
function_ref< ParseResult()> parseElement,
bool allowEmptyList = true )

Parse a comma-separated list of elements up until the specified end token.

Parse a comma-separated list of elements, terminated with an arbitrary token.

This allows empty lists if allowEmptyList is true.

abstract-list ::= rightToken // if allowEmptyList == true abstract-list ::= element (',' element)* rightToken

Definition at line 173 of file Parser.cpp.

References consumeToken(), emitWrongTokenError(), getToken(), mlir::Token::getTokenSpelling(), parseCommaSeparatedList(), parseToken(), and success().

Referenced by parseAttribute(), and parseMemRefType().

◆ parseComplexType()

Type Parser::parseComplexType ( )

Parse a complex type.

complex-type ::= complex < type >

Definition at line 134 of file TypeParser.cpp.

References consumeToken(), emitError(), mlir::Token::getLoc(), getToken(), parseToken(), and parseType().

Referenced by parseNonFunctionType().

◆ parseDecOrHexAttr()

Attribute Parser::parseDecOrHexAttr ( Type type,
bool isNegative )

Parse a decimal or a hexadecimal literal, which can be either an integer or a float attribute.

Definition at line 406 of file AttributeParser.cpp.

References buildAttributeAPInt(), builder, consumeIf(), consumeToken(), emitError(), mlir::Token::getLoc(), mlir::Token::getSpelling(), getToken(), mlir::Type::isUnsignedInteger(), parseFloatFromIntegerLiteral(), parseType(), and result.

Referenced by parseAttribute().

◆ parseDenseArrayAttr()

◆ parseDenseElementsAttr()

Attribute Parser::parseDenseElementsAttr ( Type attrType)

Parse a dense elements attribute.

Definition at line 956 of file AttributeParser.cpp.

References consumeIf(), consumeToken(), mlir::Token::getLoc(), getToken(), parseElementsLiteralType(), and parseToken().

Referenced by parseAttribute().

◆ parseDenseResourceElementsAttr()

Attribute Parser::parseDenseResourceElementsAttr ( Type attrType)

Parse a dense resource elements attribute.

Definition at line 976 of file AttributeParser.cpp.

References consumeToken(), emitError(), getContext(), mlir::Token::getLoc(), getToken(), parseResourceHandle(), parseToken(), and parseType().

Referenced by parseAttribute().

◆ parseDialectSymbolBody() [1/2]

ParseResult mlir::detail::Parser::parseDialectSymbolBody ( StringRef & body)
inline

Definition at line 68 of file Parser.h.

References parseDialectSymbolBody().

◆ parseDialectSymbolBody() [2/2]

ParseResult Parser::parseDialectSymbolBody ( StringRef & body,
bool & isCodeCompletion )

Parse the body of a dialect symbol, which starts and ends with <>'s, and may be recursive.

pretty-dialect-sym-body ::= '<' pretty-dialect-sym-contents+ '>' pretty-dialect-sym-contents ::= pretty-dialect-sym-body | '(' pretty-dialect-sym-contents+ ')' | '[' pretty-dialect-sym-contents+ ']' | '{' pretty-dialect-sym-contents+ '}' | '[^[<({>])}\0]+'

Return with the 'body' StringRef encompassing the entire body. isCodeCompletion is set to true if the body contained a code completion location, in which case the body is only populated up to the completion.

Definition at line 66 of file DialectSymbolParser.cpp.

References emitError(), getTokenSpelling(), parseDialectSymbolBody(), resetToken(), state, and success().

Referenced by parseDialectSymbolBody(), parseDialectSymbolBody(), and parseExtendedSymbol().

◆ parseDimensionListRanked()

ParseResult Parser::parseDimensionListRanked ( SmallVectorImpl< int64_t > & dimensions,
bool allowDynamic = true,
bool withTrailingX = true )

Parse a dimension list of a tensor or memref type.

This populates the dimension list, using ShapedType::kDynamic for the ? dimensions if allowDynamic is set and errors out on ? otherwise. Parsing the trailing x is configurable.

dimension-list ::= eps | dimension (x dimension)* dimension-list-with-trailing-x ::= (dimension x)* dimension ::= ? | decimal-literal

When allowDynamic is not set, this is used to parse:

static-dimension-list ::= eps | decimal-literal (x decimal-literal)* static-dimension-list-with-trailing-x ::= (dimension x)*

Definition at line 542 of file TypeParser.cpp.

References consumeIf(), emitError(), mlir::Token::getLoc(), getToken(), getTokenSpelling(), parseIntegerInDimensionList(), parseXInDimensionList(), and success().

Referenced by parseMemRefType(), and parseTensorType().

◆ parseDistinctAttr()

Attribute Parser::parseDistinctAttr ( Type type)

Parse a distinct attribute.

distinct-attribute ::= distinct [ integer-literal ]< attribute-value >

Definition at line 1201 of file AttributeParser.cpp.

References builder, consumeToken(), mlir::DistinctAttr::create(), emitError(), mlir::Token::getLoc(), getToken(), mlir::Token::getUInt64IntegerValue(), parseAttribute(), parseToken(), and state.

Referenced by parseAttribute().

◆ parseElementsLiteralType()

ShapedType Parser::parseElementsLiteralType ( SMLoc loc,
Type type )

Shaped type for elements attribute.

elements-literal-type ::= vector-type | ranked-tensor-type

This method also checks the type has static shape.

Definition at line 1014 of file AttributeParser.cpp.

References emitError(), parseToken(), and parseType().

Referenced by parseDenseElementsAttr(), and parseSparseElementsAttr().

◆ parseExtendedAttr()

Attribute Parser::parseExtendedAttr ( Type type)

Parse an extended attribute.

extended-attribute ::= (dialect-attribute | attribute-alias) dialect-attribute ::= # dialect-namespace < attr-data > (: type)? | # alias-name pretty-dialect-sym-body? (: type)? attribute-alias ::= # alias-name

Definition at line 259 of file DialectSymbolParser.cpp.

References getContext(), parseExtendedSymbol(), and state.

Referenced by parseAttribute(), and parseLocationInstance().

◆ parseExtendedType()

Type Parser::parseExtendedType ( )

Parse an extended type.

extended-type ::= (dialect-type | type-alias) dialect-type ::= ! dialect-namespace < "</tt> type-data <tt>" > dialect-type ::= ! alias-name pretty-dialect-attribute-body? type-alias ::= ! alias-name

Definition at line 306 of file DialectSymbolParser.cpp.

References getContext(), parseExtendedSymbol(), and state.

Referenced by parseNonFunctionType().

◆ parseFloatAttr()

Attribute Parser::parseFloatAttr ( Type type,
bool isNegative )

Parse a float attribute.

Definition at line 340 of file AttributeParser.cpp.

References builder, consumeIf(), consumeToken(), emitError(), mlir::Token::getFloatingPointValue(), getToken(), and parseType().

Referenced by parseAttribute().

◆ parseFloatFromIntegerLiteral()

ParseResult Parser::parseFloatFromIntegerLiteral ( std::optional< APFloat > & result,
const Token & tok,
bool isNegative,
const llvm::fltSemantics & semantics )

Parse a floating point value from an integer literal token.

Definition at line 385 of file Parser.cpp.

References mlir::InFlightDiagnostic::attachNote(), emitError(), mlir::Token::getLoc(), mlir::Token::getSpelling(), result, and success().

Referenced by parseDecOrHexAttr(), and parseFloatFromLiteral().

◆ parseFloatFromLiteral()

ParseResult Parser::parseFloatFromLiteral ( std::optional< APFloat > & result,
const Token & tok,
bool isNegative,
const llvm::fltSemantics & semantics )

Parse a floating point value from a literal.

Definition at line 361 of file Parser.cpp.

References emitError(), mlir::Token::getFloatingPointValue(), mlir::Token::getLoc(), mlir::Token::is(), parseFloatFromIntegerLiteral(), result, and success().

◆ parseFunctionResultTypes()

ParseResult Parser::parseFunctionResultTypes ( SmallVectorImpl< Type > & elements)

Parse a function result type.

function-result-type ::= type-list-parens | non-function-type

Definition at line 85 of file TypeParser.cpp.

References getToken(), parseNonFunctionType(), parseTypeListParens(), and success().

Referenced by parseFunctionType().

◆ parseFunctionType()

Type Parser::parseFunctionType ( )

Parse a function type.

function-type ::= type-list-parens -> function-result-type

Definition at line 157 of file TypeParser.cpp.

References builder, getToken(), parseFunctionResultTypes(), parseToken(), and parseTypeListParens().

Referenced by parseType().

◆ parseFusedLocation()

ParseResult Parser::parseFusedLocation ( LocationAttr & loc)

Parse a fused location instance.

Definition at line 67 of file LocationParser.cpp.

References consumeIf(), consumeToken(), getContext(), parseAttribute(), parseCommaSeparatedList(), parseLocationInstance(), parseToken(), and success().

Referenced by parseLocationInstance().

◆ parseIntegerInDimensionList()

ParseResult Parser::parseIntegerInDimensionList ( int64_t & value)

◆ parseIntegerSetReference()

ParseResult Parser::parseIntegerSetReference ( IntegerSet & set)

◆ parseLocationInstance()

◆ parseMemRefType()

Type Parser::parseMemRefType ( )

Parse a memref type.

memref-type ::= ranked-memref-type | unranked-memref-type

ranked-memref-type ::= memref < dimension-list-ranked type (, layout-specification)? (, memory-space)? >

unranked-memref-type ::= memref <*x type (, memory-space)? >

stride-list ::= [ (dimension (, dimension)*)? ] strided-layout ::= offset: dimension , strides: stride-list layout-specification ::= semi-affine-map | strided-layout | attribute memory-space ::= integer-literal | attribute

Definition at line 183 of file TypeParser.cpp.

References consumeIf(), consumeToken(), emitError(), getChecked(), mlir::Token::getLoc(), getToken(), mlir::BaseMemRefType::isValidElementType(), parseAttribute(), parseCommaSeparatedListUntil(), parseDimensionListRanked(), parseToken(), parseType(), parseXInDimensionList(), and success().

Referenced by parseNonFunctionType().

◆ parseNameOrFileLineColRange()

◆ parseNonFunctionType()

Type Parser::parseNonFunctionType ( )

Parse a non function type.

Parse any type except the function type.

non-function-type ::= integer-type | index-type | float-type | extended-type | vector-type | tensor-type | memref-type | complex-type | tuple-type | none-type

index-type ::= index float-type ::= f16 | bf16 | f32 | f64 | f80 | f128 none-type ::= none

Definition at line 275 of file TypeParser.cpp.

References builder, codeCompleteType(), consumeToken(), emitError(), emitWrongTokenError(), getContext(), mlir::Token::getIntTypeBitwidth(), getToken(), parseComplexType(), parseExtendedType(), parseMemRefType(), parseTensorType(), parseTupleType(), and parseVectorType().

Referenced by parseFunctionResultTypes(), and parseType().

◆ parseOptionalAttribute() [1/4]

OptionalParseResult Parser::parseOptionalAttribute ( ArrayAttr & attribute,
Type type )

Definition at line 276 of file AttributeParser.cpp.

References ArrayAttr(), and parseOptionalAttributeWithToken().

◆ parseOptionalAttribute() [2/4]

OptionalParseResult Parser::parseOptionalAttribute ( Attribute & attribute,
Type type = {} )

Parse an optional attribute with the provided type.

Definition at line 244 of file AttributeParser.cpp.

References getToken(), parseAttribute(), parseOptionalType(), result, and success().

Referenced by parseTensorType().

◆ parseOptionalAttribute() [3/4]

OptionalParseResult Parser::parseOptionalAttribute ( StringAttr & attribute,
Type type )

Definition at line 280 of file AttributeParser.cpp.

References parseOptionalAttributeWithToken().

◆ parseOptionalAttribute() [4/4]

OptionalParseResult Parser::parseOptionalAttribute ( SymbolRefAttr & result,
Type type )

Definition at line 284 of file AttributeParser.cpp.

References parseOptionalAttributeWithToken(), and result.

◆ parseOptionalAttributeWithToken()

template<typename AttributeT>
OptionalParseResult mlir::detail::Parser::parseOptionalAttributeWithToken ( Token::Kind kind,
AttributeT & attr,
Type type = {} )
inline

Parse an optional attribute that is demarcated by a specific token.

Definition at line 260 of file Parser.h.

Referenced by parseOptionalAttribute(), parseOptionalAttribute(), and parseOptionalAttribute().

◆ parseOptionalDecimalInteger()

OptionalParseResult Parser::parseOptionalDecimalInteger ( APInt & result)

Parse an optional integer value only in decimal format from the stream.

Definition at line 323 of file Parser.cpp.

References consumeIf(), consumeToken(), emitError(), mlir::Token::getLoc(), mlir::Token::getSpelling(), getToken(), mlir::Token::isNot(), parseToken(), result, state, and success().

◆ parseOptionalInteger()

OptionalParseResult Parser::parseOptionalInteger ( APInt & result)

Parse an optional integer value from the stream.

Definition at line 286 of file Parser.cpp.

References consumeIf(), emitError(), mlir::Token::getLoc(), mlir::Token::getSpelling(), getToken(), mlir::Token::isNot(), parseToken(), result, and success().

◆ parseOptionalKeyword()

ParseResult Parser::parseOptionalKeyword ( StringRef * keyword)

Parse a keyword, if present, into 'keyword'.

Definition at line 416 of file Parser.cpp.

References consumeToken(), getTokenSpelling(), isCurrentTokenAKeyword(), and success().

Referenced by parseOptionalKeywordOrString().

◆ parseOptionalKeywordOrString()

ParseResult Parser::parseOptionalKeywordOrString ( std::string * result)

Parse an optional keyword or string and set instance into 'result'.`.

Definition at line 426 of file Parser.cpp.

References parseOptionalKeyword(), parseOptionalString(), result, and success().

Referenced by parseResourceHandle().

◆ parseOptionalString()

ParseResult Parser::parseOptionalString ( std::string * string)

Parses a quoted string token if present.

Definition at line 275 of file Parser.cpp.

References consumeToken(), mlir::Token::getStringValue(), getToken(), and success().

Referenced by parseOptionalKeywordOrString().

◆ parseOptionalType()

OptionalParseResult Parser::parseOptionalType ( Type & type)

Optionally parse a type.

Definition at line 31 of file TypeParser.cpp.

References getToken(), parseOptionalType(), and parseType().

Referenced by parseAttribute(), parseOptionalAttribute(), and parseOptionalType().

◆ parseResourceHandle() [1/2]

◆ parseResourceHandle() [2/2]

FailureOr< AsmDialectResourceHandle > Parser::parseResourceHandle ( Dialect * dialect)

Definition at line 470 of file Parser.cpp.

References emitError(), mlir::Dialect::getNamespace(), and parseResourceHandle().

◆ parseSparseElementsAttr()

Attribute Parser::parseSparseElementsAttr ( Type attrType)

Parse a sparse elements attribute.

Parse the indices. We don't allow hex values here as we may need to use the inferred shape.

Parse the values.

Definition at line 1038 of file AttributeParser.cpp.

References builder, consumeIf(), consumeToken(), mlir::DenseElementsAttr::get(), getChecked(), mlir::Token::getLoc(), getToken(), indices, parseElementsLiteralType(), and parseToken().

Referenced by parseAttribute().

◆ parseStridedLayoutAttr()

Attribute Parser::parseStridedLayoutAttr ( )

◆ parseTensorType()

Type Parser::parseTensorType ( )

Parse a tensor type.

tensor-type ::= tensor < dimension-list type > dimension-list ::= dimension-list-ranked | *x

Definition at line 391 of file TypeParser.cpp.

References consumeIf(), consumeToken(), emitError(), mlir::Token::getLoc(), getToken(), mlir::TensorType::isValidElementType(), parseDimensionListRanked(), parseOptionalAttribute(), parseToken(), parseType(), and parseXInDimensionList().

Referenced by parseNonFunctionType().

◆ parseToken()

◆ parseTupleType()

Type Parser::parseTupleType ( )

Parse a tuple type.

tuple-type ::= tuple < (type (, type)*)? >

Definition at line 449 of file TypeParser.cpp.

References consumeIf(), consumeToken(), getContext(), parseToken(), and parseTypeListNoParens().

Referenced by parseNonFunctionType().

◆ parseType()

◆ parseTypeListNoParens()

ParseResult Parser::parseTypeListNoParens ( SmallVectorImpl< Type > & elements)

Parse a list of types without an enclosing parenthesis.

The list must have at least one member.

type-list-no-parens ::= type (, type)*

Definition at line 101 of file TypeParser.cpp.

References parseCommaSeparatedList(), parseType(), and success().

Referenced by parseTupleType(), and parseTypeListParens().

◆ parseTypeListParens()

ParseResult Parser::parseTypeListParens ( SmallVectorImpl< Type > & elements)

Parse a parenthesized list of types.

type-list-parens ::= ( ) | ( type-list-no-parens )

Definition at line 116 of file TypeParser.cpp.

References consumeToken(), getToken(), parseToken(), parseTypeListNoParens(), and success().

Referenced by parseFunctionResultTypes(), and parseFunctionType().

◆ parseVectorDimensionList()

ParseResult Parser::parseVectorDimensionList ( SmallVectorImpl< int64_t > & dimensions,
SmallVectorImpl< bool > & scalableDims )

Parse a dimension list in a vector type.

This populates the dimension list. For i-th dimension, scalableDims[i] contains either:

  • false for a non-scalable dimension (e.g. 4),
  • true for a scalable dimension (e.g. [4]).

vector-dim-list := (static-dim-list x)? static-dim-list ::= static-dim (x static-dim)* static-dim ::= (decimal-literal | [ decimal-literal ])

Definition at line 506 of file TypeParser.cpp.

References consumeIf(), emitWrongTokenError(), getToken(), parseIntegerInDimensionList(), parseXInDimensionList(), and success().

Referenced by parseVectorType().

◆ parseVectorType()

VectorType Parser::parseVectorType ( )

Parse a vector type.

vector-type ::= vector < vector-dim-list vector-element-type > vector-dim-list := (static-dim-list x)? ([ static-dim-list ] x)? static-dim-list ::= decimal-literal (x decimal-literal)*

Definition at line 475 of file TypeParser.cpp.

References consumeToken(), getChecked(), mlir::Token::getLoc(), getToken(), parseToken(), parseType(), and parseVectorDimensionList().

Referenced by parseNonFunctionType().

◆ parseXInDimensionList()

ParseResult Parser::parseXInDimensionList ( )

Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element type, as in "xf32", leaving the "f32" as the next token.

Definition at line 607 of file TypeParser.cpp.

References consumeToken(), emitWrongTokenError(), getToken(), getTokenSpelling(), state, and success().

Referenced by parseDimensionListRanked(), parseMemRefType(), parseTensorType(), and parseVectorDimensionList().

◆ resetToken()

void mlir::detail::Parser::resetToken ( const char * tokPos)
inline

Reset the parser to the given lexer position.

Resetting the parser/lexer position does not update 'state.lastToken'. 'state.lastToken' is the last parsed token, and is used to provide the scope end location for OperationDefinitions. To ensure the correctness of the end location, the last consumed token of an OperationDefinition needs to be the last token belonging to it.

Definition at line 140 of file Parser.h.

References state.

Referenced by parseDialectSymbolBody().

Member Data Documentation

◆ builder

◆ state


The documentation for this class was generated from the following files: