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/celltypes.h"
22 #include "kernel/rtlil.h"
23 #include "kernel/log.h"
26 PRIVATE_NAMESPACE_BEGIN
28 struct PrepPass
: public ScriptPass
30 PrepPass() : ScriptPass("prep", "generic synthesis script") { }
32 void help() YS_OVERRIDE
34 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
36 log(" prep [options]\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");
42 log(" -top <module>\n");
43 log(" use the specified module as top module (default='top')\n");
46 log(" automatically determine the top of the design hierarchy\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");
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");
57 log(" simulate verilog simulation behavior for out-of-bounds memory accesses\n");
58 log(" using the 'memory_memx' pass.\n");
61 log(" do not run any of the memory_* passes\n");
64 log(" do not pass -nordff to 'memory_dff'. This enables merging of FFs into\n");
65 log(" memory read ports.\n");
68 log(" do not call opt_* with -keepdc\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");
76 log("The following commands are executed by this synthesis command:\n");
81 string top_module
, fsm_opts
;
82 bool autotop
, flatten
, ifxmode
, memxmode
, nomemmode
, nokeepdc
, nordff
;
84 void clear_flags() YS_OVERRIDE
97 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
99 string run_from
, run_to
;
102 for (argidx
= 1; argidx
< args
.size(); argidx
++)
104 if (args
[argidx
] == "-top" && argidx
+1 < args
.size()) {
105 top_module
= args
[++argidx
];
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
];
114 run_from
= args
[++argidx
].substr(0, pos
);
115 run_to
= args
[argidx
].substr(pos
+1);
119 if (args
[argidx
] == "-auto-top") {
123 if (args
[argidx
] == "-flatten") {
127 if (args
[argidx
] == "-ifx") {
131 if (args
[argidx
] == "-memx") {
135 if (args
[argidx
] == "-nomem") {
139 if (args
[argidx
] == "-nordff") {
143 if (args
[argidx
] == "-rdff") {
147 if (args
[argidx
] == "-nokeepdc") {
153 extra_args(args
, argidx
, design
);
155 if (!design
->full_selection())
156 log_cmd_error("This command only operates on fully selected designs!\n");
158 log_header(design
, "Executing PREP pass.\n");
161 run_script(design
, run_from
, run_to
);
166 void script() YS_OVERRIDE
169 if (check_label("begin"))
172 run("hierarchy -check [-top <top> | -auto-top]");
174 if (top_module
.empty()) {
175 if (flatten
|| autotop
)
176 run("hierarchy -check -auto-top");
178 run("hierarchy -check");
180 run(stringf("hierarchy -check -top %s", top_module
.c_str()));
184 if (check_label("coarse"))
189 run(ifxmode
? "proc -ifx" : "proc");
190 if (help_mode
|| flatten
)
191 run("flatten", "(if -flatten)");
192 run(nokeepdc
? "opt_expr" : "opt_expr -keepdc");
195 run(nokeepdc
? "opt" : "opt -keepdc");
198 run("wreduce -keepdc [-memx]");
200 run(memxmode
? "wreduce -memx" : "wreduce");
202 run(memxmode
? "wreduce -keepdc -memx" : "wreduce -keepdc");
205 run(string("memory_dff") + (help_mode
? " [-nordff]" : nordff
? " -nordff" : ""));
206 if (help_mode
|| memxmode
)
207 run("memory_memx", "(if -memx)");
209 run("memory_collect");
211 run(nokeepdc
? "opt -fast" : "opt -keepdc -fast");
214 if (check_label("check"))
222 PRIVATE_NAMESPACE_END