Initial version of donated sources by Avertec, 3.4p5.
[tas-yagle.git] / distrib / sources / behvrlog / bgl_drive.c
1 /****************************************************************************/
2 /* */
3 /* file : vhd_drive.c */
4 /* date : Oct 1999 */
5 /* version : v202 */
6 /* author(s): LESTER A.P.P */
7 /* : PINTO A. */
8 /* description : Synopsys VHDL driver */
9 /* */
10 /****************************************************************************/
11
12 #include <stdlib.h>
13 #include <stdio.h>
14 #include <string.h>
15 #include <time.h>
16 #include <stdarg.h>
17 #include <math.h>
18
19 #include AVT_H
20 #include MUT_H
21 #include LOG_H
22 #include BEH_H
23 #include BEG_H
24 #include BEF_H
25 #include BHL_H
26 #include BGL_H
27 #include BVL_H
28
29 #include "bgl_type.h"
30 #include "bgl_util.h"
31 #include "bgl_drive.h"
32
33 /* Global variables */
34
35 static char *TIME_UNIT;
36
37 int BGL_DRIVE_PRIMITIVES = FALSE;
38 int BGL_ONLY_PRIMITIVES = FALSE;
39
40
41 static int BGL_VECT_ASS = 0;
42 static int BGL_CPT_IND = 0;
43
44 static char *CLOCKSTR;
45
46 /****************************************************************************/
47 /*{{{ Static function prototypes */
48 /****************************************************************************/
49 static void writelist(FILE *fp, chain_list *ptchain, int indent, int posEdge, int negEdge);
50 static void print_value(FILE *fp,chain_list *abl, char type, int time, int,int,char **buffer, int *bufsize);
51 //static void begen_treatment (FILE *fp, befig_list *figure);
52
53 static void print_withselect(FILE *fp, biabl_list *biabl, char *name, int vectsize, char **buffer, int *bufsize);
54 static void print_affected(FILE *fp, char indent, char type, int time, int,int,char *name, char *vname, loop_list *loop,long);
55 static void print_loop (FILE *fp, char indent,char *head,int np,int *cpt,loop_list *loop);
56 static void print_endLoop (FILE *fp,char indent,char *head,int np,int cpt, int nbsame,loop_list *loop);
57 static void print_loopList (FILE *fp,char indent,char *head,int np,int *cpt, int nbsame,loop_list *loop);
58 static void print_signal(FILE *fp, char *name, char type, int left, int right);
59 static chain_list * print_process_declaration(FILE *fp, biabl_list *biabl, char *name, int np, char *head, char **buffer,ptype_list *clock);
60 static char *bgl_bebusname(char *name);
61 static char *bgl_beregname(char *name);
62 static void print_interassign(FILE *fp, char *dest, char *src, int mode);
63
64
65 static void print_special(long flags, char *buf)
66 {
67 strcpy(buf,"");
68 if (flags & (BEH_CND_WEAK|BEH_CND_STRONG|BEH_CND_PULL))
69 {
70 char *str="weak";
71 if (flags & BEH_CND_STRONG) str="strong";
72 else if (flags & BEH_CND_PULL) str="pull";
73 sprintf(buf,"(%s1, %s0) ", str, str);
74 }
75 }
76 /*}}}************************************************************************/
77 /*{{{ Utilities */
78 /****************************************************************************/
79 /*{{{ writelist() */
80 /* */
81 /* ecrit dans un fichier une chaine list */
82 /****************************************************************************/
83 static void
84 writelist(FILE *fp, chain_list *ptchain, int indent, int posEdge, int negEdge)
85 {
86 char *name;
87 char indentstr[80];
88 char buf[1024];
89 int hpos = indent;
90 int first = TRUE;
91 int i;
92 chain_list *namelist = NULL;
93 chain_list *chainx;
94
95 hpos = indent;
96 for (i = 0; i < indent; i ++)
97 indentstr[i] = ' ';
98 indentstr[i] = '\0';
99
100 if (posEdge)
101 {
102 name = bgl_getRadical(CLOCKSTR,NULL);
103 hpos += strlen(name);
104 if (!negEdge)
105 {
106 fprintf(fp, "posedge ");
107 hpos += 8;
108 }
109 fprintf(fp, "%s", name);
110 first = FALSE;
111 }
112 else if (negEdge)
113 {
114 name = bgl_getRadical(CLOCKSTR,NULL);
115 hpos += strlen(name) + 8;
116 fprintf(fp, "negedge %s", name);
117 first = FALSE;
118 }
119 else
120 {
121 // pre-treatment to delete twice word
122 // and clock in case of posedge or negedge
123 for (; ptchain; ptchain = delchain(ptchain,ptchain))
124 {
125 chain_list *tail;
126
127 if ( isBitStr(ptchain->DATA)
128 /*|| ( (posEdge || negEdge) && ptchain->DATA == CLOCKSTR)*/)
129 continue;
130 beg_get_vectname(ptchain->DATA,&name,NULL,NULL,BEG_SEARCH_ABL);
131 tail = NULL;
132 for (chainx = namelist; chainx; chainx = chainx->NEXT)
133 {
134 tail = chainx;
135 if ( name == chainx->DATA )
136 break;
137 }
138 if (!chainx)
139 if (tail)
140 tail->NEXT = addchain(NULL,name);
141 else
142 namelist = addchain(NULL,name);
143 else
144 continue;
145 }
146
147 for (chainx = namelist; chainx; chainx = delchain(chainx,chainx))
148 {
149 if (!first)
150 fprintf(fp, " or ");
151 if (hpos > 60)
152 {
153 fprintf(fp, "\n%s", indentstr);
154 hpos = indent;
155 }
156 name = chainx->DATA;
157 hpos += strlen(name) + 4 ;
158 fprintf(fp,"%s",bgl_vectorize_sub(name, buf));
159 first = FALSE;
160 }
161 }
162 }
163
164 /*}}}************************************************************************/
165 /*{{{ print_time() */
166 /* */
167 /* */
168 /****************************************************************************/
169 static void print_time_int(FILE *fp,int time,int timer, int timef, int timehz)
170 {
171 if (timef<=0) timef=timer;
172 if (timer<=0) timer=timef;
173 if (timer==0 && timef==0) timef=timer=time;
174
175 if (timer)
176 {
177 if (timehz<0)
178 {
179 if (timer==timef)
180 fprintf(fp,"#%u ",timer);
181 else
182 fprintf(fp,"#(%u, %u) ",timer, timef);
183 }
184 else
185 {
186 fprintf(fp,"#(%u, %u, %u) ",timer, timef, timehz);
187 }
188 }
189 }
190
191 static void print_time(FILE *fp,int time,int timer, int timef)
192 {
193 print_time_int(fp,time,timer,timef,-1);
194 }
195
196 /*}}}************************************************************************/
197 /*{{{ isone() */
198 /* */
199 /* */
200 /****************************************************************************/
201 static int isone(char *txt)
202 {
203 return !strcmp(txt,"1'b1");
204 }
205
206
207 /*}}}************************************************************************/
208 /*{{{ bebus_suffix() */
209 /* */
210 /* */
211 /****************************************************************************/
212 static char *bgl_bebusname(char *name)
213 {
214 char buf[256], *c;
215
216 if ((c=strchr(name, ' '))!=NULL && *(c+1)!='\0')
217 {
218 *c='\0';
219 sprintf(buf, "%s_bebus %s",name,c+1);
220 *c=' ';
221 }
222 else
223 sprintf(buf, "%s_bebus", name);
224 return namealloc(buf);
225 }
226
227 /*}}}************************************************************************/
228 /*{{{ bereg_suffix() */
229 /* */
230 /* */
231 /****************************************************************************/
232 static char *bgl_beregname(char *name)
233 {
234 char buf[256], *c;
235
236 if ((c=strchr(name, ' '))!=NULL && *(c+1)!='\0')
237 {
238 *c='\0';
239 sprintf(buf, "%s_bereg %s",name,c+1);
240 *c=' ';
241 }
242 else
243 sprintf(buf, "%s_bereg", name);
244 return namealloc(buf);
245 }
246
247 /*}}}************************************************************************/
248 /*{{{ Module declaration */
249 /****************************************************************************/
250 /*{{{ module_declaration_vect() */
251 /* */
252 /* */
253 /****************************************************************************/
254 static void module_declaration_vect(FILE *fp,bevectpor_list *vpor,int cpt)
255 {
256 if (vpor)
257 {
258 module_declaration_vect(fp,vpor->NEXT,cpt+1);
259 fprintf(fp,"%s",bgl_vlogname(vpor->NAME));
260 if (cpt)
261 fprintf(fp,", ");
262 }
263 }
264
265 /*}}}************************************************************************/
266 /*{{{ module_declaration_sing() */
267 /* */
268 /* */
269 /****************************************************************************/
270 static void module_declaration_sing(FILE *fp,bepor_list *por,int vpor)
271 {
272 if (por)
273 {
274 int left, right;
275 char *name;
276 struct bepor *porx;
277
278 if (vpor)
279 fprintf(fp,", ");
280 por = (bepor_list *)reverse((chain_list *)por);
281 for (porx = por; porx; porx = porx->NEXT)
282 {
283 porx = bgl_vectnam(porx, &left, &right, &name, 0);
284 fprintf(fp, "%s", bgl_vlogname(name));
285 mbkfree(name);
286 if (porx->NEXT)
287 fprintf(fp,", ");
288 }
289 por = (bepor_list *)reverse((chain_list *)por);
290 }
291 }
292
293 /*}}}************************************************************************/
294 /*{{{ module_declaration() */
295 /* */
296 /* */
297 /****************************************************************************/
298 static void
299 module_declaration(FILE *fp, befig_list *figure)
300 {
301 iprint(fp,'i',"module %s", bgl_vlogname(figure->NAME));
302
303 if (figure->BEPOR || figure->BEVECTPOR)
304 {
305 fprintf(fp," (");
306 module_declaration_vect(fp,figure->BEVECTPOR,0);
307 module_declaration_sing(fp,figure->BEPOR,(int)(long)figure->BEVECTPOR);
308 fprintf(fp,")");
309 }
310
311 fprintf(fp, ";\n\n");
312 }
313
314 /*}}}************************************************************************/
315 /*}}}************************************************************************/
316 /*{{{ print_process_declaration() */
317 /* */
318 /* Create the sensitivity list */
319 /****************************************************************************/
320 static chain_list *
321 print_process_declaration(FILE *fp, biabl_list *biabl, char *name,
322 int np, char *head, char **buffer, ptype_list *clock)
323 {
324 chain_list *loopchain = NULL;
325 chain_list *chainx;
326 loop_list *loop;
327 biabl_list *biablx;
328 chain_list *temp_expr;
329 int isFlipFlop = FALSE;
330 int isEdgeCondition = FALSE;
331 int posEdge = 0;
332 int negEdge = 0;
333 char *clk;
334
335 iprint(fp,'i',"always @ (");
336 for (biablx = biabl; biablx; biablx = biablx->NEXT)
337 {
338 if (beh_isloop(biablx))
339 {
340 for (loop = beh_getloop(biablx); loop; loop = loop->NEXT)
341 {
342 for (chainx = loopchain; chainx; chainx = chainx->NEXT)
343 if (chainx->DATA == loop->VARNAME)
344 break;
345 if (!chainx)
346 loopchain = addchain(loopchain,loop->VARNAME);
347 }
348 }
349 if (biablx->VALABL == NULL)// || biablx->CNDABL == NULL)
350 beh_toolbug(20, "print_process_declaration", name, 0);
351 /* if ( biablx->CNDABL &&
352 (isEdgeCondition = bef_search_stable(biablx->CNDABL,&CLOCKSTR)) > 0)
353 {
354 if (bef_search_notck(biablx->CNDABL,CLOCKSTR) > 0)
355 negEdge = 1;
356 else
357 posEdge = 1;
358 isFlipFlop = TRUE;
359 }*/
360 }
361 if (clock==NULL || clock->DATA==NULL)
362 {
363 chain_list *list;
364 temp_expr = createExpr(OR);
365 if (!isFlipFlop)
366 for (biablx = biabl; biablx; biablx = biablx->NEXT)
367 {
368 if (clock==NULL || (clock->DATA==NULL && clock->TYPE==1 && bef_search_stable(biablx->CNDABL,&clk))<=0)
369 {
370 if (biablx->CNDABL)
371 addQExpr(temp_expr, copyExpr(biablx->CNDABL));
372 addQExpr(temp_expr, copyExpr(biablx->VALABL));
373 }
374 }
375 else
376 for (biablx = biabl; biablx; biablx = biablx->NEXT)
377 if (biablx->CNDABL)
378 {
379 if (clock==NULL || (clock->DATA==NULL && clock->TYPE==1 && bef_search_stable(biablx->CNDABL,&clk))<=0)
380 addQExpr(temp_expr, copyExpr(biablx->CNDABL));
381 }
382
383 list=supportChain_listExpr(temp_expr);
384 /*if (clock!=NULL && clock->DATA==NULL)
385 {
386 chain_list *temp=NULL;
387 while (list!=NULL)
388 {
389 if (bgl_getRadical((char *)list->DATA,NULL)==list->DATA)
390 temp=addchain(temp, list->DATA);
391 list=delchain(list, list);
392 }
393 list=reverse(temp);
394 }*/
395 writelist(fp, list, 10, posEdge, negEdge);
396 freeExpr(temp_expr);
397 }
398 else
399 {
400 CLOCKSTR=clock->DATA;
401 writelist(fp, addchain(NULL, clock->DATA), 10, clock->TYPE==1?1:0, clock->TYPE==0?1:0);
402 }
403 fprintf(fp, ")\n");
404
405 return loopchain;
406
407 //
408 np = 0;
409 head = NULL;
410 buffer = NULL;
411 }
412
413 /*}}}************************************************************************/
414 /*{{{ Process driving */
415 /****************************************************************************/
416 static void print_procBegin(FILE *fp, chain_list *loopchain)
417 {
418 chain_list *chainx;
419
420 if (loopchain)
421 {
422 iprint(fp,'i',"begin : LOOP_NB_%d\n",BGL_CPT_IND ++);
423 iprint(fp,'0',"integer ");
424 for (chainx = loopchain; chainx; chainx = delchain(chainx,chainx))
425 if (chainx != loopchain)
426 fprintf(fp,", %s",(char*)chainx->DATA);
427 else
428 fprintf(fp,"%s",(char*)chainx->DATA);
429 fprintf(fp,";\n\n");
430 }
431 else
432 iprint(fp,'i',"begin\n");
433 }
434
435 static void print_procEnd(FILE *fp)
436 {
437 iprint(fp,'-',"end\n");
438 }
439
440 static void print_procIf(FILE *fp, char *buffer)
441 {
442 if (buffer[0]=='@')
443 {
444 // iprint(fp,'+',"%s\n",buffer);
445 iprint(fp,'+',"");
446 }
447 else
448 iprint(fp,'+',"if (%s)\n",bgl_printabl(buffer));
449 }
450
451 static void print_procElsif(FILE *fp, char *buffer)
452 {
453 iprint(fp,'+',"else if (%s)\n",bgl_printabl(buffer));
454 }
455
456 static int print_procElse(FILE *fp)
457 {
458 iprint(fp,'+',"else\n");
459
460 return 1;
461 }
462
463 static int print_procEndif(FILE *fp, char ind)
464 {
465 iprint(fp,ind,NULL);
466
467 return 1;
468
469 fp = NULL;
470 ind = 0;
471 }
472
473 static int print_edge(char *buffer, char *ckname, char ckstate,
474 char *signame)
475 {
476 sprintf(buffer,"@ (%sedge %s)",(ckstate=='1')?"pos":"neg",ckname);
477
478 return 0;
479 signame = NULL;
480 }
481
482
483 /*}}}************************************************************************/
484 /*{{{ Ports driving */
485 /* */
486 /* */
487 /****************************************************************************/
488
489 static void port_begin(FILE *fp)
490 {
491 fp = NULL;
492 }
493
494 static void port_end(FILE *fp)
495 {
496 fprintf(fp,";\n\n");
497 }
498
499 /*}}}************************************************************************/
500 /*{{{ print_endLoop() */
501 /* */
502 /* */
503 /****************************************************************************/
504 static void print_endLoop(FILE *fp,char indent,char *head,int np,int cpt,
505 int nbsame,loop_list *loop)
506 {
507 if (loop)
508 {
509 if (nbsame <= 0)
510 iprint(fp,indent,"end\n");
511 print_endLoop(fp,indent,head,np,0,nbsame-1,loop->NEXT);
512 }
513
514 cpt = 0;
515 }
516
517 /*}}}************************************************************************/
518 /*{{{ print_loopList() */
519 /* */
520 /* */
521 /****************************************************************************/
522 static void print_loopList(FILE *fp,char indent,char *head,int np,int *cpt,
523 int nbsame,loop_list *loop)
524 {
525 if (loop)
526 {
527 if (nbsame <= 0)
528 print_loop(fp,indent,head,np,cpt,loop);
529 print_loopList(fp,indent,head,np,cpt,nbsame - 1,loop->NEXT);
530 }
531 }
532
533 /*}}}************************************************************************/
534 /*{{{ print_loop() */
535 /* */
536 /* */
537 /****************************************************************************/
538 static void print_loop(FILE *fp,char indent,char *head,int np,int *cpt,
539 loop_list *loop)
540 {
541 int left, right, up;
542 char *name;
543
544 name = loop->VARNAME;
545 left = loop->LEFT;
546 right = loop->RIGHT;
547 up = (left < right) ? 1 : 0;
548
549 iprint(fp,'0',"for (%s = %d; %s %c= %d; %s = %s %c 1)\n",
550 name,left,name,(up)?'<':'>',right,name,name,(up)?'+':'-');
551 iprint(fp,indent,"begin\n");
552
553 cpt = NULL;
554 head = NULL;
555 np = 0;
556 }
557
558 /*}}}************************************************************************/
559 /*{{{ print_withselect() */
560 /* */
561 /* */
562 /****************************************************************************/
563 static void
564 print_withselect(FILE *fp, biabl_list *biabl, char *name,
565 int vectsize, char **buffer, int *bufsize)
566 {
567 int cpt = 1;
568 char buf[4096];
569
570 // sensibility list
571 print_process_declaration(fp,biabl,name,cpt,"BUS",buffer,NULL);
572
573 // process
574 iprint(fp,'i',"begin\n");
575
576 *buffer[0] = '\0';
577 *buffer = bgl_abl2str(biabl->CNDABL,*buffer,bufsize);
578
579 iprint(fp,'+',"case (%s)\n",bgl_printabl(*buffer));
580
581 for (; biabl; biabl = biabl->NEXT, cpt ++)
582 {
583 if (biabl->VALABL == NULL)
584 beh_toolbug(20,"print_withselect",name,0);
585
586 if (biabl->FLAG&BEH_CND_SEL_OTHERS)
587 iprint (fp,'0',"default : ");
588 else if (biabl->FLAG&BEH_CND_SELECT)
589 {
590 char *bitcnd;
591
592 bitcnd = bgl_getBitStr(beh_getcndvectfbiabl(biabl),buf);
593 iprint(fp,'0',"%s : ",bitcnd);
594 mbkfree(bitcnd);
595 }
596 else
597 beh_toolbug(19, "print_withselect", name, 0);
598
599 fprintf(fp,"%s = ",name);
600 print_time(fp,biabl->TIME, 0, 0);
601 *buffer[0] = '\0';
602 *buffer = bgl_abl2str(biabl->VALABL, *buffer, bufsize);
603 fprintf(fp,"%s;\n",bgl_printabl(*buffer));
604
605 if ( !biabl->NEXT )
606 if ( !(biabl->FLAG&BEH_CND_SEL_OTHERS) )
607 {
608 char *tmp;
609
610 iprint (fp,'0',"default : ");
611 fprintf(fp,"%s = ",name);
612 tmp = bgl_getBitStr(genHZBitStr(vectsize),buf);
613 fprintf(fp,"%s;\n",tmp);
614 mbkfree(tmp);
615 }
616 }
617 iprint(fp,'<',"endcase\n");
618 iprint(fp,'<',"end\n");
619 }
620
621 /*}}}************************************************************************/
622 /*{{{ print_value() */
623 /* */
624 /* */
625 /****************************************************************************/
626 static void
627 print_value(FILE *fp,chain_list *abl, char type, int time, int timer, int timef,
628 char **buffer, int *bufsize)
629 {
630 *buffer[0] = '\0';
631
632 switch (type)
633 {
634 case 'R' :
635 print_time(fp,time,timer,timef);
636 case 'W':
637 default:
638 break;
639 }
640
641 if (BGL_VECT_ASS)
642 {
643 abl = beg_compactAbl(copyExpr(abl));
644 *buffer = bgl_abl2str(abl, *buffer, bufsize);
645 freeExpr(abl);
646 }
647 else
648 *buffer = bgl_abl2str(abl, *buffer, bufsize);
649 fprintf(fp,"%s",bgl_printabl(*buffer));
650 if (type!='w')
651 fprintf(fp,";\n");
652
653 time = 0;
654 }
655
656 /*}}}************************************************************************/
657 /*{{{ print_affected() */
658 /* */
659 /* */
660 /****************************************************************************/
661 static void
662 print_affected(FILE *fp, char indent, char type, int time, int timer, int timef,
663 char *name, char *vname, loop_list *loop, long specialflags)
664 {
665 char buf[128];
666 char *sign="=";
667 if (indent)
668 iprint(fp,indent,"");
669 switch (type)
670 {
671 case 'W':
672 case 'w':
673 fprintf(fp,"assign ");
674 print_special(specialflags, buf);
675 fprintf(fp,buf);
676 if (type=='w')
677 print_time_int(fp,time,timer,timef,0);
678 else
679 print_time(fp,time,timer,timef);
680 break;
681 case 'R':
682 if (V_BOOL_TAB[__MGL_NONBLOKING_ASSIGN].VALUE)
683 sign="<=";
684 default:
685 break;
686 }
687
688 if (vname == name)
689 fprintf(fp,"%s %s ",bgl_vectorize(name), sign);
690 else if (loop && loop->INDEX)
691 fprintf(fp,"%s[%s] %s ",name,loop->INDEX, sign);
692 else
693 fprintf(fp,"%s %s ",vname, sign);
694 }
695
696 /*}}}************************************************************************/
697 /*{{{ print_signal() */
698 /* */
699 /* */
700 /****************************************************************************/
701 static void
702 print_signal(FILE *fp, char *name, char type, int left, int right)
703 {
704 switch (type)
705 {
706 case 'P' :
707 case 'R' :
708 case 'b' :
709 iprint(fp,'0',"reg ");
710 break;
711 case 'B' :
712 case 'r' :
713 case 'c' :
714 case 'W' :
715 iprint(fp,'0',"wire ");
716 break;
717 default :
718 iprint(fp,'0',"linkage ");
719 }
720 if (type == 'B')
721 name = bgl_bebusname(name);
722 else if (type == 'b')
723 name = bgl_bebusname(name);
724 else if (type == 'P')
725 name = bgl_beregname(name);
726
727 if (left != -1)
728 fprintf(fp,"[%d:%d] %s;\n",left,right,bgl_vlogname(name));
729 else
730 fprintf(fp,"%s;\n",bgl_vlogname(name));
731 }
732
733 /*}}}************************************************************************/
734 /*{{{ print_por() */
735 /* */
736 /* */
737 /****************************************************************************/
738 static void print_por(FILE *fp, char *name, char dir, int left, int right)
739 {
740 char *mode;
741
742 mode = NULL;
743
744 switch (dir)
745 {
746 case 'I':
747 mode = "input"; break;
748 case 'O': case 'Z':
749 mode = "output"; break;
750 case 'B': case 'T':
751 mode = "inout"; break;
752 default:
753 mode = "input"; break;
754 }
755
756 if (left != -1)
757 iprint(fp,'0',"%-6s [%d:%d] %s", mode, left, right, bgl_vlogname(name));
758 else
759 iprint(fp,'0',"%-6s %s", mode, bgl_vlogname(name));
760 }
761
762 /*}}}************************************************************************/
763 /*{{{ print_interassign() */
764 /* */
765 /* */
766 /****************************************************************************/
767 static void print_interassign(FILE *fp, char *dest, char *src, int mode)
768 {
769 char buf0[1024];
770 char buf1[1024];
771 if (mode)
772 iprint(fp,'0',"assign %s = %s;\n",bgl_vectorize_sub(dest,buf0),bgl_vectorize_sub(src,buf1));
773 else
774 iprint(fp,'0',"assign %s = %s;\n", dest, src);
775 }
776
777 /*}}}************************************************************************/
778 /*}}}************************************************************************/
779 ///*{{{ Traitement de la begen */
780 ///****************************************************************************/
781 ///*{{{ begen_treatment() */
782 ///* */
783 ///* */
784 ///****************************************************************************/
785 //static void
786 //begen_treatment(FILE *fp, befig_list *figure)
787 //{
788 // begen_list *gen;
789 //
790 // gen = figure->BEGEN;
791 //
792 // iprint(fp,'i',NULL);
793 // if (gen)
794 // {
795 // iprint(fp,'+',"GENERIC (\n");
796 //
797 // for (gen = figure->BEGEN; gen->NEXT; gen = gen->NEXT)
798 // iprint(fp,'0',"CONSTANT %s : %s := %ld ;\t-- %s\n",
799 // gen->NAME,gen->TYPE,*((long *)gen->VALUE),gen->NAME);
800 //
801 // iprint(fp,'-',"CONSTANT %s : %s := %ld \t-- %s\n",
802 // gen->NAME,gen->TYPE,*((long *)gen->VALUE),gen->NAME);
803 // iprint(fp,'-',"); \n");
804 // }
805 //}
806 //
807 ///*}}}************************************************************************/
808 ///*}}}************************************************************************/
809 /*{{{ Traitement des messages */
810 /****************************************************************************/
811 /*{{{ bgl_initDriver() */
812 /* */
813 /* */
814 /****************************************************************************/
815 void bgl_initDriver(bef_driver *driver, FILE *fp, befig_list *fig, ht *porht,
816 char **buffer, int *bufsize)
817 {
818 bef_driverSet(driver,fp,fig,buffer,bufsize,
819 print_time,
820 print_endLoop,
821 print_loopList,
822 print_loop,
823 print_value,
824 print_affected,
825 print_signal,
826 print_interassign,
827 isone);
828 bef_driverSetAbl(driver,
829 bgl_abl2strbool);
830 bef_driverSetProcess(driver,
831 print_withselect,
832 print_process_declaration,
833 print_procBegin,
834 print_procEnd,
835 print_procIf,
836 print_procElsif,
837 print_procElse,
838 print_procEndif,
839 print_edge);
840 bef_driverSetStr(driver,
841 bgl_vlogname,
842 beh_buildvlgvectname,
843 bgl_vectorize_sub,
844 bgl_getBitStr,
845 bgl_bebusname,
846 bgl_beregname);
847 bef_driverSetPor(driver,
848 print_por,
849 port_end,
850 port_begin,
851 porht);
852 driver->VLG=1;
853 }
854
855 /*}}}************************************************************************/
856 /*}}}************************************************************************/
857 /*{{{ Function de drive */
858 /****************************************************************************/
859 /*{{{ vlogsavebefig() */
860 /* */
861 /* description : print out a text file containing a data-flow VHDL */
862 /* description */
863 /****************************************************************************/
864 void
865 vlogsavebefig(befig_list *pthedbefig, unsigned int trace_mode)
866 {
867 char *suffix, *str;
868 char *buffer;
869 int bufsize;
870 FILE *fp;
871 ht *vlgportht;
872 bef_driver driver;
873
874 BGL_VECT_ASS = (int)(long)getenv("DRI_VECT_ASS");
875
876 if (!pthedbefig)
877 beh_toolbug(10, "vlogsavebefig", NULL, 0);
878
879 bufsize = 2048;
880 buffer = mbkalloc(bufsize);
881 buffer[0] = '\0';
882
883 suffix = V_STR_TAB[__BGL_FILE_SUFFIX].VALUE;
884 if (!suffix)
885 suffix = namealloc("v");
886 fp = mbkfopen(pthedbefig->NAME,suffix,WRITE_TEXT);
887 if (!fp)
888 {
889 beh_error(107, NULL);
890 EXIT(1);
891 }
892
893 vlgportht = addht(40);
894 // imported
895 bgl_initDriver(&driver,fp,pthedbefig,vlgportht,&buffer,&bufsize);
896 str = getenv("BGL_DRIVE_PRIMITIVES");
897 if (str != NULL)
898 if ((str[0]=='y') || (str[0]=='Y'))
899 BGL_DRIVE_PRIMITIVES = 1;
900 else
901 BGL_DRIVE_PRIMITIVES = 0;
902 else
903 BGL_DRIVE_PRIMITIVES = 0;
904
905 //BGL_LOOP_CPT = 0;
906
907 if ((trace_mode & BGL_TRACE) != 0)
908 (void) fprintf(stdout, "Saving '%s' in a verilog file (%s)\n",
909 pthedbefig->NAME, suffix);
910
911 sprintf(buffer,"Verilog data flow description generated from `%s`\n",
912 pthedbefig->NAME);
913 (void) avt_printExecInfo(fp, "/*", buffer, "*/");
914
915 TIME_UNIT = bef_gettimeunit(pthedbefig->TIME_UNIT);
916 fprintf(fp, "\n");
917 fprintf(fp, "`timescale 1 %s/1 %s\n\n", TIME_UNIT, TIME_UNIT);
918
919
920 module_declaration(fp, pthedbefig);
921
922 bef_drive_porDeclaration(&driver);
923 bef_drive_sigDeclaration(&driver);
924
925 delht(vlgportht);
926 vlgportht = NULL;
927
928 bef_drive_aux(&driver);
929 bef_drive_reg(&driver);
930 bef_drive_bux(&driver);
931 bef_drive_bus(&driver);
932 bef_drive_out(&driver);
933
934 delht(vlgportht);
935 vlgportht = NULL;
936
937 (void) fprintf(fp, "\nendmodule\n");
938 (void) fclose(fp);
939
940 if (V_BOOL_TAB[__API_DRIVE_CORRESP].VALUE)
941 bvl_drivecorresp(pthedbefig->NAME, pthedbefig, 1);
942
943 bgl_freenames();
944 mbkfree(buffer);
945 }
946
947 /*}}}************************************************************************/
948 /*}}}************************************************************************/