Skip to content

Commit 6bb3a0b

Browse files
committed
Refactored. Moved common functions to dbUtil.h
Signed-off-by: Jaehyun Kim <[email protected]>
1 parent 151e7b9 commit 6bb3a0b

File tree

3 files changed

+226
-208
lines changed

3 files changed

+226
-208
lines changed

src/odb/src/db/dbModNet.cpp

Lines changed: 6 additions & 132 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include "dbModule.h"
1616
#include "dbTable.h"
1717
#include "dbTable.hpp"
18+
#include "dbUtil.h"
1819
#include "dbVector.h"
1920
#include "odb/db.h"
2021
// User Code Begin Includes
@@ -493,140 +494,13 @@ dbNet* dbModNet::findRelatedNet() const
493494

494495
void dbModNet::checkSanity() const
495496
{
496-
utl::Logger* logger = getImpl()->getLogger();
497497
std::vector<std::string> drvr_info_list;
498+
dbUtil::findBTermDrivers(this, drvr_info_list);
499+
dbUtil::findITermDrivers(this, drvr_info_list);
500+
dbUtil::findModBTermDrivers(this, drvr_info_list);
501+
dbUtil::findModITermDrivers(this, drvr_info_list);
498502

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-
}
503+
dbUtil::checkNetSanity(this, drvr_info_list);
630504
}
631505

632506
// User Code End dbModNetPublicMethods

src/odb/src/db/dbNet.cpp

Lines changed: 4 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include "dbTable.hpp"
4141
#include "dbTech.h"
4242
#include "dbTechNonDefaultRule.h"
43+
#include "dbUtil.h"
4344
#include "dbWire.h"
4445
#include "odb/db.h"
4546
#include "odb/dbBlockCallBackObj.h"
@@ -2348,84 +2349,11 @@ void dbNet::setJumpers(bool has_jumpers)
23482349

23492350
void dbNet::checkSanity() const
23502351
{
2351-
utl::Logger* logger = getImpl()->getLogger();
23522352
std::vector<std::string> drvr_info_list;
2353+
dbUtil::findBTermDrivers(this, drvr_info_list);
2354+
dbUtil::findITermDrivers(this, drvr_info_list);
23532355

2354-
// Find BTerm drivers
2355-
for (dbBTerm* bterm : getBTerms()) {
2356-
if (bterm->getIoType() == dbIoType::INPUT
2357-
|| bterm->getIoType() == dbIoType::INOUT) {
2358-
dbBlock* block = bterm->getBlock();
2359-
dbModule* parent_module = block->getTopModule();
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"));
2365-
}
2366-
}
2367-
2368-
// Find ITerm drivers
2369-
for (dbITerm* iterm : getITerms()) {
2370-
if (iterm->getIoType() == dbIoType::OUTPUT
2371-
|| iterm->getIoType() == dbIoType::INOUT) {
2372-
dbInst* inst = iterm->getInst();
2373-
dbMaster* master = inst->getMaster();
2374-
dbModule* parent_module = inst->getModule();
2375-
dbBlock* block = inst->getBlock();
2376-
drvr_info_list.push_back(fmt::format( // NOLINT(misc-include-cleaner)
2377-
"\n - iterm: '{}' (block: '{}', parent_module: '{}', master: '{}')",
2378-
iterm->getName(),
2379-
(block) ? block->getConstName() : "null",
2380-
(parent_module) ? parent_module->getName() : "null",
2381-
(master) ? master->getConstName() : "null"));
2382-
}
2383-
}
2384-
2385-
size_t drvr_count = drvr_info_list.size();
2386-
if (drvr_count > 1) {
2387-
// Multiple drivers found.
2388-
logger->error(
2389-
utl::ODB,
2390-
49,
2391-
"SanityCheck: dbNet '{}' has multiple drivers: {}",
2392-
getName(),
2393-
fmt::join(drvr_info_list, "")); // NOLINT(misc-include-cleaner)
2394-
}
2395-
2396-
const uint iterm_count = getITerms().size();
2397-
const uint bterm_count = getBTerms().size();
2398-
2399-
// No driver
2400-
if (drvr_count == 0 && (iterm_count + bterm_count > 0)) {
2401-
logger->warn(
2402-
utl::ODB, 50, "SanityCheck: dbNet '{}' has no driver.", getName());
2403-
}
2404-
2405-
if (iterm_count + bterm_count < 2) {
2406-
// Skip power/ground net
2407-
if (getSigType().isSupply()) {
2408-
return; // OK: Unconnected power/ground net
2409-
}
2410-
2411-
// A net connected to 1 terminal
2412-
if (iterm_count == 1
2413-
&& (*(getITerms().begin()))->getIoType() == dbIoType::OUTPUT) {
2414-
return; // OK: Unconnected output pin
2415-
}
2416-
if (bterm_count == 1
2417-
&& (*(getBTerms().begin()))->getIoType() == dbIoType::INPUT) {
2418-
return; // OK: Unconnected input port
2419-
}
2420-
2421-
logger->warn(utl::ODB,
2422-
51,
2423-
"SanityCheck: dbNet '{}' is dangling. It has less than 2 "
2424-
"connections (# of ITerms = {}, # of BTerms = {}).",
2425-
getName(),
2426-
iterm_count,
2427-
bterm_count);
2428-
}
2356+
dbUtil::checkNetSanity(this, drvr_info_list);
24292357
}
24302358

24312359
dbModInst* dbNet::findMainParentModInst() const

0 commit comments

Comments
 (0)