yosys/passes/fsm/fsm.cc

158 lines
4.6 KiB
C++
Raw Normal View History

2013-01-05 04:13:26 -06:00
/*
* yosys -- Yosys Open SYnthesis Suite
*
* Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
2015-07-02 04:14:30 -05:00
*
2013-01-05 04:13:26 -06:00
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
2015-07-02 04:14:30 -05:00
*
2013-01-05 04:13:26 -06:00
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
*/
#include "kernel/register.h"
#include "kernel/log.h"
#include <stdlib.h>
#include <stdio.h>
2014-09-27 09:17:53 -05:00
USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
2013-01-05 04:13:26 -06:00
struct FsmPass : public Pass {
2013-03-01 05:35:12 -06:00
FsmPass() : Pass("fsm", "extract and optimize finite state machines") { }
virtual void help()
{
// |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
log("\n");
log(" fsm [options] [selection]\n");
log("\n");
log("This pass calls all the other fsm_* passes in a useful order. This performs\n");
2015-08-14 03:56:05 -05:00
log("FSM extraction and optimization. It also calls opt_clean as needed:\n");
2013-03-01 05:35:12 -06:00
log("\n");
2013-05-24 08:34:25 -05:00
log(" fsm_detect unless got option -nodetect\n");
2013-03-01 05:35:12 -06:00
log(" fsm_extract\n");
log("\n");
log(" fsm_opt\n");
2013-06-05 00:07:31 -05:00
log(" opt_clean\n");
2013-03-01 05:35:12 -06:00
log(" fsm_opt\n");
log("\n");
log(" fsm_expand if got option -expand\n");
2013-06-05 00:07:31 -05:00
log(" opt_clean if got option -expand\n");
2013-03-01 05:35:12 -06:00
log(" fsm_opt if got option -expand\n");
log("\n");
log(" fsm_recode unless got option -norecode\n");
log("\n");
log(" fsm_info\n");
log("\n");
log(" fsm_export if got option -export\n");
log(" fsm_map unless got option -nomap\n");
log("\n");
log("Options:\n");
log("\n");
log(" -expand, -norecode, -export, -nomap\n");
log(" enable or disable passes as indicated above\n");
log("\n");
2016-11-02 03:31:39 -05:00
log(" -fullexpand\n");
log(" call expand with -full option\n");
log("\n");
2015-08-14 03:56:05 -05:00
log(" -encoding type\n");
2013-03-01 05:35:12 -06:00
log(" -fm_set_fsm_file file\n");
2015-01-30 15:46:53 -06:00
log(" -encfile file\n");
2013-03-01 05:35:12 -06:00
log(" passed through to fsm_recode pass\n");
log("\n");
}
2013-01-05 04:13:26 -06:00
virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
{
bool flag_nomap = false;
bool flag_norecode = false;
2013-05-24 08:34:25 -05:00
bool flag_nodetect = false;
2013-01-05 04:13:26 -06:00
bool flag_expand = false;
2016-11-02 03:31:39 -05:00
bool flag_fullexpand = false;
2013-01-05 04:13:26 -06:00
bool flag_export = false;
std::string fm_set_fsm_file_opt;
2015-01-30 15:46:53 -06:00
std::string encfile_opt;
std::string encoding_opt;
2013-01-05 04:13:26 -06:00
2016-04-21 16:28:37 -05:00
log_header(design, "Executing FSM pass (extract and optimize FSM).\n");
2013-01-05 04:13:26 -06:00
log_push();
size_t argidx;
for (argidx = 1; argidx < args.size(); argidx++) {
std::string arg = args[argidx];
if (arg == "-fm_set_fsm_file" && argidx+1 < args.size() && fm_set_fsm_file_opt.empty()) {
fm_set_fsm_file_opt = " -fm_set_fsm_file " + args[++argidx];
continue;
}
2015-01-30 15:46:53 -06:00
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;
}
2013-05-24 08:34:25 -05:00
if (arg == "-nodetect") {
flag_nodetect = true;
continue;
}
2013-01-05 04:13:26 -06:00
if (arg == "-norecode") {
flag_norecode = true;
continue;
}
if (arg == "-nomap") {
flag_nomap = true;
continue;
}
if (arg == "-expand") {
flag_expand = true;
continue;
}
2016-11-02 03:31:39 -05:00
if (arg == "-fullexpand") {
flag_fullexpand = true;
continue;
}
2013-01-05 04:13:26 -06:00
if (arg == "-export") {
flag_export = true;
continue;
}
break;
}
extra_args(args, argidx, design);
2013-05-24 08:34:25 -05:00
if (!flag_nodetect)
Pass::call(design, "fsm_detect");
2013-01-05 04:13:26 -06:00
Pass::call(design, "fsm_extract");
Pass::call(design, "fsm_opt");
2013-06-05 00:07:31 -05:00
Pass::call(design, "opt_clean");
2013-01-05 04:13:26 -06:00
Pass::call(design, "fsm_opt");
2016-11-02 03:31:39 -05:00
if (flag_expand || flag_fullexpand) {
Pass::call(design, flag_fullexpand ? "fsm_expand -full" : "fsm_expand");
2013-06-05 00:07:31 -05:00
Pass::call(design, "opt_clean");
2013-01-05 04:13:26 -06:00
Pass::call(design, "fsm_opt");
}
if (!flag_norecode)
2015-01-30 15:46:53 -06:00
Pass::call(design, "fsm_recode" + fm_set_fsm_file_opt + encfile_opt + encoding_opt);
2013-01-05 04:13:26 -06:00
Pass::call(design, "fsm_info");
if (flag_export)
Pass::call(design, "fsm_export");
2014-08-08 07:49:06 -05:00
if (!flag_nomap)
Pass::call(design, "fsm_map");
2013-01-05 04:13:26 -06:00
log_pop();
}
} FsmPass;
2015-07-02 04:14:30 -05:00
2014-09-27 09:17:53 -05:00
PRIVATE_NAMESPACE_END