From 8f2b707d026597018333ac60e707e5ab78c25a91 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Thu, 23 Jul 2020 18:35:18 +0200 Subject: Initial conversion to pybind11 --- ice40/arch_pybindings.cc | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) (limited to 'ice40/arch_pybindings.cc') diff --git a/ice40/arch_pybindings.cc b/ice40/arch_pybindings.cc index 9dd17f01..9011d1dc 100644 --- a/ice40/arch_pybindings.cc +++ b/ice40/arch_pybindings.cc @@ -26,12 +26,12 @@ NEXTPNR_NAMESPACE_BEGIN -void arch_wrap_python() +void arch_wrap_python(py::module &m) { using namespace PythonConversion; - class_("ArchArgs").def_readwrite("type", &ArchArgs::type); + py::class_(m, "ArchArgs").def_readwrite("type", &ArchArgs::type); - enum_().type)>("iCE40Type") + py::enum_().type)>(m, "iCE40Type") .value("NONE", ArchArgs::NONE) .value("LP384", ArchArgs::LP384) .value("LP1K", ArchArgs::LP1K) @@ -47,16 +47,14 @@ void arch_wrap_python() .value("U4K", ArchArgs::U4K) .export_values(); - class_("BelId").def_readwrite("index", &BelId::index); + py::class_(m, "BelId").def_readwrite("index", &BelId::index); - class_("WireId").def_readwrite("index", &WireId::index); + py::class_(m, "WireId").def_readwrite("index", &WireId::index); - class_("PipId").def_readwrite("index", &PipId::index); + py::class_(m, "PipId").def_readwrite("index", &PipId::index); - class_("BelPin").def_readwrite("bel", &BelPin::bel).def_readwrite("pin", &BelPin::pin); - - auto arch_cls = class_, boost::noncopyable>("Arch", init()); - auto ctx_cls = class_, boost::noncopyable>("Context", no_init) + auto arch_cls = py::class_(m, "Arch").def(py::init()); + auto ctx_cls = py::class_(m, "Context") .def("checksum", &Context::checksum) .def("pack", &Context::pack) .def("place", &Context::place) @@ -70,21 +68,21 @@ void arch_wrap_python() typedef std::unordered_map AliasMap; typedef std::unordered_map HierarchyMap; - auto belpin_cls = class_>("BelPin", no_init); + auto belpin_cls = py::class_>(m, "BelPin"); readonly_wrapper>::def_wrap(belpin_cls, "bel"); readonly_wrapper>::def_wrap(belpin_cls, "pin"); #include "arch_pybindings_shared.h" - WRAP_RANGE(Bel, conv_to_str); - WRAP_RANGE(Wire, conv_to_str); - WRAP_RANGE(AllPip, conv_to_str); - WRAP_RANGE(Pip, conv_to_str); - WRAP_RANGE(BelPin, wrap_context); + WRAP_RANGE(m, Bel, conv_to_str); + WRAP_RANGE(m, Wire, conv_to_str); + WRAP_RANGE(m, AllPip, conv_to_str); + WRAP_RANGE(m, Pip, conv_to_str); + WRAP_RANGE(m, BelPin, wrap_context); - WRAP_MAP_UPTR(CellMap, "IdCellMap"); - WRAP_MAP_UPTR(NetMap, "IdNetMap"); - WRAP_MAP(HierarchyMap, wrap_context, "HierarchyMap"); + WRAP_MAP_UPTR(m, CellMap, "IdCellMap"); + WRAP_MAP_UPTR(m, NetMap, "IdNetMap"); + WRAP_MAP(m, HierarchyMap, wrap_context, "HierarchyMap"); } NEXTPNR_NAMESPACE_END -- cgit v1.2.3