Replaced RTLIL::Const::str with generic decoder method
[yosys.git] / passes / fsm / fsm.cc
1 /*
2 * yosys -- Yosys Open SYnthesis Suite
3 *
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
5 *
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.
9 *
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.
17 *
18 */
19
20 #include "kernel/register.h"
21 #include "kernel/log.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24
25 struct FsmPass : public Pass {
26 FsmPass() : Pass("fsm", "extract and optimize finite state machines") { }
27 virtual void help()
28 {
29 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
30 log("\n");
31 log(" fsm [options] [selection]\n");
32 log("\n");
33 log("This pass calls all the other fsm_* passes in a useful order. This performs\n");
34 log("FSM extraction and optimiziation. It also calls opt_clean as needed:\n");
35 log("\n");
36 log(" fsm_detect unless got option -nodetect\n");
37 log(" fsm_extract\n");
38 log("\n");
39 log(" fsm_opt\n");
40 log(" opt_clean\n");
41 log(" fsm_opt\n");
42 log("\n");
43 log(" fsm_expand if got option -expand\n");
44 log(" opt_clean if got option -expand\n");
45 log(" fsm_opt if got option -expand\n");
46 log("\n");
47 log(" fsm_recode unless got option -norecode\n");
48 log("\n");
49 log(" fsm_info\n");
50 log("\n");
51 log(" fsm_export if got option -export\n");
52 log(" fsm_map unless got option -nomap\n");
53 log("\n");
54 log("Options:\n");
55 log("\n");
56 log(" -expand, -norecode, -export, -nomap\n");
57 log(" enable or disable passes as indicated above\n");
58 log("\n");
59 log(" -encoding tye\n");
60 log(" -fm_set_fsm_file file\n");
61 log(" passed through to fsm_recode pass\n");
62 log("\n");
63 }
64 virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
65 {
66 bool flag_nomap = false;
67 bool flag_norecode = false;
68 bool flag_nodetect = false;
69 bool flag_expand = false;
70 bool flag_export = false;
71 std::string fm_set_fsm_file_opt;
72 std::string encoding_opt;
73
74 log_header("Executing FSM pass (extract and optimize FSM).\n");
75 log_push();
76
77 size_t argidx;
78 for (argidx = 1; argidx < args.size(); argidx++) {
79 std::string arg = args[argidx];
80 if (arg == "-fm_set_fsm_file" && argidx+1 < args.size() && fm_set_fsm_file_opt.empty()) {
81 fm_set_fsm_file_opt = " -fm_set_fsm_file " + args[++argidx];
82 continue;
83 }
84 if (arg == "-encoding" && argidx+1 < args.size() && fm_set_fsm_file_opt.empty()) {
85 encoding_opt = " -encoding " + args[++argidx];
86 continue;
87 }
88 if (arg == "-nodetect") {
89 flag_nodetect = true;
90 continue;
91 }
92 if (arg == "-norecode") {
93 flag_norecode = true;
94 continue;
95 }
96 if (arg == "-nomap") {
97 flag_nomap = true;
98 continue;
99 }
100 if (arg == "-expand") {
101 flag_expand = true;
102 continue;
103 }
104 if (arg == "-export") {
105 flag_export = true;
106 continue;
107 }
108 break;
109 }
110 extra_args(args, argidx, design);
111
112 if (!flag_nodetect)
113 Pass::call(design, "fsm_detect");
114 Pass::call(design, "fsm_extract");
115
116 Pass::call(design, "fsm_opt");
117 Pass::call(design, "opt_clean");
118 Pass::call(design, "fsm_opt");
119
120 if (flag_expand) {
121 Pass::call(design, "fsm_expand");
122 Pass::call(design, "opt_clean");
123 Pass::call(design, "fsm_opt");
124 }
125
126 if (!flag_norecode)
127 Pass::call(design, "fsm_recode" + fm_set_fsm_file_opt + encoding_opt);
128 Pass::call(design, "fsm_info");
129
130 if (!flag_nomap)
131 Pass::call(design, "fsm_map");
132
133 if (flag_export)
134 Pass::call(design, "fsm_export");
135
136 log_pop();
137 }
138 } FsmPass;
139