53 std::map<RTLIL::IdString, RTLIL::Const>::iterator attr_it;
56 std::ofstream kiss_file;
57 std::string kiss_name;
60 attr_it = cell->attributes.find(
"\\fsm_export");
61 if (!filename.empty()) {
62 kiss_name.assign(filename);
63 }
else if (attr_it != cell->attributes.end() && attr_it->second.decode_string() !=
"") {
64 kiss_name.assign(attr_it->second.decode_string());
67 kiss_name.assign(
log_id(module) + std::string(
"-") +
log_id(cell) +
".kiss2");
71 log(
"Exporting FSM `%s' from module `%s' to file `%s'.\n",
76 kiss_file.open(kiss_name, std::ios::out | std::ios::trunc);
78 if (!kiss_file.is_open()) {
79 log_error(
"Could not open file \"%s\" with write access.\n", kiss_name.c_str());
84 kiss_file <<
".i " << std::dec << fsm_data.
num_inputs << std::endl;
85 kiss_file <<
".o " << std::dec << fsm_data.
num_outputs << std::endl;
86 kiss_file <<
".p " << std::dec << fsm_data.
transition_table.size() << std::endl;
87 kiss_file <<
".s " << std::dec << fsm_data.
state_table.size() << std::endl;
91 kiss_file <<
".r s" << std::dec << fsm_data.
reset_state << std::endl;
103 kiss_file <<
's' << tr.
state_in <<
' ';
110 log_error(
"exporting an FSM input or output signal failed.\n");
127 log(
" fsm_export [-noauto] [-o filename] [-origenc] [selection]\n");
129 log(
"This pass creates a KISS2 file for every selected FSM. For FSMs with the\n");
130 log(
"'fsm_export' attribute set, the attribute value is used as filename, otherwise\n");
131 log(
"the module and cell name is used as filename. If the parameter '-o' is given,\n");
132 log(
"the first exported FSM is written to the specified filename. This overwrites\n");
133 log(
"the setting as specified with the 'fsm_export' attribute. All other FSMs are\n");
134 log(
"exported to the default name as mentioned above.\n");
137 log(
" only export FSMs that have the 'fsm_export' attribute set\n");
139 log(
" -o filename\n");
140 log(
" filename of the first exported FSM\n");
143 log(
" use binary state encoding as state names instead of s0, s1, ...\n");
148 std::map<RTLIL::IdString, RTLIL::Const>::iterator attr_it;
150 bool flag_noauto =
false;
151 std::string filename;
152 bool flag_origenc =
false;
155 log_header(
"Executing FSM_EXPORT pass (exporting FSMs in KISS2 file format).\n");
157 for (argidx = 1; argidx < args.size(); argidx++) {
159 if (arg ==
"-noauto") {
165 filename = args[argidx];
168 if (arg ==
"-origenc") {
176 for (
auto &mod_it : design->
modules_)
177 if (design->
selected(mod_it.second))
178 for (
auto &cell_it : mod_it.second->cells_)
179 if (cell_it.second->type ==
"$fsm" && design->
selected(mod_it.second, cell_it.second)) {
180 attr_it = cell_it.second->attributes.find(
"\\fsm_export");
181 if (!flag_noauto || (attr_it != cell_it.second->attributes.end())) {
182 write_kiss2(mod_it.second, cell_it.second, filename, flag_origenc);
const char * c_str() const
bool selected(T1 *module) const
void write_kiss2(struct RTLIL::Module *module, struct RTLIL::Cell *cell, std::string filename, bool origenc)
std::vector< transition_t > transition_table
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
FsmExportPass FsmExportPass
void log_header(const char *format,...)
RTLIL::Const as_const() const
void log_error(const char *format,...)
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN std::string kiss_convert_signal(const RTLIL::SigSpec &sig)
std::string as_string() const
#define PRIVATE_NAMESPACE_BEGIN
#define log_assert(_assert_expr_)
bool is_fully_const() const
#define PRIVATE_NAMESPACE_END
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
std::vector< RTLIL::Const > state_table
void log(const char *format,...)
void copy_from_cell(RTLIL::Cell *cell)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
const char * log_id(RTLIL::IdString str)