MLIR  20.0.0git
Public Types | Public Member Functions | Public Attributes | Protected Attributes | List of all members
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. More...
 
ParseResult parseCommaSeparatedList (Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())
 Parse a list of comma-separated items with an optional delimiter. More...
 
ParseResult parseCommaSeparatedList (function_ref< ParseResult()> parseElementFn)
 Parse a comma separated list of elements that must have at least one entry in it. More...
 
ParseResult parseDialectSymbolBody (StringRef &body, bool &isCodeCompletion)
 Parse the body of a dialect symbol, which starts and ends with <>'s, and may be recursive. More...
 
ParseResult parseDialectSymbolBody (StringRef &body)
 
InFlightDiagnostic emitError (const Twine &message={})
 Emit an error and return failure. More...
 
InFlightDiagnostic emitError (SMLoc loc, const Twine &message={})
 
InFlightDiagnostic emitWrongTokenError (const Twine &message={})
 Emit an error about a "wrong token". More...
 
Location getEncodedSourceLocation (SMLoc loc)
 Encode the specified source location information into an attribute for attachment to the IR. More...
 
const TokengetToken () const
 Return the current token the parser is inspecting. More...
 
StringRef getTokenSpelling () const
 
const TokengetLastToken () const
 Return the last parsed token. More...
 
bool consumeIf (Token::Kind kind)
 If the current token has the specified kind, consume it and return true. More...
 
void consumeToken ()
 Advance the current lexer onto the next token. More...
 
void consumeToken (Token::Kind kind)
 Advance the current lexer onto the next token, asserting what the expected current token is. More...
 
void resetToken (const char *tokPos)
 Reset the parser to the given lexer position. More...
 
ParseResult parseToken (Token::Kind expectedToken, const Twine &message)
 Consume the specified token if present and return success. More...
 
OptionalParseResult parseOptionalInteger (APInt &result)
 Parse an optional integer value from the stream. More...
 
OptionalParseResult parseOptionalDecimalInteger (APInt &result)
 Parse an optional integer value only in decimal format from the stream. More...
 
ParseResult parseFloatFromLiteral (std::optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics)
 Parse a floating point value from a literal. More...
 
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. More...
 
bool isCurrentTokenAKeyword () const
 Returns true if the current token corresponds to a keyword. More...
 
ParseResult parseOptionalKeyword (StringRef *keyword)
 Parse a keyword, if present, into 'keyword'. More...
 
FailureOr< AsmDialectResourceHandleparseResourceHandle (const OpAsmDialectInterface *dialect, StringRef &name)
 Parse a handle to a dialect resource within the assembly format. More...
 
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. More...
 
ParseResult parseFunctionResultTypes (SmallVectorImpl< Type > &elements)
 Parse a function result type. More...
 
ParseResult parseTypeListNoParens (SmallVectorImpl< Type > &elements)
 Parse a list of types without an enclosing parenthesis. More...
 
ParseResult parseTypeListParens (SmallVectorImpl< Type > &elements)
 Parse a parenthesized list of types. More...
 
OptionalParseResult parseOptionalType (Type &type)
 Optionally parse a type. More...
 
Type parseType ()
 Parse an arbitrary type. More...
 
Type parseComplexType ()
 Parse a complex type. More...
 
Type parseExtendedType ()
 Parse an extended type. More...
 
Type parseFunctionType ()
 Parse a function type. More...
 
Type parseMemRefType ()
 Parse a memref type. More...
 
Type parseNonFunctionType ()
 Parse a non function type. More...
 
Type parseTensorType ()
 Parse a tensor type. More...
 
Type parseTupleType ()
 Parse a tuple type. More...
 
VectorType parseVectorType ()
 Parse a vector type. More...
 
ParseResult parseVectorDimensionList (SmallVectorImpl< int64_t > &dimensions, SmallVectorImpl< bool > &scalableDims)
 Parse a dimension list in a vector type. More...
 
ParseResult parseDimensionListRanked (SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)
 Parse a dimension list of a tensor or memref type. More...
 
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. More...
 
Attribute parseAttribute (Type type={})
 Parse an arbitrary attribute with an optional type. More...
 
OptionalParseResult parseOptionalAttribute (Attribute &attribute, Type type={})
 Parse an optional attribute with the provided type. More...
 
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. More...
 
ParseResult parseAttributeDict (NamedAttrList &attributes)
 Parse an attribute dictionary. More...
 
Attribute parseDistinctAttr (Type type)
 Parse a distinct attribute. More...
 
Attribute parseExtendedAttr (Type type)
 Parse an extended attribute. More...
 
Attribute parseFloatAttr (Type type, bool isNegative)
 Parse a float attribute. More...
 
Attribute parseDecOrHexAttr (Type type, bool isNegative)
 Parse a decimal or a hexadecimal literal, which can be either an integer or a float attribute. More...
 
Attribute parseDenseElementsAttr (Type attrType)
 Parse a dense elements attribute. More...
 
ShapedType parseElementsLiteralType (Type type)
 Shaped type for elements attribute. More...
 
Attribute parseDenseResourceElementsAttr (Type attrType)
 Parse a dense resource elements attribute. More...
 
Attribute parseDenseArrayAttr (Type type)
 Parse a DenseArrayAttr. More...
 
Attribute parseSparseElementsAttr (Type attrType)
 Parse a sparse elements attribute. More...
 
Attribute parseStridedLayoutAttr ()
 Parse a strided layout attribute. More...
 
ParseResult parseLocationInstance (LocationAttr &loc)
 Parse a raw location instance. More...
 
ParseResult parseCallSiteLocation (LocationAttr &loc)
 Parse a callsite location instance. More...
 
ParseResult parseFusedLocation (LocationAttr &loc)
 Parse a fused location instance. More...
 
ParseResult parseNameOrFileLineColLocation (LocationAttr &loc)
 Parse a name or FileLineCol location instance. More...
 
ParseResult parseAffineMapOrIntegerSetReference (AffineMap &map, IntegerSet &set)
 Parse a reference to either an affine map, expr, or an integer set. More...
 
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. More...
 
ParseResult parseAffineExprOfSSAIds (AffineExpr &expr, function_ref< ParseResult(bool)> parseElement)
 Parse an AffineExpr where dim and symbol identifiers are SSA ids. More...
 
ParseResult codeCompleteDialectName ()
 The set of various code completion methods. More...
 
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. More...
 

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

Definition at line 29 of file Parser.h.

Constructor & Destructor Documentation

◆ Parser()

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

Definition at line 33 of file Parser.h.

Member Function Documentation

◆ codeCompleteAttribute()

Attribute Parser::codeCompleteAttribute ( )

◆ 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 461 of file Parser.cpp.

References mlir::detail::ParserState::codeCompleteContext, mlir::AsmParserCodeCompleteContext::completeDialectName(), and state.

Referenced by codeCompleteDialectOrElidedOpName(), and codeCompleteStringDialectOrOperationName().

◆ codeCompleteDialectOrElidedOpName()

ParseResult Parser::codeCompleteDialectOrElidedOpName ( SMLoc  loc)

◆ codeCompleteDialectSymbol() [1/2]

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

◆ codeCompleteDialectSymbol() [2/2]

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

◆ codeCompleteExpectedTokens()

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

◆ codeCompleteOperationName()

LogicalResult Parser::codeCompleteOperationName ( StringRef  dialectName)

◆ codeCompleteOptionalTokens()

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

◆ codeCompleteStringDialectOrOperationName()

ParseResult Parser::codeCompleteStringDialectOrOperationName ( StringRef  name)

Definition at line 499 of file Parser.cpp.

References codeCompleteDialectName(), and codeCompleteOperationName().

◆ codeCompleteType()

Type Parser::codeCompleteType ( )

◆ consumeIf()

bool mlir::detail::Parser::consumeIf ( Token::Kind  kind)
inline

If the current token has the specified kind, consume it and return true.

If not, return false.

Definition at line 111 of file Parser.h.

References consumeToken(), mlir::detail::ParserState::curToken, mlir::Token::isNot(), and state.

Referenced by parseAttribute(), parseAttributeDict(), parseCommaSeparatedList(), parseDecOrHexAttr(), parseDenseArrayAttr(), parseDenseElementsAttr(), parseDimensionListRanked(), mlir::detail::AsmParserImpl< BaseT >::parseFloat(), parseFloatAttr(), parseFusedLocation(), parseMemRefType(), parseNameOrFileLineColLocation(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalArrow(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalArrowTypeList(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalColon(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalColonTypeList(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalComma(), parseOptionalDecimalInteger(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalEllipsis(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalEqual(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalGreater(), parseOptionalInteger(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalLBrace(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalLess(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalLParen(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalLSquare(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalMinus(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalPlus(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalQuestion(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalRBrace(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalRParen(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalRSquare(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalStar(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalVerticalBar(), parseSparseElementsAttr(), parseStridedLayoutAttr(), parseTensorType(), parseToken(), parseTupleType(), and parseVectorDimensionList().

◆ consumeToken() [1/2]

void mlir::detail::Parser::consumeToken ( )
inline

◆ 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(), mlir::detail::ParserState::curToken, mlir::Token::is(), and state.

◆ emitError() [1/2]

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

◆ 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 mlir::detail::ParserState::curToken, emitError(), mlir::Lexer::getBufferBegin(), mlir::Token::getLoc(), mlir::Token::is(), mlir::detail::ParserState::lex, and state.

Referenced by parseAttribute(), parseAttributeDict(), parseCallSiteLocation(), parseCommaSeparatedListUntil(), parseExtendedSymbol(), parseLocationInstance(), parseNameOrFileLineColLocation(), 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 192 of file Parser.h.

References emitError().

◆ getContext()

MLIRContext* mlir::detail::Parser::getContext ( ) const
inline

◆ 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 mlir::Lexer::getEncodedSourceLocation(), mlir::detail::ParserState::lex, and state.

Referenced by emitError(), and mlir::detail::AsmParserImpl< BaseT >::getEncodedSourceLoc().

◆ getLastToken()

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

Return the last parsed token.

Definition at line 107 of file Parser.h.

References mlir::detail::ParserState::lastToken, and state.

◆ getSourceMgr()

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

Definition at line 39 of file Parser.h.

References mlir::Lexer::getSourceMgr(), mlir::detail::ParserState::lex, and state.

◆ getState()

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

◆ getToken()

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

Return the current token the parser is inspecting.

Definition at line 103 of file Parser.h.

References mlir::detail::ParserState::curToken, and state.

Referenced by mlir::detail::AsmParserImpl< BaseT >::codeCompleteExpectedTokens(), emitError(), mlir::detail::AsmParserImpl< BaseT >::getCurrentLocation(), isCurrentTokenAKeyword(), parseAffineMapReference(), parseAttribute(), parseAttributeDict(), mlir::detail::AsmParserImpl< BaseT >::parseBase64Bytes(), parseCallSiteLocation(), parseCommaSeparatedList(), parseCommaSeparatedListUntil(), parseComplexType(), mlir::detail::AsmParserImpl< BaseT >::parseCustomAttributeWithFallback(), mlir::detail::AsmParserImpl< BaseT >::parseCustomTypeWithFallback(), parseDecOrHexAttr(), parseDenseArrayAttr(), parseDenseElementsAttr(), parseDenseResourceElementsAttr(), parseDimensionListRanked(), parseDistinctAttr(), parseExtendedSymbol(), mlir::detail::AsmParserImpl< BaseT >::parseFloat(), parseFloatAttr(), parseFunctionResultTypes(), parseFunctionType(), parseIntegerInDimensionList(), parseIntegerSetReference(), mlir::detail::AsmParserImpl< BaseT >::parseKeyword(), mlir::detail::AsmParserImpl< BaseT >::parseKeywordOrCompletion(), parseLocationInstance(), parseMemRefType(), parseNameOrFileLineColLocation(), parseNonFunctionType(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalAttrDict(), parseOptionalAttribute(), parseOptionalDecimalInteger(), parseOptionalInteger(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalKeyword(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalString(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalSymbolName(), parseOptionalType(), parseResourceHandle(), parseSparseElementsAttr(), parseStridedLayoutAttr(), parseTensorType(), parseType(), parseTypeListParens(), parseVectorDimensionList(), parseVectorType(), and parseXInDimensionList().

◆ 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 166 of file Parser.h.

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

Referenced by parseOptionalKeyword(), and mlir::detail::AsmParserImpl< BaseT >::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 state.

◆ parseAffineExprReference()

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

Definition at line 729 of file AffineParser.cpp.

References state.

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseAffineExpr().

◆ 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 state.

◆ 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 state.

Referenced by 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 52 of file AttributeParser.cpp.

References mlir::AsmParserState::addUses(), mlir::detail::ParserState::asmState, builder, codeCompleteAttribute(), consumeIf(), consumeToken(), emitError(), emitWrongTokenError(), mlir::get(), mlir::Builder::getArrayAttr(), mlir::Builder::getBoolAttr(), getContext(), mlir::NamedAttrList::getDictionary(), mlir::Token::getLoc(), mlir::Token::getStringValue(), mlir::Token::getSymbolReference(), getToken(), mlir::Builder::getUnitAttr(), mlir::OptionalParseResult::has_value(), mlir::detail::ParserState::lex, parseAffineMapReference(), parseAttributeDict(), parseCommaSeparatedListUntil(), parseDecOrHexAttr(), parseDenseArrayAttr(), parseDenseElementsAttr(), parseDenseResourceElementsAttr(), parseDistinctAttr(), parseExtendedAttr(), parseFloatAttr(), parseIntegerSetReference(), parseLocationInstance(), parseOptionalType(), parseSparseElementsAttr(), parseStridedLayoutAttr(), parseToken(), parseType(), mlir::Lexer::resetPointer(), and state.

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseAttribute(), parseAttributeDict(), mlir::detail::AsmParserImpl< BaseT >::parseCustomAttributeWithFallback(), parseDistinctAttr(), parseFusedLocation(), parseMemRefType(), and parseOptionalAttribute().

◆ parseAttributeDict()

ParseResult Parser::parseAttributeDict ( NamedAttrList attributes)

◆ 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 34 of file LocationParser.cpp.

References consumeToken(), emitWrongTokenError(), mlir::get(), getToken(), parseLocationInstance(), and parseToken().

Referenced by parseLocationInstance().

◆ parseCommaSeparatedList() [1/2]

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

◆ 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 mlir::AsmParser::None, and 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(), and parseToken().

Referenced by parseAttribute(), and parseMemRefType().

◆ parseComplexType()

Type Parser::parseComplexType ( )

Parse a complex type.

complex-type ::= complex < type >

Definition at line 135 of file TypeParser.cpp.

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

Referenced by parseNonFunctionType().

◆ parseDecOrHexAttr()

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

◆ parseDenseArrayAttr()

Attribute Parser::parseDenseArrayAttr ( Type  type)

◆ parseDenseElementsAttr()

Attribute Parser::parseDenseElementsAttr ( Type  attrType)

Parse a dense elements attribute.

Definition at line 940 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 964 of file AttributeParser.cpp.

References consumeToken(), emitError(), mlir::get(), 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 mlir::detail::ParserState::curToken, emitError(), mlir::Lexer::getCodeCompleteLoc(), mlir::Token::getEndLoc(), getTokenSpelling(), mlir::Token::isCodeCompletion(), mlir::Token::isNot(), mlir::detail::ParserState::lex, resetToken(), and state.

Referenced by 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 543 of file TypeParser.cpp.

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

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseDimensionList(), parseMemRefType(), and parseTensorType().

◆ parseDistinctAttr()

Attribute Parser::parseDistinctAttr ( Type  type)

◆ parseElementsLiteralType()

ShapedType Parser::parseElementsLiteralType ( 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 1002 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 252 of file DialectSymbolParser.cpp.

References mlir::detail::ParserState::asmState, mlir::detail::SymbolState::attributeAliasDefinitions, mlir::get(), getContext(), state, and mlir::detail::ParserState::symbols.

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 299 of file DialectSymbolParser.cpp.

References getContext().

Referenced by parseNonFunctionType().

◆ parseFloatAttr()

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

◆ 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 374 of file Parser.cpp.

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

Referenced by parseDecOrHexAttr(), and parseFloatFromLiteral().

◆ parseFloatFromLiteral()

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

◆ parseFunctionResultTypes()

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

Parse a function result type.

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

Definition at line 86 of file TypeParser.cpp.

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

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseArrowTypeList(), parseFunctionType(), and mlir::detail::AsmParserImpl< BaseT >::parseOptionalArrowTypeList().

◆ parseFunctionType()

Type Parser::parseFunctionType ( )

Parse a function type.

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

Definition at line 158 of file TypeParser.cpp.

References builder, mlir::Builder::getFunctionType(), getToken(), parseFunctionResultTypes(), parseToken(), and parseTypeListParens().

Referenced by parseType().

◆ parseFusedLocation()

ParseResult Parser::parseFusedLocation ( LocationAttr loc)

◆ parseIntegerInDimensionList()

ParseResult Parser::parseIntegerInDimensionList ( int64_t &  value)

◆ parseIntegerSetReference()

ParseResult Parser::parseIntegerSetReference ( IntegerSet set)

◆ parseLocationInstance()

ParseResult Parser::parseLocationInstance ( LocationAttr loc)

◆ 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 184 of file TypeParser.cpp.

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

Referenced by parseNonFunctionType().

◆ parseNameOrFileLineColLocation()

ParseResult Parser::parseNameOrFileLineColLocation ( LocationAttr loc)

◆ parseNonFunctionType()

Type Parser::parseNonFunctionType ( )

◆ parseOptionalAttribute() [1/4]

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

Definition at line 280 of file AttributeParser.cpp.

References parseOptionalAttributeWithToken().

◆ parseOptionalAttribute() [2/4]

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

Parse an optional attribute with the provided type.

Definition at line 248 of file AttributeParser.cpp.

References mlir::get(), getToken(), mlir::OptionalParseResult::has_value(), parseAttribute(), and parseOptionalType().

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseOptionalAttribute(), and parseTensorType().

◆ parseOptionalAttribute() [3/4]

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

Definition at line 284 of file AttributeParser.cpp.

References parseOptionalAttributeWithToken().

◆ parseOptionalAttribute() [4/4]

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

Definition at line 288 of file AttributeParser.cpp.

References parseOptionalAttributeWithToken().

◆ 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 254 of file Parser.h.

Referenced by parseOptionalAttribute().

◆ parseOptionalDecimalInteger()

OptionalParseResult Parser::parseOptionalDecimalInteger ( APInt &  result)

◆ parseOptionalInteger()

OptionalParseResult Parser::parseOptionalInteger ( APInt &  result)

Parse an optional integer value from the stream.

Definition at line 275 of file Parser.cpp.

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

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseOptionalInteger().

◆ parseOptionalKeyword()

ParseResult Parser::parseOptionalKeyword ( StringRef *  keyword)

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

Definition at line 405 of file Parser.cpp.

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

Referenced by parseResourceHandle().

◆ parseOptionalType()

OptionalParseResult Parser::parseOptionalType ( Type type)

Optionally parse a type.

Definition at line 32 of file TypeParser.cpp.

References getToken(), and parseType().

Referenced by parseAttribute(), parseOptionalAttribute(), and mlir::detail::AsmParserImpl< BaseT >::parseOptionalType().

◆ parseResourceHandle() [1/2]

FailureOr< AsmDialectResourceHandle > Parser::parseResourceHandle ( const OpAsmDialectInterface dialect,
StringRef &  name 
)

◆ parseResourceHandle() [2/2]

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

Definition at line 448 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 1024 of file AttributeParser.cpp.

References builder, consumeIf(), consumeToken(), mlir::get(), mlir::DenseElementsAttr::get(), mlir::Builder::getIntegerType(), mlir::Token::getLoc(), getToken(), 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 392 of file TypeParser.cpp.

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

Referenced by parseNonFunctionType().

◆ parseToken()

ParseResult Parser::parseToken ( Token::Kind  expectedToken,
const Twine &  message 
)

Consume the specified token if present and return success.

On failure, output a diagnostic and return failure.

Definition at line 267 of file Parser.cpp.

References consumeIf(), and emitWrongTokenError().

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseArrow(), parseAttribute(), parseCallSiteLocation(), mlir::detail::AsmParserImpl< BaseT >::parseColon(), mlir::detail::AsmParserImpl< BaseT >::parseColonType(), mlir::detail::AsmParserImpl< BaseT >::parseColonTypeList(), mlir::detail::AsmParserImpl< BaseT >::parseComma(), parseCommaSeparatedList(), parseCommaSeparatedListUntil(), parseComplexType(), parseDenseArrayAttr(), parseDenseElementsAttr(), parseDenseResourceElementsAttr(), parseDistinctAttr(), parseElementsLiteralType(), mlir::detail::AsmParserImpl< BaseT >::parseEllipsis(), mlir::detail::AsmParserImpl< BaseT >::parseEqual(), parseFunctionType(), parseFusedLocation(), mlir::detail::AsmParserImpl< BaseT >::parseGreater(), mlir::detail::AsmParserImpl< BaseT >::parseLBrace(), mlir::detail::AsmParserImpl< BaseT >::parseLess(), mlir::detail::AsmParserImpl< BaseT >::parseLParen(), mlir::detail::AsmParserImpl< BaseT >::parseLSquare(), parseMemRefType(), mlir::detail::AsmParserImpl< BaseT >::parseMinus(), parseNameOrFileLineColLocation(), parseOptionalDecimalInteger(), parseOptionalInteger(), mlir::detail::AsmParserImpl< BaseT >::parsePlus(), mlir::detail::AsmParserImpl< BaseT >::parseQuestion(), mlir::detail::AsmParserImpl< BaseT >::parseRBrace(), mlir::detail::AsmParserImpl< BaseT >::parseRParen(), mlir::detail::AsmParserImpl< BaseT >::parseRSquare(), parseSparseElementsAttr(), mlir::detail::AsmParserImpl< BaseT >::parseStar(), parseStridedLayoutAttr(), parseTensorType(), parseTupleType(), parseTypeListParens(), parseVectorType(), and mlir::detail::AsmParserImpl< BaseT >::parseVerticalBar().

◆ parseTupleType()

Type Parser::parseTupleType ( )

Parse a tuple type.

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

Definition at line 450 of file TypeParser.cpp.

References consumeIf(), consumeToken(), mlir::get(), getContext(), parseToken(), and parseTypeListNoParens().

Referenced by parseNonFunctionType().

◆ parseType()

Type Parser::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 102 of file TypeParser.cpp.

References parseCommaSeparatedList(), and parseType().

Referenced by mlir::detail::AsmParserImpl< BaseT >::parseColonTypeList(), mlir::detail::AsmParserImpl< BaseT >::parseOptionalColonTypeList(), 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 117 of file TypeParser.cpp.

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

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 507 of file TypeParser.cpp.

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

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 476 of file TypeParser.cpp.

References consumeToken(), 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 608 of file TypeParser.cpp.

References consumeToken(), emitWrongTokenError(), getToken(), getTokenSpelling(), mlir::detail::ParserState::lex, mlir::Lexer::resetPointer(), and state.

Referenced by parseDimensionListRanked(), parseMemRefType(), parseTensorType(), parseVectorDimensionList(), and mlir::detail::AsmParserImpl< BaseT >::parseXInDimensionList().

◆ 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 mlir::detail::ParserState::curToken, mlir::detail::ParserState::lex, mlir::Lexer::lexToken(), mlir::Lexer::resetPointer(), and state.

Referenced by parseDialectSymbolBody().

Member Data Documentation

◆ builder

Builder mlir::detail::Parser::builder

◆ state

ParserState& mlir::detail::Parser::state
protected

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