Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/odb/include/odb/3dblox.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,5 +69,6 @@ class ThreeDBlox
std::unordered_set<odb::dbTech*> written_techs_;
std::unordered_set<odb::dbLib*> written_libs_;
std::unordered_set<std::string> read_files_;
std::unordered_set<odb::dbChip*> insts_with_def_;
};
} // namespace odb
41 changes: 31 additions & 10 deletions src/odb/src/3dblox/3dblox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,6 +398,20 @@ static std::string getFileName(const std::string& tech_file_path)
return tech_file_path_fs.stem().string();
}

static inline void readDefForChip(odb::dbDatabase* db,
utl::Logger* logger,
odb::dbChip* chip,
const std::string& def_file)
{
odb::defin def_reader(db, logger, odb::defin::DEFAULT);
std::vector<odb::dbLib*> search_libs;
for (odb::dbLib* lib : db->getLibs()) {
search_libs.push_back(lib);
}
// No callbacks here as we are going to give one postRead3Dbx later
def_reader.readChip(search_libs, def_file.c_str(), chip, false);
}

void ThreeDBlox::createChiplet(const ChipletDef& chiplet)
{
dbTech* tech = nullptr;
Expand Down Expand Up @@ -454,16 +468,7 @@ void ThreeDBlox::createChiplet(const ChipletDef& chiplet)

// Read DEF file
if (!chiplet.external.def_file.empty()) {
odb::defin def_reader(db_, logger_, odb::defin::DEFAULT);
std::vector<odb::dbLib*> search_libs;
for (odb::dbLib* lib : db_->getLibs()) {
search_libs.push_back(lib);
}
// No callbacks here as we are going to give one postRead3Dbx later
def_reader.readChip(search_libs,
chiplet.external.def_file.c_str(),
chip,
/*issue_callback*/ false);
readDefForChip(db_, logger_, chip, chiplet.external.def_file);
}
const int dbu_per_micron = db_->getDbuPerMicron();
if (chiplet.design_width != -1.0) {
Expand Down Expand Up @@ -677,6 +682,22 @@ void ThreeDBlox::createChipInst(const ChipletInst& chip_inst)
chip_inst.reference,
chip_inst.name);
}

if (!chip_inst.external.def_file.empty()) {
if (insts_with_def_.contains(chip)) {
logger_->error(utl::ODB,
546,
"3DBX Parser Error: There can't be 2 instances of the "
"same chiplet {} with a def file each",
chip->getName());
}
insts_with_def_.insert(chip);
if (chip->getBlock() != nullptr) {
odb::dbBlock::destroy(chip->getBlock());
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you probably should log an error here. There can't be 2 instances of the same chiplet with a def file each.

}
readDefForChip(db_, logger_, chip, chip_inst.external.def_file);
}
Comment on lines +686 to +699
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The logic for reading a DEF file for a chiplet is duplicated between createChiplet and createChipInst. This logic (checking for the property, destroying the existing block, populating search libraries, and reading the chip) should be refactored into a shared free function within a namespace to improve maintainability and ensure consistency.

References
  1. Helper logic should be defined as a free function in a namespace rather than as a local lambda within a function.


dbChipInst* inst = dbChipInst::create(db_->getChip(), chip, chip_inst.name);
auto orient_str = chip_inst.orient;
if (dup_orient_map.contains(orient_str)) {
Expand Down
10 changes: 9 additions & 1 deletion src/odb/src/3dblox/dbxWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ DbxWriter::DbxWriter(utl::Logger* logger, odb::dbDatabase* db)

void DbxWriter::writeChiplet(const std::string& filename, odb::dbChip* chiplet)
{
written_def_chips_.clear();
YAML::Node root;
writeYamlContent(root, chiplet);
writeYamlToFile(filename, root);
Expand Down Expand Up @@ -65,8 +66,15 @@ void DbxWriter::writeChipletInsts(YAML::Node& instances_node,
void DbxWriter::writeChipletInst(YAML::Node& instance_node,
odb::dbChipInst* inst)
{
auto master_name = inst->getMasterChip()->getName();
auto chip = inst->getMasterChip();
auto master_name = chip->getName();
instance_node["reference"] = master_name;

if (written_def_chips_.find(chip) == written_def_chips_.end()) {
YAML::Node external_node = instance_node["external"];
external_node["def_file"] = std::string(master_name) + ".def";
written_def_chips_.insert(chip);
}
}

void DbxWriter::writeStack(YAML::Node& stack_node, odb::dbChip* chiplet)
Expand Down
3 changes: 3 additions & 0 deletions src/odb/src/3dblox/dbxWriter.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <string>
#include <unordered_set>
#include <vector>

#include "baseWriter.h"
Expand Down Expand Up @@ -42,6 +43,8 @@ class DbxWriter : public BaseWriter
void writeConnection(YAML::Node& connection_node, odb::dbChipConn* conn);
std::string buildPath(const std::vector<dbChipInst*>& path_insts,
odb::dbChipRegionInst* region);

std::unordered_set<odb::dbChip*> written_def_chips_;
};

} // namespace odb
Loading