From 6f0be1b4e9f636809f761c03289021313cf85e4a Mon Sep 17 00:00:00 2001 From: "Emil J. Tywoniak" Date: Tue, 23 Dec 2025 16:58:16 +0100 Subject: [PATCH] rtlil: allow friends to use Wire constructors with a factory token pattern --- kernel/rtlil.h | 16 +++++++++------- kernel/unstable/patch.cc | 10 ++-------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/kernel/rtlil.h b/kernel/rtlil.h index 6c22efcd5..d21e0cd56 100644 --- a/kernel/rtlil.h +++ b/kernel/rtlil.h @@ -2454,18 +2454,20 @@ void dump_wire(std::ostream &f, std::string indent, const RTLIL::Wire *wire); struct RTLIL::Wire : public RTLIL::NamedObject { +private: + struct ConstructToken { explicit ConstructToken() = default; }; + friend struct RTLIL::Design; + friend struct RTLIL::Cell; + friend struct RTLIL::Module; + friend struct RTLIL::Patch; +public: Hasher::hash_t hashidx_; [[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; } - -protected: // use module->addWire() and module->remove() to create or destroy wires - friend struct RTLIL::Module; friend struct RTLIL::SigNormIndex; Wire(); ~Wire(); - friend struct RTLIL::Design; - friend struct RTLIL::Cell; friend void RTLIL_BACKEND::dump_wire(std::ostream &f, std::string indent, const RTLIL::Wire *wire); RTLIL::Cell *driverCell_ = nullptr; RTLIL::IdString driverPort_; @@ -2527,13 +2529,13 @@ struct RTLIL::Cell : public RTLIL::NamedObject { private: struct ConstructToken { explicit ConstructToken() = default; }; + friend struct RTLIL::Module; + friend struct RTLIL::Patch; public: Hasher::hash_t hashidx_; [[nodiscard]] Hasher hash_into(Hasher h) const { h.eat(hashidx_); return h; } // use module->addCell() and module->remove() to create or destroy cells - friend struct RTLIL::Module; - friend struct RTLIL::Patch; Cell(ConstructToken); ~Cell(); diff --git a/kernel/unstable/patch.cc b/kernel/unstable/patch.cc index 53632114d..8f01daaee 100644 --- a/kernel/unstable/patch.cc +++ b/kernel/unstable/patch.cc @@ -9,13 +9,7 @@ Cell* Patch::addCell(IdString name, IdString type) { cell.type = type; return &cell; } -// RTLIL::Cell *RTLIL::Module::addCell(RTLIL::IdString name, RTLIL::IdString type) -// { -// RTLIL::Cell *cell = new RTLIL::Cell; -// cell->name = std::move(name); -// cell->type = type; -// add(cell); -// return cell; -// } + + YOSYS_NAMESPACE_END \ No newline at end of file