Merge pull request #1004 from YosysHQ/clifford/fix1002
[yosys.git] / passes / memory / memory.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/log.h"
22 #include <stdlib.h>
23 #include <stdio.h>
24
25 USING_YOSYS_NAMESPACE
26 PRIVATE_NAMESPACE_BEGIN
27
28 struct MemoryPass : public Pass {
29 MemoryPass() : Pass("memory", "translate memories to basic cells") { }
30 void help() YS_OVERRIDE
31 {
32 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
33 log("\n");
34 log(" memory [-nomap] [-nordff] [-memx] [-bram <bram_rules>] [selection]\n");
35 log("\n");
36 log("This pass calls all the other memory_* passes in a useful order:\n");
37 log("\n");
38 log(" memory_dff [-nordff] (-memx implies -nordff)\n");
39 log(" opt_clean\n");
40 log(" memory_share\n");
41 log(" opt_clean\n");
42 log(" memory_memx (when called with -memx)\n");
43 log(" memory_collect\n");
44 log(" memory_bram -rules <bram_rules> (when called with -bram)\n");
45 log(" memory_map (skipped if called with -nomap)\n");
46 log("\n");
47 log("This converts memories to word-wide DFFs and address decoders\n");
48 log("or multiport memory blocks if called with the -nomap option.\n");
49 log("\n");
50 }
51 void execute(std::vector<std::string> args, RTLIL::Design *design) YS_OVERRIDE
52 {
53 bool flag_nomap = false;
54 bool flag_nordff = false;
55 bool flag_memx = false;
56 string memory_bram_opts;
57
58 log_header(design, "Executing MEMORY pass.\n");
59 log_push();
60
61 size_t argidx;
62 for (argidx = 1; argidx < args.size(); argidx++) {
63 if (args[argidx] == "-nomap") {
64 flag_nomap = true;
65 continue;
66 }
67 if (args[argidx] == "-nordff") {
68 flag_nordff = true;
69 continue;
70 }
71 if (args[argidx] == "-memx") {
72 flag_nordff = true;
73 flag_memx = true;
74 continue;
75 }
76 if (argidx+1 < args.size() && args[argidx] == "-bram") {
77 memory_bram_opts += " -rules " + args[++argidx];
78 continue;
79 }
80 break;
81 }
82 extra_args(args, argidx, design);
83
84 Pass::call(design, flag_nordff ? "memory_dff -nordff" : "memory_dff");
85 Pass::call(design, "opt_clean");
86 Pass::call(design, "memory_share");
87 if (flag_memx)
88 Pass::call(design, "memory_memx");
89 Pass::call(design, "opt_clean");
90 Pass::call(design, "memory_collect");
91
92 if (!memory_bram_opts.empty())
93 Pass::call(design, "memory_bram" + memory_bram_opts);
94
95 if (!flag_nomap)
96 Pass::call(design, "memory_map");
97
98 log_pop();
99 }
100 } MemoryPass;
101
102 PRIVATE_NAMESPACE_END