From c928b3c8c84d683654252817948b0c6ad52aad15 Mon Sep 17 00:00:00 2001 From: emmau678 Date: Tue, 8 Oct 2024 14:23:25 +0100 Subject: [PATCH] dialects: (mod_arith) Add updates based on review comments --- .../dialects/mod_arith/mod_arith.mlir | 2 +- xdsl/dialects/mod_arith.py | 20 +++++++++---------- 2 files changed, 10 insertions(+), 12 deletions(-) diff --git a/tests/filecheck/dialects/mod_arith/mod_arith.mlir b/tests/filecheck/dialects/mod_arith/mod_arith.mlir index a8714e569e..4a929c817d 100644 --- a/tests/filecheck/dialects/mod_arith/mod_arith.mlir +++ b/tests/filecheck/dialects/mod_arith/mod_arith.mlir @@ -4,5 +4,5 @@ %lhsi1, %rhsi1 = "test.op"() : () -> (i1, i1) // CHECK: %add_res = mod_arith.add %lhsi1, %rhsi1 {"modulus" = 17 : i64} : i1 -// CHECK-GENERIC: %add_res = "mod_arith.add"(%lhsi1, %rhsi1) {"modulus" = 17 : i64} : (i1, i1) -> i1 +// CHECK-GENERIC: %add_res = "mod_arith.add"(%lhsi1, %rhsi1) <{"modulus" = 17 : i64}> : (i1, i1) -> i1 %add_res = "mod_arith.add"(%lhsi1, %rhsi1) {modulus=17} : (i1, i1) -> i1 diff --git a/xdsl/dialects/mod_arith.py b/xdsl/dialects/mod_arith.py index c544e45aac..d6a73ff5c1 100644 --- a/xdsl/dialects/mod_arith.py +++ b/xdsl/dialects/mod_arith.py @@ -12,9 +12,10 @@ from xdsl.irdl import ( ConstraintVar, IRDLOperation, - attr_def, + ParsePropInAttrDict, irdl_op_definition, operand_def, + prop_def, result_def, ) from xdsl.traits import Pure @@ -33,10 +34,13 @@ class BinaryOp(ModArithOp, ABC, Generic[_T]): """ T = Annotated[Attribute, ConstraintVar("T"), _T] + modulus = prop_def(AnyIntegerAttr) lhs = operand_def(T) rhs = operand_def(T) output = result_def(T) + irdl_options = [ParsePropInAttrDict()] + assembly_format = "$lhs `,` $rhs attr-dict `:` type($output)" traits = frozenset((Pure(),)) @@ -52,20 +56,14 @@ def __init__( super().__init__(operands=[lhs, rhs], result_types=[result_type]) -class BinaryModuloOp(BinaryOp[_T], ABC, Generic[_T]): - """ - Adds the modulus attribute - """ - - modulus = attr_def(AnyIntegerAttr) - - @irdl_op_definition -class AddOp(BinaryModuloOp[Annotated[Attribute, signlessIntegerLike]]): +class AddOp(BinaryOp[Annotated[Attribute, signlessIntegerLike]]): name = "mod_arith.add" ModArith = Dialect( "mod_arith", - [AddOp], + [ + AddOp, + ], )