From 6fffe24177f9b99d6c332c18e343648cf33d4397 Mon Sep 17 00:00:00 2001 From: David Shah Date: Wed, 3 Apr 2019 16:08:33 +0100 Subject: generic: GUI Python bindings Signed-off-by: David Shah --- generic/arch.cc | 14 ++++++++++++-- generic/arch_pybindings.cc | 20 ++++++++++++++++---- generic/examples/simple.py | 7 ++++++- 3 files changed, 34 insertions(+), 7 deletions(-) (limited to 'generic') diff --git a/generic/arch.cc b/generic/arch.cc index 01f7ef55..08146b65 100644 --- a/generic/arch.cc +++ b/generic/arch.cc @@ -18,6 +18,7 @@ */ #include +#include #include "nextpnr.h" #include "placer1.h" #include "router1.h" @@ -201,7 +202,10 @@ void Arch::setDelayScaling(double scale, double offset) // --------------------------------------------------------------- -Arch::Arch(ArchArgs args) : chipName("generic"), args(args) {} +Arch::Arch(ArchArgs args) : chipName("generic"), args(args) { + // Dummy for empty decals + decal_graphics[IdString()]; +} void IdString::initialize_arch(const BaseCtx *ctx) {} @@ -469,7 +473,13 @@ bool Arch::route() { return router1(getCtx(), Router1Cfg(getCtx())); } // --------------------------------------------------------------- -const std::vector &Arch::getDecalGraphics(DecalId decal) const { return decal_graphics.at(decal); } +const std::vector &Arch::getDecalGraphics(DecalId decal) const { + if (!decal_graphics.count(decal)) { + std::cerr << "No decal named " << decal.str(this) << std::endl; + log_error("No decal named %s!\n", decal.c_str(this)); + } + return decal_graphics.at(decal); +} DecalXY Arch::getBelDecal(BelId bel) const { return bels.at(bel).decalxy; } diff --git a/generic/arch_pybindings.cc b/generic/arch_pybindings.cc index eae78c9a..5eb2f2c8 100644 --- a/generic/arch_pybindings.cc +++ b/generic/arch_pybindings.cc @@ -40,6 +40,15 @@ void arch_wrap_python() using namespace PythonConversion; auto arch_cls = class_, boost::noncopyable>("Arch", init()); + + auto dxy_cls = class_>("DecalXY_", no_init); + readwrite_wrapper, + conv_from_str>::def_wrap(dxy_cls, "decal"); + readwrite_wrapper, pass_through>::def_wrap( + dxy_cls, "x"); + readwrite_wrapper, pass_through>::def_wrap( + dxy_cls, "y"); + auto ctx_cls = class_, boost::noncopyable>("Context", no_init) .def("checksum", &Context::checksum) .def("pack", &Context::pack) @@ -127,6 +136,9 @@ void arch_wrap_python() fn_wrapper_0a>::def_wrap(ctx_cls, "archId"); + fn_wrapper_3a, + conv_from_str, pass_through, pass_through>::def_wrap(ctx_cls, "DecalXY"); + typedef std::unordered_map> CellMap; typedef std::unordered_map> NetMap; @@ -178,13 +190,13 @@ void arch_wrap_python() fn_wrapper_2a_v, pass_through>::def_wrap(ctx_cls, "addDecalGraphic", (arg("decal"), "graphic")); fn_wrapper_2a_v, - pass_through>::def_wrap(ctx_cls, "setWireDecal", (arg("wire"), "decalxy")); + unwrap_context>::def_wrap(ctx_cls, "setWireDecal", (arg("wire"), "decalxy")); fn_wrapper_2a_v, - pass_through>::def_wrap(ctx_cls, "setPipDecal", (arg("pip"), "decalxy")); + unwrap_context>::def_wrap(ctx_cls, "setPipDecal", (arg("pip"), "decalxy")); fn_wrapper_2a_v, - pass_through>::def_wrap(ctx_cls, "setBelDecal", (arg("bel"), "decalxy")); + unwrap_context>::def_wrap(ctx_cls, "setBelDecal", (arg("bel"), "decalxy")); fn_wrapper_2a_v, - pass_through>::def_wrap(ctx_cls, "setGroupDecal", (arg("group"), "decalxy")); + unwrap_context>::def_wrap(ctx_cls, "setGroupDecal", (arg("group"), "decalxy")); fn_wrapper_3a_v, conv_from_str, pass_through>::def_wrap(ctx_cls, "setWireAttr", diff --git a/generic/examples/simple.py b/generic/examples/simple.py index b8ca3f78..2628c041 100644 --- a/generic/examples/simple.py +++ b/generic/examples/simple.py @@ -14,6 +14,10 @@ Sq = 4 # "Sparsity" of local to neighbour local wire pips Sl = 8 +# Create graphic elements +# Bels +ctx.addDecalGraphic("bel", GraphicElement(type=TYPE_BOX, style=STYLE_INACTIVE, x1=0, y1=0, x2=0.2, y2=(1/(Z+1))-0.02, z=0)) + def is_io(x, y): return x == 0 or x == X-1 or y == 0 or y == Y-1 @@ -37,7 +41,7 @@ for x in range(X): ctx.addBelInput(bel="X%dY%d_IO%d" % (x, y, z), name="I", wire="X%dY%dZ%d_I0" % (x, y, z)) ctx.addBelInput(bel="X%dY%d_IO%d" % (x, y, z), name="EN", wire="X%dY%dZ%d_I1" % (x, y, z)) ctx.addBelOutput(bel="X%dY%d_IO%d" % (x, y, z), name="O", wire="X%dY%dZ%d_Q" % (x, y, z)) - + ctx.setBelDecal(bel="X%dY%d_IO%d" % (x, y, z), decalxy=ctx.DecalXY("bel", 0.6, z * (1/(Z+1)))) else: for z in range(Z): ctx.addBel(name="X%dY%d_SLICE%d" % (x, y, z), type="GENERIC_SLICE", loc=Loc(x, y, z), gb=False) @@ -45,6 +49,7 @@ for x in range(X): for k in range(K): ctx.addBelInput(bel="X%dY%d_SLICE%d" % (x, y, z), name="I[%d]" % k, wire="X%dY%dZ%d_I%d" % (x, y, z, k)) ctx.addBelOutput(bel="X%dY%d_SLICE%d" % (x, y, z), name="Q", wire="X%dY%dZ%d_Q" % (x, y, z)) + ctx.setBelDecal(bel="X%dY%d_SLICE%d" % (x, y, z), decalxy=ctx.DecalXY("bel", 0.6, z * (1/(Z+1)))) for x in range(X): for y in range(Y): -- cgit v1.2.3