|
25 | 25 | #include <set> |
26 | 26 | #include <sstream> |
27 | 27 | #include <string> |
| 28 | +#include <unordered_map> |
28 | 29 | #include <utility> |
29 | 30 | #include <vector> |
30 | 31 |
|
@@ -859,6 +860,43 @@ dbOStream& operator<<(dbOStream& stream, const _dbBlock& block) |
859 | 860 | return stream; |
860 | 861 | } |
861 | 862 |
|
| 863 | +/** |
| 864 | + * @brief Rebuilds the name-to-ID hash maps for hierarchical objects within |
| 865 | + * their respective modules. |
| 866 | + * |
| 867 | + * This function is used during database loading (operator>>) to restore the |
| 868 | + * fast-lookup hashes that were stored in the ODB. |
| 869 | + * |
| 870 | + * @tparam T The public ODB object type (e.g., dbInst, dbModNet). |
| 871 | + * @tparam T_impl The internal implementation type (e.g., _dbInst, _dbModNet). |
| 872 | + * @param block The database block containing the objects. |
| 873 | + * @param table The internal database table storing the object implementations. |
| 874 | + * @param module_field Member pointer to the field storing the parent module ID |
| 875 | + * (e.g., &_dbInst::module_ or &_dbModInst::parent_). |
| 876 | + * @param hash_field Member pointer to the hash map member in _dbModule where |
| 877 | + * the object ID should be stored. |
| 878 | + */ |
| 879 | +template <typename T, typename T_impl> |
| 880 | +static void rebuildModuleHash( |
| 881 | + _dbBlock& block, |
| 882 | + dbTable<T_impl>* table, |
| 883 | + dbId<_dbModule> T_impl::*module_field, |
| 884 | + std::unordered_map<std::string, dbId<T_impl>> _dbModule::*hash_field) |
| 885 | +{ |
| 886 | + dbSet<T> items((dbBlock*) &block, table); |
| 887 | + for (T* obj : items) { |
| 888 | + T_impl* _obj = (T_impl*) obj; |
| 889 | + dbId<_dbModule> mid = _obj->*module_field; |
| 890 | + if (mid == 0) { |
| 891 | + mid = block.top_module_; |
| 892 | + } |
| 893 | + _dbModule* module = block.module_tbl_->getPtr(mid); |
| 894 | + if (module && _obj->name_) { |
| 895 | + (module->*hash_field)[_obj->name_] = _obj->getId(); |
| 896 | + } |
| 897 | + } |
| 898 | +} |
| 899 | + |
862 | 900 | dbIStream& operator>>(dbIStream& stream, _dbBlock& block) |
863 | 901 | { |
864 | 902 | _dbDatabase* db = block.getImpl()->getDatabase(); |
@@ -950,17 +988,43 @@ dbIStream& operator>>(dbIStream& stream, _dbBlock& block) |
950 | 988 | stream >> *block.inst_tbl_; |
951 | 989 | stream >> *block.module_tbl_; |
952 | 990 | } |
| 991 | + if (db->isSchema(kSchemaDbRemoveHash)) { |
| 992 | + // Construct dbinst_hash_ |
| 993 | + rebuildModuleHash<dbInst>( |
| 994 | + block, block.inst_tbl_, &_dbInst::module_, &_dbModule::dbinst_hash_); |
| 995 | + } |
953 | 996 | if (db->isSchema(kSchemaBlockOwnsScanInsts)) { |
954 | 997 | stream >> *block.scan_inst_tbl_; |
955 | 998 | } |
956 | 999 | stream >> *block.modinst_tbl_; |
| 1000 | + if (db->isSchema(kSchemaDbRemoveHash)) { |
| 1001 | + // Construct modinst_hash_ |
| 1002 | + rebuildModuleHash<dbModInst>(block, |
| 1003 | + block.modinst_tbl_, |
| 1004 | + &_dbModInst::parent_, |
| 1005 | + &_dbModule::modinst_hash_); |
| 1006 | + } |
957 | 1007 | if (db->isSchema(kSchemaUpdateHierarchy)) { |
958 | 1008 | stream >> *block.modbterm_tbl_; |
| 1009 | + if (db->isSchema(kSchemaDbRemoveHash)) { |
| 1010 | + // Construct modbterm_hash_ |
| 1011 | + rebuildModuleHash<dbModBTerm>(block, |
| 1012 | + block.modbterm_tbl_, |
| 1013 | + &_dbModBTerm::parent_, |
| 1014 | + &_dbModule::modbterm_hash_); |
| 1015 | + } |
959 | 1016 | if (db->isSchema(kSchemaDbRemoveHash)) { |
960 | 1017 | stream >> *block.busport_tbl_; |
961 | 1018 | } |
962 | 1019 | stream >> *block.moditerm_tbl_; |
963 | 1020 | stream >> *block.modnet_tbl_; |
| 1021 | + if (db->isSchema(kSchemaDbRemoveHash)) { |
| 1022 | + // Construct modnet_hash_ |
| 1023 | + rebuildModuleHash<dbModNet>(block, |
| 1024 | + block.modnet_tbl_, |
| 1025 | + &_dbModNet::parent_, |
| 1026 | + &_dbModule::modnet_hash_); |
| 1027 | + } |
964 | 1028 | } |
965 | 1029 | stream >> *block.powerdomain_tbl_; |
966 | 1030 | stream >> *block.logicport_tbl_; |
|
0 commit comments