26 #ifdef CIRCT_INCLUDE_TESTS
33 #include "mlir-c/Bindings/Python/Interop.h"
34 #include "mlir-c/IR.h"
35 #include "mlir-c/Transforms.h"
36 #include "mlir/Bindings/Python/PybindAdaptors.h"
38 #include "llvm-c/ErrorHandling.h"
39 #include "llvm/Support/Signals.h"
42 #include <pybind11/pybind11.h>
55 mlirRegisterConversionPasses();
56 mlirRegisterTransformsPasses();
60 m.doc() =
"CIRCT Python Native Extension";
62 llvm::sys::PrintStackTraceOnErrorSignal(
"");
63 LLVMEnablePrettyStackTrace();
67 [](py::object capsule) {
69 auto wrappedCapsule = capsule.attr(MLIR_PYTHON_CAPI_PTR_ATTR);
70 MlirContext context = mlirPythonCapsuleToContext(wrappedCapsule.ptr());
73 MlirDialectHandle
comb = mlirGetDialectHandle__comb__();
74 mlirDialectHandleRegisterDialect(
comb, context);
75 mlirDialectHandleLoadDialect(
comb, context);
77 MlirDialectHandle
debug = mlirGetDialectHandle__debug__();
78 mlirDialectHandleRegisterDialect(
debug, context);
79 mlirDialectHandleLoadDialect(
debug, context);
81 MlirDialectHandle
emit = mlirGetDialectHandle__emit__();
82 mlirDialectHandleRegisterDialect(
emit, context);
83 mlirDialectHandleLoadDialect(
emit, context);
85 MlirDialectHandle
esi = mlirGetDialectHandle__esi__();
86 mlirDialectHandleRegisterDialect(
esi, context);
87 mlirDialectHandleLoadDialect(
esi, context);
89 MlirDialectHandle
msft = mlirGetDialectHandle__msft__();
90 mlirDialectHandleRegisterDialect(
msft, context);
91 mlirDialectHandleLoadDialect(
msft, context);
93 MlirDialectHandle
hw = mlirGetDialectHandle__hw__();
94 mlirDialectHandleRegisterDialect(
hw, context);
95 mlirDialectHandleLoadDialect(
hw, context);
97 MlirDialectHandle
hwarith = mlirGetDialectHandle__hwarith__();
98 mlirDialectHandleRegisterDialect(
hwarith, context);
99 mlirDialectHandleLoadDialect(
hwarith, context);
101 MlirDialectHandle
om = mlirGetDialectHandle__om__();
102 mlirDialectHandleRegisterDialect(
om, context);
103 mlirDialectHandleLoadDialect(
om, context);
105 MlirDialectHandle
rtg = mlirGetDialectHandle__rtg__();
106 mlirDialectHandleRegisterDialect(
rtg, context);
107 mlirDialectHandleLoadDialect(
rtg, context);
109 #ifdef CIRCT_INCLUDE_TESTS
110 MlirDialectHandle
rtgtest = mlirGetDialectHandle__rtgtest__();
111 mlirDialectHandleRegisterDialect(
rtgtest, context);
112 mlirDialectHandleLoadDialect(
rtgtest, context);
115 MlirDialectHandle
seq = mlirGetDialectHandle__seq__();
116 mlirDialectHandleRegisterDialect(
seq, context);
117 mlirDialectHandleLoadDialect(
seq, context);
119 MlirDialectHandle
sv = mlirGetDialectHandle__sv__();
120 mlirDialectHandleRegisterDialect(
sv, context);
121 mlirDialectHandleLoadDialect(
sv, context);
123 MlirDialectHandle
fsm = mlirGetDialectHandle__fsm__();
124 mlirDialectHandleRegisterDialect(
fsm, context);
125 mlirDialectHandleLoadDialect(
fsm, context);
127 MlirDialectHandle
handshake = mlirGetDialectHandle__handshake__();
128 mlirDialectHandleRegisterDialect(
handshake, context);
129 mlirDialectHandleLoadDialect(
handshake, context);
131 MlirDialectHandle
ltl = mlirGetDialectHandle__ltl__();
132 mlirDialectHandleRegisterDialect(
ltl, context);
133 mlirDialectHandleLoadDialect(
ltl, context);
135 MlirDialectHandle
verif = mlirGetDialectHandle__verif__();
136 mlirDialectHandleRegisterDialect(
verif, context);
137 mlirDialectHandleLoadDialect(
verif, context);
139 "Register CIRCT dialects on a PyMlirContext.");
141 m.def(
"export_verilog", [](MlirModule mod, py::object fileObject) {
143 py::gil_scoped_release();
147 m.def(
"export_split_verilog", [](MlirModule mod, std::string directory) {
148 auto cDirectory = mlirStringRefCreateFromCString(directory.c_str());
152 py::module
esi = m.def_submodule(
"_esi",
"ESI API");
154 py::module
msft = m.def_submodule(
"_msft",
"MSFT API");
156 py::module
hw = m.def_submodule(
"_hw",
"HW API");
158 py::module
seq = m.def_submodule(
"_seq",
"Seq API");
160 py::module
om = m.def_submodule(
"_om",
"OM API");
162 py::module
rtg = m.def_submodule(
"_rtg",
"RTG API");
164 py::module rtgtool = m.def_submodule(
"_rtgtool",
"RTGTool API");
166 #ifdef CIRCT_INCLUDE_TESTS
167 py::module
rtgtest = m.def_submodule(
"_rtgtest",
"RTGTest API");
168 circt::python::populateDialectRTGTestSubmodule(
rtgtest);
170 py::module
sv = m.def_submodule(
"_sv",
"SV API");
172 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 registerDCPasses(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 populateDialectRTGToolSubmodule(pybind11::module &m)
void populateDialectRTGSubmodule(pybind11::module &m)
void populateDialectSVSubmodule(pybind11::module &m)