diff options
| author | Andi Drebes <47449897+andidr@users.noreply.github.com> | 2025-05-14 18:33:21 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-14 09:33:21 -0700 |
| commit | ba23eedc68ee1363ae8c31afc0f4b5071779eb0b (patch) | |
| tree | ed8b0b48b7d122833ce466462d87182485e56459 /mlir/test/lib/Dialect/Test/TestAttributes.cpp | |
| parent | 899f26315cdae25addfd0ddbc6c9390bfbb74c3e (diff) | |
[MLIR][parser] Add token type and parser methods for forward slashes (#125056)
This adds a token for a forward slash to the token definition list and
the methods to `AsmParser::parseSlash()` and
`AsmParser::parseOptionalSlash()`, similar to other tokens used as
operators (e.g., star, plus, etc.). This allows implementations of
attributes that contain arithmetic expressions to support operators with
a forward slash, e.g., a division.
The newly added check tests trigger the parsing of a slash in an
attribute.
Diffstat (limited to 'mlir/test/lib/Dialect/Test/TestAttributes.cpp')
| -rw-r--r-- | mlir/test/lib/Dialect/Test/TestAttributes.cpp | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/mlir/test/lib/Dialect/Test/TestAttributes.cpp b/mlir/test/lib/Dialect/Test/TestAttributes.cpp index b36f246b83d7..80661e68754c 100644 --- a/mlir/test/lib/Dialect/Test/TestAttributes.cpp +++ b/mlir/test/lib/Dialect/Test/TestAttributes.cpp @@ -498,6 +498,24 @@ getDynamicCustomAssemblyFormatAttr(TestDialect *testDialect) { } //===----------------------------------------------------------------------===// +// SlashAttr +//===----------------------------------------------------------------------===// + +Attribute SlashAttr::parse(AsmParser &parser, Type type) { + int lhs, rhs; + + if (parser.parseLess() || parser.parseInteger(lhs) || parser.parseSlash() || + parser.parseInteger(rhs) || parser.parseGreater()) + return Attribute(); + + return SlashAttr::get(parser.getContext(), lhs, rhs); +} + +void SlashAttr::print(AsmPrinter &printer) const { + printer << "<" << getLhs() << " / " << getRhs() << ">"; +} + +//===----------------------------------------------------------------------===// // TestDialect //===----------------------------------------------------------------------===// |
