FreeCalypso > hg > ueda-linux
comparison ueda/unet-utils/unet-destar.c @ 24:7e8a2cb54b6b
started implementing unet-destar
author | Space Falcon <falcon@ivan.Harhan.ORG> |
---|---|
date | Thu, 06 Aug 2015 20:20:11 +0000 |
parents | |
children | b2b60ec8d9ca |
comparison
equal
deleted
inserted
replaced
23:558269596a5c | 24:7e8a2cb54b6b |
---|---|
1 #include <stdio.h> | |
2 #include <stdlib.h> | |
3 #include <string.h> | |
4 #include <strings.h> | |
5 #include <unistd.h> | |
6 #include "../libunet/unetrd.h" | |
7 #include "../libunet/nethash.h" | |
8 | |
9 extern struct net *enter_net_object(); | |
10 extern struct net *find_net_by_name(); | |
11 | |
12 static char *input_filename, *output_filename; | |
13 static struct unetrd_state rdstate; | |
14 static struct unetrd_out rdout; | |
15 static int total_input_nets; | |
16 static struct net *starpoint_head; | |
17 static FILE *tempFILE, *outFILE; | |
18 | |
19 struct netextra { | |
20 struct net *squashed_to; | |
21 int npoints; | |
22 }; | |
23 | |
24 static FILE * | |
25 tempfile() | |
26 { | |
27 char template[16]; | |
28 register int fd; | |
29 register FILE *f; | |
30 | |
31 strcpy(template, "/tmp/uedaXXXXXX"); | |
32 fd = mkstemp(template); | |
33 if (fd < 0) { | |
34 perror("mkstemp"); | |
35 exit(1); | |
36 } | |
37 unlink(template); | |
38 f = fdopen(fd, "r+w"); | |
39 if (!f) { | |
40 perror("fdopen"); | |
41 exit(1); | |
42 } | |
43 return(f); | |
44 } | |
45 | |
46 static void | |
47 dump_tempfile() | |
48 { | |
49 register FILE *inf = tempFILE; | |
50 register FILE *outf = outFILE; | |
51 register int c; | |
52 | |
53 rewind(inf); | |
54 while ((c = getc(inf)) != EOF) | |
55 putc(c, outf); | |
56 fclose(inf); | |
57 } | |
58 | |
59 static void | |
60 process_starpoint_head() | |
61 { | |
62 register struct net *n; | |
63 register struct netextra *nx; | |
64 | |
65 n = find_net_by_name(rdout.connect_to_net); | |
66 for (;;) { | |
67 nx = (struct netextra *)(n + 1); | |
68 if (!nx->squashed_to) | |
69 break; | |
70 n = nx->squashed_to; | |
71 } | |
72 starpoint_head = n; | |
73 } | |
74 | |
75 static void | |
76 process_starpoint_arm() | |
77 { | |
78 register struct net *n; | |
79 register struct netextra *nx; | |
80 | |
81 n = find_net_by_name(rdout.connect_to_net); | |
82 if (n == starpoint_head) { | |
83 fprintf(stderr, | |
84 "%s line %d: starpoint between net %s and itself!\n", | |
85 input_filename, rdstate.lineno, n->name); | |
86 exit(1); | |
87 } | |
88 nx = (struct netextra *)(n + 1); | |
89 if (nx->squashed_to) { | |
90 fprintf(stderr, | |
91 "%s line %d: net %s has already been squashed\n", | |
92 input_filename, rdstate.lineno, n->name); | |
93 exit(1); | |
94 } | |
95 nx->squashed_to = starpoint_head; | |
96 } | |
97 | |
98 static void | |
99 process_starpoint() | |
100 { | |
101 starpoint_head = 0; | |
102 for (;;) { | |
103 if (!read_unet_line(&rdstate, &rdout)) { | |
104 fprintf(stderr, "%s error: EOF in STARPOINT block\n", | |
105 input_filename); | |
106 exit(1); | |
107 } | |
108 if (rdout.typecode == UNETOBJ_CLOSINGBRACE) | |
109 break; | |
110 switch(rdout.typecode) { | |
111 case UNETOBJ_PRIMITIVE: | |
112 case UNETOBJ_ALTNAME: | |
113 continue; | |
114 case UNETOBJ_PIN: | |
115 if (!rdout.connect_to_net) { | |
116 fprintf(stderr, | |
117 "%s line %d: no-connect is meaningless for a starpoint arm\n", | |
118 input_filename, rdstate.lineno); | |
119 exit(1); | |
120 } | |
121 if (!starpoint_head) | |
122 process_starpoint_head(); | |
123 else | |
124 process_starpoint_arm(); | |
125 continue; | |
126 case UNETOBJ_PINMAP: | |
127 fprintf(stderr, | |
128 "%s line %d: PINMAP meaningless in a STARPOINT block\n", | |
129 input_filename, rdstate.lineno); | |
130 exit(1); | |
131 default: | |
132 fprintf(stderr, | |
133 "%s line %d: object type %s unexpected in STARPOINT block\n", | |
134 input_filename, rdstate.lineno, rdout.keyword); | |
135 exit(1); | |
136 } | |
137 } | |
138 } | |
139 | |
140 static void | |
141 process_component_pin() | |
142 { | |
143 register struct net *n; | |
144 register struct netextra *nx; | |
145 | |
146 if (!rdout.connect_to_net) { | |
147 fprintf(tempFILE, " %s %s = NC (%s)\n", rdout.keyword, | |
148 rdout.objname, rdout.nc_comment); | |
149 return; | |
150 } | |
151 n = find_net_by_name(rdout.connect_to_net); | |
152 for (;;) { | |
153 nx = (struct netextra *)(n + 1); | |
154 if (!nx->squashed_to) | |
155 break; | |
156 n = nx->squashed_to; | |
157 } | |
158 fprintf(tempFILE, " %s %s = NET %s\n", rdout.keyword, rdout.objname, | |
159 n->name); | |
160 nx->npoints++; | |
161 } | |
162 | |
163 static void | |
164 process_component() | |
165 { | |
166 fprintf(tempFILE, "\nCOMPONENT %s {\n", rdout.objname); | |
167 for (;;) { | |
168 if (!read_unet_line(&rdstate, &rdout)) { | |
169 fprintf(stderr, "%s error: EOF in COMPONENT block\n", | |
170 input_filename); | |
171 exit(1); | |
172 } | |
173 if (rdout.typecode == UNETOBJ_CLOSINGBRACE) | |
174 break; | |
175 switch(rdout.typecode) { | |
176 case UNETOBJ_PRIMITIVE: | |
177 case UNETOBJ_ALTNAME: | |
178 fprintf(tempFILE, " %s %s\n", rdout.keyword, | |
179 rdout.objname); | |
180 continue; | |
181 case UNETOBJ_PIN: | |
182 case UNETOBJ_PINMAP: | |
183 process_component_pin(); | |
184 continue; | |
185 default: | |
186 fprintf(stderr, | |
187 "%s line %d: object type %s unexpected in COMPONENT block\n", | |
188 input_filename, rdstate.lineno, rdout.keyword); | |
189 exit(1); | |
190 } | |
191 } | |
192 fputs("}\n", tempFILE); | |
193 } | |
194 | |
195 static void | |
196 process_input_unet() | |
197 { | |
198 struct net *n; | |
199 int state = 0; | |
200 | |
201 open_unet_input_file(input_filename, &rdstate); | |
202 while (read_unet_line(&rdstate, &rdout)) { | |
203 switch(rdout.typecode) { | |
204 case UNETOBJ_CLOSINGBRACE: | |
205 fprintf(stderr, | |
206 "%s line %d: unexpected '}' outside of component block\n", | |
207 input_filename, rdstate.lineno); | |
208 exit(1); | |
209 case UNETOBJ_NET: | |
210 if (state == 0) | |
211 state = 1; | |
212 else if (state > 1) { | |
213 fprintf(stderr, | |
214 "error: all input nets must precede all starpoints and components (%s line %d)\n", | |
215 input_filename, rdstate.lineno); | |
216 exit(1); | |
217 } | |
218 n = enter_net_object(rdout.objname, | |
219 sizeof(struct netextra)); | |
220 bzero(n + 1, sizeof(struct netextra)); | |
221 total_input_nets++; | |
222 continue; | |
223 case UNETOBJ_STARPOINT: | |
224 if (state < 1) { | |
225 fprintf(stderr, | |
226 "error (%s line %d): STARPOINT without any preceding NETs\n", | |
227 input_filename, rdstate.lineno); | |
228 exit(1); | |
229 } | |
230 if (state > 2) { | |
231 fprintf(stderr, | |
232 "error: all STARPOINTs must precede all COMPONENTs (%s line %d)\n", | |
233 input_filename, rdstate.lineno); | |
234 exit(1); | |
235 } | |
236 state = 2; | |
237 process_starpoint(); | |
238 continue; | |
239 case UNETOBJ_COMPONENT: | |
240 if (state < 1) { | |
241 fprintf(stderr, | |
242 "error (%s line %d): COMPONENT without any preceding NETs\n", | |
243 input_filename, rdstate.lineno); | |
244 exit(1); | |
245 } | |
246 if (state < 3) { | |
247 tempFILE = tempfile(); | |
248 state = 3; | |
249 } | |
250 process_component(); | |
251 continue; | |
252 default: | |
253 fprintf(stderr, | |
254 "%s line %d: unexpected object type %s\n", | |
255 input_filename, rdstate.lineno, rdout.keyword); | |
256 exit(1); | |
257 } | |
258 } | |
259 } | |
260 | |
261 main(argc, argv) | |
262 char **argv; | |
263 { | |
264 if (argc < 2 || argc > 3) { | |
265 fprintf(stderr, "usage: %s input.unet [output.unet]\n", | |
266 argv[0]); | |
267 exit(1); | |
268 } | |
269 input_filename = argv[1]; | |
270 output_filename = argv[2]; | |
271 process_input_unet(); | |
272 /* output remains to be implemented */ | |
273 exit(0); | |
274 } |