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 @@
## TODO
* add OpenDB
* with swig
* use the original OpenDB, and build the tcl api by myself.
* add DB Manager
* manager multi block circuits. Because OpenDB supports only 2-level hierarchical dbBlock.
* each db is a block?
* clean up Util.tcl
## DONE
### 2022.10.30
......@@ -37,3 +35,7 @@
* logger: based on spdlog
* tcl_utl: evalTclInit which decode the user defined tcl scripts.
### 2022.11.27
* add OpenDB
include("swig_lib")
# swig_lib()
add_library(db_mgr)
swig_lib(NAME db_mgr
NAMESPACE db_mgr
I_FILE src/db_mgr.i
SCRIPTS src/db_mgr.tcl
SWIG_INCLUDES ${MINIEDA_HOME}/src/utl
)
target_sources(db_mgr
PRIVATE
......@@ -13,10 +16,11 @@ target_sources(db_mgr
target_include_directories(db_mgr
PUBLIC
include
${MINIEDA_HOME}/src/main/include
)
target_link_libraries(db_mgr
PRIVATE
PUBLIC
odb
utl
)
......
......@@ -6,6 +6,8 @@ namespace db_mgr {
class DbMgr;
}
class MiniEda;
/*
* this is one of the components of minieda, and
* minieda should first call make*Comp*(), then
......@@ -15,6 +17,6 @@ class DbMgr;
// simply return a ptr
db_mgr::DbMgr* makeDbMgr();
// initDbMgr();
void initDbMgr(MiniEda* minieda);
} // namespace eda
\ No newline at end of file
......@@ -5,6 +5,7 @@
#include <unordered_map>
#include <string>
#include <memory>
namespace odb {
class dbDatabase;
......@@ -45,7 +46,8 @@ class DbMgr {
public:
DbMgr();
~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 addBlockDB();
......@@ -72,8 +74,7 @@ private:
utl::Logger* logger_;
// parsers
odb::lefin* lef_parser_;
std::unique_ptr<odb::lefin> lef_parser_;
};
} // namespace db_mgr
} // namespace eda
......
#include <tcl.h>
#include "db_mgr/MakeDbMgr.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 {
extern const char* db_mgr_tcl_inits[];
db_mgr::DbMgr* makeDbMgr()
{
return new db_mgr::DbMgr();
}
} // namespace eda
\ No newline at end of file
void initDbMgr(MiniEda* minieda)
{
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.h"
#include "lefin.h"
......@@ -18,21 +16,19 @@ DbMgr::DbMgr()
void DbMgr::init(utl::Logger* logger)
{
setLogger(logger);
lib_db_ = new odb::dbDatabase();
bool ignore_non_routing_layers = false;
lef_parser_ = new odb::lefin(lib_db_, logger_,
ignore_non_routing_layers);
lib_db_ = odb::dbDatabase::create();
lef_parser_ = std::make_unique<odb::lefin>(lib_db_, logger_, false);
}
DbMgr::~DbMgr()
{
if (lib_db_ != nullptr) {
lib_db_->destroy(lib_db_);
odb::dbDatabase::destroy(lib_db_);
}
if (!block_dbs_.empty()) {
for (auto item : block_dbs_) {
odb::dbDatabase* block_db = item.second;
block_db->destroy(block_db);
odb::dbDatabase* db = item.second;
odb::dbDatabase::destroy(db);
}
block_dbs_.clear();
}
......@@ -49,17 +45,23 @@ void DbMgr::setLogger(utl::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 (!lib_db_->getTech()) {
return lef_parser_->createTechAndLib(libname, path) != nullptr;
if (isTech && isLib) {
lef_parser_->createTechAndLib(libname, path);
} else if (isTech && !isLib) {
lef_parser_->createTech(path);
} else if (!isTech && isLib) {
lef_parser_->createLib(libname, path);
} 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;
}
} // namespace db_mgr
} // 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)
// defined in MakeModuleXX.h
initLogger(logger_, interp);
// TOBE implemented
// initDbMgr(this);
initDbMgr(this);
}
} // namespace eda
......@@ -24,12 +24,10 @@ utl::Logger* getLogger()
return MiniEda::miniEda()->getLogger();
}
/*
db_mgr::DbMgr* getDbMgr()
{
return MiniEda::miniEda()->getDbMgr();
}
*/
} // namespace eda
......@@ -46,7 +44,7 @@ using eda::getLogger;
////////////////////////////////////////////////////////////////
#ifdef SWIGTCL
// %include "../Exception.i"
%include "Exception.i"
// %typemap(in) utl::ToolId {
// int length;
......@@ -64,6 +62,11 @@ void logger_echo(const char* usr_input)
getLogger()->info(utl::EDA, 1, usr_input);
}
// void read_lef(const char* lef_file)
// {
// getDbMgr()->readLibDB(lef_file);
// }
}
%} // inline
......
......@@ -8,7 +8,3 @@ proc simple_test {args} {
parse_key_args "simple_test" args keys {-tmp}
logger_echo $keys(-tmp)
}
proc get_db {} {
eda::get_db
}
......@@ -55,7 +55,7 @@ using eda::getLogger;
}
// Catch exceptions in inline functions.
// %include "../../Exception.i"
%include "Exception.i"
%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