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 SynthSf2Pass
: public ScriptPass
30 SynthSf2Pass() : ScriptPass("synth_sf2", "synthesis for SmartFusion2 and IGLOO2 FPGAs") { }
32 void help() YS_OVERRIDE
34 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
36 log(" synth_sf2 [options]\n");
38 log("This command runs synthesis for SmartFusion2 and IGLOO2 FPGAs.\n");
40 log(" -top <module>\n");
41 log(" use the specified module as top module\n");
43 log(" -edif <file>\n");
44 log(" write the design to the specified EDIF file. writing of an output file\n");
45 log(" is omitted if this parameter is not specified.\n");
47 log(" -vlog <file>\n");
48 log(" write the design to the specified Verilog file. writing of an output file\n");
49 log(" is omitted if this parameter is not specified.\n");
51 log(" -json <file>\n");
52 log(" write the design to the specified JSON file. writing of an output file\n");
53 log(" is omitted if this parameter is not specified.\n");
55 log(" -run <from_label>:<to_label>\n");
56 log(" only run the commands between the labels (see below). an empty\n");
57 log(" from label is synonymous to 'begin', and empty to label is\n");
58 log(" synonymous to the end of the command list.\n");
61 log(" do not flatten design before synthesis\n");
64 log(" run synthesis in \"block mode\", i.e. do not insert IO buffers\n");
67 log(" insert direct PAD->global_net buffers\n");
70 log(" run 'abc' with '-dff -D 1' options\n");
73 log("The following commands are executed by this synthesis command:\n");
78 string top_opt
, edif_file
, vlog_file
, json_file
;
79 bool flatten
, retime
, iobs
, clkbuf
;
81 void clear_flags() YS_OVERRIDE
83 top_opt
= "-auto-top";
93 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
95 string run_from
, run_to
;
99 for (argidx
= 1; argidx
< args
.size(); argidx
++)
101 if (args
[argidx
] == "-top" && argidx
+1 < args
.size()) {
102 top_opt
= "-top " + args
[++argidx
];
105 if (args
[argidx
] == "-edif" && argidx
+1 < args
.size()) {
106 edif_file
= args
[++argidx
];
109 if (args
[argidx
] == "-vlog" && argidx
+1 < args
.size()) {
110 vlog_file
= args
[++argidx
];
113 if (args
[argidx
] == "-json" && argidx
+1 < args
.size()) {
114 json_file
= args
[++argidx
];
117 if (args
[argidx
] == "-run" && argidx
+1 < args
.size()) {
118 size_t pos
= args
[argidx
+1].find(':');
119 if (pos
== std::string::npos
)
121 run_from
= args
[++argidx
].substr(0, pos
);
122 run_to
= args
[argidx
].substr(pos
+1);
125 if (args
[argidx
] == "-noflatten") {
129 if (args
[argidx
] == "-retime") {
133 if (args
[argidx
] == "-noiobs") {
137 if (args
[argidx
] == "-clkbuf") {
143 extra_args(args
, argidx
, design
);
145 if (!design
->full_selection())
146 log_cmd_error("This command only operates on fully selected designs!\n");
148 log_header(design
, "Executing SYNTH_SF2 pass.\n");
151 run_script(design
, run_from
, run_to
);
156 void script() YS_OVERRIDE
158 if (check_label("begin"))
160 run("read_verilog -lib +/sf2/cells_sim.v");
161 run(stringf("hierarchy -check %s", help_mode
? "-top <top>" : top_opt
.c_str()));
164 if (flatten
&& check_label("flatten", "(unless -noflatten)"))
168 run("tribuf -logic");
172 if (check_label("coarse"))
174 run("synth -run coarse");
177 if (check_label("fine"))
179 run("opt -fast -mux_undef -undriven -fine");
181 run("opt -undriven -fine");
182 run("techmap -map +/techmap.v -map +/sf2/arith_map.v");
184 if (retime
|| help_mode
)
185 run("abc -dff -D 1", "(only if -retime)");
188 if (check_label("map_ffs"))
190 run("techmap -D NO_LUT -map +/sf2/cells_map.v");
191 run("opt_expr -mux_undef");
193 // run("sf2_ffinit");
195 // run("sf2_opt -full");
198 if (check_label("map_luts"))
204 if (check_label("map_cells"))
206 run("techmap -map +/sf2/cells_map.v");
210 if (check_label("map_iobs"))
213 run("sf2_iobs [-clkbuf]", "(unless -noiobs)");
215 run(clkbuf
? "sf2_iobs -clkbuf" : "sf2_iobs");
219 if (check_label("check"))
221 run("hierarchy -check");
223 run("check -noinit");
226 if (check_label("edif"))
228 if (!edif_file
.empty() || help_mode
)
229 run(stringf("write_edif -gndvccy %s", help_mode
? "<file-name>" : edif_file
.c_str()));
232 if (check_label("vlog"))
234 if (!vlog_file
.empty() || help_mode
)
235 run(stringf("write_verilog %s", help_mode
? "<file-name>" : vlog_file
.c_str()));
238 if (check_label("json"))
240 if (!json_file
.empty() || help_mode
)
241 run(stringf("write_json %s", help_mode
? "<file-name>" : json_file
.c_str()));
246 PRIVATE_NAMESPACE_END