2013-09-15 06:13:01 -05:00
|
|
|
/*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// [[CITE]] Berkeley Logic Interchange Format (BLIF)
|
|
|
|
// University of California. Berkeley. July 28, 1992
|
|
|
|
// http://www.ece.cmu.edu/~ee760/760docs/blif.pdf
|
|
|
|
|
|
|
|
#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-09-15 06:33:33 -05:00
|
|
|
struct BlifDumperConfig
|
|
|
|
{
|
2014-02-21 03:40:15 -06:00
|
|
|
bool icells_mode;
|
2013-09-15 06:33:33 -05:00
|
|
|
bool conn_mode;
|
|
|
|
bool impltf_mode;
|
2014-02-21 03:40:15 -06:00
|
|
|
bool gates_mode;
|
|
|
|
bool param_mode;
|
2014-12-14 10:45:03 -06:00
|
|
|
bool blackbox_mode;
|
2013-09-15 06:33:33 -05:00
|
|
|
|
2013-10-17 14:37:18 -05:00
|
|
|
std::string buf_type, buf_in, buf_out;
|
2014-12-14 10:37:46 -06:00
|
|
|
std::map<RTLIL::IdString, std::pair<RTLIL::IdString, RTLIL::IdString>> unbuf_types;
|
2013-10-17 14:37:18 -05:00
|
|
|
std::string true_type, true_out, false_type, false_out;
|
|
|
|
|
2014-12-14 10:45:03 -06:00
|
|
|
BlifDumperConfig() : icells_mode(false), conn_mode(false), impltf_mode(false), gates_mode(false), param_mode(false), blackbox_mode(false) { }
|
2013-09-15 06:33:33 -05:00
|
|
|
};
|
|
|
|
|
2013-09-15 06:13:01 -05:00
|
|
|
struct BlifDumper
|
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
std::ostream &f;
|
2013-09-15 06:13:01 -05:00
|
|
|
RTLIL::Module *module;
|
|
|
|
RTLIL::Design *design;
|
2013-09-15 06:33:33 -05:00
|
|
|
BlifDumperConfig *config;
|
2013-09-15 06:13:01 -05:00
|
|
|
CellTypes ct;
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
BlifDumper(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, BlifDumperConfig *config) :
|
2013-09-15 06:33:33 -05:00
|
|
|
f(f), module(module), design(design), config(config), ct(design)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> cstr_buf;
|
|
|
|
|
|
|
|
const char *cstr(RTLIL::IdString id)
|
|
|
|
{
|
|
|
|
std::string str = RTLIL::unescape_id(id);
|
|
|
|
for (size_t i = 0; i < str.size(); i++)
|
|
|
|
if (str[i] == '#' || str[i] == '=')
|
|
|
|
str[i] = '?';
|
|
|
|
cstr_buf.push_back(str);
|
|
|
|
return cstr_buf.back().c_str();
|
|
|
|
}
|
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
const char *cstr(RTLIL::SigBit sig)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
2014-07-24 15:47:57 -05:00
|
|
|
if (sig.wire == NULL)
|
|
|
|
return sig == RTLIL::State::S1 ? "$true" : "$false";
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
std::string str = RTLIL::unescape_id(sig.wire->name);
|
2013-09-15 06:13:01 -05:00
|
|
|
for (size_t i = 0; i < str.size(); i++)
|
|
|
|
if (str[i] == '#' || str[i] == '=')
|
|
|
|
str[i] = '?';
|
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
if (sig.wire->width != 1)
|
|
|
|
str += stringf("[%d]", sig.offset);
|
2013-09-15 06:13:01 -05:00
|
|
|
|
|
|
|
cstr_buf.push_back(str);
|
|
|
|
return cstr_buf.back().c_str();
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
const char *subckt_or_gate(std::string cell_type)
|
|
|
|
{
|
|
|
|
if (!config->gates_mode)
|
|
|
|
return "subckt";
|
2014-07-27 03:18:00 -05:00
|
|
|
if (!design->modules_.count(RTLIL::escape_id(cell_type)))
|
2014-02-21 03:40:15 -06:00
|
|
|
return "gate";
|
2014-07-27 03:18:00 -05:00
|
|
|
if (design->modules_.at(RTLIL::escape_id(cell_type))->get_bool_attribute("\\blackbox"))
|
2014-02-21 03:40:15 -06:00
|
|
|
return "gate";
|
|
|
|
return "subckt";
|
|
|
|
}
|
|
|
|
|
2013-09-15 06:13:01 -05:00
|
|
|
void dump()
|
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
|
|
|
f << stringf(".model %s\n", cstr(module->name));
|
2013-09-15 06:13:01 -05:00
|
|
|
|
|
|
|
std::map<int, RTLIL::Wire*> inputs, outputs;
|
|
|
|
|
2014-07-26 18:49:51 -05:00
|
|
|
for (auto &wire_it : module->wires_) {
|
2013-09-15 06:13:01 -05:00
|
|
|
RTLIL::Wire *wire = wire_it.second;
|
|
|
|
if (wire->port_input)
|
|
|
|
inputs[wire->port_id] = wire;
|
|
|
|
if (wire->port_output)
|
|
|
|
outputs[wire->port_id] = wire;
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".inputs");
|
2013-09-15 06:13:01 -05:00
|
|
|
for (auto &it : inputs) {
|
|
|
|
RTLIL::Wire *wire = it.second;
|
|
|
|
for (int i = 0; i < wire->width; i++)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" %s", cstr(RTLIL::SigSpec(wire, i)));
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".outputs");
|
2013-09-15 06:13:01 -05:00
|
|
|
for (auto &it : outputs) {
|
|
|
|
RTLIL::Wire *wire = it.second;
|
|
|
|
for (int i = 0; i < wire->width; i++)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" %s", cstr(RTLIL::SigSpec(wire, i)));
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2014-12-14 10:45:03 -06:00
|
|
|
if (module->get_bool_attribute("\\blackbox")) {
|
|
|
|
f << stringf(".blackbox\n");
|
|
|
|
f << stringf(".end\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-15 06:33:33 -05:00
|
|
|
if (!config->impltf_mode) {
|
2013-10-17 14:37:18 -05:00
|
|
|
if (!config->false_type.empty())
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".%s %s %s=$false\n", subckt_or_gate(config->false_type),
|
2014-02-21 03:40:15 -06:00
|
|
|
config->false_type.c_str(), config->false_out.c_str());
|
2013-10-17 14:37:18 -05:00
|
|
|
else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names $false\n");
|
2013-10-17 14:37:18 -05:00
|
|
|
if (!config->true_type.empty())
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".%s %s %s=$true\n", subckt_or_gate(config->true_type),
|
2014-02-21 03:40:15 -06:00
|
|
|
config->true_type.c_str(), config->true_out.c_str());
|
2013-10-17 14:37:18 -05:00
|
|
|
else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names $true\n1\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
}
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2014-07-26 18:51:45 -05:00
|
|
|
for (auto &cell_it : module->cells_)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
|
|
|
RTLIL::Cell *cell = cell_it.second;
|
|
|
|
|
2014-12-14 10:37:46 -06:00
|
|
|
if (config->unbuf_types.count(cell->type)) {
|
|
|
|
auto portnames = config->unbuf_types.at(cell->type);
|
|
|
|
f << stringf(".names %s %s\n1 1\n",
|
|
|
|
cstr(cell->getPort(portnames.first)), cstr(cell->getPort(portnames.second)));
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-15 07:11:40 -05:00
|
|
|
if (!config->icells_mode && cell->type == "$_NOT_") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s\n0 1\n",
|
2014-07-31 09:38:54 -05:00
|
|
|
cstr(cell->getPort("\\A")), cstr(cell->getPort("\\Y")));
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
if (!config->icells_mode && cell->type == "$_AND_") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s\n11 1\n",
|
2014-07-31 09:38:54 -05:00
|
|
|
cstr(cell->getPort("\\A")), cstr(cell->getPort("\\B")), cstr(cell->getPort("\\Y")));
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
if (!config->icells_mode && cell->type == "$_OR_") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s\n1- 1\n-1 1\n",
|
2014-07-31 09:38:54 -05:00
|
|
|
cstr(cell->getPort("\\A")), cstr(cell->getPort("\\B")), cstr(cell->getPort("\\Y")));
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
if (!config->icells_mode && cell->type == "$_XOR_") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s\n10 1\n01 1\n",
|
2014-07-31 09:38:54 -05:00
|
|
|
cstr(cell->getPort("\\A")), cstr(cell->getPort("\\B")), cstr(cell->getPort("\\Y")));
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
if (!config->icells_mode && cell->type == "$_MUX_") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s %s\n1-0 1\n-11 1\n",
|
2014-07-31 09:38:54 -05:00
|
|
|
cstr(cell->getPort("\\A")), cstr(cell->getPort("\\B")),
|
|
|
|
cstr(cell->getPort("\\S")), cstr(cell->getPort("\\Y")));
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
if (!config->icells_mode && cell->type == "$_DFF_N_") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".latch %s %s fe %s\n",
|
2014-07-31 09:38:54 -05:00
|
|
|
cstr(cell->getPort("\\D")), cstr(cell->getPort("\\Q")), cstr(cell->getPort("\\C")));
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
if (!config->icells_mode && cell->type == "$_DFF_P_") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".latch %s %s re %s\n",
|
2014-07-31 09:38:54 -05:00
|
|
|
cstr(cell->getPort("\\D")), cstr(cell->getPort("\\Q")), cstr(cell->getPort("\\C")));
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-02-22 07:25:32 -06:00
|
|
|
if (!config->icells_mode && cell->type == "$lut") {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names");
|
2014-08-15 07:18:40 -05:00
|
|
|
auto &inputs = cell->getPort("\\A");
|
2014-02-22 07:25:32 -06:00
|
|
|
auto width = cell->parameters.at("\\WIDTH").as_int();
|
2014-07-22 13:15:14 -05:00
|
|
|
log_assert(inputs.size() == width);
|
|
|
|
for (int i = 0; i < inputs.size(); i++) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" %s", cstr(inputs.extract(i, 1)));
|
2014-02-22 07:25:32 -06:00
|
|
|
}
|
2014-08-15 07:18:40 -05:00
|
|
|
auto &output = cell->getPort("\\Y");
|
2014-07-22 13:15:14 -05:00
|
|
|
log_assert(output.size() == 1);
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" %s", cstr(output));
|
|
|
|
f << stringf("\n");
|
2014-02-22 07:25:32 -06:00
|
|
|
auto mask = cell->parameters.at("\\LUT").as_string();
|
|
|
|
for (int i = 0; i < (1 << width); i++) {
|
|
|
|
if (mask[i] == '0') continue;
|
|
|
|
for (int j = width-1; j >= 0; j--) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << ((i>>j)&1 ? '1' : '0');
|
2014-02-22 07:25:32 -06:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" %c\n", mask[i]);
|
2014-02-22 07:25:32 -06:00
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".%s %s", subckt_or_gate(cell->type.str()), cstr(cell->type));
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &conn : cell->connections())
|
2014-07-22 13:15:14 -05:00
|
|
|
for (int i = 0; i < conn.second.size(); i++) {
|
|
|
|
if (conn.second.size() == 1)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" %s", cstr(conn.first));
|
2013-09-15 06:13:01 -05:00
|
|
|
else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(" %s[%d]", cstr(conn.first), i);
|
|
|
|
f << stringf("=%s", cstr(conn.second.extract(i, 1)));
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2014-02-21 03:40:15 -06:00
|
|
|
|
|
|
|
if (config->param_mode)
|
|
|
|
for (auto ¶m : cell->parameters) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".param %s ", RTLIL::id2cstr(param.first));
|
2014-02-21 03:40:15 -06:00
|
|
|
if (param.second.flags & RTLIL::CONST_FLAG_STRING) {
|
|
|
|
std::string str = param.second.decode_string();
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\"");
|
2014-02-21 03:40:15 -06:00
|
|
|
for (char ch : str)
|
|
|
|
if (ch == '"' || ch == '\\')
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\\%c", ch);
|
2014-02-21 03:40:15 -06:00
|
|
|
else if (ch < 32 || ch >= 127)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\\%03o", ch);
|
2014-02-21 03:40:15 -06:00
|
|
|
else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%c", ch);
|
|
|
|
f << stringf("\"\n");
|
2014-02-21 03:40:15 -06:00
|
|
|
} else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("%s\n", param.second.as_string().c_str());
|
2014-02-21 03:40:15 -06:00
|
|
|
}
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &conn : module->connections())
|
2014-07-22 13:15:14 -05:00
|
|
|
for (int i = 0; i < conn.first.size(); i++)
|
2013-09-15 06:33:33 -05:00
|
|
|
if (config->conn_mode)
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".conn %s %s\n", cstr(conn.second.extract(i, 1)), cstr(conn.first.extract(i, 1)));
|
2013-10-17 14:37:18 -05:00
|
|
|
else if (!config->buf_type.empty())
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".%s %s %s=%s %s=%s\n", subckt_or_gate(config->buf_type), config->buf_type.c_str(), config->buf_in.c_str(), cstr(conn.second.extract(i, 1)),
|
2013-10-17 14:37:18 -05:00
|
|
|
config->buf_out.c_str(), cstr(conn.first.extract(i, 1)));
|
2013-09-15 06:33:33 -05:00
|
|
|
else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s\n1 1\n", cstr(conn.second.extract(i, 1)), cstr(conn.first.extract(i, 1)));
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2013-10-17 14:37:18 -05:00
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".end\n");
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
static void dump(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, BlifDumperConfig &config)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
2013-09-15 06:33:33 -05:00
|
|
|
BlifDumper dumper(f, module, design, &config);
|
2013-09-15 06:13:01 -05:00
|
|
|
dumper.dump();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct BlifBackend : public Backend {
|
|
|
|
BlifBackend() : Backend("blif", "write design to BLIF file") { }
|
|
|
|
virtual void help()
|
|
|
|
{
|
|
|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
|
|
|
log("\n");
|
|
|
|
log(" write_blif [options] [filename]\n");
|
|
|
|
log("\n");
|
|
|
|
log("Write the current design to an BLIF file.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -top top_module\n");
|
|
|
|
log(" set the specified module as design top module\n");
|
|
|
|
log("\n");
|
2013-10-17 14:37:18 -05:00
|
|
|
log(" -buf <cell-type> <in-port> <out-port>\n");
|
|
|
|
log(" use cells of type <cell-type> with the specified port names for buffers\n");
|
|
|
|
log("\n");
|
2014-12-14 10:37:46 -06:00
|
|
|
log(" -unbuf <cell-type> <in-port> <out-port>\n");
|
|
|
|
log(" replace buffer cells with the specified name and port names with\n");
|
|
|
|
log(" a .names statement that models a buffer\n");
|
|
|
|
log("\n");
|
2013-10-17 14:37:18 -05:00
|
|
|
log(" -true <cell-type> <out-port>\n");
|
|
|
|
log(" -false <cell-type> <out-port>\n");
|
|
|
|
log(" use the specified cell types to drive nets that are constant 1 or 0\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
log("\n");
|
2014-09-06 01:47:06 -05:00
|
|
|
log("The following options can be useful when the generated file is not going to be\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
log("read by a BLIF parser but a custom tool. It is recommended to not name the output\n");
|
|
|
|
log("file *.blif when any of this options is used.\n");
|
|
|
|
log("\n");
|
2014-02-21 03:40:15 -06:00
|
|
|
log(" -icells\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
log(" do not translate Yosys's internal gates to generic BLIF logic\n");
|
2014-02-21 03:40:15 -06:00
|
|
|
log(" functions. Instead create .subckt or .gate lines for all cells.\n");
|
|
|
|
log("\n");
|
|
|
|
log(" -gates\n");
|
|
|
|
log(" print .gate instead of .subckt lines for all cells that are not\n");
|
|
|
|
log(" instantiations of other modules from this design.\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
log("\n");
|
|
|
|
log(" -conn\n");
|
|
|
|
log(" do not generate buffers for connected wires. instead use the\n");
|
|
|
|
log(" non-standard .conn statement.\n");
|
|
|
|
log("\n");
|
2014-02-21 03:40:15 -06:00
|
|
|
log(" -param\n");
|
|
|
|
log(" use the non-standard .param statement to write module parameters\n");
|
|
|
|
log("\n");
|
2014-12-14 10:45:03 -06:00
|
|
|
log(" -blackbox\n");
|
|
|
|
log(" write blackbox cells with .blackbox statement.\n");
|
|
|
|
log("\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
log(" -impltf\n");
|
|
|
|
log(" do not write definitions for the $true and $false wires.\n");
|
|
|
|
log("\n");
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
2014-08-23 06:54:21 -05:00
|
|
|
virtual void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
|
|
|
std::string top_module_name;
|
2013-10-17 14:37:18 -05:00
|
|
|
std::string buf_type, buf_in, buf_out;
|
|
|
|
std::string true_type, true_out;
|
|
|
|
std::string false_type, false_out;
|
2013-09-15 06:33:33 -05:00
|
|
|
BlifDumperConfig config;
|
2013-09-15 06:13:01 -05:00
|
|
|
|
|
|
|
log_header("Executing BLIF 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;
|
|
|
|
}
|
2013-10-17 14:37:18 -05:00
|
|
|
if (args[argidx] == "-buf" && argidx+3 < args.size()) {
|
|
|
|
config.buf_type = args[++argidx];
|
|
|
|
config.buf_in = args[++argidx];
|
|
|
|
config.buf_out = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2014-12-14 10:37:46 -06:00
|
|
|
if (args[argidx] == "-unbuf" && argidx+3 < args.size()) {
|
|
|
|
RTLIL::IdString unbuf_type = RTLIL::escape_id(args[++argidx]);
|
|
|
|
RTLIL::IdString unbuf_in = RTLIL::escape_id(args[++argidx]);
|
|
|
|
RTLIL::IdString unbuf_out = RTLIL::escape_id(args[++argidx]);
|
|
|
|
config.unbuf_types[unbuf_type] = std::pair<RTLIL::IdString, RTLIL::IdString>(unbuf_in, unbuf_out);
|
|
|
|
continue;
|
|
|
|
}
|
2013-10-17 14:37:18 -05:00
|
|
|
if (args[argidx] == "-true" && argidx+2 < args.size()) {
|
|
|
|
config.true_type = args[++argidx];
|
|
|
|
config.true_out = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-false" && argidx+2 < args.size()) {
|
|
|
|
config.false_type = args[++argidx];
|
|
|
|
config.false_out = args[++argidx];
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-21 03:40:15 -06:00
|
|
|
if (args[argidx] == "-icells") {
|
|
|
|
config.icells_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-gates") {
|
|
|
|
config.gates_mode = true;
|
2013-09-15 06:33:33 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-conn") {
|
|
|
|
config.conn_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-21 03:40:15 -06:00
|
|
|
if (args[argidx] == "-param") {
|
|
|
|
config.param_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-12-14 10:45:03 -06:00
|
|
|
if (args[argidx] == "-blackbox") {
|
|
|
|
config.blackbox_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-15 06:33:33 -05:00
|
|
|
if (args[argidx] == "-impltf") {
|
|
|
|
config.impltf_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2013-09-15 06:13:01 -05:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
extra_args(f, filename, args, argidx);
|
|
|
|
|
2013-11-23 22:03:43 -06:00
|
|
|
if (top_module_name.empty())
|
2014-07-27 03:18:00 -05:00
|
|
|
for (auto & mod_it:design->modules_)
|
2013-11-23 22:03:43 -06:00
|
|
|
if (mod_it.second->get_bool_attribute("\\top"))
|
2014-08-02 11:58:40 -05:00
|
|
|
top_module_name = mod_it.first.str();
|
2013-11-23 22:03:43 -06:00
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
*f << stringf("# Generated by %s\n", yosys_version_str);
|
2013-11-03 14:41:39 -06:00
|
|
|
|
2013-09-15 06:13:01 -05:00
|
|
|
std::vector<RTLIL::Module*> mod_list;
|
|
|
|
|
2014-07-27 03:18:00 -05:00
|
|
|
for (auto module_it : design->modules_)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
|
|
|
RTLIL::Module *module = module_it.second;
|
2014-12-14 10:45:03 -06:00
|
|
|
if (module->get_bool_attribute("\\blackbox") && !config.blackbox_mode)
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (module->processes.size() != 0)
|
|
|
|
log_error("Found unmapped processes in module %s: unmapped processes are not supported in BLIF backend!\n", RTLIL::id2cstr(module->name));
|
|
|
|
if (module->memories.size() != 0)
|
|
|
|
log_error("Found munmapped emories in module %s: unmapped memories are not supported in BLIF backend!\n", RTLIL::id2cstr(module->name));
|
|
|
|
|
|
|
|
if (module->name == RTLIL::escape_id(top_module_name)) {
|
2014-08-23 06:54:21 -05:00
|
|
|
BlifDumper::dump(*f, module, design, config);
|
2013-09-15 06:13:01 -05:00
|
|
|
top_module_name.clear();
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
mod_list.push_back(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!top_module_name.empty())
|
|
|
|
log_error("Can't find top module `%s'!\n", top_module_name.c_str());
|
|
|
|
|
|
|
|
for (auto module : mod_list)
|
2014-08-23 06:54:21 -05:00
|
|
|
BlifDumper::dump(*f, module, design, config);
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
} BlifBackend;
|
|
|
|
|
2014-09-27 09:17:53 -05:00
|
|
|
PRIVATE_NAMESPACE_END
|