From c2299c8972e0cd22641d7d3b8e0bf7c19a42c3cb Mon Sep 17 00:00:00 2001 From: David Shah Date: Sun, 15 Sep 2019 15:59:16 +0100 Subject: [PATCH] python: Fix getWireBelPins Fixes #327 Signed-off-by: David Shah --- ecp5/arch_pybindings.cc | 5 +++++ ecp5/arch_pybindings.h | 15 +++++++++++++++ ice40/arch_pybindings.cc | 5 +++++ ice40/arch_pybindings.h | 15 +++++++++++++++ 4 files changed, 40 insertions(+) diff --git a/ecp5/arch_pybindings.cc b/ecp5/arch_pybindings.cc index 275956f3..e131826c 100644 --- a/ecp5/arch_pybindings.cc +++ b/ecp5/arch_pybindings.cc @@ -146,10 +146,15 @@ void arch_wrap_python() fn_wrapper_2a_v, conv_from_str>::def_wrap(ctx_cls, "constrainCellToRegion"); + auto belpin_cls = class_>("BelPin", no_init); + readonly_wrapper>::def_wrap(belpin_cls, "bel"); + readonly_wrapper>::def_wrap(belpin_cls, "pin"); + WRAP_RANGE(Bel, conv_to_str); WRAP_RANGE(Wire, conv_to_str); WRAP_RANGE(AllPip, conv_to_str); WRAP_RANGE(Pip, conv_to_str); + WRAP_RANGE(BelPin, wrap_context); WRAP_MAP_UPTR(CellMap, "IdCellMap"); WRAP_MAP_UPTR(NetMap, "IdNetMap"); diff --git a/ecp5/arch_pybindings.h b/ecp5/arch_pybindings.h index 9bd7bcdf..cf343976 100644 --- a/ecp5/arch_pybindings.h +++ b/ecp5/arch_pybindings.h @@ -76,6 +76,21 @@ template <> struct string_converter } }; +template <> struct string_converter +{ + BelPin from_str(Context *ctx, std::string name) + { + NPNR_ASSERT_FALSE("string_converter::from_str not implemented"); + } + + std::string to_str(Context *ctx, BelPin pin) + { + if (pin.bel == BelId()) + throw bad_wrap(); + return ctx->getBelName(pin.bel).str(ctx) + "/" + pin.pin.str(ctx); + } +}; + } // namespace PythonConversion NEXTPNR_NAMESPACE_END diff --git a/ice40/arch_pybindings.cc b/ice40/arch_pybindings.cc index 194d7c6d..a9aaeb83 100644 --- a/ice40/arch_pybindings.cc +++ b/ice40/arch_pybindings.cc @@ -157,10 +157,15 @@ void arch_wrap_python() fn_wrapper_2a_v, conv_from_str>::def_wrap(ctx_cls, "constrainCellToRegion"); + auto belpin_cls = class_>("BelPin", no_init); + readonly_wrapper>::def_wrap(belpin_cls, "bel"); + readonly_wrapper>::def_wrap(belpin_cls, "pin"); + WRAP_RANGE(Bel, conv_to_str); WRAP_RANGE(Wire, conv_to_str); WRAP_RANGE(AllPip, conv_to_str); WRAP_RANGE(Pip, conv_to_str); + WRAP_RANGE(BelPin, wrap_context); WRAP_MAP_UPTR(CellMap, "IdCellMap"); WRAP_MAP_UPTR(NetMap, "IdNetMap"); diff --git a/ice40/arch_pybindings.h b/ice40/arch_pybindings.h index eaf3ac97..7c15b269 100644 --- a/ice40/arch_pybindings.h +++ b/ice40/arch_pybindings.h @@ -77,6 +77,21 @@ template <> struct string_converter } }; +template <> struct string_converter +{ + BelPin from_str(Context *ctx, std::string name) + { + NPNR_ASSERT_FALSE("string_converter::from_str not implemented"); + } + + std::string to_str(Context *ctx, BelPin pin) + { + if (pin.bel == BelId()) + throw bad_wrap(); + return ctx->getBelName(pin.bel).str(ctx) + "/" + pin.pin.str(ctx); + } +}; + } // namespace PythonConversion NEXTPNR_NAMESPACE_END