abc9: generate $abc9_holes design instead of <name>$holes
[yosys.git] / techlibs / common / prep.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/celltypes.h"
22 #include "kernel/rtlil.h"
23 #include "kernel/log.h"
24
25 USING_YOSYS_NAMESPACE
26 PRIVATE_NAMESPACE_BEGIN
27
28 struct PrepPass : public ScriptPass
29 {
30 PrepPass() : ScriptPass("prep", "generic synthesis script") { }
31
32 void help() YS_OVERRIDE
33 {
34 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
35 log("\n");
36 log(" prep [options]\n");
37 log("\n");
38 log("This command runs a conservative RTL synthesis. A typical application for this\n");
39 log("is the preparation stage of a verification flow. This command does not operate\n");
40 log("on partly selected designs.\n");
41 log("\n");
42 log(" -top <module>\n");
43 log(" use the specified module as top module (default='top')\n");
44 log("\n");
45 log(" -auto-top\n");
46 log(" automatically determine the top of the design hierarchy\n");
47 log("\n");
48 log(" -flatten\n");
49 log(" flatten the design before synthesis. this will pass '-auto-top' to\n");
50 log(" 'hierarchy' if no top module is specified.\n");
51 log("\n");
52 log(" -ifx\n");
53 log(" passed to 'proc'. uses verilog simulation behavior for verilog if/case\n");
54 log(" undef handling. this also prevents 'wreduce' from being run.\n");
55 log("\n");
56 log(" -memx\n");
57 log(" simulate verilog simulation behavior for out-of-bounds memory accesses\n");
58 log(" using the 'memory_memx' pass.\n");
59 log("\n");
60 log(" -nomem\n");
61 log(" do not run any of the memory_* passes\n");
62 log("\n");
63 log(" -rdff\n");
64 log(" do not pass -nordff to 'memory_dff'. This enables merging of FFs into\n");
65 log(" memory read ports.\n");
66 log("\n");
67 log(" -nokeepdc\n");
68 log(" do not call opt_* with -keepdc\n");
69 log("\n");
70 log(" -run <from_label>[:<to_label>]\n");
71 log(" only run the commands between the labels (see below). an empty\n");
72 log(" from label is synonymous to 'begin', and empty to label is\n");
73 log(" synonymous to the end of the command list.\n");
74 log("\n");
75 log("\n");
76 log("The following commands are executed by this synthesis command:\n");
77 help_script();
78 log("\n");
79 }
80
81 string top_module, fsm_opts;
82 bool autotop, flatten, ifxmode, memxmode, nomemmode, nokeepdc, nordff;
83
84 void clear_flags() YS_OVERRIDE
85 {
86 top_module.clear();
87
88 autotop = false;
89 flatten = false;
90 ifxmode = false;
91 memxmode = false;
92 nomemmode = false;
93 nokeepdc = false;
94 nordff = true;
95 }
96
97 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
98 {
99 string run_from, run_to;
100
101 size_t argidx;
102 for (argidx = 1; argidx < args.size(); argidx++)
103 {
104 if (args[argidx] == "-top" && argidx+1 < args.size()) {
105 top_module = args[++argidx];
106 continue;
107 }
108 if (args[argidx] == "-run" && argidx+1 < args.size()) {
109 size_t pos = args[argidx+1].find(':');
110 if (pos == std::string::npos) {
111 run_from = args[++argidx];
112 run_to = args[argidx];
113 } else {
114 run_from = args[++argidx].substr(0, pos);
115 run_to = args[argidx].substr(pos+1);
116 }
117 continue;
118 }
119 if (args[argidx] == "-auto-top") {
120 autotop = true;
121 continue;
122 }
123 if (args[argidx] == "-flatten") {
124 flatten = true;
125 continue;
126 }
127 if (args[argidx] == "-ifx") {
128 ifxmode = true;
129 continue;
130 }
131 if (args[argidx] == "-memx") {
132 memxmode = true;
133 continue;
134 }
135 if (args[argidx] == "-nomem") {
136 nomemmode = true;
137 continue;
138 }
139 if (args[argidx] == "-nordff") {
140 nordff = true;
141 continue;
142 }
143 if (args[argidx] == "-rdff") {
144 nordff = false;
145 continue;
146 }
147 if (args[argidx] == "-nokeepdc") {
148 nokeepdc = true;
149 continue;
150 }
151 break;
152 }
153 extra_args(args, argidx, design);
154
155 if (!design->full_selection())
156 log_cmd_error("This command only operates on fully selected designs!\n");
157
158 log_header(design, "Executing PREP pass.\n");
159 log_push();
160
161 run_script(design, run_from, run_to);
162
163 log_pop();
164 }
165
166 void script() YS_OVERRIDE
167 {
168
169 if (check_label("begin"))
170 {
171 if (help_mode) {
172 run("hierarchy -check [-top <top> | -auto-top]");
173 } else {
174 if (top_module.empty()) {
175 if (flatten || autotop)
176 run("hierarchy -check -auto-top");
177 else
178 run("hierarchy -check");
179 } else
180 run(stringf("hierarchy -check -top %s", top_module.c_str()));
181 }
182 }
183
184 if (check_label("coarse"))
185 {
186 if (help_mode)
187 run("proc [-ifx]");
188 else
189 run(ifxmode ? "proc -ifx" : "proc");
190 if (help_mode || flatten)
191 run("flatten", "(if -flatten)");
192 run(nokeepdc ? "opt_expr" : "opt_expr -keepdc");
193 run("opt_clean");
194 run("check");
195 run(nokeepdc ? "opt" : "opt -keepdc");
196 if (!ifxmode) {
197 if (help_mode)
198 run("wreduce -keepdc [-memx]");
199 else if (nokeepdc)
200 run(memxmode ? "wreduce -memx" : "wreduce");
201 else
202 run(memxmode ? "wreduce -keepdc -memx" : "wreduce -keepdc");
203 }
204 if (!nomemmode) {
205 run(string("memory_dff") + (help_mode ? " [-nordff]" : nordff ? " -nordff" : ""));
206 if (help_mode || memxmode)
207 run("memory_memx", "(if -memx)");
208 run("opt_clean");
209 run("memory_collect");
210 }
211 run(nokeepdc ? "opt -fast" : "opt -keepdc -fast");
212 }
213
214 if (check_label("check"))
215 {
216 run("stat");
217 run("check");
218 }
219 }
220 } PrepPass;
221
222 PRIVATE_NAMESPACE_END