xref: /llvm-project/mlir/python/mlir/dialects/builtin.py (revision 537b2aa264c5a9879a80289c8d123b39e520eb15)
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
5from typing import Dict, Optional
6
7from ._builtin_ops_gen import *
8from ._builtin_ops_gen import _Dialect
9from ..extras.meta import region_op
10
11try:
12    from ..ir import *
13    from ._ods_common import _cext as _ods_cext
14except ImportError as e:
15    raise RuntimeError("Error loading imports from extension module") from e
16
17
18@_ods_cext.register_operation(_Dialect, replace=True)
19class ModuleOp(ModuleOp):
20    """Specialization for the module op class."""
21
22    def __init__(self, *, loc=None, ip=None):
23        super().__init__(loc=loc, ip=ip)
24        body = self.regions[0].blocks.append()
25
26    @property
27    def body(self):
28        return self.regions[0].blocks[0]
29
30
31@region_op
32def module(
33    *,
34    sym_name=None,
35    sym_visibility=None,
36    attrs: Optional[Dict[str, Attribute]] = None,
37    loc=None,
38    ip=None,
39):
40    mod = ModuleOp.__base__(
41        sym_name=sym_name, sym_visibility=sym_visibility, loc=loc, ip=ip
42    )
43    if attrs is None:
44        attrs = {}
45    for attr_name, attr in attrs.items():
46        mod.operation.attributes[attr_name] = attr
47
48    return mod
49