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_copy.c,v 1.4 2009/03/09 20:25:57 fabio Exp $ |
---|
22 | |
---|
23 | |
---|
24 | */ |
---|
25 | |
---|
26 | |
---|
27 | #include "util.h" |
---|
28 | #include "st.h" |
---|
29 | #include "list.h" |
---|
30 | #include "array.h" |
---|
31 | #include "set.h" |
---|
32 | #include "stack.h" |
---|
33 | #include "vl_types.h" |
---|
34 | #include "vl_defs.h" |
---|
35 | #include "vlr_int.h" |
---|
36 | #include "vl_create.h" |
---|
37 | #include "vl_copy.h" |
---|
38 | #include "vl_traverse.h" |
---|
39 | #include "dataflow.h" |
---|
40 | #include "verilog.h" |
---|
41 | |
---|
42 | extern vl_desc *mod_list; |
---|
43 | static int CpyTrace=0; |
---|
44 | static vl_module *creatingModule; |
---|
45 | |
---|
46 | EXTERN void vl_fprintf_stmt(FILE* file, ...); |
---|
47 | |
---|
48 | vl_module *vl_copy_rename_module(vl_module *mod, char *new_name) |
---|
49 | { |
---|
50 | vl_module *retval; |
---|
51 | vl_id_range *new_id; |
---|
52 | |
---|
53 | if (mod == NULL) return NIL(vl_module); |
---|
54 | |
---|
55 | ASSERT(mod->type==ModDecl, "Expecting ModDecl"); |
---|
56 | |
---|
57 | CpyTRACE("copying module\n"); |
---|
58 | new_id = vl_copy_id_range(mod->name); |
---|
59 | vl_chk_free(new_id->name); |
---|
60 | new_id->name = vlStrdup(new_name); |
---|
61 | retval = vl_create_module(new_id, vl_copy_ports(mod->ports), (lsList)0); |
---|
62 | creatingModule = retval; |
---|
63 | retval->mod_items = vl_copy_mod_item_list(mod->mod_items); |
---|
64 | retval->type = mod->type; |
---|
65 | |
---|
66 | return retval; |
---|
67 | } |
---|
68 | |
---|
69 | vl_module *vl_copy_module(vl_module *mod) |
---|
70 | { |
---|
71 | vl_module *retval; |
---|
72 | |
---|
73 | if (mod == NULL) return NIL(vl_module); |
---|
74 | |
---|
75 | ASSERT(mod->type==ModDecl, "Expecting ModDecl"); |
---|
76 | |
---|
77 | CpyTRACE("copying module\n"); |
---|
78 | retval = vl_create_module(vl_copy_id_range(mod->name), |
---|
79 | vl_copy_ports(mod->ports), (lsList)0); |
---|
80 | creatingModule = retval; |
---|
81 | retval->mod_items = vl_copy_mod_item_list(mod->mod_items); |
---|
82 | retval->type = mod->type; |
---|
83 | |
---|
84 | return retval; |
---|
85 | } |
---|
86 | |
---|
87 | |
---|
88 | vl_primitive *vl_copy_primitive(vl_primitive *prim) |
---|
89 | { |
---|
90 | vl_primitive *retval; |
---|
91 | |
---|
92 | if (prim == NULL) return NIL(vl_primitive); |
---|
93 | |
---|
94 | ASSERT((prim->type==CombPrimDecl || prim->type==SeqPrimDecl), |
---|
95 | "Expecting PrimDecl"); |
---|
96 | |
---|
97 | CpyTRACE("copying primitive\n"); |
---|
98 | retval = vl_create_primitive(vl_copy_id_range(prim->name), |
---|
99 | vl_copy_ports(prim->ports), |
---|
100 | vl_copy_mod_item_list(prim->decls), |
---|
101 | vl_copy_prim_table(prim->type,prim->entries)); |
---|
102 | retval->type = prim->type; |
---|
103 | |
---|
104 | return retval; |
---|
105 | } |
---|
106 | |
---|
107 | |
---|
108 | lsList vl_copy_prim_table(short type, lsList entries) |
---|
109 | { |
---|
110 | vl_prim_entry *e, *entry; |
---|
111 | int i; |
---|
112 | lsHandle handle; |
---|
113 | lsGen gen; |
---|
114 | lsList retval; |
---|
115 | |
---|
116 | retval = lsCreate(); |
---|
117 | |
---|
118 | if (entries == NULL) return retval; |
---|
119 | |
---|
120 | CpyTRACE("copying primitive table\n"); |
---|
121 | for(gen = lsStart(entries); lsNext(gen, (lsGeneric*)&e, &handle) |
---|
122 | != LS_NOMORE; ) { |
---|
123 | entry = (vl_prim_entry*)chk_malloc(sizeof(vl_prim_entry)); |
---|
124 | for (i=0; i<10; i++) { |
---|
125 | if (type) type = type; |
---|
126 | entry->inputs[i] = e->inputs[i]; |
---|
127 | } |
---|
128 | entry->state = e->state; |
---|
129 | entry->next_state = e->next_state; |
---|
130 | lsNewEnd(retval, (lsGeneric)entry, 0); |
---|
131 | } |
---|
132 | (void) lsFinish(gen); |
---|
133 | |
---|
134 | return retval; |
---|
135 | } |
---|
136 | |
---|
137 | |
---|
138 | vl_decl *vl_copy_basicdecl(vl_decl *decl) |
---|
139 | { |
---|
140 | vl_decl *retval; |
---|
141 | |
---|
142 | CpyTRACE("copying Basic decl\n"); |
---|
143 | |
---|
144 | retval = (vl_decl*)chk_malloc(sizeof(vl_decl)); |
---|
145 | retval->type = decl->type; |
---|
146 | switch(decl->type) { |
---|
147 | case RealDecl: |
---|
148 | retval->ids = vl_copy_id_list(decl->ids); |
---|
149 | break; |
---|
150 | case EventDecl: |
---|
151 | retval->ids = vl_copy_id_list(decl->ids); |
---|
152 | break; |
---|
153 | case IntDecl: |
---|
154 | retval->ids = vl_copy_id_range_list(decl->ids); |
---|
155 | break; |
---|
156 | case TimeDecl: |
---|
157 | retval->ids = vl_copy_id_range_list(decl->ids); |
---|
158 | break; |
---|
159 | default: |
---|
160 | internal_error("Unexpected Basic Decl type"); break; |
---|
161 | } |
---|
162 | |
---|
163 | return retval; |
---|
164 | } |
---|
165 | |
---|
166 | |
---|
167 | vl_rangedecl *vl_copy_rangedecl(vl_rangedecl *decl) |
---|
168 | { |
---|
169 | vl_rangedecl *retval; |
---|
170 | vl_module *orig_module; |
---|
171 | |
---|
172 | CpyTRACE("copying Range decl\n"); |
---|
173 | |
---|
174 | switch(decl->type) { |
---|
175 | case InputDecl: break; |
---|
176 | case OutputDecl: break; |
---|
177 | case InoutDecl: break; |
---|
178 | case RegDecl: break; |
---|
179 | default: internal_error("Unexpected Range Decl"); break; |
---|
180 | } |
---|
181 | |
---|
182 | |
---|
183 | orig_module = vl_currentModule; |
---|
184 | vl_currentModule = creatingModule; |
---|
185 | retval = vl_create_rangedecl(NIL(vl_type), decl->type, |
---|
186 | vl_copy_range(decl->range), |
---|
187 | vl_copy_id_list(decl->ids), 0); |
---|
188 | vl_currentModule = orig_module; |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | return retval; |
---|
193 | } |
---|
194 | |
---|
195 | vl_paramdecl *vl_copy_paramdecl(vl_paramdecl *decl) |
---|
196 | { |
---|
197 | vl_module *orig_module; |
---|
198 | vl_paramdecl *retval, *old_paramdecl; |
---|
199 | |
---|
200 | CpyTRACE("Printing Parameter decl\n"); |
---|
201 | |
---|
202 | retval = (vl_paramdecl*)chk_malloc(sizeof(vl_paramdecl)); |
---|
203 | retval->type = decl->type; |
---|
204 | switch(decl->type) { |
---|
205 | case ParamDecl: break; |
---|
206 | case DefparamDecl: break; |
---|
207 | default: internal_error("Unexpected Param Decl"); break; |
---|
208 | } |
---|
209 | |
---|
210 | { |
---|
211 | vl_bassign_stmt *assign; |
---|
212 | lsHandle handle; |
---|
213 | lsGen gen; |
---|
214 | |
---|
215 | retval->assigns = lsCreate(); |
---|
216 | gen = lsStart(decl->assigns); |
---|
217 | if (lsNext(gen, (lsGeneric*)&assign, &handle) == LS_OK) { |
---|
218 | lsNewEnd(retval->assigns, |
---|
219 | (lsGeneric)vl_copy_bassign_stmt(assign), 0); |
---|
220 | while(lsNext(gen, (lsGeneric*)&assign, &handle) != LS_NOMORE) { |
---|
221 | lsNewEnd(retval->assigns, |
---|
222 | (lsGeneric)vl_copy_bassign_stmt(assign), 0); |
---|
223 | } |
---|
224 | } |
---|
225 | } |
---|
226 | |
---|
227 | old_paramdecl = retval; |
---|
228 | orig_module = vl_currentModule; |
---|
229 | vl_currentModule = creatingModule; |
---|
230 | retval = vl_create_paramdecl(retval->type, retval->assigns); |
---|
231 | vl_currentModule = orig_module; |
---|
232 | vl_chk_free((char*)old_paramdecl); |
---|
233 | |
---|
234 | return retval; |
---|
235 | } |
---|
236 | |
---|
237 | vl_netdecl *vl_copy_netdecl(vl_netdecl *decl) |
---|
238 | { |
---|
239 | vl_netdecl *retval; |
---|
240 | |
---|
241 | CpyTRACE("copying Net decl\n"); |
---|
242 | retval = (vl_netdecl*)chk_malloc(sizeof(vl_netdecl)); |
---|
243 | retval->type = decl->type; |
---|
244 | switch(decl->type) { |
---|
245 | case WireDecl: break; |
---|
246 | case TriDecl: break; |
---|
247 | case Tri0Decl: break; |
---|
248 | case Tri1Decl: break; |
---|
249 | case Supply0Decl: break; |
---|
250 | case Supply1Decl: break; |
---|
251 | case WandDecl: break; |
---|
252 | case TriandDecl: break; |
---|
253 | case WorDecl: break; |
---|
254 | case TriorDecl: break; |
---|
255 | case TriregDecl: break; |
---|
256 | default: internal_error("Unexpected Net Decl"); break; |
---|
257 | } |
---|
258 | retval->strength = vl_copy_strength(decl->strength); |
---|
259 | retval->range = vl_copy_range(decl->range); |
---|
260 | retval->delay = vl_copy_delay(decl->delay); |
---|
261 | retval->ids = vl_copy_net_list(decl->ids); |
---|
262 | |
---|
263 | return retval; |
---|
264 | } |
---|
265 | |
---|
266 | vl_task *vl_copy_task(vl_task *task) |
---|
267 | { |
---|
268 | vl_task *retval; |
---|
269 | |
---|
270 | CpyTRACE("copying Task\n"); |
---|
271 | retval = (vl_task*)chk_malloc(sizeof(vl_task)); |
---|
272 | ASSERT(task->type == TaskDecl, "Unexpected Task Type"); |
---|
273 | |
---|
274 | retval->type = task->type; |
---|
275 | retval->name = vl_copy_id_range(task->name); |
---|
276 | retval->decls = vl_copy_decl_list(task->decls); |
---|
277 | retval->stmts = vl_copy_stmt_list(task->stmts); |
---|
278 | |
---|
279 | return retval; |
---|
280 | } |
---|
281 | |
---|
282 | vl_function *vl_copy_function(vl_function *func) |
---|
283 | { |
---|
284 | vl_function *retval; |
---|
285 | |
---|
286 | CpyTRACE("Printing Function\n"); |
---|
287 | retval = (vl_function*)chk_malloc(sizeof(vl_function)); |
---|
288 | retval->type = func->type; |
---|
289 | switch(func->type) { |
---|
290 | case IntFuncDecl: |
---|
291 | |
---|
292 | break; |
---|
293 | case RealFuncDecl: |
---|
294 | |
---|
295 | break; |
---|
296 | case RangeFuncDecl: |
---|
297 | |
---|
298 | break; |
---|
299 | default: |
---|
300 | internal_error("Unexpected Function Type"); |
---|
301 | } |
---|
302 | retval->name = vl_copy_id_range(func->name); |
---|
303 | retval->decls = vl_copy_decl_list(func->decls); |
---|
304 | retval->stmts = vl_copy_stmt_list(func->stmts); |
---|
305 | |
---|
306 | return retval; |
---|
307 | } |
---|
308 | |
---|
309 | vl_gate_inst_list *vl_copy_gate_inst_list(vl_gate_inst_list *gatelist) |
---|
310 | { |
---|
311 | vl_gate_inst_list *retval; |
---|
312 | |
---|
313 | CpyTRACE("copying Gate Instance List\n"); |
---|
314 | retval = (vl_gate_inst_list*)chk_malloc(sizeof(vl_gate_inst_list)); |
---|
315 | retval->type = gatelist->type; |
---|
316 | |
---|
317 | switch(gatelist->type) { |
---|
318 | case AndGate: break; |
---|
319 | case NandGate: break; |
---|
320 | case OrGate: break; |
---|
321 | case NorGate: break; |
---|
322 | case XorGate: break; |
---|
323 | case XnorGate: break; |
---|
324 | case BufGate: break; |
---|
325 | case Bufif0Gate:break; |
---|
326 | case Bufif1Gate:break; |
---|
327 | case NotGate: break; |
---|
328 | case Notif0Gate:break; |
---|
329 | case Notif1Gate:break; |
---|
330 | case PulldownGate: break; |
---|
331 | case PullupGate: break; |
---|
332 | case NmosGate: break; |
---|
333 | case RnmosGate: break; |
---|
334 | case PmosGate: break; |
---|
335 | case RpmosGate: break; |
---|
336 | case CmosGate: break; |
---|
337 | case RcmosGate: break; |
---|
338 | case TranGate: break; |
---|
339 | case RtranGate: break; |
---|
340 | case Tranif0Gate: break; |
---|
341 | case Rtranif0Gate: break; |
---|
342 | case Tranif1Gate: break; |
---|
343 | case Rtranif1Gate: break; |
---|
344 | default: internal_error("Unexpected Gate Type"); break; |
---|
345 | } |
---|
346 | |
---|
347 | retval->strength = vl_copy_strength(gatelist->strength); |
---|
348 | retval->delays = vl_copy_delay(gatelist->delays); |
---|
349 | retval->gates = vl_copy_gates(gatelist->gates); |
---|
350 | |
---|
351 | return retval; |
---|
352 | } |
---|
353 | |
---|
354 | lsList vl_copy_gates(lsList gates) |
---|
355 | { |
---|
356 | vl_gate_inst *gate; |
---|
357 | lsHandle handle; |
---|
358 | lsGen gen; |
---|
359 | lsList retval; |
---|
360 | |
---|
361 | CpyTRACE("copying Gate Instances\n"); |
---|
362 | |
---|
363 | retval = lsCreate(); |
---|
364 | gen = lsStart(gates); |
---|
365 | if (lsNext(gen, (lsGeneric*)&gate, &handle) == LS_OK) { |
---|
366 | lsNewEnd(retval, (lsGeneric)vl_copy_gate(gate), 0); |
---|
367 | while(lsNext(gen, (lsGeneric*)&gate, &handle) != LS_NOMORE) { |
---|
368 | lsNewEnd(retval, (lsGeneric)vl_copy_gate(gate), 0); |
---|
369 | } |
---|
370 | } |
---|
371 | (void) lsFinish(gen); |
---|
372 | |
---|
373 | return retval; |
---|
374 | } |
---|
375 | |
---|
376 | vl_mod_prim_inst_list *vl_copy_prim_inst_list(vl_mod_prim_inst_list *primlist) |
---|
377 | { |
---|
378 | vl_mod_prim_inst_list *retval; |
---|
379 | |
---|
380 | CpyTRACE("copying Primitive Instance List\n"); |
---|
381 | |
---|
382 | retval = (vl_mod_prim_inst_list*)chk_malloc(sizeof(vl_mod_prim_inst_list)); |
---|
383 | retval->type = primlist->type; |
---|
384 | |
---|
385 | retval->name = vl_copy_id_range(primlist->name); |
---|
386 | retval->strength = vl_copy_strength(primlist->strength); |
---|
387 | retval->delays = vl_copy_delay(primlist->delays); |
---|
388 | retval->mps = vl_copy_prims(primlist->mps); |
---|
389 | |
---|
390 | return retval; |
---|
391 | } |
---|
392 | |
---|
393 | lsList vl_copy_prims(lsList prims) |
---|
394 | { |
---|
395 | vl_mod_prim_inst *prim; |
---|
396 | lsHandle handle; |
---|
397 | lsGen gen; |
---|
398 | lsList retval; |
---|
399 | |
---|
400 | CpyTRACE("copying Primitive Instances\n"); |
---|
401 | retval = lsCreate(); |
---|
402 | gen = lsStart(prims); |
---|
403 | if (lsNext(gen, (lsGeneric*)&prim, &handle) == LS_OK) { |
---|
404 | lsNewEnd(retval, (lsGeneric)vl_copy_prim(prim), 0); |
---|
405 | while(lsNext(gen, (lsGeneric*)&prim, &handle) != LS_NOMORE) { |
---|
406 | lsNewEnd(retval, (lsGeneric)vl_copy_prim(prim), 0); |
---|
407 | } |
---|
408 | } |
---|
409 | (void) lsFinish(gen); |
---|
410 | |
---|
411 | return retval; |
---|
412 | } |
---|
413 | |
---|
414 | vl_mod_prim_inst_list *vl_copy_mod_inst_list(vl_mod_prim_inst_list *modinstlist) |
---|
415 | { |
---|
416 | vl_mod_prim_inst_list *retval; |
---|
417 | |
---|
418 | CpyTRACE("copying Module Instance List\n"); |
---|
419 | retval = (vl_mod_prim_inst_list*)chk_malloc(sizeof(vl_mod_prim_inst_list)); |
---|
420 | retval->type = modinstlist->type; |
---|
421 | retval->name = vl_copy_id_range(modinstlist->name); |
---|
422 | retval->delays = |
---|
423 | (vl_delay*)vl_copy_param_vals((lsList)modinstlist->delays); |
---|
424 | retval->mps = vl_copy_mod_insts(modinstlist->mps); |
---|
425 | |
---|
426 | return retval; |
---|
427 | } |
---|
428 | |
---|
429 | lsList vl_copy_mod_insts(lsList modinsts) |
---|
430 | { |
---|
431 | vl_mod_prim_inst *modinst; |
---|
432 | lsHandle handle; |
---|
433 | lsGen gen; |
---|
434 | lsList retval; |
---|
435 | |
---|
436 | CpyTRACE("copying Module Instances\n"); |
---|
437 | retval = lsCreate(); |
---|
438 | gen = lsStart(modinsts); |
---|
439 | if (lsNext(gen, (lsGeneric*)&modinst, &handle) == LS_OK) { |
---|
440 | lsNewEnd(retval, (lsGeneric)vl_copy_modinst(modinst), 0); |
---|
441 | while(lsNext(gen, (lsGeneric*)&modinst, &handle) != LS_NOMORE) { |
---|
442 | lsNewEnd(retval, (lsGeneric)vl_copy_modinst(modinst), 0); |
---|
443 | } |
---|
444 | } |
---|
445 | (void) lsFinish(gen); |
---|
446 | |
---|
447 | return retval; |
---|
448 | } |
---|
449 | |
---|
450 | |
---|
451 | vl_procstmt *vl_copy_procstmt(vl_procstmt *pstmt) |
---|
452 | { |
---|
453 | vl_procstmt *retval; |
---|
454 | |
---|
455 | CpyTRACE("copying Process stmt\n"); |
---|
456 | |
---|
457 | retval = (vl_procstmt*)chk_malloc(sizeof(vl_procstmt)); |
---|
458 | retval->type = pstmt->type; |
---|
459 | |
---|
460 | switch(pstmt->type) { |
---|
461 | case AlwaysStmt: break; |
---|
462 | case InitialStmt: break; |
---|
463 | default: internal_error("Unexpected Process Statement Type"); break; |
---|
464 | } |
---|
465 | |
---|
466 | retval->stmt = vl_copy_stmt(pstmt->stmt); |
---|
467 | retval->pc = vl_create_symbolic_var(vlStrdup(new_pc())); |
---|
468 | |
---|
469 | return retval; |
---|
470 | } |
---|
471 | |
---|
472 | vl_begin_end_stmt *vl_copy_begin_end_stmt(vl_begin_end_stmt *bestmt) |
---|
473 | { |
---|
474 | vl_begin_end_stmt *retval; |
---|
475 | |
---|
476 | CpyTRACE("copying beginend\n"); |
---|
477 | ASSERT(bestmt->type == BeginEndStmt, "Unexpected BeginEndStmt Type"); |
---|
478 | |
---|
479 | retval = (vl_begin_end_stmt*)chk_malloc(sizeof(vl_begin_end_stmt)); |
---|
480 | retval->type = bestmt->type; |
---|
481 | |
---|
482 | retval->decls = vl_copy_decl_list(bestmt->decls); |
---|
483 | retval->stmts = vl_copy_stmt_list(bestmt->stmts); |
---|
484 | |
---|
485 | return retval; |
---|
486 | } |
---|
487 | |
---|
488 | vl_if_else_stmt *vl_copy_if_else_stmt(vl_if_else_stmt *stmt) |
---|
489 | { |
---|
490 | vl_if_else_stmt *retval; |
---|
491 | |
---|
492 | CpyTRACE("copying if_else_stmt\n"); |
---|
493 | ASSERT(stmt->type == IfElseStmt, "Unexpected IfElseStmt Type"); |
---|
494 | |
---|
495 | retval = (vl_if_else_stmt*)chk_malloc(sizeof(vl_if_else_stmt)); |
---|
496 | retval->type = stmt->type; |
---|
497 | |
---|
498 | retval->cond = vl_copy_expr(stmt->cond); |
---|
499 | retval->if_stmt = vl_copy_stmt(stmt->if_stmt); |
---|
500 | |
---|
501 | if (stmt->else_stmt) { |
---|
502 | retval->else_stmt = vl_copy_stmt(stmt->else_stmt); |
---|
503 | } else { |
---|
504 | retval->else_stmt = NIL(void); |
---|
505 | } |
---|
506 | |
---|
507 | return retval; |
---|
508 | } |
---|
509 | |
---|
510 | vl_case_stmt *vl_copy_case_stmt(vl_case_stmt *stmt) |
---|
511 | { |
---|
512 | vl_case_stmt *retval; |
---|
513 | |
---|
514 | CpyTRACE("copying case_stmt\n"); |
---|
515 | |
---|
516 | retval = (vl_case_stmt*)chk_malloc(sizeof(vl_case_stmt)); |
---|
517 | retval->type = stmt->type; |
---|
518 | switch(stmt->type) { |
---|
519 | case CaseStmt: break; |
---|
520 | case CasexStmt: break; |
---|
521 | case CasezStmt: break; |
---|
522 | default: internal_error("Unexpected Case Type"); break; |
---|
523 | } |
---|
524 | retval->cond = vl_copy_expr(stmt->cond); |
---|
525 | |
---|
526 | { |
---|
527 | vl_case_item *item, *case_item; |
---|
528 | lsHandle handle; |
---|
529 | lsGen gen; |
---|
530 | |
---|
531 | retval->case_items = lsCreate(); |
---|
532 | gen = lsStart(stmt->case_items); |
---|
533 | while(lsNext(gen, (lsGeneric*)&item, &handle) != LS_NOMORE) { |
---|
534 | case_item = vl_copy_case_item(item); |
---|
535 | case_item->type = item->type; |
---|
536 | lsNewEnd(retval->case_items, (lsGeneric)case_item, 0); |
---|
537 | } |
---|
538 | } |
---|
539 | |
---|
540 | return retval; |
---|
541 | } |
---|
542 | |
---|
543 | vl_forever_stmt *vl_copy_forever_stmt(vl_forever_stmt *stmt) |
---|
544 | { |
---|
545 | vl_forever_stmt *retval; |
---|
546 | |
---|
547 | CpyTRACE("Printing forever_stmt\n"); |
---|
548 | ASSERT(stmt->type == ForeverStmt, "Unexpected ForeverStmt Type"); |
---|
549 | |
---|
550 | retval = (vl_forever_stmt*)chk_malloc(sizeof(vl_forever_stmt)); |
---|
551 | retval->type = stmt->type; |
---|
552 | retval->stmt = vl_copy_stmt(stmt->stmt); |
---|
553 | |
---|
554 | return retval; |
---|
555 | } |
---|
556 | |
---|
557 | vl_repeat_stmt *vl_copy_repeat_stmt(vl_repeat_stmt *stmt) |
---|
558 | { |
---|
559 | vl_repeat_stmt *retval; |
---|
560 | |
---|
561 | CpyTRACE("copying repeat_stmt\n"); |
---|
562 | ASSERT(stmt->type == RepeatStmt, "Unexpected RepeatStmt Type"); |
---|
563 | |
---|
564 | retval = (vl_repeat_stmt*)chk_malloc(sizeof(vl_repeat_stmt)); |
---|
565 | retval->type = stmt->type; |
---|
566 | retval->count = vl_copy_expr(stmt->count); |
---|
567 | retval->stmt = vl_copy_stmt(stmt->stmt); |
---|
568 | |
---|
569 | return retval; |
---|
570 | } |
---|
571 | |
---|
572 | vl_while_stmt *vl_copy_while_stmt(vl_while_stmt *stmt) |
---|
573 | { |
---|
574 | vl_while_stmt *retval; |
---|
575 | |
---|
576 | CpyTRACE("Printing while_stmt\n"); |
---|
577 | ASSERT(stmt->type == WhileStmt, "Unexpected WhileStmt Type"); |
---|
578 | |
---|
579 | retval = (vl_while_stmt*)chk_malloc(sizeof(vl_while_stmt)); |
---|
580 | retval->type = stmt->type; |
---|
581 | retval->cond = vl_copy_expr(stmt->cond); |
---|
582 | retval->stmt = vl_copy_stmt(stmt->stmt); |
---|
583 | |
---|
584 | return retval; |
---|
585 | } |
---|
586 | |
---|
587 | vl_for_stmt *vl_copy_for_stmt(vl_for_stmt *stmt) |
---|
588 | { |
---|
589 | vl_for_stmt *retval; |
---|
590 | |
---|
591 | CpyTRACE("copying for_stmt\n"); |
---|
592 | ASSERT(stmt->type == ForStmt, "Unexpected ForStmt Type"); |
---|
593 | |
---|
594 | retval = (vl_for_stmt*)chk_malloc(sizeof(vl_for_stmt)); |
---|
595 | retval->type = stmt->type; |
---|
596 | retval->init = vl_copy_bassign_stmt(stmt->init); |
---|
597 | retval->cond = vl_copy_expr(stmt->cond); |
---|
598 | retval->end = vl_copy_bassign_stmt(stmt->end); |
---|
599 | retval->stmt = vl_copy_stmt(stmt->stmt); |
---|
600 | |
---|
601 | return retval; |
---|
602 | } |
---|
603 | |
---|
604 | vl_delay_control_stmt *vl_copy_delay_control_stmt(vl_delay_control_stmt *stmt) |
---|
605 | { |
---|
606 | vl_delay_control_stmt *retval; |
---|
607 | |
---|
608 | CpyTRACE("copying delay_control_stmt\n"); |
---|
609 | ASSERT(stmt->type == DelayControlStmt, "Unexpected DelayControlStmt Type"); |
---|
610 | |
---|
611 | retval = (vl_delay_control_stmt*)chk_malloc(sizeof(vl_delay_control_stmt)); |
---|
612 | retval->type = stmt->type; |
---|
613 | retval->delay = vl_copy_delay(stmt->delay); |
---|
614 | retval->stmt = vl_copy_stmt(stmt->stmt); |
---|
615 | |
---|
616 | return retval; |
---|
617 | } |
---|
618 | |
---|
619 | vl_event_control_stmt *vl_copy_event_control_stmt(vl_event_control_stmt *stmt) |
---|
620 | { |
---|
621 | vl_event_control_stmt *retval; |
---|
622 | |
---|
623 | CpyTRACE("copying event_control_stmt\n"); |
---|
624 | ASSERT(stmt->type == EventControlStmt, "Unexpected EventControlStmt Type"); |
---|
625 | |
---|
626 | retval = (vl_event_control_stmt*)chk_malloc(sizeof(vl_event_control_stmt)); |
---|
627 | retval->type = stmt->type; |
---|
628 | retval->event = vl_copy_event_expr(stmt->event); |
---|
629 | retval->stmt = vl_copy_stmt(stmt->stmt); |
---|
630 | |
---|
631 | return retval; |
---|
632 | } |
---|
633 | |
---|
634 | |
---|
635 | vl_bassign_stmt *vl_copy_bassign_stmt(vl_bassign_stmt *bassign) |
---|
636 | { |
---|
637 | vl_bassign_stmt *retval; |
---|
638 | |
---|
639 | CpyTRACE("Printing bassign_stmt\n"); |
---|
640 | |
---|
641 | if (bassign->type == AssignStmt) { |
---|
642 | vl_fprintf_stmt(stdout, "assign "); /* Fabio's temp. fix */ |
---|
643 | } |
---|
644 | |
---|
645 | retval = (vl_bassign_stmt*)chk_malloc(sizeof(vl_bassign_stmt)); |
---|
646 | retval->type = bassign->type; |
---|
647 | |
---|
648 | retval->lhs = vl_copy_lval(bassign->lhs); |
---|
649 | |
---|
650 | bassign->control = NIL(void); |
---|
651 | switch(bassign->type) { |
---|
652 | case AssignStmt: |
---|
653 | case BassignStmt: |
---|
654 | break; |
---|
655 | case NbassignStmt: |
---|
656 | break; |
---|
657 | case DelayBassignStmt: |
---|
658 | retval->control = vl_copy_delay((vl_delay *)bassign->control); |
---|
659 | break; |
---|
660 | case DelayNbassignStmt: |
---|
661 | retval->control = vl_copy_delay((vl_delay *)bassign->control); |
---|
662 | break; |
---|
663 | case EventBassignStmt: |
---|
664 | retval->control = vl_copy_event_expr((vl_event_expr*)bassign->control); |
---|
665 | break; |
---|
666 | case EventNbassignStmt: |
---|
667 | retval->control = vl_copy_event_expr((vl_event_expr*)bassign->control); |
---|
668 | break; |
---|
669 | default: internal_error("Unexpected Assign Type"); break; |
---|
670 | } |
---|
671 | retval->rhs = vl_copy_expr(bassign->rhs); |
---|
672 | |
---|
673 | return retval; |
---|
674 | } |
---|
675 | |
---|
676 | vl_wait_stmt *vl_copy_wait_stmt(vl_wait_stmt *stmt) |
---|
677 | { |
---|
678 | vl_wait_stmt *retval; |
---|
679 | |
---|
680 | CpyTRACE("copying wait_stmt\n"); |
---|
681 | ASSERT(stmt->type == WaitStmt, "Unexpected WaitStmt Type"); |
---|
682 | |
---|
683 | retval = (vl_wait_stmt*)chk_malloc(sizeof(vl_wait_stmt)); |
---|
684 | retval->type = stmt->type; |
---|
685 | retval->cond = vl_copy_expr(stmt->cond); |
---|
686 | retval->stmt = vl_copy_stmt(stmt->stmt); |
---|
687 | |
---|
688 | return retval; |
---|
689 | } |
---|
690 | |
---|
691 | vl_fork_join_stmt *vl_copy_fork_join_stmt(vl_fork_join_stmt *stmt) |
---|
692 | { |
---|
693 | vl_fork_join_stmt *retval; |
---|
694 | |
---|
695 | CpyTRACE("copying fork_join_stmt\n"); |
---|
696 | ASSERT(stmt->type == ForkJoinStmt, "Unexpected ForkJoinStmt Type"); |
---|
697 | |
---|
698 | retval = (vl_fork_join_stmt*)chk_malloc(sizeof(vl_fork_join_stmt)); |
---|
699 | retval->type = stmt->type; |
---|
700 | retval->decls = vl_copy_decl_list(stmt->decls); |
---|
701 | retval->stmts = vl_copy_stmt_list(stmt->stmts); |
---|
702 | |
---|
703 | return retval; |
---|
704 | } |
---|
705 | |
---|
706 | |
---|
707 | vl_task_enable_stmt *vl_copy_task_enable_stmt(vl_task_enable_stmt *stmt) |
---|
708 | { |
---|
709 | vl_task_enable_stmt *retval; |
---|
710 | |
---|
711 | CpyTRACE("Printing task_enable_stmt\n"); |
---|
712 | ASSERT(((stmt->type == TaskEnableStmt) || |
---|
713 | (stmt->type == SysTaskEnableStmt)), |
---|
714 | "Unexpected TaskEnableStmt Type"); |
---|
715 | |
---|
716 | retval = (vl_task_enable_stmt*)chk_malloc(sizeof(vl_task_enable_stmt)); |
---|
717 | retval->type = stmt->type; |
---|
718 | retval->name = vl_copy_id_range(stmt->name); |
---|
719 | if (stmt->args) { |
---|
720 | |
---|
721 | retval->args = vl_copy_expr_list(stmt->args); |
---|
722 | } else { |
---|
723 | retval->args = (lsList)0; |
---|
724 | } |
---|
725 | |
---|
726 | return retval; |
---|
727 | } |
---|
728 | |
---|
729 | vl_disable_stmt *vl_copy_disable_stmt(vl_disable_stmt *stmt) |
---|
730 | { |
---|
731 | vl_disable_stmt *retval; |
---|
732 | |
---|
733 | CpyTRACE("copying disable_stmt\n"); |
---|
734 | ASSERT(stmt->type == DisableStmt, "Unexpected DisableStmt Type"); |
---|
735 | |
---|
736 | retval = (vl_disable_stmt*)chk_malloc(sizeof(vl_disable_stmt)); |
---|
737 | retval->type = stmt->type; |
---|
738 | retval->name = vl_copy_id_range(stmt->name); |
---|
739 | |
---|
740 | return retval; |
---|
741 | } |
---|
742 | |
---|
743 | vl_deassign_stmt *vl_copy_deassign_stmt(vl_deassign_stmt *stmt) |
---|
744 | { |
---|
745 | vl_deassign_stmt *retval; |
---|
746 | |
---|
747 | CpyTRACE("Printing deassign_stmt\n"); |
---|
748 | ASSERT(stmt->type == DeassignStmt, "Unexpected DeassignStmt Type"); |
---|
749 | |
---|
750 | retval = (vl_deassign_stmt*)chk_malloc(sizeof(vl_deassign_stmt)); |
---|
751 | retval->type = stmt->type; |
---|
752 | retval->lhs = vl_copy_lval(stmt->lhs); |
---|
753 | |
---|
754 | return retval; |
---|
755 | } |
---|
756 | |
---|
757 | vl_case_item *vl_copy_case_item(vl_case_item *item) |
---|
758 | { |
---|
759 | vl_case_item *retval; |
---|
760 | |
---|
761 | CpyTRACE("Printing case_item\n"); |
---|
762 | retval = (vl_case_item*)chk_malloc(sizeof(vl_case_item)); |
---|
763 | retval->type = item->type; |
---|
764 | switch(item->type) { |
---|
765 | case CaseItem: retval->exprs = vl_copy_expr_list(item->exprs); break; |
---|
766 | case DefaultItem: break; |
---|
767 | default: internal_error("Unexpected CaseItem Type"); break; |
---|
768 | } |
---|
769 | retval->stmt = vl_copy_stmt(item->stmt); |
---|
770 | |
---|
771 | return retval; |
---|
772 | } |
---|
773 | |
---|
774 | vl_event_expr *vl_copy_event_expr(vl_event_expr *event) |
---|
775 | { |
---|
776 | vl_event_expr *retval; |
---|
777 | |
---|
778 | CpyTRACE("Printing event_expr\n"); |
---|
779 | if (event == NIL(vl_event_expr)) return NIL(vl_event_expr); |
---|
780 | |
---|
781 | retval = (vl_event_expr*)chk_malloc(sizeof(vl_event_expr)); |
---|
782 | retval->type = event->type; |
---|
783 | retval->list = (lsList)0; |
---|
784 | switch(event->type) { |
---|
785 | case OrEventExpr: { |
---|
786 | vl_event_expr *e; |
---|
787 | lsHandle handle; |
---|
788 | lsGen gen; |
---|
789 | |
---|
790 | retval->list = lsCreate(); |
---|
791 | gen = lsStart(event->list); |
---|
792 | if (lsNext(gen, (lsGeneric*)&e, &handle) == LS_OK) { |
---|
793 | lsNewEnd(retval->list, (lsGeneric)vl_copy_event_expr(e), 0); |
---|
794 | while(lsNext(gen, (lsGeneric*)&e, &handle) != LS_NOMORE) { |
---|
795 | lsNewEnd(retval->list, (lsGeneric)vl_copy_event_expr(e), 0); |
---|
796 | } |
---|
797 | } |
---|
798 | (void) lsFinish(gen); |
---|
799 | |
---|
800 | return retval; |
---|
801 | } |
---|
802 | case NegedgeEventExpr: retval->expr = vl_copy_expr(event->expr); break; |
---|
803 | case PosedgeEventExpr: retval->expr = vl_copy_expr(event->expr); break; |
---|
804 | case EdgeEventExpr: retval->expr = vl_copy_expr(event->expr); break; |
---|
805 | case EventExpr: retval->expr = vl_copy_expr(event->expr); break; |
---|
806 | default: internal_error("Unexpected EventExpr Type"); break; |
---|
807 | } |
---|
808 | |
---|
809 | return retval; |
---|
810 | } |
---|
811 | |
---|
812 | vl_lval *vl_copy_lval(vl_lval *lval) |
---|
813 | { |
---|
814 | vl_lval *retval; |
---|
815 | |
---|
816 | CpyTRACE("Printing lval\n"); |
---|
817 | |
---|
818 | retval = (vl_lval*)chk_malloc(sizeof(vl_lval)); |
---|
819 | retval->type = lval->type; |
---|
820 | switch(lval->type) { |
---|
821 | case IDExpr: retval->name = vl_copy_id_range(lval->name); break; |
---|
822 | case BitSelExpr: |
---|
823 | case PartSelExpr: |
---|
824 | retval->name = vl_copy_id_range(lval->name); |
---|
825 | retval->range = vl_copy_range(lval->range); |
---|
826 | break; |
---|
827 | case ConcatExpr: { |
---|
828 | vl_expr *e; |
---|
829 | lsHandle handle; |
---|
830 | lsGen gen; |
---|
831 | |
---|
832 | retval->concat = lsCreate(); |
---|
833 | gen = lsStart(lval->concat); |
---|
834 | if (lsNext(gen, (lsGeneric*)&e, &handle) == LS_OK) { |
---|
835 | lsNewEnd(lval->concat, (lsGeneric)vl_copy_expr(e), 0); |
---|
836 | while(lsNext(gen, (lsGeneric*)&e, &handle) != LS_NOMORE) { |
---|
837 | lsNewEnd(lval->concat, (lsGeneric)vl_copy_expr(e), 0); |
---|
838 | } |
---|
839 | } |
---|
840 | (void) lsFinish(gen); |
---|
841 | |
---|
842 | break; |
---|
843 | } |
---|
844 | |
---|
845 | default: internal_error("Unexpected Lval Type"); break; |
---|
846 | } |
---|
847 | |
---|
848 | return retval; |
---|
849 | } |
---|
850 | |
---|
851 | vl_expr *vl_copy_expr(vl_expr *expr) |
---|
852 | { |
---|
853 | vl_expr *retval; |
---|
854 | |
---|
855 | if (!expr) return NIL(vl_expr); |
---|
856 | CpyTRACE("Printing expr\n"); |
---|
857 | |
---|
858 | retval = (vl_expr*)chk_malloc(sizeof(vl_expr)); |
---|
859 | retval->type = expr->type; |
---|
860 | switch (expr->type) { |
---|
861 | case BitExpr: |
---|
862 | retval->u.exprs.e1 = expr->u.exprs.e1; |
---|
863 | retval->u.exprs.e2 = expr->u.exprs.e2; |
---|
864 | retval->u.exprs.e3 = (vl_expr*)vlStrdup((char*)expr->u.exprs.e3); |
---|
865 | break; |
---|
866 | case IntExpr: |
---|
867 | retval->u.intval = expr->u.intval; |
---|
868 | break; |
---|
869 | case RealExpr: |
---|
870 | retval->u.realval = expr->u.realval; |
---|
871 | break; |
---|
872 | case IDExpr: |
---|
873 | retval->u.name = vl_copy_id_range(expr->u.name); |
---|
874 | break; |
---|
875 | case BitSelExpr: case PartSelExpr: |
---|
876 | retval->u.idrng = vl_copy_id_range_rec(expr->u.idrng); |
---|
877 | break; |
---|
878 | case ConcatExpr: { |
---|
879 | |
---|
880 | vl_expr *e; |
---|
881 | lsHandle handle; |
---|
882 | lsGen gen; |
---|
883 | |
---|
884 | retval->u.exprs.e1 = (vl_expr*)lsCreate(); |
---|
885 | gen = lsStart((lsList)(expr->u.exprs.e1)); |
---|
886 | if (lsNext(gen, (lsGeneric*)&e, &handle) == LS_OK) { |
---|
887 | lsNewEnd((lsList)retval->u.exprs.e1, |
---|
888 | (lsGeneric)vl_copy_expr(e), 0); |
---|
889 | while(lsNext(gen, (lsGeneric*)&e, &handle) != LS_NOMORE) { |
---|
890 | lsNewEnd((lsList)retval->u.exprs.e1, |
---|
891 | (lsGeneric)vl_copy_expr(e), 0); |
---|
892 | } |
---|
893 | } |
---|
894 | (void) lsFinish(gen); |
---|
895 | break; |
---|
896 | } |
---|
897 | case MinTypMaxExpr: { |
---|
898 | |
---|
899 | retval->u.exprs.e1 = vl_copy_expr(expr->u.exprs.e1); |
---|
900 | if (expr->u.exprs.e2) { |
---|
901 | retval->u.exprs.e2 = vl_copy_expr(expr->u.exprs.e2); |
---|
902 | } |
---|
903 | if (expr->u.exprs.e3) { |
---|
904 | retval->u.exprs.e3 = vl_copy_expr(expr->u.exprs.e3); |
---|
905 | } |
---|
906 | break; |
---|
907 | } |
---|
908 | case StringExpr: retval->u.string = vlStrdup(expr->u.string); break; |
---|
909 | case FuncExpr: |
---|
910 | retval->u.func_call.name = vl_copy_id_range(expr->u.func_call.name); |
---|
911 | if (expr->u.func_call.args) { |
---|
912 | retval->u.func_call.args = |
---|
913 | vl_copy_expr_list(expr->u.func_call.args); |
---|
914 | } |
---|
915 | break; |
---|
916 | case UplusExpr: case UminusExpr: |
---|
917 | case UnotExpr: case UcomplExpr: |
---|
918 | |
---|
919 | case UandExpr: case UnandExpr: |
---|
920 | case UorExpr: case UnorExpr: |
---|
921 | case UxorExpr: case UxnorExpr: |
---|
922 | retval->u.exprs.e1 = vl_copy_expr(expr->u.exprs.e1); |
---|
923 | break; |
---|
924 | |
---|
925 | case BplusExpr: case BminusExpr: |
---|
926 | case BtimesExpr: case BdivExpr: |
---|
927 | case BremExpr: case Beq2Expr: |
---|
928 | case Bneq2Expr: case Beq3Expr: |
---|
929 | case Bneq3Expr: case BlandExpr: |
---|
930 | case BlorExpr: case BltExpr: |
---|
931 | case BleExpr: case BgtExpr: |
---|
932 | case BgeExpr: case BandExpr: |
---|
933 | case BorExpr: case BxorExpr: |
---|
934 | case BxnorExpr: case BlshiftExpr: |
---|
935 | case BrshiftExpr: |
---|
936 | retval->u.exprs.e1 = vl_copy_expr(expr->u.exprs.e1); |
---|
937 | retval->u.exprs.e2 = vl_copy_expr(expr->u.exprs.e2); |
---|
938 | break; |
---|
939 | |
---|
940 | case TcondExpr: |
---|
941 | retval->u.exprs.e1 = vl_copy_expr(expr->u.exprs.e1); |
---|
942 | retval->u.exprs.e2 = vl_copy_expr(expr->u.exprs.e2); |
---|
943 | retval->u.exprs.e3 = vl_copy_expr(expr->u.exprs.e3); |
---|
944 | break; |
---|
945 | case NondExpr: |
---|
946 | retval->u.expr_list = vl_copy_expr_list(expr->u.expr_list); |
---|
947 | break; |
---|
948 | } |
---|
949 | |
---|
950 | return retval; |
---|
951 | } |
---|
952 | |
---|
953 | |
---|
954 | lsList vl_copy_expr_list(lsList exprs) |
---|
955 | { |
---|
956 | void *expr; |
---|
957 | lsHandle handle; |
---|
958 | lsGen gen; |
---|
959 | lsList retval; |
---|
960 | |
---|
961 | CpyTRACE("copying Expression List\n"); |
---|
962 | if (lsLength(exprs) <= 0) return (lsList)0; |
---|
963 | retval = lsCreate(); |
---|
964 | gen = lsStart(exprs); |
---|
965 | if (lsNext(gen, (lsGeneric*)&expr, &handle) == LS_OK) { |
---|
966 | lsNewEnd(retval, (lsGeneric)vl_copy_expr(expr), 0); |
---|
967 | while(lsNext(gen, (lsGeneric*)&expr, &handle) != LS_NOMORE) { |
---|
968 | lsNewEnd(retval, (lsGeneric)vl_copy_expr(expr), 0); |
---|
969 | } |
---|
970 | } |
---|
971 | (void) lsFinish(gen); |
---|
972 | |
---|
973 | return retval; |
---|
974 | } |
---|
975 | |
---|
976 | vl_range *vl_copy_range(vl_range *range) |
---|
977 | { |
---|
978 | vl_range *retval; |
---|
979 | |
---|
980 | CpyTRACE("copying range\n"); |
---|
981 | |
---|
982 | if (range == NIL(vl_range) || |
---|
983 | (range->left == NIL(vl_expr) && range->right == NIL(vl_expr))) |
---|
984 | return NIL(vl_range); |
---|
985 | |
---|
986 | retval = (vl_range*)chk_malloc(sizeof(vl_range)); |
---|
987 | retval->left = vl_copy_expr(range->left); |
---|
988 | if (range->right) { |
---|
989 | retval->right = vl_copy_expr(range->right); |
---|
990 | } |
---|
991 | |
---|
992 | return retval; |
---|
993 | } |
---|
994 | |
---|
995 | |
---|
996 | vl_delay *vl_copy_delay(vl_delay *delay) |
---|
997 | { |
---|
998 | vl_delay *retval; |
---|
999 | |
---|
1000 | CpyTRACE("copying delay\n"); |
---|
1001 | if (delay == NIL(vl_delay)) return NIL(vl_delay); |
---|
1002 | |
---|
1003 | retval = (vl_delay*)chk_malloc(sizeof(vl_delay)); |
---|
1004 | retval->delay1 = vl_copy_expr(delay->delay1); |
---|
1005 | if (delay->delay2) { |
---|
1006 | delay->delay2 = vl_copy_expr(delay->delay2); |
---|
1007 | if (delay->delay3) { |
---|
1008 | delay->delay3 = vl_copy_expr(delay->delay3); |
---|
1009 | } |
---|
1010 | } |
---|
1011 | |
---|
1012 | return retval; |
---|
1013 | } |
---|
1014 | |
---|
1015 | |
---|
1016 | lsList vl_copy_id_list(lsList ids) |
---|
1017 | { |
---|
1018 | vl_id_range *id; |
---|
1019 | lsHandle handle; |
---|
1020 | lsGen gen; |
---|
1021 | lsList retval; |
---|
1022 | |
---|
1023 | retval = lsCreate(); |
---|
1024 | gen = lsStart(ids); |
---|
1025 | if (lsNext(gen, (lsGeneric*)&id, &handle) == LS_OK) { |
---|
1026 | lsNewEnd(retval, (lsGeneric)vl_copy_id_range(id), 0); |
---|
1027 | while(lsNext(gen, (lsGeneric*)&id, &handle) != LS_NOMORE) { |
---|
1028 | lsNewEnd(retval, (lsGeneric)vl_copy_id_range(id), 0); |
---|
1029 | } |
---|
1030 | } |
---|
1031 | (void) lsFinish(gen); |
---|
1032 | |
---|
1033 | return retval; |
---|
1034 | } |
---|
1035 | |
---|
1036 | |
---|
1037 | lsList vl_copy_id_range_list(lsList ids) |
---|
1038 | { |
---|
1039 | vl_id_range *id; |
---|
1040 | lsHandle handle; |
---|
1041 | lsGen gen; |
---|
1042 | lsList retval; |
---|
1043 | |
---|
1044 | if (ids == (lsList)0) return (lsList)0; |
---|
1045 | retval = lsCreate(); |
---|
1046 | gen = lsStart(ids); |
---|
1047 | if (lsNext(gen, (lsGeneric*)&id, &handle) == LS_OK) { |
---|
1048 | lsNewEnd(retval, (lsGeneric)vl_copy_id_range(id), 0); |
---|
1049 | while(lsNext(gen, (lsGeneric*)&id, &handle) != LS_NOMORE) { |
---|
1050 | lsNewEnd(retval, (lsGeneric)vl_copy_id_range(id), 0); |
---|
1051 | } |
---|
1052 | } |
---|
1053 | (void) lsFinish(gen); |
---|
1054 | |
---|
1055 | return retval; |
---|
1056 | } |
---|
1057 | |
---|
1058 | |
---|
1059 | lsList vl_copy_net_list(lsList nets) |
---|
1060 | { |
---|
1061 | void *net; |
---|
1062 | lsHandle handle; |
---|
1063 | lsGen gen; |
---|
1064 | lsList retval; |
---|
1065 | |
---|
1066 | retval = lsCreate(); |
---|
1067 | gen = lsStart(nets); |
---|
1068 | if (lsNext(gen, (lsGeneric*)&net, &handle) == LS_OK) { |
---|
1069 | lsNewEnd(retval, vl_copy_net(net), 0); |
---|
1070 | while(lsNext(gen, (lsGeneric*)&net, &handle) != LS_NOMORE) { |
---|
1071 | lsNewEnd(retval, vl_copy_net(net), 0); |
---|
1072 | } |
---|
1073 | } |
---|
1074 | (void) lsFinish(gen); |
---|
1075 | |
---|
1076 | return retval; |
---|
1077 | } |
---|
1078 | |
---|
1079 | |
---|
1080 | void *vl_copy_net(void *net) |
---|
1081 | { |
---|
1082 | void *retval=NIL(void); |
---|
1083 | |
---|
1084 | switch(((vl_expr *)net)->type) { |
---|
1085 | case BassignStmt: retval = (void*)vl_copy_bassign_stmt(net); break; |
---|
1086 | case IDExpr: retval = (void*)vl_copy_expr(net); break; |
---|
1087 | default: retval = (void*)vl_copy_id_range((vl_id_range*)net); break; |
---|
1088 | } |
---|
1089 | |
---|
1090 | return retval; |
---|
1091 | } |
---|
1092 | |
---|
1093 | |
---|
1094 | lsList vl_copy_ports (lsList ports) |
---|
1095 | { |
---|
1096 | void *item; |
---|
1097 | lsHandle handle; |
---|
1098 | lsGen gen; |
---|
1099 | lsList retval; |
---|
1100 | |
---|
1101 | if (ports != (lsList)0) { |
---|
1102 | retval = lsCreate(); |
---|
1103 | gen = lsStart(ports); |
---|
1104 | if (lsNext(gen, (lsGeneric*)&item, &handle) == LS_OK) { |
---|
1105 | lsNewEnd(retval, (lsGeneric)vl_copy_port(item), 0); |
---|
1106 | while (lsNext(gen, (lsGeneric*)&item, &handle) != LS_NOMORE) { |
---|
1107 | lsNewEnd(retval, (lsGeneric)vl_copy_port(item), 0); |
---|
1108 | } |
---|
1109 | } |
---|
1110 | (void) lsFinish(gen); |
---|
1111 | return retval; |
---|
1112 | } |
---|
1113 | |
---|
1114 | return (lsList)0; |
---|
1115 | } |
---|
1116 | |
---|
1117 | vl_port *vl_copy_port(vl_portPtr port) |
---|
1118 | { |
---|
1119 | vl_port *retval; |
---|
1120 | |
---|
1121 | retval = (vl_port*)chk_malloc(sizeof(vl_port)); |
---|
1122 | retval->type = port->type; |
---|
1123 | if (port->type == NamedPort) { |
---|
1124 | retval->id = vl_copy_id_range(port->id); |
---|
1125 | } |
---|
1126 | |
---|
1127 | retval->port_exp = vl_copy_id_range_list(port->port_exp); |
---|
1128 | |
---|
1129 | return retval; |
---|
1130 | } |
---|
1131 | |
---|
1132 | |
---|
1133 | lsList vl_copy_connects (lsList connects) |
---|
1134 | { |
---|
1135 | void *item; |
---|
1136 | lsHandle handle; |
---|
1137 | lsGen gen; |
---|
1138 | lsList retval; |
---|
1139 | |
---|
1140 | |
---|
1141 | if (connects != (lsList)0) { |
---|
1142 | retval = lsCreate(); |
---|
1143 | gen = lsStart(connects); |
---|
1144 | if (lsNext(gen, (lsGeneric*)&item, &handle) == LS_OK) { |
---|
1145 | lsNewEnd(retval, (lsGeneric)vl_copy_port_connect(item), 0); |
---|
1146 | while (lsNext(gen, (lsGeneric*)&item, &handle) != LS_NOMORE) { |
---|
1147 | lsNewEnd(retval, (lsGeneric)vl_copy_port_connect(item), 0); |
---|
1148 | } |
---|
1149 | } |
---|
1150 | (void) lsFinish(gen); |
---|
1151 | return retval; |
---|
1152 | } |
---|
1153 | |
---|
1154 | return (lsList)0; |
---|
1155 | } |
---|
1156 | |
---|
1157 | vl_port_connect *vl_copy_port_connect(vl_port_connectPtr connect) |
---|
1158 | { |
---|
1159 | vl_port_connect *retval=NIL(vl_port_connect); |
---|
1160 | |
---|
1161 | retval = (vl_port_connect*)chk_malloc(sizeof(vl_port_connect)); |
---|
1162 | retval->type = connect->type; |
---|
1163 | if (connect->type == NamedConnect) { |
---|
1164 | retval->id = vl_copy_id_range(connect->id); |
---|
1165 | } |
---|
1166 | |
---|
1167 | retval->expr = vl_copy_expr(connect->expr); |
---|
1168 | |
---|
1169 | return retval; |
---|
1170 | } |
---|
1171 | |
---|
1172 | |
---|
1173 | lsList vl_copy_mod_item_list (lsList mitems) |
---|
1174 | { |
---|
1175 | void *item; |
---|
1176 | lsHandle handle; |
---|
1177 | lsGen gen; |
---|
1178 | lsList retval; |
---|
1179 | |
---|
1180 | CpyTRACE("copying Module Items\n"); |
---|
1181 | if (mitems != (lsList)0) { |
---|
1182 | retval = lsCreate(); |
---|
1183 | gen = lsStart(mitems); |
---|
1184 | if (lsNext(gen, (lsGeneric*)&item, &handle) == LS_OK) { |
---|
1185 | lsNewEnd(retval, vl_copy_mod_item(item), 0); |
---|
1186 | while(lsNext(gen, (lsGeneric*)&item, &handle) != LS_NOMORE) { |
---|
1187 | lsNewEnd(retval, vl_copy_mod_item(item), 0); |
---|
1188 | } |
---|
1189 | } |
---|
1190 | (void) lsFinish(gen); |
---|
1191 | |
---|
1192 | return retval; |
---|
1193 | } |
---|
1194 | |
---|
1195 | return (lsList)0; |
---|
1196 | } |
---|
1197 | |
---|
1198 | |
---|
1199 | void *vl_copy_mod_item(void *item) |
---|
1200 | { |
---|
1201 | void *retval=NIL(void); |
---|
1202 | |
---|
1203 | switch(((vl_decl *)item)->type) { |
---|
1204 | |
---|
1205 | case RealDecl: case EventDecl: |
---|
1206 | retval = (void*)vl_copy_basicdecl((vl_decl *)item); |
---|
1207 | break; |
---|
1208 | |
---|
1209 | case IntDecl: case TimeDecl: |
---|
1210 | retval = (void*)vl_copy_basicdecl((vl_decl *)item); |
---|
1211 | break; |
---|
1212 | |
---|
1213 | case InputDecl: case OutputDecl: |
---|
1214 | case InoutDecl: case RegDecl: |
---|
1215 | retval = (void*)vl_copy_rangedecl((vl_rangedecl *)item); |
---|
1216 | break; |
---|
1217 | |
---|
1218 | case ParamDecl: case DefparamDecl: |
---|
1219 | retval = (void*)vl_copy_paramdecl((vl_paramdecl *)item); |
---|
1220 | break; |
---|
1221 | |
---|
1222 | case WireDecl: case TriDecl: |
---|
1223 | case Tri0Decl: case Tri1Decl: |
---|
1224 | case Supply0Decl: case Supply1Decl: |
---|
1225 | case WandDecl: case TriandDecl: |
---|
1226 | case WorDecl: case TriorDecl: |
---|
1227 | case TriregDecl: |
---|
1228 | retval = (void*)vl_copy_netdecl((vl_netdecl *)item); |
---|
1229 | break; |
---|
1230 | |
---|
1231 | case ContAssign: |
---|
1232 | retval = (void*)vl_copy_cont_assign((vl_cont_assign *)item); |
---|
1233 | break; |
---|
1234 | |
---|
1235 | case TaskDecl: |
---|
1236 | retval = (void*)vl_copy_task((vl_task *)item); |
---|
1237 | break; |
---|
1238 | |
---|
1239 | case IntFuncDecl: case RealFuncDecl: |
---|
1240 | case RangeFuncDecl: |
---|
1241 | retval = (void*)vl_copy_function((vl_function *)item); |
---|
1242 | break; |
---|
1243 | |
---|
1244 | case AndGate: case NandGate: |
---|
1245 | case OrGate: case NorGate: |
---|
1246 | case XorGate: case XnorGate: |
---|
1247 | case BufGate: case Bufif0Gate: |
---|
1248 | case Bufif1Gate: case NotGate: |
---|
1249 | case Notif0Gate: case Notif1Gate: |
---|
1250 | case PulldownGate: case PullupGate: |
---|
1251 | case NmosGate: case RnmosGate: |
---|
1252 | case PmosGate: case RpmosGate: |
---|
1253 | case CmosGate: case RcmosGate: |
---|
1254 | case TranGate: case RtranGate: |
---|
1255 | case Tranif0Gate: case Rtranif0Gate: |
---|
1256 | case Tranif1Gate: case Rtranif1Gate: |
---|
1257 | retval = (void*)vl_copy_gate_inst_list((vl_gate_inst_list *)item); |
---|
1258 | break; |
---|
1259 | |
---|
1260 | case ModInst: { |
---|
1261 | char *mp; |
---|
1262 | |
---|
1263 | if (st_lookup(vl_description->mp_st, |
---|
1264 | ((vl_mod_prim_inst_list *)item)->name->name, |
---|
1265 | &mp)) { |
---|
1266 | if (((typestructPtr)mp)->type == CombPrimDecl || |
---|
1267 | ((typestructPtr)mp)->type == SeqPrimDecl) |
---|
1268 | goto copy_prim_inst; |
---|
1269 | } |
---|
1270 | } |
---|
1271 | |
---|
1272 | retval = (void*)vl_copy_mod_inst_list((vl_mod_prim_inst_list *)item); |
---|
1273 | break; |
---|
1274 | |
---|
1275 | copy_prim_inst: |
---|
1276 | |
---|
1277 | case PrimInst: |
---|
1278 | retval = (void*)vl_copy_prim_inst_list((vl_mod_prim_inst_list *)item); |
---|
1279 | break; |
---|
1280 | |
---|
1281 | case AlwaysStmt: |
---|
1282 | case InitialStmt: |
---|
1283 | retval = (void*)vl_copy_procstmt((vl_procstmt *)item); |
---|
1284 | break; |
---|
1285 | |
---|
1286 | default: internal_error("Unexpected Module Item"); break; |
---|
1287 | } |
---|
1288 | |
---|
1289 | return retval; |
---|
1290 | } |
---|
1291 | |
---|
1292 | |
---|
1293 | lsList vl_copy_decl_list (void *decls) |
---|
1294 | { |
---|
1295 | void *decl; |
---|
1296 | lsHandle handle; |
---|
1297 | lsGen gen; |
---|
1298 | lsList retval; |
---|
1299 | |
---|
1300 | CpyTRACE("copying Decls\n"); |
---|
1301 | if (decls == NIL(void)) return (lsList)0; |
---|
1302 | retval = lsCreate(); |
---|
1303 | gen = lsStart(decls); |
---|
1304 | if (lsNext(gen, (lsGeneric*)&decl, &handle) == LS_OK) { |
---|
1305 | lsNewEnd(retval, vl_copy_decl(decl), 0); |
---|
1306 | while(lsNext(gen, (lsGeneric*)&decl, &handle) != LS_NOMORE) { |
---|
1307 | lsNewEnd(retval, vl_copy_decl(decl), 0); |
---|
1308 | } |
---|
1309 | } |
---|
1310 | (void) lsFinish(gen); |
---|
1311 | |
---|
1312 | return retval; |
---|
1313 | } |
---|
1314 | |
---|
1315 | lsList vl_copy_stmt_list (void *stmts) |
---|
1316 | { |
---|
1317 | void *stmt; |
---|
1318 | lsHandle handle; |
---|
1319 | lsGen gen; |
---|
1320 | lsList retval; |
---|
1321 | |
---|
1322 | CpyTRACE("copying Statements\n"); |
---|
1323 | retval = lsCreate(); |
---|
1324 | gen = lsStart(stmts); |
---|
1325 | if (lsNext(gen, (lsGeneric*)&stmt, &handle) == LS_OK) { |
---|
1326 | lsNewEnd(retval, vl_copy_stmt(stmt), 0); |
---|
1327 | while(lsNext(gen, (lsGeneric*)&stmt, &handle) != LS_NOMORE) { |
---|
1328 | lsNewEnd(retval, vl_copy_stmt(stmt), 0); |
---|
1329 | } |
---|
1330 | } |
---|
1331 | (void) lsFinish(gen); |
---|
1332 | |
---|
1333 | return retval; |
---|
1334 | } |
---|
1335 | |
---|
1336 | int vl_copy_strength (int s) |
---|
1337 | { |
---|
1338 | return s; |
---|
1339 | } |
---|
1340 | |
---|
1341 | |
---|
1342 | vl_gate_inst *vl_copy_gate (vl_gate_inst *gate) |
---|
1343 | { |
---|
1344 | vl_gate_inst *retval; |
---|
1345 | |
---|
1346 | retval = (vl_gate_inst*)chk_malloc(sizeof(vl_gate_inst)); |
---|
1347 | retval->name = vl_copy_id_range(gate->name); |
---|
1348 | retval->terms = vl_copy_expr_list(gate->terms); |
---|
1349 | |
---|
1350 | return retval; |
---|
1351 | } |
---|
1352 | |
---|
1353 | vl_mod_prim_inst *vl_copy_prim (vl_mod_prim_inst *prim) |
---|
1354 | { |
---|
1355 | vl_mod_prim_inst *retval; |
---|
1356 | |
---|
1357 | retval = (vl_mod_prim_inst*)chk_malloc(sizeof(vl_mod_prim_inst)); |
---|
1358 | retval->name = vl_copy_id_range(prim->name); |
---|
1359 | retval->ports = vl_copy_expr_list(prim->ports); |
---|
1360 | |
---|
1361 | return retval; |
---|
1362 | } |
---|
1363 | |
---|
1364 | lsList vl_copy_param_vals (lsList param_vals) |
---|
1365 | { |
---|
1366 | if (param_vals == (lsList)0) return (lsList)0; |
---|
1367 | |
---|
1368 | return vl_copy_expr_list(param_vals); |
---|
1369 | } |
---|
1370 | |
---|
1371 | vl_mod_prim_inst *vl_copy_modinst (vl_mod_prim_inst *mod) |
---|
1372 | { |
---|
1373 | vl_mod_prim_inst *retval; |
---|
1374 | |
---|
1375 | retval = (vl_mod_prim_inst*)chk_malloc(sizeof(vl_mod_prim_inst)); |
---|
1376 | retval->name = vl_copy_id_range(mod->name); |
---|
1377 | retval->ports = vl_copy_connects(mod->ports); |
---|
1378 | |
---|
1379 | return retval; |
---|
1380 | } |
---|
1381 | |
---|
1382 | void *vl_copy_stmt (void *stmt) |
---|
1383 | { |
---|
1384 | void *retval=NIL(void); |
---|
1385 | |
---|
1386 | if (stmt == NIL(void)) { |
---|
1387 | return NIL(void); |
---|
1388 | } |
---|
1389 | |
---|
1390 | switch(((vl_bassign_stmt *)stmt)->type) { |
---|
1391 | case BeginEndStmt: |
---|
1392 | retval = (void*)vl_copy_begin_end_stmt((vl_begin_end_stmt *)stmt); |
---|
1393 | break; |
---|
1394 | case IfElseStmt: |
---|
1395 | retval = (void*)vl_copy_if_else_stmt((vl_if_else_stmt *)stmt); |
---|
1396 | break; |
---|
1397 | case CaseStmt: |
---|
1398 | case CasexStmt: |
---|
1399 | case CasezStmt: |
---|
1400 | retval = (void*)vl_copy_case_stmt((vl_case_stmt *)stmt); |
---|
1401 | break; |
---|
1402 | case CaseItem: |
---|
1403 | retval = (void*)vl_copy_stmt(((vl_case_item *)stmt)->stmt); |
---|
1404 | break; |
---|
1405 | case DefaultItem: |
---|
1406 | retval = (void*)vl_copy_stmt(((vl_case_item *)stmt)->stmt); |
---|
1407 | break; |
---|
1408 | case ForeverStmt: |
---|
1409 | retval = (void*)vl_copy_forever_stmt((vl_forever_stmt *)stmt); |
---|
1410 | break; |
---|
1411 | case RepeatStmt: |
---|
1412 | retval = (void*)vl_copy_repeat_stmt((vl_repeat_stmt *)stmt); |
---|
1413 | break; |
---|
1414 | case WhileStmt: |
---|
1415 | retval = (void*)vl_copy_while_stmt((vl_while_stmt *)stmt); |
---|
1416 | break; |
---|
1417 | case ForStmt: |
---|
1418 | retval = (void*)vl_copy_for_stmt((vl_for_stmt *)stmt); |
---|
1419 | break; |
---|
1420 | case DelayControlStmt: |
---|
1421 | retval = (void*)vl_copy_delay_control_stmt((vl_delay_control_stmt *)stmt); |
---|
1422 | break; |
---|
1423 | case EventControlStmt: |
---|
1424 | retval = (void*)vl_copy_event_control_stmt((vl_event_control_stmt *)stmt); |
---|
1425 | break; |
---|
1426 | case AssignStmt: |
---|
1427 | case BassignStmt: |
---|
1428 | case NbassignStmt: |
---|
1429 | case DelayBassignStmt: |
---|
1430 | case DelayNbassignStmt: |
---|
1431 | case EventBassignStmt: |
---|
1432 | case EventNbassignStmt: |
---|
1433 | retval = (void*)vl_copy_bassign_stmt((vl_bassign_stmt *)stmt); |
---|
1434 | break; |
---|
1435 | case WaitStmt: |
---|
1436 | retval = (void*)vl_copy_wait_stmt((vl_wait_stmt *)stmt); |
---|
1437 | break; |
---|
1438 | case ForkJoinStmt: |
---|
1439 | retval = (void*)vl_copy_fork_join_stmt((vl_fork_join_stmt *)stmt); |
---|
1440 | break; |
---|
1441 | case TaskEnableStmt: |
---|
1442 | case SysTaskEnableStmt: |
---|
1443 | retval = (void*)vl_copy_task_enable_stmt((vl_task_enable_stmt *)stmt); |
---|
1444 | break; |
---|
1445 | case DisableStmt: |
---|
1446 | retval = (void*)vl_copy_disable_stmt((vl_disable_stmt *)stmt); |
---|
1447 | break; |
---|
1448 | case DeassignStmt: |
---|
1449 | retval = (void*)vl_copy_deassign_stmt((vl_deassign_stmt *)stmt); |
---|
1450 | break; |
---|
1451 | case SendEventStmt: |
---|
1452 | retval = (void*)vl_copy_id_range(((vl_send_event_stmt *)stmt)->name); |
---|
1453 | break; |
---|
1454 | default: { |
---|
1455 | char msg[MAXSTRLEN]; |
---|
1456 | sprintf(msg, "vl_copy_stmt:Unexpected Statement Type %d", |
---|
1457 | ((vl_bassign_stmt *)stmt)->type); |
---|
1458 | internal_error(msg); |
---|
1459 | } |
---|
1460 | } |
---|
1461 | |
---|
1462 | return retval; |
---|
1463 | } |
---|
1464 | |
---|
1465 | void *vl_copy_decl (void *decl) |
---|
1466 | { |
---|
1467 | void *retval=NIL(void); |
---|
1468 | |
---|
1469 | switch(((vl_decl *)decl)->type) { |
---|
1470 | case RealDecl: case EventDecl: |
---|
1471 | case IntDecl: case TimeDecl: |
---|
1472 | retval = (void*)vl_copy_basicdecl((vl_decl *)decl); |
---|
1473 | break; |
---|
1474 | |
---|
1475 | case InputDecl: case OutputDecl: |
---|
1476 | case InoutDecl: case RegDecl: |
---|
1477 | retval = (void*)vl_copy_rangedecl((vl_rangedecl *)decl); |
---|
1478 | break; |
---|
1479 | case ParamDecl: case DefparamDecl: |
---|
1480 | retval = (void*)vl_copy_paramdecl((vl_paramdecl *)decl); |
---|
1481 | break; |
---|
1482 | case WireDecl: case TriDecl: |
---|
1483 | case Tri0Decl: case Tri1Decl: |
---|
1484 | case Supply0Decl: case Supply1Decl: |
---|
1485 | case WandDecl: case TriandDecl: |
---|
1486 | case WorDecl: case TriorDecl: |
---|
1487 | case TriregDecl: |
---|
1488 | retval = (void*)vl_copy_netdecl((vl_netdecl *)decl); |
---|
1489 | break; |
---|
1490 | default: |
---|
1491 | internal_error("Unexprected Declaration Type"); |
---|
1492 | break; |
---|
1493 | } |
---|
1494 | |
---|
1495 | return retval; |
---|
1496 | } |
---|
1497 | |
---|
1498 | vl_cont_assign *vl_copy_cont_assign (vl_cont_assign *assign) |
---|
1499 | { |
---|
1500 | vl_cont_assign *retval; |
---|
1501 | |
---|
1502 | retval = (vl_cont_assign*)chk_malloc(sizeof(vl_cont_assign)); |
---|
1503 | retval->type = ContAssign; |
---|
1504 | retval->strength = vl_copy_strength(assign->strength); |
---|
1505 | retval->delay = vl_copy_delay(assign->delay); |
---|
1506 | retval->assigns = vl_copy_net_list(assign->assigns); |
---|
1507 | |
---|
1508 | return retval; |
---|
1509 | } |
---|
1510 | |
---|
1511 | vl_id_range *vl_copy_id_range_rec(vl_id_range *id_range) |
---|
1512 | { |
---|
1513 | vl_id_range *retval; |
---|
1514 | |
---|
1515 | CpyTRACE("Copying id_range\n"); |
---|
1516 | retval = (vl_id_range *)chk_malloc(sizeof(vl_id_range)); |
---|
1517 | retval->name = vlStrdup(id_range->name); |
---|
1518 | retval->flags = id_range->flags; |
---|
1519 | retval->range = vl_copy_range(id_range->range); |
---|
1520 | retval->initial = lsCreate(); |
---|
1521 | retval->syndrome_expr_list = id_range->syndrome_expr_list; |
---|
1522 | retval->rst_syndrome_expr_list = id_range->rst_syndrome_expr_list; |
---|
1523 | retval->mpg_master_exp = id_range->mpg_master_exp; |
---|
1524 | retval->id_type = id_range->id_type; |
---|
1525 | return(retval); |
---|
1526 | } |
---|