FreeCalypso > hg > ueda-linux
comparison ueda/libuschem/pins.c @ 0:cd92449fdb51
initial import of ueda and ifctf-part-lib from ifctfvax CVS
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Mon, 20 Jul 2015 00:24:37 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cd92449fdb51 |
---|---|
1 /* | |
2 * Working with graphical symbol pin instances | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <strings.h> | |
8 #include "schemstruct.h" | |
9 #include "graphsym.h" | |
10 | |
11 extern char *malloc(); | |
12 | |
13 #define HASH_SIZE 1103 | |
14 | |
15 static int | |
16 hash_coord(x, y) | |
17 { | |
18 return((x + y) % HASH_SIZE); | |
19 } | |
20 | |
21 static | |
22 add_pin_to_hash(schem, pin) | |
23 struct schem *schem; | |
24 register struct graphsym_pininst *pin; | |
25 { | |
26 register struct graphsym_pininst *hp, **hpp; | |
27 | |
28 for (hpp = schem->pininst_hash + hash_coord(pin->x, pin->y); hp = *hpp; | |
29 hpp = &hp->nextinhash) | |
30 if (pin->x == hp->x && pin->y == hp->y) { | |
31 fprintf(stderr, | |
32 "%s: more than one pin at (%d,%d), see lines %d and %d\n", | |
33 schem->orig_filename, pin->x, pin->y, | |
34 hp->compinst->obj_lineno, pin->compinst->obj_lineno); | |
35 return(-1); | |
36 } | |
37 *hpp = pin; | |
38 return(0); | |
39 } | |
40 | |
41 static | |
42 instantiate_obj_pins(schem, obj, dohash) | |
43 struct schem *schem; | |
44 register struct schemobj *obj; | |
45 { | |
46 register struct graphsym_pindef *pd; | |
47 register struct graphsym_pininst *pi; | |
48 int npins; | |
49 int x, y; | |
50 int errflag = 0, clashflag = 0; | |
51 | |
52 npins = obj->compobj_graphsym->gs_npins; | |
53 pi = (struct graphsym_pininst *) | |
54 malloc(sizeof(struct graphsym_pininst) * npins); | |
55 if (!pi) { | |
56 perror("malloc"); | |
57 exit(1); | |
58 } | |
59 obj->compobj_pins = pi; | |
60 for (pd = obj->compobj_graphsym->gs_pins; pd; pd = pd->gspd_next, pi++){ | |
61 pi->compinst = obj; | |
62 pi->pindef = pd; | |
63 x = pd->gspd_x; | |
64 y = pd->gspd_y; | |
65 if (obj->compobj_mirror) | |
66 x = -x; | |
67 switch (obj->compobj_rotate) { | |
68 case 0: | |
69 pi->x = x; | |
70 pi->y = y; | |
71 break; | |
72 case 90: | |
73 pi->x = -y; | |
74 pi->y = x; | |
75 break; | |
76 case 180: | |
77 pi->x = -x; | |
78 pi->y = -y; | |
79 break; | |
80 case 270: | |
81 pi->x = y; | |
82 pi->y = -x; | |
83 break; | |
84 default: | |
85 if (!errflag) { | |
86 fprintf(stderr, | |
87 "%s: line %d: symbol rotated by %d deg, can't do pin instances\n", | |
88 schem->orig_filename, obj->obj_lineno, | |
89 obj->compobj_rotate); | |
90 errflag = 1; | |
91 } | |
92 /* a dummy so we don't have to abort */ | |
93 pi->x = pi->y = 0; | |
94 } | |
95 pi->x += obj->compobj_x; | |
96 pi->y += obj->compobj_y; | |
97 pi->nextinhash = NULL; | |
98 if (dohash && !errflag) | |
99 if (add_pin_to_hash(schem, pi)) | |
100 clashflag = 1; | |
101 } | |
102 return(errflag || clashflag); | |
103 } | |
104 | |
105 /* prerequisite: load_graphsyms() */ | |
106 instantiate_graphsym_pins(schem, dohash) | |
107 struct schem *schem; | |
108 { | |
109 register struct schemobj *obj; | |
110 int errstat = 0; | |
111 struct graphsym_pininst **hashtab; | |
112 | |
113 if (dohash) { | |
114 hashtab = (struct graphsym_pininst **) | |
115 malloc(sizeof(struct graphsym_pininst *) * HASH_SIZE); | |
116 if (!hashtab) { | |
117 perror("malloc"); | |
118 exit(1); | |
119 } | |
120 bzero(hashtab, sizeof(struct graphsym_pininst *) * HASH_SIZE); | |
121 schem->pininst_hash = hashtab; | |
122 } | |
123 | |
124 for (obj = schem->obj_next; obj != (struct schemobj *)schem; | |
125 obj = obj->obj_next) | |
126 switch (obj->obj_type) { | |
127 case OBJTYPE_COMPINST: | |
128 if (!obj->compobj_isgraph) | |
129 continue; | |
130 /* FALL THRU */ | |
131 case OBJTYPE_GRAPHSYM: | |
132 if (instantiate_obj_pins(schem, obj, dohash)) | |
133 errstat = -1; | |
134 break; | |
135 } | |
136 return(errstat); | |
137 } | |
138 | |
139 report_pininst_hash_quality(schem) | |
140 struct schem *schem; | |
141 { | |
142 struct graphsym_pininst **hashtab; | |
143 int maxchain, total; | |
144 register int hb, curchain; | |
145 register struct graphsym_pininst *pin; | |
146 | |
147 hashtab = schem->pininst_hash; | |
148 for (hb = 0, total = maxchain = 0; hb < HASH_SIZE; hb++) { | |
149 for (pin = hashtab[hb], curchain = 0; pin; | |
150 pin = pin->nextinhash) { | |
151 curchain++; | |
152 total++; | |
153 } | |
154 if (curchain > maxchain) | |
155 maxchain = curchain; | |
156 } | |
157 printf("%s: %d pin instances total, longest hash chain is %d\n", | |
158 schem->orig_filename, total, maxchain); | |
159 } | |
160 | |
161 struct graphsym_pininst * | |
162 find_comp_pininst(comp, soughtpin, bynum) | |
163 struct schemobj *comp; | |
164 char *soughtpin; | |
165 int bynum; | |
166 { | |
167 int npins; | |
168 register int i; | |
169 register struct graphsym_pininst *pi; | |
170 register char *pinid; | |
171 | |
172 npins = comp->compobj_graphsym->gs_npins; | |
173 for (pi = comp->compobj_pins, i = 0; i < npins; pi++, i++) { | |
174 if (bynum) | |
175 pinid = pi->pindef->gspd_pinnumber; | |
176 else | |
177 pinid = pi->pindef->gspd_pinname; | |
178 if (pinid && !strcmp(pinid, soughtpin)) | |
179 return(pi); | |
180 } | |
181 return(NULL); | |
182 } | |
183 | |
184 struct graphsym_pininst * | |
185 find_pin_by_coord(schem, x, y) | |
186 struct schem *schem; | |
187 register int x, y; | |
188 { | |
189 register struct graphsym_pininst *pin; | |
190 | |
191 for (pin = schem->pininst_hash[hash_coord(x, y)]; pin; | |
192 pin = pin->nextinhash) | |
193 if (pin->x == x && pin->y == y) | |
194 return(pin); | |
195 return(NULL); | |
196 } |