diff options
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(); } |