-
Notifications
You must be signed in to change notification settings - Fork 859
odb: impl 3dblox verilog writer #9813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
osamahammad21
merged 3 commits into
The-OpenROAD-Project:master
from
The-OpenROAD-Project-staging:feat/3dblox-write-top-verilog
Mar 30, 2026
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,8 +3,6 @@ | |
|
|
||
| #pragma once | ||
|
|
||
| #include <memory> | ||
| #include <set> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) 2019-2025, The OpenROAD Authors | ||
|
|
||
| #include "verilogWriter.h" | ||
|
|
||
| #include <algorithm> | ||
| #include <cstddef> | ||
| #include <cstdint> | ||
| #include <fstream> | ||
| #include <map> | ||
| #include <string> | ||
| #include <utility> | ||
| #include <vector> | ||
|
|
||
| #include "odb/db.h" | ||
| #include "utl/Logger.h" | ||
|
|
||
| namespace odb { | ||
|
|
||
| VerilogWriter::VerilogWriter(utl::Logger* logger) : logger_(logger) | ||
| { | ||
| } | ||
|
|
||
| void VerilogWriter::writeChiplet(const std::string& filename, odb::dbChip* chip) | ||
| { | ||
| std::ofstream verilog_file(filename); | ||
| if (!verilog_file.is_open()) { | ||
| logger_->error( | ||
| utl::ODB, 563, "Unable to open Verilog file for writing: {}", filename); | ||
osamahammad21 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return; | ||
| } | ||
|
|
||
| // chip_inst -> list of (port_name, net_name) | ||
| std::map<dbChipInst*, std::vector<std::pair<std::string, std::string>>> | ||
| inst_connections; | ||
|
|
||
| for (dbChipNet* net : chip->getChipNets()) { | ||
| const std::string net_name = net->getName(); | ||
| const uint32_t num_bumps = net->getNumBumpInsts(); | ||
| for (uint32_t i = 0; i < num_bumps; i++) { | ||
| std::vector<dbChipInst*> path; | ||
| dbChipBumpInst* bump_inst = net->getBumpInst(i, path); | ||
| if (bump_inst == nullptr || path.size() != 1) { | ||
| continue; | ||
| } | ||
| // Only handle direct children (path length 1) — "single bump | ||
| // connections". | ||
| dbChipInst* chip_inst = path[0]; | ||
| dbChipBump* bump = bump_inst->getChipBump(); | ||
| if (bump == nullptr) { | ||
| continue; | ||
| } | ||
| dbBTerm* bterm = bump->getBTerm(); | ||
| if (bterm == nullptr) { | ||
| continue; | ||
| } | ||
| inst_connections[chip_inst].emplace_back(bterm->getName(), net_name); | ||
| } | ||
| } | ||
|
|
||
| // Sort each instance's port connections alphabetically by port name. | ||
| for (std::pair<dbChipInst* const, | ||
| std::vector<std::pair<std::string, std::string>>>& entry : | ||
| inst_connections) { | ||
| std::ranges::sort(entry.second); | ||
| } | ||
|
|
||
| // Write module header. | ||
| fmt::print(verilog_file, "module {} ();\n", chip->getName()); | ||
|
|
||
| // Collect and sort net names alphabetically for deterministic wire order. | ||
| std::vector<std::string> net_names; | ||
| for (dbChipNet* net : chip->getChipNets()) { | ||
| net_names.push_back(net->getName()); | ||
| } | ||
| std::ranges::sort(net_names); | ||
|
|
||
| // Write wire declarations in sorted order. | ||
| for (const std::string& name : net_names) { | ||
| fmt::print(verilog_file, " wire {};\n", name); | ||
| } | ||
|
|
||
| // Collect and sort instances alphabetically by instance name. | ||
| std::vector<dbChipInst*> chip_insts; | ||
| for (dbChipInst* chip_inst : chip->getChipInsts()) { | ||
| chip_insts.push_back(chip_inst); | ||
| } | ||
| std::ranges::sort(chip_insts, [](dbChipInst* a, dbChipInst* b) { | ||
| return a->getName() < b->getName(); | ||
| }); | ||
|
|
||
| // Write instance declarations in sorted order. | ||
| for (dbChipInst* chip_inst : chip_insts) { | ||
| fmt::print(verilog_file, | ||
| " {} {} (\n", | ||
| chip_inst->getMasterChip()->getName(), | ||
| chip_inst->getName()); | ||
| auto it = inst_connections.find(chip_inst); | ||
| if (it != inst_connections.end()) { | ||
| const std::vector<std::pair<std::string, std::string>>& conns | ||
| = it->second; | ||
| for (size_t j = 0; j < conns.size(); j++) { | ||
| const bool is_last = (j + 1 == conns.size()); | ||
| fmt::print(verilog_file, | ||
| " .{}({}){}\n", | ||
| conns[j].first, | ||
| conns[j].second, | ||
| is_last ? "" : ","); | ||
|
Comment on lines
+102
to
+108
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
| } | ||
| } | ||
| fmt::print(verilog_file, " );\n"); | ||
| } | ||
|
|
||
| fmt::print(verilog_file, "endmodule\n"); | ||
| verilog_file.close(); | ||
| } | ||
|
|
||
| } // namespace odb | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| // SPDX-License-Identifier: BSD-3-Clause | ||
| // Copyright (c) 2019-2025, The OpenROAD Authors | ||
|
|
||
| #pragma once | ||
|
|
||
| #include <string> | ||
|
|
||
| namespace utl { | ||
| class Logger; | ||
| } | ||
| namespace odb { | ||
| class dbChip; | ||
|
|
||
| class VerilogWriter | ||
| { | ||
| public: | ||
| VerilogWriter(utl::Logger* logger); | ||
| void writeChiplet(const std::string& filename, odb::dbChip* chip); | ||
|
|
||
| private: | ||
| utl::Logger* logger_ = nullptr; | ||
| }; | ||
|
|
||
| } // namespace odb |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
writeDbxmethod now has a side effect of writing a Verilog connectivity file. While this might be intended for hierarchical chiplets, the method namewriteDbx(presumably for 'write Dbx') does not clearly indicate this additional output. Consider renaming the method to better reflect its full functionality or making the Verilog writing an explicit, optional step if it's not always required when writing a Dbx file.