36 lines · cpp
1//===--- DialectIRDL.cpp - Pybind module for IRDL dialect API support ---===//2//3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.4// See https://llvm.org/LICENSE.txt for license information.5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception6//7//===----------------------------------------------------------------------===//8 9#include "mlir-c/Dialect/IRDL.h"10#include "mlir-c/IR.h"11#include "mlir-c/Support.h"12#include "mlir/Bindings/Python/Nanobind.h"13#include "mlir/Bindings/Python/NanobindAdaptors.h"14 15namespace nb = nanobind;16using namespace mlir;17using namespace mlir::python;18using namespace mlir::python::nanobind_adaptors;19 20static void populateDialectIRDLSubmodule(nb::module_ &m) {21 m.def(22 "load_dialects",23 [](MlirModule module) {24 if (mlirLogicalResultIsFailure(mlirLoadIRDLDialects(module)))25 throw std::runtime_error(26 "failed to load IRDL dialects from the input module");27 },28 nb::arg("module"), "Load IRDL dialects from the given module.");29}30 31NB_MODULE(_mlirDialectsIRDL, m) {32 m.doc() = "MLIR IRDL dialect.";33 34 populateDialectIRDLSubmodule(m);35}36