Skip to content

Commit

Permalink
PDLL: Parse string literals into AttributeExpr
Browse files Browse the repository at this point in the history
  • Loading branch information
mgehre-amd committed Jan 26, 2024
1 parent 1049aba commit afd9e9a
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mlir/lib/Tools/PDLL/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@ class Parser {
FailureOr<ast::Expr *> parseMemberAccessExpr(ast::Expr *parentExpr);
FailureOr<ast::Expr *> parseNegatedExpr();
FailureOr<ast::Expr *> parseIntegerExpr();
FailureOr<ast::Expr *> parseStringExpr();
FailureOr<ast::OpNameDecl *> parseOperationName(bool allowEmptyName = false);
FailureOr<ast::OpNameDecl *> parseWrappedOperationName(bool allowEmptyName);
FailureOr<ast::Expr *>
Expand Down Expand Up @@ -1838,6 +1839,9 @@ FailureOr<ast::Expr *> Parser::parseExpr() {
case Token::integer:
lhsExpr = parseIntegerExpr();
break;
case Token::string:
lhsExpr = parseStringExpr();
break;
case Token::string_block:
return emitError("expected expression. If you are trying to create an "
"ArrayAttr, use a space between `[` and `{`.");
Expand Down Expand Up @@ -2100,6 +2104,13 @@ FailureOr<ast::Expr *> Parser::parseIntegerExpr() {
return ast::AttributeExpr::create(ctx, loc, allocated);
}

FailureOr<ast::Expr *> Parser::parseStringExpr() {
SMRange loc = curToken.getLoc();
StringRef value = curToken.getSpelling();
consumeToken();
return ast::AttributeExpr::create(ctx, loc, value);
}

FailureOr<ast::OpNameDecl *> Parser::parseOperationName(bool allowEmptyName) {
SMRange loc = curToken.getLoc();

Expand Down
9 changes: 9 additions & 0 deletions mlir/test/mlir-pdll/Parser/expr.pdll
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,15 @@ Pattern {

// -----

// CHECK: Module
// CHECK: `-AttributeExpr {{.*}} Value<""value"">
Pattern {
let attr = "value";
erase _: Op;
}

// -----

// CHECK: |-NamedAttributeDecl {{.*}} Name<some_array>
// CHECK: `-UserRewriteDecl {{.*}} Name<addElemToArrayAttr> ResultType<Attr>
// CHECK: `Arguments`
Expand Down

0 comments on commit afd9e9a

Please sign in to comment.