yosys-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
delete.cc
Go to the documentation of this file.
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/yosys.h"
21 
24 
25 struct DeletePass : public Pass {
26  DeletePass() : Pass("delete", "delete objects in the design") { }
27  virtual void help()
28  {
29  // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
30  log("\n");
31  log(" delete [selection]\n");
32  log("\n");
33  log("Deletes the selected objects. This will also remove entire modules, if the\n");
34  log("whole module is selected.\n");
35  log("\n");
36  log("\n");
37  log(" delete {-input|-output|-port} [selection]\n");
38  log("\n");
39  log("Does not delete any object but removes the input and/or output flag on the\n");
40  log("selected wires, thus 'deleting' module ports.\n");
41  log("\n");
42  }
43  virtual void execute(std::vector<std::string> args, RTLIL::Design *design)
44  {
45  bool flag_input = false;
46  bool flag_output = false;
47 
48  size_t argidx;
49  for (argidx = 1; argidx < args.size(); argidx++)
50  {
51  if (args[argidx] == "-input") {
52  flag_input = true;
53  continue;
54  }
55  if (args[argidx] == "-output") {
56  flag_output = true;
57  continue;
58  }
59  if (args[argidx] == "-port") {
60  flag_input = true;
61  flag_output = true;
62  continue;
63  }
64  break;
65  }
66  extra_args(args, argidx, design);
67 
68  std::vector<RTLIL::IdString> delete_mods;
69 
70  for (auto &mod_it : design->modules_)
71  {
72  if (design->selected_whole_module(mod_it.first) && !flag_input && !flag_output) {
73  delete_mods.push_back(mod_it.first);
74  continue;
75  }
76 
77  if (!design->selected_module(mod_it.first))
78  continue;
79 
80  RTLIL::Module *module = mod_it.second;
81 
82  if (flag_input || flag_output) {
83  for (auto &it : module->wires_)
84  if (design->selected(module, it.second)) {
85  if (flag_input)
86  it.second->port_input = false;
87  if (flag_output)
88  it.second->port_output = false;
89  }
90  module->fixup_ports();
91  continue;
92  }
93 
94  std::set<RTLIL::Wire*> delete_wires;
95  std::set<RTLIL::Cell*> delete_cells;
96  std::set<RTLIL::IdString> delete_procs;
97  std::set<RTLIL::IdString> delete_mems;
98 
99  for (auto &it : module->wires_)
100  if (design->selected(module, it.second))
101  delete_wires.insert(it.second);
102 
103  for (auto &it : module->memories)
104  if (design->selected(module, it.second))
105  delete_mems.insert(it.first);
106 
107  for (auto &it : module->cells_) {
108  if (design->selected(module, it.second))
109  delete_cells.insert(it.second);
110  if ((it.second->type == "$memrd" || it.second->type == "$memwr") &&
111  delete_mems.count(it.second->parameters.at("\\MEMID").decode_string()) != 0)
112  delete_cells.insert(it.second);
113  }
114 
115  for (auto &it : module->processes)
116  if (design->selected(module, it.second))
117  delete_procs.insert(it.first);
118 
119  for (auto &it : delete_mems) {
120  delete module->memories.at(it);
121  module->memories.erase(it);
122  }
123 
124  for (auto &it : delete_cells)
125  module->remove(it);
126 
127  for (auto &it : delete_procs) {
128  delete module->processes.at(it);
129  module->processes.erase(it);
130  }
131 
132  module->remove(delete_wires);
133 
134  module->fixup_ports();
135  }
136 
137  for (auto &it : delete_mods) {
138  delete design->modules_.at(it);
139  design->modules_.erase(it);
140  }
141  }
142 } DeletePass;
143 
bool selected(T1 *module) const
Definition: rtlil.h:551
bool selected_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:379
std::map< RTLIL::IdString, RTLIL::Wire * > wires_
Definition: rtlil.h:595
std::map< RTLIL::IdString, RTLIL::Memory * > memories
Definition: rtlil.h:601
RTLIL::Module * module
Definition: abc.cc:94
virtual void help()
Definition: delete.cc:27
#define PRIVATE_NAMESPACE_BEGIN
Definition: yosys.h:97
DeletePass()
Definition: delete.cc:26
void fixup_ports()
Definition: rtlil.cc:1312
bool selected_whole_module(RTLIL::IdString mod_name) const
Definition: rtlil.cc:388
#define PRIVATE_NAMESPACE_END
Definition: yosys.h:98
Definition: register.h:27
std::map< RTLIL::IdString, RTLIL::Process * > processes
Definition: rtlil.h:602
#define USING_YOSYS_NAMESPACE
Definition: yosys.h:102
std::map< RTLIL::IdString, RTLIL::Module * > modules_
Definition: rtlil.h:507
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
virtual void execute(std::vector< std::string > args, RTLIL::Design *design)
Definition: delete.cc:43
void extra_args(std::vector< std::string > args, size_t argidx, RTLIL::Design *design, bool select=true)
Definition: register.cc:128
DeletePass DeletePass