28 #include "mlir-c/Bindings/Python/Interop.h"
29 #include "mlir-c/IR.h"
30 #include "mlir-c/Transforms.h"
31 #include "mlir/Bindings/Python/PybindAdaptors.h"
33 #include "llvm-c/ErrorHandling.h"
34 #include "llvm/Support/Signals.h"
37 #include <pybind11/pybind11.h>
49 mlirRegisterConversionPasses();
50 mlirRegisterTransformsPasses();
54 m.doc() =
"CIRCT Python Native Extension";
56 llvm::sys::PrintStackTraceOnErrorSignal(
"");
57 LLVMEnablePrettyStackTrace();
61 [](py::object capsule) {
63 auto wrappedCapsule = capsule.attr(MLIR_PYTHON_CAPI_PTR_ATTR);
64 MlirContext context = mlirPythonCapsuleToContext(wrappedCapsule.ptr());
67 MlirDialectHandle
comb = mlirGetDialectHandle__comb__();
68 mlirDialectHandleRegisterDialect(
comb, context);
69 mlirDialectHandleLoadDialect(
comb, context);
71 MlirDialectHandle
debug = mlirGetDialectHandle__debug__();
72 mlirDialectHandleRegisterDialect(
debug, context);
73 mlirDialectHandleLoadDialect(
debug, context);
75 MlirDialectHandle
emit = mlirGetDialectHandle__emit__();
76 mlirDialectHandleRegisterDialect(
emit, context);
77 mlirDialectHandleLoadDialect(
emit, context);
79 MlirDialectHandle
esi = mlirGetDialectHandle__esi__();
80 mlirDialectHandleRegisterDialect(
esi, context);
81 mlirDialectHandleLoadDialect(
esi, context);
83 MlirDialectHandle
msft = mlirGetDialectHandle__msft__();
84 mlirDialectHandleRegisterDialect(
msft, context);
85 mlirDialectHandleLoadDialect(
msft, context);
87 MlirDialectHandle
hw = mlirGetDialectHandle__hw__();
88 mlirDialectHandleRegisterDialect(
hw, context);
89 mlirDialectHandleLoadDialect(
hw, context);
91 MlirDialectHandle
hwarith = mlirGetDialectHandle__hwarith__();
92 mlirDialectHandleRegisterDialect(
hwarith, context);
93 mlirDialectHandleLoadDialect(
hwarith, context);
95 MlirDialectHandle
om = mlirGetDialectHandle__om__();
96 mlirDialectHandleRegisterDialect(
om, context);
97 mlirDialectHandleLoadDialect(
om, context);
99 MlirDialectHandle
seq = mlirGetDialectHandle__seq__();
100 mlirDialectHandleRegisterDialect(
seq, context);
101 mlirDialectHandleLoadDialect(
seq, context);
103 MlirDialectHandle
sv = mlirGetDialectHandle__sv__();
104 mlirDialectHandleRegisterDialect(
sv, context);
105 mlirDialectHandleLoadDialect(
sv, context);
107 MlirDialectHandle
fsm = mlirGetDialectHandle__fsm__();
108 mlirDialectHandleRegisterDialect(
fsm, context);
109 mlirDialectHandleLoadDialect(
fsm, context);
111 MlirDialectHandle
handshake = mlirGetDialectHandle__handshake__();
112 mlirDialectHandleRegisterDialect(
handshake, context);
113 mlirDialectHandleLoadDialect(
handshake, context);
115 MlirDialectHandle
ltl = mlirGetDialectHandle__ltl__();
116 mlirDialectHandleRegisterDialect(
ltl, context);
117 mlirDialectHandleLoadDialect(
ltl, context);
119 MlirDialectHandle
verif = mlirGetDialectHandle__verif__();
120 mlirDialectHandleRegisterDialect(
verif, context);
121 mlirDialectHandleLoadDialect(
verif, context);
123 "Register CIRCT dialects on a PyMlirContext.");
125 m.def(
"export_verilog", [](MlirModule mod, py::object fileObject) {
127 py::gil_scoped_release();
131 m.def(
"export_split_verilog", [](MlirModule mod, std::string directory) {
132 auto cDirectory = mlirStringRefCreateFromCString(directory.c_str());
136 py::module
esi = m.def_submodule(
"_esi",
"ESI API");
138 py::module
msft = m.def_submodule(
"_msft",
"MSFT API");
140 py::module
hw = m.def_submodule(
"_hw",
"HW API");
142 py::module
seq = m.def_submodule(
"_seq",
"Seq API");
144 py::module
om = m.def_submodule(
"_om",
"OM API");
146 py::module
sv = m.def_submodule(
"_sv",
"SV API");
148 py::module support = m.def_submodule(
"_support",
"CIRCT support");
MLIR_CAPI_EXPORTED void registerArcPasses(void)
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 registerHWPasses(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)