3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2026-05-25 19:36:21 +00:00

patch: signorm, move

This commit is contained in:
Emil J. Tywoniak 2026-05-19 12:36:41 +02:00
parent b7ea32dbee
commit d2ae9b48e4
3 changed files with 51 additions and 22 deletions

View file

@ -1,5 +1,6 @@
#include "kernel/unstable/patch.h"
#include "kernel/celltypes.h"
#include "kernel/log.h"
#include "kernel/rtlil.h"
YOSYS_NAMESPACE_BEGIN
@ -17,10 +18,10 @@ using namespace RTLIL;
template class CellAdderMixin<Patch>;
Cell* Patch::addCell(IdString name, IdString type) {
cells_.emplace(cells_.end(), std::make_unique<Cell>(Cell::ConstructToken{}));
cells_.push_back(std::make_unique<Cell>(Cell::ConstructToken{}));
Cell* cell = cells_.back().get();
cell->name = std::move(name);
cell->name = name;
cell->type = type;
return cell;
}
@ -32,25 +33,52 @@ Wire* Patch::addWire(IdString name, int width) {
return nullptr;
}
void Patch::patch() {
void Patch::patch(Cell* old_cell, Cell* new_cell) {
pool<Cell*> patch_cells;
for (auto& cell: cells_) {
Cell* new_cell = mod->addCell(cell->name, cell->type);
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
patch_cells.insert(cell.get());
}
log("patching:\n");
log_cell(old_cell);
for (auto& cell: cells_) {
log("with:\n");
log_cell(cell.get());
log("ptr %p\n", cell.get());
Cell* raw = cell.release();
log("ptr2 %p\n", raw);
mod->cells_[raw->name] = raw;
raw->module = mod;
for (auto [port_name, sig] : raw->connections()) {
auto dir = raw->port_dir(port_name);
log_assert(dir != PD_UNKNOWN);
if (raw == new_cell)
if (dir == PD_OUTPUT || dir == PD_INOUT) {
// RAUW
old_cell->setPort(port_name, mod->addWire(NEW_ID, sig.size()));
new_cell->setPort(port_name, sig);
auto* wire = sig.as_wire();
wire->driverCell_ = new_cell;
wire->driverPort_ = port_name;
}
}
// } else {
// new_cell->setPort(port_name, sig); // map?
// for (auto chunk : map(sig).chunks()) {
// if (chunk.size() == 0)
// continue;
// log_assert(chunk.is_wire());
// auto* wire = chunk.wire;
// // TODO Use roots instead?
// if (patch_cells.count(wire->driverCell_)) {
// // How do we handle this?
// log_assert(false);
// } else {
// // mod->sig_norm_index
// }
// }
}
}
log_module(mod, "");
}

View file

@ -29,7 +29,7 @@ public:
void connect(const RTLIL::SigSpec &lhs, const RTLIL::SigSpec &rhs);
const std::vector<RTLIL::SigSig> &connections() const;
void patch();
void patch(Cell* old_cell, Cell* new_cell);
RTLIL::Wire *addWire(RTLIL::IdString name, int width = 1);
RTLIL::Wire *addWire(RTLIL::IdString name, const RTLIL::Wire *other);