source: vis_dev/vis-2.3/src/io/io.y

Last change on this file was 14, checked in by cecile, 15 years ago

vis2.3

File size: 13.8 KB
Line 
1%{
2/**CFile***********************************************************************
3
4 FileName [io.y]
5
6 PackageName [io]
7
8 Synopsis [Yacc file for the BLIF-MV parser.]
9
10 Description []
11
12 SeeAlso []
13
14 Author [Yuji Kukimoto, Rajeev Ranjan, Huey-Yih Wang]
15
16 Copyright [Copyright (c) 1994-1996 The Regents of the Univ. of California.
17 All rights reserved.
18
19 Permission is hereby granted, without written agreement and without license
20 or royalty fees, to use, copy, modify, and distribute this software and its
21 documentation for any purpose, provided that the above copyright notice and
22 the following two paragraphs appear in all copies of this software.
23
24 IN NO EVENT SHALL THE UNIVERSITY OF CALIFORNIA BE LIABLE TO ANY PARTY FOR
25 DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT
26 OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF THE UNIVERSITY OF
27 CALIFORNIA HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
29 THE UNIVERSITY OF CALIFORNIA SPECIFICALLY DISCLAIMS ANY WARRANTIES,
30 INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
31 FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS ON AN
32 "AS IS" BASIS, AND THE UNIVERSITY OF CALIFORNIA HAS NO OBLIGATION TO PROVIDE
33 MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.]
34
35******************************************************************************/
36
37#include "ioInt.h"
38
39/*
40 * The following is a workaround for a bug in bison, which generates code
41 * that uses alloca(). Their lengthy sequence of #ifdefs for defining
42 * alloca() does the wrong thing for HPUX (it should do what is defined below)
43 */
44#ifdef __hpux
45# include <alloca.h>
46#endif
47
48static char rcsid[] UNUSED = "$Id: io.y,v 1.11 2010/04/09 23:32:13 fabio Exp $";
49
50/*---------------------------------------------------------------------------*/
51/* Constant declarations */
52/*---------------------------------------------------------------------------*/
53
54
55/*---------------------------------------------------------------------------*/
56/* Stucture declarations */
57/*---------------------------------------------------------------------------*/
58
59
60/*---------------------------------------------------------------------------*/
61/* Type declarations */
62/*---------------------------------------------------------------------------*/
63
64
65/*---------------------------------------------------------------------------*/
66/* Variable declarations */
67/*---------------------------------------------------------------------------*/
68int globalLineNumber;
69Hrc_Manager_t *globalYaccHmgr;
70Hrc_Model_t *globalModel;
71Hrc_Node_t *globalHnode;
72Hrc_Model_t *globalFirstModel;
73Hrc_Model_t *globalRootModel;
74char *globalRootInstanceName;
75array_t *globalMvNameArray;
76array_t *globalSymValueArray;
77array_t *globalTableInputArray;
78array_t *globalTableOutputArray;
79array_t *globalTableDefaultArray;
80array_t *globalTableSymCubeArray;
81array_t *globalFormalNameArray;
82array_t *globalActualNameArray;
83array_t *globalSubcktArray;
84array_t *globalResetArray;
85st_table *globalParserResetInfo;
86st_table *globalParserSubcktInfo;
87array_t *globalNewModelArray;
88
89/*---------------------------------------------------------------------------*/
90/* Macro declarations */
91/*---------------------------------------------------------------------------*/
92
93
94/**AutomaticStart*************************************************************/
95
96/*---------------------------------------------------------------------------*/
97/* Static function prototypes */
98/*---------------------------------------------------------------------------*/
99
100/**AutomaticEnd***************************************************************/
101
102
103/*---------------------------------------------------------------------------*/
104/* Definition of exported functions */
105/*---------------------------------------------------------------------------*/
106
107
108/*---------------------------------------------------------------------------*/
109/* Definition of internal functions */
110/*---------------------------------------------------------------------------*/
111
112
113/*---------------------------------------------------------------------------*/
114/* Definition of static functions */
115/*---------------------------------------------------------------------------*/
116
117#include "ioLex.c"
118
119static void
120IoYyerror(char *string)
121{
122 (void)fprintf(vis_stderr,"%s",error_string());
123 (void)fprintf(vis_stderr,"%s in line %d with token %s\n",string,globalLineNumber,IoYytext);
124 fflush(vis_stderr);
125}
126
127%}
128
129/* %token YYERROR_VERBOSE */
130
131%token MODEL END INPUTS OUTPUTS MV LATCH RESET NAMES DEFAULT SUBCKT ROOT
132%token IDENTIFIER ARROW ASSIGN NEWLINE
133
134%union {
135 char *string;
136 int integer;
137 IoSymValue_t *IoSymValue_t_ptr;
138 array_t *array_t_ptr;
139}
140
141%type <string> name;
142%type <integer> range;
143%type <IoSymValue_t_ptr> sym_value sym_value_without_assign basic_sym_value;
144%type <array_t_ptr> sub_sym_value;
145
146%start models
147
148%%
149
150models:
151 model
152 | models model
153 | models error {
154 IoError();
155 }
156 ;
157model:
158 model_start model_content model_end
159 ;
160model_start:
161 MODEL name NEWLINE {
162 if ( Hrc_ManagerFindModelByName(globalYaccHmgr,$2) ){
163 error_append("Model ");
164 error_append($2);
165 error_append(" is multiply-defined\n");
166 FREE($2);
167 IoError();
168 }
169 globalModel = Hrc_ModelAlloc(globalYaccHmgr,$2);
170 globalHnode = Hrc_ModelReadMasterNode(globalModel);
171 if ( globalFirstModel == NIL(Hrc_Model_t) )
172 globalFirstModel = globalModel;
173 FREE($2);
174 array_insert_last(Hrc_Model_t *,globalNewModelArray,globalModel);
175 }
176 option_root
177 ;
178option_root:
179 /* empty */
180 | ROOT NEWLINE {
181 if ( globalRootModel != NIL(Hrc_Model_t) ){
182 error_append("Two models ");
183 error_append(Hrc_ModelReadName(globalRootModel));
184 error_append(" and ");
185 error_append(Hrc_ModelReadName(globalModel));
186 error_append(" are defined as the root model\n");
187 IoError();
188 }
189 globalRootModel = globalModel;
190 }
191 | ROOT name NEWLINE {
192 if ( globalRootModel != NIL(Hrc_Model_t) ){
193 error_append("Two models ");
194 error_append(Hrc_ModelReadName(globalRootModel));
195 error_append(" and ");
196 error_append(Hrc_ModelReadName(globalModel));
197 error_append(" are defined as the root model\n");
198 IoError();
199 }
200 globalRootModel = globalModel;
201 globalRootInstanceName = $2;
202 }
203 ;
204model_end:
205 END NEWLINE {
206 if (st_is_member(globalParserResetInfo,(char *)globalModel) == 1){
207 error_append("Model ");
208 error_append(Hrc_ModelReadName(globalModel));
209 error_append(" is multiply-defined.\n");
210 IoError();
211 }
212 /* the following st_insert should return 0 */
213 (void)st_insert(globalParserResetInfo,(char *)globalModel,(char *)globalResetArray);
214 if (st_is_member(globalParserSubcktInfo,(char *)globalModel) == 1){
215 error_append("Model ");
216 error_append(Hrc_ModelReadName(globalModel));
217 error_append(" is multiply-defined.\n");
218 IoError();
219 }
220 /* the following st_insert should return 0 */
221 (void)st_insert(globalParserSubcktInfo,(char *)globalModel,(char *)globalSubcktArray);
222 globalResetArray = NIL(array_t);
223 globalSubcktArray = NIL(array_t);
224 globalModel = NIL(Hrc_Model_t);
225 globalHnode = NIL(Hrc_Node_t);
226 }
227 ;
228model_content:
229 /* empty */
230 | model_content command
231 ;
232command:
233 input
234 | output
235 | mv
236 | latch
237 | table
238 | reset
239 | subckt
240 ;
241input:
242 INPUTS input_names NEWLINE
243 ;
244input_names:
245 /* empty */
246 | input_names input_name
247 ;
248input_name:
249 name {
250 if (IoInputProcess(globalHnode,$1) == 0){
251 error_append("Input ");
252 error_append($1);
253 error_append(" is multiply defined.\n");
254 FREE($1);
255 IoError();
256 }
257 FREE($1);
258 }
259 ;
260output:
261 OUTPUTS output_names NEWLINE
262 ;
263output_names:
264 /* empty */
265 | output_names output_name
266 ;
267output_name:
268 name {
269 if (IoOutputProcess(globalHnode,$1) == 0){
270 error_append("Output ");
271 error_append($1);
272 error_append(" is multiply defined.\n");
273 FREE($1);
274 IoError();
275 }
276 FREE($1);
277 }
278 ;
279mv:
280 MV mv_names range NEWLINE {
281 if (IoMvProcess(globalModel,globalHnode,globalMvNameArray,$3,NIL(array_t)) == 0){
282 IoStringArrayFree(globalMvNameArray);
283 IoError();
284 }
285 IoStringArrayFree(globalMvNameArray);
286 globalMvNameArray = NIL(array_t);
287 }
288 | MV mv_names range val_names NEWLINE {
289 if (IoMvProcess(globalModel,globalHnode,globalMvNameArray,$3,globalSymValueArray) == 0){
290 IoStringArrayFree(globalMvNameArray);
291 IoStringArrayFree(globalSymValueArray);
292 IoError();
293 }
294 IoStringArrayFree(globalMvNameArray);
295 IoStringArrayFree(globalSymValueArray);
296 globalMvNameArray = NIL(array_t);
297 globalSymValueArray = NIL(array_t);
298 }
299 ;
300mv_names:
301 mv_name
302 | mv_names ',' mv_name
303 ;
304mv_name:
305 name {
306 IoNameInsertInArray(&globalMvNameArray,$1);
307 }
308 ;
309range:
310 name {
311 $$ = IoAtoi($1);
312 FREE($1);
313 }
314 ;
315val_names:
316 val_name
317 | val_names val_name
318 ;
319val_name:
320 name {
321 IoNameInsertInArray(&globalSymValueArray,$1);
322 }
323 ;
324latch:
325 LATCH name name NEWLINE {
326 if (IoLatchProcess(globalModel,globalHnode,$2,$3) == 0){
327 IoError();
328 FREE($2);
329 FREE($3);
330 }
331 FREE($2);
332 FREE($3);
333 }
334 ;
335
336
337reset:
338 RESET table_io_names NEWLINE option_default table_content {
339 if (IoResetProcess(&globalResetArray,globalModel,globalHnode,globalTableInputArray,globalTableOutputArray,globalTableDefaultArray,globalTableSymCubeArray) == 0){
340 IoError();
341 }
342 globalTableInputArray = NIL(array_t);
343 globalTableOutputArray = NIL(array_t);
344 globalTableDefaultArray = NIL(array_t);
345 globalTableSymCubeArray = NIL(array_t);
346 }
347 ;
348table:
349 NAMES table_io_names NEWLINE option_default table_content {
350 if (IoTableProcess(globalModel,globalHnode, globalTableInputArray,globalTableOutputArray,globalTableDefaultArray,globalTableSymCubeArray) == 0){
351 IoError();
352 }
353 globalTableInputArray = NIL(array_t);
354 globalTableOutputArray = NIL(array_t);
355 globalTableDefaultArray = NIL(array_t);
356 globalTableSymCubeArray = NIL(array_t);
357 }
358 ;
359table_io_names:
360 table_input_names ARROW table_output_names
361 | table_input_names table_output_name
362 ;
363table_input_names:
364 /* empty */
365 | table_input_names table_input_name
366 ;
367table_input_name:
368 name {
369 IoNameInsertInArray(&globalTableInputArray,$1);
370 }
371 ;
372table_output_names:
373 table_output_name
374 | table_output_names table_output_name
375 ;
376table_output_name:
377 name {
378 IoNameInsertInArray(&globalTableOutputArray,$1);
379 }
380 ;
381option_default:
382 /* empty */
383 | DEFAULT def_values NEWLINE
384 ;
385def_values:
386 def_value
387 | def_values def_value
388 ;
389def_value:
390 sym_value {
391 IoSymValueInsertInArray(&globalTableDefaultArray,$1);
392 }
393 ;
394sym_values:
395 sym_value {
396 IoSymValueInsertInArray(&globalSymValueArray,$1);
397 }
398 | sym_values sym_value {
399 IoSymValueInsertInArray(&globalSymValueArray,$2);
400 }
401 ;
402sym_value:
403 basic_sym_value
404 | ASSIGN name {
405 IoSymValue_t *entry;
406 entry = IoSymValueAlloc();
407 entry->left = (IoSymValue_t *)$2;
408 entry->flag = IoAssign_c;
409 $$ = entry;
410 }
411 | '(' sub_sym_value ')' {
412 IoSymValue_t *entry;
413 entry = IoSymValueAlloc();
414 entry->elements = $2;
415 entry->flag = IoList_c;
416 $$ = entry;
417 }
418 | '!' sym_value_without_assign {
419 IoSymValue_t *entry;
420 entry = IoSymValueAlloc();
421 entry->left = $2;
422 entry->flag = IoComplement_c;
423 $$ = entry;
424 }
425 ;
426sym_value_without_assign:
427 basic_sym_value
428 | '(' sub_sym_value ')' {
429 IoSymValue_t *entry;
430 entry = IoSymValueAlloc();
431 entry->elements = $2;
432 entry->flag = IoList_c;
433 $$ = entry;
434 }
435 | '!' sym_value_without_assign {
436 IoSymValue_t *entry;
437 entry = IoSymValueAlloc();
438 entry->left = $2;
439 entry->flag = IoComplement_c;
440 $$ = entry;
441 }
442 ;
443basic_sym_value:
444 '-' {
445 IoSymValue_t *entry;
446 entry = IoSymValueAlloc();
447 entry->flag = IoUniverse_c;
448 $$ = entry;
449 }
450 | name {
451 IoSymValue_t *entry;
452 entry = IoSymValueAlloc();
453 entry->flag = IoLeaf_c;
454 entry->left = (IoSymValue_t *)$1;
455 $$ = entry;
456 }
457 | '{' name '-' name '}' {
458 IoSymValue_t *entry;
459 entry = IoSymValueAlloc();
460 entry->left = (IoSymValue_t *)$2;
461 entry->right = (IoSymValue_t *)$4;
462 entry->flag = IoRange_c;
463 $$ = entry;
464 }
465 ;
466sub_sym_value:
467 sym_value_without_assign {
468 array_t *array;
469 array = array_alloc(IoSymValue_t *,0);
470 array_insert_last(IoSymValue_t *,array,$1);
471 $$ = array;
472 }
473 | sub_sym_value ',' sym_value_without_assign {
474 array_insert_last(IoSymValue_t *,$1,$3);
475 }
476 ;
477table_content: /* must have at least one row */
478 /* empty */
479 /*
480 sym_values NEWLINE {
481 IoSymCubeInsertInArray(&globalTableSymCubeArray,globalSymValueArray);
482 globalSymValueArray = NIL(array_t);
483 }
484 */
485 | table_content sym_values NEWLINE {
486 IoSymCubeInsertInArray(&globalTableSymCubeArray,globalSymValueArray);
487 globalSymValueArray = NIL(array_t);
488 }
489 ;
490
491subckt:
492 SUBCKT name name connections NEWLINE {
493 if (IoSubcktProcess(&globalSubcktArray,globalModel,globalHnode,$2,$3,globalFormalNameArray,globalActualNameArray) == 0 ){
494 IoError();
495 }
496 globalFormalNameArray = NIL(array_t);
497 globalActualNameArray = NIL(array_t);
498 }
499 ;
500connections:
501 connection
502 | connections connection
503 ;
504connection:
505 name ASSIGN name {
506 IoNameInsertInArray(&globalFormalNameArray,$1);
507 IoNameInsertInArray(&globalActualNameArray,$3);
508 }
509 ;
510name:
511 IDENTIFIER {
512 $$ = util_strsav(IoYytext);
513 }
514 ;
515
516%%
517
Note: See TracBrowser for help on using the repository browser.