1 | /* |
---|
2 | |
---|
3 | Copyright (c) 1992, 1993 |
---|
4 | Regents of the University of California |
---|
5 | All rights reserved. |
---|
6 | |
---|
7 | Use and copying of this software and preparation of derivative works |
---|
8 | based upon this software are permitted. However, any distribution of |
---|
9 | this software or derivative works must include the above copyright |
---|
10 | notice. |
---|
11 | |
---|
12 | This software is made available AS IS, and neither the Electronics |
---|
13 | Research Laboratory or the Universify of California make any |
---|
14 | warranty about the software, its performance or its conformity to |
---|
15 | any specification. |
---|
16 | |
---|
17 | Author: Szu-Tsung Cheng, stcheng@ic.Berkeley.EDU |
---|
18 | 10/92 |
---|
19 | 10/93 |
---|
20 | |
---|
21 | $Header: /projects/development/hsv/CVSRepository/vl2mv/src/parser/vl_reset.c,v 1.2 2009/03/09 20:25:58 fabio Exp $ |
---|
22 | |
---|
23 | |
---|
24 | */ |
---|
25 | |
---|
26 | #include <stdio.h> |
---|
27 | #include <math.h> |
---|
28 | #include "util.h" |
---|
29 | #include "array.h" |
---|
30 | #include "list.h" |
---|
31 | #include "st.h" |
---|
32 | #include "set.h" |
---|
33 | #include "vl_types.h" |
---|
34 | #include "vl_defs.h" |
---|
35 | #include "vlr_int.h" |
---|
36 | #include "vl_fg_defs.h" |
---|
37 | #include "vl_create.h" |
---|
38 | #include "vl_write.h" |
---|
39 | #include "vl_write_util.h" |
---|
40 | #include "vl_vardecl.h" |
---|
41 | |
---|
42 | extern int set_notation; |
---|
43 | extern int smartEvent; |
---|
44 | extern int vis_nond; |
---|
45 | |
---|
46 | static void warn_uninit_vars ARGS((char *latch_name)); |
---|
47 | |
---|
48 | void reset_mvar_latch(FILE *file, int non_block_var, vl_id_range *id_sym, |
---|
49 | int lo, int hi, char *lname) |
---|
50 | { |
---|
51 | int dummy; |
---|
52 | int idx, idx_lo, idx_hi; |
---|
53 | lsList domain; |
---|
54 | lsGen enum_gen; |
---|
55 | lsHandle enum_handle; |
---|
56 | vl_enumerator *enum_elt; |
---|
57 | vl_id_range *comb_id_sym; |
---|
58 | char latch_name[MAXSTRLEN]; |
---|
59 | |
---|
60 | if (st_lookup(vl_currentModule->combVar_st, lname, (char**)&comb_id_sym)) |
---|
61 | return; |
---|
62 | |
---|
63 | domain = id_sym->id_type->specifier->u.enum_type->domain_list; |
---|
64 | if (!(id_sym->range)) { |
---|
65 | if (non_block_var) sel_var(lname); |
---|
66 | strip_char(lname, SEP_SEL_VAR); |
---|
67 | sprintf(latch_name, lname); |
---|
68 | if (st_lookup(vl_currentModule->quasi_st,lname,(char**)&dummy)) { |
---|
69 | strcat(latch_name, SEP_GATEPIN); |
---|
70 | strcat(latch_name, PIN_PS); |
---|
71 | } |
---|
72 | |
---|
73 | |
---|
74 | if (lsLength(id_sym->initial) > 0) { |
---|
75 | int i; |
---|
76 | vl_term *init_term; |
---|
77 | lsGen gen; |
---|
78 | lsHandle handle; |
---|
79 | |
---|
80 | fprintf(file, ".r "); |
---|
81 | for (gen=lsStart(id_sym->initial), i=0; |
---|
82 | lsNext(gen, (lsGeneric*)&init_term, &handle)!=LS_NOMORE; |
---|
83 | i++) |
---|
84 | fprintf(file, "%s ", init_term->name->name); |
---|
85 | lsFinish(gen); |
---|
86 | fprintf(file, "%s", latch_name); |
---|
87 | } else |
---|
88 | fprintf(file, ".r %s", latch_name); |
---|
89 | fprintf(file, "\n"); |
---|
90 | if (lsLength(id_sym->initial) == 0) |
---|
91 | if (vis_nond) |
---|
92 | warn_uninit_vars(lname); |
---|
93 | if (set_notation) { |
---|
94 | if (lsLength(id_sym->initial) > 0) { |
---|
95 | int i; |
---|
96 | vl_term *init_term; |
---|
97 | for (i=0; i<lsLength(id_sym->initial); i++) |
---|
98 | fprintf(file, "- "); |
---|
99 | lsLastItem(id_sym->initial, (lsGeneric*)&init_term, 0); |
---|
100 | fprintf(file, "%s%s\n", |
---|
101 | HSIS_EQUAL, init_term->name->name); |
---|
102 | } else { |
---|
103 | fprintf(file, "-\n"); |
---|
104 | } |
---|
105 | } else { |
---|
106 | for (enum_gen=lsStart(domain); |
---|
107 | lsNext(enum_gen,(lsGeneric*)&enum_elt,&enum_handle)!= |
---|
108 | LS_NOMORE;) |
---|
109 | if (lsLength(id_sym->initial) > 0) |
---|
110 | fprintf(file,"%s %s\n",enum_elt->name,enum_elt->name); |
---|
111 | else |
---|
112 | fprintf(file, "%s\n", enum_elt->name); |
---|
113 | lsFinish(enum_gen); |
---|
114 | } |
---|
115 | } else { |
---|
116 | idx_lo = vl_eval_expr(id_sym->range->left); |
---|
117 | if (id_sym->range->right) |
---|
118 | idx_hi = |
---|
119 | vl_eval_expr(id_sym->range->right); |
---|
120 | else |
---|
121 | idx_hi = idx_lo; |
---|
122 | |
---|
123 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
124 | |
---|
125 | if (lsLength(id_sym->initial) > 0) { |
---|
126 | int i; |
---|
127 | vl_term *init_term; |
---|
128 | lsGen gen; |
---|
129 | lsHandle handle; |
---|
130 | fprintf(file, ".r "); |
---|
131 | for (gen=lsStart(id_sym->initial), i=0; |
---|
132 | lsNext(gen, (lsGeneric*)&init_term, &handle) != |
---|
133 | LS_NOMORE; |
---|
134 | i++) |
---|
135 | fprintf(file, "%s%s%d%s ", |
---|
136 | init_term->name->name, |
---|
137 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
138 | lsFinish(gen); |
---|
139 | fprintf(file, "%s%s%d%s", |
---|
140 | non_block_var?sel_var(lname):lname, |
---|
141 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
142 | } else { |
---|
143 | fprintf(file, ".r %s%s%d%s", |
---|
144 | non_block_var? |
---|
145 | sel_var(lname):lname, |
---|
146 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
147 | } |
---|
148 | strip_char(lname,SEP_SEL_VAR); |
---|
149 | if (st_lookup(vl_currentModule->quasi_st,lname,(char**)&dummy)) |
---|
150 | fprintf(file, "%s%s", SEP_GATEPIN, PIN_PS); |
---|
151 | fprintf(file, "\n"); |
---|
152 | if (lsLength(id_sym->initial) == 0) |
---|
153 | if (vis_nond) |
---|
154 | warn_uninit_vars(lname); |
---|
155 | if (set_notation) { |
---|
156 | if (lsLength(id_sym->initial)>0) { |
---|
157 | int i, j, k; |
---|
158 | vl_term *init_term; |
---|
159 | vl_enumerator *first_enum; |
---|
160 | lsGen gen; |
---|
161 | lsHandle handle; |
---|
162 | lsFirstItem(domain, (lsGeneric*)&first_enum, 0); |
---|
163 | fprintf(file, "%s %s\n", HSIS_DEFAULT, |
---|
164 | first_enum->name); |
---|
165 | for (gen=lsStart(id_sym->initial), j=0; |
---|
166 | lsNext(gen, (lsGeneric*)&init_term, &handle) != |
---|
167 | LS_NOMORE; j++) { |
---|
168 | for (enum_gen=lsEnd(domain), i=0; |
---|
169 | lsPrev(enum_gen, (lsGeneric*)&enum_elt, |
---|
170 | &enum_handle) != LS_NOMORE && |
---|
171 | i < lsLength(domain)-1; i++) { |
---|
172 | for (k=0; k<j; k++) |
---|
173 | fprintf(file, "%s ", first_enum->name); |
---|
174 | fprintf(file, "%s ", enum_elt->name); |
---|
175 | k++; |
---|
176 | for (; k<lsLength(id_sym->initial); k++) |
---|
177 | fprintf(file, "- "); |
---|
178 | fprintf(file, "%s%s%s%d%s\n", |
---|
179 | HSIS_EQUAL, init_term->name->name, |
---|
180 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
181 | } |
---|
182 | lsFinish(enum_gen); |
---|
183 | } |
---|
184 | lsFinish(gen); |
---|
185 | } else { |
---|
186 | fprintf(file, "-\n"); |
---|
187 | } |
---|
188 | } else { |
---|
189 | for (enum_gen=lsStart(domain); |
---|
190 | lsNext(enum_gen, |
---|
191 | (lsGeneric*)&enum_elt,&enum_handle)!= |
---|
192 | LS_NOMORE;) |
---|
193 | if (lsLength(id_sym->initial) > 0) { |
---|
194 | int i; |
---|
195 | for (i=0; i<lsLength(id_sym->initial)-1; i++) |
---|
196 | fprintf(file, "- "); |
---|
197 | fprintf(file, "%s %s\n", |
---|
198 | enum_elt->name, enum_elt->name); |
---|
199 | } else |
---|
200 | fprintf(file, "%s\n", enum_elt->name); |
---|
201 | lsFinish(enum_gen); |
---|
202 | } |
---|
203 | } |
---|
204 | } |
---|
205 | |
---|
206 | |
---|
207 | lo = lo; |
---|
208 | hi = hi; |
---|
209 | } |
---|
210 | |
---|
211 | |
---|
212 | void reset_bin_scalar_latch(FILE *file, int non_block_var, |
---|
213 | vl_id_range *id_sym, char *lname) |
---|
214 | { |
---|
215 | int dummy; |
---|
216 | int idx, idx_lo, idx_hi; |
---|
217 | vl_id_range *comb_id_sym; |
---|
218 | char latch_name[MAXSTRLEN]; |
---|
219 | |
---|
220 | if (st_lookup(vl_currentModule->combVar_st, lname, (char**)&comb_id_sym)) |
---|
221 | return; |
---|
222 | |
---|
223 | if (lsLength(id_sym->initial) == 0) |
---|
224 | if (vis_nond) |
---|
225 | warn_uninit_vars(lname); |
---|
226 | if (!id_sym->range) { |
---|
227 | if (non_block_var) sel_var(lname); |
---|
228 | strip_char(lname,SEP_SEL_VAR); |
---|
229 | sprintf(latch_name, "%s", lname); |
---|
230 | if (st_lookup(vl_currentModule->quasi_st,lname,(char**)&dummy)) { |
---|
231 | strcat(latch_name,SEP_GATEPIN); |
---|
232 | strcat(latch_name,PIN_PS); |
---|
233 | } |
---|
234 | |
---|
235 | if (lsLength(id_sym->initial)>0) { |
---|
236 | vl_term *init_term; |
---|
237 | lsLastItem(id_sym->initial, (lsGeneric*)&init_term, 0); |
---|
238 | fprintf(file, ".r %s %s\n0 0\n1 1\n", |
---|
239 | init_term->name->name, latch_name); |
---|
240 | } else if ((id_sym->flags & EventVar) && !smartEvent) { |
---|
241 | fprintf(file, ".r %s%s%s\n0\n", |
---|
242 | latch_name,SEP_GATEPIN,PIN_EVENT); |
---|
243 | } else if ((id_sym->flags & EventVar) && smartEvent) { |
---|
244 | } else { |
---|
245 | |
---|
246 | fprintf(file, ".r %s\n0\n1\n", latch_name); |
---|
247 | } |
---|
248 | } else { |
---|
249 | idx_lo = vl_eval_expr(id_sym->range->left); |
---|
250 | if (id_sym->range->right) |
---|
251 | idx_hi = |
---|
252 | vl_eval_expr(id_sym->range->right); |
---|
253 | else |
---|
254 | idx_hi = idx_lo; |
---|
255 | |
---|
256 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
257 | |
---|
258 | if (lsLength(id_sym->initial) > 0) { |
---|
259 | vl_term *init_term; |
---|
260 | lsGen gen; |
---|
261 | lsHandle handle; |
---|
262 | fprintf(file, ".r "); |
---|
263 | for (gen=lsStart(id_sym->initial); |
---|
264 | lsNext(gen, (lsGeneric*)&init_term, &handle) |
---|
265 | != LS_NOMORE; ) |
---|
266 | fprintf(file, "%s%s%d%s ", |
---|
267 | init_term->name->name, |
---|
268 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
269 | lsFinish(gen); |
---|
270 | fprintf(file, "%s%s%d%s", |
---|
271 | non_block_var?sel_var(lname):lname, |
---|
272 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
273 | } else |
---|
274 | fprintf(file, ".r %s%s%d%s", |
---|
275 | non_block_var? |
---|
276 | sel_var(lname):lname, |
---|
277 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
278 | strip_char(lname,SEP_SEL_VAR); |
---|
279 | if (st_lookup(vl_currentModule->quasi_st,lname,(char**)&dummy)) |
---|
280 | fprintf(file, "%s%s", SEP_GATEPIN, PIN_PS); |
---|
281 | fprintf(file, "\n"); |
---|
282 | if (lsLength(id_sym->initial) > 0) { |
---|
283 | int i, j; |
---|
284 | fprintf(file, "%s 0\n", HSIS_DEFAULT); |
---|
285 | for (i=0; i<lsLength(id_sym->initial); i++) { |
---|
286 | for (j=0; j<lsLength(id_sym->initial); j++) |
---|
287 | fprintf(file, "%c ", (i==j)?'1':'0'); |
---|
288 | fprintf(file, "1\n"); |
---|
289 | } |
---|
290 | } else |
---|
291 | fprintf(file, "0\n1\n"); |
---|
292 | } |
---|
293 | } |
---|
294 | } |
---|
295 | |
---|
296 | |
---|
297 | void reset_bin_vector_latch(FILE *file, int non_block_var, |
---|
298 | vl_id_range *id_sym, |
---|
299 | int lo, int hi, char *lname) |
---|
300 | { |
---|
301 | int i=0; |
---|
302 | int idx, idx_lo, idx_hi; |
---|
303 | vl_id_range *comb_id_sym; |
---|
304 | int dummy; |
---|
305 | extern int combinationalReduction; |
---|
306 | |
---|
307 | if (st_lookup(vl_currentModule->combVar_st, lname, (char**)&comb_id_sym)) |
---|
308 | return; |
---|
309 | |
---|
310 | if (lsLength(id_sym->initial) == 0) |
---|
311 | if (vis_nond) |
---|
312 | warn_uninit_vars(lname); |
---|
313 | |
---|
314 | if (id_sym->syndrome_expr_list) |
---|
315 | if (lsLength(id_sym->syndrome_expr_list) == 0) |
---|
316 | if (id_sym->rst_syndrome_expr_list) |
---|
317 | if (lsLength(id_sym->rst_syndrome_expr_list) == 0) |
---|
318 | if (combinationalReduction) |
---|
319 | return; |
---|
320 | |
---|
321 | for (i=lo; i<=hi; i++) { |
---|
322 | if (!id_sym->range) { |
---|
323 | |
---|
324 | if (lsLength(id_sym->initial) > 0) { |
---|
325 | int k; |
---|
326 | vl_term *init_term; |
---|
327 | lsGen gen; |
---|
328 | lsHandle handle; |
---|
329 | fprintf(file, ".r "); |
---|
330 | for (gen=lsStart(id_sym->initial), k=0; |
---|
331 | lsNext(gen, (lsGeneric*)&init_term, &handle) |
---|
332 | != LS_NOMORE; k++) { |
---|
333 | fprintf(file, "%s%s%d%s ", init_term->name->name, |
---|
334 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
335 | } |
---|
336 | lsFinish(gen); |
---|
337 | fprintf(file, "%s%s%d%s", |
---|
338 | non_block_var?sel_var(lname):lname, |
---|
339 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
340 | |
---|
341 | } else { |
---|
342 | fprintf(file, ".r %s%s%d%s", |
---|
343 | non_block_var? |
---|
344 | sel_var(lname):lname, |
---|
345 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
346 | } |
---|
347 | strip_char(lname,SEP_SEL_VAR); |
---|
348 | if (st_lookup(vl_currentModule->quasi_st, |
---|
349 | lname,(char**)&dummy)) |
---|
350 | fprintf(file, "%s%s", SEP_GATEPIN, PIN_PS); |
---|
351 | fprintf(file, "\n"); |
---|
352 | if (set_notation) { |
---|
353 | if (lsLength(id_sym->initial) > 0) { |
---|
354 | int i, j; |
---|
355 | fprintf(file, "%s 0\n", HSIS_DEFAULT); |
---|
356 | for (i=0; i<lsLength(id_sym->initial); i++) { |
---|
357 | for (j=0; j<lsLength(id_sym->initial); j++) |
---|
358 | fprintf(file, "%c ", (i==j)?'1':'-'); |
---|
359 | fprintf(file, "1\n"); |
---|
360 | } |
---|
361 | } else { |
---|
362 | fprintf(file, "-\n"); |
---|
363 | } |
---|
364 | } else { |
---|
365 | if (lsLength(id_sym->initial) > 0) { |
---|
366 | int i, j; |
---|
367 | for (i=0; i<lsLength(id_sym->initial); i++) { |
---|
368 | for (j=0; j<lsLength(id_sym->initial); j++) |
---|
369 | fprintf(file, "%c ", (i==j)?'1':'-'); |
---|
370 | fprintf(file, "1\n"); |
---|
371 | } |
---|
372 | for (i=0; i<lsLength(id_sym->initial); i++) |
---|
373 | fprintf(file, "0 "); |
---|
374 | fprintf(file, "0\n"); |
---|
375 | } else { |
---|
376 | fprintf(file, "0\n1\n"); |
---|
377 | } |
---|
378 | } |
---|
379 | } else { |
---|
380 | idx_lo = vl_eval_expr(id_sym->range->left); |
---|
381 | if (id_sym->range->right) |
---|
382 | idx_hi = vl_eval_expr(id_sym->range->right); |
---|
383 | else |
---|
384 | idx_hi = idx_lo; |
---|
385 | |
---|
386 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
387 | |
---|
388 | if (lsLength(id_sym->initial) > 0) { |
---|
389 | int k; |
---|
390 | vl_term *init_term; |
---|
391 | lsGen gen; |
---|
392 | lsHandle handle; |
---|
393 | fprintf(file, ".r "); |
---|
394 | for (gen=lsStart(id_sym->initial), k=0; |
---|
395 | lsNext(gen,(lsGeneric*)&init_term,&handle) |
---|
396 | != LS_NOMORE; k++) { |
---|
397 | fprintf(file, "%s%s%d%s%s%d%s ", |
---|
398 | init_term->name->name, |
---|
399 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
400 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
401 | } |
---|
402 | lsFinish(gen); |
---|
403 | fprintf(file, "%s%s%d%s%s%d%s", |
---|
404 | non_block_var?sel_var(lname):lname, |
---|
405 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
406 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
407 | } else |
---|
408 | fprintf(file, ".r %s%s%d%s%s%d%s", |
---|
409 | non_block_var? |
---|
410 | sel_var(lname):lname, |
---|
411 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
412 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
413 | strip_char(lname,SEP_SEL_VAR); |
---|
414 | if (st_lookup(vl_currentModule->quasi_st, |
---|
415 | lname,(char**)&dummy)) |
---|
416 | fprintf(file, "%s%s", SEP_GATEPIN, PIN_PS); |
---|
417 | fprintf(file, "\n"); |
---|
418 | if (set_notation) { |
---|
419 | if (lsLength(id_sym->initial) > 0) { |
---|
420 | int i, j; |
---|
421 | fprintf(file, "%s 0\n", HSIS_DEFAULT); |
---|
422 | for (i=0; i<lsLength(id_sym->initial); i++) { |
---|
423 | for (j=0; j<lsLength(id_sym->initial); j++) |
---|
424 | fprintf(file, "%c ", (i==j)?'1':'-'); |
---|
425 | fprintf(file, "1\n"); |
---|
426 | } |
---|
427 | } else { |
---|
428 | fprintf(file, "-\n"); |
---|
429 | } |
---|
430 | } else { |
---|
431 | if (lsLength(id_sym->initial) > 0) { |
---|
432 | int i, j; |
---|
433 | for (i=0; i<lsLength(id_sym->initial); i++) { |
---|
434 | for (j=0; j<lsLength(id_sym->initial); j++) |
---|
435 | fprintf(file, "%c ", (i==j)?'1':'-'); |
---|
436 | fprintf(file, "1\n"); |
---|
437 | } |
---|
438 | for (i=0; i<lsLength(id_sym->initial); i++) |
---|
439 | fprintf(file, "0 "); |
---|
440 | fprintf(file, "0\n"); |
---|
441 | } else |
---|
442 | fprintf(file,"0\n1\n"); |
---|
443 | } |
---|
444 | } |
---|
445 | } |
---|
446 | } |
---|
447 | } |
---|
448 | |
---|
449 | |
---|
450 | static void warn_uninit_vars(char *latch_name) |
---|
451 | { |
---|
452 | char buf[MAXSTRLEN]; |
---|
453 | |
---|
454 | sprintf(buf, "'%s': variable '%s' is uninitialized", |
---|
455 | vl_currentModule->name->name, latch_name); |
---|
456 | yylineno = -1; |
---|
457 | fprintf(stderr, "%s, be careful\n", buf); |
---|
458 | } |
---|