yosys/passes/cmds/test_patch.cc

43 lines
1.2 KiB
C++
Raw Permalink Normal View History

2025-12-31 17:46:27 +01:00
#include "kernel/rtlil.h"
#include "kernel/yosys.h"
#include "kernel/unstable/patch.h"
USING_YOSYS_NAMESPACE
PRIVATE_NAMESPACE_BEGIN
struct TestPatchPass : public Pass {
TestPatchPass() : Pass("test_patch", "test patcher") { }
void help() override
{
}
void execute(std::vector<std::string> args, RTLIL::Design *design) override
{
(void) args;
2026-05-19 12:36:41 +02:00
design->sigNormalize();
2025-12-31 17:46:27 +01:00
for (auto module : design->selected_modules()) {
SigMap sigmap(module);
2025-12-31 17:46:27 +01:00
for (auto cell : module->selected_cells()) {
2026-06-12 00:18:53 +02:00
if (cell->type == TW($add)) {
2026-05-19 15:57:10 +02:00
Cell* add = cell;
2026-06-10 19:22:53 +02:00
log_assert(add->getPort(TW::B).is_wire());
log_assert(add->getPort(TW::B).known_driver());
auto neg = add->getPort(TW::B)[0].wire->driverCell();
2026-06-12 00:18:53 +02:00
log_assert(neg->type == TW($not));
2026-05-28 12:56:13 +02:00
RTLIL::Patch patcher(module, nullptr);
2026-06-10 19:22:53 +02:00
int width = cell->getPort(TW::A).size();
2026-06-11 13:17:54 +02:00
auto sub = patcher.addSub(NEW_TWINE,
2026-06-10 19:22:53 +02:00
neg->getPort(TW::A),
add->getPort(TW::A),
patcher.addWire(NEW_TWINE, width));
auto new_out_wire = patcher.addWire(NEW_TWINE, width);
2026-06-11 13:17:54 +02:00
auto new_cell = patcher.addNeg(NEW_TWINE, sub->getPort(TW::Y), new_out_wire);
2026-05-19 15:57:10 +02:00
log_cell(new_cell);
2026-06-11 13:17:54 +02:00
patcher.patch(add, TW::Y, new_out_wire);
2025-12-31 17:46:27 +01:00
}
}
}
}
} TestPatchPass;
PRIVATE_NAMESPACE_END