diff --git a/.gitignore b/.gitignore index 67853076..a250f1a6 100644 --- a/.gitignore +++ b/.gitignore @@ -26,11 +26,18 @@ *.a *.lib +# Logs +*.log + # Executables *.exe *.out *.app +# python cache +__pycache__/ +*.py[cod] + # build build lbuild diff --git a/include/opendb/db.h b/include/opendb/db.h index 2a2cee30..239e6533 100644 --- a/include/opendb/db.h +++ b/include/opendb/db.h @@ -71,9 +71,8 @@ class dbStringProperty; class dbIntProperty; class dbDoubleProperty; -//Generator Code Begin 1 -//Generator Code End 1 - +// Generator Code Begin 1 +// Generator Code End 1 // Design objects class dbChip; @@ -100,9 +99,10 @@ class dbTechAntennaPinModel; class dbBlockCallBackObj; class dbRegion; class dbBPin; -//Generator Code Begin 2 -//Generator Code End 2 - +// Generator Code Begin 2 +class dbModule; +class dbModInst; +// Generator Code End 2 // Lib objects class dbLib; @@ -111,8 +111,8 @@ class dbMaster; class dbMTerm; class dbMPin; class dbTarget; -//Generator Code Begin 3 -//Generator Code End 3 +// Generator Code Begin 3 +// Generator Code End 3 // Tech objects class dbTech; @@ -129,8 +129,8 @@ class dbTechMinCutRule; class dbTechMinEncRule; class dbTechV55InfluenceEntry; class dbTechSameNetRule; -//Generator Code Begin 4 -//Generator Code End 4 +// Generator Code Begin 4 +// Generator Code End 4 class dbViaParams; @@ -518,13 +518,11 @@ class dbBox : public dbObject uint getWidth(uint dir = 1); uint getLength(uint dir = 1); - /// /// Get GeomShape Interface /// GeomShape* getGeomShape(); - /// /// Set temporary flag visited /// @@ -684,7 +682,7 @@ class dbSBox : public dbBox /// Get Oct Wire Shape /// Oct getOct(); - + /// /// Add a rect to a dbSWire. /// @@ -709,7 +707,7 @@ class dbSBox : public dbBox int x2, int y2, dbWireShapeType type, - Direction dir = UNDEFINED, + Direction dir = UNDEFINED, int width = 0); /// @@ -849,12 +847,28 @@ class dbBlock : public dbObject /// dbSet getInsts(); + /// + /// Get the modules of this block. + /// + dbSet getModules(); + + /// + /// Get the modinsts of this block. + /// + dbSet getModInsts(); + /// /// Find a specific instance of this block. /// Returns NULL if the object was not found. /// dbInst* findInst(const char* name); + /// + /// Find a specific module in this block. + /// Returns NULL if the object was not found. + /// + dbModule* findModule(const char* name); + /// /// Find a set of insts. Each name can be real name, or Ixxx, or xxx, /// where xxx is the inst oid. @@ -2922,6 +2936,12 @@ class dbInst : public dbObject /// dbRegion* getRegion(); + /// + /// Get the module this instance belongs to. Returns NULL if instance has no + /// assigned module. + /// + dbModule* getModule(); + /// /// Find the iterm of the given terminal name. /// Returns NULL if no terminal was found. @@ -3627,7 +3647,6 @@ class dbWire : public dbObject /// void detach(); - /// /// Copy the src wire to the desintation wire. /// @@ -3741,7 +3760,6 @@ class dbSWire : public dbObject /// Translate a database-id back to a pointer. /// static dbSWire* getSWire(dbBlock* block, uint oid); - }; /////////////////////////////////////////////////////////////////////////////// @@ -3876,7 +3894,7 @@ class dbTrackGrid : public dbObject /// Translate a database-id back to a pointer. /// static dbTrackGrid* getTrackGrid(dbBlock* block, uint oid); - + /// /// destroy a grid /// @@ -7120,7 +7138,55 @@ class dbViaParams : private _dbViaParams void setBottomLayer(dbTechLayer* layer); }; -//Generator Code Begin 5 -//Generator Code End 5 +// Generator Code Begin 5 + +class dbModule : public dbObject +{ + public: + char* getName() const; + + dbModInst* getModInst() const; + + // User Code Begin dbModule + void addInst(dbInst* inst); + + void removeInst(dbInst* inst); + + dbSet getInsts(); + + dbSet getChildren(); + + dbModInst* findModInst(const char* name); + + static dbModule* create(dbBlock* block, const char* name); + + static void destroy(dbModule* module); + + dbModule* getModule(dbBlock* block_, uint dbid_); + + // User Code End dbModule +}; + +class dbModInst : public dbObject +{ + public: + dbModule* getParent() const; + + dbModule* getMaster() const; + + // User Code Begin dbModInst + static dbModInst* create(dbModule* parentModule, + dbModule* masterModule, + const char* name); + + static void destroy(dbModInst* modinst); + + static dbSet::iterator destroy(dbSet::iterator& itr); + + char* getName() const; + // User Code End dbModInst +}; + +// Generator Code End 5 } // namespace odb diff --git a/include/opendb/dbObject.h b/include/opendb/dbObject.h index ce164bed..49ef1e5c 100644 --- a/include/opendb/dbObject.h +++ b/include/opendb/dbObject.h @@ -87,8 +87,10 @@ enum dbObjectType dbRegionObj, dbHierObj, dbBPinObj, - //Generator Code Begin 1 - //Generator Code End 1 + // Generator Code Begin 1 + dbModuleObj, + dbModInstObj, + // Generator Code End 1 // Lib Objects dbLibObj, diff --git a/src/codeGenerator/README.md b/src/codeGenerator/README.md index 84ab1a59..b7de46a1 100644 --- a/src/codeGenerator/README.md +++ b/src/codeGenerator/README.md @@ -3,7 +3,7 @@ This is an automatic code generation tool for OpenDB objects and Iterators. To test the tool you can use the following command ```bash -python3 gen.py --json schema.json --src_dir ../db --include_dir ../../include --impl impl +python3 gen.py --json schema-verilog.json --src_dir ../db --include_dir ../../include/opendb --impl impl ``` Where schema.json is the json file that includes the requirements, src is the source files directory, include is the include directory, and impl is the directory including the jinja templates for the classes. \ No newline at end of file diff --git a/src/codeGenerator/gen.py b/src/codeGenerator/gen.py index 8bf0597d..2cc1d112 100755 --- a/src/codeGenerator/gen.py +++ b/src/codeGenerator/gen.py @@ -81,7 +81,7 @@ inParentField['table'] = True inParentField['dbSetGetter'] = True inParentField['components'] = [inParentField['name']] - inParentField['flags'] = ["cmp","serial", "diff", "set", "get"] + inParentField['flags'] = ["cmp","serial", "diff", "no-set", "get"] schema['classes'][parent]['fields'].append(inParentField) schema['classes'][parent]['cpp_includes'].extend([ @@ -118,9 +118,10 @@ field['isHashTable'] = isHashTable(field['type']) field['hashTableType'] = getHashTableType(field['type']) - # Check if a class is being used inside a template definition to add to the list of forward declared classes - + #### + #### This needs documentation + #### templateClassName = None tmp = getTemplateType(field['type']) while tmp is not None: @@ -131,9 +132,9 @@ if templateClassName is not None: if templateClassName not in klass['classes'] and klass['name'] != templateClassName[1:]: klass['classes'].append(templateClassName) - - - + #### + #### + #### if field.get('table', False): if field['type'].startswith('db'): field['functional_name'] = '{}s'.format(field['type'][2:]) diff --git a/src/codeGenerator/helper.py b/src/codeGenerator/helper.py index d1f5af22..b3124e7c 100644 --- a/src/codeGenerator/helper.py +++ b/src/codeGenerator/helper.py @@ -15,7 +15,9 @@ 'long', 'long long', 'long double', - 'char*' + 'char *', + 'char*', + 'char' ] removable = [ @@ -39,7 +41,7 @@ def getStruct(name, structs): return None def components(structs, name, _type): - if(stem(_type) in comparable): + if(stem(_type) in comparable or isRef(_type)): return [name] idx = 0; absType = _type.rstrip(' *') @@ -124,8 +126,6 @@ def isTemplateType(type_name): def getTemplateType(type_name): if isTemplateType(type_name) == False: return None - - numBrackets = 1 openBracket = type_name.find("<") diff --git a/src/codeGenerator/impl/db.h b/src/codeGenerator/impl/db.h index 3260ffd9..342f3c0f 100644 --- a/src/codeGenerator/impl/db.h +++ b/src/codeGenerator/impl/db.h @@ -15,13 +15,13 @@ class {{klass.name}} : public dbObject {%endif%} {%if 'no-get' not in field.flags%} - {{field.getterReturnType}} {{field.getterFunctionName}}() const; - - {%endif%} {%if field.dbSetGetter%} dbSet<{{field.type}}> get{{field.functional_name}}() const; - + {%else%} + {{field.getterReturnType}} {{field.getterFunctionName}}() const; + {%endif%} {%endif%} + {%endfor%} diff --git a/src/codeGenerator/impl/impl.cpp b/src/codeGenerator/impl/impl.cpp index acb65676..6fb2b37f 100755 --- a/src/codeGenerator/impl/impl.cpp +++ b/src/codeGenerator/impl/impl.cpp @@ -327,40 +327,31 @@ namespace odb { {%endif%} {%if 'no-get' not in field.flags%} + {%if field.dbSetGetter%} + dbSet<{{field.type}}> {{klass.name}}::get{{field.functional_name}}() const + { + _{{klass.name}}* obj = (_{{klass.name}}*)this; + return dbSet<{{field.type}}>(obj, obj->{{field.name}}); + } + {%else%} {{field.getterReturnType}} {{klass.name}}::{{field.getterFunctionName}}({%if field.isHashTable%}const char* name{%endif%}) const { _{{klass.name}}* obj = (_{{klass.name}}*)this; - {%if field.isRef%} - - _{{field.parent}} par = (_{{field.parent}}*) obj->getOwner(); if(obj->{{field.name}} == 0) return NULL; - return ({{field.refType}}) par->_{{field.refType[2:-1].lower()}}_tbl->getPtr(obj->{{field.name}}) - - + _{{field.parent}}* par = (_{{field.parent}}*) obj->getOwner(); + return ({{field.refType}}) par->_{{field.refType[2:-1].lower()}}_tbl->getPtr(obj->{{field.name}}); {%elif field.isHashTable%} - return {{field.getterReturnType}} obj->{{field.name}}.find(name); - - {%else%} - - return obj->{{field.name}}; - - {%endif%} } {%endif%} - - {%if field.dbSetGetter%} - dbSet<{{field.type}}> {{klass.name}}::get{{field.functional_name}}() const - { - _{{klass.name}}* obj = (_{{klass.name}}*)this; - return dbSet<{{field.type}}>(obj, obj->{{field.name}}); - } {%endif%} + + {%endfor%} diff --git a/src/codeGenerator/impl/impl.h b/src/codeGenerator/impl/impl.h index 34a1da0b..d5cadcd6 100755 --- a/src/codeGenerator/impl/impl.h +++ b/src/codeGenerator/impl/impl.h @@ -50,6 +50,9 @@ namespace odb { class dbDiff; class _dbDatabase; {% for _class in klass.classes %} + {%if _class=="dbTable"%} + template + {%endif%} class {{ _class }}; {% endfor %} //User Code Begin Classes diff --git a/src/codeGenerator/schema-verilog.json b/src/codeGenerator/schema-verilog.json new file mode 100644 index 00000000..8caa2495 --- /dev/null +++ b/src/codeGenerator/schema-verilog.json @@ -0,0 +1,98 @@ +{ + "classes": [ + { + "name":"dbModule", + "type":"dbObject", + "fields":[ + { + "name":"_name", + "type":"char *", + "flags":["no-set"] + }, + { + "name":"_next_entry", + "type":"dbId<_dbModule>", + "flags":["no-set","no-get"] + }, + { + "name":"_insts", + "type":"dbId<_dbInst>", + "flags":["no-set","no-get"], + "parent":"dbBlock" + }, + { + "name":"_modinsts", + "type":"dbId<_dbModInst>", + "flags":["no-set","no-get"], + "parent":"dbBlock" + }, + { + "name":"_mod_inst", + "type":"dbId<_dbModInst>", + "flags":["no-set"], + "parent":"dbBlock" + } + ], + "constructors":[], + "cpp_includes":["dbBlock.h","dbHashTable.hpp"] + }, + { + "name":"dbModInst", + "type":"dbObject", + "fields":[ + { + "name":"_name", + "type":"char *", + "flags":["no-set","no-get"] + }, + { + "name":"_next_entry", + "type":"dbId<_dbModInst>", + "flags":["no-set","no-get"] + }, + { + "name":"_parent", + "type":"dbId<_dbModule>", + "flags":["no-set"], + "parent":"dbBlock" + }, + { + "name":"_module_next", + "type":"dbId<_dbModInst>", + "flags":["no-get","no-set"], + "parent":"dbBlock" + }, + { + "name":"_master", + "type":"dbId<_dbModule>", + "flags":["no-set"], + "parent":"dbBlock" + } + ], + "constructors":[], + "cpp_includes":["dbBlock.h","dbModule.h","dbHashTable.hpp"] + } + ], + "iterators":[ + { + "name": "dbModuleInstItr", + "parentObject": "dbInst", + "tableName": "inst_tbl", + "reversible": "true", + "orderReversed": "true", + "sequential": 0, + "includes": ["dbModule.h", "dbInst.h", "dbTable.h"] + }, + { + "name": "dbModuleModInstItr", + "parentObject": "dbModInst", + "tableName": "modinst_tbl", + "reversible": "true", + "orderReversed": "true", + "sequential": 0, + "includes": ["dbModule.h", "dbModInst.h", "dbTable.h"] + } + ], + "relations":[ + ] +} \ No newline at end of file diff --git a/src/db/CMakeLists.txt b/src/db/CMakeLists.txt index 5d705661..0b957f8f 100644 --- a/src/db/CMakeLists.txt +++ b/src/db/CMakeLists.txt @@ -96,6 +96,10 @@ add_library(opendb wOrder.cpp Logger.cpp # Generator Code Begin cpp + dbModule.cpp + dbModInst.cpp + dbModuleInstItr.cpp + dbModuleModInstItr.cpp # Generator Code End cpp ) diff --git a/src/db/dbBlock.cpp b/src/db/dbBlock.cpp index 04cdff2f..3a66add4 100644 --- a/src/db/dbBlock.cpp +++ b/src/db/dbBlock.cpp @@ -88,6 +88,10 @@ #include "dbSWireItr.h" #include "dbSearch.h" #include "dbShape.h" +#include "dbModule.h" +#include "dbModuleInstItr.h" +#include "dbModuleModInstItr.h" +#include "dbModInst.h" #include "dbTable.h" #include "dbTable.hpp" #include "dbTech.h" @@ -175,6 +179,14 @@ _dbBlock::_dbBlock(_dbDatabase* db) db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbInstObj); ZALLOCATED(_inst_tbl); + _module_tbl = new dbTable<_dbModule>( + db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbModuleObj); + ZALLOCATED(_module_tbl); + + _modinst_tbl = new dbTable<_dbModInst>( + db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbModInstObj); + ZALLOCATED(_modinst_tbl); + _box_tbl = new dbTable<_dbBox>( db, this, (GetObjTbl_t) &_dbBlock::getObjectTable, dbBoxObj, 1024, 10); ZALLOCATED(_box_tbl); @@ -295,6 +307,8 @@ _dbBlock::_dbBlock(_dbDatabase* db) _net_hash.setTable(_net_tbl); _inst_hash.setTable(_inst_tbl); + _module_hash.setTable(_module_tbl); + _modinst_hash.setTable(_modinst_tbl); _inst_hdr_hash.setTable(_inst_hdr_tbl); _bterm_hash.setTable(_bterm_tbl); @@ -328,6 +342,12 @@ _dbBlock::_dbBlock(_dbDatabase* db) _region_inst_itr = new dbRegionInstItr(_inst_tbl); ZALLOCATED(_region_inst_itr); + _module_inst_itr = new dbModuleInstItr(_inst_tbl); + ZALLOCATED(_module_inst_itr); + + _module_modinst_itr = new dbModuleModInstItr(_modinst_tbl); + ZALLOCATED(_module_modinst_itr); + _bpin_itr = new dbBPinItr(_bpin_tbl); ZALLOCATED(_bpin_itr); @@ -370,6 +390,8 @@ _dbBlock::_dbBlock(_dbDatabase* db, const _dbBlock& block) _parent_inst(block._parent_inst), _net_hash(block._net_hash), _inst_hash(block._inst_hash), + _module_hash(block._module_hash), + _modinst_hash(block._modinst_hash), _inst_hdr_hash(block._inst_hdr_hash), _bterm_hash(block._bterm_hash), _maxCapNodeId(block._maxCapNodeId), @@ -400,6 +422,12 @@ _dbBlock::_dbBlock(_dbDatabase* db, const _dbBlock& block) _inst_tbl = new dbTable<_dbInst>(db, this, *block._inst_tbl); ZALLOCATED(_inst_tbl); + _module_tbl = new dbTable<_dbModule>(db, this, *block._module_tbl); + ZALLOCATED(_module_tbl); + + _modinst_tbl = new dbTable<_dbModInst>(db, this, *block._modinst_tbl); + ZALLOCATED(_modinst_tbl); + _box_tbl = new dbTable<_dbBox>(db, this, *block._box_tbl); ZALLOCATED(_box_tbl); @@ -480,6 +508,8 @@ _dbBlock::_dbBlock(_dbDatabase* db, const _dbBlock& block) _net_hash.setTable(_net_tbl); _inst_hash.setTable(_inst_tbl); + _module_hash.setTable(_module_tbl); + _modinst_hash.setTable(_modinst_tbl); _inst_hdr_hash.setTable(_inst_hdr_tbl); _bterm_hash.setTable(_bterm_tbl); @@ -513,6 +543,12 @@ _dbBlock::_dbBlock(_dbDatabase* db, const _dbBlock& block) _region_inst_itr = new dbRegionInstItr(_inst_tbl); ZALLOCATED(_region_inst_itr); + _module_inst_itr = new dbModuleInstItr(_inst_tbl); + ZALLOCATED(_module_inst_itr); + + _module_modinst_itr = new dbModuleModInstItr(_modinst_tbl); + ZALLOCATED(_module_modinst_itr); + _bpin_itr = new dbBPinItr(_bpin_tbl); ZALLOCATED(_bpin_itr); @@ -544,6 +580,8 @@ _dbBlock::~_dbBlock() delete _net_tbl; delete _inst_hdr_tbl; delete _inst_tbl; + delete _module_tbl; + delete _modinst_tbl; delete _box_tbl; delete _via_tbl; delete _gcell_grid_tbl; @@ -579,6 +617,8 @@ _dbBlock::~_dbBlock() delete _r_seg_itr; delete _cc_seg_itr; delete _region_inst_itr; + delete _module_inst_itr; + delete _module_modinst_itr; delete _bpin_itr; delete _region_itr; delete _prop_itr; @@ -681,6 +721,12 @@ dbObjectTable* _dbBlock::getObjectTable(dbObjectType type) case dbInstObj: return _inst_tbl; + + case dbModuleObj: + return _module_tbl; + + case dbModInstObj: + return _modinst_tbl; case dbNetObj: return _net_tbl; @@ -789,6 +835,8 @@ dbOStream& operator<<(dbOStream& stream, const _dbBlock& block) } stream << block._net_hash; stream << block._inst_hash; + stream << block._module_hash; + stream << block._modinst_hash; stream << block._inst_hdr_hash; stream << block._bterm_hash; stream << block._maxCapNodeId; @@ -808,6 +856,8 @@ dbOStream& operator<<(dbOStream& stream, const _dbBlock& block) stream << *block._net_tbl; stream << *block._inst_hdr_tbl; stream << *block._inst_tbl; + stream << *block._module_tbl; + stream << *block._modinst_tbl; stream << *block._box_tbl; stream << *block._via_tbl; stream << *block._gcell_grid_tbl; @@ -871,6 +921,8 @@ dbIStream& operator>>(dbIStream& stream, _dbBlock& block) stream >> block._parent_inst; stream >> block._net_hash; stream >> block._inst_hash; + stream >> block._module_hash; + stream >> block._modinst_hash; stream >> block._inst_hdr_hash; stream >> block._bterm_hash; stream >> block._maxCapNodeId; @@ -885,6 +937,8 @@ dbIStream& operator>>(dbIStream& stream, _dbBlock& block) stream >> *block._net_tbl; stream >> *block._inst_hdr_tbl; stream >> *block._inst_tbl; + stream >> *block._module_tbl; + stream >> *block._modinst_tbl; stream >> *block._box_tbl; stream >> *block._via_tbl; stream >> *block._gcell_grid_tbl; @@ -1019,6 +1073,12 @@ bool _dbBlock::operator==(const _dbBlock& rhs) const if (_inst_hash != rhs._inst_hash) return false; + if (_module_hash != rhs._module_hash) + return false; + + if (_modinst_hash != rhs._modinst_hash) + return false; + if (_inst_hdr_hash != rhs._inst_hdr_hash) return false; @@ -1060,6 +1120,12 @@ bool _dbBlock::operator==(const _dbBlock& rhs) const if (*_inst_tbl != *rhs._inst_tbl) return false; + + if (*_module_tbl != *rhs._module_tbl) + return false; + + if (*_modinst_tbl != *rhs._modinst_tbl) + return false; if (*_box_tbl != *rhs._box_tbl) return false; @@ -1163,6 +1229,8 @@ void _dbBlock::differences(dbDiff& diff, if (!diff.deepDiff()) { DIFF_HASH_TABLE(_net_hash); DIFF_HASH_TABLE(_inst_hash); + DIFF_HASH_TABLE(_module_hash); + DIFF_HASH_TABLE(_modinst_hash); DIFF_HASH_TABLE(_inst_hdr_hash); DIFF_HASH_TABLE(_bterm_hash); } @@ -1179,6 +1247,8 @@ void _dbBlock::differences(dbDiff& diff, DIFF_TABLE(_net_tbl); DIFF_TABLE_NO_DEEP(_inst_hdr_tbl); DIFF_TABLE(_inst_tbl); + DIFF_TABLE(_module_tbl); + DIFF_TABLE(_modinst_tbl); DIFF_TABLE_NO_DEEP(_box_tbl); DIFF_TABLE(_via_tbl); DIFF_TABLE_NO_DEEP(_gcell_grid_tbl); @@ -1238,6 +1308,8 @@ void _dbBlock::out(dbDiff& diff, char side, const char* field) const if (!diff.deepDiff()) { DIFF_OUT_HASH_TABLE(_net_hash); DIFF_OUT_HASH_TABLE(_inst_hash); + DIFF_OUT_HASH_TABLE(_module_hash); + DIFF_OUT_HASH_TABLE(_modinst_hash); DIFF_OUT_HASH_TABLE(_inst_hdr_hash); DIFF_OUT_HASH_TABLE(_bterm_hash); } @@ -1254,6 +1326,8 @@ void _dbBlock::out(dbDiff& diff, char side, const char* field) const DIFF_OUT_TABLE(_net_tbl); DIFF_OUT_TABLE_NO_DEEP(_inst_hdr_tbl); DIFF_OUT_TABLE(_inst_tbl); + DIFF_OUT_TABLE(_module_tbl); + DIFF_OUT_TABLE(_modinst_tbl); DIFF_OUT_TABLE_NO_DEEP(_box_tbl); DIFF_OUT_TABLE(_via_tbl); DIFF_OUT_TABLE_NO_DEEP(_gcell_grid_tbl); @@ -1464,12 +1538,31 @@ dbSet dbBlock::getInsts() _dbBlock* block = (_dbBlock*) this; return dbSet(block, block->_inst_tbl); } + +dbSet dbBlock::getModules() +{ + _dbBlock* block = (_dbBlock*) this; + return dbSet(block, block->_module_tbl); +} + +dbSet dbBlock::getModInsts() +{ + _dbBlock* block = (_dbBlock*) this; + return dbSet(block, block->_modinst_tbl); +} + dbInst* dbBlock::findInst(const char* name) { _dbBlock* block = (_dbBlock*) this; return (dbInst*) block->_inst_hash.find(name); } +dbModule* dbBlock::findModule(const char* name) +{ + _dbBlock* block = (_dbBlock*) this; + return (dbModule*) block->_module_hash.find(name); +} + dbITerm* dbBlock::findITerm(const char* name) { _dbBlock* block = (_dbBlock*) this; diff --git a/src/db/dbBlock.h b/src/db/dbBlock.h index 5f71ca55..098cea5d 100644 --- a/src/db/dbBlock.h +++ b/src/db/dbBlock.h @@ -88,6 +88,8 @@ class _dbHier; class _dbBPin; class _dbTechLayerRule; class _dbTechNonDefaultRule; +class _dbModule; +class _dbModInst; class dbJournal; class dbNetBTermItr; @@ -95,6 +97,8 @@ class dbBPinItr; class dbNetITermItr; class dbInstITermItr; class dbRegionInstItr; +class dbModuleInstItr; +class dbModuleModInstItr; class dbRegionItr; class dbSWireItr; class dbNameServer; @@ -162,6 +166,8 @@ class _dbBlock : public _dbObject dbId<_dbInst> _parent_inst; // Up hierarchy: TWG dbHashTable<_dbNet> _net_hash; dbHashTable<_dbInst> _inst_hash; + dbHashTable<_dbModule> _module_hash; + dbHashTable<_dbModInst> _modinst_hash; dbIntHashTable<_dbInstHdr> _inst_hdr_hash; dbHashTable<_dbBTerm> _bterm_hash; uint _maxCapNodeId; @@ -195,6 +201,8 @@ class _dbBlock : public _dbObject dbTable<_dbTechNonDefaultRule>* _non_default_rule_tbl; dbTable<_dbTechLayerRule>* _layer_rule_tbl; dbTable<_dbProperty>* _prop_tbl; + dbTable<_dbModule>* _module_tbl; + dbTable<_dbModInst>* _modinst_tbl; _dbNameCache* _name_cache; dbPagedVector* _r_val_tbl; @@ -217,6 +225,8 @@ class _dbBlock : public _dbObject dbRSegItr* _r_seg_itr; dbCCSegItr* _cc_seg_itr; dbRegionInstItr* _region_inst_itr; + dbModuleInstItr* _module_inst_itr; + dbModuleModInstItr* _module_modinst_itr; dbBPinItr* _bpin_itr; dbRegionItr* _region_itr; dbPropertyItr* _prop_itr; diff --git a/src/db/dbInst.cpp b/src/db/dbInst.cpp index 1b0c435a..274bb8e5 100644 --- a/src/db/dbInst.cpp +++ b/src/db/dbInst.cpp @@ -59,6 +59,7 @@ #include "dbTable.h" #include "dbTable.hpp" #include "dbTransform.h" +#include "dbModule.h" namespace odb { @@ -135,7 +136,9 @@ _dbInst::_dbInst(_dbDatabase*, const _dbInst& i) _inst_hdr(i._inst_hdr), _bbox(i._bbox), _region(i._region), + _module(i._module), _region_next(i._region_next), + _module_next(i._module_next), _region_prev(i._region_prev), _hierarchy(i._hierarchy), _iterms(i._iterms), @@ -165,7 +168,9 @@ dbOStream& operator<<(dbOStream& stream, const _dbInst& inst) stream << inst._inst_hdr; stream << inst._bbox; stream << inst._region; + stream << inst._module; stream << inst._region_next; + stream << inst._module_next; stream << inst._region_prev; stream << inst._hierarchy; stream << inst._iterms; @@ -185,7 +190,9 @@ dbIStream& operator>>(dbIStream& stream, _dbInst& inst) stream >> inst._inst_hdr; stream >> inst._bbox; stream >> inst._region; + stream >> inst._module; stream >> inst._region_next; + stream >> inst._module_next; stream >> inst._region_prev; stream >> inst._hierarchy; stream >> inst._iterms; @@ -255,8 +262,14 @@ bool _dbInst::operator==(const _dbInst& rhs) const if (_region != rhs._region) return false; + if (_module != rhs._module) + return false; + if (_region_next != rhs._region_next) return false; + + if (_module_next != rhs._module_next) + return false; if (_region_prev != rhs._region_prev) return false; @@ -298,7 +311,9 @@ void _dbInst::differences(dbDiff& diff, DIFF_FIELD_NO_DEEP(_inst_hdr); DIFF_OBJECT(_bbox, lhs_blk->_box_tbl, rhs_blk->_box_tbl); DIFF_FIELD(_region); + DIFF_FIELD(_module); DIFF_FIELD(_region_next); + DIFF_FIELD(_module_next); DIFF_FIELD(_region_prev); DIFF_FIELD(_hierarchy); DIFF_OBJECT(_halo, lhs_blk->_box_tbl, rhs_blk->_box_tbl); @@ -349,7 +364,9 @@ void _dbInst::out(dbDiff& diff, char side, const char* field) const DIFF_OUT_FIELD_NO_DEEP(_inst_hdr); DIFF_OUT_OBJECT(_bbox, blk->_box_tbl); DIFF_OUT_FIELD(_region); + DIFF_OUT_FIELD(_module); DIFF_OUT_FIELD(_region_next); + DIFF_OUT_FIELD(_module_next); DIFF_OUT_FIELD(_region_prev); DIFF_OUT_FIELD(_hierarchy); @@ -875,6 +892,18 @@ dbRegion* dbInst::getRegion() return (dbRegion*) r; } +dbModule* dbInst::getModule() +{ + _dbInst* inst = (_dbInst*) this; + + if (inst->_module == 0) + return NULL; + + _dbBlock* block = (_dbBlock*) inst->getOwner(); + _dbModule* module = block->_module_tbl->getPtr(inst->_module); + return (dbModule*) module; +} + dbBox* dbInst::getHalo() { _dbInst* inst = (_dbInst*) this; @@ -1316,6 +1345,10 @@ void dbInst::destroy(dbInst* inst_) if (region) region->removeInst(inst_); + + dbModule* module = inst_->getModule(); + if (module) + module->removeInst(inst_); uint i; uint n = inst->_iterms.size(); diff --git a/src/db/dbInst.h b/src/db/dbInst.h index 2ca5de93..780a5bf7 100644 --- a/src/db/dbInst.h +++ b/src/db/dbInst.h @@ -47,6 +47,7 @@ class _dbHier; class _dbITerm; class _dbRegion; class _dbDatabase; +class _dbModule; class dbInst; class dbIStream; class dbOStream; @@ -90,7 +91,9 @@ class _dbInst : public _dbObject dbId<_dbInstHdr> _inst_hdr; dbId<_dbBox> _bbox; dbId<_dbRegion> _region; + dbId<_dbModule> _module; dbId<_dbInst> _region_next; + dbId<_dbInst> _module_next; dbId<_dbInst> _region_prev; dbId<_dbHier> _hierarchy; dbVector _iterms; diff --git a/src/db/dbModInst.cpp b/src/db/dbModInst.cpp new file mode 100644 index 00000000..84ad3f1f --- /dev/null +++ b/src/db/dbModInst.cpp @@ -0,0 +1,266 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2020, OpenRoad Project +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#include "dbModInst.h" + +#include "db.h" +#include "dbBlock.h" +#include "dbDatabase.h" +#include "dbDiff.hpp" +#include "dbHashTable.hpp" +#include "dbModule.h" +#include "dbTable.h" +#include "dbTable.hpp" +// User Code Begin includes +// User Code End includes +namespace odb { + +// User Code Begin definitions +// User Code End definitions +template class dbTable<_dbModInst>; + +bool _dbModInst::operator==(const _dbModInst& rhs) const +{ + if (_name != rhs._name) + return false; + + if (_next_entry != rhs._next_entry) + return false; + + if (_parent != rhs._parent) + return false; + + if (_module_next != rhs._module_next) + return false; + + if (_master != rhs._master) + return false; + + // User Code Begin == + // User Code End == + return true; +} +bool _dbModInst::operator<(const _dbModInst& rhs) const +{ + // User Code Begin < + if (strcmp(_name, rhs._name) >= 0) + return false; + // User Code End < + return true; +} +void _dbModInst::differences(dbDiff& diff, + const char* field, + const _dbModInst& rhs) const +{ + DIFF_BEGIN + + DIFF_FIELD(_name); + + DIFF_FIELD(_next_entry); + + DIFF_FIELD(_parent); + + DIFF_FIELD(_module_next); + + DIFF_FIELD(_master); + + // User Code Begin differences + // User Code End differences + DIFF_END +} +void _dbModInst::out(dbDiff& diff, char side, const char* field) const +{ + DIFF_OUT_BEGIN + + DIFF_OUT_FIELD(_name); + + DIFF_OUT_FIELD(_next_entry); + + DIFF_OUT_FIELD(_parent); + + DIFF_OUT_FIELD(_module_next); + + DIFF_OUT_FIELD(_master); + + // User Code Begin out + // User Code End out + DIFF_END +} +_dbModInst::_dbModInst(_dbDatabase* db) +{ + // User Code Begin constructor + _name = 0; + _parent = 0; + _module_next = 0; + _master = 0; + // User Code End constructor +} +_dbModInst::_dbModInst(_dbDatabase* db, const _dbModInst& r) +{ + _name = r._name; + _next_entry = r._next_entry; + _parent = r._parent; + _module_next = r._module_next; + _master = r._master; + // User Code Begin CopyConstructor + // User Code End CopyConstructor +} + +dbIStream& operator>>(dbIStream& stream, _dbModInst& obj) +{ + stream >> obj._name; + stream >> obj._next_entry; + stream >> obj._parent; + stream >> obj._module_next; + stream >> obj._master; + // User Code Begin >> + // User Code End >> + return stream; +} +dbOStream& operator<<(dbOStream& stream, const _dbModInst& obj) +{ + stream << obj._name; + stream << obj._next_entry; + stream << obj._parent; + stream << obj._module_next; + stream << obj._master; + // User Code Begin << + // User Code End << + return stream; +} +dbObjectTable* _dbModInst::getObjectTable(dbObjectType type) +{ + switch (type) { + // User Code Begin getObjectTable + // User Code End getObjectTable + default: + break; + } + return getTable()->getObjectTable(type); +} +_dbModInst::~_dbModInst() +{ +} +//////////////////////////////////////////////////////////////////// +// +// dbModInst - Methods +// +//////////////////////////////////////////////////////////////////// + +dbModule* dbModInst::getParent() const +{ + _dbModInst* obj = (_dbModInst*) this; + if (obj->_parent == 0) + return NULL; + _dbBlock* par = (_dbBlock*) obj->getOwner(); + return (dbModule*) par->_module_tbl->getPtr(obj->_parent); +} + +dbModule* dbModInst::getMaster() const +{ + _dbModInst* obj = (_dbModInst*) this; + if (obj->_master == 0) + return NULL; + _dbBlock* par = (_dbBlock*) obj->getOwner(); + return (dbModule*) par->_module_tbl->getPtr(obj->_master); +} + +// User Code Begin dbModInstPublicMethods +dbModInst* dbModInst::create(dbModule* parentModule, + dbModule* masterModule, + const char* name) +{ + _dbModule* parent = (_dbModule*) parentModule; + _dbBlock* block = (_dbBlock*) parent->getOwner(); + std::string h_name = std::string(parent->_name) + '/' + std::string(name); + if (block->_modinst_hash.hasMember(h_name.c_str())) + return nullptr; + _dbModule* master = (_dbModule*) masterModule; + if (master->_mod_inst != 0) + return nullptr; + _dbModInst* modinst = block->_modinst_tbl->create(); + modinst->_name = strdup(h_name.c_str()); + ZALLOCATED(modinst->_name); + modinst->_master = master->getOID(); + modinst->_parent = parent->getOID(); + modinst->_module_next = parent->_modinsts; + parent->_modinsts = modinst->getOID(); + master->_mod_inst = modinst->getOID(); + block->_modinst_hash.insert(modinst); + return (dbModInst*) modinst; +} + +void dbModInst::destroy(dbModInst* modinst) +{ + _dbModInst* _modinst = (_dbModInst*) modinst; + _dbBlock* block = (_dbBlock*) _modinst->getOwner(); + _dbModule* module = (_dbModule*) modinst->getParent(); + + // unlink from parent start + uint id = _modinst->getOID(); + _dbModInst* prev = NULL; + uint cur = module->_modinsts; + while (cur) { + _dbModInst* c = block->_modinst_tbl->getPtr(cur); + if (cur == id) { + if (prev == NULL) + module->_modinsts = _modinst->_module_next; + else + prev->_module_next = _modinst->_module_next; + break; + } + prev = c; + cur = c->_module_next; + } + // unlink from parent end + dbProperty::destroyProperties(_modinst); + block->_modinst_hash.remove(_modinst); + block->_modinst_tbl->destroy(_modinst); +} +dbSet::iterator dbModInst::destroy(dbSet::iterator& itr) +{ + dbModInst* modinst = *itr; + dbSet::iterator next = ++itr; + destroy(modinst); + return next; +} +char* dbModInst::getName() const +{ + _dbModInst* obj = (_dbModInst*) this; + std::string h_name = std::string(obj->_name); + size_t idx = h_name.find_last_of('/'); + return strdup(h_name.substr(idx + 1).c_str()); +} +// User Code End dbModInstPublicMethods +} // namespace odb + // Generator Code End 1 \ No newline at end of file diff --git a/src/db/dbModInst.h b/src/db/dbModInst.h new file mode 100644 index 00000000..ede9d659 --- /dev/null +++ b/src/db/dbModInst.h @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2020, OpenRoad Project +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#pragma once + +#include "dbCore.h" +#include "odb.h" + +// User Code Begin includes +// User Code End includes + +namespace odb { + +class dbIStream; +class dbOStream; +class dbDiff; +class _dbDatabase; +class _dbModule; +// User Code Begin Classes +// User Code End Classes + +// User Code Begin structs +// User Code End structs + +class _dbModInst : public _dbObject +{ + public: + // User Code Begin enums + // User Code End enums + char* _name; + + dbId<_dbModInst> _next_entry; + + dbId<_dbModule> _parent; + + dbId<_dbModInst> _module_next; + + dbId<_dbModule> _master; + + // User Code Begin fields + // User Code End fields + _dbModInst(_dbDatabase*, const _dbModInst& r); + _dbModInst(_dbDatabase*); + ~_dbModInst(); + bool operator==(const _dbModInst& rhs) const; + bool operator!=(const _dbModInst& rhs) const { return !operator==(rhs); } + bool operator<(const _dbModInst& rhs) const; + void differences(dbDiff& diff, + const char* field, + const _dbModInst& rhs) const; + void out(dbDiff& diff, char side, const char* field) const; + dbObjectTable* getObjectTable(dbObjectType type); + // User Code Begin methods + // User Code End methods +}; +dbIStream& operator>>(dbIStream& stream, _dbModInst& obj); +dbOStream& operator<<(dbOStream& stream, const _dbModInst& obj); +// User Code Begin general +// User Code End general +} // namespace odb + // Generator Code End 1 \ No newline at end of file diff --git a/src/db/dbModule.cpp b/src/db/dbModule.cpp new file mode 100644 index 00000000..57bec811 --- /dev/null +++ b/src/db/dbModule.cpp @@ -0,0 +1,310 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2020, OpenRoad Project +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#include "dbModule.h" + +#include "db.h" +#include "dbBlock.h" +#include "dbDatabase.h" +#include "dbDiff.hpp" +#include "dbHashTable.hpp" +#include "dbTable.h" +#include "dbTable.hpp" +// User Code Begin includes +#include + +#include "dbInst.h" +#include "dbModInst.h" +#include "dbModuleInstItr.h" +#include "dbModuleModInstItr.h" +// User Code End includes +namespace odb { + +// User Code Begin definitions +// User Code End definitions +template class dbTable<_dbModule>; + +bool _dbModule::operator==(const _dbModule& rhs) const +{ + if (_name != rhs._name) + return false; + + if (_next_entry != rhs._next_entry) + return false; + + if (_insts != rhs._insts) + return false; + + if (_modinsts != rhs._modinsts) + return false; + + if (_mod_inst != rhs._mod_inst) + return false; + + // User Code Begin == + // User Code End == + return true; +} +bool _dbModule::operator<(const _dbModule& rhs) const +{ + // User Code Begin < + if (strcmp(_name, rhs._name) >= 0) + return false; + // User Code End < + return true; +} +void _dbModule::differences(dbDiff& diff, + const char* field, + const _dbModule& rhs) const +{ + DIFF_BEGIN + + DIFF_FIELD(_name); + + DIFF_FIELD(_next_entry); + + DIFF_FIELD(_insts); + + DIFF_FIELD(_modinsts); + + DIFF_FIELD(_mod_inst); + + // User Code Begin differences + // User Code End differences + DIFF_END +} +void _dbModule::out(dbDiff& diff, char side, const char* field) const +{ + DIFF_OUT_BEGIN + + DIFF_OUT_FIELD(_name); + + DIFF_OUT_FIELD(_next_entry); + + DIFF_OUT_FIELD(_insts); + + DIFF_OUT_FIELD(_modinsts); + + DIFF_OUT_FIELD(_mod_inst); + + // User Code Begin out + // User Code End out + DIFF_END +} +_dbModule::_dbModule(_dbDatabase* db) +{ + // User Code Begin constructor + _name = 0; + _insts = 0; + _modinsts = 0; + _mod_inst = 0; + // User Code End constructor +} +_dbModule::_dbModule(_dbDatabase* db, const _dbModule& r) +{ + _name = r._name; + _next_entry = r._next_entry; + _insts = r._insts; + _modinsts = r._modinsts; + _mod_inst = r._mod_inst; + // User Code Begin CopyConstructor + // User Code End CopyConstructor +} + +dbIStream& operator>>(dbIStream& stream, _dbModule& obj) +{ + stream >> obj._name; + stream >> obj._next_entry; + stream >> obj._insts; + stream >> obj._modinsts; + stream >> obj._mod_inst; + // User Code Begin >> + // User Code End >> + return stream; +} +dbOStream& operator<<(dbOStream& stream, const _dbModule& obj) +{ + stream << obj._name; + stream << obj._next_entry; + stream << obj._insts; + stream << obj._modinsts; + stream << obj._mod_inst; + // User Code Begin << + // User Code End << + return stream; +} +dbObjectTable* _dbModule::getObjectTable(dbObjectType type) +{ + switch (type) { + // User Code Begin getObjectTable + // User Code End getObjectTable + default: + break; + } + return getTable()->getObjectTable(type); +} +_dbModule::~_dbModule() +{ +} +//////////////////////////////////////////////////////////////////// +// +// dbModule - Methods +// +//////////////////////////////////////////////////////////////////// + +char* dbModule::getName() const +{ + _dbModule* obj = (_dbModule*) this; + return obj->_name; +} + +dbModInst* dbModule::getModInst() const +{ + _dbModule* obj = (_dbModule*) this; + if (obj->_mod_inst == 0) + return NULL; + _dbBlock* par = (_dbBlock*) obj->getOwner(); + return (dbModInst*) par->_modinst_tbl->getPtr(obj->_mod_inst); +} + +// User Code Begin dbModulePublicMethods + +void dbModule::addInst(dbInst* inst) +{ + _dbModule* module = (_dbModule*) this; + _dbInst* _inst = (_dbInst*) inst; + _dbBlock* block = (_dbBlock*) module->getOwner(); + + if (_inst->_module != 0) { + dbModule* mod = dbModule::getModule((dbBlock*) block, _inst->_module); + mod->removeInst(inst); + } + + _inst->_module = module->getOID(); + _inst->_module_next = module->_insts; + module->_insts = _inst->getOID(); +} + +void dbModule::removeInst(dbInst* inst) +{ + _dbModule* module = (_dbModule*) this; + _dbInst* _inst = (_dbInst*) inst; + _dbBlock* block = (_dbBlock*) module->getOwner(); + if (_inst->_module != module->getOID()) + return; + uint id = _inst->getOID(); + _dbInst* prev = NULL; + uint cur = module->_insts; + while (cur) { + _dbInst* c = block->_inst_tbl->getPtr(cur); + if (cur == id) { + if (prev == NULL) + module->_insts = _inst->_module_next; + else + prev->_module_next = _inst->_module_next; + break; + } + prev = c; + cur = c->_module_next; + } + _inst->_module = 0; + _inst->_module_next = 0; +} + +dbSet dbModule::getChildren() +{ + _dbModule* module = (_dbModule*) this; + _dbBlock* block = (_dbBlock*) module->getOwner(); + return dbSet(module, block->_module_modinst_itr); +} + +dbSet dbModule::getInsts() +{ + _dbModule* module = (_dbModule*) this; + _dbBlock* block = (_dbBlock*) module->getOwner(); + return dbSet(module, block->_module_inst_itr); +} + +dbModule* dbModule::create(dbBlock* block, const char* name) +{ + _dbBlock* _block = (_dbBlock*) block; + if (_block->_module_hash.hasMember(name)) + return nullptr; + _dbModule* module = _block->_module_tbl->create(); + module->_name = strdup(name); + ZALLOCATED(module->_name); + _block->_module_hash.insert(module); + return (dbModule*) module; +} + +void dbModule::destroy(dbModule* module) +{ + _dbModule* _module = (_dbModule*) module; + _dbBlock* block = (_dbBlock*) _module->getOwner(); + + dbSet modinsts = module->getChildren(); + dbSet::iterator itr; + for (itr = modinsts.begin(); itr != modinsts.end();) { + itr = dbModInst::destroy(itr); + } + if (_module->_mod_inst != 0) + dbModInst::destroy(module->getModInst()); + + for (auto inst : module->getInsts()) { + _dbInst* _inst = (_dbInst*) inst; + _inst->_module = 0; + _inst->_module_next = 0; + } + + dbProperty::destroyProperties(_module); + block->_module_hash.remove(_module); + block->_module_tbl->destroy(_module); +} + +dbModule* dbModule::getModule(dbBlock* block_, uint dbid_) +{ + _dbBlock* block = (_dbBlock*) block_; + return (dbModule*) block->_module_tbl->getPtr(dbid_); +} + +dbModInst* dbModule::findModInst(const char* name) +{ + _dbModule* obj = (_dbModule*) this; + _dbBlock* par = (_dbBlock*) obj->getOwner(); + std::string h_name = std::string(obj->_name) + "/" + std::string(name); + return (dbModInst*) par->_modinst_hash.find(h_name.c_str()); +} + +// User Code End dbModulePublicMethods +} // namespace odb + // Generator Code End 1 \ No newline at end of file diff --git a/src/db/dbModule.h b/src/db/dbModule.h new file mode 100644 index 00000000..05e17e6f --- /dev/null +++ b/src/db/dbModule.h @@ -0,0 +1,91 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2020, OpenRoad Project +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#pragma once + +#include "dbCore.h" +#include "odb.h" + +// User Code Begin includes +#include "dbHashTable.h" +// User Code End includes + +namespace odb { + +class dbIStream; +class dbOStream; +class dbDiff; +class _dbDatabase; +class _dbInst; +class _dbModInst; +// User Code Begin Classes +// User Code End Classes + +// User Code Begin structs +// User Code End structs + +class _dbModule : public _dbObject +{ + public: + // User Code Begin enums + // User Code End enums + char* _name; + + dbId<_dbModule> _next_entry; + + dbId<_dbInst> _insts; + + dbId<_dbModInst> _modinsts; + + dbId<_dbModInst> _mod_inst; + + // User Code Begin fields + // User Code End fields + _dbModule(_dbDatabase*, const _dbModule& r); + _dbModule(_dbDatabase*); + ~_dbModule(); + bool operator==(const _dbModule& rhs) const; + bool operator!=(const _dbModule& rhs) const { return !operator==(rhs); } + bool operator<(const _dbModule& rhs) const; + void differences(dbDiff& diff, const char* field, const _dbModule& rhs) const; + void out(dbDiff& diff, char side, const char* field) const; + dbObjectTable* getObjectTable(dbObjectType type); + // User Code Begin methods + // User Code End methods +}; +dbIStream& operator>>(dbIStream& stream, _dbModule& obj); +dbOStream& operator<<(dbOStream& stream, const _dbModule& obj); +// User Code Begin general +// User Code End general +} // namespace odb + // Generator Code End 1 \ No newline at end of file diff --git a/src/db/dbModuleInstItr.cpp b/src/db/dbModuleInstItr.cpp new file mode 100644 index 00000000..b80bfda2 --- /dev/null +++ b/src/db/dbModuleInstItr.cpp @@ -0,0 +1,123 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2019, Nefelus Inc +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#include "dbModuleInstItr.h" + +#include "dbInst.h" +#include "dbModule.h" +#include "dbTable.h" +// User Code Begin includes +// User Code End includes + +namespace odb { + +//////////////////////////////////////////////////////////////////// +// +// dbModuleInstItr - Methods +// +//////////////////////////////////////////////////////////////////// + +bool dbModuleInstItr::reversible() +{ + return true; +} + +bool dbModuleInstItr::orderReversed() +{ + return true; +} + +void dbModuleInstItr::reverse(dbObject* parent) +{ + // User Code Begin reverse + _dbModule* module = (_dbModule*) parent; + uint id = module->_insts; + uint list = 0; + + while (id != 0) { + _dbInst* inst = _inst_tbl->getPtr(id); + uint n = inst->_module_next; + inst->_module_next = list; + list = id; + id = n; + } + module->_insts = list; + // User Code End reverse +} + +uint dbModuleInstItr::sequential() +{ + return 0; +} + +uint dbModuleInstItr::size(dbObject* parent) +{ + uint id; + uint cnt = 0; + + for (id = dbModuleInstItr::begin(parent); id != dbModuleInstItr::end(parent); + id = dbModuleInstItr::next(id)) + ++cnt; + + return cnt; +} + +uint dbModuleInstItr::begin(dbObject* parent) +{ + // User Code Begin begin + _dbModule* module = (_dbModule*) parent; + return module->_insts; + // User Code End begin +} + +uint dbModuleInstItr::end(dbObject* /* unused: parent */) +{ + return 0; +} + +uint dbModuleInstItr::next(uint id, ...) +{ + // User Code Begin next + _dbInst* inst = _inst_tbl->getPtr(id); + return inst->_module_next; + // User Code End next +} + +dbObject* dbModuleInstItr::getObject(uint id, ...) +{ + return _inst_tbl->getPtr(id); +} +// User Code Begin methods +// User Code End methods +} // namespace odb + // Generator Code End 1 \ No newline at end of file diff --git a/src/db/dbModuleInstItr.h b/src/db/dbModuleInstItr.h new file mode 100644 index 00000000..4ccea945 --- /dev/null +++ b/src/db/dbModuleInstItr.h @@ -0,0 +1,70 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2020, OpenRoad Project +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#pragma once + +#include "dbIterator.h" +#include "odb.h" +// User Code Begin includes +// User Code End includes + +namespace odb { + +class _dbInst; +template +class dbTable; +// User Code Begin classes +// User Code End classes +class dbModuleInstItr : public dbIterator +{ + dbTable<_dbInst>* _inst_tbl; + // User Code Begin fields + // User Code End fields + public: + dbModuleInstItr(dbTable<_dbInst>* inst_tbl) { _inst_tbl = inst_tbl; } + + bool reversible(); + bool orderReversed(); + void reverse(dbObject* parent); + uint sequential(); + uint size(dbObject* parent); + uint begin(dbObject* parent); + uint end(dbObject* parent); + uint next(uint id, ...); + dbObject* getObject(uint id, ...); + // User Code Begin methods + // User Code End methods +}; + +} // namespace odb + // GeneratorCodeEnd 1 \ No newline at end of file diff --git a/src/db/dbModuleModInstItr.cpp b/src/db/dbModuleModInstItr.cpp new file mode 100644 index 00000000..b1a93c13 --- /dev/null +++ b/src/db/dbModuleModInstItr.cpp @@ -0,0 +1,124 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2019, Nefelus Inc +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#include "dbModuleModInstItr.h" + +#include "dbModInst.h" +#include "dbModule.h" +#include "dbTable.h" +// User Code Begin includes +// User Code End includes + +namespace odb { + +//////////////////////////////////////////////////////////////////// +// +// dbModuleModInstItr - Methods +// +//////////////////////////////////////////////////////////////////// + +bool dbModuleModInstItr::reversible() +{ + return true; +} + +bool dbModuleModInstItr::orderReversed() +{ + return true; +} + +void dbModuleModInstItr::reverse(dbObject* parent) +{ + // User Code Begin reverse + _dbModule* module = (_dbModule*) parent; + uint id = module->_modinsts; + uint list = 0; + + while (id != 0) { + _dbModInst* modinst = _modinst_tbl->getPtr(id); + uint n = modinst->_module_next; + modinst->_module_next = list; + list = id; + id = n; + } + module->_modinsts = list; + // User Code End reverse +} + +uint dbModuleModInstItr::sequential() +{ + return 0; +} + +uint dbModuleModInstItr::size(dbObject* parent) +{ + uint id; + uint cnt = 0; + + for (id = dbModuleModInstItr::begin(parent); + id != dbModuleModInstItr::end(parent); + id = dbModuleModInstItr::next(id)) + ++cnt; + + return cnt; +} + +uint dbModuleModInstItr::begin(dbObject* parent) +{ + // User Code Begin begin + _dbModule* module = (_dbModule*) parent; + return module->_modinsts; + // User Code End begin +} + +uint dbModuleModInstItr::end(dbObject* /* unused: parent */) +{ + return 0; +} + +uint dbModuleModInstItr::next(uint id, ...) +{ + // User Code Begin next + _dbModInst* modinst = _modinst_tbl->getPtr(id); + return modinst->_module_next; + // User Code End next +} + +dbObject* dbModuleModInstItr::getObject(uint id, ...) +{ + return _modinst_tbl->getPtr(id); +} +// User Code Begin methods +// User Code End methods +} // namespace odb + // Generator Code End 1 \ No newline at end of file diff --git a/src/db/dbModuleModInstItr.h b/src/db/dbModuleModInstItr.h new file mode 100644 index 00000000..bde3f868 --- /dev/null +++ b/src/db/dbModuleModInstItr.h @@ -0,0 +1,73 @@ +/////////////////////////////////////////////////////////////////////////////// +// BSD 3-Clause License +// +// Copyright (c) 2020, OpenRoad Project +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, this +// list of conditions and the following disclaimer. +// +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * Neither the name of the copyright holder nor the names of its +// contributors may be used to endorse or promote products derived from +// this software without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. + +// Generator Code Begin 1 +#pragma once + +#include "dbIterator.h" +#include "odb.h" +// User Code Begin includes +// User Code End includes + +namespace odb { + +class _dbModInst; +template +class dbTable; +// User Code Begin classes +// User Code End classes +class dbModuleModInstItr : public dbIterator +{ + dbTable<_dbModInst>* _modinst_tbl; + // User Code Begin fields + // User Code End fields + public: + dbModuleModInstItr(dbTable<_dbModInst>* modinst_tbl) + { + _modinst_tbl = modinst_tbl; + } + + bool reversible(); + bool orderReversed(); + void reverse(dbObject* parent); + uint sequential(); + uint size(dbObject* parent); + uint begin(dbObject* parent); + uint end(dbObject* parent); + uint next(uint id, ...); + dbObject* getObject(uint id, ...); + // User Code Begin methods + // User Code End methods +}; + +} // namespace odb + // GeneratorCodeEnd 1 \ No newline at end of file diff --git a/src/db/dbObject.cpp b/src/db/dbObject.cpp index 28f04a28..a3156bab 100644 --- a/src/db/dbObject.cpp +++ b/src/db/dbObject.cpp @@ -627,8 +627,10 @@ static const char* name_tbl[] = {"dbDatabase", "dbRegion", "dbHier", "dbBPin", - //Generator Code Begin 1 - //Generator Code End 1 + // Generator Code Begin 1 + "dbModule", + "dbModInst", + // Generator Code End 1 // Lib Objects "dbLib", diff --git a/tests/cpp/CMakeLists.txt b/tests/cpp/CMakeLists.txt index 7957eba4..d4ddfe29 100644 --- a/tests/cpp/CMakeLists.txt +++ b/tests/cpp/CMakeLists.txt @@ -17,7 +17,9 @@ set(TEST_LIBS add_executable( TestCallBacks ${PROJECT_SOURCE_DIR}/tests/cpp/TestCallBacks.cpp ) add_executable( TestGeom ${PROJECT_SOURCE_DIR}/tests/cpp/TestGeom.cpp ) add_executable( TestLogger ${PROJECT_SOURCE_DIR}/tests/cpp/TestLogger.cpp ) +add_executable( TestModule ${PROJECT_SOURCE_DIR}/tests/cpp/TestModule.cpp ) target_link_libraries(TestCallBacks ${TEST_LIBS}) target_link_libraries(TestGeom ${TEST_LIBS}) target_link_libraries(TestLogger ${TEST_LIBS}) +target_link_libraries(TestModule ${TEST_LIBS}) diff --git a/tests/cpp/TestModule.cpp b/tests/cpp/TestModule.cpp new file mode 100644 index 00000000..cba6c162 --- /dev/null +++ b/tests/cpp/TestModule.cpp @@ -0,0 +1,183 @@ +#define BOOST_TEST_MODULE example +#include +#include +#include "db.h" +#include "helper.cpp" +#include + +using namespace odb; +using namespace std; +BOOST_AUTO_TEST_SUITE(test_suite) + +struct F_DEFAULT { + F_DEFAULT() + { + db = createSimpleDB(); + block = db->getChip()->getBlock(); + lib = db->findLib("lib1"); + } + ~F_DEFAULT() + { + dbDatabase::destroy(db); + } + dbDatabase* db; + dbLib* lib; + dbBlock* block; +}; +BOOST_FIXTURE_TEST_CASE(test_default,F_DEFAULT) +{ + //dbModule::create() Succeed + BOOST_ASSERT(dbModule::create(block,"parent_mod")!=nullptr); + dbModule* master_mod = dbModule::create(block,"master_mod"); + //dbModule::create() rejected + BOOST_ASSERT(dbModule::create(block,"parent_mod")==nullptr); + //dbBlock::findModule() + dbModule* parent_mod = block->findModule("parent_mod"); + BOOST_ASSERT(parent_mod!=nullptr); + //dbModule::getName() + BOOST_ASSERT(string(parent_mod->getName())=="parent_mod"); + //dbModInst::create() Succeed + BOOST_ASSERT(dbModInst::create(parent_mod,master_mod,"i1")!=nullptr); + //dbModInst::create() rejected duplicate name + BOOST_ASSERT(dbModInst::create(parent_mod,master_mod,"i1")==nullptr); + //dbModInst::create() rejected master already has a modinst + BOOST_ASSERT(dbModInst::create(parent_mod,master_mod,"i2")==nullptr); + //dbModule::findModInst()1 + dbModInst* modInst = parent_mod->findModInst("i1"); + //dbModule getModInst() + BOOST_ASSERT(master_mod->getModInst()==modInst); + //dbModInst::getName() + BOOST_ASSERT(string(modInst->getName())=="i1"); + //dbModule::getChildren() + BOOST_ASSERT(parent_mod->getChildren().size()==1); + //dbBlock::getModInsts() + BOOST_ASSERT(block->getModInsts().size()==1); + //dbInst <--> dbModule + auto inst1 = dbInst::create(block,lib->findMaster("and2"),"inst1"); + auto inst2 = dbInst::create(block,lib->findMaster("and2"),"inst2"); + //dbModule::addInst() + parent_mod->addInst(inst1); + parent_mod->addInst(inst2); + //dbModule::getInsts() + BOOST_ASSERT(parent_mod->getInsts().size()==2); + //dbInst::getModule() + BOOST_ASSERT(std::string(inst1->getModule()->getName())=="parent_mod"); + //dbModule::removeInst() + parent_mod->removeInst(inst2); + BOOST_ASSERT(parent_mod->getInsts().size()==1); + BOOST_ASSERT(inst2->getModule()==nullptr); + //dbInst::destroy -> dbModule insts + dbInst::destroy(inst1); + BOOST_ASSERT(parent_mod->getInsts().size()==0); +} +struct F_DETAILED { + F_DETAILED() + { + db = createSimpleDB(); + block = db->getChip()->getBlock(); + lib = db->findLib("lib1"); + master_mod1 = dbModule::create(block,"master_mod1"); + master_mod2 = dbModule::create(block,"master_mod2"); + master_mod3 = dbModule::create(block,"master_mod3"); + parent_mod = dbModule::create(block,"parent_mod"); + i1 = dbModInst::create(parent_mod,master_mod1,"i1"); + i2 = dbModInst::create(parent_mod,master_mod2,"i2"); + i3 = dbModInst::create(parent_mod,master_mod3,"i3"); + inst1 = dbInst::create(block,lib->findMaster("and2"),"inst1"); + inst2 = dbInst::create(block,lib->findMaster("and2"),"inst2"); + inst3 = dbInst::create(block,lib->findMaster("and2"),"inst3"); + parent_mod->addInst(inst1); + parent_mod->addInst(inst2); + parent_mod->addInst(inst3); + } + ~F_DETAILED() + { + dbDatabase::destroy(db); + } + dbDatabase* db; + dbLib* lib; + dbBlock* block; + dbModule* master_mod1; + dbModule* master_mod2; + dbModule* master_mod3; + dbModule* parent_mod; + dbModInst* i1; + dbModInst* i2; + dbModInst* i3; + dbInst* inst1; + dbInst* inst2; + dbInst* inst3; +}; +BOOST_FIXTURE_TEST_CASE(test_destroy,F_DETAILED) +{ + BOOST_ASSERT(block->getModInsts().size()==3); + //dbModInst::destroy() + dbModInst::destroy(i1); + BOOST_ASSERT(parent_mod->findModInst("i1")==nullptr); + BOOST_ASSERT(block->getModInsts().size()==2); + //dbModule::destroy() master + dbModule::destroy(master_mod2); + BOOST_ASSERT(parent_mod->findModInst("i2")==nullptr); + BOOST_ASSERT(block->getModInsts().size()==1); + //dbModule::destroy() parent + dbModule::destroy(parent_mod); + BOOST_ASSERT(block->findModule("parent_mod")==nullptr); + BOOST_ASSERT(block->getModInsts().size()==0); +} +BOOST_FIXTURE_TEST_CASE(test_iterators,F_DETAILED) +{ + int i; + dbSet children = parent_mod->getChildren(); + dbSet::iterator modinst_itr; + BOOST_ASSERT(children.size()==3); + BOOST_ASSERT(children.reversible()); + for(int j = 0; j<2 ; j++) + { + if(j==1) + children.reverse(); + for(modinst_itr = children.begin() , i=j?1:3 ; modinst_itr != children.end() ; ++modinst_itr, i=i+(j?1:-1)) + switch (i) + { + case 1: + BOOST_ASSERT(*modinst_itr==i1); + break; + case 2: + BOOST_ASSERT(*modinst_itr==i2); + break; + case 3: + BOOST_ASSERT(*modinst_itr==i3); + break; + default: + BOOST_ASSERT(false); + break; + } + } + + dbSet insts = parent_mod->getInsts(); + dbSet::iterator inst_itr; + BOOST_ASSERT(insts.size()==3); + BOOST_ASSERT(insts.reversible()); + for(int j = 0; j<2 ; j++) + { + if(j==1) + insts.reverse(); + for(inst_itr = insts.begin() , i=j?1:3 ; inst_itr != insts.end() ; ++inst_itr, i=i+(j?1:-1)) + switch (i) + { + case 1: + BOOST_ASSERT(*inst_itr==inst1); + break; + case 2: + BOOST_ASSERT(*inst_itr==inst2); + break; + case 3: + BOOST_ASSERT(*inst_itr==inst3); + break; + default: + BOOST_ASSERT(false); + break; + } + } +} + +BOOST_AUTO_TEST_SUITE_END() \ No newline at end of file diff --git a/tests/unitTestsPython/__pycache__/helper.cpython-38.pyc b/tests/unitTestsPython/__pycache__/helper.cpython-38.pyc deleted file mode 100644 index dfb9ca5e..00000000 Binary files a/tests/unitTestsPython/__pycache__/helper.cpython-38.pyc and /dev/null differ diff --git a/tests/unitTestsPython/__pycache__/odbUnitTest.cpython-38.pyc b/tests/unitTestsPython/__pycache__/odbUnitTest.cpython-38.pyc deleted file mode 100644 index 613851f8..00000000 Binary files a/tests/unitTestsPython/__pycache__/odbUnitTest.cpython-38.pyc and /dev/null differ