@@ -26,6 +26,12 @@ bool _dbChipConn::operator==(const _dbChipConn& rhs) const
2626 if (thickness_ != rhs.thickness_ ) {
2727 return false ;
2828 }
29+ if (chip_ != rhs.chip_ ) {
30+ return false ;
31+ }
32+ if (chip_conn_next_ != rhs.chip_conn_next_ ) {
33+ return false ;
34+ }
2935 if (top_region_ != rhs.top_region_ ) {
3036 return false ;
3137 }
@@ -49,6 +55,8 @@ dbIStream& operator>>(dbIStream& stream, _dbChipConn& obj)
4955{
5056 stream >> obj.name_ ;
5157 stream >> obj.thickness_ ;
58+ stream >> obj.chip_ ;
59+ stream >> obj.chip_conn_next_ ;
5260 stream >> obj.top_region_ ;
5361 stream >> obj.top_region_path_ ;
5462 stream >> obj.bottom_region_ ;
@@ -60,6 +68,8 @@ dbOStream& operator<<(dbOStream& stream, const _dbChipConn& obj)
6068{
6169 stream << obj.name_ ;
6270 stream << obj.thickness_ ;
71+ stream << obj.chip_ ;
72+ stream << obj.chip_conn_next_ ;
6373 stream << obj.top_region_ ;
6474 stream << obj.top_region_path_ ;
6575 stream << obj.bottom_region_ ;
@@ -99,6 +109,14 @@ int dbChipConn::getThickness() const
99109}
100110
101111// User Code Begin dbChipConnPublicMethods
112+
113+ dbChip* dbChipConn::getParentChip () const
114+ {
115+ _dbChipConn* obj = (_dbChipConn*) this ;
116+ _dbDatabase* _db = (_dbDatabase*) obj->getOwner ();
117+ return (dbChip*) _db->chip_tbl_ ->getPtr (obj->chip_ );
118+ }
119+
102120dbChipRegionInst* dbChipConn::getTopRegion () const
103121{
104122 _dbChipConn* obj = (_dbChipConn*) this ;
@@ -139,35 +157,89 @@ std::vector<dbChipInst*> dbChipConn::getBottomRegionPath() const
139157 return bottom_region_path;
140158}
141159
160+ std::vector<dbId<_dbChipInst>> extractChipInstsPath (
161+ dbChip* parent_chip,
162+ std::vector<dbChipInst*> chip_insts)
163+ {
164+ _dbDatabase* _db = (_dbDatabase*) parent_chip->getImpl ()->getOwner ();
165+ utl::Logger* logger = _db->getLogger ();
166+ std::vector<dbId<_dbChipInst>> chip_insts_path;
167+ for (auto chipinst : chip_insts) {
168+ if (chipinst->getParentChip () != parent_chip) {
169+ logger->error (utl::ODB,
170+ 510 ,
171+ " Cannot create chip connection. ChipInst {} is not a child "
172+ " of chip {}" ,
173+ chipinst->getName (),
174+ parent_chip->getName ());
175+ }
176+ chip_insts_path.push_back (chipinst->getImpl ()->getOID ());
177+ parent_chip = chipinst->getMasterChip ();
178+ }
179+ return chip_insts_path;
180+ }
181+
142182dbChipConn* dbChipConn::create (const std::string& name,
143- dbChipRegionInst* top_region,
144- dbChipRegionInst* bottom_region,
183+ dbChip* parent_chip,
145184 std::vector<dbChipInst*> top_region_path,
146- std::vector<dbChipInst*> bottom_region_path)
185+ dbChipRegionInst* top_region,
186+ std::vector<dbChipInst*> bottom_region_path,
187+ dbChipRegionInst* bottom_region)
147188{
148189 _dbDatabase* _db = (_dbDatabase*) top_region->getImpl ()->getOwner ();
190+ if (parent_chip == nullptr || top_region_path.empty ()
191+ || bottom_region_path.empty () || top_region == nullptr
192+ || bottom_region == nullptr ) {
193+ return nullptr ;
194+ }
195+ if (top_region->getChipInst () != top_region_path.back ()) {
196+ _db->getLogger ()->error (utl::ODB,
197+ 511 ,
198+ " Cannot create chip connection. Top region path "
199+ " does not match top region" );
200+ }
201+ if (bottom_region->getChipInst () != bottom_region_path.back ()) {
202+ _db->getLogger ()->error (utl::ODB,
203+ 512 ,
204+ " Cannot create chip connection. Bottom region path "
205+ " does not match bottom region" );
206+ }
149207 _dbChipConn* obj = (_dbChipConn*) _db->chip_conn_tbl_ ->create ();
208+ _dbChip* chip = (_dbChip*) parent_chip;
150209 obj->name_ = name;
151210 obj->thickness_ = 0 ;
211+ obj->chip_ = chip->getOID ();
152212 obj->top_region_ = top_region->getImpl ()->getOID ();
153213 obj->bottom_region_ = bottom_region->getImpl ()->getOID ();
154- std::vector<dbId<_dbChipInst>> top_region_path_ids;
155- for (auto chipinst : top_region_path) {
156- top_region_path_ids.push_back (chipinst->getImpl ()->getOID ());
157- }
158- obj->top_region_path_ = top_region_path_ids;
159- std::vector<dbId<_dbChipInst>> bottom_region_path_ids;
160- for (auto chipinst : bottom_region_path) {
161- bottom_region_path_ids.push_back (chipinst->getImpl ()->getOID ());
162- }
163- obj->bottom_region_path_ = bottom_region_path_ids;
214+ obj->top_region_path_ = extractChipInstsPath (parent_chip, top_region_path);
215+ obj->bottom_region_path_
216+ = extractChipInstsPath (parent_chip, bottom_region_path);
217+
218+ obj->chip_conn_next_ = chip->conns_ ;
219+ chip->conns_ = obj->getOID ();
164220 return (dbChipConn*) obj;
165221}
166222
167223void dbChipConn::destroy (dbChipConn* chipConn)
168224{
169225 _dbChipConn* obj = (_dbChipConn*) chipConn;
170226 _dbDatabase* _db = (_dbDatabase*) obj->getOwner ();
227+ // Remove from chip's list of connections
228+ _dbChip* chip = (_dbChip*) chipConn->getParentChip ();
229+ if (chip->conns_ == obj->getOID ()) {
230+ chip->conns_ = obj->chip_conn_next_ ;
231+ } else {
232+ uint id = chip->conns_ ;
233+ while (id != 0 ) {
234+ _dbChipConn* _chipconn = _db->chip_conn_tbl_ ->getPtr (id);
235+ if (_chipconn->chip_conn_next_ == obj->getOID ()) {
236+ _chipconn->chip_conn_next_ = obj->chip_conn_next_ ;
237+ break ;
238+ }
239+ id = _chipconn->chip_conn_next_ ;
240+ }
241+ }
242+ // Destroy the connection
171243 _db->chip_conn_tbl_ ->destroy (obj);
172244}
173245
0 commit comments