From 726f2020f140a1f5e89e966e7cbde1d1f79473ba Mon Sep 17 00:00:00 2001 From: David Shah Date: Wed, 4 Jul 2018 15:26:09 +0200 Subject: [PATCH] python: Convert empty BelId to None Signed-off-by: David Shah --- generic/arch_pybindings.cc | 2 +- generic/arch_pybindings.h | 2 +- ice40/arch_pybindings.cc | 2 +- ice40/arch_pybindings.h | 10 ++++++++-- python/dump_design.py | 2 +- 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/generic/arch_pybindings.cc b/generic/arch_pybindings.cc index a2997456..a99723f2 100644 --- a/generic/arch_pybindings.cc +++ b/generic/arch_pybindings.cc @@ -20,8 +20,8 @@ #ifndef NO_PYTHON -#include "pybindings.h" #include "nextpnr.h" +#include "pybindings.h" NEXTPNR_NAMESPACE_BEGIN diff --git a/generic/arch_pybindings.h b/generic/arch_pybindings.h index 12b666a2..f7f07529 100644 --- a/generic/arch_pybindings.h +++ b/generic/arch_pybindings.h @@ -21,8 +21,8 @@ #define ARCH_PYBINDINGS_H #ifndef NO_PYTHON -#include "pybindings.h" #include "nextpnr.h" +#include "pybindings.h" NEXTPNR_NAMESPACE_BEGIN diff --git a/ice40/arch_pybindings.cc b/ice40/arch_pybindings.cc index bcf6039d..4cbfc8af 100644 --- a/ice40/arch_pybindings.cc +++ b/ice40/arch_pybindings.cc @@ -20,9 +20,9 @@ #ifndef NO_PYTHON -#include "pybindings.h" #include "arch_pybindings.h" #include "nextpnr.h" +#include "pybindings.h" NEXTPNR_NAMESPACE_BEGIN diff --git a/ice40/arch_pybindings.h b/ice40/arch_pybindings.h index 42fe8a6d..e502905f 100644 --- a/ice40/arch_pybindings.h +++ b/ice40/arch_pybindings.h @@ -21,8 +21,9 @@ #define ARCH_PYBINDINGS_H #ifndef NO_PYTHON -#include "pybindings.h" #include "nextpnr.h" +#include "pybindings.h" +#include "pywrappers.h" NEXTPNR_NAMESPACE_BEGIN @@ -32,7 +33,12 @@ template <> struct string_converter { BelId from_str(Context *ctx, std::string name) { return ctx->getBelByName(ctx->id(name)); } - std::string to_str(Context *ctx, BelId id) { return ctx->getBelName(id).str(ctx); } + std::string to_str(Context *ctx, BelId id) + { + if (id == BelId()) + throw bad_wrap(); + return ctx->getBelName(id).str(ctx); + } }; template <> struct string_converter diff --git a/python/dump_design.py b/python/dump_design.py index c75df9a1..419c7304 100644 --- a/python/dump_design.py +++ b/python/dump_design.py @@ -20,6 +20,6 @@ for cell, cinfo in sorted(ctx.cells, key=lambda x: x.first): val = "{}'b{}".format(len(val), val) print("\t\t{}: {}".format(param, val)) - if cinfo.bel.index != -1: + if cinfo.bel is not None: print("\tBel: {}".format(cinfo.bel)) print()