Skip to content

Commit b8b67ba

Browse files
committed
spef unescaped names resolves #208
commit ce315777630daa66702dc08f60992dd50ad822c1 Author: James Cherry <[email protected]> Date: Mon Feb 10 17:30:34 2025 -0700 spef missing escapes Signed-off-by: James Cherry <[email protected]> Signed-off-by: James Cherry <[email protected]>
1 parent 0dfea7d commit b8b67ba

File tree

6 files changed

+89
-48
lines changed

6 files changed

+89
-48
lines changed

include/sta/Network.hh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,8 +210,8 @@ public:
210210
virtual bool isTopInstance(const Instance *inst) const;
211211
virtual Instance *findInstance(const char *path_name) const;
212212
// Find instance relative to hierarchical instance.
213-
Instance *findInstanceRelative(const Instance *inst,
214-
const char *path_name) const;
213+
virtual Instance *findInstanceRelative(const Instance *inst,
214+
const char *path_name) const;
215215
// Default implementation uses linear search.
216216
virtual InstanceSeq findInstancesMatching(const Instance *context,
217217
const PatternMatch *pattern) const;
@@ -363,8 +363,8 @@ public:
363363
virtual ObjectId id(const Net *net) const = 0;
364364
virtual Net *findNet(const char *path_name) const;
365365
// Find net relative to hierarchical instance.
366-
Net *findNetRelative(const Instance *inst,
367-
const char *path_name) const;
366+
virtual Net *findNetRelative(const Instance *inst,
367+
const char *path_name) const;
368368
// Default implementation uses linear search.
369369
virtual NetSeq findNetsMatching(const Instance *context,
370370
const PatternMatch *pattern) const;

include/sta/SdcNetwork.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,13 @@ public:
208208
const char *pathName(const Net *net) const override;
209209

210210
Instance *findInstance(const char *path_name) const override;
211+
Instance *findInstanceRelative(const Instance *inst,
212+
const char *path_name) const override;
211213
InstanceSeq findInstancesMatching(const Instance *context,
212214
const PatternMatch *pattern) const override;
213215
Net *findNet(const char *path_name) const override;
216+
Net *findNetRelative(const Instance *instance,
217+
const char *net_name) const override;
214218
Net *findNet(const Instance *instance,
215219
const char *net_name) const override;
216220
NetSeq findNetsMatching(const Instance *parent,

network/SdcNetwork.cc

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,22 @@ SdcNetwork::findInstance(const char *path_name) const
789789
return child;
790790
}
791791

792+
Instance *
793+
SdcNetwork::findInstanceRelative(const Instance *inst,
794+
const char *path_name) const
795+
{
796+
Instance *inst1 = network_->findInstanceRelative(inst, path_name);
797+
if (inst1 == nullptr) {
798+
string path_name1 = escapeBrackets(path_name, this);
799+
inst1 = network_->findInstanceRelative(inst, path_name1.c_str());
800+
if (inst1 == nullptr) {
801+
string path_name2 = escapeDividers(path_name1.c_str(), network_);
802+
inst1 = network_->findInstanceRelative(inst, path_name2.c_str());
803+
}
804+
}
805+
return inst1;
806+
}
807+
792808
InstanceSeq
793809
SdcNetwork::findInstancesMatching(const Instance *context,
794810
const PatternMatch *pattern) const
@@ -835,17 +851,34 @@ SdcNetwork::findNet(const char *path_name) const
835851
parsePath(path_name, inst, net_name);
836852
if (inst == nullptr)
837853
inst = network_->topInstance();
838-
return findNet(inst, net_name);
854+
return findNetRelative(inst, net_name);
839855
}
840856

841857
Net *
842858
SdcNetwork::findNet(const Instance *instance,
843-
const char *net_name) const
859+
const char *net_name) const
844860
{
845861
Net *net = network_->findNet(instance, net_name);
846862
if (net == nullptr) {
847863
string net_name1 = escapeBrackets(net_name, this);
848-
net = network_->findNet(instance, net_name1.c_str());
864+
string net_name2 = escapeDividers(net_name1.c_str(), network_);
865+
net = network_->findNet(instance, net_name2.c_str());
866+
}
867+
return net;
868+
}
869+
870+
Net *
871+
SdcNetwork::findNetRelative(const Instance *inst,
872+
const char *path_name) const
873+
{
874+
Net *net = network_->findNetRelative(inst, path_name);
875+
if (net == nullptr) {
876+
string path_name1 = escapeBrackets(path_name, this);
877+
net = network_->findNetRelative(inst, path_name1.c_str());
878+
if (net == nullptr) {
879+
string path_name2 = escapeDividers(path_name1.c_str(), network_);
880+
net = network_->findNetRelative(inst, path_name2.c_str());
881+
}
849882
}
850883
return net;
851884
}

parasitics/SpefLex.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ typedef sta::SpefParse::token token;
5151
%option never-interactive
5252
%option stack
5353
%option yylineno
54-
/* %option debug */
54+
%option debug
5555

5656
%x COMMENT
5757
%x QUOTE

parasitics/SpefReader.cc

Lines changed: 37 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,6 @@ SpefReader::~SpefReader()
106106
delete design_flow_;
107107
design_flow_ = nullptr;
108108
}
109-
110-
for (const auto [index, name] : name_map_)
111-
stringDelete(name);
112109
}
113110

114111
bool
@@ -121,6 +118,7 @@ SpefReader::read()
121118
SpefScanner scanner(&stream, filename_, this, report_);
122119
scanner_ = &scanner;
123120
SpefParse parser(&scanner, this);
121+
//parser.set_debug_level(1);
124122
// yyparse returns 0 on success.
125123
success = (parser.parse() == 0);
126124
stats.report("Read spef");
@@ -160,7 +158,7 @@ SpefReader::setBusBrackets(char left,
160158
Instance *
161159
SpefReader::findInstanceRelative(const char *name)
162160
{
163-
return network_->findInstanceRelative(instance_, name);
161+
return sdc_network_->findInstanceRelative(instance_, name);
164162
}
165163

166164
Net *
@@ -257,21 +255,21 @@ SpefReader::setInductScale(float scale,
257255
}
258256

259257
void
260-
SpefReader::makeNameMapEntry(char *index,
261-
char *name)
258+
SpefReader::makeNameMapEntry(const char *index,
259+
const char *name)
262260
{
263261
int i = atoi(index + 1);
264262
name_map_[i] = name;
265263
}
266264

267-
char *
268-
SpefReader::nameMapLookup(char *name)
265+
const char *
266+
SpefReader::nameMapLookup(const char *name)
269267
{
270268
if (name && name[0] == '*') {
271269
int index = atoi(name + 1);
272-
auto itr = name_map_.find(index);
270+
const auto &itr = name_map_.find(index);
273271
if (itr != name_map_.end())
274-
return itr->second;
272+
return itr->second.c_str();
275273
else {
276274
warn(1645, "no name map entry for %d.", index);
277275
return nullptr;
@@ -310,19 +308,19 @@ SpefReader::findPin(char *name)
310308
char *delim = strrchr(name, delimiter_);
311309
if (delim) {
312310
*delim = '\0';
313-
name = nameMapLookup(name);
314-
if (name) {
315-
Instance *inst = findInstanceRelative(name);
311+
const char *name1 = nameMapLookup(name);
312+
if (name1) {
313+
Instance *inst = findInstanceRelative(name1);
316314
// Replace delimiter for error messages.
317315
*delim = delimiter_;
318316
const char *port_name = delim + 1;
319317
if (inst) {
320318
pin = network_->findPin(inst, port_name);
321319
if (pin == nullptr)
322-
warn(1647, "pin %s not found.", name);
320+
warn(1647, "pin %s not found.", name1);
323321
}
324322
else
325-
warn(1648, "instance %s not found.", name);
323+
warn(1648, "instance %s not found.", name1);
326324
}
327325
}
328326
else {
@@ -335,14 +333,14 @@ SpefReader::findPin(char *name)
335333
}
336334

337335
Net *
338-
SpefReader::findNet(char *name)
336+
SpefReader::findNet(const char *name)
339337
{
340338
Net *net = nullptr;
341-
name = nameMapLookup(name);
342-
if (name) {
343-
net = findNetRelative(name);
339+
const char *name1 = nameMapLookup(name);
340+
if (name1) {
341+
net = findNetRelative(name1);
344342
if (net == nullptr)
345-
warn(1650, "net %s not found.", name);
343+
warn(1650, "net %s not found.", name1);
346344
}
347345
return net;
348346
}
@@ -447,26 +445,26 @@ SpefReader::findParasiticNode(char *name,
447445
if (delim) {
448446
*delim = '\0';
449447
char *name2 = delim + 1;
450-
name = nameMapLookup(name);
451-
if (name) {
452-
Instance *inst = findInstanceRelative(name);
448+
const char *name1 = nameMapLookup(name);
449+
if (name1) {
450+
Instance *inst = findInstanceRelative(name1);
453451
if (inst) {
454452
// <instance>:<port>
455453
Pin *pin = network_->findPin(inst, name2);
456454
if (pin) {
457455
if (local_only
458456
&& !network_->isConnected(net_, pin))
459-
warn(1651, "%s not connected to net %s.", name, network_->pathName(net_));
457+
warn(1651, "%s not connected to net %s.", name1, network_->pathName(net_));
460458
return parasitics_->ensureParasiticNode(parasitic_, pin, network_);
461459
}
462460
else {
463461
// Replace delimiter for error message.
464462
*delim = delimiter_;
465-
warn(1652, "pin %s not found.", name);
463+
warn(1652, "pin %s not found.", name1);
466464
}
467465
}
468466
else {
469-
Net *net = findNet(name);
467+
Net *net = findNet(name1);
470468
// Replace delimiter for error messages.
471469
*delim = delimiter_;
472470
if (net) {
@@ -477,25 +475,29 @@ SpefReader::findParasiticNode(char *name,
477475
if (local_only
478476
&& !network_->isConnected(net, net_))
479477
warn(1653, "%s not connected to net %s.",
480-
name,
478+
name1,
481479
network_->pathName(net_));
482480
return parasitics_->ensureParasiticNode(parasitic_, net, id, network_);
483481
}
484482
else
485-
warn(1654, "node %s not a pin or net:number", name);
483+
warn(1654, "node %s not a pin or net:number", name1);
486484
}
487485
}
488486
}
489487
}
490488
else {
491489
// <top_level_port>
492-
name = nameMapLookup(name);
493-
Pin *pin = findPortPinRelative(name);
494-
if (pin) {
495-
if (local_only
496-
&& !network_->isConnected(net_, pin))
497-
warn(1655, "%s not connected to net %s.", name, network_->pathName(net_));
498-
return parasitics_->ensureParasiticNode(parasitic_, pin, network_);
490+
const char *name1 = nameMapLookup(name);
491+
if (name1) {
492+
Pin *pin = findPortPinRelative(name1);
493+
if (pin) {
494+
if (local_only
495+
&& !network_->isConnected(net_, pin))
496+
warn(1655, "%s not connected to net %s.", name1, network_->pathName(net_));
497+
return parasitics_->ensureParasiticNode(parasitic_, pin, network_);
498+
}
499+
else
500+
warn(1656, "pin %s not found.", name1);
499501
}
500502
else
501503
warn(1656, "pin %s not found.", name);

parasitics/SpefReaderPvt.hh

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,9 @@ class SpefTriple;
4141
class Corner;
4242
class SpefScanner;
4343

44-
typedef std::map<int, char*, std::less<int>> SpefNameMap;
44+
using std::string;
45+
46+
typedef std::map<int, string> SpefNameMap;
4547

4648
class SpefReader : public StaState
4749
{
@@ -79,12 +81,12 @@ public:
7981
const char *units);
8082
void setInductScale(float scale,
8183
const char *units);
82-
void makeNameMapEntry(char *index,
83-
char *name);
84-
char *nameMapLookup(char *index);
84+
void makeNameMapEntry(const char *index,
85+
const char *name);
86+
const char *nameMapLookup(const char *index);
8587
void setDesignFlow(StringSeq *flow_keys);
8688
Pin *findPin(char *name);
87-
Net *findNet(char *name);
89+
Net *findNet(const char *name);
8890
void rspfBegin(Net *net,
8991
SpefTriple *total_cap);
9092
void rspfFinish();

0 commit comments

Comments
 (0)