From e56cdaeaab0adde8ac61801f0f5b006364c4d101 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 22 Sep 2023 22:59:43 +0200 Subject: [PATCH] WIP --- src/db/db/dbCircuit.cc | 28 +++++++++++++++++----------- src/db/db/dbNet.h | 18 ++++++++++++++++++ src/db/db/dbNetlistCompareUtils.cc | 4 ++-- src/db/db/dbSubCircuit.cc | 10 +++++++++- src/db/db/dbSubCircuit.h | 2 +- 5 files changed, 47 insertions(+), 15 deletions(-) diff --git a/src/db/db/dbCircuit.cc b/src/db/db/dbCircuit.cc index 9941d3d51..ebf520118 100644 --- a/src/db/db/dbCircuit.cc +++ b/src/db/db/dbCircuit.cc @@ -682,30 +682,36 @@ void Circuit::connect_pin (size_t pin_id, Net *net) void Circuit::join_pins (size_t pin, size_t with) { - if (with < m_pin_by_id.size () && ! tl::is_null_iterator (m_pin_by_id [with])) { + if (with != pin && with < m_pin_by_id.size () && ! tl::is_null_iterator (m_pin_by_id [with])) { m_pins.erase (m_pin_by_id [with]); m_pin_by_id.erase (m_pin_by_id.begin () + with); m_pin_refs.erase (m_pin_refs.begin () + with); + // correct the pin IDs inside the circuit: all IDS > with will be reduced by 1 + if (pin > with) { + --pin; + } + for (auto p = m_pins.begin (); p != m_pins.end (); ++p) { + if (p->id () > with) { + p->set_id (p->id () - 1); + } + } + for (auto p = m_pin_refs.begin () + with; p != m_pin_refs.end (); ++p) { + (*p)->set_pin_id ((*p)->pin_id () - 1); + } + // join nets in calls for (auto s = begin_refs (); s != end_refs (); ++s) { db::SubCircuit &sc = *s; - db::Net *with_net = sc.net_for_pin (with); - // remove the subcircuit pin reference from the "with" net - for (auto sc_pin = with_net->begin_subcircuit_pins (); sc_pin != with_net->end_subcircuit_pins (); ++sc_pin) { - if (sc_pin->subcircuit () == &sc && sc_pin->pin_id () == with) { - with_net->erase_subcircuit_pin (sc_pin); - break; - } - } + + // NOTE: this will also correct the Pin IDs on the attached nets + sc.erase_pin (with); sc.circuit ()->join_nets (sc.net_for_pin (pin), with_net); - sc.erase_pin_ref (with); - } } diff --git a/src/db/db/dbNet.h b/src/db/db/dbNet.h index 99d3be607..d76e2b676 100644 --- a/src/db/db/dbNet.h +++ b/src/db/db/dbNet.h @@ -235,6 +235,7 @@ public: private: friend class Net; + friend class Circuit; size_t m_pin_id; Net *mp_net; @@ -246,6 +247,14 @@ private: { mp_net = net; } + + /** + * @brief Sets the pin ID + */ + void set_pin_id (size_t id) + { + m_pin_id = id; + } }; /** @@ -343,6 +352,7 @@ public: private: friend class Net; + friend class SubCircuit; size_t m_pin_id; SubCircuit *mp_subcircuit; @@ -355,6 +365,14 @@ private: { mp_net = net; } + + /** + * @brief Sets the pin ID + */ + void set_pin_id (size_t pin) + { + m_pin_id = pin; + } }; /** diff --git a/src/db/db/dbNetlistCompareUtils.cc b/src/db/db/dbNetlistCompareUtils.cc index 7320e6a58..18f4f4fb3 100644 --- a/src/db/db/dbNetlistCompareUtils.cc +++ b/src/db/db/dbNetlistCompareUtils.cc @@ -414,8 +414,8 @@ generic_categorizer::cat_for (const Obj *cls) } // explicit instantiations -template class DB_PUBLIC generic_categorizer; -template class DB_PUBLIC generic_categorizer; +template class generic_categorizer; +template class generic_categorizer; // -------------------------------------------------------------------------------------------------------------------- // DeviceCategorizer implementation diff --git a/src/db/db/dbSubCircuit.cc b/src/db/db/dbSubCircuit.cc index 4107a1475..21edd6806 100644 --- a/src/db/db/dbSubCircuit.cc +++ b/src/db/db/dbSubCircuit.cc @@ -90,9 +90,17 @@ void SubCircuit::set_trans (const db::DCplxTrans &t) m_trans = t; } -void SubCircuit::erase_pin_ref (size_t pin_id) +void SubCircuit::erase_pin (size_t pin_id) { + Net *net = net_for_pin (pin_id); + net->erase_subcircuit_pin (m_pin_refs [pin_id]); + m_pin_refs.erase (m_pin_refs.begin () + pin_id); + + // correct pin IDs for the pins with ID > pin_id + for (auto p = m_pin_refs.begin () + pin_id; p != m_pin_refs.end (); ++p) { + (*p)->set_pin_id ((*p)->pin_id () - 1); + } } void SubCircuit::set_pin_ref_for_pin (size_t pin_id, Net::subcircuit_pin_iterator iter) diff --git a/src/db/db/dbSubCircuit.h b/src/db/db/dbSubCircuit.h index 9e0877adf..618b8f230 100644 --- a/src/db/db/dbSubCircuit.h +++ b/src/db/db/dbSubCircuit.h @@ -233,7 +233,7 @@ private: /** * @brief Erases the given pin reference */ - void erase_pin_ref (size_t pin_id); + void erase_pin (size_t pin_id); /** * @brief Sets the circuit the subcircuit belongs to