Added Xilinx MUXF7 and MUXF8 support
[yosys.git] / techlibs / xilinx / synth_xilinx.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 bool check_label(bool &active, std::string run_from, std::string run_to, std::string label)
29 {
30 if (label == run_from)
31 active = true;
32 if (label == run_to)
33 active = false;
34 return active;
35 }
36
37 struct SynthXilinxPass : public Pass {
38 SynthXilinxPass() : Pass("synth_xilinx", "synthesis for Xilinx FPGAs") { }
39 virtual void help()
40 {
41 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
42 log("\n");
43 log(" synth_xilinx [options]\n");
44 log("\n");
45 log("This command runs synthesis for Xilinx FPGAs. This command does not operate on\n");
46 log("partly selected designs. At the moment this command creates netlists that are\n");
47 log("compatible with 7-series and 6-series Xilinx devices.\n");
48 log("\n");
49 log(" -top <module>\n");
50 log(" use the specified module as top module (default='top')\n");
51 log("\n");
52 log(" -edif <file>\n");
53 log(" write the design to the specified edif file. writing of an output file\n");
54 log(" is omitted if this parameter is not specified.\n");
55 log("\n");
56 log(" -run <from_label>:<to_label>\n");
57 log(" only run the commands between the labels (see below). an empty\n");
58 log(" from label is synonymous to 'begin', and empty to label is\n");
59 log(" synonymous to the end of the command list.\n");
60 log("\n");
61 log("\n");
62 log("The following commands are executed by this synthesis command:\n");
63 log("\n");
64 log(" begin:\n");
65 log(" hierarchy -check -top <top>\n");
66 log("\n");
67 log(" coarse:\n");
68 log(" synth -run coarse\n");
69 log("\n");
70 log(" bram:\n");
71 log(" memory_bram -rules +/xilinx/brams.txt\n");
72 log(" techmap -map +/xilinx/brams.v\n");
73 log("\n");
74 log(" fine:\n");
75 log(" synth -run fine\n");
76 log("\n");
77 log(" map_luts:\n");
78 log(" abc -lut 6:8\n");
79 log(" clean\n");
80 log("\n");
81 log(" map_cells:\n");
82 log(" techmap -map +/xilinx/cells.v\n");
83 log(" clean\n");
84 log("\n");
85 log(" edif:\n");
86 log(" write_edif synth.edif\n");
87 log("\n");
88 }
89 virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
90 {
91 std::string top_module = "top";
92 std::string arch_name = "spartan6";
93 std::string edif_file;
94 std::string run_from, run_to;
95
96 size_t argidx;
97 for (argidx = 1; argidx < args.size(); argidx++)
98 {
99 if (args[argidx] == "-top" && argidx+1 < args.size()) {
100 top_module = args[++argidx];
101 continue;
102 }
103 if (args[argidx] == "-edif" && argidx+1 < args.size()) {
104 edif_file = args[++argidx];
105 continue;
106 }
107 if (args[argidx] == "-run" && argidx+1 < args.size()) {
108 size_t pos = args[argidx+1].find(':');
109 if (pos == std::string::npos)
110 break;
111 run_from = args[++argidx].substr(0, pos);
112 run_to = args[argidx].substr(pos+1);
113 continue;
114 }
115 break;
116 }
117 extra_args(args, argidx, design);
118
119 if (!design->full_selection())
120 log_cmd_error("This comannd only operates on fully selected designs!\n");
121
122 bool active = run_from.empty();
123
124 log_header("Executing SYNTH_XILINX pass.\n");
125 log_push();
126
127 if (check_label(active, run_from, run_to, "begin"))
128 {
129 Pass::call(design, stringf("hierarchy -check -top %s", top_module.c_str()));
130 }
131
132 if (check_label(active, run_from, run_to, "coarse"))
133 {
134 Pass::call(design, "synth -run coarse");
135 }
136
137 if (check_label(active, run_from, run_to, "bram"))
138 {
139 Pass::call(design, "memory_bram -rules +/xilinx/brams.txt");
140 Pass::call(design, "techmap -map +/xilinx/brams.v");
141 }
142
143 if (check_label(active, run_from, run_to, "fine"))
144 {
145 Pass::call(design, "synth -run fine");
146 }
147
148 if (check_label(active, run_from, run_to, "map_luts"))
149 {
150 Pass::call(design, "abc -lut 6:8");
151 Pass::call(design, "clean");
152 }
153
154 if (check_label(active, run_from, run_to, "map_cells"))
155 {
156 Pass::call(design, "techmap -map +/xilinx/cells.v");
157 Pass::call(design, "clean");
158 }
159
160 if (check_label(active, run_from, run_to, "edif"))
161 {
162 if (!edif_file.empty())
163 Pass::call(design, stringf("write_edif %s", edif_file.c_str()));
164 }
165
166 log_pop();
167 }
168 } SynthXilinxPass;
169
170 PRIVATE_NAMESPACE_END