diff --git a/mlir/lib/Tools/PDLL/Parser/Lexer.cpp b/mlir/lib/Tools/PDLL/Parser/Lexer.cpp index acfb9e9f02af3..15ea395764fb2 100644 --- a/mlir/lib/Tools/PDLL/Parser/Lexer.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Lexer.cpp @@ -171,7 +171,9 @@ int Lexer::getNextChar() { } } -StringRef Lexer::getCurrentInclude() const { return canonicalIncludeFileStack.back(); } +StringRef Lexer::getCurrentInclude() const { + return canonicalIncludeFileStack.back(); +} bool Lexer::isLexingMainFile() const { return static_cast(srcMgr.getMainFileID()) == curBufferID; @@ -402,6 +404,8 @@ Token Lexer::lexIdentifier(const char *tokStart) { .Case("log2", Token::log2) .Case("exp2", Token::exp2) .Case("math_abs", Token::abs) + .Case("true", Token::kw_true) + .Case("false", Token::kw_false) .Default(Token::identifier); return Token(kind, str); } diff --git a/mlir/lib/Tools/PDLL/Parser/Lexer.h b/mlir/lib/Tools/PDLL/Parser/Lexer.h index 74d8a3fa8a264..044bf96dce112 100644 --- a/mlir/lib/Tools/PDLL/Parser/Lexer.h +++ b/mlir/lib/Tools/PDLL/Parser/Lexer.h @@ -71,6 +71,10 @@ class Token { kw_with, KW_END, + // Boolean keywords + kw_true, + kw_false, + /// Punctuation. arrow, colon, diff --git a/mlir/lib/Tools/PDLL/Parser/Parser.cpp b/mlir/lib/Tools/PDLL/Parser/Parser.cpp index aacb049f32b09..345d5f739c2dc 100644 --- a/mlir/lib/Tools/PDLL/Parser/Parser.cpp +++ b/mlir/lib/Tools/PDLL/Parser/Parser.cpp @@ -344,6 +344,7 @@ class Parser { FailureOr parseMulDivModExpr(); FailureOr parseLogicalNotExpr(); FailureOr parseOtherExpr(); + FailureOr parseBoolExpr(); /// Identifier expressions. FailureOr parseArrayAttrExpr(); @@ -2301,6 +2302,10 @@ FailureOr Parser::parseOtherExpr() { case Token::string_block: return emitError("expected expression. If you are trying to create an " "ArrayAttr, use a space between `[` and `{`."); + case Token::kw_false: + case Token::kw_true: + lhsExpr = parseBoolExpr(); + break; default: return emitError("expected expression"); } @@ -2579,6 +2584,16 @@ FailureOr Parser::parseIntegerExpr() { return ast::AttributeExpr::create(ctx, loc, allocated); } +FailureOr Parser::parseBoolExpr() { + SMRange loc = curToken.getLoc(); + const bool isTrue = curToken.is(Token::kw_true); + consumeToken(); + const std::string boolAttrAsString = isTrue ? "true" : "false"; + + auto allocated = copyStringWithNull(ctx, boolAttrAsString); + return ast::AttributeExpr::create(ctx, loc, allocated); +} + FailureOr Parser::parseStringExpr() { SMRange loc = curToken.getLoc(); StringRef value = curToken.getSpelling();