Added "fsm -encfile"

This commit is contained in:
Clifford Wolf 2015-01-30 22:46:53 +01:00
parent aabd5097ed
commit bedd46338f
3 changed files with 50 additions and 14 deletions

View File

@ -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)

View File

@ -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("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(" -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(" .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;

View File

@ -52,6 +52,9 @@ struct SynthPass : public Pass {
log(" -top <module>\n");
log(" use the specified module as top module (default='top')\n");
log("\n");
log(" -encfile <file>\n");
log(" passed to 'fsm_recode' via 'fsm'\n");
log("\n");
log(" -run <from_label>[:<to_label>]\n");
log(" only run the commands between the labels (see below). an empty\n");
log(" from label is synonymous to 'begin', and empty to label is\n");
@ -91,7 +94,7 @@ struct SynthPass : public Pass {
}
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
{
std::string top_module;
std::string top_module, fsm_opts;
std::string run_from, run_to;
size_t argidx;
@ -101,6 +104,10 @@ struct SynthPass : public Pass {
top_module = args[++argidx];
continue;
}
if (args[argidx] == "-encfile" && argidx+1 < args.size()) {
fsm_opts = " -encfile " + args[++argidx];
continue;
}
if (args[argidx] == "-run" && argidx+1 < args.size()) {
size_t pos = args[argidx+1].find(':');
if (pos == std::string::npos) {
@ -140,7 +147,7 @@ struct SynthPass : public Pass {
Pass::call(design, "alumacc");
Pass::call(design, "share");
Pass::call(design, "opt");
Pass::call(design, "fsm");
Pass::call(design, "fsm" + fsm_opts);
Pass::call(design, "opt -fast");
Pass::call(design, "memory -nomap");
Pass::call(design, "opt_clean");