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