Skip to content

Commit

Permalink
dialects: (builtin) fix formatting of module printing with attributes (
Browse files Browse the repository at this point in the history
…#3789)

Instead of printing two spaces, print one.
  • Loading branch information
superlopuh authored Jan 25, 2025
1 parent 6fd4792 commit 35d5b6b
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 23 deletions.
46 changes: 26 additions & 20 deletions tests/filecheck/dialects/builtin/module.mlir
Original file line number Diff line number Diff line change
@@ -1,22 +1,28 @@
// RUN: XDSL_ROUNDTRIP
// RUN: xdsl-opt %s --allow-unregistered-dialect | filecheck %s
// RUN: xdsl-opt %s --allow-unregistered-dialect | filecheck --strict-whitespace %s

builtin.module {
// CHECK: builtin.module {
builtin.module {}
// CHECK: builtin.module {
// CHECK-NEXT: }
builtin.module attributes {a = "foo", b = "bar", unit} {}
// CHECK-NEXT: builtin.module attributes {a = "foo", b = "bar", unit} {
// CHECK-NEXT: }
builtin.module @moduleName {}
// CHECK-NEXT: builtin.module @moduleName {
// CHECK-NEXT: }
builtin.module @otherModule attributes {dialect.attr} {}
// CHECK-NEXT: builtin.module @otherModule attributes {dialect.attr} {
// CHECK-NEXT: }
module {}
// CHECK-NEXT: builtin.module {
// CHECK-NEXT: }
}
// CHECK: }
// CHECK:builtin.module {
builtin.module {

// CHECK-NEXT: builtin.module {
// CHECK-NEXT: }
builtin.module {}

// CHECK-NEXT: builtin.module attributes {a = "foo", b = "bar", unit} {
// CHECK-NEXT: }
builtin.module attributes {a = "foo", b = "bar", unit} {}

// CHECK-NEXT: builtin.module @moduleName {
// CHECK-NEXT: }
builtin.module @moduleName {}

// CHECK-NEXT: builtin.module @otherModule attributes {dialect.attr} {
// CHECK-NEXT: }
builtin.module @otherModule attributes {dialect.attr} {}

// CHECK-NEXT: builtin.module {
// CHECK-NEXT: }
module {}

// CHECK:}
}
5 changes: 2 additions & 3 deletions xdsl/dialects/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -1735,9 +1735,8 @@ def print(self, printer: Printer) -> None:
if self.sym_name is not None:
printer.print(f" @{self.sym_name.data}")

if len(self.attributes) != 0:
printer.print(" attributes ")
printer.print_op_attributes(self.attributes)
if self.attributes:
printer.print_op_attributes(self.attributes, print_keyword=True)

if not self.body.block.ops:
# Do not print the entry block if the region has an empty block
Expand Down

0 comments on commit 35d5b6b

Please sign in to comment.