spef unescaped names resolves #208

commit ce315777630daa66702dc08f60992dd50ad822c1
Author: James Cherry <cherry@parallaxsw.com>
Date:   Mon Feb 10 17:30:34 2025 -0700

    spef missing escapes

    Signed-off-by: James Cherry <cherry@parallaxsw.com>

Signed-off-by: James Cherry <cherry@parallaxsw.com>
This commit is contained in:
James Cherry 2025-02-10 17:32:50 -07:00
parent 0dfea7dfad
commit b8b67ba4df
6 changed files with 89 additions and 48 deletions

View File

@ -210,8 +210,8 @@ public:
virtual bool isTopInstance(const Instance *inst) const;
virtual Instance *findInstance(const char *path_name) const;
// Find instance relative to hierarchical instance.
Instance *findInstanceRelative(const Instance *inst,
const char *path_name) const;
virtual Instance *findInstanceRelative(const Instance *inst,
const char *path_name) const;
// Default implementation uses linear search.
virtual InstanceSeq findInstancesMatching(const Instance *context,
const PatternMatch *pattern) const;
@ -363,8 +363,8 @@ public:
virtual ObjectId id(const Net *net) const = 0;
virtual Net *findNet(const char *path_name) const;
// Find net relative to hierarchical instance.
Net *findNetRelative(const Instance *inst,
const char *path_name) const;
virtual Net *findNetRelative(const Instance *inst,
const char *path_name) const;
// Default implementation uses linear search.
virtual NetSeq findNetsMatching(const Instance *context,
const PatternMatch *pattern) const;

View File

@ -208,9 +208,13 @@ public:
const char *pathName(const Net *net) const override;
Instance *findInstance(const char *path_name) const override;
Instance *findInstanceRelative(const Instance *inst,
const char *path_name) const override;
InstanceSeq findInstancesMatching(const Instance *context,
const PatternMatch *pattern) const override;
Net *findNet(const char *path_name) const override;
Net *findNetRelative(const Instance *instance,
const char *net_name) const override;
Net *findNet(const Instance *instance,
const char *net_name) const override;
NetSeq findNetsMatching(const Instance *parent,

View File

@ -789,6 +789,22 @@ SdcNetwork::findInstance(const char *path_name) const
return child;
}
Instance *
SdcNetwork::findInstanceRelative(const Instance *inst,
const char *path_name) const
{
Instance *inst1 = network_->findInstanceRelative(inst, path_name);
if (inst1 == nullptr) {
string path_name1 = escapeBrackets(path_name, this);
inst1 = network_->findInstanceRelative(inst, path_name1.c_str());
if (inst1 == nullptr) {
string path_name2 = escapeDividers(path_name1.c_str(), network_);
inst1 = network_->findInstanceRelative(inst, path_name2.c_str());
}
}
return inst1;
}
InstanceSeq
SdcNetwork::findInstancesMatching(const Instance *context,
const PatternMatch *pattern) const
@ -835,17 +851,34 @@ SdcNetwork::findNet(const char *path_name) const
parsePath(path_name, inst, net_name);
if (inst == nullptr)
inst = network_->topInstance();
return findNet(inst, net_name);
return findNetRelative(inst, net_name);
}
Net *
SdcNetwork::findNet(const Instance *instance,
const char *net_name) const
const char *net_name) const
{
Net *net = network_->findNet(instance, net_name);
if (net == nullptr) {
string net_name1 = escapeBrackets(net_name, this);
net = network_->findNet(instance, net_name1.c_str());
string net_name2 = escapeDividers(net_name1.c_str(), network_);
net = network_->findNet(instance, net_name2.c_str());
}
return net;
}
Net *
SdcNetwork::findNetRelative(const Instance *inst,
const char *path_name) const
{
Net *net = network_->findNetRelative(inst, path_name);
if (net == nullptr) {
string path_name1 = escapeBrackets(path_name, this);
net = network_->findNetRelative(inst, path_name1.c_str());
if (net == nullptr) {
string path_name2 = escapeDividers(path_name1.c_str(), network_);
net = network_->findNetRelative(inst, path_name2.c_str());
}
}
return net;
}

View File

@ -51,7 +51,7 @@ typedef sta::SpefParse::token token;
%option never-interactive
%option stack
%option yylineno
/* %option debug */
%option debug
%x COMMENT
%x QUOTE

View File

@ -106,9 +106,6 @@ SpefReader::~SpefReader()
delete design_flow_;
design_flow_ = nullptr;
}
for (const auto [index, name] : name_map_)
stringDelete(name);
}
bool
@ -121,6 +118,7 @@ SpefReader::read()
SpefScanner scanner(&stream, filename_, this, report_);
scanner_ = &scanner;
SpefParse parser(&scanner, this);
//parser.set_debug_level(1);
// yyparse returns 0 on success.
success = (parser.parse() == 0);
stats.report("Read spef");
@ -160,7 +158,7 @@ SpefReader::setBusBrackets(char left,
Instance *
SpefReader::findInstanceRelative(const char *name)
{
return network_->findInstanceRelative(instance_, name);
return sdc_network_->findInstanceRelative(instance_, name);
}
Net *
@ -257,21 +255,21 @@ SpefReader::setInductScale(float scale,
}
void
SpefReader::makeNameMapEntry(char *index,
char *name)
SpefReader::makeNameMapEntry(const char *index,
const char *name)
{
int i = atoi(index + 1);
name_map_[i] = name;
}
char *
SpefReader::nameMapLookup(char *name)
const char *
SpefReader::nameMapLookup(const char *name)
{
if (name && name[0] == '*') {
int index = atoi(name + 1);
auto itr = name_map_.find(index);
const auto &itr = name_map_.find(index);
if (itr != name_map_.end())
return itr->second;
return itr->second.c_str();
else {
warn(1645, "no name map entry for %d.", index);
return nullptr;
@ -310,19 +308,19 @@ SpefReader::findPin(char *name)
char *delim = strrchr(name, delimiter_);
if (delim) {
*delim = '\0';
name = nameMapLookup(name);
if (name) {
Instance *inst = findInstanceRelative(name);
const char *name1 = nameMapLookup(name);
if (name1) {
Instance *inst = findInstanceRelative(name1);
// Replace delimiter for error messages.
*delim = delimiter_;
const char *port_name = delim + 1;
if (inst) {
pin = network_->findPin(inst, port_name);
if (pin == nullptr)
warn(1647, "pin %s not found.", name);
warn(1647, "pin %s not found.", name1);
}
else
warn(1648, "instance %s not found.", name);
warn(1648, "instance %s not found.", name1);
}
}
else {
@ -335,14 +333,14 @@ SpefReader::findPin(char *name)
}
Net *
SpefReader::findNet(char *name)
SpefReader::findNet(const char *name)
{
Net *net = nullptr;
name = nameMapLookup(name);
if (name) {
net = findNetRelative(name);
const char *name1 = nameMapLookup(name);
if (name1) {
net = findNetRelative(name1);
if (net == nullptr)
warn(1650, "net %s not found.", name);
warn(1650, "net %s not found.", name1);
}
return net;
}
@ -447,26 +445,26 @@ SpefReader::findParasiticNode(char *name,
if (delim) {
*delim = '\0';
char *name2 = delim + 1;
name = nameMapLookup(name);
if (name) {
Instance *inst = findInstanceRelative(name);
const char *name1 = nameMapLookup(name);
if (name1) {
Instance *inst = findInstanceRelative(name1);
if (inst) {
// <instance>:<port>
Pin *pin = network_->findPin(inst, name2);
if (pin) {
if (local_only
&& !network_->isConnected(net_, pin))
warn(1651, "%s not connected to net %s.", name, network_->pathName(net_));
warn(1651, "%s not connected to net %s.", name1, network_->pathName(net_));
return parasitics_->ensureParasiticNode(parasitic_, pin, network_);
}
else {
// Replace delimiter for error message.
*delim = delimiter_;
warn(1652, "pin %s not found.", name);
warn(1652, "pin %s not found.", name1);
}
}
else {
Net *net = findNet(name);
Net *net = findNet(name1);
// Replace delimiter for error messages.
*delim = delimiter_;
if (net) {
@ -477,25 +475,29 @@ SpefReader::findParasiticNode(char *name,
if (local_only
&& !network_->isConnected(net, net_))
warn(1653, "%s not connected to net %s.",
name,
name1,
network_->pathName(net_));
return parasitics_->ensureParasiticNode(parasitic_, net, id, network_);
}
else
warn(1654, "node %s not a pin or net:number", name);
warn(1654, "node %s not a pin or net:number", name1);
}
}
}
}
else {
// <top_level_port>
name = nameMapLookup(name);
Pin *pin = findPortPinRelative(name);
if (pin) {
if (local_only
&& !network_->isConnected(net_, pin))
warn(1655, "%s not connected to net %s.", name, network_->pathName(net_));
return parasitics_->ensureParasiticNode(parasitic_, pin, network_);
const char *name1 = nameMapLookup(name);
if (name1) {
Pin *pin = findPortPinRelative(name1);
if (pin) {
if (local_only
&& !network_->isConnected(net_, pin))
warn(1655, "%s not connected to net %s.", name1, network_->pathName(net_));
return parasitics_->ensureParasiticNode(parasitic_, pin, network_);
}
else
warn(1656, "pin %s not found.", name1);
}
else
warn(1656, "pin %s not found.", name);

View File

@ -41,7 +41,9 @@ class SpefTriple;
class Corner;
class SpefScanner;
typedef std::map<int, char*, std::less<int>> SpefNameMap;
using std::string;
typedef std::map<int, string> SpefNameMap;
class SpefReader : public StaState
{
@ -79,12 +81,12 @@ public:
const char *units);
void setInductScale(float scale,
const char *units);
void makeNameMapEntry(char *index,
char *name);
char *nameMapLookup(char *index);
void makeNameMapEntry(const char *index,
const char *name);
const char *nameMapLookup(const char *index);
void setDesignFlow(StringSeq *flow_keys);
Pin *findPin(char *name);
Net *findNet(char *name);
Net *findNet(const char *name);
void rspfBegin(Net *net,
SpefTriple *total_cap);
void rspfFinish();