From 9714072b28b41b1ef4205247c294f855f4b396e8 Mon Sep 17 00:00:00 2001 From: Johann Glaser Date: Fri, 5 Apr 2013 11:17:49 +0200 Subject: fsm_export: specify KISS filename on command line --- passes/fsm/fsm_export.cc | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'passes') diff --git a/passes/fsm/fsm_export.cc b/passes/fsm/fsm_export.cc index 26d120a1..2093857b 100644 --- a/passes/fsm/fsm_export.cc +++ b/passes/fsm/fsm_export.cc @@ -49,7 +49,7 @@ std::string kiss_convert_signal(const RTLIL::SigSpec &sig) { * @param module pointer to module which contains the FSM cell. * @param cell pointer to the FSM cell which should be exported. */ -void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell) { +void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell, std::string filename) { std::map::iterator attr_it; FsmData fsm_data; FsmData::transition_t tr; @@ -58,7 +58,9 @@ void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell) { size_t i; attr_it = cell->attributes.find("\\fsm_export"); - if (attr_it != cell->attributes.end() && attr_it->second.str != "") { + if (!filename.empty()) { + kiss_name.assign(filename); + } else if (attr_it != cell->attributes.end() && attr_it->second.str != "") { kiss_name.assign(attr_it->second.str); } else { @@ -114,21 +116,28 @@ struct FsmExportPass : public Pass { { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); - log(" fsm_export [-noauto] [selection]\n"); + log(" fsm_export [-noauto] [-o filename] [selection]\n"); log("\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("the module and cell name is used as filename.\n"); + log("the module and cell name is used as filename. If the parameter '-o' is given,\n"); + log("the first exported FSM is written to the specified filename. This overwrites\n"); + log("the setting as specified with the 'fsm_export' attribute. All other FSMs are\n"); + log("exported to the default name as mentioned above.\n"); log("\n"); log(" -noauto\n"); log(" only export FSMs that have the 'fsm_export' attribute set\n"); log("\n"); + log(" -o filename\n"); + log(" filename of the first exported FSM\n"); + log("\n"); } virtual void execute(std::vector args, RTLIL::Design *design) { std::map::iterator attr_it; std::string arg; bool flag_noauto = false; + std::string filename; size_t argidx; log_header("Executing FSM_EXPORT pass (exporting FSMs in KISS2 file format).\n"); @@ -139,6 +148,11 @@ struct FsmExportPass : public Pass { flag_noauto = true; continue; } + if (arg == "-o") { + argidx++; + filename = args[argidx]; + continue; + } break; } extra_args(args, argidx, design); @@ -149,7 +163,8 @@ struct FsmExportPass : public Pass { if (cell_it.second->type == "$fsm" && design->selected(mod_it.second, cell_it.second)) { attr_it = cell_it.second->attributes.find("\\fsm_export"); if (!flag_noauto || (attr_it != cell_it.second->attributes.end())) { - write_kiss2(mod_it.second, cell_it.second); + write_kiss2(mod_it.second, cell_it.second, filename); + filename.clear(); } } } -- cgit v1.2.3 From 7ef245aa7d15195b3f4200d2d3cb2796bc695b88 Mon Sep 17 00:00:00 2001 From: Johann Glaser Date: Fri, 5 Apr 2013 15:34:40 +0200 Subject: fsm_export: optionally use binary state encoding as state names instead of s0, s1, ... --- passes/fsm/fsm_export.cc | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'passes') diff --git a/passes/fsm/fsm_export.cc b/passes/fsm/fsm_export.cc index 2093857b..dc9ec2b0 100644 --- a/passes/fsm/fsm_export.cc +++ b/passes/fsm/fsm_export.cc @@ -49,7 +49,7 @@ std::string kiss_convert_signal(const RTLIL::SigSpec &sig) { * @param module pointer to module which contains the FSM cell. * @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::iterator attr_it; FsmData fsm_data; 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 << ".p " << std::dec << fsm_data.transition_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++) { tr = fsm_data.transition_table[i]; try { kiss_file << kiss_convert_signal(tr.ctrl_in) << ' '; - kiss_file << 's' << tr.state_in << ' '; - kiss_file << 's' << tr.state_out << ' '; + if (origenc) { + 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; } catch (int) { @@ -116,7 +125,7 @@ struct FsmExportPass : public Pass { { // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| log("\n"); - log(" fsm_export [-noauto] [-o filename] [selection]\n"); + log(" fsm_export [-noauto] [-o filename] [-origenc] [selection]\n"); log("\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"); @@ -131,6 +140,9 @@ struct FsmExportPass : public Pass { log(" -o filename\n"); log(" filename of the first exported FSM\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 args, RTLIL::Design *design) { @@ -138,6 +150,7 @@ struct FsmExportPass : public Pass { std::string arg; bool flag_noauto = false; std::string filename; + bool flag_origenc = false; size_t argidx; log_header("Executing FSM_EXPORT pass (exporting FSMs in KISS2 file format).\n"); @@ -153,6 +166,10 @@ struct FsmExportPass : public Pass { filename = args[argidx]; continue; } + if (arg == "-origenc") { + flag_origenc = true; + continue; + } break; } 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)) { attr_it = cell_it.second->attributes.find("\\fsm_export"); 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(); } } -- cgit v1.2.3