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 option\n");
68 log("The following commands are executed by this synthesis command:\n");
73 string top_opt
, vout_file
;
74 bool retime
, nobram
, nodram
, flatten
, nodffe
;
76 void clear_flags() YS_OVERRIDE
78 top_opt
= "-auto-top";
87 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
89 string run_from
, run_to
;
93 for (argidx
= 1; argidx
< args
.size(); argidx
++)
95 if (args
[argidx
] == "-top" && argidx
+1 < args
.size()) {
96 top_opt
= "-top " + args
[++argidx
];
99 if (args
[argidx
] == "-vout" && argidx
+1 < args
.size()) {
100 vout_file
= args
[++argidx
];
103 if (args
[argidx
] == "-run" && argidx
+1 < args
.size()) {
104 size_t pos
= args
[argidx
+1].find(':');
105 if (pos
== std::string::npos
)
107 run_from
= args
[++argidx
].substr(0, pos
);
108 run_to
= args
[argidx
].substr(pos
+1);
111 if (args
[argidx
] == "-retime") {
115 if (args
[argidx
] == "-nobram") {
119 if (args
[argidx
] == "-nodram") {
123 if (args
[argidx
] == "-nodffe") {
127 if (args
[argidx
] == "-noflatten") {
133 extra_args(args
, argidx
, design
);
135 if (!design
->full_selection())
136 log_cmd_error("This command only operates on fully selected designs!\n");
138 log_header(design
, "Executing SYNTH_GOWIN pass.\n");
141 run_script(design
, run_from
, run_to
);
146 void script() YS_OVERRIDE
148 if (check_label("begin"))
150 run("read_verilog -lib +/gowin/cells_sim.v");
151 run(stringf("hierarchy -check %s", help_mode
? "-top <top>" : top_opt
.c_str()));
154 if (flatten
&& check_label("flatten", "(unless -noflatten)"))
158 run("tribuf -logic");
162 if (check_label("coarse"))
164 run("synth -run coarse");
167 if (!nobram
&& check_label("bram", "(skip if -nobram)"))
169 run("memory_bram -rules +/gowin/bram.txt");
170 run("techmap -map +/gowin/brams_map.v -map +/gowin/cells_sim.v");
173 if (!nodram
&& check_label("dram", "(skip if -nodram)"))
175 run("memory_bram -rules +/gowin/dram.txt");
176 run("techmap -map +/gowin/drams_map.v");
177 run("determine_init");
180 if (check_label("fine"))
182 run("opt -fast -mux_undef -undriven -fine");
184 run("opt -undriven -fine");
185 run("techmap -map +/techmap.v -map +/gowin/arith_map.v");
186 run("techmap -map +/techmap.v");
187 if (retime
|| help_mode
)
188 run("abc -dff", "(only if -retime)");
191 if (check_label("map_ffs"))
197 run("dff2dffe -direct-match $_DFF_* -direct-match $__DFFS_*");
198 run("techmap -map +/gowin/cells_map.v");
199 run("opt_expr -mux_undef");
203 if (check_label("map_luts"))
209 if (check_label("map_cells"))
211 run("techmap -map +/gowin/cells_map.v");
212 run("hilomap -hicell VCC V -locell GND G");
213 run("iopadmap -bits -inpad IBUF O:I -outpad OBUF I:O", "(unless -noiopads)");
214 run("dffinit -ff DFF Q INIT");
219 if (check_label("check"))
221 run("hierarchy -check");
223 run("check -noinit");
226 if (check_label("vout"))
228 if (!vout_file
.empty() || help_mode
)
229 run(stringf("write_verilog -nodec -attr2comment -defparam -renameprefix gen %s",
230 help_mode
? "<file-name>" : vout_file
.c_str()));
235 PRIVATE_NAMESPACE_END