diff --git a/common/pybindings.cc b/common/pybindings.cc index 02928e36..6cae889d 100644 --- a/common/pybindings.cc +++ b/common/pybindings.cc @@ -154,12 +154,19 @@ BOOST_PYTHON_MODULE(MODULE_NAME) readwrite_wrapper, pass_through>::def_wrap(pr_cls, "budget"); + auto pm_cls = class_>("PipMap", no_init); + readwrite_wrapper, + conv_from_str>::def_wrap(pm_cls, "pip"); + readwrite_wrapper, + pass_through>::def_wrap(pm_cls, "strength"); + def("parse_json", parse_json_shim); def("load_design", load_design_shim, return_value_policy()); WRAP_MAP(AttrMap, pass_through, "AttrMap"); WRAP_MAP(PortMap, wrap_context, "PortMap"); WRAP_MAP(PinMap, conv_to_str, "PinMap"); + WRAP_MAP(WireMap, wrap_context, "WireMap"); WRAP_VECTOR(PortRefVector, wrap_context); diff --git a/ecp5/arch_pybindings.h b/ecp5/arch_pybindings.h index f18b5ff1..9bd7bcdf 100644 --- a/ecp5/arch_pybindings.h +++ b/ecp5/arch_pybindings.h @@ -44,14 +44,36 @@ template <> struct string_converter { WireId from_str(Context *ctx, std::string name) { return ctx->getWireByName(ctx->id(name)); } - std::string to_str(Context *ctx, WireId id) { return ctx->getWireName(id).str(ctx); } + std::string to_str(Context *ctx, WireId id) + { + if (id == WireId()) + throw bad_wrap(); + return ctx->getWireName(id).str(ctx); + } +}; + +template <> struct string_converter +{ + WireId from_str(Context *ctx, std::string name) { return ctx->getWireByName(ctx->id(name)); } + + std::string to_str(Context *ctx, WireId id) + { + if (id == WireId()) + throw bad_wrap(); + return ctx->getWireName(id).str(ctx); + } }; template <> struct string_converter { PipId from_str(Context *ctx, std::string name) { return ctx->getPipByName(ctx->id(name)); } - std::string to_str(Context *ctx, PipId id) { return ctx->getPipName(id).str(ctx); } + std::string to_str(Context *ctx, PipId id) + { + if (id == PipId()) + throw bad_wrap(); + return ctx->getPipName(id).str(ctx); + } }; } // namespace PythonConversion diff --git a/ice40/arch_pybindings.h b/ice40/arch_pybindings.h index 070c2396..eaf3ac97 100644 --- a/ice40/arch_pybindings.h +++ b/ice40/arch_pybindings.h @@ -45,14 +45,36 @@ template <> struct string_converter { WireId from_str(Context *ctx, std::string name) { return ctx->getWireByName(ctx->id(name)); } - std::string to_str(Context *ctx, WireId id) { return ctx->getWireName(id).str(ctx); } + std::string to_str(Context *ctx, WireId id) + { + if (id == WireId()) + throw bad_wrap(); + return ctx->getWireName(id).str(ctx); + } +}; + +template <> struct string_converter +{ + WireId from_str(Context *ctx, std::string name) { return ctx->getWireByName(ctx->id(name)); } + + std::string to_str(Context *ctx, WireId id) + { + if (id == WireId()) + throw bad_wrap(); + return ctx->getWireName(id).str(ctx); + } }; template <> struct string_converter { PipId from_str(Context *ctx, std::string name) { return ctx->getPipByName(ctx->id(name)); } - std::string to_str(Context *ctx, PipId id) { return ctx->getPipName(id).str(ctx); } + std::string to_str(Context *ctx, PipId id) + { + if (id == PipId()) + throw bad_wrap(); + return ctx->getPipName(id).str(ctx); + } }; } // namespace PythonConversion