9 #ifndef MLIR_LIB_ASMPARSER_PARSER_H
10 #define MLIR_LIB_ASMPARSER_PARSER_H
45 bool allowEmptyList =
true);
53 StringRef contextMessage = StringRef());
69 bool isCodeCompletion =
false;
121 "shouldn't advance past EOF or errors");
157 const Token &tok,
bool isNegative,
158 const llvm::fltSemantics &semantics);
162 const Token &tok,
bool isNegative,
163 const llvm::fltSemantics &semantics);
167 return getToken().
isAny(Token::bare_identifier, Token::inttype) ||
179 FailureOr<AsmDialectResourceHandle>
191 template <
typename T,
typename... ParamsT>
193 return T::getChecked([&] {
return emitError(loc); },
194 std::forward<ParamsT>(params)...);
233 bool allowDynamic =
true,
234 bool withTrailingX =
true);
253 template <
typename AttributeT>
261 attr = cast<AttributeT>(parsedAttr);
Delimiter
These are the supported delimiters around operand lists and region argument lists,...
@ None
Zero or more operands with no delimiters.
Attributes are known-constant values of operations.
This class is a general helper class for creating context-global objects like types,...
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
This class represents a diagnostic that is inflight and set to be reported.
const llvm::SourceMgr & getSourceMgr()
Location getEncodedSourceLocation(SMLoc loc)
Encode the specified source location information into a Location object for attachment to the IR or e...
void resetPointer(const char *newPointer)
Change the position of the lexer cursor.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
MLIRContext is the top-level object for a collection of MLIR operations.
This class implements Optional functionality for ParseResult.
MLIRContext * getContext() const
Return the MLIRContext to be used when parsing.
This represents a token in the MLIR syntax.
bool isKeyword() const
Return true if this is one of the keyword token kinds (e.g. kw_if).
bool isAny(Kind k1, Kind k2) const
StringRef getSpelling() const
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class implement support for parsing global entities like attributes and types.
ParseResult parseFloatFromLiteral(std::optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics)
Parse a floating point value from a literal.
ParseResult parseOptionalKeyword(StringRef *keyword)
Parse a keyword, if present, into 'keyword'.
const Token & getLastToken() const
Return the last parsed token.
Attribute parseDenseArrayAttr(Type type)
Parse a DenseArrayAttr.
Attribute parseStridedLayoutAttr()
Parse a strided layout attribute.
Attribute parseDecOrHexAttr(Type type, bool isNegative)
Parse a decimal or a hexadecimal literal, which can be either an integer or a float attribute.
OpAsmParser::Delimiter Delimiter
ParseResult parseXInDimensionList()
Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element t...
T getChecked(SMLoc loc, ParamsT &&...params)
Invoke the getChecked method of the given Attribute or Type class, using the provided location to emi...
OptionalParseResult parseOptionalType(Type &type)
Optionally parse a type.
ParseResult parseToken(Token::Kind expectedToken, const Twine &message)
Consume the specified token if present and return success.
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 codeCompleteOperationName(StringRef dialectName)
OptionalParseResult parseOptionalDecimalInteger(APInt &result)
Parse an optional integer value only in decimal format from the stream.
Type parseType()
Parse an arbitrary type.
Attribute parseDenseElementsAttr(Type attrType)
Parse a dense elements attribute.
void consumeToken(Token::Kind kind)
Advance the current lexer onto the next token, asserting what the expected current token is.
ParseResult parseTypeListParens(SmallVectorImpl< Type > &elements)
Parse a parenthesized list of types.
ParserState & getState() const
Attribute parseDenseResourceElementsAttr(Type attrType)
Parse a dense resource elements attribute.
ParseResult parseVectorDimensionList(SmallVectorImpl< int64_t > &dimensions, SmallVectorImpl< bool > &scalableDims)
Parse a dimension list in a vector type.
Type parseMemRefType()
Parse a memref type.
Type parseNonFunctionType()
Parse a non function type.
Parser(ParserState &state)
ParseResult parseAffineMapReference(AffineMap &map)
Location getEncodedSourceLocation(SMLoc loc)
Encode the specified source location information into an attribute for attachment to the IR.
Type parseExtendedType()
Parse an extended type.
Type parseTupleType()
Parse a tuple type.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error and return failure.
ParserState & state
The Parser is subclassed and reinstantiated.
ParseResult codeCompleteDialectName()
The set of various code completion methods.
ParseResult parseAffineExprReference(ArrayRef< std::pair< StringRef, AffineExpr >> symbolSet, AffineExpr &expr)
Attribute parseAttribute(Type type={})
Parse an arbitrary attribute with an optional type.
const llvm::SourceMgr & getSourceMgr()
StringRef getTokenSpelling() const
ParseResult parseLocationInstance(LocationAttr &loc)
Parse a raw location instance.
void consumeToken()
Advance the current lexer onto the next token.
ParseResult codeCompleteExpectedTokens(ArrayRef< StringRef > tokens)
Attribute codeCompleteAttribute()
ParseResult parseIntegerInDimensionList(int64_t &value)
ParseResult parseAttributeDict(NamedAttrList &attributes)
Parse an attribute dictionary.
ParseResult parseDialectSymbolBody(StringRef &body, bool &isCodeCompletion)
Parse the body of a dialect symbol, which starts and ends with <>'s, and may be recursive.
ShapedType parseElementsLiteralType(Type type)
Shaped type for elements attribute.
Type parseComplexType()
Parse a complex type.
ParseResult parseDimensionListRanked(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic=true, bool withTrailingX=true)
Parse a dimension list of a tensor or memref type.
ParseResult parseFunctionResultTypes(SmallVectorImpl< Type > &elements)
Parse a function result type.
ParseResult codeCompleteDialectOrElidedOpName(SMLoc loc)
ParseResult parseDialectSymbolBody(StringRef &body)
MLIRContext * getContext() const
Attribute parseDistinctAttr(Type type)
Parse a distinct attribute.
InFlightDiagnostic emitWrongTokenError(const Twine &message={})
Emit an error about a "wrong token".
ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())
Parse a list of comma-separated items with an optional delimiter.
VectorType parseVectorType()
Parse a vector type.
OptionalParseResult parseOptionalInteger(APInt &result)
Parse an optional integer value from the stream.
ParseResult parseFusedLocation(LocationAttr &loc)
Parse a fused location instance.
Type parseFunctionType()
Parse a function type.
Attribute parseSparseElementsAttr(Type attrType)
Parse a sparse elements attribute.
ParseResult parseAffineMapOrIntegerSetReference(AffineMap &map, IntegerSet &set)
Parse a reference to either an affine map, expr, or an integer set.
OptionalParseResult parseOptionalAttribute(Attribute &attribute, Type type={})
Parse an optional attribute with the provided type.
bool isCurrentTokenAKeyword() const
Returns true if the current token corresponds to a keyword.
ParseResult codeCompleteStringDialectOrOperationName(StringRef name)
ParseResult codeCompleteOptionalTokens(ArrayRef< StringRef > tokens)
ParseResult parseAffineMapOfSSAIds(AffineMap &map, function_ref< ParseResult(bool)> parseElement, Delimiter delimiter)
Parse an AffineMap where the dim and symbol identifiers are SSA ids.
Attribute parseFloatAttr(Type type, bool isNegative)
Parse a float attribute.
ParseResult parseCallSiteLocation(LocationAttr &loc)
Parse a callsite location instance.
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.
ParseResult parseIntegerSetReference(IntegerSet &set)
ParseResult parseNameOrFileLineColLocation(LocationAttr &loc)
Parse a name or FileLineCol location instance.
ParseResult parseTypeListNoParens(SmallVectorImpl< Type > &elements)
Parse a list of types without an enclosing parenthesis.
void resetToken(const char *tokPos)
Reset the parser to the given lexer position.
ParseResult parseAffineExprOfSSAIds(AffineExpr &expr, function_ref< ParseResult(bool)> parseElement)
Parse an AffineExpr where dim and symbol identifiers are SSA ids.
Attribute parseExtendedAttr(Type type)
Parse an extended attribute.
const Token & getToken() const
Return the current token the parser is inspecting.
ParseResult parseCommaSeparatedList(function_ref< ParseResult()> parseElementFn)
Parse a comma separated list of elements that must have at least one entry in it.
FailureOr< AsmDialectResourceHandle > parseResourceHandle(const OpAsmDialectInterface *dialect, StringRef &name)
Parse a handle to a dialect resource within the assembly format.
Type parseTensorType()
Parse a tensor type.
bool consumeIf(Token::Kind kind)
If the current token has the specified kind, consume it and return true.
OptionalParseResult parseOptionalAttributeWithToken(Token::Kind kind, AttributeT &attr, Type type={})
Parse an optional attribute that is demarcated by a specific token.
Attribute codeCompleteDialectSymbol(const llvm::StringMap< Attribute > &aliases)
Include the generated interface declarations.
llvm::function_ref< Fn > function_ref
This class refers to all of the state maintained globally by the parser, such as the current lexer po...
const ParserConfig & config
The configuration used to setup the parser.
Lexer lex
The lexer for the source file we're parsing.
Token curToken
This is the next token that hasn't been consumed yet.
Token lastToken
This is the last token that has been consumed.