Skip to content

Commit ac557f1

Browse files
committed
Added dbModNet::checkSanity()
Signed-off-by: Jaehyun Kim <jhkim@precisioninno.com>
1 parent 4534556 commit ac557f1

6 files changed

Lines changed: 197 additions & 31 deletions

File tree

src/dbSta/src/dbNetwork.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4544,6 +4544,7 @@ void dbNetwork::checkSanityNetConnectivity(odb::dbObject* obj) const
45444544
// Check for hier net and flat net connectivity
45454545
dbSet<dbModNet> mod_nets = block()->getModNets();
45464546
for (dbModNet* mod_net : mod_nets) {
4547+
mod_net->checkSanity();
45474548
findRelatedDbNet(mod_net);
45484549
}
45494550

src/odb/include/odb/db.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8291,6 +8291,7 @@ class dbModBTerm : public dbObject
82918291
dbModule* getParent() const;
82928292

82938293
// User Code Begin dbModBTerm
8294+
std::string getHierarchicalName() const;
82948295
void setParentModITerm(dbModITerm* parent_pin);
82958296
dbModITerm* getParentModITerm() const;
82968297
void setModNet(dbModNet* modNet);
@@ -8366,6 +8367,7 @@ class dbModITerm : public dbObject
83668367
dbModInst* getParent() const;
83678368

83688369
// User Code Begin dbModITerm
8370+
std::string getHierarchicalName() const;
83698371
void setModNet(dbModNet* modNet);
83708372
dbModNet* getModNet() const;
83718373
void setChildModBTerm(dbModBTerm* child_port);
@@ -8391,7 +8393,7 @@ class dbModNet : public dbObject
83918393
dbSet<dbModBTerm> getModBTerms() const;
83928394
dbSet<dbITerm> getITerms() const;
83938395
dbSet<dbBTerm> getBTerms() const;
8394-
unsigned connectionCount();
8396+
unsigned connectionCount() const;
83958397
std::string getName() const;
83968398
const char* getConstName() const;
83978399
std::string getHierarchicalName() const;
@@ -8404,6 +8406,7 @@ class dbModNet : public dbObject
84048406
// This function traverses the terminals connected to this dbModNet
84058407
// and returns the first dbNet it finds.
84068408
dbNet* findRelatedNet() const;
8409+
void checkSanity() const;
84078410

84088411
static dbModNet* getModNet(dbBlock* block, uint id);
84098412
static dbModNet* create(dbModule* parentModule, const char* base_name);

src/odb/src/db/dbModBTerm.cpp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,23 @@ dbModule* dbModBTerm::getParent() const
168168
}
169169

170170
// User Code Begin dbModBTermPublicMethods
171+
std::string dbModBTerm::getHierarchicalName() const
172+
{
173+
dbModule* parent = getParent();
174+
if (parent == nullptr) {
175+
return getName();
176+
}
177+
178+
dbBlock* block = parent->getOwner();
179+
if (parent == block->getTopModule()) {
180+
return getName();
181+
}
182+
183+
return fmt::format("{}{}{}", // NOLINT(misc-include-cleaner)
184+
parent->getModInst()->getHierarchicalName(),
185+
block->getHierarchyDelimiter(),
186+
getName());
187+
}
171188

172189
void dbModBTerm::setModNet(dbModNet* modNet)
173190
{

src/odb/src/db/dbModITerm.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,28 @@ dbModInst* dbModITerm::getParent() const
154154
}
155155

156156
// User Code Begin dbModITermPublicMethods
157+
std::string dbModITerm::getHierarchicalName() const
158+
{
159+
dbModInst* modinst = getParent();
160+
if (modinst == nullptr) {
161+
return getName();
162+
}
163+
164+
dbModule* module = modinst->getParent();
165+
if (module == nullptr) {
166+
return getName();
167+
}
168+
169+
dbBlock* block = module->getOwner();
170+
if (module == block->getTopModule()) {
171+
return getName();
172+
}
173+
174+
return fmt::format("{}{}{}", // NOLINT(misc-include-cleaner)
175+
modinst->getHierarchicalName(),
176+
block->getHierarchyDelimiter(),
177+
getName());
178+
}
157179

158180
void dbModITerm::setModNet(dbModNet* modNet)
159181
{

src/odb/src/db/dbModNet.cpp

Lines changed: 141 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -413,9 +413,10 @@ dbSet<dbITerm> dbModNet::getITerms() const
413413
return dbSet<dbITerm>(_mod_net, _block->_module_modnet_iterm_itr);
414414
}
415415

416-
unsigned dbModNet::connectionCount()
416+
unsigned dbModNet::connectionCount() const
417417
{
418-
return (getITerms().size() + getBTerms().size() + getModITerms().size());
418+
return (getITerms().size() + getBTerms().size() + getModITerms().size()
419+
+ getModBTerms().size());
419420
}
420421

421422
dbNet* dbModNet::findRelatedNet() const
@@ -490,6 +491,144 @@ dbNet* dbModNet::findRelatedNet() const
490491
return nullptr;
491492
}
492493

494+
void dbModNet::checkSanity() const
495+
{
496+
utl::Logger* logger = getImpl()->getLogger();
497+
std::vector<std::string> drvr_info_list;
498+
499+
// Find BTerm drivers
500+
for (dbBTerm* bterm : getBTerms()) {
501+
if (bterm->getSigType().isSupply()) {
502+
continue;
503+
}
504+
505+
if (bterm->getIoType() == dbIoType::INPUT
506+
|| bterm->getIoType() == dbIoType::INOUT) {
507+
dbBlock* block = bterm->getBlock();
508+
dbModule* parent_module = block->getTopModule();
509+
drvr_info_list.push_back(fmt::format( // NOLINT(misc-include-cleaner)
510+
"\n - bterm: '{}' (block: '{}', parent_module: '{}')",
511+
bterm->getName(),
512+
(block) ? block->getConstName() : "null",
513+
(parent_module) ? parent_module->getName() : "null"));
514+
}
515+
}
516+
517+
// Find ITerm drivers
518+
for (dbITerm* iterm : getITerms()) {
519+
if (iterm->getSigType().isSupply()) {
520+
continue;
521+
}
522+
523+
if (iterm->getIoType() == dbIoType::OUTPUT
524+
|| iterm->getIoType() == dbIoType::INOUT) {
525+
dbInst* inst = iterm->getInst();
526+
dbMaster* master = inst->getMaster();
527+
dbModule* parent_module = inst->getModule();
528+
dbBlock* block = inst->getBlock();
529+
drvr_info_list.push_back(fmt::format( // NOLINT(misc-include-cleaner)
530+
"\n - iterm: '{}' (block: '{}', parent_module: '{}', master: '{}')",
531+
iterm->getName(),
532+
(block) ? block->getConstName() : "null",
533+
(parent_module) ? parent_module->getName() : "null",
534+
(master) ? master->getConstName() : "null"));
535+
}
536+
}
537+
538+
// Find ModBTerm drivers
539+
for (dbModBTerm* modbterm : getModBTerms()) {
540+
if (modbterm->getSigType().isSupply()) {
541+
continue;
542+
}
543+
544+
if (modbterm->getIoType() == dbIoType::INPUT
545+
|| modbterm->getIoType() == dbIoType::INOUT) {
546+
drvr_info_list.push_back(
547+
// NOLINTNEXTLINE(misc-include-cleaner)
548+
fmt::format("\n - modbterm: '{}'", modbterm->getHierarchicalName()));
549+
}
550+
}
551+
552+
// Find ModITerm drivers
553+
for (dbModITerm* moditerm : getModITerms()) {
554+
if (dbModBTerm* child_bterm = moditerm->getChildModBTerm()) {
555+
if (child_bterm->getSigType().isSupply()) {
556+
continue;
557+
}
558+
559+
if (child_bterm->getIoType() == dbIoType::OUTPUT
560+
|| child_bterm->getIoType() == dbIoType::INOUT) {
561+
drvr_info_list.push_back(
562+
// NOLINTNEXTLINE(misc-include-cleaner)
563+
fmt::format("\n - moditerm: '{}'",
564+
moditerm->getHierarchicalName()));
565+
}
566+
}
567+
}
568+
569+
size_t drvr_count = drvr_info_list.size();
570+
if (drvr_count > 1) {
571+
// Multiple drivers found.
572+
logger->warn(utl::ODB,
573+
481, // Reusing error code from dbNet
574+
"SanityCheck: dbModNet '{}' has multiple drivers: {}",
575+
getHierarchicalName(),
576+
fmt::join(drvr_info_list, ""));
577+
}
578+
579+
const uint term_count = connectionCount();
580+
581+
// No driver
582+
if (drvr_count == 0 && term_count > 0) {
583+
logger->warn(utl::ODB,
584+
482,
585+
"SanityCheck: dbModNet '{}' has no driver.",
586+
getHierarchicalName());
587+
}
588+
589+
const uint iterm_count = getITerms().size();
590+
const uint bterm_count = getBTerms().size();
591+
const uint moditerm_count = getModITerms().size();
592+
const uint modbterm_count = getModBTerms().size();
593+
594+
if (term_count < 2) {
595+
// A net connected to 1 terminal
596+
if (iterm_count == 1
597+
&& (*(getITerms().begin()))->getIoType() == dbIoType::OUTPUT) {
598+
return; // OK: Unconnected output pin
599+
}
600+
if (bterm_count == 1
601+
&& (*(getBTerms().begin()))->getIoType() == dbIoType::INPUT) {
602+
return; // OK: Unconnected input port
603+
}
604+
if (moditerm_count == 1) {
605+
dbModITerm* moditerm = *(getModITerms().begin());
606+
if (dbModBTerm* child_bterm = moditerm->getChildModBTerm()) {
607+
if (child_bterm->getIoType() == dbIoType::OUTPUT) {
608+
return; // OK: Unconnected output pin on module instance
609+
}
610+
}
611+
}
612+
if (modbterm_count == 1) {
613+
dbModBTerm* modbterm = *(getModBTerms().begin());
614+
if (modbterm->getIoType() == dbIoType::INPUT) {
615+
return; // OK: Unconnected input port on module
616+
}
617+
}
618+
619+
logger->warn(utl::ODB,
620+
483,
621+
"SanityCheck: dbModNet '{}' is dangling. It has less than 2 "
622+
"connections (# of ITerms = {}, # of BTerms = {}, # of "
623+
"ModITerms = {}, # of ModBTerms = {}).",
624+
getHierarchicalName(),
625+
iterm_count,
626+
bterm_count,
627+
moditerm_count,
628+
modbterm_count);
629+
}
630+
}
631+
493632
// User Code End dbModNetPublicMethods
494633
} // namespace odb
495634
// Generator Code End Cpp

src/odb/src/db/dbNet.cpp

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -2348,8 +2348,7 @@ void dbNet::setJumpers(bool has_jumpers)
23482348

23492349
void dbNet::checkSanity() const
23502350
{
2351-
_dbNet* net = (_dbNet*) this;
2352-
utl::Logger* logger = net->getImpl()->getLogger();
2351+
utl::Logger* logger = getImpl()->getLogger();
23532352
std::vector<std::string> drvr_info_list;
23542353

23552354
// Find BTerm drivers
@@ -2358,12 +2357,11 @@ void dbNet::checkSanity() const
23582357
|| bterm->getIoType() == dbIoType::INOUT) {
23592358
dbBlock* block = bterm->getBlock();
23602359
dbModule* parent_module = block->getTopModule();
2361-
drvr_info_list.push_back(
2362-
// NOLINTNEXTLINE(misc-include-cleaner)
2363-
fmt::format("\n - bterm: '{}' (parent_module: '{}', block: '{}')",
2364-
bterm->getName(),
2365-
parent_module->getName(),
2366-
block->getName()));
2360+
drvr_info_list.push_back(fmt::format( // NOLINT(misc-include-cleaner)
2361+
"\n - bterm: '{}' (block: '{}', parent_module: '{}')",
2362+
bterm->getName(),
2363+
(block) ? block->getConstName() : "null",
2364+
(parent_module) ? parent_module->getName() : "null"));
23672365
}
23682366
}
23692367

@@ -2375,28 +2373,12 @@ void dbNet::checkSanity() const
23752373
dbMaster* master = inst->getMaster();
23762374
dbModule* parent_module = inst->getModule();
23772375
dbBlock* block = inst->getBlock();
2378-
2379-
std::string parent_module_name = "null";
2380-
if (parent_module) {
2381-
parent_module_name = parent_module->getName();
2382-
}
2383-
2384-
std::string master_name = "null";
2385-
if (master) {
2386-
master_name = master->getName();
2387-
}
2388-
2389-
std::string block_name = "null";
2390-
if (block) {
2391-
block_name = block->getName();
2392-
}
2393-
23942376
drvr_info_list.push_back(fmt::format( // NOLINT(misc-include-cleaner)
23952377
"\n - iterm: '{}' (block: '{}', parent_module: '{}', master: '{}')",
2396-
iterm->getName('/'),
2397-
block_name,
2398-
parent_module_name,
2399-
master_name));
2378+
iterm->getName(),
2379+
(block) ? block->getConstName() : "null",
2380+
(parent_module) ? parent_module->getName() : "null",
2381+
(master) ? master->getConstName() : "null"));
24002382
}
24012383
}
24022384

@@ -2414,6 +2396,7 @@ void dbNet::checkSanity() const
24142396
const uint iterm_count = getITerms().size();
24152397
const uint bterm_count = getBTerms().size();
24162398

2399+
// No driver
24172400
if (drvr_count == 0 && (iterm_count + bterm_count > 0)) {
24182401
logger->warn(
24192402
utl::ODB, 50, "SanityCheck: dbNet '{}' has no driver.", getName());
@@ -2434,6 +2417,7 @@ void dbNet::checkSanity() const
24342417
&& (*(getBTerms().begin()))->getIoType() == dbIoType::INPUT) {
24352418
return; // OK: Unconnected input port
24362419
}
2420+
24372421
logger->warn(utl::ODB,
24382422
51,
24392423
"SanityCheck: dbNet '{}' is dangling. It has less than 2 "

0 commit comments

Comments
 (0)