Skip to content

Commit afd9e9a

Browse files
committed
PDLL: Parse string literals into AttributeExpr
1 parent 1049aba commit afd9e9a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

mlir/lib/Tools/PDLL/Parser/Parser.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ class Parser {
326326
FailureOr<ast::Expr *> parseMemberAccessExpr(ast::Expr *parentExpr);
327327
FailureOr<ast::Expr *> parseNegatedExpr();
328328
FailureOr<ast::Expr *> parseIntegerExpr();
329+
FailureOr<ast::Expr *> parseStringExpr();
329330
FailureOr<ast::OpNameDecl *> parseOperationName(bool allowEmptyName = false);
330331
FailureOr<ast::OpNameDecl *> parseWrappedOperationName(bool allowEmptyName);
331332
FailureOr<ast::Expr *>
@@ -1838,6 +1839,9 @@ FailureOr<ast::Expr *> Parser::parseExpr() {
18381839
case Token::integer:
18391840
lhsExpr = parseIntegerExpr();
18401841
break;
1842+
case Token::string:
1843+
lhsExpr = parseStringExpr();
1844+
break;
18411845
case Token::string_block:
18421846
return emitError("expected expression. If you are trying to create an "
18431847
"ArrayAttr, use a space between `[` and `{`.");
@@ -2100,6 +2104,13 @@ FailureOr<ast::Expr *> Parser::parseIntegerExpr() {
21002104
return ast::AttributeExpr::create(ctx, loc, allocated);
21012105
}
21022106

2107+
FailureOr<ast::Expr *> Parser::parseStringExpr() {
2108+
SMRange loc = curToken.getLoc();
2109+
StringRef value = curToken.getSpelling();
2110+
consumeToken();
2111+
return ast::AttributeExpr::create(ctx, loc, value);
2112+
}
2113+
21032114
FailureOr<ast::OpNameDecl *> Parser::parseOperationName(bool allowEmptyName) {
21042115
SMRange loc = curToken.getLoc();
21052116

mlir/test/mlir-pdll/Parser/expr.pdll

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,15 @@ Pattern {
2323

2424
// -----
2525

26+
// CHECK: Module
27+
// CHECK: `-AttributeExpr {{.*}} Value<""value"">
28+
Pattern {
29+
let attr = "value";
30+
erase _: Op;
31+
}
32+
33+
// -----
34+
2635
// CHECK: |-NamedAttributeDecl {{.*}} Name<some_array>
2736
// CHECK: `-UserRewriteDecl {{.*}} Name<addElemToArrayAttr> ResultType<Attr>
2837
// CHECK: `Arguments`

0 commit comments

Comments
 (0)