IntegerSet &set);
DenseElementsAttr parseDenseElementsAttr(ShapedType type);
DenseElementsAttr parseDenseElementsAttrAsTensor(Type eltType);
- ShapedType parseShapedType();
+ ShapedType parseElementsLiteralType();
// Location Parsing.
if (parseToken(Token::comma, "expected ','"))
return nullptr;
- auto type = parseShapedType();
+ auto type = parseElementsLiteralType();
if (!type)
return nullptr;
+ if (parseToken(Token::comma, "expected ',' after elements literal type"))
+ return nullptr;
+
if (getToken().getKind() != Token::string)
return (emitError("opaque string should start with '0x'"), nullptr);
auto val = getToken().getStringValue();
if (parseToken(Token::less, "expected '<' after 'splat'"))
return nullptr;
- auto type = parseShapedType();
+ auto type = parseElementsLiteralType();
if (!type)
return nullptr;
+ if (parseToken(Token::comma, "expected ',' after elements literal type"))
+ return nullptr;
switch (getToken().getKind()) {
case Token::floatliteral:
case Token::integer:
if (parseToken(Token::less, "expected '<' after 'dense'"))
return nullptr;
- auto type = parseShapedType();
+ auto type = parseElementsLiteralType();
if (!type)
return nullptr;
+ if (parseToken(Token::comma, "expected ',' after elements literal type"))
+ return nullptr;
+
auto attr = parseDenseElementsAttr(type);
if (!attr)
return nullptr;
if (parseToken(Token::less, "Expected '<' after 'sparse'"))
return nullptr;
- auto type = parseShapedType();
+ auto type = parseElementsLiteralType();
if (!type)
return nullptr;
+ if (parseToken(Token::comma, "expected ',' after elements literal type"))
+ return nullptr;
+
switch (getToken().getKind()) {
case Token::l_square: {
/// Parse indices
/// Shaped type for elements attribute.
///
-/// shaped-type ::= vector-type | tensor-type
+/// elements-literal-type ::= vector-type | ranked-tensor-type
///
/// This method also checks the type has static shape.
-ShapedType Parser::parseShapedType() {
- auto elementType = parseType();
- if (!elementType)
+ShapedType Parser::parseElementsLiteralType() {
+ auto type = parseType();
+ if (!type)
return nullptr;
- auto type = elementType.dyn_cast<ShapedType>();
- if (!type) {
- return (emitError("elements literal must be a shaped type"), nullptr);
+ if (!type.isa<RankedTensorType>() && !type.isa<VectorType>()) {
+ return (
+ emitError("elements literal must be a ranked tensor or vector type"),
+ nullptr);
}
- if (parseToken(Token::comma, "expected ','"))
- return nullptr;
+ auto sType = type.cast<ShapedType>();
+ if (!sType.hasStaticShape())
+ return (emitError("elements literal type must have static shape"), nullptr);
- if (!type.hasStaticShape()) {
- return (emitError("shaped literal must have static shape"), nullptr);
- }
- return type;
+ return sType;
}
/// Debug Location.