2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2018 whitequark <whitequark@whitequark.org>
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"
23 PRIVATE_NAMESPACE_BEGIN
25 struct EquivOptPass
:public ScriptPass
27 EquivOptPass() : ScriptPass("equiv_opt", "prove equivalence for optimized circuit") { }
29 void help() YS_OVERRIDE
31 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
33 log(" equiv_opt [options] [command]\n");
35 log("This command checks circuit equivalence before and after an optimization pass.\n");
37 log(" -run <from_label>:<to_label>\n");
38 log(" only run the commands between the labels (see below). an empty\n");
39 log(" from label is synonymous to the start of the command list, and empty to\n");
40 log(" label is synonymous to the end of the command list.\n");
42 log(" -map <filename>\n");
43 log(" expand the modules in this file before proving equivalence. this is\n");
44 log(" useful for handling architecture-specific primitives.\n");
47 log(" produce an error if the circuits are not equivalent.\n");
49 log(" -multiclock\n");
50 log(" run clk2fflogic before equivalence checking.\n");
53 log(" enable modelling of undef states during equiv_induct.\n");
55 log("The following commands are executed by this verification command:\n");
60 std::string command
, techmap_opts
;
61 bool assert, undef
, multiclock
, async2sync
;
63 void clear_flags() YS_OVERRIDE
73 void execute(std::vector
< std::string
> args
, RTLIL::Design
* design
) YS_OVERRIDE
75 string run_from
, run_to
;
79 for (argidx
= 1; argidx
< args
.size(); argidx
++) {
80 if (args
[argidx
] == "-run" && argidx
+ 1 < args
.size()) {
81 size_t pos
= args
[argidx
+ 1].find(':');
82 if (pos
== std::string::npos
)
84 run_from
= args
[++argidx
].substr(0, pos
);
85 run_to
= args
[argidx
].substr(pos
+ 1);
88 if (args
[argidx
] == "-map" && argidx
+ 1 < args
.size()) {
89 techmap_opts
+= " -map " + args
[++argidx
];
92 if (args
[argidx
] == "-assert") {
96 if (args
[argidx
] == "-undef") {
100 if (args
[argidx
] == "-multiclock") {
104 if (args
[argidx
] == "-async2sync") {
111 for (; argidx
< args
.size(); argidx
++) {
112 if (command
.empty()) {
113 if (args
[argidx
].compare(0, 1, "-") == 0)
114 cmd_error(args
, argidx
, "Unknown option.");
118 command
+= args
[argidx
];
122 log_cmd_error("No optimization pass specified!\n");
124 if (!design
->full_selection())
125 log_cmd_error("This command only operates on fully selected designs!\n");
127 if (async2sync
&& multiclock
)
128 log_cmd_error("The '-async2sync' and '-multiclock' options are mutually exclusive!\n");
130 log_header(design
, "Executing EQUIV_OPT pass.\n");
133 run_script(design
, run_from
, run_to
);
138 void script() YS_OVERRIDE
140 if (check_label("run_pass")) {
141 run("hierarchy -auto-top");
142 run("design -save preopt");
147 run("design -stash postopt");
150 if (check_label("prepare")) {
151 run("design -copy-from preopt -as gold A:top");
152 run("design -copy-from postopt -as gate A:top");
155 if ((!techmap_opts
.empty() || help_mode
) && check_label("techmap", "(only with -map)")) {
158 opts
= " -map <filename> ...";
161 run("techmap -wb -D EQUIV -autoproc" + opts
);
164 if (check_label("prove")) {
165 if (multiclock
|| help_mode
)
166 run("clk2fflogic", "(only with -multiclock)");
167 if (async2sync
|| help_mode
)
168 run("async2sync", "(only with -async2sync)");
169 run("equiv_make gold gate equiv");
171 run("equiv_induct [-undef] equiv");
173 run("equiv_induct -undef equiv");
175 run("equiv_induct equiv");
177 run("equiv_status [-assert] equiv");
179 run("equiv_status -assert equiv");
181 run("equiv_status equiv");
184 if (check_label("restore")) {
185 run("design -load preopt");
190 PRIVATE_NAMESPACE_END