Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / beh / beh / beh_duplicate.c
1 /****************************************************************************/
2 /* */
3 /* Chaine de CAO & VLSI AVERTEC */
4 /* */
5 /* Produit : BEHVECT Version 1.00 */
6 /* Fichier : beh_dup.c */
7 /* */
8 /* (c) copyright 2003 AVERTEC */
9 /* Tous droits reserves */
10 /* */
11 /* Auteur(s) : Antony PINTO */
12 /* */
13 /****************************************************************************/
14
15 #include MUT_H
16 #include LOG_H
17 #include EQT_H
18 #include BEH_H
19
20 #define XOU(a,b) (!(a) && (b)) || ((a) && !(b))
21
22 static chain_list *BEH_EXP_LIST = NULL;
23 static ht *BEH_EXP_TABLE = NULL;
24
25 //static vectbiabl_list *beh_explodeVectBiabl (vectbiabl_list *vbiabl,char *name);
26 //static vectbiabl_list *beh_explodeVect (vectbiabl_list *vbiabl,char *name);
27 biabl_list *beh_explodeBiabl (biabl_list *biabl,int index, char *name,int left, int right,void (*func)(char*,int,biabl_list*));
28 static void beh_explodeLoopInt (eqt_ctx *ctx, loop_list *loop, biabl_list *biabl, char *name,void (*func)(char*,int,biabl_list*));
29 void beh_explodeLoop (loop_list *loop, biabl_list *biabl,char *name,void (*func)(char*,int,biabl_list*));
30 static chain_list *beh_explodeLoopAbl (eqt_ctx *ctx, chain_list *abl);
31
32 befig_list *beh_duplicate (befig_list *befig);
33
34 static bereg_list *beh_dupreg (bereg_list *reg);
35 static bevectreg_list *beh_dupvreg (bevectreg_list *vreg);
36 static bebus_list *beh_dupbus (bebus_list *bus);
37 static bevectbus_list *beh_dupvbus (bevectbus_list *vbus);
38 static bebux_list *beh_dupbux (bebux_list *bux);
39 static bevectbux_list *beh_dupvbux (bevectbux_list *vbux);
40 static beaux_list *beh_dupaux (beaux_list *aux);
41 static bevectaux_list *beh_dupvaux (bevectaux_list *vaux);
42 static beout_list *beh_dupout (beout_list *out);
43 static bevectout_list *beh_dupvout (bevectout_list *vout);
44 static bepor_list *beh_duppor (bepor_list *por);
45 static bevectpor_list *beh_dupvpor (bevectpor_list *vpor);
46 static berin_list *beh_duprin (berin_list *rin);
47 static bemsg_list *beh_dupmsg (bemsg_list *msg);
48
49 static vectbiabl_list *beh_dupvbiabl (vectbiabl_list *vbiabl);
50 static loop_list *beh_duploop (loop_list *loop);
51
52 static berin_list *beh_bitrzrin (berin_list *rin);
53 static bereg_list *beh_bitrzreg (bereg_list *reg);
54 static bebux_list *beh_bitrzbux (bebux_list *bux);
55 static bebus_list *beh_bitrzbus (bebus_list *bus);
56 static bemsg_list *beh_bitrzmsg (bemsg_list *msg);
57 static bereg_list *beh_bitrzvreg (bevectreg_list *vreg,bereg_list *reg);
58 static bebux_list *beh_bitrzvbux (bevectbux_list *vbux,bebux_list *bux);
59 static bebus_list *beh_bitrzvbus (bevectbus_list *vbus,bebus_list *bus);
60 static beaux_list *beh_bitrzvaux (bevectaux_list *vaux,beaux_list *aux);
61 static beout_list *beh_bitrzvout (bevectout_list *vout,beout_list *out);
62 static bepor_list *beh_bitrzvpor (bevectpor_list *vpor,bepor_list *por);
63
64 static int beh_explodews(biabl_list *biabl);
65 static chain_list *beh_bitrzcndws(chain_list *cnd, char *bitstr);
66 static void beh_bitrzcnd(chain_list *cnd);
67 static void beh_explodec(biabl_list *biabl);
68
69 static void beh_resolvingfunc(char *name,int index,biabl_list *biabl);
70
71 static bereg_list *beh_addloopreg(bereg_list *reg);
72 static bebus_list *beh_addloopbus(bebus_list *bus);
73 static bebux_list *beh_addloopbux(bebux_list *bux);
74 static biabl_list *beh_expgetbiabl(chain_list *list);
75
76 /****************************************************************************/
77 /*{{{ Biterize functions */
78 /****************************************************************************/
79 /*{{{ beh_biterize() */
80 /* */
81 /* suppress vectorisation, loop and with select */
82 /* */
83 /****************************************************************************/
84 void beh_biterize(befig_list *befig)
85 {
86 BEH_EXP_TABLE = addht(100);
87
88 befig->BEREG = beh_bitrzreg (befig->BEREG);
89 befig->BEBUX = beh_bitrzbux (befig->BEBUX);
90 befig->BEBUS = beh_bitrzbus (befig->BEBUS);
91 befig->BEAUX = befig->BEAUX ;
92 befig->BEOUT = befig->BEOUT ;
93 befig->BEPOR = befig->BEPOR ;
94
95 befig->BEREG = beh_bitrzvreg (befig->BEVECTREG,befig->BEREG);
96 befig->BEVECTREG = beh_delbevectreg (befig->BEVECTREG,befig->BEVECTREG,'Y');
97 befig->BEBUX = beh_bitrzvbux (befig->BEVECTBUX,befig->BEBUX);
98 befig->BEVECTBUX = beh_delbevectbux (befig->BEVECTBUX,befig->BEVECTBUX,'Y');
99 befig->BEBUS = beh_bitrzvbus (befig->BEVECTBUS,befig->BEBUS);
100 befig->BEVECTBUS = beh_delbevectbus (befig->BEVECTBUS,befig->BEVECTBUS,'Y');
101 befig->BEAUX = beh_bitrzvaux (befig->BEVECTAUX,befig->BEAUX);
102 befig->BEVECTAUX = beh_delbevectaux (befig->BEVECTAUX,befig->BEVECTAUX,'Y');
103 befig->BEOUT = beh_bitrzvout (befig->BEVECTOUT,befig->BEOUT);
104 befig->BEVECTOUT = beh_delbevectout (befig->BEVECTOUT,befig->BEVECTOUT,'Y');
105 befig->BEPOR = beh_bitrzvpor (befig->BEVECTPOR,befig->BEPOR);
106 befig->BEVECTPOR = beh_delbevectpor (befig->BEVECTPOR,befig->BEVECTPOR);
107
108 befig->BERIN = beh_bitrzrin (befig->BERIN);
109 befig->BEMSG = beh_bitrzmsg (befig->BEMSG);
110
111 delht(BEH_EXP_TABLE);
112 BEH_EXP_TABLE = NULL;
113 }
114
115 /*}}}************************************************************************/
116 /*{{{ beh_bitrzrin() */
117 /* */
118 /* */
119 /****************************************************************************/
120 static berin_list *beh_bitrzrin(berin_list *rin)
121 {
122 if (rin)
123 {
124 int min, max, i;
125 char buf[1024];
126
127 rin->NEXT = beh_bitrzrin(rin->NEXT);
128 min = (rin->LEFT >= rin->RIGHT) ? rin->RIGHT : rin->LEFT ;
129 max = (rin->LEFT >= rin->RIGHT) ? rin->LEFT : rin->RIGHT ;
130 for (i = min; i <= max; i ++ )
131 {
132 sprintf(buf,"%s %d",rin->NAME,i);
133 rin->NEXT = beh_addberin(rin->NEXT,namealloc(buf));
134 }
135
136 return beh_delberin(rin,rin);
137 }
138 else
139 return NULL;
140 }
141
142 /*}}}************************************************************************/
143 /*{{{ beh_bitrzmsg() */
144 /* */
145 /* */
146 /****************************************************************************/
147 static bemsg_list *beh_bitrzmsg(bemsg_list *msg)
148 {
149 if (msg)
150 {
151 int max, i;
152
153 msg->NEXT = beh_bitrzmsg(msg->NEXT);
154 max = verifyVectAbl(msg->ABL);
155 for (i = 0; i < max; i ++ )
156 msg->NEXT = beh_addbemsg(msg->NEXT,msg->LABEL,msg->LEVEL,msg->MESSAGE,
157 getAblAtPos(msg->ABL,i),NULL);
158
159 return beh_delbemsg(msg,msg,'Y');
160 }
161 else
162 return NULL;
163 }
164
165 /*}}}************************************************************************/
166 /*{{{ beh_bitrzvpor() */
167 /* */
168 /* */
169 /****************************************************************************/
170 static bepor_list *beh_bitrzvpor(bevectpor_list *vpor,bepor_list *por)
171 {
172 if (vpor)
173 {
174 int i, way;
175 char buf[1024];
176
177 way = (vpor->LEFT > vpor->RIGHT);
178 por = beh_bitrzvpor(vpor->NEXT,por);
179 vpor->NEXT = beh_delbevectpor(vpor->NEXT,vpor->NEXT);
180 for (i = vpor->LEFT; XOU(way, i <= vpor->RIGHT-way ); (way) ? i-- : i++ )
181 {
182 sprintf(buf,"%s %d",vpor->NAME,i);
183 por = beh_addbepor(por,namealloc(buf),vpor->DIRECTION,vpor->TYPE);
184 }
185 return por;
186 }
187 else
188 return por;
189 }
190
191 /*}}}************************************************************************/
192 /*{{{ beh_bitrzreg() */
193 /* */
194 /* */
195 /****************************************************************************/
196 static bereg_list *beh_bitrzreg(bereg_list *reg)
197 {
198 if (reg)
199 {
200 beh_bitrzreg(reg->NEXT);
201 beh_explodec(reg->BIABL);
202 }
203 return reg;
204 }
205 /*}}}************************************************************************/
206 /*{{{ beh_bitrzbux() */
207 /* */
208 /* */
209 /****************************************************************************/
210 static bebux_list *beh_bitrzbux(bebux_list *bux)
211 {
212 if (bux)
213 {
214 beh_bitrzbux(bux->NEXT);
215 if (!beh_explodews(bux->BIABL))
216 beh_explodec(bux->BIABL);
217 }
218 return bux;
219 }
220
221 /*}}}************************************************************************/
222 /*{{{ beh_bitrzbus() */
223 /* */
224 /* */
225 /****************************************************************************/
226 static bebus_list *beh_bitrzbus(bebus_list *bus)
227 {
228 if (bus)
229 {
230 beh_bitrzbus(bus->NEXT);
231 if (!beh_explodews(bus->BIABL))
232 beh_explodec(bus->BIABL);
233 }
234 return bus;
235 }
236
237 /*}}}************************************************************************/
238 /*{{{ beh_bitrzvreg() */
239 /* */
240 /* */
241 /****************************************************************************/
242 static bereg_list *beh_bitrzvreg(bevectreg_list *vreg,bereg_list *reg)
243 {
244 if (vreg)
245 {
246 vectbiabl_list *vbiablx;
247 biabl_list *biablx;
248 int i, way, cnddone;
249 char buf[1024];
250
251 reg = beh_bitrzvreg(vreg->NEXT,reg);
252 vreg->NEXT = beh_delbevectreg(vreg->NEXT,vreg->NEXT,'Y');
253 while ( vreg->VECTBIABL)
254 {
255 vbiablx = vreg->VECTBIABL;
256 cnddone = beh_explodews(vbiablx->BIABL);
257 way = (vbiablx->LEFT > vbiablx->RIGHT);
258 for ( i = vbiablx->LEFT; XOU(way, i <= vbiablx->RIGHT-way);
259 (way) ? i -- : i ++ )
260 {
261 biablx = beh_explodeBiabl(vbiablx->BIABL,i,vreg->NAME,vbiablx->LEFT,
262 vbiablx->RIGHT,beh_resolvingfunc);
263 if (biablx)
264 {
265 sprintf(buf,"%s %d",vreg->NAME,i);
266 reg = beh_addbereg(reg,namealloc(buf),biablx,NULL,vreg->FLAGS);
267 if (!cnddone)
268 beh_explodec(reg->BIABL);
269 }
270 else
271 {
272 reg = beh_addloopreg(reg);
273 break;
274 }
275 }
276 vreg->VECTBIABL = beh_delvectbiabl(vbiablx,vbiablx,'Y');
277 }
278 return reg;
279 }
280 else
281 return reg;
282 }
283
284 /*}}}************************************************************************/
285 /*{{{ beh_bitrzvbus() */
286 /* */
287 /* */
288 /****************************************************************************/
289 static bebus_list *beh_bitrzvbus(bevectbus_list *vbus,bebus_list *bus)
290 {
291 if (vbus)
292 {
293 vectbiabl_list *vbiablx;
294 int i, way, cnddone;
295 char buf[1024];
296 biabl_list *biablx;
297
298 bus = beh_bitrzvbus(vbus->NEXT,bus);
299 vbus->NEXT = beh_delbevectbus(vbus->NEXT,vbus->NEXT,'Y');
300 while ( vbus->VECTBIABL)
301 {
302 vbiablx = vbus->VECTBIABL;
303 cnddone = beh_explodews(vbiablx->BIABL);
304 way = (vbiablx->LEFT > vbiablx->RIGHT);
305 for ( i = vbiablx->LEFT; XOU(way, i <= vbiablx->RIGHT-way);
306 (way) ? i -- : i ++ )
307 {
308 biablx = beh_explodeBiabl(vbiablx->BIABL,i,vbus->NAME,vbiablx->LEFT,
309 vbiablx->RIGHT,beh_resolvingfunc);
310 if (biablx)
311 {
312 sprintf(buf,"%s %d",vbus->NAME,i);
313 bus = beh_addbebus(bus,namealloc(buf),biablx,NULL,0,vbus->FLAGS);
314 if (!cnddone)
315 beh_explodec(bus->BIABL);
316 }
317 else
318 {
319 bus = beh_addloopbus(bus);
320 break;
321 }
322 }
323 vbus->VECTBIABL = beh_delvectbiabl(vbiablx,vbiablx,'Y');
324 }
325 return bus;
326 }
327 else
328 return bus;
329 }
330
331 /*}}}************************************************************************/
332 /*{{{ beh_bitrzvbux() */
333 /* */
334 /* */
335 /****************************************************************************/
336 static bebux_list *beh_bitrzvbux(bevectbux_list *vbux,bebux_list *bux)
337 {
338 if (vbux)
339 {
340 vectbiabl_list *vbiablx;
341 int i, way, cnddone;
342 char buf[1024];
343 biabl_list *biablx;
344
345 bux = beh_bitrzvbux(vbux->NEXT,bux);
346 vbux->NEXT = beh_delbevectbux(vbux->NEXT,vbux->NEXT,'Y');
347 while ( vbux->VECTBIABL)
348 {
349 vbiablx = vbux->VECTBIABL;
350 cnddone = beh_explodews(vbiablx->BIABL);
351 way = (vbiablx->LEFT > vbiablx->RIGHT);
352 for ( i = vbiablx->LEFT; XOU(way, i <= vbiablx->RIGHT-way);
353 (way) ? i -- : i ++ )
354 {
355 biablx = beh_explodeBiabl(vbiablx->BIABL,i,vbux->NAME,vbiablx->LEFT,
356 vbiablx->RIGHT,beh_resolvingfunc);
357 if (biablx)
358 {
359 sprintf(buf,"%s %d",vbux->NAME,i);
360 bux = beh_addbebux(bux,namealloc(buf),biablx,NULL,0,vbux->FLAGS);
361 if (!cnddone)
362 beh_explodec(bux->BIABL);
363 }
364 else
365 {
366 bux = beh_addloopbux(bux);
367 break;
368 }
369 }
370 vbux->VECTBIABL = beh_delvectbiabl(vbiablx,vbiablx,'Y');
371 }
372 return bux;
373 }
374 else
375 return bux;
376 }
377
378 /*}}}************************************************************************/
379 /*{{{ beh_bitrzvaux() */
380 /* */
381 /* */
382 /****************************************************************************/
383 static beaux_list *beh_bitrzvaux(bevectaux_list *vaux,beaux_list *aux)
384 {
385 if (vaux)
386 {
387 int i, way;
388 char buf[1024];
389 chain_list *abl;
390
391 way = (vaux->LEFT > vaux->RIGHT);
392 aux = beh_bitrzvaux(vaux->NEXT,aux);
393 vaux->NEXT = beh_delbevectaux(vaux->NEXT,vaux->NEXT,'Y');
394 for (i = vaux->LEFT; XOU(way, i <= vaux->RIGHT-way); (way) ? i-- : i++ )
395 {
396 sprintf(buf,"%s %d",vaux->NAME,i);
397 abl = getAblAtIndex(vaux->ABL,vaux->LEFT,vaux->RIGHT,i);
398 aux = beh_addbeaux(aux,namealloc(buf),abl,NULL,aux->FLAGS);
399 aux->TIME = vaux->TIME;
400 aux->TIMEVAR = vaux->TIMEVAR;
401 }
402 return aux;
403 }
404 return aux;
405 }
406
407 /*}}}************************************************************************/
408 /*{{{ beh_bitrzvout() */
409 /* */
410 /* */
411 /****************************************************************************/
412 static beout_list *beh_bitrzvout(bevectout_list *vout,beout_list *out)
413 {
414 if (vout)
415 {
416 int i, way;
417 char buf[1024];
418 chain_list *abl;
419
420 way = (vout->LEFT > vout->RIGHT);
421 out = beh_bitrzvout(vout->NEXT,out);
422 vout->NEXT = beh_delbevectout(vout->NEXT,vout->NEXT,'Y');
423 for (i = vout->LEFT; XOU(way, i <= vout->RIGHT-way); (way) ? i-- : i++ )
424 {
425 sprintf(buf,"%s %d",vout->NAME,i);
426 abl = getAblAtIndex(vout->ABL,vout->LEFT,vout->RIGHT,i);
427 out = beh_addbeout(out,namealloc(buf),abl,NULL,out->FLAGS);
428 out->TIME = vout->TIME;
429 out->TIMEVAR = vout->TIMEVAR;
430 }
431 return out;
432 }
433 return out;
434 }
435
436 /*}}}************************************************************************/
437 /*{{{ beh_explodews() */
438 /* */
439 /* destroy with select */
440 /* */
441 /****************************************************************************/
442 static int beh_explodews(biabl_list *biabl)
443 {
444 if (biabl && biabl->FLAG & BEH_CND_SELECT)
445 {
446 biabl_list *biablx;
447 chain_list *abl;
448 long flag;
449
450 for (biablx = biabl; biablx; biablx = biablx->NEXT)
451 {
452 if (biablx->FLAG & BEH_CND_SELECT)
453 {
454 abl = beh_bitrzcndws(biablx->CNDABL,beh_getcndvectfbiabl(biablx));
455 flag = (biablx->FLAG | BEH_CND_PRECEDE) & ~BEH_CND_SELECT;
456 }
457 else if (biablx->FLAG & BEH_CND_SEL_OTHERS)
458 {
459 abl = createBitStr("1");
460 flag = (biablx->FLAG | BEH_CND_PRECEDE) & ~BEH_CND_SEL_OTHERS;
461 }
462 else
463 beh_toolbug(20,"beh_explodews",NULL,0);
464 beh_delcndvectfbiabl(biabl);
465 biablx->CNDABL = abl;
466 biablx->FLAG = flag;
467 }
468 return 1;
469 }
470 else
471 return 0;
472 }
473
474 /*}}}************************************************************************/
475 /*{{{ beh_explodec() */
476 /* */
477 /* destroy vectorized conditions */
478 /* */
479 /****************************************************************************/
480 static void beh_explodec(biabl_list *biabl)
481 {
482 if (biabl)
483 {
484 biabl_list *biablx;
485
486 for (biablx = biabl; biablx; biablx = biablx->NEXT)
487 beh_bitrzcnd(biablx->CNDABL);
488 }
489 }
490
491 /*}}}************************************************************************/
492 /*{{{ beh_bitrzcnd() */
493 /* */
494 /* */
495 /****************************************************************************/
496 static void beh_bitrzcnd(chain_list *cnd)
497 {
498 if (!ATOM(cnd))
499 {
500 switch (OPER(cnd))
501 {
502 case CAT :
503 OPER(cnd) = AND;
504 VECT_S(cnd) = 1L;
505 }
506 while ((cnd = CDR(cnd)))
507 beh_bitrzcnd(CAR(cnd));
508 }
509 }
510
511 /*}}}************************************************************************/
512 /*{{{ beh_bitrzcndws() */
513 /* */
514 /* */
515 /****************************************************************************/
516 static chain_list *beh_bitrzcndws(chain_list *cnd, char *bitstr)
517 {
518 int i, max;
519 chain_list *res, *tmp;
520
521 res = createExpr(AND);
522 max = verifyVectAbl(cnd);
523 for (i = 0; i < max; i ++)
524 {
525 tmp = getAblAtPos(cnd,i);
526 if (bitstr)
527 switch (*(bitstr+1+i))
528 {
529 case '0' :
530 tmp = notExpr(tmp);
531 case '1' :
532 addHExpr(res,tmp);
533 }
534 else
535 addHExpr(res,tmp);
536 }
537 freeExpr(cnd);
538
539 return res;
540 }
541
542 /*}}}************************************************************************/
543 /*}}}************************************************************************/
544 /*{{{ Duplication functions */
545 /****************************************************************************/
546 /*{{{ beh_duplicate() */
547 /* */
548 /* */
549 /****************************************************************************/
550 befig_list *beh_duplicate(befig_list *befig)
551 {
552 befig_list *res;
553
554 res = beh_addbefig(NULL,befig->NAME);
555 res->BEREG = beh_dupreg (befig->BEREG);
556 res->BEBUX = beh_dupbux (befig->BEBUX);
557 res->BEBUS = beh_dupbus (befig->BEBUS);
558 res->BEAUX = beh_dupaux (befig->BEAUX);
559 res->BEOUT = beh_dupout (befig->BEOUT);
560 res->BEPOR = beh_duppor (befig->BEPOR);
561 res->BEVECTREG = beh_dupvreg (befig->BEVECTREG);
562 res->BEVECTBUX = beh_dupvbux (befig->BEVECTBUX);
563 res->BEVECTBUS = beh_dupvbus (befig->BEVECTBUS);
564 res->BEVECTAUX = beh_dupvaux (befig->BEVECTAUX);
565 res->BEVECTOUT = beh_dupvout (befig->BEVECTOUT);
566 res->BEVECTPOR = beh_dupvpor (befig->BEVECTPOR);
567
568 res->BERIN = beh_duprin (befig->BERIN);
569 res->BEMSG = beh_dupmsg (befig->BEMSG);
570
571 return res;
572 }
573
574 /*}}}************************************************************************/
575 /*{{{ beh_dupbiabl() */
576 /* */
577 /* */
578 /****************************************************************************/
579 biabl_list *beh_dupbiabl(biabl_list *biabl)
580 {
581 if (biabl)
582 {
583 biabl_list *new;
584
585 new = beh_addbiabl(NULL,biabl->LABEL,NULL,NULL);
586 new->TIME = biabl->TIME;
587 new->TIMER = biabl->TIMER;
588 new->TIMEF = biabl->TIMEF;
589 new->TIMEVAR = biabl->TIMEVAR;
590 new->FLAG = biabl->FLAG;
591 new->CNDABL = copyExpr (biabl->CNDABL);
592 new->VALABL = copyExpr (biabl->VALABL);
593 new->LOOP = beh_duploop (biabl->LOOP);
594 new->NEXT = beh_dupbiabl(biabl->NEXT);
595 new->USER = dupptypelst (biabl->USER);
596
597 return new;
598 }
599 else
600 return NULL;
601 }
602
603 /*}}}************************************************************************/
604 /*{{{ beh_dupvbiabl() */
605 /* */
606 /* */
607 /****************************************************************************/
608 vectbiabl_list *beh_dupvbiabl(vectbiabl_list *vbiabl)
609 {
610 if (vbiabl)
611 {
612 vectbiabl_list *new;
613
614 new = beh_addvectbiabl(NULL,vbiabl->LEFT,vbiabl->RIGHT,NULL);
615 new->BIABL = beh_dupbiabl (vbiabl->BIABL);
616 new->NEXT = beh_dupvbiabl (vbiabl->NEXT);
617
618 return new;
619 }
620 else
621 return NULL;
622 }
623
624 /*}}}************************************************************************/
625 /*{{{ beh_duploop() */
626 /* */
627 /* */
628 /****************************************************************************/
629 loop_list *beh_duploop(loop_list *loop)
630 {
631 if (loop)
632 {
633 loop_list *res;
634
635 res = beh_duploop(loop->NEXT);
636 res = beh_newloop(res,loop->VARNAME,loop->INDEX,loop->LEFT,loop->RIGHT);
637
638 return res;
639 }
640 else
641 return NULL;
642 }
643
644 /*}}}************************************************************************/
645 /*{{{ beh_dupreg() */
646 /* */
647 /* */
648 /****************************************************************************/
649 static bereg_list *beh_dupreg(bereg_list *reg)
650 {
651 if (reg)
652 return beh_addbereg(beh_dupreg(reg->NEXT),reg->NAME,
653 beh_dupbiabl(reg->BIABL),NULL,reg->FLAGS);
654 else
655 return NULL;
656 }
657
658 /*}}}************************************************************************/
659 /*{{{ beh_dupvreg() */
660 /* */
661 /* */
662 /****************************************************************************/
663 static bevectreg_list *beh_dupvreg(bevectreg_list *vreg)
664 {
665 if (vreg)
666 return beh_addbevectreg(beh_dupvreg(vreg->NEXT),vreg->NAME,
667 beh_dupvbiabl(vreg->VECTBIABL),
668 vreg->LEFT,vreg->RIGHT,vreg->FLAGS);
669 else
670 return NULL;
671 }
672
673 /*}}}************************************************************************/
674 /*{{{ beh_dupbus() */
675 /* */
676 /* */
677 /****************************************************************************/
678 static bebus_list *beh_dupbus(bebus_list *bus)
679 {
680 if (bus)
681 return beh_addbebus(beh_dupbus(bus->NEXT),bus->NAME,
682 beh_dupbiabl(bus->BIABL),NULL,bus->TYPE,bus->FLAGS);
683 else
684 return NULL;
685 }
686
687 /*}}}************************************************************************/
688 /*{{{ beh_dupvbus() */
689 /* */
690 /* */
691 /****************************************************************************/
692 static bevectbus_list *beh_dupvbus(bevectbus_list *vbus)
693 {
694 if (vbus)
695 return beh_addbevectbus(beh_dupvbus(vbus->NEXT),vbus->NAME,
696 beh_dupvbiabl(vbus->VECTBIABL),
697 vbus->LEFT,vbus->RIGHT,vbus->TYPE,vbus->FLAGS);
698 else
699 return NULL;
700 }
701
702 /*}}}************************************************************************/
703 /*{{{ beh_dupbux() */
704 /* */
705 /* */
706 /****************************************************************************/
707 static bebux_list *beh_dupbux(bebux_list *bux)
708 {
709 if (bux)
710 return beh_addbebux(beh_dupbux(bux->NEXT),bux->NAME,
711 beh_dupbiabl(bux->BIABL),NULL,bux->TYPE,bux->FLAGS);
712 else
713 return NULL;
714 }
715
716 /*}}}************************************************************************/
717 /*{{{ beh_dupvbux() */
718 /* */
719 /* */
720 /****************************************************************************/
721 static bevectbux_list *beh_dupvbux(bevectbux_list *vbux)
722 {
723 if (vbux)
724 return beh_addbevectbux(beh_dupvbux(vbux->NEXT),vbux->NAME,
725 beh_dupvbiabl(vbux->VECTBIABL),
726 vbux->LEFT,vbux->RIGHT,vbux->TYPE,vbux->FLAGS);
727 else
728 return NULL;
729 }
730
731 /*}}}************************************************************************/
732 /*{{{ beh_dupaux() */
733 /* */
734 /* */
735 /****************************************************************************/
736 static beaux_list *beh_dupaux(beaux_list *aux)
737 {
738 if (aux)
739 {
740 beaux_list *res;
741
742 res = beh_addbeaux(beh_dupaux(aux->NEXT),aux->NAME,
743 copyExpr(aux->ABL),NULL,aux->FLAGS);
744 res->TIME = aux->TIME;
745 res->TIMER = aux->TIMER;
746 res->TIMEF = aux->TIMEF;
747 res->TIMEVAR = aux->TIMEVAR;
748
749 return res;
750 }
751 else
752 return NULL;
753 }
754
755 /*}}}************************************************************************/
756 /*{{{ beh_dupvaux() */
757 /* */
758 /* */
759 /****************************************************************************/
760 static bevectaux_list *beh_dupvaux(bevectaux_list *vaux)
761 {
762 if (vaux)
763 {
764 bevectaux_list *res;
765
766 res = beh_addbevectaux(beh_dupvaux(vaux->NEXT),vaux->NAME,
767 copyExpr(vaux->ABL),vaux->LEFT,
768 vaux->RIGHT, vaux->FLAGS);
769 res->TIME = vaux->TIME;
770 res->TIMEVAR = vaux->TIMEVAR;
771
772 return res;
773 }
774 else
775 return NULL;
776 }
777
778 /*}}}************************************************************************/
779 /*{{{ beh_dupout() */
780 /* */
781 /* */
782 /****************************************************************************/
783 static beout_list *beh_dupout(beout_list *out)
784 {
785 if (out)
786 {
787 beout_list *res;
788
789 res = beh_addbeout(beh_dupout(out->NEXT),out->NAME,
790 copyExpr(out->ABL),NULL,out->FLAGS);
791 res->TIME = out->TIME;
792 res->TIMER = out->TIMER;
793 res->TIMEF = out->TIMEF;
794 res->TIMEVAR = out->TIMEVAR;
795
796 return res;
797 }
798 else
799 return NULL;
800 }
801
802 /*}}}************************************************************************/
803 /*{{{ beh_dupvout() */
804 /* */
805 /* */
806 /****************************************************************************/
807 static bevectout_list *beh_dupvout(bevectout_list *vout)
808 {
809 if (vout)
810 {
811 bevectout_list *res;
812
813 res = beh_addbevectout(beh_dupvout(vout->NEXT),vout->NAME,
814 copyExpr(vout->ABL),vout->LEFT,
815 vout->RIGHT, vout->FLAGS);
816 res->TIME = vout->TIME;
817 res->TIMEVAR = vout->TIMEVAR;
818
819 return res;
820 }
821 else
822 return NULL;
823 }
824
825 /*}}}************************************************************************/
826 /*{{{ beh_duppor() */
827 /* */
828 /* */
829 /****************************************************************************/
830 static bepor_list *beh_duppor(bepor_list *por)
831 {
832 if (por)
833 return beh_addbepor(beh_duppor(por->NEXT),por->NAME,por->DIRECTION,
834 por->TYPE);
835 else
836 return NULL;
837 }
838
839 /*}}}************************************************************************/
840 /*{{{ beh_dupvpor() */
841 /* */
842 /* */
843 /****************************************************************************/
844 static bevectpor_list *beh_dupvpor(bevectpor_list *vpor)
845 {
846 if (vpor)
847 return beh_addbevectpor( beh_dupvpor(vpor->NEXT),vpor->NAME,
848 vpor->DIRECTION,vpor->TYPE,
849 vpor->LEFT,vpor->RIGHT);
850 else
851 return NULL;
852 }
853
854 /*}}}************************************************************************/
855 /*{{{ beh_duprin() */
856 /* */
857 /* */
858 /****************************************************************************/
859 static berin_list *beh_duprin(berin_list *rin)
860 {
861 if (rin)
862 {
863 berin_list *res;
864
865 res = beh_duprin(rin->NEXT);
866 if (!(rin->OUT_REF || rin->OUT_VEC || rin->BUS_REF || rin->BUS_VEC ||
867 rin->AUX_REF || rin->AUX_VEC || rin->REG_REF || rin->REG_VEC ||
868 rin->BUX_REF || rin->BUX_VEC))
869 {
870 res = beh_addberin(res,rin->NAME);
871 res->LEFT = rin->LEFT;
872 res->RIGHT = rin->RIGHT;
873 }
874
875 return res;
876 }
877 else
878 return NULL;
879 }
880
881 /*}}}************************************************************************/
882 /*{{{ beh_dupmsg() */
883 /* */
884 /* */
885 /****************************************************************************/
886 static bemsg_list *beh_dupmsg(bemsg_list *msg)
887 {
888 if (msg)
889 return beh_addbemsg(beh_dupmsg(msg->NEXT),msg->LABEL,msg->LEVEL,
890 msg->MESSAGE,copyExpr(msg->ABL),NULL);
891 else
892 return NULL;
893
894 }
895 /*}}}************************************************************************/
896 /*}}}************************************************************************/
897 /*{{{ Explosion functions */
898 /****************************************************************************/
899 ///*{{{ beh_bitrzbiabl() */
900 ///* */
901 ///* */
902 ///****************************************************************************/
903 //biabl_list *beh_bitrzbiabl(biabl_list *biabl, int index)
904 //{
905 // if (biabl)
906 // {
907 // biabl_list *res;
908 // loop_list *loop;
909 //
910 // res = beh_explodeBiabl(biabl->NEXT,index,name,func);
911 // if ((loop = beh_getloop(biabl)))
912 // {
913 // if (loop->INDEX)
914 // {
915 // beh_explodeLoop(loop,biabl,name,func);
916 // return NULL;
917 // }
918 // }
919 // else
920 // {
921 // ptype_list *ptx;
922 //
923 // res = beh_addbiabl(res,biabl->LABEL,biabl->CNDABL,NULL);
924 // res->VALABL = getAblAtPos(biabl->VALABL,index);
925 // res->TIME = biabl->TIME;
926 // res->FLAG = biabl->FLAG;
927 // res->USER = dupptypelst(biabl->USER);
928 // }
929 // return res;
930 // }
931 // else
932 // return biabl;
933 //}
934 //
935 ///*}}}************************************************************************/
936 /*{{{ beh_resolvingfunc() */
937 /* */
938 /* */
939 /****************************************************************************/
940 static void beh_resolvingfunc(char *name,int index,biabl_list *biabl)
941 {
942 char buf[1024], *vname;
943 chain_list *explist;
944
945 sprintf(buf,"%s %d",name, index);
946 vname = namealloc(buf);
947 explist = (chain_list *)gethtitem(BEH_EXP_TABLE,vname);
948 if ((long)explist == EMPTYHT)
949 {
950 explist = NULL;
951 BEH_EXP_LIST = addchain(BEH_EXP_LIST,vname);
952 }
953 addhtitem(BEH_EXP_TABLE,vname,(long)addchain(explist,biabl));
954 }
955
956 /*}}}************************************************************************/
957 /*{{{ beh_addloopreg() */
958 /* */
959 /* */
960 /****************************************************************************/
961 static bereg_list *beh_addloopreg(bereg_list *reg)
962 {
963 chain_list *loopreg, *chainx;
964
965 for (chainx = BEH_EXP_LIST; chainx; chainx = delchain(chainx,chainx))
966 {
967 loopreg = (chain_list *)gethtitem(BEH_EXP_TABLE,chainx->DATA);
968 reg = beh_addbereg(reg,chainx->DATA,beh_expgetbiabl(loopreg),NULL,0);
969 freechain(loopreg);
970 }
971
972 BEH_EXP_LIST = NULL;
973 return reg;
974 }
975
976
977 /*}}}************************************************************************/
978 /*{{{ beh_addloopbus() */
979 /* */
980 /* */
981 /****************************************************************************/
982 static bebus_list *beh_addloopbus(bebus_list *bus)
983 {
984 chain_list *loopbus, *chainx;
985
986 for (chainx = BEH_EXP_LIST; chainx; chainx = delchain(chainx,chainx))
987 {
988 loopbus = (chain_list *)gethtitem(BEH_EXP_TABLE,chainx->DATA);
989 bus = beh_addbebus(bus,chainx->DATA,beh_expgetbiabl(loopbus),NULL,0,0);
990 freechain(loopbus);
991 }
992
993 BEH_EXP_LIST = NULL;
994 return bus;
995 }
996
997
998 /*}}}************************************************************************/
999 /*{{{ beh_addloopbux() */
1000 /* */
1001 /* */
1002 /****************************************************************************/
1003 static bebux_list *beh_addloopbux(bebux_list *bux)
1004 {
1005 chain_list *loopbux, *chainx;
1006
1007 for (chainx = BEH_EXP_LIST; chainx; chainx = delchain(chainx,chainx))
1008 {
1009 loopbux = (chain_list *)gethtitem(BEH_EXP_TABLE,chainx->DATA);
1010 bux = beh_addbebux(bux,chainx->DATA,beh_expgetbiabl(loopbux),NULL,0,0);
1011 freechain(loopbux);
1012 }
1013
1014 BEH_EXP_LIST = NULL;
1015 return bux;
1016 }
1017
1018
1019 /*}}}************************************************************************/
1020 /*{{{ beh_expgetbiabl() */
1021 /* */
1022 /* */
1023 /****************************************************************************/
1024 static biabl_list *beh_expgetbiabl(chain_list *list)
1025 {
1026 if (list)
1027 {
1028 ((biabl_list *)(list->DATA))->NEXT = beh_expgetbiabl(list->NEXT);
1029 return list->DATA;
1030 }
1031 else
1032 return NULL;
1033 }
1034
1035 /*}}}************************************************************************/
1036 ///*{{{ beh_explodeVect() */
1037 ///* */
1038 ///* */
1039 ///****************************************************************************/
1040 //static vectbiabl_list *beh_explodeVect(vectbiabl_list *vbiabl, char *name)
1041 //{
1042 // if (vbiabl)
1043 // {
1044 // vbiabl->NEXT = beh_explodeVect(vbiabl->NEXT,name);
1045 // return beh_explodeVectBiabl(vbiabl,name);
1046 // }
1047 // else
1048 // return vbiabl;
1049 //}
1050 //
1051 ///*}}}************************************************************************/
1052 ///*{{{ beh_explodeVectBiabl() */
1053 ///* */
1054 ///* */
1055 ///****************************************************************************/
1056 //static vectbiabl_list *beh_explodeVectBiabl(vectbiabl_list *vbiabl, char *name)
1057 //{
1058 // vectbiabl_list *next = vbiabl->NEXT;
1059 // biabl_list *biabl = vbiabl->BIABL;
1060 // int left = vbiabl->LEFT;
1061 // int right = vbiabl->RIGHT;
1062 // int i;
1063 // vectbiabl_list *vbiablx;
1064 // biabl_list *new;
1065 // int way;
1066 //
1067 // if (left == right)
1068 // return vbiabl;
1069 // else
1070 // {
1071 // way = (left - right) / abs(left - right);
1072 // vbiabl->RIGHT = left;
1073 // for ( i = left - way ; way*(i - right) >= 0; i -= way )
1074 // {
1075 // if (i == left)
1076 // vbiablx = vbiabl;
1077 // else
1078 // vbiablx = beh_addvectbiabl(vbiablx,i,i,NULL);
1079 // if (( new = beh_explodeBiabl(biabl,abs(i-left),name,NULL) ))
1080 // vbiablx->BIABL = new;
1081 // }
1082 // return next;
1083 // }
1084 //}
1085 //
1086 ///*}}}************************************************************************/
1087 /*{{{ beh_explodeBiabl() */
1088 /* */
1089 /* */
1090 /****************************************************************************/
1091 biabl_list *beh_explodeBiabl(biabl_list *biabl,int index, char *name,int left,
1092 int right,void (*func)(char*,int,biabl_list*))
1093 {
1094 if (biabl)
1095 {
1096 biabl_list *res;
1097 loop_list *loop;
1098
1099 res = beh_explodeBiabl(biabl->NEXT,index,name,left,right,func);
1100 if ((loop = beh_getloop(biabl)))
1101 {
1102 if (loop->INDEX)
1103 {
1104 beh_explodeLoop(loop,biabl,name,func);
1105 return NULL;
1106 }
1107 }
1108 else
1109 {
1110 res = beh_addbiabl(res,biabl->LABEL,NULL,NULL);
1111 res->CNDABL = copyExpr(biabl->CNDABL);
1112 res->VALABL = getAblAtIndex(biabl->VALABL,left,right,index);
1113 res->TIME = biabl->TIME;
1114 res->TIMEVAR = biabl->TIMEVAR;
1115 res->FLAG = biabl->FLAG;
1116 res->USER = dupptypelst(biabl->USER);
1117 }
1118 return res;
1119 }
1120 else
1121 return NULL;
1122 }
1123
1124 /*}}}************************************************************************/
1125 /*{{{ beh_explodeLoop() */
1126 /* */
1127 /* */
1128 /****************************************************************************/
1129 void beh_explodeLoop(loop_list *loop, biabl_list *biabl,char *name,
1130 void (*func)(char*,int,biabl_list*))
1131 {
1132 eqt_ctx *ctx = eqt_init(3);
1133 beh_explodeLoopInt(ctx,loop,biabl,name,func);
1134 eqt_term(ctx);
1135 }
1136
1137 /*}}}************************************************************************/
1138 /*{{{ beh_explodeLoopInt() */
1139 /* */
1140 /* */
1141 /****************************************************************************/
1142 static void beh_explodeLoopInt(eqt_ctx *ctx,loop_list *loop,biabl_list *biabl,char *name,
1143 void (*func)(char*,int,biabl_list*))
1144 {
1145 static char ind[255];
1146
1147 if (loop)
1148 {
1149 int i , way;
1150
1151 way = (loop->LEFT - loop->RIGHT) / abs(loop->LEFT - loop->RIGHT);
1152 for (i = loop->LEFT; way*(i - (int)loop->RIGHT) >= 0; i -= way)
1153 {
1154 eqt_addvar(ctx,loop->VARNAME,i);
1155 sprintf(ind,"%s",loop->INDEX);
1156 beh_explodeLoopInt(ctx,loop->NEXT,biabl,name,func);
1157 }
1158 }
1159 else
1160 {
1161 biabl_list *new;
1162 ptype_list *ptx;
1163 char *eqtres;
1164 int index;
1165
1166 eqtres = eqt_getEvaluedEquation(ctx,ind);
1167 index = atoi(eqtres);
1168 mbkfree(eqtres);
1169 new = beh_addbiabl(NULL,biabl->LABEL,NULL,NULL);
1170 new->VALABL = beh_explodeLoopAbl(ctx,copyExpr(biabl->VALABL));
1171 new->CNDABL = beh_explodeLoopAbl(ctx,copyExpr(biabl->CNDABL));
1172 new->TIME = biabl->TIME;
1173 new->TIMEVAR = biabl->TIMEVAR;
1174 new->FLAG = biabl->FLAG & ~BEH_CND_LOOP;
1175 for ( ptx = biabl->USER; ptx; ptx = ptx->NEXT)
1176 if (ptx->TYPE != BEH_TYPE_LOOP)
1177 new->USER = addptype(new->USER,ptx->TYPE,ptx->DATA);
1178 if (func)
1179 (*func) (name,index,new);
1180 }
1181 }
1182
1183 /*}}}************************************************************************/
1184 /*{{{ beh_explodeLoopAbl() */
1185 /* */
1186 /* eqt variables positionned */
1187 /* */
1188 /****************************************************************************/
1189 static chain_list *beh_explodeLoopAbl(eqt_ctx *ctx,chain_list *abl)
1190 {
1191 if (ATOM(abl))
1192 {
1193 char name[256], index[256];
1194 char *eqtres;
1195
1196 switch (sscanf(VALUE_ATOM(abl),"%s %s",name,index))
1197 {
1198 case 2 :
1199 eqtres = eqt_getEvaluedEquation(ctx,index);
1200 sprintf(name,"%s %s",name,eqtres);
1201 abl->DATA = namealloc(name);
1202 mbkfree(eqtres);
1203 default :
1204 return abl;
1205 }
1206 }
1207 else
1208 {
1209 chain_list *ablx = abl;
1210
1211 while ((ablx = CDR(ablx)))
1212 CAR(ablx) = beh_explodeLoopAbl(ctx,CAR(ablx));
1213 return abl;
1214 }
1215 }
1216
1217 /*}}}************************************************************************/
1218 /*}}}************************************************************************/