1 /****************************************************************************/
3 /* file : vhd_drive.c */
6 /* author(s): LESTER A.P.P */
8 /* description : Synopsys VHDL driver */
10 /****************************************************************************/
27 #include "bvl_utype.h"
28 #include "bvl_utdef.h"
31 /* Global variables */
33 static char *TIME_UNIT
;
35 static int BVL_VECT_ASS
= 0;
36 static int BVL_LOOP_IND
[] = {0,0,0,0,0,0,0,0,0,0,
37 0,0,0,0,0,0,0,0,0,0,
39 static int BVL_CPT_IND
= 0;
41 /****************************************************************************/
42 /*{{{ Static function prototypes */
43 /****************************************************************************/
44 static void writelist (FILE *fp
, chain_list
*ptchain
, int indent
);
45 static void begen_treatment (FILE *fp
, befig_list
*figure
);
47 static void print_msg(FILE *fp
, befig_list
*figure
, char **buffer
, int *bufsize
);
48 //static void print_value(FILE *fp,chain_list *abl, int time, char **buffer, int *bufsize);
49 static void print_withselect(FILE *fp
, biabl_list
*biabl
, char *name
, int vectsize
, char **buffer
, int *bufsize
);
50 static void print_time (FILE *fp
, int time
,int,int);
51 static char *vhd_bebusname (char *name
);
52 //static void print_withselect (FILE *fp, biabl_list *biabl, char *name, int vectsize);
53 //static void print_value (FILE *fp, chain_list *abl, int time);
55 //static void print_affected (FILE *fp, char indent,char *name,char *vname,loop_list *loop);
56 static void print_loop (FILE *fp
, char indent
,char *head
,int np
,int *cpt
,loop_list
*loop
);
57 static void print_endLoop (FILE *fp
,char indent
,char *head
,int np
,int cpt
, int nbsame
,loop_list
*loop
);
58 static void print_loopList (FILE *fp
,char indent
,char *head
,int np
,int *cpt
, int nbsame
,loop_list
*loop
);
59 static void print_interassign (FILE *fp
, char *dest
, char *src
, int mode
);
60 //static void print_signal (FILE *fp, char *name, int left, int right);
62 static chain_list
*print_process_declaration(FILE *fp
, biabl_list
*biabl
, char *name
, int np
, char *head
, char **buffer
,ptype_list
*clock
);
64 /*}}}************************************************************************/
66 /****************************************************************************/
67 /*{{{ settimeunit() */
70 /****************************************************************************/
71 void settimeunit (unsigned char time_unit_char
)
73 TIME_UNIT
= bef_gettimeunit(time_unit_char
);
76 /*}}}************************************************************************/
79 /* ecrit dans un fichier une chaine list */
80 /****************************************************************************/
81 static void writelist(FILE *fp
, chain_list
*ptchain
, int indent
)
88 chain_list
*namelist
= NULL
;
93 for (i
=0; i
<indent
; i
++)
97 // pre-traitement de la liste pour supprimmer les doublons
98 for (; ptchain
; ptchain
= ptchain
->NEXT
)
100 if ( isBitStr(ptchain
->DATA
) )
102 beg_get_vectname(ptchain
->DATA
,&name
,NULL
,NULL
,BEG_SEARCH_ABL
);
104 for (chainx
=namelist
;chainx
;chainx
=chainx
->NEXT
)
107 if (name
== chainx
->DATA
)
112 tail
->NEXT
= addchain(NULL
,name
);
114 namelist
= addchain(NULL
,name
);
119 for (chainx
= namelist
; chainx
; chainx
= chainx
->NEXT
)
125 fprintf(fp
, "\n%s", indentstr
);
129 hpos
+= strlen(name
) + 2;
130 fprintf(fp
,"%s",bvl_vhdlname(name
));
136 /*}}}************************************************************************/
137 /*{{{ print_time() */
140 /****************************************************************************/
141 void print_time(FILE *fp
,int time
,int timer
, int timef
)
144 fprintf(fp
," AFTER %u %s",time
,TIME_UNIT
);
147 /*}}}************************************************************************/
151 /****************************************************************************/
152 static int isone(char *txt
)
154 return !strcmp(txt
,"'1'");
157 /*}}}************************************************************************/
158 /*{{{ vhd_bebusname() */
161 /****************************************************************************/
162 static char *vhd_bebusname(char *name
)
167 /*}}}************************************************************************/
168 /*{{{ vhd_beregname() */
171 /****************************************************************************/
172 static char *vhd_beregname(char *name
)
177 /*}}}************************************************************************/
178 /*{{{ print_process_declaration() */
181 /****************************************************************************/
182 static chain_list
*print_process_declaration(FILE *fp
, biabl_list
*biabl
,
183 char *name
, int np
, char *head
,
184 char **buffer
,ptype_list
*clock
)
187 chain_list
*temp_expr
;
188 chain_list
*temp_support
;
190 iprint(fp
,'i',"%s%d: PROCESS (",head
,np
);
191 temp_expr
= createExpr(OR
);
192 for(biablx
= biabl
; biablx
; biablx
= biablx
->NEXT
)
195 addQExpr(temp_expr
,copyExpr(biablx
->CNDABL
));
197 beh_toolbug(19,"print_process_declaration",name
,0);
199 addQExpr(temp_expr
,copyExpr(biablx
->VALABL
));
201 beh_toolbug(20,"print_process_declaration",name
,0);
203 sprintf(*buffer
,"%d",np
);
204 temp_support
= supportChain_listExpr(temp_expr
);
205 writelist(fp
, temp_support
, 14 + strlen(*buffer
));
207 freechain(temp_support
);
213 /*}}}************************************************************************/
214 /*{{{ Process driving */
215 /****************************************************************************/
216 static void print_procBegin(FILE *fp
, chain_list
*loopchain
)
219 iprint(fp
,'i',"BEGIN\n");
222 static void print_procEnd(FILE *fp
)
224 iprint(fp
,'-',"END PROCESS;\n");
227 static void print_procIf(FILE *fp
, char *buffer
)
229 iprint(fp
,'+',"IF %s THEN\n",bvl_printabl(buffer
));
232 static void print_procElsif(FILE *fp
, char *buffer
)
234 iprint(fp
,'+',"ELSIF %s THEN\n",bvl_printabl(buffer
));
237 static int print_procElse(FILE *fp
)
239 iprint(fp
,'+',"ELSE\n");
244 static int print_procEndif(FILE *fp
, char ind
)
246 iprint(fp
,ind
,"END IF;\n");
251 static int print_edge(char *buffer
, char *ckname
, char ckstate
,
254 sprintf(buffer
,"(%s = '%c' and %s'EVENT)",ckname
,ckstate
,signame
);
259 /*}}}************************************************************************/
260 /*{{{ Ports driving */
263 /****************************************************************************/
265 static void port_begin(FILE *fp
)
267 iprint(fp
,'+',"PORT (\n");
270 static void port_end(FILE *fp
)
273 iprint(fp
,'<',");\n");
276 /*}}}************************************************************************/
277 /*{{{ print_endLoop() */
280 /****************************************************************************/
281 static void print_endLoop(FILE *fp
,char indent
,char *head
,int np
,int cpt
,
282 int nbsame
,loop_list
*loop
)
290 ind
= BVL_LOOP_IND
[-- BVL_CPT_IND
];
291 iprint(fp
,indent
,"END LOOP %s%dLOOP%d;\n", head
, np
, ind
);
294 print_endLoop(fp
,indent
,head
,np
,cpt
,nbsame
-1,loop
->NEXT
);
298 /*}}}************************************************************************/
299 /*{{{ print_loopList() */
302 /****************************************************************************/
303 static void print_loopList(FILE *fp
,char indent
,char *head
,int np
,int *cpt
,
304 int nbsame
,loop_list
*loop
)
309 print_loop(fp
,indent
,head
,np
,cpt
,loop
);
310 print_loopList(fp
,indent
,head
,np
,cpt
,nbsame
- 1,loop
->NEXT
);
314 /*}}}************************************************************************/
315 /*{{{ print_loop() */
318 /****************************************************************************/
319 static void print_loop(FILE *fp
,char indent
,char *head
,int np
,int *cpt
,
325 name
= loop
->VARNAME
;
328 iprint(fp
, indent
, "%s%dLOOP%d : FOR %s IN %d %s %d LOOP\n",
329 head
, np
, *cpt
, name
, left
, (left
> right
)?"DOWNTO":"TO", right
);
330 BVL_LOOP_IND
[BVL_CPT_IND
++] = *cpt
;
334 /*}}}************************************************************************/
335 /*{{{ print_withselect() */
338 /****************************************************************************/
339 void print_withselect(FILE *fp
, biabl_list
*biabl
, char *name
, int vectsize
,
340 char **buffer
, int *bufsize
)
346 *buffer
= bvl_abl2str(biabl
->CNDABL
,*buffer
,bufsize
);
347 iprint(fp
,'i',"WITH %s SELECT\n",bvl_printabl(*buffer
));
348 iprint(fp
,'+',"%s <=\n",name
);
350 for (;biabl
;biabl
=biabl
->NEXT
, cpt
++)
352 if (biabl
->VALABL
== NULL
)
353 beh_toolbug(20,"print_withselect",name
,0);
356 *buffer
= bvl_abl2str(biabl
->VALABL
,*buffer
,bufsize
);
357 iprint (fp
,0,"%s",bvl_printabl(*buffer
));
358 print_time(fp
,biabl
->TIME
,0,0);
359 if (biabl
->FLAG
&BEH_CND_SEL_OTHERS
)
360 fprintf(fp
," WHEN OTHERS");
361 else if (biabl
->FLAG
&BEH_CND_SELECT
)
362 fprintf(fp
," WHEN %s",vhd_getBitStr(beh_getcndvectfbiabl(biabl
),buf
));
363 else beh_toolbug(19, "print_withselect", name
, 0);
367 else if (!(biabl
->FLAG
&BEH_CND_SEL_OTHERS
))
371 fprintHZBitStr(fp
,genHZBitStr(vectsize
));
372 fprintf(fp
," WHEN OTHERS;\n");
379 /*}}}************************************************************************/
380 /*{{{ print_value() */
383 /****************************************************************************/
384 void print_value(FILE *fp
, chain_list
*abl
, char type
, int time
, int timer
, int timef
,
385 char **buffer
, int *bufsize
)
395 abl
= beg_compactAbl(copyExpr(abl
));
396 *buffer
= bvl_abl2str(abl
,*buffer
,bufsize
);
400 *buffer
= bvl_abl2str(abl
,*buffer
,bufsize
);
401 fprintf(fp
,"%s",bvl_printabl(*buffer
));
402 print_time(fp
,time
,0,0);
409 /*}}}************************************************************************/
410 /*{{{ print_affected() */
413 /****************************************************************************/
414 static void print_affected(FILE *fp
, char indent
, char type
, int time
,int timer
, int timef
,
415 char *name
, char *vname
, loop_list
*loop
,long specialflags
)
418 iprint(fp
,indent
,"%s <= ",bvl_vectorize(name
));
419 else if (loop
&& loop
->INDEX
)
420 iprint(fp
,indent
,"%s (%s) <= ",name
,loop
->INDEX
);
422 iprint(fp
,indent
,"%s <= ",vname
);
428 static char *bvl_vectorize_sub(char *name
, char *buf
)
430 strcpy(buf
, bvl_vectorize(name
));
434 /*}}}************************************************************************/
435 /*{{{ print_signal() */
438 /****************************************************************************/
439 static void print_signal(FILE *fp
, char *name
, char type
, int left
, int right
)
449 iprint(fp
,'d',"SIGNAL %s : ",bvl_vhdlname(name
));
457 fprintf(fp
,"STD_LOGIC_VECTOR (%d %s %d);\n",left
,way
,right
);
460 fprintf(fp
,"STD_LOGIC;\n");
467 /*}}}************************************************************************/
471 /****************************************************************************/
472 static void print_por(FILE *fp
, char *name
, char dir
, int left
, int right
)
481 case 'O' : case 'Z' :
484 case 'B' : case 'T' :
491 iprint(fp
,'d',"%s : %-5s ",bvl_vhdlname(name
),mode
);
500 fprintf(fp
,"STD_LOGIC_VECTOR (%d %s %d)",left
,way
,right
);
503 fprintf(fp
,"STD_LOGIC");
506 /*}}}************************************************************************/
510 /****************************************************************************/
511 static void print_interassign(FILE *fp
, char *dest
, char *src
, int mode
)
520 /*}}}************************************************************************/
521 /*}}}************************************************************************/
522 /*}}}************************************************************************/
523 /*{{{ Traitement de la begen */
524 /****************************************************************************/
525 /*{{{ begen_treatment() */
528 /****************************************************************************/
530 begen_treatment(FILE *fp
, befig_list
*figure
)
539 iprint(fp
,'+',"GENERIC (\n");
541 for (gen
= figure
->BEGEN
; gen
->NEXT
; gen
= gen
->NEXT
)
542 iprint(fp
,'0',"CONSTANT %s : %s := %ld ;\t-- %s\n",
543 gen
->NAME
,gen
->TYPE
,*((long *)gen
->VALUE
),gen
->NAME
);
545 iprint(fp
,'-',"CONSTANT %s : %s := %ld \t-- %s\n",
546 gen
->NAME
,gen
->TYPE
,*((long *)gen
->VALUE
),gen
->NAME
);
547 iprint(fp
,'-',"); \n");
551 /*}}}************************************************************************/
552 /*}}}************************************************************************/
553 /*{{{ Traitement des messages */
554 /****************************************************************************/
558 /****************************************************************************/
559 void print_msg(FILE *fp
, befig_list
*figure
, char **buffer
, int *bufsize
)
561 // int bufsize = 512;
563 bemsg_list
*msg
; /* current BEMSG pointer */
565 chain_list
*ptcondabl
;
567 // buffer = mbkalloc(bufsize);
569 for (iprint(fp
,'i',"\n"), msg
= figure
->BEMSG
; msg
; msg
= msg
->NEXT
)
580 iprint(fp
,'+',"%s : ASSERT (",msg
->LABEL
);
582 iprint(fp
,'+',"ASSERT (");
585 if ((isedge
= bef_search_stable(msg
->ABL
,&clock
)))
587 char ckstate
, *ckname
;
590 ckname
= bvl_vhdlname(clock
);
591 ckstate
= (bef_search_notck(msg
->ABL
,clock
) > 0) ? '0' : '1';
592 attrib
= bef_get_stable_attribute(msg
->ABL
,&clock
);
594 sprintf(*buffer
,"%s = '%c' and not %s'STABLE(%d %s)",
595 ckname
,ckstate
,ckname
,attrib
,TIME_UNIT
);
597 sprintf(*buffer
,"%s = '%c' and %s'EVENT",ckname
,ckstate
,ckname
);
599 ptcondabl
= bef_strip_ckedge(msg
->ABL
,clock
);
600 sndckcnd
= ( ! ( ATOM(ptcondabl
) &&
601 ! ( strcmp (VALUE_ATOM (ptcondabl
), "'1'") &&
602 strcmp (VALUE_ATOM (ptcondabl
), "'0'"))));
604 (void) fprintf(fp
,"%s and ",bvl_printabl(*buffer
));
606 (void) fprintf(fp
,"%s",bvl_printabl(*buffer
));
611 abl_red
= bef_preprocess_abl(ptcondabl
);
619 *buffer
= bvl_abl2strbool(abl_red
,*buffer
,bufsize
);
620 (void) fprintf(fp
,"%s",bvl_printabl(*buffer
));
624 (void) fprintf(fp
,")\n");
627 iprint(fp
,'+',"REPORT %s\n",msg
->MESSAGE
);
628 if (msg
->LEVEL
== 'W')
629 iprint(fp
,'-',"SEVERITY WARNING;\n");
631 iprint(fp
,'-',"SEVERITY ERROR;\n");
636 /*}}}************************************************************************/
637 /*{{{ vhd_initDriver() */
640 /****************************************************************************/
641 void vhd_initDriver(bef_driver
*driver
, FILE *fp
, befig_list
*fig
, ht
*porht
,
642 char **buffer
, int *bufsize
)
644 bef_driverSet(driver
,fp
,fig
,buffer
,bufsize
,
654 bef_driverSetAbl(driver
,
656 bef_driverSetProcess(driver
,
658 print_process_declaration
,
666 bef_driverSetStr(driver
,
668 beh_buildvhdvectname
,
673 bef_driverSetPor(driver
,
681 /*}}}************************************************************************/
682 /*}}}************************************************************************/
683 /*{{{ Function de drive */
684 /****************************************************************************/
685 /*{{{ vhdsavebefig() */
687 /* description : print out a text file containing a data-flow VHDL */
689 /****************************************************************************/
691 vhdsavebefig(befig_list
*pthedbefig
, unsigned int trace_mode
)
700 BVL_VECT_ASS
= (int)(long)getenv("DRI_VECT_ASS");
702 if (pthedbefig
== NULL
)
703 beh_toolbug(10, "vhdsavebefig", NULL
, 0);
705 suffix
= V_STR_TAB
[__BVL_FILE_SUFFIX
].VALUE
;
706 if (suffix
== NULL
) suffix
= namealloc("vhd");
708 /* ###------------------------------------------------------### */
709 /* Opening result file */
710 /* ###------------------------------------------------------### */
712 if (!(fp
= mbkfopen(bvl_vhdlname(pthedbefig
->NAME
),suffix
,WRITE_TEXT
)))
714 beh_error(107, NULL
);
718 vhdportht
= addht(40);
721 buffer
= mbkalloc(bufsize
);
722 vhd_initDriver(&driver
,fp
,pthedbefig
,vhdportht
,&buffer
,&bufsize
);
724 if ((trace_mode
& BVL_TRACE
) != 0)
725 (void) fprintf(stdout
, "Saving '%s' in a vhdl file (vhd)\n",
728 sprintf(buffer
,"VHDL data flow description generated from `%s`\n",
730 avt_printExecInfo(fp
, "--", buffer
, "");
732 (void) fprintf(fp
, "library IEEE;\nuse IEEE.std_logic_1164.all;\n\n");
734 /* ###------------------------------------------------------### */
735 /* Entity declaration */
736 /* ###------------------------------------------------------### */
738 iprint(fp
,'i',"-- Entity Declaration\n\n");
739 iprint(fp
,'i',"ENTITY %s IS\n",bvl_vhdlname(pthedbefig
->NAME
));
741 /* ###------------------------------------------------------### */
742 /* begen declaration */
743 /* ###------------------------------------------------------### */
745 begen_treatment(fp
, pthedbefig
);
747 /* ###------------------------------------------------------### */
748 /* Port declaration */
749 /* ###------------------------------------------------------### */
751 bef_drive_porDeclaration(&driver
);
753 iprint(fp
,'i',"END %s;\n\n", bvl_vhdlname(pthedbefig
->NAME
));
755 /* ###------------------------------------------------------### */
756 /* Architecture declaration */
757 /* ###------------------------------------------------------### */
759 iprint(fp
,'i',"-- Architecture Declaration\n\n");
760 iprint(fp
,'i',"ARCHITECTURE RTL OF %s IS\n",bvl_vhdlname(pthedbefig
->NAME
));
762 /* ###------------------------------------------------------### */
763 /* Signals declaration */
764 /* ###------------------------------------------------------### */
766 bef_drive_sigDeclaration(&driver
);
771 (void) fprintf(fp
, "\nBEGIN\n");
773 TIME_UNIT
= bef_gettimeunit(pthedbefig
->TIME_UNIT
);
775 /* ###------------------------------------------------------### */
776 /* Print out a concurrent assert statement for each BEMSG */
777 /* ###------------------------------------------------------### */
779 print_msg(fp
,pthedbefig
,&buffer
,&bufsize
);
781 bef_drive_aux(&driver
);
782 bef_drive_reg(&driver
);
783 bef_drive_bux(&driver
);
784 bef_drive_bus(&driver
);
785 bef_drive_out(&driver
);
787 (void) fprintf(fp
, "\nEND;\n");
790 if (V_BOOL_TAB
[__API_DRIVE_CORRESP
].VALUE
)
791 bvl_drivecorresp(pthedbefig
->NAME
, pthedbefig
, 0);
797 /*}}}************************************************************************/
798 /*}}}************************************************************************/
800 /****************************************************************************/
801 /*{{{ print_one_bebus() */
804 /****************************************************************************/
805 void print_one_bebus(FILE *fp
, bebus_list
*bus
, int *numprocess
)
812 buffer
= mbkalloc(bufsize
);
813 vhd_initDriver(&driver
,fp
,NULL
,NULL
,&buffer
,&bufsize
);
815 bef_print_one_beobj(&driver
,bus
,numprocess
,BEG_TYPE_SINGBUS
);
819 /*}}}************************************************************************/
820 /*{{{ print_one_bebux() */
823 /****************************************************************************/
824 void print_one_bebux(FILE *fp
, bebux_list
*bux
, int *numprocess
)
831 buffer
= mbkalloc(bufsize
);
832 vhd_initDriver(&driver
,fp
,NULL
,NULL
,&buffer
,&bufsize
);
834 bef_print_one_beobj(&driver
,bux
,numprocess
,BEG_TYPE_SINGBUX
);
838 /*}}}************************************************************************/
839 /*{{{ print_one_bereg() */
841 /* exploit priority encoding */
842 /****************************************************************************/
843 void print_one_bereg(FILE *fp
, bereg_list
*reg
, int *numprocess
)
850 buffer
= mbkalloc(bufsize
);
851 vhd_initDriver(&driver
,fp
,NULL
,NULL
,&buffer
,&bufsize
);
853 bef_print_one_beobj(&driver
,reg
,numprocess
,BEG_TYPE_SINGREG
);
857 /*}}}************************************************************************/
858 /*{{{ print_one_beaux() */
861 /****************************************************************************/
862 void print_one_beaux(FILE *fp
, beaux_list
*aux
)
869 buffer
= mbkalloc(bufsize
);
870 vhd_initDriver(&driver
,fp
,NULL
,NULL
,&buffer
,&bufsize
);
872 bef_print_one_beobj(&driver
, aux
, NULL
, BEG_TYPE_SINGAUX
);
876 /*}}}************************************************************************/
877 /*{{{ print_one_bevectaux() */
880 /****************************************************************************/
881 void print_one_bevectaux(FILE *fp
, bevectaux_list
*vaux
)
888 buffer
= mbkalloc(bufsize
);
889 vhd_initDriver(&driver
,fp
,NULL
,NULL
,&buffer
,&bufsize
);
891 bef_print_one_beobj(&driver
, vaux
, NULL
, BEG_TYPE_VECTAUX
);
895 /*}}}************************************************************************/
896 /*{{{ print_one_beout() */
898 /* affectation des signaux beout */
899 /****************************************************************************/
900 void print_one_beout(FILE *fp
, beout_list
*out
)
907 buffer
= mbkalloc(bufsize
);
908 vhd_initDriver(&driver
,fp
,NULL
,NULL
,&buffer
,&bufsize
);
910 bef_print_one_beobj(&driver
, out
, NULL
, BEG_TYPE_SINGOUT
);
914 /*}}}************************************************************************/
915 /*{{{ print_one_bevectout() */
918 /****************************************************************************/
919 void print_one_bevectout(FILE *fp
, bevectout_list
*vout
)
926 buffer
= mbkalloc(bufsize
);
927 vhd_initDriver(&driver
,fp
,NULL
,NULL
,&buffer
,&bufsize
);
929 bef_print_one_beobj(&driver
, vout
, NULL
, BEG_TYPE_VECTOUT
);
933 /*}}}************************************************************************/
934 /*}}}************************************************************************/