show: Fix width labels.
authorMarcelina Kościelnicka <mwk@0x04.net>
Mon, 4 Apr 2022 18:40:46 +0000 (20:40 +0200)
committerMarcelina Kościelnicka <mwk@0x04.net>
Mon, 4 Apr 2022 20:48:09 +0000 (22:48 +0200)
See #3266.

passes/cmds/show.cc

index 8f9824f9bbc45d7372061fdd2057b80ec13a0d1a..35aa410e489bd6617e413aab00363a278317c974 100644 (file)
@@ -52,7 +52,7 @@ struct ShowWorker
        std::map<RTLIL::IdString, int> autonames;
        int single_idx_count;
 
-       struct net_conn { std::set<std::string> in, out; int bits; std::string color; };
+       struct net_conn { std::set<std::pair<std::string, int>> in, out; std::string color; };
        std::map<std::string, net_conn> net_conn_map;
 
        FILE *f;
@@ -268,8 +268,7 @@ struct ShowWorker
                                if (driver) {
                                        log_assert(!net.empty());
                                        label_string += stringf("<s%d> %d:%d - %s%d:%d |", i, pos, pos-c.width+1, repinfo.c_str(), cl, cr);
-                                       net_conn_map[net].in.insert(stringf("x%d:s%d", idx, i));
-                                       net_conn_map[net].bits = rep*c.width;
+                                       net_conn_map[net].in.insert({stringf("x%d:s%d", idx, i), rep*c.width});
                                        net_conn_map[net].color = nextColor(c, net_conn_map[net].color);
                                } else
                                if (net.empty()) {
@@ -282,8 +281,7 @@ struct ShowWorker
                                                        pos, pos-rep*c.width+1);
                                } else {
                                        label_string += stringf("<s%d> %s%d:%d - %d:%d |", i, repinfo.c_str(), cl, cr, pos, pos-rep*c.width+1);
-                                       net_conn_map[net].out.insert(stringf("x%d:s%d", idx, i));
-                                       net_conn_map[net].bits = rep*c.width;
+                                       net_conn_map[net].out.insert({stringf("x%d:s%d", idx, i), rep*c.width});
                                        net_conn_map[net].color = nextColor(c, net_conn_map[net].color);
                                }
                                pos -= rep * c.width;
@@ -293,6 +291,7 @@ struct ShowWorker
                        code += stringf("x%d [ shape=record, style=rounded, label=\"%s\" ];\n", idx, label_string.c_str());
                        if (!port.empty()) {
                                currentColor = xorshift32(currentColor);
+                               log_warning("WIDTHLABEL %s %d\n", log_signal(sig), GetSize(sig));
                                if (driver)
                                        code += stringf("%s:e -> x%d:w [arrowhead=odiamond, arrowtail=odiamond, dir=both, %s, %s];\n", port.c_str(), idx, nextColor(sig).c_str(), widthLabel(sig.size()).c_str());
                                else
@@ -305,10 +304,9 @@ struct ShowWorker
                {
                        if (!port.empty()) {
                                if (driver)
-                                       net_conn_map[net].in.insert(port);
+                                       net_conn_map[net].in.insert({port, GetSize(sig)});
                                else
-                                       net_conn_map[net].out.insert(port);
-                               net_conn_map[net].bits = sig.size();
+                                       net_conn_map[net].out.insert({port, GetSize(sig)});
                                net_conn_map[net].color = nextColor(sig, net_conn_map[net].color);
                        }
                        if (node != nullptr)
@@ -478,8 +476,7 @@ struct ShowWorker
                                std::string code, node;
                                code += gen_portbox("", sig, false, &node);
                                fprintf(f, "%s", code.c_str());
-                               net_conn_map[node].out.insert(stringf("p%d", pidx));
-                               net_conn_map[node].bits = sig.size();
+                               net_conn_map[node].out.insert({stringf("p%d", pidx), GetSize(sig)});
                                net_conn_map[node].color = nextColor(sig, net_conn_map[node].color);
                        }
 
@@ -487,8 +484,7 @@ struct ShowWorker
                                std::string code, node;
                                code += gen_portbox("", sig, true, &node);
                                fprintf(f, "%s", code.c_str());
-                               net_conn_map[node].in.insert(stringf("p%d", pidx));
-                               net_conn_map[node].bits = sig.size();
+                               net_conn_map[node].in.insert({stringf("p%d", pidx), GetSize(sig)});
                                net_conn_map[node].color = nextColor(sig, net_conn_map[node].color);
                        }
 
@@ -522,17 +518,15 @@ struct ShowWorker
                                currentColor = xorshift32(currentColor);
                                fprintf(f, "%s:e -> %s:w [arrowhead=odiamond, arrowtail=odiamond, dir=both, %s, %s];\n", left_node.c_str(), right_node.c_str(), nextColor(conn).c_str(), widthLabel(conn.first.size()).c_str());
                        } else {
-                               net_conn_map[right_node].bits = conn.first.size();
                                net_conn_map[right_node].color = nextColor(conn, net_conn_map[right_node].color);
-                               net_conn_map[left_node].bits = conn.first.size();
                                net_conn_map[left_node].color = nextColor(conn, net_conn_map[left_node].color);
                                if (left_node[0] == 'x') {
-                                       net_conn_map[right_node].in.insert(left_node);
+                                       net_conn_map[right_node].in.insert({left_node, GetSize(conn.first)});
                                } else if (right_node[0] == 'x') {
-                                       net_conn_map[left_node].out.insert(right_node);
+                                       net_conn_map[left_node].out.insert({right_node, GetSize(conn.first)});
                                } else {
-                                       net_conn_map[right_node].in.insert(stringf("x%d:e", single_idx_count));
-                                       net_conn_map[left_node].out.insert(stringf("x%d:w", single_idx_count));
+                                       net_conn_map[right_node].in.insert({stringf("x%d:e", single_idx_count), GetSize(conn.first)});
+                                       net_conn_map[left_node].out.insert({stringf("x%d:w", single_idx_count), GetSize(conn.first)});
                                        fprintf(f, "x%d [shape=box, style=rounded, label=\"BUF\"];\n", single_idx_count++);
                                }
                        }
@@ -542,12 +536,13 @@ struct ShowWorker
                {
                        currentColor = xorshift32(currentColor);
                        if (wires_on_demand.count(it.first) > 0) {
-                               if (it.second.in.size() == 1 && it.second.out.size() > 1 && it.second.in.begin()->compare(0, 1, "p") == 0)
+                               if (it.second.in.size() == 1 && it.second.out.size() > 1 && it.second.in.begin()->first.compare(0, 1, "p") == 0)
                                        it.second.out.erase(*it.second.in.begin());
                                if (it.second.in.size() == 1 && it.second.out.size() == 1) {
-                                       std::string from = *it.second.in.begin(), to = *it.second.out.begin();
+                                       std::string from = it.second.in.begin()->first, to = it.second.out.begin()->first;
+                                       int bits = it.second.in.begin()->second;
                                        if (from != to || from.compare(0, 1, "p") != 0)
-                                               fprintf(f, "%s:e -> %s:w [%s, %s];\n", from.c_str(), to.c_str(), nextColor(it.second.color).c_str(), widthLabel(it.second.bits).c_str());
+                                               fprintf(f, "%s:e -> %s:w [%s, %s];\n", from.c_str(), to.c_str(), nextColor(it.second.color).c_str(), widthLabel(bits).c_str());
                                        continue;
                                }
                                if (it.second.in.size() == 0 || it.second.out.size() == 0)
@@ -556,9 +551,9 @@ struct ShowWorker
                                        fprintf(f, "%s [ shape=point ];\n", it.first.c_str());
                        }
                        for (auto &it2 : it.second.in)
-                               fprintf(f, "%s:e -> %s:w [%s, %s];\n", it2.c_str(), it.first.c_str(), nextColor(it.second.color).c_str(), widthLabel(it.second.bits).c_str());
+                               fprintf(f, "%s:e -> %s:w [%s, %s];\n", it2.first.c_str(), it.first.c_str(), nextColor(it.second.color).c_str(), widthLabel(it2.second).c_str());
                        for (auto &it2 : it.second.out)
-                               fprintf(f, "%s:e -> %s:w [%s, %s];\n", it.first.c_str(), it2.c_str(), nextColor(it.second.color).c_str(), widthLabel(it.second.bits).c_str());
+                               fprintf(f, "%s:e -> %s:w [%s, %s];\n", it.first.c_str(), it2.first.c_str(), nextColor(it.second.color).c_str(), widthLabel(it2.second).c_str());
                }
 
                fprintf(f, "}\n");