2 * This file is part of the Alliance CAD System
3 * Copyright (C) Laboratoire LIP6 - D\8epartement ASIM
4 * Universite Pierre et Marie Curie
6 * Home page : http://www-asim.lip6.fr/alliance/
7 * E-mail support : mailto:alliance-support@asim.lip6.fr
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.
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.
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.
24 /* 10/26/95 Cone Netlist Structure functions: link.c */
28 static void *addlinkpage();
29 static link_list
*getfreelink();
31 /* define number of links per page */
32 #define LINKSPERPAGE 300
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 */
39 /*============================================================================*
40 | function initlinkmem(); |
41 | initialize link memory structure |
42 *============================================================================*/
48 if (CNS_TRACE_MODE
>= CNS_TRACE
)
49 (void) printf("TRA_cns initlinkmem\n");
51 ptlink
= (link_list
*) mbkalloc(LINKSPERPAGE
* (sizeof(link_list
)));
53 LINKPAGES
= addchain((chain_list
*) NULL
, (void *) ptlink
);
56 FREELINKLIST
= ptlink
;
61 /*============================================================================*
62 | function addlinkpage(); |
63 | add a new link page |
64 *============================================================================*/
70 if (CNS_TRACE_MODE
>= CNS_TRACE
)
71 (void) printf("TRA_cns addlinkpage\n");
73 ptlink
= (link_list
*) mbkalloc(LINKSPERPAGE
* (sizeof(link_list
)));
75 LINKPAGES
= addchain(LINKPAGES
, (void *) ptlink
);
77 FREELINKLIST
= ptlink
;
82 /*============================================================================*
83 | function getfreelink(); |
85 *============================================================================*/
91 if (CNS_TRACE_MODE
>= CNS_TRACE
)
92 (void) printf("TRA_cns getfreelink in\n");
94 if (FREEDLINKLIST
!= NULL
) {
95 ptlink
= FREEDLINKLIST
;
96 FREEDLINKLIST
= FREEDLINKLIST
->NEXT
;
98 if (CNS_TRACE_MODE
>= CNS_TRACE
)
99 (void) printf("TRA_cns getfreelink out\n");
102 else if (PAGELINKINDEX
< LINKSPERPAGE
) {
105 FREELINKLIST
->NEXT
= NULL
;
106 if (CNS_TRACE_MODE
>= CNS_TRACE
)
107 (void) printf("TRA_cns getfreelink out\n");
108 return (FREELINKLIST
);
112 FREELINKLIST
->NEXT
= NULL
;
113 if (CNS_TRACE_MODE
>= CNS_TRACE
)
114 (void) printf("TRA_cns getfreelink out\n");
115 return (FREELINKLIST
);
119 /*============================================================================*
120 | function freelink(); |
122 *============================================================================*/
129 if (CNS_TRACE_MODE
>= CNS_TRACE
)
130 (void) printf("TRA_cns freelink\n");
132 if (ptlink
== NULL
) {
133 (void) fflush(stdout
);
134 (void) fprintf(stderr
, "*** cns error ***");
135 (void) fprintf(stderr
, " freelink() impossible: NULL pointer !\n");
139 ptlink
->NEXT
= FREEDLINKLIST
;
140 FREEDLINKLIST
= ptlink
;
145 /*============================================================================*
146 | function freelklist(); |
148 *============================================================================*/
156 if (CNS_TRACE_MODE
>= CNS_TRACE
)
157 (void) printf("TRA_cns freelklist\n");
159 if (ptlklist
== NULL
) {
160 (void) fflush(stdout
);
161 (void) fprintf(stderr
, "*** cns error ***");
162 (void) fprintf(stderr
, " freelklist() impossible: NULL pointer !\n");
166 for (ptlink
= ptlklist
; ptlink
->NEXT
!= NULL
; ptlink
= ptlink
->NEXT
);
167 ptlink
->NEXT
= FREEDLINKLIST
;
168 FREEDLINKLIST
= ptlklist
;
173 /*============================================================================*
174 | function addlink(); |
175 | add an element to a link list |
176 *============================================================================*/
178 addlink(ptlinkhead
, type
, data
, ptsig
)
179 link_list
*ptlinkhead
;
187 if (CNS_TRACE_MODE
>= CNS_TRACE
)
188 (void) printf("TRA_cns addlink in\n");
190 ptlink
= getfreelink();
191 ptlink
->NEXT
= ptlinkhead
;
193 ptlink
->ULINK
.PTR
= data
;
197 if (CNS_TRACE_MODE
>= CNS_TRACE
)
198 (void) printf("TRA_cns addlink out\n");
202 /*============================================================================*
203 | function dellink(); |
204 | delete an element from a link list and free that element from memory |
205 *============================================================================*/
207 dellink(ptlinkhead
, ptlink2del
)
208 link_list
*ptlinkhead
;
209 link_list
*ptlink2del
;
213 link_list
*ptlink2sav
;
215 if (CNS_TRACE_MODE
>= CNS_TRACE
)
216 (void) printf("TRA_cns dellink in\n");
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");
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");
236 for (ptlink
= ptlinkhead
; ptlink
; ptlink
= ptlink
->NEXT
) {
237 if (ptlink
== ptlink2del
) {
242 if (ptlink
!= NULL
) {
243 ptlink2sav
->NEXT
= ptlink
->NEXT
;
244 ptlink2del
->NEXT
= NULL
;
245 freelink(ptlink2del
);
247 if (CNS_TRACE_MODE
>= CNS_TRACE
)
248 (void) printf("TRA_cns dellink out\n");
253 /*============================================================================*
254 | function appendlink(); |
255 | chain two link lists. WARNING: no consistency check |
256 *============================================================================*/
258 appendlink(ptlink1
, ptlink2
)
265 if (CNS_TRACE_MODE
>= CNS_TRACE
)
266 (void) printf("TRA_cns appendlink\n");
268 if (ptlink1
== NULL
) {
272 for (ptlink
= ptlink1
; ptlink
->NEXT
!= NULL
; ptlink
= ptlink
->NEXT
);
273 ptlink
->NEXT
= ptlink2
;
278 /*============================================================================*
279 | function viewlink(); |
280 | display the content of a given link structure |
281 *============================================================================*/
283 viewlink(ptlink
, depth
)
288 char *margin
= (char *) mbkalloc(80);
292 if (CNS_TRACE_MODE
>= CNS_TRACE
)
293 (void) printf("TRA_cns viewlink in\n");
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");
308 margin
= strcpy(margin
, " ");
309 while (k
<= CNS_VIEW_LEVEL
) {
310 margin
= strcat(margin
, " ");
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);
324 if ((depth
>= 1) && (ptlink
->ULINK
.LOCON
!= NULL
)) {
325 viewcnslocon(ptlink
->ULINK
.LOCON
, depth
- 1);
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
);
338 mbkfree((void *) margin
);
340 if (CNS_TRACE_MODE
>= CNS_TRACE
)
341 (void) printf("TRA_cns viewlink out\n");
344 /*============================================================================*
345 | function lotrsnum(); |
346 | returns the number of series transistors in the input link list |
347 *============================================================================*/
356 if (CNS_TRACE_MODE
>= CNS_TRACE
)
357 (void) printf("TRA_cns lotrsnum\n");
359 for (ptlink
= ptlklist
; ptlink
!= NULL
; ptlink
= ptlink
->NEXT
) {
360 if ((ptlink
->TYPE
& CNS_EXT
) != CNS_EXT
)