9 #ifndef MLIR_LIB_ASMPARSER_ASMPARSERIMPL_H
10 #define MLIR_LIB_ASMPARSER_ASMPARSERIMPL_H
16 #include "llvm/Support/Base64.h"
27 template <
typename BaseT>
264 return emitError(loc,
"expected string");
272 StringRef b64String =
273 b64QuotedString.ltrim(
"\" \t\n\v\f\r").rtrim(
"\" \t\n\v\f\r");
274 if (
auto err = llvm::decodeBase64(b64String, *bytes))
287 APFloat &result)
override {
290 std::optional<APFloat> apResult;
301 llvm::APFloat apResult(0.0);
302 if (
parseFloat(APFloat::IEEEdouble(), apResult))
305 result = apResult.convertToDouble();
324 StringRef contextMessage)
override {
332 ParseResult
parseKeyword(StringRef keyword,
const Twine &msg)
override {
338 return emitError(loc,
"expected '") << keyword <<
"'" << msg;
379 if (llvm::is_contained(allowedKeywords, currentKeyword)) {
380 *keyword = currentKeyword;
392 *result = keyword.str();
406 return success(
static_cast<bool>(result));
418 return success(
static_cast<bool>(result));
429 return success(
static_cast<bool>(result));
433 Type type)
override {
437 Type type)
override {
441 Type type)
override {
445 Type type)
override {
490 if (atToken.
isNot(Token::at_identifier))
510 FailureOr<AsmDialectResourceHandle>
515 <<
"' does not expect resource handles";
517 StringRef resourceName;
574 bool withTrailingX)
override {
Base type for affine expression.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
void addUses(Value value, ArrayRef< SMLoc > locations)
Add a source uses of the given value.
Delimiter
These are the supported delimiters around operand lists and region argument lists,...
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
Attributes are known-constant values of operations.
This class is a general helper class for creating context-global objects like types,...
StringAttr getStringAttr(const Twine &bytes)
Dialects are groups of MLIR operations, types and attributes, as well as behavior associated with the...
StringRef getNamespace() const
This class represents a diagnostic that is inflight and set to be reported.
An integer set representing a conjunction of one or more affine equalities and inequalities.
This class defines the main interface for locations in MLIR and acts as a non-nullable wrapper around...
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
This class implements Optional functionality for ParseResult.
This represents a token in the MLIR syntax.
SMRange getLocRange() const
std::string getStringValue() const
Given a token containing a string literal, return its value, including removing the quote characters ...
std::string getSymbolReference() const
Given a token containing a symbol reference, return the unescaped string value.
bool isCodeCompletion() const
Returns true if the current token represents a code completion.
StringRef getSpelling() const
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
This class provides the implementation of the generic parser methods within AsmParser.
ParseResult parseOptionalPlus() override
Parses a '+' token if present.
ParseResult parseOptionalLBrace() override
Parse a '{' token if present.
ParseResult parseOptionalArrowTypeList(SmallVectorImpl< Type > &result) override
Parse an optional arrow followed by a type list.
ParseResult parseOptionalStar() override
Parses a '*' if present.
ParseResult parseOptionalMinus() override
Parses a '-' token if present.
ParseResult parseColon() override
Parse a : token.
ParseResult parseFloat(double &result) override
Parse a floating point value from the stream.
InFlightDiagnostic emitError(SMLoc loc, const Twine &message) override
Emit a diagnostic at the specified location and return failure.
ParseResult parseMinus() override
Parses a '-' token.
ParseResult parseOptionalGreater() override
Parse a > token if present.
ParseResult parseOptionalEllipsis() override
Parses a ... if present.
ParseResult parseColonType(Type &result) override
Parse a colon followed by a type.
ParseResult parseArrow() override
Parse a -> token.
void codeCompleteExpectedTokens(ArrayRef< StringRef > tokens) override
Signal the code completion of a set of expected tokens.
ParseResult parseEllipsis() override
Parses a ....
ParseResult parseLParen() override
Parse a ( token.
ParseResult parseOptionalKeywordOrString(std::string *result) override
Parse an optional keyword or string and set instance into 'result'.`.
Location getEncodedSourceLoc(SMLoc loc) override
Re-encode the given source location as an MLIR location and return it.
ParseResult parseOptionalAttrDict(NamedAttrList &result) override
Parse a named dictionary into 'result' if it is present.
SMLoc nameLoc
The source location of the dialect symbol.
ParseResult parseRParen() override
Parse a ) token.
ParseResult parseQuestion() override
Parses a '?' token.
OptionalParseResult parseOptionalAttribute(ArrayAttr &result, Type type) override
ParseResult parseCustomAttributeWithFallback(Attribute &result, Type type, function_ref< ParseResult(Attribute &result, Type type)> parseAttribute) override
Parse a custom attribute with the provided callback, unless the next token is #, in which case the ge...
OptionalParseResult parseOptionalType(Type &result) override
Parse an optional type.
ParseResult parseIntegerSet(IntegerSet &set) override
Parse an integer set instance into 'set'.
ParseResult parseFloat(const llvm::fltSemantics &semantics, APFloat &result) override
Parse a floating point value with given semantics from the stream.
SMLoc getNameLoc() const override
Return the location of the original name token.
ParseResult parseOptionalQuestion() override
Parses a '?' if present.
ParseResult parseLBrace() override
Parse a '{' token.
ParseResult parseAffineExpr(ArrayRef< std::pair< StringRef, AffineExpr >> symbolSet, AffineExpr &expr) override
Parse an affine expr instance into 'expr' using the already computed mapping from symbols to affine e...
ParseResult parseOptionalComma() override
Parse a , token if present.
ParseResult parsePlus() override
Parses a '+' token.
ParseResult parseLess() override
Parse a '<' token.
ParseResult parseOptionalKeyword(StringRef *keyword, ArrayRef< StringRef > allowedKeywords) override
Parse a keyword if it is one of the 'allowedKeywords'.
OptionalParseResult parseOptionalDecimalInteger(APInt &result) override
Parse an optional integer value from the stream.
ParseResult parseRBrace() override
Parse a } token.
ParseResult parseOptionalRBrace() override
Parse a } token if present.
ParseResult parseGreater() override
Parse a '>' token.
FailureOr< AsmDialectResourceHandle > parseResourceHandle(Dialect *dialect) override
Parse a handle to a resource within the assembly format.
ParseResult parseColonTypeList(SmallVectorImpl< Type > &result) override
Parse a colon followed by a type list, which must have at least one type.
ParseResult parseOptionalLess() override
Parse a < token if present.
OptionalParseResult parseOptionalAttribute(StringAttr &result, Type type) override
OptionalParseResult parseOptionalAttribute(Attribute &result, Type type) override
ParseResult parseAttribute(Attribute &result, Type type) override
Parse an arbitrary attribute and return it in result.
Parser & parser
The main parser.
LogicalResult pushCyclicParsing(const void *opaquePointer) override
ParseResult parseKeywordOrCompletion(StringRef *keyword) override
Parse a keyword, or an empty string if the current location signals a code completion.
AsmParserImpl(SMLoc nameLoc, Parser &parser)
ParseResult parseOptionalKeyword(StringRef keyword) override
Parse the given keyword if present.
bool didEmitError() const
Return if any errors were emitted during parsing.
ParseResult parseComma() override
Parse a , token.
OptionalParseResult parseOptionalInteger(APInt &result) override
Parse an optional integer value from the stream.
ParseResult parseRSquare() override
Parse a ] token.
Builder & getBuilder() const override
Return a builder which provides useful access to MLIRContext, global objects like types and attribute...
ParseResult parseLSquare() override
Parse a [ token.
ParseResult parseBase64Bytes(std::vector< char > *bytes) override
Parses a Base64 encoded string of bytes.
ParseResult parseOptionalArrow() override
Parses a -> if present.
~AsmParserImpl() override=default
ParseResult parseDimensionList(SmallVectorImpl< int64_t > &dimensions, bool allowDynamic, bool withTrailingX) override
ParseResult parseEqual() override
Parse a = token.
ParseResult parseCustomTypeWithFallback(Type &result, function_ref< ParseResult(Type &result)> parseType) override
Parse a custom attribute with the provided callback, unless the next token is #, in which case the ge...
ParseResult parseOptionalColonTypeList(SmallVectorImpl< Type > &result) override
Parse an optional colon followed by a type list, which if present must have at least one type.
ParseResult parseOptionalVerticalBar() override
Parse a '|' token if present.
ParseResult parseOptionalAttrDictWithKeyword(NamedAttrList &result) override
Parse a named dictionary into 'result' if the attributes keyword is present.
ParseResult parseStar() override
Parses a '*' token.
ParseResult parseOptionalLParen() override
Parses a '(' if present.
ParseResult parseOptionalEqual() override
Parse a = token if present.
void popCyclicParsing() override
ParseResult parseOptionalLSquare() override
Parses a '[' if present.
ParseResult parseOptionalKeyword(StringRef *keyword) override
Parse a keyword, if present, into 'keyword'.
ParseResult parseAffineMap(AffineMap &map) override
Parse an affine map instance into 'map'.
ParseResult parseOptionalSymbolName(StringAttr &result) override
Parse an optional -identifier and store it (without the '@' symbol) in a string attribute named 'attr...
ParseResult parseVerticalBar() override
Parse a '|' token.
OptionalParseResult parseOptionalAttribute(SymbolRefAttr &result, Type type) override
SMLoc getCurrentLocation() override
Get the location of the next token and store it into the argument.
bool emittedError
A flag that indicates if any errors were emitted during parsing.
ParseResult parseKeyword(StringRef keyword)
Parse a given keyword.
ParseResult parseOptionalColon() override
Parse a : token if present.
ParseResult parseOptionalString(std::string *string) override
Parses a quoted string token if present.
ParseResult parseOptionalRParen() override
Parses a ')' if present.
ParseResult parseXInDimensionList() override
ParseResult parseKeyword(StringRef keyword, const Twine &msg) override
ParseResult parseType(Type &result) override
Parse a type.
ParseResult parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElt, StringRef contextMessage) override
Parse a list of comma-separated items with an optional delimiter.
ParseResult parseOptionalRSquare() override
Parses a ']' if present.
ParseResult parseArrowTypeList(SmallVectorImpl< Type > &result) override
Parse an arrow followed by a type list.
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 parseXInDimensionList()
Parse an 'x' token in a dimension list, handling the case where the x is juxtaposed with an element t...
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.
OptionalParseResult parseOptionalDecimalInteger(APInt &result)
Parse an optional integer value only in decimal format from the stream.
Type parseType()
Parse an arbitrary type.
ParserState & getState() const
ParseResult parseAffineMapReference(AffineMap &map)
Location getEncodedSourceLocation(SMLoc loc)
Encode the specified source location information into an attribute for attachment to the IR.
InFlightDiagnostic emitError(const Twine &message={})
Emit an error and return failure.
ParseResult parseAffineExprReference(ArrayRef< std::pair< StringRef, AffineExpr >> symbolSet, AffineExpr &expr)
Attribute parseAttribute(Type type={})
Parse an arbitrary attribute with an optional type.
StringRef getTokenSpelling() const
void consumeToken()
Advance the current lexer onto the next token.
ParseResult codeCompleteExpectedTokens(ArrayRef< StringRef > tokens)
ParseResult parseAttributeDict(NamedAttrList &attributes)
Parse an attribute dictionary.
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 parseCommaSeparatedList(Delimiter delimiter, function_ref< ParseResult()> parseElementFn, StringRef contextMessage=StringRef())
Parse a list of comma-separated items with an optional delimiter.
OptionalParseResult parseOptionalInteger(APInt &result)
Parse an optional integer value from the stream.
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 codeCompleteOptionalTokens(ArrayRef< StringRef > tokens)
ParseResult parseIntegerSetReference(IntegerSet &set)
ParseResult parseTypeListNoParens(SmallVectorImpl< Type > &elements)
Parse a list of types without an enclosing parenthesis.
const Token & getToken() const
Return the current token the parser is inspecting.
FailureOr< AsmDialectResourceHandle > parseResourceHandle(const OpAsmDialectInterface *dialect, StringRef &name)
Parse a handle to a dialect resource within the assembly format.
bool consumeIf(Token::Kind kind)
If the current token has the specified kind, consume it and return true.
Include the generated interface declarations.
StringRef toString(AsmResourceEntryKind kind)
auto get(MLIRContext *context, Ts &&...params)
Helper method that injects context only if needed, this helps unify some of the attribute constructio...
SetVector< const void * > cyclicParsingStack
Stack of potentially cyclic mutable attributes or type currently being parsed.
AsmParserState * asmState
An optional pointer to a struct containing high level parser state to be populated during parsing.