aboutsummaryrefslogtreecommitdiffstats
path: root/common/pybindings.h
diff options
context:
space:
mode:
authorDavid Shah <davey1576@gmail.com>2018-06-07 11:41:54 +0200
committerDavid Shah <davey1576@gmail.com>2018-06-07 11:41:54 +0200
commite576f71838290ff12b98145fb02af84563fc03c1 (patch)
tree023a1ac5e0ccacb2257f79f1109ea485818f13eb /common/pybindings.h
parent3769b2058019ce7c6be824085e1047e1beec07dc (diff)
downloadnextpnr-e576f71838290ff12b98145fb02af84563fc03c1.tar.gz
nextpnr-e576f71838290ff12b98145fb02af84563fc03c1.tar.bz2
nextpnr-e576f71838290ff12b98145fb02af84563fc03c1.zip
Developing Python bindings for Design and related types
Diffstat (limited to 'common/pybindings.h')
-rw-r--r--common/pybindings.h52
1 files changed, 3 insertions, 49 deletions
diff --git a/common/pybindings.h b/common/pybindings.h
index 5b2adc6a..3dfadeee 100644
--- a/common/pybindings.h
+++ b/common/pybindings.h
@@ -20,6 +20,9 @@
#ifndef COMMON_PYBINDINGS_H
#define COMMON_PYBINDINGS_H
+
+#include "pycontainers.h"
+
#include <utility>
#include <stdexcept>
#include <boost/python.hpp>
@@ -27,54 +30,6 @@
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
#include <boost/python/suite/indexing/map_indexing_suite.hpp>
using namespace boost::python;
-/*
-A wrapper for a Pythonised nextpnr Iterator. The actual class wrapped is a
-pair<Iterator, Iterator> containing (current, end)
-*/
-
-template<typename T>
-struct iterator_wrapper {
- typedef decltype(*(std::declval<T>())) value_t;
-
- static value_t next(std::pair<T, T> &iter) {
- if (iter.first != iter.second) {
- value_t val = *iter.first;
- ++iter.first;
- return val;
- } else {
- PyErr_SetString(PyExc_StopIteration, "End of range reached");
- boost::python::throw_error_already_set();
- // Should be unreachable, but prevent control may reach end of non-void
- throw std::runtime_error("unreachable");
- }
- }
-
- static void wrap(const char *python_name) {
- class_<std::pair<T, T>>(python_name, no_init)
- .def("__next__", next);
- }
-};
-
-/*
-A wrapper for a nextpnr Range. Ranges should have two functions, begin()
-and end() which return iterator-like objects supporting ++, * and !=
-Full STL iterator semantics are not required, unlike the standard Boost wrappers
-*/
-
-template<typename T>
-struct range_wrapper {
- typedef decltype(std::declval<T>().begin()) iterator_t;
-
- static std::pair<iterator_t, iterator_t> iter(T &range) {
- return std::make_pair(range.begin(), range.end());
- }
-
- static void wrap(const char *range_name, const char *iter_name) {
- class_<T>(range_name, no_init)
- .def("__iter__", iter);
- iterator_wrapper<iterator_t>().wrap(iter_name);
- }
-};
/*
A wrapper to enable custom type/ID to/from string conversions
@@ -124,7 +79,6 @@ template <typename T> struct string_wrapper {
};
};
-#define WRAP_RANGE(t) range_wrapper<t##Range>().wrap(#t "Range", #t "Iterator")
void init_python(const char *executable);
void deinit_python();