string squash

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2026-03-28 19:13:35 -07:00
parent b9e439f41c
commit 6742692876
179 changed files with 4256 additions and 4745 deletions

View File

@ -32,7 +32,7 @@ if(CMAKE_VERSION VERSION_GREATER_EQUAL 3.14)
cmake_policy(SET CMP0086 NEW) cmake_policy(SET CMP0086 NEW)
endif() endif()
project(STA VERSION 3.0.1 project(STA VERSION 3.1.0
LANGUAGES CXX LANGUAGES CXX
) )

View File

@ -28,6 +28,7 @@
#include <stdio.h> #include <stdio.h>
#include <cstdlib> // exit #include <cstdlib> // exit
#include <filesystem> #include <filesystem>
#include <string_view>
#include <tcl.h> #include <tcl.h>
#if TCL_READLINE #if TCL_READLINE
#include <tclreadline.h> #include <tclreadline.h>
@ -58,14 +59,14 @@ static char **cmd_argv;
static const char *init_filename = ".sta"; static const char *init_filename = ".sta";
static void static void
showUsage(const char *prog, showUsage(std::string_view prog,
const char *init_filename); std::string_view init_filename);
static int static int
tclAppInit(Tcl_Interp *interp); tclAppInit(Tcl_Interp *interp);
static int static int
staTclAppInit(int argc, staTclAppInit(int argc,
char *argv[], char *argv[],
const char *init_filename, std::string_view init_filename,
Tcl_Interp *interp); Tcl_Interp *interp);
static void static void
initStaApp(int &argc, initStaApp(int &argc,
@ -105,7 +106,7 @@ tclAppInit(Tcl_Interp *interp)
static int static int
staTclAppInit(int argc, staTclAppInit(int argc,
char *argv[], char *argv[],
const char *init_filename, std::string_view init_filename,
Tcl_Interp *interp) Tcl_Interp *interp)
{ {
// source init.tcl // source init.tcl
@ -130,7 +131,7 @@ staTclAppInit(int argc,
if (home) { if (home) {
std::string init_path = home; std::string init_path = home;
init_path += "/"; init_path += "/";
init_path += init_filename; init_path.append(init_filename);
if (std::filesystem::is_regular_file(init_path.c_str())) if (std::filesystem::is_regular_file(init_path.c_str()))
sourceTclFile(init_path.c_str(), true, true, interp); sourceTclFile(init_path.c_str(), true, true, interp);
} }
@ -183,15 +184,17 @@ initStaApp(int &argc,
} }
static void static void
showUsage(const char *prog, showUsage(std::string_view prog,
const char *init_filename) std::string_view init_filename)
{ {
printf("Usage: %s [-help] [-version] [-no_init] [-exit] cmd_file\n", prog); sta::print(stdout, "Usage: {} [-help] [-version] [-no_init] [-exit] cmd_file\n",
printf(" -help show help and exit\n"); prog);
printf(" -version show version and exit\n"); sta::print(stdout, " -help show help and exit\n");
printf(" -no_init do not read %s init file\n", init_filename); sta::print(stdout, " -version show version and exit\n");
printf(" -threads count|max use count threads\n"); sta::print(stdout, " -no_init do not read {} init file\n",
printf(" -no_splash do not show the license splash at startup\n"); init_filename);
printf(" -exit exit after reading cmd_file\n"); sta::print(stdout, " -threads count|max use count threads\n");
printf(" cmd_file source cmd_file\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 "StaMain.hh"
#include <string>
#include <string_view>
#include <tcl.h> #include <tcl.h>
#include <cstdlib> #include <cstdlib>
#include <sys/stat.h> #include <sys/stat.h>
@ -43,7 +45,7 @@ parseThreadsArg(int &argc,
if (stringEqual(thread_arg, "max")) if (stringEqual(thread_arg, "max"))
return processorCount(); return processorCount();
else if (isDigits(thread_arg)) else if (isDigits(thread_arg))
return atoi(thread_arg); return std::stoi(thread_arg);
else else
fprintf(stderr,"Warning: -threads must be max or a positive integer.\n"); fprintf(stderr,"Warning: -threads must be max or a positive integer.\n");
} }
@ -53,11 +55,11 @@ parseThreadsArg(int &argc,
bool bool
findCmdLineFlag(int &argc, findCmdLineFlag(int &argc,
char *argv[], char *argv[],
const char *flag) std::string_view flag)
{ {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
char *arg = argv[i]; char *arg = argv[i];
if (stringEq(arg, flag)) { if (std::string_view(arg) == flag) {
// Remove flag from argv. // Remove flag from argv.
for (int j = i + 1; j < argc; j++, i++) for (int j = i + 1; j < argc; j++, i++)
argv[i] = argv[j]; argv[i] = argv[j];
@ -72,11 +74,11 @@ findCmdLineFlag(int &argc,
char * char *
findCmdLineKey(int &argc, findCmdLineKey(int &argc,
char *argv[], char *argv[],
const char *key) std::string_view key)
{ {
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++) {
char *arg = argv[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]; char *value = argv[i + 1];
// Remove key and value from argv. // Remove key and value from argv.
for (int j = i + 2; j < argc; j++, i++) for (int j = i + 2; j < argc; j++, i++)

View File

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

View File

@ -121,7 +121,7 @@ public:
ArnoldiDelayCalc(StaState *sta); ArnoldiDelayCalc(StaState *sta);
~ArnoldiDelayCalc() override; ~ArnoldiDelayCalc() override;
ArcDelayCalc *copy() 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, Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf, const RiseFall *rf,
const Scene *scene, const Scene *scene,

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ class DmpCeffElmoreDelayCalc : public DmpCeffDelayCalc
public: public:
DmpCeffElmoreDelayCalc(StaState *sta); DmpCeffElmoreDelayCalc(StaState *sta);
ArcDelayCalc *copy() override; 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, ArcDcalcResult inputPortDelay(const Pin *port_pin,
float in_slew, float in_slew,
const RiseFall *rf, const RiseFall *rf,
@ -139,7 +139,7 @@ class DmpCeffTwoPoleDelayCalc : public DmpCeffDelayCalc
public: public:
DmpCeffTwoPoleDelayCalc(StaState *sta); DmpCeffTwoPoleDelayCalc(StaState *sta);
ArcDelayCalc *copy() override; 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, Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf, const RiseFall *rf,
const Scene *scene, const Scene *scene,

View File

@ -27,6 +27,7 @@
#include <cmath> #include <cmath>
#include <array> #include <array>
#include <set> #include <set>
#include <string_view>
#include "ContainerHelpers.hh" #include "ContainerHelpers.hh"
#include "Debug.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 Slew to_slew = graph_->slew(to_vertex, to_rf, slew_index);
const ClkNetwork *clk_network = scene->mode()->clkNetwork(); const ClkNetwork *clk_network = scene->mode()->clkNetwork();
bool from_ideal_clk = clk_network->isIdealClock(from_vertex); 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, result = arc_delay_calc_->reportCheckDelay(to_pin, arc, from_slew,
from_slew_annotation, to_slew, from_slew_annotation, to_slew,
related_out_cap, scene, min_max, digits); related_out_cap, scene, min_max, digits);

View File

@ -35,7 +35,7 @@ class LumpedCapDelayCalc : public ParallelDelayCalc
public: public:
LumpedCapDelayCalc(StaState *sta); LumpedCapDelayCalc(StaState *sta);
ArcDelayCalc *copy() override; 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, Parasitic *findParasitic(const Pin *drvr_pin,
const RiseFall *rf, const RiseFall *rf,
const Scene *scene, const Scene *scene,

View File

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

View File

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

View File

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

View File

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

View File

@ -24,6 +24,33 @@
This file summarizes STA API changes for each release. 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 2026/03/12
---------- ----------
@ -37,7 +64,7 @@ stdstrPrint, strintPrint, stringAppend have been removed. Use sta::format.
reportLineString is now reportLine reportLineString is now reportLine
Release 3.0.0 2025/01/03 Release 3.0.0 2026/01/03
------------------------ ------------------------
OpenSTA now requires c++ 20. OpenSTA now requires c++ 20.

View File

@ -52,7 +52,7 @@ Graph::Graph(StaState *sta,
vertices_(nullptr), vertices_(nullptr),
edges_(nullptr), edges_(nullptr),
ap_count_(ap_count), ap_count_(ap_count),
period_check_annotations_(nullptr), period_check_annotations_(network_),
reg_clk_vertices_(makeVertexSet(this)) reg_clk_vertices_(makeVertexSet(this))
{ {
// For the benifit of reg_clk_vertices_ that references graph_. // For the benifit of reg_clk_vertices_ that references graph_.
@ -910,13 +910,11 @@ Graph::periodCheckAnnotation(const Pin *pin,
bool &exists) bool &exists)
{ {
exists = false; exists = false;
if (period_check_annotations_) { float *periods = findKey(period_check_annotations_, pin);
float *periods = findKey(period_check_annotations_, pin); if (periods) {
if (periods) { period = periods[ap_index];
period = periods[ap_index]; if (period >= 0.0)
if (period >= 0.0) exists = true;
exists = true;
}
} }
} }
@ -925,15 +923,13 @@ Graph::setPeriodCheckAnnotation(const Pin *pin,
DcalcAPIndex ap_index, DcalcAPIndex ap_index,
float period) float period)
{ {
if (period_check_annotations_ == nullptr)
period_check_annotations_ = new PeriodCheckAnnotations(network_);
float *periods = findKey(period_check_annotations_, pin); float *periods = findKey(period_check_annotations_, pin);
if (periods == nullptr) { if (periods == nullptr) {
periods = new float[ap_count_]; periods = new float[ap_count_];
// Use negative (illegal) period values to indicate unannotated checks. // Use negative (illegal) period values to indicate unannotated checks.
for (int i = 0; i < ap_count_; i++) for (int i = 0; i < ap_count_; i++)
periods[i] = -1; periods[i] = -1;
(*period_check_annotations_)[pin] = periods; period_check_annotations_[pin] = periods;
} }
periods[ap_index] = period; periods[ap_index] = period;
} }
@ -941,12 +937,9 @@ Graph::setPeriodCheckAnnotation(const Pin *pin,
void void
Graph::removePeriodCheckAnnotations() Graph::removePeriodCheckAnnotations()
{ {
if (period_check_annotations_) { for (auto& [pin, periods] : period_check_annotations_)
for (const auto [pin, periods] : *period_check_annotations_) delete [] periods;
delete [] periods; period_check_annotations_.clear();
delete period_check_annotations_;
period_check_annotations_ = nullptr;
}
} }
void void
@ -1026,7 +1019,7 @@ Vertex::to_string(const StaState *sta) const
{ {
const Network *network = sta->sdcNetwork(); const Network *network = sta->sdcNetwork();
if (network->direction(pin_)->isBidirect()) { if (network->direction(pin_)->isBidirect()) {
std::string str = network->pathName(pin_); std::string str(network->pathName(pin_));
str += ' '; str += ' ';
str += is_bidirect_drvr_ ? "driver" : "load"; str += is_bidirect_drvr_ ? "driver" : "load";
return str; return str;
@ -1035,11 +1028,10 @@ Vertex::to_string(const StaState *sta) const
return network->pathName(pin_); return network->pathName(pin_);
} }
const char * std::string
Vertex::name(const Network *network) const Vertex::name(const Network *network) const
{ {
std::string name = to_string(network); return to_string(network);
return makeTmpString(name);
} }
bool 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 *from_pin() { return self->from(Sta::sta()->graph())->pin(); }
Pin *to_pin() { return self->to(Sta::sta()->graph())->pin(); } Pin *to_pin() { return self->to(Sta::sta()->graph())->pin(); }
const TimingRole *role() { return self->role(); } 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 & TimingArcSeq &
timing_arcs() { return self->timingArcSet()->arcs(); } timing_arcs() { return self->timingArcSet()->arcs(); }
bool is_disabled_loop() { return Sta::sta()->isDisabledLoop(self); } bool is_disabled_loop() { return Sta::sta()->isDisabledLoop(self); }
@ -212,13 +212,16 @@ disabled_constant_pins()
bool is_disabled_bidirect_inst_path() bool is_disabled_bidirect_inst_path()
{ return Sta::sta()->isDisabledBidirectInstPath(self); } { return Sta::sta()->isDisabledBidirectInstPath(self); }
bool is_disabled_preset_clear() bool is_disabled_preset_clear()
{ return Sta::sta()->isDisabledPresetClr(self); } { return Sta::sta()->isDisabledPresetClr(self); }
const char * const char *
sim_timing_sense(){ sim_timing_sense()
{
Sta *sta = Sta::sta(); Sta *sta = Sta::sta();
const Mode *mode = sta->cmdMode(); const Mode *mode = sta->cmdMode();
return to_string(sta->simTimingSense(self, mode)); return to_string(sta->simTimingSense(self, mode)).c_str();
} }
FloatSeq FloatSeq

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -74,7 +74,7 @@ using ConnectedPinIterator = Iterator<const Pin*>;
using NetConnectedPinIterator = ConnectedPinIterator; using NetConnectedPinIterator = ConnectedPinIterator;
using PinConnectedPinIterator = ConnectedPinIterator; using PinConnectedPinIterator = ConnectedPinIterator;
using ObjectId = uint32_t; 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 }; enum class LogicValue : unsigned { zero, one, unknown, rise, fall };

View File

@ -185,7 +185,7 @@ public:
// Increment the grounded capacitance on node. // Increment the grounded capacitance on node.
virtual void incrCap(ParasiticNode *node, virtual void incrCap(ParasiticNode *node,
float cap) = 0; 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 Pin *pin(const ParasiticNode *node) const = 0;
virtual const Net *net(const ParasiticNode *node, virtual const Net *net(const ParasiticNode *node,
const Network *network) const = 0; const Network *network) const = 0;

View File

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

View File

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

View File

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

View File

@ -43,7 +43,7 @@ public:
static PortDirection *power() { return power_; } static PortDirection *power() { return power_; }
static PortDirection *unknown() { return unknown_; } static PortDirection *unknown() { return unknown_; }
static PortDirection *find(const char *dir_name); 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_; } int index() const { return index_; }
bool isInput() const { return this == input_; } bool isInput() const { return this == input_; }
// Input or bidirect. // Input or bidirect.

View File

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

View File

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

View File

@ -177,13 +177,13 @@ public:
} }
// Log output to filename until logEnd is called. // Log output to filename until logEnd is called.
virtual void logBegin(std::string filename); virtual void logBegin(std::string_view filename);
virtual void logEnd(); virtual void logEnd();
// Redirect output to filename until redirectFileEnd is called. // 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. // 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(); virtual void redirectFileEnd();
// Redirect output to a string until redirectStringEnd is called. // Redirect output to a string until redirectStringEnd is called.
virtual void redirectStringBegin(); virtual void redirectStringBegin();

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,9 +24,12 @@
#pragma once #pragma once
#include <algorithm>
#include <cstdarg> #include <cstdarg>
#include <cstring> #include <cstring>
#include <string> #include <string>
#include <string_view>
#include <strings.h> // for strncasecmp
#include <vector> #include <vector>
#include <set> #include <set>
@ -53,14 +56,6 @@ stringEq(const char *str1,
return strncmp(str1, str2, length) == 0; 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. // Case sensitive compare the beginning of str1 to str2.
inline bool inline bool
stringBeginEq(const char *str1, stringBeginEq(const char *str1,
@ -71,78 +66,24 @@ stringBeginEq(const char *str1,
// Case insensitive compare the beginning of str1 to str2. // Case insensitive compare the beginning of str1 to str2.
inline bool inline bool
stringBeginEqual(const char *str1, stringBeginEqual(std::string_view str,
const char *str2) 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. // Case insensitive compare.
inline bool inline bool
stringEqual(const char *str1, stringEqual(std::string_view s1,
const char *str2) 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 void
stringDeleteCheck(const char *str); stringDeleteCheck(const char *str);
@ -153,17 +94,14 @@ stringDelete(const char *str)
delete [] str; delete [] str;
} }
std::pair<float, bool>
stringFloat(const std::string &str);
bool bool
isDigits(const char *str); isDigits(const char *str);
char *
makeTmpString(size_t length);
char *
makeTmpString(std::string &str);
bool bool
isTmpString(const char *str); isDigits(std::string_view str);
void
deleteTmpStrings();
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -171,9 +109,9 @@ deleteTmpStrings();
void void
trimRight(std::string &str); trimRight(std::string &str);
// Spit text into delimiter separated tokens and skip whitepace. // Parse text into delimiter separated tokens and skip whitepace.
StringSeq StringSeq
parseTokens(const std::string &s, parseTokens(const std::string &text,
const char delimiter); std::string_view delims = " \t");
} // namespace } // namespace

View File

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

View File

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

View File

@ -83,10 +83,10 @@ enum class TimingType {
unknown unknown
}; };
const char * std::string_view
to_string(TimingType type); to_string(TimingType type);
TimingType TimingType
findTimingType(const char *string); findTimingType(std::string_view string);
bool bool
timingTypeIsCheck(TimingType type); timingTypeIsCheck(TimingType type);
ScaleFactorType ScaleFactorType
@ -107,15 +107,15 @@ public:
FuncExpr *cond() const { return cond_; } FuncExpr *cond() const { return cond_; }
void setCond(FuncExpr *cond); void setCond(FuncExpr *cond);
const std::string &sdfCond() const { return sdf_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_; } 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_; } 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_; } 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_; } 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; TimingModel *model(const RiseFall *rf) const;
void setModel(const RiseFall *rf, void setModel(const RiseFall *rf,
TimingModel *model); TimingModel *model);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -108,7 +108,7 @@ InternalPowerModel::reportPower(const LibertyCell *cell,
findAxisValues(in_slew, load_cap, findAxisValues(in_slew, load_cap,
axis_value1, axis_value2, axis_value3); axis_value1, axis_value2, axis_value3);
const LibertyLibrary *library = cell->libertyLibrary(); 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, axis_value2, axis_value3,
library->units()->powerUnit(), digits); library->units()->powerUnit(), digits);
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -173,7 +173,7 @@ find_library_buffers(LibertyLibrary *library)
return library->buffers(); return library->buffers();
} }
const char * std::string_view
liberty_port_direction(const LibertyPort *port) liberty_port_direction(const LibertyPort *port)
{ {
return port->direction()->name(); return port->direction()->name();
@ -220,7 +220,7 @@ timing_role_is_check(const TimingRole *role)
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
%extend LibertyLibrary { %extend LibertyLibrary {
const char *name() { return self->name(); } const char *name() { return self->name().c_str(); }
LibertyCell * LibertyCell *
find_liberty_cell(const char *name) find_liberty_cell(const char *name)
@ -264,7 +264,7 @@ default_operating_conditions()
} // LibertyLibrary methods } // LibertyLibrary methods
%extend LibertyCell { %extend LibertyCell {
const char *name() { return self->name(); } const char *name() { return self->name().c_str(); }
bool is_leaf() { return self->isLeaf(); } bool is_leaf() { return self->isLeaf(); }
bool is_buffer() { return self->isBuffer(); } bool is_buffer() { return self->isBuffer(); }
bool is_inverter() { return self->isInverter(); } bool is_inverter() { return self->isInverter(); }
@ -306,7 +306,8 @@ LibertyCell *test_cell() { return self->testCell(); }
} // LibertyCell methods } // LibertyCell methods
%extend LibertyPort { %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(); } Cell *cell() { return self->cell(); }
bool is_bus() { return self->isBus(); } bool is_bus() { return self->isBus(); }
bool is_bus_bit() { return self->isBusBit(); } bool is_bus_bit() { return self->isBusBit(); }
@ -355,7 +356,7 @@ set_direction(const char *dir)
const char * const char *
scan_signal_type() scan_signal_type()
{ {
return scanSignalTypeName(self->scanSignalType()); return scanSignalTypeName(self->scanSignalType()).c_str();
} }
} // LibertyPort methods } // LibertyPort methods
@ -370,10 +371,10 @@ const char *sdf_cond() { return self->sdfCond().c_str(); }
std::string std::string
full_name() full_name()
{ {
const char *from = self->from()->name(); return sta::format("{} {} -> {}",
const char *to = self->to()->name(); self->libertyCell()->name(),
const char *cell_name = self->libertyCell()->name(); self->from()->name(),
return sta::format("{} {} -> {}", cell_name, from, to); self->to()->name());
} }
const std::string const std::string
@ -395,9 +396,9 @@ timing_arcs() { return self->arcs(); }
LibertyPort *from() { return self->from(); } LibertyPort *from() { return self->from(); }
LibertyPort *to() { return self->to(); } LibertyPort *to() { return self->to(); }
const Transition *from_edge() { return self->fromEdge(); } 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 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(); } const TimingRole *role() { return self->role(); }
float float

View File

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

View File

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

View File

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

View File

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

View File

@ -27,6 +27,7 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <regex> #include <regex>
#include <string>
#include "ContainerHelpers.hh" #include "ContainerHelpers.hh"
#include "Zlib.hh" #include "Zlib.hh"
@ -38,11 +39,12 @@
namespace sta { namespace sta {
void void
parseLibertyFile(const char *filename, parseLibertyFile(std::string_view filename,
LibertyGroupVisitor *library_visitor, LibertyGroupVisitor *library_visitor,
Report *report) Report *report)
{ {
gzstream::igzstream stream(filename); std::string fn(filename);
gzstream::igzstream stream(fn.c_str());
if (stream.is_open()) { if (stream.is_open()) {
LibertyParser reader(filename, library_visitor, report); LibertyParser reader(filename, library_visitor, report);
LibertyScanner scanner(&stream, filename, &reader, report); LibertyScanner scanner(&stream, filename, &reader, report);
@ -53,7 +55,7 @@ parseLibertyFile(const char *filename,
throw FileNotReadable(filename); throw FileNotReadable(filename);
} }
LibertyParser::LibertyParser(const char *filename, LibertyParser::LibertyParser(std::string_view filename,
LibertyGroupVisitor *library_visitor, LibertyGroupVisitor *library_visitor,
Report *report) : Report *report) :
filename_(filename), filename_(filename),
@ -63,7 +65,7 @@ LibertyParser::LibertyParser(const char *filename,
} }
void void
LibertyParser::setFilename(const std::string &filename) LibertyParser::setFilename(std::string_view filename)
{ {
filename_ = filename; filename_ = filename;
} }
@ -74,7 +76,7 @@ LibertyParser::makeDefine(const LibertyAttrValueSeq *values,
{ {
LibertyDefine *define = nullptr; LibertyDefine *define = nullptr;
if (values->size() == 3) { 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 &group_type_name = (*values)[1]->stringValue();
const std::string &value_type_name = (*values)[2]->stringValue(); const std::string &value_type_name = (*values)[2]->stringValue();
LibertyAttrType value_type = attrValueType(value_type_name); LibertyAttrType value_type = attrValueType(value_type_name);
@ -87,7 +89,7 @@ LibertyParser::makeDefine(const LibertyAttrValueSeq *values,
delete values; delete values;
} }
else else
report_->fileWarn(24, filename_.c_str(), line, report_->fileWarn(24, filename_, line,
"define does not have three arguments."); "define does not have three arguments.");
return define; return define;
} }
@ -126,12 +128,15 @@ LibertyParser::groupType(const std::string &group_type_name)
} }
void void
LibertyParser::groupBegin(const std::string type, LibertyParser::groupBegin(std::string &&type,
LibertyAttrValueSeq *params, LibertyAttrValueSeq *params,
int line) int line)
{ {
LibertyGroup *group = new LibertyGroup( LibertyGroup *group = new LibertyGroup(std::move(type),
std::move(type), params ? std::move(*params) : LibertyAttrValueSeq(), line); params
? std::move(*params)
: LibertyAttrValueSeq(),
line);
delete params; delete params;
LibertyGroup *parent_group = group_stack_.empty() ? nullptr : group_stack_.back(); LibertyGroup *parent_group = group_stack_.empty() ? nullptr : group_stack_.back();
group_visitor_->begin(group, parent_group); group_visitor_->begin(group, parent_group);
@ -163,12 +168,13 @@ LibertyParser::deleteGroups()
} }
LibertySimpleAttr * LibertySimpleAttr *
LibertyParser::makeSimpleAttr(const std::string name, LibertyParser::makeSimpleAttr(std::string &&name,
const LibertyAttrValue *value, const LibertyAttrValue *value,
int line) int line)
{ {
LibertySimpleAttr *attr = LibertySimpleAttr *attr = new LibertySimpleAttr(std::move(name),
new LibertySimpleAttr(std::move(name), std::move(*value), line); std::move(*value),
line);
delete value; delete value;
LibertyGroup *group = this->group(); LibertyGroup *group = this->group();
group->addAttr(attr); group->addAttr(attr);
@ -177,7 +183,7 @@ LibertyParser::makeSimpleAttr(const std::string name,
} }
LibertyComplexAttr * LibertyComplexAttr *
LibertyParser::makeComplexAttr(const std::string name, LibertyParser::makeComplexAttr(std::string &&name,
const LibertyAttrValueSeq *values, const LibertyAttrValueSeq *values,
int line) int line)
{ {
@ -199,7 +205,7 @@ LibertyParser::makeComplexAttr(const std::string name,
} }
LibertyVariable * LibertyVariable *
LibertyParser::makeVariable(const std::string var, LibertyParser::makeVariable(std::string &&var,
float value, float value,
int line) int line)
{ {
@ -211,7 +217,7 @@ LibertyParser::makeVariable(const std::string var,
} }
LibertyAttrValue * LibertyAttrValue *
LibertyParser::makeAttrValueString(std::string value) LibertyParser::makeAttrValueString(std::string &&value)
{ {
return new LibertyAttrValue(std::move(value)); return new LibertyAttrValue(std::move(value));
} }
@ -225,7 +231,7 @@ LibertyParser::makeAttrValueFloat(float value)
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
LibertyScanner::LibertyScanner(std::istream *stream, LibertyScanner::LibertyScanner(std::istream *stream,
const char *filename, std::string_view filename,
LibertyParser *reader, LibertyParser *reader,
Report *report) : Report *report) :
yyFlexLexer(stream), yyFlexLexer(stream),
@ -261,7 +267,7 @@ LibertyScanner::includeBegin()
return true; return true;
} }
else { else {
report_->fileWarn(25, filename_.c_str(), yylineno, report_->fileWarn(25, filename_, yylineno,
"cannot open include file {}.", filename); "cannot open include file {}.", filename);
delete stream; delete stream;
} }
@ -287,7 +293,7 @@ LibertyScanner::fileEnd()
void void
LibertyScanner::error(const char *msg) LibertyScanner::error(const char *msg)
{ {
report_->fileError(1866, filename_.c_str(), lineno(), "{}", msg); report_->fileError(1866, filename_, lineno(), "{}", msg);
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
@ -366,9 +372,9 @@ void
LibertyGroup::addAttr(LibertySimpleAttr *attr) LibertyGroup::addAttr(LibertySimpleAttr *attr)
{ {
// Only keep the most recent simple attribute value. // Only keep the most recent simple attribute value.
const auto &itr = simple_attr_map_.find(attr->name()); const auto &it = simple_attr_map_.find(attr->name());
if (itr != simple_attr_map_.end()) if (it != simple_attr_map_.end())
delete itr->second; delete it->second;
simple_attr_map_[attr->name()] = attr; simple_attr_map_[attr->name()] = attr;
} }
@ -384,37 +390,46 @@ LibertyGroup::addVariable(LibertyVariable *var)
variables_.push_back(var); variables_.push_back(var);
} }
const char * bool
LibertyGroup::firstName() const LibertyGroup::hasFirstParam() const
{ {
if (params_.size() >= 1) { return !params_.empty();
LibertyAttrValue *value = params_[0];
if (value->isString())
return value->stringValue().c_str();
}
return nullptr;
} }
const char * const std::string &
LibertyGroup::secondName() const 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]; LibertyAttrValue *value = params_[1];
if (value->isString()) return value->stringValue();
return value->stringValue().c_str();
else
return nullptr;
} }
const LibertyGroupSeq & 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 * 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) if (groups.size() >= 1)
return groups[0]; return groups[0];
else else
@ -422,39 +437,43 @@ LibertyGroup::findSubgroup(const std::string type) const
} }
const LibertySimpleAttr * 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 & 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 * 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) if (attrs.size() >= 1)
return attrs[0]; return attrs[0];
else else
return nullptr; return nullptr;
} }
const std::string * const std::string &
LibertyGroup::findAttrString(const std::string attr_name) const LibertyGroup::findAttrString(std::string_view attr_name) const
{ {
const LibertySimpleAttr *attr = findSimpleAttr(attr_name); const LibertySimpleAttr *attr = findSimpleAttr(attr_name);
if (attr) if (attr)
return &attr->value().stringValue(); return attr->value().stringValue();
else static const std::string null_string;
return nullptr; return null_string;
} }
void void
LibertyGroup::findAttrFloat(const std::string attr_name, LibertyGroup::findAttrFloat(std::string_view attr_name,
// Return values. // Return values.
float &value, float &value,
bool &exists) const bool &exists) const
@ -463,26 +482,25 @@ LibertyGroup::findAttrFloat(const std::string attr_name,
if (attr) { if (attr) {
const LibertyAttrValue &attr_value = attr->value(); const LibertyAttrValue &attr_value = attr->value();
if (attr_value.isFloat()) { if (attr_value.isFloat()) {
value = attr_value.floatValue(); auto [value1, exists1] = attr_value.floatValue();
exists = true; value = value1;
exists = exists1;
return; return;
} }
else { else {
// Possibly quoted string float. // Possibly quoted string float.
const std::string &float_str = attr_value.stringValue(); const std::string &float_str = attr_value.stringValue();
char *end = nullptr; auto [value1, valid1] = stringFloat(float_str);
value = std::strtof(float_str.c_str(), &end); value = value1;
if (end) { exists = valid1;
exists = true; return;
return;
}
} }
} }
exists = false; exists = false;
} }
void void
LibertyGroup::findAttrInt(const std::string attr_name, LibertyGroup::findAttrInt(std::string_view attr_name,
// Return values. // Return values.
int &value, int &value,
bool &exists) const bool &exists) const
@ -491,8 +509,9 @@ LibertyGroup::findAttrInt(const std::string attr_name,
if (attr) { if (attr) {
const LibertyAttrValue &attr_value = attr->value(); const LibertyAttrValue &attr_value = attr->value();
if (attr_value.isFloat()) { if (attr_value.isFloat()) {
value = static_cast<int>(attr_value.floatValue()); auto [value1, exists1] = attr_value.floatValue();
exists = true; value = static_cast<int>(value1);
exists = exists1;
return; return;
} }
} }
@ -501,7 +520,7 @@ LibertyGroup::findAttrInt(const std::string attr_name,
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
LibertySimpleAttr::LibertySimpleAttr(const std::string name, LibertySimpleAttr::LibertySimpleAttr(std::string &&name,
const LibertyAttrValue value, const LibertyAttrValue value,
int line) : int line) :
name_(std::move(name)), name_(std::move(name)),
@ -510,15 +529,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, const LibertyAttrValueSeq values,
int line) : int line) :
name_(std::move(name)), name_(std::move(name)),
@ -540,7 +553,7 @@ LibertyComplexAttr::firstValue() const
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
LibertyAttrValue::LibertyAttrValue(std::string value) : LibertyAttrValue::LibertyAttrValue(std::string &&value) :
string_value_(std::move(value)) string_value_(std::move(value))
{ {
} }
@ -562,39 +575,18 @@ LibertyAttrValue::isString() const
return !string_value_.empty(); return !string_value_.empty();
} }
float std::pair<float, bool>
LibertyAttrValue::floatValue() const LibertyAttrValue::floatValue() const
{ {
if (!string_value_.empty()) if (string_value_.empty())
criticalError(1127, "LibertyAttrValue::floatValue() called on string"); return {float_value_, true};
return float_value_; else
} return stringFloat(string_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;
}
}
} }
//////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////
LibertyDefine::LibertyDefine(std::string name, LibertyDefine::LibertyDefine(std::string &&name,
LibertyGroupType group_type, LibertyGroupType group_type,
LibertyAttrType value_type, LibertyAttrType value_type,
int line) : int line) :

View File

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

File diff suppressed because it is too large Load Diff

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -193,21 +193,21 @@ Units::Units() :
} }
Unit * 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_; return &time_unit_;
else if (stringEq(unit_name, "resistance")) else if (stringEqual(unit_name, "resistance"))
return &resistance_unit_; return &resistance_unit_;
else if (stringEq(unit_name, "capacitance")) else if (stringEqual(unit_name, "capacitance"))
return &capacitance_unit_; return &capacitance_unit_;
else if (stringEq(unit_name, "voltage")) else if (stringEqual(unit_name, "voltage"))
return &voltage_unit_; return &voltage_unit_;
else if (stringEq(unit_name, "current")) else if (stringEqual(unit_name, "current"))
return &current_unit_; return &current_unit_;
else if (stringEq(unit_name, "power")) else if (stringEqual(unit_name, "power"))
return &power_unit_; return &power_unit_;
else if (stringEq(unit_name, "distance")) else if (stringEqual(unit_name, "distance"))
return &distance_unit_; return &distance_unit_;
else else
return nullptr; return nullptr;

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -58,9 +58,9 @@ netVerilogName(std::string sta_name)
bool is_bus; bool is_bus;
std::string bus_name; std::string bus_name;
int index; 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) { 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) + ']'; std::string vname = bus_vname + '[' + std::to_string(index) + ']';
return vname; return vname;
} }

View File

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

View File

@ -24,9 +24,10 @@
#pragma once #pragma once
#include <mutex>
#include <array> #include <array>
#include <map> #include <map>
#include <mutex>
#include <string>
#include "MinMax.hh" #include "MinMax.hh"
#include "Parasitics.hh" #include "Parasitics.hh"
@ -143,7 +144,7 @@ public:
ParasiticNodeSeq nodes(const Parasitic *parasitic) const override; ParasiticNodeSeq nodes(const Parasitic *parasitic) const override;
void incrCap(ParasiticNode *node, void incrCap(ParasiticNode *node,
float cap) override; float cap) override;
const char *name(const ParasiticNode *node) const override; std::string name(const ParasiticNode *node) const override;
const Pin *pin(const ParasiticNode *node) const override; const Pin *pin(const ParasiticNode *node) const override;
const Net *net(const ParasiticNode *node, const Net *net(const ParasiticNode *node,
const Network *network) const override; const Network *network) const override;

View File

@ -26,6 +26,7 @@
#include <map> #include <map>
#include <set> #include <set>
#include <string>
#include "Parasitics.hh" #include "Parasitics.hh"
@ -272,7 +273,7 @@ public:
ConcreteParasiticNode(const Pin *pin, ConcreteParasiticNode(const Pin *pin,
bool is_external); bool is_external);
float capacitance() const { return cap_; } float capacitance() const { return cap_; }
const char *name(const Network *network) const; std::string name(const Network *network) const;
const Net *net(const Network *network) const; const Net *net(const Network *network) const;
unsigned id() const { return id_; } unsigned id() const { return id_; }
bool isExternal() const { return is_external_; } bool isExternal() const { return is_external_; }

View File

@ -163,7 +163,7 @@ INDEX "*"{POS_INTEGER}
"\"" { "\"" {
BEGIN INITIAL; BEGIN INITIAL;
yylval->string = sta::stringCopy(token_.c_str()); yylval->emplace<std::string>(std::move(token_));
return token::QSTRING; return token::QSTRING;
} }
@ -179,27 +179,27 @@ INDEX "*"{POS_INTEGER}
{BLANK}*\n { loc->lines(); loc->step(); } {BLANK}*\n { loc->lines(); loc->step(); }
{INTEGER} { {INTEGER} {
yylval->integer = atoi(yytext); yylval->emplace<int>(atoi(yytext));
return token::INTEGER; return token::INTEGER;
} }
{FLOAT} { {FLOAT} {
yylval->number = static_cast<float>(atof(yytext)); yylval->emplace<float>(static_cast<float>(atof(yytext)));
return token::FLOAT; return token::FLOAT;
} }
{IDENT} { {IDENT} {
yylval->string = reader_->translated(yytext); yylval->emplace<std::string>(reader_->translated(yytext));
return token::IDENT; return token::IDENT;
} }
{PATH}|{NAME_PAIR} { {PATH}|{NAME_PAIR} {
yylval->string = reader_->translated(yytext); yylval->emplace<std::string>(reader_->translated(yytext));
return token::NAME; return token::NAME;
} }
{INDEX} { {INDEX} {
yylval->string = sta::stringCopy(yytext); yylval->emplace<std::string>(yytext);
return token::INDEX; return token::INDEX;
} }

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