mirror of https://github.com/YosysHQ/yosys.git
fsm_export: optionally use binary state encoding as state names instead of
s0, s1, ...
This commit is contained in:
parent
9714072b28
commit
7ef245aa7d
|
@ -49,7 +49,7 @@ std::string kiss_convert_signal(const RTLIL::SigSpec &sig) {
|
||||||
* @param module pointer to module which contains the FSM cell.
|
* @param module pointer to module which contains the FSM cell.
|
||||||
* @param cell pointer to the FSM cell which should be exported.
|
* @param cell pointer to the FSM cell which should be exported.
|
||||||
*/
|
*/
|
||||||
void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell, std::string filename) {
|
void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell, std::string filename, bool origenc) {
|
||||||
std::map<RTLIL::IdString, RTLIL::Const>::iterator attr_it;
|
std::map<RTLIL::IdString, RTLIL::Const>::iterator attr_it;
|
||||||
FsmData fsm_data;
|
FsmData fsm_data;
|
||||||
FsmData::transition_t tr;
|
FsmData::transition_t tr;
|
||||||
|
@ -86,15 +86,24 @@ void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell, std::st
|
||||||
kiss_file << ".o " << std::dec << fsm_data.num_outputs << std::endl;
|
kiss_file << ".o " << std::dec << fsm_data.num_outputs << std::endl;
|
||||||
kiss_file << ".p " << std::dec << fsm_data.transition_table.size() << std::endl;
|
kiss_file << ".p " << std::dec << fsm_data.transition_table.size() << std::endl;
|
||||||
kiss_file << ".s " << std::dec << fsm_data.state_table.size() << std::endl;
|
kiss_file << ".s " << std::dec << fsm_data.state_table.size() << std::endl;
|
||||||
kiss_file << ".r s" << std::dec << fsm_data.reset_state << std::endl;
|
if (origenc) {
|
||||||
|
kiss_file << ".r " << kiss_convert_signal(fsm_data.state_table[fsm_data.reset_state]) << std::endl;
|
||||||
|
} else {
|
||||||
|
kiss_file << ".r s" << std::dec << fsm_data.reset_state << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
for (i = 0; i < fsm_data.transition_table.size(); i++) {
|
for (i = 0; i < fsm_data.transition_table.size(); i++) {
|
||||||
tr = fsm_data.transition_table[i];
|
tr = fsm_data.transition_table[i];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
kiss_file << kiss_convert_signal(tr.ctrl_in) << ' ';
|
kiss_file << kiss_convert_signal(tr.ctrl_in) << ' ';
|
||||||
kiss_file << 's' << tr.state_in << ' ';
|
if (origenc) {
|
||||||
kiss_file << 's' << tr.state_out << ' ';
|
kiss_file << kiss_convert_signal(fsm_data.state_table[tr.state_in]) << ' ';
|
||||||
|
kiss_file << kiss_convert_signal(fsm_data.state_table[tr.state_out]) << ' ';
|
||||||
|
} else {
|
||||||
|
kiss_file << 's' << tr.state_in << ' ';
|
||||||
|
kiss_file << 's' << tr.state_out << ' ';
|
||||||
|
}
|
||||||
kiss_file << kiss_convert_signal(tr.ctrl_out) << std::endl;
|
kiss_file << kiss_convert_signal(tr.ctrl_out) << std::endl;
|
||||||
}
|
}
|
||||||
catch (int) {
|
catch (int) {
|
||||||
|
@ -116,7 +125,7 @@ struct FsmExportPass : public Pass {
|
||||||
{
|
{
|
||||||
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
|
||||||
log("\n");
|
log("\n");
|
||||||
log(" fsm_export [-noauto] [-o filename] [selection]\n");
|
log(" fsm_export [-noauto] [-o filename] [-origenc] [selection]\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
log("This pass creates a KISS2 file for every selected FSM. For FSMs with the\n");
|
log("This pass creates a KISS2 file for every selected FSM. For FSMs with the\n");
|
||||||
log("'fsm_export' attribute set, the attribute value is used as filename, otherwise\n");
|
log("'fsm_export' attribute set, the attribute value is used as filename, otherwise\n");
|
||||||
|
@ -131,6 +140,9 @@ struct FsmExportPass : public Pass {
|
||||||
log(" -o filename\n");
|
log(" -o filename\n");
|
||||||
log(" filename of the first exported FSM\n");
|
log(" filename of the first exported FSM\n");
|
||||||
log("\n");
|
log("\n");
|
||||||
|
log(" -origenc\n");
|
||||||
|
log(" use binary state encoding as state names instead of s0, s1, ...\n");
|
||||||
|
log("\n");
|
||||||
}
|
}
|
||||||
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
|
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
|
||||||
{
|
{
|
||||||
|
@ -138,6 +150,7 @@ struct FsmExportPass : public Pass {
|
||||||
std::string arg;
|
std::string arg;
|
||||||
bool flag_noauto = false;
|
bool flag_noauto = false;
|
||||||
std::string filename;
|
std::string filename;
|
||||||
|
bool flag_origenc = false;
|
||||||
size_t argidx;
|
size_t argidx;
|
||||||
|
|
||||||
log_header("Executing FSM_EXPORT pass (exporting FSMs in KISS2 file format).\n");
|
log_header("Executing FSM_EXPORT pass (exporting FSMs in KISS2 file format).\n");
|
||||||
|
@ -153,6 +166,10 @@ struct FsmExportPass : public Pass {
|
||||||
filename = args[argidx];
|
filename = args[argidx];
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (arg == "-origenc") {
|
||||||
|
flag_origenc = true;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
extra_args(args, argidx, design);
|
extra_args(args, argidx, design);
|
||||||
|
@ -163,7 +180,7 @@ struct FsmExportPass : public Pass {
|
||||||
if (cell_it.second->type == "$fsm" && design->selected(mod_it.second, cell_it.second)) {
|
if (cell_it.second->type == "$fsm" && design->selected(mod_it.second, cell_it.second)) {
|
||||||
attr_it = cell_it.second->attributes.find("\\fsm_export");
|
attr_it = cell_it.second->attributes.find("\\fsm_export");
|
||||||
if (!flag_noauto || (attr_it != cell_it.second->attributes.end())) {
|
if (!flag_noauto || (attr_it != cell_it.second->attributes.end())) {
|
||||||
write_kiss2(mod_it.second, cell_it.second, filename);
|
write_kiss2(mod_it.second, cell_it.second, filename, flag_origenc);
|
||||||
filename.clear();
|
filename.clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue