Skip to content

Commit 66a6e91

Browse files
committed
odb: add test_undo_mod_inst_destroy test and properly restore the group
Signed-off-by: Matt Liberty <mliberty@precisioninno.com>
1 parent 7ae18b5 commit 66a6e91

5 files changed

Lines changed: 57 additions & 19 deletions

File tree

src/odb/include/odb/db.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8056,6 +8056,7 @@ class dbModInst : public dbObject
80568056
dbModule* masterModule,
80578057
const char* name);
80588058

8059+
// This destroys this modinst but does not destroy the master dbModule.
80598060
static void destroy(dbModInst* modinst);
80608061

80618062
static dbSet<dbModInst>::iterator destroy(dbSet<dbModInst>::iterator& itr);

src/odb/src/db/dbInst.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,24 +1395,15 @@ void dbInst::destroy(dbInst* inst_)
13951395
cb->inDbITermDestroy((dbITerm*) _iterm);
13961396
}
13971397

1398-
dbModule* module = inst_->getModule();
1399-
if (module) {
1400-
((_dbModule*) module)->_dbinst_hash.erase(inst_->getName());
1401-
}
1402-
14031398
dbProperty::destroyProperties(_iterm);
14041399
block->_iterm_tbl->destroy(_iterm);
14051400
inst->_iterms.pop_back();
14061401
}
14071402

1408-
// Move this part after inDbInstDestroy
1409-
// ----------------------------------------
1410-
// _dbMaster * master = (_dbMaster *) inst_->getMaster();
1411-
// _dbInstHdr * inst_hdr = block->_inst_hdr_hash.find(master->_id);
1412-
// inst_hdr->_inst_cnt--;
1413-
//
1414-
// if ( inst_hdr->_inst_cnt == 0 )
1415-
// dbInstHdr::destroy( (dbInstHdr *) inst_hdr );
1403+
dbModule* module = inst_->getModule();
1404+
if (module) {
1405+
((_dbModule*) module)->_dbinst_hash.erase(inst_->getName());
1406+
}
14161407

14171408
if (block->_journal) {
14181409
debugPrint(block->getImpl()->getLogger(),
@@ -1443,7 +1434,6 @@ void dbInst::destroy(dbInst* inst_)
14431434
region->removeInst(inst_);
14441435
}
14451436

1446-
dbModule* module = inst_->getModule();
14471437
if (module) {
14481438
((_dbModule*) module)->removeInst(inst_);
14491439
}

src/odb/src/db/dbJournal.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1912,15 +1912,20 @@ void dbJournal::undo_deleteObject()
19121912
uint obj_id;
19131913
uint master_module_id;
19141914
uint parent_module_id;
1915+
uint group_id;
19151916
_log.pop(name);
19161917
_log.pop(obj_id);
19171918
_log.pop(parent_module_id);
19181919
_log.pop(master_module_id);
1920+
_log.pop(group_id);
19191921
dbModule* parent_module = dbModule::getModule(_block, parent_module_id);
19201922
dbModule* master_module = dbModule::getModule(_block, master_module_id);
19211923
auto mod_inst
19221924
= dbModInst::create(parent_module, master_module, name.c_str());
1923-
(void) mod_inst;
1925+
if (group_id != 0) {
1926+
auto group = dbGroup::getGroup(_block, group_id);
1927+
group->addModInst(mod_inst);
1928+
}
19241929
break;
19251930
}
19261931

src/odb/src/db/dbModInst.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,10 +269,6 @@ void dbModInst::destroy(dbModInst* modinst)
269269
prev = c;
270270
cur = c->_module_next;
271271
}
272-
// unlink from parent end
273-
if (_modinst->_group) {
274-
modinst->getGroup()->removeModInst(modinst);
275-
}
276272

277273
dbProperty::destroyProperties(_modinst);
278274

@@ -284,9 +280,15 @@ void dbModInst::destroy(dbModInst* modinst)
284280
_block->_journal->pushParam(modinst->getId());
285281
_block->_journal->pushParam(_module->getId());
286282
_block->_journal->pushParam(_master->getId());
283+
_block->_journal->pushParam(_modinst->_group);
287284
_block->_journal->endAction();
288285
}
289286

287+
// unlink from parent end
288+
if (_modinst->_group) {
289+
modinst->getGroup()->removeModInst(modinst);
290+
}
291+
290292
_dbModule* _parent = (_dbModule*) (modinst->getParent());
291293
_parent->_modinst_hash.erase(modinst->getName());
292294
_block->_modinst_tbl->destroy(_modinst);

src/odb/test/cpp/TestJournal.cpp

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,46 @@ BOOST_FIXTURE_TEST_CASE(test_undo_inst_destroy, F_DEFAULT)
6464
BOOST_TEST(inst->getRegion() == region);
6565
}
6666

67+
BOOST_FIXTURE_TEST_CASE(test_undo_mod_inst_destroy, F_DEFAULT)
68+
{
69+
auto flat_net = dbNet::create(block, "n");
70+
// Make module and contents
71+
auto module = dbModule::create(block, "test");
72+
auto mod_net = dbModNet::create(module, "lower_net");
73+
auto mod_bterm = dbModBTerm::create(module, "bterm");
74+
mod_bterm->connect(mod_net);
75+
auto leaf_inst = dbInst::create(block, and2, "i1", false, module);
76+
auto iterm = leaf_inst->findITerm("b");
77+
iterm->connect(flat_net, mod_net);
78+
79+
// Instantiate the module and connect it
80+
auto top = block->getTopModule();
81+
dbModNet* top_net = dbModNet::create(top, "top_net");
82+
auto inst = dbModInst::create(top, module, "mod_inst");
83+
auto mod_iterm = dbModITerm::create(inst, "b", mod_bterm);
84+
mod_iterm->connect(top_net);
85+
86+
auto group = dbGroup::create(block, "g");
87+
group->addModInst(inst);
88+
89+
in_eco([&]() {
90+
dbModInst::destroy(inst);
91+
BOOST_TEST(block->getModInsts().size() == 0);
92+
});
93+
94+
BOOST_TEST(block->findModInst("mod_inst") == inst);
95+
BOOST_TEST(inst->getGroup() == group);
96+
BOOST_TEST(inst->getParent() == top);
97+
BOOST_TEST(inst->getMaster() == module);
98+
BOOST_TEST(inst->getModITerms().size() == 1);
99+
BOOST_TEST(*inst->getModITerms().begin() == mod_iterm);
100+
BOOST_TEST(mod_iterm->getModNet() == top_net);
101+
BOOST_TEST(block->getInsts().size() == 1);
102+
BOOST_TEST(*block->getInsts().begin() == leaf_inst);
103+
BOOST_TEST(block->getModInsts().size() == 1);
104+
BOOST_TEST(*block->getModInsts().begin() == inst);
105+
}
106+
67107
BOOST_FIXTURE_TEST_CASE(test_undo_net_create, F_DEFAULT)
68108
{
69109
in_eco([&]() {

0 commit comments

Comments
 (0)