aboutsummaryrefslogtreecommitdiffstats
path: root/generic/arch_pybindings.h
diff options
context:
space:
mode:
authorgatecat <gatecat@ds0.me>2021-12-30 13:12:20 +0000
committerGitHub <noreply@github.com>2021-12-30 13:12:20 +0000
commitd65c629fb0da55a8aa897d615551442e6be740d0 (patch)
tree28463b159ce424cdf7780174f1fffb421d04bf88 /generic/arch_pybindings.h
parentc272d28e575bde2675a6ae7090a0d5f0f4c9c88f (diff)
parent59874188a6800fbaa03ec21e3578160e963c2eb5 (diff)
downloadnextpnr-d65c629fb0da55a8aa897d615551442e6be740d0.tar.gz
nextpnr-d65c629fb0da55a8aa897d615551442e6be740d0.tar.bz2
nextpnr-d65c629fb0da55a8aa897d615551442e6be740d0.zip
Merge pull request #889 from YosysHQ/gatecat/generic-refactor
generic: Refactor for faster performance
Diffstat (limited to 'generic/arch_pybindings.h')
-rw-r--r--generic/arch_pybindings.h67
1 files changed, 67 insertions, 0 deletions
diff --git a/generic/arch_pybindings.h b/generic/arch_pybindings.h
index 9a573540..72d688dc 100644
--- a/generic/arch_pybindings.h
+++ b/generic/arch_pybindings.h
@@ -26,6 +26,73 @@
NEXTPNR_NAMESPACE_BEGIN
+namespace PythonConversion {
+
+template <> struct string_converter<BelId>
+{
+ BelId from_str(Context *ctx, std::string name) { return ctx->getBelByNameStr(name); }
+
+ std::string to_str(Context *ctx, BelId id)
+ {
+ if (id == BelId())
+ throw bad_wrap();
+ return ctx->getBelName(id).str(ctx);
+ }
+};
+
+template <> struct string_converter<WireId>
+{
+ WireId from_str(Context *ctx, std::string name) { return ctx->getWireByNameStr(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<const WireId>
+{
+ WireId from_str(Context *ctx, std::string name) { return ctx->getWireByNameStr(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>
+{
+ PipId from_str(Context *ctx, std::string name) { return ctx->getPipByNameStr(name); }
+
+ std::string to_str(Context *ctx, PipId id)
+ {
+ if (id == PipId())
+ throw bad_wrap();
+ return ctx->getPipName(id).str(ctx);
+ }
+};
+
+template <> struct string_converter<BelPin>
+{
+ BelPin from_str(Context *ctx, std::string name)
+ {
+ NPNR_ASSERT_FALSE("string_converter<BelPin>::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
#endif
#endif