FreeCalypso > hg > ueda-linux
comparison ueda/uschem-utils/checknets.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 * Pseudo-netlist functionality for uschem-check | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include <strings.h> | |
8 #include "../libuschem/schemstruct.h" | |
9 | |
10 extern char *malloc(); | |
11 | |
12 extern struct schem *schem; | |
13 | |
14 struct netname { | |
15 char *name; | |
16 int refcnt; | |
17 struct netexcl *excl; | |
18 struct netname *next; | |
19 }; | |
20 | |
21 struct netexcl { | |
22 char *filename; | |
23 int lineno; | |
24 struct netexcl *next; | |
25 }; | |
26 | |
27 #define HASH_SIZE 1103 | |
28 | |
29 static struct netname *hashtab[HASH_SIZE]; | |
30 | |
31 static int | |
32 hash_netname(str) | |
33 char *str; | |
34 { | |
35 register u_long accum = 0; | |
36 register char *cp; | |
37 register int c, i; | |
38 | |
39 for (cp = str, i = 1; c = *cp; cp++, i++) | |
40 accum += c * i; | |
41 return(accum % HASH_SIZE); | |
42 } | |
43 | |
44 static struct netname * | |
45 get_netname_struct(name) | |
46 register char *name; | |
47 { | |
48 register struct netname *n, **np; | |
49 | |
50 for (np = hashtab + hash_netname(name); n = *np; np = &n->next) | |
51 if (!strcmp(n->name, name)) | |
52 return(n); | |
53 n = (struct netname *) malloc(sizeof(struct netname)); | |
54 if (!n) { | |
55 perror("malloc"); | |
56 exit(1); | |
57 } | |
58 bzero(n, sizeof(struct netname)); | |
59 n->name = name; | |
60 *np = n; | |
61 return(n); | |
62 } | |
63 | |
64 record_netname_reference(netname, excl, filename, lineno) | |
65 char *netname, *filename; | |
66 { | |
67 register struct netname *n; | |
68 register struct netexcl *e; | |
69 | |
70 n = get_netname_struct(netname); | |
71 n->refcnt++; | |
72 if (!excl) | |
73 return; | |
74 e = (struct netexcl *) malloc(sizeof(struct netexcl)); | |
75 if (!e) { | |
76 perror("malloc"); | |
77 exit(1); | |
78 } | |
79 e->filename = filename; | |
80 e->lineno = lineno; | |
81 e->next = n->excl; | |
82 n->excl = e; | |
83 } | |
84 | |
85 static | |
86 get_exclusive_attr(obj, flagp) | |
87 struct schemobj *obj; | |
88 int *flagp; | |
89 { | |
90 register struct decoration *decor; | |
91 register char *val; | |
92 | |
93 for (decor = obj->obj_decorations; decor; decor = decor->decor_next) | |
94 if (decor->decor_type == DECOR_TYPE_ATTR && | |
95 !strcmp(decor->decorattr_name, "exclusive")) | |
96 break; | |
97 if (!decor) | |
98 return(0); | |
99 val = decor->decorattr_value; | |
100 if (!strcmp(val, "yes") || !strcmp(val, "true") || !strcmp(val, "1")) { | |
101 *flagp = 1; | |
102 return(1); | |
103 } | |
104 if (!strcmp(val, "no") || !strcmp(val, "false") || !strcmp(val, "0")) { | |
105 *flagp = 0; | |
106 return(1); | |
107 } | |
108 return(0); | |
109 } | |
110 | |
111 static | |
112 visual_netname_cues(grouphead) | |
113 struct schemobj *grouphead; | |
114 { | |
115 register struct schemobj *obj; | |
116 register struct decoration *decor; | |
117 | |
118 for (obj = grouphead; ; obj = obj->obj_next) { | |
119 if (obj->obj_type != OBJTYPE_GRAPHNET) | |
120 break; | |
121 if (obj->netobj_grouphead != grouphead) | |
122 break; | |
123 if (obj->netobj_forcenets) | |
124 return(1); | |
125 for (decor = obj->obj_decorations; decor; | |
126 decor = decor->decor_next) | |
127 if (decor->decor_type == DECOR_TYPE_DISPLAYNETNAME) | |
128 return(1); | |
129 } | |
130 return(0); | |
131 } | |
132 | |
133 check_exclusive_nets() | |
134 { | |
135 register struct schemobj *obj; | |
136 int isexcl; | |
137 | |
138 for (obj = schem->obj_next; obj != (struct schemobj *)schem; | |
139 obj = obj->obj_next) { | |
140 switch (obj->obj_type) { | |
141 case OBJTYPE_NET: | |
142 if (!obj->netobj_netname) | |
143 continue; | |
144 if (!get_exclusive_attr(obj, &isexcl)) | |
145 isexcl = 0; | |
146 record_netname_reference(obj->netobj_netname, isexcl, | |
147 schem->orig_filename, | |
148 obj->obj_lineno); | |
149 continue; | |
150 case OBJTYPE_GRAPHNET: | |
151 if (obj->netobj_grouphead != obj) | |
152 continue; | |
153 if (!obj->netobj_netname) | |
154 continue; | |
155 if (!get_exclusive_attr(obj, &isexcl)) { | |
156 if (visual_netname_cues(obj)) | |
157 isexcl = 0; | |
158 else | |
159 isexcl = 1; | |
160 } | |
161 record_netname_reference(obj->netobj_netname, isexcl, | |
162 schem->orig_filename, | |
163 obj->obj_lineno); | |
164 continue; | |
165 } | |
166 } | |
167 } | |
168 | |
169 static | |
170 check_netname_for_excl(n) | |
171 struct netname *n; | |
172 { | |
173 register struct netexcl *e; | |
174 | |
175 for (e = n->excl; e; e = e->next) | |
176 fprintf(stderr, | |
177 "Exclusive net %s at %s line %d has other connections\n", | |
178 n->name, e->filename, e->lineno); | |
179 } | |
180 | |
181 report_exclusive_net_violations() | |
182 { | |
183 register struct netname *n, **hb; | |
184 register int i; | |
185 | |
186 for (hb = hashtab, i = 0; i < HASH_SIZE; hb++, i++) | |
187 for (n = *hb; n; n = n->next) | |
188 if (n->refcnt > 1) | |
189 check_netname_for_excl(n); | |
190 } |