Skip to content

Commit b7f8652

Browse files
authored
Merge pull request #95 from Xilinx/matthias.string_literals
PDLL: Parse string literals into AttributeExpr
2 parents e6b751e + afd9e9a commit b7f8652

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
@@ -337,6 +337,7 @@ class Parser {
337337
FailureOr<ast::Expr *> parseMemberAccessExpr(ast::Expr *parentExpr);
338338
FailureOr<ast::Expr *> parseNegatedExpr();
339339
FailureOr<ast::Expr *> parseIntegerExpr();
340+
FailureOr<ast::Expr *> parseStringExpr();
340341
FailureOr<ast::OpNameDecl *> parseOperationName(bool allowEmptyName = false);
341342
FailureOr<ast::OpNameDecl *> parseWrappedOperationName(bool allowEmptyName);
342343
FailureOr<ast::Expr *>
@@ -1901,6 +1902,9 @@ FailureOr<ast::Expr *> Parser::parseExpr() {
19011902
case Token::integer:
19021903
lhsExpr = parseIntegerExpr();
19031904
break;
1905+
case Token::string:
1906+
lhsExpr = parseStringExpr();
1907+
break;
19041908
case Token::string_block:
19051909
return emitError("expected expression. If you are trying to create an "
19061910
"ArrayAttr, use a space between `[` and `{`.");
@@ -2164,6 +2168,13 @@ FailureOr<ast::Expr *> Parser::parseIntegerExpr() {
21642168
return ast::AttributeExpr::create(ctx, loc, allocated);
21652169
}
21662170

2171+
FailureOr<ast::Expr *> Parser::parseStringExpr() {
2172+
SMRange loc = curToken.getLoc();
2173+
StringRef value = curToken.getSpelling();
2174+
consumeToken();
2175+
return ast::AttributeExpr::create(ctx, loc, value);
2176+
}
2177+
21672178
FailureOr<ast::OpNameDecl *> Parser::parseOperationName(bool allowEmptyName) {
21682179
SMRange loc = curToken.getLoc();
21692180

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<__builtin_addElemToArrayAttr> ResultType<Attr>
2837
// CHECK: `Arguments`

0 commit comments

Comments
 (0)