Skip to content

Commit

Permalink
dialects: (builtin) make FloatAttr a TypedAttribute
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarice committed Nov 20, 2024
1 parent 9e9b34e commit cc1a83d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion xdsl/dialects/builtin.py
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ def __hash__(self):


@irdl_attr_definition
class FloatAttr(Generic[_FloatAttrType], ParametrizedAttribute):
class FloatAttr(Generic[_FloatAttrType], TypedAttribute[_FloatAttrType]):
name = "float"

value: ParameterDef[FloatData]
Expand Down Expand Up @@ -674,6 +674,19 @@ def __init__(
raise ValueError(f"Invalid bitwidth: {type}")
super().__init__([data_attr, type])

@staticmethod
def parse_with_type(
parser: AttrParser,
type: AttributeInvT,
) -> TypedAttribute[AttributeInvT]:
if not isinstance(f := parser.parse_optional_number(), float):
parser.raise_error(f"expected float, got {f}")
assert isinstance(type, AnyFloat)
return FloatAttr(f, type)

def print_without_type(self, printer: Printer):
return printer.print_float(self)


AnyFloatAttr: TypeAlias = FloatAttr[AnyFloat]
AnyFloatAttrConstr: BaseAttr[AnyFloatAttr] = BaseAttr(FloatAttr)
Expand Down

0 comments on commit cc1a83d

Please sign in to comment.