2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
20 #include "kernel/register.h"
21 #include "kernel/log.h"
26 PRIVATE_NAMESPACE_BEGIN
28 struct FsmPass
: public Pass
{
29 FsmPass() : Pass("fsm", "extract and optimize finite state machines") { }
32 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
34 log(" fsm [options] [selection]\n");
36 log("This pass calls all the other fsm_* passes in a useful order. This performs\n");
37 log("FSM extraction and optimization. It also calls opt_clean as needed:\n");
39 log(" fsm_detect unless got option -nodetect\n");
40 log(" fsm_extract\n");
46 log(" fsm_expand if got option -expand\n");
47 log(" opt_clean if got option -expand\n");
48 log(" fsm_opt if got option -expand\n");
50 log(" fsm_recode unless got option -norecode\n");
54 log(" fsm_export if got option -export\n");
55 log(" fsm_map unless got option -nomap\n");
59 log(" -expand, -norecode, -export, -nomap\n");
60 log(" enable or disable passes as indicated above\n");
62 log(" -fullexpand\n");
63 log(" call expand with -full option\n");
65 log(" -encoding type\n");
66 log(" -fm_set_fsm_file file\n");
67 log(" -encfile file\n");
68 log(" passed through to fsm_recode pass\n");
71 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) override
73 bool flag_nomap
= false;
74 bool flag_norecode
= false;
75 bool flag_nodetect
= false;
76 bool flag_expand
= false;
77 bool flag_fullexpand
= false;
78 bool flag_export
= false;
79 std::string fm_set_fsm_file_opt
;
80 std::string encfile_opt
;
81 std::string encoding_opt
;
83 log_header(design
, "Executing FSM pass (extract and optimize FSM).\n");
87 for (argidx
= 1; argidx
< args
.size(); argidx
++) {
88 std::string arg
= args
[argidx
];
89 if (arg
== "-fm_set_fsm_file" && argidx
+1 < args
.size() && fm_set_fsm_file_opt
.empty()) {
90 fm_set_fsm_file_opt
= " -fm_set_fsm_file " + args
[++argidx
];
93 if (arg
== "-encfile" && argidx
+1 < args
.size() && encfile_opt
.empty()) {
94 encfile_opt
= " -encfile " + args
[++argidx
];
97 if (arg
== "-encoding" && argidx
+1 < args
.size() && encoding_opt
.empty()) {
98 encoding_opt
= " -encoding " + args
[++argidx
];
101 if (arg
== "-nodetect") {
102 flag_nodetect
= true;
105 if (arg
== "-norecode") {
106 flag_norecode
= true;
109 if (arg
== "-nomap") {
113 if (arg
== "-expand") {
117 if (arg
== "-fullexpand") {
118 flag_fullexpand
= true;
121 if (arg
== "-export") {
127 extra_args(args
, argidx
, design
);
130 Pass::call(design
, "fsm_detect");
131 Pass::call(design
, "fsm_extract");
133 Pass::call(design
, "fsm_opt");
134 Pass::call(design
, "opt_clean");
135 Pass::call(design
, "fsm_opt");
137 if (flag_expand
|| flag_fullexpand
) {
138 Pass::call(design
, flag_fullexpand
? "fsm_expand -full" : "fsm_expand");
139 Pass::call(design
, "opt_clean");
140 Pass::call(design
, "fsm_opt");
144 Pass::call(design
, "fsm_recode" + fm_set_fsm_file_opt
+ encfile_opt
+ encoding_opt
);
145 Pass::call(design
, "fsm_info");
148 Pass::call(design
, "fsm_export");
151 Pass::call(design
, "fsm_map");
157 PRIVATE_NAMESPACE_END