Skip to content

Commit

Permalink
fix for delete modInst
Browse files Browse the repository at this point in the history
  • Loading branch information
andyfox-rushc committed Jan 8, 2024
1 parent 10c0a0e commit 3242ce0
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 9 deletions.
1 change: 1 addition & 0 deletions src/odb/include/odb/db.h
Original file line number Diff line number Diff line change
Expand Up @@ -7645,6 +7645,7 @@ class dbModule : public dbObject
dbSet<dbModInst> getChildren();

dbModInst* findModInst(const char* name);
void removeModInst(const char* name);
dbInst* findDbInst(const char* name);

std::vector<dbInst*> getLeafInsts();
Expand Down
3 changes: 1 addition & 2 deletions src/odb/include/odb/dbStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,6 @@ class dbOStream
return *this;
}


template <class T1>
dbOStream& operator<<(const std::vector<T1>& m)
{
Expand Down Expand Up @@ -242,7 +241,7 @@ class dbOStream
*this << (uint32_t) v.index();
*this << std::get<I>(v);
}
return ((*this).operator<< <I + 1>(v));
return ((*this).operator<<<I + 1>(v));
}
}

Expand Down
12 changes: 6 additions & 6 deletions src/odb/src/db/dbBlock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4096,7 +4096,7 @@ void dbBlock::dumpDebug()
printf("module table %d\n", block->_module_tbl->size());
std::vector<odb::_dbModule*> contents;
block->_module_tbl->getObjects(contents);
printf("Content size %d modules\n", contents.size());
printf("Content size %lu modules\n", contents.size());

for (auto mi : contents) {
odb::_dbModule* cur_obj = mi;
Expand Down Expand Up @@ -4170,7 +4170,7 @@ void dbBlock::dumpDebug()
printf("\t\tDb instances ---\n");

printf("\tModule nets (modnets) +++ \n");
printf("\t# nets %d\n", cur_obj->_modnet_map.size());
printf("\t# nets %lu\n", cur_obj->_modnet_map.size());
for (auto mn : cur_obj->_modnet_map) {
dbId<dbModNet> mn_el = mn.second;
printf("\t\tNet: %s (%u)\n", mn.first.c_str(), mn_el.id());
Expand All @@ -4183,10 +4183,10 @@ void dbBlock::dumpDebug()
= ((_dbModNet*) mod_net)->_modbterms;
dbVector<dbId<_dbITerm>> iterms = ((_dbModNet*) mod_net)->_iterms;
dbVector<dbId<_dbBTerm>> bterms = ((_dbModNet*) mod_net)->_bterms;
printf("\t\t -> %u moditerms\n", moditerms.size());
printf("\t\t -> %u modbterms\n", modbterms.size());
printf("\t\t -> %u iterms\n", iterms.size());
printf("\t\t -> %u bterms\n", bterms.size());
printf("\t\t -> %lu moditerms\n", moditerms.size());
printf("\t\t -> %lu modbterms\n", modbterms.size());
printf("\t\t -> %lu iterms\n", iterms.size());
printf("\t\t -> %lu bterms\n", bterms.size());

/*
dbVector<dbId<_dbITerm> >::iterator it_iter;
Expand Down
2 changes: 1 addition & 1 deletion src/odb/src/db/dbDatabase.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const uint db_schema_major = 0; // Not used...
const uint db_schema_initial = 57;
const uint db_schema_minor = 78; // Current revision number

// Revision where verilog hierarchy supported
// Revision where verilog hierarchy supported
const uint db_schema_vhierarchy = 78;

const uint db_schema_level_shifter_cell = 77;
Expand Down
10 changes: 10 additions & 0 deletions src/odb/src/db/dbModInst.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,12 @@ dbModInst* dbModInst::create(dbModule* parentModule,
if (master->_mod_inst != 0)
return nullptr;

dbModInst* ret = nullptr;
ret = ((dbModule*) module)->findModInst(name);
if (ret) {
return nullptr;
}

_dbModInst* modinst = block->_modinst_tbl->create();
modinst->_name = strdup(name);
ZALLOCATED(modinst->_name);
Expand All @@ -242,6 +248,7 @@ dbModInst* dbModInst::create(dbModule* parentModule,
module->_modinsts = modinst->getOID();
master->_mod_inst = modinst->getOID();
module->_modinst_vec.push_back(modinst->getOID());
block->_modinst_hash.insert(modinst);
return (dbModInst*) modinst;
}

Expand All @@ -251,6 +258,9 @@ void dbModInst::destroy(dbModInst* modinst)
_dbBlock* block = (_dbBlock*) _modinst->getOwner();
_dbModule* module = (_dbModule*) modinst->getParent();

// remove from module vector
modinst->getParent()->removeModInst(modinst->getName());

_dbModule* master = (_dbModule*) modinst->getMaster();
master->_mod_inst = dbId<_dbModInst>(); // clear
dbModule::destroy((dbModule*) master);
Expand Down
18 changes: 18 additions & 0 deletions src/odb/src/db/dbModule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -524,6 +524,24 @@ dbModule* dbModule::getModule(dbBlock* block_, uint dbid_)
return (dbModule*) block->_module_tbl->getPtr(dbid_);
}

void dbModule::removeModInst(const char* name)
{
_dbModule* cur_module = (_dbModule*) this;
_dbBlock* block = (_dbBlock*) cur_module->getOwner();
for (std::vector<odb::dbId<odb::dbModInst>>::iterator it
= cur_module->_modinst_vec.begin();
it != cur_module->_modinst_vec.end();
it++) {
unsigned id = (*it).id();
dbId<_dbModInst> converted_el(id);
dbModInst* mi = (dbModInst*) (block->_modinst_tbl->getPtr(converted_el));
if (mi && !strcmp(mi->getName(), name)) {
cur_module->_modinst_vec.erase(it);
return;
}
}
}

dbModInst* dbModule::findModInst(const char* name)
{
_dbModule* cur_module = (_dbModule*) this;
Expand Down

0 comments on commit 3242ce0

Please sign in to comment.