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;
95 return state.lex.getEncodedSourceLocation(loc);
112 if (
state.curToken.isNot(kind))
120 assert(
state.curToken.isNot(Token::eof, Token::error) &&
121 "shouldn't advance past EOF or errors");
130 assert(
state.curToken.is(kind) &&
"consumed an unexpected token");
141 state.lex.resetPointer(tokPos);
160 const Token &tok,
bool isNegative,
161 const llvm::fltSemantics &semantics);
165 const Token &tok,
bool isNegative,
166 const llvm::fltSemantics &semantics);
170 return getToken().
isAny(Token::bare_identifier, Token::inttype) ||
185 FailureOr<AsmDialectResourceHandle>
197 template <
typename T,
typename... ParamsT>
199 return T::getChecked([&] {
return emitError(loc); },
200 std::forward<ParamsT>(params)...);
239 bool allowDynamic =
true,
240 bool withTrailingX =
true);
259 template <
typename AttributeT>
267 attr = cast<AttributeT>(parsedAttr);
Delimiter
These are the supported delimiters around operand lists and region argument lists,...
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.
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.
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
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
ParseResult parseFloatFromLiteral(std::optional< APFloat > &result, const Token &tok, bool isNegative, const llvm::fltSemantics &semantics)
Parse a floating point value from a literal.
ParseResult parseOptionalKeywordOrString(std::string *result)
Parse an optional keyword or string and set instance into 'result'.`.
ParseResult parseOptionalKeyword(StringRef *keyword)
Parse a keyword, if present, into 'keyword'.
Attribute parseDenseArrayAttr(Type type)
Parse a DenseArrayAttr.
const Token & getLastToken() const
Return the last parsed token.
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.
const llvm::SourceMgr & getSourceMgr()
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.
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. Every completion method returns failure to signal that pa...
Attribute parseAttribute(Type type={})
Parse an arbitrary attribute with an optional type.
StringRef getTokenSpelling() const
ParserState & getState() const
FailureOr< AsmDialectResourceHandle > parseResourceHandle(const OpAsmDialectInterface *dialect, std::string &name)
Parse a handle to a dialect resource within the assembly format.
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.
ParseResult parseOptionalString(std::string *string)
Parses a quoted string token if present.
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)
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.
ParseResult parseNameOrFileLineColRange(LocationAttr &loc)
Parse a name or FileLineCol location instance.
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 parseAffineExprReference(ArrayRef< std::pair< StringRef, AffineExpr > > symbolSet, AffineExpr &expr)
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.
const Token & getToken() const
Return the current token the parser is inspecting.
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.
MLIRContext * getContext() const
ParseResult parseCommaSeparatedList(function_ref< ParseResult()> parseElementFn)
Parse a comma separated list of elements that must have at least one entry in it.
ShapedType parseElementsLiteralType(SMLoc loc, Type type)
Shaped type for elements attribute.
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.
const FrozenRewritePatternSet GreedyRewriteConfig config
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...