|
| 1 | +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 2 | +# See https://llvm.org/LICENSE.txt for license information. |
| 3 | +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
| 4 | + |
| 5 | +from ._irdl_ops_gen import * |
| 6 | +from ._irdl_ops_gen import _Dialect |
| 7 | +from ._irdl_enum_gen import * |
| 8 | +from .._mlir_libs._mlirDialectsIRDL import * |
| 9 | +from ..ir import register_attribute_builder |
| 10 | +from ._ods_common import _cext as _ods_cext |
| 11 | +from typing import Union, Sequence |
| 12 | + |
| 13 | +_ods_ir = _ods_cext.ir |
| 14 | + |
| 15 | + |
| 16 | +@_ods_cext.register_operation(_Dialect, replace=True) |
| 17 | +class DialectOp(DialectOp): |
| 18 | + __doc__ = DialectOp.__doc__ |
| 19 | + |
| 20 | + def __init__(self, sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None): |
| 21 | + super().__init__(sym_name, loc=loc, ip=ip) |
| 22 | + self.regions[0].blocks.append() |
| 23 | + |
| 24 | + @property |
| 25 | + def body(self) -> _ods_ir.Block: |
| 26 | + return self.regions[0].blocks[0] |
| 27 | + |
| 28 | + |
| 29 | +def dialect(sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None) -> DialectOp: |
| 30 | + return DialectOp(sym_name=sym_name, loc=loc, ip=ip) |
| 31 | + |
| 32 | + |
| 33 | +@_ods_cext.register_operation(_Dialect, replace=True) |
| 34 | +class OperationOp(OperationOp): |
| 35 | + __doc__ = OperationOp.__doc__ |
| 36 | + |
| 37 | + def __init__(self, sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None): |
| 38 | + super().__init__(sym_name, loc=loc, ip=ip) |
| 39 | + self.regions[0].blocks.append() |
| 40 | + |
| 41 | + @property |
| 42 | + def body(self) -> _ods_ir.Block: |
| 43 | + return self.regions[0].blocks[0] |
| 44 | + |
| 45 | + |
| 46 | +def operation_( |
| 47 | + sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None |
| 48 | +) -> OperationOp: |
| 49 | + return OperationOp(sym_name=sym_name, loc=loc, ip=ip) |
| 50 | + |
| 51 | + |
| 52 | +@_ods_cext.register_operation(_Dialect, replace=True) |
| 53 | +class TypeOp(TypeOp): |
| 54 | + __doc__ = TypeOp.__doc__ |
| 55 | + |
| 56 | + def __init__(self, sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None): |
| 57 | + super().__init__(sym_name, loc=loc, ip=ip) |
| 58 | + self.regions[0].blocks.append() |
| 59 | + |
| 60 | + @property |
| 61 | + def body(self) -> _ods_ir.Block: |
| 62 | + return self.regions[0].blocks[0] |
| 63 | + |
| 64 | + |
| 65 | +def type_(sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None) -> TypeOp: |
| 66 | + return TypeOp(sym_name=sym_name, loc=loc, ip=ip) |
| 67 | + |
| 68 | + |
| 69 | +@_ods_cext.register_operation(_Dialect, replace=True) |
| 70 | +class AttributeOp(AttributeOp): |
| 71 | + __doc__ = AttributeOp.__doc__ |
| 72 | + |
| 73 | + def __init__(self, sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None): |
| 74 | + super().__init__(sym_name, loc=loc, ip=ip) |
| 75 | + self.regions[0].blocks.append() |
| 76 | + |
| 77 | + @property |
| 78 | + def body(self) -> _ods_ir.Block: |
| 79 | + return self.regions[0].blocks[0] |
| 80 | + |
| 81 | + |
| 82 | +def attribute( |
| 83 | + sym_name: Union[str, _ods_ir.Attribute], *, loc=None, ip=None |
| 84 | +) -> AttributeOp: |
| 85 | + return AttributeOp(sym_name=sym_name, loc=loc, ip=ip) |
| 86 | + |
| 87 | + |
| 88 | +@register_attribute_builder("VariadicityArrayAttr") |
| 89 | +def _variadicity_array_attr(x: Sequence[Variadicity], context) -> _ods_ir.Attribute: |
| 90 | + return _ods_ir.Attribute.parse( |
| 91 | + f"#irdl<variadicity_array [{', '.join(str(i) for i in x)}]>", context |
| 92 | + ) |
0 commit comments