1 /*
2 * This file is part of the Alliance CAD System
3 * Copyright (C) Laboratoire LIP6 - D�partement ASIM
4 * Universite Pierre et Marie Curie
5 *
6 * Home page : http://www-asim.lip6.fr/alliance/
7 * E-mail : mailto:alliance-users@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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 */
23
24 /*
25 * Purpose : acces functions to logical structures
26 * Date : 30/04/91
27 * Author : Frederic Petrot <Frederic.Petrot@lip6.fr>
28 * Modified by Czo <Olivier.Sirol@lip6.fr> 1997,98
29 * Modified by <Gregoire.Avot@lip6.fr> 1997,98
30 * Modified by pnt <Pierre.Nguyen-Tuong@lip6.fr> 2002
31 */
32
33 #ident "$Id: mbk_lo.c,v 1.9 2012/05/14 14:20:23 alliance Exp $"
34
35 #include <stdio.h>
36 #include <unistd.h>
37 #include <string.h>
38
39 #include "mut.h"
40 #include "mlo.h"
41 #include "rcn.h"
42 #include "mbk_lo.h"
43
44 long NB_TAT_LOSIG = 0;
45 /*******************************************************************************
46 * global variable for netlist view *
47 *******************************************************************************/
48 lofig_list *HEAD_LOFIG; /* physical figure list head */
49
50 /*******************************************************************************
51 * function addlofig() *
52 *******************************************************************************/
addlofig(const char * fname)53 lofig_list *addlofig(const char *fname)
54 {
55 lofig_list *ptfig;
56 char *name;
57
58 name = namealloc(fname);
59 /* scan figure list */
60 ptfig = HEAD_LOFIG;
61 while (ptfig != NULL && ptfig->NAME != name)
62 ptfig = ptfig->NEXT;
63
64 if (ptfig != NULL) { /* figure exists */
65 (void)fflush(stdout);
66 (void)fprintf(stderr, "*** mbk error ***\n");
67 (void)fprintf(stderr, "addlofig impossible : ");
68 (void)fprintf(stderr, "figure %s already exists\n", name);
69 EXIT(1);
70 }
71 ptfig = (lofig_list *)mbkalloc(sizeof(lofig_list));
72 ptfig->MODE = 'A';
73 ptfig->NAME = name;
74 ptfig->MODELCHAIN = NULL;
75 ptfig->LOINS = NULL;
76 ptfig->LOTRS = NULL;
77 ptfig->LOCAP = NULL;
78 ptfig->LORES = NULL;
79 ptfig->LOSELF = NULL;
80 ptfig->LOCON = NULL;
81 ptfig->LOSIG = NULL;
82 ptfig->BKSIG = NULL;
83 ptfig->USER = NULL;
84 ptfig->NEXT = HEAD_LOFIG;
85 HEAD_LOFIG = ptfig;
86
87 if (TRACE_MODE == 'Y')
88 (void)fprintf(stdout, "--- mbk --- addlofig : %s\n", name);
89
90 return ptfig;
91 }
92
93 /*******************************************************************************
94 * function addlomodel() *
95 * used by the parsers to construct a temporary model *
96 *******************************************************************************/
addlomodel(lofig_list * model,const char * fname)97 lofig_list *addlomodel(lofig_list *model, const char *fname)
98 {
99 lofig_list *fig;
100 char *name = namealloc(fname);
101
102 /* check to see if the model has already been loaded */
103 for (fig = model; fig && fig->NAME != name; fig = fig->NEXT);
104
105 if (fig) { /* figure exists */
106 (void)fflush(stdout);
107 (void)fprintf(stderr, "*** mbk error ***\n");
108 (void)fprintf(stderr, "addlomodel impossible : ");
109 (void)fprintf(stderr, "model %s already exists \n", name);
110 EXIT(1);
111 }
112 fig = (lofig_list *)mbkalloc(sizeof(lofig_list));
113 fig->MODE = 'A';
114 fig->NAME = name;
115 fig->MODELCHAIN = NULL;
116 fig->LOINS = NULL;
117 fig->LOTRS = NULL;
118 fig->LOCAP = NULL;
119 fig->LORES = NULL;
120 fig->LOSELF = NULL;
121 fig->LOCON = NULL;
122 fig->LOSIG = NULL;
123 fig->BKSIG = NULL;
124 fig->USER = NULL;
125 fig->NEXT = model;
126 model = fig;
127
128 if (TRACE_MODE == 'Y')
129 (void)fprintf(stdout, "--- mbk --- addlomodel : %s\n", name);
130
131 return model;
132 }
133
134 /*******************************************************************************
135 * function addlotrs() *
136 *******************************************************************************/
addlotrs(lofig_list * ptfig,char type,long x,long y,long width,long length,long ps,long pd,long xs,long xd,losig_list * ptgrid,losig_list * ptsource,losig_list * ptdrain,losig_list * ptbulk,const char * name)137 lotrs_list *addlotrs(lofig_list *ptfig, char type, long x, long y, long width, long length, long ps, long pd, long xs, long xd, losig_list *ptgrid, losig_list *ptsource, losig_list *ptdrain, losig_list *ptbulk, const char *name)
138 {
139 static char *grid, *drain, *source, *bulk;
140 lotrs_list *pttrs;
141 locon_list *ptcon;
142
143 if (!grid) {
144 grid = namealloc("grid");
145 drain = namealloc("drain");
146 source = namealloc("source");
147 bulk = namealloc("bulk");
148 }
149
150 #if 0
151 if (type != TRANSN && type != TRANSP) {
152 (void)fflush(stdout);
153 (void)fprintf(stderr, "*** mbk error ***\n");
154 (void)fprintf(stderr, " illegal transistor type : %ld\n", (long)type);
155 EXIT(1);
156 }
157 #endif
158
159 pttrs = (lotrs_list *)mbkalloc(sizeof(lotrs_list));
160 pttrs->X = x;
161 pttrs->Y = y;
162 pttrs->WIDTH = width;
163 pttrs->LENGTH = length;
164 pttrs->PS = ps;
165 pttrs->PD = pd;
166 pttrs->XS = xs;
167 pttrs->XD = xd;
168 pttrs->TYPE = type;
169 pttrs->NEXT = ptfig->LOTRS;
170 ptfig->LOTRS = pttrs;
171 pttrs->USER = NULL;
172
173 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
174 ptcon->NAME = grid;
175 ptcon->SIG = ptgrid;
176 ptcon->ROOT = (void *)pttrs;
177 ptcon->TYPE = TRANSCV;
178 ptcon->DIRECTION = INTERNAL;
179 ptcon->USER = NULL;
180 ptcon->PNODE = NULL;
181 pttrs->GRID = ptcon;
182
183 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
184 ptcon->NAME = drain;
185 ptcon->SIG = ptdrain;
186 ptcon->ROOT = (void *)pttrs;
187 ptcon->TYPE = TRANSCV;
188 ptcon->DIRECTION = INTERNAL;
189 ptcon->USER = NULL;
190 ptcon->PNODE = NULL;
191 pttrs->DRAIN = ptcon;
192
193 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
194 ptcon->NAME = source;
195 ptcon->SIG = ptsource;
196 ptcon->ROOT = (void *)pttrs;
197 ptcon->TYPE = TRANSCV;
198 ptcon->DIRECTION = INTERNAL;
199 ptcon->USER = NULL;
200 ptcon->PNODE = NULL;
201 pttrs->SOURCE = ptcon;
202
203 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
204 ptcon->NAME = bulk;
205 ptcon->SIG = ptbulk;
206 ptcon->ROOT = (void *)pttrs;
207 ptcon->TYPE = TRANSCV;
208 ptcon->DIRECTION = INTERNAL;
209 ptcon->USER = NULL;
210 ptcon->PNODE = NULL;
211 pttrs->BULK = ptcon;
212
213 /* No check is done for transistor name unicity */
214 pttrs->TRNAME = namealloc(name);
215
216 if ((TRACE_MODE == 'Y'))
217 (void)fprintf(stdout,
218 "--- mbk --- addlotrs : %s X=%ld, Y=%ld, W=%ld, L=%ld, PS = %ld, PD = %ld, XS = %ld, XD = %ld\n",
219 type == TRANSN ? "TRANSN" : "TRANSP", x, y, width, length,
220 ps, pd, xs, xd);
221
222 return pttrs;
223 }
224
225 /*******************************************************************************
226 * function addloins() *
227 *******************************************************************************/
addloins(lofig_list * ptfig,const char * iname,lofig_list * ptnewfig,chain_list * sigchain)228 loins_list *addloins(lofig_list *ptfig, const char *iname, lofig_list *ptnewfig, chain_list *sigchain)
229 {
230 locon_list *ptcon = NULL;
231 locon_list *ptnewcon = NULL;
232 loins_list *ptins = NULL;
233 char *figname;
234 char *insname;
235 chain_list *ptchain;
236
237 insname = namealloc(iname);
238 figname = ptnewfig->NAME;
239
240 /* check insname unicity */
241 if (strcmp(insname, "*") && FAST_MODE != 'Y') {
242 for (ptins = ptfig->LOINS; ptins; ptins = ptins->NEXT) {
243 if (ptins->INSNAME == insname) {
244 (void)fflush(stdout);
245 (void)fprintf(stderr, "*** mbk error ***\n");
246 (void)fprintf(stderr, "addloins impossible : ");
247 (void)fprintf(stderr, "instance %s already exist in figure %s\n",
248 insname, ptfig->NAME);
249 EXIT(1);
250 }
251 }
252 }
253
254 if (ptfig->NAME == figname) {
255 (void)fflush(stdout);
256 (void)fprintf(stderr, "*** mbk error ***\n");
257 (void)fprintf(stderr, "addloins impossible :\n");
258 (void)fprintf(stderr, "instance model is the figure %s itself\n",
259 figname);
260 EXIT(1);
261 }
262
263 ptins = (loins_list *)mbkalloc(sizeof(loins_list));
264
265 ptins->INSNAME = insname;
266 ptins->FIGNAME = figname;
267 ptins->LOCON = NULL;
268 ptins->USER = NULL;
269 ptins->NEXT = ptfig->LOINS;
270 ptfig->LOINS = ptins;
271
272 /* update model list */
273 for (ptchain = ptfig->MODELCHAIN; ptchain; ptchain = ptchain->NEXT)
274 if (ptchain->DATA == (void *)figname)
275 break;
276
277 if (!ptchain)
278 ptfig->MODELCHAIN = addchain(ptfig->MODELCHAIN, (void *)figname);
279
280 for (ptcon = ptnewfig->LOCON; ptcon; ptcon = ptcon->NEXT) {
281 if (sigchain == NULL) {
282 (void)fflush(stdout);
283 (void)fprintf(stderr, "*** mbk error ***\n");
284 (void)fprintf(stderr, "addloins impossible : connector number ");
285 (void)fprintf(stderr, "discrepancy between figure %s",
286 ptnewfig->NAME);
287 (void)fprintf(stderr, " and instance %s in figure %s\n",
288 insname, ptfig->NAME);
289 EXIT(1);
290 }
291 ptnewcon = (locon_list *)mbkalloc(sizeof(locon_list));
292 ptnewcon->NAME = ptcon->NAME;
293 ptnewcon->DIRECTION = ptcon->DIRECTION;
294 ptnewcon->TYPE = 'I';
295 ptnewcon->SIG = (losig_list *)sigchain->DATA;
296 ptnewcon->ROOT = (void *)ptins;
297 ptnewcon->USER = NULL;
298 ptnewcon->PNODE= NULL;
299 ptnewcon->NEXT = ptins->LOCON;
300 ptins->LOCON = ptnewcon;
301 sigchain = sigchain->NEXT;
302 }
303 if (sigchain != NULL) {
304 (void)fflush(stdout);
305 (void)fprintf(stderr, "*** mbk error ***\n");
306 (void)fprintf(stderr, "addloins impossible : ");
307 (void)fprintf(stderr, "connector number discrepancy between figure %s ",
308 ptnewfig->NAME);
309 (void)fprintf(stderr, "and instance %s in figure %s\n",
310 insname, ptfig->NAME);
311 EXIT(1);
312 }
313
314 ptins->LOCON = (locon_list *)reverse((chain_list *)ptins->LOCON);
315
316 if (TRACE_MODE == 'Y')
317 (void)fprintf(stdout, "--- mbk --- addloins : %s of figure %s\n",
318 insname, figname);
319 return ptins;
320 }
321
322 /*******************************************************************************
323 * function addlocon() *
324 *******************************************************************************/
addlocon(lofig_list * ptfig,const char * cname,losig_list * ptsig,char dir)325 locon_list *addlocon(lofig_list *ptfig, const char *cname, losig_list *ptsig, char dir)
326 {
327 locon_list *ptcon;
328 char *name = namealloc(cname);
329
330 /* check name unicity */
331 if (FAST_MODE != 'Y') {
332 for (ptcon = ptfig->LOCON; ptcon; ptcon = ptcon->NEXT) {
333 if (ptcon->NAME == name) {
334 (void)fflush(stdout);
335 (void)fprintf(stderr, "*** mbk error ***\n");
336 (void)fprintf(stderr, "addlocon impossible :\n");
337 (void)fprintf(stderr, "connector %s already exists in figure %s\n",
338 name, ptfig->NAME);
339 EXIT(1);
340 }
341 }
342 if (dir != 'I' && dir != 'O' && dir != 'X' && dir != 'B'
343 && dir != 'Z' && dir != 'T') {
344 (void)fflush(stdout);
345 (void)fprintf(stderr, "*** mbk error ***\n");
346 (void)fprintf(stderr, "addlocon impossible :\n");
347 (void)fprintf(stderr, "bad direction %c in figure %s\n",
348 dir, ptfig->NAME);
349 EXIT(1);
350 }
351 }
352
353 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
354 ptcon->NAME = name;
355 ptcon->TYPE = 'E';
356 ptcon->SIG = ptsig;
357 ptcon->ROOT = (void *)ptfig;
358 ptcon->DIRECTION = dir;
359 ptcon->USER = NULL;
360 ptcon->NEXT = ptfig->LOCON;
361 ptcon->PNODE = NULL;
362 ptfig->LOCON = ptcon;
363
364 if (TRACE_MODE == 'Y')
365 {
366 if (ptsig!=NULL)
367 (void)fprintf(stdout, "--- mbk --- addlocon : %s linked to %ld\n",
368 name, ptsig->INDEX);
369 else
370 (void)fprintf(stdout, "--- mbk --- addlocon : %s no signal\n", name);
371 }
372
373 return ptcon;
374 }
375
376 /*******************************************************************************
377 * function addlosig() *
378 *******************************************************************************/
379
addlosig(lofig_list * ptfig,long index,chain_list * namechain,char type)380 losig_list *addlosig(lofig_list *ptfig, long index, chain_list *namechain, char type)
381 {
382 losig_list *ptsig;
383 losig_list *pthead;
384 ptype_list *pt;
385 chain_list *ptchain;
386 long high;
387 long low;
388 long i;
389 long sigsize;
390
391 sigsize = getsigsize( ptfig );
392
393 low = (index % sigsize);
394 high = (index / sigsize);
395 for (pt = ptfig->BKSIG; pt; pt = pt->NEXT)
396 if (pt->TYPE == high)
397 break;
398 if (pt == NULL) {
399 pthead = (losig_list *)mbkalloc(sigsize * sizeof(losig_list));
400 ptsig = pthead;
401 for (i = 0; i < sigsize; i++) {
402 ptsig->INDEX = 0;
403 ptsig++;
404 }
405 ptfig->BKSIG = (ptype_list *)addptype(ptfig->BKSIG,
406 (long)high, (void *)pthead);
407 pt = ptfig->BKSIG;
408 }
409 ptsig = (losig_list *)(pt->DATA) + low;
410
411 /* check index unicity */
412 if (ptsig->INDEX != 0L) {
413 (void)fflush(stdout);
414 (void)fprintf(stderr, "*** mbk error ***\n");
415 (void)fprintf(stderr, "addlosig impossible :\n");
416 (void)fprintf(stderr, "signal %ld already exist in figure %s\n",
417 index, ptfig->NAME);
418 EXIT(1);
419 }
420 for (ptchain = namechain; ptchain; ptchain = ptchain->NEXT)
421 ptchain->DATA = (void *)namealloc((char *)ptchain->DATA);
422
423 ptsig->NAMECHAIN = namechain;
424 ptsig->INDEX = index;
425 ptsig->USER = NULL;
426 ptsig->PRCN = NULL;
427 ptsig->TYPE = type;
428 ptsig->NEXT = ptfig->LOSIG;
429 ptfig->LOSIG = ptsig;
430
431 if (TRACE_MODE == 'Y') {
432 (void)fprintf(stdout, "--- mbk --- addlosig : %ld ", index);
433 if (ptsig->NAMECHAIN)
434 if (ptsig->NAMECHAIN->DATA)
435 (void)fprintf(stdout, "name : %s",
436 (char *)((chain_list *)(ptsig->NAMECHAIN))->DATA);
437 (void)fprintf(stdout, "\n");
438 }
439
440 return ptsig;
441 }
442
443 /*******************************************************************************
444 * function dellofig() *
445 *******************************************************************************/
dellofig(const char * fname)446 int dellofig(const char *fname)
447 {
448 lofig_list *ptfig;
449 losig_list *ptsig;
450 loins_list *ptins;
451 locon_list *ptcon;
452 lotrs_list *pttrs;
453 locap_list *ptcap;
454 lores_list *ptres;
455 loself_list *ptself;
456 ptype_list *pt;
457 char *name = namealloc(fname);
458
459 void *ptold=NULL, *ptt;
460
461 for (ptfig = HEAD_LOFIG; ptfig; ptfig = ptfig->NEXT) {
462 if (ptfig->NAME == name)
463 break;
464 ptold = (void *)ptfig;
465 }
466
467 if (ptfig == NULL)
468 return 0;
469 else if (ptfig == HEAD_LOFIG)
470 HEAD_LOFIG = ptfig->NEXT;
471 else
472 ((lofig_list *)ptold)->NEXT = ptfig->NEXT;
473
474 freectclist( ptfig, NULL );
475 for (ptsig = ptfig->LOSIG; ptsig; ptsig = ptsig->NEXT)
476 {
477 freechain(ptsig->NAMECHAIN);
478 if(ptsig->PRCN)
479 freelorcnet(ptsig);
480 dellosiguser( ptsig );
481 }
482
483 for (ptins = ptfig->LOINS; ptins; ptins = (loins_list *)ptold) {
484 delloinsuser( ptins );
485 for (ptcon = ptins->LOCON; ptcon; ptcon = (locon_list *)ptt) {
486 ptt = (void *)ptcon->NEXT;
487 delloconuser( ptcon );
488 mbkfree((void *)ptcon);
489 }
490 ptold = (void *)ptins->NEXT;
491 mbkfree((void *)ptins);
492 }
493
494 for (pt = ptfig->BKSIG; pt; pt = pt->NEXT) {
495 mbkfree((void *)pt->DATA);
496 }
497 freeptype(ptfig->BKSIG);
498 for (ptcon = ptfig->LOCON; ptcon; ptcon = (locon_list *)ptold) {
499 ptold = (void *)ptcon->NEXT;
500 delloconuser( ptcon );
501 mbkfree((void *)ptcon);
502 }
503 for (pttrs = ptfig->LOTRS; pttrs; pttrs = (lotrs_list *)ptold) {
504 delloconuser( pttrs->GRID );
505 delloconuser( pttrs->SOURCE );
506 delloconuser( pttrs->DRAIN );
507 delloconuser( pttrs->BULK );
508 mbkfree((void *)pttrs->GRID);
509 mbkfree((void *)pttrs->SOURCE);
510 mbkfree((void *)pttrs->DRAIN);
511 mbkfree((void *)pttrs->BULK);
512 ptold = (void *)pttrs->NEXT;
513 dellotrsuser( pttrs );
514 mbkfree((void *)pttrs);
515 }
516
517 for(ptcap = ptfig -> LOCAP ; ptcap != NULL ; ptcap = (locap_list *)ptold)
518 {
519 delloconuser(ptcap -> TCON) ;
520 delloconuser(ptcap -> BCON) ;
521
522 mbkfree((void *)ptcap -> TCON) ;
523 mbkfree((void *)ptcap -> BCON) ;
524 ptold = (void *)ptcap -> NEXT ;
525
526 dellocapuser(ptcap) ;
527 mbkfree((void *)ptcap) ;
528 }
529
530 for(ptres = ptfig -> LORES ; ptres != NULL ; ptres = (lores_list *)ptold)
531 {
532 delloconuser(ptres -> RCON1) ;
533 delloconuser(ptres -> RCON2) ;
534
535 mbkfree((void *)ptres -> RCON1) ;
536 mbkfree((void *)ptres -> RCON2) ;
537 ptold = (void *)ptres -> NEXT ;
538
539 delloresuser(ptres) ;
540 mbkfree((void *)ptres) ;
541 }
542
543 for(ptself = ptfig -> LOSELF ; ptself != NULL ; ptself = (loself_list *)ptold)
544 {
545 delloconuser(ptself -> SCON1) ;
546 delloconuser(ptself -> SCON2) ;
547
548 mbkfree((void *)ptself -> SCON1) ;
549 mbkfree((void *)ptself -> SCON2) ;
550 ptold = (void *)ptself -> NEXT ;
551
552 delloselfuser(ptself) ;
553 mbkfree((void *)ptself) ;
554 }
555
556 dellofiguser( ptfig );
557 freechain(ptfig->MODELCHAIN);
558 mbkfree((void *)ptfig);
559 if (TRACE_MODE == 'Y')
560 (void)fprintf(stdout, "--- mbk --- dellofig : %s\n", name);
561 return 1;
562 }
563
564 /*******************************************************************************
565 * function freelomodel() *
566 *******************************************************************************/
freelomodel(lofig_list * ptmodel)567 void freelomodel(lofig_list *ptmodel)
568 {
569 lofig_list *ptfig;
570 locon_list *ptcon;
571 locon_list *ptc;
572
573 if (!ptmodel) /* nothing to be freed */
574 return;
575
576 ptfig = ptmodel->NEXT;
577 while (1) {
578 for (ptcon = ptmodel->LOCON; ptcon; ptcon = ptc) {
579 ptc = ptcon->NEXT;
580 mbkfree((void *)ptcon);
581 }
582 mbkfree((void *)ptmodel);
583 ptmodel = ptfig;
584 if (!ptfig)
585 break;
586 ptfig = ptfig->NEXT;
587 }
588
589 if (TRACE_MODE == 'Y')
590 (void)fprintf(stdout, "--- mbk --- freelomodel\n");
591 }
592
593 /*******************************************************************************
594 * function dellosig() *
595 *******************************************************************************/
dellosig(lofig_list * ptfig,long index)596 int dellosig(lofig_list *ptfig, long index)
597 {
598 losig_list *ptsav=NULL;
599 losig_list *ptsig;
600
601 for (ptsig = ptfig->LOSIG; ptsig; ptsig = ptsig->NEXT) {
602 if (ptsig->INDEX == index)
603 break;
604 ptsav = ptsig;
605 }
606
607 if (ptsig == NULL)
608 return 0;
609 else if (ptsig == ptfig->LOSIG)
610 ptfig->LOSIG = ptsig->NEXT;
611 else
612 ptsav->NEXT = ptsig->NEXT;
613
614 if( ptsig->PRCN )
615 freelorcnet( ptsig );
616 ptsig->INDEX = 0L;
617
618 freechain(ptsig->NAMECHAIN);
619 ptsig->NAMECHAIN=NULL;
620
621 dellosiguser( ptsig );
622
623 if (TRACE_MODE == 'Y')
624 (void)fprintf(stdout, "--- mbk --- dellosig : %ld\n", index);
625
626 return 1;
627 }
628
629 /*******************************************************************************
630 * function dellotrs() *
631 *******************************************************************************/
dellotrs(lofig_list * ptfig,lotrs_list * pttrs)632 int dellotrs(lofig_list *ptfig, lotrs_list *pttrs)
633 {
634 lotrs_list *pt;
635 lotrs_list *ptsav=NULL;
636
637 for (pt = ptfig->LOTRS; pt; pt = pt->NEXT) {
638 if (pt == pttrs)
639 break;
640 ptsav = pt;
641 }
642 if (pt == NULL)
643 return 0;
644 else if (pt == ptfig->LOTRS)
645 ptfig->LOTRS = pt->NEXT;
646 else
647 ptsav->NEXT = pt->NEXT;
648
649 if( pt->GRID->PNODE )
650 delrcnlocon( pt->GRID );
651 delloconuser( pt->GRID );
652 mbkfree((void *)pt->GRID);
653
654 if( pt->SOURCE->PNODE )
655 delrcnlocon( pt->SOURCE );
656 delloconuser( pt->SOURCE );
657 mbkfree((void *)pt->SOURCE);
658
659 if( pt->DRAIN->PNODE )
660 delrcnlocon( pt->DRAIN );
661 delloconuser( pt->DRAIN );
662 mbkfree((void *)pt->DRAIN);
663
664 if( pt->BULK->PNODE )
665 delrcnlocon( pt->BULK );
666 delloconuser( pt->BULK );
667 mbkfree((void *)pt->BULK);
668
669 dellotrsuser( pt );
670 mbkfree((void *)pt);
671 if (TRACE_MODE == 'Y')
672 (void)fprintf(stdout, "--- mbk --- dellotrs : \n");
673 return 1;
674 }
675
676 /*******************************************************************************
677 * function delloins() *
678 *******************************************************************************/
delloins(lofig_list * ptfig,const char * iname)679 int delloins(lofig_list *ptfig, const char *iname)
680 {
681 loins_list *ptins;
682 locon_list *ptcon;
683 chain_list *ptchain;
684 chain_list *pttmpchain=NULL;
685 void *pt=NULL;
686 char *figname;
687 char *insname;
688
689 insname = namealloc(iname);
690 for (ptins = ptfig->LOINS; ptins; ptins = ptins->NEXT) {
691 if (ptins->INSNAME == insname)
692 break;
693 pt = (void *)ptins;
694 }
695 if (ptins == NULL)
696 return 0;
697 if (ptins == ptfig->LOINS) {
698 figname = ptins->FIGNAME;
699 ptfig->LOINS = ptins->NEXT;
700 } else {
701 figname = ptins->FIGNAME;
702 ((loins_list *)pt)->NEXT = ptins->NEXT;
703 }
704 for (ptcon = ptins->LOCON; ptcon; ptcon = (locon_list *)pt) {
705 if( ptcon->PNODE )
706 delrcnlocon( ptcon );
707 pt = (void *)ptcon->NEXT;
708 delloconuser( ptcon );
709 mbkfree((void *)ptcon);
710 }
711
712 delloinsuser( ptins );
713 mbkfree((void *)ptins);
714
715 for (ptins = ptfig->LOINS; ptins; ptins = ptins->NEXT)
716 if (ptins->FIGNAME == figname)
717 break;
718 if (ptins == NULL) { /* if no more instance have this model, destroy */
719 for (ptchain = ptfig->MODELCHAIN; ptchain; ptchain = ptchain->NEXT) {
720 if (ptchain->DATA == (void *)figname)
721 break;
722 pttmpchain = ptchain;
723 }
724 if (ptchain == ptfig->MODELCHAIN && ptchain != NULL)
725 ptfig->MODELCHAIN = ptchain ->NEXT;
726 else if (ptchain)
727 pttmpchain->NEXT = ptchain->NEXT;
728
729 if( ptchain )
730 {
731 ptchain->NEXT = NULL;
732 freechain( ptchain );
733 }
734 }
735
736 if (TRACE_MODE == 'Y')
737 (void)fprintf(stdout, "--- mbk --- delloins : %s\n", insname);
738 return 1;
739 }
740
741 /*******************************************************************************
742 * function dellocon() *
743 *******************************************************************************/
dellocon(lofig_list * ptfig,const char * cname)744 int dellocon(lofig_list *ptfig, const char *cname)
745 {
746 locon_list *ptcon;
747 locon_list *ptsav=NULL;
748 char *name = namealloc(cname);
749
750 for (ptcon = ptfig->LOCON; ptcon; ptcon = ptcon->NEXT) {
751 if (ptcon->NAME == name)
752 break;
753 ptsav = ptcon;
754 }
755 if (ptcon == NULL)
756 return 0;
757 else if (ptcon == ptfig->LOCON)
758 ptfig->LOCON = ptcon->NEXT;
759 else
760 ptsav->NEXT = ptcon->NEXT;
761
762 if( ptcon->PNODE )
763 delrcnlocon( ptcon );
764
765 delloconuser( ptcon );
766 mbkfree((void *)ptcon);
767 if (TRACE_MODE == 'Y')
768 (void)fprintf(stdout, "--- mbk --- dellocon : %s\n", name);
769
770 return 1;
771 }
772
773 /*******************************************************************************
774 * function getlomodel *
775 * gives a pointer to a model or NULL if it doesn't exist *
776 *******************************************************************************/
getlomodel(lofig_list * ptmodel,const char * mname)777 lofig_list *getlomodel(lofig_list *ptmodel, const char *mname)
778 {
779 lofig_list *ptfig;
780
781 char *name = namealloc(mname);
782 for (ptfig = ptmodel; ptfig; ptfig = ptfig->NEXT)
783 if (ptfig->NAME == name)
784 return ptfig;
785 return NULL;
786 }
787
788 /*******************************************************************************
789 * function getloins() *
790 *******************************************************************************/
getloins(lofig_list * ptfig,const char * iname)791 loins_list *getloins(lofig_list *ptfig, const char *iname)
792 {
793 loins_list *ptins;
794 char *name = namealloc(iname);
795
796 for (ptins = ptfig->LOINS; ptins; ptins = ptins->NEXT)
797 if (ptins->INSNAME == name)
798 return ptins;
799
800 (void)fflush(stdout);
801 (void)fprintf(stderr, "*** mbk error ***\n");
802 (void)fprintf(stderr, "getloins impossible :\n");
803 (void)fprintf(stderr, "instance %s doesn't exist in figure %s\n",
804 name, ptfig->NAME);
805 EXIT(1);
806 return NULL; /* never reached */
807 }
808
809 /*******************************************************************************
810 * function getlotrs() *
811 *******************************************************************************/
getlotrs(lofig_list * ptfig,const char * tname)812 lotrs_list *getlotrs(lofig_list *ptfig, const char *tname)
813 {
814 lotrs_list *pttrs;
815 char *name = namealloc(tname);
816
817 for (pttrs = ptfig->LOTRS; pttrs; pttrs = pttrs->NEXT)
818 if (pttrs->TRNAME == name)
819 return pttrs;
820
821 (void)fflush(stdout);
822 (void)fprintf(stderr, "*** mbk error ***\n");
823 (void)fprintf(stderr, "getlotrs impossible :\n");
824 (void)fprintf(stderr, "transistor %s doesn't exist in figure %s\n",
825 name, ptfig->NAME);
826 EXIT(1);
827 return NULL; /* never reached */
828 }
829
830 /*******************************************************************************
831 * function getlocon() *
832 *******************************************************************************/
getlocon(lofig_list * ptfig,const char * cname)833 locon_list *getlocon(lofig_list *ptfig, const char *cname)
834 {
835 locon_list *ptcon;
836 char *name = namealloc(cname);
837
838 for (ptcon = ptfig->LOCON; ptcon; ptcon = ptcon->NEXT)
839 if (ptcon->NAME == name)
840 return ptcon;
841
842 (void)fflush(stdout);
843 (void)fprintf(stderr, "*** mbk error ***\n");
844 (void)fprintf(stderr, "getlocon impossible :\n");
845 (void)fprintf(stderr, "connector %s doesn't exist in figure %s\n",
846 name, ptfig->NAME);
847 EXIT(1);
848 return NULL; /* never reached */
849 }
850
851 /*******************************************************************************
852 * function getlosig() *
853 *******************************************************************************/
getlosig(lofig_list * ptfig,long index)854 losig_list *getlosig(lofig_list *ptfig, long index)
855 {
856 losig_list *ptsig;
857 ptype_list *pt;
858 long low;
859 long high;
860 long sigsize;
861
862 sigsize = getsigsize( ptfig );
863 low = (index % sigsize);
864 high = (index / sigsize);
865 for (pt = ptfig->BKSIG; pt; pt = pt->NEXT)
866 if (pt->TYPE == high) break;
867 if (pt != NULL) {
868 ptsig = (losig_list *)(pt->DATA) + low;
869 if (ptsig->INDEX == index)
870 return ptsig;
871 }
872
873 (void)fflush(stdout);
874 (void)fprintf(stderr, "*** mbk error ***\n");
875 (void)fprintf(stderr, "getlosig impossible :\n");
876 (void)fprintf(stderr, "signal %ld doesn't exist in figure %s\n",
877 index, ptfig->NAME);
878 EXIT(1);
879 return NULL; /* never reached */
880 }
881
882 /*******************************************************************************
883 * function lofigchain() *
884 * For each signal, construct the list of connectors associated *
885 * with the signal.(Field USER of the "losig" structure with *
886 * the code "LOFIGCHAIN") *
887 * This provide the "dual" representation of the net-list *
888 *******************************************************************************/
lofigchain(lofig_list * ptfig)889 void lofigchain(lofig_list *ptfig)
890 {
891 locon_list *ptcon = NULL;
892 losig_list *ptsig = NULL;
893 loins_list *ptins = NULL;
894 lotrs_list *pttrs = NULL;
895 locap_list *ptcap = NULL;
896 lores_list *ptres = NULL;
897 loself_list *ptself = NULL;
898 ptype_list *ptype = NULL;
899
900 if (ptfig->MODE == 'P') {
901 /*
902 (void)fflush(stdout);
903 (void)fprintf(stderr, "*** mbk error ***\nlofigchain impossible ");
904 (void)fprintf(stderr, ": figure %s is interface only\n",
905 ptfig->NAME);
906 EXIT(1);
907 */
908 return;
909 }
910
911 /* cleaning ... */
912 for (ptsig = ptfig->LOSIG; ptsig; ptsig = ptsig->NEXT) {
913 ptype = getptype(ptsig->USER, (long)LOFIGCHAIN);
914 if (ptype != (ptype_list *)NULL) {
915 freechain((chain_list *)ptype->DATA);
916 ptype->DATA = (void *)NULL;
917 } else
918 ptsig->USER = addptype(ptsig->USER, (long)LOFIGCHAIN, (void *)NULL);
919 }
920
921 /* scan connector list */
922 for (ptcon=ptfig->LOCON; ptcon; ptcon=ptcon->NEXT) {
923 ptsig = ptcon->SIG;
924 ptype = getptype(ptsig->USER, (long)LOFIGCHAIN);
925 ptype->DATA = (void *)addchain((chain_list *)ptype->DATA, (void *)ptcon);
926 if (DEBUG_MODE == 'Y')
927 (void)printf("--- mbk --- lofigchain (lofig): on signal <%s> add con <%s>\n", getsigname(ptsig), ptcon->NAME);
928 }
929
930 /* scan instance list */
931 for (ptins =ptfig->LOINS; ptins; ptins=ptins->NEXT) {
932 for (ptcon=ptins->LOCON; ptcon; ptcon=ptcon->NEXT) {
933 ptsig=ptcon->SIG;
934 ptype = getptype(ptsig->USER, (long)LOFIGCHAIN);
935 ptype->DATA = (void *)addchain((chain_list *)ptype->DATA, (void *)ptcon);
936 if (DEBUG_MODE == 'Y')
937 (void)printf("--- mbk --- lofigchain (loins): on signal <%s> add con <%s>\n", getsigname(ptsig), ptcon->NAME);
938 }
939 }
940
941 /* scan transistor list */
942 for (pttrs = ptfig->LOTRS; pttrs; pttrs = pttrs->NEXT) {
943 ptsig = pttrs->GRID->SIG;
944 ptype = getptype(ptsig->USER, (long)LOFIGCHAIN);
945 ptype->DATA = (void *)addchain((chain_list *)ptype->DATA,
946 (void *)pttrs->GRID);
947 ptsig = pttrs->SOURCE->SIG;
948 ptype = getptype(ptsig->USER, (long)LOFIGCHAIN);
949 ptype->DATA = (void *)addchain((chain_list *)ptype->DATA,
950 (void *)pttrs->SOURCE);
951 ptsig = pttrs->DRAIN->SIG;
952 ptype = getptype(ptsig->USER, (long)LOFIGCHAIN);
953 ptype->DATA = (void *)addchain((chain_list *)ptype->DATA,
954 (void *)pttrs->DRAIN);
955 ptsig = pttrs->BULK->SIG;
956 if( ptsig ) {
957 ptype = getptype(ptsig->USER, (long)LOFIGCHAIN);
958 ptype->DATA = (void *)addchain((chain_list *)ptype->DATA,
959 (void *)pttrs->BULK);
960 }
961 }
962
963 /* scan capacitor list */
964
965 for(ptcap = ptfig -> LOCAP ; ptcap != NULL ; ptcap = ptcap -> NEXT)
966 {
967 ptsig = ptcap -> TCON -> SIG ;
968 ptype = getptype(ptsig -> USER,(long)LOFIGCHAIN) ;
969 ptype -> DATA = (void *)addchain((chain_list *)ptype -> DATA,(void *)ptcap -> TCON) ;
970
971 ptsig = ptcap -> BCON -> SIG ;
972 ptype = getptype(ptsig -> USER,(long)LOFIGCHAIN) ;
973 ptype -> DATA = (void *)addchain((chain_list *)ptype -> DATA,(void *)ptcap -> BCON) ;
974 }
975
976 /* scan resistor list */
977
978 for(ptres = ptfig -> LORES ; ptres != NULL ; ptres = ptres -> NEXT)
979 {
980 ptsig = ptres -> RCON1 -> SIG ;
981 ptype = getptype(ptsig -> USER,(long)LOFIGCHAIN) ;
982 ptype -> DATA = (void *)addchain((chain_list *)ptype -> DATA,(void *)ptres -> RCON1) ;
983
984 ptsig = ptres -> RCON2 -> SIG ;
985 ptype = getptype(ptsig -> USER,(long)LOFIGCHAIN) ;
986 ptype -> DATA = (void *)addchain((chain_list *)ptype -> DATA,(void *)ptres -> RCON2) ;
987 }
988
989 /* scan inductor list */
990
991 for(ptself = ptfig -> LOSELF ; ptself != NULL ; ptself = ptself -> NEXT)
992 {
993 ptsig = ptself -> SCON1 -> SIG ;
994 ptype = getptype(ptsig -> USER,(long)LOFIGCHAIN) ;
995 ptype -> DATA = (void *)addchain((chain_list *)ptype -> DATA,(void *)ptself -> SCON1) ;
996
997 ptsig = ptself -> SCON2 -> SIG ;
998 ptype = getptype(ptsig -> USER,(long)LOFIGCHAIN) ;
999 ptype -> DATA = (void *)addchain((chain_list *)ptype -> DATA,(void *)ptself -> SCON2) ;
1000 }
1001
1002 if (DEBUG_MODE == 'Y')
1003 (void)printf("--- mbk --- lofigchain %s\n", ptfig -> NAME) ;
1004 }
1005
1006 /*******************************************************************************
1007 * function getsigname() *
1008 * choose the least concatened signal name *
1009 *******************************************************************************/
getsigname(losig_list * ptsig)1010 char *getsigname(losig_list *ptsig)
1011 {
1012 chain_list *ptscan;
1013 char *ptchar;
1014 char buffer[50];
1015 char *result = NULL;
1016 register long nseparmin = 1000;
1017
1018 if (ptsig == NULL)
1019 return NULL;
1020
1021 for (ptscan = ptsig->NAMECHAIN; ptscan; ptscan = ptscan->NEXT) {
1022 register long nsepar = 0;
1023 if (ptscan->DATA != NULL) {
1024 for (ptchar = (char *)ptscan->DATA; *ptchar != '\0'; ptchar++)
1025 if (*ptchar == SEPAR)
1026 nsepar++;
1027 if (nsepar < nseparmin) {
1028 nseparmin = nsepar;
1029 result = (char *)ptscan->DATA;
1030 }
1031 }
1032 }
1033 if (!result) {
1034 (void)sprintf(buffer, "%ld", ptsig->INDEX);
1035 result = namealloc(buffer);
1036 }
1037 return result;
1038 }
1039
1040 /*******************************************************************************
1041 * function viewlo() *
1042 * display on screen the content of all logical figures *
1043 *******************************************************************************/
viewlo(void)1044 void viewlo(void)
1045 {
1046 lofig_list *ptfig;
1047
1048 if (HEAD_LOFIG == NULL) {
1049 (void)printf("\n!!! viewlo : empty list of figure !!!\n");
1050 return;
1051 } else for (ptfig = HEAD_LOFIG; ptfig; ptfig = ptfig->NEXT)
1052 viewlofig(ptfig);
1053 }
1054
1055 /*******************************************************************************
1056 * function viewlofig() *
1057 * display on screen the content of logical figure ptfig *
1058 *******************************************************************************/
viewlofig(lofig_list * ptfig)1059 void viewlofig(lofig_list *ptfig)
1060 {
1061 locon_list *ptcon;
1062 losig_list *ptsig;
1063 loins_list *ptins;
1064 lotrs_list *pttrs;
1065 locap_list *ptcap;
1066 lores_list *ptres;
1067 loself_list *ptself;
1068 chain_list *scanchain;
1069 ptype_list *pt;
1070
1071 if (ptfig->NAME == NULL)
1072 (void)printf("!!! figure without name !!! /n");
1073 else
1074 (void)printf("\nfigure : %-20s mode : %c\n", ptfig->NAME, ptfig->MODE);
1075
1076 if (ptfig->LOCON == NULL)
1077 (void)printf(" |---empty connector list\n");
1078 else
1079 {
1080 for (ptcon = ptfig->LOCON; ptcon; ptcon = ptcon->NEXT)
1081 viewlofigcon(ptcon);
1082
1083 pt = getptype( ptfig->USER, PH_INTERF );
1084 if( pt )
1085 {
1086 (void)printf(" |---connector list physical order\n");
1087 for( scanchain = (chain_list*)(pt->DATA); scanchain ; scanchain = scanchain->NEXT )
1088 (void)printf(" | |---%s\n",(char*)(scanchain->DATA) );
1089 (void)printf(" |\n");
1090 }
1091 }
1092
1093 if (ptfig->LOSIG == NULL)
1094 (void)printf(" |---empty signal list\n");
1095 else for (ptsig = ptfig->LOSIG; ptsig; ptsig = ptsig->NEXT)
1096 viewlosig(ptsig);
1097
1098 if (ptfig->LOINS == NULL)
1099 (void)printf(" |---empty instance list\n");
1100 else for (ptins = ptfig->LOINS; ptins; ptins = ptins->NEXT)
1101 viewloins(ptins);
1102
1103 if (ptfig->LOTRS == NULL)
1104 (void)printf(" |---empty transistor list\n");
1105 else for (pttrs = ptfig->LOTRS; pttrs; pttrs = pttrs->NEXT)
1106 viewlotrs(pttrs);
1107
1108 if(ptfig -> LOCAP == NULL)
1109 {
1110 (void)printf(" |---empty capacitor list\n") ;
1111 }
1112 else
1113 {
1114 for(ptcap = ptfig -> LOCAP ; ptcap ; ptcap = ptcap -> NEXT)
1115 {
1116 viewlocap(ptcap) ;
1117 }
1118 }
1119
1120 if(ptfig -> LORES == NULL)
1121 {
1122 (void)printf(" |---empty resistor list\n") ;
1123 }
1124 else
1125 {
1126 for(ptres = ptfig -> LORES ; ptres ; ptres = ptres -> NEXT)
1127 {
1128 viewlores(ptres) ;
1129 }
1130 }
1131
1132 if(ptfig -> LOSELF == NULL)
1133 {
1134 (void)printf(" |---empty inductor list\n") ;
1135 }
1136 else
1137 {
1138 for(ptself = ptfig -> LOSELF ; ptself ; ptself = ptself -> NEXT)
1139 {
1140 viewloself(ptself) ;
1141 }
1142 }
1143
1144 if (ptfig->USER != NULL)
1145 {
1146 (void)printf(" |---USER field\n");
1147 for( pt = ptfig->USER ; pt ; pt = pt->NEXT )
1148 (void)printf(" | |-- %ld\n",pt->TYPE);
1149 }
1150 else
1151 (void)printf(" |---empty USER field\n");
1152
1153 (void)printf(" | \n");
1154 }
1155
1156 /*******************************************************************************
1157 * function viewlofigcon() *
1158 *******************************************************************************/
viewlofigcon(locon_list * ptcon)1159 void viewlofigcon(locon_list *ptcon)
1160 {
1161 num_list *scannum;
1162 ptype_list *scanptype;
1163 chain_list *scanchain;
1164
1165 if (ptcon->NAME == NULL)
1166 (void)printf(" |--- !!! connector without name !!!\n");
1167 else
1168 (void)printf(" |---connector : \"%s\"\n", ptcon->NAME);
1169 (void)printf(" | |---direction : %c\n", ptcon->DIRECTION);
1170 if (ptcon->SIG == NULL)
1171 (void)printf(" | |---no signal\n");
1172 else
1173 (void)printf(" | |---signal : %ld\n", ptcon->SIG->INDEX);
1174 if (ptcon->ROOT == NULL)
1175 (void)printf(" |---no root\n");
1176 else
1177 (void)printf(" | |---root : %s\n",
1178 ((char *)(((lofig_list *)(ptcon->ROOT))->NAME)));
1179 (void)printf(" | |---type : %c \n", ptcon->TYPE);
1180
1181 (void)printf(" | |---USER list\n");
1182 for( scanptype = ptcon->USER ; scanptype ; scanptype = scanptype->NEXT )
1183 {
1184 switch( scanptype->TYPE )
1185 {
1186 case PNODENAME:
1187 (void)printf(" | | |---PNODENAME\n");
1188 for( scanchain = (chain_list*)(scanptype->DATA);
1189 scanchain;
1190 scanchain = scanchain->NEXT )
1191 (void)printf(" | | | |---%s\n", (char*)(scanchain->DATA)?(char*)(scanchain->DATA):"NULL" );
1192 break;
1193 default:
1194 (void)printf(" | | | |---%ld\n",scanptype->TYPE);
1195 }
1196 }
1197
1198 if(ptcon->PNODE == NULL)
1199 (void)printf(" | |---no node\n");
1200 else {
1201 (void)printf(" | |---node\n");
1202 for(scannum = ptcon->PNODE; scannum; scannum = scannum->NEXT )
1203 (void)printf(" | | |---%ld\n",scannum->DATA);
1204
1205 }
1206
1207 (void)printf(" |\n");
1208 }
1209
1210 /*******************************************************************************
1211 * function viewlosig() *
1212 *******************************************************************************/
viewlosig(losig_list * ptsig)1213 void viewlosig(losig_list *ptsig)
1214 {
1215 chain_list *ptchain;
1216 lowire_list *scanwire;
1217 chain_list *scanctc;
1218 loctc_list *ptctc;
1219 char levelrc;
1220 ptype_list *ptptype;
1221 num_list *scannum;
1222
1223 (void)printf(" |---signal : %ld \n" , ptsig->INDEX);
1224 if (ptsig->NAMECHAIN == NULL)
1225 (void)printf(" | |---no alias names\n");
1226 else for (ptchain = ptsig->NAMECHAIN; ptchain; ptchain = ptchain->NEXT) {
1227 if (ptchain->DATA == NULL)
1228 (void)printf(" | |--- !!! empty name !!!\n");
1229 else
1230 (void)printf(" | |---alias : \"%s\"\n", (char *)ptchain->DATA);
1231 }
1232 (void)printf(" | |---type : %c\n" , ptsig->TYPE);
1233
1234 levelrc = rclevel( ptsig );
1235
1236 if( levelrc == MBK_RC_A )
1237 (void)printf(" | |---no parasitic data\n");
1238 else {
1239 (void)printf(" | |---parasitic data\n");
1240 (void)printf(" | | |---capacitance : %g\n" , ptsig->PRCN->CAPA);
1241 if( levelrc == MBK_RC_C || levelrc == MBK_RC_E ) {
1242 (void)printf(" | | |---wire list\n");
1243 for( scanwire = ptsig->PRCN->PWIRE ; scanwire != NULL ; scanwire = scanwire->NEXT )
1244 (void)printf(" | | | |- %s n1=%3ld n2=%3ld r=%g c=%g\n",
1245 scanwire->LAYER == RCN_WIRE_ALU1 ? "ALU1" :
1246 scanwire->LAYER == RCN_WIRE_ALU2 ? "ALU2" :
1247 scanwire->LAYER == RCN_WIRE_POLY ? "POLY" :
1248 scanwire->LAYER == RCN_WIRE_CONT_POLY ? "CONT_POLY" :
1249 scanwire->LAYER == RCN_WIRE_CONT_DIF_N ? "CONT_DIF_N" :
1250 scanwire->LAYER == RCN_WIRE_CONT_VIA ? "CONT_VIA" :
1251 scanwire->LAYER == RCN_WIRE_CONT_VIA2 ? "CONT_VIA2" :
1252 "UNKNOWN",
1253 scanwire->NODE1,
1254 scanwire->NODE2,
1255 scanwire->RESI,
1256 scanwire->CAPA );
1257 }
1258 else
1259 (void)printf(" | | |---no wire\n");
1260 if( levelrc == MBK_RC_D || levelrc == MBK_RC_E ) {
1261 (void)printf(" | | |---crosstalk capacitance list\n");
1262 for( scanctc = ptsig->PRCN->PCTC ; scanctc != NULL ; scanctc = scanctc->NEXT ) {
1263 ptctc = (loctc_list*)scanctc->DATA;
1264 (void)printf(" | | | |-S1=%3ld N1=%3ld S2=%3ld N2=%3ld Capa=%g.\n",
1265 ptctc->SIG1->INDEX,
1266 ptctc->NODE1,
1267 ptctc->SIG2->INDEX,
1268 ptctc->NODE2,
1269 ptctc->CAPA
1270 );
1271 }
1272 }
1273 else
1274 (void)printf(" | | |---no crosstalk capacitance\n");
1275 (void)printf(" | | |---%ld node\n",ptsig->PRCN->NBNODE);
1276 }
1277 (void)printf(" | |---USER list\n");
1278 for( ptptype = ptsig->USER ; ptptype ; ptptype = ptptype->NEXT )
1279 {
1280 switch( ptptype->TYPE )
1281 {
1282 case LOFIGCHAIN:
1283 printf( " | | |-LOFIGCHAIN\n" );
1284 for( ptchain = (chain_list*)ptptype->DATA ; ptchain ; ptchain = ptchain->NEXT )
1285 {
1286 printf( " | | | |-%s ",((locon_list*)ptchain->DATA)->NAME);
1287 switch( ((locon_list*)ptchain->DATA)->TYPE )
1288 {
1289 case 'T':
1290 printf( "(T%c : %s) ",((lotrs_list*)((locon_list*)ptchain->DATA)->ROOT)->TYPE==TRANSN?'N':'P',((lotrs_list*)((locon_list*)ptchain->DATA)->ROOT)->TRNAME ? ((lotrs_list*)((locon_list*)ptchain->DATA)->ROOT)->TRNAME : "No name" );
1291 break;
1292 case 'P':
1293 printf( "(C%s : %s) ",((locap_list*)((locon_list*)ptchain->DATA)->ROOT)->TYPE==CAPMIM?"CAPMIM":"CAPPNWELL",((locap_list*)((locon_list*)ptchain->DATA)->ROOT)-> NAME ? ((locap_list*)((locon_list*)ptchain->DATA)->ROOT)->NAME : "No name" );
1294 break;
1295 case 'R':
1296 printf( "(C%s : %s) ",((lores_list*)((locon_list*)ptchain->DATA)->ROOT)->TYPE==RESMIM?"RESMIM":"RESMIM",((lores_list*)((locon_list*)ptchain->DATA)->ROOT)-> NAME ? ((lores_list*)((locon_list*)ptchain->DATA)->ROOT)->NAME : "No name" );
1297 break;
1298 case 'L':
1299 printf( "(C%s : %s) ",((loself_list*)((locon_list*)ptchain->DATA)->ROOT)->TYPE==SELFMIM?"SELFMIM":"SELFMIM",((loself_list*)((locon_list*)ptchain->DATA)->ROOT)-> NAME ? ((loself_list*)((locon_list*)ptchain->DATA)->ROOT)->NAME : "No name" );
1300 break;
1301 case 'I':
1302 printf( "(I : %s) ",((loins_list*)((locon_list*)ptchain->DATA)->ROOT)->INSNAME ? ((loins_list*)((locon_list*)ptchain->DATA)->ROOT)->INSNAME : "No name" );
1303 break;
1304 case 'E':
1305 printf( "(Figure) " );
1306 break;
1307 default:
1308 printf( "No valid type.\n" );
1309 }
1310 for( scannum = ((locon_list*)ptchain->DATA)->PNODE ; scannum ; scannum = scannum->NEXT )
1311 printf( "%ld ", scannum->DATA );
1312 printf( "\n" );
1313 }
1314 break;
1315 default:
1316 break;
1317 }
1318 }
1319 {
1320 }
1321 (void)printf(" | \n");
1322 }
1323
1324
1325 /*******************************************************************************
1326 * function viewloins() *
1327 *******************************************************************************/
viewloins(loins_list * ptins)1328 void viewloins(loins_list *ptins)
1329 {
1330 locon_list *ptcon;
1331 chain_list *scanchain;
1332 ptype_list *pt;
1333
1334 if (ptins->INSNAME == NULL)
1335 (void)printf(" |--- !!! no instance name !!!\n");
1336 else
1337 (void)printf(" |---instance : %s\n", ptins->INSNAME);
1338 if (ptins->FIGNAME == NULL)
1339 (void)printf(" | |--- !!! no instance model !!!\n");
1340 else
1341 (void)printf(" | |---model : %s \n" , ptins->FIGNAME);
1342 if (ptins->LOCON == NULL)
1343 (void)printf(" | |---empty list of connectors\n");
1344 else
1345 {
1346 for (ptcon = ptins->LOCON; ptcon != NULL; ptcon = ptcon->NEXT)
1347 viewloinscon(ptcon);
1348 pt = getptype( ptins->USER, PH_INTERF );
1349 if( pt )
1350 {
1351 (void)printf(" | |---connector list physical order\n");
1352 for( scanchain = (chain_list*)(pt->DATA); scanchain ; scanchain = scanchain->NEXT )
1353 (void)printf(" | | |---%s\n",(char*)(scanchain->DATA) );
1354 (void)printf(" | |\n");
1355 }
1356 }
1357 if (ptins->USER != NULL)
1358 (void)printf(" | |---non empty USER field\n");
1359 (void)printf(" | \n");
1360 }
1361
1362 /*******************************************************************************
1363 * function viewlotrs() *
1364 *******************************************************************************/
viewlotrs(lotrs_list * pttrs)1365 void viewlotrs(lotrs_list *pttrs)
1366 {
1367 (void)printf(" |---transistor\n");
1368 (void)printf(" | |---type : %c %s %s\n",
1369 IsTransN(pttrs->TYPE)?'N':'P',
1370 IsTransFast(pttrs->TYPE)?"FAST":"SLOW",
1371 IsTransHvio(pttrs->TYPE)?"HVIO":"----"
1372 );
1373 if (pttrs->TRNAME != NULL )
1374 (void)printf(" | |---name : %s\n", pttrs->TRNAME );
1375 else
1376 (void)printf(" | |---no name\n" );
1377
1378 if (pttrs->SOURCE == NULL)
1379 (void)printf(" | |--- !!! no signal on source !!! \n");
1380 else
1381 viewloinscon( pttrs->SOURCE );
1382
1383 if (pttrs->GRID == NULL)
1384 (void)printf(" | |--- !!! no signal on grid !!!\n");
1385 else
1386 viewloinscon( pttrs->GRID );
1387
1388 if (pttrs->DRAIN == NULL)
1389 (void)printf(" | |--- !!! no signal on drain !!!\n");
1390 else
1391 viewloinscon( pttrs->DRAIN );
1392
1393 if (pttrs->BULK == NULL)
1394 (void)printf(" | |--- !!! no signal on bulk !!!\n");
1395 else
1396 viewloinscon( pttrs->BULK );
1397
1398 (void)printf(" | |---x : %ld\n", pttrs->X);
1399 (void)printf(" | |---y : %ld\n", pttrs->Y);
1400 (void)printf(" | |---width : %ld\n", pttrs->WIDTH);
1401 (void)printf(" | |---length : %ld\n", pttrs->LENGTH);
1402 (void)printf(" | |---ps : %ld\n", pttrs->PS);
1403 (void)printf(" | |---pd : %ld\n", pttrs->PD);
1404 (void)printf(" | |---xs : %ld\n", pttrs->XS);
1405 (void)printf(" | |---xd : %ld\n", pttrs->XD);
1406 if (pttrs->USER != NULL)
1407 (void)printf(" | |---non empty USER field\n");
1408 (void)printf(" |\n");
1409 }
1410
1411 /*******************************************************************************
1412 * function viewloinscon() *
1413 *******************************************************************************/
viewloinscon(locon_list * ptcon)1414 void viewloinscon(locon_list *ptcon)
1415 {
1416 num_list *scannum;
1417 ptype_list *scanptype;
1418 chain_list *scanchain;
1419
1420 if (ptcon->NAME == NULL)
1421 (void)printf(" | |---no connector name\n");
1422 else
1423 (void)printf(" | |---connector : \"%s\"\n" , ptcon->NAME);
1424 (void)printf(" | | |---direction : %c\n" , ptcon->DIRECTION);
1425 if (ptcon->SIG == NULL)
1426 (void)printf(" | | |---no signal\n");
1427 else
1428 (void)printf(" | | |---signal : %ld\n" , ptcon->SIG->INDEX);
1429 if ((ptcon->ROOT) == NULL)
1430 (void)printf(" | | |---no root\n");
1431 else
1432 switch( ptcon->TYPE )
1433 {
1434 case 'I':
1435 (void)printf(" | | |---root : %s\n" , ((char*)(((loins_list *)(ptcon->ROOT))->INSNAME)));
1436 break;
1437 case 'T':
1438 (void)printf(" | | |---root : %s\n" ,
1439 ((lotrs_list*)(ptcon->ROOT))->TRNAME?((lotrs_list*)(ptcon->ROOT))->TRNAME:"no transistor name" );
1440 break;
1441 case 'C':
1442 (void)printf(" | | |---root : %s\n" ,
1443 ((locap_list*)(ptcon->ROOT))->NAME?((locap_list*)(ptcon->ROOT))->NAME:"no capacitor name" );
1444 break;
1445 case 'R':
1446 (void)printf(" | | |---root : %s\n" ,
1447 ((lores_list*)(ptcon->ROOT))->NAME?((lores_list*)(ptcon->ROOT))->NAME:"no resistor name" );
1448 break;
1449 case 'S':
1450 (void)printf(" | | |---root : %s\n" ,
1451 ((loself_list*)(ptcon->ROOT))->NAME?((loself_list*)(ptcon->ROOT))->NAME:"no inductor name" );
1452 break;
1453 default:
1454 (void)printf(" | | |---root : *** BAD TYPE ***\n" );
1455 }
1456 (void)printf(" | | |---type : %c\n" , ptcon->TYPE);
1457 if(ptcon->PNODE == NULL)
1458 (void)printf(" | | |---no node\n");
1459 else {
1460 (void)printf(" | | |---node\n");
1461 for(scannum = ptcon->PNODE; scannum; scannum = scannum->NEXT )
1462 (void)printf(" | | | |---%ld\n",scannum->DATA);
1463 }
1464 (void)printf(" | | |---USER list\n");
1465 for( scanptype = ptcon->USER ; scanptype ; scanptype = scanptype->NEXT )
1466 {
1467 switch( scanptype->TYPE )
1468 {
1469 case PNODENAME:
1470 (void)printf(" | | | |---PNODENAME\n");
1471 for( scanchain = (chain_list*)(scanptype->DATA);
1472 scanchain;
1473 scanchain = scanchain->NEXT )
1474 (void)printf(" | | | | |---%s\n", (char*)(scanchain->DATA)?(char*)(scanchain->DATA):"NULL" );
1475 break;
1476 default:
1477 (void)printf(" | | | |---%ld\n",scanptype->TYPE);
1478 }
1479 }
1480 (void)printf(" | | \n");
1481 }
1482
1483 /*******************************************************************************
1484 * function getsigsize() *
1485 *******************************************************************************/
1486
getsigsize(lofig_list * ptfig)1487 long getsigsize(lofig_list *ptfig)
1488 {
1489 ptype_list *ptl;
1490
1491 ptl = getptype( ptfig->USER, PTSIGSIZE );
1492 if( ptl )
1493 return( (long)(ptl->DATA) );
1494
1495 return( SIGSIZE );
1496 }
1497
1498 /*******************************************************************************
1499 * function setsigsize() *
1500 *******************************************************************************/
1501
setsigsize(lofig_list * ptfig,long nb)1502 void setsigsize(lofig_list *ptfig, long nb)
1503 {
1504 ptype_list *ptl;
1505
1506 if( ptfig->BKSIG )
1507 {
1508 fflush( stdout );
1509 fprintf( stderr,"*** mbk error ***\n" );
1510 fprintf( stderr,"setsigsize() impossible\n" );
1511 fprintf( stderr,"BKSIG not NULL.\n" );
1512 EXIT(1);
1513 }
1514
1515 ptl = getptype( ptfig->USER, PTSIGSIZE );
1516 if( !ptl )
1517 ptfig->USER = addptype( ptfig->USER, PTSIGSIZE, (void*)nb );
1518 else
1519 ptl->DATA = (void*)nb;
1520 }
1521
1522
1523 /*******************************************************************************
1524 * function for cleaning USER field of structures. *
1525 *******************************************************************************/
1526
1527 /*#define MBK_TRACE_BAD_PTYPE 0*/
1528
delloconuser(locon_list * ptlocon)1529 void delloconuser(locon_list *ptlocon)
1530 {
1531 ptype_list *scanptype;
1532 ptype_list *next;
1533 ptype_list *prev;
1534 long del;
1535
1536 prev = NULL;
1537 for( scanptype = ptlocon->USER ; scanptype ; scanptype = next )
1538 {
1539 next = scanptype->NEXT;
1540 del = 0;
1541
1542 switch( scanptype->TYPE )
1543 {
1544 case PNODENAME:
1545 freechain( scanptype->DATA );
1546 del = 1;
1547 break;
1548 default:
1549 #ifdef MBK_TRACE_BAD_PTYPE
1550 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n",
1551 scanptype->TYPE
1552 );
1553 #endif
1554 break;
1555 }
1556
1557 if( del )
1558 {
1559 if( !prev )
1560 ptlocon->USER = next;
1561 else
1562 prev->NEXT = next;
1563 scanptype->NEXT = NULL;
1564 freeptype( scanptype );
1565 }
1566 else
1567 prev = scanptype;
1568 }
1569 }
1570
dellofiguser(lofig_list * ptlofig)1571 void dellofiguser(lofig_list *ptlofig)
1572 {
1573 ptype_list *scanptype;
1574 ptype_list *next;
1575 ptype_list *prev;
1576 long del;
1577
1578 prev = NULL;
1579 for( scanptype = ptlofig->USER ; scanptype ; scanptype = next )
1580 {
1581 next = scanptype->NEXT;
1582 del = 0;
1583
1584 switch( scanptype->TYPE )
1585 {
1586 case PH_INTERF:
1587 freechain( scanptype->DATA );
1588 del = 1;
1589 break;
1590 case PTSIGSIZE:
1591 del = 1;
1592 break;
1593 default:
1594 #ifdef MBK_TRACE_BAD_PTYPE
1595 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n",
1596 scanptype->TYPE
1597 );
1598 #endif
1599 break;
1600 }
1601
1602 if( del )
1603 {
1604 if( !prev )
1605 ptlofig->USER = next;
1606 else
1607 prev->NEXT = next;
1608 scanptype->NEXT = NULL;
1609 freeptype( scanptype );
1610 }
1611 else
1612 prev = scanptype;
1613 }
1614 }
1615
delloinsuser(loins_list * ptloins)1616 void delloinsuser(loins_list *ptloins)
1617 {
1618 ptype_list *scanptype;
1619 ptype_list *next;
1620 ptype_list *prev;
1621 long del;
1622
1623 prev = NULL;
1624 for( scanptype = ptloins->USER ; scanptype ; scanptype = next )
1625 {
1626 next = scanptype->NEXT;
1627 del = 0;
1628
1629 switch( scanptype->TYPE )
1630 {
1631 case PH_INTERF:
1632 freechain( scanptype->DATA );
1633 del = 1;
1634 break;
1635 default:
1636 #ifdef MBK_TRACE_BAD_PTYPE
1637 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n",
1638 scanptype->TYPE
1639 );
1640 #endif
1641 break;
1642 }
1643
1644 if( del )
1645 {
1646 if( !prev )
1647 ptloins->USER = next;
1648 else
1649 prev->NEXT = next;
1650 scanptype->NEXT = NULL;
1651 freeptype( scanptype );
1652 }
1653 else
1654 prev = scanptype;
1655 }
1656 }
1657
dellotrsuser(lotrs_list * ptlotrs)1658 void dellotrsuser(lotrs_list *ptlotrs)
1659 {
1660 ptype_list *scanptype;
1661 ptype_list *next;
1662 ptype_list *prev;
1663 long del;
1664
1665 prev = NULL;
1666 for( scanptype = ptlotrs->USER ; scanptype ; scanptype = next )
1667 {
1668 next = scanptype->NEXT;
1669 del = 0;
1670
1671 switch( scanptype->TYPE )
1672 {
1673 default:
1674 #ifdef MBK_TRACE_BAD_PTYPE
1675 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n",
1676 scanptype->TYPE
1677 );
1678 #endif
1679 break;
1680 }
1681
1682 if( del )
1683 {
1684 if( !prev )
1685 ptlotrs->USER = next;
1686 else
1687 prev->NEXT = next;
1688 scanptype->NEXT = NULL;
1689 freeptype( scanptype );
1690 }
1691 else
1692 prev = scanptype;
1693 }
1694 }
1695
dellosiguser(losig_list * ptlosig)1696 void dellosiguser(losig_list *ptlosig)
1697 {
1698 ptype_list *scanptype;
1699 ptype_list *next;
1700 ptype_list *prev;
1701 long del;
1702
1703 prev = NULL;
1704 for( scanptype = ptlosig->USER ; scanptype ; scanptype = next )
1705 {
1706 next = scanptype->NEXT;
1707 del = 0;
1708
1709 switch( scanptype->TYPE )
1710 {
1711 case LOFIGCHAIN:
1712 freechain( scanptype->DATA );
1713 del = 1;
1714 break;
1715 default:
1716 #ifdef MBK_TRACE_BAD_PTYPE
1717 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n",
1718 scanptype->TYPE
1719 );
1720 #endif
1721 break;
1722 }
1723
1724 if( del )
1725 {
1726 if( !prev )
1727 ptlosig->USER = next;
1728 else
1729 prev->NEXT = next;
1730 scanptype->NEXT = NULL;
1731 freeptype( scanptype );
1732 }
1733 else
1734 prev = scanptype;
1735 }
1736 }
1737
1738 /***********************************************************************************************/
1739 /*********************************** Analogical World ******************************************/
1740 /***********************************************************************************************/
1741
1742 /*********************************** Capacitor : add *******************************************/
1743
addlocap(lofig_list * ptfig,char type,double capa,losig_list * pttplate,losig_list * ptbplate,char * name)1744 locap_list *addlocap(lofig_list *ptfig,char type,double capa,losig_list *pttplate,
1745 losig_list *ptbplate,char *name)
1746 {
1747 static char *tplate = NULL ;
1748 static char *bplate = NULL ;
1749 locap_list *ptcap = NULL ;
1750 locon_list *ptcon = NULL ;
1751
1752 tplate = namealloc("tplate");
1753 bplate = namealloc("bplate");
1754
1755 if((type != CAPMIM) && (type != CAPPNWELL))
1756 {
1757 (void)fflush(stdout) ;
1758 (void)fprintf(stderr, "*** mbk error ***\n") ;
1759 (void)fprintf(stderr, " illegal capacitor type : %ld\n",(long)type) ;
1760 EXIT(1) ;
1761 }
1762
1763 ptcap = (locap_list *)mbkalloc(sizeof(locap_list)) ;
1764 ptcap -> TYPE = type ;
1765 ptcap -> CAPA = capa ;
1766 ptcap -> NEXT = ptfig -> LOCAP ;
1767 ptfig -> LOCAP = ptcap ;
1768 ptcap -> USER = NULL ;
1769
1770 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
1771 ptcon -> NAME = tplate ;
1772 ptcon -> SIG = pttplate ;
1773 ptcon -> ROOT = (void *)ptcap ;
1774 ptcon -> TYPE = TRANSCV2 ;
1775 ptcon -> DIRECTION = INTERNAL ;
1776 ptcon -> USER = NULL ;
1777 ptcon -> PNODE = NULL ;
1778 ptcap -> TCON = ptcon ;
1779
1780 ptcon = (locon_list *)mbkalloc(sizeof(locon_list)) ;
1781 ptcon -> NAME = bplate ;
1782 ptcon -> SIG = ptbplate ;
1783 ptcon -> ROOT = (void *)ptcap ;
1784 ptcon -> TYPE = TRANSCV2 ;
1785 ptcon -> DIRECTION = INTERNAL ;
1786 ptcon -> USER = NULL ;
1787 ptcon -> PNODE = NULL ;
1788 ptcap -> BCON = ptcon ;
1789
1790 /* No check is done for capacitor name unicity */
1791 ptcap -> NAME = namealloc(name) ;
1792
1793 if(TRACE_MODE == 'Y')
1794 {
1795 (void)fprintf(stdout,"--- mbk --- addlocap : %s\n",type == CAPMIM ? "CAPMIM" : "CAPPNWELL") ;
1796 }
1797
1798 return ptcap ;
1799 }
1800
1801 /*********************************** Capacitor : del *******************************************/
1802
dellocap(lofig_list * ptfig,locap_list * ptcap)1803 int dellocap(lofig_list *ptfig,locap_list *ptcap)
1804 {
1805 locap_list *pt = NULL ;
1806 locap_list *ptsav = NULL ;
1807
1808 for(pt = ptfig -> LOCAP ; pt != NULL ; pt = pt -> NEXT)
1809 {
1810 if(pt == ptcap)
1811 {
1812 break ;
1813 }
1814
1815 ptsav = pt ;
1816 }
1817
1818 if(pt == NULL)
1819 {
1820 return 0 ;
1821 }
1822 else
1823 {
1824 if(pt == ptfig -> LOCAP)
1825 {
1826 ptfig -> LOCAP = pt -> NEXT ;
1827 }
1828 else
1829 {
1830 ptsav -> NEXT = pt -> NEXT ;
1831 }
1832 }
1833
1834 if(pt -> TCON -> PNODE)
1835 {
1836 delrcnlocon(pt -> TCON) ;
1837 }
1838
1839 delloconuser(pt -> TCON) ;
1840 mbkfree((void *)pt -> TCON) ;
1841
1842 if(pt -> BCON -> PNODE)
1843 {
1844 delrcnlocon(pt -> BCON) ;
1845 }
1846
1847 delloconuser(pt -> BCON) ;
1848 mbkfree((void *)pt -> BCON) ;
1849
1850 dellocapuser(pt) ;
1851 mbkfree((void *)pt) ;
1852
1853 if(TRACE_MODE == 'Y')
1854 {
1855 (void)fprintf(stdout, "--- mbk --- dellocap : \n") ;
1856 }
1857
1858 return 1 ;
1859 }
1860
1861 /*********************************** Capacitor : getlocap **************************************/
1862
getlocap(lofig_list * ptfig,const char * cname)1863 locap_list *getlocap(lofig_list *ptfig, const char *cname)
1864 {
1865 locap_list *ptcap = NULL ;
1866 char *name = namealloc(cname) ;
1867
1868 for(ptcap = ptfig -> LOCAP ; ptcap != NULL ; ptcap = ptcap -> NEXT)
1869 {
1870 if(ptcap -> NAME == name)
1871 {
1872 return ptcap ;
1873 }
1874 }
1875
1876 (void)fflush(stdout) ;
1877 (void)fprintf(stderr,"*** mbk error ***\n") ;
1878 (void)fprintf(stderr,"getlocap impossible :\n") ;
1879 (void)fprintf(stderr,"capacitor %s doesn't exist in figure %s\n",name,ptfig -> NAME) ;
1880 EXIT(1) ;
1881
1882 return NULL ; /* never reached */
1883 }
1884
1885 /*********************************** Capacitor : setlocap **************************************/
1886
setlocap(lofig_list * ptfig,const char * cname,double capa)1887 void setlocap(lofig_list *ptfig, const char *cname,double capa)
1888 {
1889 locap_list *ptcap = NULL ;
1890 locap_list *cap = NULL ;
1891 char *name = namealloc(cname) ;
1892
1893 for(ptcap = ptfig -> LOCAP ; ptcap != NULL ; ptcap = ptcap -> NEXT)
1894 {
1895 if(ptcap -> NAME == name)
1896 {
1897 cap = ptcap ;
1898 break ;
1899 }
1900 }
1901
1902 if(cap == NULL)
1903 {
1904 (void)fflush(stdout) ;
1905 (void)fprintf(stderr,"*** mbk error ***\n") ;
1906 (void)fprintf(stderr,"setlocap impossible :\n") ;
1907 (void)fprintf(stderr,"capacitor %s doesn't exist in figure %s\n",name,ptfig -> NAME) ;
1908 EXIT(1) ;
1909 }
1910
1911 cap -> CAPA = capa ;
1912 }
1913
1914 /*********************************** Capacitor : viewlocap *************************************/
1915
viewlocap(locap_list * ptcap)1916 void viewlocap(locap_list *ptcap)
1917 {
1918 (void)printf(" |---capacitor\n") ;
1919 (void)printf(" | |---type : %s\n",IsCapMIM(ptcap->TYPE)?"MIM":"POLY/NWELL") ;
1920
1921 if(ptcap -> NAME != NULL)
1922 {
1923 (void)printf(" | |---name : %s\n", ptcap -> NAME) ;
1924 }
1925 else
1926 {
1927 (void)printf(" | |---no name\n") ;
1928 }
1929
1930 if(ptcap -> TCON == NULL)
1931 {
1932 (void)printf(" | |--- !!! no signal on top plate !!! \n") ;
1933 }
1934 else
1935 {
1936 viewloinscon(ptcap -> TCON) ;
1937 }
1938
1939 if(ptcap -> BCON == NULL)
1940 {
1941 (void)printf(" | |--- !!! no signal on bottom plate !!! \n") ;
1942 }
1943 else
1944 {
1945 viewloinscon(ptcap -> BCON) ;
1946 }
1947
1948 (void)printf(" | |---capa : %g\n", ptcap -> CAPA) ;
1949
1950 if(ptcap -> USER != NULL)
1951 {
1952 (void)printf(" | |---non empty USER field\n") ;
1953 }
1954
1955 (void)printf(" |\n") ;
1956 }
1957
1958 /*********************************** Capacitor : dellocapuser **********************************/
1959
dellocapuser(locap_list * ptlocap)1960 void dellocapuser ( locap_list *ptlocap )
1961 {
1962 ptype_list *scanptype = NULL;
1963 ptype_list *next = NULL;
1964 ptype_list *prev = NULL;
1965 long del = 0;
1966
1967 for (scanptype = ptlocap->USER ; scanptype != NULL ; scanptype = next) {
1968 next = scanptype->NEXT ;
1969 del = 0 ;
1970
1971 switch (scanptype->TYPE) {
1972 case LOCAP_INFO :
1973 mbkfree( scanptype->DATA );
1974 del = 1 ;
1975 break ;
1976 default :
1977 #ifdef MBK_TRACE_BAD_PTYPE
1978 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n", scanptype->TYPE );
1979 #endif
1980 break;
1981 }
1982
1983 if (del) {
1984 if (prev == NULL) {
1985 ptlocap->USER = next;
1986 } else {
1987 prev->NEXT = next;
1988 }
1989
1990 scanptype->NEXT = NULL;
1991 freeptype( scanptype );
1992 } else {
1993 prev = scanptype ;
1994 }
1995 }
1996 }
1997
1998 /*********************************** Resistor : add ********************************************/
1999
addlores(lofig_list * ptfig,char type,double resi,losig_list * ptrcon1,losig_list * ptrcon2,char * name)2000 lores_list *addlores(lofig_list *ptfig,char type,double resi,losig_list *ptrcon1,
2001 losig_list *ptrcon2,char *name)
2002 {
2003 static char *rcon1 = NULL ;
2004 static char *rcon2 = NULL ;
2005 lores_list *ptres = NULL ;
2006 locon_list *ptcon = NULL ;
2007
2008 rcon1 = namealloc("rcon1");
2009 rcon2 = namealloc("rcon2");
2010
2011 if(type != RESMIM)
2012 {
2013 (void)fflush(stdout) ;
2014 (void)fprintf(stderr, "*** mbk error ***\n") ;
2015 (void)fprintf(stderr, " illegal resistor type : %ld\n",(long)type) ;
2016 EXIT(1) ;
2017 }
2018
2019 ptres = (lores_list *)mbkalloc(sizeof(lores_list)) ;
2020 ptres -> TYPE = type ;
2021 ptres -> RESI = resi ;
2022 ptres -> NEXT = ptfig -> LORES ;
2023 ptfig -> LORES = ptres ;
2024 ptres -> USER = NULL ;
2025
2026 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
2027 ptcon -> NAME = rcon1 ;
2028 ptcon -> SIG = ptrcon1 ;
2029 ptcon -> ROOT = (void *)ptres ;
2030 ptcon -> TYPE = TRANSCV3 ;
2031 ptcon -> DIRECTION = INTERNAL ;
2032 ptcon -> USER = NULL ;
2033 ptcon -> PNODE = NULL ;
2034 ptres -> RCON1 = ptcon ;
2035
2036 ptcon = (locon_list *)mbkalloc(sizeof(locon_list)) ;
2037 ptcon -> NAME = rcon2 ;
2038 ptcon -> SIG = ptrcon2 ;
2039 ptcon -> ROOT = (void *)ptres ;
2040 ptcon -> TYPE = TRANSCV3 ;
2041 ptcon -> DIRECTION = INTERNAL ;
2042 ptcon -> USER = NULL ;
2043 ptcon -> PNODE = NULL ;
2044 ptres -> RCON2 = ptcon ;
2045
2046 /* No check is done for resistor name unicity */
2047 ptres -> NAME = namealloc(name) ;
2048
2049 if(TRACE_MODE == 'Y')
2050 {
2051 (void)fprintf(stdout,"--- mbk --- addlores : %s\n",type == RESMIM ? "RESMIM" : "RESMIM") ;
2052 }
2053
2054 return ptres ;
2055 }
2056
2057 /*********************************** Resistor : del ********************************************/
2058
dellores(lofig_list * ptfig,lores_list * ptres)2059 int dellores(lofig_list *ptfig,lores_list *ptres)
2060 {
2061 lores_list *pt = NULL ;
2062 lores_list *ptsav = NULL ;
2063
2064 for(pt = ptfig -> LORES ; pt != NULL ; pt = pt -> NEXT)
2065 {
2066 if(pt == ptres)
2067 {
2068 break ;
2069 }
2070
2071 ptsav = pt ;
2072 }
2073
2074 if(pt == NULL)
2075 {
2076 return 0 ;
2077 }
2078 else
2079 {
2080 if(pt == ptfig -> LORES)
2081 {
2082 ptfig -> LORES = pt -> NEXT ;
2083 }
2084 else
2085 {
2086 ptsav -> NEXT = pt -> NEXT ;
2087 }
2088 }
2089
2090 if(pt -> RCON1 -> PNODE)
2091 {
2092 delrcnlocon(pt -> RCON1) ;
2093 }
2094
2095 delloconuser(pt -> RCON1) ;
2096 mbkfree((void *)pt -> RCON1) ;
2097
2098 if(pt -> RCON2 -> PNODE)
2099 {
2100 delrcnlocon(pt -> RCON2) ;
2101 }
2102
2103 delloconuser(pt -> RCON2) ;
2104 mbkfree((void *)pt -> RCON2) ;
2105
2106 delloresuser(pt) ;
2107 mbkfree((void *)pt) ;
2108
2109 if(TRACE_MODE == 'Y')
2110 {
2111 (void)fprintf(stdout, "--- mbk --- dellores : \n") ;
2112 }
2113
2114 return 1 ;
2115 }
2116
2117 /*********************************** Resistor : getlores ***************************************/
2118
getlores(lofig_list * ptfig,const char * cname)2119 lores_list *getlores(lofig_list *ptfig, const char *cname)
2120 {
2121 lores_list *ptres = NULL ;
2122 char *name = namealloc(cname) ;
2123
2124 for(ptres = ptfig -> LORES ; ptres != NULL ; ptres = ptres -> NEXT)
2125 {
2126 if(ptres -> NAME == name)
2127 {
2128 return ptres ;
2129 }
2130 }
2131
2132 (void)fflush(stdout) ;
2133 (void)fprintf(stderr,"*** mbk error ***\n") ;
2134 (void)fprintf(stderr,"getlores impossible :\n") ;
2135 (void)fprintf(stderr,"resistor %s doesn't exist in figure %s\n",name,ptfig -> NAME) ;
2136 EXIT(1) ;
2137
2138 return NULL ; /* never reached */
2139 }
2140
2141 /*********************************** Resistor : setlores **************************************/
2142
setlores(lofig_list * ptfig,const char * cname,double resi)2143 void setlores(lofig_list *ptfig, const char *cname,double resi)
2144 {
2145 lores_list *ptres = NULL ;
2146 lores_list *res = NULL ;
2147 char *name = namealloc(cname) ;
2148
2149 for(ptres = ptfig -> LORES ; ptres != NULL ; ptres = ptres -> NEXT)
2150 {
2151 if(ptres -> NAME == name)
2152 {
2153 res = ptres ;
2154 break ;
2155 }
2156 }
2157
2158 if(res == NULL)
2159 {
2160 (void)fflush(stdout) ;
2161 (void)fprintf(stderr,"*** mbk error ***\n") ;
2162 (void)fprintf(stderr,"setlores impossible :\n") ;
2163 (void)fprintf(stderr,"resistor %s doesn't exist in figure %s\n",name,ptfig -> NAME) ;
2164 EXIT(1) ;
2165 }
2166
2167 res -> RESI = resi ;
2168 }
2169
2170 /*********************************** Resistor : viewlores ***************************************/
2171
viewlores(lores_list * ptres)2172 void viewlores(lores_list *ptres)
2173 {
2174 (void)printf(" |---resistor\n") ;
2175 (void)printf(" | |---type : %s\n",IsResMIM(ptres->TYPE)?"MIM":"POLY/NWELL") ;
2176
2177 if(ptres -> NAME != NULL)
2178 {
2179 (void)printf(" | |---name : %s\n", ptres -> NAME) ;
2180 }
2181 else
2182 {
2183 (void)printf(" | |---no name\n") ;
2184 }
2185
2186 if(ptres -> RCON1 == NULL)
2187 {
2188 (void)printf(" | |--- !!! no signal on first connector !!! \n") ;
2189 }
2190 else
2191 {
2192 viewloinscon(ptres -> RCON1) ;
2193 }
2194
2195 if(ptres -> RCON2 == NULL)
2196 {
2197 (void)printf(" | |--- !!! no signal on second connector !!! \n") ;
2198 }
2199 else
2200 {
2201 viewloinscon(ptres -> RCON2) ;
2202 }
2203
2204 (void)printf(" | |---resi : %g\n", ptres -> RESI) ;
2205
2206 if(ptres -> USER != NULL)
2207 {
2208 (void)printf(" | |---non empty USER field\n") ;
2209 }
2210
2211 (void)printf(" |\n") ;
2212 }
2213
2214 /*********************************** Resistor : delloresuser ***********************************/
2215
delloresuser(lores_list * ptlores)2216 void delloresuser(lores_list *ptlores)
2217 {
2218 ptype_list *scanptype = NULL ;
2219 ptype_list *next = NULL ;
2220 ptype_list *prev = NULL ;
2221 long del = 0 ;
2222
2223 for(scanptype = ptlores -> USER ; scanptype != NULL ; scanptype = next)
2224 {
2225 next = scanptype -> NEXT ;
2226 del = 0 ;
2227
2228 switch(scanptype -> TYPE)
2229 {
2230 case LORES_INFO : mbkfree(scanptype -> DATA) ;
2231 del = 1 ;
2232 break ;
2233 default :
2234 #ifdef MBK_TRACE_BAD_PTYPE
2235 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n",scanptype -> TYPE) ;
2236 #endif
2237 break;
2238 }
2239
2240 if(del)
2241 {
2242 if(prev == NULL)
2243 {
2244 ptlores -> USER = next ;
2245 }
2246 else
2247 {
2248 prev -> NEXT = next ;
2249 }
2250
2251 scanptype -> NEXT = NULL ;
2252 freeptype(scanptype ) ;
2253 }
2254 else
2255 {
2256 prev = scanptype ;
2257 }
2258 }
2259 }
2260
2261 /*********************************** Inductor : add ********************************************/
2262
addloself(lofig_list * ptfig,char type,double self,losig_list * ptscon1,losig_list * ptscon2,char * name)2263 loself_list *addloself(lofig_list *ptfig,char type,double self,losig_list *ptscon1,
2264 losig_list *ptscon2,char *name)
2265 {
2266 static char *scon1 = NULL ;
2267 static char *scon2 = NULL ;
2268 loself_list *ptself = NULL ;
2269 locon_list *ptcon = NULL ;
2270
2271 scon1 = namealloc("scon1");
2272 scon2 = namealloc("scon2");
2273
2274 if(type != SELFMIM)
2275 {
2276 (void)fflush(stdout) ;
2277 (void)fprintf(stderr, "*** mbk error ***\n") ;
2278 (void)fprintf(stderr, " illegal inductor type : %ld\n",(long)type) ;
2279 EXIT(1) ;
2280 }
2281
2282 ptself = (loself_list *)mbkalloc(sizeof(loself_list)) ;
2283 ptself -> TYPE = type ;
2284 ptself -> SELF = self ;
2285 ptself -> NEXT = ptfig -> LOSELF ;
2286 ptfig -> LOSELF = ptself ;
2287 ptself -> USER = NULL ;
2288
2289 ptcon = (locon_list *)mbkalloc(sizeof(locon_list));
2290 ptcon -> NAME = scon1 ;
2291 ptcon -> SIG = ptscon1 ;
2292 ptcon -> ROOT = (void *)ptself ;
2293 ptcon -> TYPE = TRANSCV4 ;
2294 ptcon -> DIRECTION = INTERNAL ;
2295 ptcon -> USER = NULL ;
2296 ptcon -> PNODE = NULL ;
2297 ptself -> SCON1 = ptcon ;
2298
2299 ptcon = (locon_list *)mbkalloc(sizeof(locon_list)) ;
2300 ptcon -> NAME = scon2 ;
2301 ptcon -> SIG = ptscon2 ;
2302 ptcon -> ROOT = (void *)ptself ;
2303 ptcon -> TYPE = TRANSCV4 ;
2304 ptcon -> DIRECTION = INTERNAL ;
2305 ptcon -> USER = NULL ;
2306 ptcon -> PNODE = NULL ;
2307 ptself -> SCON2 = ptcon ;
2308
2309 /* No check is done for inductor name unicity */
2310 ptself -> NAME = namealloc(name) ;
2311
2312 if(TRACE_MODE == 'Y')
2313 {
2314 (void)fprintf(stdout,"--- mbk --- addloself : %s\n",type == SELFMIM ? "SELFMIM" : "SELFMIM") ;
2315 }
2316
2317 return ptself ;
2318 }
2319
2320 /*********************************** Inductor : del ********************************************/
2321
delloself(lofig_list * ptfig,loself_list * ptself)2322 int delloself(lofig_list *ptfig,loself_list *ptself)
2323 {
2324 loself_list *pt = NULL ;
2325 loself_list *ptsav = NULL ;
2326
2327 for(pt = ptfig -> LOSELF ; pt != NULL ; pt = pt -> NEXT)
2328 {
2329 if(pt == ptself)
2330 {
2331 break ;
2332 }
2333
2334 ptsav = pt ;
2335 }
2336
2337 if(pt == NULL)
2338 {
2339 return 0 ;
2340 }
2341 else
2342 {
2343 if(pt == ptfig -> LOSELF)
2344 {
2345 ptfig -> LOSELF = pt -> NEXT ;
2346 }
2347 else
2348 {
2349 ptsav -> NEXT = pt -> NEXT ;
2350 }
2351 }
2352
2353 if(pt -> SCON1 -> PNODE)
2354 {
2355 delrcnlocon(pt -> SCON1) ;
2356 }
2357
2358 delloconuser(pt -> SCON1) ;
2359 mbkfree((void *)pt -> SCON1) ;
2360
2361 if(pt -> SCON2 -> PNODE)
2362 {
2363 delrcnlocon(pt -> SCON2) ;
2364 }
2365
2366 delloconuser(pt -> SCON2) ;
2367 mbkfree((void *)pt -> SCON2) ;
2368
2369 delloselfuser(pt) ;
2370 mbkfree((void *)pt) ;
2371
2372 if(TRACE_MODE == 'Y')
2373 {
2374 (void)fprintf(stdout, "--- mbk --- delloself : \n") ;
2375 }
2376
2377 return 1 ;
2378 }
2379
2380 /*********************************** Inductor : getloself ***************************************/
2381
getloself(lofig_list * ptfig,const char * cname)2382 loself_list *getloself(lofig_list *ptfig, const char *cname)
2383 {
2384 loself_list *ptself = NULL ;
2385 char *name = namealloc(cname) ;
2386
2387 for(ptself = ptfig -> LOSELF ; ptself != NULL ; ptself = ptself -> NEXT)
2388 {
2389 if(ptself -> NAME == name)
2390 {
2391 return ptself ;
2392 }
2393 }
2394
2395 (void)fflush(stdout) ;
2396 (void)fprintf(stderr,"*** mbk error ***\n") ;
2397 (void)fprintf(stderr,"getloself impossible :\n") ;
2398 (void)fprintf(stderr,"inductor %s doesn't exist in figure %s\n",name,ptfig -> NAME) ;
2399 EXIT(1) ;
2400
2401 return NULL ; /* never reached */
2402 }
2403
2404 /*********************************** Inductor : setloself **************************************/
2405
setloself(lofig_list * ptfig,const char * cname,double self)2406 void setloself(lofig_list *ptfig, const char *cname,double self)
2407 {
2408 loself_list *ptself = NULL ;
2409 loself_list *theself = NULL ;
2410 char *name = namealloc(cname) ;
2411
2412 for(ptself = ptfig -> LOSELF ; ptself != NULL ; ptself = ptself -> NEXT)
2413 {
2414 if(ptself -> NAME == name)
2415 {
2416 theself = ptself ;
2417 break ;
2418 }
2419 }
2420
2421 if(theself == NULL)
2422 {
2423 (void)fflush(stdout) ;
2424 (void)fprintf(stderr,"*** mbk error ***\n") ;
2425 (void)fprintf(stderr,"setloself impossible :\n") ;
2426 (void)fprintf(stderr,"inductor %s doesn't exist in figure %s\n",name,ptfig -> NAME) ;
2427 EXIT(1) ;
2428 }
2429
2430 theself -> SELF = self ;
2431 }
2432
2433 /*********************************** Inductor : viewloself ***************************************/
2434
viewloself(loself_list * ptself)2435 void viewloself(loself_list *ptself)
2436 {
2437 (void)printf(" |---inductor\n") ;
2438 (void)printf(" | |---type : %s\n",IsSelfMIM(ptself->TYPE)?"MIM":"POLY/NWELL") ;
2439
2440 if(ptself -> NAME != NULL)
2441 {
2442 (void)printf(" | |---name : %s\n", ptself -> NAME) ;
2443 }
2444 else
2445 {
2446 (void)printf(" | |---no name\n") ;
2447 }
2448
2449 if(ptself -> SCON1 == NULL)
2450 {
2451 (void)printf(" | |--- !!! no signal on first connector !!! \n") ;
2452 }
2453 else
2454 {
2455 viewloinscon(ptself -> SCON1) ;
2456 }
2457
2458 if(ptself -> SCON2 == NULL)
2459 {
2460 (void)printf(" | |--- !!! no signal on second connector !!! \n") ;
2461 }
2462 else
2463 {
2464 viewloinscon(ptself -> SCON2) ;
2465 }
2466
2467 (void)printf(" | |---self : %g\n", ptself -> SELF) ;
2468
2469 if(ptself -> USER != NULL)
2470 {
2471 (void)printf(" | |---non empty USER field\n") ;
2472 }
2473
2474 (void)printf(" |\n") ;
2475 }
2476
2477 /*********************************** Inductor : delloselfuser ***********************************/
2478
delloselfuser(loself_list * ptloself)2479 void delloselfuser(loself_list *ptloself)
2480 {
2481 ptype_list *scanptype = NULL ;
2482 ptype_list *next = NULL ;
2483 ptype_list *prev = NULL ;
2484 long del = 0 ;
2485
2486 for(scanptype = ptloself -> USER ; scanptype != NULL ; scanptype = next)
2487 {
2488 next = scanptype -> NEXT ;
2489 del = 0 ;
2490
2491 switch(scanptype -> TYPE)
2492 {
2493 default :
2494 #ifdef MBK_TRACE_BAD_PTYPE
2495 fprintf( stderr, "WARNING in delloconuser() : unknown ptype %ld\n",scanptype -> TYPE) ;
2496 #endif
2497 break;
2498 }
2499
2500 if(del)
2501 {
2502 if(prev == NULL)
2503 {
2504 ptloself -> USER = next ;
2505 }
2506 else
2507 {
2508 prev -> NEXT = next ;
2509 }
2510
2511 scanptype -> NEXT = NULL ;
2512 freeptype(scanptype ) ;
2513 }
2514 else
2515 {
2516 prev = scanptype ;
2517 }
2518 }
2519 }
2520
2521