diff --git a/tests/filecheck/parser-printer/builtin_attrs.mlir b/tests/filecheck/parser-printer/builtin_attrs.mlir index 4d2ceb66e7..68c270ff3b 100644 --- a/tests/filecheck/parser-printer/builtin_attrs.mlir +++ b/tests/filecheck/parser-printer/builtin_attrs.mlir @@ -8,6 +8,9 @@ // CHECK: (index) + "func.func"() ({}) {function_type = () -> (), sym_name = "unit_attr_func", unitarray = [unit]} : () -> () + + // CHECK: "unitarray" = [unit] "func.func"() ({ ^bb0(%arg0: i32, %arg1: i64, %arg2: i1): diff --git a/xdsl/parser/attribute_parser.py b/xdsl/parser/attribute_parser.py index 216a698672..e38e5181f6 100644 --- a/xdsl/parser/attribute_parser.py +++ b/xdsl/parser/attribute_parser.py @@ -595,6 +595,7 @@ def _parse_optional_builtin_attr(self) -> Attribute | None: return BytesAttr(bytes_lit) attrs = ( + self.parse_optional_unit_attr, self.parse_optional_builtin_int_or_float_attr, self._parse_optional_array_attr, self._parse_optional_symref_attr, @@ -651,6 +652,22 @@ def _parse_strided_layout_attr(self, name: Span) -> Attribute: self._parse_token(Token.Kind.GREATER, "Expected '>' in end of stride attribute") return StridedLayoutAttr(strides, None if offset == "?" else offset) + def parse_optional_unit_attr(self) -> Attribute | None: + """ + Parse a value of `unit` type. + unit-attribute ::= `unit` + """ + if self._current_token.kind != Token.Kind.BARE_IDENT: + return None + name = self._current_token.span.text + + # Unit attribute + if name == "unit": + self._consume_token() + return UnitAttr() + + return None + def _parse_optional_builtin_parametrized_attr(self) -> Attribute | None: if self._current_token.kind != Token.Kind.BARE_IDENT: return None diff --git a/xdsl/printer.py b/xdsl/printer.py index 06a18014fe..4abc0fddba 100644 --- a/xdsl/printer.py +++ b/xdsl/printer.py @@ -398,6 +398,7 @@ def print_bytes_literal(self, bytestring: bytes): def print_attribute(self, attribute: Attribute) -> None: if isinstance(attribute, UnitAttr): + self.print("unit") return if isinstance(attribute, LocationAttr):