3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-04-14 04:48:46 +00:00

Using worker class in memory_map

This commit is contained in:
Clifford Wolf 2014-08-30 17:39:08 +02:00
parent eb571cba6a
commit 66763fad4e

View file

@ -23,7 +23,12 @@
#include <set> #include <set>
#include <stdlib.h> #include <stdlib.h>
static std::string genid(RTLIL::IdString name, std::string token1 = "", int i = -1, std::string token2 = "", int j = -1, std::string token3 = "", int k = -1, std::string token4 = "") struct MemoryMapWorker
{
RTLIL::Design *design;
RTLIL::Module *module;
std::string genid(RTLIL::IdString name, std::string token1 = "", int i = -1, std::string token2 = "", int j = -1, std::string token3 = "", int k = -1, std::string token4 = "")
{ {
std::stringstream sstr; std::stringstream sstr;
sstr << "$memory" << name.str() << token1; sstr << "$memory" << name.str() << token1;
@ -45,7 +50,7 @@ static std::string genid(RTLIL::IdString name, std::string token1 = "", int i =
return sstr.str(); return sstr.str();
} }
static void handle_cell(RTLIL::Module *module, RTLIL::Cell *cell) void handle_cell(RTLIL::Cell *cell)
{ {
std::set<int> static_ports; std::set<int> static_ports;
std::map<int, RTLIL::SigSpec> static_cells_map; std::map<int, RTLIL::SigSpec> static_cells_map;
@ -291,15 +296,16 @@ static void handle_cell(RTLIL::Module *module, RTLIL::Cell *cell)
module->remove(cell); module->remove(cell);
} }
static void handle_module(RTLIL::Design *design, RTLIL::Module *module) MemoryMapWorker(RTLIL::Design *design, RTLIL::Module *module) : design(design), module(module)
{ {
std::vector<RTLIL::Cell*> cells; std::vector<RTLIL::Cell*> cells;
for (auto &it : module->cells_) for (auto cell : module->selected_cells())
if (it.second->type == "$mem" && design->selected(module, it.second)) if (cell->type == "$mem" && design->selected(module, cell))
cells.push_back(it.second); cells.push_back(cell);
for (auto cell : cells) for (auto cell : cells)
handle_cell(module, cell); handle_cell(cell);
} }
};
struct MemoryMapPass : public Pass { struct MemoryMapPass : public Pass {
MemoryMapPass() : Pass("memory_map", "translate multiport memories to basic cells") { } MemoryMapPass() : Pass("memory_map", "translate multiport memories to basic cells") { }
@ -316,9 +322,8 @@ struct MemoryMapPass : public Pass {
virtual void execute(std::vector<std::string> args, RTLIL::Design *design) { virtual void execute(std::vector<std::string> args, RTLIL::Design *design) {
log_header("Executing MEMORY_MAP pass (converting $mem cells to logic and flip-flops).\n"); log_header("Executing MEMORY_MAP pass (converting $mem cells to logic and flip-flops).\n");
extra_args(args, 1, design); extra_args(args, 1, design);
for (auto &mod_it : design->modules_) for (auto mod : design->selected_modules())
if (design->selected(mod_it.second)) MemoryMapWorker(design, mod);
handle_module(design, mod_it.second);
} }
} MemoryMapPass; } MemoryMapPass;