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_write_util.c,v 1.3 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 "st.h" |
---|
30 | #include "array.h" |
---|
31 | #include "list.h" |
---|
32 | #include "set.h" |
---|
33 | #include "graph.h" |
---|
34 | #include "vl_types.h" |
---|
35 | #include "vl_defs.h" |
---|
36 | #include "vlr_int.h" |
---|
37 | #include "vl_fg_defs.h" |
---|
38 | #include "vl_fg_types.h" |
---|
39 | #include "vl_create.h" |
---|
40 | #include "vl_write.h" |
---|
41 | #include "vl_write_util.h" |
---|
42 | #include "vl_vardecl.h" |
---|
43 | #include "vl_edgedetector.h" |
---|
44 | #include "vl_traverse.h" |
---|
45 | #include "vl_mux.h" |
---|
46 | #include "vl_flowgraph.h" |
---|
47 | #include "verilog.h" |
---|
48 | |
---|
49 | extern vl_desc *mod_list; |
---|
50 | extern int implicitClocking; |
---|
51 | extern int compatibleChecking; |
---|
52 | extern int set_notation; |
---|
53 | extern int debug_mode; |
---|
54 | extern int decomposeTable; |
---|
55 | extern int noBus; |
---|
56 | extern int smartEvent; |
---|
57 | extern int vlTimedSystem; |
---|
58 | extern int Zconnection; |
---|
59 | extern int implicitDeclare; |
---|
60 | |
---|
61 | extern int WarningLevel; |
---|
62 | |
---|
63 | extern int rst_ckt, use_rst_ckt, mark_sel_var; |
---|
64 | extern lsList ctrl_list, rst_ctrl_list; |
---|
65 | extern st_table *sensitiveList; |
---|
66 | extern int lhs_hi, lhs_lo; |
---|
67 | extern int lhs_must_be_wire; |
---|
68 | extern int Vlerrno; |
---|
69 | extern int silent_err; |
---|
70 | extern char *cntxt_event; |
---|
71 | |
---|
72 | int deadlock_semantic = 0; |
---|
73 | int arrayBoundNond=0; |
---|
74 | int vis_nond=1; |
---|
75 | int vis_nond_var=0; |
---|
76 | int instantiateInputLatch = 0; |
---|
77 | |
---|
78 | static char *nond_output(); |
---|
79 | static int isTautology ARGS((lsList syndrome_expr_list)); |
---|
80 | static void postprocess_vlr_rel ARGS((FILE *file, short type, char *carry, |
---|
81 | vl_term *results, vl_term *out)); |
---|
82 | static int evaluable_expr ARGS((vl_expr *expr)); |
---|
83 | static void vl_write_bin_equal_const(FILE *file, vl_expr *val, vl_term *term, vl_term *out); |
---|
84 | |
---|
85 | void vl_mv_to_bin(vl_term *term) |
---|
86 | { |
---|
87 | if (term->flag & MVar) { |
---|
88 | char buf[MAXSTRLEN]; |
---|
89 | sprintf(buf, "enforced mv->binary encoding on '%s'", term->name->name); |
---|
90 | Translate_Warning(buf); |
---|
91 | |
---|
92 | term->flag &= !MVar; |
---|
93 | if (term->hi < 0) { |
---|
94 | term->hi = MAXBITNUM-1; |
---|
95 | term->lo = 0; |
---|
96 | } else { |
---|
97 | int range, blen; |
---|
98 | |
---|
99 | for (range = term->hi - term->lo + 1, blen = -1; |
---|
100 | range>0; range >>= 1) |
---|
101 | blen++; |
---|
102 | if (blen>0) |
---|
103 | if ((1<<(blen-1)) < term->hi-term->lo+1) |
---|
104 | blen++; |
---|
105 | term->lo = 0; |
---|
106 | term->hi = blen-1; |
---|
107 | } |
---|
108 | } |
---|
109 | } |
---|
110 | |
---|
111 | |
---|
112 | |
---|
113 | void vl_bin_to_mv(vl_term *term) |
---|
114 | { |
---|
115 | int blen; |
---|
116 | |
---|
117 | if (!(term->flag & MVar)) { |
---|
118 | Translate_Warning("enforced binary->mv encoding"); |
---|
119 | |
---|
120 | term->flag |= MVar; |
---|
121 | blen = term->hi-term->lo+1; |
---|
122 | term->lo = 1; |
---|
123 | term->hi = (1 << (blen)); |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | |
---|
128 | void vl_write_mv_comp(FILE *file, short type, vl_term *in1, vl_term *in2, vl_term *out) |
---|
129 | { |
---|
130 | lsList domain; |
---|
131 | lsGen igen, jgen; |
---|
132 | lsHandle ihandle, jhandle; |
---|
133 | vl_enumerator *i, *j; |
---|
134 | |
---|
135 | if (in1->hi-in1->lo != in2->hi-in2->lo) |
---|
136 | Translate_Warning("comparator have MV's of different domain elts"); |
---|
137 | |
---|
138 | fprintf(file, ".names %s %s %s\n", |
---|
139 | in1->name->name, in2->name->name, out->name->name); |
---|
140 | if (set_notation) { |
---|
141 | if (in1->term_type != in2->term_type) { |
---|
142 | char buf[MAXSTRLEN]; |
---|
143 | sprintf(buf, "'%s':comparing %s and %s of different domains", |
---|
144 | vl_currentModule->name->name, |
---|
145 | in1->name->name, in2->name->name); |
---|
146 | semantic_error(buf); |
---|
147 | } |
---|
148 | |
---|
149 | fprintf(file, "%s %d\n", HSIS_DEFAULT, type==Bneq2Expr); |
---|
150 | fprintf(file, "- %s%s %d\n", |
---|
151 | HSIS_EQUAL, in1->name->name, type!=Bneq2Expr); |
---|
152 | |
---|
153 | } else { |
---|
154 | switch (type) { |
---|
155 | case Beq2Expr: |
---|
156 | |
---|
157 | if (in1->term_type != in2->term_type) { |
---|
158 | char buf[MAXSTRLEN]; |
---|
159 | sprintf(buf, "'%s':comparing %s and %s of different domains", |
---|
160 | vl_currentModule->name->name, |
---|
161 | in1->name->name, in2->name->name); |
---|
162 | semantic_error(buf); |
---|
163 | } |
---|
164 | |
---|
165 | domain = in1->term_type->specifier->u.enum_type->domain_list; |
---|
166 | for (igen=lsStart(domain); |
---|
167 | lsNext(igen,(lsGeneric*)&i,&ihandle)!=LS_NOMORE;) { |
---|
168 | for (jgen=lsStart(domain); |
---|
169 | lsNext(jgen,(lsGeneric*)&j,&jhandle)!=LS_NOMORE;) { |
---|
170 | fprintf(file, "%s %s %d\n", |
---|
171 | i->name, j->name, (strcmp(i->name, j->name)==0)); |
---|
172 | } |
---|
173 | lsFinish(jgen); |
---|
174 | } |
---|
175 | lsFinish(igen); |
---|
176 | break; |
---|
177 | case Bneq2Expr: |
---|
178 | |
---|
179 | if (in1->term_type != in2->term_type) { |
---|
180 | char buf[MAXSTRLEN]; |
---|
181 | sprintf(buf, "'%s':comparing %s and %s of different domains", |
---|
182 | vl_currentModule->name->name, |
---|
183 | in1->name->name, in2->name->name); |
---|
184 | semantic_error(buf); |
---|
185 | } |
---|
186 | |
---|
187 | domain = in1->term_type->specifier->u.enum_type->domain_list; |
---|
188 | for (igen=lsStart(domain); |
---|
189 | lsNext(igen,(lsGeneric*)&i,&ihandle)!=LS_NOMORE;) { |
---|
190 | for (jgen=lsStart(domain); |
---|
191 | lsNext(jgen,(lsGeneric*)&j,&jhandle)!=LS_NOMORE;) { |
---|
192 | fprintf(file, "%s %s %d\n", |
---|
193 | i->name, j->name, (strcmp(i->name, j->name)!=0)); |
---|
194 | } |
---|
195 | lsFinish(jgen); |
---|
196 | } |
---|
197 | lsFinish(igen); |
---|
198 | break; |
---|
199 | } |
---|
200 | } |
---|
201 | } |
---|
202 | |
---|
203 | |
---|
204 | void vl_write_bin_comp(FILE *file, short type, vl_term *in1, vl_term *in2, vl_term *out) |
---|
205 | { |
---|
206 | vl_term *tmp, *ripple_term; |
---|
207 | char *ripple; |
---|
208 | |
---|
209 | tmp = new_term(NIL(vl_range), 0, -1); |
---|
210 | |
---|
211 | if (in1->lo > in1->hi) { |
---|
212 | tmp->lo = in2->lo; |
---|
213 | tmp->hi = in2->hi; |
---|
214 | } else if (in2->lo > in2->hi) { |
---|
215 | tmp->lo = in1->lo; |
---|
216 | tmp->hi = in1->hi; |
---|
217 | } else { |
---|
218 | tmp->lo = 0; |
---|
219 | tmp->hi = MIN(in1->hi-in1->lo, in2->hi-in2->lo); |
---|
220 | } |
---|
221 | write_var_decl(file, tmp); |
---|
222 | vl_write_vector_bop(file, BxorExpr, in1, in2, tmp); |
---|
223 | |
---|
224 | ripple = vlStrdup(new_termname()); |
---|
225 | ripple_term = vl_create_term(vl_create_id_range(ripple,NIL(vl_range)), |
---|
226 | tmp->lo, tmp->hi); |
---|
227 | if (tmp->lo <= tmp->hi) { |
---|
228 | ripple = |
---|
229 | vl_write_vector_bop(file, UorExpr, tmp, NIL(vl_term), ripple_term); |
---|
230 | vl_write_bit_connect(file, ripple_term->name->name, out->name->name, |
---|
231 | (type==Beq2Expr)); |
---|
232 | vl_free_term(ripple_term); |
---|
233 | } else { |
---|
234 | vl_write_bit_connect(file, tmp->name->name, out->name->name, |
---|
235 | (type==Beq2Expr)); |
---|
236 | } |
---|
237 | vl_free_term(tmp); |
---|
238 | } |
---|
239 | |
---|
240 | |
---|
241 | static void vl_write_bin_equal_const( |
---|
242 | FILE *file, |
---|
243 | vl_expr *val, |
---|
244 | vl_term *term, |
---|
245 | vl_term *out |
---|
246 | ) |
---|
247 | { |
---|
248 | int lo, hi; |
---|
249 | int i, v; |
---|
250 | |
---|
251 | if (term->lo > term->hi) { |
---|
252 | lo = 0; |
---|
253 | hi = 0; |
---|
254 | } else { |
---|
255 | lo = term->lo; |
---|
256 | hi = term->hi; |
---|
257 | } |
---|
258 | |
---|
259 | /* Write table header and default value. */ |
---|
260 | fprintf(file, ".names"); |
---|
261 | for (i=lo; i<=hi; i++) { |
---|
262 | fprintf(file, " %s%s%d%s", term->name->name, |
---|
263 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
264 | } |
---|
265 | fprintf(file, " %s\n.def 0\n", out->name->name); |
---|
266 | |
---|
267 | for (i=lo, v=vl_eval_expr(val); i<=hi; i++, v >>= 1) { |
---|
268 | fprintf(file, "%d ", (v & 1)); |
---|
269 | } |
---|
270 | fprintf(file, " 1\n"); |
---|
271 | } |
---|
272 | |
---|
273 | |
---|
274 | void vl_write_mv_connect(FILE *file, vl_term *in, vl_term *out) |
---|
275 | { |
---|
276 | lsList domain; |
---|
277 | lsGen enum_gen; |
---|
278 | lsHandle enum_handle; |
---|
279 | vl_enumerator *enum_elt; |
---|
280 | |
---|
281 | if (in->term_type != out->term_type) { |
---|
282 | char buf[MAXSTRLEN]; |
---|
283 | sprintf(buf, "connecting %s and %s of different domains", |
---|
284 | out->name->name, in->name->name); |
---|
285 | semantic_error(buf); |
---|
286 | } |
---|
287 | |
---|
288 | fprintf(file, ".names %s %s\n", in->name->name, out->name->name); |
---|
289 | |
---|
290 | if (set_notation) { |
---|
291 | fprintf(file, "- =%s\n", in->name->name); |
---|
292 | } else { |
---|
293 | domain = in->term_type->specifier->u.enum_type->domain_list; |
---|
294 | for (enum_gen=lsStart(domain); |
---|
295 | lsNext(enum_gen,(lsGeneric*)&enum_elt,&enum_handle)!=LS_NOMORE;) { |
---|
296 | fprintf(file, "%s %s\n", enum_elt->name, enum_elt->name); |
---|
297 | } |
---|
298 | lsFinish(enum_gen); |
---|
299 | } |
---|
300 | } |
---|
301 | |
---|
302 | |
---|
303 | void vl_write_bin_connect(FILE *file, vl_term *in, vl_term *out, int inverted) |
---|
304 | { |
---|
305 | int i; |
---|
306 | char out_buf[MAXSTRLEN], in_buf[MAXSTRLEN]; |
---|
307 | |
---|
308 | if (out->lo > out->hi) { |
---|
309 | if (in->lo > in->hi) { |
---|
310 | vl_write_bit_connect(file, in->name->name, out->name->name, 0); |
---|
311 | } else { |
---|
312 | char buf[MAXSTRLEN]; |
---|
313 | |
---|
314 | sprintf(buf, "%s%s%d%s", in->name->name, |
---|
315 | SEP_LBITSELECT, in->lo, SEP_RBITSELECT); |
---|
316 | vl_write_bit_connect(file, buf, out->name->name, 0); |
---|
317 | } |
---|
318 | } else { |
---|
319 | if (in->lo > in->hi) { |
---|
320 | int i; |
---|
321 | sprintf(out_buf, "%s%s%d%s", out->name->name, |
---|
322 | SEP_LBITSELECT, out->lo, SEP_RBITSELECT); |
---|
323 | sprintf(in_buf, "%s", in->name->name); |
---|
324 | if (set_notation && !inverted) { |
---|
325 | fprintf(file, ".names %s %s\n- =%s\n", |
---|
326 | in_buf, out_buf, in_buf); |
---|
327 | |
---|
328 | } else { |
---|
329 | vl_write_bit_connect(file, in_buf, out_buf, inverted); |
---|
330 | } |
---|
331 | |
---|
332 | sprintf(in_buf, "%s", WRT_BLIF_GND(file)); |
---|
333 | for (i=out->lo+1; i<=out->hi; i++) { |
---|
334 | sprintf(out_buf, "%s%s%d%s", out->name->name, |
---|
335 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
336 | if (set_notation) { |
---|
337 | fprintf(file, ".names %s %s\n- =%s\n", |
---|
338 | in_buf, out_buf, in_buf); |
---|
339 | } else { |
---|
340 | vl_write_bit_connect(file, in_buf, out_buf, 0); |
---|
341 | } |
---|
342 | } |
---|
343 | } else { |
---|
344 | for (i=out->lo; i<=out->hi; i++) { |
---|
345 | sprintf(out_buf, "%s%s%d%s", out->name->name, |
---|
346 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
347 | sprintf(in_buf, "%s%s%d%s", in->name->name, |
---|
348 | SEP_LBITSELECT, i+in->lo-out->lo, |
---|
349 | SEP_RBITSELECT); |
---|
350 | if (set_notation && !inverted) { |
---|
351 | fprintf(file, ".names %s %s\n- =%s\n", |
---|
352 | in_buf, out_buf, in_buf); |
---|
353 | } else { |
---|
354 | vl_write_bit_connect(file, in_buf, out_buf, |
---|
355 | inverted); |
---|
356 | } |
---|
357 | } |
---|
358 | } |
---|
359 | } |
---|
360 | } |
---|
361 | |
---|
362 | |
---|
363 | void vl_write_consts(FILE *file) |
---|
364 | { |
---|
365 | |
---|
366 | |
---|
367 | file = file; |
---|
368 | } |
---|
369 | |
---|
370 | |
---|
371 | void vl_write_const(FILE *file, vl_expr *val, vl_term *out) |
---|
372 | { |
---|
373 | int ismvar=0; |
---|
374 | int i, v; |
---|
375 | int lo, hi; |
---|
376 | int find_elt=0; |
---|
377 | char buf[MAXSTRLEN]; |
---|
378 | lsList domain; |
---|
379 | lsGen enum_gen; |
---|
380 | lsHandle enum_handle; |
---|
381 | vl_enumerator *enum_elt; |
---|
382 | |
---|
383 | ismvar = out->flag & MVar; |
---|
384 | |
---|
385 | if (ismvar) { |
---|
386 | assert (val); |
---|
387 | |
---|
388 | fprintf(file, ".names %s\n", out->name->name); |
---|
389 | switch(val->type) { |
---|
390 | case BitExpr: |
---|
391 | Translate_Warning("Using binary constant as value of mv variable"); |
---|
392 | case IntExpr: |
---|
393 | domain = out->term_type->specifier->u.enum_type->domain_list; |
---|
394 | for (enum_gen=lsStart(domain); |
---|
395 | lsNext(enum_gen, |
---|
396 | (lsGeneric*)&enum_elt,&enum_handle)!=LS_NOMORE;) { |
---|
397 | find_elt=1; |
---|
398 | if (enum_elt->val==val->u.intval) break; |
---|
399 | find_elt=0; |
---|
400 | } |
---|
401 | lsFinish(enum_gen); |
---|
402 | |
---|
403 | if (find_elt) |
---|
404 | fprintf(file, "%s\n", enum_elt->name); |
---|
405 | else { |
---|
406 | char buf[MAXSTRLEN]; |
---|
407 | sprintf(buf, "trying to assign to '%s' out of its domain", |
---|
408 | out->name->name); |
---|
409 | semantic_error(buf); |
---|
410 | } |
---|
411 | break; |
---|
412 | case RealExpr: |
---|
413 | semantic_error("assinging real value to enumeration typed var"); |
---|
414 | break; |
---|
415 | case IDExpr: |
---|
416 | if (st_lookup(out->term_type->specifier->u.enum_type->domain_st, |
---|
417 | val->u.name->name, (char**)&enum_elt)) { |
---|
418 | fprintf(file, "%s\n", enum_elt->name); |
---|
419 | } else { |
---|
420 | char buf[MAXSTRLEN]; |
---|
421 | |
---|
422 | sprintf(buf, "%s should be a constant/symbolic name", |
---|
423 | val->u.name->name); |
---|
424 | internal_error(buf); |
---|
425 | } |
---|
426 | break; |
---|
427 | } |
---|
428 | } else { |
---|
429 | |
---|
430 | if (out->name->mpg_master_exp && out->hi==-1 && out->lo==0) |
---|
431 | |
---|
432 | get_hilo(out->name, &hi, &lo); |
---|
433 | else { |
---|
434 | |
---|
435 | hi = out->hi; |
---|
436 | lo = out->lo; |
---|
437 | } |
---|
438 | if (val) { |
---|
439 | if (lo <= hi) { |
---|
440 | int v0; |
---|
441 | v0 = val->u.bexpr.part0; |
---|
442 | for (i=lo, v=vl_eval_expr(val); i<=hi; |
---|
443 | i++, v >>= 1, v0 >>= 1) { |
---|
444 | sprintf(buf, "%s%s%d%s", out->name->name, |
---|
445 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
446 | fprintf(file, ".names %s\n", buf); |
---|
447 | if ((v & 1) && (v0 & 1)) |
---|
448 | fprintf(file, "-\n"); |
---|
449 | else |
---|
450 | fprintf(file, "%d\n", (v & 1)); |
---|
451 | } |
---|
452 | } else { |
---|
453 | fprintf(file, ".names %s\n", out->name->name); |
---|
454 | fprintf(file, "%d\n", vl_eval_expr(val) & 1); |
---|
455 | } |
---|
456 | } else { |
---|
457 | if (lo <= hi) { |
---|
458 | for (i=lo; i<=hi; i++) { |
---|
459 | sprintf(buf, "%s%s%d%s", out->name->name, |
---|
460 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
461 | fprintf(file, ".names %s\n", buf); |
---|
462 | fprintf(file, "0\n1\n"); |
---|
463 | } |
---|
464 | } else { |
---|
465 | fprintf(file, ".names %s\n", out->name->name); |
---|
466 | fprintf(file, "0\n1\n"); |
---|
467 | } |
---|
468 | } |
---|
469 | } |
---|
470 | } |
---|
471 | |
---|
472 | |
---|
473 | |
---|
474 | void write_int_connect(FILE *file, int v, vl_term *out) |
---|
475 | { |
---|
476 | int lo, hi, i; |
---|
477 | char buf[MAXSTRLEN]; |
---|
478 | lsList args; |
---|
479 | |
---|
480 | lo = out->lo; hi = out->hi; |
---|
481 | if (hi < lo) { |
---|
482 | fprintf(file, ".names %s\n", out->name->name); |
---|
483 | fprintf(file, "%d\n", (v&1)); |
---|
484 | } else { |
---|
485 | args = lsCreate(); |
---|
486 | sprintf(buf, "%d", out->hi-out->lo+1); |
---|
487 | lsNewEnd(args, (lsGeneric)vlStrdup(buf), 0); |
---|
488 | sprintf(buf, "%d", v); |
---|
489 | lsNewEnd(args, (lsGeneric)vlStrdup(buf), 0); |
---|
490 | |
---|
491 | for (i=lo; i<=hi; i++, v >>= 1) { |
---|
492 | sprintf(buf, "%s%s%d%s", out->name->name, |
---|
493 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
494 | fprintf(file, ".names %s\n", buf); |
---|
495 | fprintf(file, "%d\n", (v & 1)); |
---|
496 | } |
---|
497 | |
---|
498 | lsDestroy(args, vl_chk_free); |
---|
499 | } |
---|
500 | } |
---|
501 | |
---|
502 | |
---|
503 | |
---|
504 | vl_term *write_local_control(FILE *file, vl_term *ctrl, lsList sub_ctrls, int inverted) |
---|
505 | { |
---|
506 | int i, j; |
---|
507 | vl_term *retval; |
---|
508 | lsGen gen; |
---|
509 | lsHandle handle; |
---|
510 | vl_term *sub_ctrl; |
---|
511 | int unconditional_assign = 0; |
---|
512 | |
---|
513 | |
---|
514 | |
---|
515 | |
---|
516 | if (!sub_ctrls) |
---|
517 | unconditional_assign = 1; |
---|
518 | else if (lsLength(sub_ctrls)==0) |
---|
519 | unconditional_assign = 1; |
---|
520 | |
---|
521 | if (unconditional_assign) { |
---|
522 | retval = new_term(NIL(vl_range), 0, -1); |
---|
523 | vl_write_bit_connect(file, ctrl->name->name, retval->name->name, |
---|
524 | inverted); |
---|
525 | return retval; |
---|
526 | } |
---|
527 | |
---|
528 | retval = new_term(NIL(vl_range), 0, -1); |
---|
529 | |
---|
530 | fprintf(file, ".names %s ", ctrl->name->name); |
---|
531 | gen = lsStart(sub_ctrls); |
---|
532 | if (lsNext(gen, (lsGeneric*)&sub_ctrl, &handle) == LS_OK) { |
---|
533 | fprintf(file, "%s ", ((vl_term*)(((int)sub_ctrl)&~1))->name->name); |
---|
534 | while (lsNext(gen, (lsGeneric*)&sub_ctrl, &handle) != LS_NOMORE) { |
---|
535 | fprintf(file, "%s ", ((vl_term*)(((int)sub_ctrl)&~1))->name->name); |
---|
536 | } |
---|
537 | } |
---|
538 | lsFinish(gen); |
---|
539 | fprintf(file, "%s\n", retval->name->name); |
---|
540 | |
---|
541 | for (i=0; i<lsLength(sub_ctrls); i++) { |
---|
542 | fprintf(file, "%c ", (inverted)?'0':'1'); |
---|
543 | for (j=0; j<lsLength(sub_ctrls); j++) { |
---|
544 | fprintf(file, "%c ", (i==j)?'1':'-'); |
---|
545 | } |
---|
546 | fprintf(file, "1\n"); |
---|
547 | } |
---|
548 | |
---|
549 | fprintf(file, "%c ", (inverted)?'0':'1'); |
---|
550 | gen = lsStart(sub_ctrls); |
---|
551 | if (lsNext(gen, (lsGeneric*)&sub_ctrl, &handle) == LS_OK) { |
---|
552 | fprintf(file, "%c ", ((int)sub_ctrl&1)?'1':'0'); |
---|
553 | while (lsNext(gen, (lsGeneric*)&sub_ctrl, &handle) != LS_NOMORE) { |
---|
554 | fprintf(file, "%c ", ((int)sub_ctrl&1)?'1':'0'); |
---|
555 | } |
---|
556 | } |
---|
557 | lsFinish(gen); |
---|
558 | fprintf(file, "0\n"); |
---|
559 | |
---|
560 | fprintf(file, "%c ", (inverted)?'1':'0'); |
---|
561 | for (i=0; i<lsLength(sub_ctrls); i++) { |
---|
562 | fprintf(file, "%c ", '-'); |
---|
563 | } |
---|
564 | fprintf(file, "0\n"); |
---|
565 | |
---|
566 | return retval; |
---|
567 | } |
---|
568 | |
---|
569 | |
---|
570 | |
---|
571 | void write_switch(FILE *file, vl_id_range *id_sym, |
---|
572 | vl_term *sel, vl_expr *sel_expr, |
---|
573 | vl_term *orig, vl_term *new, vl_term *out_term) |
---|
574 | { |
---|
575 | int lo, hi; |
---|
576 | int bit_hi, bit_lo; |
---|
577 | int idx; |
---|
578 | vl_expr *hi_expr; |
---|
579 | char new_buf[MAXSTRLEN], orig_buf[MAXSTRLEN], out_buf[MAXSTRLEN]; |
---|
580 | |
---|
581 | get_hilo(id_sym, &bit_hi, &bit_lo); |
---|
582 | |
---|
583 | lo = vl_eval_expr(out_term->name->range->left); |
---|
584 | if (out_term->name->range->right) |
---|
585 | hi = vl_eval_expr(out_term->name->range->right); |
---|
586 | else |
---|
587 | hi = lo; |
---|
588 | |
---|
589 | if (!sel) { |
---|
590 | int const_hi, const_lo; |
---|
591 | |
---|
592 | assert(ISVLCONST(sel_expr->type)); |
---|
593 | |
---|
594 | const_hi = min_bit_width(hi)-1; |
---|
595 | const_lo = 0; |
---|
596 | sel = new_term(NIL(vl_range), const_lo, const_hi); |
---|
597 | write_var_decl(file, sel); |
---|
598 | vl_write_const(file, sel_expr, sel); |
---|
599 | } |
---|
600 | |
---|
601 | hi_expr = vl_create_expr(IntExpr, hi, (double)0.0, |
---|
602 | NIL(void), NIL(void), NIL(void)); |
---|
603 | for (idx=lo; idx<=hi; idx++) { |
---|
604 | vl_term *ctrl; |
---|
605 | vl_term *new_elt, *orig_elt, *out_elt; |
---|
606 | vl_expr *const_expr; |
---|
607 | vl_term *const_trm; |
---|
608 | |
---|
609 | const_expr = vl_create_expr(IntExpr, idx, (double)0.0, |
---|
610 | NIL(void), NIL(void), NIL(void)); |
---|
611 | const_trm = new_term(NIL(vl_range), 0, data_width(hi_expr)-1); |
---|
612 | #if 0 |
---|
613 | write_var_decl(file, const_trm); |
---|
614 | vl_write_const(file, const_expr, const_trm); |
---|
615 | vl_chk_free((char*)const_expr); |
---|
616 | |
---|
617 | ctrl = new_term(NIL(vl_range), 0, -1); |
---|
618 | vl_write_bin_comp(file, Beq2Expr, const_trm, sel, ctrl); |
---|
619 | #else |
---|
620 | ctrl = new_term(NIL(vl_range), 0, -1); |
---|
621 | vl_write_bin_equal_const(file, const_expr, sel, ctrl); |
---|
622 | vl_chk_free((char*)const_expr); |
---|
623 | #endif |
---|
624 | sprintf(new_buf, "%s%s%d%s", |
---|
625 | new->name->name, SEP_LARRAY, idx, SEP_RARRAY); |
---|
626 | if (rst_ckt && !strstr(orig->name->name, SEP_GATEPIN)) { |
---|
627 | int i; |
---|
628 | sprintf(orig_buf, "%s", new_termname()); |
---|
629 | if (bit_lo == 0 && bit_hi == -1) { |
---|
630 | if (out_term->term_type) { |
---|
631 | if (vis_nond) { |
---|
632 | char *old_name; |
---|
633 | vl_range *old_range; |
---|
634 | vl_enumerator *enum_elt; |
---|
635 | old_name = out_term->name->name; |
---|
636 | old_range = out_term->name->range; |
---|
637 | out_term->name->name = orig_buf; |
---|
638 | out_term->name->range = NIL(vl_range); |
---|
639 | write_var_decl(file, out_term); |
---|
640 | out_term->name->name = old_name; |
---|
641 | out_term->name->range = old_range; |
---|
642 | lsFirstItem(out_term->term_type->specifier->u.enum_type->domain_list, (lsGeneric*)&enum_elt, 0); |
---|
643 | fprintf(file, ".names %s\n%s\n", orig_buf, |
---|
644 | enum_elt->name); |
---|
645 | } else { |
---|
646 | fprintf(file, ".names %s\n-\n", orig_buf); |
---|
647 | } |
---|
648 | } else { |
---|
649 | if (vis_nond) { |
---|
650 | fprintf(file, ".names %s\n0\n", orig_buf); |
---|
651 | } else { |
---|
652 | fprintf(file, ".names %s\n-\n", orig_buf); |
---|
653 | } |
---|
654 | } |
---|
655 | } else { |
---|
656 | for (i=bit_lo; i<=bit_hi; i++) |
---|
657 | if (vis_nond) { |
---|
658 | fprintf(file, ".names %s%s%d%s\n0\n", orig_buf, |
---|
659 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
660 | } else { |
---|
661 | fprintf(file, ".names %s%s%d%s\n-\n", orig_buf, |
---|
662 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
663 | } |
---|
664 | } |
---|
665 | } else { |
---|
666 | sprintf(orig_buf, "%s%s%d%s", |
---|
667 | orig->name->name, SEP_LARRAY, idx, SEP_RARRAY); |
---|
668 | } |
---|
669 | sprintf(out_buf, "%s%s%d%s", |
---|
670 | out_term->name->name, SEP_LARRAY, idx, SEP_RARRAY); |
---|
671 | new_elt = new; |
---|
672 | orig_elt = create_rename_term(orig->name, orig_buf, bit_lo, bit_hi); |
---|
673 | orig_elt->name->range = NIL(vl_range); |
---|
674 | orig_elt->flag = orig->flag; |
---|
675 | orig_elt->term_type = orig->term_type; |
---|
676 | out_elt = create_rename_term(out_term->name, out_buf, bit_lo, bit_hi); |
---|
677 | out_elt->name->range = NIL(vl_range); |
---|
678 | instantiate_mux(file, new_elt, orig_elt, ctrl, out_elt); |
---|
679 | } |
---|
680 | vl_chk_free((char*)hi_expr); |
---|
681 | } |
---|
682 | |
---|
683 | |
---|
684 | char *new_termname() |
---|
685 | { |
---|
686 | static char sbuf[MAXSTRLEN]; |
---|
687 | static unsigned int TermCount=0; |
---|
688 | |
---|
689 | sprintf(sbuf, "%s%x", NODE, TermCount++); |
---|
690 | return sbuf; |
---|
691 | } |
---|
692 | |
---|
693 | char *new_instname() |
---|
694 | { |
---|
695 | static char sbuf[MAXSTRLEN]; |
---|
696 | static unsigned int InstCount=0; |
---|
697 | |
---|
698 | sprintf(sbuf, "%s%x%s", NODE, InstCount++, NODE); |
---|
699 | return sbuf; |
---|
700 | } |
---|
701 | |
---|
702 | |
---|
703 | vl_range *get_decl_range(void *decl) |
---|
704 | { |
---|
705 | if (!decl) return NIL(vl_range); |
---|
706 | switch (((typestructPtr)(decl))->type) { |
---|
707 | case InputDecl: |
---|
708 | case OutputDecl: |
---|
709 | case InoutDecl: |
---|
710 | case RegDecl: |
---|
711 | return ((vl_rangedeclPtr)(decl))->range; |
---|
712 | case WireDecl: |
---|
713 | case SWireDecl: |
---|
714 | case TriDecl: |
---|
715 | case Tri0Decl: |
---|
716 | case Tri1Decl: |
---|
717 | case TriandDecl: |
---|
718 | case TriorDecl: |
---|
719 | case WandDecl: |
---|
720 | case WorDecl: |
---|
721 | return ((vl_netdeclPtr)(decl))->range; |
---|
722 | default: |
---|
723 | return NIL(vl_range); |
---|
724 | } |
---|
725 | } |
---|
726 | |
---|
727 | vl_expr *get_decl_range_left(void *decl) |
---|
728 | { |
---|
729 | switch (((typestructPtr)(decl))->type) { |
---|
730 | case InputDecl: |
---|
731 | case OutputDecl: |
---|
732 | case InoutDecl: |
---|
733 | case RegDecl: |
---|
734 | if (!((vl_rangedeclPtr)(decl))->range) return NIL(vl_expr); |
---|
735 | return ((vl_rangedeclPtr)(decl))->range->left; |
---|
736 | case WireDecl: |
---|
737 | case SWireDecl: |
---|
738 | case TriDecl: |
---|
739 | case Tri0Decl: |
---|
740 | case Tri1Decl: |
---|
741 | case TriandDecl: |
---|
742 | case TriorDecl: |
---|
743 | case WandDecl: |
---|
744 | case WorDecl: |
---|
745 | if (!((vl_netdeclPtr)(decl))->range) return NIL(vl_expr); |
---|
746 | return ((vl_netdeclPtr)(decl))->range->left; |
---|
747 | default: |
---|
748 | return NIL(vl_expr); |
---|
749 | } |
---|
750 | } |
---|
751 | |
---|
752 | vl_expr *get_decl_range_right(void *decl) |
---|
753 | { |
---|
754 | switch (((typestructPtr)(decl))->type) { |
---|
755 | case InputDecl: |
---|
756 | case OutputDecl: |
---|
757 | case InoutDecl: |
---|
758 | case RegDecl: |
---|
759 | if (!((vl_rangedeclPtr)(decl))->range) return NIL(vl_expr); |
---|
760 | return ((vl_rangedeclPtr)(decl))->range->right; |
---|
761 | case WireDecl: |
---|
762 | case SWireDecl: |
---|
763 | case TriDecl: |
---|
764 | case Tri0Decl: |
---|
765 | case Tri1Decl: |
---|
766 | case TriandDecl: |
---|
767 | case TriorDecl: |
---|
768 | case WandDecl: |
---|
769 | case WorDecl: |
---|
770 | if (!((vl_netdeclPtr)(decl))->range) return NIL(vl_expr); |
---|
771 | return ((vl_netdeclPtr)(decl))->range->right; |
---|
772 | default: |
---|
773 | return NIL(vl_expr); |
---|
774 | } |
---|
775 | } |
---|
776 | |
---|
777 | void * |
---|
778 | chng_decl_range(void *decl, vl_range *new_range) |
---|
779 | { |
---|
780 | void *retval = NIL(void); |
---|
781 | if (!decl) return decl; |
---|
782 | |
---|
783 | switch (((typestructPtr)(decl))->type) { |
---|
784 | case InputDecl: |
---|
785 | case OutputDecl: |
---|
786 | case InoutDecl: |
---|
787 | case RegDecl: |
---|
788 | retval = (void*)chk_malloc(sizeof(vl_rangedecl)); |
---|
789 | ((vl_rangedeclPtr)(retval))->type = ((vl_rangedeclPtr)decl)->type; |
---|
790 | ((vl_rangedeclPtr)(retval))->flags = ((vl_rangedeclPtr)decl)->flags; |
---|
791 | ((vl_rangedeclPtr)(retval))->handle = ((vl_rangedeclPtr)decl)->handle; |
---|
792 | ((vl_rangedeclPtr)(retval))->ids = lsCreate(); |
---|
793 | ((vl_rangedeclPtr)(retval))->range = new_range; |
---|
794 | break; |
---|
795 | case WireDecl: |
---|
796 | case SWireDecl: |
---|
797 | case TriDecl: |
---|
798 | case Tri0Decl: |
---|
799 | case Tri1Decl: |
---|
800 | case TriandDecl: |
---|
801 | case TriorDecl: |
---|
802 | case WandDecl: |
---|
803 | case WorDecl: |
---|
804 | retval = (void*)chk_malloc(sizeof(vl_netdecl)); |
---|
805 | ((vl_netdeclPtr)(retval))->type = ((vl_netdeclPtr)decl)->type; |
---|
806 | ((vl_netdeclPtr)(retval))->flags = ((vl_netdeclPtr)decl)->flags; |
---|
807 | ((vl_netdeclPtr)(retval))->strength = ((vl_netdeclPtr)decl)->strength; |
---|
808 | ((vl_netdeclPtr)(retval))->delay = ((vl_netdeclPtr)decl)->delay; |
---|
809 | ((vl_netdeclPtr)(retval))->handle = ((vl_netdeclPtr)decl)->handle; |
---|
810 | ((vl_netdeclPtr)(retval))->ids = lsCreate(); |
---|
811 | ((vl_netdeclPtr)(retval))->range = new_range; |
---|
812 | break; |
---|
813 | default: |
---|
814 | break; |
---|
815 | } |
---|
816 | return retval; |
---|
817 | } |
---|
818 | |
---|
819 | short get_decl_flags(void *decl) |
---|
820 | { |
---|
821 | if (!decl) return 0; |
---|
822 | |
---|
823 | switch (((typestructPtr)(decl))->type) { |
---|
824 | case InputDecl: |
---|
825 | case OutputDecl: |
---|
826 | case InoutDecl: |
---|
827 | case RegDecl: |
---|
828 | return ((vl_rangedeclPtr)(decl))->flags; |
---|
829 | case WireDecl: |
---|
830 | case SWireDecl: |
---|
831 | case TriDecl: |
---|
832 | case Tri0Decl: |
---|
833 | case Tri1Decl: |
---|
834 | case TriandDecl: |
---|
835 | case TriorDecl: |
---|
836 | case WandDecl: |
---|
837 | case WorDecl: |
---|
838 | return ((vl_netdeclPtr)(decl))->flags; |
---|
839 | default: |
---|
840 | return 0; |
---|
841 | } |
---|
842 | } |
---|
843 | |
---|
844 | void get_type(vl_id_range *id, vl_type **var_type) |
---|
845 | { |
---|
846 | |
---|
847 | id = id; |
---|
848 | var_type = var_type; |
---|
849 | } |
---|
850 | |
---|
851 | |
---|
852 | void get_hilo(vl_id_range *id, int *hi, int *lo) |
---|
853 | { |
---|
854 | vl_expr *left, *right; |
---|
855 | int leftval, rightval; |
---|
856 | |
---|
857 | if (get_decl_range(id->mpg_master_exp)) { |
---|
858 | left = get_decl_range_left(id->mpg_master_exp); |
---|
859 | right = get_decl_range_right(id->mpg_master_exp); |
---|
860 | leftval = vl_eval_expr(left); |
---|
861 | rightval = vl_eval_expr(right); |
---|
862 | if (leftval > rightval) { |
---|
863 | int temp; |
---|
864 | |
---|
865 | temp=leftval; leftval = rightval; rightval = temp; |
---|
866 | } |
---|
867 | *lo = leftval; |
---|
868 | *hi = rightval; |
---|
869 | } else { |
---|
870 | *lo = 0; |
---|
871 | *hi = -1; |
---|
872 | } |
---|
873 | } |
---|
874 | |
---|
875 | |
---|
876 | |
---|
877 | void insert_control_list(var_info *cur_var, vl_term *sel) |
---|
878 | { |
---|
879 | vl_id_range *id_sym; |
---|
880 | |
---|
881 | if (!sel) return; |
---|
882 | st_lookup(vl_currentModule->sig_st, cur_var->id->name, (char**)&id_sym); |
---|
883 | lsNewEnd(cur_var->cond_list, (lsGeneric)sel, LS_NH); |
---|
884 | } |
---|
885 | |
---|
886 | |
---|
887 | void print_control_var_pair(FILE *file, char *ctrl, char *var) |
---|
888 | { |
---|
889 | fprintf(file, "%s %s ", ctrl, var); |
---|
890 | } |
---|
891 | |
---|
892 | |
---|
893 | |
---|
894 | vl_term *write_multi_in_or(FILE *file, lsList in_list) |
---|
895 | { |
---|
896 | lsGen gen; |
---|
897 | lsHandle handle; |
---|
898 | vl_term *term_out; |
---|
899 | vl_term *in_term, *true_in_term; |
---|
900 | int i, j; |
---|
901 | |
---|
902 | term_out = new_term(NIL(vl_range), 0, -1); |
---|
903 | |
---|
904 | fprintf(file, ".names "); |
---|
905 | gen = lsStart(in_list); |
---|
906 | if (lsNext(gen, (lsGeneric*)&in_term, &handle) == LS_OK) { |
---|
907 | true_in_term = (vl_term*)((int)in_term & (~1)); |
---|
908 | fprintf(file, "%s ", true_in_term->name->name); |
---|
909 | while (lsNext(gen, (lsGeneric*)&in_term, &handle) != LS_NOMORE) { |
---|
910 | true_in_term = (vl_term*)((int)in_term & (~1)); |
---|
911 | fprintf(file, "%s ", true_in_term->name->name); |
---|
912 | } |
---|
913 | } |
---|
914 | fprintf(file, "%s\n", term_out->name->name); |
---|
915 | lsFinish(gen); |
---|
916 | |
---|
917 | if (set_notation) { |
---|
918 | fprintf(file, "%s 1\n", HSIS_DEFAULT); |
---|
919 | } else { |
---|
920 | gen = lsStart(in_list); |
---|
921 | for (i=0; i<lsLength(in_list); i++) { |
---|
922 | lsNext(gen, (lsGeneric*)&in_term, &handle); |
---|
923 | for (j=0; j<lsLength(in_list); j++) { |
---|
924 | fprintf(file, "%c ", (i==j)?(((int)in_term&1)?'0':'1'):'-'); |
---|
925 | } |
---|
926 | fprintf(file, "1\n"); |
---|
927 | } |
---|
928 | lsFinish(gen); |
---|
929 | } |
---|
930 | |
---|
931 | gen = lsStart(in_list); |
---|
932 | if (lsNext(gen, (lsGeneric*)&in_term, &handle) == LS_OK) { |
---|
933 | fprintf(file, "%c ", ((int)in_term&1)?'1':'0'); |
---|
934 | while (lsNext(gen, (lsGeneric*)&in_term, &handle) != LS_NOMORE) { |
---|
935 | fprintf(file, "%c ", ((int)in_term&1)?'1':'0'); |
---|
936 | } |
---|
937 | } |
---|
938 | lsFinish(gen); |
---|
939 | fprintf(file, "0\n"); |
---|
940 | |
---|
941 | return term_out; |
---|
942 | } |
---|
943 | |
---|
944 | |
---|
945 | |
---|
946 | vl_term *array_or(FILE *file, array_t *in_array) |
---|
947 | { |
---|
948 | vl_term *term_out; |
---|
949 | vl_term *in_term, *true_in_term; |
---|
950 | int i, j; |
---|
951 | int ithItem; |
---|
952 | |
---|
953 | term_out = new_term(NIL(vl_range), 0, -1); |
---|
954 | |
---|
955 | fprintf(file, ".names "); |
---|
956 | ithItem = 0; |
---|
957 | for (i=0; i<array_n(in_array); i++) { |
---|
958 | true_in_term = array_fetch(vl_term*, in_array, i); |
---|
959 | if (true_in_term) { |
---|
960 | fprintf(file, "%s ", true_in_term->name->name); |
---|
961 | } |
---|
962 | |
---|
963 | } |
---|
964 | fprintf(file, "%s\n", term_out->name->name); |
---|
965 | |
---|
966 | if (set_notation) { |
---|
967 | fprintf(file, "%s 1\n", HSIS_DEFAULT); |
---|
968 | } else { |
---|
969 | for (i=0; i<array_n(in_array); i++) { |
---|
970 | in_term = array_fetch(vl_term*, in_array, i); |
---|
971 | if (!in_term) continue; |
---|
972 | for (j=0; j<array_n(in_array); j++) { |
---|
973 | if (array_fetch(vl_term*, in_array, j)) |
---|
974 | fprintf(file, "%c ", (i==j)?'1':'-'); |
---|
975 | } |
---|
976 | fprintf(file, "1\n"); |
---|
977 | } |
---|
978 | } |
---|
979 | |
---|
980 | for (i=0; i<array_n(in_array); i++) |
---|
981 | if (array_fetch(vl_term*, in_array, i)) |
---|
982 | fprintf(file, "0 "); |
---|
983 | fprintf(file, "0\n"); |
---|
984 | |
---|
985 | return term_out; |
---|
986 | } |
---|
987 | |
---|
988 | |
---|
989 | vl_term *syndrome_to_control(FILE *file, char *key, st_table *sig_st) |
---|
990 | { |
---|
991 | vl_term *retval=NIL(vl_term); |
---|
992 | vl_id_range *id_sym; |
---|
993 | syndrome_expr *se; |
---|
994 | vl_term *ctrl_term; |
---|
995 | int ith_var = 0; |
---|
996 | char *syndrome; |
---|
997 | char *dc; |
---|
998 | lsList comp; |
---|
999 | lsGen gen; |
---|
1000 | lsHandle handle; |
---|
1001 | var_info *cur_var; |
---|
1002 | int fg_id = -1; |
---|
1003 | char lc_name[MAXSTRLEN]; |
---|
1004 | int need_leading_and = 1; |
---|
1005 | int ithItem; |
---|
1006 | |
---|
1007 | if (!st_lookup(sig_st, key, (char**)&cur_var)) return true_term(file); |
---|
1008 | id_sym = cur_var->id; |
---|
1009 | |
---|
1010 | |
---|
1011 | if (!(dc = check_dc((!rst_ckt)?id_sym->syndrome_expr_list: |
---|
1012 | id_sym->rst_syndrome_expr_list))) |
---|
1013 | return NIL(vl_term);; |
---|
1014 | |
---|
1015 | |
---|
1016 | retval = new_term(NIL(vl_range), 0, -1); |
---|
1017 | if (!vlTimedSystem) |
---|
1018 | if (isTautology((!rst_ckt)?id_sym->syndrome_expr_list: |
---|
1019 | id_sym->rst_syndrome_expr_list)) |
---|
1020 | retval->flag |= TautologyTrue; |
---|
1021 | if (vlTimedSystem && !rst_ckt) { |
---|
1022 | for (gen=lsStart((!rst_ckt)? |
---|
1023 | id_sym->syndrome_expr_list: |
---|
1024 | id_sym->rst_syndrome_expr_list); |
---|
1025 | lsNext(gen,(lsGeneric*)&se,&handle)!=LS_NOMORE; ) { |
---|
1026 | st_table *dummy; |
---|
1027 | if (st_lookup(vl_description->fg_vars_st, (char*)se->fg_id, |
---|
1028 | (char**)&dummy)) |
---|
1029 | if (dummy == sig_st) { |
---|
1030 | fg_id = se->fg_id; break; |
---|
1031 | } |
---|
1032 | } |
---|
1033 | lsFinish(gen); |
---|
1034 | sprintf(lc_name, "%s%06x", FG_LC_PS, fg_id); |
---|
1035 | if (fg_id != -1) { |
---|
1036 | fprintf(file, ".names %s ", lc_name); |
---|
1037 | } else { |
---|
1038 | fprintf(file, ".names %s\n0\n", retval->name->name); |
---|
1039 | retval->flag |= ConflictFalse; |
---|
1040 | return retval; |
---|
1041 | } |
---|
1042 | } else { |
---|
1043 | fprintf(file, ".names "); |
---|
1044 | } |
---|
1045 | ithItem = 0; |
---|
1046 | for (gen=lsStart((!rst_ckt)?ctrl_list:rst_ctrl_list), ith_var=0; |
---|
1047 | lsNext(gen,(lsGeneric*)&ctrl_term,&handle)!=LS_NOMORE; ith_var++) { |
---|
1048 | if (!dc[ith_var]) { |
---|
1049 | fprintf(file, "%s ", ctrl_term->name->name); |
---|
1050 | } |
---|
1051 | } |
---|
1052 | lsFinish(gen); |
---|
1053 | |
---|
1054 | fprintf(file, "%s\n", retval->name->name); |
---|
1055 | |
---|
1056 | if (set_notation) |
---|
1057 | fprintf(file, "%s 0\n", HSIS_DEFAULT); |
---|
1058 | |
---|
1059 | for (gen=lsStart((!rst_ckt)? |
---|
1060 | id_sym->syndrome_expr_list: |
---|
1061 | id_sym->rst_syndrome_expr_list); |
---|
1062 | lsNext(gen,(lsGeneric*)&se,&handle)!=LS_NOMORE; ) { |
---|
1063 | st_table *dummy; |
---|
1064 | int printed; |
---|
1065 | |
---|
1066 | printed = 0; |
---|
1067 | if (st_lookup(vl_description->fg_vars_st, (char*)se->fg_id, |
---|
1068 | (char**)&dummy)) |
---|
1069 | if (dummy == sig_st) { |
---|
1070 | if (vlTimedSystem && !rst_ckt) |
---|
1071 | fg_put_loc_context(file, se->pre_cond, lc_name); |
---|
1072 | fprintf(file, " "); |
---|
1073 | printed = put_entry(file, se->syndrome, dc, need_leading_and); |
---|
1074 | if (!need_leading_and && !printed) |
---|
1075 | fprintf(file, "%d ", 1); |
---|
1076 | fprintf(file, "1\n"); |
---|
1077 | } |
---|
1078 | } |
---|
1079 | lsFinish(gen); |
---|
1080 | |
---|
1081 | if (!set_notation) { |
---|
1082 | comp=put_guard_zero(file, (!rst_ckt)? |
---|
1083 | id_sym->syndrome_expr_list: |
---|
1084 | id_sym->rst_syndrome_expr_list); |
---|
1085 | for (gen=lsStart(comp); lsNext(gen,&syndrome,&handle)!=LS_NOMORE; ) { |
---|
1086 | put_entry(file, syndrome, dc, 1); |
---|
1087 | fprintf(file, "0\n"); |
---|
1088 | } |
---|
1089 | lsFinish(gen); |
---|
1090 | } |
---|
1091 | |
---|
1092 | vl_chk_free(dc); |
---|
1093 | |
---|
1094 | return retval; |
---|
1095 | } |
---|
1096 | |
---|
1097 | |
---|
1098 | lsList put_guard_zero(FILE *file, lsList se_list) |
---|
1099 | { |
---|
1100 | lsList retval=(lsList)0; |
---|
1101 | |
---|
1102 | return retval; |
---|
1103 | } |
---|
1104 | |
---|
1105 | |
---|
1106 | lsList get_transition(FILE *file) |
---|
1107 | { |
---|
1108 | lsList retval; |
---|
1109 | char buf[MAXSTRLEN], *cp; |
---|
1110 | char syndrome[MAXSTRLEN]; |
---|
1111 | int n_entries, i; |
---|
1112 | |
---|
1113 | retval = lsCreate(); |
---|
1114 | while (fgets(buf, MAXSTRLEN-1, file)) { |
---|
1115 | if ((cp = strstr(buf, ".p")) != NIL(char)) { |
---|
1116 | cp += strlen(".p"); |
---|
1117 | n_entries = atoi(cp); |
---|
1118 | for (i=0; i<n_entries && fgets(buf, MAXSTRLEN-1, file); i++) { |
---|
1119 | sscanf(buf, "%s", syndrome); |
---|
1120 | lsNewEnd(retval, vlStrdup(syndrome), 0); |
---|
1121 | } |
---|
1122 | break; |
---|
1123 | } |
---|
1124 | } |
---|
1125 | return retval; |
---|
1126 | } |
---|
1127 | |
---|
1128 | |
---|
1129 | int put_entry(FILE *file, char *str, char *dc, int need_leading_and) |
---|
1130 | { |
---|
1131 | unsigned int i; |
---|
1132 | lsGen gen; |
---|
1133 | lsHandle handle; |
---|
1134 | vl_term *ctrl_term; |
---|
1135 | int print_something=0; |
---|
1136 | |
---|
1137 | for (i=0, gen=lsStart((!rst_ckt)?ctrl_list:rst_ctrl_list); |
---|
1138 | i<strlen(str) && lsNext(gen,(lsGeneric*)&ctrl_term,&handle)!=LS_NOMORE; |
---|
1139 | i++) { |
---|
1140 | if (!dc) { |
---|
1141 | fprintf(file, "%c ", str[i]); |
---|
1142 | } else if (!dc[i]) { |
---|
1143 | fprintf(file, "%c ", str[i]); |
---|
1144 | } |
---|
1145 | } |
---|
1146 | |
---|
1147 | return print_something; |
---|
1148 | } |
---|
1149 | |
---|
1150 | |
---|
1151 | int put_blif_header(FILE *file, lsList se_list) |
---|
1152 | { |
---|
1153 | int terminal_count=0; |
---|
1154 | int retval; |
---|
1155 | unsigned int i; |
---|
1156 | syndrome_expr *se; |
---|
1157 | |
---|
1158 | fprintf(file, ".model scratch\n"); |
---|
1159 | fprintf(file, ".outputs n%d\n", retval = terminal_count++); |
---|
1160 | if (lsLength(se_list)) { |
---|
1161 | fprintf(file, ".inputs"); |
---|
1162 | lsFirstItem(se_list, (lsGeneric*)&se, 0); |
---|
1163 | for (i=0; i<strlen(se->syndrome); i++) { |
---|
1164 | fprintf(file, " n%d", terminal_count++); |
---|
1165 | } |
---|
1166 | fprintf(file, "\n"); |
---|
1167 | } |
---|
1168 | return retval; |
---|
1169 | } |
---|
1170 | |
---|
1171 | |
---|
1172 | int put_blif_gate_header(FILE *file, lsList se_list) |
---|
1173 | { |
---|
1174 | int terminal_count=0; |
---|
1175 | int retval; |
---|
1176 | unsigned int i; |
---|
1177 | syndrome_expr *se; |
---|
1178 | |
---|
1179 | fprintf(file, ".names"); |
---|
1180 | if (lsLength(se_list)) { |
---|
1181 | lsFirstItem(se_list, (lsGeneric*)&se, 0); |
---|
1182 | for (i=0; i<strlen(se->syndrome); i++) { |
---|
1183 | fprintf(file, " n%d", ++terminal_count); |
---|
1184 | } |
---|
1185 | } |
---|
1186 | fprintf(file, " n%d\n", retval = ++terminal_count); |
---|
1187 | |
---|
1188 | return retval; |
---|
1189 | } |
---|
1190 | |
---|
1191 | void put_blif_tail(FILE *file) |
---|
1192 | { |
---|
1193 | fprintf(file, ".end\n\n"); |
---|
1194 | } |
---|
1195 | |
---|
1196 | |
---|
1197 | vl_term *write_array_access(FILE *file, vl_id_range *id_sym, vl_term *idx_term, vl_expr *idx_expr) |
---|
1198 | { |
---|
1199 | int lo, hi, idx; |
---|
1200 | int bit_lo, bit_hi, bit; |
---|
1201 | int i, j; |
---|
1202 | unsigned int k; |
---|
1203 | vl_term *retval; |
---|
1204 | char buf[MAXSTRLEN]; |
---|
1205 | |
---|
1206 | lo = vl_eval_expr(id_sym->range->left); |
---|
1207 | if (id_sym->range->right) |
---|
1208 | hi = vl_eval_expr(id_sym->range->right); |
---|
1209 | else |
---|
1210 | hi = lo; |
---|
1211 | |
---|
1212 | |
---|
1213 | if (!idx_term) { |
---|
1214 | int const_hi, const_lo; |
---|
1215 | |
---|
1216 | assert(ISVLCONST(idx_expr->type)); |
---|
1217 | |
---|
1218 | const_hi = min_bit_width(hi)-1; |
---|
1219 | const_lo = 0; |
---|
1220 | idx_term = new_term(NIL(vl_range), const_lo, const_hi); |
---|
1221 | write_var_decl(file, idx_term); |
---|
1222 | vl_write_const(file, idx_expr, idx_term); |
---|
1223 | } |
---|
1224 | |
---|
1225 | |
---|
1226 | get_hilo(id_sym, &bit_hi, &bit_lo); |
---|
1227 | retval = new_term(NIL(vl_range), bit_lo, bit_hi); |
---|
1228 | retval->flag = id_sym->flags; |
---|
1229 | retval->term_type = id_sym->id_type; |
---|
1230 | write_var_decl(file, retval); |
---|
1231 | |
---|
1232 | if (bit_lo > bit_hi) { |
---|
1233 | if (id_sym->flags & MVar) { |
---|
1234 | |
---|
1235 | lsList domain; |
---|
1236 | |
---|
1237 | domain = id_sym->id_type->specifier->u.enum_type->domain_list; |
---|
1238 | |
---|
1239 | fprintf(file, ".names "); |
---|
1240 | for (i=idx_term->hi; i>=idx_term->lo; i--) { |
---|
1241 | fprintf(file, "%s%s%d%s ", idx_term->name->name, |
---|
1242 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
1243 | } |
---|
1244 | for (idx=lo; idx<=hi; idx++) { |
---|
1245 | fprintf(file, "%s%s%d%s ", id_sym->name, |
---|
1246 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
1247 | } |
---|
1248 | fprintf(file, "%s\n", retval->name->name); |
---|
1249 | |
---|
1250 | |
---|
1251 | if (set_notation) { |
---|
1252 | for (i=0; i<(1<<(idx_term->hi-idx_term->lo+1)); i++) { |
---|
1253 | strcpy(buf, |
---|
1254 | num_to_binstr(i,(idx_term->hi-idx_term->lo+1))); |
---|
1255 | for (k=0; k<strlen(buf); k++) |
---|
1256 | fprintf(file, "%c ", buf[k]); |
---|
1257 | for (idx=lo; idx<=hi; idx++) fprintf(file, "- "); |
---|
1258 | if (i <= hi && i >= lo) |
---|
1259 | fprintf(file, "%s%s%s%d%s\n", HSIS_EQUAL, |
---|
1260 | id_sym->name, SEP_LARRAY, i, SEP_RARRAY); |
---|
1261 | else { |
---|
1262 | if (arrayBoundNond) { |
---|
1263 | fprintf(file, "-\n"); |
---|
1264 | } else { |
---|
1265 | vl_enumerator *enum_elt; |
---|
1266 | lsFirstItem(id_sym->id_type->specifier |
---|
1267 | ->u.enum_type->domain_list, |
---|
1268 | (lsGeneric*)&enum_elt, 0); |
---|
1269 | fprintf(file, "%s\n", enum_elt->name); |
---|
1270 | } |
---|
1271 | } |
---|
1272 | } |
---|
1273 | } else { |
---|
1274 | lsList domain; |
---|
1275 | lsGen enum_gen; |
---|
1276 | lsHandle enum_handle; |
---|
1277 | vl_enumerator *enum_elt; |
---|
1278 | domain = id_sym->id_type->specifier->u.enum_type->domain_list; |
---|
1279 | for (i=0; i<(1<<(idx_term->hi-idx_term->lo+1)); i++) { |
---|
1280 | for (enum_gen=lsStart(domain); |
---|
1281 | lsNext(enum_gen,(lsGeneric*)&enum_elt,&enum_handle)!= |
---|
1282 | LS_NOMORE; ) { |
---|
1283 | strcpy(buf, |
---|
1284 | num_to_binstr(i,(idx_term->hi-idx_term->lo+1))); |
---|
1285 | for (k=0; k<strlen(buf); k++) |
---|
1286 | fprintf(file, "%c ", buf[k]); |
---|
1287 | for (idx=lo; idx<=hi; idx++) |
---|
1288 | fprintf(file, "%s ", |
---|
1289 | (idx==i)?enum_elt->name:"-"); |
---|
1290 | fprintf(file, "%s\n", |
---|
1291 | (i<=hi && i>=lo)?enum_elt->name: |
---|
1292 | (arrayBoundNond)?"-":enum_elt->name); |
---|
1293 | } |
---|
1294 | lsFinish(enum_gen); |
---|
1295 | } |
---|
1296 | } |
---|
1297 | } else { |
---|
1298 | |
---|
1299 | fprintf(file, ".names "); |
---|
1300 | for (i=idx_term->hi; i>=idx_term->lo; i--) { |
---|
1301 | fprintf(file, "%s%s%d%s ", idx_term->name->name, |
---|
1302 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
1303 | } |
---|
1304 | for (idx=lo; idx<=hi; idx++) { |
---|
1305 | fprintf(file, "%s%s%d%s ", id_sym->name, |
---|
1306 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
1307 | } |
---|
1308 | fprintf(file, "%s\n", retval->name->name); |
---|
1309 | fprintf(file, ".def 0\n"); |
---|
1310 | |
---|
1311 | for (i=0; i<(1<<(idx_term->hi-idx_term->lo+1)); i++) { |
---|
1312 | for (j=0; j<=1; j++) { |
---|
1313 | if (j==0 && i<=hi && i>=lo) continue; |
---|
1314 | if ((i>hi || i<lo) && !arrayBoundNond) continue; |
---|
1315 | strcpy(buf, |
---|
1316 | num_to_binstr(i, (idx_term->hi-idx_term->lo+1))); |
---|
1317 | for (k=0; k<strlen(buf); k++) |
---|
1318 | fprintf(file, "%c ", buf[k]); |
---|
1319 | for (idx=lo; idx<=hi; idx++) { |
---|
1320 | fprintf(file, "%c ", (idx==i)?((j==0)?'0':'1'):'-'); |
---|
1321 | } |
---|
1322 | fprintf(file, "%c\n", (i<=hi && i>=lo)?'1':'-'); |
---|
1323 | } |
---|
1324 | } |
---|
1325 | } |
---|
1326 | } else { |
---|
1327 | for (bit=bit_lo; bit<=bit_hi; bit++) { |
---|
1328 | |
---|
1329 | fprintf(file, ".names "); |
---|
1330 | for (i=idx_term->hi; i>=idx_term->lo; i--) { |
---|
1331 | fprintf(file, "%s%s%d%s ", idx_term->name->name, |
---|
1332 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
1333 | } |
---|
1334 | for (idx=lo; idx<=hi; idx++) { |
---|
1335 | fprintf(file, "%s%s%d%s%s%d%s ", id_sym->name, |
---|
1336 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
1337 | SEP_LBITSELECT, bit, SEP_RBITSELECT); |
---|
1338 | } |
---|
1339 | fprintf(file, "%s%s%d%s\n", retval->name->name, |
---|
1340 | SEP_LBITSELECT,bit,SEP_RBITSELECT); |
---|
1341 | fprintf(file, ".def 0\n"); |
---|
1342 | |
---|
1343 | for (i=0; i<(1<<(idx_term->hi-idx_term->lo+1)); i++) { |
---|
1344 | for (j=0; j<=1; j++) { |
---|
1345 | if (j==0 && i<=hi && i>=lo) continue; |
---|
1346 | if ((i>hi || i<lo) && !arrayBoundNond) continue; |
---|
1347 | strcpy(buf, |
---|
1348 | num_to_binstr(i,(idx_term->hi-idx_term->lo+1))); |
---|
1349 | for (k=0; k<strlen(buf); k++) |
---|
1350 | fprintf(file, "%c ", buf[k]); |
---|
1351 | for (idx=lo; idx<=hi; idx++) { |
---|
1352 | fprintf(file, "%c ", (idx==i)?((j==0)?'0':'1'):'-'); |
---|
1353 | } |
---|
1354 | fprintf(file, "%c\n", (i<=hi && i>=lo)? '1':'-'); |
---|
1355 | } |
---|
1356 | } |
---|
1357 | } |
---|
1358 | } |
---|
1359 | |
---|
1360 | return retval; |
---|
1361 | } |
---|
1362 | |
---|
1363 | |
---|
1364 | char *sel_var(char *name) |
---|
1365 | { |
---|
1366 | return name; |
---|
1367 | } |
---|
1368 | |
---|
1369 | int isMVar(short unsigned flag) |
---|
1370 | { |
---|
1371 | return (flag & MVar); |
---|
1372 | } |
---|
1373 | |
---|
1374 | int isOutPort(short unsigned flag) |
---|
1375 | { |
---|
1376 | return (flag & OutPort); |
---|
1377 | } |
---|
1378 | |
---|
1379 | |
---|
1380 | void check_assign(vl_bassign_stmt *assign, int procedural) |
---|
1381 | { |
---|
1382 | vl_id_range *lhs_id; |
---|
1383 | char buf[MAXSTRLEN]; |
---|
1384 | |
---|
1385 | st_lookup(vl_currentModule->sig_st, |
---|
1386 | assign->lhs->name->name, (char**)&lhs_id); |
---|
1387 | |
---|
1388 | if (procedural) { |
---|
1389 | if (assign->type != NbassignStmt && |
---|
1390 | assign->type != DelayNbassignStmt && |
---|
1391 | assign->type != EventNbassignStmt && |
---|
1392 | !(lhs_id->flags & RegVar)) { |
---|
1393 | yylineno = assign->lineno; |
---|
1394 | sprintf(buf, |
---|
1395 | "error: wire '%s' is used as lhs of = in procedural statement\n", |
---|
1396 | lhs_id->name); |
---|
1397 | compile_error(buf); |
---|
1398 | } |
---|
1399 | if (lhs_must_be_wire && (lhs_id->flags & RegVar)) { |
---|
1400 | |
---|
1401 | } |
---|
1402 | if (compatibleChecking && !(lhs_id->flags & RegVar)) { |
---|
1403 | yylineno = assign->lineno; |
---|
1404 | sprintf(buf, |
---|
1405 | "error: wire '%s' is used as lhs of <= in procedural statement\n", |
---|
1406 | lhs_id->name); |
---|
1407 | compile_error(buf); |
---|
1408 | } |
---|
1409 | } else { |
---|
1410 | if (lhs_id->flags & RegVar) { |
---|
1411 | yylineno = assign->lineno; |
---|
1412 | sprintf(buf, |
---|
1413 | "error: reg '%s' is used as lhs of continus assignment\n", |
---|
1414 | lhs_id->name); |
---|
1415 | compile_error(buf); |
---|
1416 | } |
---|
1417 | } |
---|
1418 | } |
---|
1419 | |
---|
1420 | |
---|
1421 | void instantiate_reset_mux(FILE *file, vl_id_range *id_sym, int lo, int hi, |
---|
1422 | var_info *var, var_info *lvar) |
---|
1423 | { |
---|
1424 | extern vl_term *Initial_Signal; |
---|
1425 | vl_term *term_out; |
---|
1426 | char buf[MAXSTRLEN]; |
---|
1427 | vl_term *init_term; |
---|
1428 | |
---|
1429 | sprintf(buf, "%s%s", id_sym->name, new_termname()); |
---|
1430 | term_out = create_rename_term(id_sym, buf, lo, hi); |
---|
1431 | term_out->flag = |
---|
1432 | get_decl_flags(var->id->mpg_master_exp); |
---|
1433 | write_var_decl(file,term_out); |
---|
1434 | lsFirstItem(id_sym->initial, (lsGeneric*)&init_term, 0); |
---|
1435 | instantiate_mux(file, init_term, |
---|
1436 | lvar->current_terminal, |
---|
1437 | Initial_Signal, term_out); |
---|
1438 | lvar->current_terminal = term_out; |
---|
1439 | } |
---|
1440 | |
---|
1441 | |
---|
1442 | void instantiate_input_latch(FILE *file, vl_id_range *id_sym) |
---|
1443 | { |
---|
1444 | char buf[MAXSTRLEN]; |
---|
1445 | |
---|
1446 | sprintf(buf, "%s%s%s", id_sym->name, SEP_DIR, PIN_IN); |
---|
1447 | if (id_sym->flags & InPort && id_sym->flags & RegVar) { |
---|
1448 | if (!instantiateInputLatch) return; |
---|
1449 | if (id_sym->flags & MVar) { |
---|
1450 | fprintf(file, ".latch %s %s\n", id_sym->name, buf); |
---|
1451 | } else { |
---|
1452 | int i, lo, hi; |
---|
1453 | |
---|
1454 | get_hilo(id_sym, &hi, &lo); |
---|
1455 | if (lo > hi) { |
---|
1456 | fprintf(file, ".latch %s %s\n", id_sym->name, buf); |
---|
1457 | } else { |
---|
1458 | for (i=lo; i<=hi; i++) { |
---|
1459 | fprintf(file, ".latch %s%s%d%s %s%s%d%s\n", |
---|
1460 | id_sym->name, |
---|
1461 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
1462 | buf, SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
1463 | } |
---|
1464 | } |
---|
1465 | } |
---|
1466 | } |
---|
1467 | } |
---|
1468 | |
---|
1469 | |
---|
1470 | void instantiate_hidden_latch(FILE *file, vl_id_range *id_sym) |
---|
1471 | { |
---|
1472 | char buf[MAXSTRLEN]; |
---|
1473 | lsList domain; |
---|
1474 | lsGen enum_gen; |
---|
1475 | lsHandle enum_handle; |
---|
1476 | vl_enumerator *enum_elt; |
---|
1477 | |
---|
1478 | |
---|
1479 | if (!id_sym->mpg_master_exp) return; |
---|
1480 | if (strstr(id_sym->name, SEP_LATCH)) return; |
---|
1481 | |
---|
1482 | sprintf(buf, "%s%s", id_sym->name, PIN_HIDDEN); |
---|
1483 | if (id_sym->flags & HiddenLatch) { |
---|
1484 | if (id_sym->flags & MVar) { |
---|
1485 | domain = id_sym->id_type->specifier->u.enum_type->domain_list; |
---|
1486 | fprintf(file, ".mv %s %d ", buf, lsLength(domain)); |
---|
1487 | for (enum_gen = lsStart(domain); |
---|
1488 | lsNext(enum_gen, (lsGeneric*)&enum_elt, &enum_handle) != |
---|
1489 | LS_NOMORE;) { |
---|
1490 | fprintf(file, "%s ", enum_elt->name); |
---|
1491 | } |
---|
1492 | lsFinish(enum_gen); |
---|
1493 | fprintf(file, "\n"); |
---|
1494 | fprintf(file, ".latch %s %s\n", id_sym->name, buf); |
---|
1495 | fprintf(file, ".r %s\n-\n", buf); |
---|
1496 | } else { |
---|
1497 | int i, lo, hi; |
---|
1498 | |
---|
1499 | get_hilo(id_sym, &hi, &lo); |
---|
1500 | if (lo > hi) { |
---|
1501 | fprintf(file, ".latch %s %s\n", id_sym->name, buf); |
---|
1502 | fprintf(file, ".r %s\n-\n", buf); |
---|
1503 | } else { |
---|
1504 | for (i=lo; i<=hi; i++) { |
---|
1505 | fprintf(file, ".latch %s%s%d%s %s%s%d%s\n", |
---|
1506 | id_sym->name, SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
1507 | buf, SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
1508 | fprintf(file, ".r %s%s%d%s\n-\n", |
---|
1509 | buf, SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
1510 | } |
---|
1511 | } |
---|
1512 | } |
---|
1513 | } |
---|
1514 | } |
---|
1515 | |
---|
1516 | |
---|
1517 | char *check_dc(lsList syndrome_expr_list) |
---|
1518 | { |
---|
1519 | lsGen lgen; |
---|
1520 | lsHandle handle; |
---|
1521 | char *retval; |
---|
1522 | int nsym; |
---|
1523 | syndrome_expr *se; |
---|
1524 | int i; |
---|
1525 | int rtvl; |
---|
1526 | |
---|
1527 | if (lsLength(syndrome_expr_list) == 0) return NIL(char); |
---|
1528 | |
---|
1529 | rtvl = lsFirstItem(syndrome_expr_list,(lsGeneric*)&se,0); |
---|
1530 | assert(rtvl == LS_OK); |
---|
1531 | nsym = strlen(se->syndrome); |
---|
1532 | retval = (char*)chk_malloc(nsym * sizeof(char)); |
---|
1533 | for (i=0; i<nsym; i++) { |
---|
1534 | retval[i] = 1; |
---|
1535 | for (lgen=lsStart(syndrome_expr_list); |
---|
1536 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE;) { |
---|
1537 | if (se->syndrome[i] != '-') |
---|
1538 | retval[i] = 0; |
---|
1539 | } |
---|
1540 | (void)lsFinish(lgen); |
---|
1541 | } |
---|
1542 | |
---|
1543 | return retval; |
---|
1544 | } |
---|
1545 | |
---|
1546 | |
---|
1547 | void put_nblock_transition(FILE *file, int non_block_wire, int n_entries, |
---|
1548 | vl_id_range *id_sym, int idx_lo, int idx_hi, int cur, char *dc, lsList ripple) |
---|
1549 | { |
---|
1550 | lsGen lgen; |
---|
1551 | lsList comp; |
---|
1552 | lsHandle handle; |
---|
1553 | int lo, hi; |
---|
1554 | int i, j, k; |
---|
1555 | char *syndrome; |
---|
1556 | syndrome_expr *se; |
---|
1557 | lsList domain=(lsList)0; |
---|
1558 | lsGen enum_gen; |
---|
1559 | lsHandle enum_handle; |
---|
1560 | vl_enumerator *enum_elt; |
---|
1561 | |
---|
1562 | for (lgen=lsStart((!rst_ckt)? |
---|
1563 | id_sym->syndrome_expr_list: |
---|
1564 | id_sym->rst_syndrome_expr_list), |
---|
1565 | i=0; |
---|
1566 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE; i++) { |
---|
1567 | if (!(id_sym->flags & MVar)) { |
---|
1568 | lo=0; hi=1; |
---|
1569 | } else { |
---|
1570 | get_hilo(id_sym, &hi, &lo); |
---|
1571 | } |
---|
1572 | |
---|
1573 | if (id_sym->id_type) |
---|
1574 | domain = id_sym->id_type->specifier->u.enum_type->domain_list; |
---|
1575 | |
---|
1576 | if (!(id_sym->flags & MVar)) { |
---|
1577 | for (k=lo; k<=hi; k++) { |
---|
1578 | if (vlTimedSystem && !rst_ckt) |
---|
1579 | fg_put_loc_context(file, se->pre_cond, NIL(char)); |
---|
1580 | fprintf(file, " "); |
---|
1581 | put_entry(file, se->syndrome, dc, 1); |
---|
1582 | |
---|
1583 | if (ripple) { |
---|
1584 | for (j=0; j<i; j++) fprintf(file, "- "); |
---|
1585 | fprintf(file, "%d ", 1); j++; |
---|
1586 | for (; j<n_entries; j++) fprintf(file, "- "); |
---|
1587 | } |
---|
1588 | |
---|
1589 | for (j=0; j<i; j++) fprintf(file, "- "); |
---|
1590 | fprintf(file, "%d ", k); j++; |
---|
1591 | for (; j<n_entries; j++) fprintf(file, "- "); |
---|
1592 | fprintf(file, "%s%d\n", (non_block_wire||rst_ckt)?"":"- ", k); |
---|
1593 | } |
---|
1594 | } else { |
---|
1595 | for (enum_gen=lsStart(domain); |
---|
1596 | lsNext(enum_gen, |
---|
1597 | (lsGeneric*)&enum_elt,&enum_handle)!=LS_NOMORE;) { |
---|
1598 | if (vlTimedSystem && !vlTimedSystem) |
---|
1599 | fg_put_loc_context(file, se->pre_cond, NIL(char)); |
---|
1600 | fprintf(file, " "); |
---|
1601 | put_entry(file, se->syndrome, dc, 1); |
---|
1602 | |
---|
1603 | if (ripple) { |
---|
1604 | for (j=0; j<i; j++) fprintf(file, "- "); |
---|
1605 | fprintf(file, "%d ", 1); j++; |
---|
1606 | for (; j<n_entries; j++) fprintf(file, "- "); |
---|
1607 | } |
---|
1608 | |
---|
1609 | for (j=0; j<i; j++) fprintf(file, "- "); |
---|
1610 | fprintf(file, "%s ", enum_elt->name); j++; |
---|
1611 | for (; j<n_entries; j++) fprintf(file, "- "); |
---|
1612 | fprintf(file, "%s%s\n", |
---|
1613 | (non_block_wire||rst_ckt)?"":"- ", enum_elt->name); |
---|
1614 | } |
---|
1615 | lsFinish(enum_gen); |
---|
1616 | } |
---|
1617 | |
---|
1618 | |
---|
1619 | } |
---|
1620 | lsFinish(lgen); |
---|
1621 | |
---|
1622 | |
---|
1623 | if (deadlock_semantic) { |
---|
1624 | comp = put_guard_zero(file, (!rst_ckt)?id_sym->syndrome_expr_list: |
---|
1625 | id_sym->rst_syndrome_expr_list); |
---|
1626 | if (comp) |
---|
1627 | if (lsLength(comp) > 0 && !(id_sym->flags & RegVar)) { |
---|
1628 | char buf[MAXSTRLEN], tmp_buf[MAXSTRLEN]; |
---|
1629 | strcpy(tmp_buf, id_sym->name); |
---|
1630 | strip_char(tmp_buf,SEP_LATCH); |
---|
1631 | sprintf(buf, "%s: wire '%s' might be unassigned in certain context(s).\n", vl_currentModule->name->name, tmp_buf); |
---|
1632 | strcat(buf, "\tDeadlock is assumed. To make its value a don't care, turn off -k option"); |
---|
1633 | if (WarningLevel > 0) |
---|
1634 | Translate_Notice(buf); |
---|
1635 | } |
---|
1636 | } |
---|
1637 | |
---|
1638 | |
---|
1639 | if (!set_notation && !(deadlock_semantic && non_block_wire)) { |
---|
1640 | comp = put_guard_zero(file, (!rst_ckt)?id_sym->syndrome_expr_list: |
---|
1641 | id_sym->rst_syndrome_expr_list); |
---|
1642 | if (!(id_sym->flags & MVar)) { |
---|
1643 | for (lgen=lsStart(comp); |
---|
1644 | lsNext(lgen,&syndrome,&handle)!=LS_NOMORE;) { |
---|
1645 | if (!(id_sym->flags & MVar)) { |
---|
1646 | lo=0; hi=1; |
---|
1647 | } |
---|
1648 | for (k=lo; k<=hi; k++) { |
---|
1649 | put_entry(file, syndrome, dc, 1); |
---|
1650 | for (j=0; j<n_entries*((ripple)?2:1); j++) |
---|
1651 | fprintf(file, "- "); |
---|
1652 | if (non_block_wire || rst_ckt) |
---|
1653 | fprintf(file, "%d\n", k); |
---|
1654 | else |
---|
1655 | fprintf(file, "%d %d\n", k, k); |
---|
1656 | } |
---|
1657 | } |
---|
1658 | lsFinish(lgen); |
---|
1659 | } else { |
---|
1660 | for (lgen=lsStart(comp); |
---|
1661 | lsNext(lgen,&syndrome,&handle)!=LS_NOMORE;) { |
---|
1662 | if (!(id_sym->flags & MVar)) { |
---|
1663 | lo=0; hi=1; |
---|
1664 | } |
---|
1665 | for (enum_gen=lsStart(domain); |
---|
1666 | lsNext(enum_gen, |
---|
1667 | (lsGeneric*)&enum_elt,&enum_handle)!=LS_NOMORE;) { |
---|
1668 | put_entry(file, syndrome, dc, 1); |
---|
1669 | for (j=0; j<n_entries*((ripple)?2:1); j++) |
---|
1670 | fprintf(file, "- "); |
---|
1671 | if (non_block_wire || rst_ckt) |
---|
1672 | fprintf(file, "%s\n", enum_elt->name); |
---|
1673 | else |
---|
1674 | fprintf(file, "%s %s\n", |
---|
1675 | enum_elt->name, enum_elt->name); |
---|
1676 | } |
---|
1677 | lsFinish(enum_gen); |
---|
1678 | } |
---|
1679 | lsFinish(lgen); |
---|
1680 | } |
---|
1681 | } |
---|
1682 | |
---|
1683 | |
---|
1684 | idx_lo = idx_lo; |
---|
1685 | idx_hi = idx_hi; |
---|
1686 | cur = cur; |
---|
1687 | } |
---|
1688 | |
---|
1689 | |
---|
1690 | void put_nblock_mout_transition(FILE *file, int non_block_wire, |
---|
1691 | int n_entries, |
---|
1692 | vl_id_range *id_sym, |
---|
1693 | int idx_lo, int idx_hi, int cur, |
---|
1694 | char *dc, char *latch_name) |
---|
1695 | { |
---|
1696 | lsGen lgen; |
---|
1697 | lsList comp; |
---|
1698 | lsHandle handle; |
---|
1699 | int lo, hi; |
---|
1700 | int i, j, k; |
---|
1701 | char *syndrome; |
---|
1702 | syndrome_expr *se; |
---|
1703 | |
---|
1704 | for (lgen=lsStart((!rst_ckt)? |
---|
1705 | id_sym->syndrome_expr_list: |
---|
1706 | id_sym->rst_syndrome_expr_list), |
---|
1707 | i=0; |
---|
1708 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE; i++) { |
---|
1709 | if (!(id_sym->flags & MVar)) { |
---|
1710 | lo=0; hi=1; |
---|
1711 | } else { |
---|
1712 | get_hilo(id_sym, &hi, &lo); |
---|
1713 | } |
---|
1714 | |
---|
1715 | if (vlTimedSystem && !rst_ckt) |
---|
1716 | fg_put_loc_context(file, se->pre_cond, NIL(char)); |
---|
1717 | fprintf(file, " "); |
---|
1718 | put_entry(file, se->syndrome, dc, 1); |
---|
1719 | |
---|
1720 | for (j=0; j<n_entries; j++) |
---|
1721 | if (idx_lo == 0 && idx_hi == -1) |
---|
1722 | fprintf(file, "- "); |
---|
1723 | else |
---|
1724 | for (k=idx_lo; k<=idx_hi; k++) fprintf(file, "- "); |
---|
1725 | if (!(non_block_wire||rst_ckt)) { |
---|
1726 | if (idx_lo == 0 && idx_hi == -1) |
---|
1727 | fprintf(file, "- "); |
---|
1728 | else |
---|
1729 | for (k=idx_lo; k<=idx_hi; k++) |
---|
1730 | fprintf(file, "- "); |
---|
1731 | } |
---|
1732 | if (id_sym->flags & MVar || (idx_lo==0 && idx_hi==-1)) { |
---|
1733 | fprintf(file, "%s%s\n", HSIS_EQUAL, se->expr->name->name); |
---|
1734 | } else { |
---|
1735 | for (k=idx_lo; k<=idx_hi; k++) { |
---|
1736 | fprintf(file, "%s%s%s%d%s ", HSIS_EQUAL, |
---|
1737 | se->expr->name->name, |
---|
1738 | SEP_LBITSELECT, k, SEP_RBITSELECT); |
---|
1739 | } |
---|
1740 | fprintf(file, "\n"); |
---|
1741 | } |
---|
1742 | } |
---|
1743 | lsFinish(lgen); |
---|
1744 | |
---|
1745 | |
---|
1746 | if (deadlock_semantic) { |
---|
1747 | comp = put_guard_zero(file, (!rst_ckt)?id_sym->syndrome_expr_list: |
---|
1748 | id_sym->rst_syndrome_expr_list); |
---|
1749 | if (comp) |
---|
1750 | if (lsLength(comp) > 0 && !(id_sym->flags & RegVar)) { |
---|
1751 | char buf[MAXSTRLEN], tmp_buf[MAXSTRLEN]; |
---|
1752 | strcpy(tmp_buf, id_sym->name); |
---|
1753 | strip_char(tmp_buf,SEP_LATCH); |
---|
1754 | sprintf(buf, "%s: wire '%s' might be unassigned in certain context(s).\n", vl_currentModule->name->name, tmp_buf); |
---|
1755 | strcat(buf, "\tDeadlock is assumed. To make its value a don't care, use -k option"); |
---|
1756 | if (WarningLevel > 0) |
---|
1757 | Translate_Notice(buf); |
---|
1758 | } |
---|
1759 | } |
---|
1760 | |
---|
1761 | |
---|
1762 | if (!set_notation && !(deadlock_semantic && non_block_wire)) { |
---|
1763 | comp = put_guard_zero(file, (!rst_ckt)?id_sym->syndrome_expr_list: |
---|
1764 | id_sym->rst_syndrome_expr_list); |
---|
1765 | for (lgen=lsStart(comp); |
---|
1766 | lsNext(lgen,&syndrome,&handle)!=LS_NOMORE;) { |
---|
1767 | |
---|
1768 | put_entry(file, syndrome, dc, 1); |
---|
1769 | for (j=0; j<n_entries; j++) |
---|
1770 | if (idx_lo == 0 && idx_hi == -1) |
---|
1771 | fprintf(file, "- "); |
---|
1772 | else |
---|
1773 | for (k=idx_lo; k<=idx_hi; k++) fprintf(file, "- "); |
---|
1774 | if (!(non_block_wire || rst_ckt)) { |
---|
1775 | if (idx_lo == 0 && idx_hi == -1) |
---|
1776 | fprintf(file, "- "); |
---|
1777 | else |
---|
1778 | for (k=idx_lo; k<=idx_hi; k++) |
---|
1779 | fprintf(file, "- "); |
---|
1780 | } |
---|
1781 | if (id_sym->flags & MVar || (idx_lo==0 && idx_hi==-1)) { |
---|
1782 | if (!(non_block_wire || rst_ckt)) { |
---|
1783 | fprintf(file, "%s%s\n", HSIS_EQUAL, latch_name); |
---|
1784 | } else { |
---|
1785 | fprintf(file, "-\n"); |
---|
1786 | } |
---|
1787 | } else { |
---|
1788 | if (!(non_block_wire || rst_ckt)) |
---|
1789 | for (k=idx_lo; k<=idx_hi; k++) { |
---|
1790 | fprintf(file, "%s%s%s%d%s ", HSIS_EQUAL, |
---|
1791 | latch_name, SEP_LBITSELECT, k, SEP_RBITSELECT); |
---|
1792 | } |
---|
1793 | else |
---|
1794 | for (k=idx_lo; k<=idx_hi; k++) { |
---|
1795 | fprintf(file,"-"); |
---|
1796 | } |
---|
1797 | fprintf(file, "\n"); |
---|
1798 | } |
---|
1799 | } |
---|
1800 | |
---|
1801 | lsFinish(lgen); |
---|
1802 | } |
---|
1803 | |
---|
1804 | |
---|
1805 | cur = cur; |
---|
1806 | } |
---|
1807 | |
---|
1808 | |
---|
1809 | void create_wire_nondeterminism(FILE *file, char * var_name, |
---|
1810 | vl_id_range *id_sym, array_t *vars_array) |
---|
1811 | { |
---|
1812 | char buf[MAXSTRLEN]; |
---|
1813 | char input_buf[MAXSTRLEN]; |
---|
1814 | char *cp; |
---|
1815 | st_table *vars; |
---|
1816 | var_info *cur_var; |
---|
1817 | int h, i, j, k; |
---|
1818 | int hi, lo; |
---|
1819 | int num_changer=0; |
---|
1820 | lsList domain; |
---|
1821 | lsGen enum_gen; |
---|
1822 | lsHandle enum_handle; |
---|
1823 | vl_enumerator *enum_elt; |
---|
1824 | |
---|
1825 | |
---|
1826 | get_hilo(id_sym, &hi, &lo); |
---|
1827 | |
---|
1828 | cp = buf; *cp = '\0'; |
---|
1829 | cp = strappend(cp, ".names "); |
---|
1830 | for (i=0; i<array_n(vars_array); i++) { |
---|
1831 | vars = array_fetch(st_table*, vars_array, i); |
---|
1832 | if (vars) { |
---|
1833 | if (st_lookup(vars, var_name, (char**)&cur_var)) { |
---|
1834 | num_changer++; |
---|
1835 | cp = strappendS(cp, |
---|
1836 | cur_var->current_terminal->name->name); |
---|
1837 | } |
---|
1838 | } |
---|
1839 | } |
---|
1840 | strcpy(input_buf, buf); |
---|
1841 | if (!num_changer) |
---|
1842 | if (!((id_sym->flags & OutPort) && Zconnection)) |
---|
1843 | return; |
---|
1844 | |
---|
1845 | |
---|
1846 | if (id_sym->flags &MVar) { |
---|
1847 | fprintf(file, "%s %s\n", buf, id_sym->name); |
---|
1848 | |
---|
1849 | if (set_notation) { |
---|
1850 | for (i=0; i<array_n(vars_array); i++) { |
---|
1851 | vars = array_fetch(st_table*, vars_array, i); |
---|
1852 | if (vars) { |
---|
1853 | if (st_lookup(vars, var_name, (char**)&cur_var)) { |
---|
1854 | for (j=0; j<num_changer; j++) { |
---|
1855 | fprintf(file, "- "); |
---|
1856 | } |
---|
1857 | fprintf(file, "%s%s\n", HSIS_EQUAL, |
---|
1858 | cur_var->current_terminal->name->name); |
---|
1859 | } |
---|
1860 | } |
---|
1861 | } |
---|
1862 | } else { |
---|
1863 | domain = id_sym->id_type->specifier->u.enum_type->domain_list; |
---|
1864 | for (i=0; i<num_changer; i++) { |
---|
1865 | for (enum_gen=lsStart(domain); |
---|
1866 | lsNext(enum_gen, |
---|
1867 | (lsGeneric*)&enum_elt,&enum_handle)!=LS_NOMORE;) { |
---|
1868 | for (k=0; k<num_changer; k++) { |
---|
1869 | fprintf(file, "%s ", (i==k)?enum_elt->name:"-"); |
---|
1870 | } |
---|
1871 | fprintf(file, "%s\n", enum_elt->name); |
---|
1872 | } |
---|
1873 | lsFinish(enum_gen); |
---|
1874 | } |
---|
1875 | } |
---|
1876 | |
---|
1877 | } else if (lo > hi) { |
---|
1878 | |
---|
1879 | fprintf(file, "%s %s\n", buf, id_sym->name); |
---|
1880 | |
---|
1881 | for (i=0; i<num_changer; i++) { |
---|
1882 | for (j=0; j<=1; j++) { |
---|
1883 | for (k=0; k<num_changer; k++) { |
---|
1884 | fprintf(file, "%c ", (i==k)?'0'+j:'-'); |
---|
1885 | } |
---|
1886 | fprintf(file, "%d\n", j); |
---|
1887 | } |
---|
1888 | } |
---|
1889 | |
---|
1890 | } else { |
---|
1891 | array_t *ctrlv; |
---|
1892 | |
---|
1893 | for (h=lo; h<=hi; h++) { |
---|
1894 | cp = buf; *cp = '\0'; |
---|
1895 | cp = strappend(cp, ".names "); |
---|
1896 | ctrlv = array_alloc(char*,0); |
---|
1897 | for (i=0, num_changer=0; i<array_n(vars_array); i++) { |
---|
1898 | vars = array_fetch(st_table*, vars_array, i); |
---|
1899 | if (vars) { |
---|
1900 | if (st_lookup(vars, var_name, (char**)&cur_var)) { |
---|
1901 | char tmp_buf[MAXSTRLEN]; |
---|
1902 | int real_changer = 0; |
---|
1903 | if (h == lo && |
---|
1904 | cur_var->current_terminal->lo > |
---|
1905 | cur_var->current_terminal->hi) |
---|
1906 | real_changer = 1; |
---|
1907 | if (cur_var->current_terminal->lo <= |
---|
1908 | cur_var->current_terminal->hi) |
---|
1909 | if (cur_var->current_terminal->lo <= h && |
---|
1910 | cur_var->current_terminal->hi >= h) |
---|
1911 | real_changer = 1; |
---|
1912 | if (real_changer) { |
---|
1913 | num_changer++; |
---|
1914 | |
---|
1915 | sprintf(tmp_buf, "%s%s%d%s", |
---|
1916 | cur_var->current_terminal->name->name, |
---|
1917 | SEP_LBITSELECT, h, SEP_RBITSELECT); |
---|
1918 | cp = strappendS(cp, tmp_buf); |
---|
1919 | array_insert_last(char*,ctrlv, |
---|
1920 | vlStrdup(cur_var->current_terminal->name->name)); |
---|
1921 | } |
---|
1922 | } |
---|
1923 | } |
---|
1924 | } |
---|
1925 | if (!num_changer) continue; |
---|
1926 | fprintf(file, "%s %s%s%d%s\n", buf, id_sym->name, |
---|
1927 | SEP_LBITSELECT, h, SEP_RBITSELECT); |
---|
1928 | if (set_notation) { |
---|
1929 | for (i=0; i<num_changer; i++) { |
---|
1930 | for (k=0; k<num_changer; k++) { |
---|
1931 | fprintf(file, "- "); |
---|
1932 | } |
---|
1933 | fprintf(file, "%s%s%s%d%s\n", HSIS_EQUAL, |
---|
1934 | array_fetch(char*, ctrlv, i), |
---|
1935 | SEP_LBITSELECT, h, SEP_RBITSELECT); |
---|
1936 | } |
---|
1937 | } else { |
---|
1938 | for (i=0; i<num_changer; i++) { |
---|
1939 | for (j=0; j<=1; j++) { |
---|
1940 | for (k=0; k<num_changer; k++) { |
---|
1941 | fprintf(file, "%c ", (i==k)?'0'+j:'-'); |
---|
1942 | } |
---|
1943 | fprintf(file, "%d\n", j); |
---|
1944 | } |
---|
1945 | } |
---|
1946 | } |
---|
1947 | |
---|
1948 | for (i=0; i<array_n(ctrlv); i++) |
---|
1949 | vl_chk_free(array_fetch(char*, ctrlv, i)); |
---|
1950 | array_free(ctrlv); |
---|
1951 | |
---|
1952 | } |
---|
1953 | } |
---|
1954 | } |
---|
1955 | |
---|
1956 | |
---|
1957 | vl_term *put_quasi_control(FILE *file, char *dc, char *quasi_name, vl_id_range *id_sym, int n_entries) |
---|
1958 | { |
---|
1959 | int ith_var; |
---|
1960 | vl_term *ctrl_term; |
---|
1961 | vl_term *retval; |
---|
1962 | lsGen lgen; |
---|
1963 | lsHandle handle; |
---|
1964 | syndrome_expr *se; |
---|
1965 | int retval_width, retval_range; |
---|
1966 | char buf[MAXSTRLEN]; |
---|
1967 | |
---|
1968 | retval_range = lsLength((!rst_ckt)? |
---|
1969 | id_sym->syndrome_expr_list: |
---|
1970 | id_sym->rst_syndrome_expr_list); |
---|
1971 | retval_width = min_bit_width(retval_range); |
---|
1972 | retval = new_term(NIL(vl_range), 0, retval_width-1); |
---|
1973 | fprintf(file, ".mv %s,%s%s%s %d\n", |
---|
1974 | retval->name->name, retval->name->name, SEP_GATEPIN, PIN_NS, |
---|
1975 | n_entries+1); |
---|
1976 | fprintf(file, ".latch %s%s%s %s\n", |
---|
1977 | retval->name->name, SEP_GATEPIN, PIN_NS, retval->name->name); |
---|
1978 | fprintf(file, ".r %s\n0\n", retval->name->name); |
---|
1979 | |
---|
1980 | |
---|
1981 | fprintf(file, ".names "); |
---|
1982 | |
---|
1983 | for (lgen=lsStart((!rst_ckt)?ctrl_list:rst_ctrl_list), ith_var=0; |
---|
1984 | lsNext(lgen,(lsGeneric*)&ctrl_term,&handle)!=LS_NOMORE; |
---|
1985 | ith_var++) { |
---|
1986 | if (!dc[ith_var]) fprintf(file, "%s ", ctrl_term->name->name); |
---|
1987 | } |
---|
1988 | (void)lsFinish(lgen); |
---|
1989 | |
---|
1990 | fprintf(file, "%s %s%s%s\n", |
---|
1991 | retval->name->name, retval->name->name, SEP_GATEPIN, PIN_NS); |
---|
1992 | |
---|
1993 | fprintf(file, "%s %s%s\n", |
---|
1994 | HSIS_DEFAULT, HSIS_EQUAL, retval->name->name); |
---|
1995 | |
---|
1996 | for (lgen=lsStart((!rst_ckt)? |
---|
1997 | id_sym->syndrome_expr_list: |
---|
1998 | id_sym->rst_syndrome_expr_list), ith_var=0; |
---|
1999 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE; |
---|
2000 | ith_var++) { |
---|
2001 | if (vlTimedSystem && !rst_ckt) |
---|
2002 | fg_put_loc_context(file, se->pre_cond, NIL(char)); |
---|
2003 | fprintf(file, " "); |
---|
2004 | put_entry(file, se->syndrome, dc, 1); |
---|
2005 | fprintf(file, "- %d\n", |
---|
2006 | (strcmp(se->expr->name->name,quasi_name))?ith_var+1:0); |
---|
2007 | } |
---|
2008 | (void)lsFinish(lgen); |
---|
2009 | |
---|
2010 | sprintf(buf, "%s%s%s", retval->name->name, SEP_GATEPIN, PIN_NS); |
---|
2011 | vl_chk_free(retval->name->name); |
---|
2012 | retval->name->name = vlStrdup(buf); |
---|
2013 | |
---|
2014 | return retval; |
---|
2015 | } |
---|
2016 | |
---|
2017 | |
---|
2018 | void put_quasi_table(FILE *file, char *dc, char *quasi_name, char *sync_name, |
---|
2019 | vl_id_range *id_sym, vl_term *out_term, int lo, int hi, |
---|
2020 | int n_entries) |
---|
2021 | { |
---|
2022 | int ith_var, j; |
---|
2023 | lsGen lgen; |
---|
2024 | lsHandle handle; |
---|
2025 | syndrome_expr *se; |
---|
2026 | vl_term *ctrl_term; |
---|
2027 | |
---|
2028 | |
---|
2029 | ctrl_term = put_quasi_control(file, dc, quasi_name, id_sym, n_entries); |
---|
2030 | |
---|
2031 | if (hi < lo) { |
---|
2032 | |
---|
2033 | |
---|
2034 | fprintf(file, ".names %s ", ctrl_term->name->name); |
---|
2035 | |
---|
2036 | for (lgen=lsStart((!rst_ckt)? |
---|
2037 | id_sym->syndrome_expr_list: |
---|
2038 | id_sym->rst_syndrome_expr_list); |
---|
2039 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE;) { |
---|
2040 | fprintf(file, "%s ", se->expr->name->name); |
---|
2041 | } |
---|
2042 | (void)lsFinish(lgen); |
---|
2043 | fprintf(file, "%s ", sync_name); |
---|
2044 | |
---|
2045 | fprintf(file, "%s\n", out_term->name->name); |
---|
2046 | |
---|
2047 | |
---|
2048 | for (lgen=lsStart((!rst_ckt)? |
---|
2049 | id_sym->syndrome_expr_list: |
---|
2050 | id_sym->rst_syndrome_expr_list), ith_var=0; |
---|
2051 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE; |
---|
2052 | ith_var++) { |
---|
2053 | if (strcmp(se->expr->name->name, quasi_name)) { |
---|
2054 | fprintf(file, "%d ", ith_var+1); |
---|
2055 | for (j=0; j<n_entries; j++) fprintf(file, "- "); |
---|
2056 | fprintf(file, "- %s%s\n", HSIS_EQUAL,se->expr->name->name); |
---|
2057 | } |
---|
2058 | } |
---|
2059 | (void)lsFinish(lgen); |
---|
2060 | fprintf(file, "0 "); |
---|
2061 | for (j=0; j<n_entries; j++) fprintf(file, "- "); |
---|
2062 | fprintf(file, "- %s%s\n", HSIS_EQUAL, sync_name); |
---|
2063 | } else { |
---|
2064 | int bit; |
---|
2065 | |
---|
2066 | |
---|
2067 | fprintf(file, ".names %s ", ctrl_term->name->name); |
---|
2068 | |
---|
2069 | for (lgen=lsStart((!rst_ckt)? |
---|
2070 | id_sym->syndrome_expr_list: |
---|
2071 | id_sym->rst_syndrome_expr_list); |
---|
2072 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE;) { |
---|
2073 | for (bit=lo; bit<=hi; bit++) |
---|
2074 | fprintf(file, "%s%s%d%s ", se->expr->name->name, |
---|
2075 | SEP_LBITSELECT, bit, SEP_RBITSELECT); |
---|
2076 | } |
---|
2077 | (void)lsFinish(lgen); |
---|
2078 | |
---|
2079 | for (bit=lo; bit<=hi; bit++) |
---|
2080 | fprintf(file, "%s%s%d%s%s%s ", quasi_name, |
---|
2081 | SEP_LBITSELECT, bit, SEP_RBITSELECT, |
---|
2082 | SEP_GATEPIN, PIN_PS); |
---|
2083 | |
---|
2084 | fprintf(file, "%s ", HSIS_ARROW); |
---|
2085 | for (bit=lo; bit<=hi; bit++) |
---|
2086 | fprintf(file, "%s%s%d%s ", out_term->name->name, |
---|
2087 | SEP_LBITSELECT, bit, SEP_RBITSELECT); |
---|
2088 | fprintf(file, "\n"); |
---|
2089 | |
---|
2090 | |
---|
2091 | for (lgen=lsStart((!rst_ckt)? |
---|
2092 | id_sym->syndrome_expr_list: |
---|
2093 | id_sym->rst_syndrome_expr_list), ith_var=0; |
---|
2094 | lsNext(lgen,(lsGeneric*)&se,&handle)!=LS_NOMORE; |
---|
2095 | ith_var++) { |
---|
2096 | if (strcmp(se->expr->name->name, quasi_name)) { |
---|
2097 | fprintf(file, "%d ", ith_var+1); |
---|
2098 | for (j=0; j<n_entries; j++) |
---|
2099 | for (bit=lo; bit<=hi; bit++) fprintf(file, "- "); |
---|
2100 | for (bit=lo; bit<=hi; bit++) fprintf(file, "- "); |
---|
2101 | for (bit=lo; bit<=hi; bit++) |
---|
2102 | fprintf(file, "%s%s%s%d%s ", |
---|
2103 | HSIS_EQUAL,se->expr->name->name, |
---|
2104 | SEP_LBITSELECT, bit, SEP_RBITSELECT); |
---|
2105 | fprintf(file, "\n"); |
---|
2106 | } |
---|
2107 | } |
---|
2108 | (void)lsFinish(lgen); |
---|
2109 | fprintf(file, "0 "); |
---|
2110 | for (j=0; j<n_entries; j++) |
---|
2111 | for (bit=lo; bit<=hi; bit++) fprintf(file, "- "); |
---|
2112 | for (bit=lo; bit<=hi; bit++) fprintf(file, "- "); |
---|
2113 | |
---|
2114 | for (bit=lo; bit<=hi; bit++) |
---|
2115 | fprintf(file, "%s%s%s%d%s%s%s ", |
---|
2116 | HSIS_EQUAL, quasi_name, |
---|
2117 | SEP_LBITSELECT, bit, SEP_RBITSELECT, |
---|
2118 | SEP_GATEPIN, PIN_PS); |
---|
2119 | fprintf(file, "\n"); |
---|
2120 | } |
---|
2121 | } |
---|
2122 | |
---|
2123 | |
---|
2124 | void declare_mvar_io(FILE *file, char *dir, vl_id_range *id_sym) |
---|
2125 | { |
---|
2126 | int idx, idx_hi, idx_lo; |
---|
2127 | |
---|
2128 | if (!id_sym->range) { |
---|
2129 | fprintf(file, "%s %s", dir, id_sym->name); |
---|
2130 | fprintf(file, "\n"); |
---|
2131 | } else { |
---|
2132 | idx_lo = vl_eval_expr(id_sym->range->left); |
---|
2133 | if (id_sym->range->right) |
---|
2134 | idx_hi = vl_eval_expr(id_sym->range->right); |
---|
2135 | else |
---|
2136 | idx_hi = idx_lo; |
---|
2137 | |
---|
2138 | for (idx = idx_lo; idx <= idx_hi; idx++) { |
---|
2139 | fprintf(file, "%s %s%s%d%s", dir, |
---|
2140 | id_sym->name, SEP_LARRAY, idx, SEP_RARRAY); |
---|
2141 | fprintf(file, "\n"); |
---|
2142 | } |
---|
2143 | } |
---|
2144 | } |
---|
2145 | |
---|
2146 | void declare_bin_scalar_io(FILE *file, char *dir, vl_id_range *id_sym) |
---|
2147 | { |
---|
2148 | int idx, idx_lo, idx_hi; |
---|
2149 | |
---|
2150 | if (!id_sym->range) { |
---|
2151 | fprintf(file, "%s %s", dir, id_sym->name); |
---|
2152 | fprintf(file, "\n"); |
---|
2153 | } else { |
---|
2154 | idx_lo = vl_eval_expr(id_sym->range->left); |
---|
2155 | if (id_sym->range->right) |
---|
2156 | idx_hi = vl_eval_expr(id_sym->range->right); |
---|
2157 | else |
---|
2158 | idx_hi = idx_lo; |
---|
2159 | |
---|
2160 | for (idx = idx_lo; idx <= idx_hi; idx++) { |
---|
2161 | fprintf(file, "%s %s%s%d%s", dir, |
---|
2162 | id_sym->name, SEP_LARRAY, idx, SEP_RARRAY); |
---|
2163 | fprintf(file, "\n"); |
---|
2164 | } |
---|
2165 | } |
---|
2166 | } |
---|
2167 | |
---|
2168 | void declare_bin_vector_io(FILE *file, char *dir, vl_id_range *id_sym) |
---|
2169 | { |
---|
2170 | int idx, idx_lo, idx_hi; |
---|
2171 | int i, lo, hi; |
---|
2172 | int ithItem; |
---|
2173 | |
---|
2174 | get_hilo(id_sym, &hi, &lo); |
---|
2175 | |
---|
2176 | if (!id_sym->range) { |
---|
2177 | fprintf(file, "%s ", dir); |
---|
2178 | ithItem = 0; |
---|
2179 | for (i=lo; i<=hi; i++) { |
---|
2180 | char buf[MAXSTRLEN]; |
---|
2181 | |
---|
2182 | sprintf(buf, "%s%s%d%s", id_sym->name, |
---|
2183 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
2184 | fprintf(file, "%s ", buf); |
---|
2185 | } |
---|
2186 | fprintf(file, "\n"); |
---|
2187 | } else { |
---|
2188 | idx_lo = vl_eval_expr(id_sym->range->left); |
---|
2189 | if (id_sym->range->right) |
---|
2190 | idx_hi = vl_eval_expr(id_sym->range->right); |
---|
2191 | else |
---|
2192 | idx_hi = idx_lo; |
---|
2193 | |
---|
2194 | for (idx = idx_lo; idx <= idx_hi; idx++) { |
---|
2195 | fprintf(file, "%s ", dir); |
---|
2196 | for (i=lo; i<=hi; i++) { |
---|
2197 | char buf[MAXSTRLEN]; |
---|
2198 | |
---|
2199 | sprintf(buf, "%s%s%d%s%s%d%s", id_sym->name, |
---|
2200 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2201 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
2202 | fprintf(file, "%s ", buf); |
---|
2203 | } |
---|
2204 | fprintf(file, "\n"); |
---|
2205 | } |
---|
2206 | } |
---|
2207 | } |
---|
2208 | |
---|
2209 | |
---|
2210 | void put_const_port_connect(FILE *file, char *outstr, |
---|
2211 | vl_id_range *master, |
---|
2212 | vl_port_connect *instance, |
---|
2213 | lsList input_consts, |
---|
2214 | vl_term *term_out) |
---|
2215 | { |
---|
2216 | int i, hi, lo; |
---|
2217 | char buf[MAXSTRLEN]; |
---|
2218 | |
---|
2219 | get_hilo(master, &hi, &lo); |
---|
2220 | if (isMVar(master->flags)) { |
---|
2221 | |
---|
2222 | sprintf(buf, "%s=%s ", master->name, term_out->name->name); |
---|
2223 | } else { |
---|
2224 | |
---|
2225 | if (lo > hi) { |
---|
2226 | |
---|
2227 | sprintf(buf, "%s=%s ", |
---|
2228 | master->name, term_out->name->name); |
---|
2229 | } else { |
---|
2230 | |
---|
2231 | char tmp[MAXSTRLEN]; |
---|
2232 | |
---|
2233 | buf[0] = '\0'; |
---|
2234 | for (i=lo; i<=hi; i++) { |
---|
2235 | sprintf(tmp, "%s%s%d%s=%s%s%d%s ", |
---|
2236 | master->name, |
---|
2237 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
2238 | term_out->name->name, |
---|
2239 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
2240 | strcat(buf, tmp); |
---|
2241 | } |
---|
2242 | } |
---|
2243 | } |
---|
2244 | |
---|
2245 | if (file) fprintf(file, "%s", buf); |
---|
2246 | if (outstr) sprintf(outstr, "%s", buf); |
---|
2247 | } |
---|
2248 | |
---|
2249 | |
---|
2250 | void put_mvar_port_connect(FILE *file, char *outstr, |
---|
2251 | vl_id_range *master, |
---|
2252 | vl_port_connect *instance) |
---|
2253 | { |
---|
2254 | int idx, idx_lo, idx_hi; |
---|
2255 | char buf[MAXSTRLEN]; |
---|
2256 | |
---|
2257 | if (!master->range) { |
---|
2258 | sprintf(buf, "%s=%s ", |
---|
2259 | master->name, |
---|
2260 | instance->expr->term->name->name); |
---|
2261 | } else { |
---|
2262 | char tmp[MAXSTRLEN]; |
---|
2263 | |
---|
2264 | buf[0] = '\0'; |
---|
2265 | idx_lo = vl_eval_expr(master->range->left); |
---|
2266 | if (master->range->right) |
---|
2267 | idx_hi = vl_eval_expr(master->range->right); |
---|
2268 | else |
---|
2269 | idx_hi = idx_lo; |
---|
2270 | |
---|
2271 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
2272 | sprintf(tmp, "%s%s%d%s=%s%s%d%s ", |
---|
2273 | master->name, SEP_LARRAY, idx, SEP_RARRAY, |
---|
2274 | instance->expr->term->name->name, |
---|
2275 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
2276 | strcat(buf, tmp); |
---|
2277 | } |
---|
2278 | } |
---|
2279 | |
---|
2280 | if (file) fprintf(file, "%s", buf); |
---|
2281 | if (outstr) sprintf(outstr, "%s", buf); |
---|
2282 | } |
---|
2283 | |
---|
2284 | |
---|
2285 | void put_bin_scalar_port_connect(FILE *file, char *outstr, |
---|
2286 | vl_id_range *master, |
---|
2287 | vl_port_connect *instance) |
---|
2288 | { |
---|
2289 | int idx, idx_lo, idx_hi; |
---|
2290 | char buf[MAXSTRLEN]; |
---|
2291 | |
---|
2292 | if (instance->expr->term->lo > instance->expr->term->hi){ |
---|
2293 | if (!master->range) { |
---|
2294 | sprintf(buf, "%s=%s ", |
---|
2295 | master->name, |
---|
2296 | instance->expr->term->name->name); |
---|
2297 | } else { |
---|
2298 | char tmp[MAXSTRLEN]; |
---|
2299 | |
---|
2300 | buf[0] = '\0'; |
---|
2301 | idx_lo = vl_eval_expr(master->range->left); |
---|
2302 | if (master->range->right) |
---|
2303 | idx_hi = vl_eval_expr(master->range->right); |
---|
2304 | else |
---|
2305 | idx_hi = idx_lo; |
---|
2306 | |
---|
2307 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
2308 | sprintf(tmp, "%s%s%d%s=%s%s%d%s ", |
---|
2309 | master->name, |
---|
2310 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2311 | instance->expr->term->name->name, |
---|
2312 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
2313 | strcat(buf, tmp); |
---|
2314 | } |
---|
2315 | } |
---|
2316 | } else { |
---|
2317 | if (!master->range) { |
---|
2318 | sprintf(buf, "%s=%s%s%d%s ", |
---|
2319 | master->name, |
---|
2320 | instance->expr->term->name->name, |
---|
2321 | SEP_LBITSELECT, |
---|
2322 | instance->expr->term->lo, |
---|
2323 | SEP_RBITSELECT); |
---|
2324 | } else { |
---|
2325 | char tmp[MAXSTRLEN]; |
---|
2326 | |
---|
2327 | buf[0] = '\0'; |
---|
2328 | idx_lo = vl_eval_expr(master->range->left); |
---|
2329 | if (master->range->right) |
---|
2330 | idx_hi = vl_eval_expr(master->range->right); |
---|
2331 | else |
---|
2332 | idx_hi = idx_lo; |
---|
2333 | |
---|
2334 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
2335 | sprintf(tmp, "%s%s%d%s=%s%s%d%s%s%d%s ", |
---|
2336 | master->name, |
---|
2337 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2338 | instance->expr->term->name->name, |
---|
2339 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2340 | SEP_LBITSELECT, |
---|
2341 | instance->expr->term->lo, |
---|
2342 | SEP_RBITSELECT); |
---|
2343 | strcat(buf, tmp); |
---|
2344 | } |
---|
2345 | } |
---|
2346 | } |
---|
2347 | |
---|
2348 | if (file) fprintf(file, "%s", buf); |
---|
2349 | if (outstr) sprintf(outstr, "%s", buf); |
---|
2350 | } |
---|
2351 | |
---|
2352 | |
---|
2353 | void put_bin_vector_port_connect(FILE *file, char *outstr, |
---|
2354 | vl_id_range *master, |
---|
2355 | vl_port_connect *instance) |
---|
2356 | { |
---|
2357 | int sig_lo; |
---|
2358 | int lo, hi; |
---|
2359 | int idx, idx_lo, idx_hi; |
---|
2360 | int i; |
---|
2361 | char buf[MAXSTRLEN]; |
---|
2362 | |
---|
2363 | get_hilo(master, &hi, &lo); |
---|
2364 | sig_lo = instance->expr->term->lo; |
---|
2365 | |
---|
2366 | if (!master->range) { |
---|
2367 | char tmp[MAXSTRLEN]; |
---|
2368 | |
---|
2369 | buf[0] = '\0'; |
---|
2370 | for (i=lo; i<=hi; i++) { |
---|
2371 | char mast_buf[MAXSTRLEN]; |
---|
2372 | char inst_buf[MAXSTRLEN]; |
---|
2373 | |
---|
2374 | sprintf(mast_buf, "%s%s%d%s", master->name, |
---|
2375 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
2376 | sprintf(inst_buf, "%s%s%d%s", |
---|
2377 | instance->expr->term->name->name, |
---|
2378 | SEP_LBITSELECT,sig_lo-lo+i,SEP_RBITSELECT); |
---|
2379 | sprintf(tmp, "%s=%s ", mast_buf, inst_buf); |
---|
2380 | strcat(buf, tmp); |
---|
2381 | } |
---|
2382 | } else { |
---|
2383 | idx_lo = vl_eval_expr(master->range->left); |
---|
2384 | if (master->range->right) |
---|
2385 | idx_hi = vl_eval_expr(master->range->right); |
---|
2386 | else |
---|
2387 | idx_hi = idx_lo; |
---|
2388 | |
---|
2389 | { |
---|
2390 | char tmp[MAXSTRLEN]; |
---|
2391 | |
---|
2392 | buf[0] = '\0'; |
---|
2393 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
2394 | for (i=lo; i<=hi; i++) { |
---|
2395 | char mast_buf[MAXSTRLEN]; |
---|
2396 | char inst_buf[MAXSTRLEN]; |
---|
2397 | |
---|
2398 | sprintf(mast_buf, "%s%s%d%s%s%d%s", master->name, |
---|
2399 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2400 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
2401 | sprintf(inst_buf, "%s%s%d%s%s%d%s", |
---|
2402 | instance->expr->term->name->name, |
---|
2403 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2404 | SEP_LBITSELECT, |
---|
2405 | sig_lo-lo+i, |
---|
2406 | SEP_RBITSELECT); |
---|
2407 | sprintf(tmp, "%s=%s ", mast_buf, inst_buf); |
---|
2408 | strcat(buf, tmp); |
---|
2409 | } |
---|
2410 | } |
---|
2411 | } |
---|
2412 | } |
---|
2413 | |
---|
2414 | if (file) fprintf(file, "%s", buf); |
---|
2415 | if (outstr) sprintf(outstr, "%s", buf); |
---|
2416 | } |
---|
2417 | |
---|
2418 | |
---|
2419 | void put_bin_scalar_func_connect(FILE *file, vl_id_range *master, |
---|
2420 | vl_term *instance) |
---|
2421 | { |
---|
2422 | int idx, idx_lo, idx_hi; |
---|
2423 | |
---|
2424 | if (instance->lo > instance->hi){ |
---|
2425 | if (!master->range) { |
---|
2426 | fprintf(file, "%s=%s ", |
---|
2427 | master->name, |
---|
2428 | instance->name->name); |
---|
2429 | } else { |
---|
2430 | idx_lo = vl_eval_expr(master->range->left); |
---|
2431 | if (master->range->right) |
---|
2432 | idx_hi = vl_eval_expr(master->range->right); |
---|
2433 | else |
---|
2434 | idx_hi = idx_lo; |
---|
2435 | |
---|
2436 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
2437 | fprintf(file, "%s%s%d%s=%s%s%d%s ", |
---|
2438 | master->name, |
---|
2439 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2440 | instance->name->name, |
---|
2441 | SEP_LARRAY, idx, SEP_RARRAY); |
---|
2442 | } |
---|
2443 | } |
---|
2444 | } else { |
---|
2445 | if (!master->range) { |
---|
2446 | fprintf(file, "%s=%s%s%d%s ", |
---|
2447 | master->name, |
---|
2448 | instance->name->name, |
---|
2449 | SEP_LBITSELECT, |
---|
2450 | instance->lo, |
---|
2451 | SEP_RBITSELECT); |
---|
2452 | } else { |
---|
2453 | idx_lo = vl_eval_expr(master->range->left); |
---|
2454 | if (master->range->right) |
---|
2455 | idx_hi = vl_eval_expr(master->range->right); |
---|
2456 | else |
---|
2457 | idx_hi = idx_lo; |
---|
2458 | |
---|
2459 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
2460 | fprintf(file, "%s%s%d%s=%s%s%d%s%s%d%s ", |
---|
2461 | master->name, |
---|
2462 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2463 | instance->name->name, |
---|
2464 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2465 | SEP_LBITSELECT, |
---|
2466 | instance->lo, |
---|
2467 | SEP_RBITSELECT); |
---|
2468 | } |
---|
2469 | } |
---|
2470 | } |
---|
2471 | } |
---|
2472 | |
---|
2473 | |
---|
2474 | void put_bin_vector_func_connect(FILE *file, vl_id_range *master, |
---|
2475 | vl_term *instance) |
---|
2476 | { |
---|
2477 | int sig_lo; |
---|
2478 | int lo, hi; |
---|
2479 | int idx, idx_lo, idx_hi; |
---|
2480 | int i; |
---|
2481 | |
---|
2482 | get_hilo(master, &hi, &lo); |
---|
2483 | sig_lo = instance->lo; |
---|
2484 | |
---|
2485 | if (!master->range) { |
---|
2486 | for (i=lo; i<=hi; i++) { |
---|
2487 | char mast_buf[MAXSTRLEN]; |
---|
2488 | char inst_buf[MAXSTRLEN]; |
---|
2489 | |
---|
2490 | sprintf(mast_buf, "%s%s%d%s", master->name, |
---|
2491 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
2492 | sprintf(inst_buf, "%s%s%d%s", |
---|
2493 | instance->name->name, |
---|
2494 | SEP_LBITSELECT,sig_lo-lo+i,SEP_RBITSELECT); |
---|
2495 | fprintf(file, "%s=%s ", mast_buf, inst_buf); |
---|
2496 | } |
---|
2497 | } else { |
---|
2498 | idx_lo = vl_eval_expr(master->range->left); |
---|
2499 | if (master->range->right) |
---|
2500 | idx_hi = vl_eval_expr(master->range->right); |
---|
2501 | else |
---|
2502 | idx_hi = idx_lo; |
---|
2503 | |
---|
2504 | for (idx=idx_lo; idx<=idx_hi; idx++) { |
---|
2505 | for (i=lo; i<=hi; i++) { |
---|
2506 | char mast_buf[MAXSTRLEN]; |
---|
2507 | char inst_buf[MAXSTRLEN]; |
---|
2508 | |
---|
2509 | sprintf(mast_buf, "%s%s%d%s%s%d%s", master->name, |
---|
2510 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2511 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
2512 | sprintf(inst_buf, "%s%s%d%s%s%d%s", |
---|
2513 | instance->name->name, |
---|
2514 | SEP_LARRAY, idx, SEP_RARRAY, |
---|
2515 | SEP_LBITSELECT, |
---|
2516 | sig_lo-lo+i, |
---|
2517 | SEP_RBITSELECT); |
---|
2518 | fprintf(file, "%s=%s ", mast_buf, inst_buf); |
---|
2519 | } |
---|
2520 | } |
---|
2521 | } |
---|
2522 | } |
---|
2523 | |
---|
2524 | |
---|
2525 | char *write_red_op(FILE *file, short type, vl_term *in1, vl_term *in2, vl_term *out) |
---|
2526 | { |
---|
2527 | int bpos; |
---|
2528 | char *ripple=NIL(char); |
---|
2529 | |
---|
2530 | fprintf(file, ".names "); |
---|
2531 | for (bpos=in1->lo; bpos<=in1->hi; bpos++) { |
---|
2532 | fprintf(file, "%s%s%d%s ", in1->name->name, |
---|
2533 | SEP_LBITSELECT, bpos, SEP_RBITSELECT); |
---|
2534 | } |
---|
2535 | |
---|
2536 | fprintf(file, "%s\n", out->name->name); |
---|
2537 | |
---|
2538 | if (set_notation) { |
---|
2539 | fprintf(file, "%s %c\n", HSIS_DEFAULT, |
---|
2540 | (type==UnorExpr||type==UandExpr)?'0':'1'); |
---|
2541 | for (bpos=in1->lo; bpos<=in1->hi; bpos++) { |
---|
2542 | fprintf(file, "%c ", |
---|
2543 | (type==UorExpr||type==UnorExpr)?'0':'1'); |
---|
2544 | } |
---|
2545 | fprintf(file, "%c\n", |
---|
2546 | (type==UnorExpr||type==UandExpr)?'1':'0'); |
---|
2547 | } else { |
---|
2548 | for (bpos=in1->lo; bpos<=in1->hi; bpos++) { |
---|
2549 | int i; |
---|
2550 | for (i=in1->lo; i<=in1->hi; i++) { |
---|
2551 | fprintf(file, "%c ", |
---|
2552 | (i==bpos)? |
---|
2553 | ((type==UorExpr||type==UnorExpr)?'1':'0'):'-'); |
---|
2554 | } |
---|
2555 | fprintf(file, "%c\n", |
---|
2556 | (type==UorExpr||type==UnandExpr)?'1':'0'); |
---|
2557 | } |
---|
2558 | for (bpos=in1->lo; bpos<=in1->hi; bpos++) { |
---|
2559 | fprintf(file, "%c ", |
---|
2560 | (type==UorExpr||type==UnorExpr)?'0':'1'); |
---|
2561 | } |
---|
2562 | fprintf(file, "%c\n", |
---|
2563 | (type==UorExpr||type==UnandExpr)?'0':'1'); |
---|
2564 | } |
---|
2565 | |
---|
2566 | in2 = in2; |
---|
2567 | |
---|
2568 | return ripple; |
---|
2569 | } |
---|
2570 | |
---|
2571 | |
---|
2572 | |
---|
2573 | char *write_rel_vector_bop(FILE *file, short type, vl_term *in1, vl_term *in2, vl_term *out) |
---|
2574 | { |
---|
2575 | int bpos; |
---|
2576 | vl_term *tmpterm; |
---|
2577 | char term1[MAXSTRLEN], term2[MAXSTRLEN], outerm[MAXSTRLEN]; |
---|
2578 | char *ripple=NIL(char); |
---|
2579 | |
---|
2580 | |
---|
2581 | tmpterm = create_rename_term(out->name, new_termname(), out->lo, out->hi); |
---|
2582 | out->lo = 0; |
---|
2583 | out->hi = -1; |
---|
2584 | |
---|
2585 | if (in1->lo > in1->hi && in2->lo > in2->hi) { |
---|
2586 | |
---|
2587 | ripple = vl_write_bop(file, type, |
---|
2588 | in1->name->name, in2->name->name, NIL(char), |
---|
2589 | tmpterm->name->name, |
---|
2590 | !IS_VLR_REL_OP(type)); |
---|
2591 | if (IS_VLR_REL_OP(type)) |
---|
2592 | postprocess_vlr_rel(file, type, ripple, tmpterm, out); |
---|
2593 | } else if (in1->lo > in1->hi && in2->lo <= in2->hi) { |
---|
2594 | |
---|
2595 | char tmpterm_buf[MAXSTRLEN]; |
---|
2596 | if (tmpterm->lo > tmpterm->hi) |
---|
2597 | sprintf(tmpterm_buf, "%s", tmpterm->name->name); |
---|
2598 | else |
---|
2599 | sprintf(tmpterm_buf, "%s%s%d%s", tmpterm->name->name, |
---|
2600 | SEP_LBITSELECT, tmpterm->lo, SEP_RBITSELECT); |
---|
2601 | sprintf(term2, "%s%s%d%s", in2->name->name, |
---|
2602 | SEP_LBITSELECT, in2->lo, SEP_RBITSELECT); |
---|
2603 | ripple = vl_write_bop(file, type, |
---|
2604 | in1->name->name, term2, NIL(char), |
---|
2605 | tmpterm_buf, |
---|
2606 | !IS_VLR_REL_OP(type)); |
---|
2607 | |
---|
2608 | for (bpos=in2->lo+1; bpos<=in2->hi; bpos++) { |
---|
2609 | sprintf(term2, "%s%s%d%s", in2->name->name, |
---|
2610 | SEP_LBITSELECT, bpos, SEP_RBITSELECT); |
---|
2611 | sprintf(tmpterm_buf, "%s%s%d%s", |
---|
2612 | tmpterm->name->name, |
---|
2613 | SEP_LBITSELECT, |
---|
2614 | tmpterm->lo+(bpos-in2->lo), |
---|
2615 | SEP_RBITSELECT); |
---|
2616 | vl_write_bit_connect(file, term2, tmpterm_buf, 0); |
---|
2617 | } |
---|
2618 | if (IS_VLR_REL_OP(type)) |
---|
2619 | postprocess_vlr_rel(file, type, ripple, tmpterm, out); |
---|
2620 | } else if (in1->lo <= in1->hi && in2->lo > in2->hi) { |
---|
2621 | |
---|
2622 | char tmpterm_buf[MAXSTRLEN]; |
---|
2623 | if (tmpterm->lo > tmpterm->hi) |
---|
2624 | sprintf(tmpterm_buf, "%s", tmpterm->name->name); |
---|
2625 | else |
---|
2626 | sprintf(tmpterm_buf, "%s%s%d%s", tmpterm->name->name, |
---|
2627 | SEP_LBITSELECT, tmpterm->lo, SEP_RBITSELECT); |
---|
2628 | sprintf(term1, "%s%s%d%s", in1->name->name, |
---|
2629 | SEP_LBITSELECT, in1->lo, SEP_RBITSELECT); |
---|
2630 | ripple = vl_write_bop(file, type, |
---|
2631 | term1, in2->name->name, NIL(char), |
---|
2632 | tmpterm_buf, |
---|
2633 | !IS_VLR_REL_OP(type)); |
---|
2634 | |
---|
2635 | for (bpos=in1->lo+1; bpos<=in1->hi; bpos++) { |
---|
2636 | sprintf(term1, "%s%s%d%s", in1->name->name, |
---|
2637 | SEP_LBITSELECT, bpos, SEP_RBITSELECT); |
---|
2638 | sprintf(tmpterm_buf, "%s%s%d%s", |
---|
2639 | tmpterm->name->name, |
---|
2640 | SEP_LBITSELECT, |
---|
2641 | tmpterm->lo+(bpos-in1->lo), |
---|
2642 | SEP_RBITSELECT); |
---|
2643 | vl_write_bit_connect(file, term1, tmpterm_buf, 0); |
---|
2644 | } |
---|
2645 | if (IS_VLR_REL_OP(type)) |
---|
2646 | postprocess_vlr_rel(file, type, ripple, tmpterm, out); |
---|
2647 | } else { |
---|
2648 | |
---|
2649 | for (bpos=tmpterm->lo, ripple=NIL(char); bpos<=tmpterm->hi; bpos++) { |
---|
2650 | if (bpos > in1->hi-in1->lo) |
---|
2651 | sprintf(term1, "%s", WRT_BLIF_GND(file)); |
---|
2652 | else |
---|
2653 | sprintf(term1, "%s%s%d%s", |
---|
2654 | in1->name->name, |
---|
2655 | SEP_LBITSELECT, in1->lo+bpos, SEP_RBITSELECT); |
---|
2656 | if (bpos > in2->hi-in2->lo) |
---|
2657 | sprintf(term2, "%s", WRT_BLIF_GND(file)); |
---|
2658 | else |
---|
2659 | sprintf(term2, "%s%s%d%s", |
---|
2660 | in2->name->name, |
---|
2661 | SEP_LBITSELECT, in2->lo+bpos, SEP_RBITSELECT); |
---|
2662 | sprintf(outerm, "%s%s%d%s", |
---|
2663 | tmpterm->name->name, |
---|
2664 | SEP_LBITSELECT, tmpterm->lo+bpos, SEP_RBITSELECT); |
---|
2665 | ripple = vl_write_bop(file, type, term1, term2, ripple, outerm, |
---|
2666 | !IS_VLR_REL_OP(type)); |
---|
2667 | } |
---|
2668 | if (IS_VLR_REL_OP(type)) |
---|
2669 | postprocess_vlr_rel(file, type, ripple, tmpterm, out); |
---|
2670 | } |
---|
2671 | |
---|
2672 | vl_chk_free((char*)tmpterm); |
---|
2673 | |
---|
2674 | return ripple; |
---|
2675 | } |
---|
2676 | |
---|
2677 | |
---|
2678 | char *write_op_vector_bop(FILE *file, short type, vl_term *in1, vl_term *in2, vl_term *out) |
---|
2679 | { |
---|
2680 | int bpos; |
---|
2681 | char term1[MAXSTRLEN], term2[MAXSTRLEN], outerm[MAXSTRLEN]; |
---|
2682 | char *ripple = NIL(char); |
---|
2683 | |
---|
2684 | |
---|
2685 | if (in1->lo > in1->hi && in2->lo > in2->hi) { |
---|
2686 | |
---|
2687 | if ((vector_width(in1->lo, in1->hi) < |
---|
2688 | vector_width(out->lo, out->hi)) && |
---|
2689 | (vector_width(in2->lo, in2->hi) < |
---|
2690 | vector_width(out->lo, out->hi))) { |
---|
2691 | sprintf(outerm, "%s%s%d%s", |
---|
2692 | out->name->name, |
---|
2693 | SEP_LBITSELECT, |
---|
2694 | out->lo, |
---|
2695 | SEP_RBITSELECT); |
---|
2696 | ripple = vl_write_bop(file, type, |
---|
2697 | in1->name->name, in2->name->name, |
---|
2698 | NIL(char), |
---|
2699 | outerm, 0); |
---|
2700 | sprintf(outerm, "%s%s%d%s", |
---|
2701 | out->name->name, |
---|
2702 | SEP_LBITSELECT, |
---|
2703 | out->lo+1, |
---|
2704 | SEP_RBITSELECT); |
---|
2705 | vl_write_bit_connect(file, ripple, outerm, 0); |
---|
2706 | } else { |
---|
2707 | ripple = vl_write_bop(file, type, |
---|
2708 | in1->name->name, in2->name->name, |
---|
2709 | NIL(char), |
---|
2710 | out->name->name, 0); |
---|
2711 | } |
---|
2712 | } else if (in1->lo > in1->hi && in2->lo <= in2->hi) { |
---|
2713 | |
---|
2714 | sprintf(term2, "%s%s%d%s", in2->name->name, |
---|
2715 | SEP_LBITSELECT, in2->lo, SEP_RBITSELECT); |
---|
2716 | sprintf(outerm, "%s%s%d%s", out->name->name, |
---|
2717 | SEP_LBITSELECT, out->lo, SEP_RBITSELECT); |
---|
2718 | ripple = vl_write_bop(file, type, |
---|
2719 | in1->name->name,term2,NIL(char),outerm, 0); |
---|
2720 | |
---|
2721 | if (IS_VLR_LOG_OP(type)) { |
---|
2722 | sprintf(term2, "%s", WRT_BLIF_GND(file)); |
---|
2723 | for (bpos=in1->lo+1; bpos<=in1->hi; bpos++) { |
---|
2724 | sprintf(outerm, "%s%s%d%s", |
---|
2725 | out->name->name, |
---|
2726 | SEP_LBITSELECT, |
---|
2727 | out->lo+(bpos-in2->lo), |
---|
2728 | SEP_RBITSELECT); |
---|
2729 | vl_write_bit_connect(file, term2, outerm, 0); |
---|
2730 | } |
---|
2731 | } else { |
---|
2732 | for (bpos=in2->lo+1; bpos<=in2->hi; bpos++) { |
---|
2733 | sprintf(term2, "%s%s%d%s", in2->name->name, |
---|
2734 | SEP_LBITSELECT, bpos, SEP_RBITSELECT); |
---|
2735 | sprintf(outerm, "%s%s%d%s", |
---|
2736 | out->name->name, |
---|
2737 | SEP_LBITSELECT, |
---|
2738 | out->lo+(bpos-in2->lo), |
---|
2739 | SEP_RBITSELECT); |
---|
2740 | if (type == BplusExpr || type == BminusExpr) { |
---|
2741 | ripple = vl_write_bop(file, type, |
---|
2742 | term2,ripple,NIL(char),outerm,0); |
---|
2743 | } else { |
---|
2744 | vl_write_bit_connect(file, term2, outerm, 0); |
---|
2745 | } |
---|
2746 | } |
---|
2747 | } |
---|
2748 | |
---|
2749 | if ((vector_width(in1->lo, in1->hi) < |
---|
2750 | vector_width(out->lo, out->hi)) && |
---|
2751 | (vector_width(in2->lo, in2->hi) < |
---|
2752 | vector_width(out->lo, out->hi))) { |
---|
2753 | sprintf(outerm, "%s%s%d%s", |
---|
2754 | out->name->name, |
---|
2755 | SEP_LBITSELECT, |
---|
2756 | bpos, |
---|
2757 | SEP_RBITSELECT); |
---|
2758 | vl_write_bit_connect(file, ripple, outerm, 0); |
---|
2759 | } |
---|
2760 | } else if (in1->lo <= in1->hi && in2->lo > in2->hi) { |
---|
2761 | |
---|
2762 | sprintf(term1, "%s%s%d%s", in1->name->name, |
---|
2763 | SEP_LBITSELECT, in1->lo, SEP_RBITSELECT); |
---|
2764 | sprintf(outerm, "%s%s%d%s", out->name->name, |
---|
2765 | SEP_LBITSELECT, out->lo, SEP_RBITSELECT); |
---|
2766 | ripple = vl_write_bop(file, type, |
---|
2767 | term1,in2->name->name,NIL(char),outerm, 0); |
---|
2768 | |
---|
2769 | if (IS_VLR_LOG_OP(type)) { |
---|
2770 | sprintf(term1, "%s", WRT_BLIF_GND(file)); |
---|
2771 | for (bpos=in1->lo+1; bpos<=in1->hi; bpos++) { |
---|
2772 | sprintf(outerm, "%s%s%d%s", out->name->name, |
---|
2773 | SEP_LBITSELECT, |
---|
2774 | out->lo+(bpos-in1->lo), |
---|
2775 | SEP_RBITSELECT); |
---|
2776 | vl_write_bit_connect(file, term1, outerm, 0); |
---|
2777 | } |
---|
2778 | } else { |
---|
2779 | for (bpos=in1->lo+1; bpos<=in1->hi; bpos++) { |
---|
2780 | sprintf(term1, "%s%s%d%s", in1->name->name, |
---|
2781 | SEP_LBITSELECT, bpos, SEP_RBITSELECT); |
---|
2782 | sprintf(outerm, "%s%s%d%s", |
---|
2783 | out->name->name, |
---|
2784 | SEP_LBITSELECT, |
---|
2785 | out->lo+(bpos-in1->lo), |
---|
2786 | SEP_RBITSELECT); |
---|
2787 | if (type == BplusExpr || type == BminusExpr) { |
---|
2788 | ripple = vl_write_bop(file, type, |
---|
2789 | term1,ripple,NIL(char),outerm,0); |
---|
2790 | } else { |
---|
2791 | vl_write_bit_connect(file, term1, outerm, 0); |
---|
2792 | } |
---|
2793 | } |
---|
2794 | } |
---|
2795 | |
---|
2796 | if ((vector_width(in1->lo, in1->hi) < |
---|
2797 | vector_width(out->lo, out->hi)) && |
---|
2798 | (vector_width(in2->lo, in2->hi) < |
---|
2799 | vector_width(out->lo, out->hi))) { |
---|
2800 | sprintf(outerm, "%s%s%d%s", |
---|
2801 | out->name->name, |
---|
2802 | SEP_LBITSELECT, |
---|
2803 | bpos, |
---|
2804 | SEP_RBITSELECT); |
---|
2805 | vl_write_bit_connect(file, ripple, outerm, 0); |
---|
2806 | } |
---|
2807 | } else { |
---|
2808 | |
---|
2809 | for (bpos=out->lo, ripple=NIL(char); bpos<=out->hi; bpos++) { |
---|
2810 | if (RIPPLE_INTERFERE(type)) { |
---|
2811 | if (bpos-out->lo <= |
---|
2812 | MIN(in1->hi-in1->lo,in2->hi-in2->lo)) { |
---|
2813 | sprintf(term1, "%s%s%d%s", |
---|
2814 | in1->name->name, |
---|
2815 | SEP_LBITSELECT, in1->lo+bpos, SEP_RBITSELECT); |
---|
2816 | sprintf(term2, "%s%s%d%s", |
---|
2817 | in2->name->name, |
---|
2818 | SEP_LBITSELECT, in2->lo+bpos, SEP_RBITSELECT); |
---|
2819 | sprintf(outerm, "%s%s%d%s", |
---|
2820 | out->name->name, |
---|
2821 | SEP_LBITSELECT, out->lo+bpos, SEP_RBITSELECT); |
---|
2822 | ripple = |
---|
2823 | vl_write_bop(file, type, term1, term2, ripple, |
---|
2824 | outerm, (bpos==out->hi)); |
---|
2825 | } else if (bpos-out->lo == |
---|
2826 | MIN(in1->hi-in1->lo,in2->hi-in2->lo)+1) { |
---|
2827 | sprintf(outerm, "%s%s%d%s", |
---|
2828 | out->name->name, |
---|
2829 | SEP_LBITSELECT, out->lo+bpos, SEP_RBITSELECT); |
---|
2830 | fprintf(file, ".names %s %s\n1 1\n0 0\n", |
---|
2831 | ripple, outerm); |
---|
2832 | } else { |
---|
2833 | sprintf(outerm, "%s%s%d%s", |
---|
2834 | out->name->name, |
---|
2835 | SEP_LBITSELECT, out->lo+bpos, SEP_RBITSELECT); |
---|
2836 | fprintf(file, ".names %s\n0\n", outerm); |
---|
2837 | } |
---|
2838 | } else { |
---|
2839 | if (bpos-out->lo <= |
---|
2840 | MIN(in1->hi-in1->lo,in2->hi-in2->lo)) { |
---|
2841 | sprintf(term1, "%s%s%d%s", |
---|
2842 | in1->name->name, |
---|
2843 | SEP_LBITSELECT, in1->lo+bpos, SEP_RBITSELECT); |
---|
2844 | sprintf(term2, "%s%s%d%s", |
---|
2845 | in2->name->name, |
---|
2846 | SEP_LBITSELECT, in2->lo+bpos, SEP_RBITSELECT); |
---|
2847 | sprintf(outerm, "%s%s%d%s", |
---|
2848 | out->name->name, |
---|
2849 | SEP_LBITSELECT, out->lo+bpos, SEP_RBITSELECT); |
---|
2850 | ripple = |
---|
2851 | vl_write_bop(file, type, term1, term2, ripple, |
---|
2852 | outerm, (bpos==out->hi)); |
---|
2853 | } else { |
---|
2854 | if (bpos-out->lo <= in1->hi-in1->lo) { |
---|
2855 | sprintf(term1, "%s%s%d%s", |
---|
2856 | in1->name->name, |
---|
2857 | SEP_LBITSELECT, in1->lo+bpos, |
---|
2858 | SEP_RBITSELECT); |
---|
2859 | sprintf(outerm, "%s%s%d%s", |
---|
2860 | out->name->name, |
---|
2861 | SEP_LBITSELECT, out->lo+bpos, |
---|
2862 | SEP_RBITSELECT); |
---|
2863 | fprintf(file, ".names %s %s\n0 0\n1 1\n", |
---|
2864 | term1, outerm); |
---|
2865 | } else if (bpos-out->lo <= in2->hi-in2->lo) { |
---|
2866 | sprintf(term2, "%s%s%d%s", |
---|
2867 | in2->name->name, |
---|
2868 | SEP_LBITSELECT, in2->lo+bpos, |
---|
2869 | SEP_RBITSELECT); |
---|
2870 | sprintf(outerm, "%s%s%d%s", |
---|
2871 | out->name->name, |
---|
2872 | SEP_LBITSELECT, out->lo+bpos, |
---|
2873 | SEP_RBITSELECT); |
---|
2874 | fprintf(file, ".names %s %s\n0 0\n1 1\n", |
---|
2875 | term2, outerm); |
---|
2876 | } else { |
---|
2877 | sprintf(outerm, "%s%s%d%s", |
---|
2878 | out->name->name, |
---|
2879 | SEP_LBITSELECT, out->lo+bpos, |
---|
2880 | SEP_RBITSELECT); |
---|
2881 | fprintf(file, ".names %s\n0\n", outerm); |
---|
2882 | } |
---|
2883 | } |
---|
2884 | } |
---|
2885 | } |
---|
2886 | } |
---|
2887 | |
---|
2888 | return ripple; |
---|
2889 | } |
---|
2890 | |
---|
2891 | |
---|
2892 | static void postprocess_vlr_rel(FILE *file, short type, char *carry, |
---|
2893 | vl_term *results, vl_term *out) |
---|
2894 | { |
---|
2895 | char *tmp_termname; |
---|
2896 | vl_term *zero_term; |
---|
2897 | |
---|
2898 | switch(type) { |
---|
2899 | case BltExpr: |
---|
2900 | |
---|
2901 | zero_term = new_term(NIL(vl_range), 0, -1); |
---|
2902 | if (results->hi < results->lo) |
---|
2903 | vl_write_bit_connect(file, |
---|
2904 | results->name->name, zero_term->name->name, 0); |
---|
2905 | else |
---|
2906 | vl_write_vector_bop(file, UorExpr, |
---|
2907 | results, NIL(vl_term), zero_term); |
---|
2908 | vl_write_bop(file, BandExpr, carry, zero_term->name->name, NIL(char), |
---|
2909 | out->name->name, 1); |
---|
2910 | break; |
---|
2911 | case BgtExpr: |
---|
2912 | |
---|
2913 | zero_term = new_term(NIL(vl_range), 0, -1); |
---|
2914 | if (results->hi < results->lo) |
---|
2915 | vl_write_bit_connect(file, |
---|
2916 | results->name->name, zero_term->name->name, 1); |
---|
2917 | else |
---|
2918 | vl_write_vector_bop(file, UnorExpr, |
---|
2919 | results, NIL(vl_term), zero_term); |
---|
2920 | tmp_termname = new_termname(); |
---|
2921 | vl_write_bop(file, BorExpr, carry, zero_term->name->name, NIL(char), |
---|
2922 | tmp_termname, 1); |
---|
2923 | vl_write_bit_connect(file, tmp_termname, out->name->name, 1); |
---|
2924 | break; |
---|
2925 | case BleExpr: |
---|
2926 | |
---|
2927 | zero_term = new_term(NIL(vl_range), 0, -1); |
---|
2928 | if (results->hi < results->lo) |
---|
2929 | vl_write_bit_connect(file, |
---|
2930 | results->name->name, zero_term->name->name, 1); |
---|
2931 | else |
---|
2932 | vl_write_vector_bop(file, UnorExpr, |
---|
2933 | results, NIL(vl_term), zero_term); |
---|
2934 | vl_write_bop(file, BorExpr, carry, zero_term->name->name, NIL(char), |
---|
2935 | out->name->name, 1); |
---|
2936 | break; |
---|
2937 | case BgeExpr: |
---|
2938 | |
---|
2939 | zero_term = new_term(NIL(vl_range), 0, -1); |
---|
2940 | if (results->hi < results->lo) |
---|
2941 | vl_write_bit_connect(file, |
---|
2942 | results->name->name, zero_term->name->name, 0); |
---|
2943 | else |
---|
2944 | vl_write_vector_bop(file, UorExpr, |
---|
2945 | results, NIL(vl_term), zero_term); |
---|
2946 | tmp_termname = new_termname(); |
---|
2947 | vl_write_bop(file, BandExpr, carry, zero_term->name->name, NIL(char), |
---|
2948 | tmp_termname, 1); |
---|
2949 | vl_write_bit_connect(file, tmp_termname, out->name->name, 1); |
---|
2950 | break; |
---|
2951 | } |
---|
2952 | } |
---|
2953 | |
---|
2954 | |
---|
2955 | vl_port *search_match_port(char *name, lsList ports) |
---|
2956 | { |
---|
2957 | lsGen gen; |
---|
2958 | lsHandle handle; |
---|
2959 | vl_port *retval=NIL(vl_port), *port; |
---|
2960 | lsHandle port_handle; |
---|
2961 | vl_id_range *id; |
---|
2962 | |
---|
2963 | gen = lsStart(ports); |
---|
2964 | while (lsNext(gen, (lsGeneric*)&port, &handle)!=LS_NOMORE) { |
---|
2965 | lsFirstItem(port->port_exp, (lsGeneric*)&id, &port_handle); |
---|
2966 | if (!strcmp(name, id->name)) { |
---|
2967 | retval = port; |
---|
2968 | break; |
---|
2969 | } |
---|
2970 | } |
---|
2971 | lsFinish(gen); |
---|
2972 | |
---|
2973 | return retval; |
---|
2974 | } |
---|
2975 | |
---|
2976 | |
---|
2977 | vl_port_connect *search_inst_port(char *name, lsList ports) |
---|
2978 | { |
---|
2979 | lsGen gen; |
---|
2980 | lsHandle handle; |
---|
2981 | vl_port_connect *retval=NIL(vl_port_connect), *port; |
---|
2982 | |
---|
2983 | gen = lsStart(ports); |
---|
2984 | while (lsNext(gen, (lsGeneric*)&port, &handle)!=LS_NOMORE) { |
---|
2985 | if (!strcmp(name, port->id->name)) { |
---|
2986 | retval = port; |
---|
2987 | break; |
---|
2988 | } |
---|
2989 | } |
---|
2990 | lsFinish(gen); |
---|
2991 | |
---|
2992 | return retval; |
---|
2993 | } |
---|
2994 | |
---|
2995 | |
---|
2996 | |
---|
2997 | char *vl_translate_prim_symbol(unsigned char sym) |
---|
2998 | { |
---|
2999 | char buf[MAXSTRLEN]; |
---|
3000 | |
---|
3001 | switch(sym) { |
---|
3002 | case PrimNone: return(""); |
---|
3003 | case Prim0: return("0"); |
---|
3004 | case Prim1: return("1"); |
---|
3005 | case PrimX: return("-"); |
---|
3006 | case PrimQ: return("-"); |
---|
3007 | case PrimB: return("-"); |
---|
3008 | case PrimM: return("-"); |
---|
3009 | case PrimR: return("0 1"); |
---|
3010 | case PrimF: return("1 0"); |
---|
3011 | case PrimS: return("- -"); |
---|
3012 | case PrimBB: return("- -"); |
---|
3013 | case PrimQ0: return("- 0"); |
---|
3014 | case PrimQ1: return("- 1"); |
---|
3015 | case PrimQB: return("- -"); |
---|
3016 | case Prim0X: return("0 -"); |
---|
3017 | case Prim1X: return("1 -"); |
---|
3018 | case PrimX0: return("- 0"); |
---|
3019 | case PrimX1: return("- 1"); |
---|
3020 | case PrimXB: return("- -"); |
---|
3021 | case PrimBX: return("- -"); |
---|
3022 | case PrimP: sprintf(buf, "P"); |
---|
3023 | case PrimN: sprintf(buf, "N"); |
---|
3024 | strcat(buf, " :: can not be handled yet"); |
---|
3025 | Translate_Warning(buf); |
---|
3026 | return(""); |
---|
3027 | default: { |
---|
3028 | char msg[MAXSTRLEN]; |
---|
3029 | sprintf(msg, "Unexpected primitive symbol type %d", sym); |
---|
3030 | internal_error(msg); return(NULL); |
---|
3031 | } |
---|
3032 | } |
---|
3033 | } |
---|
3034 | |
---|
3035 | vl_term *sensitive_control(FILE *file, st_table *sensitive_list) |
---|
3036 | { |
---|
3037 | vl_term *retval; |
---|
3038 | st_generator *gen; |
---|
3039 | char *key, *dummy; |
---|
3040 | vl_id_range *id_sym; |
---|
3041 | int i, j; |
---|
3042 | int lo, hi; |
---|
3043 | int ithItem; |
---|
3044 | |
---|
3045 | retval = new_term(NIL(vl_range), 0, -1); |
---|
3046 | fprintf(file, ".names "); |
---|
3047 | ithItem = 0; |
---|
3048 | gen = st_init_gen(sensitive_list); |
---|
3049 | while (st_gen(gen, &key, &dummy)) { |
---|
3050 | if (!st_lookup(vl_currentModule->sig_st, key, (char**)&id_sym)) { |
---|
3051 | char buf[MAXSTRLEN]; |
---|
3052 | |
---|
3053 | sprintf(buf, "sensitive var:%s is not defined in module %s", |
---|
3054 | key, vl_currentModule->name->name); |
---|
3055 | semantic_error(buf); |
---|
3056 | } |
---|
3057 | |
---|
3058 | get_hilo(id_sym, &hi, &lo); |
---|
3059 | if (lo < hi || id_sym->range) { |
---|
3060 | char buf[MAXSTRLEN]; |
---|
3061 | |
---|
3062 | sprintf(buf, "%s is vector/array while as sensitive var in %s", |
---|
3063 | key, vl_currentModule->name->name); |
---|
3064 | semantic_error(buf); |
---|
3065 | } |
---|
3066 | |
---|
3067 | fprintf(file, "%s ", key); |
---|
3068 | } |
---|
3069 | st_free_gen(gen); |
---|
3070 | fprintf(file, "%s\n", retval->name->name); |
---|
3071 | |
---|
3072 | for (i=0; i<st_count(sensitive_list); i++) { |
---|
3073 | for (j=0; j<st_count(sensitive_list); j++) |
---|
3074 | fprintf(file, "%c ", (i==j)?'1':'-'); |
---|
3075 | fprintf(file, "1\n"); |
---|
3076 | } |
---|
3077 | for (i=0; i<st_count(sensitive_list); i++) |
---|
3078 | fprintf(file, "0 "); |
---|
3079 | fprintf(file, "0\n"); |
---|
3080 | |
---|
3081 | return retval; |
---|
3082 | } |
---|
3083 | |
---|
3084 | |
---|
3085 | void patch_unaffected_term(FILE *file, vl_id_range *id_sym, |
---|
3086 | vl_term *orig_term, |
---|
3087 | vl_term *out_term) |
---|
3088 | { |
---|
3089 | int i; |
---|
3090 | int set_floating = 0; |
---|
3091 | |
---|
3092 | if (orig_term->lo == out_term->lo && orig_term->hi == out_term->hi) |
---|
3093 | return; |
---|
3094 | if (orig_term->lo >= orig_term->hi && out_term->lo >= out_term->hi) |
---|
3095 | return; |
---|
3096 | |
---|
3097 | if (vl_currentFunction) |
---|
3098 | if (!strcmp(id_sym->name, orig_term->name->name)) |
---|
3099 | set_floating = 1; |
---|
3100 | |
---|
3101 | if (set_floating) { |
---|
3102 | for (i=orig_term->lo; i<out_term->lo; i++) { |
---|
3103 | fprintf(file, ".names %s%s%d%s\n-\n", |
---|
3104 | out_term->name->name, |
---|
3105 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3106 | } |
---|
3107 | |
---|
3108 | for (i=out_term->hi+1; i<=orig_term->hi; i++) { |
---|
3109 | fprintf(file, ".names %s%s%d%s\n-\n", |
---|
3110 | out_term->name->name, |
---|
3111 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3112 | } |
---|
3113 | } else { |
---|
3114 | |
---|
3115 | for (i=orig_term->lo; i<out_term->lo; i++) { |
---|
3116 | if (set_notation) { |
---|
3117 | fprintf(file,".names %s%s%d%s %s%s%d%s\n- %s%s%s%d%s\n", |
---|
3118 | orig_term->name->name, |
---|
3119 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
3120 | out_term->name->name, |
---|
3121 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
3122 | HSIS_EQUAL, |
---|
3123 | orig_term->name->name, |
---|
3124 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3125 | } else { |
---|
3126 | fprintf(file, ".names %s%s%d%s %s%s%d%s\n1 1\n0 0\n", |
---|
3127 | orig_term->name->name, |
---|
3128 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
3129 | out_term->name->name, |
---|
3130 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3131 | } |
---|
3132 | } |
---|
3133 | |
---|
3134 | for (i=out_term->hi+1; i<=orig_term->hi; i++) { |
---|
3135 | if (set_notation) { |
---|
3136 | fprintf(file,".names %s%s%d%s %s%s%d%s\n- %s%s%s%d%s\n", |
---|
3137 | orig_term->name->name, |
---|
3138 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
3139 | out_term->name->name, |
---|
3140 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
3141 | HSIS_EQUAL, |
---|
3142 | orig_term->name->name, |
---|
3143 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3144 | } else { |
---|
3145 | fprintf(file, ".names %s%s%d%s %s%s%d%s\n1 1\n0 0\n", |
---|
3146 | orig_term->name->name, |
---|
3147 | SEP_LBITSELECT, i, SEP_RBITSELECT, |
---|
3148 | out_term->name->name, |
---|
3149 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3150 | } |
---|
3151 | } |
---|
3152 | } |
---|
3153 | |
---|
3154 | out_term->lo = orig_term->lo; |
---|
3155 | out_term->hi = orig_term->hi; |
---|
3156 | } |
---|
3157 | |
---|
3158 | int need_edge_detector(lsList table_entries, int ith_port) |
---|
3159 | { |
---|
3160 | int retval=0; |
---|
3161 | lsGen gen; |
---|
3162 | lsHandle handle; |
---|
3163 | vl_prim_entry *e; |
---|
3164 | |
---|
3165 | for (gen=lsStart(table_entries); |
---|
3166 | lsNext(gen, (lsGeneric*)&e, &handle) != LS_NOMORE; ) { |
---|
3167 | register unsigned char sym; |
---|
3168 | sym = e->inputs[ith_port]; |
---|
3169 | if (IS_TRANSITION(sym)) { |
---|
3170 | retval = 1; |
---|
3171 | break; |
---|
3172 | } |
---|
3173 | } |
---|
3174 | (void)lsFinish(gen); |
---|
3175 | |
---|
3176 | return retval; |
---|
3177 | } |
---|
3178 | |
---|
3179 | |
---|
3180 | void dump_debug_information(FILE *file, vl_id_range *id_var, |
---|
3181 | vl_term *current_term, int lineno, |
---|
3182 | lsList ctrl_list, char *ctrl_syndrome) |
---|
3183 | { |
---|
3184 | lsGen gen; |
---|
3185 | lsHandle handle; |
---|
3186 | vl_term *ctrl; |
---|
3187 | int i; |
---|
3188 | char *Comment; |
---|
3189 | |
---|
3190 | Comment = HSIS_COMMENT; |
---|
3191 | if (debug_mode) { |
---|
3192 | if (lineno >= 0) { |
---|
3193 | fprintf(file, "%s%sl %d%s%s\n", |
---|
3194 | Comment, Comment, |
---|
3195 | lineno, |
---|
3196 | Comment, Comment); |
---|
3197 | } |
---|
3198 | fprintf(file, "%s%sv %s.%s%s%s\n", |
---|
3199 | Comment, Comment, |
---|
3200 | vl_currentModule->name->name, id_var->name, |
---|
3201 | Comment, Comment); |
---|
3202 | for (i=0, gen=lsStart(ctrl_list); |
---|
3203 | lsNext(gen, (lsGeneric*)&ctrl, &handle)!=LS_NOMORE; i++) { |
---|
3204 | if (ctrl_syndrome[i] == '-') continue; |
---|
3205 | if (ctrl_syndrome[i] == '1') |
---|
3206 | fprintf(file, "%s%sg %s%s%s\n", |
---|
3207 | Comment, Comment, |
---|
3208 | ctrl->name->name, |
---|
3209 | Comment, Comment); |
---|
3210 | if (ctrl_syndrome[i] == '0') |
---|
3211 | fprintf(file, "%s%sG %s%s%s\n", |
---|
3212 | Comment, Comment, |
---|
3213 | ctrl->name->name, |
---|
3214 | Comment, Comment); |
---|
3215 | } |
---|
3216 | lsFinish(gen); |
---|
3217 | } |
---|
3218 | |
---|
3219 | current_term = current_term; |
---|
3220 | } |
---|
3221 | |
---|
3222 | |
---|
3223 | int vector_width(int lo, int hi) |
---|
3224 | { |
---|
3225 | if (lo > hi) return 1; |
---|
3226 | return hi - lo + 1; |
---|
3227 | } |
---|
3228 | |
---|
3229 | |
---|
3230 | void expand_term(FILE *file, vl_term *in, vl_term *out) |
---|
3231 | { |
---|
3232 | int i; |
---|
3233 | char in_buf[MAXSTRLEN], out_buf[MAXSTRLEN]; |
---|
3234 | lsList args; |
---|
3235 | |
---|
3236 | assert(vector_width(in->lo, in->hi) <= vector_width(out->lo, out->hi)); |
---|
3237 | |
---|
3238 | if (vector_width(in->lo, in->hi) == vector_width(out->lo, out->hi)) { |
---|
3239 | vl_write_bin_connect(file, in, out, 0); |
---|
3240 | } else { |
---|
3241 | char buf[MAXSTRLEN]; |
---|
3242 | args = lsCreate(); |
---|
3243 | sprintf(buf, "%d", in->hi-in->lo+1); |
---|
3244 | lsNewEnd(args, (lsGeneric)vlStrdup(buf), 0); |
---|
3245 | sprintf(buf, "%d", out->hi-out->lo+1); |
---|
3246 | lsNewEnd(args, (lsGeneric)vlStrdup(buf), 0); |
---|
3247 | |
---|
3248 | for (i=out->lo; i<=out->hi; i++) { |
---|
3249 | if (in->lo > in->hi) { |
---|
3250 | sprintf(out_buf, "%s%s%d%s", out->name->name, |
---|
3251 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3252 | sprintf(in_buf, "%s", |
---|
3253 | (i==out->lo)?in->name->name:WRT_BLIF_GND(file)); |
---|
3254 | if (set_notation) { |
---|
3255 | fprintf(file, ".names %s %s\n- =%s\n", |
---|
3256 | in_buf, out_buf, in_buf); |
---|
3257 | } else { |
---|
3258 | vl_write_bit_connect(file, in_buf, out_buf, 0); |
---|
3259 | } |
---|
3260 | } else { |
---|
3261 | sprintf(out_buf, "%s%s%d%s", out->name->name, |
---|
3262 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3263 | if (i-out->lo <= in->hi-in->lo) |
---|
3264 | sprintf(in_buf, "%s%s%d%s", in->name->name, |
---|
3265 | SEP_LBITSELECT, i+in->lo-out->lo, SEP_RBITSELECT); |
---|
3266 | else |
---|
3267 | sprintf(in_buf, "%s", WRT_BLIF_GND(file)); |
---|
3268 | if (set_notation) { |
---|
3269 | fprintf(file, ".names %s %s\n- =%s\n", |
---|
3270 | in_buf, out_buf, in_buf); |
---|
3271 | } else { |
---|
3272 | vl_write_bit_connect(file, in_buf, out_buf, 0); |
---|
3273 | } |
---|
3274 | } |
---|
3275 | } |
---|
3276 | |
---|
3277 | lsDestroy(args, vl_chk_free); |
---|
3278 | } |
---|
3279 | } |
---|
3280 | |
---|
3281 | void shrink_term(FILE *file, vl_term *in, vl_term *out) |
---|
3282 | { |
---|
3283 | int i; |
---|
3284 | char in_buf[MAXSTRLEN], out_buf[MAXSTRLEN]; |
---|
3285 | lsList args; |
---|
3286 | |
---|
3287 | assert(vector_width(in->lo, in->hi) >= vector_width(out->lo, out->hi)); |
---|
3288 | |
---|
3289 | if (vector_width(in->lo, in->hi) == vector_width(out->lo, out->hi)) { |
---|
3290 | vl_write_bin_connect(file, in, out, 0); |
---|
3291 | } else { |
---|
3292 | char buf[MAXSTRLEN]; |
---|
3293 | args = lsCreate(); |
---|
3294 | sprintf(buf, "%d", in->hi-in->lo+1); |
---|
3295 | lsNewEnd(args, (lsGeneric)vlStrdup(buf), 0); |
---|
3296 | sprintf(buf, "%d", out->hi-out->lo+1); |
---|
3297 | lsNewEnd(args, (lsGeneric)vlStrdup(buf), 0); |
---|
3298 | |
---|
3299 | for (i=in->lo; i<=in->hi; i++) { |
---|
3300 | if (out->lo > out->hi) { |
---|
3301 | if (i == in->lo) { |
---|
3302 | sprintf(out_buf, "%s", out->name->name); |
---|
3303 | sprintf(in_buf, "%s%s%d%s", in->name->name, |
---|
3304 | SEP_LARRAY, i, SEP_RARRAY); |
---|
3305 | if (set_notation) { |
---|
3306 | fprintf(file, ".names %s %s\n- =%s\n", |
---|
3307 | in_buf, out_buf, in_buf); |
---|
3308 | } else { |
---|
3309 | vl_write_bit_connect(file, in_buf, out_buf, 0); |
---|
3310 | } |
---|
3311 | } |
---|
3312 | } else { |
---|
3313 | if (i-in->lo <= out->hi-out->lo) { |
---|
3314 | sprintf(out_buf, "%s%s%d%s", out->name->name, |
---|
3315 | SEP_LBITSELECT,i+in->lo-out->lo,SEP_RBITSELECT); |
---|
3316 | sprintf(in_buf, "%s%s%d%s", in->name->name, |
---|
3317 | SEP_LBITSELECT, i, SEP_RBITSELECT); |
---|
3318 | if (set_notation) { |
---|
3319 | fprintf(file, ".names %s %s\n- =%s\n", |
---|
3320 | in_buf, out_buf, in_buf); |
---|
3321 | } else { |
---|
3322 | vl_write_bit_connect(file, in_buf, out_buf, 0); |
---|
3323 | } |
---|
3324 | } |
---|
3325 | } |
---|
3326 | } |
---|
3327 | |
---|
3328 | lsDestroy(args, vl_chk_free); |
---|
3329 | } |
---|
3330 | } |
---|
3331 | |
---|
3332 | |
---|
3333 | void subrange_term(FILE *file, vl_term *in, vl_term *out) |
---|
3334 | { |
---|
3335 | } |
---|
3336 | |
---|
3337 | |
---|
3338 | vl_term *vl_write_nond_wire(FILE *file, vl_term *ctrl_term, lsList nond_list, vl_term *reference_term) |
---|
3339 | { |
---|
3340 | vl_term *retval; |
---|
3341 | vl_term *nond_term; |
---|
3342 | vl_expr *nond_expr; |
---|
3343 | lsHandle handle; |
---|
3344 | lsGen gen; |
---|
3345 | lsList domain; |
---|
3346 | lsGen enum_gen; |
---|
3347 | vl_enumerator *enum_elt; |
---|
3348 | lsHandle enum_handle; |
---|
3349 | lsList nond_consts, nond_terms; |
---|
3350 | int num_terms, num_consts; |
---|
3351 | int i, j, k, l; |
---|
3352 | |
---|
3353 | retval = typed_new_term(reference_term->term_type, NIL(vl_range), |
---|
3354 | reference_term->lo, reference_term->hi); |
---|
3355 | if (vis_nond && rst_ckt) { |
---|
3356 | char *cp; |
---|
3357 | cp = (char*)chk_malloc(strlen(reference_term->name->name) + |
---|
3358 | strlen(retval->name->name) + |
---|
3359 | 2*strlen(SEP_GATEPIN)+strlen(PIN_INITIAL)+1); |
---|
3360 | sprintf(cp, "%s%s%s%s%s", reference_term->name->name, SEP_GATEPIN, |
---|
3361 | PIN_INITIAL, SEP_GATEPIN, retval->name->name); |
---|
3362 | retval->name->name = cp; |
---|
3363 | } |
---|
3364 | retval->flag = reference_term->flag; |
---|
3365 | if (!vis_nond || rst_ckt) |
---|
3366 | write_var_decl(file, retval); |
---|
3367 | nond_consts = lsCreate(); |
---|
3368 | nond_terms = lsCreate(); |
---|
3369 | for (gen=lsStart(nond_list), num_terms=0, num_consts=0; |
---|
3370 | lsNext(gen, (lsGeneric*)&nond_expr, &handle) != LS_NOMORE; ) { |
---|
3371 | if (ISVLCONST(nond_expr->type)) { |
---|
3372 | |
---|
3373 | num_consts++; |
---|
3374 | lsNewEnd(nond_consts, (lsGeneric)nond_expr->u.intval, 0); |
---|
3375 | } else { |
---|
3376 | |
---|
3377 | num_terms++; |
---|
3378 | lsNewEnd(nond_terms, (lsGeneric)nond_expr->term, 0); |
---|
3379 | } |
---|
3380 | } |
---|
3381 | (void)lsFinish(gen); |
---|
3382 | |
---|
3383 | |
---|
3384 | fprintf(file, ".names "); |
---|
3385 | for (gen=lsStart(nond_terms); |
---|
3386 | lsNext(gen, (lsGeneric*)&nond_term, &handle) != LS_NOMORE; ) { |
---|
3387 | if (reference_term->lo > reference_term->hi || |
---|
3388 | reference_term->flag & MVar) |
---|
3389 | if (nond_term->lo > nond_term->hi || reference_term->flag & MVar) |
---|
3390 | fprintf(file, "%s ", nond_term->name->name); |
---|
3391 | else |
---|
3392 | fprintf(file, "%s%s%d%s ", nond_term->name->name, |
---|
3393 | SEP_LBITSELECT, nond_term->lo, SEP_RBITSELECT); |
---|
3394 | else { |
---|
3395 | for (l=reference_term->lo; l<=reference_term->hi; l++) |
---|
3396 | fprintf(file, "%s%s%d%s ", nond_term->name->name, |
---|
3397 | SEP_LBITSELECT, l, SEP_RBITSELECT); |
---|
3398 | } |
---|
3399 | } |
---|
3400 | (void)lsFinish(gen); |
---|
3401 | if (reference_term->lo > reference_term->hi || |
---|
3402 | reference_term->flag & MVar) |
---|
3403 | fprintf(file, "%s\n", |
---|
3404 | nond_output(retval->name->name, reference_term->name->name)); |
---|
3405 | else { |
---|
3406 | fprintf(file, "%s ", HSIS_ARROW); |
---|
3407 | for (l=reference_term->lo; l<=reference_term->hi; l++) |
---|
3408 | fprintf(file, "%s%s%d%s ", |
---|
3409 | nond_output(retval->name->name,reference_term->name->name), |
---|
3410 | SEP_LBITSELECT, l, SEP_RBITSELECT); |
---|
3411 | fprintf(file, "\n"); |
---|
3412 | } |
---|
3413 | |
---|
3414 | |
---|
3415 | |
---|
3416 | for (gen=lsStart(nond_consts); |
---|
3417 | lsNext(gen,(lsGeneric*)&k,&handle) != LS_NOMORE; ) { |
---|
3418 | if (reference_term->lo > reference_term->hi || |
---|
3419 | reference_term->flag & MVar) |
---|
3420 | for (j=0; j<num_terms; j++) fprintf(file, "- "); |
---|
3421 | else |
---|
3422 | for (l=reference_term->lo; l<=reference_term->hi; l++) |
---|
3423 | for (j=0; j<num_terms; j++) fprintf(file, "- "); |
---|
3424 | |
---|
3425 | if (reference_term->flag & MVar) { |
---|
3426 | domain = reference_term->term_type->specifier->u.enum_type->domain_list; |
---|
3427 | for (enum_gen = lsStart(domain), i=0; |
---|
3428 | lsNext(enum_gen, (lsGeneric*)&enum_elt, &enum_handle) != |
---|
3429 | LS_NOMORE; i++) |
---|
3430 | if (k == i) { |
---|
3431 | fprintf(file, "%s ", enum_elt->name); |
---|
3432 | |
---|
3433 | } |
---|
3434 | (void)lsFinish(enum_gen); |
---|
3435 | } else { |
---|
3436 | if (reference_term->lo > reference_term->hi) { |
---|
3437 | |
---|
3438 | fprintf(file, "%d", k); |
---|
3439 | } else { |
---|
3440 | |
---|
3441 | for (l=reference_term->lo, j=k; l<=reference_term->hi; |
---|
3442 | l++, j >>= 1) |
---|
3443 | fprintf(file, "%d ", j & 0x1); |
---|
3444 | } |
---|
3445 | } |
---|
3446 | fprintf(file, "\n"); |
---|
3447 | } |
---|
3448 | (void)lsFinish(gen); |
---|
3449 | |
---|
3450 | for (gen=lsStart(nond_terms), j=0; |
---|
3451 | lsNext(gen,(lsGeneric*)&nond_term,&handle) != LS_NOMORE; j++) { |
---|
3452 | if (set_notation || reference_term->lo <= reference_term->hi) { |
---|
3453 | |
---|
3454 | |
---|
3455 | for (i=0; i<num_terms; i++) |
---|
3456 | if (reference_term->lo > reference_term->hi || |
---|
3457 | reference_term->flag & MVar) |
---|
3458 | fprintf(file, "- "); |
---|
3459 | else { |
---|
3460 | for (l=reference_term->lo; l<=reference_term->hi; l++) |
---|
3461 | fprintf(file, "- "); |
---|
3462 | } |
---|
3463 | |
---|
3464 | if (reference_term->lo > reference_term->hi || |
---|
3465 | reference_term->flag & MVar) { |
---|
3466 | if (nond_term->lo > nond_term->hi) |
---|
3467 | fprintf(file, "%s%s\n", HSIS_EQUAL, nond_term->name->name); |
---|
3468 | else |
---|
3469 | fprintf(file, "%s%s%s%d%s\n", HSIS_EQUAL, |
---|
3470 | nond_term->name->name, |
---|
3471 | SEP_LBITSELECT, nond_term->lo, SEP_RBITSELECT); |
---|
3472 | } else { |
---|
3473 | for (l=reference_term->lo; l<=reference_term->hi; l++) |
---|
3474 | fprintf(file, "%s%s%s%d%s ", HSIS_EQUAL, |
---|
3475 | nond_term->name->name, |
---|
3476 | SEP_LBITSELECT, |
---|
3477 | nond_term->lo-reference_term->lo+l, |
---|
3478 | SEP_RBITSELECT); |
---|
3479 | fprintf(file, "\n"); |
---|
3480 | } |
---|
3481 | |
---|
3482 | } else { |
---|
3483 | |
---|
3484 | |
---|
3485 | if (reference_term->flag & MVar) { |
---|
3486 | |
---|
3487 | domain = reference_term->term_type->specifier->u.enum_type->domain_list; |
---|
3488 | for (enum_gen=lsStart(domain); |
---|
3489 | lsNext(enum_gen, (lsGeneric*)&enum_elt, |
---|
3490 | &enum_handle) != |
---|
3491 | LS_NOMORE; ) { |
---|
3492 | for (i=0; i<j; i++) fprintf(file, "- "); |
---|
3493 | fprintf(file, "%s ", enum_elt->name); |
---|
3494 | for (i++; i<num_terms; i++) fprintf(file, "- "); |
---|
3495 | fprintf(file, "%s\n", enum_elt->name); |
---|
3496 | } |
---|
3497 | (void)lsFinish(enum_gen); |
---|
3498 | } else { |
---|
3499 | |
---|
3500 | } |
---|
3501 | |
---|
3502 | } |
---|
3503 | } |
---|
3504 | (void)lsFinish(gen); |
---|
3505 | |
---|
3506 | lsDestroy(nond_consts, 0); |
---|
3507 | lsDestroy(nond_terms, 0); |
---|
3508 | return retval; |
---|
3509 | } |
---|
3510 | |
---|
3511 | |
---|
3512 | void vl_get_minmax_delay(vl_delay *delay, vl_expr **min_delay, vl_expr **max_delay) |
---|
3513 | { |
---|
3514 | lsGen gen; |
---|
3515 | lsHandle handle; |
---|
3516 | vl_expr *delayi; |
---|
3517 | int i; |
---|
3518 | |
---|
3519 | if (!(delay->delay3 && !delay->delay2)) return; |
---|
3520 | assert(lsLength((lsList)delay->delay1) == 2); |
---|
3521 | |
---|
3522 | *min_delay = *max_delay = NIL(vl_expr); |
---|
3523 | for (gen=lsStart((lsList)delay->delay1), i=1; |
---|
3524 | lsNext(gen, (lsGeneric*)&delayi, &handle) != LS_NOMORE; i++) { |
---|
3525 | if (i==1) *min_delay = delayi; |
---|
3526 | else if (i==2) *max_delay = delayi; |
---|
3527 | else break; |
---|
3528 | } |
---|
3529 | lsFinish(gen); |
---|
3530 | } |
---|
3531 | |
---|
3532 | |
---|
3533 | static int isTautology(lsList syndrome_expr_list) |
---|
3534 | { |
---|
3535 | lsGen gen; |
---|
3536 | lsHandle handle; |
---|
3537 | syndrome_expr *se; |
---|
3538 | unsigned int i; |
---|
3539 | int unguarded = 0; |
---|
3540 | |
---|
3541 | for (gen = lsStart(syndrome_expr_list); |
---|
3542 | lsNext(gen, (lsGeneric*)&se, &handle) != LS_NOMORE; ) { |
---|
3543 | unguarded = 1; |
---|
3544 | for (i=0; i<strlen(se->syndrome); i++) { |
---|
3545 | if ((se->syndrome)[i] != '-') { |
---|
3546 | unguarded = 0; |
---|
3547 | break; |
---|
3548 | } |
---|
3549 | } |
---|
3550 | if (unguarded) break; |
---|
3551 | } |
---|
3552 | lsFinish(gen); |
---|
3553 | |
---|
3554 | return unguarded; |
---|
3555 | } |
---|
3556 | |
---|
3557 | |
---|
3558 | |
---|
3559 | void write_case_tag_const(FILE *file, vl_term *selector, |
---|
3560 | vl_expr *tag_expr, st_table *vars) |
---|
3561 | { |
---|
3562 | |
---|
3563 | if (!tag_expr->term) { |
---|
3564 | if (tag_expr->type == IntExpr || tag_expr->type == BitExpr || |
---|
3565 | evaluable_expr(tag_expr)) { |
---|
3566 | tag_expr->term = typed_new_term(selector->name->id_type, |
---|
3567 | NIL(vl_range), |
---|
3568 | selector->lo, selector->hi); |
---|
3569 | write_var_decl(file, tag_expr->term); |
---|
3570 | write_int_connect(file, vl_eval_expr(tag_expr), tag_expr->term); |
---|
3571 | } else if (tag_expr->type != IDExpr && tag_expr->type != ConcatExpr) { |
---|
3572 | vl_write_expr(file, tag_expr, vars); |
---|
3573 | } else if (tag_expr->type == IDExpr) { |
---|
3574 | vl_id_range *sel_id_sym; |
---|
3575 | vl_enumerator *enum_elt; |
---|
3576 | |
---|
3577 | if (!st_lookup(vl_currentModule->sig_st, selector->name->name, |
---|
3578 | (char**)&sel_id_sym)) { |
---|
3579 | sel_id_sym = vl_copy_id_range(selector->name); |
---|
3580 | if (selector->term_type) |
---|
3581 | sel_id_sym->id_type = selector->term_type; |
---|
3582 | if (!strstr(selector->name->name, SEP_GATEPIN)) { |
---|
3583 | st_insert(vl_currentModule->sig_st, |
---|
3584 | vlStrdup(selector->name->name), |
---|
3585 | (char*)sel_id_sym); |
---|
3586 | } |
---|
3587 | } |
---|
3588 | if (!sel_id_sym->id_type) { |
---|
3589 | vl_write_expr(file, tag_expr, vars); |
---|
3590 | return; |
---|
3591 | } |
---|
3592 | |
---|
3593 | if (st_lookup(sel_id_sym->id_type->specifier-> |
---|
3594 | u.enum_type->domain_st, |
---|
3595 | tag_expr->u.name->name, |
---|
3596 | (char**)&enum_elt)) { |
---|
3597 | |
---|
3598 | tag_expr->term = typed_new_term(selector->term_type, |
---|
3599 | NIL(vl_range), |
---|
3600 | selector->lo, selector->hi); |
---|
3601 | tag_expr->term->flag = selector->flag; |
---|
3602 | write_var_decl(file, tag_expr->term); |
---|
3603 | tag_expr->type = IntExpr; |
---|
3604 | tag_expr->u.intval = enum_elt->val; |
---|
3605 | vl_write_const(file, tag_expr, tag_expr->term); |
---|
3606 | } else { |
---|
3607 | char buf[MAXSTRLEN]; |
---|
3608 | |
---|
3609 | sprintf(buf,"'%s':var '%s' should not be used as CASE-tag", |
---|
3610 | vl_currentModule->name->name, tag_expr->u.name->name); |
---|
3611 | semantic_error(buf); |
---|
3612 | } |
---|
3613 | } else if (tag_expr->type == ConcatExpr) { |
---|
3614 | vl_write_expr(file, tag_expr, vars); |
---|
3615 | } |
---|
3616 | } |
---|
3617 | } |
---|
3618 | |
---|
3619 | |
---|
3620 | void width_unknown() |
---|
3621 | { |
---|
3622 | char buf[MAXSTRLEN]; |
---|
3623 | |
---|
3624 | sprintf(buf, "%s:you are giving me concatenation of something I can't determined the width", vl_currentModule->name->name); |
---|
3625 | yylineno = -1; |
---|
3626 | compile_error(buf); |
---|
3627 | } |
---|
3628 | |
---|
3629 | |
---|
3630 | vl_term *concate_assigns(array_t *assign_array) |
---|
3631 | { |
---|
3632 | vl_term *retval; |
---|
3633 | vl_term *ith_term; |
---|
3634 | int n_bits; |
---|
3635 | int i; |
---|
3636 | |
---|
3637 | n_bits=0; |
---|
3638 | for (i=0; i<array_n(assign_array); i++) { |
---|
3639 | ith_term = array_fetch(vl_term*, assign_array, i); |
---|
3640 | if (ith_term->flag & MVar) |
---|
3641 | compile_error("boomer:concating symbolic variables"); |
---|
3642 | |
---|
3643 | if (ith_term->hi < ith_term->lo) n_bits++; |
---|
3644 | else n_bits += (ith_term->hi - ith_term->lo + 1); |
---|
3645 | } |
---|
3646 | |
---|
3647 | retval = new_term(NIL(vl_range), 0, n_bits-1); |
---|
3648 | |
---|
3649 | return retval; |
---|
3650 | } |
---|
3651 | |
---|
3652 | |
---|
3653 | void connect_concat(FILE *file, vl_term *assign_term, array_t *lhs_array) |
---|
3654 | { |
---|
3655 | int i; |
---|
3656 | int old_lo, old_hi; |
---|
3657 | int n_bits, bit_pos; |
---|
3658 | vl_term *lhs_term; |
---|
3659 | |
---|
3660 | old_lo = assign_term->lo; |
---|
3661 | old_hi = assign_term->hi; |
---|
3662 | for (i=array_n(lhs_array)-1, bit_pos = assign_term->lo; i>=0; i--) { |
---|
3663 | lhs_term = array_fetch(vl_term*, lhs_array, i); |
---|
3664 | if (lhs_term->hi < lhs_term->lo) n_bits = 1; |
---|
3665 | else n_bits = lhs_term->hi - lhs_term->lo + 1; |
---|
3666 | assign_term->lo = bit_pos; |
---|
3667 | assign_term->hi = assign_term->lo + n_bits - 1; |
---|
3668 | vl_write_bin_connect(file, assign_term, lhs_term, 0); |
---|
3669 | bit_pos += n_bits; |
---|
3670 | } |
---|
3671 | assign_term->lo = old_lo; |
---|
3672 | assign_term->hi = old_hi; |
---|
3673 | } |
---|
3674 | |
---|
3675 | |
---|
3676 | fg_graph_info *get_assoc_lc_name(char *loc, char *lc_name) |
---|
3677 | { |
---|
3678 | int location; |
---|
3679 | lsGen ggen; |
---|
3680 | lsHandle ghandle; |
---|
3681 | graph_t *graph; |
---|
3682 | fg_graph_info *retval=NIL(fg_graph_info); |
---|
3683 | |
---|
3684 | if (!loc) return retval; |
---|
3685 | if (!lc_name) return retval; |
---|
3686 | |
---|
3687 | location = atoi(strstr(loc, FG_LLOC)+strlen(FG_LLOC)); |
---|
3688 | for(ggen=lsStart(vl_currentModule->flow_graphs); |
---|
3689 | lsNext(ggen, (lsGeneric*)&graph, &ghandle) != LS_NOMORE; ) { |
---|
3690 | if (location >= ((fg_graph_info*)graph->user_data)->pause_lo && |
---|
3691 | location < ((fg_graph_info*)graph->user_data)->pause_hi) { |
---|
3692 | sprintf(lc_name, "%s%06x", |
---|
3693 | FG_LC_PS, ((fg_graph_info*)graph->user_data)->fg_id); |
---|
3694 | retval = (fg_graph_info*)(graph->user_data); |
---|
3695 | break; |
---|
3696 | } |
---|
3697 | } |
---|
3698 | lsFinish(ggen); |
---|
3699 | |
---|
3700 | return retval; |
---|
3701 | } |
---|
3702 | |
---|
3703 | |
---|
3704 | void write_out_port(FILE *file, vl_id_range *id_sym, |
---|
3705 | int m_hi, int m_lo, vl_expr *inst_expr, |
---|
3706 | st_table *auxSigST) |
---|
3707 | { |
---|
3708 | if (inst_expr->type == IDExpr) { |
---|
3709 | st_insert(vl_currentModule->sig_st, inst_expr->u.name->name, |
---|
3710 | (char*)vl_create_id_range(inst_expr->u.name->name, |
---|
3711 | NIL(vl_range))); |
---|
3712 | } |
---|
3713 | inst_expr->term = new_term(NIL(vl_range), m_lo, m_hi); |
---|
3714 | } |
---|
3715 | |
---|
3716 | |
---|
3717 | void vl_write_outport_connect(FILE *file, vl_expr *inst_expr) |
---|
3718 | { |
---|
3719 | int rep=1; |
---|
3720 | int i; |
---|
3721 | int bitWidth; |
---|
3722 | lsGen gen; |
---|
3723 | lsHandle handle; |
---|
3724 | vl_term *term_out; |
---|
3725 | vl_expr *e; |
---|
3726 | |
---|
3727 | if (inst_expr->type != ConcatExpr) return; |
---|
3728 | |
---|
3729 | if (inst_expr->u.exprs.e2) { |
---|
3730 | rep = vl_eval_expr(inst_expr->u.exprs.e2); |
---|
3731 | } |
---|
3732 | |
---|
3733 | term_out = inst_expr->term; |
---|
3734 | assert(term_out); |
---|
3735 | term_out->hi = term_out->lo - 1; |
---|
3736 | for (i=0; i<rep; i++) { |
---|
3737 | for (gen=lsStart((lsList)(inst_expr->u.exprs.e1)); |
---|
3738 | lsNext(gen, (lsGeneric*)&e, &handle) != LS_NOMORE; ) { |
---|
3739 | vl_write_expr(file, e, NIL(st_table)); |
---|
3740 | assert(e->term); |
---|
3741 | bitWidth = (e->term->hi - e->term->lo+1); |
---|
3742 | bitWidth = (bitWidth>0) ? bitWidth : 1; |
---|
3743 | term_out->lo = term_out->hi + 1; |
---|
3744 | term_out->hi = term_out->lo + bitWidth - 1; |
---|
3745 | vl_write_bin_connect(file, term_out, e->term, 0); |
---|
3746 | } |
---|
3747 | lsFinish(gen); |
---|
3748 | } |
---|
3749 | term_out->lo = 0; |
---|
3750 | } |
---|
3751 | |
---|
3752 | |
---|
3753 | static int evaluable_expr(vl_expr *expr) |
---|
3754 | { |
---|
3755 | int old_silent_err; |
---|
3756 | int retval; |
---|
3757 | |
---|
3758 | old_silent_err = silent_err; |
---|
3759 | silent_err = 1; |
---|
3760 | Vlerrno = 0; |
---|
3761 | |
---|
3762 | vl_eval_expr(expr); |
---|
3763 | |
---|
3764 | retval = Vlerrno; |
---|
3765 | silent_err = old_silent_err; |
---|
3766 | return !retval; |
---|
3767 | } |
---|
3768 | |
---|
3769 | |
---|
3770 | void write_const_param(FILE *file, vl_expr *expr, vl_id_range *ival) |
---|
3771 | { |
---|
3772 | int l, r; |
---|
3773 | vl_expr *ce; |
---|
3774 | |
---|
3775 | if (expr->type == IDExpr) { |
---|
3776 | |
---|
3777 | l = 31; r = 0; |
---|
3778 | } else { |
---|
3779 | l = vl_eval_expr(expr->u.idrng->range->left); |
---|
3780 | if (expr->u.idrng->range->right) |
---|
3781 | r = vl_eval_expr(expr->u.idrng->range->right); |
---|
3782 | else |
---|
3783 | r = l; |
---|
3784 | } |
---|
3785 | |
---|
3786 | expr->term = new_term(NIL(vl_range), 0, (l>r)?l:r); |
---|
3787 | write_var_decl(file, expr->term); |
---|
3788 | |
---|
3789 | ce = vl_create_expr(IntExpr, (int)ival->mpg_master_exp, (double)0.0, |
---|
3790 | NIL(void), NIL(void), NIL(void)); |
---|
3791 | vl_write_const(file, ce, expr->term); |
---|
3792 | vl_chk_free((char*)ce); |
---|
3793 | |
---|
3794 | expr->term->hi = (l>r)?l:r; |
---|
3795 | expr->term->lo = (l>r)?r:l; |
---|
3796 | } |
---|
3797 | |
---|
3798 | |
---|
3799 | void chkUndefPorts(vl_expr *expr, st_table *sig_st) |
---|
3800 | { |
---|
3801 | char *dummy; |
---|
3802 | |
---|
3803 | if (implicitDeclare) |
---|
3804 | if (sig_st) |
---|
3805 | if (expr->type == IDExpr) |
---|
3806 | if (!st_lookup(vl_currentModule->sig_st, expr->u.name->name, |
---|
3807 | &dummy)) { |
---|
3808 | st_insert(sig_st, expr->u.name->name, 0); |
---|
3809 | } |
---|
3810 | } |
---|
3811 | |
---|
3812 | |
---|
3813 | void record_pseudo_cntxt(FILE *file, int fg_id, st_table *pre_cond, |
---|
3814 | char *ctrl_syndrome, |
---|
3815 | char *rst_ctrl_syndrome, st_table *vars) |
---|
3816 | { |
---|
3817 | vl_id_range *cntxt_idsym; |
---|
3818 | vl_term *out_term, *new_out; |
---|
3819 | |
---|
3820 | cntxt_idsym = vl_create_id_range(cntxt_event, NIL(vl_range)); |
---|
3821 | cntxt_idsym->flags |= EventVar; |
---|
3822 | st_insert(vl_currentModule->sig_st, cntxt_idsym->name, (char*)cntxt_idsym); |
---|
3823 | |
---|
3824 | out_term = new_term(NIL(vl_range), 0, -1); |
---|
3825 | write_int_connect(file, 1, out_term); |
---|
3826 | new_out = vl_copy_term(out_term); |
---|
3827 | |
---|
3828 | if (!rst_ckt) { |
---|
3829 | lsNewEnd(cntxt_idsym->syndrome_expr_list, |
---|
3830 | (lsGeneric)create_syndrome_expr(vlStrdup(ctrl_syndrome), |
---|
3831 | new_out, pre_cond, fg_id), |
---|
3832 | 0); |
---|
3833 | } else { |
---|
3834 | lsNewEnd(cntxt_idsym->rst_syndrome_expr_list, |
---|
3835 | (lsGeneric)create_syndrome_expr(vlStrdup(rst_ctrl_syndrome), |
---|
3836 | new_out, pre_cond, fg_id), |
---|
3837 | 0); |
---|
3838 | } |
---|
3839 | |
---|
3840 | |
---|
3841 | |
---|
3842 | |
---|
3843 | st_insert(vars, cntxt_idsym->name, |
---|
3844 | (char*)create_var_info(vl_copy_id_range(cntxt_idsym), out_term)); |
---|
3845 | |
---|
3846 | cntxt_event = NIL(char); |
---|
3847 | } |
---|
3848 | |
---|
3849 | |
---|
3850 | char *descape(char *str, char ch1, char ch2) |
---|
3851 | { |
---|
3852 | static char retval[MAXSTRLEN]; |
---|
3853 | |
---|
3854 | strcpy(retval, str); |
---|
3855 | return retval; |
---|
3856 | } |
---|
3857 | |
---|
3858 | |
---|
3859 | char *triPort(char *name) |
---|
3860 | { |
---|
3861 | static char retval[MAXSTRLEN]; |
---|
3862 | vl_id_range *id_sym; |
---|
3863 | |
---|
3864 | strcpy(retval, name); |
---|
3865 | if (st_lookup(vl_currentModule->sig_st, name, (char**)&id_sym)) { |
---|
3866 | if (Zconnection) { |
---|
3867 | if ((id_sym->flags & InPort) && (id_sym->flags & OutPort)) { |
---|
3868 | strcat(retval, SEP_GATEPIN); strcat(retval, PIN_INOUT); |
---|
3869 | } |
---|
3870 | } |
---|
3871 | } |
---|
3872 | return retval; |
---|
3873 | } |
---|
3874 | |
---|
3875 | |
---|
3876 | static char * |
---|
3877 | nond_output(char *local_name, char *var_name) |
---|
3878 | { |
---|
3879 | static char buf[MAXSTRLEN]; |
---|
3880 | char *cp; |
---|
3881 | |
---|
3882 | if (vis_nond && !rst_ckt) { |
---|
3883 | sprintf(buf, var_name); |
---|
3884 | if ((cp=strstr(buf, SEP_GATEPIN))) *cp = '\0'; |
---|
3885 | vis_nond_var = 1; |
---|
3886 | return buf; |
---|
3887 | } else { |
---|
3888 | return local_name; |
---|
3889 | } |
---|
3890 | } |
---|
3891 | |
---|
3892 | |
---|
3893 | void to_upper(char *str) |
---|
3894 | { |
---|
3895 | int i; |
---|
3896 | int len; |
---|
3897 | |
---|
3898 | len = strlen(str); |
---|
3899 | for (i=0; i<len; i++) |
---|
3900 | if (islower((int)(str[i]))) |
---|
3901 | str[i] += ('A' - 'a'); |
---|
3902 | } |
---|
3903 | |
---|
3904 | |
---|
3905 | char * |
---|
3906 | shift_mv_vars(char *inputs, int nval) |
---|
3907 | { |
---|
3908 | static char buf[MAXSTRLEN]; |
---|
3909 | int len, i; |
---|
3910 | char arg[MAXSTRLEN]; |
---|
3911 | char token[MAXSTRLEN]; |
---|
3912 | char *cp; |
---|
3913 | int ith; |
---|
3914 | |
---|
3915 | buf[0] = '\0'; |
---|
3916 | len = strlen(inputs); |
---|
3917 | for (cp=inputs, ith=0; cp<inputs+len; ith++) { |
---|
3918 | i=0; |
---|
3919 | while ((*cp == ' ' || *cp == '\t') && *cp != '\0') cp++; |
---|
3920 | while ((*cp != ' ' && *cp != '\t') && *cp != '\0') { |
---|
3921 | token[i] = *cp; |
---|
3922 | cp++; i++; |
---|
3923 | } |
---|
3924 | if (i > 0) { |
---|
3925 | token[i] = '\0'; |
---|
3926 | if (ith == 0) |
---|
3927 | sprintf(arg, " %s ", token); |
---|
3928 | else |
---|
3929 | sprintf(arg, " , %s ", token); |
---|
3930 | strcat(buf, arg); |
---|
3931 | } |
---|
3932 | } |
---|
3933 | |
---|
3934 | return buf; |
---|
3935 | } |
---|