diff options
| author | David Shah <davey1576@gmail.com> | 2018-07-04 14:44:45 +0200 | 
|---|---|---|
| committer | David Shah <davey1576@gmail.com> | 2018-07-04 14:55:24 +0200 | 
| commit | 46db5001234ff42cd5b94407c2122bbf0b2994df (patch) | |
| tree | 51052f7886134407c8db44dd6ab596ff7e63b663 /common/pybindings.cc | |
| parent | 79e91368f901343c7f0c88d5841ae231432a4c0b (diff) | |
| download | nextpnr-46db5001234ff42cd5b94407c2122bbf0b2994df.tar.gz nextpnr-46db5001234ff42cd5b94407c2122bbf0b2994df.tar.bz2 nextpnr-46db5001234ff42cd5b94407c2122bbf0b2994df.zip  | |
python: More design-related bindings, dump_design.py working again
Signed-off-by: David Shah <davey1576@gmail.com>
Diffstat (limited to 'common/pybindings.cc')
| -rw-r--r-- | common/pybindings.cc | 70 | 
1 files changed, 49 insertions, 21 deletions
diff --git a/common/pybindings.cc b/common/pybindings.cc index a85c5fe2..9bca307c 100644 --- a/common/pybindings.cc +++ b/common/pybindings.cc @@ -82,43 +82,71 @@ BOOST_PYTHON_MODULE(MODULE_NAME)              .def_readwrite("y2", &GraphicElement::y2)              .def_readwrite("text", &GraphicElement::text); -    class_<PortRef>("PortRef").def_readwrite("cell", &PortRef::cell).def_readwrite("port", &PortRef::port); - -    class_<NetInfo, NetInfo *, boost::noncopyable>("NetInfo") -            .def_readwrite("name", &NetInfo::name) -            .def_readwrite("driver", &NetInfo::driver) -            .def_readwrite("users", &NetInfo::users) -            .def_readwrite("attrs", &NetInfo::attrs) -            .def_readwrite("wires", &NetInfo::wires); - -    // WRAP_MAP(decltype(NetInfo::attrs), "IdStrMap"); - -    class_<std::vector<PortRef>>("PortRefVector").def(vector_indexing_suite<std::vector<PortRef>>()); -      enum_<PortType>("PortType")              .value("PORT_IN", PORT_IN)              .value("PORT_OUT", PORT_OUT)              .value("PORT_INOUT", PORT_INOUT)              .export_values(); -    class_<PortInfo>("PortInfo") -            .def_readwrite("name", &PortInfo::name) -            .def_readwrite("net", &PortInfo::net) -            .def_readwrite("type", &PortInfo::type); +    typedef std::unordered_map<IdString, std::string> AttrMap; +    typedef std::unordered_map<IdString, PortInfo> PortMap; +    typedef std::unordered_map<IdString, IdString> PinMap;      class_<BaseCtx, BaseCtx *, boost::noncopyable>("BaseCtx", no_init); -    typedef std::unordered_map<IdString, std::string> AttrMap; -      auto ci_cls = class_<ContextualWrapper<CellInfo &>>("CellInfo", no_init); -    readonly_wrapper<CellInfo &, typeof(&CellInfo::type), &CellInfo::type, conv_to_str<IdString>>::def_wrap(ci_cls, -                                                                                                            "type"); +    readwrite_wrapper<CellInfo &, typeof(&CellInfo::name), &CellInfo::name, conv_to_str<IdString>, +                      conv_from_str<IdString>>::def_wrap(ci_cls, "name"); +    readwrite_wrapper<CellInfo &, typeof(&CellInfo::type), &CellInfo::type, conv_to_str<IdString>, +                      conv_from_str<IdString>>::def_wrap(ci_cls, "type");      readonly_wrapper<CellInfo &, typeof(&CellInfo::attrs), &CellInfo::attrs, wrap_context<AttrMap &>>::def_wrap(              ci_cls, "attrs"); +    readonly_wrapper<CellInfo &, typeof(&CellInfo::params), &CellInfo::params, wrap_context<AttrMap &>>::def_wrap( +            ci_cls, "params"); +    readonly_wrapper<CellInfo &, typeof(&CellInfo::ports), &CellInfo::ports, wrap_context<PortMap &>>::def_wrap( +            ci_cls, "ports"); +    readwrite_wrapper<CellInfo &, typeof(&CellInfo::bel), &CellInfo::bel, conv_to_str<BelId>, +                      conv_from_str<BelId>>::def_wrap(ci_cls, "bel"); +    readwrite_wrapper<CellInfo &, typeof(&CellInfo::belStrength), &CellInfo::belStrength, pass_through<PlaceStrength>, +                      pass_through<PlaceStrength>>::def_wrap(ci_cls, "belStrength"); +    readonly_wrapper<CellInfo &, typeof(&CellInfo::pins), &CellInfo::pins, wrap_context<PinMap &>>::def_wrap(ci_cls, +                                                                                                             "pins"); + +    auto pi_cls = class_<ContextualWrapper<PortInfo &>>("PortInfo", no_init); +    readwrite_wrapper<PortInfo &, typeof(&PortInfo::name), &PortInfo::name, conv_to_str<IdString>, +                      conv_from_str<IdString>>::def_wrap(pi_cls, "name"); +    readonly_wrapper<PortInfo &, typeof(&PortInfo::net), &PortInfo::net, deref_and_wrap<NetInfo>>::def_wrap(pi_cls, +                                                                                                            "net"); +    readwrite_wrapper<PortInfo &, typeof(&PortInfo::type), &PortInfo::type, pass_through<PortType>, +                      pass_through<PortType>>::def_wrap(pi_cls, "type"); + +    typedef std::vector<PortRef> PortVector; +    typedef std::unordered_map<WireId, PipMap> WireMap; + +    auto ni_cls = class_<ContextualWrapper<NetInfo &>>("NetInfo", no_init); +    readwrite_wrapper<NetInfo &, typeof(&NetInfo::name), &NetInfo::name, conv_to_str<IdString>, +                      conv_from_str<IdString>>::def_wrap(ni_cls, "name"); +    readwrite_wrapper<NetInfo &, typeof(&NetInfo::driver), &NetInfo::driver, wrap_context<PortRef &>, +                      unwrap_context<PortRef &>>::def_wrap(ni_cls, "driver"); +    readonly_wrapper<NetInfo &, typeof(&NetInfo::users), &NetInfo::users, wrap_context<PortVector &>>::def_wrap( +            ni_cls, "users"); +    readonly_wrapper<NetInfo &, typeof(&NetInfo::wires), &NetInfo::wires, wrap_context<WireMap &>>::def_wrap(ni_cls, +                                                                                                             "wires"); + +    auto pr_cls = class_<ContextualWrapper<PortRef &>>("PortRef", no_init); +    readonly_wrapper<PortRef &, typeof(&PortRef::cell), &PortRef::cell, deref_and_wrap<CellInfo>>::def_wrap(pr_cls, +                                                                                                            "cell"); +    readwrite_wrapper<PortRef &, typeof(&PortRef::port), &PortRef::port, conv_to_str<IdString>, +                      conv_from_str<IdString>>::def_wrap(pr_cls, "port"); +    readwrite_wrapper<PortRef &, typeof(&PortRef::budget), &PortRef::budget, pass_through<delay_t>, +                      pass_through<delay_t>>::def_wrap(pr_cls, "budget"); +      def("parse_json", parse_json_shim);      def("load_design", load_design_shim, return_value_policy<manage_new_object>());      WRAP_MAP(AttrMap, pass_through<std::string>, "AttrMap"); +    WRAP_MAP(PortMap, wrap_context<PortInfo &>, "PortMap"); +    WRAP_MAP(PinMap, conv_to_str<IdString>, "PinMap");      arch_wrap_python();  }  | 
