Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify parsing ceildiv/floordiv/mod #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
12 changes: 6 additions & 6 deletions mlir/lark/mlir.lark
Original file line number Diff line number Diff line change
Expand Up @@ -251,9 +251,9 @@ affine_expr : "(" affine_expr ")" -> affine_parens
| affine_expr "-" affine_expr -> affine_sub
| posneg_integer_literal "*" affine_expr -> affine_mul
| affine_expr "*" posneg_integer_literal -> affine_mul
| affine_expr "&ceildiv&" integer_literal -> affine_ceildiv
| affine_expr "&floordiv&" integer_literal -> affine_floordiv
| affine_expr "&mod&" integer_literal -> affine_mod
| affine_expr "ceildiv" integer_literal -> affine_ceildiv
| affine_expr "floordiv" integer_literal -> affine_floordiv
| affine_expr "mod" integer_literal -> affine_mod
| "-" affine_expr -> affine_neg
| "symbol" "(" ssa_id ")" -> affine_symbol_explicit
| posneg_integer_literal -> affine_literal
Expand All @@ -265,9 +265,9 @@ semi_affine_expr : "(" semi_affine_expr ")" -> semi_affin
| semi_affine_expr "-" semi_affine_expr -> semi_affine_sub
| symbol_or_const "*" semi_affine_expr -> semi_affine_mul
| semi_affine_expr "*" symbol_or_const -> semi_affine_mul
| semi_affine_expr "&ceildiv&" semi_affine_oprnd -> semi_affine_ceildiv
| semi_affine_expr "&floordiv&" semi_affine_oprnd -> semi_affine_floordiv
| semi_affine_expr "&mod&" semi_affine_oprnd -> semi_affine_mod
| semi_affine_expr "ceildiv" semi_affine_oprnd -> semi_affine_ceildiv
| semi_affine_expr "floordiv" semi_affine_oprnd -> semi_affine_floordiv
| semi_affine_expr "mod" semi_affine_oprnd -> semi_affine_mod
| "symbol" "(" symbol_or_const ")" -> semi_affine_symbol_explicit
| symbol_or_const -> semi_affine_symbol

Expand Down
7 changes: 0 additions & 7 deletions mlir/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,6 @@ def parse(self, code: str) -> mast.Module:
:return: A module node representing the root of the AST.
"""

# Pre-transform code to avoid parsing issues with ceildiv/floordiv/mod,
# in which two symbols could be parsed as one legal symbol (due to
# ignoring whitespace): "d0floordivs0"
code = code.replace(' floordiv ', '&floordiv&')
code = code.replace(' ceildiv ', '&ceildiv&')
code = code.replace(' mod ', '&mod&')

# Parse the code using Lark
tree = self.parser.parse(code)

Expand Down