Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion mlir/lib/Tools/PDLL/Parser/Lexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(srcMgr.getMainFileID()) == curBufferID;
Expand Down Expand Up @@ -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);
}
Expand Down
4 changes: 4 additions & 0 deletions mlir/lib/Tools/PDLL/Parser/Lexer.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,10 @@ class Token {
kw_with,
KW_END,

// Boolean keywords
kw_true,
kw_false,

/// Punctuation.
arrow,
colon,
Expand Down
15 changes: 15 additions & 0 deletions mlir/lib/Tools/PDLL/Parser/Parser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,6 +344,7 @@ class Parser {
FailureOr<ast::Expr *> parseMulDivModExpr();
FailureOr<ast::Expr *> parseLogicalNotExpr();
FailureOr<ast::Expr *> parseOtherExpr();
FailureOr<ast::Expr *> parseBoolExpr();

/// Identifier expressions.
FailureOr<ast::Expr *> parseArrayAttrExpr();
Expand Down Expand Up @@ -2301,6 +2302,10 @@ FailureOr<ast::Expr *> 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");
}
Expand Down Expand Up @@ -2579,6 +2584,16 @@ FailureOr<ast::Expr *> Parser::parseIntegerExpr() {
return ast::AttributeExpr::create(ctx, loc, allocated);
}

FailureOr<ast::Expr *> 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<ast::Expr *> Parser::parseStringExpr() {
SMRange loc = curToken.getLoc();
StringRef value = curToken.getSpelling();
Expand Down