Skip to content

Commit 0f5a41a

Browse files
committed
Add gatesi_mode to init gates under gates_mode in BLIF format
1 parent 39aacc9 commit 0f5a41a

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

backends/blif/blif.cc

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ struct BlifDumperConfig
4444
bool iattr_mode;
4545
bool blackbox_mode;
4646
bool noalias_mode;
47+
bool gatesi_mode;
4748

4849
std::string buf_type, buf_in, buf_out;
4950
std::map<RTLIL::IdString, std::pair<RTLIL::IdString, RTLIL::IdString>> unbuf_types;
5051
std::string true_type, true_out, false_type, false_out, undef_type, undef_out;
5152

5253
BlifDumperConfig() : icells_mode(false), conn_mode(false), impltf_mode(false), gates_mode(false),
5354
cname_mode(false), iname_mode(false), param_mode(false), attr_mode(false), iattr_mode(false),
54-
blackbox_mode(false), noalias_mode(false) { }
55+
blackbox_mode(false), noalias_mode(false), gatesi_mode(false) { }
5556
};
5657

5758
struct BlifDumper
@@ -229,6 +230,8 @@ struct BlifDumper
229230
if (cell->type == ID($scopeinfo))
230231
continue;
231232

233+
auto gate_init = cell->hasPort(ID::Q) ? str_init(cell->getPort(ID::Q)) : std::string("");
234+
232235
if (config->unbuf_types.count(cell->type)) {
233236
auto portnames = config->unbuf_types.at(cell->type);
234237
f << stringf(".names %s %s\n1 1\n",
@@ -410,7 +413,13 @@ struct BlifDumper
410413
goto internal_cell;
411414
}
412415

413-
f << stringf(".%s %s", subckt_or_gate(cell->type.str()), str(cell->type).c_str());
416+
if (config->gatesi_mode && config->gates_mode) {
417+
f << stringf(".%s %s%s", subckt_or_gate(cell->type.str()), str(cell->type).c_str(), gate_init.c_str());
418+
}
419+
else {
420+
f << stringf(".%s %s", subckt_or_gate(cell->type.str()), str(cell->type).c_str());
421+
}
422+
414423
for (auto &conn : cell->connections())
415424
{
416425
if (conn.second.size() == 1) {
@@ -550,6 +559,9 @@ struct BlifBackend : public Backend {
550559
log(" -impltf\n");
551560
log(" do not write definitions for the $true, $false and $undef wires.\n");
552561
log("\n");
562+
log(" -gatesi\n");
563+
log(" append initial bit(s) for gates that needs to be initialized.\n");
564+
log("\n");
553565
}
554566
void execute(std::ostream *&f, std::string filename, std::vector<std::string> args, RTLIL::Design *design) override
555567
{
@@ -640,6 +652,10 @@ struct BlifBackend : public Backend {
640652
config.noalias_mode = true;
641653
continue;
642654
}
655+
if (args[argidx] == "-gatesi") {
656+
config.gatesi_mode = true;
657+
continue;
658+
}
643659
break;
644660
}
645661
extra_args(f, filename, args, argidx);

0 commit comments

Comments
 (0)