yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
SubmodWorker Struct Reference
+ Collaboration diagram for SubmodWorker:

Data Structures

struct  SubModule
 
struct  wire_flags_t
 

Public Member Functions

void flag_wire (RTLIL::Wire *wire, bool create, bool set_int_driven, bool set_int_used, bool set_ext_driven, bool set_ext_used)
 
void flag_signal (const RTLIL::SigSpec &sig, bool create, bool set_int_driven, bool set_int_used, bool set_ext_driven, bool set_ext_used)
 
void handle_submodule (SubModule &submod)
 
 SubmodWorker (RTLIL::Design *design, RTLIL::Module *module, std::string opt_name=std::string())
 

Data Fields

CellTypes ct
 
RTLIL::Designdesign
 
RTLIL::Modulemodule
 
std::string opt_name
 
std::map< std::string, SubModulesubmodules
 
std::map< RTLIL::Wire
*, wire_flags_t
wire_flags
 
bool flag_found_something
 

Detailed Description

Definition at line 30 of file submod.cc.

Constructor & Destructor Documentation

SubmodWorker::SubmodWorker ( RTLIL::Design design,
RTLIL::Module module,
std::string  opt_name = std::string() 
)
inline

Definition at line 194 of file submod.cc.

194  : design(design), module(module), opt_name(opt_name)
195  {
196  if (!design->selected_whole_module(module->name) && opt_name.empty())
197  return;
198 
199  if (module->processes.size() > 0) {
200  log("Skipping module %s as it contains processes (run 'proc' pass first).\n", module->name.c_str());
201  return;
202  }
203 
204  if (module->memories.size() > 0) {
205  log("Skipping module %s as it contains memories (run 'memory' pass first).\n", module->name.c_str());
206  return;
207  }
208 
211  ct.setup_stdcells();
213  ct.setup_design(design);
214 
215  if (opt_name.empty())
216  {
217  for (auto &it : module->wires_)
218  it.second->attributes.erase("\\submod");
219 
220  for (auto &it : module->cells_)
221  {
222  RTLIL::Cell *cell = it.second;
223  if (cell->attributes.count("\\submod") == 0 || cell->attributes["\\submod"].bits.size() == 0) {
224  cell->attributes.erase("\\submod");
225  continue;
226  }
227 
228  std::string submod_str = cell->attributes["\\submod"].decode_string();
229  cell->attributes.erase("\\submod");
230 
231  if (submodules.count(submod_str) == 0) {
232  submodules[submod_str].name = submod_str;
233  submodules[submod_str].full_name = module->name.str() + "_" + submod_str;
234  while (design->modules_.count(submodules[submod_str].full_name) != 0 ||
235  module->count_id(submodules[submod_str].full_name) != 0)
236  submodules[submod_str].full_name += "_";
237  }
238 
239  submodules[submod_str].cells.insert(cell);
240  }
241  }
242  else
243  {
244  for (auto &it : module->cells_)
245  {
246  RTLIL::Cell *cell = it.second;
247  if (!design->selected(module, cell))
248  continue;
249  submodules[opt_name].name = opt_name;
251  submodules[opt_name].cells.insert(cell);
252  }
253 
254  if (submodules.size() == 0)
255  log("Nothing selected -> do nothing.\n");
256  }
257 
258  for (auto &it : submodules)
259  handle_submodule(it.second);
260  }
const char * c_str() const
Definition: rtlil.h:178
bool selected(T1 *module) const
Definition: rtlil.h:551
std::string str() const
Definition: rtlil.h:182
void setup_stdcells()
Definition: celltypes.h:132
RTLIL::Module * module
Definition: submod.cc:34
void setup_internals_mem()
Definition: celltypes.h:115
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
std::map< RTLIL::IdString, RTLIL::Memory * > memories
Definition: rtlil.h:601
void handle_submodule(SubModule &submod)
Definition: submod.cc:78
static std::string escape_id(std::string str)
Definition: rtlil.h:251
RTLIL::IdString name
Definition: rtlil.h:599
bool selected_whole_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:388
std::map< RTLIL::IdString, RTLIL::Process * > processes
Definition: rtlil.h:602
virtual size_t count_id(RTLIL::IdString id)
Definition: rtlil.cc:472
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
std::map< std::string, SubModule > submodules
Definition: submod.cc:43
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596
void log(const char *format,...)
Definition: log.cc:180
void setup_internals()
Definition: celltypes.h:83
std::string opt_name
Definition: submod.cc:35
void setup_design(RTLIL::Design *design)
Definition: celltypes.h:77
void setup_stdcells_mem()
Definition: celltypes.h:149
RTLIL::Design * design
Definition: submod.cc:33
CellTypes ct
Definition: submod.cc:32

+ Here is the call graph for this function:

Member Function Documentation

void SubmodWorker::flag_signal ( const RTLIL::SigSpec sig,
bool  create,
bool  set_int_driven,
bool  set_int_used,
bool  set_ext_driven,
bool  set_ext_used 
)
inline

Definition at line 71 of file submod.cc.

72  {
73  for (auto &c : sig.chunks())
74  if (c.wire != NULL)
75  flag_wire(c.wire, create, set_int_driven, set_int_used, set_ext_driven, set_ext_used);
76  }
void flag_wire(RTLIL::Wire *wire, bool create, bool set_int_driven, bool set_int_used, bool set_ext_driven, bool set_ext_used)
Definition: submod.cc:53
#define NULL
const std::vector< RTLIL::SigChunk > & chunks() const
Definition: rtlil.h:1016

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void SubmodWorker::flag_wire ( RTLIL::Wire wire,
bool  create,
bool  set_int_driven,
bool  set_int_used,
bool  set_ext_driven,
bool  set_ext_used 
)
inline

Definition at line 53 of file submod.cc.

54  {
55  if (wire_flags.count(wire) == 0) {
56  if (!create)
57  return;
58  wire_flags[wire] = wire_flags_t();
59  }
60  if (set_int_driven)
61  wire_flags[wire].is_int_driven = true;
62  if (set_int_used)
63  wire_flags[wire].is_int_used = true;
64  if (set_ext_driven)
65  wire_flags[wire].is_ext_driven = true;
66  if (set_ext_used)
67  wire_flags[wire].is_ext_used = true;
68  flag_found_something = true;
69  }
std::map< RTLIL::Wire *, wire_flags_t > wire_flags
Definition: submod.cc:50
bool flag_found_something
Definition: submod.cc:51

+ Here is the caller graph for this function:

void SubmodWorker::handle_submodule ( SubModule submod)
inline

Definition at line 78 of file submod.cc.

79  {
80  log("Creating submodule %s (%s) of module %s.\n", submod.name.c_str(), submod.full_name.c_str(), module->name.c_str());
81 
82  wire_flags.clear();
83  for (RTLIL::Cell *cell : submod.cells) {
84  if (ct.cell_known(cell->type)) {
85  for (auto &conn : cell->connections())
86  flag_signal(conn.second, true, ct.cell_output(cell->type, conn.first), ct.cell_input(cell->type, conn.first), false, false);
87  } else {
88  log_warning("Port directions for cell %s (%s) are unknown. Assuming inout for all ports.\n", cell->name.c_str(), cell->type.c_str());
89  for (auto &conn : cell->connections())
90  flag_signal(conn.second, true, true, true, false, false);
91  }
92  }
93  for (auto &it : module->cells_) {
94  RTLIL::Cell *cell = it.second;
95  if (submod.cells.count(cell) > 0)
96  continue;
97  if (ct.cell_known(cell->type)) {
98  for (auto &conn : cell->connections())
99  flag_signal(conn.second, false, false, false, ct.cell_output(cell->type, conn.first), ct.cell_input(cell->type, conn.first));
100  } else {
101  flag_found_something = false;
102  for (auto &conn : cell->connections())
103  flag_signal(conn.second, false, false, false, true, true);
105  log_warning("Port directions for cell %s (%s) are unknown. Assuming inout for all ports.\n", cell->name.c_str(), cell->type.c_str());
106  }
107  }
108 
109  RTLIL::Module *new_mod = new RTLIL::Module;
110  new_mod->name = submod.full_name;
111  design->add(new_mod);
112  int auto_name_counter = 1;
113 
114  std::set<RTLIL::IdString> all_wire_names;
115  for (auto &it : wire_flags) {
116  all_wire_names.insert(it.first->name);
117  }
118 
119  for (auto &it : wire_flags)
120  {
121  RTLIL::Wire *wire = it.first;
122  wire_flags_t &flags = it.second;
123 
124  if (wire->port_input)
125  flags.is_ext_driven = true;
126  if (wire->port_output)
127  flags.is_ext_used = true;
128 
129  bool new_wire_port_input = false;
130  bool new_wire_port_output = false;
131 
132  if (flags.is_int_driven && flags.is_ext_used)
133  new_wire_port_output = true;
134  if (flags.is_ext_driven && flags.is_int_used)
135  new_wire_port_input = true;
136 
137  if (flags.is_int_driven && flags.is_ext_driven)
138  new_wire_port_input = true, new_wire_port_output = true;
139 
140  std::string new_wire_name = wire->name.str();
141  if (new_wire_port_input || new_wire_port_output) {
142  while (new_wire_name[0] == '$') {
143  std::string next_wire_name = stringf("\\n%d", auto_name_counter++);
144  if (all_wire_names.count(next_wire_name) == 0) {
145  all_wire_names.insert(next_wire_name);
146  new_wire_name = next_wire_name;
147  }
148  }
149  }
150 
151  RTLIL::Wire *new_wire = new_mod->addWire(new_wire_name, wire->width);
152  new_wire->port_input = new_wire_port_input;
153  new_wire->port_output = new_wire_port_output;
154  new_wire->start_offset = wire->start_offset;
155  new_wire->attributes = wire->attributes;
156 
157  if (new_wire->port_input && new_wire->port_output)
158  log(" signal %s: inout %s\n", wire->name.c_str(), new_wire->name.c_str());
159  else if (new_wire->port_input)
160  log(" signal %s: input %s\n", wire->name.c_str(), new_wire->name.c_str());
161  else if (new_wire->port_output)
162  log(" signal %s: output %s\n", wire->name.c_str(), new_wire->name.c_str());
163  else
164  log(" signal %s: internal\n", wire->name.c_str());
165 
166  flags.new_wire = new_wire;
167  }
168 
169  new_mod->fixup_ports();
170 
171  for (RTLIL::Cell *cell : submod.cells) {
172  RTLIL::Cell *new_cell = new_mod->addCell(cell->name, cell);
173  for (auto &conn : new_cell->connections_)
174  for (auto &bit : conn.second)
175  if (bit.wire != NULL) {
176  log_assert(wire_flags.count(bit.wire) > 0);
177  bit.wire = wire_flags[bit.wire].new_wire;
178  }
179  log(" cell %s (%s)\n", new_cell->name.c_str(), new_cell->type.c_str());
180  module->remove(cell);
181  }
182  submod.cells.clear();
183 
184  RTLIL::Cell *new_cell = module->addCell(submod.full_name, submod.full_name);
185  for (auto &it : wire_flags)
186  {
187  RTLIL::Wire *old_wire = it.first;
188  RTLIL::Wire *new_wire = it.second.new_wire;
189  if (new_wire->port_id > 0)
190  new_cell->setPort(new_wire->name, RTLIL::SigSpec(old_wire));
191  }
192  }
const char * c_str() const
Definition: rtlil.h:178
std::string str() const
Definition: rtlil.h:182
std::string stringf(const char *fmt,...)
Definition: yosys.cc:58
int auto_name_counter
void log_warning(const char *format,...)
Definition: log.cc:196
RTLIL::Module * module
Definition: submod.cc:34
RTLIL::Cell * addCell(RTLIL::IdString name, RTLIL::IdString type)
Definition: rtlil.cc:1353
void add(RTLIL::Module *module)
Definition: rtlil.cc:259
std::map< RTLIL::Wire *, wire_flags_t > wire_flags
Definition: submod.cc:50
RTLIL::IdString name
Definition: rtlil.h:853
void setPort(RTLIL::IdString portname, RTLIL::SigSpec signal)
Definition: rtlil.cc:1789
bool port_input
Definition: rtlil.h:827
int width
Definition: rtlil.h:826
int port_id
Definition: rtlil.h:826
RTLIL::IdString type
Definition: rtlil.h:854
bool port_output
Definition: rtlil.h:827
bool cell_known(RTLIL::IdString type)
Definition: celltypes.h:188
bool cell_output(RTLIL::IdString type, RTLIL::IdString port)
Definition: celltypes.h:193
void fixup_ports()
Definition: rtlil.cc:1312
#define log_assert(_assert_expr_)
Definition: log.h:85
RTLIL::Wire * addWire(RTLIL::IdString name, int width=1)
Definition: rtlil.cc:1331
RTLIL::IdString name
Definition: rtlil.h:599
bool flag_found_something
Definition: submod.cc:51
RTLIL::IdString name
Definition: rtlil.h:825
#define NULL
std::map< RTLIL::IdString, RTLIL::Cell * > cells_
Definition: rtlil.h:596
void remove(const std::set< RTLIL::Wire * > &wires)
Definition: rtlil.cc:1158
void log(const char *format,...)
Definition: log.cc:180
int start_offset
Definition: rtlil.h:826
bool cell_input(RTLIL::IdString type, RTLIL::IdString port)
Definition: celltypes.h:199
std::map< RTLIL::IdString, RTLIL::SigSpec > connections_
Definition: rtlil.h:855
RTLIL::Design * design
Definition: submod.cc:33
CellTypes ct
Definition: submod.cc:32
void flag_signal(const RTLIL::SigSpec &sig, bool create, bool set_int_driven, bool set_int_used, bool set_ext_driven, bool set_ext_used)
Definition: submod.cc:71
const std::map< RTLIL::IdString, RTLIL::SigSpec > & connections() const
Definition: rtlil.cc:1814

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

CellTypes SubmodWorker::ct

Definition at line 32 of file submod.cc.

RTLIL::Design* SubmodWorker::design

Definition at line 33 of file submod.cc.

bool SubmodWorker::flag_found_something

Definition at line 51 of file submod.cc.

RTLIL::Module* SubmodWorker::module

Definition at line 34 of file submod.cc.

std::string SubmodWorker::opt_name

Definition at line 35 of file submod.cc.

std::map<std::string, SubModule> SubmodWorker::submodules

Definition at line 43 of file submod.cc.

std::map<RTLIL::Wire*, wire_flags_t> SubmodWorker::wire_flags

Definition at line 50 of file submod.cc.


The documentation for this struct was generated from the following file: