Skip to content

Commit

Permalink
dialects: (arith) fix attribute dictionary printing and parsing (#3327)
Browse files Browse the repository at this point in the history
Currently dropped, this is needed for #3315 to work correctly.
  • Loading branch information
superlopuh authored Oct 20, 2024
1 parent 7c86cfb commit 54fc9a8
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 18 deletions.
4 changes: 4 additions & 0 deletions tests/filecheck/dialects/arith/arith_ops.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,10 @@
// CHECK-NEXT: %minf = arith.minnumf %lhsf32, %rhsf32 : f32
// CHECK-NEXT: %minf_vector = arith.minnumf %lhsvec, %rhsvec : vector<4xf32>

%addi = arith.addi %lhsi32, %rhsi32 {"hello" = "world"} : i32

// CHECK-NEXT: %addi = arith.addi %lhsi32, %rhsi32 {"hello" = "world"} : i32

%addf = arith.addf %lhsf32, %rhsf32 : f32
%addf_vector = arith.addf %lhsvec, %rhsvec : vector<4xf32>

Expand Down
20 changes: 2 additions & 18 deletions xdsl/dialects/arith.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,8 @@ class SignlessIntegerBinaryOperation(IRDLOperation, abc.ABC):
rhs = operand_def(T)
result = result_def(T)

assembly_format = "$lhs `,` $rhs attr-dict `:` type($result)"

def __init__(
self,
operand1: Operation | SSAValue,
Expand All @@ -191,24 +193,6 @@ def __init__(
result_type = SSAValue.get(operand1).type
super().__init__(operands=[operand1, operand2], result_types=[result_type])

@classmethod
def parse(cls, parser: Parser):
lhs = parser.parse_unresolved_operand()
parser.parse_punctuation(",")
rhs = parser.parse_unresolved_operand()
parser.parse_punctuation(":")
result_type = parser.parse_type()
(lhs, rhs) = parser.resolve_operands([lhs, rhs], 2 * [result_type], parser.pos)
return cls(lhs, rhs, result_type)

def print(self, printer: Printer):
printer.print(" ")
printer.print_ssa_value(self.lhs)
printer.print(", ")
printer.print_ssa_value(self.rhs)
printer.print(" : ")
printer.print_attribute(self.result.type)

def __hash__(self) -> int:
return id(self)

Expand Down

0 comments on commit 54fc9a8

Please sign in to comment.