[Mlir-commits] [mlir] [mlir][AsmParser] Expose `parseMinus()` (PR #106881)

Ivan Butygin llvmlistbot at llvm.org
Sat Aug 31 19:23:38 PDT 2024


https://github.com/Hardcode84 created https://github.com/llvm/llvm-project/pull/106881

Found while working on custom expression type for my dialect.

Builtin `AffineExpr` uses low-level parser API which is not available for external users.

>From 1f12333e56145f45c14f4b80c1f30fe92219d188 Mon Sep 17 00:00:00 2001
From: Ivan Butygin <ivan.butygin at gmail.com>
Date: Sun, 1 Sep 2024 03:58:14 +0200
Subject: [PATCH] [mlir][AsmParser] Expose `parseMinus()`

Found while working on custom expression type for my dialect.

Builtin `AffineExpr` uses low-level parser API which is not available for expernal users.
---
 mlir/include/mlir/IR/OpImplementation.h |  6 ++++++
 mlir/lib/AsmParser/AsmParserImpl.h      | 10 ++++++++++
 2 files changed, 16 insertions(+)

diff --git a/mlir/include/mlir/IR/OpImplementation.h b/mlir/include/mlir/IR/OpImplementation.h
index ae412c7227f8ea..e2472eea8a3714 100644
--- a/mlir/include/mlir/IR/OpImplementation.h
+++ b/mlir/include/mlir/IR/OpImplementation.h
@@ -641,6 +641,12 @@ class AsmParser {
   /// Parse a '+' token if present.
   virtual ParseResult parseOptionalPlus() = 0;
 
+  /// Parse a '-' token.
+  virtual ParseResult parseMinus() = 0;
+
+  /// Parse a '-' token if present.
+  virtual ParseResult parseOptionalMinus() = 0;
+
   /// Parse a '*' token.
   virtual ParseResult parseStar() = 0;
 
diff --git a/mlir/lib/AsmParser/AsmParserImpl.h b/mlir/lib/AsmParser/AsmParserImpl.h
index b12687833e3fde..04250f63dcd253 100644
--- a/mlir/lib/AsmParser/AsmParserImpl.h
+++ b/mlir/lib/AsmParser/AsmParserImpl.h
@@ -226,6 +226,16 @@ class AsmParserImpl : public BaseT {
     return success(parser.consumeIf(Token::plus));
   }
 
+  /// Parses a '-' token.
+  ParseResult parseMinus() override {
+    return parser.parseToken(Token::minus, "expected '-'");
+  }
+
+  /// Parses a '-' token if present.
+  ParseResult parseOptionalMinus() override {
+    return success(parser.consumeIf(Token::minus));
+  }
+
   /// Parse a '|' token.
   ParseResult parseVerticalBar() override {
     return parser.parseToken(Token::vertical_bar, "expected '|'");



More information about the Mlir-commits mailing list