Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / cns / link.c
1 /*
2 * This file is part of the Alliance CAD System
3 * Copyright (C) Laboratoire LIP6 - D\8epartement ASIM
4 * Universite Pierre et Marie Curie
5 *
6 * Home page : http://www-asim.lip6.fr/alliance/
7 * E-mail support : mailto:alliance-support@asim.lip6.fr
8 *
9 * This library is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU Library General Public License as published
11 * by the Free Software Foundation; either version 2 of the License, or (at
12 * your option) any later version.
13 *
14 * Alliance VLSI CAD System is distributed in the hope that it will be
15 * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
17 * Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with the GNU C Library; see the file COPYING. If not, write to the Free
21 * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 */
23
24 /* 10/26/95 Cone Netlist Structure functions: link.c */
25
26 #include"cnsall.h"
27
28 static void *addlinkpage();
29 static link_list *getfreelink();
30
31 /* define number of links per page */
32 #define LINKSPERPAGE 300
33
34 static chain_list *LINKPAGES; /* chain list of link pages */
35 static int PAGELINKINDEX = 0; /* link index in current page */
36 static link_list *FREELINKLIST; /* list of free links in current page */
37 static link_list *FREEDLINKLIST; /* list of freed links in current page */
38
39 /*============================================================================*
40 | function initlinkmem(); |
41 | initialize link memory structure |
42 *============================================================================*/
43 void *
44 initlinkmem()
45 {
46 link_list *ptlink;
47
48 if (CNS_TRACE_MODE >= CNS_TRACE)
49 (void) printf("TRA_cns initlinkmem\n");
50
51 ptlink = (link_list *) mbkalloc(LINKSPERPAGE * (sizeof(link_list)));
52
53 LINKPAGES = addchain((chain_list *) NULL, (void *) ptlink);
54 FREEDLINKLIST = NULL;
55 PAGELINKINDEX = 1;
56 FREELINKLIST = ptlink;
57
58 return NULL;
59 }
60
61 /*============================================================================*
62 | function addlinkpage(); |
63 | add a new link page |
64 *============================================================================*/
65 static void *
66 addlinkpage()
67 {
68 link_list *ptlink;
69
70 if (CNS_TRACE_MODE >= CNS_TRACE)
71 (void) printf("TRA_cns addlinkpage\n");
72
73 ptlink = (link_list *) mbkalloc(LINKSPERPAGE * (sizeof(link_list)));
74
75 LINKPAGES = addchain(LINKPAGES, (void *) ptlink);
76 PAGELINKINDEX = 1;
77 FREELINKLIST = ptlink;
78
79 return NULL;
80 }
81
82 /*============================================================================*
83 | function getfreelink(); |
84 | get a new link |
85 *============================================================================*/
86 static link_list *
87 getfreelink()
88 {
89 link_list *ptlink;
90
91 if (CNS_TRACE_MODE >= CNS_TRACE)
92 (void) printf("TRA_cns getfreelink in\n");
93
94 if (FREEDLINKLIST != NULL) {
95 ptlink = FREEDLINKLIST;
96 FREEDLINKLIST = FREEDLINKLIST->NEXT;
97 ptlink->NEXT = NULL;
98 if (CNS_TRACE_MODE >= CNS_TRACE)
99 (void) printf("TRA_cns getfreelink out\n");
100 return (ptlink);
101 }
102 else if (PAGELINKINDEX < LINKSPERPAGE) {
103 PAGELINKINDEX++;
104 FREELINKLIST++;
105 FREELINKLIST->NEXT = NULL;
106 if (CNS_TRACE_MODE >= CNS_TRACE)
107 (void) printf("TRA_cns getfreelink out\n");
108 return (FREELINKLIST);
109 }
110 else {
111 addlinkpage();
112 FREELINKLIST->NEXT = NULL;
113 if (CNS_TRACE_MODE >= CNS_TRACE)
114 (void) printf("TRA_cns getfreelink out\n");
115 return (FREELINKLIST);
116 }
117 }
118
119 /*============================================================================*
120 | function freelink(); |
121 | free a link |
122 *============================================================================*/
123 void *
124 freelink(ptlink)
125 link_list *ptlink;
126
127 {
128
129 if (CNS_TRACE_MODE >= CNS_TRACE)
130 (void) printf("TRA_cns freelink\n");
131
132 if (ptlink == NULL) {
133 (void) fflush(stdout);
134 (void) fprintf(stderr, "*** cns error ***");
135 (void) fprintf(stderr, " freelink() impossible: NULL pointer !\n");
136 EXIT(-1);
137 }
138
139 ptlink->NEXT = FREEDLINKLIST;
140 FREEDLINKLIST = ptlink;
141
142 return NULL;
143 }
144
145 /*============================================================================*
146 | function freelklist(); |
147 | free a link list |
148 *============================================================================*/
149 void *
150 freelklist(ptlklist)
151 link_list *ptlklist;
152
153 {
154 link_list *ptlink;
155
156 if (CNS_TRACE_MODE >= CNS_TRACE)
157 (void) printf("TRA_cns freelklist\n");
158
159 if (ptlklist == NULL) {
160 (void) fflush(stdout);
161 (void) fprintf(stderr, "*** cns error ***");
162 (void) fprintf(stderr, " freelklist() impossible: NULL pointer !\n");
163 EXIT(-1);
164 }
165
166 for (ptlink = ptlklist; ptlink->NEXT != NULL; ptlink = ptlink->NEXT);
167 ptlink->NEXT = FREEDLINKLIST;
168 FREEDLINKLIST = ptlklist;
169
170 return NULL;
171 }
172
173 /*============================================================================*
174 | function addlink(); |
175 | add an element to a link list |
176 *============================================================================*/
177 link_list *
178 addlink(ptlinkhead, type, data, ptsig)
179 link_list *ptlinkhead;
180 long type;
181 void *data;
182 losig_list *ptsig;
183
184 {
185 link_list *ptlink;
186
187 if (CNS_TRACE_MODE >= CNS_TRACE)
188 (void) printf("TRA_cns addlink in\n");
189
190 ptlink = getfreelink();
191 ptlink->NEXT = ptlinkhead;
192 ptlink->TYPE = type;
193 ptlink->ULINK.PTR = data;
194 ptlink->SIG = ptsig;
195 ptlink->USER = NULL;
196
197 if (CNS_TRACE_MODE >= CNS_TRACE)
198 (void) printf("TRA_cns addlink out\n");
199 return (ptlink);
200 }
201
202 /*============================================================================*
203 | function dellink(); |
204 | delete an element from a link list and free that element from memory |
205 *============================================================================*/
206 link_list *
207 dellink(ptlinkhead, ptlink2del)
208 link_list *ptlinkhead;
209 link_list *ptlink2del;
210
211 {
212 link_list *ptlink;
213 link_list *ptlink2sav;
214
215 if (CNS_TRACE_MODE >= CNS_TRACE)
216 (void) printf("TRA_cns dellink in\n");
217
218 if ((ptlinkhead == NULL) || (ptlink2del == NULL)) {
219 (void) fflush(stdout);
220 (void) fprintf(stderr, "*** cns error ***");
221 (void) fprintf(stderr, " dellink() impossible: NULL pointer !\n");
222 if (CNS_TRACE_MODE >= CNS_TRACE)
223 (void) printf("TRA_cns dellink out\n");
224 EXIT(-1);
225 }
226
227 if (ptlink2del == ptlinkhead) {
228 ptlink = ptlinkhead->NEXT;
229 ptlinkhead->NEXT = NULL;
230 freelink(ptlinkhead);
231 if (CNS_TRACE_MODE >= CNS_TRACE)
232 (void) printf("TRA_cns dellink out\n");
233 return (ptlink);
234 }
235 else {
236 for (ptlink = ptlinkhead; ptlink; ptlink = ptlink->NEXT) {
237 if (ptlink == ptlink2del) {
238 break;
239 }
240 ptlink2sav = ptlink;
241 }
242 if (ptlink != NULL) {
243 ptlink2sav->NEXT = ptlink->NEXT;
244 ptlink2del->NEXT = NULL;
245 freelink(ptlink2del);
246 }
247 if (CNS_TRACE_MODE >= CNS_TRACE)
248 (void) printf("TRA_cns dellink out\n");
249 return (ptlinkhead);
250 }
251 }
252
253 /*============================================================================*
254 | function appendlink(); |
255 | chain two link lists. WARNING: no consistency check |
256 *============================================================================*/
257 link_list *
258 appendlink(ptlink1, ptlink2)
259 link_list *ptlink1;
260 link_list *ptlink2;
261
262 {
263 link_list *ptlink;
264
265 if (CNS_TRACE_MODE >= CNS_TRACE)
266 (void) printf("TRA_cns appendlink\n");
267
268 if (ptlink1 == NULL) {
269 return (ptlink2);
270 }
271 else {
272 for (ptlink = ptlink1; ptlink->NEXT != NULL; ptlink = ptlink->NEXT);
273 ptlink->NEXT = ptlink2;
274 return (ptlink1);
275 }
276 }
277
278 /*============================================================================*
279 | function viewlink(); |
280 | display the content of a given link structure |
281 *============================================================================*/
282 void
283 viewlink(ptlink, depth)
284 link_list *ptlink;
285 int depth;
286
287 {
288 char *margin = (char *) mbkalloc(80);
289 int k = 1;
290 ptype_list *ptptype;
291
292 if (CNS_TRACE_MODE >= CNS_TRACE)
293 (void) printf("TRA_cns viewlink in\n");
294
295 if (ptlink == NULL) {
296 (void) fflush(stdout);
297 (void) fprintf(stderr, "*** cns error ***");
298 (void) fprintf(stderr, " viewlink() impossible: NULL pointer !\n");
299 if (CNS_TRACE_MODE >= CNS_TRACE)
300 (void) printf("TRA_cns viewlink out\n");
301 EXIT(-1);
302 }
303
304 if (depth < 0) {
305 depth = CNS_LK_VIEW;
306 }
307
308 margin = strcpy(margin, " ");
309 while (k <= CNS_VIEW_LEVEL) {
310 margin = strcat(margin, " ");
311 k++;
312 }
313
314 CNS_VIEW_LEVEL++;
315 printf("%slink->NEXT = 0x%lx\n", margin, (unsigned long)ptlink->NEXT);
316 printf("%slink->TYPE = 0x%lx\n", margin, (unsigned long)ptlink->TYPE);
317 printf("%slink->ULINK.PTR = 0x%lx\n", margin, (unsigned long)ptlink->ULINK.PTR);
318 if ((ptlink->TYPE & CNS_EXT) != CNS_EXT) {
319 if ((depth >= 1) && (ptlink->ULINK.LOTRS != NULL)) {
320 viewcnslotrs(ptlink->ULINK.LOTRS, depth - 1);
321 }
322 }
323 else {
324 if ((depth >= 1) && (ptlink->ULINK.LOCON != NULL)) {
325 viewcnslocon(ptlink->ULINK.LOCON, depth - 1);
326 }
327 }
328 printf("%slink->USER = 0x%lx\n", margin, (unsigned long)ptlink->USER);
329 if ((depth >= 1) && (ptlink->USER != NULL)) {
330 for (ptptype = ptlink->USER; ptptype != NULL; ptptype = ptptype->NEXT) {
331 viewcnsptype(ptptype);
332 }
333 }
334 else {
335 printf("\n");
336 }
337 CNS_VIEW_LEVEL--;
338 mbkfree((void *) margin);
339
340 if (CNS_TRACE_MODE >= CNS_TRACE)
341 (void) printf("TRA_cns viewlink out\n");
342 }
343
344 /*============================================================================*
345 | function lotrsnum(); |
346 | returns the number of series transistors in the input link list |
347 *============================================================================*/
348 short
349 lotrsnum(ptlklist)
350 link_list *ptlklist;
351
352 {
353 link_list *ptlink;
354 short count = 0;
355
356 if (CNS_TRACE_MODE >= CNS_TRACE)
357 (void) printf("TRA_cns lotrsnum\n");
358
359 for (ptlink = ptlklist; ptlink != NULL; ptlink = ptlink->NEXT) {
360 if ((ptlink->TYPE & CNS_EXT) != CNS_EXT)
361 count++;
362 }
363
364 return (count);
365 }