aboutsummaryrefslogtreecommitdiffstats
path: root/common/pybindings.cc
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2019-03-31 12:34:26 +0100
committerDavid Shah <dave@ds0.me>2019-04-02 15:30:01 +0100
commitf5bfd557b625d1b5349c4a8305eccec30bafbe69 (patch)
tree6e921679a0dca0be857f68214c3f6fb52e24a5a8 /common/pybindings.cc
parent2e246c196895a3bb211278d9405e8ea7e886eaa9 (diff)
downloadnextpnr-f5bfd557b625d1b5349c4a8305eccec30bafbe69.tar.gz
nextpnr-f5bfd557b625d1b5349c4a8305eccec30bafbe69.tar.bz2
nextpnr-f5bfd557b625d1b5349c4a8305eccec30bafbe69.zip
python: Infrastructure for generic arch Python API
Signed-off-by: David Shah <dave@ds0.me>
Diffstat (limited to 'common/pybindings.cc')
-rw-r--r--common/pybindings.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/common/pybindings.cc b/common/pybindings.cc
index eee78b5e..dad8e5c7 100644
--- a/common/pybindings.cc
+++ b/common/pybindings.cc
@@ -81,6 +81,34 @@ template <> struct string_converter<PortRef &>
} // namespace PythonConversion
+struct loc_from_tuple
+{
+ loc_from_tuple() { converter::registry::push_back(&convertible, &construct, boost::python::type_id<Loc>()); }
+
+ static void *convertible(PyObject *obj_ptr)
+ {
+ if (!PyTuple_Check(obj_ptr))
+ return 0;
+ return obj_ptr;
+ }
+
+ static void construct(PyObject *obj_ptr, converter::rvalue_from_python_stage1_data *data)
+ {
+ int val[3];
+ for (int i = 0; i < 3; i++) {
+ PyObject *pyo = PyTuple_GetItem(obj_ptr, i);
+ if (!pyo)
+ throw_error_already_set();
+ NPNR_ASSERT(PyLong_Check(pyo));
+ val[i] = int(PyLong_AsLong(pyo));
+ }
+
+ void *storage = ((converter::rvalue_from_python_storage<Loc> *)data)->storage.bytes;
+ new (storage) Loc(val[0], val[1], val[2]);
+ data->convertible = storage;
+ }
+};
+
BOOST_PYTHON_MODULE(MODULE_NAME)
{
register_exception_translator<assertion_failure>(&translate_assertfail);
@@ -108,6 +136,9 @@ BOOST_PYTHON_MODULE(MODULE_NAME)
class_<BaseCtx, BaseCtx *, boost::noncopyable>("BaseCtx", no_init);
+ auto loc_cls =
+ class_<Loc>("Loc").def_readwrite("x", &Loc::x).def_readwrite("y", &Loc::y).def_readwrite("z", &Loc::z);
+
auto ci_cls = class_<ContextualWrapper<CellInfo &>>("CellInfo", no_init);
readwrite_wrapper<CellInfo &, decltype(&CellInfo::name), &CellInfo::name, conv_to_str<IdString>,
conv_from_str<IdString>>::def_wrap(ci_cls, "name");