From 35d5b6b2f349fa56a6170efd63e6b7ae78ca60a8 Mon Sep 17 00:00:00 2001 From: Sasha Lopoukhine Date: Sun, 26 Jan 2025 00:32:35 +0100 Subject: [PATCH] dialects: (builtin) fix formatting of module printing with attributes (#3789) Instead of printing two spaces, print one. --- tests/filecheck/dialects/builtin/module.mlir | 46 +++++++++++--------- xdsl/dialects/builtin.py | 5 +-- 2 files changed, 28 insertions(+), 23 deletions(-) diff --git a/tests/filecheck/dialects/builtin/module.mlir b/tests/filecheck/dialects/builtin/module.mlir index 195b50ec6c..5869a6b789 100644 --- a/tests/filecheck/dialects/builtin/module.mlir +++ b/tests/filecheck/dialects/builtin/module.mlir @@ -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:} + } diff --git a/xdsl/dialects/builtin.py b/xdsl/dialects/builtin.py index 26786aacb1..493978021e 100644 --- a/xdsl/dialects/builtin.py +++ b/xdsl/dialects/builtin.py @@ -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