2013-01-05 04:13:26 -06:00
|
|
|
/*
|
|
|
|
* yosys -- Yosys Open SYnthesis Suite
|
|
|
|
*
|
2021-06-07 17:39:36 -05:00
|
|
|
* Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com>
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* 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.
|
2015-07-02 04:14:30 -05:00
|
|
|
*
|
2013-01-05 04:13:26 -06:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/celltypes.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
#include <string.h>
|
2014-10-16 11:06:54 -05:00
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
# include <dirent.h>
|
|
|
|
#endif
|
2014-08-22 09:09:13 -05:00
|
|
|
|
2019-09-23 10:25:30 -05:00
|
|
|
#ifdef __APPLE__
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif
|
|
|
|
|
2014-08-22 09:09:13 -05:00
|
|
|
#ifdef YOSYS_ENABLE_READLINE
|
|
|
|
# include <readline/readline.h>
|
|
|
|
#endif
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2017-11-07 19:54:24 -06:00
|
|
|
#ifdef YOSYS_ENABLE_EDITLINE
|
|
|
|
# include <editline/readline.h>
|
|
|
|
#endif
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
#undef CLUSTER_CELLS_AND_PORTBOXES
|
|
|
|
|
|
|
|
struct ShowWorker
|
|
|
|
{
|
|
|
|
CellTypes ct;
|
|
|
|
|
2015-06-11 06:39:49 -05:00
|
|
|
vector<shared_str> dot_escape_store;
|
2013-01-05 04:13:26 -06:00
|
|
|
std::map<RTLIL::IdString, int> dot_id2num_store;
|
|
|
|
std::map<RTLIL::IdString, int> autonames;
|
|
|
|
int single_idx_count;
|
|
|
|
|
2022-04-04 13:40:46 -05:00
|
|
|
struct net_conn { std::set<std::pair<std::string, int>> in, out; std::string color; };
|
2013-01-05 04:13:26 -06:00
|
|
|
std::map<std::string, net_conn> net_conn_map;
|
|
|
|
|
|
|
|
FILE *f;
|
|
|
|
RTLIL::Design *design;
|
|
|
|
RTLIL::Module *module;
|
2013-03-24 04:41:24 -05:00
|
|
|
uint32_t currentColor;
|
2013-03-24 07:11:06 -05:00
|
|
|
bool genWidthLabels;
|
2014-08-04 08:33:51 -05:00
|
|
|
bool genSignedLabels;
|
2013-03-24 07:27:04 -05:00
|
|
|
bool stretchIO;
|
2013-11-28 14:02:19 -06:00
|
|
|
bool enumerateIds;
|
|
|
|
bool abbreviateIds;
|
2014-02-02 10:55:32 -06:00
|
|
|
bool notitle;
|
2013-01-05 04:13:26 -06:00
|
|
|
int page_counter;
|
|
|
|
|
2013-04-01 07:12:17 -05:00
|
|
|
const std::vector<std::pair<std::string, RTLIL::Selection>> &color_selections;
|
|
|
|
const std::vector<std::pair<std::string, RTLIL::Selection>> &label_selections;
|
|
|
|
|
2014-12-23 05:29:29 -06:00
|
|
|
std::map<RTLIL::Const, int> colorattr_cache;
|
|
|
|
RTLIL::IdString colorattr;
|
|
|
|
|
|
|
|
|
2014-07-18 09:44:45 -05:00
|
|
|
static uint32_t xorshift32(uint32_t x) {
|
2013-03-24 04:41:24 -05:00
|
|
|
x ^= x << 13;
|
|
|
|
x ^= x >> 17;
|
|
|
|
x ^= x << 5;
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string nextColor()
|
|
|
|
{
|
|
|
|
if (currentColor == 0)
|
2023-05-24 10:52:14 -05:00
|
|
|
return "color=\"black\", fontcolor=\"black\"";
|
2014-10-10 10:22:08 -05:00
|
|
|
return stringf("colorscheme=\"dark28\", color=\"%d\", fontcolor=\"%d\"", currentColor%8+1, currentColor%8+1);
|
2013-03-24 07:11:06 -05:00
|
|
|
}
|
|
|
|
|
2013-04-01 07:12:17 -05:00
|
|
|
std::string nextColor(std::string presetColor)
|
|
|
|
{
|
|
|
|
if (presetColor.empty())
|
|
|
|
return nextColor();
|
|
|
|
return presetColor;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string nextColor(RTLIL::SigSpec sig, std::string defaultColor)
|
|
|
|
{
|
2023-05-24 10:52:14 -05:00
|
|
|
std::string color = findColor(sig);
|
|
|
|
if (!color.empty()) return color;
|
2013-04-01 07:12:17 -05:00
|
|
|
return defaultColor;
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:57 -05:00
|
|
|
std::string nextColor(const RTLIL::SigSig &conn, std::string defaultColor)
|
2013-04-01 07:12:17 -05:00
|
|
|
{
|
2023-05-24 10:52:14 -05:00
|
|
|
std::string color = findColor(conn);
|
|
|
|
if (!color.empty()) return color;
|
2023-05-31 10:38:46 -05:00
|
|
|
return defaultColor;
|
2013-04-01 07:12:17 -05:00
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:57 -05:00
|
|
|
std::string nextColor(const RTLIL::SigSpec &sig)
|
2013-04-01 07:12:17 -05:00
|
|
|
{
|
|
|
|
return nextColor(sig, nextColor());
|
|
|
|
}
|
|
|
|
|
2014-07-26 08:57:57 -05:00
|
|
|
std::string nextColor(const RTLIL::SigSig &conn)
|
2013-04-01 07:12:17 -05:00
|
|
|
{
|
|
|
|
return nextColor(conn, nextColor());
|
|
|
|
}
|
|
|
|
|
2013-03-24 07:11:06 -05:00
|
|
|
std::string widthLabel(int bits)
|
|
|
|
{
|
|
|
|
if (bits <= 1)
|
|
|
|
return "label=\"\"";
|
|
|
|
if (!genWidthLabels)
|
|
|
|
return "style=\"setlinewidth(3)\", label=\"\"";
|
|
|
|
return stringf("style=\"setlinewidth(3)\", label=\"<%d>\"", bits);
|
2013-03-24 04:41:24 -05:00
|
|
|
}
|
|
|
|
|
2023-05-24 10:52:14 -05:00
|
|
|
std::string findColor(RTLIL::SigSpec sig)
|
|
|
|
{
|
|
|
|
sig.sort_and_unify();
|
|
|
|
for (auto &c : sig.chunks()) {
|
|
|
|
if (c.wire != nullptr)
|
|
|
|
return findColor(c.wire->name);
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string findColor(const RTLIL::SigSig &conn)
|
|
|
|
{
|
|
|
|
std::string firstColor = findColor(conn.first);
|
|
|
|
if (findColor(conn.second) == firstColor) return firstColor;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string findColor(IdString member_name)
|
2014-02-01 11:23:32 -06:00
|
|
|
{
|
|
|
|
for (auto &s : color_selections)
|
|
|
|
if (s.second.selected_member(module->name, member_name)) {
|
2023-05-24 10:52:14 -05:00
|
|
|
return stringf("color=\"%s\", fontcolor=\"%s\"", s.first.c_str(), s.first.c_str());
|
2014-02-01 11:23:32 -06:00
|
|
|
}
|
2014-12-23 05:29:29 -06:00
|
|
|
|
|
|
|
RTLIL::Const colorattr_value;
|
|
|
|
RTLIL::Cell *cell = module->cell(member_name);
|
|
|
|
RTLIL::Wire *wire = module->wire(member_name);
|
|
|
|
|
|
|
|
if (cell && cell->attributes.count(colorattr))
|
|
|
|
colorattr_value = cell->attributes.at(colorattr);
|
|
|
|
else if (wire && wire->attributes.count(colorattr))
|
|
|
|
colorattr_value = wire->attributes.at(colorattr);
|
|
|
|
else
|
|
|
|
return "";
|
|
|
|
|
|
|
|
if (colorattr_cache.count(colorattr_value) == 0) {
|
|
|
|
int next_id = GetSize(colorattr_cache);
|
|
|
|
colorattr_cache[colorattr_value] = (next_id % 8) + 1;
|
|
|
|
}
|
|
|
|
|
2023-05-24 10:52:14 -05:00
|
|
|
return stringf("colorscheme=\"dark28\", color=\"%d\", fontcolor=\"%d\"", colorattr_cache.at(colorattr_value), colorattr_cache.at(colorattr_value));
|
2014-02-01 11:23:32 -06:00
|
|
|
}
|
|
|
|
|
2014-08-03 05:40:23 -05:00
|
|
|
const char *findLabel(std::string member_name)
|
2014-02-01 11:23:32 -06:00
|
|
|
{
|
|
|
|
for (auto &s : label_selections)
|
2014-08-02 06:11:01 -05:00
|
|
|
if (s.second.selected_member(module->name, member_name))
|
2014-02-01 11:23:32 -06:00
|
|
|
return escape(s.first);
|
|
|
|
return escape(member_name, true);
|
|
|
|
}
|
|
|
|
|
2014-08-03 05:40:23 -05:00
|
|
|
const char *escape(std::string id, bool is_name = false)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2014-08-03 05:40:23 -05:00
|
|
|
if (id.size() == 0)
|
2013-01-05 04:13:26 -06:00
|
|
|
return "";
|
|
|
|
|
2014-08-03 05:40:23 -05:00
|
|
|
if (id[0] == '$' && is_name) {
|
2013-11-28 14:02:19 -06:00
|
|
|
if (enumerateIds) {
|
|
|
|
if (autonames.count(id) == 0) {
|
|
|
|
autonames[id] = autonames.size() + 1;
|
|
|
|
log("Generated short name for internal identifier: _%d_ -> %s\n", autonames[id], id.c_str());
|
|
|
|
}
|
|
|
|
id = stringf("_%d_", autonames[id]);
|
|
|
|
} else if (abbreviateIds) {
|
2014-08-03 05:40:23 -05:00
|
|
|
const char *p = id.c_str();
|
2013-11-28 14:02:19 -06:00
|
|
|
const char *q = strrchr(p, '$');
|
2014-08-03 05:40:23 -05:00
|
|
|
id = std::string(q);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-08-03 05:40:23 -05:00
|
|
|
if (id[0] == '\\')
|
|
|
|
id = id.substr(1);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2023-06-20 05:53:56 -05:00
|
|
|
// TODO: optionally include autoname + print correspondence in case of ambiguity
|
|
|
|
size_t max_label_len = abbreviateIds ? 256 : 16384;
|
|
|
|
if (id.size() > max_label_len) {
|
|
|
|
id = id.substr(0,max_label_len-3) + "...";
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
std::string str;
|
2014-08-03 05:40:23 -05:00
|
|
|
for (char ch : id) {
|
2022-06-03 01:38:16 -05:00
|
|
|
if (ch == '\\') {
|
|
|
|
// new graphviz have bug with escaping '\'
|
|
|
|
str += "╲";
|
|
|
|
continue;
|
|
|
|
}
|
2023-06-20 04:17:12 -05:00
|
|
|
if (ch == '"' || ch == '<' || ch == '>')
|
2013-01-05 04:13:26 -06:00
|
|
|
str += "\\";
|
|
|
|
str += ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
dot_escape_store.push_back(str);
|
|
|
|
return dot_escape_store.back().c_str();
|
|
|
|
}
|
|
|
|
|
|
|
|
int id2num(RTLIL::IdString id)
|
|
|
|
{
|
|
|
|
if (dot_id2num_store.count(id) > 0)
|
|
|
|
return dot_id2num_store[id];
|
|
|
|
return dot_id2num_store[id] = dot_id2num_store.size() + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string gen_signode_simple(RTLIL::SigSpec sig, bool range_check = true)
|
|
|
|
{
|
2014-10-10 09:59:44 -05:00
|
|
|
if (GetSize(sig) == 0) {
|
2013-01-05 04:13:26 -06:00
|
|
|
fprintf(f, "v%d [ label=\"\" ];\n", single_idx_count);
|
|
|
|
return stringf("v%d", single_idx_count++);
|
|
|
|
}
|
|
|
|
|
2014-07-25 07:23:31 -05:00
|
|
|
if (sig.is_chunk()) {
|
|
|
|
const RTLIL::SigChunk &c = sig.as_chunk();
|
2020-04-06 03:51:25 -05:00
|
|
|
if (c.wire != nullptr && design->selected_member(module->name, c.wire->name)) {
|
2013-01-05 04:13:26 -06:00
|
|
|
if (!range_check || c.wire->width == c.width)
|
|
|
|
return stringf("n%d", id2num(c.wire->name));
|
|
|
|
} else {
|
2014-02-01 11:23:32 -06:00
|
|
|
fprintf(f, "v%d [ label=\"%s\" ];\n", single_idx_count, findLabel(log_signal(c)));
|
2013-01-05 04:13:26 -06:00
|
|
|
return stringf("v%d", single_idx_count++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return std::string();
|
|
|
|
}
|
|
|
|
|
2023-01-12 10:09:53 -06:00
|
|
|
// Return the pieces of a label joined by a '|' separator
|
|
|
|
std::string join_label_pieces(std::vector<std::string> pieces)
|
|
|
|
{
|
|
|
|
std::string ret = "";
|
|
|
|
bool first_piece = true;
|
|
|
|
|
|
|
|
for (auto &piece : pieces) {
|
|
|
|
if (!first_piece)
|
|
|
|
ret += "|";
|
|
|
|
ret += piece;
|
|
|
|
first_piece = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2020-04-06 03:51:25 -05:00
|
|
|
std::string gen_portbox(std::string port, RTLIL::SigSpec sig, bool driver, std::string *node = nullptr)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
std::string code;
|
|
|
|
std::string net = gen_signode_simple(sig);
|
|
|
|
if (net.empty())
|
|
|
|
{
|
2023-01-12 10:03:13 -06:00
|
|
|
int dot_idx = single_idx_count++;
|
2023-01-12 10:09:53 -06:00
|
|
|
std::vector<std::string> label_pieces;
|
2023-01-13 09:16:03 -06:00
|
|
|
int bitpos = sig.size()-1;
|
2023-01-12 10:24:31 -06:00
|
|
|
|
2023-01-13 09:10:20 -06:00
|
|
|
for (int rep, chunk_idx = ((int) sig.chunks().size()) - 1; chunk_idx >= 0; chunk_idx -= rep) {
|
|
|
|
const RTLIL::SigChunk &c = sig.chunks().at(chunk_idx);
|
|
|
|
|
|
|
|
// Find the number of times this chunk is repeating
|
|
|
|
for (rep = 1; chunk_idx - rep >= 0 && c == sig.chunks().at(chunk_idx - rep); rep++);
|
|
|
|
|
2021-11-12 04:55:47 -06:00
|
|
|
int cl, cr;
|
2023-01-12 10:24:31 -06:00
|
|
|
cl = c.offset + c.width - 1;
|
|
|
|
cr = c.offset;
|
|
|
|
|
|
|
|
if (c.is_wire()) {
|
2021-11-12 04:55:47 -06:00
|
|
|
if (c.wire->upto) {
|
2023-01-12 10:24:31 -06:00
|
|
|
cr = (c.wire->width - 1) - c.offset;
|
2021-11-12 04:55:47 -06:00
|
|
|
cl = cr - (c.width - 1);
|
|
|
|
}
|
2023-01-12 10:24:31 -06:00
|
|
|
|
|
|
|
cl += c.wire->start_offset;
|
|
|
|
cr += c.wire->start_offset;
|
2021-11-12 04:55:47 -06:00
|
|
|
}
|
2023-01-12 10:24:31 -06:00
|
|
|
|
2023-01-13 09:17:03 -06:00
|
|
|
// Is this chunk a constant filled with one kind of bit state?
|
|
|
|
bool no_signode = !driver && !c.is_wire() \
|
|
|
|
&& std::equal(c.data.begin() + 1, c.data.end(), c.data.begin());
|
|
|
|
|
|
|
|
if (!no_signode) {
|
2019-04-19 17:37:43 -05:00
|
|
|
net = gen_signode_simple(c, false);
|
|
|
|
log_assert(!net.empty());
|
|
|
|
}
|
2023-01-13 09:17:03 -06:00
|
|
|
|
2014-11-08 03:58:57 -06:00
|
|
|
std::string repinfo = rep > 1 ? stringf("%dx ", rep) : "";
|
2023-01-13 09:16:03 -06:00
|
|
|
std::string portside = stringf("%d:%d", bitpos, bitpos - rep*c.width + 1);
|
2023-01-13 09:25:02 -06:00
|
|
|
std::string remoteside = stringf("%s%d:%d", repinfo.c_str(), cl, cr);
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (driver) {
|
2019-04-19 17:37:43 -05:00
|
|
|
log_assert(!net.empty());
|
2023-01-13 09:25:02 -06:00
|
|
|
label_pieces.push_back(stringf("<s%d> %s - %s ", chunk_idx, portside.c_str(), remoteside.c_str()));
|
2023-01-13 09:10:20 -06:00
|
|
|
net_conn_map[net].in.insert({stringf("x%d:s%d", dot_idx, chunk_idx), rep*c.width});
|
2013-04-01 07:58:43 -05:00
|
|
|
net_conn_map[net].color = nextColor(c, net_conn_map[net].color);
|
2013-01-05 04:13:26 -06:00
|
|
|
} else {
|
2023-01-13 09:17:03 -06:00
|
|
|
if (no_signode) {
|
|
|
|
log_assert(rep == 1);
|
|
|
|
label_pieces.push_back(stringf("%c -> %d:%d ",
|
|
|
|
c.data.front() == State::S0 ? '0' :
|
|
|
|
c.data.front() == State::S1 ? '1' :
|
|
|
|
c.data.front() == State::Sx ? 'X' :
|
|
|
|
c.data.front() == State::Sz ? 'Z' : '?',
|
2023-01-13 09:16:03 -06:00
|
|
|
bitpos, bitpos-rep*c.width+1));
|
2023-01-13 09:17:03 -06:00
|
|
|
} else {
|
2023-01-13 09:25:02 -06:00
|
|
|
label_pieces.push_back(stringf("<s%d> %s - %s ", chunk_idx, remoteside.c_str(), portside.c_str()));
|
2023-01-13 09:10:20 -06:00
|
|
|
net_conn_map[net].out.insert({stringf("x%d:s%d", dot_idx, chunk_idx), rep*c.width});
|
2023-01-13 09:17:03 -06:00
|
|
|
net_conn_map[net].color = nextColor(c, net_conn_map[net].color);
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2023-01-13 09:16:03 -06:00
|
|
|
|
|
|
|
bitpos -= rep * c.width;
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2023-01-12 10:09:53 -06:00
|
|
|
|
|
|
|
code += stringf("x%d [ shape=record, style=rounded, label=\"", dot_idx) \
|
2023-06-01 03:02:30 -05:00
|
|
|
+ join_label_pieces(label_pieces) + stringf("\", %s ];\n", nextColor(sig).c_str());
|
2023-01-12 10:09:53 -06:00
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (!port.empty()) {
|
2013-03-24 07:32:56 -05:00
|
|
|
currentColor = xorshift32(currentColor);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (driver)
|
2023-01-12 10:03:13 -06:00
|
|
|
code += stringf("%s:e -> x%d:w [arrowhead=odiamond, arrowtail=odiamond, dir=both, %s, %s];\n", port.c_str(), dot_idx, nextColor(sig).c_str(), widthLabel(sig.size()).c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
2023-01-12 10:03:13 -06:00
|
|
|
code += stringf("x%d:e -> %s:w [arrowhead=odiamond, arrowtail=odiamond, dir=both, %s, %s];\n", dot_idx, port.c_str(), nextColor(sig).c_str(), widthLabel(sig.size()).c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2020-04-06 03:51:25 -05:00
|
|
|
if (node != nullptr)
|
2023-01-12 10:03:13 -06:00
|
|
|
*node = stringf("x%d", dot_idx);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (!port.empty()) {
|
|
|
|
if (driver)
|
2022-04-04 13:40:46 -05:00
|
|
|
net_conn_map[net].in.insert({port, GetSize(sig)});
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
2022-04-04 13:40:46 -05:00
|
|
|
net_conn_map[net].out.insert({port, GetSize(sig)});
|
2013-04-01 07:12:17 -05:00
|
|
|
net_conn_map[net].color = nextColor(sig, net_conn_map[net].color);
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2020-04-06 03:51:25 -05:00
|
|
|
if (node != nullptr)
|
2013-01-05 04:13:26 -06:00
|
|
|
*node = net;
|
|
|
|
}
|
|
|
|
return code;
|
|
|
|
}
|
|
|
|
|
2013-05-23 02:15:51 -05:00
|
|
|
void collect_proc_signals(std::vector<RTLIL::SigSpec> &obj, std::set<RTLIL::SigSpec> &signals)
|
|
|
|
{
|
|
|
|
for (auto &it : obj)
|
|
|
|
if (!it.is_fully_const())
|
|
|
|
signals.insert(it);
|
|
|
|
}
|
|
|
|
|
|
|
|
void collect_proc_signals(std::vector<RTLIL::SigSig> &obj, std::set<RTLIL::SigSpec> &input_signals, std::set<RTLIL::SigSpec> &output_signals)
|
|
|
|
{
|
|
|
|
for (auto &it : obj) {
|
|
|
|
output_signals.insert(it.first);
|
|
|
|
if (!it.second.is_fully_const())
|
|
|
|
input_signals.insert(it.second);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void collect_proc_signals(RTLIL::CaseRule *obj, std::set<RTLIL::SigSpec> &input_signals, std::set<RTLIL::SigSpec> &output_signals)
|
|
|
|
{
|
|
|
|
collect_proc_signals(obj->compare, input_signals);
|
|
|
|
collect_proc_signals(obj->actions, input_signals, output_signals);
|
|
|
|
for (auto it : obj->switches)
|
|
|
|
collect_proc_signals(it, input_signals, output_signals);
|
|
|
|
}
|
|
|
|
|
|
|
|
void collect_proc_signals(RTLIL::SwitchRule *obj, std::set<RTLIL::SigSpec> &input_signals, std::set<RTLIL::SigSpec> &output_signals)
|
|
|
|
{
|
|
|
|
input_signals.insert(obj->signal);
|
|
|
|
for (auto it : obj->cases)
|
|
|
|
collect_proc_signals(it, input_signals, output_signals);
|
|
|
|
}
|
|
|
|
|
|
|
|
void collect_proc_signals(RTLIL::SyncRule *obj, std::set<RTLIL::SigSpec> &input_signals, std::set<RTLIL::SigSpec> &output_signals)
|
|
|
|
{
|
|
|
|
input_signals.insert(obj->signal);
|
|
|
|
collect_proc_signals(obj->actions, input_signals, output_signals);
|
2021-02-22 17:21:46 -06:00
|
|
|
for (auto it : obj->mem_write_actions) {
|
|
|
|
input_signals.insert(it.address);
|
|
|
|
input_signals.insert(it.data);
|
|
|
|
input_signals.insert(it.enable);
|
|
|
|
}
|
2013-05-23 02:15:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
void collect_proc_signals(RTLIL::Process *obj, std::set<RTLIL::SigSpec> &input_signals, std::set<RTLIL::SigSpec> &output_signals)
|
|
|
|
{
|
|
|
|
collect_proc_signals(&obj->root_case, input_signals, output_signals);
|
|
|
|
for (auto it : obj->syncs)
|
|
|
|
collect_proc_signals(it, input_signals, output_signals);
|
|
|
|
}
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
void handle_module()
|
|
|
|
{
|
|
|
|
single_idx_count = 0;
|
|
|
|
dot_escape_store.clear();
|
|
|
|
dot_id2num_store.clear();
|
|
|
|
net_conn_map.clear();
|
|
|
|
|
2014-08-03 05:40:23 -05:00
|
|
|
fprintf(f, "digraph \"%s\" {\n", escape(module->name.str()));
|
2014-02-02 10:55:32 -06:00
|
|
|
if (!notitle)
|
2014-08-03 05:40:23 -05:00
|
|
|
fprintf(f, "label=\"%s\";\n", escape(module->name.str()));
|
2013-01-05 04:13:26 -06:00
|
|
|
fprintf(f, "rankdir=\"LR\";\n");
|
|
|
|
fprintf(f, "remincross=true;\n");
|
|
|
|
|
2013-03-24 07:27:04 -05:00
|
|
|
std::set<std::string> all_sources, all_sinks;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
std::map<std::string, std::string> wires_on_demand;
|
2020-04-06 09:48:27 -05:00
|
|
|
for (auto wire : module->selected_wires()) {
|
2013-01-05 04:13:26 -06:00
|
|
|
const char *shape = "diamond";
|
2020-04-06 09:48:27 -05:00
|
|
|
if (wire->port_input || wire->port_output)
|
2013-01-05 04:13:26 -06:00
|
|
|
shape = "octagon";
|
2020-09-14 05:43:18 -05:00
|
|
|
if (wire->name.isPublic()) {
|
2023-05-24 10:52:14 -05:00
|
|
|
fprintf(f, "n%d [ shape=%s, label=\"%s\", %s ];\n",
|
2020-04-06 09:48:27 -05:00
|
|
|
id2num(wire->name), shape, findLabel(wire->name.str()),
|
2023-05-24 10:52:14 -05:00
|
|
|
nextColor(RTLIL::SigSpec(wire), "color=\"black\", fontcolor=\"black\"").c_str());
|
2020-04-06 09:48:27 -05:00
|
|
|
if (wire->port_input)
|
|
|
|
all_sources.insert(stringf("n%d", id2num(wire->name)));
|
|
|
|
else if (wire->port_output)
|
|
|
|
all_sinks.insert(stringf("n%d", id2num(wire->name)));
|
2013-03-24 09:15:28 -05:00
|
|
|
} else {
|
2020-04-06 09:48:27 -05:00
|
|
|
wires_on_demand[stringf("n%d", id2num(wire->name))] = wire->name.str();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-24 07:27:04 -05:00
|
|
|
if (stretchIO)
|
|
|
|
{
|
|
|
|
fprintf(f, "{ rank=\"source\";");
|
|
|
|
for (auto n : all_sources)
|
|
|
|
fprintf(f, " %s;", n.c_str());
|
|
|
|
fprintf(f, "}\n");
|
|
|
|
|
|
|
|
fprintf(f, "{ rank=\"sink\";");
|
|
|
|
for (auto n : all_sinks)
|
|
|
|
fprintf(f, " %s;", n.c_str());
|
|
|
|
fprintf(f, "}\n");
|
|
|
|
}
|
|
|
|
|
2020-04-06 03:51:25 -05:00
|
|
|
for (auto cell : module->selected_cells())
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
std::vector<RTLIL::IdString> in_ports, out_ports;
|
2023-01-12 10:09:53 -06:00
|
|
|
std::vector<std::string> in_label_pieces, out_label_pieces;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2020-04-06 03:51:25 -05:00
|
|
|
for (auto &conn : cell->connections()) {
|
|
|
|
if (!ct.cell_output(cell->type, conn.first))
|
2013-01-05 04:13:26 -06:00
|
|
|
in_ports.push_back(conn.first);
|
|
|
|
else
|
|
|
|
out_ports.push_back(conn.first);
|
|
|
|
}
|
|
|
|
|
2014-09-19 04:13:10 -05:00
|
|
|
std::sort(in_ports.begin(), in_ports.end(), RTLIL::sort_by_id_str());
|
|
|
|
std::sort(out_ports.begin(), out_ports.end(), RTLIL::sort_by_id_str());
|
|
|
|
|
2023-01-12 10:06:31 -06:00
|
|
|
for (auto &p : in_ports) {
|
|
|
|
bool signed_suffix = genSignedLabels && cell->hasParam(p.str() + "_SIGNED")
|
|
|
|
&& cell->getParam(p.str() + "_SIGNED").as_bool();
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2023-01-12 10:09:53 -06:00
|
|
|
in_label_pieces.push_back(stringf("<p%d> %s%s", id2num(p), escape(p.str()),
|
|
|
|
signed_suffix ? "*" : ""));
|
2023-01-12 10:06:31 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
for (auto &p : out_ports)
|
2023-01-12 10:09:53 -06:00
|
|
|
out_label_pieces.push_back(stringf("<p%d> %s", id2num(p), escape(p.str())));
|
|
|
|
|
|
|
|
std::string in_label = join_label_pieces(in_label_pieces);
|
|
|
|
std::string out_label = join_label_pieces(out_label_pieces);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2023-01-12 10:09:53 -06:00
|
|
|
std::string label_string = stringf("{{%s}|%s\\n%s|{%s}}", in_label.c_str(),
|
|
|
|
findLabel(cell->name.str()), escape(cell->type.str()),
|
|
|
|
out_label.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
std::string code;
|
2020-04-06 03:51:25 -05:00
|
|
|
for (auto &conn : cell->connections()) {
|
|
|
|
code += gen_portbox(stringf("c%d:p%d", id2num(cell->name), id2num(conn.first)),
|
|
|
|
conn.second, ct.cell_output(cell->type, conn.first));
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CLUSTER_CELLS_AND_PORTBOXES
|
|
|
|
if (!code.empty())
|
2014-02-01 11:23:32 -06:00
|
|
|
fprintf(f, "subgraph cluster_c%d {\nc%d [ shape=record, label=\"%s\"%s ];\n%s}\n",
|
2023-05-24 10:52:14 -05:00
|
|
|
id2num(cell->name), id2num(cell->name), label_string.c_str(), color.c_str(), code.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
|
|
|
#endif
|
2023-05-31 10:38:46 -05:00
|
|
|
fprintf(f, "c%d [ shape=record, label=\"%s\", %s ];\n%s",
|
|
|
|
id2num(cell->name), label_string.c_str(), findColor(cell->name).c_str(), code.c_str());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2013-05-23 02:15:51 -05:00
|
|
|
for (auto &it : module->processes)
|
|
|
|
{
|
|
|
|
RTLIL::Process *proc = it.second;
|
|
|
|
|
|
|
|
if (!design->selected_member(module->name, proc->name))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::set<RTLIL::SigSpec> input_signals, output_signals;
|
|
|
|
collect_proc_signals(proc, input_signals, output_signals);
|
|
|
|
|
|
|
|
int pidx = single_idx_count++;
|
|
|
|
input_signals.erase(RTLIL::SigSpec());
|
|
|
|
output_signals.erase(RTLIL::SigSpec());
|
|
|
|
|
|
|
|
for (auto &sig : input_signals) {
|
|
|
|
std::string code, node;
|
|
|
|
code += gen_portbox("", sig, false, &node);
|
|
|
|
fprintf(f, "%s", code.c_str());
|
2022-04-04 13:40:46 -05:00
|
|
|
net_conn_map[node].out.insert({stringf("p%d", pidx), GetSize(sig)});
|
2013-11-28 14:02:19 -06:00
|
|
|
net_conn_map[node].color = nextColor(sig, net_conn_map[node].color);
|
2013-05-23 02:15:51 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &sig : output_signals) {
|
|
|
|
std::string code, node;
|
|
|
|
code += gen_portbox("", sig, true, &node);
|
|
|
|
fprintf(f, "%s", code.c_str());
|
2022-04-04 13:40:46 -05:00
|
|
|
net_conn_map[node].in.insert({stringf("p%d", pidx), GetSize(sig)});
|
2013-11-28 14:02:19 -06:00
|
|
|
net_conn_map[node].color = nextColor(sig, net_conn_map[node].color);
|
2013-05-23 02:15:51 -05:00
|
|
|
}
|
|
|
|
|
2013-11-28 10:37:50 -06:00
|
|
|
std::string proc_src = RTLIL::unescape_id(proc->name);
|
2020-03-12 14:57:01 -05:00
|
|
|
if (proc->attributes.count(ID::src) > 0)
|
|
|
|
proc_src = proc->attributes.at(ID::src).decode_string();
|
2024-01-15 10:47:59 -06:00
|
|
|
fprintf(f, "p%d [shape=box, style=rounded, label=\"PROC %s\\n%s\", %s];\n", pidx, findLabel(proc->name.str()), proc_src.c_str(), findColor(proc->name).c_str());
|
2013-05-23 02:15:51 -05:00
|
|
|
}
|
|
|
|
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &conn : module->connections())
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
bool found_lhs_wire = false;
|
2014-07-22 13:15:14 -05:00
|
|
|
for (auto &c : conn.first.chunks()) {
|
2020-04-06 03:51:25 -05:00
|
|
|
if (c.wire == nullptr || design->selected_member(module->name, c.wire->name))
|
2013-01-05 04:13:26 -06:00
|
|
|
found_lhs_wire = true;
|
|
|
|
}
|
|
|
|
bool found_rhs_wire = false;
|
2014-07-22 13:15:14 -05:00
|
|
|
for (auto &c : conn.second.chunks()) {
|
2020-04-06 03:51:25 -05:00
|
|
|
if (c.wire == nullptr || design->selected_member(module->name, c.wire->name))
|
2013-01-05 04:13:26 -06:00
|
|
|
found_rhs_wire = true;
|
|
|
|
}
|
|
|
|
if (!found_lhs_wire || !found_rhs_wire)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
std::string code, left_node, right_node;
|
|
|
|
code += gen_portbox("", conn.second, false, &left_node);
|
|
|
|
code += gen_portbox("", conn.first, true, &right_node);
|
|
|
|
fprintf(f, "%s", code.c_str());
|
|
|
|
|
2013-03-24 07:11:06 -05:00
|
|
|
if (left_node[0] == 'x' && right_node[0] == 'x') {
|
2013-03-24 07:32:56 -05:00
|
|
|
currentColor = xorshift32(currentColor);
|
2014-12-23 06:49:54 -06:00
|
|
|
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 {
|
2013-04-01 07:12:17 -05:00
|
|
|
net_conn_map[right_node].color = nextColor(conn, net_conn_map[right_node].color);
|
|
|
|
net_conn_map[left_node].color = nextColor(conn, net_conn_map[left_node].color);
|
2013-03-24 07:11:06 -05:00
|
|
|
if (left_node[0] == 'x') {
|
2022-04-04 13:40:46 -05:00
|
|
|
net_conn_map[right_node].in.insert({left_node, GetSize(conn.first)});
|
2013-03-24 07:11:06 -05:00
|
|
|
} else if (right_node[0] == 'x') {
|
2022-04-04 13:40:46 -05:00
|
|
|
net_conn_map[left_node].out.insert({right_node, GetSize(conn.first)});
|
2013-03-24 07:11:06 -05:00
|
|
|
} else {
|
2023-05-31 10:38:46 -05:00
|
|
|
net_conn_map[right_node].in.insert({stringf("x%d", single_idx_count), GetSize(conn.first)});
|
|
|
|
net_conn_map[left_node].out.insert({stringf("x%d", single_idx_count), GetSize(conn.first)});
|
2023-09-25 10:20:16 -05:00
|
|
|
fprintf(f, "x%d [shape=point, %s];\n", single_idx_count++, findColor(conn).c_str());
|
2013-03-24 07:11:06 -05:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto &it : net_conn_map)
|
|
|
|
{
|
2013-03-24 07:32:56 -05:00
|
|
|
currentColor = xorshift32(currentColor);
|
2013-01-05 04:13:26 -06:00
|
|
|
if (wires_on_demand.count(it.first) > 0) {
|
2022-04-04 13:40:46 -05:00
|
|
|
if (it.second.in.size() == 1 && it.second.out.size() > 1 && it.second.in.begin()->first.compare(0, 1, "p") == 0)
|
2013-05-23 02:15:51 -05:00
|
|
|
it.second.out.erase(*it.second.in.begin());
|
2013-01-05 04:13:26 -06:00
|
|
|
if (it.second.in.size() == 1 && it.second.out.size() == 1) {
|
2022-04-04 13:40:46 -05:00
|
|
|
std::string from = it.second.in.begin()->first, to = it.second.out.begin()->first;
|
|
|
|
int bits = it.second.in.begin()->second;
|
2019-08-07 14:20:08 -05:00
|
|
|
if (from != to || from.compare(0, 1, "p") != 0)
|
2022-04-04 13:40:46 -05:00
|
|
|
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());
|
2013-01-05 04:13:26 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (it.second.in.size() == 0 || it.second.out.size() == 0)
|
2014-02-01 11:23:32 -06:00
|
|
|
fprintf(f, "%s [ shape=diamond, label=\"%s\" ];\n", it.first.c_str(), findLabel(wires_on_demand[it.first]));
|
2013-01-05 04:13:26 -06:00
|
|
|
else
|
|
|
|
fprintf(f, "%s [ shape=point ];\n", it.first.c_str());
|
|
|
|
}
|
|
|
|
for (auto &it2 : it.second.in)
|
2022-04-04 13:40:46 -05:00
|
|
|
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());
|
2013-01-05 04:13:26 -06:00
|
|
|
for (auto &it2 : it.second.out)
|
2022-04-04 13:40:46 -05:00
|
|
|
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());
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-05-10 09:22:56 -05:00
|
|
|
fprintf(f, "}\n");
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
|
2014-08-04 08:33:51 -05:00
|
|
|
ShowWorker(FILE *f, RTLIL::Design *design, std::vector<RTLIL::Design*> &libs, uint32_t colorSeed, bool genWidthLabels,
|
|
|
|
bool genSignedLabels, bool stretchIO, bool enumerateIds, bool abbreviateIds, bool notitle,
|
2013-04-01 07:12:17 -05:00
|
|
|
const std::vector<std::pair<std::string, RTLIL::Selection>> &color_selections,
|
2014-12-23 05:29:29 -06:00
|
|
|
const std::vector<std::pair<std::string, RTLIL::Selection>> &label_selections, RTLIL::IdString colorattr) :
|
2013-11-28 14:02:19 -06:00
|
|
|
f(f), design(design), currentColor(colorSeed), genWidthLabels(genWidthLabels),
|
2014-08-04 08:33:51 -05:00
|
|
|
genSignedLabels(genSignedLabels), stretchIO(stretchIO), enumerateIds(enumerateIds), abbreviateIds(abbreviateIds),
|
2014-12-23 05:29:29 -06:00
|
|
|
notitle(notitle), color_selections(color_selections), label_selections(label_selections), colorattr(colorattr)
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
|
|
|
ct.setup_internals();
|
|
|
|
ct.setup_internals_mem();
|
2022-07-21 07:22:15 -05:00
|
|
|
ct.setup_internals_anyinit();
|
2013-01-05 04:13:26 -06:00
|
|
|
ct.setup_stdcells();
|
|
|
|
ct.setup_stdcells_mem();
|
2013-03-03 03:36:23 -06:00
|
|
|
ct.setup_design(design);
|
|
|
|
|
|
|
|
for (auto lib : libs)
|
|
|
|
ct.setup_design(lib);
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
design->optimize();
|
|
|
|
page_counter = 0;
|
2020-04-06 03:51:25 -05:00
|
|
|
for (auto mod : design->selected_modules())
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2020-04-06 03:51:25 -05:00
|
|
|
module = mod;
|
2013-03-24 20:14:33 -05:00
|
|
|
if (design->selected_whole_module(module->name)) {
|
2019-04-18 10:42:12 -05:00
|
|
|
if (module->get_blackbox_attribute()) {
|
2020-04-06 03:51:25 -05:00
|
|
|
// log("Skipping blackbox module %s.\n", log_id(module->name));
|
2013-03-28 03:20:10 -05:00
|
|
|
continue;
|
|
|
|
} else
|
2020-04-06 03:51:25 -05:00
|
|
|
if (module->cells().size() == 0 && module->connections().empty() && module->processes.empty()) {
|
|
|
|
log("Skipping empty module %s.\n", log_id(module->name));
|
2013-03-24 20:14:33 -05:00
|
|
|
continue;
|
|
|
|
} else
|
2020-04-06 03:51:25 -05:00
|
|
|
log("Dumping module %s to page %d.\n", log_id(module->name), ++page_counter);
|
2013-03-24 20:14:33 -05:00
|
|
|
} else
|
2020-04-06 03:51:25 -05:00
|
|
|
log("Dumping selected parts of module %s to page %d.\n", log_id(module->name), ++page_counter);
|
2013-01-05 04:13:26 -06:00
|
|
|
handle_module();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ShowPass : public Pass {
|
2013-02-28 06:59:49 -06:00
|
|
|
ShowPass() : Pass("show", "generate schematics using graphviz") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2013-02-28 06:59:49 -06:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2013-03-03 03:36:23 -06:00
|
|
|
log(" show [options] [selection]\n");
|
2013-02-28 06:59:49 -06:00
|
|
|
log("\n");
|
|
|
|
log("Create a graphviz DOT file for the selected part of the design and compile it\n");
|
2013-03-27 12:14:16 -05:00
|
|
|
log("to a graphics file (usually SVG or PostScript).\n");
|
2013-02-28 06:59:49 -06:00
|
|
|
log("\n");
|
2013-03-27 12:14:16 -05:00
|
|
|
log(" -viewer <viewer>\n");
|
|
|
|
log(" Run the specified command with the graphics file as parameter.\n");
|
2018-08-15 16:16:07 -05:00
|
|
|
log(" On Windows, this pauses yosys until the viewer exits.\n");
|
2023-06-01 03:02:30 -05:00
|
|
|
log(" Use \"-viewer none\" to not run any command.\n");
|
2013-03-27 12:14:16 -05:00
|
|
|
log("\n");
|
|
|
|
log(" -format <format>\n");
|
2016-08-28 05:34:36 -05:00
|
|
|
log(" Generate a graphics file in the specified format. Use 'dot' to just\n");
|
|
|
|
log(" generate a .dot file, or other <format> strings such as 'svg' or 'ps'\n");
|
|
|
|
log(" to generate files in other formats (this calls the 'dot' command).\n");
|
2013-02-28 06:59:49 -06:00
|
|
|
log("\n");
|
2020-08-26 12:29:32 -05:00
|
|
|
log(" -lib <verilog_or_rtlil_file>\n");
|
2013-03-24 07:11:06 -05:00
|
|
|
log(" Use the specified library file for determining whether cell ports are\n");
|
|
|
|
log(" inputs or outputs. This option can be used multiple times to specify\n");
|
|
|
|
log(" more than one library.\n");
|
|
|
|
log("\n");
|
2015-03-29 13:22:08 -05:00
|
|
|
log(" note: in most cases it is better to load the library before calling\n");
|
|
|
|
log(" show with 'read_verilog -lib <filename>'. it is also possible to\n");
|
|
|
|
log(" load liberty files with 'read_liberty -lib <filename>'.\n");
|
|
|
|
log("\n");
|
2013-03-24 07:11:06 -05:00
|
|
|
log(" -prefix <prefix>\n");
|
2013-08-21 05:16:44 -05:00
|
|
|
log(" generate <prefix>.* instead of ~/.yosys_show.*\n");
|
2013-03-03 03:36:23 -06:00
|
|
|
log("\n");
|
2014-02-01 11:23:32 -06:00
|
|
|
log(" -color <color> <object>\n");
|
|
|
|
log(" assign the specified color to the specified object. The object can be\n");
|
2013-04-01 07:12:17 -05:00
|
|
|
log(" a single selection wildcard expressions or a saved set of objects in\n");
|
|
|
|
log(" the @<name> syntax (see \"help select\" for details).\n");
|
|
|
|
log("\n");
|
2014-02-01 11:23:32 -06:00
|
|
|
log(" -label <text> <object>\n");
|
|
|
|
log(" assign the specified label text to the specified object. The object can\n");
|
|
|
|
log(" be a single selection wildcard expressions or a saved set of objects in\n");
|
|
|
|
log(" the @<name> syntax (see \"help select\" for details).\n");
|
|
|
|
log("\n");
|
2013-03-24 04:41:24 -05:00
|
|
|
log(" -colors <seed>\n");
|
2013-03-24 07:11:06 -05:00
|
|
|
log(" Randomly assign colors to the wires. The integer argument is the seed\n");
|
|
|
|
log(" for the random number generator. Change the seed value if the colored\n");
|
2015-08-14 03:56:05 -05:00
|
|
|
log(" graph still is ambiguous. A seed of zero deactivates the coloring.\n");
|
2013-03-24 07:11:06 -05:00
|
|
|
log("\n");
|
2014-12-23 05:29:29 -06:00
|
|
|
log(" -colorattr <attribute_name>\n");
|
|
|
|
log(" Use the specified attribute to assign colors. A unique color is\n");
|
|
|
|
log(" assigned to each unique value of this attribute.\n");
|
|
|
|
log("\n");
|
2013-03-24 07:27:04 -05:00
|
|
|
log(" -width\n");
|
2018-12-07 13:14:07 -06:00
|
|
|
log(" annotate buses with a label indicating the width of the bus.\n");
|
2013-03-24 04:41:24 -05:00
|
|
|
log("\n");
|
2014-08-04 08:33:51 -05:00
|
|
|
log(" -signed\n");
|
2015-08-14 03:56:05 -05:00
|
|
|
log(" mark ports (A, B) that are declared as signed (using the [AB]_SIGNED\n");
|
2014-08-04 08:33:51 -05:00
|
|
|
log(" cell parameter) with an asterisk next to the port name.\n");
|
|
|
|
log("\n");
|
2013-03-24 07:27:04 -05:00
|
|
|
log(" -stretch\n");
|
|
|
|
log(" stretch the graph so all inputs are on the left side and all outputs\n");
|
|
|
|
log(" (including inout ports) are on the right side.\n");
|
|
|
|
log("\n");
|
2013-11-28 06:35:28 -06:00
|
|
|
log(" -pause\n");
|
2021-11-12 04:55:47 -06:00
|
|
|
log(" wait for the user to press enter to before returning\n");
|
2013-11-28 06:35:28 -06:00
|
|
|
log("\n");
|
2013-11-28 14:02:19 -06:00
|
|
|
log(" -enum\n");
|
|
|
|
log(" enumerate objects with internal ($-prefixed) names\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -long\n");
|
2015-08-14 03:56:05 -05:00
|
|
|
log(" do not abbreviate objects with internal ($-prefixed) names\n");
|
2013-11-28 14:02:19 -06:00
|
|
|
log("\n");
|
2014-02-02 10:55:32 -06:00
|
|
|
log(" -notitle\n");
|
|
|
|
log(" do not add the module name as graph title to the dot file\n");
|
|
|
|
log("\n");
|
2018-07-06 19:04:16 -05:00
|
|
|
log(" -nobg\n");
|
|
|
|
log(" don't run viewer in the background, IE wait for the viewer tool to\n");
|
|
|
|
log(" exit before returning\n");
|
|
|
|
log("\n");
|
2014-09-01 21:03:06 -05:00
|
|
|
log("When no <format> is specified, 'dot' is used. When no <format> and <viewer> is\n");
|
2018-08-15 16:16:07 -05:00
|
|
|
log("specified, 'xdot' is used to display the schematic (POSIX systems only).\n");
|
2013-03-27 12:14:16 -05:00
|
|
|
log("\n");
|
2013-06-12 03:42:59 -05:00
|
|
|
log("The generated output files are '~/.yosys_show.dot' and '~/.yosys_show.<format>',\n");
|
2013-03-27 12:14:16 -05:00
|
|
|
log("unless another prefix is specified using -prefix <prefix>.\n");
|
2013-02-28 06:59:49 -06:00
|
|
|
log("\n");
|
2015-02-19 02:11:38 -06:00
|
|
|
log("Yosys on Windows and YosysJS use different defaults: The output is written\n");
|
2016-08-28 05:34:36 -05:00
|
|
|
log("to 'show.dot' in the current directory and new viewer is launched each time\n");
|
|
|
|
log("the 'show' command is executed.\n");
|
2015-02-19 02:11:38 -06:00
|
|
|
log("\n");
|
2013-02-28 06:59:49 -06:00
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::vector<std::string> args, RTLIL::Design *design) override
|
2013-01-05 04:13:26 -06:00
|
|
|
{
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Generating Graphviz representation of design.\n");
|
2013-03-03 03:36:23 -06:00
|
|
|
log_push();
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2013-04-01 07:12:17 -05:00
|
|
|
std::vector<std::pair<std::string, RTLIL::Selection>> color_selections;
|
|
|
|
std::vector<std::pair<std::string, RTLIL::Selection>> label_selections;
|
|
|
|
|
2019-11-11 03:23:06 -06:00
|
|
|
#if defined(_WIN32) || defined(YOSYS_DISABLE_SPAWN)
|
2015-02-15 15:53:41 -06:00
|
|
|
std::string format = "dot";
|
|
|
|
std::string prefix = "show";
|
|
|
|
#else
|
2013-03-27 12:14:16 -05:00
|
|
|
std::string format;
|
2013-06-12 03:42:59 -05:00
|
|
|
std::string prefix = stringf("%s/.yosys_show", getenv("HOME") ? getenv("HOME") : ".");
|
2015-02-15 15:53:41 -06:00
|
|
|
#endif
|
|
|
|
std::string viewer_exe;
|
2013-03-03 03:36:23 -06:00
|
|
|
std::vector<std::string> libfiles;
|
|
|
|
std::vector<RTLIL::Design*> libs;
|
2013-03-24 04:41:24 -05:00
|
|
|
uint32_t colorSeed = 0;
|
2013-03-24 07:27:04 -05:00
|
|
|
bool flag_width = false;
|
2014-08-04 08:33:51 -05:00
|
|
|
bool flag_signed = false;
|
2013-03-24 07:27:04 -05:00
|
|
|
bool flag_stretch = false;
|
2013-11-28 06:35:28 -06:00
|
|
|
bool flag_pause = false;
|
2013-11-28 14:02:19 -06:00
|
|
|
bool flag_enum = false;
|
2015-08-14 03:56:05 -05:00
|
|
|
bool flag_abbreviate = true;
|
2014-02-02 10:55:32 -06:00
|
|
|
bool flag_notitle = false;
|
2018-01-07 09:36:13 -06:00
|
|
|
bool custom_prefix = false;
|
2018-07-06 19:04:16 -05:00
|
|
|
std::string background = "&";
|
2014-12-23 05:29:29 -06:00
|
|
|
RTLIL::IdString colorattr;
|
2013-01-05 04:13:26 -06:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
|
|
|
std::string arg = args[argidx];
|
|
|
|
if (arg == "-viewer" && argidx+1 < args.size()) {
|
|
|
|
viewer_exe = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-03 03:36:23 -06:00
|
|
|
if (arg == "-lib" && argidx+1 < args.size()) {
|
|
|
|
libfiles.push_back(args[++argidx]);
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-24 07:11:06 -05:00
|
|
|
if (arg == "-prefix" && argidx+1 < args.size()) {
|
|
|
|
prefix = args[++argidx];
|
2018-01-07 09:36:13 -06:00
|
|
|
custom_prefix = true;
|
2013-03-24 07:11:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-04-01 07:12:17 -05:00
|
|
|
if (arg == "-color" && argidx+2 < args.size()) {
|
|
|
|
std::pair<std::string, RTLIL::Selection> data;
|
|
|
|
data.first = args[++argidx], argidx++;
|
|
|
|
handle_extra_select_args(this, args, argidx, argidx+1, design);
|
|
|
|
data.second = design->selection_stack.back();
|
|
|
|
design->selection_stack.pop_back();
|
|
|
|
color_selections.push_back(data);
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-01 11:23:32 -06:00
|
|
|
if (arg == "-label" && argidx+2 < args.size()) {
|
2013-04-01 07:12:17 -05:00
|
|
|
std::pair<std::string, RTLIL::Selection> data;
|
|
|
|
data.first = args[++argidx], argidx++;
|
|
|
|
handle_extra_select_args(this, args, argidx, argidx+1, design);
|
|
|
|
data.second = design->selection_stack.back();
|
|
|
|
design->selection_stack.pop_back();
|
|
|
|
label_selections.push_back(data);
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-24 04:41:24 -05:00
|
|
|
if (arg == "-colors" && argidx+1 < args.size()) {
|
2019-08-07 13:09:17 -05:00
|
|
|
colorSeed = atoi(args[++argidx].c_str());
|
2014-07-18 09:44:45 -05:00
|
|
|
for (int i = 0; i < 100; i++)
|
|
|
|
colorSeed = ShowWorker::xorshift32(colorSeed);
|
2013-03-24 04:41:24 -05:00
|
|
|
continue;
|
|
|
|
}
|
2014-12-23 05:29:29 -06:00
|
|
|
if (arg == "-colorattr" && argidx+1 < args.size()) {
|
|
|
|
colorattr = RTLIL::escape_id(args[++argidx]);
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-27 12:14:16 -05:00
|
|
|
if (arg == "-format" && argidx+1 < args.size()) {
|
2013-04-15 04:59:35 -05:00
|
|
|
format = args[++argidx];
|
2013-03-27 12:14:16 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-03-24 07:27:04 -05:00
|
|
|
if (arg == "-width") {
|
|
|
|
flag_width= true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-08-04 08:33:51 -05:00
|
|
|
if (arg == "-signed") {
|
|
|
|
flag_signed= true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-24 07:27:04 -05:00
|
|
|
if (arg == "-stretch") {
|
|
|
|
flag_stretch= true;
|
2013-03-24 07:11:06 -05:00
|
|
|
continue;
|
|
|
|
}
|
2013-11-28 06:35:28 -06:00
|
|
|
if (arg == "-pause") {
|
|
|
|
flag_pause= true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-11-28 14:02:19 -06:00
|
|
|
if (arg == "-enum") {
|
|
|
|
flag_enum = true;
|
2015-08-14 03:56:05 -05:00
|
|
|
flag_abbreviate = false;
|
2013-11-28 14:02:19 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (arg == "-long") {
|
|
|
|
flag_enum = false;
|
2015-08-14 03:56:05 -05:00
|
|
|
flag_abbreviate = false;
|
2013-11-28 14:02:19 -06:00
|
|
|
continue;
|
|
|
|
}
|
2014-02-02 10:55:32 -06:00
|
|
|
if (arg == "-notitle") {
|
|
|
|
flag_notitle = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-07-06 19:04:16 -05:00
|
|
|
if (arg == "-nobg") {
|
|
|
|
background= "";
|
|
|
|
continue;
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(args, argidx, design);
|
|
|
|
|
2016-08-15 17:36:24 -05:00
|
|
|
if (format != "ps" && format != "dot") {
|
2013-03-27 12:31:42 -05:00
|
|
|
int modcount = 0;
|
2020-04-06 03:51:25 -05:00
|
|
|
for (auto module : design->selected_modules()) {
|
|
|
|
if (module->get_blackbox_attribute())
|
2013-03-28 03:20:10 -05:00
|
|
|
continue;
|
2020-04-06 03:51:25 -05:00
|
|
|
if (module->cells().size() == 0 && module->connections().empty())
|
2013-03-28 03:20:10 -05:00
|
|
|
continue;
|
2020-04-06 03:51:25 -05:00
|
|
|
modcount++;
|
2013-03-28 03:20:10 -05:00
|
|
|
}
|
2013-03-27 12:31:42 -05:00
|
|
|
if (modcount > 1)
|
2016-08-15 17:36:24 -05:00
|
|
|
log_cmd_error("For formats different than 'ps' or 'dot' only one module must be selected.\n");
|
2013-03-27 12:31:42 -05:00
|
|
|
}
|
|
|
|
|
2013-03-03 03:36:23 -06:00
|
|
|
for (auto filename : libfiles) {
|
2014-08-23 08:03:55 -05:00
|
|
|
std::ifstream f;
|
2022-08-18 05:39:11 -05:00
|
|
|
rewrite_filename(filename);
|
2014-08-23 08:03:55 -05:00
|
|
|
f.open(filename.c_str());
|
2018-01-07 09:36:13 -06:00
|
|
|
yosys_input_files.insert(filename);
|
2014-08-23 08:03:55 -05:00
|
|
|
if (f.fail())
|
2013-03-03 03:36:23 -06:00
|
|
|
log_error("Can't open lib file `%s'.\n", filename.c_str());
|
|
|
|
RTLIL::Design *lib = new RTLIL::Design;
|
2020-08-26 12:29:32 -05:00
|
|
|
Frontend::frontend_call(lib, &f, filename, (filename.size() > 3 && filename.compare(filename.size()-3, std::string::npos, ".il") == 0 ? "rtlil" : "verilog"));
|
2013-03-03 03:36:23 -06:00
|
|
|
libs.push_back(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (libs.size() > 0)
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Continuing show pass.\n");
|
2013-03-03 03:36:23 -06:00
|
|
|
|
2013-03-24 07:11:06 -05:00
|
|
|
std::string dot_file = stringf("%s.dot", prefix.c_str());
|
2013-03-27 12:14:16 -05:00
|
|
|
std::string out_file = stringf("%s.%s", prefix.c_str(), format.empty() ? "svg" : format.c_str());
|
2013-03-24 07:11:06 -05:00
|
|
|
|
|
|
|
log("Writing dot description to `%s'.\n", dot_file.c_str());
|
|
|
|
FILE *f = fopen(dot_file.c_str(), "w");
|
2018-01-07 09:36:13 -06:00
|
|
|
if (custom_prefix)
|
|
|
|
yosys_output_files.insert(dot_file);
|
2020-04-06 03:51:25 -05:00
|
|
|
if (f == nullptr) {
|
2013-03-27 12:14:16 -05:00
|
|
|
for (auto lib : libs)
|
|
|
|
delete lib;
|
2013-03-24 07:11:06 -05:00
|
|
|
log_cmd_error("Can't open dot file `%s' for writing.\n", dot_file.c_str());
|
2013-03-27 12:14:16 -05:00
|
|
|
}
|
2015-08-14 03:56:05 -05:00
|
|
|
ShowWorker worker(f, design, libs, colorSeed, flag_width, flag_signed, flag_stretch, flag_enum, flag_abbreviate, flag_notitle, color_selections, label_selections, colorattr);
|
2013-01-05 04:13:26 -06:00
|
|
|
fclose(f);
|
|
|
|
|
2013-03-27 12:14:16 -05:00
|
|
|
for (auto lib : libs)
|
|
|
|
delete lib;
|
|
|
|
|
2013-01-05 04:13:26 -06:00
|
|
|
if (worker.page_counter == 0)
|
|
|
|
log_cmd_error("Nothing there to show.\n");
|
|
|
|
|
2014-09-01 20:28:46 -05:00
|
|
|
if (format != "dot" && !format.empty()) {
|
2018-08-15 16:15:44 -05:00
|
|
|
#ifdef _WIN32
|
|
|
|
// system()/cmd.exe does not understand single quotes on Windows.
|
|
|
|
#define DOT_CMD "dot -T%s \"%s\" > \"%s.new\" && move \"%s.new\" \"%s\""
|
|
|
|
#else
|
|
|
|
#define DOT_CMD "dot -T%s '%s' > '%s.new' && mv '%s.new' '%s'"
|
|
|
|
#endif
|
|
|
|
std::string cmd = stringf(DOT_CMD, format.c_str(), dot_file.c_str(), out_file.c_str(), out_file.c_str(), out_file.c_str());
|
|
|
|
#undef DOT_CMD
|
2013-11-28 06:35:28 -06:00
|
|
|
log("Exec: %s\n", cmd.c_str());
|
2019-11-11 03:23:06 -06:00
|
|
|
#if !defined(YOSYS_DISABLE_SPAWN)
|
|
|
|
if (run_command(cmd) != 0)
|
|
|
|
log_cmd_error("Shell command failed!\n");
|
|
|
|
#endif
|
2013-11-28 06:35:28 -06:00
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
|
2019-11-11 03:23:06 -06:00
|
|
|
#if defined(YOSYS_DISABLE_SPAWN)
|
|
|
|
log_assert(viewer_exe.empty() && !format.empty());
|
|
|
|
#else
|
2023-06-01 03:02:30 -05:00
|
|
|
if (viewer_exe != "none") {
|
|
|
|
if (!viewer_exe.empty()) {
|
|
|
|
#ifdef _WIN32
|
|
|
|
// system()/cmd.exe does not understand single quotes nor
|
|
|
|
// background tasks on Windows. So we have to pause yosys
|
|
|
|
// until the viewer exits.
|
|
|
|
std::string cmd = stringf("%s \"%s\"", viewer_exe.c_str(), out_file.c_str());
|
|
|
|
#else
|
|
|
|
std::string cmd = stringf("%s '%s' %s", viewer_exe.c_str(), out_file.c_str(), background.c_str());
|
|
|
|
#endif
|
|
|
|
log("Exec: %s\n", cmd.c_str());
|
|
|
|
if (run_command(cmd) != 0)
|
|
|
|
log_cmd_error("Shell command failed!\n");
|
|
|
|
} else
|
|
|
|
if (format.empty()) {
|
|
|
|
#ifdef __APPLE__
|
|
|
|
std::string cmd = stringf("ps -fu %d | grep -q '[ ]%s' || xdot '%s' %s", getuid(), dot_file.c_str(), dot_file.c_str(), background.c_str());
|
|
|
|
#else
|
|
|
|
std::string cmd = stringf("{ test -f '%s.pid' && fuser -s '%s.pid' 2> /dev/null; } || ( echo $$ >&3; exec xdot '%s'; ) 3> '%s.pid' %s", dot_file.c_str(), dot_file.c_str(), dot_file.c_str(), dot_file.c_str(), background.c_str());
|
|
|
|
#endif
|
|
|
|
log("Exec: %s\n", cmd.c_str());
|
|
|
|
if (run_command(cmd) != 0)
|
|
|
|
log_cmd_error("Shell command failed!\n");
|
|
|
|
}
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
2019-11-11 03:23:06 -06:00
|
|
|
#endif
|
2013-03-03 03:36:23 -06:00
|
|
|
|
2013-11-28 06:35:28 -06:00
|
|
|
if (flag_pause) {
|
2014-08-22 09:09:13 -05:00
|
|
|
#ifdef YOSYS_ENABLE_READLINE
|
2020-04-06 03:51:25 -05:00
|
|
|
char *input = nullptr;
|
|
|
|
while ((input = readline("Press ENTER to continue (or type 'shell' to open a shell)> ")) != nullptr) {
|
2013-11-28 06:35:28 -06:00
|
|
|
if (input[strspn(input, " \t\r\n")] == 0)
|
|
|
|
break;
|
|
|
|
char *p = input + strspn(input, " \t\r\n");
|
|
|
|
if (!strcmp(p, "shell")) {
|
|
|
|
Pass::call(design, "shell");
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2014-08-22 09:09:13 -05:00
|
|
|
#else
|
|
|
|
log_cmd_error("This version of yosys is built without readline support => 'show -pause' is not available.\n");
|
|
|
|
#endif
|
2013-11-28 06:35:28 -06:00
|
|
|
}
|
|
|
|
|
2013-03-03 03:36:23 -06:00
|
|
|
log_pop();
|
2013-01-05 04:13:26 -06:00
|
|
|
}
|
|
|
|
} ShowPass;
|
2015-07-02 04:14:30 -05:00
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|