Commit 374c8b04 by lvzhengyang

implement read_lef

parent b1500981
{
"C_Cpp.default.configurationProvider": "go2sh.cmake-integration",
"files.associations": {
"*.cps": "javascript",
"logger.h": "c"
}
}
\ No newline at end of file
...@@ -5,14 +5,12 @@ ...@@ -5,14 +5,12 @@
## TODO ## TODO
* add OpenDB
* with swig
* use the original OpenDB, and build the tcl api by myself.
* add DB Manager * add DB Manager
* manager multi block circuits. Because OpenDB supports only 2-level hierarchical dbBlock. * manager multi block circuits. Because OpenDB supports only 2-level hierarchical dbBlock.
* each db is a block? * each db is a block?
* clean up Util.tcl
## DONE ## DONE
### 2022.10.30 ### 2022.10.30
...@@ -37,3 +35,7 @@ ...@@ -37,3 +35,7 @@
* logger: based on spdlog * logger: based on spdlog
* tcl_utl: evalTclInit which decode the user defined tcl scripts. * tcl_utl: evalTclInit which decode the user defined tcl scripts.
### 2022.11.27
* add OpenDB
include("swig_lib") include("swig_lib")
# swig_lib() swig_lib(NAME db_mgr
NAMESPACE db_mgr
add_library(db_mgr) I_FILE src/db_mgr.i
SCRIPTS src/db_mgr.tcl
SWIG_INCLUDES ${MINIEDA_HOME}/src/utl
)
target_sources(db_mgr target_sources(db_mgr
PRIVATE PRIVATE
...@@ -13,10 +16,11 @@ target_sources(db_mgr ...@@ -13,10 +16,11 @@ target_sources(db_mgr
target_include_directories(db_mgr target_include_directories(db_mgr
PUBLIC PUBLIC
include include
${MINIEDA_HOME}/src/main/include
) )
target_link_libraries(db_mgr target_link_libraries(db_mgr
PRIVATE PUBLIC
odb odb
utl utl
) )
......
...@@ -6,6 +6,8 @@ namespace db_mgr { ...@@ -6,6 +6,8 @@ namespace db_mgr {
class DbMgr; class DbMgr;
} }
class MiniEda;
/* /*
* this is one of the components of minieda, and * this is one of the components of minieda, and
* minieda should first call make*Comp*(), then * minieda should first call make*Comp*(), then
...@@ -15,6 +17,6 @@ class DbMgr; ...@@ -15,6 +17,6 @@ class DbMgr;
// simply return a ptr // simply return a ptr
db_mgr::DbMgr* makeDbMgr(); db_mgr::DbMgr* makeDbMgr();
// initDbMgr(); void initDbMgr(MiniEda* minieda);
} // namespace eda } // namespace eda
\ No newline at end of file
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
#include <unordered_map> #include <unordered_map>
#include <string> #include <string>
#include <memory>
namespace odb { namespace odb {
class dbDatabase; class dbDatabase;
...@@ -45,7 +46,8 @@ class DbMgr { ...@@ -45,7 +46,8 @@ class DbMgr {
public: public:
DbMgr(); DbMgr();
~DbMgr(); // dbDatadase::destroy() ~DbMgr(); // dbDatadase::destroy()
bool readLibDB(const char* path); bool readLibDB(const char* path, const char* libname,
bool isTech=false, bool isLib=true);
/* /*
bool readBlockDBs(); bool readBlockDBs();
bool addBlockDB(); bool addBlockDB();
...@@ -72,8 +74,7 @@ private: ...@@ -72,8 +74,7 @@ private:
utl::Logger* logger_; utl::Logger* logger_;
// parsers // parsers
odb::lefin* lef_parser_; std::unique_ptr<odb::lefin> lef_parser_;
}; };
} // namespace db_mgr } // namespace db_mgr
} // namespace eda } // namespace eda
......
#include <tcl.h>
#include "db_mgr/MakeDbMgr.h" #include "db_mgr/MakeDbMgr.h"
#include "db_mgr/db_mgr.h" #include "db_mgr/db_mgr.h"
#include "utl/Logger.h"
#include "utl/tcl_utl.h"
#include "eda/MiniEda.hh"
extern "C" {
extern int Db_mgr_Init(Tcl_Interp* interp);
}
namespace eda { namespace eda {
extern const char* db_mgr_tcl_inits[];
db_mgr::DbMgr* makeDbMgr() db_mgr::DbMgr* makeDbMgr()
{ {
return new db_mgr::DbMgr(); return new db_mgr::DbMgr();
} }
} // namespace eda void initDbMgr(MiniEda* minieda)
\ No newline at end of file {
Tcl_Interp* interp = minieda->tclInterp();
utl::evalTclInit(interp, db_mgr_tcl_inits);
minieda->getDbMgr()->init(minieda->getLogger());
Db_mgr_Init(interp);
}
} // namespace eda
#include <libgen.h> // for basename()
#include "db_mgr/db_mgr.h" #include "db_mgr/db_mgr.h"
#include "db.h" #include "db.h"
#include "lefin.h" #include "lefin.h"
...@@ -18,21 +16,19 @@ DbMgr::DbMgr() ...@@ -18,21 +16,19 @@ DbMgr::DbMgr()
void DbMgr::init(utl::Logger* logger) void DbMgr::init(utl::Logger* logger)
{ {
setLogger(logger); setLogger(logger);
lib_db_ = new odb::dbDatabase(); lib_db_ = odb::dbDatabase::create();
bool ignore_non_routing_layers = false; lef_parser_ = std::make_unique<odb::lefin>(lib_db_, logger_, false);
lef_parser_ = new odb::lefin(lib_db_, logger_,
ignore_non_routing_layers);
} }
DbMgr::~DbMgr() DbMgr::~DbMgr()
{ {
if (lib_db_ != nullptr) { if (lib_db_ != nullptr) {
lib_db_->destroy(lib_db_); odb::dbDatabase::destroy(lib_db_);
} }
if (!block_dbs_.empty()) { if (!block_dbs_.empty()) {
for (auto item : block_dbs_) { for (auto item : block_dbs_) {
odb::dbDatabase* block_db = item.second; odb::dbDatabase* db = item.second;
block_db->destroy(block_db); odb::dbDatabase::destroy(db);
} }
block_dbs_.clear(); block_dbs_.clear();
} }
...@@ -49,17 +45,23 @@ void DbMgr::setLogger(utl::Logger* logger) ...@@ -49,17 +45,23 @@ void DbMgr::setLogger(utl::Logger* logger)
logger_ = logger; logger_ = logger;
} }
bool DbMgr::readLibDB(const char* path) bool DbMgr::readLibDB(const char* path, const char* libname,
bool isTech, bool isLib)
{ {
const char* libname = basename(const_cast<char*>(path)); if (isTech && isLib) {
if (!lib_db_->getTech()) { lef_parser_->createTechAndLib(libname, path);
return lef_parser_->createTechAndLib(libname, path) != nullptr; } else if (isTech && !isLib) {
lef_parser_->createTech(path);
} else if (!isTech && isLib) {
lef_parser_->createLib(libname, path);
} else { } else {
return lef_parser_->createLib(libname, path) != nullptr; logger_->warn(utl::MGR, 1,
"Failed to read {}. LEF file must be Tech or Lib.",
path);
return false;
} }
return true; return true;
} }
} // namespace db_mgr } // namespace db_mgr
} // namespace eda } // namespace eda
%{
#include "db_mgr/db_mgr.h"
#include "utl/Logger.h"
namespace eda {
// defined in MiniEda.i
utl::Logger* getLogger();
db_mgr::DbMgr* getDbMgr();
} // namespace eda
using eda::getDbMgr;
using eda::getLogger;
%}
%include "Exception.i"
%inline %{
namespace db_mgr {
bool read_lef(const char* file_path, const char* libname,
bool isTech, bool isLib)
{
return getDbMgr()->readLibDB(file_path, libname, isTech, isLib);
}
} // namespace db_mgr
%} // inline
define_cmd_args "read_lef" { [-tech] \
[-lib] \
lef_name \
}
proc read_lef { args } {
parse_key_args "read_lef" args \
keys {} \
flags {-tech -library}
set lef_name [file nativename [lindex $args 0]]
if { ![file exists $lef_name] } {
utl::error "MGR" 1 "$lef_name does not exist."
}
if { ![file readable $lef_name] } {
utl::error "MGR" 2 "$lef_name is not readable."
}
set is_tech [info exists flags(-tech)]
if { $is_tech } {
set is_lib [info exists flags(-lib)]
} else {
# default true
set is_lib 1
}
set lib_name [file rootname [file tail $lef_name]]
db_mgr::read_lef $lef_name $lib_name $is_tech $is_lib
}
\ No newline at end of file
...@@ -76,8 +76,7 @@ void MiniEda::init(Tcl_Interp* interp) ...@@ -76,8 +76,7 @@ void MiniEda::init(Tcl_Interp* interp)
// defined in MakeModuleXX.h // defined in MakeModuleXX.h
initLogger(logger_, interp); initLogger(logger_, interp);
// TOBE implemented initDbMgr(this);
// initDbMgr(this);
} }
} // namespace eda } // namespace eda
...@@ -24,12 +24,10 @@ utl::Logger* getLogger() ...@@ -24,12 +24,10 @@ utl::Logger* getLogger()
return MiniEda::miniEda()->getLogger(); return MiniEda::miniEda()->getLogger();
} }
/*
db_mgr::DbMgr* getDbMgr() db_mgr::DbMgr* getDbMgr()
{ {
return MiniEda::miniEda()->getDbMgr(); return MiniEda::miniEda()->getDbMgr();
} }
*/
} // namespace eda } // namespace eda
...@@ -46,7 +44,7 @@ using eda::getLogger; ...@@ -46,7 +44,7 @@ using eda::getLogger;
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
#ifdef SWIGTCL #ifdef SWIGTCL
// %include "../Exception.i" %include "Exception.i"
// %typemap(in) utl::ToolId { // %typemap(in) utl::ToolId {
// int length; // int length;
...@@ -64,6 +62,11 @@ void logger_echo(const char* usr_input) ...@@ -64,6 +62,11 @@ void logger_echo(const char* usr_input)
getLogger()->info(utl::EDA, 1, usr_input); getLogger()->info(utl::EDA, 1, usr_input);
} }
// void read_lef(const char* lef_file)
// {
// getDbMgr()->readLibDB(lef_file);
// }
} }
%} // inline %} // inline
......
...@@ -8,7 +8,3 @@ proc simple_test {args} { ...@@ -8,7 +8,3 @@ proc simple_test {args} {
parse_key_args "simple_test" args keys {-tmp} parse_key_args "simple_test" args keys {-tmp}
logger_echo $keys(-tmp) logger_echo $keys(-tmp)
} }
proc get_db {} {
eda::get_db
}
...@@ -55,7 +55,7 @@ using eda::getLogger; ...@@ -55,7 +55,7 @@ using eda::getLogger;
} }
// Catch exceptions in inline functions. // Catch exceptions in inline functions.
// %include "../../Exception.i" %include "Exception.i"
%inline %{ %inline %{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment