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

dialects: (builtin) fix formatting of module printing with attributes #3789

Merged
merged 1 commit into from
Jan 25, 2025
Merged
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
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
Loading