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 SynthGowinPass
: public ScriptPass
30 SynthGowinPass() : ScriptPass("synth_gowin", "synthesis for Gowin FPGAs") { }
32 void help() YS_OVERRIDE
34 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
36 log(" synth_gowin [options]\n");
38 log("This command runs synthesis for Gowin FPGAs. This work is experimental.\n");
40 log(" -top <module>\n");
41 log(" use the specified module as top module (default='top')\n");
43 log(" -vout <file>\n");
44 log(" write the design to the specified Verilog netlist file. writing of an\n");
45 log(" output file is omitted if this parameter is not specified.\n");
47 log(" -run <from_label>:<to_label>\n");
48 log(" only run the commands between the labels (see below). an empty\n");
49 log(" from label is synonymous to 'begin', and empty to label is\n");
50 log(" synonymous to the end of the command list.\n");
53 log(" do not use flipflops with CE in output netlist\n");
56 log(" do not use BRAM cells in output netlist\n");
59 log(" do not use distributed RAM cells in output netlist\n");
62 log(" do not flatten design before synthesis\n");
65 log(" run 'abc' with '-dff -D 1' options\n");
68 log(" do not use muxes to implement LUTs larger than LUT4s\n");
71 log(" do not emit IOB at top level ports\n");
74 //log(" use new ABC9 flow (EXPERIMENTAL)\n");
77 log("The following commands are executed by this synthesis command:\n");
82 string top_opt
, vout_file
;
83 bool retime
, nobram
, nolutram
, flatten
, nodffe
, nowidelut
, abc9
, noiopads
;
85 void clear_flags() YS_OVERRIDE
87 top_opt
= "-auto-top";
99 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
101 string run_from
, run_to
;
105 for (argidx
= 1; argidx
< args
.size(); argidx
++)
107 if (args
[argidx
] == "-top" && argidx
+1 < args
.size()) {
108 top_opt
= "-top " + args
[++argidx
];
111 if (args
[argidx
] == "-vout" && argidx
+1 < args
.size()) {
112 vout_file
= args
[++argidx
];
115 if (args
[argidx
] == "-run" && argidx
+1 < args
.size()) {
116 size_t pos
= args
[argidx
+1].find(':');
117 if (pos
== std::string::npos
)
119 run_from
= args
[++argidx
].substr(0, pos
);
120 run_to
= args
[argidx
].substr(pos
+1);
123 if (args
[argidx
] == "-retime") {
127 if (args
[argidx
] == "-nobram") {
131 if (args
[argidx
] == "-nolutram" || /*deprecated*/args
[argidx
] == "-nodram") {
135 if (args
[argidx
] == "-nodffe") {
139 if (args
[argidx
] == "-noflatten") {
143 if (args
[argidx
] == "-nowidelut") {
147 //if (args[argidx] == "-abc9") {
151 if (args
[argidx
] == "-noiopads") {
157 extra_args(args
, argidx
, design
);
159 if (!design
->full_selection())
160 log_cmd_error("This command only operates on fully selected designs!\n");
162 log_header(design
, "Executing SYNTH_GOWIN pass.\n");
165 run_script(design
, run_from
, run_to
);
170 void script() YS_OVERRIDE
172 if (check_label("begin"))
174 run("read_verilog -lib +/gowin/cells_sim.v");
175 run(stringf("hierarchy -check %s", help_mode
? "-top <top>" : top_opt
.c_str()));
178 if (flatten
&& check_label("flatten", "(unless -noflatten)"))
182 run("tribuf -logic");
186 if (check_label("coarse"))
188 run("synth -run coarse");
191 if (!nobram
&& check_label("map_bram", "(skip if -nobram)"))
193 run("memory_bram -rules +/gowin/brams.txt");
194 run("techmap -map +/gowin/brams_map.v -map +/gowin/cells_sim.v");
197 if (!nolutram
&& check_label("map_lutram", "(skip if -nolutram)"))
199 run("memory_bram -rules +/gowin/lutrams.txt");
200 run("techmap -map +/gowin/lutrams_map.v");
201 run("determine_init");
204 if (check_label("map_ffram"))
206 run("opt -fast -mux_undef -undriven -fine");
208 run("opt -undriven -fine");
211 if (check_label("map_gates"))
213 run("techmap -map +/techmap.v -map +/gowin/arith_map.v");
214 run("techmap -map +/techmap.v");
215 if (retime
|| help_mode
)
216 run("abc -dff -D 1", "(only if -retime)");
220 if (check_label("map_ffs"))
223 run("dff2dffs -match-init");
226 run("dff2dffe -direct-match $_DFF_* -direct-match $__DFFS_*");
227 run("techmap -map +/gowin/cells_map.v");
228 run("opt_expr -mux_undef");
232 if (check_label("map_luts"))
234 /*if (nowidelut && abc9) {
236 } else*/ if (nowidelut
&& !abc9
) {
238 } else /*if (!nowidelut && abc9) {
239 run("abc9 -lut 4:8");
240 } else*/ if (!nowidelut
&& !abc9
) {
246 if (check_label("map_cells"))
248 run("techmap -map +/gowin/cells_map.v");
249 run("setundef -undriven -params -zero");
250 run("hilomap -singleton -hicell VCC V -locell GND G");
251 if (!noiopads
|| help_mode
)
252 run("iopadmap -bits -inpad IBUF O:I -outpad OBUF I:O "
253 "-toutpad TBUF OEN:I:O -tinoutpad IOBUF OEN:O:I:IO", "(unless -noiopads)");
257 if (check_label("check"))
259 run("hierarchy -check");
261 run("check -noinit");
264 if (check_label("vout"))
266 if (!vout_file
.empty() || help_mode
)
267 run(stringf("write_verilog -decimal -attr2comment -defparam -renameprefix gen %s",
268 help_mode
? "<file-name>" : vout_file
.c_str()));
273 PRIVATE_NAMESPACE_END