Commit 44ce7a53 by lvzhengyang

use OpenSTA's verilog parser

parent 97d27f12
......@@ -89,7 +89,6 @@ add_compile_options(
add_subdirectory(main)
add_subdirectory(utl)
add_subdirectory(odb)
add_subdirectory(thirdparty)
add_subdirectory(db_mgr)
# add_subdirectory(thirdparty)
add_subdirectory(sta)
add_subdirectory(db_mgr)
......@@ -19,6 +19,10 @@ namespace utl {
class Logger;
}
namespace sta {
class Sta;
}
namespace eda {
namespace db_mgr {
......@@ -93,9 +97,8 @@ private:
std::unique_ptr<odb::lefin> lef_parser_;
std::unique_ptr<odb::defin> def_parser_;
// use Limbo's verilog parser
std::unique_ptr<VParser> verilog_parser_;
std::unique_ptr<sta::Sta> sta_;
};
} // namespace db_mgr
} // namespace eda
......
......@@ -4,6 +4,7 @@
#include "defin.h"
#include "utl/Logger.h"
#include "verilog_parser.h"
#include "sta/Sta.hh"
#include <cstring>
......@@ -26,9 +27,11 @@ void DbMgr::init(utl::Logger* logger)
setLogger(logger);
lib_db_ = odb::dbDatabase::create();
lef_parser_ = std::make_unique<odb::lefin>(lib_db_, logger_, false);
sta_ = std::make_unique<sta::Sta>();
// def_parser_
verilog_parser_ = std::make_unique<VParser>();
verilog_parser_->setLogger(logger_);
verilog_parser_->setSta(sta_.get());
}
DbMgr::~DbMgr()
......
......@@ -2,27 +2,17 @@ add_library(db_mgr_verilog_parser)
target_sources(db_mgr_verilog_parser
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/verilog_database.cpp
${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.cpp
)
target_include_directories(db_mgr_verilog_parser
PUBLIC
.
PRIVATE
${LIMBO_HOME}
)
target_link_libraries(db_mgr_verilog_parser
PUBLIC
odb
utl
PRIVATE
verilogparser # built in thirdparty Limbo
Boost::boost
)
target_compile_options(db_mgr_verilog_parser
PRIVATE
-D_GLIBCXX_USE_CXX11_ABI=0 # to avoid the std::string bug
OpenSTA
)
#include "verilog_parser.h"
#include "verilog_database.h"
#include "utl/Logger.h"
#include "db.h"
#include <cstring>
#define _GLIBCXX_USE_CXX11_ABI 0
#include "sta/VerilogReader.hh"
// TODO: add VerilogWriter later
// #include "VerilogWriter.hh"
#include "sta/Sta.hh"
namespace eda {
namespace db_mgr{
VParser::VParser()
: current_block_(nullptr),
odb_(nullptr),
logger_(nullptr)
: logger_(nullptr),
current_block_(nullptr),
odb_(nullptr),
sta_(nullptr)
{}
VParser::VParser(utl::Logger* logger,
odb::dbDatabase* db,
sta::Sta* sta)
{
v_db_ = std::make_unique<VDb>();
setLogger(logger);
setOdb(db);
setSta(sta);
}
void VParser::setLogger(utl::Logger* logger)
{
v_db_->setLogger(logger);
logger_ = logger;
}
void VParser::setOdb(odb::dbDatabase* db)
{
v_db_->setOdb(db);
odb_ = db;
if (db != nullptr) {
current_block_ = db->getChip()->getBlock();
}
}
bool VParser::read(const char* design_name,
const char* v_file)
void VParser::setSta(sta::Sta* sta)
{
std::string design_name_str(design_name, std::strlen(design_name));
std::string v_file_str(v_file, std::strlen(v_file));
return read(design_name_str, v_file_str);
sta_ = sta;
}
bool VParser::read(std::string const& design_name,
std::string const& v_file)
{
return read(design_name.c_str(), v_file.c_str());
}
bool VParser::read(const char* design_name,
const char* v_file)
{
if (current_block_ == nullptr) {
return false;
}
if (current_block_->getConstName() != design_name) {
return false;
}
VDb v_db;
v_db.setLogger(logger_);
v_db.setOdb(odb_);
return VerilogParser::read(v_db, v_file);
sta::NetworkReader *network = sta_->networkReader();
bool flag = false;
if (network) {
sta_->readNetlistBefore();
flag = sta::readVerilogFile(v_file, network);
} else {
return false;
}
if (!flag) {
return false;
}
// TODO: copy results to OpenDB
return true;
}
VParser::~VParser()
......
#ifndef _VERILOG_PARSER_H_
#define _VERILOG_PARSER_H_
#include "limbo/parsers/verilog/bison/VerilogDriver.h"
#include "sta/VerilogReader.hh"
#include <string>
#include <memory>
namespace odb {
class dbDatabase;
......@@ -14,17 +13,22 @@ namespace utl {
class Logger;
}
namespace sta{
class Sta;
}
namespace eda {
namespace db_mgr {
using VerilogParser::read;
class VDb;
class VParser
{
public:
VParser();
VParser(utl::Logger* logger,
odb::dbDatabase* db,
sta::Sta* sta);
~VParser();
bool read(std::string const& design_name,
std::string const& v_file);
......@@ -32,12 +36,14 @@ public:
const char* v_file);
void setLogger(utl::Logger* logger);
void setOdb(odb::dbDatabase* db);
void setSta(sta::Sta* sta);
private:
std::unique_ptr<VDb> v_db_;
odb::dbBlock* current_block_;
odb::dbDatabase* odb_;
utl::Logger* logger_;
sta::Sta* sta_;
};
} // namsepace db_mgr
......
add_library(db_mgr_verilog_parser)
target_sources(db_mgr_verilog_parser
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}/verilog_database.cpp
${CMAKE_CURRENT_SOURCE_DIR}/verilog_parser.cpp
)
target_include_directories(db_mgr_verilog_parser
PUBLIC
.
PRIVATE
${LIMBO_HOME}
)
target_link_libraries(db_mgr_verilog_parser
PUBLIC
odb
utl
PRIVATE
verilogparser # built in thirdparty Limbo
Boost::boost
OpenSTA
)
target_compile_options(db_mgr_verilog_parser
PRIVATE
-D_GLIBCXX_USE_CXX11_ABI=0 # to avoid the std::string bug
)
#include "verilog_parser.h"
#include "verilog_database.h"
#include "utl/Logger.h"
#include "db.h"
#include <cstring>
#define _GLIBCXX_USE_CXX11_ABI 0
namespace eda {
namespace db_mgr{
VParser::VParser()
: current_block_(nullptr),
odb_(nullptr),
logger_(nullptr)
{
v_db_ = std::make_unique<VDb>();
}
void VParser::setLogger(utl::Logger* logger)
{
v_db_->setLogger(logger);
logger_ = logger;
}
void VParser::setOdb(odb::dbDatabase* db)
{
v_db_->setOdb(db);
odb_ = db;
if (db != nullptr) {
current_block_ = db->getChip()->getBlock();
}
}
bool VParser::read(const char* design_name,
const char* v_file)
{
std::string design_name_str(design_name, std::strlen(design_name));
std::string v_file_str(v_file, std::strlen(v_file));
return read(design_name_str, v_file_str);
}
bool VParser::read(std::string const& design_name,
std::string const& v_file)
{
if (current_block_ == nullptr) {
return false;
}
if (current_block_->getConstName() != design_name) {
return false;
}
VDb v_db;
v_db.setLogger(logger_);
v_db.setOdb(odb_);
return VerilogParser::read(v_db, v_file);
}
VParser::~VParser()
{}
} // db_mgr
} // eda
\ No newline at end of file
#ifndef _VERILOG_PARSER_H_
#define _VERILOG_PARSER_H_
#include "limbo/parsers/verilog/bison/VerilogDriver.h"
#include "sta/VerilogReader.hh"
#include <string>
#include <memory>
namespace odb {
class dbDatabase;
class dbBlock;
}
namespace utl {
class Logger;
}
namespace eda {
namespace db_mgr {
using VerilogParser::read;
class VDb;
class VParser
{
public:
VParser();
~VParser();
bool read(std::string const& design_name,
std::string const& v_file);
bool read(const char* design_name,
const char* v_file);
void setLogger(utl::Logger* logger);
void setOdb(odb::dbDatabase* db);
private:
std::unique_ptr<VDb> v_db_;
odb::dbBlock* current_block_;
odb::dbDatabase* odb_;
utl::Logger* logger_;
};
} // namsepace db_mgr
} // namsepace eda
#endif
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