Skip to content

Commit

Permalink
Merge pull request #95 from Xilinx/matthias.string_literals
Browse files Browse the repository at this point in the history
PDLL: Parse string literals into AttributeExpr
  • Loading branch information
mgehre-amd authored Feb 21, 2024
2 parents e6b751e + afd9e9a commit b7f8652
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 @@ -337,6 +337,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 @@ -1901,6 +1902,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 @@ -2164,6 +2168,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<__builtin_addElemToArrayAttr> ResultType<Attr>
// CHECK: `Arguments`
Expand Down

0 comments on commit b7f8652

Please sign in to comment.