aboutsummaryrefslogtreecommitdiff
path: root/mlir/lib/Bindings/Python/DialectIRDL.cpp
blob: 08bcab97c03ecea6258084bd602ea72ef8343089 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//===--- DialectIRDL.cpp - Pybind module for IRDL dialect API support ---===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//

#include "mlir-c/Dialect/IRDL.h"
#include "mlir-c/IR.h"
#include "mlir-c/Support.h"
#include "mlir/Bindings/Python/Nanobind.h"
#include "mlir/Bindings/Python/NanobindAdaptors.h"

namespace nb = nanobind;
using namespace mlir;
using namespace mlir::python;
using namespace mlir::python::nanobind_adaptors;

static void populateDialectIRDLSubmodule(nb::module_ &m) {
  m.def(
      "load_dialects",
      [](MlirModule module) {
        if (mlirLogicalResultIsFailure(mlirLoadIRDLDialects(module)))
          throw std::runtime_error(
              "failed to load IRDL dialects from the input module");
      },
      nb::arg("module"), "Load IRDL dialects from the given module.");
}

NB_MODULE(_mlirDialectsIRDL, m) {
  m.doc() = "MLIR IRDL dialect.";

  populateDialectIRDLSubmodule(m);
}