1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (c) 2019, Nefelus Inc
5 // All rights reserved.
6 //
7 // Redistribution and use in source and binary forms, with or without
8 // modification, are permitted provided that the following conditions are met:
9 //
10 // * Redistributions of source code must retain the above copyright notice, this
11 // list of conditions and the following disclaimer.
12 //
13 // * Redistributions in binary form must reproduce the above copyright notice,
14 // this list of conditions and the following disclaimer in the documentation
15 // and/or other materials provided with the distribution.
16 //
17 // * Neither the name of the copyright holder nor the names of its
18 // contributors may be used to endorse or promote products derived from
19 // this software without specific prior written permission.
20 //
21 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
25 // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26 // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27 // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28 // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29 // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30 // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31 // POSSIBILITY OF SUCH DAMAGE.
32
33 #include "dbLib.h"
34
35 #include "db.h"
36 #include "dbDatabase.h"
37 #include "dbHashTable.hpp"
38 #include "dbMaster.h"
39 #include "dbNameCache.h"
40 #include "dbProperty.h"
41 #include "dbPropertyItr.h"
42 #include "dbSite.h"
43 #include "dbTable.h"
44 #include "dbTable.hpp"
45 #include "dbTech.h"
46 #include "dbTransform.h"
47
48 namespace odb {
49
50 template class dbTable<_dbLib>;
51 template class dbHashTable<_dbMaster>;
52 template class dbHashTable<_dbSite>;
53
operator ==(const _dbLib & rhs) const54 bool _dbLib::operator==(const _dbLib& rhs) const
55 {
56 if (_lef_units != rhs._lef_units)
57 return false;
58
59 if (_dbu_per_micron != rhs._dbu_per_micron)
60 return false;
61
62 if (_hier_delimeter != rhs._hier_delimeter)
63 return false;
64
65 if (_left_bus_delimeter != rhs._left_bus_delimeter)
66 return false;
67
68 if (_right_bus_delimeter != rhs._right_bus_delimeter)
69 return false;
70
71 if (_spare != rhs._spare)
72 return false;
73
74 if (_name && rhs._name) {
75 if (strcmp(_name, rhs._name) != 0)
76 return false;
77 } else if (_name || rhs._name)
78 return false;
79
80 if (_master_hash != rhs._master_hash)
81 return false;
82
83 if (_site_hash != rhs._site_hash)
84 return false;
85
86 if (*_master_tbl != *rhs._master_tbl)
87 return false;
88
89 if (*_site_tbl != *rhs._site_tbl)
90 return false;
91
92 if (*_prop_tbl != *rhs._prop_tbl)
93 return false;
94
95 if (*_name_cache != *rhs._name_cache)
96 return false;
97
98 return true;
99 }
100
differences(dbDiff & diff,const char * field,const _dbLib & rhs) const101 void _dbLib::differences(dbDiff& diff,
102 const char* field,
103 const _dbLib& rhs) const
104 {
105 DIFF_BEGIN
106 DIFF_FIELD(_lef_units);
107 DIFF_FIELD(_dbu_per_micron);
108 DIFF_FIELD(_hier_delimeter);
109 DIFF_FIELD(_left_bus_delimeter);
110 DIFF_FIELD(_right_bus_delimeter);
111 DIFF_FIELD(_spare);
112 DIFF_FIELD(_name);
113 DIFF_HASH_TABLE(_master_hash);
114 DIFF_HASH_TABLE(_site_hash);
115 DIFF_TABLE_NO_DEEP(_master_tbl);
116 DIFF_TABLE_NO_DEEP(_site_tbl);
117 DIFF_TABLE_NO_DEEP(_prop_tbl);
118 DIFF_NAME_CACHE(_name_cache);
119 DIFF_END
120 }
121
out(dbDiff & diff,char side,const char * field) const122 void _dbLib::out(dbDiff& diff, char side, const char* field) const
123 {
124 DIFF_OUT_BEGIN
125 DIFF_OUT_FIELD(_lef_units);
126 DIFF_OUT_FIELD(_dbu_per_micron);
127 DIFF_OUT_FIELD(_hier_delimeter);
128 DIFF_OUT_FIELD(_left_bus_delimeter);
129 DIFF_OUT_FIELD(_right_bus_delimeter);
130 DIFF_OUT_FIELD(_spare);
131 DIFF_OUT_FIELD(_name);
132 DIFF_OUT_HASH_TABLE(_master_hash);
133 DIFF_OUT_HASH_TABLE(_site_hash);
134 DIFF_OUT_TABLE_NO_DEEP(_master_tbl);
135 DIFF_OUT_TABLE_NO_DEEP(_site_tbl);
136 DIFF_OUT_TABLE_NO_DEEP(_prop_tbl);
137 DIFF_OUT_NAME_CACHE(_name_cache);
138 DIFF_END
139 }
140
141 ////////////////////////////////////////////////////////////////////
142 //
143 // _dbLib - Methods
144 //
145 ////////////////////////////////////////////////////////////////////
_dbLib(_dbDatabase * db)146 _dbLib::_dbLib(_dbDatabase* db)
147 {
148 _lef_units = 0;
149 _dbu_per_micron = 1000;
150 _hier_delimeter = 0;
151 _left_bus_delimeter = 0;
152 _right_bus_delimeter = 0;
153 _spare = 0;
154 _name = 0;
155
156 _master_tbl = new dbTable<_dbMaster>(
157 db, this, (GetObjTbl_t) &_dbLib::getObjectTable, dbMasterObj);
158 ZALLOCATED(_master_tbl);
159
160 _site_tbl = new dbTable<_dbSite>(
161 db, this, (GetObjTbl_t) &_dbLib::getObjectTable, dbSiteObj);
162 ZALLOCATED(_site_tbl);
163
164 _prop_tbl = new dbTable<_dbProperty>(
165 db, this, (GetObjTbl_t) &_dbLib::getObjectTable, dbPropertyObj);
166 ZALLOCATED(_prop_tbl);
167
168 _name_cache
169 = new _dbNameCache(db, this, (GetObjTbl_t) &_dbLib::getObjectTable);
170 ZALLOCATED(_name_cache);
171
172 _prop_itr = new dbPropertyItr(_prop_tbl);
173 ZALLOCATED(_prop_itr);
174
175 _master_hash.setTable(_master_tbl);
176 _site_hash.setTable(_site_tbl);
177 }
178
_dbLib(_dbDatabase * db,const _dbLib & l)179 _dbLib::_dbLib(_dbDatabase* db, const _dbLib& l)
180 : _lef_units(l._lef_units),
181 _dbu_per_micron(l._dbu_per_micron),
182 _hier_delimeter(l._hier_delimeter),
183 _left_bus_delimeter(l._left_bus_delimeter),
184 _right_bus_delimeter(l._right_bus_delimeter),
185 _spare(l._spare),
186 _name(NULL),
187 _master_hash(l._master_hash),
188 _site_hash(l._site_hash)
189 {
190 if (l._name) {
191 _name = strdup(l._name);
192 ZALLOCATED(_name);
193 }
194
195 _master_tbl = new dbTable<_dbMaster>(db, this, *l._master_tbl);
196 ZALLOCATED(_master_tbl);
197
198 _site_tbl = new dbTable<_dbSite>(db, this, *l._site_tbl);
199 ZALLOCATED(_site_tbl);
200
201 _prop_tbl = new dbTable<_dbProperty>(db, this, *l._prop_tbl);
202 ZALLOCATED(_prop_tbl);
203
204 _name_cache = new _dbNameCache(db, this, *l._name_cache);
205 ZALLOCATED(_name_cache);
206
207 _prop_itr = new dbPropertyItr(_prop_tbl);
208 ZALLOCATED(_prop_itr);
209
210 _master_hash.setTable(_master_tbl);
211 _site_hash.setTable(_site_tbl);
212 }
213
~_dbLib()214 _dbLib::~_dbLib()
215 {
216 delete _master_tbl;
217 delete _site_tbl;
218 delete _prop_tbl;
219 delete _name_cache;
220 delete _prop_itr;
221
222 if (_name)
223 free((void*) _name);
224 }
225
operator <<(dbOStream & stream,const _dbLib & lib)226 dbOStream& operator<<(dbOStream& stream, const _dbLib& lib)
227 {
228 stream << lib._lef_units;
229 stream << lib._dbu_per_micron;
230 stream << lib._hier_delimeter;
231 stream << lib._left_bus_delimeter;
232 stream << lib._right_bus_delimeter;
233 stream << lib._spare;
234 stream << lib._name;
235 stream << lib._master_hash;
236 stream << lib._site_hash;
237 stream << *lib._master_tbl;
238 stream << *lib._site_tbl;
239 stream << *lib._prop_tbl;
240 stream << *lib._name_cache;
241 return stream;
242 }
243
operator >>(dbIStream & stream,_dbLib & lib)244 dbIStream& operator>>(dbIStream& stream, _dbLib& lib)
245 {
246 stream >> lib._lef_units;
247 stream >> lib._dbu_per_micron;
248 stream >> lib._hier_delimeter;
249 stream >> lib._left_bus_delimeter;
250 stream >> lib._right_bus_delimeter;
251 stream >> lib._spare;
252 stream >> lib._name;
253 stream >> lib._master_hash;
254 stream >> lib._site_hash;
255 stream >> *lib._master_tbl;
256 stream >> *lib._site_tbl;
257 stream >> *lib._prop_tbl;
258 stream >> *lib._name_cache;
259
260 return stream;
261 }
262
getObjectTable(dbObjectType type)263 dbObjectTable* _dbLib::getObjectTable(dbObjectType type)
264 {
265 switch (type) {
266 case dbMasterObj:
267 return _master_tbl;
268 case dbSiteObj:
269 return _site_tbl;
270 case dbPropertyObj:
271 return _prop_tbl;
272 default:
273 break;
274 }
275
276 return getTable()->getObjectTable(type);
277 }
278
279 ////////////////////////////////////////////////////////////////////
280 //
281 // dbLib - Methods
282 //
283 ////////////////////////////////////////////////////////////////////
284
getName()285 std::string dbLib::getName()
286 {
287 _dbLib* lib = (_dbLib*) this;
288 return lib->_name;
289 }
290
getConstName()291 const char* dbLib::getConstName()
292 {
293 _dbLib* lib = (_dbLib*) this;
294 return lib->_name;
295 }
296
getTech()297 dbTech* dbLib::getTech()
298 {
299 _dbDatabase* db = getImpl()->getDatabase();
300 return (dbTech*) db->_tech_tbl->getPtr(db->_tech);
301 }
302
getDbUnitsPerMicron()303 int dbLib::getDbUnitsPerMicron()
304 {
305 _dbLib* lib = (_dbLib*) this;
306 return lib->_dbu_per_micron;
307 }
308
getMasters()309 dbSet<dbMaster> dbLib::getMasters()
310 {
311 _dbLib* lib = (_dbLib*) this;
312 return dbSet<dbMaster>(lib, lib->_master_tbl);
313 }
314
findMaster(const char * name)315 dbMaster* dbLib::findMaster(const char* name)
316 {
317 _dbLib* lib = (_dbLib*) this;
318 return (dbMaster*) lib->_master_hash.find(name);
319 }
320
getSites()321 dbSet<dbSite> dbLib::getSites()
322 {
323 _dbLib* lib = (_dbLib*) this;
324 return dbSet<dbSite>(lib, lib->_site_tbl);
325 }
326
findSite(const char * name)327 dbSite* dbLib::findSite(const char* name)
328 {
329 _dbLib* lib = (_dbLib*) this;
330 return (dbSite*) lib->_site_hash.find(name);
331 }
332
getLefUnits()333 int dbLib::getLefUnits()
334 {
335 _dbLib* lib = (_dbLib*) this;
336 return lib->_lef_units;
337 }
338
setLefUnits(int units)339 void dbLib::setLefUnits(int units)
340 {
341 _dbLib* lib = (_dbLib*) this;
342 lib->_lef_units = units;
343 }
344
getHierarchyDelimeter()345 char dbLib::getHierarchyDelimeter()
346 {
347 _dbLib* lib = (_dbLib*) this;
348 return lib->_hier_delimeter;
349 }
350
setBusDelimeters(char left,char right)351 void dbLib::setBusDelimeters(char left, char right)
352 {
353 _dbLib* lib = (_dbLib*) this;
354 lib->_left_bus_delimeter = left;
355 lib->_right_bus_delimeter = right;
356 }
357
getBusDelimeters(char & left,char & right)358 void dbLib::getBusDelimeters(char& left, char& right)
359 {
360 _dbLib* lib = (_dbLib*) this;
361 left = lib->_left_bus_delimeter;
362 right = lib->_right_bus_delimeter;
363 }
364
create(dbDatabase * db_,const char * name,char hier_delimeter)365 dbLib* dbLib::create(dbDatabase* db_, const char* name, char hier_delimeter)
366 {
367 if (db_->findLib(name))
368 return NULL;
369
370 _dbDatabase* db = (_dbDatabase*) db_;
371 _dbLib* lib = db->_lib_tbl->create();
372 lib->_name = strdup(name);
373 ZALLOCATED(lib->_name);
374 lib->_hier_delimeter = hier_delimeter;
375 _dbTech* tech = (_dbTech*) db_->getTech();
376 lib->_dbu_per_micron = tech->_dbu_per_micron;
377 return (dbLib*) lib;
378 }
379
getLib(dbDatabase * db_,uint dbid_)380 dbLib* dbLib::getLib(dbDatabase* db_, uint dbid_)
381 {
382 _dbDatabase* db = (_dbDatabase*) db_;
383 return (dbLib*) db->_lib_tbl->getPtr(dbid_);
384 }
385
destroy(dbLib * lib_)386 void dbLib::destroy(dbLib* lib_)
387 {
388 _dbLib* lib = (_dbLib*) lib_;
389 _dbDatabase* db = lib->getDatabase();
390 dbProperty::destroyProperties(lib);
391 db->_lib_tbl->destroy(lib);
392 }
393
394 } // namespace odb
395