2 * yosys -- Yosys Open SYnthesis Suite
4 * Copyright (C) 2012 Clifford Wolf <clifford@clifford.at>
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.
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.
20 #include "kernel/yosys.h"
23 PRIVATE_NAMESPACE_BEGIN
25 struct DeletePass
: public Pass
{
26 DeletePass() : Pass("delete", "delete objects in the design") { }
29 // |---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|---v---|
31 log(" delete [selection]\n");
33 log("Deletes the selected objects. This will also remove entire modules, if the\n");
34 log("whole module is selected.\n");
37 log(" delete {-input|-output|-port} [selection]\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");
43 void execute(std::vector
<std::string
> args
, RTLIL::Design
*design
) override
45 bool flag_input
= false;
46 bool flag_output
= false;
49 for (argidx
= 1; argidx
< args
.size(); argidx
++)
51 if (args
[argidx
] == "-input") {
55 if (args
[argidx
] == "-output") {
59 if (args
[argidx
] == "-port") {
66 extra_args(args
, argidx
, design
);
68 std::vector
<RTLIL::Module
*> delete_mods
;
69 for (auto module
: design
->modules())
71 if (design
->selected_whole_module(module
->name
) && !flag_input
&& !flag_output
) {
72 delete_mods
.push_back(module
);
76 if (!design
->selected_module(module
->name
))
79 if (flag_input
|| flag_output
) {
80 for (auto wire
: module
->wires())
81 if (design
->selected(module
, wire
)) {
83 wire
->port_input
= false;
85 wire
->port_output
= false;
87 module
->fixup_ports();
91 pool
<RTLIL::Wire
*> delete_wires
;
92 pool
<RTLIL::Cell
*> delete_cells
;
93 pool
<RTLIL::IdString
> delete_procs
;
94 pool
<RTLIL::IdString
> delete_mems
;
96 for (auto wire
: module
->selected_wires())
97 delete_wires
.insert(wire
);
99 for (auto &it
: module
->memories
)
100 if (design
->selected(module
, it
.second
))
101 delete_mems
.insert(it
.first
);
103 for (auto cell
: module
->cells()) {
104 if (design
->selected(module
, cell
))
105 delete_cells
.insert(cell
);
106 if (cell
->type
.in(ID($memrd
), ID($memwr
)) &&
107 delete_mems
.count(cell
->parameters
.at(ID::MEMID
).decode_string()) != 0)
108 delete_cells
.insert(cell
);
111 for (auto &it
: module
->processes
)
112 if (design
->selected(module
, it
.second
))
113 delete_procs
.insert(it
.first
);
115 for (auto &it
: delete_mems
) {
116 delete module
->memories
.at(it
);
117 module
->memories
.erase(it
);
120 for (auto &it
: delete_cells
)
123 for (auto &it
: delete_procs
) {
124 delete module
->processes
.at(it
);
125 module
->processes
.erase(it
);
128 module
->remove(delete_wires
);
130 module
->fixup_ports();
133 for (auto mod
: delete_mods
) {
139 PRIVATE_NAMESPACE_END