forked from The-OpenROAD-Project-Attic/Resizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
LefDefSdcNetwork.cc
216 lines (202 loc) · 5.89 KB
/
LefDefSdcNetwork.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
// Resizer, LEF/DEF gate resizer
// Copyright (c) 2019, Parallax Software, Inc.
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include "Machine.hh"
#include "PatternMatch.hh"
#include "ParseBus.hh"
#include "LefDefSdcNetwork.hh"
namespace sta {
static const char *
escapeDividers(const char *token,
const Network *network);
LefDefSdcNetwork::LefDefSdcNetwork(Network *network) :
SdcNetwork(network)
{
}
// Override SdcNetwork to NetworkNameAdapter.
Instance *
LefDefSdcNetwork::findInstance(const char *path_name) const
{
Instance *inst = network_->findInstance(path_name);
if (inst == nullptr)
inst = network_->findInstance(escapeDividers(path_name, this));
return inst;
}
void
LefDefSdcNetwork::findInstancesMatching(const Instance *,
const PatternMatch *pattern,
InstanceSeq *insts) const
{
if (pattern->hasWildcards())
findInstancesMatching1(pattern, insts);
else {
Instance *inst = findInstance(pattern->pattern());
if (inst)
insts->push_back(inst);
else {
// Look for a match with path dividers escaped.
const char *escaped = escapeChars(pattern->pattern(), divider_, '\0',
escape_);
inst = findInstance(escaped);
if (inst)
insts->push_back(inst);
else
findInstancesMatching1(pattern, insts);
}
}
}
void
LefDefSdcNetwork::findInstancesMatching1(const PatternMatch *pattern,
InstanceSeq *insts) const
{
InstanceChildIterator *child_iter = childIterator(topInstance());
while (child_iter->hasNext()) {
Instance *child = child_iter->next();
if (pattern->match(staToSdc(name(child))))
insts->push_back(child);
}
delete child_iter;
}
void
LefDefSdcNetwork::findNetsMatching(const Instance *,
const PatternMatch *pattern,
NetSeq *nets) const
{
if (pattern->hasWildcards())
findNetsMatching1(pattern, nets);
else {
Net *net = findNet(pattern->pattern());
if (net)
nets->push_back(net);
else {
// Look for a match with path dividers escaped.
const char *escaped = escapeChars(pattern->pattern(), divider_, '\0',
escape_);
net = findNet(escaped);
if (net)
nets->push_back(net);
else
findNetsMatching1(pattern, nets);
}
}
}
void
LefDefSdcNetwork::findNetsMatching1(const PatternMatch *pattern,
NetSeq *nets) const
{
NetIterator *net_iter = netIterator(topInstance());
while (net_iter->hasNext()) {
Net *net = net_iter->next();
if (pattern->match(staToSdc(name(net))))
nets->push_back(net);
}
delete net_iter;
}
void
LefDefSdcNetwork::findPinsMatching(const Instance *instance,
const PatternMatch *pattern,
PinSeq *pins) const
{
if (stringEq(pattern->pattern(), "*")) {
// Pattern of '*' matches all child instance pins.
InstanceChildIterator *child_iter = childIterator(instance);
while (child_iter->hasNext()) {
Instance *child = child_iter->next();
InstancePinIterator *pin_iter = pinIterator(child);
while (pin_iter->hasNext()) {
Pin *pin = pin_iter->next();
pins->push_back(pin);
}
delete pin_iter;
}
delete child_iter;
}
else {
char *inst_path, *port_name;
pathNameLast(pattern->pattern(), inst_path, port_name);
if (port_name) {
PatternMatch inst_pattern(inst_path, pattern);
InstanceSeq insts;
findInstancesMatching(nullptr, &inst_pattern, &insts);
PatternMatch port_pattern(port_name, pattern);
for (auto inst : insts)
findMatchingPins(inst, &port_pattern, pins);
}
}
}
void
LefDefSdcNetwork::findMatchingPins(const Instance *instance,
const PatternMatch *port_pattern,
PinSeq *pins) const
{
if (instance != network_->topInstance()) {
Cell *cell = network_->cell(instance);
CellPortIterator *port_iter = network_->portIterator(cell);
while (port_iter->hasNext()) {
Port *port = port_iter->next();
const char *port_name = network_->name(port);
if (network_->hasMembers(port)) {
bool bus_matches = port_pattern->match(port_name)
|| port_pattern->match(escapeDividers(port_name, network_));
PortMemberIterator *member_iter = network_->memberIterator(port);
while (member_iter->hasNext()) {
Port *member_port = member_iter->next();
Pin *pin = network_->findPin(instance, member_port);
if (pin) {
if (bus_matches)
pins->push_back(pin);
else {
const char *member_name = network_->name(member_port);
if (port_pattern->match(member_name)
|| port_pattern->match(escapeDividers(member_name, network_)))
pins->push_back(pin);
}
}
}
delete member_iter;
}
else if (port_pattern->match(port_name)
|| port_pattern->match(escapeDividers(port_name, network_))) {
Pin *pin = network_->findPin(instance, port);
if (pin)
pins->push_back(pin);
}
}
delete port_iter;
}
}
Pin *
LefDefSdcNetwork::findPin(const char *path_name) const
{
char *inst_path, *port_name;
pathNameLast(path_name, inst_path, port_name);
if (inst_path) {
Instance *inst = findInstance(inst_path);
if (inst)
return findPin(inst, port_name);
else
return nullptr;
}
else
return findPin(topInstance(), path_name);
}
static const char *
escapeDividers(const char *token,
const Network *network)
{
return escapeChars(token, network->pathDivider(), '\0',
network->pathEscape());
}
} // namespace