diff options
author | David Shah <davey1576@gmail.com> | 2018-06-08 15:53:24 +0200 |
---|---|---|
committer | David Shah <davey1576@gmail.com> | 2018-06-08 15:53:24 +0200 |
commit | 57cd67dbc12eb0b46528282958dea7b2d7e5c927 (patch) | |
tree | 15a7fcd450b8dd3a5b1a61bf3107bf8670a04f55 /common/pybindings.cc | |
parent | 5fa79cd2b586d9bb0c872360ff30434f8fcfa5ba (diff) | |
download | nextpnr-57cd67dbc12eb0b46528282958dea7b2d7e5c927.tar.gz nextpnr-57cd67dbc12eb0b46528282958dea7b2d7e5c927.tar.bz2 nextpnr-57cd67dbc12eb0b46528282958dea7b2d7e5c927.zip |
Improving the Python bindings, particularly the map/pair wrappers
Signed-off-by: David Shah <davey1576@gmail.com>
Diffstat (limited to 'common/pybindings.cc')
-rw-r--r-- | common/pybindings.cc | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/common/pybindings.cc b/common/pybindings.cc index 454a571c..24269b55 100644 --- a/common/pybindings.cc +++ b/common/pybindings.cc @@ -21,10 +21,13 @@ #include "chip.h" #include "design.h" #include "emb.h" +#include "jsonparse.h" // include after design.h/chip.h #include "pybindings.h" +#include <fstream> + // Required to determine concatenated module name (which differs for different // archs) #define PASTER(x, y) x##_##y @@ -43,6 +46,24 @@ bool operator==(const PortRef &a, const PortRef &b) return (a.cell == b.cell) && (a.port == b.port); } +// Load a JSON file into a design +void parse_json_shim(std::string filename, Design &d) +{ + std::ifstream inf(filename); + if (!inf) + throw std::runtime_error("failed to open file " + filename); + std::istream *ifp = &inf; + parse_json_file(ifp, filename, &d); +} + +// Create a new Chip and load design from json file +Design load_design_shim(std::string filename, ChipArgs args) +{ + Design d(args); + parse_json_shim(filename, d); + return d; +} + BOOST_PYTHON_MODULE(MODULE_NAME) { class_<GraphicElement>("GraphicElement") @@ -101,6 +122,9 @@ BOOST_PYTHON_MODULE(MODULE_NAME) WRAP_MAP(decltype(Design::nets), "IdNetMap"); WRAP_MAP(decltype(Design::cells), "IdCellMap"); + def("parse_json", parse_json_shim); + def("load_design", load_design_shim); + arch_wrap_python(); } |