Progress on new wrapper system

Signed-off-by: David Shah <davey1576@gmail.com>
This commit is contained in:
David Shah 2018-07-02 15:29:58 +02:00
parent 65195513eb
commit 4bc12f2ead
3 changed files with 44 additions and 31 deletions

View File

@ -123,7 +123,6 @@ BOOST_PYTHON_MODULE(MODULE_NAME)
.def(self == self); .def(self == self);
arch_wrap_python(); arch_wrap_python();
class_<Context, Context *, bases<Arch>, boost::noncopyable>("Context", no_init).def("checksum", &Context::checksum);
} }
static wchar_t *program; static wchar_t *program;

View File

@ -122,7 +122,9 @@ template <typename Class, typename FuncT, FuncT fn, typename rv_conv, typename a
static conv_result_type wrapped_fn(class_type &cls, conv_arg1_type arg1) static conv_result_type wrapped_fn(class_type &cls, conv_arg1_type arg1)
{ {
return rv_conv()(get_base(cls).ctx, get_base(cls).*fn(arg1_conv()(get_ctx(cls), arg1))); Context *ctx = get_ctx<Class>(cls);
Class &base = get_base<Class>(cls);
return rv_conv()(ctx, (base.*fn)(arg1_conv()(ctx, arg1)));
} }
template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); } template <typename WrapCls> static void def_wrap(WrapCls cls_, const char *name) { cls_.def(name, wrapped_fn); }

View File

@ -27,18 +27,24 @@ NEXTPNR_NAMESPACE_BEGIN
namespace PythonConversion { namespace PythonConversion {
template <> struct string_converter<BelId> template<>
struct string_converter<BelId>
{ {
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<BelType> template<>
struct string_converter<BelType>
{ {
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 } // namespace PythonConversion
@ -68,34 +74,40 @@ void arch_wrap_python()
enum_<PortPin>("PortPin") enum_<PortPin>("PortPin")
#define X(t) .value("PIN_" #t, PIN_##t) #define X(t) .value("PIN_" #t, PIN_##t)
#include "portpins.inc" #include "portpins.inc"
; ;
#undef X #undef X
auto arch_cls = class_<Arch, Arch *, bases<BaseCtx>, boost::noncopyable>("Arch", init<ArchArgs>()) auto arch_cls = class_<Arch, Arch *, bases<BaseCtx>, boost::noncopyable>("Arch", init<ArchArgs>());
.def("getBelByName", &Arch::getBelByName) auto ctx_cls = class_<Context, Context *, bases<Arch>, boost::noncopyable>("Context", no_init).def("checksum",
.def("getWireByName", &Arch::getWireByName) &Context::checksum);
.def("getBelName", &Arch::getBelName) fn_wrapper<Context, typeof(&Context::getBelType), &Context::getBelType, conv_to_str<BelType>,
.def("getWireName", &Arch::getWireName) conv_from_str<BelId>>::def_wrap(ctx_cls, "getBelType");
.def("getBels", &Arch::getBels)
.def("getWireBelPin", &Arch::getWireBelPin) /*
.def("getBelPinUphill", &Arch::getBelPinUphill) .def("getBelByName", &Arch::getBelByName)
.def("getBelPinsDownhill", &Arch::getBelPinsDownhill) .def("getWireByName", &Arch::getWireByName)
.def("getWires", &Arch::getWires) .def("getBelName", &Arch::getBelName)
.def("getPipByName", &Arch::getPipByName) .def("getWireName", &Arch::getWireName)
.def("getPipName", &Arch::getPipName) .def("getBels", &Arch::getBels)
.def("getPips", &Arch::getPips) .def("getWireBelPin", &Arch::getWireBelPin)
.def("getPipSrcWire", &Arch::getPipSrcWire) .def("getBelPinUphill", &Arch::getBelPinUphill)
.def("getPipDstWire", &Arch::getPipDstWire) .def("getBelPinsDownhill", &Arch::getBelPinsDownhill)
.def("getPipDelay", &Arch::getPipDelay) .def("getWires", &Arch::getWires)
.def("getPipsDownhill", &Arch::getPipsDownhill) .def("getPipByName", &Arch::getPipByName)
.def("getPipsUphill", &Arch::getPipsUphill) .def("getPipName", &Arch::getPipName)
.def("getWireAliases", &Arch::getWireAliases) .def("getPips", &Arch::getPips)
.def("estimatePosition", &Arch::estimatePosition) .def("getPipSrcWire", &Arch::getPipSrcWire)
.def("estimateDelay", &Arch::estimateDelay); .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<Arch, typeof(&Arch::getBelType), &Arch::getBelType, conv_from_str<BelId>,
conv_to_str<BelType>>::def_wrap(arch_cls, "getBelType");*/
WRAP_RANGE(Bel); WRAP_RANGE(Bel);
WRAP_RANGE(BelPin); WRAP_RANGE(BelPin);