Fixed copy&paste typo in synth_greenpak4
[yosys.git] / techlibs / greenpak4 / synth_greenpak4.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 bool check_label(bool &active, std::string run_from, std::string run_to, std::string label)
29 {
30 if (label == run_from)
31 active = true;
32 if (label == run_to)
33 active = false;
34 return active;
35 }
36
37 struct SynthGreenPAK4Pass : public Pass {
38 SynthGreenPAK4Pass() : Pass("synth_greenpak4", "synthesis for GreenPAK4 FPGAs") { }
39 virtual void help()
40 {
41 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
42 log("\n");
43 log(" synth_greenpak4 [options]\n");
44 log("\n");
45 log("This command runs synthesis for GreenPAK4 FPGAs. This work is experimental.\n");
46 log("\n");
47 log(" -top <module>\n");
48 log(" use the specified module as top module (default='top')\n");
49 log("\n");
50 log(" -blif <file>\n");
51 log(" write the design to the specified BLIF file. writing of an output file\n");
52 log(" is omitted if this parameter is not specified.\n");
53 log("\n");
54 log(" -edif <file>\n");
55 log(" write the design to the specified edif file. writing of an output file\n");
56 log(" is omitted if this parameter is not specified.\n");
57 log("\n");
58 log(" -run <from_label>:<to_label>\n");
59 log(" only run the commands between the labels (see below). an empty\n");
60 log(" from label is synonymous to 'begin', and empty to label is\n");
61 log(" synonymous to the end of the command list.\n");
62 log("\n");
63 log(" -noflatten\n");
64 log(" do not flatten design before synthesis\n");
65 log("\n");
66 log(" -retime\n");
67 log(" run 'abc' with -dff option\n");
68 log("\n");
69 log("\n");
70 log("The following commands are executed by this synthesis command:\n");
71 log("\n");
72 log(" begin:\n");
73 log(" read_verilog -lib +/greenpak4/cells_sim.v\n");
74 log(" hierarchy -check -top <top>\n");
75 log("\n");
76 log(" flatten: (unless -noflatten)\n");
77 log(" proc\n");
78 log(" flatten\n");
79 log(" tribuf -logic\n");
80 log("\n");
81 log(" coarse:\n");
82 log(" synth -run coarse\n");
83 log("\n");
84 log(" fine:\n");
85 log(" opt -fast -mux_undef -undriven -fine\n");
86 log(" memory_map\n");
87 log(" opt -undriven -fine\n");
88 log(" techmap\n");
89 log(" abc -dff (only if -retime)\n");
90 log("\n");
91 log(" map_luts:\n");
92 log(" abc -lut 4\n");
93 log(" clean\n");
94 log("\n");
95 log(" map_cells:\n");
96 log(" techmap -map +/greenpak4/cells_map.v\n");
97 log(" clean\n");
98 log("\n");
99 log(" check:\n");
100 log(" hierarchy -check\n");
101 log(" stat\n");
102 log(" check -noinit\n");
103 log("\n");
104 log(" blif:\n");
105 log(" write_blif -gates -attr -param <file-name>\n");
106 log("\n");
107 log(" edif:\n");
108 log(" write_edif <file-name>\n");
109 log("\n");
110 }
111 virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
112 {
113 std::string top_opt = "-auto-top";
114 std::string run_from, run_to;
115 std::string blif_file, edif_file;
116 bool flatten = true;
117 bool retime = false;
118
119 size_t argidx;
120 for (argidx = 1; argidx < args.size(); argidx++)
121 {
122 if (args[argidx] == "-top" && argidx+1 < args.size()) {
123 top_opt = "-top " + args[++argidx];
124 continue;
125 }
126 if (args[argidx] == "-blif" && argidx+1 < args.size()) {
127 blif_file = args[++argidx];
128 continue;
129 }
130 if (args[argidx] == "-edif" && argidx+1 < args.size()) {
131 edif_file = args[++argidx];
132 continue;
133 }
134 if (args[argidx] == "-run" && argidx+1 < args.size()) {
135 size_t pos = args[argidx+1].find(':');
136 if (pos == std::string::npos)
137 break;
138 run_from = args[++argidx].substr(0, pos);
139 run_to = args[argidx].substr(pos+1);
140 continue;
141 }
142 if (args[argidx] == "-flatten") {
143 flatten = true;
144 continue;
145 }
146 if (args[argidx] == "-noflatten") {
147 flatten = false;
148 continue;
149 }
150 if (args[argidx] == "-retime") {
151 retime = true;
152 continue;
153 }
154 break;
155 }
156 extra_args(args, argidx, design);
157
158 if (!design->full_selection())
159 log_cmd_error("This comannd only operates on fully selected designs!\n");
160
161 bool active = run_from.empty();
162
163 log_header("Executing SYNTH_GREENPAK4 pass.\n");
164 log_push();
165
166 if (check_label(active, run_from, run_to, "begin"))
167 {
168 Pass::call(design, "read_verilog -lib +/greenpak4/cells_sim.v");
169 Pass::call(design, stringf("hierarchy -check %s", top_opt.c_str()));
170 }
171
172 if (flatten && check_label(active, run_from, run_to, "flatten"))
173 {
174 Pass::call(design, "proc");
175 Pass::call(design, "flatten");
176 Pass::call(design, "tribuf -logic");
177 }
178
179 if (check_label(active, run_from, run_to, "coarse"))
180 {
181 Pass::call(design, "synth -run coarse");
182 }
183
184 if (check_label(active, run_from, run_to, "fine"))
185 {
186 Pass::call(design, "opt -fast -mux_undef -undriven -fine");
187 Pass::call(design, "memory_map");
188 Pass::call(design, "opt -undriven -fine");
189 Pass::call(design, "techmap");
190 if (retime)
191 Pass::call(design, "abc -dff");
192 }
193
194 if (check_label(active, run_from, run_to, "map_luts"))
195 {
196 Pass::call(design, "abc -lut 4");
197 Pass::call(design, "clean");
198 }
199
200 if (check_label(active, run_from, run_to, "map_cells"))
201 {
202 Pass::call(design, "techmap -map +/greenpak4/cells_map.v");
203 Pass::call(design, "clean");
204 }
205
206 if (check_label(active, run_from, run_to, "check"))
207 {
208 Pass::call(design, "hierarchy -check");
209 Pass::call(design, "stat");
210 Pass::call(design, "check -noinit");
211 }
212
213 if (check_label(active, run_from, run_to, "blif"))
214 {
215 if (!blif_file.empty())
216 Pass::call(design, stringf("write_blif -gates -attr -param %s", blif_file.c_str()));
217 }
218
219 if (check_label(active, run_from, run_to, "edif"))
220 {
221 if (!edif_file.empty())
222 Pass::call(design, stringf("write_edif %s", edif_file.c_str()));
223 }
224
225 log_pop();
226 }
227 } SynthGreenPAK4Pass;
228
229 PRIVATE_NAMESPACE_END