2013-09-15 06:13:01 -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-09-15 06:13:01 -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-09-15 06:13:01 -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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
// [[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;
|
2016-01-06 07:32:28 -06:00
|
|
|
bool cname_mode;
|
2018-04-15 07:07:21 -05:00
|
|
|
bool iname_mode;
|
2014-02-21 03:40:15 -06:00
|
|
|
bool param_mode;
|
2015-03-02 16:47:45 -06:00
|
|
|
bool attr_mode;
|
2018-04-15 07:07:21 -05:00
|
|
|
bool iattr_mode;
|
2014-12-14 10:45:03 -06:00
|
|
|
bool blackbox_mode;
|
2016-05-06 08:05:53 -05:00
|
|
|
bool noalias_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;
|
2014-12-14 11:00:38 -06:00
|
|
|
std::string true_type, true_out, false_type, false_out, undef_type, undef_out;
|
2013-10-17 14:37:18 -05:00
|
|
|
|
2016-01-06 07:32:28 -06:00
|
|
|
BlifDumperConfig() : icells_mode(false), conn_mode(false), impltf_mode(false), gates_mode(false),
|
2018-04-15 07:07:21 -05:00
|
|
|
cname_mode(false), iname_mode(false), param_mode(false), attr_mode(false), iattr_mode(false),
|
|
|
|
blackbox_mode(false), noalias_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;
|
|
|
|
|
2015-07-29 10:06:19 -05:00
|
|
|
SigMap sigmap;
|
|
|
|
dict<SigBit, int> init_bits;
|
|
|
|
|
2014-08-23 06:54:21 -05:00
|
|
|
BlifDumper(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, BlifDumperConfig *config) :
|
2015-07-29 10:06:19 -05:00
|
|
|
f(f), module(module), design(design), config(config), ct(design), sigmap(module)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
2015-07-29 10:06:19 -05:00
|
|
|
for (Wire *wire : module->wires())
|
2020-04-02 11:51:32 -05:00
|
|
|
if (wire->attributes.count(ID::init)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
SigSpec initsig = sigmap(wire);
|
2020-04-02 11:51:32 -05:00
|
|
|
Const initval = wire->attributes.at(ID::init);
|
2015-07-29 10:06:19 -05:00
|
|
|
for (int i = 0; i < GetSize(initsig) && i < GetSize(initval); i++)
|
|
|
|
switch (initval[i]) {
|
|
|
|
case State::S0:
|
|
|
|
init_bits[initsig[i]] = 0;
|
|
|
|
break;
|
|
|
|
case State::S1:
|
|
|
|
init_bits[initsig[i]] = 1;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2016-05-06 08:05:53 -05:00
|
|
|
pool<SigBit> cstr_bits_seen;
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2020-11-16 02:31:48 -06:00
|
|
|
const std::string str(RTLIL::IdString id)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
|
|
|
std::string str = RTLIL::unescape_id(id);
|
|
|
|
for (size_t i = 0; i < str.size(); i++)
|
2015-04-28 02:56:00 -05:00
|
|
|
if (str[i] == '#' || str[i] == '=' || str[i] == '<' || str[i] == '>')
|
2013-09-15 06:13:01 -05:00
|
|
|
str[i] = '?';
|
2020-11-16 02:31:48 -06:00
|
|
|
return str;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-11-16 02:31:48 -06:00
|
|
|
const std::string str(RTLIL::SigBit sig)
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
2016-05-06 08:05:53 -05:00
|
|
|
cstr_bits_seen.insert(sig);
|
|
|
|
|
2014-12-14 11:00:38 -06:00
|
|
|
if (sig.wire == NULL) {
|
2016-07-08 04:49:55 -05:00
|
|
|
if (sig == RTLIL::State::S0) return config->false_type == "-" || config->false_type == "+" ? config->false_out.c_str() : "$false";
|
|
|
|
if (sig == RTLIL::State::S1) return config->true_type == "-" || config->true_type == "+" ? config->true_out.c_str() : "$true";
|
|
|
|
return config->undef_type == "-" || config->undef_type == "+" ? config->undef_out.c_str() : "$undef";
|
2014-12-14 11:00:38 -06:00
|
|
|
}
|
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++)
|
2015-05-03 04:37:20 -05:00
|
|
|
if (str[i] == '#' || str[i] == '=' || str[i] == '<' || str[i] == '>')
|
2013-09-15 06:13:01 -05:00
|
|
|
str[i] = '?';
|
|
|
|
|
2014-07-24 15:47:57 -05:00
|
|
|
if (sig.wire->width != 1)
|
2016-11-23 06:49:25 -06:00
|
|
|
str += stringf("[%d]", sig.wire->upto ? sig.wire->start_offset+sig.wire->width-sig.offset-1 : sig.wire->start_offset+sig.offset);
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2020-11-16 02:31:48 -06:00
|
|
|
return str;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-11-16 02:31:48 -06:00
|
|
|
const std::string str_init(RTLIL::SigBit sig)
|
2015-07-29 10:06:19 -05:00
|
|
|
{
|
|
|
|
sigmap.apply(sig);
|
|
|
|
|
|
|
|
if (init_bits.count(sig) == 0)
|
2016-10-18 03:54:04 -05:00
|
|
|
return " 2";
|
2015-07-29 10:06:19 -05:00
|
|
|
|
|
|
|
string str = stringf(" %d", init_bits.at(sig));
|
|
|
|
|
2020-11-16 02:31:48 -06:00
|
|
|
return str;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2014-02-21 03:40:15 -06:00
|
|
|
const char *subckt_or_gate(std::string cell_type)
|
|
|
|
{
|
|
|
|
if (!config->gates_mode)
|
|
|
|
return "subckt";
|
2020-04-01 00:50:48 -05:00
|
|
|
if (design->module(RTLIL::escape_id(cell_type)) == nullptr)
|
2014-02-21 03:40:15 -06:00
|
|
|
return "gate";
|
2020-04-01 00:50:48 -05:00
|
|
|
if (design->module(RTLIL::escape_id(cell_type))->get_blackbox_attribute())
|
2014-02-21 03:40:15 -06:00
|
|
|
return "gate";
|
|
|
|
return "subckt";
|
|
|
|
}
|
|
|
|
|
2015-03-02 16:47:45 -06:00
|
|
|
void dump_params(const char *command, dict<IdString, Const> ¶ms)
|
|
|
|
{
|
|
|
|
for (auto ¶m : params) {
|
2020-04-01 00:50:48 -05:00
|
|
|
f << stringf("%s %s ", command, log_id(param.first));
|
2015-03-02 16:47:45 -06:00
|
|
|
if (param.second.flags & RTLIL::CONST_FLAG_STRING) {
|
|
|
|
std::string str = param.second.decode_string();
|
|
|
|
f << stringf("\"");
|
|
|
|
for (char ch : str)
|
|
|
|
if (ch == '"' || ch == '\\')
|
|
|
|
f << stringf("\\%c", ch);
|
|
|
|
else if (ch < 32 || ch >= 127)
|
|
|
|
f << stringf("\\%03o", ch);
|
|
|
|
else
|
|
|
|
f << stringf("%c", ch);
|
|
|
|
f << stringf("\"\n");
|
|
|
|
} else
|
|
|
|
f << stringf("%s\n", param.second.as_string().c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-15 06:13:01 -05:00
|
|
|
void dump()
|
|
|
|
{
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".model %s\n", str(module->name).c_str());
|
2013-09-15 06:13:01 -05:00
|
|
|
|
|
|
|
std::map<int, RTLIL::Wire*> inputs, outputs;
|
|
|
|
|
2020-04-01 00:50:48 -05:00
|
|
|
for (auto wire : module->wires()) {
|
2013-09-15 06:13:01 -05:00
|
|
|
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++)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s", str(RTLIL::SigSpec(wire, i)).c_str());
|
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++)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s", str(RTLIL::SigSpec(wire, i)).c_str());
|
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
|
|
|
|
2019-04-18 10:42:12 -05:00
|
|
|
if (module->get_blackbox_attribute()) {
|
2014-12-14 10:45:03 -06:00
|
|
|
f << stringf(".blackbox\n");
|
|
|
|
f << stringf(".end\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-09-15 06:33:33 -05:00
|
|
|
if (!config->impltf_mode) {
|
2014-12-14 11:00:38 -06:00
|
|
|
if (!config->false_type.empty()) {
|
2016-07-08 04:49:55 -05:00
|
|
|
if (config->false_type == "+")
|
|
|
|
f << stringf(".names %s\n", config->false_out.c_str());
|
|
|
|
else if (config->false_type != "-")
|
2014-12-14 11:00:38 -06:00
|
|
|
f << stringf(".%s %s %s=$false\n", subckt_or_gate(config->false_type),
|
|
|
|
config->false_type.c_str(), config->false_out.c_str());
|
|
|
|
} else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names $false\n");
|
2014-12-14 11:00:38 -06:00
|
|
|
if (!config->true_type.empty()) {
|
2016-07-08 04:49:55 -05:00
|
|
|
if (config->true_type == "+")
|
|
|
|
f << stringf(".names %s\n1\n", config->true_out.c_str());
|
|
|
|
else if (config->true_type != "-")
|
2014-12-14 11:00:38 -06:00
|
|
|
f << stringf(".%s %s %s=$true\n", subckt_or_gate(config->true_type),
|
|
|
|
config->true_type.c_str(), config->true_out.c_str());
|
|
|
|
} else
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names $true\n1\n");
|
2014-12-14 11:00:38 -06:00
|
|
|
if (!config->undef_type.empty()) {
|
2016-07-08 04:49:55 -05:00
|
|
|
if (config->undef_type == "+")
|
|
|
|
f << stringf(".names %s\n", config->undef_out.c_str());
|
|
|
|
else if (config->undef_type != "-")
|
2014-12-14 11:00:38 -06:00
|
|
|
f << stringf(".%s %s %s=$undef\n", subckt_or_gate(config->undef_type),
|
|
|
|
config->undef_type.c_str(), config->undef_out.c_str());
|
|
|
|
} else
|
|
|
|
f << stringf(".names $undef\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
}
|
2013-09-15 06:13:01 -05:00
|
|
|
|
2020-04-01 00:50:48 -05:00
|
|
|
for (auto cell : module->cells())
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
2024-01-11 07:57:34 -06:00
|
|
|
if (cell->type == ID($scopeinfo))
|
|
|
|
continue;
|
|
|
|
|
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",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(portnames.first)).c_str(), str(cell->getPort(portnames.second)).c_str());
|
2014-12-14 10:37:46 -06:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_NOT_)) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s\n0 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_AND_)) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s\n11 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_OR_)) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s\n1- 1\n-1 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_XOR_)) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s\n10 1\n01 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_NAND_)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
f << stringf(".names %s %s %s\n0- 1\n-0 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_NOR_)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
f << stringf(".names %s %s %s\n00 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_XNOR_)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
f << stringf(".names %s %s %s\n11 1\n00 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_ANDNOT_)) {
|
2017-05-17 02:08:29 -05:00
|
|
|
f << stringf(".names %s %s %s\n10 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2017-05-17 02:08:29 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_ORNOT_)) {
|
2017-05-17 02:08:29 -05:00
|
|
|
f << stringf(".names %s %s %s\n1- 1\n-0 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2017-05-17 02:08:29 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_AOI3_)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
f << stringf(".names %s %s %s %s\n-00 1\n0-0 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::C)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_OAI3_)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
f << stringf(".names %s %s %s %s\n00- 1\n--0 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(), str(cell->getPort(ID::C)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_AOI4_)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
f << stringf(".names %s %s %s %s %s\n-0-0 1\n-00- 1\n0--0 1\n0-0- 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(),
|
|
|
|
str(cell->getPort(ID::C)).c_str(), str(cell->getPort(ID::D)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_OAI4_)) {
|
2015-07-29 10:06:19 -05:00
|
|
|
f << stringf(".names %s %s %s %s %s\n00-- 1\n--00 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(),
|
|
|
|
str(cell->getPort(ID::C)).c_str(), str(cell->getPort(ID::D)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2015-07-29 10:06:19 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_MUX_)) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names %s %s %s %s\n1-0 1\n-11 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(),
|
|
|
|
str(cell->getPort(ID::S)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_NMUX_)) {
|
2019-08-05 21:47:55 -05:00
|
|
|
f << stringf(".names %s %s %s %s\n0-0 1\n-01 1\n",
|
2020-11-16 02:31:48 -06:00
|
|
|
str(cell->getPort(ID::A)).c_str(), str(cell->getPort(ID::B)).c_str(),
|
|
|
|
str(cell->getPort(ID::S)).c_str(), str(cell->getPort(ID::Y)).c_str());
|
2019-08-05 21:47:55 -05:00
|
|
|
goto internal_cell;
|
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_FF_)) {
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".latch %s %s%s\n", str(cell->getPort(ID::D)).c_str(), str(cell->getPort(ID::Q)).c_str(),
|
|
|
|
str_init(cell->getPort(ID::Q)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2016-10-11 18:18:39 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_DFF_N_)) {
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".latch %s %s fe %s%s\n", str(cell->getPort(ID::D)).c_str(), str(cell->getPort(ID::Q)).c_str(),
|
|
|
|
str(cell->getPort(ID::C)).c_str(), str_init(cell->getPort(ID::Q)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_DFF_P_)) {
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".latch %s %s re %s%s\n", str(cell->getPort(ID::D)).c_str(), str(cell->getPort(ID::Q)).c_str(),
|
|
|
|
str(cell->getPort(ID::C)).c_str(), str_init(cell->getPort(ID::Q)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_DLATCH_N_)) {
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".latch %s %s al %s%s\n", str(cell->getPort(ID::D)).c_str(), str(cell->getPort(ID::Q)).c_str(),
|
|
|
|
str(cell->getPort(ID::E)).c_str(), str_init(cell->getPort(ID::Q)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2016-04-22 11:00:46 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($_DLATCH_P_)) {
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".latch %s %s ah %s%s\n", str(cell->getPort(ID::D)).c_str(), str(cell->getPort(ID::Q)).c_str(),
|
|
|
|
str(cell->getPort(ID::E)).c_str(), str_init(cell->getPort(ID::Q)).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2016-04-22 11:00:46 -05:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($lut)) {
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf(".names");
|
2020-03-12 14:57:01 -05:00
|
|
|
auto &inputs = cell->getPort(ID::A);
|
2020-04-02 11:51:32 -05:00
|
|
|
auto width = cell->parameters.at(ID::WIDTH).as_int();
|
2014-07-22 13:15:14 -05:00
|
|
|
log_assert(inputs.size() == width);
|
2016-06-18 05:28:49 -05:00
|
|
|
for (int i = width-1; i >= 0; i--)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s", str(inputs.extract(i, 1)).c_str());
|
2020-03-12 14:57:01 -05:00
|
|
|
auto &output = cell->getPort(ID::Y);
|
2014-07-22 13:15:14 -05:00
|
|
|
log_assert(output.size() == 1);
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s", str(output).c_str());
|
2014-08-23 06:54:21 -05:00
|
|
|
f << stringf("\n");
|
2020-04-02 11:51:32 -05:00
|
|
|
RTLIL::SigSpec mask = cell->parameters.at(ID::LUT);
|
2014-12-17 04:13:57 -06:00
|
|
|
for (int i = 0; i < (1 << width); i++)
|
2019-08-07 13:12:38 -05:00
|
|
|
if (mask[i] == State::S1) {
|
2014-12-17 04:13:57 -06:00
|
|
|
for (int j = width-1; j >= 0; j--) {
|
|
|
|
f << ((i>>j)&1 ? '1' : '0');
|
|
|
|
}
|
|
|
|
f << " 1\n";
|
2014-02-22 07:25:32 -06:00
|
|
|
}
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2014-02-22 07:25:32 -06:00
|
|
|
}
|
|
|
|
|
2020-04-02 11:51:32 -05:00
|
|
|
if (!config->icells_mode && cell->type == ID($sop)) {
|
2016-06-18 05:28:49 -05:00
|
|
|
f << stringf(".names");
|
2020-03-12 14:57:01 -05:00
|
|
|
auto &inputs = cell->getPort(ID::A);
|
2020-04-02 11:51:32 -05:00
|
|
|
auto width = cell->parameters.at(ID::WIDTH).as_int();
|
|
|
|
auto depth = cell->parameters.at(ID::DEPTH).as_int();
|
2024-10-09 12:39:45 -05:00
|
|
|
vector<State> table = cell->parameters.at(ID::TABLE).to_bits();
|
2016-06-18 05:28:49 -05:00
|
|
|
while (GetSize(table) < 2*width*depth)
|
|
|
|
table.push_back(State::S0);
|
|
|
|
log_assert(inputs.size() == width);
|
|
|
|
for (int i = 0; i < width; i++)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s", str(inputs.extract(i, 1)).c_str());
|
2020-03-12 14:57:01 -05:00
|
|
|
auto &output = cell->getPort(ID::Y);
|
2016-06-18 05:28:49 -05:00
|
|
|
log_assert(output.size() == 1);
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s", str(output).c_str());
|
2016-06-18 05:28:49 -05:00
|
|
|
f << stringf("\n");
|
|
|
|
for (int i = 0; i < depth; i++) {
|
|
|
|
for (int j = 0; j < width; j++) {
|
|
|
|
bool pat0 = table.at(2*width*i + 2*j + 0) == State::S1;
|
|
|
|
bool pat1 = table.at(2*width*i + 2*j + 1) == State::S1;
|
|
|
|
if (pat0 && !pat1) f << "0";
|
|
|
|
else if (!pat0 && pat1) f << "1";
|
|
|
|
else f << "-";
|
|
|
|
}
|
|
|
|
f << " 1\n";
|
|
|
|
}
|
2018-04-15 07:07:21 -05:00
|
|
|
goto internal_cell;
|
2016-06-18 05:28:49 -05:00
|
|
|
}
|
|
|
|
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".%s %s", subckt_or_gate(cell->type.str()), str(cell->type).c_str());
|
2014-07-26 07:32:50 -05:00
|
|
|
for (auto &conn : cell->connections())
|
2019-05-25 10:45:14 -05:00
|
|
|
{
|
|
|
|
if (conn.second.size() == 1) {
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s=%s", str(conn.first).c_str(), str(conn.second[0]).c_str());
|
2019-05-25 10:45:14 -05:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
Module *m = design->module(cell->type);
|
|
|
|
Wire *w = m ? m->wire(conn.first) : nullptr;
|
|
|
|
|
|
|
|
if (w == nullptr) {
|
|
|
|
for (int i = 0; i < GetSize(conn.second); i++)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s[%d]=%s", str(conn.first).c_str(), i, str(conn.second[i]).c_str());
|
2019-05-25 10:45:14 -05:00
|
|
|
} else {
|
|
|
|
for (int i = 0; i < std::min(GetSize(conn.second), GetSize(w)); i++) {
|
|
|
|
SigBit sig(w, i);
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(" %s[%d]=%s", str(conn.first).c_str(), sig.wire->upto ?
|
2019-05-25 10:45:14 -05:00
|
|
|
sig.wire->start_offset+sig.wire->width-sig.offset-1 :
|
2020-11-16 02:31:48 -06:00
|
|
|
sig.wire->start_offset+sig.offset, str(conn.second[i]).c_str());
|
2019-05-25 10:45:14 -05:00
|
|
|
}
|
|
|
|
}
|
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
|
|
|
|
2016-01-06 07:32:28 -06:00
|
|
|
if (config->cname_mode)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".cname %s\n", str(cell->name).c_str());
|
2015-03-02 16:47:45 -06:00
|
|
|
if (config->attr_mode)
|
|
|
|
dump_params(".attr", cell->attributes);
|
2014-02-21 03:40:15 -06:00
|
|
|
if (config->param_mode)
|
2015-03-02 16:47:45 -06:00
|
|
|
dump_params(".param", cell->parameters);
|
2018-04-15 07:07:21 -05:00
|
|
|
|
|
|
|
if (0) {
|
|
|
|
internal_cell:
|
|
|
|
if (config->iname_mode)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".cname %s\n", str(cell->name).c_str());
|
2018-04-15 07:07:21 -05:00
|
|
|
if (config->iattr_mode)
|
|
|
|
dump_params(".attr", cell->attributes);
|
|
|
|
}
|
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++)
|
2016-05-06 08:05:53 -05:00
|
|
|
{
|
|
|
|
SigBit lhs_bit = conn.first[i];
|
|
|
|
SigBit rhs_bit = conn.second[i];
|
|
|
|
|
|
|
|
if (config->noalias_mode && cstr_bits_seen.count(lhs_bit) == 0)
|
|
|
|
continue;
|
|
|
|
|
2013-09-15 06:33:33 -05:00
|
|
|
if (config->conn_mode)
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".conn %s %s\n", str(rhs_bit).c_str(), str(lhs_bit).c_str());
|
2013-10-17 14:37:18 -05:00
|
|
|
else if (!config->buf_type.empty())
|
2016-05-06 08:05:53 -05:00
|
|
|
f << stringf(".%s %s %s=%s %s=%s\n", subckt_or_gate(config->buf_type), config->buf_type.c_str(),
|
2020-11-16 02:31:48 -06:00
|
|
|
config->buf_in.c_str(), str(rhs_bit).c_str(), config->buf_out.c_str(), str(lhs_bit).c_str());
|
2013-09-15 06:33:33 -05:00
|
|
|
else
|
2020-11-16 02:31:48 -06:00
|
|
|
f << stringf(".names %s %s\n1 1\n", str(rhs_bit).c_str(), str(lhs_bit).c_str());
|
2016-05-06 08:05:53 -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") { }
|
2020-06-18 18:34:52 -05:00
|
|
|
void help() override
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
|
|
|
// |---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");
|
2014-12-14 11:00:38 -06:00
|
|
|
log(" -undef <cell-type> <out-port>\n");
|
|
|
|
log(" use the specified cell types to drive nets that are constant 1, 0, or\n");
|
|
|
|
log(" undefined. when '-' is used as <cell-type>, then <out-port> specifies\n");
|
|
|
|
log(" the wire name to be used for the constant signal and no cell driving\n");
|
2016-07-08 04:49:55 -05:00
|
|
|
log(" that wire is generated. when '+' is used as <cell-type>, then <out-port>\n");
|
|
|
|
log(" specifies the wire name to be used for the constant signal and a .names\n");
|
|
|
|
log(" statement is generated to drive the wire.\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
log("\n");
|
2016-05-06 08:05:53 -05:00
|
|
|
log(" -noalias\n");
|
|
|
|
log(" if a net name is aliasing another net name, then by default a net\n");
|
|
|
|
log(" without fanout is created that is driven by the other net. This option\n");
|
|
|
|
log(" suppresses the generation of this nets without fanout.\n");
|
|
|
|
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");
|
2023-07-10 05:20:19 -05:00
|
|
|
log("read by a BLIF parser but a custom tool. It is recommended not to name the\n");
|
|
|
|
log("output file *.blif when any of these options are used.\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
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");
|
2015-03-02 16:47:45 -06:00
|
|
|
log(" -attr\n");
|
|
|
|
log(" use the non-standard .attr statement to write cell attributes\n");
|
|
|
|
log("\n");
|
2014-02-21 03:40:15 -06:00
|
|
|
log(" -param\n");
|
2015-03-02 16:47:45 -06:00
|
|
|
log(" use the non-standard .param statement to write cell parameters\n");
|
2014-02-21 03:40:15 -06:00
|
|
|
log("\n");
|
2016-01-06 07:32:28 -06:00
|
|
|
log(" -cname\n");
|
|
|
|
log(" use the non-standard .cname statement to write cell names\n");
|
|
|
|
log("\n");
|
2018-04-15 07:07:21 -05:00
|
|
|
log(" -iname, -iattr\n");
|
|
|
|
log(" enable -cname and -attr functionality for .names statements\n");
|
|
|
|
log(" (the .cname and .attr statements will be included in the BLIF\n");
|
|
|
|
log(" output after the truth table for the .names statement)\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");
|
2014-12-14 11:00:38 -06:00
|
|
|
log(" do not write definitions for the $true, $false and $undef wires.\n");
|
2013-09-15 06:33:33 -05:00
|
|
|
log("\n");
|
2013-09-15 06:13:01 -05:00
|
|
|
}
|
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-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
|
|
|
|
2016-04-21 16:28:37 -05:00
|
|
|
log_header(design, "Executing BLIF backend.\n");
|
2013-09-15 06:13:01 -05:00
|
|
|
|
|
|
|
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-12-14 11:00:38 -06:00
|
|
|
if (args[argidx] == "-undef" && argidx+2 < args.size()) {
|
|
|
|
config.undef_type = args[++argidx];
|
|
|
|
config.undef_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;
|
|
|
|
}
|
2016-01-06 07:32:28 -06:00
|
|
|
if (args[argidx] == "-cname") {
|
|
|
|
config.cname_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2014-02-21 03:40:15 -06:00
|
|
|
if (args[argidx] == "-param") {
|
|
|
|
config.param_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2015-03-02 16:47:45 -06:00
|
|
|
if (args[argidx] == "-attr") {
|
|
|
|
config.attr_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
2018-04-15 07:07:21 -05:00
|
|
|
if (args[argidx] == "-iname") {
|
|
|
|
config.iname_mode = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if (args[argidx] == "-iattr") {
|
|
|
|
config.iattr_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;
|
|
|
|
}
|
2016-05-06 08:05:53 -05:00
|
|
|
if (args[argidx] == "-noalias") {
|
|
|
|
config.noalias_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())
|
2020-04-01 00:50:48 -05:00
|
|
|
for (auto module : design->modules())
|
2020-03-12 14:57:01 -05:00
|
|
|
if (module->get_bool_attribute(ID::top))
|
2020-04-01 00:50:48 -05:00
|
|
|
top_module_name = module->name.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;
|
|
|
|
|
2015-05-24 01:03:21 -05:00
|
|
|
design->sort();
|
2020-04-01 00:50:48 -05:00
|
|
|
for (auto module : design->modules())
|
2013-09-15 06:13:01 -05:00
|
|
|
{
|
2019-04-18 10:42:12 -05:00
|
|
|
if (module->get_blackbox_attribute() && !config.blackbox_mode)
|
2013-09-15 06:13:01 -05:00
|
|
|
continue;
|
|
|
|
|
|
|
|
if (module->processes.size() != 0)
|
2020-04-01 00:50:48 -05:00
|
|
|
log_error("Found unmapped processes in module %s: unmapped processes are not supported in BLIF backend!\n", log_id(module->name));
|
2013-09-15 06:13:01 -05:00
|
|
|
if (module->memories.size() != 0)
|
2020-04-01 00:50:48 -05:00
|
|
|
log_error("Found unmapped memories in module %s: unmapped memories are not supported in BLIF backend!\n", log_id(module->name));
|
2013-09-15 06:13:01 -05:00
|
|
|
|
|
|
|
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
|