yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fsm.cc
Go to the documentation of this file.
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 
27 
28 struct FsmPass : public Pass {
29  FsmPass() : Pass("fsm", "extract and optimize finite state machines") { }
30  virtual void help()
31  {
32  // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
33  log("\n");
34  log(" fsm [options] [selection]\n");
35  log("\n");
36  log("This pass calls all the other fsm_* passes in a useful order. This performs\n");
37  log("FSM extraction and optimiziation. It also calls opt_clean as needed:\n");
38  log("\n");
39  log(" fsm_detect unless got option -nodetect\n");
40  log(" fsm_extract\n");
41  log("\n");
42  log(" fsm_opt\n");
43  log(" opt_clean\n");
44  log(" fsm_opt\n");
45  log("\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");
49  log("\n");
50  log(" fsm_recode unless got option -norecode\n");
51  log("\n");
52  log(" fsm_info\n");
53  log("\n");
54  log(" fsm_export if got option -export\n");
55  log(" fsm_map unless got option -nomap\n");
56  log("\n");
57  log("Options:\n");
58  log("\n");
59  log(" -expand, -norecode, -export, -nomap\n");
60  log(" enable or disable passes as indicated above\n");
61  log("\n");
62  log(" -encoding tye\n");
63  log(" -fm_set_fsm_file file\n");
64  log(" passed through to fsm_recode pass\n");
65  log("\n");
66  }
67  virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
68  {
69  bool flag_nomap = false;
70  bool flag_norecode = false;
71  bool flag_nodetect = false;
72  bool flag_expand = false;
73  bool flag_export = false;
74  std::string fm_set_fsm_file_opt;
75  std::string encoding_opt;
76 
77  log_header("Executing FSM pass (extract and optimize FSM).\n");
78  log_push();
79 
80  size_t argidx;
81  for (argidx = 1; argidx < args.size(); argidx++) {
82  std::string arg = args[argidx];
83  if (arg == "-fm_set_fsm_file" && argidx+1 < args.size() && fm_set_fsm_file_opt.empty()) {
84  fm_set_fsm_file_opt = " -fm_set_fsm_file " + args[++argidx];
85  continue;
86  }
87  if (arg == "-encoding" && argidx+1 < args.size() && fm_set_fsm_file_opt.empty()) {
88  encoding_opt = " -encoding " + args[++argidx];
89  continue;
90  }
91  if (arg == "-nodetect") {
92  flag_nodetect = true;
93  continue;
94  }
95  if (arg == "-norecode") {
96  flag_norecode = true;
97  continue;
98  }
99  if (arg == "-nomap") {
100  flag_nomap = true;
101  continue;
102  }
103  if (arg == "-expand") {
104  flag_expand = true;
105  continue;
106  }
107  if (arg == "-export") {
108  flag_export = true;
109  continue;
110  }
111  break;
112  }
113  extra_args(args, argidx, design);
114 
115  if (!flag_nodetect)
116  Pass::call(design, "fsm_detect");
117  Pass::call(design, "fsm_extract");
118 
119  Pass::call(design, "fsm_opt");
120  Pass::call(design, "opt_clean");
121  Pass::call(design, "fsm_opt");
122 
123  if (flag_expand) {
124  Pass::call(design, "fsm_expand");
125  Pass::call(design, "opt_clean");
126  Pass::call(design, "fsm_opt");
127  }
128 
129  if (!flag_norecode)
130  Pass::call(design, "fsm_recode" + fm_set_fsm_file_opt + encoding_opt);
131  Pass::call(design, "fsm_info");
132 
133  if (flag_export)
134  Pass::call(design, "fsm_export");
135 
136  if (!flag_nomap)
137  Pass::call(design, "fsm_map");
138 
139  log_pop();
140  }
141 } FsmPass;
142 
FsmPass()
Definition: fsm.cc:29
void log_header(const char *format,...)
Definition: log.cc:188
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
Definition: fsm.cc:67
void log_pop()
Definition: log.cc:237
virtual void help()
Definition: fsm.cc:30
Definition: fsm.cc:28
#define PRIVATE_NAMESPACE_BEGIN
Definition: yosys.h:97
FsmPass FsmPass
#define PRIVATE_NAMESPACE_END
Definition: yosys.h:98
Definition: register.h:27
#define USING_YOSYS_NAMESPACE
Definition: yosys.h:102
void log(const char *format,...)
Definition: log.cc:180
void log_push()
Definition: log.cc:232
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
Definition: register.cc:128
static void call(RTLIL::Design *design, std::string command)
Definition: register.cc:146