yosys/kernel/unstable/patch.cc

55 lines
1.2 KiB
C++
Raw Normal View History

2025-12-19 19:14:33 +01:00
#include "kernel/unstable/patch.h"
2025-12-31 17:46:27 +01:00
#include "kernel/celltypes.h"
#include "kernel/rtlil.h"
2025-12-19 19:14:33 +01:00
YOSYS_NAMESPACE_BEGIN
2025-12-31 17:59:24 +01:00
/**
* Notes
*
* If we want GC, we need more indices
* namely user count (and users?). This should be optional
*
*
2025-12-31 17:59:24 +01:00
*/
2025-12-19 19:14:33 +01:00
using namespace RTLIL;
template class CellAdderMixin<Patch>;
2025-12-19 19:14:33 +01:00
Cell* Patch::addCell(IdString name, IdString type) {
auto& cell = cells_.emplace_back(Cell::ConstructToken{});
2025-12-19 19:14:33 +01:00
cell.name = std::move(name);
cell.type = type;
return &cell;
}
Wire* Patch::addWire(IdString name, int width) {
(void)name;
(void)width;
log_assert(false);
return nullptr;
2025-12-19 19:14:33 +01:00
}
2025-12-31 17:46:27 +01:00
void Patch::patch() {
for (auto& cell: cells_) {
Cell* new_cell = mod->addCell(cell.name, &cell);
for (auto [port_name, sig] : new_cell->connections()) {
log_assert(yosys_celltypes.cell_known(cell.type));
auto dir = cell.port_dir(port_name);
if (dir == PD_OUTPUT || dir == PD_INOUT) {
for (auto chunk : sig.chunks()) {
log_assert(chunk.is_wire());
auto* wire = chunk.wire;
// Unwire old driver
wire->driverCell_->setPort(wire->driverPort_, SigSpec());
// Maintain bufnorm
wire->driverCell_ = new_cell;
wire->driverPort_ = port_name;
}
}
}
}
2025-12-31 17:46:27 +01:00
}
2025-12-19 19:14:33 +01:00
YOSYS_NAMESPACE_END