31 if (a->
type ==
"$memrd" && b->
type ==
"$memrd")
33 if (a->
type ==
"$memrd" || b->
type ==
"$memrd")
34 return (a->
type ==
"$memrd") < (b->
type ==
"$memrd");
40 log(
"Collecting $memrd and $memwr for memory `%s' in module `%s':\n",
44 while ((1 << addr_bits) < memory->
size)
63 std::vector<RTLIL::Cell*> del_cells;
64 std::vector<RTLIL::Cell*> memcells;
66 for (
auto &cell_it : module->
cells_) {
68 if ((cell->
type ==
"$memwr" || cell->
type ==
"$memrd") && memory->
name == cell->
parameters[
"\\MEMID"].decode_string())
69 memcells.push_back(cell);
74 for (
auto cell : memcells)
76 if (cell->type ==
"$memwr" && memory->
name == cell->parameters[
"\\MEMID"].decode_string())
79 del_cells.push_back(cell);
89 clk_enable.
extend(1,
false);
90 clk_polarity.
extend(1,
false);
91 addr.
extend(addr_bits,
false);
96 sig_wr_clk_enable.
append(clk_enable);
97 sig_wr_clk_polarity.
append(clk_polarity);
103 if (cell->type ==
"$memrd" && memory->
name == cell->parameters[
"\\MEMID"].decode_string())
106 del_cells.push_back(cell);
116 clk_enable.
extend(1,
false);
117 clk_polarity.
extend(1,
false);
118 transparent.
extend(1,
false);
119 addr.
extend(addr_bits,
false);
123 sig_rd_clk_enable.
append(clk_enable);
124 sig_rd_clk_polarity.
append(clk_polarity);
125 sig_rd_transparent.
append(transparent);
131 std::stringstream sstr;
152 mem->
setPort(
"\\WR_CLK", sig_wr_clk);
153 mem->
setPort(
"\\WR_ADDR", sig_wr_addr);
154 mem->
setPort(
"\\WR_DATA", sig_wr_data);
155 mem->
setPort(
"\\WR_EN", sig_wr_en);
168 mem->
setPort(
"\\RD_CLK", sig_rd_clk);
169 mem->
setPort(
"\\RD_ADDR", sig_rd_addr);
170 mem->
setPort(
"\\RD_DATA", sig_rd_data);
172 for (
auto c : del_cells)
178 std::vector<RTLIL::IdString> delme;
179 for (
auto &mem_it : module->
memories)
180 if (design->
selected(module, mem_it.second)) {
182 delme.push_back(mem_it.first);
184 for (
auto &it : delme) {
196 log(
" memory_collect [selection]\n");
198 log(
"This pass collects memories and memory ports and creates generic multiport\n");
199 log(
"memory cells.\n");
203 log_header(
"Executing MEMORY_COLLECT pass (generating $mem cells).\n");
205 for (
auto &mod_it : design->
modules_)
206 if (design->
selected(mod_it.second))
const char * c_str() const
bool selected(T1 *module) const
void sort(T *array, int size, LessThan lt)
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
void log_header(const char *format,...)
RTLIL::Const as_const() const
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
std::map< RTLIL::IdString, RTLIL::Memory * > memories
std::map< RTLIL::IdString, RTLIL::Const > parameters
#define PRIVATE_NAMESPACE_BEGIN
void handle_memory(RTLIL::Module *module, RTLIL::Memory *memory)
MemoryCollectPass MemoryCollectPass
#define log_assert(_assert_expr_)
bool is_fully_const() const
#define PRIVATE_NAMESPACE_END
USING_YOSYS_NAMESPACE PRIVATE_NAMESPACE_BEGIN bool memcells_cmp(RTLIL::Cell *a, RTLIL::Cell *b)
#define USING_YOSYS_NAMESPACE
std::map< RTLIL::IdString, RTLIL::Module * > modules_
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
void remove(const std::set< RTLIL::Wire * > &wires)
void log(const char *format,...)
void append(const RTLIL::SigSpec &signal)
void extend(int width, bool is_signed=false)
static void handle_module(RTLIL::Design *design, RTLIL::Module *module)
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
YOSYS_NAMESPACE_BEGIN int autoidx
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)