aboutsummaryrefslogtreecommitdiffstats
path: root/common/pybindings.cc
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2018-11-22 12:35:07 +0000
committerDavid Shah <dave@ds0.me>2018-11-22 12:35:07 +0000
commite48c9e73e7bd30ef49fe3386330337b8a8c02054 (patch)
tree98e0eaa7f406867d539e441b07dcd555b1486e4b /common/pybindings.cc
parent17315901605ed46a5c3b5c743453e054c50013ce (diff)
downloadnextpnr-e48c9e73e7bd30ef49fe3386330337b8a8c02054.tar.gz
nextpnr-e48c9e73e7bd30ef49fe3386330337b8a8c02054.tar.bz2
nextpnr-e48c9e73e7bd30ef49fe3386330337b8a8c02054.zip
python: Add wrapper for vectors to allow Python access to net.users
Signed-off-by: David Shah <dave@ds0.me>
Diffstat (limited to 'common/pybindings.cc')
-rw-r--r--common/pybindings.cc19
1 files changed, 17 insertions, 2 deletions
diff --git a/common/pybindings.cc b/common/pybindings.cc
index 061dfc47..02928e36 100644
--- a/common/pybindings.cc
+++ b/common/pybindings.cc
@@ -68,6 +68,19 @@ void translate_assertfail(const assertion_failure &e)
PyErr_SetString(PyExc_AssertionError, e.what());
}
+namespace PythonConversion {
+template <> struct string_converter<PortRef &>
+{
+ inline PortRef from_str(Context *ctx, std::string name) { NPNR_ASSERT_FALSE("PortRef from_str not implemented"); }
+
+ inline std::string to_str(Context *ctx, const PortRef &pr)
+ {
+ return pr.cell->name.str(ctx) + "." + pr.port.str(ctx);
+ }
+};
+
+} // namespace PythonConversion
+
BOOST_PYTHON_MODULE(MODULE_NAME)
{
register_exception_translator<assertion_failure>(&translate_assertfail);
@@ -120,7 +133,7 @@ BOOST_PYTHON_MODULE(MODULE_NAME)
readwrite_wrapper<PortInfo &, decltype(&PortInfo::type), &PortInfo::type, pass_through<PortType>,
pass_through<PortType>>::def_wrap(pi_cls, "type");
- typedef std::vector<PortRef> PortVector;
+ typedef std::vector<PortRef> PortRefVector;
typedef std::unordered_map<WireId, PipMap> WireMap;
auto ni_cls = class_<ContextualWrapper<NetInfo &>>("NetInfo", no_init);
@@ -128,7 +141,7 @@ BOOST_PYTHON_MODULE(MODULE_NAME)
conv_from_str<IdString>>::def_wrap(ni_cls, "name");
readwrite_wrapper<NetInfo &, decltype(&NetInfo::driver), &NetInfo::driver, wrap_context<PortRef &>,
unwrap_context<PortRef &>>::def_wrap(ni_cls, "driver");
- readonly_wrapper<NetInfo &, decltype(&NetInfo::users), &NetInfo::users, wrap_context<PortVector &>>::def_wrap(
+ readonly_wrapper<NetInfo &, decltype(&NetInfo::users), &NetInfo::users, wrap_context<PortRefVector &>>::def_wrap(
ni_cls, "users");
readonly_wrapper<NetInfo &, decltype(&NetInfo::wires), &NetInfo::wires, wrap_context<WireMap &>>::def_wrap(ni_cls,
"wires");
@@ -148,6 +161,8 @@ BOOST_PYTHON_MODULE(MODULE_NAME)
WRAP_MAP(PortMap, wrap_context<PortInfo &>, "PortMap");
WRAP_MAP(PinMap, conv_to_str<IdString>, "PinMap");
+ WRAP_VECTOR(PortRefVector, wrap_context<PortRef &>);
+
arch_wrap_python();
}