aboutsummaryrefslogtreecommitdiffstats
path: root/fpga_interchange/arch_pybindings.h
diff options
context:
space:
mode:
authorDavid Shah <dave@ds0.me>2021-02-05 19:15:29 +0000
committerGitHub <noreply@github.com>2021-02-05 19:15:29 +0000
commit8b4163b77c667c4f2a29e48adab96abc2a83b03d (patch)
treef0ebf104fd3b9a5f1752698b3df4e5c2f2af3304 /fpga_interchange/arch_pybindings.h
parentb0f9b7834e4cb035d1fd60f0fa1948c0fdfa233c (diff)
parenta0ee42833b774483f9b2fc35109f7ec948dbdc9b (diff)
downloadnextpnr-8b4163b77c667c4f2a29e48adab96abc2a83b03d.tar.gz
nextpnr-8b4163b77c667c4f2a29e48adab96abc2a83b03d.tar.bz2
nextpnr-8b4163b77c667c4f2a29e48adab96abc2a83b03d.zip
Merge pull request #567 from litghost/initial_fpga_interchange
Initial FPGA interchange arch
Diffstat (limited to 'fpga_interchange/arch_pybindings.h')
-rw-r--r--fpga_interchange/arch_pybindings.h110
1 files changed, 110 insertions, 0 deletions
diff --git a/fpga_interchange/arch_pybindings.h b/fpga_interchange/arch_pybindings.h
new file mode 100644
index 00000000..1cccdf55
--- /dev/null
+++ b/fpga_interchange/arch_pybindings.h
@@ -0,0 +1,110 @@
+/*
+ * nextpnr -- Next Generation Place and Route
+ *
+ * Copyright (C) 2020 David Shah <dave@ds0.me>
+ * Copyright (C) 2021 Symbiflow Authors
+ *
+ * Permission to use, copy, modify, and/or distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ *
+ */
+#ifndef ARCH_PYBINDINGS_H
+#define ARCH_PYBINDINGS_H
+#ifndef NO_PYTHON
+
+#include "nextpnr.h"
+#include "pybindings.h"
+
+NEXTPNR_NAMESPACE_BEGIN
+
+namespace PythonConversion {
+
+template <> struct string_converter<BelId>
+{
+ BelId from_str(Context *ctx, std::string name) { return ctx->getBelByName(IdStringList::parse(ctx, 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->getWireByName(IdStringList::parse(ctx, 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->getWireByName(IdStringList::parse(ctx, 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->getPipByName(IdStringList::parse(ctx, 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<BelBucketId>
+{
+ BelBucketId from_str(Context *ctx, std::string name) { return ctx->getBelBucketByName(ctx->id(name)); }
+
+ std::string to_str(Context *ctx, BelBucketId id)
+ {
+ if (id == BelBucketId())
+ throw bad_wrap();
+ return ctx->getBelBucketName(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