|
21 | 21 | #include "odb/dbTransform.h" |
22 | 22 | #include "odb/dbTypes.h" |
23 | 23 | #include "odb/defin.h" |
| 24 | +#include "odb/defout.h" |
24 | 25 | #include "odb/geom.h" |
25 | 26 | #include "odb/lefin.h" |
| 27 | +#include "odb/lefout.h" |
26 | 28 | #include "sta/Sta.hh" |
27 | 29 | #include "utl/Logger.h" |
28 | | - |
| 30 | +#include "utl/ScopedTemporaryFile.h" |
29 | 31 | namespace odb { |
30 | 32 |
|
31 | 33 | static std::map<std::string, std::string> dup_orient_map |
@@ -94,10 +96,91 @@ void ThreeDBlox::check() |
94 | 96 | checker.check(db_->getChip()); |
95 | 97 | } |
96 | 98 |
|
97 | | -void ThreeDBlox::writeDbv(const std::string& dbv_file) |
| 99 | +namespace { |
| 100 | +std::unordered_set<odb::dbTech*> getUsedTechs(odb::dbChip* chip) |
| 101 | +{ |
| 102 | + std::unordered_set<odb::dbTech*> techs; |
| 103 | + for (auto inst : chip->getChipInsts()) { |
| 104 | + if (inst->getMasterChip()->getTech() != nullptr) { |
| 105 | + techs.insert(inst->getMasterChip()->getTech()); |
| 106 | + } |
| 107 | + } |
| 108 | + return techs; |
| 109 | +} |
| 110 | +std::unordered_set<odb::dbLib*> getUsedLibs(odb::dbChip* chip) |
| 111 | +{ |
| 112 | + std::unordered_set<odb::dbLib*> libs; |
| 113 | + for (auto inst : chip->getChipInsts()) { |
| 114 | + auto master_chip = inst->getMasterChip(); |
| 115 | + if (master_chip->getBlock() != nullptr) { |
| 116 | + for (auto inst : master_chip->getBlock()->getInsts()) { |
| 117 | + libs.insert(inst->getMaster()->getLib()); |
| 118 | + } |
| 119 | + } |
| 120 | + } |
| 121 | + return libs; |
| 122 | +} |
| 123 | +std::string getResultsDirectoryPath(const std::string& file_path) |
98 | 124 | { |
| 125 | + std::string current_dir_path; |
| 126 | + auto path = std::filesystem::path(file_path); |
| 127 | + if (path.has_parent_path()) { |
| 128 | + current_dir_path = path.parent_path().string() + "/"; |
| 129 | + } |
| 130 | + return current_dir_path; |
| 131 | +} |
| 132 | +} // namespace |
| 133 | +void ThreeDBlox::writeDbv(const std::string& dbv_file, odb::dbChip* chip) |
| 134 | +{ |
| 135 | + if (chip == nullptr) { |
| 136 | + return; |
| 137 | + } |
| 138 | + ///////////Results Directory Path /////////// |
| 139 | + std::string current_dir_path = getResultsDirectoryPath(dbv_file); |
| 140 | + //////////////////////////////////////////// |
| 141 | + |
| 142 | + for (auto inst : chip->getChipInsts()) { |
| 143 | + auto master_chip = inst->getMasterChip(); |
| 144 | + if (master_chip->getChipType() == odb::dbChip::ChipType::HIER) { |
| 145 | + writeDbx(current_dir_path + master_chip->getName() + ".3dbx", |
| 146 | + master_chip); |
| 147 | + } |
| 148 | + } |
| 149 | + // write used techs |
| 150 | + for (auto tech : getUsedTechs(chip)) { |
| 151 | + if (written_techs_.find(tech) != written_techs_.end()) { |
| 152 | + continue; |
| 153 | + } |
| 154 | + written_techs_.insert(tech); |
| 155 | + std::string tech_file_path = current_dir_path + tech->getName() + ".lef"; |
| 156 | + utl::OutStreamHandler stream_handler(tech_file_path.c_str()); |
| 157 | + odb::lefout lef_writer(logger_, stream_handler.getStream()); |
| 158 | + lef_writer.writeTech(tech); |
| 159 | + } |
| 160 | + // write used libs |
| 161 | + for (auto lib : getUsedLibs(chip)) { |
| 162 | + if (written_libs_.find(lib) != written_libs_.end()) { |
| 163 | + continue; |
| 164 | + } |
| 165 | + written_libs_.insert(lib); |
| 166 | + std::string lib_file_path = current_dir_path + lib->getName() + "_lib.lef"; |
| 167 | + utl::OutStreamHandler stream_handler(lib_file_path.c_str()); |
| 168 | + odb::lefout lef_writer(logger_, stream_handler.getStream()); |
| 169 | + lef_writer.writeLib(lib); |
| 170 | + } |
| 171 | + |
99 | 172 | DbvWriter writer(logger_, db_); |
100 | | - writer.writeChiplet(dbv_file, db_->getChip()); |
| 173 | + writer.writeChiplet(dbv_file, chip); |
| 174 | +} |
| 175 | + |
| 176 | +void ThreeDBlox::writeDbx(const std::string& dbx_file, odb::dbChip* chip) |
| 177 | +{ |
| 178 | + if (chip == nullptr) { |
| 179 | + return; |
| 180 | + } |
| 181 | + // TODO: implement |
| 182 | + std::string current_dir_path = getResultsDirectoryPath(dbx_file); |
| 183 | + writeDbv(current_dir_path + chip->getName() + ".3dbv", chip); |
101 | 184 | } |
102 | 185 |
|
103 | 186 | void ThreeDBlox::calculateSize(dbChip* chip) |
@@ -142,11 +225,13 @@ dbChip::ChipType getChipType(const std::string& type, utl::Logger* logger) |
142 | 225 | logger->error( |
143 | 226 | utl::ODB, 527, "3DBV Parser Error: Invalid chip type: {}", type); |
144 | 227 | } |
| 228 | + |
145 | 229 | std::string getFileName(const std::string& tech_file_path) |
146 | 230 | { |
147 | 231 | std::filesystem::path tech_file_path_fs(tech_file_path); |
148 | 232 | return tech_file_path_fs.stem().string(); |
149 | 233 | } |
| 234 | + |
150 | 235 | void ThreeDBlox::createChiplet(const ChipletDef& chiplet) |
151 | 236 | { |
152 | 237 | dbTech* tech = nullptr; |
@@ -239,6 +324,7 @@ void ThreeDBlox::createChiplet(const ChipletDef& chiplet) |
239 | 324 | createRegion(region, chip); |
240 | 325 | } |
241 | 326 | } |
| 327 | + |
242 | 328 | dbChipRegion::Side getChipRegionSide(const std::string& side, |
243 | 329 | utl::Logger* logger) |
244 | 330 | { |
@@ -348,6 +434,7 @@ dbChip* ThreeDBlox::createDesignTopChiplet(const DesignDef& design) |
348 | 434 | db_->setTopChip(chip); |
349 | 435 | return chip; |
350 | 436 | } |
| 437 | + |
351 | 438 | void ThreeDBlox::createChipInst(const ChipletInst& chip_inst) |
352 | 439 | { |
353 | 440 | auto chip = db_->findChip(chip_inst.reference.c_str()); |
|
0 commit comments