55412ea2b3d976c31d7e89247c8a5b6203445a2e
[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 struct SynthGreenPAK4Pass : public ScriptPass
29 {
30 SynthGreenPAK4Pass() : ScriptPass("synth_greenpak4", "synthesis for GreenPAK4 FPGAs") { }
31
32 virtual void help() YS_OVERRIDE
33 {
34 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
35 log("\n");
36 log(" synth_greenpak4 [options]\n");
37 log("\n");
38 log("This command runs synthesis for GreenPAK4 FPGAs. This work is experimental.\n");
39 log("\n");
40 log(" -top <module>\n");
41 log(" use the specified module as top module (default='top')\n");
42 log("\n");
43 log(" -part <part>\n");
44 log(" synthesize for the specified part. Valid values are SLG46140V,\n");
45 log(" SLG46620V, and SLG46621V (default).\n");
46 log("\n");
47 log(" -json <file>\n");
48 log(" write the design to the specified JSON file. writing of an output file\n");
49 log(" is omitted if this parameter is not specified.\n");
50 log("\n");
51 log(" -run <from_label>:<to_label>\n");
52 log(" only run the commands between the labels (see below). an empty\n");
53 log(" from label is synonymous to 'begin', and empty to label is\n");
54 log(" synonymous to the end of the command list.\n");
55 log("\n");
56 log(" -noflatten\n");
57 log(" do not flatten design before synthesis\n");
58 log("\n");
59 log(" -retime\n");
60 log(" run 'abc' with -dff option\n");
61 log("\n");
62 log("\n");
63 log("The following commands are executed by this synthesis command:\n");
64 help_script();
65 log("\n");
66 }
67
68 string top_opt, part, json_file;
69 bool flatten, retime;
70
71 virtual void clear_flags() YS_OVERRIDE
72 {
73 top_opt = "-auto-top";
74 part = "SLG46621V";
75 json_file = "";
76 flatten = true;
77 retime = false;
78 }
79
80 virtual void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
81 {
82 string run_from, run_to;
83 clear_flags();
84
85 size_t argidx;
86 for (argidx = 1; argidx < args.size(); argidx++)
87 {
88 if (args[argidx] == "-top" && argidx+1 < args.size()) {
89 top_opt = "-top " + args[++argidx];
90 continue;
91 }
92 if (args[argidx] == "-json" && argidx+1 < args.size()) {
93 json_file = args[++argidx];
94 continue;
95 }
96 if (args[argidx] == "-part" && argidx+1 < args.size()) {
97 part = args[++argidx];
98 continue;
99 }
100 if (args[argidx] == "-run" && argidx+1 < args.size()) {
101 size_t pos = args[argidx+1].find(':');
102 if (pos == std::string::npos)
103 break;
104 run_from = args[++argidx].substr(0, pos);
105 run_to = args[argidx].substr(pos+1);
106 continue;
107 }
108 if (args[argidx] == "-noflatten") {
109 flatten = false;
110 continue;
111 }
112 if (args[argidx] == "-retime") {
113 retime = true;
114 continue;
115 }
116 break;
117 }
118 extra_args(args, argidx, design);
119
120 if (!design->full_selection())
121 log_cmd_error("This comannd only operates on fully selected designs!\n");
122
123 if (part != "SLG46140V" && part != "SLG46620V" && part != "SLG46621V")
124 log_cmd_error("Invalid part name: '%s'\n", part.c_str());
125
126 log_header(design, "Executing SYNTH_GREENPAK4 pass.\n");
127 log_push();
128
129 run_script(design, run_from, run_to);
130
131 log_pop();
132 }
133
134 virtual void script() YS_OVERRIDE
135 {
136 if (check_label("begin"))
137 {
138 run("read_verilog -lib +/greenpak4/cells_sim.v");
139 run(stringf("hierarchy -check %s", help_mode ? "-top <top>" : top_opt.c_str()));
140 }
141
142 if (flatten && check_label("flatten", "(unless -noflatten)"))
143 {
144 run("proc");
145 run("flatten");
146 run("tribuf -logic");
147 }
148
149 if (check_label("coarse"))
150 {
151 run("synth -run coarse");
152 }
153
154 if (check_label("fine"))
155 {
156 run("greenpak4_counters");
157 run("clean");
158 run("opt -fast -mux_undef -undriven -fine");
159 run("memory_map");
160 run("opt -undriven -fine");
161 run("techmap");
162 run("dfflibmap -prepare -liberty +/greenpak4/gp_dff.lib");
163 run("opt -fast");
164 if (retime || help_mode)
165 run("abc -dff", "(only if -retime)");
166 }
167
168 if (check_label("map_luts"))
169 {
170 if (help_mode || part == "SLG46140V") run("nlutmap -luts 0,6,8,2", " (for -part SLG46140V)");
171 if (help_mode || part == "SLG46620V") run("nlutmap -luts 2,8,16,2", "(for -part SLG46620V)");
172 if (help_mode || part == "SLG46621V") run("nlutmap -luts 2,8,16,2", "(for -part SLG46621V)");
173 run("clean");
174 }
175
176 if (check_label("map_cells"))
177 {
178 run("shregmap -tech greenpak4");
179 run("iopadmap -bits -inpad GP_IBUF OUT:IN -outpad GP_OBUF IN:OUT -inoutpad GP_IBUF OUT:IN");
180 run("extract -map +/greenpak4/cells_extract.v -verbose");
181 run("dfflibmap -liberty +/greenpak4/gp_dff.lib");
182 run("techmap -map +/greenpak4/cells_map.v");
183 run("dffinit -ff GP_DFF Q INIT");
184 run("dffinit -ff GP_DFFR Q INIT");
185 run("dffinit -ff GP_DFFS Q INIT");
186 run("dffinit -ff GP_DFFSR Q INIT");
187 run("clean");
188 }
189
190 if (check_label("check"))
191 {
192 run("hierarchy -check");
193 run("stat");
194 run("check -noinit");
195 }
196
197 if (check_label("json"))
198 {
199 run("splitnets;;", "(temporary workaround for gp4par parser limitation)");
200 if (!json_file.empty() || help_mode)
201 run(stringf("write_json %s", help_mode ? "<file-name>" : json_file.c_str()));
202 }
203
204 log_pop();
205 }
206 } SynthGreenPAK4Pass;
207
208 PRIVATE_NAMESPACE_END