27 #include "mlir-c/Bindings/Python/Interop.h"
28 #include "mlir-c/IR.h"
29 #include "mlir-c/Transforms.h"
30 #include "mlir/Bindings/Python/PybindAdaptors.h"
32 #include "llvm-c/ErrorHandling.h"
33 #include "llvm/Support/Signals.h"
36 #include <pybind11/pybind11.h>
46 mlirRegisterConversionPasses();
47 mlirRegisterTransformsPasses();
51 m.doc() =
"CIRCT Python Native Extension";
53 llvm::sys::PrintStackTraceOnErrorSignal(
"");
54 LLVMEnablePrettyStackTrace();
58 [](py::object capsule) {
60 auto wrappedCapsule = capsule.attr(MLIR_PYTHON_CAPI_PTR_ATTR);
61 MlirContext context = mlirPythonCapsuleToContext(wrappedCapsule.ptr());
64 MlirDialectHandle
comb = mlirGetDialectHandle__comb__();
65 mlirDialectHandleRegisterDialect(
comb, context);
66 mlirDialectHandleLoadDialect(
comb, context);
68 MlirDialectHandle
debug = mlirGetDialectHandle__debug__();
69 mlirDialectHandleRegisterDialect(
debug, context);
70 mlirDialectHandleLoadDialect(
debug, context);
72 MlirDialectHandle
emit = mlirGetDialectHandle__emit__();
73 mlirDialectHandleRegisterDialect(
emit, context);
74 mlirDialectHandleLoadDialect(
emit, context);
76 MlirDialectHandle
esi = mlirGetDialectHandle__esi__();
77 mlirDialectHandleRegisterDialect(
esi, context);
78 mlirDialectHandleLoadDialect(
esi, context);
80 MlirDialectHandle
msft = mlirGetDialectHandle__msft__();
81 mlirDialectHandleRegisterDialect(
msft, context);
82 mlirDialectHandleLoadDialect(
msft, context);
84 MlirDialectHandle
hw = mlirGetDialectHandle__hw__();
85 mlirDialectHandleRegisterDialect(
hw, context);
86 mlirDialectHandleLoadDialect(
hw, context);
88 MlirDialectHandle
hwarith = mlirGetDialectHandle__hwarith__();
89 mlirDialectHandleRegisterDialect(
hwarith, context);
90 mlirDialectHandleLoadDialect(
hwarith, context);
92 MlirDialectHandle
om = mlirGetDialectHandle__om__();
93 mlirDialectHandleRegisterDialect(
om, context);
94 mlirDialectHandleLoadDialect(
om, context);
96 MlirDialectHandle
seq = mlirGetDialectHandle__seq__();
97 mlirDialectHandleRegisterDialect(
seq, context);
98 mlirDialectHandleLoadDialect(
seq, context);
100 MlirDialectHandle
sv = mlirGetDialectHandle__sv__();
101 mlirDialectHandleRegisterDialect(
sv, context);
102 mlirDialectHandleLoadDialect(
sv, context);
104 MlirDialectHandle
fsm = mlirGetDialectHandle__fsm__();
105 mlirDialectHandleRegisterDialect(
fsm, context);
106 mlirDialectHandleLoadDialect(
fsm, context);
108 MlirDialectHandle handshake = mlirGetDialectHandle__handshake__();
109 mlirDialectHandleRegisterDialect(handshake, context);
110 mlirDialectHandleLoadDialect(handshake, context);
112 MlirDialectHandle
ltl = mlirGetDialectHandle__ltl__();
113 mlirDialectHandleRegisterDialect(
ltl, context);
114 mlirDialectHandleLoadDialect(
ltl, context);
116 MlirDialectHandle
verif = mlirGetDialectHandle__verif__();
117 mlirDialectHandleRegisterDialect(
verif, context);
118 mlirDialectHandleLoadDialect(
verif, context);
120 "Register CIRCT dialects on a PyMlirContext.");
122 m.def(
"export_verilog", [](MlirModule mod, py::object fileObject) {
124 py::gil_scoped_release();
128 m.def(
"export_split_verilog", [](MlirModule mod, std::string directory) {
129 auto cDirectory = mlirStringRefCreateFromCString(directory.c_str());
133 py::module
esi = m.def_submodule(
"_esi",
"ESI API");
135 py::module
msft = m.def_submodule(
"_msft",
"MSFT API");
137 py::module
hw = m.def_submodule(
"_hw",
"HW API");
139 py::module
seq = m.def_submodule(
"_seq",
"Seq API");
141 py::module
om = m.def_submodule(
"_om",
"OM API");
143 py::module
sv = m.def_submodule(
"_sv",
"SV API");
145 py::module support = m.def_submodule(
"_support",
"CIRCT support");
static void registerPasses()
PYBIND11_MODULE(_circt, m)
MLIR_CAPI_EXPORTED void registerCombPasses(void)
MLIR_CAPI_EXPORTED void registerFSMPasses(void)
MLIR_CAPI_EXPORTED void registerHWArithPasses(void)
MLIR_CAPI_EXPORTED void registerHandshakePasses(void)
MLIR_CAPI_EXPORTED void registerSVPasses(void)
MLIR_CAPI_EXPORTED void registerSeqPasses(void)
MLIR_CAPI_EXPORTED MlirLogicalResult mlirExportSplitVerilog(MlirModule, MlirStringRef)
Emits split Verilog files for the specified module into the given directory.
MLIR_CAPI_EXPORTED MlirLogicalResult mlirExportVerilog(MlirModule, MlirStringCallback, void *userData)
Emits verilog for the specified module using the provided callback and user data.
Taken from PybindUtils.h in MLIR.
MlirStringCallback getCallback()
void populateDialectMSFTSubmodule(pybind11::module &m)
void populateDialectOMSubmodule(pybind11::module &m)
void populateSupportSubmodule(pybind11::module &m)
void populateDialectHWSubmodule(pybind11::module &m)
void populateDialectESISubmodule(pybind11::module &m)
void populateDialectSeqSubmodule(pybind11::module &m)
void populateDialectSVSubmodule(pybind11::module &m)