-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathnetlist.c
6673 lines (5674 loc) · 208 KB
/
netlist.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*----------------------------------------------------------------------*/
/* netlist.c --- xcircuit routines specific to schematic capture and */
/* netlist generation */
/*----------------------------------------------------------------------*/
/* Copyright (c) 2004 Tim Edwards, Johns Hopkins University, */
/* MultiGiG, Inc., and Open Circuit Design, Inc. */
/* Copyright (c) 2005 Tim Edwards, MultiGiG, Inc. */
/* */
/* Written April 1998 to January 2004 */
/* Original version for Pcb netlisting 3/20/98 by Chow Seong Hwai, */
/* Leeds University, U.K. */
/* */
/* Greatly modified 4/2/04 to handle bus notation; net identifier */
/* changed from a listing by net to two listings, by polygon and by */
/* label, with nets and subnets identifiers attached to each element, */
/* rather than vice versa. */
/*----------------------------------------------------------------------*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <sys/types.h> /* For preventing multiple file inclusions, use stat() */
#include <sys/stat.h>
#ifndef _MSC_VER
#include <unistd.h>
#endif
#ifdef HAVE_PYTHON
#include <Python.h>
#endif
#ifndef _MSC_VER
#include <X11/Intrinsic.h>
#include <X11/StringDefs.h>
#endif
#ifdef TCL_WRAPPER
#include <tk.h>
#endif
/*----------------------------------------------------------------------*/
/* Local includes */
/*----------------------------------------------------------------------*/
#include "xcircuit.h"
#include "colordefs.h"
/*----------------------------------------------------------------------*/
/* Function prototype declarations */
/*----------------------------------------------------------------------*/
#include "prototypes.h"
#ifdef HAVE_PYTHON
extern PyObject *PyGetStringParts(stringpart *);
#endif
#ifdef TCL_WRAPPER
extern Tcl_Interp *xcinterp;
extern Tcl_Obj *TclGetStringParts(stringpart *);
#endif
/*----------------------------------------------------------------------*/
/* Externally declared global variables */
/*----------------------------------------------------------------------*/
extern Display *dpy;
/*----------------------------------------------------------------------*/
extern char _STR[150];
extern char _STR2[250];
extern XCWindowData *areawin;
extern Globaldata xobjs;
extern Boolean load_in_progress;
extern int number_colors;
extern colorindex *colorlist;
LabellistPtr global_labels;
typedef struct _flatindex *fidxptr;
typedef struct _flatindex {
char *devname;
u_int index;
fidxptr next;
} flatindex; /* count for labeling devices in a flattened file */
flatindex *flatrecord = NULL;
static char *spice_devname = "X"; /* SPICE subcircuit device name */
Boolean spice_end = True; /* whether or not to write a .end statement */
ino_t *included_files = NULL; /* Files included with "%F" escape */
#define EndPoint(n) (((n == 1) ? 1 : (int)(n - 1)))
#define NextPoint(n) (((n == 1) ? 0 : 1))
/* For bus matching: whether to match by number of nets, by */
/* exact match of sub-bus numbers, or an exact match of net IDs. */
#define MATCH_EXACT 0
#define MATCH_SUBNETS 1
#define MATCH_SIZE 2
#define MATCH_OVERLAP 3
/*----------------------------------------------------------------------*/
/* Check whether two line segments attach to or cross each other */
/* Return 1 if attached, 0 if not (INLINE code) */
/* int onsegment(XPoint *a, XPoint *b, XPoint *x) {} */
/*----------------------------------------------------------------------*/
#define ONDIST 4 /* "slack" in algorithm for almost-touching lines */
#define onsegment(a, b, x) (finddist(a, b, x) <= ONDIST)
/*--------------------------------------------------------------*/
/* d36a: Base 36 to string conversion */
/*--------------------------------------------------------------*/
char *d36a(int number)
{
static char bconv[10];
int i, locn, rem;
bconv[9] = '\0';
i = 8;
locn = number;
while ((locn > 0) && (i >= 0)) {
rem = locn % 36;
locn /= 36;
bconv[i--] = (rem < 10) ? (rem + '0') : (rem - 10 + 'A');
}
return &bconv[i + 1];
}
/*--------------------------------------------------------------*/
/* Translate a pin name to a position relative to an object's */
/* point of origin. This is used by the ASG module to find */
/* the placement of pins based on names from a netlist. */
/* */
/* returns 0 on success and fills x_ret and y_ret with the */
/* pin position coordinates. Returns -1 if the pin name did */
/* not match any label names in the object. */
/*--------------------------------------------------------------*/
int NameToPinLocation(objinstptr thisinst, char *pinname, int *x_ret, int *y_ret)
{
objectptr thisobj = thisinst->thisobject;
genericptr *pgen;
labelptr plab;
if (thisobj->schemtype == SECONDARY)
thisobj = thisobj->symschem;
for (pgen = thisobj->plist; pgen < thisobj->plist + thisobj->parts; pgen++) {
if (IS_LABEL(*pgen)) {
plab = TOLABEL(pgen);
if (plab->pin != False && plab->pin != INFO) {
if (!textcomp(plab->string, pinname, thisinst)) {
*x_ret = (int)plab->position.x;
*y_ret = (int)plab->position.y;
return 0;
}
}
}
}
return -1;
}
/*--------------------------------------------------------------*/
/* Translate a point position back to the calling object's */
/* coordinate system. */
/* Original value is passed in "thispoint"; Translated value */
/* is put in "refpoint". */
/*--------------------------------------------------------------*/
void ReferencePosition(objinstptr thisinst, XPoint *thispoint, XPoint *refpoint)
{
/* objectptr thisobj = thisinst->thisobject; (jdk) */
Matrix locctm;
/* Translate pin position back to originating object */
UResetCTM(&locctm);
UPreMultCTM(&locctm, thisinst->position, thisinst->scale,
thisinst->rotation);
UTransformbyCTM(&locctm, thispoint, refpoint, 1);
}
/*--------------------------------------------------------------*/
/* Variant of NameToPinLocation(): Given a port number, find */
/* the pin associated with that port. */
/*--------------------------------------------------------------*/
labelptr PortToLabel(objinstptr thisinst, int portno)
{
labelptr plab;
objectptr thisobj = thisinst->thisobject;
PortlistPtr ports;
if ((thisobj->schemtype == SYMBOL) && (thisobj->symschem != NULL))
ports = thisobj->symschem->ports;
else
ports = thisobj->ports;
for (; ports != NULL; ports = ports->next) {
if (ports->portid == portno) {
plab = NetToLabel(ports->netid, thisobj); /* in the symbol! */
return plab;
}
}
return NULL;
}
/*--------------------------------------------------------------*/
/* This function is the same as PortToLocalPosition() but */
/* returns the point in the coordinate system of the parent. */
/*--------------------------------------------------------------*/
Boolean PortToPosition(objinstptr thisinst, int portno, XPoint *refpoint)
{
labelptr plab = PortToLabel(thisinst, portno);
if (plab)
ReferencePosition(thisinst, &(plab->position), refpoint);
return (plab != NULL) ? TRUE : FALSE;
}
/*----------------------------------------------------------------------*/
/* Get the hierarchy of the page stack and return as a string */
/*----------------------------------------------------------------------*/
Boolean getnexthier(pushlistptr stack, char **hierstr, objinstptr callinst,
Boolean canonical)
{
objectptr topobj, thisobj;
CalllistPtr calls;
/* char numstr[12]; (jdk) */
int hierlen, devlen;
char *devstr;
if (!stack) return False;
/* Recurse so we build up the prefix string from top down */
if (stack->next != NULL) {
if (getnexthier(stack->next, hierstr, stack->thisinst, canonical) == False)
return False;
}
else {
topobj = stack->thisinst->thisobject;
if (topobj->schemtype != PRIMARY && topobj->symschem != NULL)
topobj = topobj->symschem;
if (topobj->calls == NULL) {
if (topobj->schemtype == FUNDAMENTAL) {
/* Top level is a fundamental symbol */
return True;
}
else if ((updatenets(stack->thisinst, FALSE) <= 0) || (topobj->calls == NULL)) {
Wprintf("Error in generating netlists!");
return False;
}
}
}
thisobj = stack->thisinst->thisobject;
/* When we have "traveled" through both a symbol and its */
/* associated schematic, only append the prefix for the */
/* first one encountered. */
/*
if (thisobj->symschem != NULL && stack->next != NULL &&
thisobj->symschem == stack->next->thisinst->thisobject)
return True;
*/
if ((thisobj->calls == NULL) && (thisobj->schemtype != PRIMARY)
&& (thisobj->symschem != NULL))
thisobj = thisobj->symschem;
/* Check for resolved device indices and generate them if necessary */
for (calls = thisobj->calls; calls != NULL; calls = calls->next)
if (calls->callinst == callinst)
if (calls->devindex == -1) {
cleartraversed(thisobj);
resolve_indices(thisobj, FALSE);
break;
}
/* Add this level of the hierarchy to the prefix string */
for (calls = thisobj->calls; calls != NULL; calls = calls->next) {
if (calls->callinst == callinst) {
devlen = (canonical || calls->devname == NULL) ?
strlen(callinst->thisobject->name) : strlen(calls->devname);
devstr = d36a(calls->devindex);
devlen += strlen(devstr) + 1;
if (*hierstr == NULL) {
*hierstr = malloc(devlen);
hierlen = 0;
}
else {
hierlen = strlen(*hierstr) + 2;
*hierstr = realloc(*hierstr, hierlen + devlen);
}
if (canonical)
sprintf(*hierstr + hierlen, "%s%s(%s)",
((hierlen > 0) ? "/" : ""),
callinst->thisobject->name, devstr);
else
sprintf(*hierstr + hierlen, "%s%s%s",
((hierlen > 0) ? "/" : ""),
(calls->devname == NULL) ? callinst->thisobject->name
: calls->devname, devstr);
break;
}
}
return True;
}
/*----------------------------------------------------------------------*/
char *GetHierarchy(pushlistptr *stackptr, Boolean canonical)
{
Boolean pushed_top = FALSE;
char *snew = NULL;
if ((*stackptr) && ((*stackptr)->thisinst != areawin->topinstance)) {
pushed_top = TRUE;
push_stack(stackptr, areawin->topinstance, NULL);
}
getnexthier(*stackptr, &snew, NULL, canonical);
if (pushed_top) pop_stack(stackptr);
return snew;
}
/*----------------------------------------------------------------------*/
/* Invalidate a netlist. The invalidation must be referred to the */
/* master schematic, if the object is a secondary schematic. */
/*----------------------------------------------------------------------*/
void invalidate_netlist(objectptr thisobject)
{
if (thisobject->schemtype != NONETWORK) {
if (thisobject->schemtype == SECONDARY)
thisobject->symschem->valid = False;
else
thisobject->valid = False;
}
}
/*--------------------------------------------------------------*/
/* Check if the selected items are relevant to the netlist. */
/* Only invalidate the current netlist if they are. */
/*--------------------------------------------------------------*/
void select_invalidate_netlist()
{
int i;
Boolean netcheck = FALSE;
for (i = 0; i < areawin->selects; i++) {
genericptr gptr = SELTOGENERIC(areawin->selectlist + i);
switch (gptr->type) {
case POLYGON:
if (!nonnetwork(TOPOLY(&gptr)))
netcheck = TRUE;
break;
case LABEL:
if ((TOLABEL(&gptr))->pin == LOCAL || (TOLABEL(&gptr))->pin == GLOBAL)
netcheck = TRUE;
break;
case OBJINST:
if ((TOOBJINST(&gptr))->thisobject->schemtype != NONETWORK)
netcheck = TRUE;
break;
}
}
if (netcheck) invalidate_netlist(topobject);
}
/*------------------------------------------------------------------*/
/* Check proximity of two points (within roundoff tolerance ONDIST) */
/*------------------------------------------------------------------*/
Boolean proximity(XPoint *point1, XPoint *point2)
{
int dx, dy;
dx = point1->x - point2->x;
dy = point1->y - point2->y;
if ((abs(dx) < ONDIST) && (abs(dy) < ONDIST)) return True;
else return False;
}
/*----------------------------------------------------------------------*/
/* createnets(): Generate netlist structures */
/* */
/* Result is the creation of three linked lists inside each object in */
/* the circuit hierarchy: */
/* */
/* 1) the netlist: assigns a number to each network of polygons and */
/* pin labels on the object. */
/* 2) the ports: a list of every network which is connected from */
/* objects above this one in the hierarchy. */
/* 3) the calls: a list of calls made from the object to all sub- */
/* circuits. Each calls indicates the object and/or */
/* instance being called, and a port list which must match */
/* the ports of the object being called (the port lists */
/* are not reflexive, as the caller does not have to call */
/* all of the instance's ports, but the instance must have */
/* a port defined for every connection being called). */
/* (see structure definitions in xcircuit.h). */
/*----------------------------------------------------------------------*/
void createnets(objinstptr thisinst, Boolean quiet)
{
objectptr thisobject = thisinst->thisobject;
if (!setobjecttype(thisobject)) {
/* New in 3.3.32: Generating a netlist from a symbol is */
/* okay if the symbol has an associated netlist. */
if (thisobject->schemtype == SYMBOL && thisobject->symschem != NULL)
thisobject = thisobject->symschem;
else {
if (!quiet)
Wprintf("Error: attempt to generate netlist for a symbol.");
return;
}
}
/* Wprintf("Generating netlists"); */ /* Diagnostic */
gennetlist(thisinst);
gencalls(thisobject);
cleartraversed(thisobject);
resolve_devnames(thisobject);
/* Wprintf("Finished netlists"); */
}
/*----------------------------------------------------------------------*/
/* Free all memory associated with the netlists. */
/*----------------------------------------------------------------------*/
void destroynets(objectptr thisobject)
{
objectptr pschem;
pschem = (thisobject->schemtype == SECONDARY) ? thisobject->symschem :
thisobject;
freetemplabels(pschem);
freenets(pschem);
freeglobals();
}
/*----------------------------------------------------------------------*/
/* Polygon types which are ignored when considering if a polygon */
/* belongs to a circuit network: */
/* Closed polygons (boxes) */
/* Bounding box polygons */
/* Filled polygons */
/* Dashed and dotted line-style polygons */
/*----------------------------------------------------------------------*/
Boolean nonnetwork(polyptr cpoly)
{
if (!(cpoly->style & UNCLOSED)) return True;
if (cpoly->style & (DASHED | DOTTED | FILLSOLID | BBOX))
return True;
return False;
}
/*----------------------------------------------------------------------*/
/* Return the largest (most negative) net number in the global netlist */
/*----------------------------------------------------------------------*/
int globalmax()
{
LabellistPtr gl;
int bidx, sbus;
buslist *lbus;
int smin = 0;
for (gl = global_labels; gl != NULL; gl = gl->next) {
if (!(gl->subnets)) {
if (gl->net.id < smin)
smin = gl->net.id;
}
else {
for (bidx = 0; bidx < gl->subnets; bidx++) {
lbus = gl->net.list + bidx;
sbus = lbus->netid;
if (sbus < smin)
smin = sbus;
}
}
}
return smin;
}
/*----------------------------------------------------------------------*/
/* Return the largest net number in an object's netlist */
/*----------------------------------------------------------------------*/
int netmax(objectptr cschem)
{
PolylistPtr gp;
LabellistPtr gl;
int bidx, sbus;
buslist *lbus;
int smax = 0;
for (gp = cschem->polygons; gp != NULL; gp = gp->next) {
if (!(gp->subnets)) {
if (gp->net.id > smax)
smax = gp->net.id;
}
else {
for (bidx = 0; bidx < gp->subnets; bidx++) {
lbus = gp->net.list + bidx;
sbus = lbus->netid;
if (sbus > smax)
smax = sbus;
}
}
}
for (gl = cschem->labels; gl != NULL; gl = gl->next) {
if (!(gl->subnets)) {
if (gl->net.id > smax)
smax = gl->net.id;
}
else {
for (bidx = 0; bidx < gl->subnets; bidx++) {
lbus = gl->net.list + bidx;
sbus = lbus->netid;
if (sbus > smax)
smax = sbus;
}
}
}
return smax;
}
/*----------------------------------------------------------------------*/
/* Resolve nets and pins for the indicated object */
/* */
/* When encountering object instances, call gennetlist() on the object */
/* if it does not have a valid netlist, then recursively call */
/* gennetlist(). Ignore "info" labels, which are not part of the */
/* network. */
/* */
/*----------------------------------------------------------------------*/
void gennetlist(objinstptr thisinst)
{
genericptr *cgen;
labelptr olabel, clab;
polyptr cpoly, tpoly;
objectptr thisobject, callobj, cschem, pschem;
objinstptr cinst, labinst;
int old_parts; /* netid, tmpid, sub_bus, (jdk) */
stringpart *cstr;
Boolean visited;
XPoint *tpt, *tpt2, *endpt, *endpt2;
int i, j, n, nextnet, lbus;
buslist *sbus;
PolylistPtr plist;
LabellistPtr lseek;
Genericlist *netlist, *tmplist, *buspins, *resolved_net, newlist;
newlist.subnets = 0;
newlist.net.id = -1;
/* Determine the type of object being netlisted */
thisobject = thisinst->thisobject;
setobjecttype(thisobject);
if (thisobject->schemtype == NONETWORK) return;
/* Has this object been visited before? */
visited = ((thisobject->labels != NULL) || (thisobject->polygons != NULL)) ?
TRUE : FALSE;
if (!visited && (thisobject->schemtype == SYMBOL)
&& (thisobject->symschem != NULL)) {
/* Make sure that schematics are netlisted before their symbols */
if ((thisobject->symschem->polygons == NULL) &&
(thisobject->symschem->labels == NULL)) {
n = is_page(thisobject->symschem);
if (n == -1) {
Fprintf(stderr, "Error: associated schematic is not a page!\n");
return;
}
else
gennetlist(xobjs.pagelist[n]->pageinst);
}
/* Sanity check on symbols with schematics: Are there any pins? */
for (i = 0; i < thisobject->parts; i++) {
cgen = thisobject->plist + i;
if (IS_LABEL(*cgen)) {
clab = TOLABEL(cgen);
if (clab->pin != False && clab->pin != INFO)
break;
}
}
if (i == thisobject->parts)
/* Don't warn if schematic has infolabels */
if (thisobject->symschem == NULL || thisobject->symschem->infolabels == 0)
Fprintf(stderr, "Warning: Symbol %s has no pins!\n", thisobject->name);
}
/* If this is a secondary schematic, run on the primary (master) */
pschem = (thisobject->schemtype == SECONDARY) ? thisobject->symschem :
thisobject;
nextnet = netmax(pschem) + 1;
/* We start the loop for schematics but will modify the loop */
/* variable to execute just once in the case of a symbol. */
/* It's just not worth the trouble to turn this into a */
/* separate subroutine. . . */
for (j = 0; j < xobjs.pages; j++) {
if (pschem->schemtype != PRIMARY) {
j = xobjs.pages;
cinst = thisinst;
cschem = thisobject;
}
else {
cinst = xobjs.pagelist[j]->pageinst;
if ((cinst == NULL) ||
((cinst->thisobject != pschem) &&
((cinst->thisobject->schemtype != SECONDARY) ||
(cinst->thisobject->symschem != pschem)))) continue;
cschem = cinst->thisobject;
}
/* Determine the existing number of parts. We do not want to */
/* search over elements that we create in this routine. */
old_parts = cschem->parts;
/* Part 1: Recursion */
/* Schematic pages and symbols acting as their own schematics are the */
/* two types on which we recurse to find all sub-schematics. */
if ((!visited) && (cschem->schemtype == PRIMARY ||
cschem->schemtype == SECONDARY ||
(cschem->schemtype == SYMBOL && cschem->symschem == NULL))) {
for (i = 0; i < old_parts; i++) {
cgen = cschem->plist + i;
if (IS_OBJINST(*cgen)) {
objinstptr geninst, callinst;
geninst = TOOBJINST(cgen);
if (geninst->thisobject->symschem != NULL) {
callobj = geninst->thisobject->symschem;
n = is_page(callobj);
if (n == -1) {
Fprintf(stderr, "Error: associated schematic is not a page!\n");
continue;
}
else
callinst = xobjs.pagelist[n]->pageinst;
}
else {
callobj = geninst->thisobject;
callinst = geninst;
}
/* object on its own schematic */
if (callobj == pschem) continue;
gennetlist(callinst);
/* Also generate netlist for pins in the corresponding symbol */
if (geninst->thisobject->symschem != NULL)
gennetlist(geninst);
}
}
}
/* Part 2: Match pin labels to nets, and add to list of globals */
/* if appropriate. We do all pins first, before ennumerating */
/* polygons, so that buses can be handled correctly, generating */
/* overlapping subnets. */
for (i = 0; i < old_parts; i++) {
cgen = cschem->plist + i;
if (IS_LABEL(*cgen)) {
clab = TOLABEL(cgen);
if (clab->pin != False && clab->pin != INFO) {
/* Check if the label has a non-default parameter. */
/* If so, we want to record the instance along */
/* the other netlist information about the pin. */
labinst = NULL;
for (cstr = clab->string; cstr != NULL; cstr = cstr->nextpart)
if (cstr->type == PARAM_START)
if (match_instance_param(cinst, cstr->data.string) != NULL) {
labinst = cinst;
break;
}
/* If we have netlisted this object before, and the */
/* label is already in the netlist, then ignore it. */
/* This only happens for labels without instanced */
/* parameter values. */
if (visited && (labinst == NULL)) {
for (lseek = pschem->labels; lseek != NULL; lseek = lseek->next)
if ((lseek->label == clab) && (lseek->cinst == NULL))
break;
if (lseek != NULL) continue;
}
else if (visited)
netlist = NULL;
else
/* Note any overlapping labels. */
netlist = pointtonet(cschem, cinst, &clab->position);
if (pschem->symschem != NULL && pschem->schemtype == SYMBOL) {
/* For symbols: Check that this pin has a */
/* corresponding pin in the schematic. The schematic */
/* is netlisted before the symbol, so the netlist */
/* should be there. */
tmplist = pintonet(pschem->symschem, cinst, clab);
/* There is always the possibility that the symbol */
/* pin does not correspond to anything in the */
/* schematic. If so, it gets its own unique net */
/* number. HOWEVER, this situation usually indicates */
/* an error in the schematic, so output a warning */
/* message. */
if (tmplist == NULL) {
char *snew = NULL;
snew = textprint(clab->string, NULL),
Fprintf(stderr, "Warning: Pin \"%s\" in symbol %s has no "
"connection in schematic %s\n",
snew, pschem->name,
pschem->symschem->name);
free(snew);
newlist.net.id = nextnet++;
tmplist = &newlist;
}
}
else {
/* For schematics: Relate the pin to a network */
tmplist = pintonet(pschem, cinst, clab);
/* If only part of a bus has been identified, generate */
/* the net ID's of the parts that haven't been. */
if ((tmplist != NULL) && (tmplist->subnets > 0)) {
for (lbus = 0; lbus < tmplist->subnets; lbus++) {
sbus = tmplist->net.list + lbus;
if (sbus->netid == 0)
sbus->netid = nextnet++;
}
}
}
if (clab->pin == LOCAL) {
if (tmplist != NULL) {
addpin(cschem, labinst, clab, tmplist);
if (netlist != NULL)
mergenets(pschem, netlist, tmplist);
}
else {
if (netlist == NULL) {
netlist = &newlist;
netlist->net.id = nextnet++;
buspins = break_up_bus(clab, cinst, netlist);
if (buspins != NULL) {
buslist *sbus = buspins->net.list + buspins->subnets - 1;
nextnet = sbus->netid + 1;
netlist = addpin(cschem, labinst, clab, buspins);
}
else {
tmplist = addpin(cschem, labinst, clab, netlist);
netlist = tmplist;
}
}
else {
tmplist = addpin(cschem, labinst, clab, netlist);
netlist = tmplist;
}
}
}
else if (clab->pin == GLOBAL) {
if (tmplist == NULL) {
tmplist = &newlist;
tmplist->net.id = globalmax() - 1;
}
addglobalpin(cschem, cinst, clab, tmplist);
addpin(cschem, labinst, clab, tmplist);
if (netlist != NULL)
mergenets(pschem, netlist, tmplist);
}
}
else if (clab->pin == INFO) {
/* Note the presence of info labels in the */
/* subcircuit, indicating that it needs to be */
/* called because it will generate output. */
cschem->infolabels = TRUE;
}
}
}
/* Part 3: Polygon enumeration */
/* Assign network numbers to all polygons in the object. */
/* (Ignore symbols, as we only consider pins on symbols) */
/* Where multiple pins occur at a point (bus notation), */
/* polygons will be duplicated in each network. */
if ((!visited) && (cschem->schemtype == PRIMARY ||
cschem->schemtype == SECONDARY ||
(cschem->schemtype == SYMBOL && cschem->symschem == NULL))) {
for (i = 0; i < old_parts; i++) {
cgen = cschem->plist + i;
if (IS_POLYGON(*cgen)) {
cpoly = TOPOLY(cgen);
/* Ignore non-network (closed, bbox, filled) polygons */
if (nonnetwork(cpoly)) continue;
resolved_net = (Genericlist *)NULL;
/* Check for attachment of each segment of this polygon */
/* to position of every recorded pin label. */
for (lseek = pschem->labels; lseek != NULL; lseek = lseek->next) {
if (lseek->cschem != cschem) continue;
else if ((lseek->cinst != NULL) && (lseek->cinst != cinst))
continue;
olabel = lseek->label;
tmplist = (Genericlist *)lseek;
for (endpt = cpoly->points; endpt < cpoly->points
+ EndPoint(cpoly->number); endpt++) {
endpt2 = endpt + NextPoint(cpoly->number);
if (onsegment(endpt, endpt2, &olabel->position)) {
if (resolved_net != NULL) {
if (mergenets(pschem, resolved_net, tmplist))
resolved_net = tmplist;
}
if (resolved_net == NULL) {
addpoly(cschem, cpoly, tmplist);
resolved_net = tmplist;
}
}
}
/* if we've encountered a unique instance, then con- */
/* tinue past all other instances using this label. */
if (lseek->cinst != NULL)
while (lseek->next && (lseek->next->label == lseek->label))
lseek = lseek->next;
}
/* Check for attachment of each segment of this polygon */
/* to endpoints of every recorded network polygon. */
for (plist = pschem->polygons; plist != NULL; plist = plist->next) {
if (plist->cschem != cschem) continue;
else if ((tpoly = plist->poly) == cpoly) continue;
tpt = tpoly->points;
tpt2 = tpoly->points + tpoly->number - 1;
tmplist = (Genericlist *)plist;
for (endpt = cpoly->points; endpt < cpoly->points
+ EndPoint(cpoly->number); endpt++) {
endpt2 = endpt + NextPoint(cpoly->number);
if (onsegment(endpt, endpt2, tpt) ||
onsegment(endpt, endpt2, tpt2)) {
/* Nets previously counted distinct have */
/* been connected together by this polygon. */
if (resolved_net != NULL) {
if (mergenets(pschem, resolved_net, tmplist))
resolved_net = tmplist;
}
if (resolved_net == NULL) {
addpoly(cschem, cpoly, tmplist);
resolved_net = tmplist;
}
}
}
/* Check for attachment of the endpoints of this polygon */
/* to each segment of every recorded network polygon. */
endpt = cpoly->points;
endpt2 = cpoly->points + cpoly->number - 1;
for (tpt = tpoly->points; tpt < tpoly->points
+ EndPoint(tpoly->number); tpt++) {
tpt2 = tpt + NextPoint(tpoly->number);
if (onsegment(tpt, tpt2, endpt) ||
onsegment(tpt, tpt2, endpt2)) {
/* Nets previously counted distinct have */
/* been connected together by this polygon. */
if (resolved_net != 0) {
if (mergenets(pschem, resolved_net, tmplist))
resolved_net = tmplist;
}
if (resolved_net == 0) {
addpoly(cschem, cpoly, tmplist);
resolved_net = tmplist;
}
}
}
}
if (resolved_net == 0) {
/* This polygon belongs to an unvisited */
/* network. Give this polygon a new net */
/* number and add to the net list. */
newlist.net.id = nextnet++;
addpoly(cschem, cpoly, &newlist);
}
}
}
}
}
}
/*--------------------------------------------------------------*/
/* Search a sibling of object instance "cinst" for connections */
/* between the two. Recurse through the schematic hierarchy of */
/* the sibling object. */
/*--------------------------------------------------------------*/
void search_on_siblings(objinstptr cinst, objinstptr isib, pushlistptr schemtop,
short llx, short lly, short urx, short ury)
{
XPoint *tmppts, sbbox[2];
int i;
labelptr olabel;
polyptr tpoly;
PolylistPtr pseek;
LabellistPtr lseek;
genericptr *iseek;
objinstptr subsibinst;
pushlistptr psearch, newlist;
objectptr sibling = isib->thisobject;
tmppts = (XPoint *)malloc(sizeof(XPoint));
/* If the sibling is a symbol or fundamental or trivial object, then */
/* we just look at pin labels from the parts list and return. */
if (sibling->symschem != NULL || sibling->schemtype == FUNDAMENTAL
|| sibling->schemtype == TRIVIAL) {
for (lseek = sibling->labels; lseek != NULL; lseek = lseek->next) {
olabel = lseek->label;
tmppts = (XPoint *)realloc(tmppts, sizeof(XPoint));
UTransformPoints(&(olabel->position), tmppts, 1,
isib->position, isib->scale, isib->rotation);
/* Transform all the way up to the level above cinst */
for (psearch = schemtop; psearch != NULL; psearch = psearch->next) {
subsibinst = psearch->thisinst;
UTransformPoints(tmppts, tmppts, 1, subsibinst->position,
subsibinst->scale, subsibinst->rotation);
}
searchconnect(tmppts, 1, cinst, lseek->subnets);
}
}
/* If the sibling is a schematic, we look at connections to pins and */
/* polygons, and recursively search subschematics of the sibling. */
else {