diff --git a/include/ord/Design.h b/include/ord/Design.h index 23afdc67526..fbf13704d31 100644 --- a/include/ord/Design.h +++ b/include/ord/Design.h @@ -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); diff --git a/include/ord/OpenRoad.hh b/include/ord/OpenRoad.hh index 6efc3b8ae67..cd23a867e64 100644 --- a/include/ord/OpenRoad.hh +++ b/include/ord/OpenRoad.hh @@ -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); diff --git a/src/Design.cc b/src/Design.cc index c115c6e0771..a75b8537b89 100644 --- a/src/Design.cc +++ b/src/Design.cc @@ -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(); diff --git a/src/OpenRoad.cc b/src/OpenRoad.cc index 3a07e3b6795..c5fe1bc9e20 100644 --- a/src/OpenRoad.cc +++ b/src/OpenRoad.cc @@ -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);