aboutsummaryrefslogtreecommitdiffstats
path: root/backends/table/table.cc
blob: 27b7edfff1e4bf9e285f1d861bcfa71e410aff9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
pre { line-height: 125%; margin: 0; }
td.linenos pre { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
span.linenos { color: #000000; background-color: #f0f0f0; padding: 0 5px 0 5px; }
td.linenos pre.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding: 0 5px 0 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight { background: #ffffff; }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } 
/*
 *  yosys -- Yosys Open SYnthesis Suite
 *
 *  Copyright (C) 2012  Clifford Wolf <clifford@clifford.at>
 *
 *  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.
 *
 */

#include "kernel/rtlil.h"
#include "kernel/register.h"
#include "kernel/sigtools.h"
#include "kernel/celltypes.h"
#include "kernel/log.h"
#include <string>

USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN

struct TableBackend : public Backend {
	TableBackend() : Backend("table", "write design as connectivity table") { }
	virtual void help()
	{
		//   |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
		log("\n");
		log("    write_table [options] [filename]\n");
		log("\n");
		log("Write the current design as connectivity table. The output is a tab-separated\n");
		log("ASCII table with the following columns:\n");
		log("\n");
		log("  module name\n");
		log("  cell name\n");
		log("  cell type\n");
		log("  cell port\n");
		log("  direction\n");
		log("  signal\n");
		log("\n");
		log("module inputs and outputs are output using cell type and port '-' and with\n");
		log("'pi' (primary input) or 'po' (primary output) or 'pio' as direction.\n");
	}
	virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
	{
		log_header(design, "Executing TABLE backend.\n");

		size_t argidx;
		for (argidx = 1; argidx < args.size(); argidx++)
		{
			// if (args[argidx] == "-top" && argidx+1 < args.size()) {
			// 	top_module_name = args[++argidx];
			// 	continue;
			// }
			break;
		}
		extra_args(f, filename, args, argidx);

		design->sort();

		for (auto module : design->modules())
		{
			if (module->get_bool_attribute("\\blackbox"))
				continue;

			SigMap sigmap(module);

			for (auto wire : module->wires())
			{
				if (wire->port_id == 0)
					continue;

				*f << log_id(module) << "\t";
				*f << log_id(wire) << "\t";
				*f << "-" << "\t";
				*f << "-" << "\t";

				if (wire->port_input && wire->port_output)
					*f << "pio" << "\t";
				else if (wire->port_input)
					*f << "pi" << "\t";
				else if (wire->port_output)
					*f << "po" << "\t";
				else
					log_abort();

				*f << log_signal(sigmap(wire)) << "\n";
			}

			for (auto cell : module->cells())
			for (auto conn : cell->connections())
			{
				*f << log_id(module) << "\t";
				*f << log_id(cell) << "\t";
				*f << log_id(cell->type) << "\t";
				*f << log_id(conn.first) << "\t";

				if (cell->input(conn.first) && cell->output(conn.first))
					*f << "inout" << "\t";
				else if (cell->input(conn.first))
					*f << "in" << "\t";
				else if (cell->output(conn.first))
					*f << "out" << "\t";
				else
					*f << "unkown" << "\t";

				*f << log_signal(sigmap(conn.second)) << "\n";
			}
		}
	}
} TableBackend;

PRIVATE_NAMESPACE_END