51 case Token::kw_affine_map: {
55 if (
parseToken(Token::less,
"expected '<' in affine map") ||
57 parseToken(Token::greater,
"expected '>' in affine map"))
59 return AffineMapAttr::get(map);
61 case Token::kw_affine_set: {
65 if (
parseToken(Token::less,
"expected '<' in integer set") ||
67 parseToken(Token::greater,
"expected '>' in integer set"))
69 return IntegerSetAttr::get(set);
73 case Token::l_square: {
76 auto parseElt = [&]() -> ParseResult {
78 return elements.back() ?
success() : failure();
83 return builder.getArrayAttr(elements);
89 return builder.getBoolAttr(
false);
92 return builder.getBoolAttr(
true);
99 case Token::kw_dense_resource:
103 case Token::kw_array:
107 case Token::l_brace: {
115 case Token::hash_identifier:
119 case Token::floatliteral:
127 if (
getToken().is(Token::floatliteral))
131 "expected constant integer or floating point value"),
136 case Token::kw_loc: {
140 if (
parseToken(Token::l_paren,
"expected '(' in inline location") ||
142 parseToken(Token::r_paren,
"expected ')' in inline location"))
148 case Token::kw_sparse:
152 case Token::kw_strided:
156 case Token::kw_distinct:
160 case Token::string: {
167 return type ? StringAttr::get(val, type)
172 case Token::at_identifier: {
177 referenceLocations.push_back(
getToken().getLocRange());
184 std::vector<FlatSymbolRefAttr> nestedRefs;
185 while (
getToken().is(Token::colon)) {
190 if (
getToken().isNot(Token::eof, Token::error)) {
191 state.lex.resetPointer(curPointer);
198 if (
getToken().isNot(Token::at_identifier)) {
199 emitError(curLoc,
"expected nested symbol reference identifier");
206 referenceLocations.push_back(
getToken().getLocRange());
210 nestedRefs.push_back(SymbolRefAttr::get(
getContext(), nameStr));
212 SymbolRefAttr symbolRefAttr =
213 SymbolRefAttr::get(
getContext(), nameStr, nestedRefs);
217 state.asmState->addUses(symbolRefAttr, referenceLocations);
218 return symbolRefAttr;
227 case Token::code_complete:
228 if (
getToken().isCodeCompletionFor(Token::hash_identifier))
247 case Token::at_identifier:
248 case Token::floatliteral:
250 case Token::hash_identifier:
251 case Token::kw_affine_map:
252 case Token::kw_affine_set:
253 case Token::kw_dense:
254 case Token::kw_dense_resource:
255 case Token::kw_false:
257 case Token::kw_sparse:
261 case Token::l_square:
265 return success(attribute !=
nullptr);
272 attribute = TypeAttr::get(type);
296 llvm::SmallDenseSet<StringAttr> seenKeys;
297 auto parseElt = [&]() -> ParseResult {
299 std::optional<StringAttr> nameId;
302 else if (
getToken().isAny(Token::bare_identifier, Token::inttype) ||
309 return emitError(
"expected valid attribute name");
311 if (!seenKeys.insert(*nameId).second)
313 << nameId->getValue() <<
"' in dictionary attribute";
317 auto splitName = nameId->strref().split(
'.');
318 if (!splitName.second.empty())
336 " in attribute dictionary");
343 return (
emitError(
"floating point value too large for attribute"),
nullptr);
352 if (!isa<FloatType>(type))
353 return (
emitError(
"floating point value not valid for specified type"),
355 return FloatAttr::get(type, isNegative ? -*val : *val);
361 StringRef spelling) {
364 bool isHex = spelling.size() > 1 && spelling[1] ==
'x';
365 if (spelling.getAsInteger(isHex ? 0 : 10,
result))
369 unsigned width = type.
isIndex() ? IndexType::kInternalStorageBitWidth
372 if (width >
result.getBitWidth()) {
374 }
else if (width <
result.getBitWidth()) {
377 if (
result.countl_zero() <
result.getBitWidth() - width)
388 }
else if (isNegative) {
392 if (!
result.isSignBitSet())
415 type =
builder.getIntegerType(64);
420 if (
auto floatType = dyn_cast<FloatType>(type)) {
421 std::optional<APFloat>
result;
423 floatType.getFloatSemantics())))
425 return FloatAttr::get(floatType, *
result);
428 if (!isa<IntegerType, IndexType>(type))
429 return emitError(loc,
"integer literal not valid for specified type"),
434 "negative integer literal not valid for unsigned integer type");
440 return emitError(loc,
"integer constant out of range for attribute"),
442 return builder.getIntegerAttr(type, *apInt);
454 result = std::move(*value);
458 tok.
getLoc(),
"expected string containing hex digits starting with `0x`");
465class TensorLiteralParser {
467 TensorLiteralParser(Parser &p) : p(p) {}
471 ParseResult
parse(
bool allowHex);
475 DenseElementsAttr getAttr(SMLoc loc, ShapedType type);
477 ArrayRef<int64_t>
getShape()
const {
return shape; }
481 ParseResult getIntAttrElements(SMLoc loc, Type eltTy,
482 std::vector<APInt> &intValues);
485 ParseResult getFloatAttrElements(SMLoc loc, FloatType eltTy,
486 std::vector<APFloat> &floatValues);
489 DenseElementsAttr getStringAttr(SMLoc loc, ShapedType type, Type eltTy);
492 DenseElementsAttr getHexAttr(SMLoc loc, ShapedType type);
498 ParseResult parseElement();
506 ParseResult parseList(SmallVectorImpl<int64_t> &dims);
509 ParseResult parseHexElements();
514 SmallVector<int64_t, 4> shape;
517 std::vector<std::pair<bool, Token>> storage;
520 std::optional<Token> hexStorage;
526ParseResult TensorLiteralParser::parse(
bool allowHex) {
528 if (allowHex && p.getToken().is(Token::string)) {
529 hexStorage = p.getToken();
530 p.consumeToken(Token::string);
534 if (p.getToken().is(Token::l_square))
535 return parseList(shape);
536 return parseElement();
541DenseElementsAttr TensorLiteralParser::getAttr(SMLoc loc, ShapedType type) {
542 Type eltType = type.getElementType();
547 return getHexAttr(loc, type);
551 if (!shape.empty() &&
getShape() != type.getShape()) {
552 p.emitError(loc) <<
"inferred shape of elements literal ([" <<
getShape()
553 <<
"]) does not match type ([" << type.getShape() <<
"])";
558 if (!hexStorage && storage.empty() && type.getNumElements()) {
559 p.emitError(loc) <<
"parsed zero elements, but type (" << type
560 <<
") expected at least 1";
565 bool isComplex =
false;
566 if (ComplexType complexTy = dyn_cast<ComplexType>(eltType)) {
567 eltType = complexTy.getElementType();
571 bool isSplat = shape.empty() && type.getNumElements() != 0;
572 if (isSplat && storage.size() != 2) {
573 p.emitError(loc) <<
"parsed " << storage.size() <<
" elements, but type ("
574 << complexTy <<
") expected 2 elements";
577 if (!shape.empty() &&
578 storage.size() !=
static_cast<size_t>(type.getNumElements()) * 2) {
579 p.emitError(loc) <<
"parsed " << storage.size() <<
" elements, but type ("
580 << type <<
") expected " << type.getNumElements() * 2
588 std::vector<APInt> intValues;
589 if (
failed(getIntAttrElements(loc, eltType, intValues)))
593 auto complexData = llvm::ArrayRef(
594 reinterpret_cast<std::complex<APInt> *
>(intValues.data()),
595 intValues.size() / 2);
601 if (FloatType floatTy = dyn_cast<FloatType>(eltType)) {
602 std::vector<APFloat> floatValues;
603 if (
failed(getFloatAttrElements(loc, floatTy, floatValues)))
607 auto complexData = llvm::ArrayRef(
608 reinterpret_cast<std::complex<APFloat> *
>(floatValues.data()),
609 floatValues.size() / 2);
616 return getStringAttr(loc, type, type.getElementType());
621TensorLiteralParser::getIntAttrElements(SMLoc loc, Type eltTy,
622 std::vector<APInt> &intValues) {
623 intValues.reserve(storage.size());
625 for (
const auto &signAndToken : storage) {
626 bool isNegative = signAndToken.first;
627 const Token &token = signAndToken.second;
628 auto tokenLoc = token.
getLoc();
630 if (isNegative && isUintType) {
631 return p.emitError(tokenLoc)
632 <<
"expected unsigned integer elements, but parsed negative value";
636 if (token.
is(Token::floatliteral)) {
637 return p.emitError(tokenLoc)
638 <<
"expected integer elements, but parsed floating-point";
641 assert(token.
isAny(Token::integer, Token::kw_true, Token::kw_false) &&
642 "unexpected token type");
643 if (token.
isAny(Token::kw_true, Token::kw_false)) {
645 return p.emitError(tokenLoc)
646 <<
"expected i1 type for 'true' or 'false' values";
648 APInt apInt(1, token.
is(Token::kw_true),
false);
649 intValues.push_back(apInt);
654 std::optional<APInt> apInt =
657 return p.emitError(tokenLoc,
"integer constant out of range for type");
658 intValues.push_back(*apInt);
665TensorLiteralParser::getFloatAttrElements(SMLoc loc, FloatType eltTy,
666 std::vector<APFloat> &floatValues) {
667 floatValues.reserve(storage.size());
668 for (
const auto &signAndToken : storage) {
669 bool isNegative = signAndToken.first;
670 const Token &token = signAndToken.second;
671 std::optional<APFloat>
result;
672 if (
failed(p.parseFloatFromLiteral(
result, token, isNegative,
673 eltTy.getFloatSemantics())))
675 floatValues.push_back(*
result);
681DenseElementsAttr TensorLiteralParser::getStringAttr(SMLoc loc, ShapedType type,
683 if (hexStorage.has_value()) {
684 auto stringValue = hexStorage->getStringValue();
685 return DenseStringElementsAttr::get(type, {stringValue});
688 std::vector<std::string> stringValues;
689 std::vector<StringRef> stringRefValues;
690 stringValues.reserve(storage.size());
691 stringRefValues.reserve(storage.size());
693 for (
auto val : storage) {
694 if (!val.second.is(Token::string)) {
695 p.emitError(loc) <<
"expected string token, got "
696 << val.second.getSpelling();
699 stringValues.push_back(val.second.getStringValue());
700 stringRefValues.emplace_back(stringValues.back());
703 return DenseStringElementsAttr::get(type, stringRefValues);
707DenseElementsAttr TensorLiteralParser::getHexAttr(SMLoc loc, ShapedType type) {
708 Type elementType = type.getElementType();
711 <<
"expected floating-point, integer, or complex element type, got "
720 ArrayRef<char> rawData(data);
722 p.emitError(loc) <<
"elements hex data size is invalid for provided type: "
727 if (llvm::endianness::native == llvm::endianness::big) {
732 SmallVector<char, 64> outDataVec(rawData.size());
733 MutableArrayRef<char> convRawData(outDataVec);
734 DenseIntOrFPElementsAttr::convertEndianOfArrayRefForBEmachine(
735 rawData, convRawData, type);
742ParseResult TensorLiteralParser::parseElement() {
743 switch (p.getToken().getKind()) {
746 case Token::kw_false:
747 case Token::floatliteral:
749 storage.emplace_back(
false, p.getToken());
755 p.consumeToken(Token::minus);
756 if (!p.getToken().isAny(Token::floatliteral, Token::integer))
757 return p.emitError(
"expected integer or floating point literal");
758 storage.emplace_back(
true, p.getToken());
763 storage.emplace_back(
false, p.getToken());
769 p.consumeToken(Token::l_paren);
770 if (parseElement() ||
771 p.parseToken(Token::comma,
"expected ',' between complex elements") ||
773 p.parseToken(Token::r_paren,
"expected ')' after complex elements"))
778 return p.emitError(
"expected element literal of primitive type");
790ParseResult TensorLiteralParser::parseList(SmallVectorImpl<int64_t> &dims) {
791 auto checkDims = [&](
const SmallVectorImpl<int64_t> &prevDims,
792 const SmallVectorImpl<int64_t> &newDims) -> ParseResult {
793 if (prevDims == newDims)
795 return p.emitError(
"tensor literal is invalid; ranks are not consistent "
800 SmallVector<int64_t, 4> newDims;
802 auto parseOneElement = [&]() -> ParseResult {
803 SmallVector<int64_t, 4> thisDims;
804 if (p.getToken().getKind() == Token::l_square) {
805 if (parseList(thisDims))
807 }
else if (parseElement()) {
812 return checkDims(newDims, thisDims);
817 if (p.parseCommaSeparatedList(Parser::Delimiter::Square, parseOneElement))
822 dims.push_back(size);
823 dims.append(newDims.begin(), newDims.end());
834class DenseArrayElementParser {
836 explicit DenseArrayElementParser(Type type) : type(type) {}
839 ParseResult parseIntegerElement(Parser &p);
842 ParseResult parseFloatElement(Parser &p);
845 DenseArrayAttr getAttr() {
return DenseArrayAttr::get(type, size, rawData); }
849 void append(
const APInt &data);
854 std::vector<char> rawData;
860void DenseArrayElementParser::append(
const APInt &data) {
861 if (data.getBitWidth()) {
862 assert(data.getBitWidth() % 8 == 0);
863 unsigned byteSize = data.getBitWidth() / 8;
864 size_t offset = rawData.size();
865 rawData.insert(rawData.end(), byteSize, 0);
866 llvm::StoreIntToMemory(
867 data,
reinterpret_cast<uint8_t *
>(rawData.data() + offset), byteSize);
872ParseResult DenseArrayElementParser::parseIntegerElement(
Parser &p) {
873 bool isNegative = p.
consumeIf(Token::minus);
876 std::optional<APInt> value;
879 if (!type.isInteger(1))
880 return p.
emitError(
"expected i1 type for 'true' or 'false' values");
881 value = APInt(8, p.
getToken().
is(Token::kw_true),
882 !type.isUnsignedInteger());
884 }
else if (p.
consumeIf(Token::integer)) {
885 if (type.isInteger(1))
886 return p.
emitError(
"expected 'true' or 'false' values for i1 type");
889 return p.
emitError(
"integer constant out of range");
891 return p.
emitError(
"expected integer literal");
897ParseResult DenseArrayElementParser::parseFloatElement(
Parser &p) {
898 bool isNegative = p.
consumeIf(Token::minus);
900 std::optional<APFloat> fromIntLit;
903 cast<FloatType>(type).getFloatSemantics())))
906 append(fromIntLit->bitcastToAPInt());
913 if (
parseToken(Token::less,
"expected '<' after 'array'"))
919 emitError(typeLoc,
"expected an integer or floating point type");
926 emitError(typeLoc,
"expected integer or float type, got: ") << eltType;
930 emitError(typeLoc,
"element type bitwidth must be a multiple of 8");
936 return DenseArrayAttr::get(eltType, 0, {});
938 if (
parseToken(Token::colon,
"expected ':' after dense array type"))
941 DenseArrayElementParser eltParser(eltType);
942 if (isa<IntegerType>(eltType)) {
944 [&] {
return eltParser.parseIntegerElement(*
this); }))
948 [&] {
return eltParser.parseFloatElement(*
this); }))
951 if (
parseToken(Token::greater,
"expected '>' to close an array attribute"))
953 return eltParser.getAttr();
960 if (
parseToken(Token::less,
"expected '<' after 'dense'"))
964 TensorLiteralParser literalParser(*
this);
966 if (literalParser.parse(
true) ||
974 return literalParser.getAttr(attribLoc, type);
980 if (
parseToken(Token::less,
"expected '<' after 'dense_resource'"))
984 FailureOr<AsmDialectResourceHandle> rawHandle =
986 if (failed(rawHandle) ||
parseToken(Token::greater,
"expected '>'"))
989 auto *handle = dyn_cast<DenseResourceElementsHandle>(&*rawHandle);
991 return emitError(loc,
"invalid `dense_resource` handle type"),
nullptr;
1001 ShapedType shapedType = dyn_cast<ShapedType>(attrType);
1003 emitError(typeLoc,
"`dense_resource` expected a shaped type");
1007 return DenseResourceElementsAttr::get(shapedType, *handle);
1018 if (
parseToken(Token::colon,
"expected ':'"))
1024 auto sType = dyn_cast<ShapedType>(type);
1026 emitError(loc,
"elements literal must be a shaped type");
1030 if (!sType.hasStaticShape()) {
1031 emitError(loc,
"elements literal type must have static shape");
1042 if (
parseToken(Token::less,
"Expected '<' after 'sparse'"))
1056 ShapedType indicesType =
1057 RankedTensorType::get({0, type.getRank()}, indiceEltType);
1058 ShapedType valuesType = RankedTensorType::get({0}, type.getElementType());
1067 TensorLiteralParser indiceParser(*
this);
1068 if (indiceParser.parse(
false))
1071 if (
parseToken(Token::comma,
"expected ','"))
1076 TensorLiteralParser valuesParser(*
this);
1077 if (valuesParser.parse(
true))
1080 if (
parseToken(Token::greater,
"expected '>'"))
1092 ShapedType indicesType;
1093 if (indiceParser.getShape().empty()) {
1094 indicesType = RankedTensorType::get({1, type.getRank()}, indiceEltType);
1097 indicesType = RankedTensorType::get(indiceParser.getShape(), indiceEltType);
1099 auto indices = indiceParser.getAttr(indicesLoc, indicesType);
1106 auto valuesEltType = type.getElementType();
1107 ShapedType valuesType =
1108 valuesParser.getShape().empty()
1109 ? RankedTensorType::get({indicesType.getDimSize(0)}, valuesEltType)
1110 : RankedTensorType::get(valuesParser.getShape(), valuesEltType);
1111 auto values = valuesParser.getAttr(valuesLoc, valuesType);
1122 auto errorEmitter = [&] {
return emitError(loc); };
1125 if (failed(
parseToken(Token::less,
"expected '<' after 'strided'")) ||
1126 failed(
parseToken(Token::l_square,
"expected '['")))
1132 auto parseStrideOrOffset = [&]() -> std::optional<int64_t> {
1134 return ShapedType::kDynamic;
1138 emitError(loc,
"expected a 64-bit signed integer or '?'");
1139 return std::nullopt;
1142 bool negative =
consumeIf(Token::minus);
1144 if (
getToken().is(Token::integer)) {
1147 *value >
static_cast<uint64_t
>(std::numeric_limits<int64_t>::max()))
1162 if (!
getToken().is(Token::r_square)) {
1164 std::optional<int64_t> stride = parseStrideOrOffset();
1167 strides.push_back(*stride);
1171 if (failed(
parseToken(Token::r_square,
"expected ']'")))
1176 if (failed(StridedLayoutAttr::verify(errorEmitter,
1179 return StridedLayoutAttr::get(
getContext(), 0, strides);
1182 if (failed(
parseToken(Token::comma,
"expected ','")) ||
1183 failed(
parseToken(Token::kw_offset,
"expected 'offset' after comma")) ||
1184 failed(
parseToken(Token::colon,
"expected ':' after 'offset'")))
1187 std::optional<int64_t> offset = parseStrideOrOffset();
1188 if (!offset || failed(
parseToken(Token::greater,
"expected '>'")))
1191 if (failed(StridedLayoutAttr::verify(errorEmitter, *offset, strides)))
1193 return StridedLayoutAttr::get(
getContext(), *offset, strides);
1205 if (
parseToken(Token::l_square,
"expected '[' after 'distinct'"))
1210 if (
parseToken(Token::integer,
"expected distinct ID"))
1214 emitError(
"expected an unsigned 64-bit integer");
1219 if (
parseToken(Token::r_square,
"expected ']' to close distinct ID") ||
1220 parseToken(Token::less,
"expected '<' after distinct ID"))
1224 if (
getToken().is(Token::greater)) {
1226 referencedAttr =
builder.getUnitAttr();
1229 if (!referencedAttr) {
1234 if (
parseToken(Token::greater,
"expected '>' to close distinct attribute"))
1242 state.symbols.distinctAttributes;
1243 auto it = distinctAttrs.find(*value);
1244 if (it == distinctAttrs.end()) {
1246 it = distinctAttrs.try_emplace(*value, distinctAttr).first;
1247 }
else if (it->getSecond().getReferencedAttr() != referencedAttr) {
1248 emitError(loc,
"referenced attribute does not match previous definition: ")
1249 << it->getSecond().getReferencedAttr();
1253 return it->getSecond();
static std::optional< APInt > buildAttributeAPInt(Type type, bool isNegative, StringRef spelling)
Construct an APint from a parsed value, a known attribute type and sign.
static ParseResult parseElementAttrHexValues(Parser &parser, Token tok, std::string &result)
Parse elements values stored within a hex string.
static ArrayRef< int64_t > getShape(Type type)
Returns the shape of the given type.
A multi-dimensional affine map Affine map's are immutable like Type's, and they are uniqued.
Attributes are known-constant values of operations.
static DenseElementsAttr getFromRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Construct a dense elements attribute from a raw buffer representing the data for this attribute.
static bool isValidRawBuffer(ShapedType type, ArrayRef< char > rawBuffer)
Returns true if the given buffer is a valid raw buffer for the given type.
static DenseElementsAttr get(ShapedType type, ArrayRef< Attribute > values)
Constructs a dense elements attribute from an array of element values.
An attribute that associates a referenced attribute with a unique identifier.
static DistinctAttr create(Attribute referencedAttr)
Creates a distinct attribute that associates a referenced attribute with a unique identifier.
An integer set representing a conjunction of one or more affine equalities and inequalities.
Location objects represent source locations information in MLIR.
T * getOrLoadDialect()
Get (or create) a dialect for the given derived dialect type.
NamedAttrList is array of NamedAttributes that tracks whether it is sorted and does some basic work t...
DictionaryAttr getDictionary(MLIRContext *context) const
Return a dictionary attribute for the underlying dictionary.
void push_back(NamedAttribute newAttribute)
Add an attribute with the specified name.
This class implements Optional functionality for ParseResult.
This represents a token in the MLIR syntax.
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.
static std::optional< uint64_t > getUInt64IntegerValue(StringRef spelling)
For an integer token, return its value as an uint64_t.
std::optional< double > getFloatingPointValue() const
For a floatliteral token, return its value as a double.
bool isAny(Kind k1, Kind k2) const
StringRef getSpelling() const
std::optional< std::string > getHexStringValue() const
Given a token containing a hex string literal, return its value or std::nullopt if the token does not...
Instances of the Type class are uniqued, have an immutable identifier and an optional mutable compone...
bool isSignedInteger() const
Return true if this is a signed integer type (with the specified width).
bool isIntOrIndexOrFloat() const
Return true if this is an integer (of any signedness), index, or float type.
bool isUnsignedInteger() const
Return true if this is an unsigned integer type (with the specified width).
bool isIntOrIndex() const
Return true if this is an integer (of any signedness) or an index type.
bool isInteger() const
Return true if this is an integer type (with the specified width).
bool isIntOrFloat() const
Return true if this is an integer (of any signedness) or a float type.
unsigned getIntOrFloatBitWidth() const
Return the bit width of an integer or a float type, assert failure on other types.
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.
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.
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.
Type parseType()
Parse an arbitrary type.
Attribute parseDenseElementsAttr(Type attrType)
Parse a dense elements attribute.
Attribute parseDenseResourceElementsAttr(Type attrType)
Parse a dense resource elements attribute.
ParseResult parseAffineMapReference(AffineMap &map)
InFlightDiagnostic emitError(const Twine &message={})
Emit an error and return failure.
ParserState & state
The Parser is subclassed and reinstantiated.
Attribute parseAttribute(Type type={})
Parse an arbitrary attribute with an optional type.
StringRef getTokenSpelling() 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.
Attribute codeCompleteAttribute()
ParseResult parseAttributeDict(NamedAttrList &attributes)
Parse an attribute dictionary.
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.
Attribute parseSparseElementsAttr(Type attrType)
Parse a sparse elements attribute.
OptionalParseResult parseOptionalAttribute(Attribute &attribute, Type type={})
Parse an optional attribute with the provided type.
Attribute parseFloatAttr(Type type, bool isNegative)
Parse a float attribute.
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)
const Token & getToken() const
Return the current token the parser is inspecting.
Attribute parseExtendedAttr(Type type)
Parse an extended attribute.
MLIRContext * getContext() const
ShapedType parseElementsLiteralType(SMLoc loc, Type type)
Shaped type for elements attribute.
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.
QueryRef parse(llvm::StringRef line, const QuerySession &qs)
Include the generated interface declarations.
llvm::DenseMap< KeyT, ValueT, KeyInfoT, BucketT > DenseMap