Skip to content

Commit

Permalink
Allow to parse types where attributes are expected (#415)
Browse files Browse the repository at this point in the history
  • Loading branch information
math-fehr authored Feb 7, 2023
1 parent 30073f5 commit eea6141
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/filecheck/mlir-conversion/builtin_attrs.mlir
Original file line number Diff line number Diff line change
Expand Up @@ -148,5 +148,16 @@

// CHECK: dense_resource<resource_1> : tensor<1xi32>

"func.func"() ({}) {function_type = () -> (),
type_attr = index,
sym_name = "memref"} : () -> ()

// CHECK: "type_attr" = index

"func.func"() ({}) {function_type = () -> (),
type_attr = !index,
sym_name = "memref"} : () -> ()

// CHECK: "type_attr" = index

}) : () -> ()
6 changes: 6 additions & 0 deletions xdsl/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -1665,6 +1665,12 @@ def parse_attribute(self) -> Attribute:

return value

# In MLIR, a type can be parsed at any attribute location.
# While MLIR wraps the type in a `TypeAttr`, we do not require this
# in xDSL.
if (type := self.try_parse_type()) is not None:
return type

# If it isn't a dialect attr, parse builtin
builtin_val = self.try_parse_builtin_attr()

Expand Down

0 comments on commit eea6141

Please sign in to comment.