Skip to content

Commit

Permalink
ord: add Design (read|write)Db methods that work on streams
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Liberty <[email protected]>
  • Loading branch information
maliberty committed Sep 3, 2024
1 parent db910c6 commit b6c4933
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 2 additions & 0 deletions include/ord/Design.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,9 @@ class Design
bool child = false);
void link(const std::string& design_name);

void readDb(std::istream& stream);
void readDb(const std::string& file_name);
void writeDb(std::ostream& stream);
void writeDb(const std::string& file_name);
void writeDef(const std::string& file_name);

Expand Down
2 changes: 2 additions & 0 deletions include/ord/OpenRoad.hh
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ class OpenRoad
// to notify the tools (eg dbSta, gui).
void designCreated();

void readDb(std::istream& stream);
void readDb(const char* filename);
void writeDb(std::ostream& stream);
void writeDb(const char* filename);

void diffDbs(const char* filename1, const char* filename2, const char* diffs);
Expand Down
12 changes: 12 additions & 0 deletions src/Design.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,12 +101,24 @@ void Design::link(const std::string& design_name)
app->linkDesign(design_name.c_str(), false);
}

void Design::readDb(std::istream& stream)
{
auto app = OpenRoad::openRoad();
app->readDb(stream);
}

void Design::readDb(const std::string& file_name)
{
auto app = OpenRoad::openRoad();
app->readDb(file_name.c_str());
}

void Design::writeDb(std::ostream& stream)
{
auto app = OpenRoad::openRoad();
app->writeDb(stream);
}

void Design::writeDb(const std::string& file_name)
{
auto app = OpenRoad::openRoad();
Expand Down
25 changes: 18 additions & 7 deletions src/OpenRoad.cc
Original file line number Diff line number Diff line change
Expand Up @@ -438,28 +438,39 @@ void OpenRoad::writeCdl(const char* outFilename,
}

void OpenRoad::readDb(const char* filename)
{
std::ifstream stream;
stream.open(filename, std::ios::binary);
try {
readDb(stream);
} catch (const std::ios_base::failure& f) {
logger_->error(ORD, 54, "odb file {} is invalid: {}", filename, f.what());
}
}

void OpenRoad::readDb(std::istream& stream)
{
if (db_->getChip() && db_->getChip()->getBlock()) {
logger_->error(
ORD, 47, "You can't load a new db file as the db is already populated");
}

std::ifstream stream;
stream.exceptions(std::ifstream::failbit | std::ifstream::badbit
| std::ios::eofbit);
stream.open(filename, std::ios::binary);

try {
db_->read(stream);
} catch (const std::ios_base::failure& f) {
logger_->error(ORD, 54, "odb file {} is invalid: {}", filename, f.what());
}
db_->read(stream);

for (OpenRoadObserver* observer : observers_) {
observer->postReadDb(db_);
}
}

void OpenRoad::writeDb(std::ostream& stream)
{
stream.exceptions(std::ofstream::failbit | std::ofstream::badbit);
db_->write(stream);
}

void OpenRoad::writeDb(const char* filename)
{
utl::StreamHandler stream_handler(filename, true);
Expand Down

0 comments on commit b6c4933

Please sign in to comment.