44 std::map<RTLIL::IdString, std::pair<RTLIL::IdString, RTLIL::IdString>>
unbuf_types;
59 f(f), module(module), design(design), config(config),
ct(design)
68 for (
size_t i = 0; i < str.size(); i++)
69 if (str[i] ==
'#' || str[i] ==
'=')
84 for (
size_t i = 0; i < str.size(); i++)
85 if (str[i] ==
'#' || str[i] ==
'=')
111 std::map<int, RTLIL::Wire*> inputs, outputs;
122 for (
auto &it : inputs) {
124 for (
int i = 0; i < wire->
width; i++)
130 for (
auto &it : outputs) {
132 for (
int i = 0; i < wire->
width; i++)
137 if (
module->get_bool_attribute(
"\\blackbox")) {
182 f <<
stringf(
".names %s %s %s\n11 1\n",
188 f <<
stringf(
".names %s %s %s\n1- 1\n-1 1\n",
194 f <<
stringf(
".names %s %s %s\n10 1\n01 1\n",
200 f <<
stringf(
".names %s %s %s %s\n1-0 1\n-11 1\n",
207 f <<
stringf(
".latch %s %s fe %s\n",
213 f <<
stringf(
".latch %s %s re %s\n",
220 auto &inputs = cell->
getPort(
"\\A");
221 auto width = cell->
parameters.at(
"\\WIDTH").as_int();
223 for (
int i = 0; i < inputs.size(); i++) {
226 auto &output = cell->
getPort(
"\\Y");
230 auto mask = cell->
parameters.at(
"\\LUT").as_string();
231 for (
int i = 0; i < (1 << width); i++) {
232 if (mask[i] ==
'0')
continue;
233 for (
int j = width-1; j >= 0; j--) {
234 f << ((i>>j)&1 ?
'1' :
'0');
243 for (
int i = 0; i < conn.second.size(); i++) {
244 if (conn.second.size() == 1)
256 std::string str = param.second.decode_string();
259 if (ch ==
'"' || ch ==
'\\')
261 else if (ch < 32 || ch >= 127)
267 f <<
stringf(
"%s\n", param.second.as_string().c_str());
272 for (
int i = 0; i < conn.first.size(); i++)
274 f <<
stringf(
".conn %s %s\n",
cstr(conn.second.extract(i, 1)),
cstr(conn.first.extract(i, 1)));
279 f <<
stringf(
".names %s %s\n1 1\n",
cstr(conn.second.extract(i, 1)),
cstr(conn.first.extract(i, 1)));
287 BlifDumper dumper(f, module, design, &config);
298 log(
" write_blif [options] [filename]\n");
300 log(
"Write the current design to an BLIF file.\n");
302 log(
" -top top_module\n");
303 log(
" set the specified module as design top module\n");
305 log(
" -buf <cell-type> <in-port> <out-port>\n");
306 log(
" use cells of type <cell-type> with the specified port names for buffers\n");
308 log(
" -unbuf <cell-type> <in-port> <out-port>\n");
309 log(
" replace buffer cells with the specified name and port names with\n");
310 log(
" a .names statement that models a buffer\n");
312 log(
" -true <cell-type> <out-port>\n");
313 log(
" -false <cell-type> <out-port>\n");
314 log(
" -undef <cell-type> <out-port>\n");
315 log(
" use the specified cell types to drive nets that are constant 1, 0, or\n");
316 log(
" undefined. when '-' is used as <cell-type>, then <out-port> specifies\n");
317 log(
" the wire name to be used for the constant signal and no cell driving\n");
318 log(
" that wire is generated.\n");
320 log(
"The following options can be useful when the generated file is not going to be\n");
321 log(
"read by a BLIF parser but a custom tool. It is recommended to not name the output\n");
322 log(
"file *.blif when any of this options is used.\n");
325 log(
" do not translate Yosys's internal gates to generic BLIF logic\n");
326 log(
" functions. Instead create .subckt or .gate lines for all cells.\n");
329 log(
" print .gate instead of .subckt lines for all cells that are not\n");
330 log(
" instantiations of other modules from this design.\n");
333 log(
" do not generate buffers for connected wires. instead use the\n");
334 log(
" non-standard .conn statement.\n");
337 log(
" use the non-standard .param statement to write module parameters\n");
340 log(
" write blackbox cells with .blackbox statement.\n");
343 log(
" do not write definitions for the $true, $false and $undef wires.\n");
348 std::string top_module_name;
349 std::string buf_type, buf_in, buf_out;
350 std::string true_type, true_out;
351 std::string false_type, false_out;
357 for (argidx = 1; argidx < args.size(); argidx++)
359 if (args[argidx] ==
"-top" && argidx+1 < args.size()) {
360 top_module_name = args[++argidx];
363 if (args[argidx] ==
"-buf" && argidx+3 < args.size()) {
365 config.
buf_in = args[++argidx];
366 config.
buf_out = args[++argidx];
369 if (args[argidx] ==
"-unbuf" && argidx+3 < args.size()) {
373 config.
unbuf_types[unbuf_type] = std::pair<RTLIL::IdString, RTLIL::IdString>(unbuf_in, unbuf_out);
376 if (args[argidx] ==
"-true" && argidx+2 < args.size()) {
381 if (args[argidx] ==
"-false" && argidx+2 < args.size()) {
386 if (args[argidx] ==
"-undef" && argidx+2 < args.size()) {
391 if (args[argidx] ==
"-icells") {
395 if (args[argidx] ==
"-gates") {
399 if (args[argidx] ==
"-conn") {
403 if (args[argidx] ==
"-param") {
407 if (args[argidx] ==
"-blackbox") {
411 if (args[argidx] ==
"-impltf") {
419 if (top_module_name.empty())
420 for (
auto & mod_it:design->
modules_)
421 if (mod_it.second->get_bool_attribute(
"\\top"))
422 top_module_name = mod_it.first.str();
426 std::vector<RTLIL::Module*> mod_list;
428 for (
auto module_it : design->
modules_)
431 if (module->get_bool_attribute(
"\\blackbox") && !config.
blackbox_mode)
435 log_error(
"Found unmapped processes in module %s: unmapped processes are not supported in BLIF backend!\n",
RTLIL::id2cstr(module->
name));
437 log_error(
"Found munmapped emories in module %s: unmapped memories are not supported in BLIF backend!\n",
RTLIL::id2cstr(module->
name));
441 top_module_name.clear();
445 mod_list.push_back(module);
448 if (!top_module_name.empty())
449 log_error(
"Can't find top module `%s'!\n", top_module_name.c_str());
451 for (
auto module : mod_list)
const char * yosys_version_str
std::map< RTLIL::IdString, std::pair< RTLIL::IdString, RTLIL::IdString > > unbuf_types
std::string stringf(const char *fmt,...)
static void dump(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, BlifDumperConfig &config)
BlifDumperConfig * config
void log_header(const char *format,...)
const std::vector< RTLIL::SigSig > & connections() const
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
static std::string unescape_id(std::string str)
std::map< RTLIL::IdString, RTLIL::Memory * > memories
std::vector< std::string > cstr_buf
void log_error(const char *format,...)
std::map< RTLIL::IdString, RTLIL::Const > parameters
static std::string escape_id(std::string str)
void extra_args(std::ostream *&f, std::string &filename, std::vector< std::string > args, size_t argidx)
#define PRIVATE_NAMESPACE_BEGIN
virtual void execute(std::ostream *&f, std::string filename, std::vector< std::string > args, RTLIL::Design *design)
const RTLIL::SigSpec & getPort(RTLIL::IdString portname) const
#define log_assert(_assert_expr_)
BlifDumper(std::ostream &f, RTLIL::Module *module, RTLIL::Design *design, BlifDumperConfig *config)
const char * cstr(RTLIL::SigBit sig)
#define PRIVATE_NAMESPACE_END
static const char * id2cstr(const RTLIL::IdString &str)
std::map< RTLIL::IdString, RTLIL::Process * > processes
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
const char * subckt_or_gate(std::string cell_type)
void log(const char *format,...)
const char * cstr(RTLIL::IdString id)
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const