Merge branch 'xc7' into xc7_gui
diff --git a/gui/designwidget.cc b/gui/designwidget.cc
index 235dd2c..958d884 100644
--- a/gui/designwidget.cc
+++ b/gui/designwidget.cc
@@ -318,6 +318,12 @@
                 wireMap[std::pair<int, int>(wire.location.x, wire.location.y)].push_back(wire);

             }

 #endif

+#ifdef ARCH_XC7

+            for (const auto &wire : ctx->getWires()) {

+                const auto loc = torc_info->wire_to_loc(wire.index);

+                wireMap[std::pair<int, int>(loc.x, loc.y)].push_back(wire);

+            }

+#endif

             auto wireGetter = [](Context *ctx, WireId id) { return ctx->getWireName(id); };

             getTreeByElementType(ElementType::WIRE)

                     ->loadData(ctx,

@@ -706,8 +712,9 @@
         addProperty(topItem, QVariant::String, "Type", ctx->getPipType(pip).c_str(ctx));

         addProperty(topItem, QVariant::Bool, "Available", ctx->checkPipAvail(pip));

         addProperty(topItem, QVariant::String, "Bound Net", ctx->nameOf(ctx->getBoundPipNet(pip)), ElementType::NET);

+        WireId conflict = ctx->getConflictingPipWire(pip);

         addProperty(topItem, QVariant::String, "Conflicting Wire",

-                    ctx->getWireName(ctx->getConflictingPipWire(pip)).c_str(ctx), ElementType::WIRE);

+                    (conflict!=WireId() ? ctx->getWireName(conflict).c_str(ctx) : ""), ElementType::WIRE);

         addProperty(topItem, QVariant::String, "Conflicting Net", ctx->nameOf(ctx->getConflictingPipNet(pip)),

                     ElementType::NET);

         addProperty(topItem, QVariant::String, "Src Wire", ctx->getWireName(ctx->getPipSrcWire(pip)).c_str(ctx),

diff --git a/xc7/arch.cc b/xc7/arch.cc
index 87864a3..c4178b0 100644
--- a/xc7/arch.cc
+++ b/xc7/arch.cc
@@ -397,11 +397,26 @@
 
 // -----------------------------------------------------------------------
 
+static bool endsWith(const std::string& str, const std::string& suffix)
+{
+    return str.size() >= suffix.size() && 0 == str.compare(str.size()-suffix.size(), suffix.size(), suffix);
+}
+
 BelId Arch::getBelByName(IdString name) const
 {
-    auto it = torc_info->sites.findSiteIndex(name.str(this));
-    if (it != SiteIndex(-1))
-        return torc_info->site_index_to_bel.at(it);
+    std::string n = name.str(this);
+    int ndx = 0;
+    if (endsWith(n,"_A") || endsWith(n,"_B") || endsWith(n,"_C") || endsWith(n,"_D"))
+    {
+        ndx = (int)(n.back() - 'A');
+        n = n.substr(0,n.size()-2);
+    }
+    auto it = torc_info->sites.findSiteIndex(n);
+    if (it != SiteIndex(-1)) {
+        BelId id = torc_info->site_index_to_bel.at(it);
+        id.index += ndx;
+        return id;
+    }
     return BelId();
 }
 
@@ -531,9 +546,14 @@
 {
     WireId ret;
     if (wire_by_name.empty()) {
-        for (int i = 0; i < chip_info->num_wires; i++)
-            wire_by_name[id(chip_info->wire_data[i].name.get())] = i;
+        for (int i = 0; i < torc_info->num_wires; i++)
+            wire_by_name[id(torc_info->wire_to_name(i))] = i;
     }
+
+    auto it = wire_by_name.find(name);
+    if (it != wire_by_name.end())
+        ret.index = it->second;
+
     return ret;
 }
 
@@ -557,7 +577,19 @@
 PipId Arch::getPipByName(IdString name) const
 {
     PipId ret;
-    NPNR_ASSERT("TODO");
+
+    if (pip_by_name.empty()) {
+        for (int i = 0; i < torc_info->num_pips; i++) {
+            PipId pip;
+            pip.index = i;
+            pip_by_name[getPipName(pip)] = i;
+        }
+    }
+
+    auto it = pip_by_name.find(name);
+    if (it != pip_by_name.end())
+        ret.index = it->second;
+
     return ret;
 }
 
@@ -696,7 +728,31 @@
 std::vector<GraphicElement> Arch::getDecalGraphics(DecalId decal) const
 {
     std::vector<GraphicElement> ret;
-    NPNR_ASSERT("TODO");
+
+    if (decal.type == DecalId::TYPE_BEL) {
+        BelId bel;
+        bel.index = decal.index;
+        auto bel_type = getBelType(bel);
+        int x = torc_info->bel_to_loc[bel.index].x;
+        int y = torc_info->bel_to_loc[bel.index].y;
+        int z = torc_info->bel_to_loc[bel.index].z;
+        if (bel_type == id_SLICE_LUT6) {
+            GraphicElement el;
+            /*if (z>3) {
+                z = z - 4;
+                x -= logic_cell_x2- logic_cell_x1;
+            }*/
+            el.type = GraphicElement::TYPE_BOX;
+            el.style = decal.active ? GraphicElement::STYLE_ACTIVE : GraphicElement::STYLE_INACTIVE;
+            el.x1 = x + logic_cell_x1;
+            el.x2 = x + logic_cell_x2;
+            el.y1 = y + logic_cell_y1 + (z)*logic_cell_pitch;
+            el.y2 = y + logic_cell_y2 + (z)*logic_cell_pitch;
+            ret.push_back(el);
+        }
+
+    }
+
     return ret;
 }
 
diff --git a/xc7/arch.h b/xc7/arch.h
index 75f8530..699d357 100644
--- a/xc7/arch.h
+++ b/xc7/arch.h
@@ -297,6 +297,17 @@
         ss << "(" << tw.getWireIndex() << "@" << tw.getTileIndex() << ")";
         return ss.str();
     }
+
+    Loc wire_to_loc(int32_t index) const
+    {
+        const auto &tw = wire_to_tilewire[index];
+        ExtendedWireInfo ewi(*ddb, tw);
+        Loc l;
+        l.x = (int)ewi.mTileCol;
+        l.y = (int)ewi.mTileRow;
+        return l;
+    }
+    
     WireId tilewire_to_wire(const Tilewire &tw) const
     {
         const auto &segment = segments.getTilewireSegment(tw);
@@ -682,7 +693,7 @@
     BelPinRange getWireBelPins(WireId wire) const
     {
         BelPinRange range;
-        NPNR_ASSERT("TODO");
+        // TODO
         return range;
     }