Skip to content

Commit fa64661

Browse files
committed
ODB: updates to the 3dblox 3dbv writer
In this commit, I do the following changes: - Remove the chipletHierarchy logic which will be relayed to the checker. - Clean up includes and add forward declarations for used classes instead of including them. - Fix the floating point precision issue noticed when writing out coordinates. - Move the writeLef and writeDef to dbvWriter as they won't be used by any other writer. - Resolve the 3dbv path and write needed files under the same directory. - Fix library and tech resolution. Signed-off-by: osamahammad21 <[email protected]>
1 parent 1797b79 commit fa64661

File tree

11 files changed

+197
-372
lines changed

11 files changed

+197
-372
lines changed

src/odb/src/3dblox/3dblox.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ void ThreeDBlox::check()
9696

9797
void ThreeDBlox::writeDbv(const std::string& dbv_file)
9898
{
99-
DbvWriter writer(logger_);
100-
writer.writeFile(dbv_file, db_);
99+
DbvWriter writer(logger_, db_);
100+
writer.writeChiplet(dbv_file, db_->getChip());
101101
}
102102

103103
void ThreeDBlox::calculateSize(dbChip* chip)

src/odb/src/3dblox/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ add_library(3dblox
1010
dbxParser.cpp
1111
baseWriter.cpp
1212
dbvWriter.cpp
13-
chipletHierarchy.cpp
1413
3dblox.cpp
1514
checker.cpp
1615
)

src/odb/src/3dblox/baseWriter.cpp

Lines changed: 27 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,19 @@
1010
#include <string>
1111

1212
#include "odb/db.h"
13-
#include "odb/defout.h"
14-
#include "odb/lefout.h"
1513
#include "utl/Logger.h"
16-
#include "utl/ScopedTemporaryFile.h"
17-
1814
namespace odb {
1915

20-
BaseWriter::BaseWriter(utl::Logger* logger) : logger_(logger)
16+
BaseWriter::BaseWriter(utl::Logger* logger, odb::dbDatabase* db)
17+
: logger_(logger), dbu_per_micron_(db->getDbuPerMicron())
2118
{
2219
}
2320

24-
void BaseWriter::writeHeader(YAML::Node& header_node, odb::dbDatabase* db)
21+
void BaseWriter::writeHeader(YAML::Node& header_node)
2522
{
2623
header_node["version"] = "3";
2724
header_node["unit"] = "micron";
28-
header_node["precision"] = db->getDbuPerMicron();
25+
header_node["precision"] = dbu_per_micron_;
2926
}
3027

3128
void BaseWriter::writeYamlToFile(const std::string& filename,
@@ -42,65 +39,26 @@ void BaseWriter::writeYamlToFile(const std::string& filename,
4239
out << root;
4340
}
4441

45-
void BaseWriter::writeLef(YAML::Node& external_node,
46-
odb::dbDatabase* db,
47-
odb::dbChip* chiplet)
42+
void BaseWriter::writeCoordinate(YAML::Node& coord_node,
43+
const odb::Point& point)
4844
{
49-
auto libs = db->getLibs();
50-
int num_libs = libs.size();
51-
if (num_libs > 0) {
52-
if (num_libs > 1) {
53-
logger_->info(
54-
utl::ODB,
55-
541,
56-
"More than one lib exists, multiple files will be written.");
57-
}
58-
int cnt = 0;
59-
for (auto lib : libs) {
60-
std::string name(std::string(lib->getName()) + ".lef");
61-
if (cnt > 0) {
62-
auto pos = name.rfind('.');
63-
if (pos != std::string::npos) {
64-
name.insert(pos, "_" + std::to_string(cnt));
65-
} else {
66-
name += "_" + std::to_string(cnt);
67-
}
68-
utl::OutStreamHandler stream_handler(name.c_str());
69-
odb::lefout lef_writer(logger_, stream_handler.getStream());
70-
lef_writer.writeLib(lib);
71-
} else {
72-
utl::OutStreamHandler stream_handler(name.c_str());
73-
odb::lefout lef_writer(logger_, stream_handler.getStream());
74-
lef_writer.writeTechAndLib(lib);
75-
}
76-
YAML::Node list_node;
77-
list_node.SetStyle(YAML::EmitterStyle::Flow);
78-
list_node.push_back(name.c_str());
79-
if ((name.find("_tech") != std::string::npos) || (libs.size() == 1)) {
80-
external_node["APR_tech_file"] = list_node;
81-
} else {
82-
external_node["LEF_file"] = list_node;
83-
}
84-
++cnt;
85-
}
86-
} else if (db->getTech()) {
87-
utl::OutStreamHandler stream_handler(
88-
(std::string(chiplet->getName()) + ".lef").c_str());
89-
odb::lefout lef_writer(logger_, stream_handler.getStream());
90-
lef_writer.writeTech(db->getTech());
91-
external_node["APR_tech_file"] = (std::string(chiplet->getName()) + ".lef");
92-
}
45+
coord_node.SetStyle(YAML::EmitterStyle::Flow);
46+
coord_node.push_back(dbuToMicron(point.x()));
47+
coord_node.push_back(dbuToMicron(point.y()));
9348
}
9449

95-
void BaseWriter::writeDef(YAML::Node& external_node,
96-
odb::dbDatabase* db,
97-
odb::dbChip* chiplet)
50+
void BaseWriter::writeCoordinates(YAML::Node& coords_node,
51+
const odb::Rect& rect)
9852
{
99-
odb::DefOut def_writer(logger_);
100-
auto block = chiplet->getBlock();
101-
def_writer.writeBlock(block,
102-
(std::string(chiplet->getName()) + ".def").c_str());
103-
external_node["DEF_file"] = std::string(chiplet->getName()) + ".def";
53+
YAML::Node c0, c1, c2, c3;
54+
writeCoordinate(c0, rect.ll());
55+
writeCoordinate(c1, rect.lr());
56+
writeCoordinate(c2, rect.ur());
57+
writeCoordinate(c3, rect.ul());
58+
coords_node.push_back(c0);
59+
coords_node.push_back(c1);
60+
coords_node.push_back(c2);
61+
coords_node.push_back(c3);
10462
}
10563

10664
void BaseWriter::logError(const std::string& message)
@@ -120,4 +78,11 @@ std::string BaseWriter::trim(const std::string& str)
12078
return str.substr(first, (last - first + 1));
12179
}
12280

81+
template <typename IntType>
82+
std::string BaseWriter::dbuToMicron(IntType dbu) const
83+
{
84+
return fmt::format("{:.11g}", dbu / static_cast<double>(dbu_per_micron_));
85+
}
86+
87+
template std::string BaseWriter::dbuToMicron<int>(int dbu) const;
12388
} // namespace odb

src/odb/src/3dblox/baseWriter.h

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,42 +3,41 @@
33

44
#pragma once
55

6-
#include <yaml-cpp/node/node.h>
7-
86
#include <string>
97

10-
#include "odb/db.h"
11-
#include "odb/dbObject.h"
12-
#include "odb/dbShape.h"
138
namespace utl {
149
class Logger;
1510
}
1611

12+
namespace YAML {
13+
class Node;
14+
}
1715
namespace odb {
16+
class dbDatabase;
17+
class Rect;
18+
class Point;
1819

1920
class BaseWriter
2021
{
2122
public:
22-
BaseWriter(utl::Logger* logger);
23+
BaseWriter(utl::Logger* logger, odb::dbDatabase* db);
2324
virtual ~BaseWriter() = default;
24-
virtual void writeFile(const std::string& filename, odb::dbDatabase* db) = 0;
2525

2626
protected:
2727
// Common YAML content writing
28-
void writeHeader(YAML::Node& header_node, odb::dbDatabase* db);
29-
void writeLef(YAML::Node& external_node,
30-
odb::dbDatabase* db,
31-
odb::dbChip* chiplet);
32-
void writeDef(YAML::Node& external_node,
33-
odb::dbDatabase* db,
34-
odb::dbChip* chiplet);
28+
void writeHeader(YAML::Node& header_node);
29+
void writeCoordinates(YAML::Node& coords_node, const odb::Rect& rect);
30+
void writeCoordinate(YAML::Node& coord_node, const odb::Point& point);
3531
void logError(const std::string& message);
3632
std::string trim(const std::string& str);
3733
void writeYamlToFile(const std::string& filename, const YAML::Node& root);
34+
template <typename IntType>
35+
std::string dbuToMicron(IntType dbu) const;
3836

3937
// Member variables
4038
utl::Logger* logger_ = nullptr;
41-
std::string current_file_path_;
39+
std::string current_dir_path_;
40+
uint dbu_per_micron_ = 0;
4241
};
4342

4443
} // namespace odb

src/odb/src/3dblox/chipletHierarchy.cpp

Lines changed: 0 additions & 90 deletions
This file was deleted.

src/odb/src/3dblox/chipletHierarchy.h

Lines changed: 0 additions & 36 deletions
This file was deleted.

0 commit comments

Comments
 (0)