Merge pull request #324 from The-OpenROAD-Project-staging/sta_latest_merge_strings

Sta latest merge strings
This commit is contained in:
Matt Liberty 2026-03-31 02:00:13 +00:00 committed by GitHub
commit fe61456df6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
190 changed files with 4906 additions and 5570 deletions

View File

@ -22,24 +22,9 @@
#
# This notice may not be removed or altered from any source distribution.
cmake_minimum_required (VERSION 3.10)
cmake_minimum_required (VERSION 3.16)
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.12)
# Use <PACKAGENAME>_ROOT in find_package
cmake_policy(SET CMP0074 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.13)
# Use standard target names
cmake_policy(SET CMP0078 NEW)
endif()
if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
# Allows SWIG_MODULE_NAME to be set
cmake_policy(SET CMP0086 NEW)
endif()
project(STA VERSION 3.0.1
project(STA VERSION 3.1.0
LANGUAGES CXX
)
@ -460,6 +445,7 @@ configure_file(${STA_HOME}/util/StaConfig.hh.cmake
###########################################################
find_package(SWIG 3.0 REQUIRED)
message(STATUS "SWIG version: ${SWIG_VERSION}")
include(UseSWIG)
set(STA_SWIG_FILE app/StaApp.i)
@ -467,14 +453,12 @@ set(STA_SWIG_FILE app/StaApp.i)
set_property(SOURCE ${STA_SWIG_FILE}
PROPERTY CPLUSPLUS ON
)
# Ubuntu 18.04 cmake version 3.10.2 does not support the
# COMPILE_OPTIONS and INCLUDE_DIRECTORIES properties, so cram
# them into SWIG_FLAGS for the time being.
# SWIG flags (CMake UseSWIG).
set_property(SOURCE ${STA_SWIG_FILE}
PROPERTY SWIG_FLAGS
PROPERTY COMPILE_OPTIONS
-module sta
-namespace -prefix sta
-I${STA_HOME}
-namespace
-prefix sta
)
set(SWIG_FILES
@ -531,6 +515,9 @@ target_include_directories(sta_swig
${CMAKE_CURRENT_BINARY_DIR}/include/sta
)
# Pass sta_swig include directories to SWIG as -I (same paths as the C++ build).
set_property(TARGET sta_swig PROPERTY SWIG_USE_TARGET_INCLUDE_DIRECTORIES TRUE)
###########################################################
# Library
###########################################################

View File

@ -28,6 +28,7 @@
#include <stdio.h>
#include <cstdlib> // exit
#include <filesystem>
#include <string_view>
#include <tcl.h>
#if TCL_READLINE
#include <tclreadline.h>
@ -58,14 +59,14 @@ static char **cmd_argv;
static const char *init_filename = ".sta";
static void
showUsage(const char *prog,
const char *init_filename);
showUsage(std::string_view prog,
std::string_view init_filename);
static int
tclAppInit(Tcl_Interp *interp);
static int
staTclAppInit(int argc,
char *argv[],
const char *init_filename,
std::string_view init_filename,
Tcl_Interp *interp);
static void
initStaApp(int &argc,
@ -105,7 +106,7 @@ tclAppInit(Tcl_Interp *interp)
static int
staTclAppInit(int argc,
char *argv[],
const char *init_filename,
std::string_view init_filename,
Tcl_Interp *interp)
{
// source init.tcl
@ -130,7 +131,7 @@ staTclAppInit(int argc,
if (home) {
std::string init_path = home;
init_path += "/";
init_path += init_filename;
init_path.append(init_filename);
if (std::filesystem::is_regular_file(init_path.c_str()))
sourceTclFile(init_path.c_str(), true, true, interp);
}
@ -183,15 +184,17 @@ initStaApp(int &argc,
}
static void
showUsage(const char *prog,
const char *init_filename)
showUsage(std::string_view prog,
std::string_view init_filename)
{
printf("Usage: %s [-help] [-version] [-no_init] [-exit] cmd_file\n", prog);
printf(" -help show help and exit\n");
printf(" -version show version and exit\n");
printf(" -no_init do not read %s init file\n", init_filename);
printf(" -threads count|max use count threads\n");
printf(" -no_splash do not show the license splash at startup\n");
printf(" -exit exit after reading cmd_file\n");
printf(" cmd_file source cmd_file\n");
sta::print(stdout, "Usage: {} [-help] [-version] [-no_init] [-exit] cmd_file\n",
prog);
sta::print(stdout, " -help show help and exit\n");
sta::print(stdout, " -version show version and exit\n");
sta::print(stdout, " -no_init do not read {} init file\n",
init_filename);
sta::print(stdout, " -threads count|max use count threads\n");
sta::print(stdout, " -no_splash do not show the license splash at startup\n");
sta::print(stdout, " -exit exit after reading cmd_file\n");
sta::print(stdout, " cmd_file source cmd_file\n");
}

View File

@ -24,6 +24,8 @@
#include "StaMain.hh"
#include <string>
#include <string_view>
#include <tcl.h>
#include <cstdlib>
#include <sys/stat.h>
@ -43,7 +45,7 @@ parseThreadsArg(int &argc,
if (stringEqual(thread_arg, "max"))
return processorCount();
else if (isDigits(thread_arg))
return atoi(thread_arg);
return std::stoi(thread_arg);
else
fprintf(stderr,"Warning: -threads must be max or a positive integer.\n");
}
@ -53,11 +55,11 @@ parseThreadsArg(int &argc,
bool
findCmdLineFlag(int &argc,
char *argv[],
const char *flag)
std::string_view flag)
{
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (stringEq(arg, flag)) {
if (std::string_view(arg) == flag) {
// Remove flag from argv.
for (int j = i + 1; j < argc; j++, i++)
argv[i] = argv[j];
@ -72,11 +74,11 @@ findCmdLineFlag(int &argc,
char *
findCmdLineKey(int &argc,
char *argv[],
const char *key)
std::string_view key)
{
for (int i = 1; i < argc; i++) {
char *arg = argv[i];
if (stringEq(arg, key) && i + 1 < argc) {
if (std::string_view(arg) == key && i + 1 < argc) {
char *value = argv[i + 1];
// Remove key and value from argv.
for (int j = i + 2; j < argc; j++, i++)

View File

@ -25,7 +25,9 @@
#include "ArcDelayCalc.hh"
#include <cstdlib>
#include <string>
#include "StringUtil.hh"
#include "Units.hh"
#include "Liberty.hh"
#include "TimingArc.hh"
@ -61,13 +63,14 @@ ArcDelayCalc::gateDelay(const TimingArc *arc,
////////////////////////////////////////////////////////////////
// For TCL %typemap(in) ArcDcalcArg.
ArcDcalcArg
makeArcDcalcArg(const char *inst_name,
const char *in_port_name,
const char *in_rf_name,
const char *drvr_port_name,
const char *drvr_rf_name,
const char *input_delay_str,
makeArcDcalcArg(std::string_view inst_name,
std::string_view in_port_name,
std::string_view in_rf_name,
std::string_view drvr_port_name,
std::string_view drvr_rf_name,
std::string_view input_delay_str,
const StaState *sta)
{
Report *report = sta->report();
@ -82,7 +85,8 @@ makeArcDcalcArg(const char *inst_name,
if (drvr_pin) {
const RiseFall *drvr_rf = RiseFall::find(drvr_rf_name);
if (drvr_rf) {
float input_delay = strtof(input_delay_str, nullptr);
const std::string input_delay_buf(input_delay_str);
auto [input_delay, valid] = stringFloat(input_delay_buf);
input_delay = sta->units()->timeUnit()->userToSta(input_delay);
const Graph *graph = sta->graph();

View File

@ -121,7 +121,7 @@ public:
ArnoldiDelayCalc(StaState *sta);
~ArnoldiDelayCalc() override;
ArcDelayCalc *copy() override;
const char *name() const override { return "arnoldi"; }
std::string_view name() const override { return "arnoldi"; }
Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf,
const Scene *scene,

View File

@ -670,7 +670,7 @@ CcsCeffDelayCalc::reportGateDelay(const Pin *drvr_pin,
}
void
CcsCeffDelayCalc::fail(const char *reason)
CcsCeffDelayCalc::fail(std::string_view reason)
{
// Report failures with a unique debug flag.
if (debug_->check("ccs_dcalc", 1) || debug_->check("dcalc_error", 1))

View File

@ -41,7 +41,7 @@ public:
CcsCeffDelayCalc(StaState *sta);
virtual ~CcsCeffDelayCalc();
ArcDelayCalc *copy() override;
const char *name() const override { return "ccs_ceff"; }
std::string_view name() const override { return "ccs_ceff"; }
bool reduceSupported() const override { return true; }
ArcDcalcResult gateDelay(const Pin *drvr_pin,
const TimingArc *arc,
@ -113,7 +113,7 @@ protected:
double &dvl_dt);
double vl(double t,
double elmore);
void fail(const char *reason);
void fail(std::string_view reason);
const Pin *drvr_pin_;
const RiseFall *drvr_rf_;

View File

@ -38,7 +38,7 @@
namespace sta {
typedef std::map<std::string, MakeArcDelayCalc> DelayCalcMap;
typedef std::map<std::string, MakeArcDelayCalc, std::less<>> DelayCalcMap;
static DelayCalcMap delay_calcs;
@ -55,10 +55,10 @@ registerDelayCalcs()
}
void
registerDelayCalc(const std::string &name,
registerDelayCalc(std::string_view name,
MakeArcDelayCalc maker)
{
delay_calcs[name] = maker;
delay_calcs[std::string(name)] = maker;
}
void
@ -68,10 +68,10 @@ deleteDelayCalcs()
}
ArcDelayCalc *
makeDelayCalc(const std::string &name,
makeDelayCalc(const std::string_view name,
StaState *sta)
{
MakeArcDelayCalc maker = findKey(&delay_calcs, name);
MakeArcDelayCalc maker = findStringKey(delay_calcs, name);
if (maker)
return maker(sta);
else
@ -79,7 +79,7 @@ makeDelayCalc(const std::string &name,
}
bool
isDelayCalcName(const std::string &name)
isDelayCalcName(std::string_view name)
{
return delay_calcs.contains(name);
}

View File

@ -24,6 +24,8 @@
%module dcalc
%include <std_string.i>
%{
#include "DelayCalc.hh"

View File

@ -174,7 +174,7 @@ std::string
DelayCalcBase::reportCheckDelay(const Pin *check_pin,
const TimingArc *arc,
const Slew &from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
const Slew &to_slew,
float related_out_cap,
const Scene *scene,

View File

@ -58,7 +58,7 @@ public:
std::string reportCheckDelay(const Pin *check_pin,
const TimingArc *arc,
const Slew &from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
const Slew &to_slew,
float related_out_cap,
const Scene *scene,

View File

@ -35,6 +35,7 @@
#include <algorithm>
#include <cmath>
#include <functional>
#include <string_view>
#include "Format.hh"
#include "Report.hh"
@ -126,7 +127,7 @@ public:
DmpAlg(int nr_order,
StaState *sta);
~DmpAlg() override = default;
virtual const char *name() = 0;
virtual std::string_view name() = 0;
// Set driver model and pi model parameters for delay calculation.
virtual void init(const LibertyLibrary *library,
const LibertyCell *drvr_cell,
@ -201,7 +202,7 @@ protected:
double lower_bound,
double upper_bound);
void showVl();
void fail(const char *reason);
void fail(std::string_view reason);
// Output response to vs(t) ramp driving capacitive load.
double y(double t,
@ -655,7 +656,7 @@ DmpAlg::showVl()
}
void
DmpAlg::fail(const char *reason)
DmpAlg::fail(std::string_view reason)
{
// Report failures with a unique debug flag.
if (debug_->check("dmp_ceff", 1) || debug_->check("dcalc_error", 1))
@ -673,7 +674,7 @@ class DmpCap : public DmpAlg
{
public:
DmpCap(StaState *sta);
const char *name() override { return "cap"; }
std::string_view name() override { return "cap"; }
void init(const LibertyLibrary *library,
const LibertyCell *drvr_cell,
const Pvt *pvt,
@ -789,7 +790,7 @@ class DmpPi : public DmpAlg
{
public:
DmpPi(StaState *sta);
const char *name() override { return "Pi"; }
std::string_view name() override { return "Pi"; }
void init(const LibertyLibrary *library,
const LibertyCell *drvr_cell,
const Pvt *pvt,
@ -1115,7 +1116,7 @@ class DmpZeroC2 : public DmpOnePole
{
public:
DmpZeroC2(StaState *sta);
const char *name() override { return "c2=0"; }
std::string_view name() override { return "c2=0"; }
void init(const LibertyLibrary *drvr_library,
const LibertyCell *drvr_cell,
const Pvt *pvt,

View File

@ -43,7 +43,7 @@ class DmpCeffElmoreDelayCalc : public DmpCeffDelayCalc
public:
DmpCeffElmoreDelayCalc(StaState *sta);
ArcDelayCalc *copy() override;
const char *name() const override { return "dmp_ceff_elmore"; }
std::string_view name() const override { return "dmp_ceff_elmore"; }
ArcDcalcResult inputPortDelay(const Pin *port_pin,
float in_slew,
const RiseFall *rf,
@ -139,7 +139,7 @@ class DmpCeffTwoPoleDelayCalc : public DmpCeffDelayCalc
public:
DmpCeffTwoPoleDelayCalc(StaState *sta);
ArcDelayCalc *copy() override;
const char *name() const override { return "dmp_ceff_two_pole"; }
std::string_view name() const override { return "dmp_ceff_two_pole"; }
Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf,
const Scene *scene,

View File

@ -27,6 +27,7 @@
#include <cmath>
#include <array>
#include <set>
#include <string_view>
#include "ContainerHelpers.hh"
#include "Debug.hh"
@ -1685,7 +1686,8 @@ GraphDelayCalc::reportDelayCalc(const Edge *edge,
const Slew to_slew = graph_->slew(to_vertex, to_rf, slew_index);
const ClkNetwork *clk_network = scene->mode()->clkNetwork();
bool from_ideal_clk = clk_network->isIdealClock(from_vertex);
const char *from_slew_annotation = from_ideal_clk ? " (ideal clock)" : nullptr;
std::string_view from_slew_annotation =
from_ideal_clk ? std::string_view(" (ideal clock)") : std::string_view{};
result = arc_delay_calc_->reportCheckDelay(to_pin, arc, from_slew,
from_slew_annotation, to_slew,
related_out_cap, scene, min_max, digits);

View File

@ -35,7 +35,7 @@ class LumpedCapDelayCalc : public ParallelDelayCalc
public:
LumpedCapDelayCalc(StaState *sta);
ArcDelayCalc *copy() override;
const char *name() const override { return "lumped_cap"; }
std::string_view name() const override { return "lumped_cap"; }
Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf,
const Scene *scene,

View File

@ -25,6 +25,7 @@
#include "PrimaDelayCalc.hh"
#include <cmath> // abs
#include <string_view>
#include "Debug.hh"
#include "Units.hh"
@ -951,7 +952,7 @@ PrimaDelayCalc::watchWaveform(const Pin *pin)
////////////////////////////////////////////////////////////////
void
PrimaDelayCalc::reportMatrix(const char *name,
PrimaDelayCalc::reportMatrix(std::string_view name,
MatrixSd &matrix)
{
report_->report("{}", name);
@ -959,7 +960,7 @@ PrimaDelayCalc::reportMatrix(const char *name,
}
void
PrimaDelayCalc::reportMatrix(const char *name,
PrimaDelayCalc::reportMatrix(std::string_view name,
Eigen::MatrixXd &matrix)
{
report_->report("{}", name);
@ -967,7 +968,7 @@ PrimaDelayCalc::reportMatrix(const char *name,
}
void
PrimaDelayCalc::reportMatrix(const char *name,
PrimaDelayCalc::reportMatrix(std::string_view name,
Eigen::VectorXd &matrix)
{
report_->report("{}", name);
@ -975,7 +976,7 @@ PrimaDelayCalc::reportMatrix(const char *name,
}
void
PrimaDelayCalc::reportVector(const char *name,
PrimaDelayCalc::reportVector(std::string_view name,
std::vector<double> &matrix)
{
report_->report("{}", name);

View File

@ -60,7 +60,7 @@ public:
~PrimaDelayCalc();
ArcDelayCalc *copy() override;
void copyState(const StaState *sta) override;
const char *name() const override { return "prima"; }
std::string_view name() const override { return "prima"; }
void setPrimaReduceOrder(size_t order);
Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf,
@ -157,13 +157,13 @@ protected:
void primaReduce();
void primaReduce2();
void reportMatrix(const char *name,
void reportMatrix(std::string_view name,
MatrixSd &matrix);
void reportMatrix(const char *name,
void reportMatrix(std::string_view name,
Eigen::MatrixXd &matrix);
void reportMatrix(const char *name,
void reportMatrix(std::string_view name,
Eigen::VectorXd &matrix);
void reportVector(const char *name,
void reportVector(std::string_view name,
std::vector<double> &matrix);
void reportMatrix(MatrixSd &matrix);
void reportMatrix(Eigen::MatrixXd &matrix);

View File

@ -172,7 +172,7 @@ std::string
UnitDelayCalc::reportCheckDelay(const Pin *,
const TimingArc *,
const Slew &,
const char *,
std::string_view,
const Slew &,
float,
const Scene *,

View File

@ -34,7 +34,7 @@ class UnitDelayCalc : public ArcDelayCalc
public:
UnitDelayCalc(StaState *sta);
ArcDelayCalc *copy() override;
const char *name() const override { return "unit"; }
std::string_view name() const override { return "unit"; }
Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf,
const Scene *scene,
@ -94,7 +94,7 @@ public:
std::string reportCheckDelay(const Pin *check_pin,
const TimingArc *arc,
const Slew &from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
const Slew &to_slew,
float related_out_cap,
const Scene *scene,

View File

@ -24,6 +24,33 @@
This file summarizes STA API changes for each release.
Release 3.1.0 2026/03/25
------------------------
OpenSTA now uses std::string and std::string_view instead of const char *.
Lookup funtions such as Network::findPin use std::string_view that accept
a const char *, std::string, or std::string_view caller argument.
2026/03/19
----------
LibertyCell::footprint() returns const std::string& instead of const char*.
LibertyCell::userFunctionClass returns const std::string& instead of const char*.
The Sdc, Liberty, ConcreteLibrary, ConcreteNetwork classes have been updated to
use std::string and std::string_view instead of const char *. std::string_view
is used when the lifetime of the string argument is only while the function is
called. std::string is used when the string value outlives the function call
because it is stored in data structures.
The LibertyPort functions
relatedGroundPin
relatedPowerPin
are renamed to
relatedGroundPort
relatedPowerPort
and return LibertyPort's instead of strings.
2026/03/12
----------
@ -37,7 +64,7 @@ stdstrPrint, strintPrint, stringAppend have been removed. Use sta::format.
reportLineString is now reportLine
Release 3.0.0 2025/01/03
Release 3.0.0 2026/01/03
------------------------
OpenSTA now requires c++ 20.

View File

@ -52,7 +52,7 @@ Graph::Graph(StaState *sta,
vertices_(nullptr),
edges_(nullptr),
ap_count_(ap_count),
period_check_annotations_(nullptr),
period_check_annotations_(network_),
reg_clk_vertices_(makeVertexSet(this))
{
// For the benifit of reg_clk_vertices_ that references graph_.
@ -910,13 +910,11 @@ Graph::periodCheckAnnotation(const Pin *pin,
bool &exists)
{
exists = false;
if (period_check_annotations_) {
float *periods = findKey(period_check_annotations_, pin);
if (periods) {
period = periods[ap_index];
if (period >= 0.0)
exists = true;
}
float *periods = findKey(period_check_annotations_, pin);
if (periods) {
period = periods[ap_index];
if (period >= 0.0)
exists = true;
}
}
@ -925,15 +923,13 @@ Graph::setPeriodCheckAnnotation(const Pin *pin,
DcalcAPIndex ap_index,
float period)
{
if (period_check_annotations_ == nullptr)
period_check_annotations_ = new PeriodCheckAnnotations(network_);
float *periods = findKey(period_check_annotations_, pin);
if (periods == nullptr) {
periods = new float[ap_count_];
// Use negative (illegal) period values to indicate unannotated checks.
for (int i = 0; i < ap_count_; i++)
periods[i] = -1;
(*period_check_annotations_)[pin] = periods;
period_check_annotations_[pin] = periods;
}
periods[ap_index] = period;
}
@ -941,12 +937,9 @@ Graph::setPeriodCheckAnnotation(const Pin *pin,
void
Graph::removePeriodCheckAnnotations()
{
if (period_check_annotations_) {
for (const auto [pin, periods] : *period_check_annotations_)
delete [] periods;
delete period_check_annotations_;
period_check_annotations_ = nullptr;
}
for (auto& [pin, periods] : period_check_annotations_)
delete [] periods;
period_check_annotations_.clear();
}
void
@ -1026,7 +1019,7 @@ Vertex::to_string(const StaState *sta) const
{
const Network *network = sta->sdcNetwork();
if (network->direction(pin_)->isBidirect()) {
std::string str = network->pathName(pin_);
std::string str(network->pathName(pin_));
str += ' ';
str += is_bidirect_drvr_ ? "driver" : "load";
return str;
@ -1035,11 +1028,10 @@ Vertex::to_string(const StaState *sta) const
return network->pathName(pin_);
}
const char *
std::string
Vertex::name(const Network *network) const
{
std::string name = to_string(network);
return makeTmpString(name);
return to_string(network);
}
bool

View File

@ -180,7 +180,7 @@ Vertex *to() { return self->to(Sta::sta()->graph()); }
Pin *from_pin() { return self->from(Sta::sta()->graph())->pin(); }
Pin *to_pin() { return self->to(Sta::sta()->graph())->pin(); }
const TimingRole *role() { return self->role(); }
const char *sense() { return to_string(self->sense()); }
const char *sense() { return to_string(self->sense()).c_str(); }
TimingArcSeq &
timing_arcs() { return self->timingArcSet()->arcs(); }
bool is_disabled_loop() { return Sta::sta()->isDisabledLoop(self); }
@ -212,13 +212,16 @@ disabled_constant_pins()
bool is_disabled_bidirect_inst_path()
{ return Sta::sta()->isDisabledBidirectInstPath(self); }
bool is_disabled_preset_clear()
{ return Sta::sta()->isDisabledPresetClr(self); }
const char *
sim_timing_sense(){
sim_timing_sense()
{
Sta *sta = Sta::sta();
const Mode *mode = sta->cmdMode();
return to_string(sta->simTimingSense(self, mode));
return to_string(sta->simTimingSense(self, mode)).c_str();
}
FloatSeq

View File

@ -953,8 +953,8 @@ TEST_F(GraphDesignTest, GraphVerticesAndEdges) {
Vertex *vertex = graph->pinDrvrVertex(pin);
if (vertex) {
// Vertex::name needs network
const char *vname = vertex->name(network);
EXPECT_NE(vname, nullptr);
std::string vname = vertex->name(network);
EXPECT_FALSE(vname.empty());
found++;
}
}
@ -979,9 +979,8 @@ TEST_F(GraphDesignTest, VertexName) {
if (y_pin) {
Vertex *v = graph->pinDrvrVertex(y_pin);
if (v) {
const char *name = v->name(network);
EXPECT_NE(name, nullptr);
EXPECT_NE(strlen(name), 0u);
std::string name = v->name(network);
EXPECT_FALSE(name.empty());
}
}
}
@ -1076,7 +1075,7 @@ protected:
FloatSeq *waveform = new FloatSeq;
waveform->push_back(0.0f);
waveform->push_back(5.0f);
sta_->makeClock("clk", clk_pins, false, 10.0f, waveform, nullptr, sta_->cmdMode());
sta_->makeClock("clk", clk_pins, false, 10.0f, waveform, "", sta_->cmdMode());
Clock *clk = sta_->cmdSdc()->findClock("clk");
ASSERT_NE(clk, nullptr);
@ -1456,7 +1455,7 @@ protected:
FloatSeq *wave1 = new FloatSeq;
wave1->push_back(0.0f);
wave1->push_back(5.0f);
sta_->makeClock("clk1", clk1_pins, false, 10.0f, wave1, nullptr, sta_->cmdMode());
sta_->makeClock("clk1", clk1_pins, false, 10.0f, wave1, "", sta_->cmdMode());
// Create clock2
Pin *clk2_pin = network->findPin(top, "clk2");
@ -1466,7 +1465,7 @@ protected:
FloatSeq *wave2 = new FloatSeq;
wave2->push_back(0.0f);
wave2->push_back(2.5f);
sta_->makeClock("clk2", clk2_pins, false, 5.0f, wave2, nullptr, sta_->cmdMode());
sta_->makeClock("clk2", clk2_pins, false, 5.0f, wave2, "", sta_->cmdMode());
// Input delays
Clock *clk1 = sta_->cmdSdc()->findClock("clk1");
@ -1665,7 +1664,7 @@ protected:
FloatSeq *waveform = new FloatSeq;
waveform->push_back(0.0f);
waveform->push_back(5.0f);
sta_->makeClock("clk", clk_pins, false, 10.0f, waveform, nullptr, sta_->cmdMode());
sta_->makeClock("clk", clk_pins, false, 10.0f, waveform, "", sta_->cmdMode());
Clock *clk = sta_->cmdSdc()->findClock("clk");
ASSERT_NE(clk, nullptr);
@ -1930,7 +1929,7 @@ protected:
FloatSeq *waveform = new FloatSeq;
waveform->push_back(0.0f);
waveform->push_back(5.0f);
sta_->makeClock("clk", clk_pins, false, 10.0f, waveform, nullptr, sta_->cmdMode());
sta_->makeClock("clk", clk_pins, false, 10.0f, waveform, "", sta_->cmdMode());
Clock *clk = sta_->cmdSdc()->findClock("clk");
ASSERT_NE(clk, nullptr);

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
#include <map>
@ -103,12 +104,12 @@ protected:
ArcDcalcArg
makeArcDcalcArg(const char *inst_name,
const char *in_port_name,
const char *in_rf_name,
const char *drvr_port_name,
const char *drvr_rf_name,
const char *input_delay_str,
makeArcDcalcArg(std::string_view inst_name,
std::string_view in_port_name,
std::string_view in_rf_name,
std::string_view drvr_port_name,
std::string_view drvr_rf_name,
std::string_view input_delay_str,
const StaState *sta);
// Arc delay calc result.
@ -161,7 +162,7 @@ public:
ArcDelayCalc(StaState *sta);
virtual ~ArcDelayCalc() {}
virtual ArcDelayCalc *copy() = 0;
virtual const char *name() const = 0;
virtual std::string_view name() const = 0;
// Find the parasitic for drvr_pin that is acceptable to the delay
// calculator by probing parasitics_.
@ -252,7 +253,7 @@ public:
virtual std::string reportCheckDelay(const Pin *check_pin,
const TimingArc *arc,
const Slew &from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
const Slew &to_slew,
float related_out_cap,
const Scene *scene,

View File

@ -41,7 +41,7 @@ class Clock : public SdcCmdComment
{
public:
~Clock();
const char *name() const { return name_; }
const std::string &name() const { return name_; }
float period() const { return period_; }
// Virtual clocks have no pins.
bool isVirtual() const;
@ -135,14 +135,14 @@ public:
protected:
// Private to Sdc::makeClock.
Clock(const char *name,
Clock(std::string_view name,
int index,
const Network *network);
void initClk(PinSet *pins,
bool add_to_pins,
float period,
FloatSeq *waveform,
const char *comment,
std::string_view comment,
const Network *network);
void initGeneratedClk(PinSet *pins,
bool add_to_pins,
@ -156,7 +156,7 @@ protected:
IntSeq *edges,
FloatSeq *edge_shifts,
bool is_propagated,
const char *comment,
std::string_view comment,
const Network *network);
void setPins(PinSet *pins,
const Network *network);
@ -168,7 +168,7 @@ protected:
float scale);
void generateEdgesClk(const Clock *src_clk);
const char *name_;
std::string name_;
PinSet pins_;
bool add_to_pins_;
// Hierarchical pins in pins_ become driver pins through the pin.
@ -241,7 +241,10 @@ class ClockNameLess
{
public:
bool operator()(const Clock *clk1,
const Clock *clk2);
const Clock *clk2) const
{
return clk1->name() < clk2->name();
}
};
////////////////////////////////////////////////////////////////
@ -282,16 +285,6 @@ public:
const InterClockUncertainty *inter2) const;
};
class ClkNameLess
{
public:
bool operator()(const Clock *clk1,
const Clock *clk2) const
{
return stringLess(clk1->name(), clk2->name());
}
};
ClockSeq
sortByName(ClockSet *set);
int

View File

@ -39,7 +39,7 @@ public:
bool physically_exclusive,
bool asynchronous,
bool allow_paths,
const char *comment);
std::string comment);
~ClockGroups();
void makeClockGroup(ClockSet *clks);
const std::string &name() const { return name_; }

View File

@ -25,6 +25,7 @@
#pragma once
#include <functional>
#include <string_view>
#include <vector>
#include <map>
@ -45,9 +46,9 @@ class PatternMatch;
class LibertyCell;
class LibertyPort;
using ConcreteCellMap = std::map<std::string, ConcreteCell*>;
using ConcreteCellMap = std::map<std::string, ConcreteCell*, std::less<>>;
using ConcretePortSeq = std::vector<ConcretePort*>;
using ConcretePortMap = std::map<std::string, ConcretePort*>;
using ConcretePortMap = std::map<std::string, ConcretePort*, std::less<>>;
using ConcreteLibraryCellIterator = MapIterator<ConcreteCellMap, ConcreteCell*>;
using ConcreteCellPortIterator = VectorIterator<ConcretePortSeq, ConcretePort*>;
using ConcretePortMemberIterator = VectorIterator<ConcretePortSeq, ConcretePort*>;
@ -55,22 +56,21 @@ using ConcretePortMemberIterator = VectorIterator<ConcretePortSeq, ConcretePort*
class ConcreteLibrary
{
public:
ConcreteLibrary(const char *name,
const char *filename,
ConcreteLibrary(std::string name,
std::string filename,
bool is_liberty);
virtual ~ConcreteLibrary();
const char *name() const { return name_.c_str(); }
void setName(const char *name);
const std::string &name() const { return name_; }
ObjectId id() const { return id_; }
bool isLiberty() const { return is_liberty_; }
const char *filename() const { return filename_.c_str(); }
const std::string &filename() const { return filename_; }
void addCell(ConcreteCell *cell);
ConcreteCell *makeCell(const char *name,
ConcreteCell *makeCell(std::string_view name,
bool is_leaf,
const char *filename);
std::string_view filename);
void deleteCell(ConcreteCell *cell);
ConcreteLibraryCellIterator *cellIterator() const;
ConcreteCell *findCell(const char *name) const;
ConcreteCell *findCell(std::string_view name) const;
CellSeq findCellsMatching(const PatternMatch *pattern) const;
char busBrktLeft() const { return bus_brkt_left_; }
char busBrktRight() const { return bus_brkt_right_; }
@ -78,8 +78,7 @@ public:
char right);
protected:
void renameCell(ConcreteCell *cell,
const char *cell_name);
void removeCell(ConcreteCell *cell);
std::string name_;
ObjectId id_;
@ -98,62 +97,62 @@ class ConcreteCell
public:
// Use ConcreteLibrary::deleteCell.
virtual ~ConcreteCell();
const char *name() const { return name_.c_str(); }
const std::string &name() const { return name_; }
ObjectId id() const { return id_; }
const char *filename() const { return filename_.c_str(); }
const std::string &filename() const { return filename_; }
ConcreteLibrary *library() const { return library_; }
LibertyCell *libertyCell() const { return liberty_cell_; }
void setLibertyCell(LibertyCell *cell);
void *extCell() const { return ext_cell_; }
void setExtCell(void *ext_cell);
int portBitCount() const { return port_bit_count_; }
ConcretePort *findPort(const char *name) const;
ConcretePort *findPort(std::string_view name) const;
PortSeq findPortsMatching(const PatternMatch *pattern) const;
ConcreteCellPortIterator *portIterator() const;
ConcreteCellPortBitIterator *portBitIterator() const;
bool isLeaf() const { return is_leaf_; }
void setIsLeaf(bool is_leaf);
void setAttribute(const std::string &key,
const std::string &value);
std::string getAttribute(const std::string &key) const;
void setAttribute(std::string_view key,
std::string_view value);
std::string getAttribute(std::string_view key) const;
const AttributeMap &attributeMap() const { return attribute_map_; }
// Cell acts as port factory.
ConcretePort *makePort(const char *name);
ConcretePort *makePort(std::string_view name);
// Bus port.
ConcretePort *makeBusPort(const char *name,
ConcretePort *makeBusPort(std::string_view name,
int from_index,
int to_index);
// Bundle port.
ConcretePort *makeBundlePort(const char *name,
ConcretePort *makeBundlePort(std::string_view name,
ConcretePortSeq *members);
// Group previously defined bus bit ports together.
void groupBusPorts(const char bus_brkt_left,
const char bus_brkt_right,
std::function<bool(const char*)> port_msb_first);
std::function<bool(std::string_view)> port_msb_first);
size_t portCount() const;
void setName(const char *name);
void setName(std::string_view name);
void addPort(ConcretePort *port);
void addPortBit(ConcretePort *port);
protected:
ConcreteCell(const char *name,
const char *filename,
ConcreteCell(std::string_view name,
std::string_view filename,
bool is_leaf,
ConcreteLibrary *library);
ConcretePort *makeBusPort(const char *name,
ConcretePort *makeBusPort(std::string_view name,
int from_index,
int to_index,
ConcretePortSeq *members);
void makeBusPortBits(ConcretePort *bus_port,
const char *name,
std::string_view bus_name,
int from_index,
int to_index);
// Bus port bit (internal to makeBusPortBits).
ConcretePort *makePort(const char *bit_name,
ConcretePort *makePort(std::string bit_name,
int bit_index);
void makeBusPortBit(ConcretePort *bus_port,
const char *name,
std::string_view bus_name,
int index);
std::string name_;
@ -181,9 +180,9 @@ class ConcretePort
{
public:
virtual ~ConcretePort();
const char *name() const { return name_.c_str(); }
const std::string &name() const { return name_; }
ObjectId id() const { return id_; }
const char *busName() const;
std::string busName() const;
Cell *cell() const;
ConcreteLibrary *library() const { return cell_->library(); }
PortDirection *direction() const { return direction_; }
@ -231,7 +230,7 @@ public:
protected:
// Constructors for factory in cell class.
ConcretePort(const char *name,
ConcretePort(std::string_view name,
bool is_bus,
int from_index,
int to_index,

View File

@ -25,6 +25,7 @@
#pragma once
#include <functional>
#include <string_view>
#include <vector>
#include <map>
#include <set>
@ -47,9 +48,9 @@ class ConcreteBindingTbl;
class ConcreteLibertyLibraryIterator;
using ConcreteLibrarySeq = std::vector<ConcreteLibrary*>;
using ConcreteLibraryMap = std::map<const char*, ConcreteLibrary*, CharPtrLess>;
using ConcreteInstanceChildMap = std::map<const char *, ConcreteInstance*, CharPtrLess>;
using ConcreteInstanceNetMap = std::map<const char *, ConcreteNet*, CharPtrLess>;
using ConcreteLibraryMap = std::map<std::string, ConcreteLibrary*, std::less<>>;
using ConcreteInstanceChildMap = std::map<std::string, ConcreteInstance*, std::less<>>;
using ConcreteInstanceNetMap = std::map<std::string, ConcreteNet*, std::less<>>;
using ConcreteNetSeq = std::vector<ConcreteNet*>;
using ConcretePinSeq = std::vector<ConcretePin*>;
using CellNetworkViewMap = std::map<Cell*, Instance*>;
@ -63,26 +64,26 @@ public:
ConcreteNetwork();
~ConcreteNetwork();
void clear() override;
bool linkNetwork(const char *top_cell_name,
bool linkNetwork(std::string_view top_cell_name,
bool make_black_boxes,
Report *report) override;
Instance *topInstance() const override;
const char *name(const Library *library) const override;
std::string name(const Library *library) const override;
ObjectId id(const Library *library) const override;
LibraryIterator *libraryIterator() const override;
LibertyLibraryIterator *libertyLibraryIterator() const override;
Library *findLibrary(const char *name) override;
LibertyLibrary *findLiberty(const char *name) override;
Library *findLibrary(std::string_view name) override;
LibertyLibrary *findLiberty(std::string_view name) override;
Cell *findCell(const Library *library,
const char *name) const override;
Cell *findAnyCell(const char *name) override;
std::string_view name) const override;
Cell *findAnyCell(std::string_view name) override;
CellSeq findCellsMatching(const Library *library,
const PatternMatch *pattern) const override;
const char *name(const Cell *cell) const override;
std::string name(const Cell *cell) const override;
std::string getAttribute(const Cell *cell,
const std::string &key) const override;
std::string_view key) const override;
const AttributeMap &attributeMap(const Cell *cell) const override;
ObjectId id(const Cell *cell) const override;
Library *library(const Cell *cell) const override;
@ -90,15 +91,15 @@ public:
const LibertyCell *libertyCell(const Cell *cell) const override;
Cell *cell(LibertyCell *cell) const override;
const Cell *cell(const LibertyCell *cell) const override;
const char *filename(const Cell *cell) override;
std::string_view filename(const Cell *cell) const override;
Port *findPort(const Cell *cell,
const char *name) const override;
std::string_view name) const override;
bool isLeaf(const Cell *cell) const override;
CellPortIterator *portIterator(const Cell *cell) const override;
CellPortBitIterator *portBitIterator(const Cell *cell) const override;
int portBitCount(const Cell *cell) const override;
const char *name(const Port *port) const override;
std::string name(const Port *port) const override;
ObjectId id(const Port *port) const override;
Cell *cell(const Port *port) const override;
LibertyPort *libertyPort(const Port *port) const override;
@ -108,7 +109,7 @@ public:
bool isBus(const Port *port) const override;
int size(const Port *port) const override;
const char *busName(const Port *port) const override;
std::string busName(const Port *port) const override;
Port *findBusBit(const Port *port,
int index) const override;
int fromIndex(const Port *port) const override;
@ -117,18 +118,18 @@ public:
int index) const override;
PortMemberIterator *memberIterator(const Port *port) const override;
const char *name(const Instance *instance) const override;
std::string name(const Instance *instance) const override;
std::string getAttribute(const Instance *inst,
const std::string &key) const override;
std::string_view key) const override;
const AttributeMap &attributeMap(const Instance *inst) const override;
ObjectId id(const Instance *instance) const override;
Cell *cell(const Instance *instance) const override;
Instance *parent(const Instance *instance) const override;
bool isLeaf(const Instance *instance) const override;
Instance *findChild(const Instance *parent,
const char *name) const override;
std::string_view name) const override;
Pin *findPin(const Instance *instance,
const char *port_name) const override;
std::string_view port_name) const override;
Pin *findPin(const Instance *instance,
const Port *port) const override;
@ -153,10 +154,10 @@ public:
Net *net(const Term *term) const override;
Pin *pin(const Term *term) const override;
const char *name(const Net *net) const override;
std::string name(const Net *net) const override;
ObjectId id(const Net *net) const override;
Net *findNet(const Instance *instance,
const char *net_name) const override;
std::string_view net_name) const override;
void findInstNetsMatching(const Instance *instance,
const PatternMatch *pattern,
NetSeq &matches) const override;
@ -174,44 +175,44 @@ public:
LogicValue value) override;
// Edit methods.
Library *makeLibrary(const char *name,
const char *filename) override;
LibertyLibrary *makeLibertyLibrary(const char *name,
const char *filename) override;
Library *makeLibrary(std::string_view name,
std::string_view filename) override;
LibertyLibrary *makeLibertyLibrary(std::string_view name,
std::string_view filename) override;
void deleteLibrary(Library *library) override;
Cell *makeCell(Library *library,
const char *name,
std::string_view name,
bool is_leaf,
const char *filename) override;
std::string_view filename) override;
void deleteCell(Cell *cell) override;
void setName(Cell *cell,
const char *name) override;
std::string_view name) override;
void setIsLeaf(Cell *cell,
bool is_leaf) override;
void setAttribute(Cell *cell,
const std::string &key,
const std::string &value) override;
std::string_view key,
std::string_view value) override;
Port *makePort(Cell *cell,
const char *name) override;
std::string_view name) override;
Port *makeBusPort(Cell *cell,
const char *name,
std::string_view name,
int from_index,
int to_index) override;
void groupBusPorts(Cell *cell,
std::function<bool(const char*)> port_msb_first) override;
std::function<bool(std::string_view)> port_msb_first) override;
Port *makeBundlePort(Cell *cell,
const char *name,
std::string_view name,
PortSeq *members) override;
void setDirection(Port *port,
PortDirection *dir) override;
// For NetworkEdit.
Instance *makeInstance(LibertyCell *cell,
const char *name,
std::string_view name,
Instance *parent) override;
void makePins(Instance *inst) override;
// For linking.
Instance *makeInstance(Cell *cell,
const char *name,
std::string_view name,
Instance *parent) override;
void replaceCell(Instance *inst,
Cell *cell) override;
@ -223,11 +224,11 @@ public:
LibertyPort *port,
Net *net) override;
void setAttribute(Instance *inst,
const std::string &key,
const std::string &value) override;
std::string_view key,
std::string_view value) override;
void disconnectPin(Pin *pin) override;
void deletePin(Pin *pin) override;
Net *makeNet(const char *name,
Net *makeNet(std::string_view name,
Instance *parent) override;
void deleteNet(Net *net) override;
@ -263,13 +264,13 @@ public:
protected:
void addLibrary(ConcreteLibrary *library);
void setName(const char *name);
void setName(std::string_view name);
void clearConstantNets();
void visitConnectedPins(const Net *net,
PinVisitor &visitor,
NetSet &visited_nets) const override;
Instance *makeConcreteInstance(ConcreteCell *cell,
const char *name,
std::string_view name,
Instance *parent);
void disconnectNetPin(ConcreteNet *cnet,
ConcretePin *cpin);
@ -292,40 +293,40 @@ private:
class ConcreteInstance
{
public:
const char *name() const { return name_; }
std::string_view name() const { return name_; }
ObjectId id() const { return id_; }
Cell *cell() const;
ConcreteInstance *parent() const { return parent_; }
ConcretePin *findPin(const char *port_name) const;
ConcretePin *findPin(std::string_view port_name) const;
ConcretePin *findPin(const Port *port) const;
ConcreteNet *findNet(const char *net_name) const;
ConcreteNet *findNet(std::string_view net_name) const;
void findNetsMatching(const PatternMatch *pattern,
NetSeq &matches) const;
InstanceNetIterator *netIterator() const;
Instance *findChild(const char *name) const;
Instance *findChild(std::string_view name) const;
InstanceChildIterator *childIterator() const;
void setAttribute(const std::string &key,
const std::string &value);
std::string getAttribute(const std::string &key) const;
void setAttribute(std::string_view key,
std::string_view value);
std::string getAttribute(std::string_view key) const;
const AttributeMap &attributeMap() const { return attribute_map_; }
void addChild(ConcreteInstance *child);
void deleteChild(ConcreteInstance *child);
void addPin(ConcretePin *pin);
void deletePin(ConcretePin *pin);
void addNet(ConcreteNet *net);
void addNet(const char *name,
void addNet(std::string_view name,
ConcreteNet *net);
void deleteNet(ConcreteNet *net);
void setCell(ConcreteCell *cell);
void initPins();
protected:
ConcreteInstance(const char *name,
ConcreteInstance(std::string_view name,
ConcreteCell *cell,
ConcreteInstance *parent);
~ConcreteInstance();
const char *name_;
std::string name_;
ObjectId id_;
ConcreteCell *cell_;
ConcreteInstance *parent_;
@ -343,7 +344,7 @@ private:
class ConcretePin
{
public:
const char *name() const;
std::string_view name() const;
ConcreteInstance *instance() const { return instance_; }
ConcreteNet *net() const { return net_; }
ConcretePort *port() const { return port_; }
@ -377,7 +378,7 @@ private:
class ConcreteTerm
{
public:
const char *name() const;
std::string_view name() const;
ObjectId id() const { return id_; }
ConcreteNet *net() const { return net_; }
ConcretePin *pin() const { return pin_; }
@ -402,7 +403,7 @@ private:
class ConcreteNet
{
public:
const char *name() const { return name_; }
std::string_view name() const { return name_; }
ObjectId id() const { return id_; }
ConcreteInstance *instance() const { return instance_; }
void addPin(ConcretePin *pin);
@ -413,10 +414,9 @@ public:
ConcreteNet *mergedInto() { return merged_into_; }
protected:
ConcreteNet(const char *name,
ConcreteNet(std::string_view name,
ConcreteInstance *instance);
~ConcreteNet();
const char *name_;
std::string name_;
ObjectId id_;
ConcreteInstance *instance_;
// Pointer to head of linked list of pins.

View File

@ -143,7 +143,7 @@ struct find_return<C, false>
};
// Find an pointer value in a reference to a contaiiner of pointers.
// Find a pointer value in a reference to a contaiiner of pointers.
// Return nullptr if not found.
template<typename AssocContainer>
auto
@ -166,29 +166,24 @@ findKey(const AssocContainer& c,
return *it; // set
}
// Find an pointer value in a pointer to a contaiiner of pointers.
// Find a pointer value in a reference to a map that uses strings as keys.
// Return nullptr if not found.
template<typename AssocContainer>
auto
findKey(const AssocContainer *c,
typename AssocContainer::key_type key)
findStringKey(const AssocContainer& c,
std::string_view key)
-> typename find_return<AssocContainer>::type
{
using ReturnType = typename find_return<AssocContainer>::type;
static_assert(std::is_pointer_v<ReturnType>,
"findKey requires pointer types");
"findStringKey requires pointer types");
auto it = c->find(key);
if (it == c->end())
auto it = c.find(key);
if (it == c.end())
return nullptr;
if constexpr (has_mapped_type<AssocContainer>::value)
// map
return it->second;
else
// set
return *it;
return it->second;
}
////////////////////////////////////////////////////////////////
@ -212,7 +207,7 @@ findKeyValue(const AssocContainer& c,
return empty;
}
// Find an value reference in a reference to a contaiiner of objects.
// Find a value reference in a reference to a contaiiner of objects.
// Return exists.
template<typename AssocContainer>
void
@ -239,7 +234,7 @@ findKeyValue(const AssocContainer& c,
}
}
// Find an value reference in a pointer to a contaiiner of objects.
// Find a value reference in a pointer to a contaiiner of objects.
// Return exists.
template<typename AssocContainer>
void
@ -268,7 +263,8 @@ findKeyValue(const AssocContainer *c,
////////////////////////////////////////////////////////////////
// Find an value pointer in a reference to a contaiiner of objects.
// Find a value pointer in a reference to a contaiiner of objects.
// Return nullptr if not found.
template<typename AssocContainer>
auto
findKeyValuePtr(AssocContainer& c,
@ -283,17 +279,17 @@ findKeyValuePtr(AssocContainer& c,
// map
return &it->second;
else
// set
// sett
return *it;
}
// Find an pointger to a value in a const reference to a contaiiner objects.
// Find a value pointer in a reference to a contaiiner of objects.
// Return nullptr if not found.
template<typename AssocContainer>
auto
findKeyValuePtr(const AssocContainer& c,
typename AssocContainer::key_type key)
-> const typename find_return<AssocContainer>::type*
-> typename find_return<AssocContainer>::type const*
{
auto it = c.find(key);
if (it == c.end())
@ -307,6 +303,38 @@ findKeyValuePtr(const AssocContainer& c,
return *it;
}
// Find a pointer to a value in a reference to a contaiiner of objects
// using std::string as the key.
// Return nullptr if not found.
template<typename AssocContainer>
auto
findStringValuePtr(AssocContainer& c,
std::string_view key)
-> typename find_return<AssocContainer>::type*
{
auto it = c.find(key);
if (it == c.end())
return nullptr;
else
return &it->second;
}
// Find a const pointer to a value in a const reference to a contaiiner objects
// using std::string as the key.
// Return nullptr if not found.
template<typename AssocContainer>
auto
findStringValuePtr(const AssocContainer& c,
std::string_view key)
-> typename find_return<AssocContainer>::type const*
{
auto it = c.find(key);
if (it == c.end())
return nullptr;
else
return &it->second;
}
////////////////////////////////////////////////////////////////
// Determine if two std::set's intersect.

View File

@ -38,20 +38,20 @@ namespace sta {
class Report;
class Pin;
using DebugMap = std::map<std::string, int>;
using DebugMap = std::map<std::string, int, std::less<>>;
class Debug
{
public:
Debug(Report *report);
int level(const char *what);
void setLevel(const char *what,
int level(std::string_view what);
void setLevel(std::string_view what,
int level);
bool check(const char *what,
bool check(std::string_view what,
int level) const;
int statsLevel() const { return stats_level_; }
template <typename... Args>
void report(const char *what,
void report(std::string_view what,
std::string_view fmt,
Args &&...args)
{

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <string_view>
#include "StringUtil.hh"
@ -40,10 +41,10 @@ void
registerDelayCalcs();
// Register a delay calculator for the set_delay_calc command.
void
registerDelayCalc(const std::string &name,
registerDelayCalc(std::string_view name,
MakeArcDelayCalc maker);
bool
isDelayCalcName(const std::string &name);
isDelayCalcName(std::string_view name);
StringSeq
delayCalcNames();
void
@ -51,7 +52,7 @@ deleteDelayCalcs();
// Make a registered delay calculator by name.
ArcDelayCalc *
makeDelayCalc(const std::string &name,
makeDelayCalc(std::string_view name,
StaState *sta);
} // namespace

View File

@ -35,17 +35,17 @@ class EnumNameMap
{
public:
EnumNameMap(std::initializer_list<std::pair<const ENUM, std::string>> enum_names);
const char *find(ENUM key) const;
ENUM find(std::string name,
const std::string &find(ENUM key) const;
ENUM find(std::string_view name,
ENUM unknown_key) const;
void find(std::string name,
void find(std::string_view name,
// Return values.
ENUM &key,
bool &exists) const;
private:
std::map<ENUM, std::string> enum_map_;
std::map<std::string, ENUM> name_map_;
std::map<std::string, ENUM, std::less<>> name_map_;
};
template <class ENUM>
@ -57,19 +57,21 @@ EnumNameMap<ENUM>::EnumNameMap(std::initializer_list<std::pair<const ENUM,std::s
}
template <class ENUM>
const char *
const std::string&
EnumNameMap<ENUM>::find(ENUM key) const
{
auto find_iter = enum_map_.find(key);
if (find_iter != enum_map_.end())
return find_iter->second.c_str();
else
return nullptr;
return find_iter->second;
else {
static std::string null_ref;
return null_ref;
}
}
template <class ENUM>
void
EnumNameMap<ENUM>::find(std::string name,
EnumNameMap<ENUM>::find(std::string_view name,
// Return values.
ENUM &key,
bool &exists) const
@ -85,7 +87,7 @@ EnumNameMap<ENUM>::find(std::string name,
template <class ENUM>
ENUM
EnumNameMap<ENUM>::find(std::string name,
EnumNameMap<ENUM>::find(std::string_view name,
ENUM unknown_key) const
{
auto find_iter = name_map_.find(name);

View File

@ -37,7 +37,7 @@ class Exception : public std::exception
public:
Exception();
virtual ~Exception() {}
virtual const char *what() const noexcept = 0;
const char *what() const noexcept override = 0;
};
class ExceptionMsg : public Exception
@ -45,8 +45,8 @@ class ExceptionMsg : public Exception
public:
ExceptionMsg(const std::string &msg,
const bool suppressed);
virtual const char *what() const noexcept;
virtual bool suppressed() const { return suppressed_; }
const char *what() const noexcept override;
bool suppressed() const { return suppressed_; }
private:
std::string msg_;
@ -68,11 +68,10 @@ protected:
class FileNotReadable : public Exception
{
public:
FileNotReadable(std::string filename);
virtual const char *what() const noexcept;
FileNotReadable(std::string_view filename);
const char *what() const noexcept override;
protected:
std::string filename_;
std::string msg_;
};
@ -80,11 +79,10 @@ protected:
class FileNotWritable : public Exception
{
public:
FileNotWritable(std::string filename);
virtual const char *what() const noexcept;
FileNotWritable(std::string_view filename);
const char *what() const noexcept override;
protected:
std::string filename_;
std::string msg_;
};

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
#include "Error.hh"
@ -57,7 +58,7 @@ public:
const MinMaxAll *min_max,
bool own_pts,
int priority,
const char *comment);
std::string_view comment);
virtual ~ExceptionPath();
size_t id() const { return id_; }
void setId(size_t id);
@ -128,7 +129,7 @@ public:
virtual bool useEndClk() const { return false; }
virtual int pathMultiplier() const { return 0; }
virtual float delay() const { return 0.0; }
virtual std::string name() const { return ""; }
virtual std::string_view name() const { return {}; }
virtual bool isDefault() const { return false; }
virtual bool ignoreClkLatency() const { return false; }
virtual bool breakPath() const { return false; }
@ -157,14 +158,14 @@ public:
ExceptionTo *to,
const MinMaxAll *min_max,
bool own_pts,
const char *comment);
std::string_view comment);
FalsePath(ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
const MinMaxAll *min_max,
bool own_pts,
int priority,
const char *comment);
std::string_view comment);
ExceptionPath *clone(ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
@ -203,7 +204,7 @@ public:
bool break_path,
float delay,
bool own_pts,
const char *comment);
std::string_view comment);
ExceptionPath *clone(ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
@ -237,7 +238,7 @@ public:
bool use_end_clk,
int path_multiplier,
bool own_pts,
const char *comment);
std::string_view comment);
ExceptionPath *clone(ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
@ -293,13 +294,13 @@ public:
class GroupPath : public ExceptionPath
{
public:
GroupPath(const std::string &name,
GroupPath(std::string_view name,
bool is_default,
ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
bool own_pts,
const char *comment);
std::string_view comment);
~GroupPath() override;
ExceptionPath *clone(ExceptionFrom *from,
ExceptionThruSeq *thrus,
@ -312,7 +313,7 @@ public:
bool overrides(ExceptionPath *exception) const override;
int typePriority() const override;
bool tighterThan(ExceptionPath *exception) const override;
std::string name() const override { return name_; }
std::string_view name() const override { return name_; }
bool isDefault() const override { return is_default_; }
protected:

View File

@ -220,7 +220,7 @@ protected:
PinVertexMap pin_bidirect_drvr_vertex_map_;
DcalcAPIndex ap_count_;
// Sdf period check annotations.
PeriodCheckAnnotations *period_check_annotations_;
PeriodCheckAnnotations period_check_annotations_;
// Register/latch clock vertices to search from.
VertexSet reg_clk_vertices_;
@ -241,7 +241,7 @@ public:
// Pin path with load/driver suffix for bidirects.
std::string to_string(const StaState *sta) const;
// compatibility
const char *name(const Network *network) const;
std::string name(const Network *network) const;
[[nodiscard]] bool isBidirectDriver() const { return is_bidirect_drvr_; }
[[nodiscard]] bool isDriver(const Network *network) const;
Level level() const { return level_; }

View File

@ -26,6 +26,7 @@
#include <cstdint>
#include <cstddef>
#include <string_view>
namespace sta {
@ -56,7 +57,7 @@ nextMersenne(size_t n)
// Sadly necessary until c++ std::hash works for char *.
size_t
hashString(const char *str);
hashString(std::string_view str);
// Pointer hashing is strongly discouraged because it causes results to change
// from run to run. Use Network::id functions instead.

View File

@ -31,6 +31,7 @@
#include <set>
#include <map>
#include <string>
#include <string_view>
#include <vector>
#include "ContainerHelpers.hh"
@ -68,7 +69,7 @@ class DriverWaveform;
class ModeValueDef
{
public:
ModeValueDef(std::string value, FuncExpr *cond, std::string sdf_cond);
ModeValueDef(std::string value);
ModeValueDef(ModeValueDef &&other) noexcept;
~ModeValueDef();
const std::string &value() const { return value_; }
@ -115,14 +116,14 @@ private:
TimingArcSet *setup_check_;
};
using TableTemplateMap = std::map<std::string, TableTemplate>;
using TableTemplateMap = std::map<std::string, TableTemplate, std::less<>>;
using TableTemplateSeq = std::vector<TableTemplate*>;
using BusDclMap = std::map<std::string, BusDcl>;
using BusDclMap = std::map<std::string, BusDcl, std::less<>>;
using BusDclSeq = std::vector<BusDcl*>;
using ScaleFactorsMap = std::map<std::string, ScaleFactors>;
using WireloadMap = std::map<std::string, Wireload>;
using WireloadSelectionMap = std::map<std::string, WireloadSelection>;
using OperatingConditionsMap = std::map<std::string, OperatingConditions>;
using ScaleFactorsMap = std::map<std::string, ScaleFactors, std::less<>>;
using WireloadMap = std::map<std::string, Wireload, std::less<>>;
using WireloadSelectionMap = std::map<std::string, WireloadSelection, std::less<>>;
using OperatingConditionsMap = std::map<std::string, OperatingConditions, std::less<>>;
using PortToSequentialMap = std::map<LibertyPort*, size_t>;
using TimingArcSetSeq = std::vector<TimingArcSet*>;
using TimingArcSetSet = std::set<TimingArcSet*, TimingArcSetLess>;
@ -135,13 +136,13 @@ using PortInternalPowerMap = std::map<const LibertyPort *, InternalPowerIndexSeq
using LeakagePowerSeq = std::vector<LeakagePower>;
using ScaledCellMap = std::map<const OperatingConditions*, LibertyCell*>;
using ScaledPortMap = std::map<const OperatingConditions*, LibertyPort*>;
using ModeDefMap = std::map<std::string, ModeDef>;
using ModeValueMap = std::map<std::string, ModeValueDef>;
using ModeDefMap = std::map<std::string, ModeDef, std::less<>>;
using ModeValueMap = std::map<std::string, ModeValueDef, std::less<>>;
using LatchEnableIndexMap = std::map<const TimingArcSet*, size_t>;
using LatchEnableSeq = std::vector<LatchEnable>;
using OcvDerateMap = std::map<std::string, OcvDerate>;
using SupplyVoltageMap = std::map<std::string, float>;
using DriverWaveformMap = std::map<std::string, DriverWaveform>;
using OcvDerateMap = std::map<std::string, OcvDerate, std::less<>>;
using SupplyVoltageMap = std::map<std::string, float, std::less<>>;
using DriverWaveformMap = std::map<std::string, DriverWaveform, std::less<>>;
using SceneSeq = std::vector<Scene*>;
enum class ClockGateType { none, latch_posedge, latch_negedge, other };
@ -175,13 +176,13 @@ void
deleteLiberty();
ScaleFactorPvt
findScaleFactorPvt(const char *name);
const char *
findScaleFactorPvt(std::string_view name);
const std::string&
scaleFactorPvtName(ScaleFactorPvt pvt);
ScaleFactorType
findScaleFactorType(const char *name);
const char *
findScaleFactorType(std::string_view name);
const std::string&
scaleFactorTypeName(ScaleFactorType type);
bool
scaleFactorTypeRiseFallSuffix(ScaleFactorType type);
@ -191,7 +192,7 @@ bool
scaleFactorTypeLowHighSuffix(ScaleFactorType type);
// Timing sense as a string.
const char *
const std::string&
to_string(TimingSense sense);
// Opposite timing sense.
@ -203,10 +204,10 @@ timingSenseOpposite(TimingSense sense);
class LibertyLibrary : public ConcreteLibrary
{
public:
LibertyLibrary(const char *name,
const char *filename);
LibertyLibrary(std::string name,
std::string filename);
virtual ~LibertyLibrary();
LibertyCell *findLibertyCell(const char *name) const;
LibertyCell *findLibertyCell(std::string_view name) const;
LibertyCellSeq findLibertyCellsMatching(PatternMatch *pattern);
// Liberty cells that are buffers.
LibertyCellSeq *buffers();
@ -214,12 +215,14 @@ public:
DelayModelType delayModelType() const { return delay_model_type_; }
void setDelayModelType(DelayModelType type);
BusDcl *makeBusDcl(std::string name, int from, int to);
BusDcl *findBusDcl(const char *name) const;
BusDcl *makeBusDcl(std::string name,
int from,
int to);
BusDcl *findBusDcl(std::string_view name);
BusDclSeq busDcls() const;
TableTemplate *makeTableTemplate(std::string name,
TableTemplateType type);
TableTemplate *findTableTemplate(const char *name,
TableTemplate *findTableTemplate(std::string_view name,
TableTemplateType type);
TableTemplateSeq tableTemplates() const;
TableTemplateSeq tableTemplates(TableTemplateType type) const;
@ -232,8 +235,8 @@ public:
void setScaleFactors(ScaleFactors *scales);
// Make named scale factor group. Returns pointer to the inserted element.
ScaleFactors *makeScaleFactors(const char *name);
ScaleFactors *findScaleFactors(const char *name);
ScaleFactors *makeScaleFactors(std::string name);
ScaleFactors *findScaleFactors(std::string_view name);
ScaleFactors *scaleFactors() const { return scale_factors_; }
float scaleFactor(ScaleFactorType type,
const Pvt *pvt) const;
@ -334,18 +337,18 @@ public:
const Units *units() const { return units_; }
Wireload *makeWireload(std::string name);
const Wireload *findWireload(const char *name) const;
const Wireload *findWireload(std::string_view name);
void setDefaultWireload(const Wireload *wireload);
const Wireload *defaultWireload() const;
WireloadSelection *makeWireloadSelection(std::string name);
const WireloadSelection *findWireloadSelection(const char *name) const;
const WireloadSelection *findWireloadSelection(std::string_view name) const;
const WireloadSelection *defaultWireloadSelection() const;
WireloadMode defaultWireloadMode() const;
void setDefaultWireloadMode(WireloadMode mode);
void setDefaultWireloadSelection(const WireloadSelection *selection);
OperatingConditions *makeOperatingConditions(std::string name);
OperatingConditions *findOperatingConditions(const char *name);
OperatingConditions *findOperatingConditions(std::string_view name);
OperatingConditions *defaultOperatingConditions() const;
void setDefaultOperatingConditions(OperatingConditions *op_cond);
@ -356,18 +359,18 @@ public:
OcvDerate *defaultOcvDerate() const;
void setDefaultOcvDerate(OcvDerate *derate);
OcvDerate *makeOcvDerate(std::string name);
OcvDerate *findOcvDerate(const char *derate_name);
void addSupplyVoltage(const char *suppy_name,
OcvDerate *findOcvDerate(std::string_view derate_name);
void addSupplyVoltage(std::string suppy_name,
float voltage);
bool supplyExists(const char *suppy_name) const;
void supplyVoltage(const char *supply_name,
bool supplyExists(std::string_view supply_name) const;
void supplyVoltage(std::string_view supply_name,
// Return value.
float &voltage,
bool &exists) const;
// Make scaled cell. Call LibertyCell::addScaledCell after it is complete.
LibertyCell *makeScaledCell(const char *name,
const char *filename);
LibertyCell *makeScaledCell(std::string name,
std::string filename);
static void
makeSceneMap(LibertyLibrary *lib,
@ -390,9 +393,9 @@ public:
const SceneSeq &scenes,
Report *report);
DriverWaveform *findDriverWaveform(const char *name);
DriverWaveform *findDriverWaveform(std::string_view name);
DriverWaveform *driverWaveformDefault() { return findDriverWaveform(""); }
DriverWaveform *makeDriverWaveform(const std::string &name,
DriverWaveform *makeDriverWaveform(std::string name,
TablePtr waveforms);
protected:
@ -471,18 +474,18 @@ class LibertyCell : public ConcreteCell
{
public:
LibertyCell(LibertyLibrary *library,
const char *name,
const char *filename);
std::string name,
std::string filename);
virtual ~LibertyCell();
LibertyLibrary *libertyLibrary() const { return liberty_library_; }
LibertyLibrary *libertyLibrary() { return liberty_library_; }
LibertyPort *findLibertyPort(const char *name) const;
LibertyPort *findLibertyPort(std::string_view name) const;
LibertyPortSeq findLibertyPortsMatching(PatternMatch *pattern) const;
bool hasInternalPorts() const { return has_internal_ports_; }
ScaleFactors *scaleFactors() const { return scale_factors_; }
void setScaleFactors(ScaleFactors *scale_factors);
ModeDef *makeModeDef(std::string name);
const ModeDef *findModeDef(const char *name) const;
const ModeDef *findModeDef(std::string_view name) const;
float area() const { return area_; }
void setArea(float area);
@ -541,8 +544,10 @@ public:
const Statetable *statetable() const { return statetable_; }
// Find bus declaration local to this cell.
BusDcl *makeBusDcl(std::string name, int from, int to);
BusDcl *findBusDcl(const char *name) const;
BusDcl *makeBusDcl(std::string name,
int from,
int to);
BusDcl *findBusDcl(std::string_view name);
// True when TimingArcSetBuilder::makeRegLatchArcs infers register
// timing arcs.
bool hasInferedRegTimingArcs() const { return has_infered_reg_timing_arcs_; }
@ -561,7 +566,7 @@ public:
float ocvArcDepth() const;
OcvDerate *ocvDerate() const;
OcvDerate *makeOcvDerate(std::string name);
OcvDerate *findOcvDerate(const char *derate_name);
OcvDerate *findOcvDerate(std::string_view derate_name);
// Build helpers.
void makeSequential(int size,
@ -614,10 +619,10 @@ public:
// for all the defined scenes.
static void checkLibertyScenes();
void ensureVoltageWaveforms(const SceneSeq &scenes);
const char *footprint() const;
void setFootprint(const char *footprint);
const char *userFunctionClass() const;
void setUserFunctionClass(const char *user_function_class);
const std::string &footprint() const { return footprint_; }
void setFootprint(std::string footprint);
const std::string &userFunctionClass() const { return user_function_class_; }
void setUserFunctionClass(std::string user_function_class);
protected:
void addPort(ConcretePort *port);
@ -752,8 +757,8 @@ public:
bool isPwrGnd() const;
PwrGndType pwrGndType() const { return pwr_gnd_type_; }
void setPwrGndType(PwrGndType type);
const char *voltageName() const { return voltage_name_.c_str(); }
void setVoltageName(const char *voltage_name);
const std::string &voltageName() const { return voltage_name_; }
void setVoltageName(std::string voltage_name);
////////////////////////////////////////////////////////////////
ScanSignalType scanSignalType() const { return scan_signal_type_; }
@ -876,10 +881,10 @@ public:
const LibertyPort *scenePort(int ap_index) const;
void setScenePort(LibertyPort *scene_port,
int ap_index);
const char *relatedGroundPin() const;
void setRelatedGroundPin(const char *related_ground_pin);
const char *relatedPowerPin() const;
void setRelatedPowerPin(const char *related_power_pin);
LibertyPort *relatedGroundPort() const { return related_ground_port_; }
void setRelatedGroundPort(LibertyPort *related_ground_port);
LibertyPort *relatedPowerPort() const { return related_power_port_; }
void setRelatedPowerPort(LibertyPort *related_power_port);
const ReceiverModel *receiverModel() const { return receiver_model_.get(); }
void setReceiverModel(ReceiverModelPtr receiver_model);
DriverWaveform *driverWaveform(const RiseFall *rf) const;
@ -901,7 +906,7 @@ public:
protected:
// Constructor is internal to LibertyBuilder.
LibertyPort(LibertyCell *cell,
const char *name,
std::string name,
bool is_bus,
BusDcl *bus_dcl,
int from_index,
@ -942,8 +947,8 @@ protected:
float min_pulse_width_[RiseFall::index_count];
const RiseFall *pulse_clk_trigger_;
const RiseFall *pulse_clk_sense_;
std::string related_ground_pin_;
std::string related_power_pin_;
LibertyPort *related_ground_port_;
LibertyPort *related_power_port_;
std::vector<LibertyPort*> scene_ports_;
ReceiverModelPtr receiver_model_;
DriverWaveform *driver_waveform_[RiseFall::index_count];
@ -1011,13 +1016,8 @@ protected:
class OperatingConditions : public Pvt
{
public:
OperatingConditions(const char *name);
OperatingConditions(const char *name,
float process,
float voltage,
float temperature,
WireloadTree wire_load_tree);
const char *name() const { return name_.c_str(); }
OperatingConditions(std::string name);
const std::string &name() const { return name_; }
WireloadTree wireloadTree() const { return wire_load_tree_; }
void setWireloadTree(WireloadTree tree);
@ -1029,8 +1029,8 @@ protected:
class ScaleFactors
{
public:
ScaleFactors(const char *name);
const char *name() const { return name_.c_str(); }
ScaleFactors(std::string name);
const std::string &name() const { return name_; }
float scale(ScaleFactorType type,
ScaleFactorPvt pvt,
const RiseFall *rf);
@ -1073,14 +1073,11 @@ protected:
class ModeDef
{
public:
ModeDef(std::string name);
const std::string &name() const { return name_; }
ModeValueDef *defineValue(const char *value,
FuncExpr *cond,
const char *sdf_cond);
const ModeValueDef *findValueDef(const char *value) const;
const ModeValueMap *values() const { return &values_; }
explicit ModeDef(std::string name);
ModeValueDef *defineValue(std::string value);
const ModeValueDef *findValueDef(std::string_view value) const;
const ModeValueMap &values() const { return values_; }
protected:
std::string name_;
@ -1152,12 +1149,12 @@ private:
};
std::string
portLibertyToSta(const char *port_name);
const char *
portLibertyToSta(std::string_view port_name);
const std::string &
scanSignalTypeName(ScanSignalType scan_type);
const char *
const std::string &
pwrGndTypeName(PwrGndType pwr_gnd_type);
PwrGndType
findPwrGndType(const char *pg_name);
findPwrGndType(std::string_view pg_name);
} // namespace

View File

@ -76,7 +76,7 @@ public:
PocvMode pocv_mode) const override;
std::string reportCheckDelay(const Pvt *pvt,
float from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
float to_slew,
float related_out_cap,
const MinMax *min_max,

View File

@ -42,7 +42,7 @@ using PathGroupSeq = std::vector<PathGroup*>;
class Mode : public StaState
{
public:
Mode(const std::string &name,
Mode(std::string_view name,
size_t mode_index,
StaState *sta);
virtual ~Mode();

View File

@ -26,6 +26,8 @@
#include <functional>
#include <map>
#include <string>
#include <string_view>
#include "StringUtil.hh"
#include "LibertyClass.hh"
@ -39,11 +41,11 @@ class Report;
class PatternMatch;
class PinVisitor;
using LibertyLibraryMap = std::map<const char*, LibertyLibrary*, CharPtrLess>;
using LibertyLibraryMap = std::map<std::string, LibertyLibrary*, std::less<>>;
// Link network function returns top level instance.
// Return nullptr if link fails.
using LinkNetworkFunc = std::function<Instance* (const char *top_cell_name,
bool make_black_boxes)>;
using LinkNetworkFunc = std::function<Instance* (std::string_view top_cell_name,
bool make_black_boxes)>;
using NetDrvrPinsMap = std::map<const Net*, PinSet*>;
// The Network class defines the network API used by sta.
@ -100,7 +102,7 @@ public:
// has been linked. When the network interfaces to an external database,
// linking is not necessary because the network has already been expanded.
// Return true if successful.
virtual bool linkNetwork(const char *top_cell_name,
virtual bool linkNetwork(std::string_view top_cell_name,
bool make_black_boxes,
Report *report) = 0;
virtual bool isLinked() const;
@ -108,23 +110,23 @@ public:
////////////////////////////////////////////////////////////////
// Library functions.
virtual const char *name(const Library *library) const = 0;
virtual std::string name(const Library *library) const = 0;
virtual ObjectId id(const Library *library) const = 0;
virtual LibraryIterator *libraryIterator() const = 0;
virtual LibertyLibraryIterator *libertyLibraryIterator() const = 0;
virtual Library *findLibrary(const char *name) = 0;
virtual LibertyLibrary *findLiberty(const char *name) = 0;
virtual Library *findLibrary(std::string_view name) = 0;
virtual LibertyLibrary *findLiberty(std::string_view name) = 0;
// Find liberty library by filename.
virtual LibertyLibrary *findLibertyFilename(const char *filename);
virtual LibertyLibrary *findLibertyFilename(std::string_view filename);
virtual Cell *findCell(const Library *library,
const char *name) const = 0;
std::string_view name) const = 0;
// Search the design (non-liberty) libraries for cells matching pattern.
virtual CellSeq findCellsMatching(const Library *library,
const PatternMatch *pattern) const = 0;
// Search liberty libraries for cell name.
virtual LibertyCell *findLibertyCell(const char *name) const;
virtual LibertyLibrary *makeLibertyLibrary(const char *name,
const char *filename) = 0;
virtual LibertyCell *findLibertyCell(std::string_view name) const;
virtual LibertyLibrary *makeLibertyLibrary(std::string_view name,
std::string_view filename) = 0;
// Hook for network after reading liberty library.
virtual void readLibertyAfter(LibertyLibrary *library);
// First liberty library read is used to look up defaults.
@ -139,7 +141,7 @@ public:
////////////////////////////////////////////////////////////////
// Cell functions.
virtual const char *name(const Cell *cell) const = 0;
virtual std::string name(const Cell *cell) const = 0;
virtual ObjectId id(const Cell *cell) const = 0;
virtual Library *library(const Cell *cell) const = 0;
virtual LibertyLibrary *libertyLibrary(const Cell *cell) const;
@ -149,14 +151,13 @@ public:
virtual const Cell *cell(const LibertyCell *cell) const = 0;
virtual Cell *cell(LibertyCell *cell) const = 0;
// Filename may return null.
virtual const char *filename(const Cell *cell) = 0;
// Attributes can be null
virtual std::string_view filename(const Cell *cell) const = 0;
virtual std::string getAttribute(const Cell *cell,
const std::string &key) const = 0;
std::string_view key) const = 0;
virtual const AttributeMap &attributeMap(const Cell *cell) const = 0;
// Name can be a simple, bundle, bus, or bus bit name.
virtual Port *findPort(const Cell *cell,
const char *name) const = 0;
std::string_view name) const = 0;
virtual PortSeq findPortsMatching(const Cell *cell,
const PatternMatch *pattern) const;
virtual bool isLeaf(const Cell *cell) const = 0;
@ -168,7 +169,7 @@ public:
////////////////////////////////////////////////////////////////
// Port functions
virtual const char *name(const Port *port) const = 0;
virtual std::string name(const Port *port) const = 0;
virtual ObjectId id(const Port *port) const = 0;
virtual Cell *cell(const Port *port) const = 0;
virtual LibertyPort *libertyPort(const Port *port) const = 0;
@ -179,7 +180,7 @@ public:
// Size is the bus/bundle member count (1 for non-bus/bundle ports).
virtual int size(const Port *port) const = 0;
// Bus range bus[from:to].
virtual const char *busName(const Port *port) const = 0;
virtual std::string busName(const Port *port) const = 0;
// Bus member, bus[subscript].
virtual Port *findBusBit(const Port *port,
int index) const = 0;
@ -202,25 +203,25 @@ public:
////////////////////////////////////////////////////////////////
// Instance functions
// Name local to containing cell/instance.
virtual const char *name(const Instance *instance) const = 0;
virtual std::string name(const Instance *instance) const = 0;
virtual ObjectId id(const Instance *instance) const = 0;
// Top level instance of the design (defined after link).
virtual Instance *topInstance() const = 0;
virtual bool isTopInstance(const Instance *inst) const;
virtual Instance *findInstance(const char *path_name) const;
virtual Instance *findInstance(std::string_view path_name) const;
// Find instance relative to hierarchical instance.
virtual Instance *findInstanceRelative(const Instance *inst,
const char *path_name) const;
std::string_view path_name) const;
// Default implementation uses linear search.
virtual InstanceSeq findInstancesMatching(const Instance *context,
const PatternMatch *pattern) const;
virtual InstanceSeq findInstancesHierMatching(const Instance *instance,
const PatternMatch *pattern) const;
virtual std::string getAttribute(const Instance *inst,
const std::string &key) const = 0;
std::string_view key) const = 0;
virtual const AttributeMap &attributeMap(const Instance *inst) const = 0;
// Hierarchical path name.
virtual const char *pathName(const Instance *instance) const;
virtual std::string pathName(const Instance *instance) const;
bool pathNameLess(const Instance *inst1,
const Instance *inst2) const;
int pathNameCmp(const Instance *inst1,
@ -230,14 +231,14 @@ public:
// Return value.
InstanceSeq &path) const;
virtual Cell *cell(const Instance *instance) const = 0;
virtual const char *cellName(const Instance *instance) const;
virtual std::string cellName(const Instance *instance) const;
virtual LibertyLibrary *libertyLibrary(const Instance *instance) const;
virtual LibertyCell *libertyCell(const Instance *instance) const;
virtual Instance *parent(const Instance *instance) const = 0;
virtual bool isLeaf(const Instance *instance) const = 0;
virtual bool isHierarchical(const Instance *instance) const;
virtual Instance *findChild(const Instance *parent,
const char *name) const = 0;
std::string_view name) const = 0;
virtual void findChildrenMatching(const Instance *parent,
const PatternMatch *pattern,
// Return value.
@ -270,18 +271,18 @@ public:
////////////////////////////////////////////////////////////////
// Pin functions
// Name is instance_name/port_name (the same as path name).
virtual const char *name(const Pin *pin) const;
virtual std::string name(const Pin *pin) const;
virtual ObjectId id(const Pin *pin) const = 0;
virtual Pin *findPin(const char *path_name) const;
virtual Pin *findPin(std::string_view path_name) const;
virtual Pin *findPin(const Instance *instance,
const char *port_name) const = 0;
std::string_view port_name) const = 0;
virtual Pin *findPin(const Instance *instance,
const Port *port) const;
virtual Pin *findPin(const Instance *instance,
const LibertyPort *port) const;
// Find pin relative to hierarchical instance.
Pin *findPinRelative(const Instance *inst,
const char *path_name) const;
std::string_view path_name) const;
// Default implementation uses linear search.
virtual PinSeq findPinsMatching(const Instance *instance,
const PatternMatch *pattern) const;
@ -289,9 +290,9 @@ public:
// pattern of the form instance_name/port_name.
virtual PinSeq findPinsHierMatching(const Instance *instance,
const PatternMatch *pattern) const;
virtual const char *portName(const Pin *pin) const;
virtual std::string portName(const Pin *pin) const;
// Path name is instance_name/port_name.
virtual const char *pathName(const Pin *pin) const;
virtual std::string pathName(const Pin *pin) const;
bool pathNameLess(const Pin *pin1,
const Pin *pin2) const;
int pathNameCmp(const Pin *pin1,
@ -349,27 +350,27 @@ public:
////////////////////////////////////////////////////////////////
// Terminal functions
// Name is instance_name/port_name (the same as path name).
virtual const char *name(const Term *term) const;
virtual std::string name(const Term *term) const;
virtual ObjectId id(const Term *term) const = 0;
virtual const char *portName(const Term *term) const;
virtual std::string portName(const Term *term) const;
// Path name is instance_name/port_name (pin name).
virtual const char *pathName(const Term *term) const;
virtual std::string pathName(const Term *term) const;
virtual Net *net(const Term *term) const = 0;
virtual Pin *pin(const Term *term) const = 0;
////////////////////////////////////////////////////////////////
// Net functions
virtual const char *name(const Net *net) const = 0; // no hierarchy prefix
virtual std::string name(const Net *net) const = 0; // no hierarchy prefix
virtual ObjectId id(const Net *net) const = 0;
virtual Net *findNet(const char *path_name) const;
virtual Net *findNet(std::string_view path_name) const;
// Find net relative to hierarchical instance.
virtual Net *findNetRelative(const Instance *inst,
const char *path_name) const;
std::string_view path_name) const;
// Default implementation uses linear search.
virtual NetSeq findNetsMatching(const Instance *context,
const PatternMatch *pattern) const;
virtual Net *findNet(const Instance *instance,
const char *net_name) const = 0;
std::string_view net_name) const = 0;
// Traverse the hierarchy from instance down and find nets matching
// pattern of the form instance_name/net_name.
virtual NetSeq findNetsHierMatching(const Instance *instance,
@ -378,7 +379,7 @@ public:
virtual void findInstNetsMatching(const Instance *instance,
const PatternMatch *pattern,
NetSeq &matches) const = 0;
virtual const char *pathName(const Net *net) const;
virtual std::string pathName(const Net *net) const;
bool pathNameLess(const Net *net1,
const Net *net2) const;
int pathNameCmp(const Net *net1,
@ -424,17 +425,13 @@ public:
////////////////////////////////////////////////////////////////
// Parse path into first/tail (first hierarchy divider separated token).
// first and tail are both null if there are no dividers in path.
// Caller must delete first and tail.
void pathNameFirst(const char *path_name,
char *&first,
char *&tail) const;
void pathNameFirst(std::string_view path_name,
std::string &first,
std::string &tail) const;
// Parse path into head/last (last hierarchy divider separated token).
// head and last are both null if there are no dividers in path.
// Caller must delete head and last.
void pathNameLast(const char *path_name,
char *&head,
char *&last) const;
void pathNameLast(std::string_view path_name,
std::string &head,
std::string &last) const;
// Divider between instance names in a hierarchical path name.
virtual char pathDivider() const { return divider_; }
@ -445,7 +442,7 @@ public:
protected:
Pin *findPinLinear(const Instance *instance,
const char *port_name) const;
std::string_view port_name) const;
void findInstancesMatching1(const Instance *context,
size_t context_name_length,
const PatternMatch *pattern,
@ -484,7 +481,7 @@ protected:
PinSeq &matches) const;
// findNet using linear search.
Net *findNetLinear(const Instance *instance,
const char *net_name) const;
std::string_view net_name) const;
// findNetsMatching using linear search.
NetSeq findNetsMatchingLinear(const Instance *instance,
const PatternMatch *pattern) const;
@ -506,7 +503,7 @@ public:
NetworkEdit();
virtual bool isEditable() const { return true; }
virtual Instance *makeInstance(LibertyCell *cell,
const char *name,
std::string_view name,
Instance *parent) = 0;
virtual void makePins(Instance *inst) = 0;
virtual void replaceCell(Instance *inst,
@ -523,7 +520,7 @@ public:
// Disconnect pin from net.
virtual void disconnectPin(Pin *pin) = 0;
virtual void deletePin(Pin *pin) = 0;
virtual Net *makeNet(const char *name,
virtual Net *makeNet(std::string_view name,
Instance *parent) = 0;
// Deleting net disconnects (but does not delete) net pins.
virtual void deleteNet(Net *net) = 0;
@ -540,39 +537,39 @@ public:
// Called before reading a netlist to delete any previously linked network.
virtual void readNetlistBefore() = 0;
virtual void setLinkFunc(LinkNetworkFunc link) = 0;
virtual Library *makeLibrary(const char *name,
const char *filename) = 0;
virtual Library *makeLibrary(std::string_view name,
std::string_view filename) = 0;
virtual void deleteLibrary(Library *library) = 0;
// Search the libraries in read order for a cell by name.
virtual Cell *findAnyCell(const char *name) = 0;
virtual Cell *findAnyCell(std::string_view name) = 0;
virtual Cell *makeCell(Library *library,
const char *name,
std::string_view name,
bool is_leaf,
const char *filename) = 0;
std::string_view filename) = 0;
virtual void deleteCell(Cell *cell) = 0;
virtual void setName(Cell *cell,
const char *name) = 0;
std::string_view name) = 0;
virtual void setIsLeaf(Cell *cell,
bool is_leaf) = 0;
virtual void setAttribute(Cell *cell,
const std::string &key,
const std::string &value) = 0;
std::string_view key,
std::string_view value) = 0;
virtual void setAttribute(Instance *instance,
const std::string &key,
const std::string &value) = 0;
std::string_view key,
std::string_view value) = 0;
virtual Port *makePort(Cell *cell,
const char *name) = 0;
std::string_view name) = 0;
virtual Port *makeBusPort(Cell *cell,
const char *name,
std::string_view name,
int from_index,
int to_index) = 0;
virtual void groupBusPorts(Cell *cell,
std::function<bool(const char*)> port_msb_first) = 0;
std::function<bool(std::string_view)> port_msb_first) = 0;
virtual Port *makeBundlePort(Cell *cell,
const char *name,
std::string_view name,
PortSeq *members) = 0;
virtual Instance *makeInstance(Cell *cell,
const char *name,
std::string_view name,
Instance *parent) = 0;
virtual Pin *makePin(Instance *inst,
Port *port,

View File

@ -74,7 +74,7 @@ using ConnectedPinIterator = Iterator<const Pin*>;
using NetConnectedPinIterator = ConnectedPinIterator;
using PinConnectedPinIterator = ConnectedPinIterator;
using ObjectId = uint32_t;
using AttributeMap = std::map<std::string, std::string>;
using AttributeMap = std::map<std::string, std::string, std::less<>>;
enum class LogicValue : unsigned { zero, one, unknown, rise, fall };

View File

@ -185,7 +185,7 @@ public:
// Increment the grounded capacitance on node.
virtual void incrCap(ParasiticNode *node,
float cap) = 0;
virtual const char *name(const ParasiticNode *node) const = 0;
virtual std::string name(const ParasiticNode *node) const = 0;
virtual const Pin *pin(const ParasiticNode *node) const = 0;
virtual const Net *net(const ParasiticNode *node,
const Network *network) const = 0;

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <string_view>
#include <vector>
#include <map>
#include <mutex>
@ -50,7 +51,7 @@ class PathGroup
{
public:
// Path group that compares compare slacks.
static PathGroup *makePathGroupArrival(const char *name,
static PathGroup *makePathGroupArrival(std::string_view name,
int group_path_count,
int endpoint_path_count,
bool unique_pins,
@ -58,7 +59,7 @@ public:
const MinMax *min_max,
const StaState *sta);
// Path group that compares arrival time, sorted by min_max.
static PathGroup *makePathGroupSlack(const char *name,
static PathGroup *makePathGroupSlack(std::string_view name,
int group_path_count,
int endpoint_path_count,
bool unique_pins,
@ -82,7 +83,7 @@ public:
static int group_path_count_max;
protected:
PathGroup(const char *name,
PathGroup(std::string_view name,
int group_path_count,
int endpoint_path_count,
bool unique_pins,
@ -147,10 +148,10 @@ public:
PathGroupSeq pathGroups(const PathEnd *path_end) const;
static StringSeq pathGroupNames(const PathEnd *path_end,
const StaState *sta);
static const char *asyncPathGroupName() { return async_group_name_; }
static const char *pathDelayGroupName() { return path_delay_group_name_; }
static const char *gatedClkGroupName() { return gated_clk_group_name_; }
static const char *unconstrainedGroupName() { return unconstrained_group_name_; }
static std::string_view asyncPathGroupName() { return async_group_name_; }
static std::string_view pathDelayGroupName() { return path_delay_group_name_; }
static std::string_view gatedClkGroupName() { return gated_clk_group_name_; }
static std::string_view unconstrainedGroupName() { return unconstrained_group_name_; }
protected:
void makeGroupPathEnds(ExceptionTo *to,
@ -219,10 +220,10 @@ protected:
// Unconstrained paths.
PathGroup *unconstrained_[MinMax::index_count];
static const char *path_delay_group_name_;
static const char *gated_clk_group_name_;
static const char *async_group_name_;
static const char *unconstrained_group_name_;
static constexpr std::string_view path_delay_group_name_ = "path delay";
static constexpr std::string_view gated_clk_group_name_ = "gated clock";
static constexpr std::string_view async_group_name_ = "asynchronous";
static constexpr std::string_view unconstrained_group_name_ = "unconstrained";
};
} // namespace

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <string_view>
#include "Error.hh"
@ -45,20 +46,17 @@ public:
// Regular expressions are always anchored.
// If nocase is true, ignore case in the pattern.
// Tcl_Interp is optional for reporting regexp compile errors.
PatternMatch(const char *pattern,
PatternMatch(std::string_view pattern,
bool is_regexp,
bool nocase,
Tcl_Interp *interp);
// Use unix glob style matching.
PatternMatch(const char *pattern);
PatternMatch(const char *pattern,
PatternMatch(std::string_view pattern);
PatternMatch(std::string_view pattern,
const PatternMatch *inherit_from);
PatternMatch(const std::string &pattern,
const PatternMatch *inherit_from);
bool match(const char *str) const;
bool match(const std::string &str) const;
bool matchNoCase(const char *str) const;
const char *pattern() const { return pattern_; }
bool match(std::string_view str) const;
bool matchNoCase(std::string_view str) const;
const std::string &pattern() const { return pattern_; }
bool isRegexp() const { return is_regexp_; }
bool nocase() const { return nocase_; }
Tcl_Interp *tclInterp() const { return interp_; }
@ -67,7 +65,7 @@ public:
private:
void compileRegexp();
const char *pattern_;
std::string pattern_;
bool is_regexp_;
bool nocase_;
Tcl_Interp *interp_;
@ -78,7 +76,7 @@ private:
class RegexpCompileError : public Exception
{
public:
RegexpCompileError(const char *pattern);
RegexpCompileError(std::string_view pattern);
virtual ~RegexpCompileError() noexcept {}
virtual const char *what() const noexcept;
@ -90,14 +88,14 @@ private:
// '*' matches zero or more characters
// '?' matches any character
bool
patternMatch(const char *pattern,
const char *str);
patternMatch(std::string_view pattern,
std::string_view str);
bool
patternMatchNoCase(const char *pattern,
const char *str,
patternMatchNoCase(std::string_view pattern,
std::string_view str,
bool nocase);
// Predicate to find out if there are wildcard characters in the pattern.
bool
patternWildcards(const char *pattern);
patternWildcards(std::string_view pattern);
} // namespace

View File

@ -24,13 +24,15 @@
#pragma once
#include <string>
namespace sta {
enum class PocvMode { scalar, normal, skew_normal };
const char *
const std::string &
pocvModeName(PocvMode mode);
PocvMode
findPocvMode(const char *mode_name);
findPocvMode(std::string_view mode_name);
} // namespace

View File

@ -43,7 +43,7 @@ public:
static PortDirection *power() { return power_; }
static PortDirection *unknown() { return unknown_; }
static PortDirection *find(const char *dir_name);
const char *name() const { return name_; }
std::string_view name() const { return name_; }
int index() const { return index_; }
bool isInput() const { return this == input_; }
// Input or bidirect.

View File

@ -58,7 +58,7 @@ public:
void setDuty(float duty);
PwrActivityOrigin origin() const { return origin_; }
void setOrigin(PwrActivityOrigin origin);
const char *originName() const;
const std::string &originName() const;
void set(float density,
float duty,
PwrActivityOrigin origin);

View File

@ -51,12 +51,12 @@ public:
void defineProperty(std::string_view property,
PropertyHandler handler);
PropertyValue getProperty(TYPE object,
const std::string &property,
const char *type_name,
std::string_view property,
std::string_view type_name,
Sta *sta);
private:
std::map<std::string, PropertyHandler> registry_;
std::map<std::string, PropertyHandler, std::less<>> registry_;
};
class Properties
@ -66,33 +66,33 @@ public:
virtual ~Properties() {}
PropertyValue getProperty(const Library *lib,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const LibertyLibrary *lib,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const Cell *cell,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const LibertyCell *cell,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const Port *port,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const LibertyPort *port,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const Instance *inst,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const Pin *pin,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const Net *net,
const std::string &property);
std::string_view property);
PropertyValue getProperty(Edge *edge,
const std::string &property);
std::string_view property);
PropertyValue getProperty(const Clock *clk,
const std::string &property);
std::string_view property);
PropertyValue getProperty(PathEnd *end,
const std::string &property);
std::string_view property);
PropertyValue getProperty(Path *path,
const std::string &property);
std::string_view property);
PropertyValue getProperty(TimingArcSet *arc_set,
const std::string &property);
std::string_view property);
// Define handler for external property.
// properties->defineProperty("foo",
@ -160,7 +160,7 @@ protected:
};
// Adding a new property type
// value union
// value union (string values use std::string* so the union stays trivial)
// enum Type
// constructor
// copy constructor switch clause
@ -178,11 +178,11 @@ public:
instance, pin, pins, net,
clk, clks, paths, pwr_activity };
PropertyValue();
PropertyValue(const char *value);
PropertyValue(std::string &value);
PropertyValue(std::string_view value);
PropertyValue(std::string value);
PropertyValue(float value,
const Unit *unit);
explicit PropertyValue(bool value);
PropertyValue(bool value);
PropertyValue(const Library *value);
PropertyValue(const Cell *value);
PropertyValue(const Port *value);
@ -209,7 +209,7 @@ public:
const Unit *unit() const { return unit_; }
std::string to_string(const Network *network) const;
const char *stringValue() const; // valid for type string
const std::string &stringValue() const; // valid for type string
float floatValue() const; // valid for type float
bool boolValue() const; // valid for type bool
const LibertyLibrary *libertyLibrary() const { return liberty_library_; }
@ -233,9 +233,12 @@ public:
PropertyValue &operator=(PropertyValue &&) noexcept;
private:
void destroyActive();
Type type_;
union {
const char *string_;
// Use heap string to simplify initialization/destrucction.
std::string *string_;
float float_;
bool bool_;
const Library *library_;

View File

@ -177,13 +177,13 @@ public:
}
// Log output to filename until logEnd is called.
virtual void logBegin(std::string filename);
virtual void logBegin(std::string_view filename);
virtual void logEnd();
// Redirect output to filename until redirectFileEnd is called.
virtual void redirectFileBegin(std::string filename);
virtual void redirectFileBegin(std::string_view filename);
// Redirect append output to filename until redirectFileEnd is called.
virtual void redirectFileAppendBegin(std::string filename);
virtual void redirectFileAppendBegin(std::string_view filename);
virtual void redirectFileEnd();
// Redirect output to a string until redirectStringEnd is called.
virtual void redirectStringBegin();

View File

@ -44,10 +44,10 @@ class ReportTcl : public Report
public:
ReportTcl();
virtual ~ReportTcl();
void logBegin(std::string filename) override;
void logBegin(std::string_view filename) override;
void logEnd() override;
void redirectFileBegin(std::string filename) override;
void redirectFileAppendBegin(std::string filename) override;
void redirectFileBegin(std::string_view filename) override;
void redirectFileAppendBegin(std::string_view filename) override;
void redirectFileEnd() override;
void redirectStringBegin() override;
const char *redirectStringEnd() override;

View File

@ -28,6 +28,7 @@
#include <map>
#include <unordered_map>
#include <mutex>
#include <string_view>
#include "StringUtil.hh"
#include "MinMax.hh"
@ -131,7 +132,7 @@ private:
bool subtract_pin_cap_[MinMax::index_count];
};
using ClockNameMap = std::map<const char*,Clock*, CharPtrLess>;
using ClockNameMap = std::map<std::string ,Clock*, std::less<>>;
using ClockPinMap = std::unordered_map<const Pin*, ClockSet*, PinIdHash>;
using InputDelaySet = std::set<InputDelay*>;
using InputDelaysPinMap = std::map<const Pin*, InputDelaySet*, PinIdLess>;
@ -179,11 +180,11 @@ using InstDeratingFactorsMap = std::map<const Instance*, DeratingFactorsCell*>;
using CellDeratingFactorsMap = std::map<const LibertyCell*, DeratingFactorsCell*>;
using ClockGroupsSet = std::set<ClockGroups*>;
using ClockGroupsClkMap = std::map<const Clock*, ClockGroupsSet*>;
using ClockGroupsNameMap = std::map<std::string, ClockGroups*>;
using ClockGroupsNameMap = std::map<std::string, ClockGroups*, std::less<>>;
using ClockSenseMap = std::map<PinClockPair, ClockSense, PinClockPairLess>;
using ClkHpinDisables = std::set<ClkHpinDisable*, ClkHpinDisableLess>;
using GroupPathSet = std::set<GroupPath*, ExceptionPathLess>;
using GroupPathMap = std::map<std::string, GroupPathSet*>;
using GroupPathMap = std::map<std::string, GroupPathSet*, std::less<>>;
using ClockPairSet = std::set<ClockPair, ClockPairLess>;
using NetVoltageMap = std::map<const Net*, MinMaxFloatValues>;
@ -377,14 +378,14 @@ public:
float fanout);
void setMaxArea(float area);
float maxArea() const;
Clock *makeClock(const char *name,
Clock *makeClock(std::string_view name,
PinSet *pins,
bool add_to_pins,
float period,
FloatSeq *waveform,
const char *comment);
std::string_view comment);
// edges size must be 3.
Clock *makeGeneratedClock(const char *name,
Clock *makeGeneratedClock(std::string_view name,
PinSet *pins,
bool add_to_pins,
Pin *src_pin,
@ -396,7 +397,7 @@ public:
bool combinational,
IntSeq *edges,
FloatSeq *edge_shifts,
const char *comment);
std::string_view comment);
// Invalidate all generated clock waveforms.
void invalidateGeneratedClks() const;
void removeClock(Clock *clk);
@ -504,7 +505,7 @@ public:
bool physically_exclusive,
bool asynchronous,
bool allow_paths,
const char *comment);
std::string comment);
void makeClockGroup(ClockGroups *clk_groups,
ClockSet *clks);
void removeClockGroups(const std::string &name);
@ -730,7 +731,7 @@ public:
ExceptionThruSeq *thrus,
ExceptionTo *to,
const MinMaxAll *min_max,
const char *comment);
std::string_view comment);
// Loop paths are false paths used to disable paths around
// combinational loops when dynamic loop breaking is enabled.
void makeLoopExceptions();
@ -742,7 +743,7 @@ public:
const MinMaxAll *min_max,
bool use_end_clk,
int path_multiplier,
const char *comment);
std::string_view comment);
void makePathDelay(ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
@ -750,7 +751,7 @@ public:
bool ignore_clk_latency,
bool break_path,
float delay,
const char *comment);
std::string_view comment);
bool pathDelaysWithoutTo() const { return path_delays_without_to_; }
// Delete matching false/multicycle/path_delay exceptions.
// Caller owns from, thrus, to exception points (and must delete them).
@ -758,13 +759,13 @@ public:
ExceptionThruSeq *thrus,
ExceptionTo *to,
const MinMaxAll *min_max);
void makeGroupPath(const std::string &name,
void makeGroupPath(std::string_view name,
bool is_default,
ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
const char *comment);
bool isGroupPathName(const char *group_name) const;
std::string_view comment);
bool isGroupPathName(std::string_view group_name) const;
const GroupPathMap &groupPaths() const { return group_path_map_; }
void addException(ExceptionPath *exception);
// The pin/clk/instance/net set arguments passed into the following
@ -833,7 +834,7 @@ public:
const MinMax *min_max,
float voltage);
InputDrive *findInputDrive(Port *port) const;
Clock *findClock(const char *name) const;
Clock *findClock(std::string_view name) const;
ClockSeq findClocksMatching(PatternMatch *pattern) const;
// True if pin is defined as a clock source (pin may be hierarchical).
bool isClock(const Pin *pin) const;

View File

@ -24,22 +24,28 @@
#pragma once
#include <string>
#include <string_view>
namespace sta {
class SdcCmdComment
{
public:
SdcCmdComment();
SdcCmdComment(const char *comment);
const char *comment() { return comment_; }
void setComment(const char *comment);
SdcCmdComment(std::string comment);
SdcCmdComment(std::string_view comment);
const std::string &comment() { return comment_; }
const std::string &comment() const { return comment_; }
void setComment(std::string comment);
void setComment(std::string_view comment);
protected:
// Destructor is protected to prevent deletion of a derived
// class with a pointer to this base class.
~SdcCmdComment();
char *comment_;
std::string comment_;
};
} // namespace

View File

@ -25,6 +25,8 @@
#pragma once
#include <functional>
#include <string>
#include <string_view>
#include "Network.hh"
@ -36,26 +38,26 @@ class NetworkNameAdapter : public NetworkEdit
{
public:
NetworkNameAdapter(Network *network);
bool linkNetwork(const char *top_cell_name,
bool linkNetwork(std::string_view top_cell_name,
bool make_black_boxes,
Report *report) override;
const char *name(const Library *library) const override;
std::string name(const Library *library) const override;
ObjectId id(const Library *library) const override;
LibertyLibrary *defaultLibertyLibrary() const override;
LibraryIterator *libraryIterator() const override;
LibertyLibraryIterator *libertyLibraryIterator() const override;
Library *findLibrary(const char *name) override;
LibertyLibrary *findLibertyFilename(const char *filename) override;
LibertyLibrary *findLiberty(const char *name) override;
Library *findLibrary(std::string_view name) override;
LibertyLibrary *findLibertyFilename(std::string_view filename) override;
LibertyLibrary *findLiberty(std::string_view name) override;
Cell *findCell(const Library *library,
const char *name) const override;
std::string_view name) const override;
CellSeq findCellsMatching(const Library *library,
const PatternMatch *pattern) const override;
const char *name(const Cell *cell) const override;
std::string name(const Cell *cell) const override;
std::string getAttribute(const Cell *cell,
const std::string &key) const override;
std::string_view key) const override;
const AttributeMap &attributeMap(const Cell *cell) const override;
ObjectId id(const Cell *cell) const override;
Library *library(const Cell *cell) const override;
@ -63,9 +65,9 @@ public:
const LibertyCell *libertyCell(const Cell *cell) const override;
Cell *cell(LibertyCell *cell) const override;
const Cell *cell(const LibertyCell *cell) const override;
const char *filename(const Cell *cell) override;
std::string_view filename(const Cell *cell) const override;
Port *findPort(const Cell *cell,
const char *name) const override;
std::string_view name) const override;
PortSeq findPortsMatching(const Cell *cell,
const PatternMatch *pattern) const override;
bool isLeaf(const Cell *cell) const override;
@ -73,7 +75,7 @@ public:
CellPortBitIterator *portBitIterator(const Cell *cell) const override;
int portBitCount(const Cell *cell) const override;
const char *name(const Port *port) const override;
std::string name(const Port *port) const override;
ObjectId id(const Port *port) const override;
Cell *cell(const Port *port) const override;
LibertyPort *libertyPort(const Port *port) const override;
@ -81,7 +83,7 @@ public:
bool isBundle(const Port *port) const override;
bool isBus(const Port *port) const override;
int size(const Port *port) const override;
const char *busName(const Port *port) const override;
std::string busName(const Port *port) const override;
Port *findBusBit(const Port *port,
int index) const override;
int fromIndex(const Port *port) const override;
@ -93,7 +95,7 @@ public:
ObjectId id(const Instance *instance) const override;
std::string getAttribute(const Instance *inst,
const std::string &key) const override;
std::string_view key) const override;
const AttributeMap &attributeMap(const Instance *inst) const override;
Instance *topInstance() const override;
Cell *cell(const Instance *instance) const override;
@ -145,15 +147,15 @@ public:
void setPathEscape(char escape) override;
bool isEditable() const override;
LibertyLibrary *makeLibertyLibrary(const char *name,
const char *filename) override;
LibertyLibrary *makeLibertyLibrary(std::string_view name,
std::string_view filename) override;
Instance *makeInstance(LibertyCell *cell,
const char *name,
std::string_view name,
Instance *parent) override;
void makePins(Instance *inst) override;
void replaceCell(Instance *inst,
Cell *to_cell) override;
Net *makeNet(const char *name,
Net *makeNet(std::string_view name,
Instance *parent) override;
Pin *connect(Instance *inst,
Port *port,
@ -195,47 +197,47 @@ public:
SdcNetwork(Network *network);
Port *findPort(const Cell *cell,
const char *name) const override;
std::string_view name) const override;
PortSeq findPortsMatching(const Cell *cell,
const PatternMatch *pattern) const override;
const char *name(const Port *port) const override;
const char *busName(const Port *port) const override;
std::string name(const Port *port) const override;
std::string busName(const Port *port) const override;
const char *name(const Instance *instance) const override;
const char *pathName(const Instance *instance) const override;
const char *pathName(const Pin *pin) const override;
const char *portName(const Pin *pin) const override;
std::string name(const Instance *instance) const override;
std::string pathName(const Instance *instance) const override;
std::string pathName(const Pin *pin) const override;
std::string portName(const Pin *pin) const override;
const char *name(const Net *net) const override;
const char *pathName(const Net *net) const override;
std::string name(const Net *net) const override;
std::string pathName(const Net *net) const override;
Instance *findInstance(const char *path_name) const override;
Instance *findInstance(std::string_view path_name) const override;
Instance *findInstanceRelative(const Instance *inst,
const char *path_name) const override;
std::string_view path_name) const override;
InstanceSeq findInstancesMatching(const Instance *context,
const PatternMatch *pattern) const override;
Net *findNet(const char *path_name) const override;
Net *findNet(std::string_view path_name) const override;
Net *findNetRelative(const Instance *instance,
const char *net_name) const override;
std::string_view net_name) const override;
Net *findNet(const Instance *instance,
const char *net_name) const override;
std::string_view net_name) const override;
NetSeq findNetsMatching(const Instance *parent,
const PatternMatch *pattern) const override;
void findInstNetsMatching(const Instance *instance,
const PatternMatch *pattern,
NetSeq &nets) const override;
Instance *findChild(const Instance *parent,
const char *name) const override;
Pin *findPin(const char *path_name) const override;
std::string_view name) const override;
Pin *findPin(std::string_view path_name) const override;
Pin *findPin(const Instance *instance,
const char *port_name) const override;
std::string_view port_name) const override;
PinSeq findPinsMatching(const Instance *instance,
const PatternMatch *pattern) const override;
Instance *makeInstance(LibertyCell *cell,
const char *name,
std::string_view name,
Instance *parent) override;
Net *makeNet(const char *name,
Net *makeNet(std::string_view name,
Instance *parent) override;
// The following member functions are inherited from the
@ -247,21 +249,21 @@ public:
using Network::findPin;
protected:
void parsePath(const char *path,
void parsePath(std::string_view path,
// Return values.
Instance *&inst,
const char *&path_tail) const;
void scanPath(const char *path,
std::string &path_tail) const;
void scanPath(std::string_view path,
// Return values.
// Unescaped divider count.
int &divider_count,
int &path_length) const;
void parsePath(const char *path,
void parsePath(std::string_view path,
int divider_count,
int path_length,
// Return values.
Instance *&inst,
const char *&path_tail) const;
std::string &path_tail) const;
bool visitMatches(const Instance *parent,
const PatternMatch *pattern,
std::function<bool (const Instance *instance,
@ -274,11 +276,18 @@ protected:
const PatternMatch *pattern,
InstanceSeq &matches) const;
const char *staToSdc(std::string_view sta_name) const;
std::string staToSdc(std::string_view sta_name) const;
};
// Encapsulate a network to map names to/from the sdc namespace.
Network *
makeSdcNetwork(Network *network);
std::string
escapeDividers(std::string_view name,
const Network *network);
std::string
escapeBrackets(std::string_view name,
const Network *network);
} // namespace

View File

@ -57,7 +57,6 @@ class VertexPathIterator;
class MinPulseWidthCheck;
class MinPeriodCheck;
class MaxSkewCheck;
class CharPtrLess;
class SearchPred;
class BfsFwdIterator;
class ClkDelays;

View File

@ -75,7 +75,7 @@ class EquivCells;
class StaSimObserver;
class GraphLoop;
using ModeNameMap = std::map<std::string, Mode*>;
using ModeNameMap = std::map<std::string, Mode*, std::less<>>;
using SceneNameMap = std::map<std::string, Scene*>;
using SlowDrvrIterator = Iterator<Instance*>;
using CheckError = StringSeq;
@ -143,12 +143,12 @@ public:
Mode *cmdMode() const { return cmd_scene_->mode(); }
const std::string &cmdModeName();
void setCmdMode(const std::string &mode_name);
Mode *findMode(const std::string &mode_name) const;
void setCmdMode(std::string_view mode_name);
Mode *findMode(std::string_view mode_name) const;
ModeSeq findModes(const std::string &mode_name) const;
Sdc *cmdSdc() const;
virtual LibertyLibrary *readLiberty(const char *filename,
virtual LibertyLibrary *readLiberty(std::string_view filename,
Scene *scene,
const MinMaxAll *min_max,
bool infer_latches);
@ -156,7 +156,7 @@ public:
void readLibertyAfter(LibertyLibrary *liberty,
Scene *scene,
const MinMax *min_max);
bool readVerilog(const char *filename);
bool readVerilog(std::string_view filename);
// Network readers call this to notify the Sta to delete any previously
// linked network.
void readNetlistBefore();
@ -164,6 +164,13 @@ public:
bool linkDesign(const char *top_cell_name,
bool make_black_boxes);
bool readSdf(std::string_view filename,
std::string_view path,
Scene *scene,
bool unescaped_dividers,
bool incremental_only,
MinMaxAll *cond_use);
// SDC Swig API.
Instance *currentInstance() const;
void setCurrentInstance(Instance *inst);
@ -340,15 +347,15 @@ public:
void setMaxArea(float area,
Sdc *sdc);
void makeClock(const char *name,
void makeClock(std::string_view name,
PinSet *pins,
bool add_to_pins,
float period,
FloatSeq *waveform,
char *comment,
std::string_view comment,
const Mode *mode);
// edges size must be 3.
void makeGeneratedClock(const char *name,
void makeGeneratedClock(std::string_view name,
PinSet *pins,
bool add_to_pins,
Pin *src_pin,
@ -360,7 +367,7 @@ public:
bool combinational,
IntSeq *edges,
FloatSeq *edge_shifts,
char *comment,
std::string_view comment,
const Mode *mode);
void removeClock(Clock *clk,
Sdc *sdc);
@ -439,7 +446,7 @@ public:
bool physically_exclusive,
bool asynchronous,
bool allow_paths,
const char *comment,
std::string comment,
Sdc *sdc);
void removeClockGroupsLogicallyExclusive(Sdc *sdc);
void removeClockGroupsLogicallyExclusive(const std::string &name,
@ -623,7 +630,7 @@ public:
ExceptionThruSeq *thrus,
ExceptionTo *to,
const MinMaxAll *min_max,
const char *comment,
std::string_view comment,
Sdc *sdc);
void makeMulticyclePath(ExceptionFrom *from,
ExceptionThruSeq *thrus,
@ -631,7 +638,7 @@ public:
const MinMaxAll *min_max,
bool use_end_clk,
int path_multiplier,
const char *comment,
std::string_view comment,
Sdc *sdc);
void makePathDelay(ExceptionFrom *from,
ExceptionThruSeq *thrus,
@ -640,19 +647,19 @@ public:
bool ignore_clk_latency,
bool break_path,
float delay,
const char *comment,
std::string_view comment,
Sdc *sdc);
void makeGroupPath(const std::string &name,
void makeGroupPath(std::string_view name,
bool is_default,
ExceptionFrom *from,
ExceptionThruSeq *thrus,
ExceptionTo *to,
const char *comment,
std::string_view comment,
Sdc *sdc);
// Deprecated 10/24/2025
bool isGroupPathName(const char *group_name,
bool isGroupPathName(std::string_view group_name,
const Sdc *sdc) __attribute__ ((deprecated));
bool isPathGroupName(const char *group_name,
bool isPathGroupName(std::string_view group_name,
const Sdc *sdc) const;
StringSeq pathGroupNames(const Sdc *sdc) const;
void resetPath(ExceptionFrom *from,
@ -667,7 +674,7 @@ public:
const RiseFallBoth *from_rf,
const Sdc *sdc);
void checkExceptionFromPins(ExceptionFrom *from,
const char *file,
std::string_view filename,
int line,
const Sdc *sdc) const;
void deleteExceptionFrom(ExceptionFrom *from);
@ -892,7 +899,7 @@ public:
const MinMaxAll *min_max,
const RiseFallBoth *rf,
float slew);
void writeSdf(const char *filename,
void writeSdf(std::string_view filename,
const Scene *scene,
char divider,
bool include_typ,
@ -986,7 +993,7 @@ public:
bool report_fanout,
bool report_variation,
bool report_src_attr);
ReportField *findReportPathField(const char *name);
ReportField *findReportPathField(std::string_view name);
void setReportPathDigits(int digits);
void setReportPathNoSplit(bool no_split);
void reportPathEnd(PathEnd *end);
@ -1038,7 +1045,7 @@ public:
const MinMax *min_max,
int digits);
void writeSdc(const Sdc *sdc,
const char *filename,
std::string_view filename,
// Map hierarchical pins and instances to leaf pins and instances.
bool leaf,
// Replace non-sdc get functions with OpenSTA equivalents.
@ -1128,7 +1135,7 @@ public:
Slack (&slacks)[RiseFall::index_count][MinMax::index_count]);
// Worst slack for an endpoint in a path group.
Slack endpointSlack(const Pin *pin,
const std::string &path_group_name,
std::string_view path_group_name,
const MinMax *min_max);
void reportArrivalWrtClks(const Pin *pin,
@ -1193,8 +1200,8 @@ public:
// networks (dspf) are reduced and deleted after reading each net
// with reduce_to and delete_after_reduce.
// Return true if successful.
bool readSpef(const std::string &name,
const std::string &filename,
bool readSpef(std::string_view name,
std::string_view filename,
Instance *instance,
Scene *scene,
const MinMaxAll *min_max,
@ -1333,7 +1340,7 @@ public:
void searchPreamble();
// Define the delay calculator implementation.
void setArcDelayCalc(const char *delay_calc_name);
void setArcDelayCalc(std::string_view delay_calc_name);
void setDebugLevel(const char *what,
int level);
@ -1381,9 +1388,9 @@ public:
PwrActivity activity(const Pin *pin,
const Scene *scene);
void writeTimingModel(const char *lib_name,
const char *cell_name,
const char *filename,
void writeTimingModel(std::string_view lib_name,
std::string_view cell_name,
std::string_view filename,
const Scene *scene);
// Find equivalent cells in equiv_libs.
@ -1393,12 +1400,12 @@ public:
LibertyCellSeq *equivCells(LibertyCell *cell);
void writePathSpice(const Path *path,
const char *spice_filename,
const char *subckt_filename,
const char *lib_subckt_filename,
const char *model_filename,
const char *power_name,
const char *gnd_name,
std::string_view spice_filename,
std::string_view subckt_filename,
std::string_view lib_subckt_filename,
std::string_view model_filename,
std::string_view power_name,
std::string_view gnd_name,
CircuitSim ckt_sim);
////////////////////////////////////////////////////////////////
@ -1490,13 +1497,10 @@ protected:
virtual void makeObservers();
NetworkEdit *networkCmdEdit();
LibertyLibrary *readLibertyFile(const char *filename,
LibertyLibrary *readLibertyFile(std::string_view filename,
Scene *scene,
const MinMaxAll *min_max,
bool infer_latches);
// Allow external Liberty reader to parse forms not used by Sta.
virtual LibertyLibrary *readLibertyFile(const char *filename,
bool infer_latches);
void delayCalcPreamble();
void delaysInvalidFrom(const Port *port);
void delaysInvalidFromFanin(const Port *port);

View File

@ -24,6 +24,8 @@
#pragma once
#include <string_view>
struct Tcl_Interp;
namespace sta {
@ -58,11 +60,11 @@ unencode(const char *inits[]);
bool
findCmdLineFlag(int &argc,
char *argv[],
const char *flag);
std::string_view flag);
char *
findCmdLineKey(int &argc,
char *argv[],
const char *key);
std::string_view key);
int
parseThreadsArg(int &argc,

View File

@ -24,9 +24,12 @@
#pragma once
#include <algorithm>
#include <cstdarg>
#include <cstring>
#include <string>
#include <string_view>
#include <strings.h> // for strncasecmp
#include <vector>
#include <set>
@ -53,14 +56,6 @@ stringEq(const char *str1,
return strncmp(str1, str2, length) == 0;
}
inline bool
stringEqIf(const char *str1,
const char *str2)
{
return (str1 == nullptr && str2 == nullptr)
|| (str1 && str2 && strcmp(str1, str2) == 0);
}
// Case sensitive compare the beginning of str1 to str2.
inline bool
stringBeginEq(const char *str1,
@ -71,78 +66,24 @@ stringBeginEq(const char *str1,
// Case insensitive compare the beginning of str1 to str2.
inline bool
stringBeginEqual(const char *str1,
const char *str2)
stringBeginEqual(std::string_view str,
std::string_view prefix)
{
return strncasecmp(str1, str2, strlen(str2)) == 0;
if (str.size() < prefix.size())
return false;
return strncasecmp(str.data(), prefix.data(), prefix.size()) == 0;
}
// Case insensitive compare.
inline bool
stringEqual(const char *str1,
const char *str2)
stringEqual(std::string_view s1,
std::string_view s2)
{
return strcasecmp(str1, str2) == 0;
return std::ranges::equal(s1, s2, [](unsigned char c1, unsigned char c2) {
return std::tolower(c1) == std::tolower(c2);
});
}
inline bool
stringEqualIf(const char *str1,
const char *str2)
{
return (str1 == nullptr && str2 == nullptr)
|| (str1 && str2 && strcasecmp(str1, str2) == 0);
}
inline bool
stringLess(const char *str1,
const char *str2)
{
return strcmp(str1, str2) < 0;
}
inline bool
stringLessIf(const char *str1,
const char *str2)
{
return (str1 == nullptr && str2 != nullptr)
|| (str1 != nullptr && str2 != nullptr && strcmp(str1, str2) < 0);
}
class CharPtrLess
{
public:
bool operator()(const char *string1,
const char *string2) const
{
return stringLess(string1, string2);
}
};
// Case insensitive comparision.
class CharPtrCaseLess
{
public:
bool operator()(const char *string1,
const char *string2) const
{
return strcasecmp(string1, string2) < 0;
}
};
class StringLessIf
{
public:
bool operator()(const char *string1,
const char *string2) const
{
return stringLessIf(string1, string2);
}
};
// strdup using new instead of malloc so delete can be used on the strings.
char *
stringCopy(const char *str);
void
stringDeleteCheck(const char *str);
@ -153,17 +94,14 @@ stringDelete(const char *str)
delete [] str;
}
std::pair<float, bool>
stringFloat(const std::string &str);
bool
isDigits(const char *str);
char *
makeTmpString(size_t length);
char *
makeTmpString(std::string &str);
bool
isTmpString(const char *str);
void
deleteTmpStrings();
isDigits(std::string_view str);
////////////////////////////////////////////////////////////////
@ -171,9 +109,9 @@ deleteTmpStrings();
void
trimRight(std::string &str);
// Spit text into delimiter separated tokens and skip whitepace.
// Parse text into delimiter separated tokens and skip whitepace.
StringSeq
parseTokens(const std::string &s,
const char delimiter);
parseTokens(const std::string &text,
std::string_view delims = " \t");
} // namespace

View File

@ -27,6 +27,7 @@
#include <array>
#include <memory>
#include <string>
#include <string_view>
#include <vector>
#include "MinMax.hh"
@ -54,8 +55,8 @@ using Waveform = Table;
using TableModelsEarlyLate = std::array<TableModel*, EarlyLate::index_count>;
TableAxisVariable
stringTableAxisVariable(const char *variable);
const char *
stringTableAxisVariable(std::string_view variable);
std::string_view
tableVariableString(TableAxisVariable variable);
const Unit *
tableVariableUnit(TableAxisVariable variable,
@ -121,7 +122,7 @@ protected:
float in_slew,
float load_cap,
float related_out_cap) const;
std::string reportTableLookup(const char *result_name,
std::string reportTableLookup(std::string_view result_name,
const Pvt *pvt,
const TableModel *model,
float in_slew,
@ -158,7 +159,7 @@ public:
PocvMode pocv_mode) const override;
std::string reportCheckDelay(const Pvt *pvt,
float from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
float to_slew,
float related_out_cap,
const MinMax *min_max,
@ -189,11 +190,11 @@ protected:
float load_cap,
float in_slew,
float related_out_cap) const;
std::string reportTableDelay(const char *result_name,
std::string reportTableDelay(std::string_view result_name,
const Pvt *pvt,
const TableModel *model,
float from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
float to_slew,
float related_out_cap,
int digits) const;
@ -208,7 +209,7 @@ public:
TableAxis(TableAxisVariable variable,
FloatSeq &&values);
TableAxisVariable variable() const { return variable_; }
const char *variableString() const;
std::string_view variableString() const;
const Unit *unit(const Units *units);
size_t size() const { return values_.size(); }
bool inBounds(float value) const;
@ -287,11 +288,11 @@ public:
float axis_value2,
float axis_value3) const;
std::string reportValue(const char *result_name,
std::string reportValue(std::string_view result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -309,30 +310,30 @@ private:
void clear();
float findValueOrder2(float axis_value1, float axis_value2) const;
float findValueOrder3(float axis_value1, float axis_value2, float axis_value3) const;
std::string reportValueOrder0(const char *result_name,
const char *comment1,
std::string reportValueOrder0(std::string_view result_name,
std::string_view comment1,
const Unit *table_unit,
int digits) const;
std::string reportValueOrder1(const char *result_name,
std::string reportValueOrder1(std::string_view result_name,
const LibertyCell *cell,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const;
std::string reportValueOrder2(const char *result_name,
std::string reportValueOrder2(std::string_view result_name,
const LibertyCell *cell,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
int digits) const;
std::string reportValueOrder3(const char *result_name,
std::string reportValueOrder3(std::string_view result_name,
const LibertyCell *cell,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -379,11 +380,11 @@ public:
float value1,
float value2,
float value3) const;
std::string reportValue(const char *result_name,
std::string reportValue(std::string_view result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -535,9 +536,9 @@ private:
class DriverWaveform
{
public:
DriverWaveform(const std::string &name,
DriverWaveform(std::string name,
TablePtr waveforms);
const char *name() const { return name_.c_str(); }
std::string_view name() const { return name_; }
Table waveform(float slew);
private:

View File

@ -34,14 +34,14 @@ namespace sta {
#endif
StringSeq
tclListSeqStdString(Tcl_Obj *const source,
Tcl_Interp *interp);
tclListStringSeq(Tcl_Obj *const source,
Tcl_Interp *interp);
StringSeq *
tclListSeqStdStringPtr(Tcl_Obj *const source,
Tcl_Interp *interp);
StringSet *
tclListSetStdString(Tcl_Obj *const source,
tclListStringSeqPtr(Tcl_Obj *const source,
Tcl_Interp *interp);
StringSet *
tclListStringSet(Tcl_Obj *const source,
Tcl_Interp *interp);
void
tclArgError(Tcl_Interp *interp,

View File

@ -83,10 +83,10 @@ enum class TimingType {
unknown
};
const char *
std::string_view
to_string(TimingType type);
TimingType
findTimingType(const char *string);
findTimingType(std::string_view string);
bool
timingTypeIsCheck(TimingType type);
ScaleFactorType
@ -107,15 +107,15 @@ public:
FuncExpr *cond() const { return cond_; }
void setCond(FuncExpr *cond);
const std::string &sdfCond() const { return sdf_cond_; }
void setSdfCond(const std::string &cond);
void setSdfCond(std::string cond);
const std::string &sdfCondStart() const { return sdf_cond_start_; }
void setSdfCondStart(const std::string &cond);
void setSdfCondStart(std::string cond);
const std::string &sdfCondEnd() const { return sdf_cond_end_; }
void setSdfCondEnd(const std::string &cond);
void setSdfCondEnd(std::string cond);
const std::string &modeName() const { return mode_name_; }
void setModeName(const std::string &name);
void setModeName(std::string name);
const std::string &modeValue() const { return mode_value_; }
void setModeValue(const std::string &value);
void setModeValue(std::string value);
TimingModel *model(const RiseFall *rf) const;
void setModel(const RiseFall *rf,
TimingModel *model);

View File

@ -25,6 +25,7 @@
#pragma once
#include <string>
#include <string_view>
#include "Delay.hh"
#include "LibertyClass.hh"
@ -88,7 +89,7 @@ public:
PocvMode pocv_mode) const = 0;
virtual std::string reportCheckDelay(const Pvt *pvt,
float from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
float to_slew,
float related_out_cap,
const MinMax *min_max,

View File

@ -25,8 +25,9 @@
#pragma once
#include <array>
#include <vector>
#include <functional>
#include <map>
#include <vector>
#include "Iterator.hh"
#include "StringUtil.hh"
@ -37,7 +38,7 @@ class Transition;
class RiseFall;
class RiseFallBoth;
using TransitionMap = std::map<const std::string, const Transition*>;
using TransitionMap = std::map<std::string, const Transition*, std::less<>>;
// Rise/fall transition.
class RiseFall
@ -49,14 +50,14 @@ public:
static int riseIndex() { return rise_.sdf_triple_index_; }
static int fallIndex() { return fall_.sdf_triple_index_; }
const std::string &to_string(bool use_short = false) const;
const char *name() const { return name_.c_str(); }
const char *shortName() const { return short_name_.c_str(); }
const std::string &name() const { return name_; }
const std::string &shortName() const { return short_name_; }
int index() const { return sdf_triple_index_; }
const RiseFallBoth *asRiseFallBoth();
const RiseFallBoth *asRiseFallBoth() const;
const Transition *asTransition() const;
// Find transition corresponding to rf_str.
static const RiseFall *find(const char *rf_str);
static const RiseFall *find(std::string_view rf_str);
// Find transition from index.
static const RiseFall *find(int index);
const RiseFall *opposite() const;
@ -71,8 +72,8 @@ public:
static const int index_bit_count = 1;
protected:
RiseFall(const char *name,
const char *short_name,
RiseFall(std::string_view name,
std::string_view short_name,
int sdf_triple_index);
const std::string name_;
@ -94,14 +95,14 @@ public:
static const RiseFallBoth *fall() { return &fall_; }
static const RiseFallBoth *riseFall() { return &rise_fall_; }
const std::string &to_string(bool use_short = false) const;
const char *name() const { return name_.c_str(); }
const char *shortName() const { return short_name_.c_str(); }
const std::string &name() const { return name_; }
const std::string &shortName() const { return short_name_; }
int index() const { return sdf_triple_index_; }
bool matches(const RiseFall *rf) const;
bool matches(const Transition *tr) const;
const RiseFall *asRiseFall() const { return as_rise_fall_; }
// Find transition corresponding to string.
static const RiseFallBoth *find(const char *tr_str);
static const RiseFallBoth *find(std::string_view tr_str);
// for (const auto rf : rf->range()) {}
const std::vector<const RiseFall*> &range() const { return range_; }
// for (const auto rf_index : rf->rangeIndex()) {}
@ -112,8 +113,8 @@ public:
static const int index_bit_count = 2;
protected:
RiseFallBoth(const char *name,
const char *short_name,
RiseFallBoth(std::string_view name,
std::string_view short_name,
int sdf_triple_index,
const RiseFall *as_rise_fall,
std::vector<const RiseFall*> range,
@ -152,19 +153,19 @@ public:
static const Transition *riseFall() { return &rise_fall_; }
const std::string &to_string() const { return name_; }
// As initial/final value pair.
const char *asInitFinalString() const { return init_final_.c_str(); }
const std::string &asInitFinalString() const { return init_final_; }
int sdfTripleIndex() const { return sdf_triple_index_; }
int index() const { return sdf_triple_index_; }
const RiseFall *asRiseFall() const { return as_rise_fall_; }
const RiseFallBoth *asRiseFallBoth() const;
bool matches(const Transition *tr) const;
// Find transition corresponding to string.
static const Transition *find(const char *tr_str);
static const Transition *find(std::string_view tr_str);
static int maxIndex() { return max_index_; }
private:
Transition(const char *name,
const char *init_final,
Transition(std::string_view name,
std::string_view init_final,
const RiseFall *as_rise_fall,
int sdf_triple_index);

View File

@ -75,7 +75,7 @@ class Units
{
public:
Units();
Unit *find(const char *unit_name);
Unit *find(std::string_view unit_name);
void operator=(const Units &units);
Unit *timeUnit() { return &time_unit_; }
const Unit *timeUnit() const { return &time_unit_; }

View File

@ -74,7 +74,7 @@ public:
std::string_view msg,
bool warn);
const char *msg() const { return msg_.c_str(); }
const char *filename() const { return filename_.c_str(); }
std::string_view filename() const { return filename_; }
int id() const { return id_; }
int line() const { return line_; }
bool warn() const { return warn_; }
@ -102,14 +102,14 @@ class VerilogReader
public:
VerilogReader(NetworkReader *network);
~VerilogReader();
bool read(const char *filename);
bool read(std::string_view filename);
void makeModule(const std::string *module_name,
void makeModule(std::string &&module_name,
VerilogNetSeq *ports,
VerilogStmtSeq *stmts,
VerilogAttrStmtSeq *attr_stmts,
int line);
void makeModule(const std::string *module_name,
void makeModule(std::string &&module_name,
VerilogStmtSeq *port_dcls,
VerilogStmtSeq *stmts,
VerilogAttrStmtSeq *attr_stmts,
@ -122,7 +122,7 @@ public:
VerilogDclArg *arg,
VerilogAttrStmtSeq *attr_stmts,
int line);
VerilogDclArg *makeDclArg(const std::string *net_name);
VerilogDclArg *makeDclArg(std::string &&net_name);
VerilogDclArg*makeDclArg(VerilogAssign *assign);
VerilogDclBus *makeDclBus(PortDirection *dir,
int from_index,
@ -136,43 +136,43 @@ public:
VerilogDclArgSeq *args,
VerilogAttrStmtSeq *attr_stmts,
int line);
VerilogInst *makeModuleInst(const std::string *module_name,
const std::string *inst_name,
VerilogInst *makeModuleInst(std::string &&module_name,
std::string &&inst_name,
VerilogNetSeq *pins,
VerilogAttrStmtSeq *attr_stmts,
const int line);
VerilogAssign *makeAssign(VerilogNet *lhs,
VerilogNet *rhs,
int line);
VerilogNetScalar *makeNetScalar(const std::string *name);
VerilogNetPortRef *makeNetNamedPortRefScalarNet(const std::string *port_vname);
VerilogNetPortRef *makeNetNamedPortRefScalarNet(const std::string *port_name,
const std::string *net_name);
VerilogNetPortRef *makeNetNamedPortRefBitSelect(const std::string *port_name,
const std::string *bus_name,
VerilogNetScalar *makeNetScalar(std::string &&name);
VerilogNetPortRef *makeNetNamedPortRefScalarNet(std::string &&port_vname);
VerilogNetPortRef *makeNetNamedPortRefScalarNet(std::string &&port_name,
std::string &&net_name);
VerilogNetPortRef *makeNetNamedPortRefBitSelect(std::string &&port_name,
std::string &&bus_name,
int index);
VerilogNetPortRef *makeNetNamedPortRefScalar(const std::string *port_name,
VerilogNetPortRef *makeNetNamedPortRefScalar(std::string &&port_name,
VerilogNet *net);
VerilogNetPortRef *makeNetNamedPortRefBit(const std::string *port_name,
VerilogNetPortRef *makeNetNamedPortRefBit(std::string &&port_name,
int index,
VerilogNet *net);
VerilogNetPortRef *makeNetNamedPortRefPart(const std::string *port_name,
VerilogNetPortRef *makeNetNamedPortRefPart(std::string &&port_name,
int from_index,
int to_index,
VerilogNet *net);
VerilogNetConcat *makeNetConcat(VerilogNetSeq *nets);
VerilogNetConstant *makeNetConstant(const std::string *constant,
int line);
VerilogNetBitSelect *makeNetBitSelect(const std::string *name,
VerilogNetConstant *makeNetConstant(std::string &&constant,
int line);
VerilogNetBitSelect *makeNetBitSelect(std::string &&name,
int index);
VerilogNetPartSelect *makeNetPartSelect(const std::string *name,
VerilogNetPartSelect *makeNetPartSelect(std::string &&name,
int from_index,
int to_index);
VerilogModule *module(Cell *cell);
Instance *linkNetwork(const char *top_cell_name,
Instance *linkNetwork(std::string_view top_cell_name,
bool make_black_boxes,
bool delete_modules);
const char *filename() const { return filename_.c_str(); }
std::string_view filename() const { return filename_; }
void incrLine();
Report *report() const { return report_; }
template <typename... Args>
@ -196,11 +196,10 @@ public:
const std::string &zeroNetName() const { return zero_net_name_; }
const std::string &oneNetName() const { return one_net_name_; }
void deleteModules();
void reportStmtCounts();
const std::string &constant10Max() const { return constant10_max_; }
protected:
void init(const char *filename);
void init(std::string_view filename);
void makeCellPorts(Cell *cell,
VerilogModule *module,
VerilogNetSeq *ports);
@ -315,29 +314,6 @@ protected:
const std::string one_net_name_;
std::string constant10_max_;
ViewType *view_type_;
bool report_stmt_stats_;
int module_count_;
int inst_mod_count_;
int inst_lib_count_;
int inst_lib_net_arrays_;
int port_names_;
int inst_module_names_;
int inst_names_;
int dcl_count_;
int dcl_bus_count_;
int dcl_arg_count_;
int net_scalar_count_;
int net_scalar_names_;
int net_bus_names_;
int net_part_select_count_;
int net_bit_select_count_;
int net_port_ref_scalar_count_;
int net_port_ref_scalar_net_count_;
int net_port_ref_bit_count_;
int net_port_ref_part_count_;
int net_constant_count_;
int assign_count_;
int concat_count_;
};
} // namespace sta

View File

@ -24,6 +24,8 @@
#pragma once
#include <string>
#include <string_view>
#include <utility>
#include <vector>
@ -40,26 +42,26 @@ using WireloadForAreaSeq = std::vector<WireloadForArea*>;
const char *
wireloadTreeString(WireloadTree tree);
WireloadTree
stringWireloadTree(const char *tree);
stringWireloadTree(std::string_view tree);
const char *
wireloadModeString(WireloadMode wire_load_mode);
WireloadMode
stringWireloadMode(const char *wire_load_mode);
stringWireloadMode(std::string_view wire_load_mode);
class Wireload
{
public:
Wireload(const char *name,
Wireload(std::string name,
LibertyLibrary *library);
Wireload(const char *name,
Wireload(std::string name,
LibertyLibrary *library,
float area,
float resistance,
float capacitance,
float slope);
virtual ~Wireload();
const char *name() const { return name_; }
const std::string &name() const { return name_; }
void setArea(float area);
void setResistance(float res);
void setCapacitance(float cap);
@ -73,7 +75,7 @@ public:
float &res) const;
protected:
const char *name_;
std::string name_;
LibertyLibrary *library_;
float area_;
float resistance_;
@ -86,16 +88,16 @@ protected:
class WireloadSelection
{
public:
WireloadSelection(const char *name);
WireloadSelection(std::string name);
~WireloadSelection();
const char *name() const { return name_; }
const std::string &name() const { return name_; }
void addWireloadFromArea(float min_area,
float max_area,
const Wireload *wireload);
const Wireload *findWireload(float area) const;
private:
const char *name_;
const std::string name_;
WireloadForAreaSeq wireloads_;
};

View File

@ -208,7 +208,7 @@ hashCellPorts(const LibertyCell *cell)
static unsigned
hashPort(const LibertyPort *port)
{
return hashString(port->name()) * 3
return hashString(port->name().c_str()) * 3
+ port->direction()->index() * 5;
}
@ -338,8 +338,7 @@ equivCellFuncs(const LibertyCell *cell1,
LibertyCellPortIterator port_iter1(cell1);
while (port_iter1.hasNext()) {
LibertyPort *port1 = port_iter1.next();
const char *name = port1->name();
LibertyPort *port2 = cell2->findLibertyPort(name);
LibertyPort *port2 = cell2->findLibertyPort(port1->name());
if (!(port2
&& FuncExpr::equiv(port1->function(), port2->function())
&& FuncExpr::equiv(port1->tristateEnable(),
@ -359,8 +358,7 @@ equivCellPorts(const LibertyCell *cell1,
LibertyCellPortIterator port_iter1(cell1);
while (port_iter1.hasNext()) {
LibertyPort *port1 = port_iter1.next();
const char* name = port1->name();
LibertyPort *port2 = cell2->findLibertyPort(name);
LibertyPort *port2 = cell2->findLibertyPort(port1->name());
if (!(port2 && LibertyPort::equiv(port1, port2)))
return false;
}

View File

@ -108,7 +108,7 @@ InternalPowerModel::reportPower(const LibertyCell *cell,
findAxisValues(in_slew, load_cap,
axis_value1, axis_value2, axis_value3);
const LibertyLibrary *library = cell->libertyLibrary();
return model_->reportValue("Power", cell, pvt, axis_value1, nullptr,
return model_->reportValue("Power", cell, pvt, axis_value1, {},
axis_value2, axis_value3,
library->units()->powerUnit(), digits);
}

View File

@ -25,14 +25,14 @@
// Liberty function expression lexical analyzer
#include <string>
#include "util/FlexDisableRegister.hh"
#include "Debug.hh"
#include "StringUtil.hh"
#include "liberty/LibExprReaderPvt.hh"
#include "liberty/LibExprReader.hh"
#include "liberty/LibExprScanner.hh"
using sta::stringCopy;
using sta::FuncExpr;
#include "LibExprParse.hh"
@ -76,12 +76,12 @@ EOL \r?\n
<ESCAPED_STRING>{ESCAPE}{QUOTE} {
BEGIN(INITIAL);
yylval->string = stringCopy(token_.c_str());
yylval->emplace<std::string>(token_);
return token::PORT;
}
{PORT} {
yylval->string = stringCopy(yytext);
yylval->emplace<std::string>(yytext, yyleng);
return token::PORT;
}

View File

@ -25,6 +25,8 @@
// Liberty function expression parser.
%{
#include <string>
#include "FuncExpr.hh"
#include "liberty/LibExprReader.hh"
#include "liberty/LibExprReaderPvt.hh"
@ -39,7 +41,7 @@
void
sta::LibExprParse::error(const std::string &msg)
{
reader->parseError(msg.c_str());
reader->parseError(msg);
}
%}
@ -52,21 +54,15 @@ sta::LibExprParse::error(const std::string &msg)
%parse-param{LibExprScanner *scanner}
%parse-param{LibExprReader *reader}
%define api.parser.class {LibExprParse}
%define api.value.type variant
%union {
int int_val;
const char *string;
sta::FuncExpr *expr;
}
%token PORT
%token <std::string> PORT
%left '+' '|'
%left '*' '&'
%left '^'
%left '!' '\''
%type <string> PORT
%type <expr> expr terminal terminal_expr implicit_and
%type <sta::FuncExpr *> expr terminal terminal_expr implicit_and
%%
@ -76,14 +72,14 @@ result_expr:
;
terminal:
PORT { $$ = reader->makeFuncExprPort($1); }
PORT { $$ = reader->makeFuncExprPort(std::move($1)); }
| '0' { $$ = sta::FuncExpr::makeZero(); }
| '1' { $$ = sta::FuncExpr::makeOne(); }
| '(' expr ')' { $$ = $2; }
;
terminal_expr:
terminal
terminal { $$ = $1; }
| '!' terminal { $$ = reader->makeFuncExprNot($2); }
| terminal '\'' { $$ = reader->makeFuncExprNot($1); }
;
@ -96,8 +92,8 @@ implicit_and:
;
expr:
terminal_expr
| implicit_and
terminal_expr { $$ = $1; }
| implicit_and { $$ = $1; }
| expr '+' expr { $$ = reader->makeFuncExprOr($1, $3); }
| expr '|' expr { $$ = reader->makeFuncExprOr($1, $3); }
| expr '*' expr { $$ = reader->makeFuncExprAnd($1, $3); }

View File

@ -26,9 +26,10 @@
#include <iostream>
#include <sstream>
#include <string>
#include <string_view>
#include "Report.hh"
#include "StringUtil.hh"
#include "Liberty.hh"
#include "LibExprReaderPvt.hh"
#include "LibExprScanner.hh"
@ -36,14 +37,14 @@
namespace sta {
FuncExpr *
parseFuncExpr(const char *func,
parseFuncExpr(std::string_view func,
const LibertyCell *cell,
const char *error_msg,
std::string_view error_msg,
Report *report)
{
if (func != nullptr && func[0] != '\0') {
std::string func1(func);
std::istringstream stream(func);
if (!func.empty()) {
std::string func_str(func);
std::istringstream stream(func_str);
LibExprReader reader(func, cell, error_msg, report);
LibExprScanner scanner(stream);
LibExprParse parser(&scanner, &reader);
@ -55,9 +56,9 @@ parseFuncExpr(const char *func,
return nullptr;
}
LibExprReader::LibExprReader(const char *func,
LibExprReader::LibExprReader(std::string_view func,
const LibertyCell *cell,
const char *error_msg,
std::string_view error_msg,
Report *report) :
func_(func),
cell_(cell),
@ -70,18 +71,18 @@ LibExprReader::LibExprReader(const char *func,
// defined in LibertyReader.cc
LibertyPort *
libertyReaderFindPort(const LibertyCell *cell,
const char *port_name);
std::string_view port_name);
FuncExpr *
LibExprReader::makeFuncExprPort(const char *port_name)
LibExprReader::makeFuncExprPort(std::string &&port_name)
{
FuncExpr *expr = nullptr;
LibertyPort *port = libertyReaderFindPort(cell_, port_name);
const std::string_view port_view(port_name);
LibertyPort *port = libertyReaderFindPort(cell_, port_view);
if (port)
expr = FuncExpr::makePort(port);
else
report_->warn(1130, "{} references unknown port {}.", error_msg_, port_name);
stringDelete(port_name);
report_->warn(1130, "{} references unknown port {}.", error_msg_, port_view);
return expr;
}
@ -131,7 +132,7 @@ LibExprReader::setResult(FuncExpr *result)
}
void
LibExprReader::parseError(const char *msg)
LibExprReader::parseError(std::string_view msg)
{
report_->error(1131, "{} {}.", error_msg_, msg);
}

View File

@ -24,6 +24,8 @@
#pragma once
#include <string_view>
namespace sta {
class Report;
@ -31,9 +33,9 @@ class FuncExpr;
class LibertyCell;
FuncExpr *
parseFuncExpr(const char *func,
parseFuncExpr(std::string_view func,
const LibertyCell *cell,
const char *error_msg,
std::string_view error_msg,
Report *report);
} // namespace

View File

@ -24,6 +24,9 @@
#pragma once
#include <string>
#include <string_view>
namespace sta {
class Report;
@ -34,11 +37,11 @@ class LibExprScanner;
class LibExprReader
{
public:
LibExprReader(const char *func,
LibExprReader(std::string_view func,
const LibertyCell *cell,
const char *error_msg,
std::string_view error_msg,
Report *report);
FuncExpr *makeFuncExprPort(const char *port_name);
FuncExpr *makeFuncExprPort(std::string &&port_name);
FuncExpr *makeFuncExprOr(FuncExpr *arg1,
FuncExpr *arg2);
FuncExpr *makeFuncExprAnd(FuncExpr *arg1,
@ -48,15 +51,13 @@ public:
FuncExpr *makeFuncExprNot(FuncExpr *arg);
void setResult(FuncExpr *result);
FuncExpr *result() { return result_; }
void parseError(const char *msg);
size_t copyInput(char *buf,
size_t max_size);
void parseError(std::string_view msg);
Report *report() const { return report_; }
private:
const char *func_;
std::string_view func_;
const LibertyCell *cell_;
const char *error_msg_;
std::string_view error_msg_;
Report *report_;
FuncExpr *result_;
};

View File

@ -62,9 +62,9 @@ deleteLiberty()
TimingArcSet::destroy();
}
LibertyLibrary::LibertyLibrary(const char *name,
const char *filename) :
ConcreteLibrary(name, filename, true),
LibertyLibrary::LibertyLibrary(std::string name,
std::string filename) :
ConcreteLibrary(std::move(name), std::move(filename), true),
units_(new Units()),
delay_model_type_(DelayModelType::table), // default
nominal_process_(0.0),
@ -121,7 +121,7 @@ LibertyLibrary::~LibertyLibrary()
}
LibertyCell *
LibertyLibrary::findLibertyCell(const char *name) const
LibertyLibrary::findLibertyCell(std::string_view name) const
{
return static_cast<LibertyCell*>(findCell(name));
}
@ -188,10 +188,9 @@ LibertyLibrary::makeBusDcl(std::string name,
}
BusDcl *
LibertyLibrary::findBusDcl(const char *name) const
LibertyLibrary::findBusDcl(std::string_view name)
{
auto it = bus_dcls_.find(name);
return it != bus_dcls_.end() ? const_cast<BusDcl *>(&it->second) : nullptr;
return findStringValuePtr(bus_dcls_, name);
}
BusDclSeq
@ -208,16 +207,17 @@ LibertyLibrary::makeTableTemplate(std::string name,
TableTemplateType type)
{
std::string key = name;
auto [it, inserted] = template_maps_[int(type)].try_emplace(
std::move(key), std::move(name), type);
auto [it, inserted] = template_maps_[int(type)].try_emplace(std::move(key),
std::move(name),
type);
return &it->second;
}
TableTemplate *
LibertyLibrary::findTableTemplate(const char *name,
LibertyLibrary::findTableTemplate(std::string_view name,
TableTemplateType type)
{
return findKeyValuePtr(template_maps_[int(type)], name);
return findStringValuePtr(template_maps_[int(type)], name);
}
TableTemplateSeq
@ -265,16 +265,17 @@ LibertyLibrary::setScaleFactors(ScaleFactors *scales)
}
ScaleFactors *
LibertyLibrary::makeScaleFactors(const char *name)
LibertyLibrary::makeScaleFactors(std::string name)
{
auto [it, inserted] = scale_factors_map_.emplace(name, name);
std::string key = name;
auto [it, inserted] = scale_factors_map_.emplace(std::move(key), std::move(name));
return &it->second;
}
ScaleFactors *
LibertyLibrary::findScaleFactors(const char *name)
LibertyLibrary::findScaleFactors(std::string_view name)
{
return findKeyValuePtr(scale_factors_map_, name);
return findStringValuePtr(scale_factors_map_,name);
}
float
@ -566,16 +567,14 @@ LibertyLibrary::setDefaultOutputPinRes(const RiseFall *rf,
Wireload *
LibertyLibrary::makeWireload(std::string name)
{
std::string key = name;
auto [it, inserted] = wireloads_.try_emplace(
std::move(key), name.c_str(), this);
auto [it, inserted] = wireloads_.try_emplace(name, name, this);
return &it->second;
}
const Wireload *
LibertyLibrary::findWireload(const char *name) const
LibertyLibrary::findWireload(std::string_view name)
{
return findKeyValuePtr(wireloads_, name);
return findStringValuePtr(wireloads_, name);
}
void
@ -594,14 +593,15 @@ WireloadSelection *
LibertyLibrary::makeWireloadSelection(std::string name)
{
std::string key = name;
auto [it, inserted] = wire_load_selections_.try_emplace(std::move(key), name.c_str());
auto [it, inserted] = wire_load_selections_.try_emplace(std::move(key),
std::move(name));
return &it->second;
}
const WireloadSelection *
LibertyLibrary::findWireloadSelection(const char *name) const
LibertyLibrary::findWireloadSelection(std::string_view name) const
{
return findKeyValuePtr(wire_load_selections_, name);
return findStringValuePtr(wire_load_selections_, name);
}
const WireloadSelection *
@ -632,15 +632,14 @@ OperatingConditions *
LibertyLibrary::makeOperatingConditions(std::string name)
{
std::string key = name;
auto [it, inserted] = operating_conditions_.try_emplace(
std::move(key), name.c_str());
auto [it, inserted] = operating_conditions_.try_emplace(std::move(key), std::move(name));
return &it->second;
}
OperatingConditions *
LibertyLibrary::findOperatingConditions(const char *name)
LibertyLibrary::findOperatingConditions(std::string_view name)
{
return findKeyValuePtr(operating_conditions_, name);
return findStringValuePtr(operating_conditions_, name);
}
OperatingConditions *
@ -720,11 +719,10 @@ LibertyLibrary::setSlewDerateFromLibrary(float derate)
}
LibertyCell *
LibertyLibrary::makeScaledCell(const char *name,
const char *filename)
LibertyLibrary::makeScaledCell(std::string name,
std::string filename)
{
LibertyCell *cell = new LibertyCell(this, name, filename);
return cell;
return new LibertyCell(this, std::move(name), std::move(filename));
}
////////////////////////////////////////////////////////////////
@ -738,8 +736,7 @@ LibertyLibrary::makeSceneMap(LibertyLibrary *lib,
LibertyCellIterator cell_iter(lib);
while (cell_iter.hasNext()) {
LibertyCell *cell = cell_iter.next();
const char *name = cell->name();
LibertyCell *link_cell = network->findLibertyCell(name);
LibertyCell *link_cell = network->findLibertyCell(cell->name());
if (link_cell)
makeSceneMap(link_cell, cell, ap_index, report);
}
@ -769,8 +766,7 @@ LibertyLibrary::makeSceneMap(LibertyCell *cell1,
LibertyCellPortBitIterator port_iter1(cell1);
while (port_iter1.hasNext()) {
LibertyPort *port1 = port_iter1.next();
const char *port_name = port1->name();
LibertyPort *port2 = cell2->findLibertyPort(port_name);
LibertyPort *port2 = cell2->findLibertyPort(port1->name());
if (port2) {
if (link)
port1->setScenePort(port2, ap_index);
@ -779,7 +775,7 @@ LibertyLibrary::makeSceneMap(LibertyCell *cell1,
report->warn(1110, "cell {}/{} port {} not found in cell {}/{}.",
cell1->library()->name(),
cell1->name(),
port_name,
port1->name(),
cell2->library()->name(),
cell2->name());
}
@ -807,7 +803,7 @@ LibertyLibrary::makeSceneMap(LibertyCell *cell1,
cell1->name(),
arc_set1->from() ? arc_set1->from()->name() : "",
arc_set1->to()->name(),
arc_set1->role()->to_string().c_str(),
arc_set1->role()->to_string(),
cell2->library()->name(),
cell2->name());
}
@ -824,8 +820,8 @@ LibertyLibrary::checkScenes(LibertyCell *cell,
report->error(1112, "Liberty cell {}/{} for corner {}/{} not found.",
cell->libertyLibrary()->name(),
cell->name(),
scene->name().c_str(),
min_max->to_string().c_str());
scene->name(),
min_max->to_string());
}
}
}
@ -865,21 +861,20 @@ LibertyLibrary::makeOcvDerate(std::string name)
}
OcvDerate *
LibertyLibrary::findOcvDerate(const char *derate_name)
LibertyLibrary::findOcvDerate(std::string_view derate_name)
{
auto it = ocv_derate_map_.find(derate_name);
return it != ocv_derate_map_.end() ? &it->second : nullptr;
return findStringValuePtr(ocv_derate_map_, derate_name);
}
void
LibertyLibrary::addSupplyVoltage(const char *supply_name,
LibertyLibrary::addSupplyVoltage(std::string supply_name,
float voltage)
{
supply_voltage_map_[supply_name] = voltage;
supply_voltage_map_[std::move(supply_name)] = voltage;
}
void
LibertyLibrary::supplyVoltage(const char *supply_name,
LibertyLibrary::supplyVoltage(std::string_view supply_name,
// Return value.
float &voltage,
bool &exists) const
@ -896,26 +891,26 @@ LibertyLibrary::supplyVoltage(const char *supply_name,
}
bool
LibertyLibrary::supplyExists(const char *supply_name) const
LibertyLibrary::supplyExists(std::string_view supply_name) const
{
return supply_voltage_map_.contains(supply_name);
}
DriverWaveform *
LibertyLibrary::findDriverWaveform(const char *name)
LibertyLibrary::findDriverWaveform(std::string_view name)
{
auto it = driver_waveform_map_.find(name);
if (it != driver_waveform_map_.end())
return &it->second;
return nullptr;
return findStringValuePtr(driver_waveform_map_, name);
}
DriverWaveform *
LibertyLibrary::makeDriverWaveform(const std::string &name,
LibertyLibrary::makeDriverWaveform(std::string name,
TablePtr waveforms)
{
auto it = driver_waveform_map_.emplace(name, DriverWaveform(name, waveforms));
return &it.first->second;
std::string key = name;
auto [it, inserted] = driver_waveform_map_.try_emplace(std::move(key),
std::move(name),
waveforms);
return &it->second;
}
////////////////////////////////////////////////////////////////
@ -940,8 +935,8 @@ LibertyCellIterator::next()
////////////////////////////////////////////////////////////////
LibertyCell::LibertyCell(LibertyLibrary *library,
const char *name,
const char *filename) :
std::string name,
std::string filename) :
ConcreteCell(name, filename, true, library),
liberty_library_(library),
area_(0.0),
@ -982,7 +977,7 @@ LibertyCell::~LibertyCell()
}
LibertyPort *
LibertyCell::findLibertyPort(const char *name) const
LibertyCell::findLibertyPort(std::string_view name) const
{
return static_cast<LibertyPort*>(findPort(name));
}
@ -1032,9 +1027,9 @@ LibertyCell::makeModeDef(std::string name)
}
const ModeDef *
LibertyCell::findModeDef(const char *name) const
LibertyCell::findModeDef(std::string_view name) const
{
return findKeyValuePtr(mode_defs_, name);
return findStringValuePtr(mode_defs_, name);
}
void
@ -1054,10 +1049,9 @@ LibertyCell::makeBusDcl(std::string name,
}
BusDcl *
LibertyCell::findBusDcl(const char *name) const
LibertyCell::findBusDcl(std::string_view name)
{
auto it = bus_dcls_.find(name);
return it != bus_dcls_.end() ? const_cast<BusDcl *>(&it->second) : nullptr;
return findStringValuePtr(bus_dcls_, name);
}
void
@ -1494,8 +1488,7 @@ LibertyCell::outputPortSequential(LibertyPort *port)
bool
LibertyCell::hasSequentials() const
{
return !sequentials_.empty()
|| statetable_ != nullptr;
return !sequentials_.empty();
}
void
@ -1639,10 +1632,9 @@ LibertyCell::makeOcvDerate(std::string name)
}
OcvDerate *
LibertyCell::findOcvDerate(const char *derate_name)
LibertyCell::findOcvDerate(std::string_view derate_name)
{
auto it = ocv_derate_map_.find(derate_name);
return it != ocv_derate_map_.end() ? &it->second : nullptr;
return findStringValuePtr(ocv_derate_map_, derate_name);
}
////////////////////////////////////////////////////////////////
@ -1936,35 +1928,16 @@ LibertyCell::ensureVoltageWaveforms(const SceneSeq &scenes)
}
}
const char *
LibertyCell::footprint() const
{
if (footprint_.empty())
return nullptr;
else
return footprint_.c_str();
}
void
LibertyCell::setFootprint(const char *footprint)
LibertyCell::setFootprint(std::string footprint)
{
footprint_ = footprint;
}
const char *
LibertyCell::userFunctionClass() const
{
if (user_function_class_.empty())
return nullptr;
else
return user_function_class_.c_str();
footprint_ = std::move(footprint);
}
void
LibertyCell::setUserFunctionClass(const char *user_function_class)
LibertyCell::setUserFunctionClass(std::string user_function_class)
{
user_function_class_ = user_function_class;
user_function_class_ = std::move(user_function_class);
}
////////////////////////////////////////////////////////////////
@ -2013,14 +1986,15 @@ LibertyCellPortBitIterator::next()
////////////////////////////////////////////////////////////////
LibertyPort::LibertyPort(LibertyCell *cell,
const char *name,
std::string name,
bool is_bus,
BusDcl *bus_dcl,
int from_index,
int to_index,
bool is_bundle,
ConcretePortSeq *members) :
ConcretePort(name, is_bus, from_index, to_index, is_bundle, members, cell),
ConcretePort(name, is_bus, from_index, to_index,
is_bundle, members, cell),
liberty_cell_(cell),
bus_dcl_(bus_dcl),
pwr_gnd_type_(PwrGndType::none),
@ -2033,6 +2007,8 @@ LibertyPort::LibertyPort(LibertyCell *cell,
min_period_(0.0),
pulse_clk_trigger_(nullptr),
pulse_clk_sense_(nullptr),
related_ground_port_(nullptr),
related_power_port_(nullptr),
receiver_model_(nullptr),
driver_waveform_{nullptr, nullptr},
min_pulse_width_exists_(false),
@ -2103,9 +2079,9 @@ LibertyPort::setPwrGndType(PwrGndType type)
}
void
LibertyPort::setVoltageName(const char *voltage_name)
LibertyPort::setVoltageName(std::string voltage_name)
{
voltage_name_ = voltage_name;
voltage_name_ = std::move(voltage_name);
}
static EnumNameMap<PwrGndType> pwr_gnd_type_map =
@ -2121,21 +2097,21 @@ static EnumNameMap<PwrGndType> pwr_gnd_type_map =
{PwrGndType::deepnwell, "deepnwell"},
{PwrGndType::deeppwell, "deeppwell"}};
const char *
const std::string &
pwrGndTypeName(PwrGndType pg_type)
{
return pwr_gnd_type_map.find(pg_type);
}
PwrGndType
findPwrGndType(const char *pg_name)
findPwrGndType(std::string_view pg_name)
{
return pwr_gnd_type_map.find(pg_name, PwrGndType::none);
}
////////////////////////////////////////////////////////////////
const char *
const std::string &
scanSignalTypeName(ScanSignalType scan_type)
{
return scan_signal_type_map.find(scan_type);
@ -2491,7 +2467,7 @@ LibertyPort::equiv(const LibertyPort *port1,
{
return (port1 == nullptr && port2 == nullptr)
|| (port1 != nullptr && port2 != nullptr
&& stringEq(port1->name(), port2->name())
&& port1->name() == port2->name()
&& port1->direction() == port2->direction()
&& port1->pwr_gnd_type_ == port2->pwr_gnd_type_);
}
@ -2504,14 +2480,14 @@ LibertyPort::less(const LibertyPort *port1,
return true;
if (port1 != nullptr && port2 == nullptr)
return false;
const char *name1 = port1->name();
const char *name2 = port2->name();
if (stringEq(name1, name2)) {
const std::string &name1 = port1->name();
const std::string &name2 = port2->name();
if (name1 == name2) {
PortDirection *dir1 = port1->direction();
PortDirection *dir2 = port2->direction();
return dir1->index() < dir2->index();
}
return stringLess(name1, name2);
return name1 < name2;
}
void
@ -2674,34 +2650,16 @@ LibertyPort::setScenePort(LibertyPort *scene_port,
scene_ports_[ap_index] = scene_port;
}
const char *
LibertyPort::relatedGroundPin() const
void
LibertyPort::setRelatedGroundPort(LibertyPort *related_ground_port)
{
if (related_ground_pin_.empty())
return nullptr;
else
return related_ground_pin_.c_str();
related_ground_port_ = related_ground_port;
}
void
LibertyPort::setRelatedGroundPin(const char *related_ground_pin)
LibertyPort::setRelatedPowerPort(LibertyPort *related_power_port)
{
related_ground_pin_ = related_ground_pin;
}
const char *
LibertyPort::relatedPowerPin() const
{
if (related_power_pin_.empty())
return nullptr;
else
return related_power_pin_.c_str();
}
void
LibertyPort::setRelatedPowerPin(const char *related_power_pin)
{
related_power_pin_ = related_power_pin;
related_power_port_ = related_power_port;
}
void
@ -2711,13 +2669,12 @@ LibertyPort::setReceiverModel(ReceiverModelPtr receiver_model)
}
std::string
portLibertyToSta(const char *port_name)
portLibertyToSta(std::string_view port_name)
{
constexpr char bus_brkt_left = '[';
constexpr char bus_brkt_right = ']';
size_t name_length = strlen(port_name);
std::string sta_name;
for (size_t i = 0; i < name_length; i++) {
for (size_t i = 0; i < port_name.size(); i++) {
char ch = port_name[i];
if (ch == bus_brkt_left
|| ch == bus_brkt_right)
@ -2841,7 +2798,7 @@ bool
LibertyPortNameLess::operator()(const LibertyPort *port1,
const LibertyPort *port2) const
{
return stringLess(port1->name(), port2->name());
return port1->name() < port2->name();
}
bool
@ -2900,30 +2857,24 @@ ModeDef::ModeDef(std::string name) :
}
ModeValueDef *
ModeDef::defineValue(const char *value,
FuncExpr *cond,
const char *sdf_cond)
ModeDef::defineValue(std::string value)
{
std::string key = value;
std::string sdf = sdf_cond ? sdf_cond : std::string();
auto [it, inserted] = values_.try_emplace(key, key, cond, std::move(sdf));
auto [it, inserted] = values_.try_emplace(std::move(key), std::move(value));
return &it->second;
}
const ModeValueDef *
ModeDef::findValueDef(const char *value) const
ModeDef::findValueDef(std::string_view value) const
{
return findKeyValuePtr(values_, value);
return findStringValuePtr(values_, value);
}
////////////////////////////////////////////////////////////////
ModeValueDef::ModeValueDef(std::string value,
FuncExpr *cond,
std::string sdf_cond) :
ModeValueDef::ModeValueDef(std::string value) :
value_(std::move(value)),
cond_(cond),
sdf_cond_(std::move(sdf_cond))
cond_(nullptr)
{
}
@ -3038,25 +2989,14 @@ Pvt::setTemperature(float temp)
temperature_ = temp;
}
OperatingConditions::OperatingConditions(const char *name) :
OperatingConditions::OperatingConditions(std::string name) :
Pvt(0.0, 0.0, 0.0),
name_(name),
name_(std::move(name)),
// Default wireload tree.
wire_load_tree_(WireloadTree::unknown)
{
}
OperatingConditions::OperatingConditions(const char *name,
float process,
float voltage,
float temperature,
WireloadTree wire_load_tree) :
Pvt(process, voltage, temperature),
name_(name),
wire_load_tree_(wire_load_tree)
{
}
void
OperatingConditions::setWireloadTree(WireloadTree tree)
{
@ -3084,14 +3024,14 @@ static EnumNameMap<ScaleFactorType> scale_factor_type_map =
{ScaleFactorType::unknown, "unknown"}
};
const char *
const std::string &
scaleFactorTypeName(ScaleFactorType type)
{
return scale_factor_type_map.find(type);
}
ScaleFactorType
findScaleFactorType(const char *name)
findScaleFactorType(std::string_view name)
{
return scale_factor_type_map.find(name, ScaleFactorType::unknown);
}
@ -3132,12 +3072,12 @@ EnumNameMap<ScaleFactorPvt> scale_factor_pvt_names =
};
ScaleFactorPvt
findScaleFactorPvt(const char *name)
findScaleFactorPvt(std::string_view name)
{
return scale_factor_pvt_names.find(name, ScaleFactorPvt::unknown);
}
const char *
const std::string &
scaleFactorPvtName(ScaleFactorPvt pvt)
{
return scale_factor_pvt_names.find(pvt);
@ -3145,8 +3085,8 @@ scaleFactorPvtName(ScaleFactorPvt pvt)
////////////////////////////////////////////////////////////////
ScaleFactors::ScaleFactors(const char *name) :
name_(name)
ScaleFactors::ScaleFactors(std::string name) :
name_(std::move(name))
{
for (int type = 0; type < scale_factor_type_count; type++) {
for (int pvt = 0; pvt < scale_factor_pvt_count; pvt++) {
@ -3230,7 +3170,7 @@ ScaleFactors::report(Report *report)
TestCell::TestCell(LibertyLibrary *library,
std::string name,
std::string filename) :
LibertyCell(library, name.c_str(), filename.c_str())
LibertyCell(library, name, filename)
{
}

View File

@ -25,6 +25,7 @@
%module liberty
%{
#include "PatternMatch.hh"
#include "PortDirection.hh"
#include "Liberty.hh"
#include "EquivCells.hh"
@ -173,7 +174,7 @@ find_library_buffers(LibertyLibrary *library)
return library->buffers();
}
const char *
std::string_view
liberty_port_direction(const LibertyPort *port)
{
return port->direction()->name();
@ -220,7 +221,7 @@ timing_role_is_check(const TimingRole *role)
////////////////////////////////////////////////////////////////
%extend LibertyLibrary {
const char *name() { return self->name(); }
const char *name() { return self->name().c_str(); }
LibertyCell *
find_liberty_cell(const char *name)
@ -264,7 +265,7 @@ default_operating_conditions()
} // LibertyLibrary methods
%extend LibertyCell {
const char *name() { return self->name(); }
const char *name() { return self->name().c_str(); }
bool is_leaf() { return self->isLeaf(); }
bool is_buffer() { return self->isBuffer(); }
bool is_inverter() { return self->isInverter(); }
@ -306,7 +307,8 @@ LibertyCell *test_cell() { return self->testCell(); }
} // LibertyCell methods
%extend LibertyPort {
const char *bus_name() { return self->busName(); }
const char *name() { return self->name().c_str(); }
std::string bus_name() { return self->busName(); }
Cell *cell() { return self->cell(); }
bool is_bus() { return self->isBus(); }
bool is_bus_bit() { return self->isBusBit(); }
@ -355,7 +357,7 @@ set_direction(const char *dir)
const char *
scan_signal_type()
{
return scanSignalTypeName(self->scanSignalType());
return scanSignalTypeName(self->scanSignalType()).c_str();
}
} // LibertyPort methods
@ -370,10 +372,10 @@ const char *sdf_cond() { return self->sdfCond().c_str(); }
std::string
full_name()
{
const char *from = self->from()->name();
const char *to = self->to()->name();
const char *cell_name = self->libertyCell()->name();
return sta::format("{} {} -> {}", cell_name, from, to);
return sta::format("{} {} -> {}",
self->libertyCell()->name(),
self->from()->name(),
self->to()->name());
}
const std::string
@ -395,9 +397,9 @@ timing_arcs() { return self->arcs(); }
LibertyPort *from() { return self->from(); }
LibertyPort *to() { return self->to(); }
const Transition *from_edge() { return self->fromEdge(); }
const char *from_edge_name() { return self->fromEdge()->asRiseFall()->name(); }
const char *from_edge_name() { return self->fromEdge()->asRiseFall()->name().c_str(); }
const Transition *to_edge() { return self->toEdge(); }
const char *to_edge_name() { return self->toEdge()->asRiseFall()->name(); }
const char *to_edge_name() { return self->toEdge()->asRiseFall()->name().c_str(); }
const TimingRole *role() { return self->role(); }
float

View File

@ -36,7 +36,7 @@
namespace sta {
LibertyBuilder::LibertyBuilder(Debug *debug,
Report *report) :
Report *report) :
debug_(debug),
report_(report)
{
@ -44,19 +44,19 @@ LibertyBuilder::LibertyBuilder(Debug *debug,
LibertyCell *
LibertyBuilder::makeCell(LibertyLibrary *library,
const char *name,
const char *filename)
std::string_view name,
std::string_view filename)
{
LibertyCell *cell = new LibertyCell(library, name, filename);
LibertyCell *cell = new LibertyCell(library, std::string(name), std::string(filename));
library->addCell(cell);
return cell;
}
LibertyPort *
LibertyBuilder::makePort(LibertyCell *cell,
const char *port_name)
std::string_view port_name)
{
LibertyPort *port = new LibertyPort(cell, port_name, false, nullptr,
LibertyPort *port = new LibertyPort(cell, std::string(port_name), false, nullptr,
-1, -1, false, nullptr);
cell->addPort(port);
return port;
@ -64,12 +64,12 @@ LibertyBuilder::makePort(LibertyCell *cell,
LibertyPort *
LibertyBuilder::makeBusPort(LibertyCell *cell,
const char *bus_name,
std::string_view bus_name,
int from_index,
int to_index,
BusDcl *bus_dcl)
{
LibertyPort *port = new LibertyPort(cell, bus_name, true, bus_dcl,
LibertyPort *port = new LibertyPort(cell, std::string(bus_name), true, bus_dcl,
from_index, to_index,
false, new ConcretePortSeq);
cell->addPort(port);
@ -81,7 +81,7 @@ void
LibertyBuilder::makeBusPortBits(ConcreteLibrary *library,
LibertyCell *cell,
ConcretePort *bus_port,
const char *bus_name,
std::string_view bus_name,
int from_index,
int to_index)
{
@ -99,22 +99,25 @@ void
LibertyBuilder::makeBusPortBit(ConcreteLibrary *library,
LibertyCell *cell,
ConcretePort *bus_port,
const char *bus_name,
std::string_view bus_name,
int bit_index)
{
std::string bit_name = std::string(bus_name) + library->busBrktLeft()
+ std::to_string(bit_index) + library->busBrktRight();
LibertyPort *port = makePort(cell, bit_name.c_str(), bit_index);
std::string bit_name;
bit_name.append(bus_name);
bit_name += library->busBrktLeft();
bit_name += std::to_string(bit_index);
bit_name += library->busBrktRight();
LibertyPort *port = makePort(cell, std::move(bit_name), bit_index);
bus_port->addPortBit(port);
cell->addPortBit(port);
}
LibertyPort *
LibertyBuilder::makePort(LibertyCell *cell,
const char *bit_name,
std::string bit_name,
int bit_index)
{
LibertyPort *port = new LibertyPort(cell, bit_name, false, nullptr,
LibertyPort *port = new LibertyPort(cell, std::move(bit_name), false, nullptr,
bit_index, bit_index, false, nullptr);
return port;
}

View File

@ -24,6 +24,9 @@
#pragma once
#include <string>
#include <string_view>
#include "MinMax.hh"
#include "Transition.hh"
#include "LibertyClass.hh"
@ -41,12 +44,12 @@ public:
LibertyBuilder(Debug *debug,
Report *report);
LibertyCell *makeCell(LibertyLibrary *library,
const char *name,
const char *filename);
std::string_view name,
std::string_view filename);
LibertyPort *makePort(LibertyCell *cell,
const char *name);
std::string_view name);
LibertyPort *makeBusPort(LibertyCell *cell,
const char *bus_name,
std::string_view bus_name,
int from_index,
int to_index,
BusDcl *bus_dcl);
@ -87,24 +90,24 @@ public:
TimingArcAttrsPtr attrs);
protected:
ConcretePort *makeBusPort(const char *name,
ConcretePort *makeBusPort(std::string_view name,
int from_index,
int to_index,
ConcretePortSeq *members);
void makeBusPortBits(ConcreteLibrary *library,
LibertyCell *cell,
ConcretePort *bus_port,
const char *bus_name,
std::string_view bus_name,
int from_index,
int to_index);
// Bus port bit (internal to makeBusPortBits).
LibertyPort *makePort(LibertyCell *cell,
const char *bit_name,
std::string bit_name,
int bit_index);
void makeBusPortBit(ConcreteLibrary *library,
LibertyCell *cell,
ConcretePort *bus_port,
const char *bus_name,
std::string_view bus_name,
int index);
TimingArc *makeTimingArc(TimingArcSet *set,
const Transition *from_rf,

View File

@ -28,6 +28,7 @@
// * a string attribute named "thingy" is parsed
#include <stdio.h>
#include <string>
#include "Machine.hh"
#include "StringUtil.hh"
#include "LibertyReader.hh"
@ -162,15 +163,17 @@ BigcoTimingArcSet::BigcoTimingArcSet(LibertyCell *cell, LibertyPort *from,
class BigcoLibertyBuilder : public LibertyBuilder
{
public:
virtual LibertyCell *makeCell(LibertyLibrary *library, const char *name,
const char *filename);
virtual LibertyCell *makeCell(LibertyLibrary *library, std::string_view name,
std::string_view filename);
};
LibertyCell *
BigcoLibertyBuilder::makeCell(LibertyLibrary *library, const char *name,
const char *filename)
BigcoLibertyBuilder::makeCell(LibertyLibrary *library, std::string_view name,
std::string_view filename)
{
LibertyCell *cell = new BigcoCell(library, name, filename);
std::string name_str(name);
std::string filename_str(filename);
LibertyCell *cell = new BigcoCell(library, name_str.c_str(), filename_str.c_str());
library->addCell(cell);
return cell;
}
@ -210,9 +213,8 @@ void
BigcoLibertyReader::beginCell(const LibertyGroup *group,
const LibertyGroup *library_group)
{
const char *name = group->firstName();
if (name
&& libertyCellRequired(name))
if (group->hasFirstParam()
&& libertyCellRequired(group->firstParam().c_str()))
LibertyReader::beginCell(group, library_group);
}
@ -263,7 +265,7 @@ public:
BigcoSta();
protected:
virtual LibertyLibrary *readLibertyFile(const char *filename,
virtual LibertyLibrary *readLibertyFile(std::string_view filename,
bool infer_latches,
Network *network);
};
@ -275,7 +277,7 @@ BigcoSta::BigcoSta() :
// Replace Sta liberty file reader with Bigco's very own.
LibertyLibrary *
Sta::readLibertyFile(const char *filename,
Sta::readLibertyFile(std::string_view filename,
bool infer_latches,
Network *network)
{

View File

@ -44,7 +44,7 @@ void
sta::LibertyParse::error(const location_type &loc,
const std::string &msg)
{
reader->report()->fileError(164, reader->filename().c_str(),
reader->report()->fileError(164, reader->filename(),
loc.begin.line, "{}", msg);
}
@ -192,7 +192,7 @@ volt_op:
expr:
expr_term1
| expr_term1 expr_op expr
{ $$ = sta::format("{}{}{}", $1.c_str(), $2, $3.c_str()); }
{ $$ = sta::format("{}{}{}", $1, $2, $3); }
;
expr_term:

View File

@ -27,6 +27,7 @@
#include <cstdio>
#include <cstring>
#include <regex>
#include <string>
#include "ContainerHelpers.hh"
#include "Zlib.hh"
@ -38,11 +39,12 @@
namespace sta {
void
parseLibertyFile(const char *filename,
parseLibertyFile(std::string_view filename,
LibertyGroupVisitor *library_visitor,
Report *report)
{
gzstream::igzstream stream(filename);
std::string fn(filename);
gzstream::igzstream stream(fn.c_str());
if (stream.is_open()) {
LibertyParser reader(filename, library_visitor, report);
LibertyScanner scanner(&stream, filename, &reader, report);
@ -53,7 +55,7 @@ parseLibertyFile(const char *filename,
throw FileNotReadable(filename);
}
LibertyParser::LibertyParser(const char *filename,
LibertyParser::LibertyParser(std::string_view filename,
LibertyGroupVisitor *library_visitor,
Report *report) :
filename_(filename),
@ -63,7 +65,7 @@ LibertyParser::LibertyParser(const char *filename,
}
void
LibertyParser::setFilename(const std::string &filename)
LibertyParser::setFilename(std::string_view filename)
{
filename_ = filename;
}
@ -74,12 +76,12 @@ LibertyParser::makeDefine(const LibertyAttrValueSeq *values,
{
LibertyDefine *define = nullptr;
if (values->size() == 3) {
const std::string &define_name = (*values)[0]->stringValue();
std::string &define_name = (*values)[0]->stringValue();
const std::string &group_type_name = (*values)[1]->stringValue();
const std::string &value_type_name = (*values)[2]->stringValue();
LibertyAttrType value_type = attrValueType(value_type_name);
LibertyGroupType group_type = groupType(group_type_name);
define = new LibertyDefine(define_name, group_type, value_type, line);
define = new LibertyDefine(std::move(define_name), group_type, value_type, line);
LibertyGroup *group = this->group();
group->addDefine(define);
for (auto value : *values)
@ -87,7 +89,7 @@ LibertyParser::makeDefine(const LibertyAttrValueSeq *values,
delete values;
}
else
report_->fileWarn(24, filename_.c_str(), line,
report_->fileWarn(24, filename_, line,
"define does not have three arguments.");
return define;
}
@ -126,12 +128,15 @@ LibertyParser::groupType(const std::string &group_type_name)
}
void
LibertyParser::groupBegin(const std::string type,
LibertyParser::groupBegin(std::string &&type,
LibertyAttrValueSeq *params,
int line)
{
LibertyGroup *group = new LibertyGroup(
std::move(type), params ? std::move(*params) : LibertyAttrValueSeq(), line);
LibertyGroup *group = new LibertyGroup(std::move(type),
params
? std::move(*params)
: LibertyAttrValueSeq(),
line);
delete params;
LibertyGroup *parent_group = group_stack_.empty() ? nullptr : group_stack_.back();
group_visitor_->begin(group, parent_group);
@ -163,12 +168,11 @@ LibertyParser::deleteGroups()
}
LibertySimpleAttr *
LibertyParser::makeSimpleAttr(const std::string name,
LibertyParser::makeSimpleAttr(std::string &&name,
const LibertyAttrValue *value,
int line)
{
LibertySimpleAttr *attr =
new LibertySimpleAttr(name, *value, line);
LibertySimpleAttr *attr = new LibertySimpleAttr(std::move(name), *value, line);
delete value;
LibertyGroup *group = this->group();
group->addAttr(attr);
@ -177,7 +181,7 @@ LibertyParser::makeSimpleAttr(const std::string name,
}
LibertyComplexAttr *
LibertyParser::makeComplexAttr(const std::string name,
LibertyParser::makeComplexAttr(std::string &&name,
const LibertyAttrValueSeq *values,
int line)
{
@ -188,8 +192,7 @@ LibertyParser::makeComplexAttr(const std::string name,
return nullptr; // Define is not a complex attr; already added to group
}
else {
LibertyComplexAttr *attr =
new LibertyComplexAttr(name, *values, line);
LibertyComplexAttr *attr = new LibertyComplexAttr(std::move(name), *values, line);
delete values;
LibertyGroup *group = this->group();
group->addAttr(attr);
@ -199,7 +202,7 @@ LibertyParser::makeComplexAttr(const std::string name,
}
LibertyVariable *
LibertyParser::makeVariable(const std::string var,
LibertyParser::makeVariable(std::string &&var,
float value,
int line)
{
@ -211,7 +214,7 @@ LibertyParser::makeVariable(const std::string var,
}
LibertyAttrValue *
LibertyParser::makeAttrValueString(std::string value)
LibertyParser::makeAttrValueString(std::string &&value)
{
return new LibertyAttrValue(std::move(value));
}
@ -225,7 +228,7 @@ LibertyParser::makeAttrValueFloat(float value)
////////////////////////////////////////////////////////////////
LibertyScanner::LibertyScanner(std::istream *stream,
const char *filename,
std::string_view filename,
LibertyParser *reader,
Report *report) :
yyFlexLexer(stream),
@ -261,7 +264,7 @@ LibertyScanner::includeBegin()
return true;
}
else {
report_->fileWarn(25, filename_.c_str(), yylineno,
report_->fileWarn(25, filename_, yylineno,
"cannot open include file {}.", filename);
delete stream;
}
@ -287,7 +290,7 @@ LibertyScanner::fileEnd()
void
LibertyScanner::error(const char *msg)
{
report_->fileError(1866, filename_.c_str(), lineno(), "{}", msg);
report_->fileError(1866, filename_, lineno(), "{}", msg);
}
////////////////////////////////////////////////////////////////
@ -366,9 +369,9 @@ void
LibertyGroup::addAttr(LibertySimpleAttr *attr)
{
// Only keep the most recent simple attribute value.
const auto &itr = simple_attr_map_.find(attr->name());
if (itr != simple_attr_map_.end())
delete itr->second;
const auto &it = simple_attr_map_.find(attr->name());
if (it != simple_attr_map_.end())
delete it->second;
simple_attr_map_[attr->name()] = attr;
}
@ -384,37 +387,46 @@ LibertyGroup::addVariable(LibertyVariable *var)
variables_.push_back(var);
}
const char *
LibertyGroup::firstName() const
bool
LibertyGroup::hasFirstParam() const
{
if (params_.size() >= 1) {
LibertyAttrValue *value = params_[0];
if (value->isString())
return value->stringValue().c_str();
}
return nullptr;
return !params_.empty();
}
const char *
LibertyGroup::secondName() const
const std::string &
LibertyGroup::firstParam() const
{
LibertyAttrValue *value = params_[0];
return value->stringValue();
}
bool
LibertyGroup::hasSecondParam() const
{
return params_.size() >= 2;
}
const std::string &
LibertyGroup::secondParam() const
{
LibertyAttrValue *value = params_[1];
if (value->isString())
return value->stringValue().c_str();
else
return nullptr;
return value->stringValue();
}
const LibertyGroupSeq &
LibertyGroup::findSubgroups(const std::string type) const
LibertyGroup::findSubgroups(std::string_view type) const
{
return findKeyValue(subgroup_map_, type);
auto it = subgroup_map_.find(type);
if (it != subgroup_map_.end())
return it->second;
static const LibertyGroupSeq empty;
return empty;
}
const LibertyGroup *
LibertyGroup::findSubgroup(const std::string type) const
LibertyGroup::findSubgroup(std::string_view type) const
{
const LibertyGroupSeq groups = findKeyValue(subgroup_map_, type);
const LibertyGroupSeq &groups = findSubgroups(type);
if (groups.size() >= 1)
return groups[0];
else
@ -422,39 +434,43 @@ LibertyGroup::findSubgroup(const std::string type) const
}
const LibertySimpleAttr *
LibertyGroup::findSimpleAttr(const std::string attr_name) const
LibertyGroup::findSimpleAttr(std::string_view attr_name) const
{
return findKeyValue(simple_attr_map_, attr_name);
return findStringKey(simple_attr_map_, attr_name);
}
const LibertyComplexAttrSeq &
LibertyGroup::findComplexAttrs(const std::string attr_name) const
LibertyGroup::findComplexAttrs(std::string_view attr_name) const
{
return findKeyValue(complex_attr_map_, attr_name);
auto it = complex_attr_map_.find(attr_name);
if (it != complex_attr_map_.end())
return it->second;
static const LibertyComplexAttrSeq empty;
return empty;
}
const LibertyComplexAttr *
LibertyGroup::findComplexAttr(const std::string attr_name) const
LibertyGroup::findComplexAttr(std::string_view attr_name) const
{
const LibertyComplexAttrSeq attrs = findKeyValue(complex_attr_map_, attr_name);
const LibertyComplexAttrSeq &attrs = findComplexAttrs(attr_name);
if (attrs.size() >= 1)
return attrs[0];
else
return nullptr;
}
const std::string *
LibertyGroup::findAttrString(const std::string attr_name) const
const std::string &
LibertyGroup::findAttrString(std::string_view attr_name) const
{
const LibertySimpleAttr *attr = findSimpleAttr(attr_name);
if (attr)
return &attr->value().stringValue();
else
return nullptr;
return attr->value().stringValue();
static const std::string null_string;
return null_string;
}
void
LibertyGroup::findAttrFloat(const std::string attr_name,
LibertyGroup::findAttrFloat(std::string_view attr_name,
// Return values.
float &value,
bool &exists) const
@ -463,26 +479,25 @@ LibertyGroup::findAttrFloat(const std::string attr_name,
if (attr) {
const LibertyAttrValue &attr_value = attr->value();
if (attr_value.isFloat()) {
value = attr_value.floatValue();
exists = true;
auto [value1, exists1] = attr_value.floatValue();
value = value1;
exists = exists1;
return;
}
else {
// Possibly quoted string float.
const std::string &float_str = attr_value.stringValue();
char *end = nullptr;
value = std::strtof(float_str.c_str(), &end);
if (end) {
exists = true;
return;
}
auto [value1, valid1] = stringFloat(float_str);
value = value1;
exists = valid1;
return;
}
}
exists = false;
}
void
LibertyGroup::findAttrInt(const std::string attr_name,
LibertyGroup::findAttrInt(std::string_view attr_name,
// Return values.
int &value,
bool &exists) const
@ -491,8 +506,9 @@ LibertyGroup::findAttrInt(const std::string attr_name,
if (attr) {
const LibertyAttrValue &attr_value = attr->value();
if (attr_value.isFloat()) {
value = static_cast<int>(attr_value.floatValue());
exists = true;
auto [value1, exists1] = attr_value.floatValue();
value = static_cast<int>(value1);
exists = exists1;
return;
}
}
@ -501,7 +517,7 @@ LibertyGroup::findAttrInt(const std::string attr_name,
////////////////////////////////////////////////////////////////
LibertySimpleAttr::LibertySimpleAttr(const std::string name,
LibertySimpleAttr::LibertySimpleAttr(std::string &&name,
const LibertyAttrValue value,
int line) :
name_(std::move(name)),
@ -510,15 +526,9 @@ LibertySimpleAttr::LibertySimpleAttr(const std::string name,
{
}
const std::string *
LibertySimpleAttr::stringValue() const
{
return &value().stringValue();
}
////////////////////////////////////////////////////////////////
LibertyComplexAttr::LibertyComplexAttr(std::string name,
LibertyComplexAttr::LibertyComplexAttr(std::string &&name,
const LibertyAttrValueSeq values,
int line) :
name_(std::move(name)),
@ -540,7 +550,7 @@ LibertyComplexAttr::firstValue() const
////////////////////////////////////////////////////////////////
LibertyAttrValue::LibertyAttrValue(std::string value) :
LibertyAttrValue::LibertyAttrValue(std::string &&value) :
string_value_(std::move(value))
{
}
@ -562,39 +572,18 @@ LibertyAttrValue::isString() const
return !string_value_.empty();
}
float
std::pair<float, bool>
LibertyAttrValue::floatValue() const
{
if (!string_value_.empty())
criticalError(1127, "LibertyAttrValue::floatValue() called on string");
return float_value_;
}
void
LibertyAttrValue::floatValue( // Return values.
float &value,
bool &valid) const
{
valid = false;
if (string_value_.empty()) {
value = float_value_;
valid = true;
}
else {
// Some floats are enclosed in quotes.
char *end;
value = strtof(string_value_.c_str(), &end);
if ((*end == '\0' || isspace(*end))
// strtof support INF as a valid float.
&& string_value_ != "inf") {
valid = true;
}
}
if (string_value_.empty())
return {float_value_, true};
else
return stringFloat(string_value_);
}
////////////////////////////////////////////////////////////////
LibertyDefine::LibertyDefine(std::string name,
LibertyDefine::LibertyDefine(std::string &&name,
LibertyGroupType group_type,
LibertyAttrType value_type,
int line) :

View File

@ -24,8 +24,11 @@
#pragma once
#include <functional>
#include <string_view>
#include <vector>
#include <map>
#include <utility>
#include "Zlib.hh"
#include "StringUtil.hh"
@ -43,15 +46,15 @@ class LibertyVariable;
class LibertyScanner;
using LibertyGroupSeq = std::vector<LibertyGroup*>;
using LibertySubGroupMap = std::map<std::string, LibertyGroupSeq>;
using LibertySimpleAttrMap = std::map<std::string, LibertySimpleAttr*>;
using LibertySubGroupMap = std::map<std::string, LibertyGroupSeq, std::less<>>;
using LibertySimpleAttrMap = std::map<std::string, LibertySimpleAttr*, std::less<>>;
using LibertyComplexAttrSeq = std::vector<LibertyComplexAttr*>;
using LibertyComplexAttrMap = std::map<std::string, LibertyComplexAttrSeq>;
using LibertyDefineMap = std::map<std::string, LibertyDefine*>;
using LibertyComplexAttrMap = std::map<std::string, LibertyComplexAttrSeq, std::less<>>;
using LibertyDefineMap = std::map<std::string, LibertyDefine*, std::less<>>;
using LibertyAttrValueSeq = std::vector<LibertyAttrValue*>;
using LibertyVariableSeq = std::vector<LibertyVariable*>;
using LibertyVariableMap = std::map<std::string, float>;
using LibertyGroupVisitorMap = std::map<std::string, LibertyGroupVisitor*>;
using LibertyVariableMap = std::map<std::string, float, std::less<>>;
using LibertyGroupVisitorMap = std::map<std::string, LibertyGroupVisitor*, std::less<>>;
enum class LibertyAttrType { attr_string, attr_int, attr_double,
attr_boolean, attr_unknown };
@ -61,31 +64,31 @@ enum class LibertyGroupType { library, cell, pin, timing, unknown };
class LibertyParser
{
public:
LibertyParser(const char *filename,
LibertyParser(std::string_view filename,
LibertyGroupVisitor *library_visitor,
Report *report);
const std::string &filename() const { return filename_; }
void setFilename(const std::string &filename);
void setFilename(std::string_view filename);
Report *report() const { return report_; }
LibertyDefine *makeDefine(const LibertyAttrValueSeq *values,
int line);
LibertyAttrType attrValueType(const std::string &value_type_name);
LibertyGroupType groupType(const std::string &group_type_name);
void groupBegin(const std::string type,
void groupBegin(std::string &&type,
LibertyAttrValueSeq *params,
int line);
LibertyGroup *groupEnd();
LibertyGroup *group();
void deleteGroups();
LibertySimpleAttr *makeSimpleAttr(const std::string name,
LibertySimpleAttr *makeSimpleAttr(std::string &&name,
const LibertyAttrValue *value,
int line);
LibertyComplexAttr *makeComplexAttr(const std::string name,
LibertyComplexAttr *makeComplexAttr(std::string &&name,
const LibertyAttrValueSeq *values,
int line);
LibertyAttrValue *makeAttrValueString(const std::string value);
LibertyAttrValue *makeAttrValueString(std::string &&value);
LibertyAttrValue *makeAttrValueFloat(float value);
LibertyVariable *makeVariable(const std::string var,
LibertyVariable *makeVariable(std::string &&var,
float value,
int line);
@ -102,14 +105,12 @@ class LibertyAttrValue
public:
LibertyAttrValue() {}
LibertyAttrValue(float value);
LibertyAttrValue(std::string value);
LibertyAttrValue(std::string &&value);
bool isString() const;
bool isFloat() const;
float floatValue() const;
void floatValue(// Return values.
float &value,
bool &valid) const;
std::pair<float, bool> floatValue() const;
const std::string &stringValue() const { return string_value_; }
std::string &stringValue() { return string_value_; }
private:
float float_value_;
@ -131,23 +132,23 @@ public:
bool oneGroupOnly() const;
const std::string &type() const { return type_; }
const LibertyAttrValueSeq &params() const { return params_; }
// First param as a string.
const char *firstName() const;
// Second param as a string.
const char *secondName() const;
bool hasFirstParam() const;
const std::string &firstParam() const;
bool hasSecondParam() const;
const std::string &secondParam() const;
int line() const { return line_; }
const LibertyGroupSeq &findSubgroups(const std::string type) const;
const LibertyGroup *findSubgroup(const std::string type) const;
const LibertySimpleAttr *findSimpleAttr(const std::string attr_name) const;
const LibertyComplexAttrSeq &findComplexAttrs(const std::string attr_name) const;
const LibertyComplexAttr *findComplexAttr(const std::string attr_name) const;
const std::string *findAttrString(const std::string attr_name) const;
void findAttrFloat(const std::string attr_name,
const LibertyGroupSeq &findSubgroups(std::string_view type) const;
const LibertyGroup *findSubgroup(std::string_view type) const;
const LibertySimpleAttr *findSimpleAttr(std::string_view attr_name) const;
const LibertyComplexAttrSeq &findComplexAttrs(std::string_view attr_name) const;
const LibertyComplexAttr *findComplexAttr(std::string_view attr_name) const;
const std::string &findAttrString(std::string_view attr_name) const;
void findAttrFloat(std::string_view attr_name,
// Return values.
float &value,
bool &exists) const;
void findAttrInt(const std::string attr_name,
void findAttrInt(std::string_view attr_name,
// Return values.
int &value,
bool &exists) const;
@ -189,12 +190,12 @@ public:
class LibertySimpleAttr
{
public:
LibertySimpleAttr(const std::string name,
LibertySimpleAttr(std::string &&name,
const LibertyAttrValue value,
int line);
const std::string &name() const { return name_; }
const LibertyAttrValue &value() const { return value_; };
const std::string *stringValue() const;
const std::string &stringValue() const { return value_.stringValue(); }
int line() const { return line_; }
private:
@ -208,7 +209,7 @@ private:
class LibertyComplexAttr
{
public:
LibertyComplexAttr(const std::string name,
LibertyComplexAttr(std::string &&name,
const LibertyAttrValueSeq values,
int line);
~LibertyComplexAttr();
@ -229,7 +230,7 @@ private:
class LibertyDefine
{
public:
LibertyDefine(std::string name,
LibertyDefine(std::string &&name,
LibertyGroupType group_type,
LibertyAttrType value_type,
int line);
@ -280,7 +281,7 @@ public:
};
void
parseLibertyFile(const char *filename,
parseLibertyFile(std::string_view filename,
LibertyGroupVisitor *library_visitor,
Report *report);
} // namespace

File diff suppressed because it is too large Load Diff

View File

@ -24,13 +24,15 @@
#pragma once
#include <string_view>
namespace sta {
class Network;
class LibertyLibrary;
LibertyLibrary *
readLibertyFile(const char *filename,
readLibertyFile(std::string_view filename,
bool infer_latches,
Network *network);

View File

@ -28,6 +28,7 @@
#include <functional>
#include <memory>
#include <array>
#include <string>
#include <string_view>
#include <vector>
#include <unordered_map>
@ -65,10 +66,10 @@ using OutputWaveformSeq = std::vector<OutputWaveform>;
class LibertyReader : public LibertyGroupVisitor
{
public:
LibertyReader(const char *filename,
LibertyReader(std::string_view filename,
bool infer_latches,
Network *network);
virtual LibertyLibrary *readLibertyFile(const char *filename);
virtual LibertyLibrary *readLibertyFile(std::string_view filename);
LibertyLibrary *library() { return library_; }
const LibertyLibrary *library() const { return library_; }
@ -90,7 +91,7 @@ public:
void checkScaledCell(LibertyCell *scaled_cell,
LibertyCell *owner,
const LibertyGroup *scaled_cell_group,
const char *op_cond_name);
std::string_view op_cond_name);
void setPortCapDefault(LibertyPort *port);
void checkLatchEnableSense(FuncExpr *enable_func,
@ -102,9 +103,9 @@ public:
float scale);
LibertyPort *findPort(LibertyCell *cell,
const char *port_name);
std::string_view port_name);
StringSeq findAttributStrings(const LibertyGroup *group,
const char *name_attr);
std::string_view name_attr);
protected:
virtual void begin(const LibertyGroup *group,
@ -113,7 +114,7 @@ protected:
LibertyGroup *library_group);
// Library gruops.
void makeLibrary(const LibertyGroup *libary_group);
void makeLibrary(const LibertyGroup *library_group);
void readLibraryAttributes(const LibertyGroup *library_group);
void readLibraryUnits(const LibertyGroup *library_group);
void readDelayModel(const LibertyGroup *library_group);
@ -122,8 +123,8 @@ protected:
void readDefaultWireLoadMode(const LibertyGroup *library_group);
void readTechnology(const LibertyGroup *library_group);
void readDefaultWireLoadSelection(const LibertyGroup *library_group);
void readUnit(const char *unit_attr_name,
const char *unit_suffix,
void readUnit(std::string_view unit_attr_name,
std::string_view unit_suffix,
float &scale_var,
Unit *unit,
const LibertyGroup *library_group);
@ -131,7 +132,7 @@ protected:
const LibertyGroup *type_group);
void readTableTemplates(const LibertyGroup *library_group);
void readTableTemplates(const LibertyGroup *library_group,
const char *group_name,
std::string_view group_name,
TableTemplateType type);
void readThresholds(const LibertyGroup *library_group);
void checkThresholds(const LibertyGroup *library_group) const;
@ -150,17 +151,17 @@ protected:
void readNormalizedDriverWaveform(const LibertyGroup *library_group);
void readSlewDegradations(const LibertyGroup *library_group);
void readLibAttrFloat(const LibertyGroup *library_group,
const char *attr_name,
std::string_view attr_name,
void (LibertyLibrary::*set_func)(float value),
float scale);
void readLibAttrFloat(const LibertyGroup *library_group,
const char *attr_name,
std::string_view attr_name,
void (LibertyLibrary::*set_func)(const RiseFall *rf,
float value),
const RiseFall *rf,
float scale);
void readLibAttrFloatWarnZero(const LibertyGroup *library_group,
const char *attr_name,
std::string_view attr_name,
void (LibertyLibrary::*set_func)(float value),
float scale);
@ -188,9 +189,9 @@ protected:
void makePgPinPort(LibertyCell *cell,
const LibertyGroup *pg_pin_group);
LibertyPort *makePort(LibertyCell *cell,
const char *port_name);
std::string_view port_name);
LibertyPort *makeBusPort(LibertyCell *cell,
const char *bus_name,
std::string_view bus_name,
int from_index,
int to_index,
BusDcl *bus_dcl);
@ -198,22 +199,27 @@ protected:
void readPortAttributes(LibertyCell *cell,
const LibertyPortSeq &ports,
const LibertyGroup *port_group);
void readPortAttrString(const char *attr_name,
void (LibertyPort::*set_func)(const char *value),
void readPortAttrString(std::string_view attr_name,
void (LibertyPort::*set_func)(std::string value),
const LibertyPortSeq &ports,
const LibertyGroup *group);
void readPortAttrFloat(const char *attr_name,
void readPortAttrLibertyPort(std::string_view attr_name,
void (LibertyPort::*set_func)(LibertyPort *port),
LibertyCell *cell,
const LibertyPortSeq &ports,
const LibertyGroup *group);
void readPortAttrFloat(std::string_view attr_name,
void (LibertyPort::*set_func)(float value),
const LibertyPortSeq &ports,
const LibertyGroup *group,
float scale);
void readPortAttrBool(const char *attr_name,
void readPortAttrBool(std::string_view attr_name,
void (LibertyPort::*set_func)(bool value),
const LibertyPortSeq &ports,
const LibertyGroup *group);
void readDriverWaveform(const LibertyPortSeq &ports,
const LibertyGroup *port_group);
void readPortAttrFloatMinMax(const char *attr_name,
void readPortAttrFloatMinMax(std::string_view attr_name,
void (LibertyPort::*set_func)(float value,
const MinMax *min_max),
const LibertyPortSeq &ports,
@ -243,7 +249,7 @@ protected:
const std::function<bool(TableModel *model)> check_axes);
TableModelsEarlyLate
readEarlyLateTableModels(const LibertyGroup *timing_group,
const char *table_group_name,
std::string_view table_group_name,
const RiseFall *rf,
TableTemplateType template_type,
float scale,
@ -252,7 +258,7 @@ protected:
ReceiverModelPtr readReceiverCapacitance(const LibertyGroup *timing_group,
const RiseFall *rf);
void readReceiverCapacitance(const LibertyGroup *timing_group,
const char *cap_group_name,
std::string_view cap_group_name,
int index,
const RiseFall *rf,
ReceiverModelPtr &receiver_model);
@ -291,9 +297,9 @@ protected:
const std::function<bool(TableModel *model)> check_axes);
TableAxisPtr makeTableAxis(const LibertyGroup *table_group,
const char *index_attr_name,
std::string_view index_attr_name,
TableAxisPtr template_axis);
void readGroupAttrFloat(const char *attr_name,
void readGroupAttrFloat(std::string_view attr_name,
const LibertyGroup *group,
const std::function<void(float)> &set_func,
float scale = 1.0F);
@ -318,12 +324,12 @@ protected:
void makeSequentials(LibertyCell *cell,
const LibertyGroup *cell_group,
bool is_register,
const char *seq_group_name,
const char *clk_attr_name,
const char *data_attr_name);
std::string_view seq_group_name,
std::string_view clk_attr_name,
std::string_view data_attr_name);
FuncExpr *makeSeqFunc(LibertyCell *cell,
const LibertyGroup *seq_group,
const char *attr_name,
std::string_view attr_name,
int size);
void makeSeqPorts(LibertyCell *cell,
const LibertyGroup *seq_group,
@ -332,8 +338,9 @@ protected:
LibertyPort *&out_port_inv,
size_t &size);
void seqPortNames(const LibertyGroup *group,
const char *&out_name,
const char *&out_inv_name,
// Return values.
std::string &out_name,
std::string &out_inv_name,
bool &has_size,
size_t &size);
TimingModel *makeScalarCheckModel(LibertyCell *cell,
@ -367,17 +374,17 @@ protected:
const LibertyGroup *cell_group);
void readScaleFactors(LibertyCell *cell,
const LibertyGroup *cell_group);
void readCellAttrString(const char *attr_name,
void (LibertyCell::*set_func)(const char *value),
void readCellAttrString(std::string_view attr_name,
void (LibertyCell::*set_func)(std::string value),
LibertyCell *cell,
const LibertyGroup *group);
void readCellAttrFloat(const char *attr_name,
void readCellAttrFloat(std::string_view attr_name,
void (LibertyCell::*set_func)(float value),
LibertyCell *cell,
const LibertyGroup *group,
float scale);
void readCellAttrBool(const char *attr_name,
void (LibertyCell::*set_func)(bool value),
void readCellAttrBool(std::string_view attr_name,
void (LibertyCell::*set_func)(bool value),
LibertyCell *cell,
const LibertyGroup *group);
void readLevelShifterType(LibertyCell *cell,
@ -393,18 +400,18 @@ protected:
FuncExpr *readFuncExpr(LibertyCell *cell,
const LibertyGroup *group,
const char *attr_name);
std::string_view attr_name);
LibertyPort *findLibertyPort(LibertyCell *cell,
const LibertyGroup *group,
const char *port_name_attr);
std::string_view port_name_attr);
LibertyPortSeq findLibertyPorts(LibertyCell *cell,
const LibertyGroup *group,
const char *port_name_attr);
std::string_view port_name_attr);
float energyScale();
void defineVisitors();
void defineGroupVisitor(const char *type,
void defineGroupVisitor(std::string_view type,
LibraryGroupVisitor begin_visitor,
LibraryGroupVisitor end_visitor);
@ -436,52 +443,49 @@ protected:
bool &exists);
const EarlyLateAll *getAttrEarlyLate(const LibertySimpleAttr *attr);
FloatSeq parseStringFloatList(const std::string &float_list,
float scale,
const LibertySimpleAttr *attr);
FloatSeq parseStringFloatList(const std::string &float_list,
float scale,
const LibertyComplexAttr *attr);
FloatSeq parseFloatList(const std::string &float_list,
float scale,
int line);
TableAxisPtr makeAxis(int index,
const LibertyGroup *group);
FloatSeq readFloatSeq(const LibertyComplexAttr *attr,
float scale);
void variableValue(const char *var,
void variableValue(std::string_view var,
float &value,
bool &exists);
FuncExpr *parseFunc(const char *func,
const char *attr_name,
FuncExpr *parseFunc(std::string_view func,
std::string_view attr_name,
const LibertyCell *cell,
int line);
template <typename... Args>
void warn(int id,
const LibertyGroup *group,
std::string_view fmt,
Args &&...args) const
const LibertyGroup *group,
std::string_view fmt,
Args &&...args) const
{
report_->fileWarn(id, filename_, group->line(), fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void warn(int id,
const LibertySimpleAttr *attr,
std::string_view fmt,
Args &&...args) const
const LibertySimpleAttr *attr,
std::string_view fmt,
Args &&...args) const
{
report_->fileWarn(id, filename_, attr->line(), fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void warn(int id,
const LibertyComplexAttr *attr,
std::string_view fmt,
Args &&...args) const
const LibertyComplexAttr *attr,
std::string_view fmt,
Args &&...args) const
{
report_->fileWarn(id, filename_, attr->line(), fmt, std::forward<Args>(args)...);
}
template <typename... Args>
void warn(int id,
int line,
std::string_view fmt,
Args &&...args) const
int line,
std::string_view fmt,
Args &&...args) const
{
report_->fileWarn(id, filename_, line, fmt, std::forward<Args>(args)...);
}
@ -513,7 +517,7 @@ protected:
std::forward<Args>(args)...);
}
const char *filename_;
std::string_view filename_;
bool infer_latches_;
Report *report_;
Debug *debug_;
@ -547,7 +551,7 @@ class PortNameBitIterator : public Iterator<LibertyPort*>
{
public:
PortNameBitIterator(LibertyCell *cell,
const char *port_name,
std::string_view port_name,
LibertyReader *visitor,
int line);
~PortNameBitIterator();
@ -558,7 +562,7 @@ public:
protected:
void findRangeBusNameNext();
void init(const char *port_name);
void init(std::string_view port_name);
LibertyCell *cell_;
LibertyReader *visitor_;
int line_;

View File

@ -24,8 +24,9 @@
#pragma once
#include <string>
#include <istream>
#include <string>
#include <string_view>
#include "LibertyParse.hh"
@ -44,7 +45,7 @@ class LibertyScanner : public LibertyFlexLexer
{
public:
LibertyScanner(std::istream *stream,
const char *filename,
std::string_view filename,
LibertyParser *reader,
Report *report);
virtual ~LibertyScanner() {}

View File

@ -298,11 +298,11 @@ LibertyWriter::writeCell(const LibertyCell *cell)
sta::print(stream_, " is_macro_cell : true;\n");
if (cell->interfaceTiming())
sta::print(stream_, " interface_timing : true;\n");
const char *footprint = cell->footprint();
if (footprint)
const std::string &footprint = cell->footprint();
if (!footprint.empty())
sta::print(stream_, " cell_footprint : \"{}\";\n", footprint);
const char *user_function_class = cell->userFunctionClass();
if (user_function_class)
const std::string &user_function_class = cell->userFunctionClass();
if (!user_function_class.empty())
sta::print(stream_, " user_function_class : \"{}\";\n", user_function_class);
LibertyCellPortIterator port_iter(cell);

View File

@ -119,7 +119,7 @@ CheckLinearModel::checkDelay(const Pvt *,
std::string
CheckLinearModel::reportCheckDelay(const Pvt *,
float,
const char *,
std::string_view,
float,
float,
const MinMax *,

View File

@ -242,7 +242,7 @@ GateTableModel::reportGateDelay(const Pvt *pvt,
}
std::string
GateTableModel::reportTableLookup(const char *result_name,
GateTableModel::reportTableLookup(std::string_view result_name,
const Pvt *pvt,
const TableModel *model,
float in_slew,
@ -255,7 +255,7 @@ GateTableModel::reportTableLookup(const char *result_name,
findAxisValues(model, in_slew, load_cap, related_out_cap, axis_value1,
axis_value2, axis_value3);
const LibertyLibrary *library = cell_->libertyLibrary();
return model->reportValue(result_name, cell_, pvt, axis_value1, nullptr,
return model->reportValue(result_name, cell_, pvt, axis_value1, {},
axis_value2, axis_value3, library->units()->timeUnit(),
digits);
}
@ -538,7 +538,7 @@ CheckTableModel::findValue(const Pvt *pvt,
std::string
CheckTableModel::reportCheckDelay(const Pvt *pvt,
float from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
float to_slew,
float related_out_cap,
const MinMax *min_max,
@ -567,11 +567,11 @@ CheckTableModel::reportCheckDelay(const Pvt *pvt,
}
std::string
CheckTableModel::reportTableDelay(const char *result_name,
CheckTableModel::reportTableDelay(std::string_view result_name,
const Pvt *pvt,
const TableModel *model,
float from_slew,
const char *from_slew_annotation,
std::string_view from_slew_annotation,
float to_slew,
float related_out_cap,
int digits) const
@ -852,11 +852,11 @@ TableModel::scaleFactor(const LibertyCell *cell,
}
std::string
TableModel::reportValue(const char *result_name,
TableModel::reportValue(std::string_view result_name,
const LibertyCell *cell,
const Pvt *pvt,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -868,7 +868,7 @@ TableModel::reportValue(const char *result_name,
result += reportPvtScaleFactor(cell, pvt, digits);
result += result_name;
result.append(result_name);
result += " = ";
result +=
table_unit->asString(findValue(cell, pvt, value1, value2, value3), digits);
@ -1255,11 +1255,11 @@ Table::findValue(const LibertyLibrary *,
}
std::string
Table::reportValue(const char *result_name,
Table::reportValue(std::string_view result_name,
const LibertyCell *cell,
const Pvt *,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -1283,25 +1283,24 @@ Table::reportValue(const char *result_name,
}
std::string
Table::reportValueOrder0(const char *result_name,
const char *comment1,
Table::reportValueOrder0(std::string_view result_name,
std::string_view comment1,
const Unit *table_unit,
int digits) const
{
std::string result = result_name;
std::string result(result_name);
result += " constant = ";
result += table_unit->asString(value_, digits);
if (comment1)
result += comment1;
result.append(comment1);
result += '\n';
return result;
}
std::string
Table::reportValueOrder1(const char *result_name,
Table::reportValueOrder1(std::string_view result_name,
const LibertyCell *cell,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -1313,8 +1312,7 @@ Table::reportValueOrder1(const char *result_name,
result += axis1_->variableString();
result += " = ";
result += unit1->asString(value1, digits);
if (comment1)
result += comment1;
result.append(comment1);
result += '\n';
if (axis1_->size() != 1) {
size_t index1 = axis1_->findAxisIndex(value1);
@ -1330,7 +1328,7 @@ Table::reportValueOrder1(const char *result_name,
result += table_unit->asString(value(index1 + 1), digits);
result += '\n';
}
result += result_name;
result.append(result_name);
result += " = ";
result += table_unit->asString(findValue(value1, value2, value3), digits);
result += '\n';
@ -1338,10 +1336,10 @@ Table::reportValueOrder1(const char *result_name,
}
std::string
Table::reportValueOrder2(const char *result_name,
Table::reportValueOrder2(std::string_view result_name,
const LibertyCell *cell,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -1354,8 +1352,7 @@ Table::reportValueOrder2(const char *result_name,
result += axis1_->variableString();
result += " = ";
result += unit1->asString(value1, digits);
if (comment1)
result += comment1;
result.append(comment1);
result += '\n';
result += "| ";
result += axis2_->variableString();
@ -1390,7 +1387,7 @@ Table::reportValueOrder2(const char *result_name,
}
}
result += '\n';
result += result_name;
result.append(result_name);
result += " = ";
result += table_unit->asString(findValue(value1, value2, value3), digits);
result += '\n';
@ -1398,10 +1395,10 @@ Table::reportValueOrder2(const char *result_name,
}
std::string
Table::reportValueOrder3(const char *result_name,
Table::reportValueOrder3(std::string_view result_name,
const LibertyCell *cell,
float value1,
const char *comment1,
std::string_view comment1,
float value2,
float value3,
const Unit *table_unit,
@ -1415,8 +1412,7 @@ Table::reportValueOrder3(const char *result_name,
result += axis1_->variableString();
result += " = ";
result += unit1->asString(value1, digits);
if (comment1)
result += comment1;
result.append(comment1);
result += '\n';
result += " | ---- ";
result += axis2_->variableString();
@ -1492,7 +1488,7 @@ Table::reportValueOrder3(const char *result_name,
}
}
result += '\n';
result += result_name;
result.append(result_name);
result += " = ";
result += table_unit->asString(findValue(value1, value2, value3), digits);
result += '\n';
@ -1703,7 +1699,7 @@ TableAxis::findAxisClosestIndex(float value) const
}
}
const char *
std::string_view
TableAxis::variableString() const
{
return tableVariableString(variable_);
@ -1741,12 +1737,12 @@ static EnumNameMap<TableAxisVariable> table_axis_variable_map = {
{TableAxisVariable::normalized_voltage, "normalized_voltage"}};
TableAxisVariable
stringTableAxisVariable(const char *variable)
stringTableAxisVariable(std::string_view variable)
{
return table_axis_variable_map.find(variable, TableAxisVariable::unknown);
}
const char *
std::string_view
tableVariableString(TableAxisVariable variable)
{
return table_axis_variable_map.find(variable);
@ -2213,9 +2209,9 @@ OutputWaveforms::finalResistance()
////////////////////////////////////////////////////////////////
DriverWaveform::DriverWaveform(const std::string &name,
DriverWaveform::DriverWaveform(std::string name,
TablePtr waveforms) :
name_(name),
name_(std::move(name)),
waveforms_(waveforms)
{
}

View File

@ -88,34 +88,34 @@ TimingArcAttrs::setCond(FuncExpr *cond)
}
void
TimingArcAttrs::setSdfCond(const std::string &cond)
TimingArcAttrs::setSdfCond(std::string cond)
{
sdf_cond_ = cond;
sdf_cond_ = std::move(cond);
sdf_cond_start_ = sdf_cond_end_ = sdf_cond_;
}
void
TimingArcAttrs::setSdfCondStart(const std::string &cond)
TimingArcAttrs::setSdfCondStart(std::string cond)
{
sdf_cond_start_ = cond;
sdf_cond_start_ = std::move(cond);
}
void
TimingArcAttrs::setSdfCondEnd(const std::string &cond)
TimingArcAttrs::setSdfCondEnd(std::string cond)
{
sdf_cond_end_ = cond;
sdf_cond_end_ = std::move(cond);
}
void
TimingArcAttrs::setModeName(const std::string &name)
TimingArcAttrs::setModeName(std::string name)
{
mode_name_ = name;
mode_name_ = std::move(name);
}
void
TimingArcAttrs::setModeValue(const std::string &value)
TimingArcAttrs::setModeValue(std::string value)
{
mode_value_ = value;
mode_value_ = std::move(value);
}
TimingModel *
@ -679,7 +679,7 @@ static EnumNameMap<TimingSense> timing_sense_name_map =
{TimingSense::unknown, "unknown"}
};
const char *
const std::string &
to_string(TimingSense sense)
{
return timing_sense_name_map.find(sense);
@ -747,14 +747,14 @@ EnumNameMap<TimingType> timing_type_name_map =
{TimingType::unknown, "unknown"}
};
const char *
std::string_view
timingTypeString(TimingType type)
{
return timing_type_name_map.find(type);
}
TimingType
findTimingType(const char *type_name)
findTimingType(std::string_view type_name)
{
return timing_type_name_map.find(type_name, TimingType::unknown);
}

View File

@ -193,21 +193,21 @@ Units::Units() :
}
Unit *
Units::find(const char *unit_name)
Units::find(std::string_view unit_name)
{
if (stringEq(unit_name, "time"))
if (stringEqual(unit_name, "time"))
return &time_unit_;
else if (stringEq(unit_name, "resistance"))
else if (stringEqual(unit_name, "resistance"))
return &resistance_unit_;
else if (stringEq(unit_name, "capacitance"))
else if (stringEqual(unit_name, "capacitance"))
return &capacitance_unit_;
else if (stringEq(unit_name, "voltage"))
else if (stringEqual(unit_name, "voltage"))
return &voltage_unit_;
else if (stringEq(unit_name, "current"))
else if (stringEqual(unit_name, "current"))
return &current_unit_;
else if (stringEq(unit_name, "power"))
else if (stringEqual(unit_name, "power"))
return &power_unit_;
else if (stringEq(unit_name, "distance"))
else if (stringEqual(unit_name, "distance"))
return &distance_unit_;
else
return nullptr;

View File

@ -31,9 +31,9 @@
namespace sta {
Wireload::Wireload(const char *name,
Wireload::Wireload(std::string name,
LibertyLibrary *library) :
name_(stringCopy(name)),
name_(std::move(name)),
library_(library),
area_(0.0F),
resistance_(0.0F),
@ -42,13 +42,13 @@ Wireload::Wireload(const char *name,
{
}
Wireload::Wireload(const char *name,
Wireload::Wireload(std::string name,
LibertyLibrary *library,
float area,
float resistance,
float capacitance,
float slope) :
name_(stringCopy(name)),
name_(std::move(name)),
library_(library),
area_(area),
resistance_(resistance),
@ -60,7 +60,6 @@ Wireload::Wireload(const char *name,
Wireload::~Wireload()
{
deleteContents(fanout_lengths_);
stringDelete(name_);
}
void
@ -186,15 +185,14 @@ WireloadForArea::WireloadForArea(float min_area,
{
}
WireloadSelection::WireloadSelection(const char *name) :
name_(stringCopy(name))
WireloadSelection::WireloadSelection(std::string name) :
name_(std::move(name))
{
}
WireloadSelection::~WireloadSelection()
{
deleteContents(wireloads_);
stringDelete(name_);
}
struct WireloadForAreaMinLess
@ -264,13 +262,13 @@ wireloadTreeString(WireloadTree tree)
}
WireloadTree
stringWireloadTree(const char *wire_load_type)
stringWireloadTree(std::string_view wire_load_type)
{
if (stringEq(wire_load_type, "worst_case_tree"))
if (wire_load_type == "worst_case_tree")
return WireloadTree::worst_case;
else if (stringEq(wire_load_type, "best_case_tree"))
else if (wire_load_type == "best_case_tree")
return WireloadTree::best_case;
else if (stringEq(wire_load_type, "balanced_tree"))
else if (wire_load_type == "balanced_tree")
return WireloadTree::balanced;
else
return WireloadTree::unknown;
@ -294,13 +292,13 @@ wireloadModeString(WireloadMode wire_load_mode)
}
WireloadMode
stringWireloadMode(const char *wire_load_mode)
stringWireloadMode(std::string_view wire_load_mode)
{
if (stringEq(wire_load_mode, "top"))
if (wire_load_mode == "top")
return WireloadMode::top;
else if (stringEq(wire_load_mode, "enclosed"))
else if (wire_load_mode == "enclosed")
return WireloadMode::enclosed;
else if (stringEq(wire_load_mode, "segmented"))
else if (wire_load_mode == "segmented")
return WireloadMode::segmented;
else
return WireloadMode::unknown;

View File

@ -683,9 +683,8 @@ TEST_F(TableAxisTest, FindAxisIndexExact) {
TEST_F(TableAxisTest, VariableString) {
auto axis = makeAxis(TableAxisVariable::total_output_net_capacitance,
{1.0f});
const char *str = axis->variableString();
EXPECT_NE(str, nullptr);
EXPECT_STREQ(str, "total_output_net_capacitance");
auto str = axis->variableString();
EXPECT_EQ(str, "total_output_net_capacitance");
}
TEST_F(TableAxisTest, UnitLookup) {
@ -740,12 +739,12 @@ TEST(TableVariableTest, StringTableAxisVariable) {
}
TEST(TableVariableTest, TableVariableString) {
EXPECT_STREQ(tableVariableString(TableAxisVariable::total_output_net_capacitance),
"total_output_net_capacitance");
EXPECT_STREQ(tableVariableString(TableAxisVariable::input_net_transition),
"input_net_transition");
EXPECT_STREQ(tableVariableString(TableAxisVariable::time),
"time");
EXPECT_EQ(tableVariableString(TableAxisVariable::total_output_net_capacitance),
"total_output_net_capacitance");
EXPECT_EQ(tableVariableString(TableAxisVariable::input_net_transition),
"input_net_transition");
EXPECT_EQ(tableVariableString(TableAxisVariable::time),
"time");
}
TEST(TableVariableTest, TableVariableUnit) {
@ -1155,11 +1154,11 @@ TEST(TimingTypeTest, TimingTypeScaleFactorType) {
}
TEST(TimingSenseTest, ToString) {
EXPECT_STREQ(to_string(TimingSense::positive_unate), "positive_unate");
EXPECT_STREQ(to_string(TimingSense::negative_unate), "negative_unate");
EXPECT_STREQ(to_string(TimingSense::non_unate), "non_unate");
EXPECT_STREQ(to_string(TimingSense::none), "none");
EXPECT_STREQ(to_string(TimingSense::unknown), "unknown");
EXPECT_EQ(to_string(TimingSense::positive_unate), "positive_unate");
EXPECT_EQ(to_string(TimingSense::negative_unate), "negative_unate");
EXPECT_EQ(to_string(TimingSense::non_unate), "non_unate");
EXPECT_EQ(to_string(TimingSense::none), "none");
EXPECT_EQ(to_string(TimingSense::unknown), "unknown");
}
TEST(TimingSenseTest, Opposite) {
@ -1353,8 +1352,8 @@ TEST(TimingArcAttrsTest, SetSdfCondStartEnd) {
TEST(RiseFallTest, BasicProperties) {
EXPECT_EQ(RiseFall::rise()->index(), 0);
EXPECT_EQ(RiseFall::fall()->index(), 1);
EXPECT_STREQ(RiseFall::rise()->name(), "rise");
EXPECT_STREQ(RiseFall::fall()->name(), "fall");
EXPECT_EQ(RiseFall::rise()->name(), "rise");
EXPECT_EQ(RiseFall::fall()->name(), "fall");
EXPECT_EQ(RiseFall::rise()->opposite(), RiseFall::fall());
EXPECT_EQ(RiseFall::fall()->opposite(), RiseFall::rise());
}
@ -1496,7 +1495,7 @@ TEST_F(LinearModelTest, CheckLinearModelCheckDelay) {
TEST_F(LinearModelTest, CheckLinearModelReportCheckDelay) {
CheckLinearModel model(cell_, 2.0f);
std::string report = model.reportCheckDelay(nullptr, 0.0f, nullptr,
std::string report = model.reportCheckDelay(nullptr, 0.0f, "",
0.0f, 0.0f,
nullptr, PocvMode::scalar, 3);
EXPECT_FALSE(report.empty());
@ -1686,13 +1685,13 @@ TEST(TableModelTest, Order2) {
TEST(WireloadTest, BasicConstruction) {
LibertyLibrary lib("test_lib", "test.lib");
Wireload wl("test_wl", &lib, 0.0f, 1.0f, 2.0f, 3.0f);
EXPECT_STREQ(wl.name(), "test_wl");
EXPECT_EQ(wl.name(), "test_wl");
}
TEST(WireloadTest, SimpleConstructor) {
LibertyLibrary lib("test_lib", "test.lib");
Wireload wl("test_wl", &lib);
EXPECT_STREQ(wl.name(), "test_wl");
EXPECT_EQ(wl.name(), "test_wl");
// Set individual properties
wl.setArea(10.0f);
wl.setResistance(1.5f);
@ -1917,7 +1916,7 @@ TEST_F(LinearModelTest, Table0ReportValue) {
Table tbl(42.0f);
const Units *units = lib_->units();
std::string report = tbl.reportValue("Delay", cell_, nullptr,
0.0f, nullptr, 0.0f, 0.0f,
0.0f, "", 0.0f, 0.0f,
units->timeUnit(), 3);
EXPECT_FALSE(report.empty());
EXPECT_NE(report.find("Delay"), std::string::npos);
@ -1936,7 +1935,7 @@ TEST_F(LinearModelTest, Table1ReportValue) {
const Units *units = lib_->units();
std::string report = tbl.reportValue("Delay", cell_, nullptr,
0.5f, nullptr, 0.0f, 0.0f,
0.5f, "", 0.0f, 0.0f,
units->timeUnit(), 3);
EXPECT_FALSE(report.empty());
EXPECT_NE(report.find("Delay"), std::string::npos);
@ -1959,7 +1958,7 @@ TEST_F(LinearModelTest, Table2ReportValue) {
const Units *units = lib_->units();
std::string report = tbl.reportValue("Delay", cell_, nullptr,
0.5f, nullptr, 0.5f, 0.0f,
0.5f, "", 0.5f, 0.0f,
units->timeUnit(), 3);
EXPECT_FALSE(report.empty());
EXPECT_NE(report.find("Delay"), std::string::npos);
@ -1989,7 +1988,7 @@ TEST_F(LinearModelTest, Table3ReportValue) {
const Units *units = lib_->units();
std::string report = tbl.reportValue("Delay", cell_, nullptr,
0.5f, nullptr, 0.5f, 0.5f,
0.5f, "", 0.5f, 0.5f,
units->timeUnit(), 3);
EXPECT_FALSE(report.empty());
EXPECT_NE(report.find("Delay"), std::string::npos);
@ -2036,7 +2035,7 @@ TEST_F(LinearModelTest, TableModelReportValue) {
const Units *units = lib_->units();
std::string report = model.reportValue("Delay", cell_, nullptr,
0.5f, nullptr, 0.0f, 0.0f,
0.5f, "", 0.0f, 0.0f,
units->timeUnit(), 3);
EXPECT_FALSE(report.empty());
EXPECT_NE(report.find("Delay"), std::string::npos);
@ -2116,11 +2115,11 @@ TEST(FuncExprTest, ZeroOneExpressions) {
TEST(SequentialTest, BasicConstruction) {
// Sequential class is constructed and used during liberty parsing
// We can test the StringTableAxisVariable utility
const char *var_str = tableVariableString(TableAxisVariable::input_transition_time);
EXPECT_STREQ(var_str, "input_transition_time");
auto var_str = tableVariableString(TableAxisVariable::input_transition_time);
EXPECT_EQ(var_str, "input_transition_time");
var_str = tableVariableString(TableAxisVariable::total_output_net_capacitance);
EXPECT_STREQ(var_str, "total_output_net_capacitance");
EXPECT_EQ(var_str, "total_output_net_capacitance");
}
TEST(TableAxisVariableTest, StringToVariable) {
@ -2140,7 +2139,7 @@ TEST(TableAxisVariableTest, StringToVariable) {
TEST(WireloadSelectionTest, BasicConstruction) {
WireloadSelection sel("test_sel");
EXPECT_STREQ(sel.name(), "test_sel");
EXPECT_EQ(sel.name(), "test_sel");
}
TEST(WireloadSelectionTest, FindWireload) {
@ -2507,7 +2506,7 @@ TEST(TableModelTest, FindValueOrder2) {
TEST(ScaleFactorsTest, BasicConstruction) {
ScaleFactors sf("test_scales");
EXPECT_STREQ(sf.name(), "test_scales");
EXPECT_EQ(sf.name(), "test_scales");
}
TEST(ScaleFactorsTest, SetAndGetWithRiseFall) {
@ -2541,12 +2540,12 @@ TEST(ScaleFactorsTest, SetAndGetWithoutRiseFall) {
////////////////////////////////////////////////////////////////
TEST(OcvDerateTest, BasicConstruction) {
OcvDerate derate(stringCopy("test_ocv"));
OcvDerate derate("test_ocv");
EXPECT_EQ(derate.name(), "test_ocv");
}
TEST(OcvDerateTest, SetAndGetDerateTable) {
OcvDerate derate(stringCopy("ocv1"));
OcvDerate derate("ocv1");
TablePtr tbl = std::make_shared<Table>(0.95f);
derate.setDerateTable(RiseFall::rise(), EarlyLate::early(),
PathType::data, tbl);
@ -2556,7 +2555,7 @@ TEST(OcvDerateTest, SetAndGetDerateTable) {
}
TEST(OcvDerateTest, NullByDefault) {
OcvDerate derate(stringCopy("ocv2"));
OcvDerate derate("ocv2");
const Table *found = derate.derateTable(RiseFall::fall(), EarlyLate::late(),
PathType::clk);
EXPECT_EQ(found, nullptr);
@ -2575,7 +2574,7 @@ TEST(LibertyLibraryTest, OcvArcDepth) {
TEST(LibertyLibraryTest, DefaultOcvDerate) {
LibertyLibrary lib("test_lib", "test.lib");
EXPECT_EQ(lib.defaultOcvDerate(), nullptr);
OcvDerate *derate = new OcvDerate(stringCopy("default_ocv"));
OcvDerate *derate = new OcvDerate("default_ocv");
lib.setDefaultOcvDerate(derate);
EXPECT_EQ(lib.defaultOcvDerate(), derate);
}
@ -2626,7 +2625,7 @@ TEST(LibertyLibraryTest, MakeScaledCell) {
LibertyLibrary lib("test_lib", "test.lib");
LibertyCell *cell = lib.makeScaledCell("scaled_inv", "test.lib");
EXPECT_NE(cell, nullptr);
EXPECT_STREQ(cell->name(), "scaled_inv");
EXPECT_EQ(cell->name(), "scaled_inv");
delete cell;
}
@ -2666,7 +2665,7 @@ TEST(LibertyLibraryTest, TableTemplates) {
TEST(TestCellTest, BasicConstruction) {
LibertyLibrary lib("test_lib", "test.lib");
TestCell cell(&lib, "INV_X1", "test.lib");
EXPECT_STREQ(cell.name(), "INV_X1");
EXPECT_EQ(cell.name(), "INV_X1");
EXPECT_EQ(cell.libertyLibrary(), &lib);
}
@ -2834,7 +2833,7 @@ TEST(TestCellTest, CellOcvDerate) {
// Without cell-level derate, returns library default
EXPECT_EQ(cell.ocvDerate(), nullptr);
OcvDerate *derate = new OcvDerate(stringCopy("cell_ocv"));
OcvDerate *derate = new OcvDerate("cell_ocv");
cell.setOcvDerate(derate);
EXPECT_EQ(cell.ocvDerate(), derate);
}
@ -2873,8 +2872,8 @@ TEST(TestCellTest, TimingArcSetCount) {
////////////////////////////////////////////////////////////////
TEST(ScanSignalTypeTest, Names) {
EXPECT_NE(scanSignalTypeName(ScanSignalType::enable), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::enable_inverted), nullptr);
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::enable).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::enable_inverted).empty());
}
////////////////////////////////////////////////////////////////
@ -2979,8 +2978,8 @@ TEST(LibertyUtilTest, PortLibertyToSta) {
}
TEST(LibertyUtilTest, PwrGndTypeName) {
const char *name = pwrGndTypeName(PwrGndType::primary_power);
EXPECT_NE(name, nullptr);
const std::string &name = pwrGndTypeName(PwrGndType::primary_power);
EXPECT_FALSE(name.empty());
}
TEST(LibertyUtilTest, FindPwrGndType) {
@ -3000,9 +2999,9 @@ TEST(ScaleFactorPvtTest, FindByName) {
}
TEST(ScaleFactorPvtTest, PvtToName) {
EXPECT_STREQ(scaleFactorPvtName(ScaleFactorPvt::process), "process");
EXPECT_STREQ(scaleFactorPvtName(ScaleFactorPvt::volt), "volt");
EXPECT_STREQ(scaleFactorPvtName(ScaleFactorPvt::temp), "temp");
EXPECT_EQ(scaleFactorPvtName(ScaleFactorPvt::process), "process");
EXPECT_EQ(scaleFactorPvtName(ScaleFactorPvt::volt), "volt");
EXPECT_EQ(scaleFactorPvtName(ScaleFactorPvt::temp), "temp");
}
////////////////////////////////////////////////////////////////
@ -3029,16 +3028,16 @@ TEST(ScaleFactorTypeTest, FindByName) {
}
TEST(ScaleFactorTypeTest, TypeToName) {
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::pin_cap), "pin_cap");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::wire_cap), "wire_cap");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::wire_res), "wire_res");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::cell), "cell");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::hold), "hold");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::setup), "setup");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::recovery), "recovery");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::removal), "removal");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::transition), "transition");
EXPECT_STREQ(scaleFactorTypeName(ScaleFactorType::min_pulse_width), "min_pulse_width");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::pin_cap), "pin_cap");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::wire_cap), "wire_cap");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::wire_res), "wire_res");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::cell), "cell");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::hold), "hold");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::setup), "setup");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::recovery), "recovery");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::removal), "removal");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::transition), "transition");
EXPECT_EQ(scaleFactorTypeName(ScaleFactorType::min_pulse_width), "min_pulse_width");
}
TEST(ScaleFactorTypeTest, RiseFallSuffix) {
@ -3097,13 +3096,16 @@ TEST(PvtTest, Setters) {
TEST(OperatingConditionsTest, NameOnlyConstructor) {
OperatingConditions opcond("typical");
EXPECT_STREQ(opcond.name(), "typical");
EXPECT_EQ(opcond.name(), "typical");
}
TEST(OperatingConditionsTest, FullConstructor) {
OperatingConditions opcond("worst", 1.0f, 0.9f, 125.0f,
WireloadTree::worst_case);
EXPECT_STREQ(opcond.name(), "worst");
OperatingConditions opcond("worst");
opcond.setProcess(1.0f);
opcond.setVoltage(0.9f);
opcond.setTemperature(125.0f);
opcond.setWireloadTree(WireloadTree::worst_case);
EXPECT_EQ(opcond.name(), "worst");
EXPECT_FLOAT_EQ(opcond.process(), 1.0f);
EXPECT_FLOAT_EQ(opcond.voltage(), 0.9f);
EXPECT_FLOAT_EQ(opcond.temperature(), 125.0f);
@ -3201,8 +3203,10 @@ TEST(ModeDefTest, DefineAndFindValue) {
EXPECT_NE(mode, nullptr);
FuncExpr *cond = FuncExpr::makeOne();
ModeValueDef *valdef = mode->defineValue("test_value", cond, "A==1");
ModeValueDef *valdef = mode->defineValue("test_value");
EXPECT_NE(valdef, nullptr);
valdef->setCond(cond);
valdef->setSdfCond("A==1");
EXPECT_EQ(valdef->value(), "test_value");
EXPECT_EQ(valdef->cond(), cond);
EXPECT_EQ(valdef->sdfCond(), "A==1");
@ -3211,8 +3215,8 @@ TEST(ModeDefTest, DefineAndFindValue) {
EXPECT_EQ(found, valdef);
EXPECT_EQ(mode->findValueDef("nonexistent"), nullptr);
const ModeValueMap *vals = mode->values();
EXPECT_NE(vals, nullptr);
const ModeValueMap &vals = mode->values();
EXPECT_FALSE(vals.empty());
}
////////////////////////////////////////////////////////////////
@ -3286,34 +3290,30 @@ TEST(TestCellTest, TimingArcSetsEmpty) {
TEST(TestCellTest, FootprintDefault) {
LibertyLibrary lib("test_lib", "test.lib");
TestCell cell(&lib, "CELL1", "test.lib");
const char *fp = cell.footprint();
// Empty string or nullptr for default
if (fp) {
EXPECT_EQ(fp, "");
}
const std::string &fp = cell.footprint();
// Empty string for default
EXPECT_TRUE(fp.empty());
}
TEST(TestCellTest, SetFootprint) {
LibertyLibrary lib("test_lib", "test.lib");
TestCell cell(&lib, "CELL1", "test.lib");
cell.setFootprint("INV_FP");
EXPECT_STREQ(cell.footprint(), "INV_FP");
EXPECT_EQ(cell.footprint(), "INV_FP");
}
TEST(TestCellTest, UserFunctionClassDefault) {
LibertyLibrary lib("test_lib", "test.lib");
TestCell cell(&lib, "CELL1", "test.lib");
const char *ufc = cell.userFunctionClass();
if (ufc) {
EXPECT_EQ(ufc, "");
}
const std::string &ufc = cell.userFunctionClass();
EXPECT_TRUE(ufc.empty());
}
TEST(TestCellTest, SetUserFunctionClass) {
LibertyLibrary lib("test_lib", "test.lib");
TestCell cell(&lib, "CELL1", "test.lib");
cell.setUserFunctionClass("inverter");
EXPECT_STREQ(cell.userFunctionClass(), "inverter");
EXPECT_EQ(cell.userFunctionClass(), "inverter");
}
TEST(TestCellTest, SwitchCellTypeGetter) {
@ -3425,15 +3425,15 @@ TEST(TimingTypeTest, ScaleFactorTypeAdditional) {
////////////////////////////////////////////////////////////////
TEST(ScanSignalTypeTest, AllNames) {
EXPECT_NE(scanSignalTypeName(ScanSignalType::enable), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::enable_inverted), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::clock), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::clock_a), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::clock_b), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::input), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::input_inverted), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::output), nullptr);
EXPECT_NE(scanSignalTypeName(ScanSignalType::output_inverted), nullptr);
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::enable).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::enable_inverted).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::clock).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::clock_a).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::clock_b).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::input).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::input_inverted).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::output).empty());
EXPECT_FALSE(scanSignalTypeName(ScanSignalType::output_inverted).empty());
}
////////////////////////////////////////////////////////////////
@ -3441,16 +3441,16 @@ TEST(ScanSignalTypeTest, AllNames) {
////////////////////////////////////////////////////////////////
TEST(LibertyUtilTest, PwrGndTypeAllNames) {
EXPECT_NE(pwrGndTypeName(PwrGndType::primary_power), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::primary_ground), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::backup_power), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::backup_ground), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::internal_power), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::internal_ground), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::nwell), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::pwell), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::deepnwell), nullptr);
EXPECT_NE(pwrGndTypeName(PwrGndType::deeppwell), nullptr);
EXPECT_FALSE(pwrGndTypeName(PwrGndType::primary_power).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::primary_ground).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::backup_power).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::backup_ground).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::internal_power).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::internal_ground).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::nwell).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::pwell).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::deepnwell).empty());
EXPECT_FALSE(pwrGndTypeName(PwrGndType::deeppwell).empty());
}
TEST(LibertyUtilTest, FindPwrGndTypeAll) {
@ -3675,7 +3675,7 @@ TEST(Table0Test, ReportValue) {
TestCell cell(&lib, "INV", "test.lib");
const Units *units = lib.units();
std::string report = tbl.reportValue("Power", &cell, nullptr,
0.0f, nullptr, 0.0f, 0.0f,
0.0f, "", 0.0f, 0.0f,
units->powerUnit(), 3);
EXPECT_FALSE(report.empty());
}

View File

@ -38,12 +38,12 @@ namespace sta {
static constexpr char escape_ = '\\';
ConcreteLibrary::ConcreteLibrary(const char *name,
const char *filename,
ConcreteLibrary::ConcreteLibrary(std::string name,
std::string filename,
bool is_liberty) :
name_(name),
name_(std::move(name)),
id_(ConcreteNetwork::nextObjectId()),
filename_(filename ? filename : ""),
filename_(std::move(filename)),
is_liberty_(is_liberty),
bus_brkt_left_('['),
bus_brkt_right_(']')
@ -56,9 +56,9 @@ ConcreteLibrary::~ConcreteLibrary()
}
ConcreteCell *
ConcreteLibrary::makeCell(const char *name,
ConcreteLibrary::makeCell(std::string_view name,
bool is_leaf,
const char *filename)
std::string_view filename)
{
ConcreteCell *cell = new ConcreteCell(name, filename, is_leaf, this);
addCell(cell);
@ -72,11 +72,9 @@ ConcreteLibrary::addCell(ConcreteCell *cell)
}
void
ConcreteLibrary::renameCell(ConcreteCell *cell,
const char *cell_name)
ConcreteLibrary::removeCell(ConcreteCell *cell)
{
cell_map_.erase(cell->name());
cell_map_[cell_name] = cell;
}
void
@ -93,9 +91,9 @@ ConcreteLibrary::cellIterator() const
}
ConcreteCell *
ConcreteLibrary::findCell(const char *name) const
ConcreteLibrary::findCell(std::string_view name) const
{
return findKey(cell_map_, name);
return findStringKey(cell_map_, name);
}
CellSeq
@ -119,13 +117,13 @@ ConcreteLibrary::setBusBrkts(char left,
////////////////////////////////////////////////////////////////
ConcreteCell::ConcreteCell(const char *name,
const char *filename,
ConcreteCell::ConcreteCell(std::string_view name,
std::string_view filename,
bool is_leaf,
ConcreteLibrary *library) :
name_(name),
id_(ConcreteNetwork::nextObjectId()),
filename_(filename ? filename : ""),
filename_(filename),
library_(library),
liberty_cell_(nullptr),
ext_cell_(nullptr),
@ -140,10 +138,11 @@ ConcreteCell::~ConcreteCell()
}
void
ConcreteCell::setName(const char *name)
ConcreteCell::setName(std::string_view name)
{
library_->renameCell(this, name);
library_->removeCell(this);
name_ = name;
library_->addCell(this);
}
void
@ -159,18 +158,20 @@ ConcreteCell::setExtCell(void *ext_cell)
}
ConcretePort *
ConcreteCell::makePort(const char *name)
ConcreteCell::makePort(std::string_view name)
{
ConcretePort *port = new ConcretePort(name, false, -1, -1, false, nullptr, this);
ConcretePort *port = new ConcretePort(name, false, -1, -1,
false, nullptr, this);
addPort(port);
return port;
}
ConcretePort *
ConcreteCell::makeBundlePort(const char *name,
ConcreteCell::makeBundlePort(std::string_view name,
ConcretePortSeq *members)
{
ConcretePort *port = new ConcretePort(name, false, -1, -1, true, members, this);
ConcretePort *port = new ConcretePort(name, false, -1, -1, true,
members, this);
addPort(port);
for (ConcretePort *member : *members)
member->setBundlePort(port);
@ -178,19 +179,19 @@ ConcreteCell::makeBundlePort(const char *name,
}
ConcretePort *
ConcreteCell::makeBusPort(const char *name,
ConcreteCell::makeBusPort(std::string_view name,
int from_index,
int to_index)
{
ConcretePort *port = new ConcretePort(name, true, from_index, to_index,
false, new ConcretePortSeq, this);
addPort(port);
makeBusPortBits(port, name, from_index, to_index);
makeBusPortBits(port, port->name(), from_index, to_index);
return port;
}
ConcretePort *
ConcreteCell::makeBusPort(const char *name,
ConcreteCell::makeBusPort(std::string_view name,
int from_index,
int to_index,
ConcretePortSeq *members)
@ -203,40 +204,42 @@ ConcreteCell::makeBusPort(const char *name,
void
ConcreteCell::makeBusPortBits(ConcretePort *bus_port,
const char *name,
std::string_view bus_name,
int from_index,
int to_index)
{
if (from_index < to_index) {
for (int index = from_index; index <= to_index; index++)
makeBusPortBit(bus_port, name, index);
makeBusPortBit(bus_port, bus_name, index);
}
else {
for (int index = from_index; index >= to_index; index--)
makeBusPortBit(bus_port, name, index);
makeBusPortBit(bus_port, bus_name, index);
}
}
void
ConcreteCell::makeBusPortBit(ConcretePort *bus_port,
const char *bus_name,
std::string_view bus_name,
int bit_index)
{
std::string bit_name = std::string(bus_name)
+ library_->busBrktLeft()
+ std::to_string(bit_index)
+ library_->busBrktRight();
ConcretePort *port = makePort(bit_name.c_str(), bit_index);
std::string bit_name;
bit_name.append(bus_name);
bit_name += library_->busBrktLeft();
bit_name += std::to_string(bit_index);
bit_name += library_->busBrktRight();
ConcretePort *port = makePort(bit_name, bit_index);
bus_port->addPortBit(port);
addPortBit(port);
}
ConcretePort *
ConcreteCell::makePort(const char *bit_name,
ConcreteCell::makePort(std::string bit_name,
int bit_index)
{
ConcretePort *port = new ConcretePort(bit_name, false, bit_index,
bit_index, false, nullptr, this);
ConcretePort *port = new ConcretePort(bit_name, false,
bit_index, bit_index, false,
nullptr, this);
addPortBit(port);
return port;
}
@ -264,14 +267,14 @@ ConcreteCell::setIsLeaf(bool is_leaf)
}
void
ConcreteCell::setAttribute(const std::string &key,
const std::string &value)
ConcreteCell::setAttribute(std::string_view key,
std::string_view value)
{
attribute_map_[key] = value;
attribute_map_[std::string(key)] = value;
}
std::string
ConcreteCell::getAttribute(const std::string &key) const
ConcreteCell::getAttribute(std::string_view key) const
{
const auto &itr = attribute_map_.find(key);
if (itr != attribute_map_.end())
@ -280,9 +283,9 @@ ConcreteCell::getAttribute(const std::string &key) const
}
ConcretePort *
ConcreteCell::findPort(const char *name) const
ConcreteCell::findPort(std::string_view name) const
{
return findKey(port_map_, name);
return findStringKey(port_map_, name);
}
size_t
@ -350,7 +353,7 @@ BusPort::addBusBit(ConcretePort *port,
void
ConcreteCell::groupBusPorts(const char bus_brkt_left,
const char bus_brkt_right,
std::function<bool(const char*)> port_msb_first)
std::function<bool(std::string_view)> port_msb_first)
{
const char bus_brkts_left[2]{bus_brkt_left, '\0'};
const char bus_brkts_right[2]{bus_brkt_right, '\0'};
@ -362,11 +365,10 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
ConcretePortSeq ports = ports_;
ports_.clear();
for (ConcretePort *port : ports) {
const char *port_name = port->name();
bool is_bus;
std::string bus_name;
int index;
parseBusName(port_name, bus_brkts_left, bus_brkts_right, escape_,
parseBusName(port->name(), bus_brkts_left, bus_brkts_right, escape_,
is_bus, bus_name, index);
if (is_bus) {
if (!port->isBusBit()) {
@ -385,7 +387,7 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
int from = bus_port.from();
int to = bus_port.to();
size_t size = to - from + 1;
bool msb_first = port_msb_first(bus_name.c_str());
bool msb_first = port_msb_first(bus_name);
ConcretePortSeq *members = new ConcretePortSeq(size);
// Index the bus bit ports.
for (ConcretePort *bus_bit : bus_port.members()) {
@ -395,14 +397,14 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
}
if (msb_first)
std::swap(from, to);
ConcretePort *port = makeBusPort(bus_name.c_str(), from, to, members);
ConcretePort *port = makeBusPort(bus_name, from, to, members);
port->setDirection(bus_port.direction());
}
}
////////////////////////////////////////////////////////////////
ConcretePort::ConcretePort(const char *name,
ConcretePort::ConcretePort(std::string_view name,
bool is_bus,
int from_index,
int to_index,
@ -458,18 +460,17 @@ ConcretePort::setExtPort(void *port)
ext_port_ = port;
}
const char *
std::string
ConcretePort::busName() const
{
if (is_bus_) {
ConcreteLibrary *lib = cell_->library();
std::string bus_name = sta::format("{}{}{}:{}{}",
name(),
lib->busBrktLeft(),
from_index_,
to_index_,
lib->busBrktRight());
return makeTmpString(bus_name);
return sta::format("{}{}{}:{}{}",
name(),
lib->busBrktLeft(),
from_index_,
to_index_,
lib->busBrktRight());
}
else
return name();

View File

@ -25,6 +25,7 @@
#include "ConcreteNetwork.hh"
#include <map>
#include <string_view>
#include "PatternMatch.hh"
#include "Report.hh"
@ -424,19 +425,21 @@ ConcreteNetwork::libertyLibraryIterator() const
////////////////////////////////////////////////////////////////
Library *
ConcreteNetwork::makeLibrary(const char *name,
const char *filename)
ConcreteNetwork::makeLibrary(std::string_view name,
std::string_view filename)
{
ConcreteLibrary *library = new ConcreteLibrary(name, filename, false);
ConcreteLibrary *library = new ConcreteLibrary(std::string(name),
std::string(filename), false);
addLibrary(library);
return reinterpret_cast<Library*>(library);
}
LibertyLibrary *
ConcreteNetwork::makeLibertyLibrary(const char *name,
const char *filename)
ConcreteNetwork::makeLibertyLibrary(std::string_view name,
std::string_view filename)
{
LibertyLibrary *library = new LibertyLibrary(name, filename);
LibertyLibrary *library = new LibertyLibrary(std::string(name),
std::string(filename));
addLibrary(library);
return library;
}
@ -449,9 +452,9 @@ ConcreteNetwork::addLibrary(ConcreteLibrary *library)
}
Library *
ConcreteNetwork::findLibrary(const char *name)
ConcreteNetwork::findLibrary(std::string_view name)
{
return reinterpret_cast<Library*>(findKey(library_map_, name));
return reinterpret_cast<Library*>(findStringKey(library_map_, name));
}
void
@ -463,7 +466,7 @@ ConcreteNetwork::deleteLibrary(Library *library)
delete clib;
}
const char *
std::string
ConcreteNetwork::name(const Library *library) const
{
const ConcreteLibrary *clib =
@ -480,16 +483,16 @@ ConcreteNetwork::id(const Library *library) const
}
LibertyLibrary *
ConcreteNetwork::findLiberty(const char *name)
ConcreteNetwork::findLiberty(std::string_view name)
{
ConcreteLibrary *lib = findKey(library_map_, name);
ConcreteLibrary *lib = findStringKey(library_map_, name);
if (lib) {
if (lib->isLiberty())
return static_cast<LibertyLibrary*>(lib);
// Potential name conflict
else {
for (ConcreteLibrary *lib : library_seq_) {
if (stringEq(lib->name(), name)
if (lib->name() == name
&& lib->isLiberty())
return static_cast<LibertyLibrary*>(lib);
}
@ -500,9 +503,9 @@ ConcreteNetwork::findLiberty(const char *name)
Cell *
ConcreteNetwork::makeCell(Library *library,
const char *name,
std::string_view name,
bool is_leaf,
const char *filename)
std::string_view filename)
{
ConcreteLibrary *clib = reinterpret_cast<ConcreteLibrary*>(library);
return reinterpret_cast<Cell*>(clib->makeCell(name, is_leaf, filename));
@ -510,7 +513,7 @@ ConcreteNetwork::makeCell(Library *library,
Cell *
ConcreteNetwork::findCell(const Library *library,
const char *name) const
std::string_view name) const
{
const ConcreteLibrary *clib =
reinterpret_cast<const ConcreteLibrary*>(library);
@ -518,7 +521,7 @@ ConcreteNetwork::findCell(const Library *library,
}
Cell *
ConcreteNetwork::findAnyCell(const char *name)
ConcreteNetwork::findAnyCell(std::string_view name)
{
for (ConcreteLibrary *lib : library_seq_) {
ConcreteCell *cell = lib->findCell(name);
@ -547,7 +550,7 @@ ConcreteNetwork::deleteCell(Cell *cell)
////////////////////////////////////////////////////////////////
const char *
std::string
ConcreteNetwork::name(const Cell *cell) const
{
const ConcreteCell *ccell = reinterpret_cast<const ConcreteCell*>(cell);
@ -563,7 +566,7 @@ ConcreteNetwork::id(const Cell *cell) const
void
ConcreteNetwork::setName(Cell *cell,
const char *name)
std::string_view name)
{
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell);
ccell->setName(name);
@ -579,8 +582,8 @@ ConcreteNetwork::setIsLeaf(Cell *cell,
void
ConcreteNetwork::setAttribute(Cell *cell,
const std::string &key,
const std::string &value)
std::string_view key,
std::string_view value)
{
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell);
ccell->setAttribute(key, value);
@ -619,8 +622,8 @@ ConcreteNetwork::cell(const LibertyCell *cell) const
return reinterpret_cast<const Cell*>(cell);
}
const char *
ConcreteNetwork::filename(const Cell *cell)
std::string_view
ConcreteNetwork::filename(const Cell *cell) const
{
const ConcreteCell *ccell = reinterpret_cast<const ConcreteCell*>(cell);
return ccell->filename();
@ -628,7 +631,7 @@ ConcreteNetwork::filename(const Cell *cell)
std::string
ConcreteNetwork::getAttribute(const Cell *cell,
const std::string &key) const
std::string_view key) const
{
const ConcreteCell *ccell = reinterpret_cast<const ConcreteCell*>(cell);
return ccell->getAttribute(key);
@ -643,7 +646,7 @@ ConcreteNetwork::attributeMap(const Cell *cell) const
Port *
ConcreteNetwork::findPort(const Cell *cell,
const char *name) const
std::string_view name) const
{
const ConcreteCell *ccell = reinterpret_cast<const ConcreteCell*>(cell);
return reinterpret_cast<Port*>(ccell->findPort(name));
@ -658,7 +661,7 @@ ConcreteNetwork::isLeaf(const Cell *cell) const
Port *
ConcreteNetwork::makePort(Cell *cell,
const char *name)
std::string_view name)
{
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell);
ConcretePort *port = ccell->makePort(name);
@ -667,7 +670,7 @@ ConcreteNetwork::makePort(Cell *cell,
Port *
ConcreteNetwork::makeBusPort(Cell *cell,
const char *name,
std::string_view name,
int from_index,
int to_index)
{
@ -678,7 +681,7 @@ ConcreteNetwork::makeBusPort(Cell *cell,
void
ConcreteNetwork::groupBusPorts(Cell *cell,
std::function<bool(const char*)> port_msb_first)
std::function<bool(std::string_view)> port_msb_first)
{
Library *lib = library(cell);
ConcreteLibrary *clib = reinterpret_cast<ConcreteLibrary*>(lib);
@ -689,7 +692,7 @@ ConcreteNetwork::groupBusPorts(Cell *cell,
Port *
ConcreteNetwork::makeBundlePort(Cell *cell,
const char *name,
std::string_view name,
PortSeq *members)
{
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell);
@ -795,7 +798,7 @@ ConcreteNetwork::portBitCount(const Cell *cell) const
////////////////////////////////////////////////////////////////
const char *
std::string
ConcreteNetwork::name(const Port *port) const
{
const ConcretePort *cport = reinterpret_cast<const ConcretePort*>(port);
@ -844,7 +847,7 @@ ConcreteNetwork::isBus(const Port *port) const
return cport->isBus();
}
const char *
std::string
ConcreteNetwork::busName(const Port *port) const
{
const ConcretePort *cport = reinterpret_cast<const ConcretePort*>(port);
@ -949,12 +952,12 @@ ConcreteNetwork::memberIterator(const Port *port) const
////////////////////////////////////////////////////////////////
const char *
std::string
ConcreteNetwork::name(const Instance *instance) const
{
const ConcreteInstance *inst =
reinterpret_cast<const ConcreteInstance*>(instance);
return inst->name();
return std::string(inst->name());
}
ObjectId
@ -967,7 +970,7 @@ ConcreteNetwork::id(const Instance *instance) const
std::string
ConcreteNetwork::getAttribute(const Instance *inst,
const std::string &key) const
std::string_view key) const
{
const ConcreteInstance *cinst = reinterpret_cast<const ConcreteInstance*>(inst);
return cinst->getAttribute(key);
@ -1007,7 +1010,7 @@ ConcreteNetwork::isLeaf(const Instance *instance) const
Instance *
ConcreteNetwork::findChild(const Instance *parent,
const char *name) const
std::string_view name) const
{
const ConcreteInstance *inst =
reinterpret_cast<const ConcreteInstance*>(parent);
@ -1016,7 +1019,7 @@ ConcreteNetwork::findChild(const Instance *parent,
Pin *
ConcreteNetwork::findPin(const Instance *instance,
const char *port_name) const
std::string_view port_name) const
{
const ConcreteInstance *inst =
reinterpret_cast<const ConcreteInstance*>(instance);
@ -1034,7 +1037,7 @@ ConcreteNetwork::findPin(const Instance *instance,
Net *
ConcreteNetwork::findNet(const Instance *instance,
const char *net_name) const
std::string_view net_name) const
{
const ConcreteInstance *inst =
reinterpret_cast<const ConcreteInstance*>(instance);
@ -1164,11 +1167,11 @@ ConcreteNetwork::pin(const Term *term) const
////////////////////////////////////////////////////////////////
const char *
std::string
ConcreteNetwork::name(const Net *net) const
{
const ConcreteNet *cnet = reinterpret_cast<const ConcreteNet*>(net);
return cnet->name();
return std::string(cnet->name());
}
ObjectId
@ -1238,7 +1241,7 @@ ConcreteInstance::cell() const
Instance *
ConcreteNetwork::makeInstance(Cell *cell,
const char *name,
std::string_view name,
Instance *parent)
{
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell);
@ -1247,7 +1250,7 @@ ConcreteNetwork::makeInstance(Cell *cell,
Instance *
ConcreteNetwork::makeInstance(LibertyCell *cell,
const char *name,
std::string_view name,
Instance *parent)
{
return makeConcreteInstance(cell, name, parent);
@ -1255,7 +1258,7 @@ ConcreteNetwork::makeInstance(LibertyCell *cell,
Instance *
ConcreteNetwork::makeConcreteInstance(ConcreteCell *cell,
const char *name,
std::string_view name,
Instance *parent)
{
ConcreteInstance *cparent =
@ -1387,8 +1390,8 @@ ConcreteNetwork::connect(Instance *inst,
void
ConcreteNetwork::setAttribute(Instance *inst,
const std::string &key,
const std::string &value)
std::string_view key,
std::string_view value)
{
ConcreteInstance *cinst = reinterpret_cast<ConcreteInstance*>(inst);
cinst->setAttribute(key, value);
@ -1509,7 +1512,7 @@ ConcreteNetwork::deletePin(Pin *pin)
}
Net *
ConcreteNetwork::makeNet(const char *name,
ConcreteNetwork::makeNet(std::string_view name,
Instance *parent)
{
ConcreteInstance *cparent = reinterpret_cast<ConcreteInstance*>(parent);
@ -1608,10 +1611,10 @@ ConcreteNetwork::visitConnectedPins(const Net *net,
////////////////////////////////////////////////////////////////
ConcreteInstance::ConcreteInstance(const char *name,
ConcreteInstance::ConcreteInstance(std::string_view name,
ConcreteCell *cell,
ConcreteInstance *parent) :
name_(stringCopy(name)),
name_(name),
id_(ConcreteNetwork::nextObjectId()),
cell_(cell),
parent_(parent),
@ -1630,22 +1633,21 @@ ConcreteInstance::initPins()
ConcreteInstance::~ConcreteInstance()
{
stringDelete(name_);
delete children_;
delete nets_;
}
Instance *
ConcreteInstance::findChild(const char *name) const
ConcreteInstance::findChild(std::string_view name) const
{
if (children_)
return reinterpret_cast<Instance*>(findKey(children_, name));
return reinterpret_cast<Instance*>(findStringKey(*children_, name));
else
return nullptr;
}
ConcretePin *
ConcreteInstance::findPin(const char *port_name) const
ConcreteInstance::findPin(std::string_view port_name) const
{
ConcreteCell *ccell = reinterpret_cast<ConcreteCell*>(cell_);
const ConcretePort *cport =
@ -1669,11 +1671,11 @@ ConcreteInstance::findPin(const Port *port) const
}
ConcreteNet *
ConcreteInstance::findNet(const char *net_name) const
ConcreteInstance::findNet(std::string_view net_name) const
{
ConcreteNet *net = nullptr;
if (nets_) {
net = findKey(nets_, net_name);
net = findStringKey(*nets_, net_name);
// Follow merge pointer to surviving net.
if (net) {
while (net->mergedInto())
@ -1716,14 +1718,14 @@ ConcreteInstance::childIterator() const
}
void
ConcreteInstance::setAttribute(const std::string &key,
const std::string &value)
ConcreteInstance::setAttribute(std::string_view key,
std::string_view value)
{
attribute_map_[key] = value;
attribute_map_[std::string(key)] = value;
}
std::string
ConcreteInstance::getAttribute(const std::string &key) const
ConcreteInstance::getAttribute(std::string_view key) const
{
const auto &itr = attribute_map_.find(key);
if (itr != attribute_map_.end())
@ -1736,13 +1738,13 @@ ConcreteInstance::addChild(ConcreteInstance *child)
{
if (children_ == nullptr)
children_ = new ConcreteInstanceChildMap;
(*children_)[child->name()] = child;
(*children_)[child->name().data()] = child;
}
void
ConcreteInstance::deleteChild(ConcreteInstance *child)
{
children_->erase(child->name());
children_->erase(child->name().data());
}
void
@ -1767,22 +1769,22 @@ ConcreteInstance::addNet(ConcreteNet *net)
{
if (nets_ == nullptr)
nets_ = new ConcreteInstanceNetMap;
(*nets_)[net->name()] = net;
(*nets_)[net->name().data()] = net;
}
void
ConcreteInstance::addNet(const char *name,
ConcreteInstance::addNet(std::string_view,
ConcreteNet *net)
{
if (nets_ == nullptr)
nets_ = new ConcreteInstanceNetMap;
(*nets_)[name] = net;
(*nets_)[net->name().data()] = net;
}
void
ConcreteInstance::deleteNet(ConcreteNet *net)
{
nets_->erase(net->name());
nets_->erase(net->name().data());
}
void
@ -1807,7 +1809,7 @@ ConcretePin::ConcretePin(ConcreteInstance *instance,
{
}
const char *
std::string_view
ConcretePin::name() const
{
return port_->name();
@ -1821,7 +1823,7 @@ ConcretePin::setVertexId(VertexId id)
////////////////////////////////////////////////////////////////
const char *
std::string_view
ConcreteTerm::name() const
{
ConcretePin *cpin = reinterpret_cast<ConcretePin*>(pin_);
@ -1841,9 +1843,9 @@ ConcreteTerm::ConcreteTerm(ConcretePin *pin,
////////////////////////////////////////////////////////////////
ConcreteNet::ConcreteNet(const char *name,
ConcreteNet::ConcreteNet(std::string_view name,
ConcreteInstance *instance) :
name_(stringCopy(name)),
name_(name),
id_(ConcreteNetwork::nextObjectId()),
instance_(instance),
pins_(nullptr),
@ -1852,11 +1854,6 @@ ConcreteNet::ConcreteNet(const char *name,
{
}
ConcreteNet::~ConcreteNet()
{
stringDelete(name_);
}
// Merged nets are kept around to serve as name aliases.
// Only Instance::findNet and InstanceNetIterator need to know
// the net has been merged.
@ -1990,14 +1987,15 @@ ConcreteNetwork::setLinkFunc(LinkNetworkFunc link)
}
bool
ConcreteNetwork::linkNetwork(const char *top_cell_name,
ConcreteNetwork::linkNetwork(std::string_view top_cell_name,
bool make_black_boxes,
Report *report)
{
if (link_func_) {
clearConstantNets();
deleteTopInstance();
top_instance_ = link_func_(top_cell_name, make_black_boxes);
top_instance_ = link_func_(top_cell_name,
make_black_boxes);
if (top_instance_)
checkNetworkLibertyScenes();
return top_instance_ != nullptr;

View File

@ -25,6 +25,7 @@
#include "Network.hh"
#include <compare>
#include <set>
#include "ContainerHelpers.hh"
@ -79,7 +80,7 @@ Network::findPortsMatching(const Cell *cell,
parseBusName(pattern->pattern(), '[', ']', '\\',
is_bus, is_range, bus_name, from, to, subscript_wild);
if (is_bus) {
PatternMatch bus_pattern(bus_name.c_str(), pattern);
PatternMatch bus_pattern(bus_name, pattern);
CellPortIterator *port_iter = portIterator(cell);
while (port_iter->hasNext()) {
Port *port = port_iter->next();
@ -138,7 +139,7 @@ Network::readLibertyAfter(LibertyLibrary *)
}
LibertyCell *
Network::findLibertyCell(const char *name) const
Network::findLibertyCell(std::string_view name) const
{
LibertyLibraryIterator *iter = libertyLibraryIterator();
while (iter->hasNext()) {
@ -207,12 +208,12 @@ Network::checkNetworkLibertyScenes()
}
LibertyLibrary *
Network::findLibertyFilename(const char *filename)
Network::findLibertyFilename(std::string_view filename)
{
LibertyLibraryIterator *lib_iter = libertyLibraryIterator();
while (lib_iter->hasNext()) {
LibertyLibrary *lib = lib_iter->next();
if (stringEq(lib->filename(), filename)) {
if (lib->filename() == filename) {
delete lib_iter;
return lib;
}
@ -257,7 +258,7 @@ Network::hasMembers(const Port *port) const
return isBus(port) || isBundle(port);
}
const char *
std::string
Network::pathName(const Instance *instance) const
{
InstanceSeq inst_path;
@ -270,7 +271,7 @@ Network::pathName(const Instance *instance) const
if (!inst_path.empty())
path_name += pathDivider();
}
return makeTmpString(path_name);
return path_name;
}
bool
@ -298,9 +299,9 @@ Network::pathNameCmp(const Instance *inst1,
while (!path1.empty() && !path2.empty()) {
const Instance *inst1 = path1.back();
const Instance *inst2 = path2.back();
int cmp = strcmp(name(inst1), name(inst2));
auto cmp = name(inst1) <=> name(inst2);
if (cmp != 0)
return cmp;
return cmp < 0 ? -1 : 1;
path1.pop_back();
path2.pop_back();
}
@ -350,27 +351,27 @@ Network::isHierarchical(const Instance *instance) const
////////////////////////////////////////////////////////////////
const char *
std::string
Network::name(const Pin *pin) const
{
return pathName(pin);
}
const char *
std::string
Network::portName(const Pin *pin) const
{
return name(port(pin));
}
const char *
std::string
Network::pathName(const Pin *pin) const
{
const Instance *inst = instance(pin);
if (inst && inst != topInstance()) {
std::string path_name = pathName(inst);
std::string path_name(pathName(inst));
path_name += pathDivider();
path_name += portName(pin);
return makeTmpString(path_name);
return path_name;
}
else
return portName(pin);
@ -388,8 +389,14 @@ Network::pathNameCmp(const Pin *pin1,
const Pin *pin2) const
{
int inst_cmp = pathNameCmp(instance(pin1), instance(pin2));
if (inst_cmp == 0)
return strcmp(portName(pin1), portName(pin2));
if (inst_cmp == 0) {
auto cmp = portName(pin1) <=> portName(pin2);
if (cmp < 0)
return -1;
if (cmp > 0)
return 1;
return 0;
}
else
return inst_cmp;
}
@ -442,18 +449,18 @@ Network::pinLess(const Pin *pin1,
////////////////////////////////////////////////////////////////
const char *
std::string
Network::pathName(const Net *net) const
{
const Instance *inst = instance(net);
if (inst && inst != topInstance()) {
std::string path_name = pathName(inst);
std::string path_name(pathName(inst));
path_name += pathDivider();
path_name += name(net);
return makeTmpString(path_name);
return path_name;
}
else
return name(net);
return std::string(name(net));
}
bool
@ -468,8 +475,14 @@ Network::pathNameCmp(const Net *net1,
const Net *net2) const
{
int inst_cmp = pathNameCmp(instance(net1), instance(net2));
if (inst_cmp == 0)
return strcmp(name(net1), name(net2));
if (inst_cmp == 0) {
auto cmp = name(net1) <=> name(net2);
if (cmp < 0)
return -1;
if (cmp > 0)
return 1;
return 0;
}
else
return inst_cmp;
}
@ -506,7 +519,7 @@ Network::highestConnectedNet(Net *net) const
int level = hierarchyLevel(net1);
if (level < highest_level
|| (level == highest_level
&& stringLess(pathName(net1), pathName(highest_net)))) {
&& pathName(net1) < pathName(highest_net))) {
highest_net = net1;
highest_level = level;
}
@ -632,19 +645,19 @@ Network::isLatchData(const Pin *pin) const
////////////////////////////////////////////////////////////////
const char *
std::string
Network::name(const Term *term) const
{
return name(pin(term));
}
const char *
std::string
Network::pathName(const Term *term) const
{
return pathName(pin(term));
}
const char *
std::string
Network::portName(const Term *term) const
{
return portName(pin(term));
@ -652,40 +665,35 @@ Network::portName(const Term *term) const
////////////////////////////////////////////////////////////////
const char *
std::string
Network::cellName(const Instance *inst) const
{
return name(cell(inst));
}
Instance *
Network::findInstance(const char *path_name) const
Network::findInstance(std::string_view path_name) const
{
return findInstanceRelative(topInstance(), path_name);
}
Instance *
Network::findInstanceRelative(const Instance *inst,
const char *path_name) const
std::string_view path_name) const
{
char *first, *tail;
std::string first, tail;
pathNameFirst(path_name, first, tail);
if (first) {
if (!first.empty()) {
Instance *inst1 = findChild(inst, first);
stringDelete(first);
while (inst1 && tail) {
char *next_tail;
while (inst1 && !tail.empty()) {
std::string next_tail;
pathNameFirst(tail, first, next_tail);
if (first) {
if (!first.empty())
inst1 = findChild(inst1, first);
stringDelete(first);
}
else
inst1 = findChild(inst1, tail);
stringDelete(tail);
tail = next_tail;
}
stringDelete(tail);
return inst1;
}
else
@ -701,7 +709,7 @@ Network::findInstancesMatching(const Instance *context,
size_t context_name_length = 0;
if (context != topInstance())
// Add one for the trailing divider.
context_name_length = strlen(pathName(context)) + 1;
context_name_length = pathName(context).size() + 1;
findInstancesMatching1(context, context_name_length, pattern, matches);
}
else {
@ -721,9 +729,10 @@ Network::findInstancesMatching1(const Instance *context,
InstanceChildIterator *child_iter = childIterator(context);
while (child_iter->hasNext()) {
Instance *child = child_iter->next();
const char *child_name = pathName(child);
std::string child_name = pathName(child);
// Remove context prefix from the name.
const char *child_context_name = &child_name[context_name_length];
std::string_view child_context_name =
std::string_view(child_name).substr(context_name_length);
if (pattern->match(child_context_name))
matches.push_back(child);
if (!isLeaf(child))
@ -779,27 +788,22 @@ Network::findChildrenMatching(const Instance *parent,
}
Pin *
Network::findPin(const char *path_name) const
Network::findPin(std::string_view path_name) const
{
return findPinRelative(topInstance(), path_name);
}
Pin *
Network::findPinRelative(const Instance *inst,
const char *path_name) const
std::string_view path_name) const
{
char *inst_path, *port_name;
pathNameLast(path_name, inst_path, port_name);
if (inst_path) {
std::string inst_path, port_name;
std::string path_storage(path_name);
pathNameLast(path_storage, inst_path, port_name);
if (!inst_path.empty()) {
Instance *pin_inst = findInstanceRelative(inst, inst_path);
if (pin_inst) {
Pin *pin = findPin(pin_inst, port_name);
stringDelete(inst_path);
stringDelete(port_name);
return pin;
}
stringDelete(inst_path);
stringDelete(port_name);
if (pin_inst)
return findPin(pin_inst, port_name);
return nullptr;
}
else
@ -809,12 +813,12 @@ Network::findPinRelative(const Instance *inst,
Pin *
Network::findPinLinear(const Instance *instance,
const char *port_name) const
std::string_view port_name) const
{
InstancePinIterator *pin_iter = pinIterator(instance);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
if (stringEq(port_name, portName(pin))) {
if (port_name == portName(pin)) {
delete pin_iter;
return pin;
}
@ -838,27 +842,22 @@ Network::findPin(const Instance *instance,
}
Net *
Network::findNet(const char *path_name) const
Network::findNet(std::string_view path_name) const
{
return findNetRelative(topInstance(), path_name);
}
Net *
Network::findNetRelative(const Instance *inst,
const char *path_name) const
std::string_view path_name) const
{
char *inst_path, *net_name;
pathNameLast(path_name, inst_path, net_name);
if (inst_path) {
std::string inst_path, net_name;
std::string path_storage(path_name);
pathNameLast(path_storage, inst_path, net_name);
if (!inst_path.empty()) {
Instance *net_inst = findInstanceRelative(inst, inst_path);
if (net_inst) {
Net *net = findNet(net_inst, net_name);
stringDelete(inst_path);
stringDelete(net_name);
return net;
}
stringDelete(inst_path);
stringDelete(net_name);
if (net_inst)
return findNet(net_inst, net_name);
return nullptr;
}
else
@ -868,12 +867,12 @@ Network::findNetRelative(const Instance *inst,
Net *
Network::findNetLinear(const Instance *instance,
const char *net_name) const
std::string_view net_name) const
{
InstanceNetIterator *net_iter = netIterator(instance);
while (net_iter->hasNext()) {
Net *net = net_iter->next();
if (stringEq(name(net), net_name)) {
if (name(net) == net_name) {
delete net_iter;
return net;
}
@ -897,16 +896,14 @@ Network::findNetsMatching(const Instance *context,
NetSeq &matches) const
{
if (pattern->hasWildcards()) {
char *inst_path, *net_name;
std::string inst_path, net_name;
pathNameLast(pattern->pattern(), inst_path, net_name);
if (inst_path) {
if (!inst_path.empty()) {
PatternMatch inst_pattern(inst_path, pattern);
PatternMatch net_pattern(net_name, pattern);
InstanceSeq insts = findInstancesMatching(context, &inst_pattern);
for (const Instance *inst : insts)
findNetsMatching(inst, &net_pattern, matches);
stringDelete(inst_path);
stringDelete(net_name);
}
else
// Top level net.
@ -963,16 +960,14 @@ Network::findPinsMatching(const Instance *instance,
{
PinSeq matches;
if (pattern->hasWildcards()) {
char *inst_path, *port_name;
std::string inst_path, port_name;
pathNameLast(pattern->pattern(), inst_path, port_name);
if (inst_path) {
if (!inst_path.empty()) {
PatternMatch inst_pattern(inst_path, pattern);
PatternMatch port_pattern(port_name, pattern);
InstanceSeq insts = findInstancesMatching(instance, &inst_pattern);
for (const Instance *inst : insts)
findInstPinsMatching(inst, &port_pattern, matches);
stringDelete(inst_path);
stringDelete(port_name);
}
else
// Top level pin.
@ -1016,13 +1011,13 @@ Network::findInstPinsHierMatching(const Instance *instance,
// Return value.
PinSeq &matches) const
{
std::string inst_name = name(instance);
std::string inst_name(name(instance));
InstancePinIterator *pin_iter = pinIterator(instance);
while (pin_iter->hasNext()) {
const Pin *pin = pin_iter->next();
const char *port_name = name(port(pin));
std::string pin_name = inst_name + divider_ + port_name;
if (pattern->match(pin_name.c_str()))
std::string port_name = name(port(pin));
std::string pin_name = inst_name + divider_ + std::string(port_name);
if (pattern->match(pin_name))
matches.push_back(pin);
}
delete pin_iter;
@ -1601,64 +1596,54 @@ Network::drivers(const Net *net)
////////////////////////////////////////////////////////////////
void
Network::pathNameFirst(const char *path_name,
char *&first,
char *&tail) const
Network::pathNameFirst(std::string_view path_name,
std::string &first,
std::string &tail) const
{
first.clear();
tail.clear();
char escape = pathEscape();
char divider = pathDivider();
const char *d = strchr(path_name, divider);
// Skip escaped dividers.
while (d != nullptr
&& d > path_name
&& d[-1] == escape)
d = strchr(d + 1, divider);
if (d) {
first = new char[d - path_name + 1];
strncpy(first, path_name, d - path_name);
first[d - path_name] = '\0';
tail = new char[strlen(d)];
// Chop off the leading divider.
strcpy(tail, d + 1);
}
else {
// No divider in path_name.
first = nullptr;
tail = nullptr;
size_t i = 0;
while (i < path_name.size()) {
size_t d = path_name.find(divider, i);
while (d != std::string_view::npos && d > 0
&& path_name[d - 1] == escape)
d = path_name.find(divider, d + 1);
if (d != std::string_view::npos) {
first = path_name.substr(0, d);
tail = path_name.substr(d + 1);
return;
}
break;
}
}
void
Network::pathNameLast(const char *path_name,
char *&head,
char *&last) const
Network::pathNameLast(std::string_view path_name,
std::string &head,
std::string &last) const
{
head.clear();
last.clear();
char escape = pathEscape();
char divider = pathDivider();
const char *d = strrchr(path_name, divider);
// Search for a non-escaped divider.
if (d) {
while (d > path_name
&& (d[0] != divider
|| (d[0] == divider
&& d > &path_name[1]
&& d[-1] == escape)))
d--;
}
if (d && d != path_name) {
head = new char[d - path_name + 1];
strncpy(head, path_name, d - path_name);
head[d - path_name] = '\0';
last = new char[strlen(d)];
// Chop off the last divider.
strcpy(last, d + 1);
}
else {
// No divider in path_name.
head = nullptr;
last = nullptr;
size_t div_pos = path_name.rfind(divider);
size_t path_end = path_name.size();
while (div_pos > 0) {
if (div_pos == std::string_view::npos)
return;
if (path_name[div_pos - 1] != escape) {
// Found the last non-escaped divider.
head = path_name.substr(0, div_pos);
last = path_name.substr(div_pos + 1);
return;
}
path_end = div_pos - 1;
div_pos = path_name.rfind(divider, path_end);
}
}

View File

@ -24,8 +24,12 @@
%module network
%include <std_string.i>
%{
#include "Network.hh"
#include "StringUtil.hh"
#include <string>
%}
////////////////////////////////////////////////////////////////
@ -252,12 +256,12 @@ find_cells_matching(const char *pattern,
}
void
set_cmd_namespace_cmd(const char *namespc)
set_cmd_namespace_cmd(std::string namespc)
{
Sta *sta = Sta::sta();
if (stringEq(namespc, "sdc"))
if (namespc == "sdc")
sta->setCmdNamespace(CmdNamespace::sdc);
else if (stringEq(namespc, "sta"))
else if (namespc == "sta")
sta->setCmdNamespace(CmdNamespace::sta);
else
sta->report()->warn(2120, "unknown namespace");
@ -284,16 +288,16 @@ leaf_instance_iterator()
return network->leafInstanceIterator();
}
const char *
std::string_view
port_direction(const Port *port)
{
return Sta::sta()->ensureLinked()->direction(port)->name();
}
const char *
std::string
pin_direction(const Pin *pin)
{
return Sta::sta()->ensureLinked()->direction(pin)->name();
return std::string(Sta::sta()->ensureLinked()->direction(pin)->name());
}
PortSeq
@ -542,7 +546,7 @@ port_location(const Port *port)
////////////////////////////////////////////////////////////////
%extend Library {
const char *name()
std::string name()
{
return Sta::sta()->ensureLinked()->name(self);
}
@ -574,13 +578,13 @@ void finish() { delete self; }
} // LibraryIterator methods
%extend Cell {
const char *name() { return Sta::sta()->cmdNetwork()->name(self); }
std::string name() { return Sta::sta()->cmdNetwork()->name(self); }
Library *library() { return Sta::sta()->cmdNetwork()->library(self); }
LibertyCell *liberty_cell() { return Sta::sta()->cmdNetwork()->libertyCell(self); }
bool is_leaf() { return Sta::sta()->cmdNetwork()->isLeaf(self); }
CellPortIterator *
port_iterator() { return Sta::sta()->cmdNetwork()->portIterator(self); }
std::string
std::string
get_attribute(const char *key)
{
return Sta::sta()->cmdNetwork()->getAttribute(self, key);
@ -612,7 +616,7 @@ void finish() { delete self; }
} // CellPortIterator methods
%extend Port {
const char *bus_name() { return Sta::sta()->ensureLinked()->busName(self); }
std::string bus_name() { return Sta::sta()->ensureLinked()->busName(self); }
Cell *cell() { return Sta::sta()->ensureLinked()->cell(self); }
LibertyPort *liberty_port() { return Sta::sta()->ensureLibLinked()->libertyPort(self); }
bool is_bus() { return Sta::sta()->ensureLinked()->isBus(self); }
@ -678,7 +682,7 @@ void finish() { delete self; }
} // InstanceNetIterator methods
%extend Pin {
const char *port_name() { return Sta::sta()->ensureLinked()->portName(self); }
std::string port_name() { return Sta::sta()->ensureLinked()->portName(self); }
Instance *instance() { return Sta::sta()->ensureLinked()->instance(self); }
Net *net() { return Sta::sta()->ensureLinked()->net(self); }
Port *port() { return Sta::sta()->ensureLinked()->port(self); }

View File

@ -41,7 +41,7 @@ bool
PortNameLess::operator()(const Port *port1,
const Port *port2) const
{
return stringLess(network_->name(port1), network_->name(port2));
return network_->name(port1) < network_->name(port2);
}
PinPathNameLess::PinPathNameLess(const Network *network) :

View File

@ -30,13 +30,6 @@
namespace sta {
static std::string
escapeDividers(const char *token,
const Network *network);
static std::string
escapeBrackets(const char *token,
const Network *network);
NetworkNameAdapter::NetworkNameAdapter(Network *network) :
NetworkEdit(),
network_(network),
@ -45,7 +38,7 @@ NetworkNameAdapter::NetworkNameAdapter(Network *network) :
}
bool
NetworkNameAdapter::linkNetwork(const char *top_cell_name,
NetworkNameAdapter::linkNetwork(std::string_view top_cell_name,
bool make_black_boxes,
Report *report)
{
@ -77,24 +70,24 @@ NetworkNameAdapter::libertyLibraryIterator() const
}
Library *
NetworkNameAdapter::findLibrary(const char *name)
NetworkNameAdapter::findLibrary(std::string_view name)
{
return network_->findLibrary(name);
}
LibertyLibrary *
NetworkNameAdapter::findLiberty(const char *name)
NetworkNameAdapter::findLiberty(std::string_view name)
{
return network_->findLiberty(name);
}
LibertyLibrary *
NetworkNameAdapter::findLibertyFilename(const char *filename)
NetworkNameAdapter::findLibertyFilename(std::string_view filename)
{
return network_->findLibertyFilename(filename);
}
const char *
std::string
NetworkNameAdapter::name(const Library *library) const
{
return network_->name(library);
@ -108,7 +101,7 @@ NetworkNameAdapter::id(const Library *library) const
Cell *
NetworkNameAdapter::findCell(const Library *library,
const char *name) const
std::string_view name) const
{
return network_->findCell(library, name);
}
@ -122,7 +115,7 @@ NetworkNameAdapter::findCellsMatching(const Library *library,
////////////////////////////////////////////////////////////////
const char *
std::string
NetworkNameAdapter::name(const Cell *cell) const
{
return network_->name(cell);
@ -136,7 +129,7 @@ NetworkNameAdapter::id(const Cell *cell) const
std::string
NetworkNameAdapter::getAttribute(const Cell *cell,
const std::string &key) const
std::string_view key) const
{
return network_->getAttribute(cell, key);
}
@ -153,8 +146,8 @@ NetworkNameAdapter::library(const Cell *cell) const
return network_->library(cell);
}
const char *
NetworkNameAdapter::filename(const Cell *cell)
std::string_view
NetworkNameAdapter::filename(const Cell *cell) const
{
return network_->filename(cell);
}
@ -185,7 +178,7 @@ NetworkNameAdapter::cell(const LibertyCell *cell) const
Port *
NetworkNameAdapter::findPort(const Cell *cell,
const char *name) const
std::string_view name) const
{
return network_->findPort(cell, name);
}
@ -223,7 +216,7 @@ NetworkNameAdapter::portBitCount(const Cell *cell) const
////////////////////////////////////////////////////////////////
const char *
std::string
NetworkNameAdapter::name(const Port *port) const
{
return network_->name(port);
@ -288,7 +281,7 @@ NetworkNameAdapter::isBus(const Port *port) const
return network_->isBus(port);
}
const char *
std::string
NetworkNameAdapter::busName(const Port *port) const
{
return network_->busName(port);
@ -354,7 +347,7 @@ NetworkNameAdapter::cell(const Instance *instance) const
std::string
NetworkNameAdapter::getAttribute(const Instance *inst,
const std::string &key) const
std::string_view key) const
{
return network_->getAttribute(inst, key);
}
@ -537,15 +530,15 @@ NetworkNameAdapter::isEditable() const
LibertyLibrary *
NetworkNameAdapter::makeLibertyLibrary(const char *name,
const char *filename)
NetworkNameAdapter::makeLibertyLibrary(std::string_view name,
std::string_view filename)
{
return network_edit_->makeLibertyLibrary(name, filename);
}
Instance *
NetworkNameAdapter::makeInstance(LibertyCell *cell,
const char *name,
std::string_view name,
Instance *parent)
{
return network_edit_->makeInstance(cell, name, parent);
@ -571,7 +564,7 @@ NetworkNameAdapter::mergedInto(Net *net)
}
Net *
NetworkNameAdapter::makeNet(const char *name,
NetworkNameAdapter::makeNet(std::string_view name,
Instance *parent)
{
return network_edit_->makeNet(name, parent);
@ -639,7 +632,7 @@ SdcNetwork::SdcNetwork(Network *network) :
// Translate sta namespace to sdc namespace.
// Remove all escapes.
const char *
std::string
SdcNetwork::staToSdc(std::string_view sta_name) const
{
char escape = pathEscape();
@ -660,12 +653,12 @@ SdcNetwork::staToSdc(std::string_view sta_name) const
// Non escape.
sdc_name += ch;
}
return makeTmpString(sdc_name);
return sdc_name;
}
Port *
SdcNetwork::findPort(const Cell *cell,
const char *name) const
std::string_view name) const
{
Port *port = network_->findPort(cell, name);
if (port == nullptr) {
@ -675,22 +668,22 @@ SdcNetwork::findPort(const Cell *cell,
int index;
parseBusName(name, '[', ']', pathEscape(), is_bus, bus_name, index);
if (is_bus) {
std::string escaped1 = escapeBrackets(name, this);
port = network_->findPort(cell, escaped1.c_str());
std::string escaped1 = escapeBrackets(std::string(name), this);
port = network_->findPort(cell, escaped1);
if (port == nullptr) {
// Try escaping base foo\[0\][1]
std::string escaped_bus_name = escapeBrackets(bus_name.c_str(), this);
std::string escaped_bus_name = escapeBrackets(bus_name, this);
std::string escaped2 = escaped_bus_name
+ '['
+ std::to_string(index)
+ ']';
port = network_->findPort(cell, escaped2.c_str());
port = network_->findPort(cell, escaped2);
}
}
else {
// Try escaping brackets foo\[0\].bar
std::string escaped = escapeBrackets(name, this);
port = network_->findPort(cell, escaped.c_str());
std::string escaped = escapeBrackets(std::string(name), this);
port = network_->findPort(cell, escaped);
}
}
return port;
@ -710,71 +703,71 @@ SdcNetwork::findPortsMatching(const Cell *cell,
is_bus, bus_name, index);
if (is_bus) {
std::string escaped1 = escapeBrackets(pattern->pattern(), this);
PatternMatch escaped_pattern1(escaped1.c_str(), pattern);
PatternMatch escaped_pattern1(escaped1, pattern);
matches = network_->findPortsMatching(cell, &escaped_pattern1);
if (matches.empty()) {
// Try escaping base foo\[0\][1]
std::string escaped_name = escapeBrackets(bus_name.c_str(), this);
std::string escaped_name = escapeBrackets(bus_name, this);
escaped_name += '[';
escaped_name += std::to_string(index);
escaped_name += ']';
PatternMatch escaped_pattern2(escaped_name.c_str(), pattern);
PatternMatch escaped_pattern2(escaped_name, pattern);
matches = network_->findPortsMatching(cell, &escaped_pattern2);
}
}
else {
// Try escaping brackets foo\[0\].bar
std::string escaped = escapeBrackets(pattern->pattern(), this);
PatternMatch escaped_pattern(escaped.c_str(), pattern);
PatternMatch escaped_pattern(escaped, pattern);
matches = network_->findPortsMatching(cell, &escaped_pattern);
}
}
return matches;
}
const char *
std::string
SdcNetwork::name(const Port *port) const
{
return staToSdc(network_->name(port));
}
const char *
std::string
SdcNetwork::busName(const Port *port) const
{
return staToSdc(network_->busName(port));
}
const char *
std::string
SdcNetwork::name(const Instance *instance) const
{
return staToSdc(network_->name(instance));
}
const char *
std::string
SdcNetwork::pathName(const Instance *instance) const
{
return staToSdc(network_->pathName(instance));
}
const char *
std::string
SdcNetwork::pathName(const Pin *pin) const
{
return staToSdc(network_->pathName(pin));
}
const char *
std::string
SdcNetwork::portName(const Pin *pin) const
{
return staToSdc(network_->portName(pin));
}
const char *
std::string
SdcNetwork::name(const Net *net) const
{
return staToSdc(network_->name(net));
}
const char *
std::string
SdcNetwork::pathName(const Net *net) const
{
return staToSdc(network_->pathName(net));
@ -783,9 +776,9 @@ SdcNetwork::pathName(const Net *net) const
////////////////////////////////////////////////////////////////
Instance *
SdcNetwork::findInstance(const char *path_name) const
SdcNetwork::findInstance(std::string_view path_name) const
{
const char *child_name;
std::string child_name;
Instance *parent;
parsePath(path_name, parent, child_name);
if (parent == nullptr)
@ -793,22 +786,22 @@ SdcNetwork::findInstance(const char *path_name) const
Instance *child = findChild(parent, child_name);
if (child == nullptr) {
std::string escaped_name = escapeDividers(child_name, this);
child = findChild(parent, escaped_name.c_str());
child = findChild(parent, escaped_name);
}
return child;
}
Instance *
SdcNetwork::findInstanceRelative(const Instance *inst,
const char *path_name) const
std::string_view path_name) const
{
Instance *inst1 = network_->findInstanceRelative(inst, path_name);
if (inst1 == nullptr) {
std::string path_name1 = escapeBrackets(path_name, this);
inst1 = network_->findInstanceRelative(inst, path_name1.c_str());
std::string path_name1 = escapeBrackets(std::string(path_name), this);
inst1 = network_->findInstanceRelative(inst, path_name1);
if (inst1 == nullptr) {
std::string path_name2 = escapeDividers(path_name1.c_str(), network_);
inst1 = network_->findInstanceRelative(inst, path_name2.c_str());
std::string path_name2 = escapeDividers(path_name1, network_);
inst1 = network_->findInstanceRelative(inst, path_name2);
}
}
return inst1;
@ -840,12 +833,12 @@ SdcNetwork::findInstancesMatching1(const Instance *context,
Instance *
SdcNetwork::findChild(const Instance *parent,
const char *name) const
std::string_view name) const
{
Instance *child = network_->findChild(parent, name);
if (child == nullptr) {
std::string escaped = escapeBrackets(name, this);
child = network_->findChild(parent, escaped.c_str());
std::string escaped = escapeBrackets(std::string(name), this);
child = network_->findChild(parent, escaped);
}
return child;
}
@ -853,9 +846,9 @@ SdcNetwork::findChild(const Instance *parent,
////////////////////////////////////////////////////////////////
Net *
SdcNetwork::findNet(const char *path_name) const
SdcNetwork::findNet(std::string_view path_name) const
{
const char *net_name;
std::string net_name;
Instance *inst;
parsePath(path_name, inst, net_name);
if (inst == nullptr)
@ -865,33 +858,33 @@ SdcNetwork::findNet(const char *path_name) const
Net *
SdcNetwork::findNet(const Instance *instance,
const char *net_name) const
std::string_view net_name) const
{
Net *net = network_->findNet(instance, net_name);
if (net == nullptr) {
std::string net_name1 = escapeBrackets(net_name, this);
std::string net_name2 = escapeDividers(net_name1.c_str(), network_);
net = network_->findNet(instance, net_name2.c_str());
std::string net_name1 = escapeBrackets(std::string(net_name), this);
std::string net_name2 = escapeDividers(net_name1, network_);
net = network_->findNet(instance, net_name2);
}
return net;
}
Net *
SdcNetwork::findNetRelative(const Instance *inst,
const char *path_name) const
std::string_view path_name) const
{
Net *net = network_->findNetRelative(inst, path_name);
if (net == nullptr) {
std::string path_name1 = escapeDividers(path_name, network_);
net = network_->findNetRelative(inst, path_name1.c_str());
std::string path_name1 = escapeDividers(std::string(path_name), network_);
net = network_->findNetRelative(inst, path_name1);
if (net == nullptr) {
std::string path_name2 = escapeBrackets(path_name, network_);
net = network_->findNetRelative(inst, path_name2.c_str());
std::string path_name2 = escapeBrackets(std::string(path_name), network_);
net = network_->findNetRelative(inst, path_name2);
if (net == nullptr) {
std::string path_name3 = escapeDividers(path_name2.c_str(), network_);
net = network_->findNetRelative(inst, path_name3.c_str());
std::string path_name3 = escapeDividers(path_name2, network_);
net = network_->findNetRelative(inst, path_name3);
}
}
}
@ -923,12 +916,12 @@ SdcNetwork::findInstNetsMatching(const Instance *instance,
if (matches.empty()) {
// Look for matches after escaping path dividers.
std::string escaped_pattern = escapeDividers(pattern->pattern(), this);
const PatternMatch escaped_dividers(escaped_pattern.c_str(), pattern);
const PatternMatch escaped_dividers(escaped_pattern, pattern);
network_->findInstNetsMatching(instance, &escaped_dividers, matches);
if (matches.empty()) {
// Look for matches after escaping brackets.
std::string escaped_pattern2 = escapeBrackets(pattern->pattern(),this);
const PatternMatch escaped_brkts(escaped_pattern2.c_str(), pattern);
const PatternMatch escaped_brkts(escaped_pattern2, pattern);
network_->findInstNetsMatching(instance, &escaped_brkts, matches);
}
}
@ -937,9 +930,9 @@ SdcNetwork::findInstNetsMatching(const Instance *instance,
////////////////////////////////////////////////////////////////
Pin *
SdcNetwork::findPin(const char *path_name) const
SdcNetwork::findPin(std::string_view path_name) const
{
const char *port_name;
std::string port_name;
Instance *inst;
parsePath(path_name, inst, port_name);
if (inst == nullptr)
@ -949,7 +942,7 @@ SdcNetwork::findPin(const char *path_name) const
Pin *
SdcNetwork::findPin(const Instance *instance,
const char *port_name) const
std::string_view port_name) const
{
Pin *pin = network_->findPin(instance, port_name);
if (pin == nullptr) {
@ -960,22 +953,22 @@ SdcNetwork::findPin(const Instance *instance,
parseBusName(port_name, '[', ']', pathEscape(),
is_bus, bus_name, index);
if (is_bus) {
std::string escaped1 = escapeBrackets(port_name, this);
pin = network_->findPin(instance, escaped1.c_str());
std::string escaped1 = escapeBrackets(std::string(port_name), this);
pin = network_->findPin(instance, escaped1);
if (pin == nullptr) {
// Try escaping base foo\[0\][1]
std::string escaped_bus_name = escapeBrackets(bus_name.c_str(), this);
std::string escaped_bus_name = escapeBrackets(bus_name, this);
std::string escaped2 = escaped_bus_name
+ '['
+ std::to_string(index)
+ ']';
pin = network_->findPin(instance, escaped2.c_str());
pin = network_->findPin(instance, escaped2);
}
}
else {
// Try escaping port brackets foo\[0\].bar
std::string escaped = escapeBrackets(port_name, this);
pin = network_->findPin(instance, escaped.c_str());
std::string escaped = escapeBrackets(std::string(port_name), this);
pin = network_->findPin(instance, escaped);
}
}
return pin;
@ -987,7 +980,7 @@ SdcNetwork::findPinsMatching(const Instance *instance,
const PatternMatch *pattern) const
{
PinSeq matches;
if (stringEq(pattern->pattern(), "*")) {
if (pattern->pattern() == "*") {
// Pattern of '*' matches all child instance pins.
InstanceChildIterator *child_iter = childIterator(instance);
while (child_iter->hasNext()) {
@ -1022,11 +1015,12 @@ SdcNetwork::visitPinTail(const Instance *instance,
CellPortIterator *port_iter = network_->portIterator(cell);
while (port_iter->hasNext()) {
Port *port = port_iter->next();
const char *port_name = network_->name(port);
std::string port_name = network_->name(port);
if (network_->hasMembers(port)) {
bool bus_matches = tail->match(port_name);
if (!bus_matches) {
std::string escaped_name = escapeDividers(port_name, network_);
std::string escaped_name = escapeDividers(std::string(port_name),
network_);
bus_matches = tail->match(escaped_name);
}
PortMemberIterator *member_iter = network_->memberIterator(port);
@ -1039,10 +1033,11 @@ SdcNetwork::visitPinTail(const Instance *instance,
found_match = true;
}
else {
const char *member_name = network_->name(member_port);
std::string member_name = network_->name(member_port);
bool member_matches = tail->match(member_name);
if (!member_matches) {
std::string escaped_name = escapeDividers(member_name, network_);
std::string escaped_name = escapeDividers(std::string(member_name),
network_);
member_matches = tail->match(escaped_name);
}
if (member_matches) {
@ -1057,7 +1052,8 @@ SdcNetwork::visitPinTail(const Instance *instance,
else {
bool port_matches = tail->match(port_name);
if (!port_matches) {
std::string escaped_name = escapeDividers(port_name, network_);
std::string escaped_name = escapeDividers(std::string(port_name),
network_);
port_matches = tail->match(escaped_name);
}
if (port_matches) {
@ -1076,19 +1072,19 @@ SdcNetwork::visitPinTail(const Instance *instance,
Instance *
SdcNetwork::makeInstance(LibertyCell *cell,
const char *name,
std::string_view name,
Instance *parent)
{
std::string escaped_name = escapeDividers(name, this);
return network_edit_->makeInstance(cell, escaped_name.c_str(), parent);
std::string escaped_name = escapeDividers(std::string(name), this);
return network_edit_->makeInstance(cell, escaped_name, parent);
}
Net *
SdcNetwork::makeNet(const char *name,
SdcNetwork::makeNet(std::string_view name,
Instance *parent)
{
std::string escaped_name = escapeDividers(name, this);
return network_edit_->makeNet(escaped_name.c_str(), parent);
std::string escaped_name = escapeDividers(std::string(name), this);
return network_edit_->makeNet(escaped_name, parent);
}
////////////////////////////////////////////////////////////////
@ -1101,10 +1097,10 @@ SdcNetwork::makeNet(const char *name,
// a\/b
// a\/b\/c
void
SdcNetwork::parsePath(const char *path,
SdcNetwork::parsePath(std::string_view path,
// Return values.
Instance *&inst,
const char *&path_tail) const
std::string &path_tail) const
{
int divider_count, path_length;
scanPath(path, divider_count, path_length);
@ -1118,7 +1114,7 @@ SdcNetwork::parsePath(const char *path,
// Scan the path for unescaped dividers.
void
SdcNetwork::scanPath(const char *path,
SdcNetwork::scanPath(std::string_view path,
// Return values.
// Unescaped divider count.
int &divider_count,
@ -1126,12 +1122,12 @@ SdcNetwork::scanPath(const char *path,
{
divider_count = 0;
path_length = 0;
for (const char *s = path; *s; s++) {
char ch = *s;
for (size_t i = 0; i < path.size(); i++) {
char ch = path[i];
if (ch == escape_) {
// Make sure we don't skip the null if escape is the last char.
if (s[1] != '\0') {
s++;
if (i != path.size() - 1) {
i++;
path_length++;
}
}
@ -1142,37 +1138,37 @@ SdcNetwork::scanPath(const char *path,
}
void
SdcNetwork::parsePath(const char *path,
SdcNetwork::parsePath(std::string_view path,
int divider_count,
int path_length,
// Return values.
Instance *&inst,
const char *&path_tail) const
std::string &path_tail) const
{
Instance *parent = topInstance();
std::string inst_path;
// Leave room to escape all the dividers and '\0'.
inst_path.reserve(path_length + divider_count + 1);
// Leave room to escape all the dividers.
inst_path.reserve(path_length + divider_count);
inst = nullptr;
path_tail = path;
for (const char *s = path; *s; s++) {
char ch = *s;
for (size_t i = 0; i < path.size(); i++) {
char ch = path[i];
if (ch == escape_) {
// Make sure we don't skip the null if escape is the last char.
if (s[1] != '\0') {
if (i < path.size() - 1) {
inst_path += ch;
inst_path += s[1];
s++;
inst_path += path[i + 1];
i++;
}
}
else if (ch == divider_) {
Instance *child = findChild(parent, inst_path.c_str());
Instance *child = findChild(parent, inst_path);
if (child) {
// Found an instance for the sub-path up to this divider.
parent = inst = child;
// Reset the instance path.
inst_path.clear();
path_tail = s + 1;
path_tail = path.substr(i + 1);
}
else {
// No match for sub-path. Escape the divider and keep looking.
@ -1206,29 +1202,30 @@ SdcNetwork::visitMatches(const Instance *parent,
inst_path.reserve(path_length + divider_count + 1);
bool has_brkts = false;
bool found_match = false;
for (const char *s = pattern->pattern(); *s; s++) {
char ch = *s;
const std::string &pattern_str = pattern->pattern();
for (size_t i = 0; i < pattern_str.size(); i++) {
char ch = pattern_str[i];
if (ch == escape_) {
// Make sure we don't skip the null if escape is the last char.
if (s[1] != '\0') {
if (i < pattern_str.size() - 1) {
inst_path += ch;
inst_path += s[1];
s++;
inst_path += pattern_str[i + 1];
i++;
}
}
else if (ch == divider_) {
PatternMatch matcher(inst_path.c_str(), pattern);
PatternMatch matcher(inst_path, pattern);
InstanceSeq matches;
network_->findChildrenMatching(parent, &matcher, matches);
if (has_brkts && matches.empty()) {
// Look for matches after escaping brackets.
std::string escaped_brkts = escapeBrackets(inst_path.c_str(), this);
std::string escaped_brkts = escapeBrackets(inst_path, this);
const PatternMatch escaped_pattern(escaped_brkts, pattern);
network_->findChildrenMatching(parent, &escaped_pattern, matches);
}
if (!matches.empty()) {
// Found instance matches for the sub-path up to this divider.
const PatternMatch tail_pattern(s + 1, pattern);
const PatternMatch tail_pattern(pattern_str.substr(i + 1), pattern);
for (const Instance *match : matches)
// Recurse to save the iterator state so we can iterate over
// multiple nested partial matches.
@ -1245,11 +1242,11 @@ SdcNetwork::visitMatches(const Instance *parent,
}
}
if (!found_match) {
PatternMatch tail_pattern(inst_path.c_str(), pattern);
PatternMatch tail_pattern(inst_path, pattern);
found_match |= visit_tail(parent, &tail_pattern);
if (!found_match && has_brkts) {
// Look for matches after escaping brackets.
std::string escaped_path = escapeBrackets(inst_path.c_str(), this);
std::string escaped_path = escapeBrackets(inst_path, this);
const PatternMatch escaped_tail(escaped_path, pattern);
found_match |= visit_tail(parent, &escaped_tail);
}
@ -1259,19 +1256,19 @@ SdcNetwork::visitMatches(const Instance *parent,
////////////////////////////////////////////////////////////////
static std::string
escapeDividers(const char *token,
std::string
escapeDividers(std::string_view name,
const Network *network)
{
return escapeChars(token, network->pathDivider(), '\0',
return escapeChars(name, network->pathDivider(), '\0',
network->pathEscape());
}
static std::string
escapeBrackets(const char *token,
std::string
escapeBrackets(std::string_view name,
const Network *network)
{
return escapeChars(token, '[', ']', network->pathEscape());
return escapeChars(name, '[', ']', network->pathEscape());
}
} // namespace

View File

@ -58,9 +58,9 @@ netVerilogName(std::string sta_name)
bool is_bus;
std::string bus_name;
int index;
parseBusName(sta_name.c_str(), '[', ']', verilog_escape, is_bus, bus_name, index);
parseBusName(sta_name, '[', ']', verilog_escape, is_bus, bus_name, index);
if (is_bus) {
std::string bus_vname = staToVerilog(bus_name.c_str());
std::string bus_vname = staToVerilog(bus_name);
std::string vname = bus_vname + '[' + std::to_string(index) + ']';
return vname;
}

View File

@ -1,5 +1,6 @@
#include <gtest/gtest.h>
#include <string>
#include <string_view>
#include "VerilogNamespace.hh"
#include "PortDirection.hh"
#include "ConcreteLibrary.hh"
@ -97,7 +98,7 @@ protected:
TEST_F(PortDirectionTest, InputSingleton) {
PortDirection *dir = PortDirection::input();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "input");
EXPECT_EQ(dir->name(), "input");
EXPECT_EQ(dir->index(), 0);
EXPECT_TRUE(dir->isInput());
EXPECT_FALSE(dir->isOutput());
@ -112,7 +113,7 @@ TEST_F(PortDirectionTest, InputSingleton) {
TEST_F(PortDirectionTest, OutputSingleton) {
PortDirection *dir = PortDirection::output();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "output");
EXPECT_EQ(dir->name(), "output");
EXPECT_EQ(dir->index(), 1);
EXPECT_TRUE(dir->isOutput());
EXPECT_FALSE(dir->isInput());
@ -121,7 +122,7 @@ TEST_F(PortDirectionTest, OutputSingleton) {
TEST_F(PortDirectionTest, TristateSingleton) {
PortDirection *dir = PortDirection::tristate();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "tristate");
EXPECT_EQ(dir->name(), "tristate");
EXPECT_EQ(dir->index(), 2);
EXPECT_TRUE(dir->isTristate());
EXPECT_FALSE(dir->isInput());
@ -131,7 +132,7 @@ TEST_F(PortDirectionTest, TristateSingleton) {
TEST_F(PortDirectionTest, BidirectSingleton) {
PortDirection *dir = PortDirection::bidirect();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "bidirect");
EXPECT_EQ(dir->name(), "bidirect");
EXPECT_EQ(dir->index(), 3);
EXPECT_TRUE(dir->isBidirect());
}
@ -139,7 +140,7 @@ TEST_F(PortDirectionTest, BidirectSingleton) {
TEST_F(PortDirectionTest, InternalSingleton) {
PortDirection *dir = PortDirection::internal();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "internal");
EXPECT_EQ(dir->name(), "internal");
EXPECT_EQ(dir->index(), 4);
EXPECT_TRUE(dir->isInternal());
}
@ -147,7 +148,7 @@ TEST_F(PortDirectionTest, InternalSingleton) {
TEST_F(PortDirectionTest, GroundSingleton) {
PortDirection *dir = PortDirection::ground();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "ground");
EXPECT_EQ(dir->name(), "ground");
EXPECT_EQ(dir->index(), 5);
EXPECT_TRUE(dir->isGround());
}
@ -155,7 +156,7 @@ TEST_F(PortDirectionTest, GroundSingleton) {
TEST_F(PortDirectionTest, PowerSingleton) {
PortDirection *dir = PortDirection::power();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "power");
EXPECT_EQ(dir->name(), "power");
EXPECT_EQ(dir->index(), 6);
EXPECT_TRUE(dir->isPower());
}
@ -163,7 +164,7 @@ TEST_F(PortDirectionTest, PowerSingleton) {
TEST_F(PortDirectionTest, UnknownSingleton) {
PortDirection *dir = PortDirection::unknown();
EXPECT_NE(dir, nullptr);
EXPECT_STREQ(dir->name(), "unknown");
EXPECT_EQ(dir->name(), "unknown");
EXPECT_EQ(dir->index(), 7);
EXPECT_TRUE(dir->isUnknown());
}
@ -229,8 +230,8 @@ TEST_F(PortDirectionTest, IsPowerGround) {
TEST(ConcreteLibraryTest, CreateAndFind) {
ConcreteLibrary lib("test_lib", "test.lib", false);
EXPECT_STREQ(lib.name(), "test_lib");
EXPECT_STREQ(lib.filename(), "test.lib");
EXPECT_EQ(lib.name(), "test_lib");
EXPECT_EQ(lib.filename(), "test.lib");
EXPECT_FALSE(lib.isLiberty());
}
@ -245,8 +246,8 @@ TEST(ConcreteLibraryTest, MakeCell) {
ConcreteLibrary lib("test_lib", "test.lib", false);
ConcreteCell *cell = lib.makeCell("INV", true, "inv.v");
EXPECT_NE(cell, nullptr);
EXPECT_STREQ(cell->name(), "INV");
EXPECT_STREQ(cell->filename(), "inv.v");
EXPECT_EQ(cell->name(), "INV");
EXPECT_EQ(cell->filename(), "inv.v");
EXPECT_TRUE(cell->isLeaf());
EXPECT_EQ(cell->library(), &lib);
@ -299,7 +300,7 @@ TEST(ConcreteCellTest, MakePort) {
ConcreteCell *cell = lib.makeCell("INV", true, "");
ConcretePort *port_a = cell->makePort("A");
EXPECT_NE(port_a, nullptr);
EXPECT_STREQ(port_a->name(), "A");
EXPECT_EQ(port_a->name(), "A");
EXPECT_EQ(port_a->cell(), reinterpret_cast<Cell*>(cell));
ConcretePort *found = cell->findPort("A");
@ -357,9 +358,9 @@ TEST(ConcreteCellTest, AttributeMap) {
TEST(ConcreteCellTest, SetName) {
ConcreteLibrary lib("test_lib", "test.lib", false);
ConcreteCell *cell = lib.makeCell("OLD", true, "");
EXPECT_STREQ(cell->name(), "OLD");
EXPECT_EQ(cell->name(), "OLD");
cell->setName("NEW");
EXPECT_STREQ(cell->name(), "NEW");
EXPECT_EQ(cell->name(), "NEW");
}
TEST(ConcreteCellTest, PortIterator) {
@ -646,10 +647,10 @@ TEST(ConcreteCellTest, MakeBusPortAscending) {
TEST(ConcreteCellTest, Filename) {
ConcreteLibrary lib("test_lib", "test.lib", false);
ConcreteCell *cell = lib.makeCell("INV", true, "test_cell.v");
EXPECT_STREQ(cell->filename(), "test_cell.v");
EXPECT_EQ(cell->filename(), "test_cell.v");
ConcreteCell *cell2 = lib.makeCell("BUF", true, "");
EXPECT_STREQ(cell2->filename(), "");
EXPECT_EQ(cell2->filename(), "");
}
TEST(ConcreteCellTest, FindCellsMatching) {
@ -692,8 +693,8 @@ TEST(ConcretePortTest, BusPortBusName) {
lib.setBusBrkts('[', ']');
ConcreteCell *cell = lib.makeCell("REG", true, "");
ConcretePort *bus = cell->makeBusPort("D", 3, 0);
const char *bus_name = bus->busName();
EXPECT_NE(bus_name, nullptr);
std::string bus_name = bus->busName();
EXPECT_FALSE(bus_name.empty());
// Should contain bus bracket notation
std::string name_str(bus_name);
EXPECT_NE(name_str.find("["), std::string::npos);
@ -704,8 +705,8 @@ TEST(ConcretePortTest, ScalarBusName) {
ConcreteCell *cell = lib.makeCell("INV", true, "");
ConcretePort *port = cell->makePort("A");
// Scalar port busName returns just the name
const char *bus_name = port->busName();
EXPECT_STREQ(bus_name, "A");
std::string bus_name = port->busName();
EXPECT_EQ(bus_name, "A");
}
TEST(ConcretePortTest, FindMember) {
@ -830,7 +831,7 @@ TEST(ConcreteLibraryTest, BusBracketsChange) {
TEST(ConcreteLibraryTest, FilenameAndId) {
ConcreteLibrary lib("test_lib", "test.lib", false);
EXPECT_STREQ(lib.filename(), "test.lib");
EXPECT_EQ(lib.filename(), "test.lib");
// Library ID is a monotonically increasing counter
EXPECT_GE(lib.id(), 0u);
}
@ -878,14 +879,14 @@ TEST(PortDirectionExtraTest, DirectionNames) {
if (PortDirection::input() == nullptr) {
PortDirection::init();
}
EXPECT_STREQ(PortDirection::input()->name(), "input");
EXPECT_STREQ(PortDirection::output()->name(), "output");
EXPECT_STREQ(PortDirection::bidirect()->name(), "bidirect");
EXPECT_STREQ(PortDirection::tristate()->name(), "tristate");
EXPECT_STREQ(PortDirection::internal()->name(), "internal");
EXPECT_STREQ(PortDirection::ground()->name(), "ground");
EXPECT_STREQ(PortDirection::power()->name(), "power");
EXPECT_STREQ(PortDirection::unknown()->name(), "unknown");
EXPECT_EQ(PortDirection::input()->name(), "input");
EXPECT_EQ(PortDirection::output()->name(), "output");
EXPECT_EQ(PortDirection::bidirect()->name(), "bidirect");
EXPECT_EQ(PortDirection::tristate()->name(), "tristate");
EXPECT_EQ(PortDirection::internal()->name(), "internal");
EXPECT_EQ(PortDirection::ground()->name(), "ground");
EXPECT_EQ(PortDirection::power()->name(), "power");
EXPECT_EQ(PortDirection::unknown()->name(), "unknown");
}
TEST(PortDirectionExtraTest, FindAllByName) {
@ -940,7 +941,7 @@ TEST(ConcreteCellTest, GroupBusPorts) {
cell->makePort("CLK");
// groupBusPorts should group D[0]-D[3] into bus D
cell->groupBusPorts('[', ']', [](const char*) { return true; });
cell->groupBusPorts('[', ']', [](std::string_view) { return true; });
// After grouping, we should find the bus port D
ConcretePort *bus = cell->findPort("D");
@ -969,7 +970,7 @@ TEST(ConcreteNetworkTest, MakeLibrary) {
EXPECT_EQ(found, lib);
// Library name
EXPECT_STREQ(network.name(lib), "test_lib");
EXPECT_EQ(network.name(lib), "test_lib");
}
TEST(ConcreteNetworkTest, LibraryIterator) {
@ -1008,7 +1009,7 @@ TEST(ConcreteNetworkTest, CellName) {
Cell *cell = network.findCell(lib, "INV_X1");
EXPECT_NE(cell, nullptr);
EXPECT_STREQ(network.name(cell), "INV_X1");
EXPECT_EQ(network.name(cell), "INV_X1");
}
TEST(ConcreteNetworkTest, CellIsLeaf) {
@ -1052,7 +1053,7 @@ TEST(ConcreteNetworkTest, PortProperties) {
ConcretePort *a = ccell->makePort("A");
Port *port = reinterpret_cast<Port*>(a);
EXPECT_STREQ(network.name(port), "A");
EXPECT_EQ(network.name(port), "A");
EXPECT_FALSE(network.isBus(port));
EXPECT_FALSE(network.isBundle(port));
}
@ -1068,7 +1069,7 @@ TEST(ConcreteNetworkTest, FindPort) {
Cell *cell = reinterpret_cast<Cell*>(ccell);
Port *found = network.findPort(cell, "A");
EXPECT_NE(found, nullptr);
EXPECT_STREQ(network.name(found), "A");
EXPECT_EQ(network.name(found), "A");
Port *not_found = network.findPort(cell, "B");
EXPECT_EQ(not_found, nullptr);
@ -1102,7 +1103,7 @@ TEST(ConcreteNetworkTest, FindLibraryByName) {
TEST(ConcreteNetworkTest, LibraryName) {
ConcreteNetwork network;
Library *lib = network.makeLibrary("test_name_lib", "test.lib");
EXPECT_STREQ(network.name(lib), "test_name_lib");
EXPECT_EQ(network.name(lib), "test_name_lib");
}
TEST(ConcreteNetworkTest, LibraryId) {
@ -1151,7 +1152,7 @@ TEST(ConcreteNetworkTest, CellNameViaNetwork) {
ConcreteNetwork network;
Library *lib = network.makeLibrary("nm_lib", "nm.lib");
Cell *cell = network.makeCell(lib, "OR2_X1", true, "nm.lib");
EXPECT_STREQ(network.name(cell), "OR2_X1");
EXPECT_EQ(network.name(cell), "OR2_X1");
}
TEST(ConcreteNetworkTest, CellIdViaNetwork) {
@ -1167,7 +1168,7 @@ TEST(ConcreteNetworkTest, SetCellName) {
Library *lib = network.makeLibrary("rn_lib", "rn.lib");
Cell *cell = network.makeCell(lib, "OLD_NAME", true, "rn.lib");
network.setName(cell, "NEW_NAME");
EXPECT_STREQ(network.name(cell), "NEW_NAME");
EXPECT_EQ(network.name(cell), "NEW_NAME");
}
TEST(ConcreteNetworkTest, SetIsLeaf) {
@ -1210,7 +1211,7 @@ TEST(ConcreteNetworkTest, CellFilename) {
ConcreteNetwork network;
Library *lib = network.makeLibrary("fn_lib", "fn.lib");
Cell *cell = network.makeCell(lib, "CELL1", true, "fn.lib");
EXPECT_STREQ(network.filename(cell), "fn.lib");
EXPECT_EQ(network.filename(cell), "fn.lib");
}
TEST(ConcreteNetworkTest, DeleteCell) {
@ -1343,8 +1344,8 @@ TEST_F(ConcreteNetworkLinkedTest, IsTopInstance) {
}
TEST_F(ConcreteNetworkLinkedTest, InstanceName) {
EXPECT_STREQ(network_.name(u1_), "u1");
EXPECT_STREQ(network_.name(u2_), "u2");
EXPECT_EQ(network_.name(u1_), "u1");
EXPECT_EQ(network_.name(u2_), "u2");
}
TEST_F(ConcreteNetworkLinkedTest, InstanceId) {
@ -1356,12 +1357,12 @@ TEST_F(ConcreteNetworkLinkedTest, InstanceId) {
TEST_F(ConcreteNetworkLinkedTest, InstanceCell) {
Cell *cell = network_.cell(u1_);
EXPECT_NE(cell, nullptr);
EXPECT_STREQ(network_.name(cell), "INV");
EXPECT_EQ(network_.name(cell), "INV");
}
TEST_F(ConcreteNetworkLinkedTest, InstanceCellName) {
const char *name = network_.cellName(u1_);
EXPECT_STREQ(name, "INV");
std::string name = network_.cellName(u1_);
EXPECT_EQ(name, "INV");
}
TEST_F(ConcreteNetworkLinkedTest, InstanceParent) {
@ -1388,9 +1389,9 @@ TEST_F(ConcreteNetworkLinkedTest, InstanceFindChild) {
}
TEST_F(ConcreteNetworkLinkedTest, InstancePathName) {
const char *path = network_.pathName(u1_);
EXPECT_NE(path, nullptr);
EXPECT_STREQ(path, "u1");
std::string path = network_.pathName(u1_);
EXPECT_FALSE(path.empty());
EXPECT_EQ(path, "u1");
}
TEST_F(ConcreteNetworkLinkedTest, ChildIterator) {
@ -1447,7 +1448,7 @@ TEST_F(ConcreteNetworkLinkedTest, PinNet) {
TEST_F(ConcreteNetworkLinkedTest, PinPort) {
Port *port = network_.port(pin_u1_a_);
EXPECT_NE(port, nullptr);
EXPECT_STREQ(network_.name(port), "A");
EXPECT_EQ(network_.name(port), "A");
}
TEST_F(ConcreteNetworkLinkedTest, PinDirection) {
@ -1473,18 +1474,18 @@ TEST_F(ConcreteNetworkLinkedTest, PinVertexId) {
TEST_F(ConcreteNetworkLinkedTest, PinName) {
const Network &net = network_;
const char *name = net.name(pin_u1_a_);
EXPECT_NE(name, nullptr);
std::string name = net.name(pin_u1_a_);
EXPECT_FALSE(name.empty());
}
TEST_F(ConcreteNetworkLinkedTest, PinPortName) {
const char *pname = network_.portName(pin_u1_a_);
EXPECT_STREQ(pname, "A");
std::string pname = network_.portName(pin_u1_a_);
EXPECT_EQ(pname, "A");
}
TEST_F(ConcreteNetworkLinkedTest, PinPathName) {
const char *path = network_.pathName(pin_u1_a_);
EXPECT_NE(path, nullptr);
std::string path = network_.pathName(pin_u1_a_);
EXPECT_FALSE(path.empty());
}
TEST_F(ConcreteNetworkLinkedTest, PinIsLeaf) {
@ -1517,7 +1518,7 @@ TEST_F(ConcreteNetworkLinkedTest, FindPinByPort) {
// Net tests
TEST_F(ConcreteNetworkLinkedTest, NetName) {
EXPECT_STREQ(network_.name(net1_), "n1");
EXPECT_EQ(network_.name(net1_), "n1");
}
TEST_F(ConcreteNetworkLinkedTest, NetId) {
@ -1531,8 +1532,8 @@ TEST_F(ConcreteNetworkLinkedTest, NetInstance) {
}
TEST_F(ConcreteNetworkLinkedTest, NetPathName) {
const char *path = network_.pathName(net1_);
EXPECT_NE(path, nullptr);
std::string path = network_.pathName(net1_);
EXPECT_FALSE(path.empty());
}
TEST_F(ConcreteNetworkLinkedTest, NetIsPowerGround) {
@ -1628,7 +1629,7 @@ TEST_F(ConcreteNetworkLinkedTest, ReplaceCell) {
network_.disconnectPin(pin_u1_y_);
network_.replaceCell(u1_, buf_cell);
Cell *new_cell = network_.cell(u1_);
EXPECT_STREQ(network_.name(new_cell), "BUF");
EXPECT_EQ(network_.name(new_cell), "BUF");
}
// Network pathName comparisons
@ -1666,35 +1667,31 @@ TEST_F(ConcreteNetworkLinkedTest, PathNameCmpNet) {
// Network: pathNameFirst / pathNameLast
TEST_F(ConcreteNetworkLinkedTest, PathNameFirst) {
char *first = nullptr;
char *tail = nullptr;
std::string first;
std::string tail;
network_.pathNameFirst("a/b/c", first, tail);
if (first) {
EXPECT_STREQ(first, "a");
EXPECT_STREQ(tail, "b/c");
delete [] first;
delete [] tail;
if (!first.empty()) {
EXPECT_EQ(first, "a");
EXPECT_EQ(tail, "b/c");
}
}
TEST_F(ConcreteNetworkLinkedTest, PathNameLast) {
char *head = nullptr;
char *last = nullptr;
std::string head;
std::string last;
network_.pathNameLast("a/b/c", head, last);
if (last) {
EXPECT_STREQ(last, "c");
EXPECT_STREQ(head, "a/b");
delete [] head;
delete [] last;
if (!last.empty()) {
EXPECT_EQ(last, "c");
EXPECT_EQ(head, "a/b");
}
}
TEST_F(ConcreteNetworkLinkedTest, PathNameFirstNoDivider) {
char *first = nullptr;
char *tail = nullptr;
std::string first;
std::string tail;
network_.pathNameFirst("simple", first, tail);
EXPECT_EQ(first, nullptr);
EXPECT_EQ(tail, nullptr);
EXPECT_TRUE(first.empty());
EXPECT_TRUE(tail.empty());
}
// Network: pathDivider / pathEscape
@ -2027,8 +2024,8 @@ TEST_F(ConcreteNetworkLinkedTest, SortByPathNameInstances) {
inst_set.insert(u1_);
InstanceSeq sorted = sortByPathName(&inst_set, &network_);
EXPECT_EQ(sorted.size(), 2u);
EXPECT_STREQ(network_.name(sorted[0]), "u1");
EXPECT_STREQ(network_.name(sorted[1]), "u2");
EXPECT_EQ(network_.name(sorted[0]), "u1");
EXPECT_EQ(network_.name(sorted[1]), "u2");
}
TEST_F(ConcreteNetworkLinkedTest, SortByPathNameNets) {
@ -2049,8 +2046,8 @@ TEST_F(ConcreteNetworkLinkedTest, SortByNamePorts) {
port_set.insert(port_a);
PortSeq sorted = sortByName(&port_set, &network_);
EXPECT_EQ(sorted.size(), 2u);
EXPECT_STREQ(network_.name(sorted[0]), "A");
EXPECT_STREQ(network_.name(sorted[1]), "Y");
EXPECT_EQ(network_.name(sorted[0]), "A");
EXPECT_EQ(network_.name(sorted[1]), "Y");
}
// NetworkCmp comparator constructors
@ -2212,8 +2209,8 @@ TEST_F(ConcreteNetworkLinkedTest, PortFromToIndexViaNetwork) {
TEST_F(ConcreteNetworkLinkedTest, PortBusNameViaNetwork) {
Cell *inv_cell = network_.findCell(lib_, "INV");
Port *port_a = network_.findPort(inv_cell, "A");
const char *bus_name = network_.busName(port_a);
EXPECT_STREQ(bus_name, "A");
std::string bus_name = network_.busName(port_a);
EXPECT_EQ(bus_name, "A");
}
TEST_F(ConcreteNetworkLinkedTest, PortFindBusBitViaNetwork) {
@ -2308,7 +2305,7 @@ TEST_F(ConcreteNetworkLinkedTest, GroupBusPortsViaNetwork) {
ConcreteLibrary *clib = reinterpret_cast<ConcreteLibrary*>(lib_);
clib->setBusBrkts('[', ']');
network_.groupBusPorts(cell, [](const char*) { return true; });
network_.groupBusPorts(cell, [](std::string_view) { return true; });
Port *bus = network_.findPort(cell, "D");
EXPECT_NE(bus, nullptr);
if (bus) {
@ -2558,29 +2555,29 @@ TEST_F(ConcreteNetworkLinkedTest, PortDirectionAccess) {
// Network: various accessor methods
TEST_F(ConcreteNetworkLinkedTest, LibraryNameAccess) {
EXPECT_STREQ(network_.name(lib_), "test_lib");
EXPECT_EQ(network_.name(lib_), "test_lib");
}
TEST_F(ConcreteNetworkLinkedTest, CellNameAccess) {
Cell *inv_cell = network_.findCell(lib_, "INV");
EXPECT_STREQ(network_.name(inv_cell), "INV");
EXPECT_EQ(network_.name(inv_cell), "INV");
}
TEST_F(ConcreteNetworkLinkedTest, PortNameAccess) {
Cell *inv_cell = network_.findCell(lib_, "INV");
Port *port_a = network_.findPort(inv_cell, "A");
EXPECT_STREQ(network_.name(port_a), "A");
EXPECT_EQ(network_.name(port_a), "A");
}
TEST_F(ConcreteNetworkLinkedTest, NetNameAccess) {
EXPECT_STREQ(network_.name(net1_), "n1");
EXPECT_EQ(network_.name(net1_), "n1");
}
// Network: cell filename
TEST_F(ConcreteNetworkLinkedTest, CellFilename) {
Cell *inv_cell = network_.findCell(lib_, "INV");
const char *fn = network_.filename(inv_cell);
EXPECT_STREQ(fn, "test.lib");
std::string_view fn = network_.filename(inv_cell);
EXPECT_EQ(fn, "test.lib");
}
// PinSet default constructor

View File

@ -406,14 +406,14 @@ ConcreteParasiticNode::incrCapacitance(float cap)
cap_ += cap;
}
const char *
std::string
ConcreteParasiticNode::name(const Network *network) const
{
if (is_net_) {
std::string name = std::string(network->pathName(net_pin_.net_))
+ ':'
+ std::to_string(id_);
return makeTmpString(name);
return name;
}
else
return network->pathName(net_pin_.pin_);
@ -1312,7 +1312,7 @@ ConcreteParasitics::capacitors(const Parasitic *parasitic) const
}
const char *
std::string
ConcreteParasitics::name(const ParasiticNode *node) const
{
const ConcreteParasiticNode *cnode =

Some files were not shown because too many files have changed in this diff Show More