forked from wrcad/xictools
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathext_duality.h
333 lines (291 loc) · 11.3 KB
/
ext_duality.h
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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
/*========================================================================*
* *
* Distributed by Whiteley Research Inc., Sunnyvale, California, USA *
* http://wrcad.com *
* Copyright (C) 2017 Whiteley Research Inc., all rights reserved. *
* Author: Stephen R. Whiteley, except as indicated. *
* *
* As fully as possible recognizing licensing terms and conditions *
* imposed by earlier work from which this work was derived, if any, *
* this work is released under the Apache License, Version 2.0 (the *
* "License"). You may not use this file except in compliance with *
* the License, and compliance with inherited licenses which are *
* specified in a sub-header below this one if applicable. A copy *
* of the License is provided with this distribution, or you may *
* obtain a copy of the License at *
* *
* http://www.apache.org/licenses/LICENSE-2.0 *
* *
* See the License for the specific language governing permissions *
* and limitations under the License. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, *
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES *
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON- *
* INFRINGEMENT. IN NO EVENT SHALL WHITELEY RESEARCH INCORPORATED *
* OR STEPHEN R. WHITELEY BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, *
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* *
*========================================================================*
* XicTools Integrated Circuit Design System *
* *
* Xic Integrated Circuit Layout and Schematic Editor *
* *
*========================================================================*
$Id:$
*========================================================================*/
#ifndef EXT_DUALITY_H
#define EXT_DUALITY_H
//========================================================================
//
// Structs to record associations after an imposed symmetry breaking.
// This allows the actions to be undone, another of the symmetry
// choices applied, and the associations redone. The structures are
// linked, allowing the context to be nested.
//
//========================================================================
namespace ext_duality {
// List element for group/node associations.
//
struct sSymGrp
{
sSymGrp(int g, int n, sSymGrp *nx = 0)
{
sg_group = g;
sg_node = n;
sg_next = nx;
}
static void destroy(sSymGrp *s)
{
while (s) {
sSymGrp *x = s;
s = s->next();
delete x;
}
}
int group() const { return (sg_group); }
int node() const { return (sg_node); }
sSymGrp *next() const { return (sg_next); }
void set_next(sSymGrp *n) { sg_next = n; }
private:
int sg_group;
int sg_node;
sSymGrp *sg_next;
};
// List element for device associations.
//
struct sSymDev
{
sSymDev(sDevInst *d, sEinstList *e, sSymDev *nx = 0)
{
sd_pdev = d;
sd_edev = e;
sd_next = nx;
}
static void destroy(sSymDev *s)
{
while (s) {
sSymDev *x = s;
s = s->next();
delete x;
}
}
sDevInst *phys_dev() const { return (sd_pdev); }
sEinstList *elec_dev() const { return (sd_edev); }
sSymDev *next() const { return (sd_next); }
void set_next(sSymDev *n) { sd_next = n; }
private:
sDevInst *sd_pdev;
sEinstList *sd_edev;
sSymDev *sd_next;
};
// List element for subcircuit associations.
//
struct sSymSubc
{
sSymSubc(sSubcInst *s, sEinstList *e, sSymSubc *nx = 0)
{
ss_psub = s;
ss_esub = e;
ss_next = nx;
}
static void destroy(sSymSubc *s)
{
while (s) {
sSymSubc *x = s;
s = s->next();
delete x;
}
}
sSubcInst *phys_subc() const { return (ss_psub); }
sEinstList *elec_subc() const { return (ss_esub); }
sSymSubc *next() const { return (ss_next); }
void set_next(sSymSubc *n) { ss_next = n; }
private:
sSubcInst *ss_psub;
sEinstList *ss_esub;
sSymSubc *ss_next;
};
// List element for sEinstList objects.
//
struct sSymCll
{
sSymCll(sEinstList *c, sSymCll *nx = 0)
{
sc_clist = c;
sc_next = nx;
}
static void destroy(sSymCll *s)
{
while (s) {
sSymCll *x = s;
s = s->next();
delete x;
}
}
sEinstList *inst_elem() const { return (sc_clist); }
sSymCll *next() const { return (sc_next); }
void set_next(sSymCll *n) { sc_next = n; }
private:
sEinstList *sc_clist;
sSymCll *sc_next;
};
// The main context scruct. This is created when symmetry
// breaking is imposed.
//
struct sSymBrk
{
sSymBrk(sDevInst *di, sSymCll *el, sSymBrk *n)
{
sb_dev = di;
sb_subc = 0;
sb_elist = el;
sb_grp_assoc = 0;
sb_dev_assoc = 0;
sb_subc_assoc = 0;
sb_next = n;
}
sSymBrk(sSubcInst *s, sSymCll *el, sSymBrk *n)
{
sb_dev = 0;
sb_subc = s;
sb_elist = el;
sb_grp_assoc = 0;
sb_dev_assoc = 0;
sb_subc_assoc = 0;
sb_next = n;
}
sSymBrk(const sSymBrk&);
~sSymBrk()
{
sSymCll::destroy(sb_elist);
sSymGrp::destroy(sb_grp_assoc);
sSymDev::destroy(sb_dev_assoc);
sSymSubc::destroy(sb_subc_assoc);
}
static void destroy(sSymBrk *s)
{
while (s) {
sSymBrk *x = s;
s = s->next();
delete x;
}
}
static sSymBrk *dup(const sSymBrk *thissb)
{
sSymBrk *s0 = 0, *se = 0;
for (const sSymBrk *s = thissb; s; s = s->next()) {
if (!s0)
s0 = se = new sSymBrk(*s);
else {
se->set_next(new sSymBrk(*s));
se = se->next();
}
}
return (s0);
}
void new_grp_assoc(int g, int n)
{
sb_grp_assoc = new sSymGrp(g, n, sb_grp_assoc);
}
void new_dev_assoc(sDevInst *di, sEinstList *e)
{
sb_dev_assoc = new sSymDev(di, e, sb_dev_assoc);
}
void new_subc_assoc(sSubcInst *s, sEinstList *e)
{
sb_subc_assoc = new sSymSubc(s, e, sb_subc_assoc);
}
sDevInst *device() const { return (sb_dev); }
sSubcInst *subckt() const { return (sb_subc); }
sSymCll *elec_insts() const { return (sb_elist); }
void set_elec_insts(sSymCll *s) { sb_elist = s; }
sSymGrp *grp_assoc() const { return (sb_grp_assoc); }
void set_grp_assoc(sSymGrp *s) { sb_grp_assoc = s; }
sSymDev *dev_assoc() const { return (sb_dev_assoc); }
void set_dev_assoc(sSymDev *s) { sb_dev_assoc = s; }
sSymSubc *subc_assoc() const { return (sb_subc_assoc); }
void set_subc_assoc(sSymSubc *s) { sb_subc_assoc = s; }
sSymBrk *next() const { return (sb_next); }
void set_next(sSymBrk *n) { sb_next = n; }
private:
sDevInst *sb_dev; // device associated by symmetry breaking
sSubcInst *sb_subc; // subckt associated by symmetry breaking
sSymCll *sb_elist; // list of associations not made
sSymGrp *sb_grp_assoc; // groups associated since symmetry_break
sSymDev *sb_dev_assoc; // devs associated since symmetry break
sSymSubc *sb_subc_assoc; // subs associated since symmetry break
sSymBrk *sb_next;
};
sSymBrk::sSymBrk(const sSymBrk &s)
{
sb_dev = s.sb_dev;
sb_subc = s.sb_subc;
sb_elist = 0;
sSymCll *ce = 0;
for (sSymCll *p = s.sb_elist; p; p = p->next()) {
if (!sb_elist)
sb_elist = ce = new sSymCll(p->inst_elem());
else {
ce->set_next(new sSymCll(p->inst_elem()));
ce = ce->next();
}
}
sb_grp_assoc = 0;
sSymGrp *ge = 0;
for (sSymGrp *p = s.sb_grp_assoc; p; p = p->next()) {
if (!sb_grp_assoc)
sb_grp_assoc = ge = new sSymGrp(p->group(), p->node());
else {
ge->set_next(new sSymGrp(p->group(), p->node()));
ge = ge->next();
}
}
sb_dev_assoc = 0;
sSymDev *de = 0;
for (sSymDev *p = s.sb_dev_assoc; p; p = p->next()) {
if (!sb_dev_assoc)
sb_dev_assoc = de = new sSymDev(p->phys_dev(), p->elec_dev());
else {
de->set_next(new sSymDev(p->phys_dev(), p->elec_dev()));
de = de->next();
}
}
sb_subc_assoc = 0;
sSymSubc *se = 0;
for (sSymSubc *p = s.sb_subc_assoc; p; p = p->next()) {
if (!sb_subc_assoc)
sb_subc_assoc = se =
new sSymSubc(p->phys_subc(), p->elec_subc());
else {
se->set_next(new sSymSubc(p->phys_subc(), p->elec_subc()));
se = se->next();
}
}
sb_next = 0;
}
}
using namespace ext_duality;
#endif