mirror of
https://github.com/The-OpenROAD-Project/OpenSTA.git
synced 2026-09-03 07:53:31 +02:00
rm tmp string uses
commit 2d0a4f8e9a8b46faa2ba91e1be636c3c3ad95a7f Author: James Cherry <[email protected]> Date: Sat Mar 25 21:25:37 2023 -0700 leaks Signed-off-by: James Cherry <[email protected]> commit 5514910a91707d615bac0bbed3a29f579eca8de2 Author: James Cherry <[email protected]> Date: Sat Mar 25 18:21:54 2023 -0700 foo Signed-off-by: James Cherry <[email protected]> commit 076a51d5816444e883232933c2ded7309291d0bc Author: James Cherry <[email protected]> Date: Sat Mar 25 16:38:42 2023 -0700 parse bus string Signed-off-by: James Cherry <[email protected]> commit 2b80e563cbbb6563a6b716431f391bbb6639f816 Author: James Cherry <[email protected]> Date: Sat Mar 25 15:57:05 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit 9e4f2308658232d0b1ee9efcd948bb19ae5dd30f Author: James Cherry <[email protected]> Date: Sat Mar 25 14:37:35 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit ebad3afd49b08e7194452dd082c3c7c05767f875 Author: James Cherry <[email protected]> Date: Sat Mar 25 10:59:11 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit 69647913932312a04ca06e7a04cca17ed50d4daf Author: James Cherry <[email protected]> Date: Fri Mar 24 21:02:20 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit 55e67996a7b0651dbb5ee06cb89fe0410648c3c1 Author: James Cherry <[email protected]> Date: Sat Mar 25 10:42:43 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit 73cee43925c0d32940989c616440b4da18640121 Author: James Cherry <[email protected]> Date: Sat Mar 25 09:55:17 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit eba6d1413b8d87a64a90141e5263a56eede1df51 Author: James Cherry <[email protected]> Date: Sat Mar 25 09:40:16 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit 95d6ed78144512a37fd7c1d3d8a62fc4c8965818 Author: James Cherry <[email protected]> Date: Sat Mar 25 08:18:46 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit faf82464d7be7fd6c958a21d401fa48ece4ac341 Author: James Cherry <[email protected]> Date: Sat Mar 25 07:49:11 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit cfc9064496cb6f46ec562b104bc7fff2fbc1b32e Author: James Cherry <[email protected]> Date: Sat Mar 25 07:37:12 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit 057933a6ac356a7541883aa64b5109c7a0e8b8d1 Author: James Cherry <[email protected]> Date: Fri Mar 24 21:02:20 2023 -0700 rm tmp string Signed-off-by: James Cherry <[email protected]> commit fdeb6436a72413356a627dd1de1d8cec7fca4c4a Author: James Cherry <[email protected]> Date: Fri Mar 24 19:53:44 2023 -0700 rm TmpString uses Signed-off-by: James Cherry <[email protected]> Signed-off-by: James Cherry <[email protected]>
This commit is contained in:
+35
-33
@@ -25,6 +25,8 @@
|
||||
|
||||
namespace sta {
|
||||
|
||||
using std::map;
|
||||
|
||||
static constexpr char escape_ = '\\';
|
||||
|
||||
ConcreteLibrary::ConcreteLibrary(const char *name,
|
||||
@@ -381,7 +383,7 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
|
||||
{
|
||||
const char bus_brkts_left[2]{bus_brkt_left, '\0'};
|
||||
const char bus_brkts_right[2]{bus_brkt_right, '\0'};
|
||||
BusPortMap port_map;
|
||||
map<string, BusPort*> port_map;
|
||||
// Find ungrouped bus ports.
|
||||
// Remove bus bit ports from the ports_ vector during the scan by
|
||||
// keeping an index to the next insertion index and skipping over
|
||||
@@ -390,19 +392,21 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
|
||||
ports_.clear();
|
||||
for (ConcretePort *port : ports) {
|
||||
const char *port_name = port->name();
|
||||
char *bus_name;
|
||||
bool is_bus;
|
||||
string bus_name;
|
||||
int index;
|
||||
parseBusName(port_name, bus_brkts_left, bus_brkts_right, escape_,
|
||||
bus_name, index);
|
||||
if (bus_name) {
|
||||
is_bus, bus_name, index);
|
||||
if (is_bus) {
|
||||
if (!port->isBusBit()) {
|
||||
BusPort *bus_port = port_map.findKey(bus_name);
|
||||
if (bus_port)
|
||||
stringDelete(bus_name);
|
||||
else {
|
||||
bus_port = new BusPort(bus_name, index, port->direction());
|
||||
auto name_bus_port = port_map.find(bus_name);
|
||||
BusPort *bus_port;
|
||||
if (name_bus_port == port_map.end()) {
|
||||
bus_port = new BusPort(bus_name.c_str(), index, port->direction());
|
||||
port_map[bus_name] = bus_port;
|
||||
}
|
||||
else
|
||||
bus_port = name_bus_port->second;
|
||||
bus_port->pushMember(port);
|
||||
}
|
||||
else
|
||||
@@ -413,47 +417,45 @@ ConcreteCell::groupBusPorts(const char bus_brkt_left,
|
||||
}
|
||||
|
||||
// Make the bus ports.
|
||||
BusPortMap::Iterator bus_iter(port_map);
|
||||
while (bus_iter.hasNext()) {
|
||||
BusPort *bus_port = bus_iter.next();
|
||||
const char *bus_name = bus_port->name();
|
||||
bool msb_first = port_msb_first(bus_name);
|
||||
for (auto name_bus : port_map) {
|
||||
const string &bus_name = name_bus.first;
|
||||
BusPort *bus_port = name_bus.second;
|
||||
bool msb_first = port_msb_first(bus_name.c_str());
|
||||
ConcretePortSeq *members = bus_port->members();
|
||||
sort(members, [&](ConcretePort *port1,
|
||||
ConcretePort *port2) {
|
||||
char *bus_name;
|
||||
int index1, index2;
|
||||
parseBusName(port1->name(), bus_brkts_left, bus_brkts_right, escape_,
|
||||
bus_name, index1);
|
||||
stringDelete(bus_name);
|
||||
parseBusName(port2->name(), bus_brkts_left, bus_brkts_right, escape_,
|
||||
bus_name, index2);
|
||||
stringDelete(bus_name);
|
||||
return msb_first ? index1 > index2 : index1 < index2;
|
||||
});
|
||||
bool is_bus;
|
||||
string bus_name;
|
||||
int index1, index2;
|
||||
parseBusName(port1->name(), bus_brkts_left, bus_brkts_right, escape_,
|
||||
is_bus, bus_name, index1);
|
||||
parseBusName(port2->name(), bus_brkts_left, bus_brkts_right, escape_,
|
||||
is_bus, bus_name, index2);
|
||||
return msb_first ? index1 > index2 : index1 < index2;
|
||||
});
|
||||
|
||||
char *bus_name1;
|
||||
bool is_bus1;
|
||||
string bus_name1;
|
||||
int from_index, to_index;
|
||||
parseBusName((*members)[0]->name(),
|
||||
bus_brkts_left, bus_brkts_right, escape_,
|
||||
bus_name1, from_index);
|
||||
stringDelete(bus_name1);
|
||||
is_bus1, bus_name1, from_index);
|
||||
parseBusName((*members)[members->size() - 1]->name(),
|
||||
bus_brkts_left, bus_brkts_right, escape_,
|
||||
bus_name1, to_index);
|
||||
stringDelete(bus_name1);
|
||||
is_bus1, bus_name1, to_index);
|
||||
|
||||
ConcretePort *port = makeBusPort(bus_name, from_index, to_index, members);
|
||||
ConcretePort *port = makeBusPort(bus_name.c_str(), from_index,
|
||||
to_index, members);
|
||||
port->setDirection(bus_port->direction());
|
||||
delete bus_port;
|
||||
|
||||
for (ConcretePort *port : *members) {
|
||||
char *bus_name;
|
||||
bool is_bus;
|
||||
string bus_name;
|
||||
int index;
|
||||
parseBusName(port->name(), bus_brkts_left, bus_brkts_right, escape_,
|
||||
bus_name, index);
|
||||
is_bus, bus_name, index);
|
||||
port->setBusBitIndex(index);
|
||||
stringDelete(bus_name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+30
-49
@@ -51,12 +51,14 @@ parseBusName(const char *name,
|
||||
const char brkt_right,
|
||||
const char escape,
|
||||
// Return values.
|
||||
char *&bus_name,
|
||||
bool &is_bus,
|
||||
string &bus_name,
|
||||
int &index)
|
||||
{
|
||||
const char brkts_left[2] = {brkt_left, '\0'};
|
||||
const char brkts_right[2] = {brkt_right, '\0'};
|
||||
parseBusName(name, brkts_left, brkts_right, escape, bus_name, index);
|
||||
parseBusName(name, brkts_left, brkts_right, escape,
|
||||
is_bus, bus_name, index);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -65,10 +67,11 @@ parseBusName(const char *name,
|
||||
const char *brkts_right,
|
||||
char escape,
|
||||
// Return values.
|
||||
char *&bus_name,
|
||||
bool &is_bus,
|
||||
string &bus_name,
|
||||
int &index)
|
||||
{
|
||||
bus_name = nullptr;
|
||||
is_bus = false;
|
||||
size_t len = strlen(name);
|
||||
// Shortest bus name is a[0].
|
||||
if (len >= 4
|
||||
@@ -81,10 +84,9 @@ parseBusName(const char *name,
|
||||
char brkt_left = brkts_left[brkt_index];
|
||||
const char *left = strrchr(name, brkt_left);
|
||||
if (left) {
|
||||
is_bus = true;
|
||||
size_t bus_name_len = left - name;
|
||||
bus_name = new char[bus_name_len + 1];
|
||||
strncpy(bus_name, name, bus_name_len);
|
||||
bus_name[bus_name_len] = '\0';
|
||||
bus_name.append(name, bus_name_len);
|
||||
// Simple bus subscript.
|
||||
index = atoi(left + 1);
|
||||
}
|
||||
@@ -98,13 +100,15 @@ parseBusRange(const char *name,
|
||||
const char brkt_right,
|
||||
char escape,
|
||||
// Return values.
|
||||
char *&bus_name,
|
||||
bool &is_bus,
|
||||
string &bus_name,
|
||||
int &from,
|
||||
int &to)
|
||||
{
|
||||
const char brkts_left[2] = {brkt_left, '\0'};
|
||||
const char brkts_right[2] = {brkt_right, '\0'};
|
||||
parseBusRange(name, brkts_left, brkts_right, escape, bus_name, from, to);
|
||||
parseBusRange(name, brkts_left, brkts_right, escape,
|
||||
is_bus, bus_name, from, to);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -113,11 +117,12 @@ parseBusRange(const char *name,
|
||||
const char *brkts_right,
|
||||
char escape,
|
||||
// Return values.
|
||||
char *&bus_name,
|
||||
bool &is_bus,
|
||||
string &bus_name,
|
||||
int &from,
|
||||
int &to)
|
||||
{
|
||||
bus_name = nullptr;
|
||||
is_bus = false;
|
||||
size_t len = strlen(name);
|
||||
// Shortest bus range is a[1:0].
|
||||
if (len >= 6
|
||||
@@ -134,10 +139,8 @@ parseBusRange(const char *name,
|
||||
const char range_sep = ':';
|
||||
const char *range = strchr(name, range_sep);
|
||||
if (range) {
|
||||
size_t bus_name_len = left - name;
|
||||
bus_name = new char[bus_name_len + 1];
|
||||
strncpy(bus_name, name, bus_name_len);
|
||||
bus_name[bus_name_len] = '\0';
|
||||
is_bus = true;
|
||||
bus_name.append(name, left - name);
|
||||
// No need to terminate bus subscript because atoi stops
|
||||
// scanning at first non-digit character.
|
||||
from = atoi(left + 1);
|
||||
@@ -148,54 +151,32 @@ parseBusRange(const char *name,
|
||||
}
|
||||
}
|
||||
|
||||
const char *
|
||||
string
|
||||
escapeChars(const char *token,
|
||||
const char ch1,
|
||||
const char ch2,
|
||||
const char escape)
|
||||
{
|
||||
int result_length = 0;
|
||||
bool need_escapes = false;
|
||||
string escaped;
|
||||
for (const char *s = token; *s; s++) {
|
||||
char ch = *s;
|
||||
if (ch == escape) {
|
||||
char next_ch = s[1];
|
||||
// Make sure we don't skip the null if escape is the last char.
|
||||
if (next_ch != '\0')
|
||||
result_length++;
|
||||
if (next_ch != '\0') {
|
||||
escaped += ch;
|
||||
escaped += next_ch;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
else if (ch == ch1 || ch == ch2) {
|
||||
result_length++;
|
||||
need_escapes = true;
|
||||
escaped += escape;
|
||||
escaped += ch;
|
||||
}
|
||||
result_length++;
|
||||
else
|
||||
escaped += ch;
|
||||
}
|
||||
if (need_escapes) {
|
||||
char *result = makeTmpString(result_length + 1);
|
||||
char *r = result;
|
||||
for (const char *s = token; *s; s++) {
|
||||
char ch = *s;
|
||||
if (ch == escape) {
|
||||
char next_ch = s[1];
|
||||
// Make sure we don't skip the null if escape is the last char.
|
||||
if (next_ch != '\0') {
|
||||
*r++ = ch;
|
||||
*r++ = next_ch;
|
||||
s++;
|
||||
}
|
||||
}
|
||||
else if (ch == ch1 || ch == ch2) {
|
||||
*r++ = escape;
|
||||
*r++ = ch;
|
||||
}
|
||||
else
|
||||
*r++ = ch;
|
||||
}
|
||||
*r++ = '\0';
|
||||
return result;
|
||||
}
|
||||
else
|
||||
return token;
|
||||
return escaped;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
+60
-57
@@ -22,10 +22,10 @@
|
||||
|
||||
namespace sta {
|
||||
|
||||
static const char *
|
||||
static string
|
||||
escapeDividers(const char *token,
|
||||
const Network *network);
|
||||
static const char *
|
||||
static string
|
||||
escapeBrackets(const char *token,
|
||||
const Network *network);
|
||||
|
||||
@@ -631,21 +631,22 @@ SdcNetwork::findPort(const Cell *cell,
|
||||
Port *port = network_->findPort(cell, name);
|
||||
if (port == nullptr) {
|
||||
// Look for matches after escaping brackets.
|
||||
char *bus_name;
|
||||
bool is_bus;
|
||||
string bus_name;
|
||||
int index;
|
||||
parseBusName(name, '[', ']', pathEscape(), bus_name, index);
|
||||
if (bus_name) {
|
||||
const char *escaped1 = escapeBrackets(name, this);
|
||||
port = network_->findPort(cell, escaped1);
|
||||
if (port == nullptr
|
||||
&& bus_name[strlen(bus_name) - 1] == ']') {
|
||||
parseBusName(name, '[', ']', pathEscape(), is_bus, bus_name, index);
|
||||
if (is_bus) {
|
||||
string escaped1 = escapeBrackets(name, this);
|
||||
port = network_->findPort(cell, escaped1.c_str());
|
||||
if (port == nullptr) {
|
||||
// Try escaping base foo\[0\][1]
|
||||
const char *escaped2 = stringPrintTmp("%s[%d]",
|
||||
escapeBrackets(bus_name, this),
|
||||
index);
|
||||
port = network_->findPort(cell, escaped2);
|
||||
string escaped2;
|
||||
string escaped_bus_name = escapeBrackets(bus_name.c_str(), this);
|
||||
stringPrint(escaped2, "%s[%d]",
|
||||
escaped_bus_name.c_str(),
|
||||
index);
|
||||
port = network_->findPort(cell, escaped2.c_str());
|
||||
}
|
||||
stringDelete(bus_name);
|
||||
}
|
||||
}
|
||||
return port;
|
||||
@@ -658,23 +659,25 @@ SdcNetwork::findPortsMatching(const Cell *cell,
|
||||
PortSeq matches = network_->findPortsMatching(cell, pattern);
|
||||
if (matches.empty()) {
|
||||
// Look for matches after escaping brackets.
|
||||
char *bus_name;
|
||||
bool is_bus;
|
||||
string bus_name;
|
||||
int index;
|
||||
parseBusName(pattern->pattern(), '[', ']', pathEscape(), bus_name, index);
|
||||
if (bus_name) {
|
||||
const char *escaped1 = escapeBrackets(pattern->pattern(), this);
|
||||
PatternMatch escaped_pattern1(escaped1, pattern);
|
||||
parseBusName(pattern->pattern(), '[', ']', pathEscape(),
|
||||
is_bus, bus_name, index);
|
||||
if (is_bus) {
|
||||
string escaped1 = escapeBrackets(pattern->pattern(), this);
|
||||
PatternMatch escaped_pattern1(escaped1.c_str(), pattern);
|
||||
matches = network_->findPortsMatching(cell, &escaped_pattern1);
|
||||
if (matches.empty()
|
||||
&& bus_name[strlen(bus_name) - 1] == ']') {
|
||||
if (matches.empty()) {
|
||||
// Try escaping base foo\[0\][1]
|
||||
const char *escaped2 = stringPrintTmp("%s[%d]",
|
||||
escapeBrackets(bus_name, this),
|
||||
index);
|
||||
PatternMatch escaped_pattern2(escaped2, pattern);
|
||||
string escaped2;
|
||||
string escaped_bus_name = escapeBrackets(bus_name.c_str(), this);
|
||||
stringPrint(escaped2, "%s[%d]",
|
||||
escaped_bus_name.c_str(),
|
||||
index);
|
||||
PatternMatch escaped_pattern2(escaped2.c_str(), pattern);
|
||||
matches = network_->findPortsMatching(cell, &escaped_pattern2);
|
||||
}
|
||||
stringDelete(bus_name);
|
||||
}
|
||||
}
|
||||
return matches;
|
||||
@@ -739,8 +742,10 @@ SdcNetwork::findInstance(const char *path_name) const
|
||||
if (parent == nullptr)
|
||||
parent = network_->topInstance();
|
||||
Instance *child = findChild(parent, child_name);
|
||||
if (child == nullptr)
|
||||
child = findChild(parent, escapeDividers(child_name, this));
|
||||
if (child == nullptr) {
|
||||
string escaped_name = escapeDividers(child_name, this);
|
||||
child = findChild(parent, escaped_name.c_str());
|
||||
}
|
||||
return child;
|
||||
}
|
||||
|
||||
@@ -774,8 +779,8 @@ SdcNetwork::findChild(const Instance *parent,
|
||||
{
|
||||
Instance *child = network_->findChild(parent, name);
|
||||
if (child == nullptr) {
|
||||
const char *escaped = escapeBrackets(name, this);
|
||||
child = network_->findChild(parent, escaped);
|
||||
string escaped = escapeBrackets(name, this);
|
||||
child = network_->findChild(parent, escaped.c_str());
|
||||
}
|
||||
return child;
|
||||
}
|
||||
@@ -799,8 +804,8 @@ SdcNetwork::findNet(const Instance *instance,
|
||||
{
|
||||
Net *net = network_->findNet(instance, net_name);
|
||||
if (net == nullptr) {
|
||||
const char *net_name_ = escapeBrackets(net_name, this);
|
||||
net = network_->findNet(instance, net_name_);
|
||||
string net_name1 = escapeBrackets(net_name, this);
|
||||
net = network_->findNet(instance, net_name1.c_str());
|
||||
}
|
||||
return net;
|
||||
}
|
||||
@@ -829,14 +834,13 @@ SdcNetwork::findInstNetsMatching(const Instance *instance,
|
||||
network_->findInstNetsMatching(instance, pattern, matches);
|
||||
if (matches.empty()) {
|
||||
// Look for matches after escaping path dividers.
|
||||
const PatternMatch escaped_dividers(escapeDividers(pattern->pattern(),
|
||||
this),
|
||||
pattern);
|
||||
string escaped_pattern = escapeDividers(pattern->pattern(), this);
|
||||
const PatternMatch escaped_dividers(escaped_pattern.c_str(), pattern);
|
||||
network_->findInstNetsMatching(instance, &escaped_dividers, matches);
|
||||
if (matches.empty()) {
|
||||
// Look for matches after escaping brackets.
|
||||
const PatternMatch escaped_brkts(escapeBrackets(pattern->pattern(),this),
|
||||
pattern);
|
||||
string escaped_pattern2 = escapeBrackets(pattern->pattern(),this);
|
||||
const PatternMatch escaped_brkts(escaped_pattern2.c_str(), pattern);
|
||||
network_->findInstNetsMatching(instance, &escaped_brkts, matches);
|
||||
}
|
||||
}
|
||||
@@ -862,21 +866,21 @@ SdcNetwork::findPin(const Instance *instance,
|
||||
Pin *pin = network_->findPin(instance, port_name);
|
||||
if (pin == nullptr) {
|
||||
// Look for match after escaping brackets.
|
||||
char *bus_name;
|
||||
bool is_bus;
|
||||
string bus_name;
|
||||
int index;
|
||||
parseBusName(port_name, '[', ']', pathEscape(), bus_name, index);
|
||||
if (bus_name) {
|
||||
const char *escaped1 = escapeBrackets(port_name, this);
|
||||
pin = network_->findPin(instance, escaped1);
|
||||
if (pin == nullptr
|
||||
&& bus_name[strlen(bus_name) - 1] == ']') {
|
||||
parseBusName(port_name, '[', ']', pathEscape(),
|
||||
is_bus, bus_name, index);
|
||||
if (is_bus) {
|
||||
string escaped1 = escapeBrackets(port_name, this);
|
||||
pin = network_->findPin(instance, escaped1.c_str());
|
||||
if (pin == nullptr) {
|
||||
// Try escaping base foo\[0\][1]
|
||||
const char *escaped2 = stringPrintTmp("%s[%d]",
|
||||
escapeBrackets(bus_name, this),
|
||||
index);
|
||||
pin = network_->findPin(instance, escaped2);
|
||||
string escaped_bus_name = escapeBrackets(bus_name.c_str(), this);
|
||||
string escaped2;
|
||||
stringPrint(escaped2, "%s[%d]", escaped_bus_name.c_str(), index);
|
||||
pin = network_->findPin(instance, escaped2.c_str());
|
||||
}
|
||||
stringDelete(bus_name);
|
||||
}
|
||||
}
|
||||
return pin;
|
||||
@@ -967,16 +971,16 @@ SdcNetwork::makeInstance(LibertyCell *cell,
|
||||
const char *name,
|
||||
Instance *parent)
|
||||
{
|
||||
const char *escaped_name = escapeDividers(name, this);
|
||||
return network_edit_->makeInstance(cell, escaped_name, parent);
|
||||
string escaped_name = escapeDividers(name, this);
|
||||
return network_edit_->makeInstance(cell, escaped_name.c_str(), parent);
|
||||
}
|
||||
|
||||
Net *
|
||||
SdcNetwork::makeNet(const char *name,
|
||||
Instance *parent)
|
||||
{
|
||||
const char *escaped_name = escapeDividers(name, this);
|
||||
return network_edit_->makeNet(escaped_name, parent);
|
||||
string escaped_name = escapeDividers(name, this);
|
||||
return network_edit_->makeNet(escaped_name.c_str(), parent);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
@@ -1154,10 +1158,9 @@ SdcNetwork::visitMatches(const Instance *parent,
|
||||
found_match |= visit_tail(parent, &tail_pattern);
|
||||
if (!found_match && has_brkts) {
|
||||
// Look for matches after escaping brackets.
|
||||
char *escaped_path = stringCopy(escapeBrackets(inst_path, this));
|
||||
string escaped_path = escapeBrackets(inst_path, this);
|
||||
const PatternMatch escaped_tail(escaped_path, pattern);
|
||||
found_match |= visit_tail(parent, &escaped_tail);
|
||||
stringDelete(escaped_path);
|
||||
}
|
||||
}
|
||||
stringDelete(inst_path);
|
||||
@@ -1166,7 +1169,7 @@ SdcNetwork::visitMatches(const Instance *parent,
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
static const char *
|
||||
static string
|
||||
escapeDividers(const char *token,
|
||||
const Network *network)
|
||||
{
|
||||
@@ -1174,7 +1177,7 @@ escapeDividers(const char *token,
|
||||
network->pathEscape());
|
||||
}
|
||||
|
||||
static const char *
|
||||
static string
|
||||
escapeBrackets(const char *token,
|
||||
const Network *network)
|
||||
{
|
||||
|
||||
+38
-77
@@ -23,72 +23,63 @@
|
||||
|
||||
namespace sta {
|
||||
|
||||
static const char *
|
||||
static string
|
||||
staToVerilog(const char *sta_name,
|
||||
const char escape);
|
||||
static const char *
|
||||
static string
|
||||
staToVerilog2(const char *sta_name,
|
||||
const char escape);
|
||||
static const char *
|
||||
static string
|
||||
verilogToSta(const char *verilog_name);
|
||||
static inline void
|
||||
vstringAppend(char *&str,
|
||||
char *&str_end,
|
||||
char *&insert,
|
||||
char ch);
|
||||
|
||||
const char *
|
||||
string
|
||||
instanceVerilogName(const char *sta_name,
|
||||
const char escape)
|
||||
{
|
||||
return staToVerilog(sta_name, escape);
|
||||
}
|
||||
|
||||
const char *
|
||||
string
|
||||
netVerilogName(const char *sta_name,
|
||||
const char escape)
|
||||
{
|
||||
char *bus_name;
|
||||
bool is_bus;
|
||||
string bus_name;
|
||||
int index;
|
||||
parseBusName(sta_name, '[', ']', escape, bus_name, index);
|
||||
if (bus_name) {
|
||||
const char *vname = stringPrintTmp("%s[%d]",
|
||||
staToVerilog(bus_name, escape),
|
||||
index);
|
||||
stringDelete(bus_name);
|
||||
parseBusName(sta_name, '[', ']', escape, is_bus, bus_name, index);
|
||||
if (is_bus) {
|
||||
string bus_vname = staToVerilog(bus_name.c_str(), escape);
|
||||
string vname;
|
||||
stringPrint(vname, "%s[%d]", bus_vname.c_str(), index);
|
||||
return vname;
|
||||
}
|
||||
else
|
||||
return staToVerilog2(sta_name, escape);
|
||||
}
|
||||
|
||||
const char *
|
||||
string
|
||||
portVerilogName(const char *sta_name,
|
||||
const char escape)
|
||||
{
|
||||
return staToVerilog2(sta_name, escape);
|
||||
}
|
||||
|
||||
static const char *
|
||||
static string
|
||||
staToVerilog(const char *sta_name,
|
||||
const char escape)
|
||||
{
|
||||
// Leave room for leading escape and trailing space if the name
|
||||
// needs to be escaped.
|
||||
size_t verilog_name_length = strlen(sta_name) + 3;
|
||||
char *verilog_name = makeTmpString(verilog_name_length);
|
||||
char *verilog_name_end = &verilog_name[verilog_name_length];
|
||||
char *v = verilog_name;
|
||||
// Assume the name has to be escaped and start copying while scanning.
|
||||
string escaped_name = "\\";
|
||||
bool escaped = false;
|
||||
*v++ = '\\';
|
||||
for (const char *s = sta_name; *s ; s++) {
|
||||
char ch = s[0];
|
||||
if (ch == escape) {
|
||||
char next_ch = s[1];
|
||||
if (next_ch == escape) {
|
||||
vstringAppend(verilog_name, verilog_name_end, v, ch);
|
||||
vstringAppend(verilog_name, verilog_name_end, v, next_ch);
|
||||
escaped_name += ch;
|
||||
escaped_name += next_ch;
|
||||
s++;
|
||||
}
|
||||
else
|
||||
@@ -98,20 +89,19 @@ staToVerilog(const char *sta_name,
|
||||
else {
|
||||
if ((!(isalnum(ch) || ch == '_')))
|
||||
escaped = true;
|
||||
vstringAppend(verilog_name, verilog_name_end, v, ch);
|
||||
escaped_name += ch;
|
||||
}
|
||||
}
|
||||
if (escaped) {
|
||||
// Add a terminating space.
|
||||
vstringAppend(verilog_name, verilog_name_end, v, ' ');
|
||||
vstringAppend(verilog_name, verilog_name_end, v, '\0');
|
||||
return verilog_name;
|
||||
escaped_name += ' ';
|
||||
return escaped_name;
|
||||
}
|
||||
else
|
||||
return sta_name;
|
||||
return string(sta_name);
|
||||
}
|
||||
|
||||
static const char *
|
||||
static string
|
||||
staToVerilog2(const char *sta_name,
|
||||
const char escape)
|
||||
{
|
||||
@@ -119,20 +109,16 @@ staToVerilog2(const char *sta_name,
|
||||
constexpr char bus_brkt_right = ']';
|
||||
// Leave room for leading escape and trailing space if the name
|
||||
// needs to be escaped.
|
||||
size_t verilog_name_length = strlen(sta_name) + 3;
|
||||
char *verilog_name = makeTmpString(verilog_name_length);
|
||||
char *verilog_name_end = &verilog_name[verilog_name_length];
|
||||
char *v = verilog_name;
|
||||
string escaped_name = "\\";
|
||||
// Assume the name has to be escaped and start copying while scanning.
|
||||
bool escaped = false;
|
||||
*v++ = '\\';
|
||||
for (const char *s = sta_name; *s ; s++) {
|
||||
char ch = s[0];
|
||||
if (ch == escape) {
|
||||
char next_ch = s[1];
|
||||
if (next_ch == escape) {
|
||||
vstringAppend(verilog_name, verilog_name_end, v, ch);
|
||||
vstringAppend(verilog_name, verilog_name_end, v, next_ch);
|
||||
escaped_name += ch;
|
||||
escaped_name += next_ch;
|
||||
s++;
|
||||
}
|
||||
else
|
||||
@@ -144,46 +130,45 @@ staToVerilog2(const char *sta_name,
|
||||
if ((!(isalnum(ch) || ch == '_') && !is_brkt)
|
||||
|| is_brkt)
|
||||
escaped = true;
|
||||
vstringAppend(verilog_name, verilog_name_end, v, ch);
|
||||
escaped_name += ch;
|
||||
}
|
||||
}
|
||||
if (escaped) {
|
||||
// Add a terminating space.
|
||||
vstringAppend(verilog_name, verilog_name_end, v, ' ');
|
||||
vstringAppend(verilog_name, verilog_name_end, v, '\0');
|
||||
return verilog_name;
|
||||
escaped_name += ' ';
|
||||
return escaped_name;
|
||||
}
|
||||
else
|
||||
return sta_name;
|
||||
return string(sta_name);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////
|
||||
|
||||
const char *
|
||||
string
|
||||
moduleVerilogToSta(const char *module_name)
|
||||
{
|
||||
return verilogToSta(module_name);
|
||||
}
|
||||
|
||||
const char *
|
||||
string
|
||||
instanceVerilogToSta(const char *inst_name)
|
||||
{
|
||||
return verilogToSta(inst_name);
|
||||
}
|
||||
|
||||
const char *
|
||||
string
|
||||
netVerilogToSta(const char *net_name)
|
||||
{
|
||||
return verilogToSta(net_name);
|
||||
}
|
||||
|
||||
const char *
|
||||
string
|
||||
portVerilogToSta(const char *port_name)
|
||||
{
|
||||
return verilogToSta(port_name);
|
||||
}
|
||||
|
||||
static const char *
|
||||
static string
|
||||
verilogToSta(const char *verilog_name)
|
||||
{
|
||||
if (verilog_name && verilog_name[0] == '\\') {
|
||||
@@ -197,11 +182,7 @@ verilogToSta(const char *verilog_name)
|
||||
size_t verilog_name_length = strlen(verilog_name);
|
||||
if (verilog_name[verilog_name_length - 1] == ' ')
|
||||
verilog_name_length--;
|
||||
// +1 for \0, +2 for escaping brackets.
|
||||
size_t sta_name_length = verilog_name_length + 1;
|
||||
char *sta_name = makeTmpString(sta_name_length);
|
||||
char *sta_name_end = &sta_name[sta_name_length];
|
||||
char *s = sta_name;
|
||||
string sta_name;
|
||||
for (size_t i = 0; i < verilog_name_length; i++) {
|
||||
char ch = verilog_name[i];
|
||||
if (ch == bus_brkt_left
|
||||
@@ -209,33 +190,13 @@ verilogToSta(const char *verilog_name)
|
||||
|| ch == divider
|
||||
|| ch == escape)
|
||||
// Escape bus brackets, dividers and escapes.
|
||||
vstringAppend(sta_name, sta_name_end, s, escape);
|
||||
vstringAppend(sta_name, sta_name_end, s, ch);
|
||||
sta_name += escape;
|
||||
sta_name += ch;
|
||||
}
|
||||
vstringAppend(sta_name, sta_name_end, s, '\0');
|
||||
return sta_name;
|
||||
}
|
||||
else
|
||||
return verilog_name;
|
||||
}
|
||||
|
||||
// Append ch to str at insert. Resize str if necessary.
|
||||
static inline void
|
||||
vstringAppend(char *&str,
|
||||
char *&str_end,
|
||||
char *&insert,
|
||||
char ch)
|
||||
{
|
||||
if (insert == str_end) {
|
||||
size_t length = str_end - str;
|
||||
size_t length2 = length * 2;
|
||||
char *new_str = makeTmpString(length2);
|
||||
strncpy(new_str, str, length);
|
||||
str = new_str;
|
||||
str_end = &str[length2];
|
||||
insert = &str[length];
|
||||
}
|
||||
*insert++ = ch;
|
||||
return string(verilog_name);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
Reference in New Issue
Block a user