Skip to content

Commit 5fc6951

Browse files
Merge pull request #8011 from osamahammad21/odb-database-chip
ODB: chip table hash and add a test case
2 parents 3fd4e08 + 29dcaf6 commit 5fc6951

File tree

12 files changed

+226
-73
lines changed

12 files changed

+226
-73
lines changed

src/odb/include/odb/db.h

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6935,7 +6935,7 @@ class dbChip : public dbObject
69356935
HIER
69366936
};
69376937

6938-
std::string getName() const;
6938+
const char* getName() const;
69396939

69406940
void setOffset(Point offset);
69416941

@@ -6994,6 +6994,8 @@ class dbChip : public dbObject
69946994
bool isTsv() const;
69956995

69966996
// User Code Begin dbChip
6997+
6998+
ChipType getChipType() const;
69976999
///
69987000
/// Get the top-block of this chip.
69997001
/// Returns nullptr if a top-block has NOT been created.
@@ -7002,10 +7004,11 @@ class dbChip : public dbObject
70027004

70037005
///
70047006
/// Create a new chip.
7005-
/// Returns nullptr if a chip already exists.
70067007
/// Returns nullptr if there is no database technology.
70077008
///
7008-
static dbChip* create(dbDatabase* db);
7009+
static dbChip* create(dbDatabase* db,
7010+
const std::string& name = "",
7011+
ChipType type = ChipType::DIE);
70097012

70107013
///
70117014
/// Translate a database-id back to a pointer.
@@ -7024,7 +7027,11 @@ class dbDatabase : public dbObject
70247027
public:
70257028
dbSet<dbChip> getChips() const;
70267029

7030+
dbChip* findChip(const char* name) const;
7031+
70277032
// User Code Begin dbDatabase
7033+
7034+
void setTopChip(dbChip* chip);
70287035
///
70297036
/// Return the libs contained in the database. A database can contain
70307037
/// multiple libs.

src/odb/src/codeGenerator/gen.py

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
get_hash_table_type,
2121
get_ref_type,
2222
get_table_name,
23-
get_template_type,
23+
is_template_type,
24+
get_template_types,
2425
is_bit_fields,
2526
is_hash_table,
2627
is_pass_by_ref,
@@ -55,9 +56,7 @@ def make_parent_field(parent, relation):
5556
field["table"] = True
5657
field["dbSetGetter"] = True
5758
field["components"] = [field["name"]]
58-
field["flags"] = ["cmp", "serial", "diff", "no-set", "get"] + relation.get(
59-
"flags", []
60-
)
59+
field["flags"] = ["no-set"] + relation.get("flags", [])
6160
if "page_size" in relation:
6261
field["page_size"] = relation["page_size"]
6362
if "schema" in relation:
@@ -74,10 +73,12 @@ def make_parent_hash_field(parent, relation, parent_field):
7473
"""Adds a hash table field to the parent of a hashed relationsip"""
7574
field = {}
7675
field["name"] = parent_field["name"][:-4] + "hash_"
77-
field["type"] = "dbHashTable<_" + relation["child"] + ">"
76+
page_size_part = f", {relation['page_size']}" if "page_size" in relation else ""
77+
field["type"] = f"dbHashTable<_{relation['child']}{page_size_part}>"
7878
field["components"] = [field["name"]]
7979
field["table_name"] = parent_field["name"]
80-
field["flags"] = ["cmp", "serial", "diff", "no-set", "get"]
80+
field["flags"] = ["no-set"]
81+
field["flags"].extend(relation.get("flags", []))
8182
parent["fields"].append(field)
8283
if "dbHashTable.h" not in parent["h_includes"]:
8384
parent["h_includes"].append("dbHashTable.h")
@@ -89,7 +90,8 @@ def make_child_next_field(child, relation):
8990
"""Adds a next entry field to the child of a hashed relationsip"""
9091
inChildNextEntry = {"name": "_next_entry"}
9192
inChildNextEntry["type"] = "dbId<_" + relation["child"] + ">"
92-
inChildNextEntry["flags"] = ["cmp", "serial", "diff", "private", "no-deep"]
93+
inChildNextEntry["flags"] = ["private"]
94+
inChildNextEntry["flags"].extend(relation.get("flags", []))
9395
child["fields"].append(inChildNextEntry)
9496
logging.debug(f"Add hash field {inChildNextEntry['name']} to {relation['child']}")
9597

@@ -138,21 +140,20 @@ def add_field_attributes(field, klass, flags_struct, schema):
138140
#
139141
# This needs documentation
140142
#
141-
template_class_name = None
142-
tmp = get_template_type(field["type"])
143-
while tmp is not None:
144-
template_class_name = tmp
145-
tmp = get_template_type(tmp)
146-
147-
if template_class_name is not None:
148-
if (
149-
template_class_name not in klass["declared_classes"]
150-
and template_class_name not in std
151-
and "no-template" not in field["flags"]
152-
and klass["name"] != template_class_name[1:]
153-
and klass["name"] + "::" != template_class_name[0 : len(klass["name"]) + 2]
154-
):
155-
klass["declared_classes"].append(template_class_name)
143+
if is_template_type(field["type"]):
144+
for template_class_name in get_template_types(field["type"]):
145+
if (
146+
template_class_name not in klass["declared_classes"]
147+
and template_class_name not in std
148+
and not template_class_name.isdigit()
149+
and template_class_name != "false"
150+
and template_class_name != "true"
151+
and "no-template" not in field["flags"]
152+
and klass["name"] != template_class_name[1:]
153+
and klass["name"] + "::"
154+
!= template_class_name[0 : len(klass["name"]) + 2]
155+
):
156+
klass["declared_classes"].append(template_class_name)
156157
####
157158
####
158159
####

src/odb/src/codeGenerator/helper.py

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,11 @@ def is_hash_table(type_name):
132132
def get_hash_table_type(type_name):
133133
if not is_hash_table(type_name) or len(type_name) < 13:
134134
return None
135-
136-
return type_name[12:-1] + "*"
135+
types = get_template_types(type_name[12:-1])
136+
for type in types:
137+
if type.find("db") != -1:
138+
return type + "*"
139+
return None
137140

138141

139142
def is_pass_by_ref(type_name):
@@ -148,18 +151,37 @@ def is_set_by_ref(type_name):
148151
)
149152

150153

151-
def _is_template_type(type_name):
154+
def is_template_type(type_name):
152155
open_bracket = type_name.find("<")
153156
if open_bracket == -1:
154157
return False
155-
156158
closed_bracket = type_name.find(">")
157159

158160
return closed_bracket >= open_bracket
159161

160162

163+
def _is_comma_divided(type_name):
164+
comma = type_name.find(",")
165+
return comma != -1
166+
167+
168+
def get_template_types(type_name):
169+
# extract all template types from a type name
170+
if is_template_type(type_name):
171+
return get_template_types(get_template_type(type_name))
172+
elif _is_comma_divided(type_name):
173+
# split and strip in one line
174+
types = [t.strip() for t in type_name.split(",")]
175+
for i in range(len(types)):
176+
if types[i].isdigit() or types[i] == "true" or types[i] == "false":
177+
types.pop(i)
178+
return types
179+
else:
180+
return [type_name]
181+
182+
161183
def get_template_type(type_name):
162-
if not _is_template_type(type_name):
184+
if not is_template_type(type_name):
163185
return None
164186
num_brackets = 1
165187

src/odb/src/codeGenerator/schema.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -376,9 +376,10 @@
376376
"parent":"dbDatabase",
377377
"child":"dbChip",
378378
"type":"1_n",
379-
"tbl_name":"_chip_tbl",
379+
"tbl_name":"chip_tbl_",
380380
"flags": ["no-serial"],
381-
"page_size": 2
381+
"page_size": 2,
382+
"hash": true
382383
}
383384
]
384385
}

src/odb/src/codeGenerator/schema/chip/dbChip.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@
1919
],
2020
"fields": [
2121
{
22-
"name": "name_",
23-
"type": "std::string",
22+
"name": "_name",
23+
"type": "char *",
2424
"schema": "db_schema_chip_extended",
25+
"default": "nullptr",
2526
"flags": ["no-set"]
2627
},
2728
{

src/odb/src/db/dbBlock.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1532,15 +1532,15 @@ dbChip* dbBlock::getChip()
15321532
{
15331533
_dbBlock* block = (_dbBlock*) this;
15341534
_dbDatabase* db = block->getDatabase();
1535-
_dbChip* chip = db->_chip_tbl->getPtr(block->_chip);
1535+
_dbChip* chip = db->chip_tbl_->getPtr(block->_chip);
15361536
return (dbChip*) chip;
15371537
}
15381538

15391539
dbBlock* dbBlock::getParent()
15401540
{
15411541
_dbBlock* block = (_dbBlock*) this;
15421542
_dbDatabase* db = block->getDatabase();
1543-
_dbChip* chip = db->_chip_tbl->getPtr(block->_chip);
1543+
_dbChip* chip = db->chip_tbl_->getPtr(block->_chip);
15441544
if (!block->_parent.isValid()) {
15451545
return nullptr;
15461546
}
@@ -1572,7 +1572,7 @@ dbSet<dbBlock> dbBlock::getChildren()
15721572
{
15731573
_dbBlock* block = (_dbBlock*) this;
15741574
_dbDatabase* db = getImpl()->getDatabase();
1575-
_dbChip* chip = db->_chip_tbl->getPtr(block->_chip);
1575+
_dbChip* chip = db->chip_tbl_->getPtr(block->_chip);
15761576
return dbSet<dbBlock>(block, chip->_block_itr);
15771577
}
15781578

src/odb/src/db/dbChip.cpp

Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
// Generator Code Begin Cpp
55
#include "dbChip.h"
66

7-
#include <string>
8-
97
#include "dbBlock.h"
108
#include "dbBlockItr.h"
119
#include "dbDatabase.h"
@@ -22,7 +20,7 @@ template class dbTable<_dbChip>;
2220

2321
bool _dbChip::operator==(const _dbChip& rhs) const
2422
{
25-
if (name_ != rhs.name_) {
23+
if (_name != rhs._name) {
2624
return false;
2725
}
2826
if (type_ != rhs.type_) {
@@ -76,6 +74,9 @@ bool _dbChip::operator==(const _dbChip& rhs) const
7674
if (*_prop_tbl != *rhs._prop_tbl) {
7775
return false;
7876
}
77+
if (_next_entry != rhs._next_entry) {
78+
return false;
79+
}
7980

8081
// User Code Begin ==
8182
if (*_block_tbl != *rhs._block_tbl) {
@@ -99,6 +100,7 @@ bool _dbChip::operator<(const _dbChip& rhs) const
99100

100101
_dbChip::_dbChip(_dbDatabase* db)
101102
{
103+
_name = nullptr;
102104
type_ = 0;
103105
offset_ = {};
104106
width_ = 0;
@@ -131,7 +133,7 @@ _dbChip::_dbChip(_dbDatabase* db)
131133
dbIStream& operator>>(dbIStream& stream, _dbChip& obj)
132134
{
133135
if (obj.getDatabase()->isSchema(db_schema_chip_extended)) {
134-
stream >> obj.name_;
136+
stream >> obj._name;
135137
}
136138
if (obj.getDatabase()->isSchema(db_schema_chip_extended)) {
137139
stream >> obj.type_;
@@ -183,14 +185,17 @@ dbIStream& operator>>(dbIStream& stream, _dbChip& obj)
183185
stream >> *obj._block_tbl;
184186
stream >> *obj._prop_tbl;
185187
stream >> *obj._name_cache;
188+
if (obj.getDatabase()->isSchema(db_schema_chip_hash_table)) {
189+
stream >> obj._next_entry;
190+
}
186191
// User Code End >>
187192
return stream;
188193
}
189194

190195
dbOStream& operator<<(dbOStream& stream, const _dbChip& obj)
191196
{
192197
dbOStreamScope scope(stream, "dbChip");
193-
stream << obj.name_;
198+
stream << obj._name;
194199
stream << obj.type_;
195200
stream << obj.offset_;
196201
stream << obj.width_;
@@ -211,6 +216,7 @@ dbOStream& operator<<(dbOStream& stream, const _dbChip& obj)
211216
stream << *obj._block_tbl;
212217
stream << NamedTable("prop_tbl", obj._prop_tbl);
213218
stream << *obj._name_cache;
219+
stream << obj._next_entry;
214220
// User Code End <<
215221
return stream;
216222
}
@@ -244,6 +250,9 @@ void _dbChip::collectMemInfo(MemInfo& info)
244250

245251
_dbChip::~_dbChip()
246252
{
253+
if (_name) {
254+
free((void*) _name);
255+
}
247256
delete _prop_tbl;
248257
// User Code Begin Destructor
249258
delete _block_tbl;
@@ -259,10 +268,10 @@ _dbChip::~_dbChip()
259268
//
260269
////////////////////////////////////////////////////////////////////
261270

262-
std::string dbChip::getName() const
271+
const char* dbChip::getName() const
263272
{
264273
_dbChip* obj = (_dbChip*) this;
265-
return obj->name_;
274+
return obj->_name;
266275
}
267276

268277
void dbChip::setOffset(Point offset)
@@ -448,6 +457,13 @@ bool dbChip::isTsv() const
448457
}
449458

450459
// User Code Begin dbChipPublicMethods
460+
461+
dbChip::ChipType dbChip::getChipType() const
462+
{
463+
_dbChip* obj = (_dbChip*) this;
464+
return (dbChip::ChipType) obj->type_;
465+
}
466+
451467
dbBlock* dbChip::getBlock()
452468
{
453469
_dbChip* chip = (_dbChip*) this;
@@ -459,31 +475,35 @@ dbBlock* dbChip::getBlock()
459475
return (dbBlock*) chip->_block_tbl->getPtr(chip->_top);
460476
}
461477

462-
dbChip* dbChip::create(dbDatabase* db_)
478+
dbChip* dbChip::create(dbDatabase* db_, const std::string& name, ChipType type)
463479
{
464480
_dbDatabase* db = (_dbDatabase*) db_;
465-
466-
if (db->_chip != 0) {
467-
return nullptr;
481+
_dbChip* chip = db->chip_tbl_->create();
482+
chip->_name = safe_strdup(name.c_str());
483+
chip->type_ = (uint) type;
484+
if (db->_chip == 0) {
485+
db->_chip = chip->getOID();
468486
}
469-
470-
_dbChip* chip = db->_chip_tbl->create();
471-
db->_chip = chip->getOID();
487+
db->chip_hash_.insert(chip);
472488
return (dbChip*) chip;
473489
}
474490

475491
dbChip* dbChip::getChip(dbDatabase* db_, uint dbid_)
476492
{
477493
_dbDatabase* db = (_dbDatabase*) db_;
478-
return (dbChip*) db->_chip_tbl->getPtr(dbid_);
494+
return (dbChip*) db->chip_tbl_->getPtr(dbid_);
479495
}
480496

481497
void dbChip::destroy(dbChip* chip_)
482498
{
483499
_dbChip* chip = (_dbChip*) chip_;
484500
_dbDatabase* db = chip->getDatabase();
501+
if (db->_chip == chip->getOID()) {
502+
db->_chip = 0;
503+
}
485504
dbProperty::destroyProperties(chip);
486-
db->_chip_tbl->destroy(chip);
505+
db->chip_hash_.remove(chip);
506+
db->chip_tbl_->destroy(chip);
487507
db->_chip = 0;
488508
}
489509
// User Code End dbChipPublicMethods

0 commit comments

Comments
 (0)