From 675a96eb9ef1406be1d0140e440fce3f57d0c106 Mon Sep 17 00:00:00 2001 From: Matthias Koefferlein Date: Fri, 10 May 2019 00:40:49 +0200 Subject: [PATCH] WIP: some refactoring. --- src/db/db/dbDevice.cc | 13 +++---------- src/db/db/dbDevice.h | 7 +++---- src/db/db/dbLayoutToNetlistReader.cc | 29 ++++++++-------------------- src/db/db/dbLayoutToNetlistWriter.cc | 12 +----------- 4 files changed, 15 insertions(+), 46 deletions(-) diff --git a/src/db/db/dbDevice.cc b/src/db/db/dbDevice.cc index f1215d59d..0e41cd9a9 100644 --- a/src/db/db/dbDevice.cc +++ b/src/db/db/dbDevice.cc @@ -194,16 +194,15 @@ void Device::add_others_terminals (unsigned int this_terminal, db::Device *other std::map >::const_iterator ot = other->m_reconnected_terminals.find (other_terminal); if (ot == other->m_reconnected_terminals.end ()) { - terminals.push_back (OtherTerminalRef (other->device_abstract (), other->position () - position (), other_terminal)); + terminals.push_back (OtherTerminalRef (other_abstracts ().size (), other_terminal)); } else { size_t n = terminals.size (); terminals.insert (terminals.end (), ot->second.begin (), ot->second.end ()); - db::DVector d = other->position () - position (); while (n < terminals.size ()) { - terminals [n].offset += d; + terminals [n].device_index += other_abstracts ().size (); ++n; } @@ -218,7 +217,7 @@ void Device::init_terminal_routes () size_t n = device_class ()->terminal_definitions ().size (); for (size_t i = 0; i < n; ++i) { - m_reconnected_terminals [i].push_back (OtherTerminalRef (device_abstract (), db::DVector (), i)); + m_reconnected_terminals [i].push_back (OtherTerminalRef (0, i)); } } @@ -285,12 +284,6 @@ void Device::translate_device_abstracts (const std::map >::iterator a = m_other_abstracts.begin (); a != m_other_abstracts.end (); ++a) { a->first = map_da (map, a->first); } - - for (std::map >::iterator t = m_reconnected_terminals.begin (); t != m_reconnected_terminals.end (); ++t) { - for (std::vector::iterator r = t->second.begin (); r != t->second.end (); ++r) { - r->device_abstract = map_da (map, r->device_abstract); - } - } } } diff --git a/src/db/db/dbDevice.h b/src/db/db/dbDevice.h index e18171fe8..ffcde9ea7 100644 --- a/src/db/db/dbDevice.h +++ b/src/db/db/dbDevice.h @@ -60,14 +60,13 @@ public: */ struct OtherTerminalRef { - OtherTerminalRef (const db::DeviceAbstract *_device_abstract, const db::DVector &_offset, unsigned int _other_terminal_id) - : device_abstract (_device_abstract), offset (_offset), other_terminal_id (_other_terminal_id) + OtherTerminalRef (size_t _device_index, unsigned int _other_terminal_id) + : device_index (_device_index), other_terminal_id (_other_terminal_id) { // .. nothing yet .. } - const db::DeviceAbstract *device_abstract; - db::DVector offset; + size_t device_index; unsigned int other_terminal_id; }; diff --git a/src/db/db/dbLayoutToNetlistReader.cc b/src/db/db/dbLayoutToNetlistReader.cc index 3cbf4d91c..5c5a249ca 100644 --- a/src/db/db/dbLayoutToNetlistReader.cc +++ b/src/db/db/dbLayoutToNetlistReader.cc @@ -530,9 +530,6 @@ LayoutToNetlistStandardReader::read_device (db::LayoutToNetlist *l2n, db::Circui double dbu = l2n->internal_layout ()->dbu (); db::VCplxTrans dbu_inv (1.0 / dbu); - std::map, size_t> abstracts; - abstracts [std::make_pair (dm, db::Vector ())] = 0; - size_t max_tid = 0; while (br) { @@ -559,7 +556,6 @@ LayoutToNetlistStandardReader::read_device (db::LayoutToNetlist *l2n, db::Circui db::DeviceAbstract *da = device_model_by_name (l2n->netlist (), n); - abstracts [std::make_pair (da, db::Vector (dx, dy))] = device->other_abstracts ().size () + 1; device->other_abstracts ().push_back (std::make_pair (da, db::DVector (dbu * dx, dbu * dy))); } else if (test (skeys::connect_key) || test (lkeys::connect_key)) { @@ -581,10 +577,7 @@ LayoutToNetlistStandardReader::read_device (db::LayoutToNetlist *l2n, db::Circui size_t touter_id = terminal_id (dm->device_class (), touter); size_t tinner_id = terminal_id (dm->device_class (), tinner); - const db::DeviceAbstract *da = device_comp_index > 0 ? device->other_abstracts () [device_comp_index - 1].first : dm; - db::DVector da_offset = device_comp_index > 0 ? device->other_abstracts () [device_comp_index - 1].second : db::DVector (); - - device->reconnected_terminals () [touter_id].push_back (db::Device::OtherTerminalRef (da, da_offset, tinner_id)); + device->reconnected_terminals () [touter_id].push_back (db::Device::OtherTerminalRef (size_t (device_comp_index), tinner_id)); } else if (test (skeys::terminal_key) || test (lkeys::terminal_key)) { @@ -673,26 +666,20 @@ LayoutToNetlistStandardReader::read_device (db::LayoutToNetlist *l2n, db::Circui if (tr) { for (std::vector::const_iterator i = tr->begin (); i != tr->end (); ++i) { - - db::Vector offset = dbu_inv * i->offset; - - std::map, size_t>::const_iterator a = abstracts.find (std::make_pair (i->device_abstract, offset)); - if (a != abstracts.end () && a->second < insts.size ()) { - Connections ref (net->cluster_id (), i->device_abstract->cluster_id_for_terminal (i->other_terminal_id)); - connections [insts [a->second]].push_back (ref); + const db::DeviceAbstract *da = dm; + if (i->device_index > 0) { + da = device->other_abstracts () [i->device_index - 1].first; } - + Connections ref (net->cluster_id (), da->cluster_id_for_terminal (i->other_terminal_id)); + connections [insts [i->device_index]].push_back (ref); } } } else { - std::map, size_t>::const_iterator a = abstracts.find (std::make_pair (dm, db::Vector ())); - if (a != abstracts.end () && a->second < insts.size ()) { - Connections ref (net->cluster_id (), dm->cluster_id_for_terminal (tid)); - connections [insts [a->second]].push_back (ref); - } + Connections ref (net->cluster_id (), dm->cluster_id_for_terminal (tid)); + connections [insts [0]].push_back (ref); } diff --git a/src/db/db/dbLayoutToNetlistWriter.cc b/src/db/db/dbLayoutToNetlistWriter.cc index b93910ce7..b3ece9cfb 100644 --- a/src/db/db/dbLayoutToNetlistWriter.cc +++ b/src/db/db/dbLayoutToNetlistWriter.cc @@ -500,14 +500,10 @@ void std_writer_impl::write (const db::LayoutToNetlist *l2n, const db::Dev tl_assert (device.device_abstract () != 0); *mp_stream << " " << tl::to_word_or_quoted_string (device.device_abstract ()->name ()) << endl; - std::map, size_t> abstracts; - abstracts.insert (std::make_pair (std::make_pair (device.device_abstract (), db::Vector ()), 0)); - const std::vector > &other_abstracts = device.other_abstracts (); for (std::vector >::const_iterator a = other_abstracts.begin (); a != other_abstracts.end (); ++a) { db::Vector pos = dbu_inv * a->second; - abstracts.insert (std::make_pair (std::make_pair (a->first, pos), a - other_abstracts.begin () + 1)); *mp_stream << " " << Keys::device_key << "(" << tl::to_word_or_quoted_string (a->first->name ()) << " " << pos.x () << " " << pos.y () << ")" << endl; @@ -517,13 +513,7 @@ void std_writer_impl::write (const db::LayoutToNetlist *l2n, const db::Dev for (std::map >::const_iterator t = reconnected_terminals.begin (); t != reconnected_terminals.end (); ++t) { for (std::vector::const_iterator c = t->second.begin (); c != t->second.end (); ++c) { - - db::Vector pos = dbu_inv * c->offset; - std::map, size_t>::const_iterator a = abstracts.find (std::make_pair (c->device_abstract, pos)); - tl_assert (a != abstracts.end ()); - - *mp_stream << " " << Keys::connect_key << "(" << a->second << " " << tl::to_word_or_quoted_string (td [t->first].name ()) << " " << tl::to_word_or_quoted_string (td [c->other_terminal_id].name ()) << ")" << endl; - + *mp_stream << " " << Keys::connect_key << "(" << c->device_index << " " << tl::to_word_or_quoted_string (td [t->first].name ()) << " " << tl::to_word_or_quoted_string (td [c->other_terminal_id].name ()) << ")" << endl; } }