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/celltypes.h"
21 #include "kernel/log.h"
22 #include "kernel/register.h"
23 #include "kernel/rtlil.h"
26 PRIVATE_NAMESPACE_BEGIN
28 struct SynthIntelPass
: public ScriptPass
{
29 SynthIntelPass() : ScriptPass("synth_intel", "synthesis for Intel (Altera) FPGAs.") { experimental(); }
31 void help() YS_OVERRIDE
33 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
35 log(" synth_intel [options]\n");
37 log("This command runs synthesis for Intel FPGAs.\n");
39 log(" -family <max10 | arria10gx | cyclone10lp | cyclonev | cycloneiv | cycloneive>\n");
40 log(" generate the synthesis netlist for the specified family.\n");
41 log(" MAX10 is the default target if no family argument specified.\n");
42 log(" For Cyclone IV GX devices, use cycloneiv argument; for Cyclone IV E, use cycloneive.\n");
43 log(" Cyclone V and Arria 10 GX devices are experimental.\n");
45 log(" -top <module>\n");
46 log(" use the specified module as top module (default='top')\n");
48 log(" -vqm <file>\n");
49 log(" write the design to the specified Verilog Quartus Mapping File. Writing of an\n");
50 log(" output file is omitted if this parameter is not specified.\n");
51 log(" Note that this backend has not been tested and is likely incompatible\n");
52 log(" with recent versions of Quartus.\n");
54 log(" -vpr <file>\n");
55 log(" write BLIF files for VPR flow experiments. The synthesized BLIF output file is not\n");
56 log(" compatible with the Quartus flow. Writing of an\n");
57 log(" output file is omitted if this parameter is not specified.\n");
59 log(" -run <from_label>:<to_label>\n");
60 log(" only run the commands between the labels (see below). an empty\n");
61 log(" from label is synonymous to 'begin', and empty to label is\n");
62 log(" synonymous to the end of the command list.\n");
65 log(" use IO pad cells in output netlist\n");
68 log(" do not use block RAM cells in output netlist\n");
71 log(" do not flatten design before synthesis\n");
74 log(" run 'abc' with '-dff -D 1' options\n");
76 log("The following commands are executed by this synthesis command:\n");
81 string top_opt
, family_opt
, vout_file
, blif_file
;
82 bool retime
, flatten
, nobram
, iopads
;
84 void clear_flags() YS_OVERRIDE
86 top_opt
= "-auto-top";
96 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) YS_OVERRIDE
98 string run_from
, run_to
;
102 for (argidx
= 1; argidx
< args
.size(); argidx
++) {
103 if (args
[argidx
] == "-family" && argidx
+ 1 < args
.size()) {
104 family_opt
= args
[++argidx
];
107 if (args
[argidx
] == "-top" && argidx
+ 1 < args
.size()) {
108 top_opt
= "-top " + args
[++argidx
];
111 if (args
[argidx
] == "-vqm" && argidx
+ 1 < args
.size()) {
112 vout_file
= args
[++argidx
];
113 log_warning("The Quartus backend has not been tested recently and is likely incompatible with modern versions of Quartus.\n");
116 if (args
[argidx
] == "-vpr" && argidx
+ 1 < args
.size()) {
117 blif_file
= args
[++argidx
];
120 if (args
[argidx
] == "-run" && argidx
+ 1 < args
.size()) {
121 size_t pos
= args
[argidx
+ 1].find(':');
122 if (pos
== std::string::npos
)
124 run_from
= args
[++argidx
].substr(0, pos
);
125 run_to
= args
[argidx
].substr(pos
+ 1);
128 if (args
[argidx
] == "-iopads") {
132 if (args
[argidx
] == "-nobram") {
136 if (args
[argidx
] == "-noflatten") {
140 if (args
[argidx
] == "-retime") {
146 extra_args(args
, argidx
, design
);
148 if (!design
->full_selection())
149 log_cmd_error("This command only operates on fully selected designs!\n");
150 if (family_opt
!= "max10" &&
151 family_opt
!= "arria10gx" &&
152 family_opt
!= "cyclonev" &&
153 family_opt
!= "cycloneiv" &&
154 family_opt
!= "cycloneive" &&
155 family_opt
!= "cyclone10lp")
156 log_cmd_error("Invalid or no family specified: '%s'\n", family_opt
.c_str());
158 log_header(design
, "Executing SYNTH_INTEL pass.\n");
161 run_script(design
, run_from
, run_to
);
166 void script() YS_OVERRIDE
168 if (check_label("begin")) {
169 if (check_label("family"))
170 run(stringf("read_verilog -sv -lib +/intel/%s/cells_sim.v", family_opt
.c_str()));
172 // Misc and common cells
173 run("read_verilog -sv -lib +/intel/common/m9k_bb.v");
174 run("read_verilog -sv -lib +/intel/common/altpll_bb.v");
175 run(stringf("hierarchy -check %s", help_mode
? "-top <top>" : top_opt
.c_str()));
178 if (flatten
&& check_label("flatten", "(unless -noflatten)")) {
181 run("tribuf -logic");
185 if (check_label("coarse")) {
186 run("synth -run coarse");
189 if (!nobram
&& check_label("map_bram", "(skip if -nobram)")) {
190 if (family_opt
== "cycloneiv" ||
191 family_opt
== "cycloneive" ||
192 family_opt
== "max10" ||
194 run("memory_bram -rules +/intel/common/brams_m9k.txt", "(if applicable for family)");
195 run("techmap -map +/intel/common/brams_map_m9k.v", "(if applicable for family)");
197 log_warning("BRAM mapping is not currently supported for %s.\n", family_opt
.c_str());
201 if (check_label("map_ffram")) {
202 run("opt -fast -mux_undef -undriven -fine -full");
204 run("opt -undriven -fine");
205 run("dff2dffe -direct-match $_DFF_*");
207 run("techmap -map +/techmap.v");
210 run("setundef -undriven -zero");
211 if (retime
|| help_mode
)
212 run("abc -markgroups -dff -D 1", "(only if -retime)");
215 if (check_label("map_luts")) {
216 if (family_opt
== "arria10gx" || family_opt
== "cyclonev")
217 run("abc -luts 2:2,3,6:5" + string(retime
? " -dff" : ""));
219 run("abc -lut 4" + string(retime
? " -dff" : ""));
223 if (check_label("map_cells")) {
224 if (iopads
|| help_mode
)
225 run("iopadmap -bits -outpad $__outpad I:O -inpad $__inpad O:I", "(if -iopads)");
226 run(stringf("techmap -map +/intel/%s/cells_map.v", family_opt
.c_str()));
227 run("dffinit -highlow -ff dffeas q power_up");
231 if (check_label("check")) {
232 run("hierarchy -check");
234 run("check -noinit");
237 if (check_label("vqm")) {
238 if (!vout_file
.empty() || help_mode
)
239 run(stringf("write_verilog -attr2comment -defparam -nohex -decimal -renameprefix syn_ %s",
240 help_mode
? "<file-name>" : vout_file
.c_str()));
243 if (check_label("vpr")) {
244 if (!blif_file
.empty() || help_mode
) {
245 run(stringf("opt_clean -purge"));
246 run(stringf("write_blif %s", help_mode
? "<file-name>" : blif_file
.c_str()));
252 PRIVATE_NAMESPACE_END