1 /****************************************************************************/
3 /* Chaine de CAO & VLSI Alliance */
5 /* Produit : GENIUS v1.00 */
6 /* Fichier : gen_library_parser.yac */
8 /* (c) copyright 1999 Laboratoire MASI equipe CAO & VLSI */
9 /* Tous droits reserves */
10 /* Support : e-mail alliance-support@asim.lip6.fr */
12 /* Auteur(s) : Francois DONNET le : 04/05/1999 */
14 /* Modifie par : le : ../../.... */
15 /* Modifie par : le : ../../.... */
16 /* Modifie par : le : ../../.... */
18 /****************************************************************************/
30 #define API_HIDE_TOKENS
33 #define yytext gen_library_parsertext
34 #define yyin gen_library_parserin
40 static char *PATH; /*path for files*/
41 static char *file, *subfig, *bbox; /*name of the library*/
42 static int order, format, keep, addaction, paramset;
43 /* syntax error schedule */
44 extern int yylex(); /* parse ahead (by step of one char)*/
45 extern int lineno_library; /* line number to give user's information */
46 extern char *yytext; /* current parsed string */
47 extern FILE *yyin; /* flow for LEX */
48 static inline int yyerror(); /* display error message */
49 static void forceexit();
52 static lib_entry *put_inlist_warn(char *elem, lib_entry *liste, int warn);
53 lib_entry *TakeDependancies(char *elem, lib_entry *liste);
54 static lib_entry *head;
69 %type <name> file_name
70 %type <le> files_list template files_list_sub .rule. .actions.
71 %type <chain_l> .define.
74 %token _STOP _YES _NO _KEEP _FORMAT _PRIORITY _VHDL _SPICE _RULE _ACTIONS
75 %token <string> _IDENT
76 %token <integer> _DIGIT
80 /****************************************************************************/
81 /* A library file can contain several model files */
82 /****************************************************************************/
85 files_list { head=$1; }
90 file_name {order=lineno_library; format=keep=0; bbox=subfig=NULL;} .params.ka. ';' {$$=put_inlist_warn($1,NULL, 1);}
92 '{' file_name '}' {order=lineno_library; format=keep=0; bbox=subfig=NULL;} .params.ka. ';'
96 sprintf(temp, "%s/%s", getdistpath_2(temp2), $2);
97 $$=put_inlist_warn(temp,NULL, 1);
102 files_list file_name {order=lineno_library; format=keep=0; bbox=subfig=NULL; } .params.ka. ';' {$$=put_inlist_warn($2,$1, 1);}
104 files_list template { $$=(lib_entry *)append((chain_list *)$1, (chain_list *)$2); }
106 files_list '{' file_name '}' {order=lineno_library; format=keep=0; bbox=subfig=NULL;} .params.ka. ';'
110 sprintf(temp, "%s/%s", getdistpath_2(temp2), $3);
111 $$=put_inlist_warn(temp,$1, 1);
116 _IDENT _IDENT '{' .rule. .actions. .define. '}' {order=-1; format=keep=-1; bbox=subfig=NULL; } .params.ka. ';'
119 lib_entry *le, *lepack;
122 for (le=$4; le!=NULL; le=le->NEXT)
124 if (keep!=-1) le->keep=keep;
125 if (order!=-1) le->priority=order;
126 le->model=namealloc($1);
131 if (order==-1) order=lineno_library;
132 if (keep==-1) keep=0;
134 sprintf(temp,"%s.vhd", $1);
135 $4=put_inlist_warn(temp,NULL, 1);
136 $4->model=namealloc($1);
141 order=lineno_library; format=keep=0;
142 sprintf(temp,"%s.c", $1);
143 $5=put_inlist_warn(temp,NULL, 1);
146 lepack=(lib_entry *)append((chain_list *)$4, (chain_list *)$5);
148 cl=addchain($6, create_adt($1, $2));
149 for (le=lepack; le!=NULL; le=le->NEXT)
154 le->paramset=dup_adt_list(cl);
155 if (gen_find_template_corresp(NULL, le->paramset, "exec_function", temp)==0)
157 if (strcmp(temp,"exec_function")!=0)
158 le->model=namealloc(temp);
168 _RULE '=' '{' files_list_sub '}' { $$=$4; }
170 _RULE '=' file_name {order=lineno_library; format=keep=0; bbox=subfig=NULL;} .params.ka. ';' {$$=put_inlist_warn($3, NULL, 1);}
176 _ACTIONS '=' '{' files_list_sub '}' { $$=$4; }
178 _ACTIONS '=' file_name {order=lineno_library; format=keep=0; bbox=subfig=NULL;} .params.ka. ';' {$$=put_inlist_warn($3, NULL, 1);}
184 files_list_sub file_name {order=lineno_library; format=keep=0; bbox=subfig=NULL;} .params.ka. ';' {$$=put_inlist_warn($2, $1, 1);}
186 file_name {order=lineno_library; format=keep=0; bbox=subfig=NULL;} .params.ka. ';' {$$=put_inlist_warn($1, NULL, 1);}
192 $$=addchain(NULL, create_adt($1, $3));
197 .define. ',' _IDENT '=' _IDENT
199 $$=addchain($1, create_adt($3, $5));
215 .order. .more.params.
227 if (strcasecmp($1,"priority")==0) order =INT_MIN+$3;
228 else { yyerror(); YYABORT; }
234 if (strcasecmp($1,"format")==0)
236 if (strcasecmp($3, "spice")==0) format = 1;
237 else if (strcasecmp($3, "vhdl")==0) format = 0;
238 else if (strcasecmp($3, "spice_hr")==0) format = 2;
239 else { yyerror(); YYABORT; }
241 else if (strcasecmp($1,"keep")==0)
243 if (strcasecmp($3, "yes")==0) keep = 1;
244 else if (strcasecmp($3, "no")==0) keep = 0;
245 else { yyerror(); YYABORT; }
247 else if (strcasecmp($1,"subfigure")==0)
249 subfig=mbkstrdup($3);
251 else if (strcasecmp($1,"match")==0)
256 { yyerror(); YYABORT; }
263 '(' _VHDL ')' { addaction=1; }
268 file_name '.' _IDENT { sprintf($$,"%s.%s",$1,$3); mbkfree($3); }
270 file_name '/' _IDENT { sprintf($$,"%s/%s",$1,$3); mbkfree($3); }
275 // sprintf($$,"%s%s",PATH,$1);
277 /*char *name = (char*)mbkalloc(strlen(PATH)+strlen($1)+1);
278 name=strcpy(name, PATH);
279 name=strcat(name, $1);
286 sprintf($$, "/%s", $2);
287 // sprintf($$,"%s%s",PATH,$1);
297 /****************************************************************************/
298 /* user's message for syntaxical error */
299 /****************************************************************************/
300 static inline int yyerror()
302 switch ((int)yychar) {
304 fprintf(stderr,"%s:%d: unexpected end of file\n",file,lineno_library);
307 fprintf(stderr,"%s:%d: syntax error happened at '%s'\n",file,lineno_library,yytext);
311 return lineno_library;
316 /****************************************************************************/
317 /* return the liste sorted by its order contained in TYPE field */
318 /* the first(or with the lowest digit) in first place in the list */
319 /****************************************************************************/
320 static lib_entry* sort_by_order(lib_entry *liste)
322 int current_priority;
323 lib_entry *p,*q,*pred,*first,*ret;
325 if (!liste) return NULL;
328 current_priority=liste->priority;
331 for (p=liste;p;p=p->NEXT) {
332 if (p->priority<current_priority) {
333 current_priority=p->priority;
339 if (!pred) {/*first in liste to put on first place*/
340 ret=sort_by_order(liste->NEXT);
344 else {/*an another than the first*/
346 pred->NEXT=first->NEXT; /*put over the first*/
347 ret=sort_by_order(liste);
353 /****************************************************************************/
355 /* return list of model files sorted by order:first as the highest priority */
356 /* if number is attached the lowest digit for the highest priority */
357 /****************************************************************************/
358 lib_entry *APIReadLibrary(char *library, char *path, FILE *debug)
361 if (!library || !path) {
362 fprintf(stderr,"Read_All: NULL pointer\n");
366 PATH=path; /* var. glob */
367 file=library; /*var. glob. */
368 /* model file exists? */
369 if (!(yyin = mbkfopen(library, NULL, READ_TEXT))) {
370 fprintf(stderr, "Cannot open library file %s (error n°%d)\n",
375 fprintf(debug, "Opening library file %s....\n",library);
381 res= sort_by_order(res);
386 fprintf(debug, "%s Closed\n",library);
392 /****************************************************************************/
394 /****************************************************************************/
395 static lib_entry *put_inlist_warn(char *elem, lib_entry *liste, int warn)
400 fprintf(stderr,"put_inlist_warn: NULL pointer\n");
404 // sprintf(temp,"%s%s",path, elem);
406 for (le=liste;le!=NULL;le=le->NEXT)
408 if (warn && !strcmp(le->name,elem))
410 fprintf(stderr,"%s:%d: %s named several times. this one is ignored\n",file,lineno_library-1,elem);
415 le1=(lib_entry *)mbkalloc(sizeof(lib_entry));
417 le1->name=mbkstrdup(elem);
418 le1->subfigurename=subfig;
432 le=(lib_entry *)mbkalloc(sizeof(lib_entry));
433 le->name=mbkstrdup(elem);
434 le->subfigurename=subfig;
449 /****************************************************************************/
450 /*************************** END of LEX&YACC ********************************/
451 /****************************************************************************/
453 void APIFreeLibrary(lib_entry *le)
460 if (le->subfigurename!=NULL) free(le->subfigurename);
461 if (le->match!=NULL) free(le->match);
462 free_adt_list(le->paramset);