summaryrefslogtreecommitdiff
path: root/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'kernel')
-rw-r--r--kernel/rtlil.cc40
-rw-r--r--kernel/rtlil.h3
2 files changed, 43 insertions, 0 deletions
diff --git a/kernel/rtlil.cc b/kernel/rtlil.cc
index 059357d2..930e8a71 100644
--- a/kernel/rtlil.cc
+++ b/kernel/rtlil.cc
@@ -827,6 +827,46 @@ void RTLIL::Module::add(RTLIL::Cell *cell)
cells[cell->name] = cell;
}
+namespace {
+ struct DeleteWireWorker
+ {
+ RTLIL::Module *module;
+ const std::set<RTLIL::Wire*> *wires_p;
+
+ void operator()(RTLIL::SigSpec &sig) {
+ std::vector<RTLIL::SigChunk> chunks = sig;
+ for (auto &c : chunks)
+ if (c.wire != NULL && wires_p->count(c.wire)) {
+ c.wire = module->addWire(NEW_ID, c.width);
+ c.offset = 0;
+ }
+ sig = chunks;
+ }
+ };
+}
+
+#if 0
+void RTLIL::Module::remove(RTLIL::Wire *wire)
+{
+ std::set<RTLIL::Wire*> wires;
+ wires.insert(wire);
+ remove(wires);
+}
+#endif
+
+void RTLIL::Module::remove(const std::set<RTLIL::Wire*> &wires)
+{
+ DeleteWireWorker delete_wire_worker;
+ delete_wire_worker.module = this;
+ delete_wire_worker.wires_p = &wires;
+ rewrite_sigspecs(delete_wire_worker);
+
+ for (auto &it : wires) {
+ this->wires.erase(it->name);
+ delete it;
+ }
+}
+
void RTLIL::Module::remove(RTLIL::Cell *cell)
{
assert(cells.count(cell->name) != 0);
diff --git a/kernel/rtlil.h b/kernel/rtlil.h
index 73d3727c..f43e7b67 100644
--- a/kernel/rtlil.h
+++ b/kernel/rtlil.h
@@ -299,6 +299,9 @@ struct RTLIL::Module
void add(RTLIL::Wire *wire);
void add(RTLIL::Cell *cell);
+
+ // Removing wires is expensive. If you have to remove wires, remove them all at once.
+ void remove(const std::set<RTLIL::Wire*> &wires);
void remove(RTLIL::Cell *cell);
void rename(RTLIL::Wire *wire, RTLIL::IdString new_name);