summaryrefslogtreecommitdiff
path: root/passes
diff options
context:
space:
mode:
Diffstat (limited to 'passes')
-rw-r--r--passes/fsm/fsm.cc10
-rw-r--r--passes/fsm/fsm_recode.cc43
2 files changed, 41 insertions, 12 deletions
diff --git a/passes/fsm/fsm.cc b/passes/fsm/fsm.cc
index 1e7c7772..e76be40c 100644
--- a/passes/fsm/fsm.cc
+++ b/passes/fsm/fsm.cc
@@ -61,6 +61,7 @@ struct FsmPass : public Pass {
log("\n");
log(" -encoding tye\n");
log(" -fm_set_fsm_file file\n");
+ log(" -encfile file\n");
log(" passed through to fsm_recode pass\n");
log("\n");
}
@@ -72,6 +73,7 @@ struct FsmPass : public Pass {
bool flag_expand = false;
bool flag_export = false;
std::string fm_set_fsm_file_opt;
+ std::string encfile_opt;
std::string encoding_opt;
log_header("Executing FSM pass (extract and optimize FSM).\n");
@@ -84,7 +86,11 @@ struct FsmPass : public Pass {
fm_set_fsm_file_opt = " -fm_set_fsm_file " + args[++argidx];
continue;
}
- if (arg == "-encoding" && argidx+1 < args.size() && fm_set_fsm_file_opt.empty()) {
+ if (arg == "-encfile" && argidx+1 < args.size() && encfile_opt.empty()) {
+ encfile_opt = " -encfile " + args[++argidx];
+ continue;
+ }
+ if (arg == "-encoding" && argidx+1 < args.size() && encoding_opt.empty()) {
encoding_opt = " -encoding " + args[++argidx];
continue;
}
@@ -127,7 +133,7 @@ struct FsmPass : public Pass {
}
if (!flag_norecode)
- Pass::call(design, "fsm_recode" + fm_set_fsm_file_opt + encoding_opt);
+ Pass::call(design, "fsm_recode" + fm_set_fsm_file_opt + encfile_opt + encoding_opt);
Pass::call(design, "fsm_info");
if (flag_export)
diff --git a/passes/fsm/fsm_recode.cc b/passes/fsm/fsm_recode.cc
index 06ac58f0..16996810 100644
--- a/passes/fsm/fsm_recode.cc
+++ b/passes/fsm/fsm_recode.cc
@@ -51,7 +51,7 @@ static void fm_set_fsm_print(RTLIL::Cell *cell, RTLIL::Module *module, FsmData &
prefix, RTLIL::unescape_id(module->name).c_str());
}
-static void fsm_recode(RTLIL::Cell *cell, RTLIL::Module *module, FILE *fm_set_fsm_file, std::string default_encoding)
+static void fsm_recode(RTLIL::Cell *cell, RTLIL::Module *module, FILE *fm_set_fsm_file, FILE *encfile, std::string default_encoding)
{
std::string encoding = cell->attributes.count("\\fsm_encoding") ? cell->attributes.at("\\fsm_encoding").decode_string() : "auto";
@@ -94,6 +94,9 @@ static void fsm_recode(RTLIL::Cell *cell, RTLIL::Module *module, FILE *fm_set_fs
} else
log_error("FSM encoding `%s' is not supported!\n", encoding.c_str());
+ if (encfile)
+ fprintf(encfile, ".fsm %s %s\n", log_id(module), RTLIL::unescape_id(cell->parameters["\\NAME"].decode_string()).c_str());
+
int state_idx_counter = fsm_data.reset_state >= 0 ? 1 : 0;
for (int i = 0; i < int(fsm_data.state_table.size()); i++)
{
@@ -110,6 +113,8 @@ static void fsm_recode(RTLIL::Cell *cell, RTLIL::Module *module, FILE *fm_set_fs
log_abort();
log(" %s -> %s\n", fsm_data.state_table[i].as_string().c_str(), new_code.as_string().c_str());
+ if (encfile)
+ fprintf(encfile, ".map %s %s\n", fsm_data.state_table[i].as_string().c_str(), new_code.as_string().c_str());
fsm_data.state_table[i] = new_code;
}
@@ -125,21 +130,31 @@ struct FsmRecodePass : public Pass {
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n");
- log(" fsm_recode [-encoding type] [-fm_set_fsm_file file] [selection]\n");
+ log(" fsm_recode [options] [selection]\n");
log("\n");
log("This pass reassign the state encodings for FSM cells. At the moment only\n");
- log("one-hot encoding and binary encoding is supported. The option -encoding\n");
- log("can be used to specify the encoding scheme used for FSMs without the\n");
- log("`fsm_encoding' attribute (or with the attribute set to `auto'.\n");
+ log("one-hot encoding and binary encoding is supported.\n");
+
+ log(" -encoding <type>\n");
+ log(" specify the encoding scheme used for FSMs without the\n");
+ log(" 'fsm_encoding' attribute or with the attribute set to `auto'.\n");
+ log("\n");
+ log(" -fm_set_fsm_file <file>\n");
+ log(" generate a file containing the mapping from old to new FSM encoding\n");
+ log(" in form of Synopsys Formality set_fsm_* commands.\n");
+ log("\n");
+ log(" -encfile <file>\n");
+ log(" write the mappings from old to new FSM encoding to a file in the\n");
+ log(" following format:\n");
log("\n");
- log("The option -fm_set_fsm_file can be used to generate a file containing the\n");
- log("mapping from old to new FSM encoding in form of Synopsys Formality set_fsm_*\n");
- log("commands.\n");
+ log(" .fsm <module_name> <state_signal>\n");
+ log(" .map <old_bitpattern> <new_bitpattern>\n");
log("\n");
}
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
{
FILE *fm_set_fsm_file = NULL;
+ FILE *encfile = NULL;
std::string default_encoding;
log_header("Executing FSM_RECODE pass (re-assigning FSM state encoding).\n");
@@ -152,7 +167,13 @@ struct FsmRecodePass : public Pass {
log_error("Can't open fm_set_fsm_file `%s' for writing: %s\n", args[argidx].c_str(), strerror(errno));
continue;
}
- if (arg == "-encoding" && argidx+1 < args.size() && fm_set_fsm_file == NULL) {
+ if (arg == "-encfile" && argidx+1 < args.size() && encfile == NULL) {
+ encfile = fopen(args[++argidx].c_str(), "w");
+ if (encfile == NULL)
+ log_error("Can't open encfile `%s' for writing: %s\n", args[argidx].c_str(), strerror(errno));
+ continue;
+ }
+ if (arg == "-encoding" && argidx+1 < args.size() && default_encoding.empty()) {
default_encoding = args[++argidx];
continue;
}
@@ -164,10 +185,12 @@ struct FsmRecodePass : public Pass {
if (design->selected(mod_it.second))
for (auto &cell_it : mod_it.second->cells_)
if (cell_it.second->type == "$fsm" && design->selected(mod_it.second, cell_it.second))
- fsm_recode(cell_it.second, mod_it.second, fm_set_fsm_file, default_encoding);
+ fsm_recode(cell_it.second, mod_it.second, fm_set_fsm_file, encfile, default_encoding);
if (fm_set_fsm_file != NULL)
fclose(fm_set_fsm_file);
+ if (encfile != NULL)
+ fclose(encfile);
}
} FsmRecodePass;