2013-03-23 04:58:14 -05: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-03-23 04:58:14 -05: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-03-23 04:58:14 -05: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/rtlil.h"
|
|
|
|
#include "kernel/register.h"
|
|
|
|
#include "kernel/sigtools.h"
|
|
|
|
#include "kernel/celltypes.h"
|
|
|
|
#include "kernel/log.h"
|
|
|
|
#include <string>
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
USING_YOSYS_NAMESPACE
|
|
|
|
PRIVATE_NAMESPACE_BEGIN
|
2013-03-23 04:58:14 -05:00
|
|
|
|
|
|
|
static std::string netname(std::set<std::string> &conntypes_code, std::set<std::string> &celltypes_code, std::set<std::string> &constcells_code, RTLIL::SigSpec sig)
|
|
|
|
{
|
2014-07-24 15:47:57 -05:00
|
|
|
if (!sig.is_fully_const() && !sig.is_wire())
|
2013-03-23 04:58:14 -05:00
|
|
|
log_error("Can't export composite or non-word-wide signal %s.\n", log_signal(sig));
|
|
|
|
|
2014-07-22 13:15:14 -05:00
|
|
|
conntypes_code.insert(stringf("conntype b%d %d 2 %d\n", sig.size(), sig.size(), sig.size()));
|
2013-03-23 04:58:14 -05:00
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
if (sig.is_fully_const()) {
|
2014-07-22 13:15:14 -05:00
|
|
|
celltypes_code.insert(stringf("celltype CONST_%d b%d *CONST cfg:%d VALUE\n", sig.size(), sig.size(), sig.size()));
|
2014-07-24 15:47:57 -05:00
|
|
|
constcells_code.insert(stringf("node CONST_%d_0x%x CONST_%d CONST CONST_%d_0x%x VALUE 0x%x\n",
|
|
|
|
sig.size(), sig.as_int(), sig.size(), sig.size(), sig.as_int(), sig.as_int()));
|
|
|
|
return stringf("CONST_%d_0x%x", sig.size(), sig.as_int());
|
2013-03-23 04:58:14 -05:00
|
|
|
}
|
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
return RTLIL::unescape_id(sig.as_wire()->name);
|
2013-03-23 04:58:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
struct IntersynthBackend : public Backend {
|
|
|
|
IntersynthBackend() : Backend("intersynth", "write design to InterSynth netlist file") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2013-03-23 04:58:14 -05:00
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
2013-03-23 06:02:09 -05:00
|
|
|
log(" write_intersynth [options] [filename]\n");
|
2013-03-23 04:58:14 -05:00
|
|
|
log("\n");
|
|
|
|
log("Write the current design to an 'intersynth' netlist file. InterSynth is\n");
|
|
|
|
log("a tool for Coarse-Grain Example-Driven Interconnect Synthesis.\n");
|
|
|
|
log("\n");
|
2013-03-24 06:05:25 -05:00
|
|
|
log(" -notypes\n");
|
|
|
|
log(" do not generate celltypes and conntypes commands. i.e. just output\n");
|
|
|
|
log(" the netlists. this is used for postsilicon synthesis.\n");
|
|
|
|
log("\n");
|
2020-08-26 12:29:32 -05:00
|
|
|
log(" -lib <verilog_or_rtlil_file>\n");
|
2013-03-24 06:05:25 -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");
|
2013-03-23 06:02:09 -05:00
|
|
|
log("\n");
|
2013-09-03 12:10:11 -05:00
|
|
|
log(" -selected\n");
|
|
|
|
log(" only write selected modules. modules must be selected entirely or\n");
|
|
|
|
log(" not at all.\n");
|
|
|
|
log("\n");
|
2021-06-09 05:42:52 -05:00
|
|
|
log("http://bygone.clairexen.net/intersynth/\n");
|
2013-03-23 04:58:14 -05:00
|
|
|
log("\n");
|
|
|
|
}
|
2020-06-18 18:34:52 -05:00
|
|
|
void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
|
2013-03-23 04:58:14 -05:00
|
|
|
{
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing INTERSYNTH backend.\n");
|
2013-03-23 06:02:09 -05:00
|
|
|
log_push();
|
|
|
|
|
|
|
|
std::vector<std::string> libfiles;
|
|
|
|
std::vector<RTLIL::Design*> libs;
|
2013-03-24 06:05:25 -05:00
|
|
|
bool flag_notypes = false;
|
2013-09-03 12:10:11 -05:00
|
|
|
bool selected = false;
|
2013-03-23 06:02:09 -05:00
|
|
|
|
|
|
|
size_t argidx;
|
|
|
|
for (argidx = 1; argidx < args.size(); argidx++)
|
|
|
|
{
|
2013-03-24 06:05:25 -05:00
|
|
|
if (args[argidx] == "-notypes") {
|
|
|
|
flag_notypes = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-23 06:02:09 -05:00
|
|
|
if (args[argidx] == "-lib" && argidx+1 < args.size()) {
|
|
|
|
libfiles.push_back(args[++argidx]);
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-03 12:10:11 -05:00
|
|
|
if (args[argidx] == "-selected") {
|
|
|
|
selected = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-03-23 06:02:09 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(f, filename, args, argidx);
|
|
|
|
|
2013-03-23 04:58:14 -05:00
|
|
|
log("Output filename: %s\n", filename.c_str());
|
|
|
|
|
2013-03-23 06:02:09 -05:00
|
|
|
for (auto filename : libfiles) {
|
2014-08-23 08:03:55 -05:00
|
|
|
std::ifstream f;
|
|
|
|
f.open(filename.c_str());
|
|
|
|
if (f.fail())
|
2013-03-23 06:02:09 -05: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-23 06:02:09 -05:00
|
|
|
libs.push_back(lib);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (libs.size() > 0)
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Continuing INTERSYNTH backend.\n");
|
2013-03-23 06:02:09 -05:00
|
|
|
|
2013-03-23 04:58:14 -05:00
|
|
|
std::set<std::string> conntypes_code, celltypes_code;
|
|
|
|
std::string netlists_code;
|
|
|
|
CellTypes ct(design);
|
|
|
|
|
2013-03-23 06:02:09 -05:00
|
|
|
for (auto lib : libs)
|
|
|
|
ct.setup_design(lib);
|
|
|
|
|
2020-04-01 01:32:09 -05:00
|
|
|
for (auto module : design->modules())
|
2013-03-23 04:58:14 -05:00
|
|
|
{
|
|
|
|
SigMap sigmap(module);
|
|
|
|
|
2019-04-18 10:42:12 -05:00
|
|
|
if (module->get_blackbox_attribute())
|
2013-09-03 12:10:11 -05:00
|
|
|
continue;
|
2020-04-01 01:32:09 -05:00
|
|
|
if (module->memories.size() == 0 && module->processes.size() == 0 && module->cells().size() == 0)
|
2013-03-23 04:58:14 -05:00
|
|
|
continue;
|
|
|
|
|
2013-09-03 12:10:11 -05:00
|
|
|
if (selected && !design->selected_whole_module(module->name)) {
|
|
|
|
if (design->selected_module(module->name))
|
2020-04-01 01:32:09 -05:00
|
|
|
log_cmd_error("Can't handle partially selected module %s!\n", log_id(module->name));
|
2013-09-03 12:10:11 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-01 01:32:09 -05:00
|
|
|
log("Generating netlist %s.\n", log_id(module->name));
|
2013-03-23 04:58:14 -05:00
|
|
|
|
|
|
|
if (module->memories.size() != 0 || module->processes.size() != 0)
|
|
|
|
log_error("Can't generate a netlist for a module with unprocessed memories or processes!\n");
|
|
|
|
|
|
|
|
std::set<std::string> constcells_code;
|
2020-04-01 01:32:09 -05:00
|
|
|
netlists_code += stringf("# Netlist of module %s\n", log_id(module->name));
|
|
|
|
netlists_code += stringf("netlist %s\n", log_id(module->name));
|
2013-03-23 04:58:14 -05:00
|
|
|
|
2014-01-25 13:16:38 -06:00
|
|
|
// Module Ports: "std::set<string> celltypes_code" prevents duplicate top level ports
|
2020-04-01 01:32:09 -05:00
|
|
|
for (auto wire : module->wires()) {
|
2013-03-23 04:58:14 -05:00
|
|
|
if (wire->port_input || wire->port_output) {
|
|
|
|
celltypes_code.insert(stringf("celltype !%s b%d %sPORT\n" "%s %s %d %s PORT\n",
|
2020-04-01 01:32:09 -05:00
|
|
|
log_id(wire->name), wire->width, wire->port_input ? "*" : "",
|
|
|
|
wire->port_input ? "input" : "output", log_id(wire->name), wire->width, log_id(wire->name)));
|
|
|
|
netlists_code += stringf("node %s %s PORT %s\n", log_id(wire->name), log_id(wire->name),
|
2013-03-23 04:58:14 -05:00
|
|
|
netname(conntypes_code, celltypes_code, constcells_code, sigmap(wire)).c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-02 04:14:30 -05:00
|
|
|
// Submodules: "std::set<string> celltypes_code" prevents duplicate cell types
|
2020-04-01 01:32:09 -05:00
|
|
|
for (auto cell : module->cells())
|
2013-03-23 04:58:14 -05:00
|
|
|
{
|
|
|
|
std::string celltype_code, node_code;
|
|
|
|
|
2013-03-23 06:02:09 -05:00
|
|
|
if (!ct.cell_known(cell->type))
|
2020-04-01 01:32:09 -05:00
|
|
|
log_error("Found unknown cell type %s in module!\n", log_id(cell->type));
|
2013-03-23 06:02:09 -05:00
|
|
|
|
2020-04-01 01:32:09 -05:00
|
|
|
celltype_code = stringf("celltype %s", log_id(cell->type));
|
|
|
|
node_code = stringf("node %s %s", log_id(cell->name), log_id(cell->type));
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &port : cell->connections()) {
|
2013-03-23 04:58:14 -05:00
|
|
|
RTLIL::SigSpec sig = sigmap(port.second);
|
2014-07-22 13:15:14 -05:00
|
|
|
if (sig.size() != 0) {
|
|
|
|
conntypes_code.insert(stringf("conntype b%d %d 2 %d\n", sig.size(), sig.size(), sig.size()));
|
2020-04-01 01:32:09 -05:00
|
|
|
celltype_code += stringf(" b%d %s%s", sig.size(), ct.cell_output(cell->type, port.first) ? "*" : "", log_id(port.first));
|
|
|
|
node_code += stringf(" %s %s", log_id(port.first), netname(conntypes_code, celltypes_code, constcells_code, sig).c_str());
|
2013-11-03 02:00:51 -06:00
|
|
|
}
|
2013-03-23 04:58:14 -05:00
|
|
|
}
|
|
|
|
for (auto ¶m : cell->parameters) {
|
2024-10-09 12:39:45 -05:00
|
|
|
celltype_code += stringf(" cfg:%d %s", int(param.second.size()), log_id(param.first));
|
|
|
|
if (param.second.size() != 32) {
|
2020-04-01 01:32:09 -05:00
|
|
|
node_code += stringf(" %s '", log_id(param.first));
|
2024-10-09 12:39:45 -05:00
|
|
|
for (int i = param.second.size()-1; i >= 0; i--)
|
|
|
|
node_code += param.second[i] == State::S1 ? "1" : "0";
|
2013-03-23 04:58:14 -05:00
|
|
|
} else
|
2020-04-01 01:32:09 -05:00
|
|
|
node_code += stringf(" %s 0x%x", log_id(param.first), param.second.as_int());
|
2013-03-23 04:58:14 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
celltypes_code.insert(celltype_code + "\n");
|
|
|
|
netlists_code += node_code + "\n";
|
|
|
|
}
|
2013-03-23 06:02:09 -05:00
|
|
|
|
2014-01-25 13:16:38 -06:00
|
|
|
if (constcells_code.size() > 0)
|
|
|
|
netlists_code += "# constant cells\n";
|
2013-03-23 06:02:09 -05:00
|
|
|
for (auto code : constcells_code)
|
|
|
|
netlists_code += code;
|
2014-01-25 13:16:38 -06:00
|
|
|
netlists_code += "\n";
|
2013-03-23 04:58:14 -05:00
|
|
|
}
|
|
|
|
|
2013-03-24 06:05:25 -05:00
|
|
|
if (!flag_notypes) {
|
2014-08-23 06:54:21 -05:00
|
|
|
*f << stringf("### Connection Types\n");
|
2013-03-24 06:05:25 -05:00
|
|
|
for (auto code : conntypes_code)
|
2014-08-23 06:54:21 -05:00
|
|
|
*f << stringf("%s", code.c_str());
|
|
|
|
*f << stringf("\n### Cell Types\n");
|
2013-03-24 06:05:25 -05:00
|
|
|
for (auto code : celltypes_code)
|
2014-08-23 06:54:21 -05:00
|
|
|
*f << stringf("%s", code.c_str());
|
2013-03-24 06:05:25 -05:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
*f << stringf("\n### Netlists\n");
|
|
|
|
*f << stringf("%s", netlists_code.c_str());
|
2013-03-23 06:02:09 -05:00
|
|
|
|
|
|
|
for (auto lib : libs)
|
|
|
|
delete lib;
|
|
|
|
|
|
|
|
log_pop();
|
2013-03-23 04:58:14 -05:00
|
|
|
}
|
|
|
|
} IntersynthBackend;
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|