1 /* 2 * yosys -- Yosys Open SYnthesis Suite 3 * 4 * Copyright (C) 2012 Claire Xenia Wolf <claire@yosyshq.com> 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 { MemoryPassMemoryPass29 MemoryPass() : Pass("memory", "translate memories to basic cells") { } helpMemoryPass30 void help() override 31 { 32 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---| 33 log("\n"); 34 log(" memory [-nomap] [-nordff] [-nowiden] [-nosat] [-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(" opt_mem\n"); 39 log(" opt_mem_priority\n"); 40 log(" opt_mem_feedback\n"); 41 log(" memory_dff (skipped if called with -nordff or -memx)\n"); 42 log(" opt_clean\n"); 43 log(" memory_share [-nowiden] [-nosat]\n"); 44 log(" opt_mem_widen\n"); 45 log(" memory_memx (when called with -memx)\n"); 46 log(" opt_clean\n"); 47 log(" memory_collect\n"); 48 log(" memory_bram -rules <bram_rules> (when called with -bram)\n"); 49 log(" memory_map (skipped if called with -nomap)\n"); 50 log("\n"); 51 log("This converts memories to word-wide DFFs and address decoders\n"); 52 log("or multiport memory blocks if called with the -nomap option.\n"); 53 log("\n"); 54 } executeMemoryPass55 void execute(std::vector<std::string> args, RTLIL::Design *design) override 56 { 57 bool flag_nomap = false; 58 bool flag_nordff = false; 59 bool flag_memx = false; 60 string memory_bram_opts; 61 string memory_share_opts; 62 63 log_header(design, "Executing MEMORY pass.\n"); 64 log_push(); 65 66 size_t argidx; 67 for (argidx = 1; argidx < args.size(); argidx++) { 68 if (args[argidx] == "-nomap") { 69 flag_nomap = true; 70 continue; 71 } 72 if (args[argidx] == "-nordff") { 73 flag_nordff = true; 74 continue; 75 } 76 if (args[argidx] == "-memx") { 77 flag_nordff = true; 78 flag_memx = true; 79 continue; 80 } 81 if (args[argidx] == "-nowiden") { 82 memory_share_opts += " -nowiden"; 83 continue; 84 } 85 if (args[argidx] == "-nosat") { 86 memory_share_opts += " -nosat"; 87 continue; 88 } 89 if (argidx+1 < args.size() && args[argidx] == "-bram") { 90 memory_bram_opts += " -rules " + args[++argidx]; 91 continue; 92 } 93 break; 94 } 95 extra_args(args, argidx, design); 96 97 Pass::call(design, "opt_mem"); 98 Pass::call(design, "opt_mem_priority"); 99 Pass::call(design, "opt_mem_feedback"); 100 if (!flag_nordff) 101 Pass::call(design, "memory_dff"); 102 Pass::call(design, "opt_clean"); 103 Pass::call(design, "memory_share" + memory_share_opts); 104 Pass::call(design, "opt_mem_widen"); 105 if (flag_memx) 106 Pass::call(design, "memory_memx"); 107 Pass::call(design, "opt_clean"); 108 Pass::call(design, "memory_collect"); 109 110 if (!memory_bram_opts.empty()) 111 Pass::call(design, "memory_bram" + memory_bram_opts); 112 113 if (!flag_nomap) 114 Pass::call(design, "memory_map"); 115 116 log_pop(); 117 } 118 } MemoryPass; 119 120 PRIVATE_NAMESPACE_END 121