From 4bc12f2eadc2c369f38dfa54f086b8aa2c94fd05 Mon Sep 17 00:00:00 2001 From: David Shah Date: Mon, 2 Jul 2018 15:29:58 +0200 Subject: [PATCH] Progress on new wrapper system Signed-off-by: David Shah --- common/pybindings.cc | 1 - common/pywrappers.h | 4 ++- ice40/pybindings.cc | 70 ++++++++++++++++++++++++++------------------ 3 files changed, 44 insertions(+), 31 deletions(-) diff --git a/common/pybindings.cc b/common/pybindings.cc index e9ceca51..329bcf1e 100644 --- a/common/pybindings.cc +++ b/common/pybindings.cc @@ -123,7 +123,6 @@ BOOST_PYTHON_MODULE(MODULE_NAME) .def(self == self); arch_wrap_python(); - class_, boost::noncopyable>("Context", no_init).def("checksum", &Context::checksum); } static wchar_t *program; diff --git a/common/pywrappers.h b/common/pywrappers.h index fe786a3b..5b0146ac 100644 --- a/common/pywrappers.h +++ b/common/pywrappers.h @@ -122,7 +122,9 @@ template (cls); + Class &base = get_base(cls); + return rv_conv()(ctx, (base.*fn)(arg1_conv()(ctx, arg1))); } template static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); } diff --git a/ice40/pybindings.cc b/ice40/pybindings.cc index ea1c5547..3c86f10c 100644 --- a/ice40/pybindings.cc +++ b/ice40/pybindings.cc @@ -27,18 +27,24 @@ NEXTPNR_NAMESPACE_BEGIN namespace PythonConversion { -template <> struct string_converter +template<> +struct string_converter { - BelId from_str(Context *ctx, std::string name) { return ctx->getBelByName(ctx->id(name)); } + BelId from_str(Context *ctx, std::string name) + { return ctx->getBelByName(ctx->id(name)); } - std::string to_str(Context *ctx, BelId id) { return ctx->getBelName(id).str(ctx); } + std::string to_str(Context *ctx, BelId id) + { return ctx->getBelName(id).str(ctx); } }; -template <> struct string_converter +template<> +struct string_converter { - BelType from_str(Context *ctx, std::string name) { return ctx->belTypeFromId(ctx->id(name)); } + BelType from_str(Context *ctx, std::string name) + { return ctx->belTypeFromId(ctx->id(name)); } - std::string to_str(Context *ctx, BelType typ) { return ctx->belTypeToId(typ).str(ctx); } + std::string to_str(Context *ctx, BelType typ) + { return ctx->belTypeToId(typ).str(ctx); } }; } // namespace PythonConversion @@ -68,34 +74,40 @@ void arch_wrap_python() enum_("PortPin") #define X(t) .value("PIN_" #t, PIN_##t) + #include "portpins.inc" ; #undef X - auto arch_cls = class_, boost::noncopyable>("Arch", init()) - .def("getBelByName", &Arch::getBelByName) - .def("getWireByName", &Arch::getWireByName) - .def("getBelName", &Arch::getBelName) - .def("getWireName", &Arch::getWireName) - .def("getBels", &Arch::getBels) - .def("getWireBelPin", &Arch::getWireBelPin) - .def("getBelPinUphill", &Arch::getBelPinUphill) - .def("getBelPinsDownhill", &Arch::getBelPinsDownhill) - .def("getWires", &Arch::getWires) - .def("getPipByName", &Arch::getPipByName) - .def("getPipName", &Arch::getPipName) - .def("getPips", &Arch::getPips) - .def("getPipSrcWire", &Arch::getPipSrcWire) - .def("getPipDstWire", &Arch::getPipDstWire) - .def("getPipDelay", &Arch::getPipDelay) - .def("getPipsDownhill", &Arch::getPipsDownhill) - .def("getPipsUphill", &Arch::getPipsUphill) - .def("getWireAliases", &Arch::getWireAliases) - .def("estimatePosition", &Arch::estimatePosition) - .def("estimateDelay", &Arch::estimateDelay); + auto arch_cls = class_, boost::noncopyable>("Arch", init()); + auto ctx_cls = class_, boost::noncopyable>("Context", no_init).def("checksum", + &Context::checksum); + fn_wrapper, + conv_from_str>::def_wrap(ctx_cls, "getBelType"); + + /* + .def("getBelByName", &Arch::getBelByName) + .def("getWireByName", &Arch::getWireByName) + .def("getBelName", &Arch::getBelName) + .def("getWireName", &Arch::getWireName) + .def("getBels", &Arch::getBels) + .def("getWireBelPin", &Arch::getWireBelPin) + .def("getBelPinUphill", &Arch::getBelPinUphill) + .def("getBelPinsDownhill", &Arch::getBelPinsDownhill) + .def("getWires", &Arch::getWires) + .def("getPipByName", &Arch::getPipByName) + .def("getPipName", &Arch::getPipName) + .def("getPips", &Arch::getPips) + .def("getPipSrcWire", &Arch::getPipSrcWire) + .def("getPipDstWire", &Arch::getPipDstWire) + .def("getPipDelay", &Arch::getPipDelay) + .def("getPipsDownhill", &Arch::getPipsDownhill) + .def("getPipsUphill", &Arch::getPipsUphill) + .def("getWireAliases", &Arch::getWireAliases) + .def("estimatePosition", &Arch::estimatePosition) + .def("estimateDelay", &Arch::estimateDelay); + */ - /*fn_wrapper, - conv_to_str>::def_wrap(arch_cls, "getBelType");*/ WRAP_RANGE(Bel); WRAP_RANGE(BelPin);