-
Notifications
You must be signed in to change notification settings - Fork 0
/
parser.mly
407 lines (336 loc) · 6.72 KB
/
parser.mly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
// (* $Id: parser.mly,v 1.28 2003/07/01 00:19:56 vaibhav Exp $ *)
%{
open Ass
open Ast
open Codegen
%}
/* File parser.mly */
%token TokModel TokEnd TokRoot
%token TokInputs TokOutputs
%token TokMV TokTable TokDef TokReset TokLatch
%token TokEOL TokEOF
%token TokTabDef
%token <string> TokTabVal
%token <string> TokVal
%token <string> TokTabVar
%token TokTabEnd
%token TokSubckt
%token <string> TokVar
%token TokNo
%token COMMA ARROW HYPHEN ASSIGN LPAREN RPAREN LBRACE RBRACE NOT
%start start1
%type <unit> start1
%start main
%type <unit> main
%%
/*
* Very Informal Documentation
* BlifMV ::= model
* model ::= Inputs Outputs Commands
*/
/* 1st parser is start1 */
start1:
models1 TokEOF { (*print_string("parse1\n"); print_all_models();*)}
;
models1:
model1 models1 {}
| {}
;
model1:
head1 decl1 body1 TokEnd TokEOL
{ add_model_to_modelTab ();
add_subcktTab ();
clear_all_list ();
}
;
head1:
TokModel TokVar TokEOL
{ set_module_name ($2);
}
;
decl1:
vdecl1 {}
| {}
;
vdecl1:
vdecl1 input1{}
| input1 {}
| vdecl1 output1{}
| output1 {}
;
input1:
TokInputs iovals1 TokEOL
{ add_i_list ($2); }
;
output1:
TokOutputs iovals1 TokEOL
{ add_o_list ($2); }
;
iovals1:
TokVar iovals1 {List.append [$1] ($2)}
| TokVar {[$1]}
;
body1:
/*(* TokNo body {}*): Give lexical error*/
table1 body1 {}
| subckt1 body1 {}
| mv1 body1 {}
| reset1 body1 {}
| latch1 body1 {}
| {}
;
/*Handling tables*/
table1:
TokTable tabvars1 TokEOL relations1 {}
;
/*Handling MV*/
mv1:
TokMV mvvars1 TokVal values1 TokEOL
{}
;
mvvars1:
TokVar COMMA mvvars1 {}
| TokVar {}
values1:
TokVar values1 {}
|TokVal values1 {}
| {}
;
/*Handling Resets*/
reset1:
TokReset tabvars1 TokEOL relations1 {}
;
/*Handling Subckt*/
subckt1:
TokSubckt TokVar TokVar param_passing1 TokEOL
{make_subckt ($2) ($3) ($4);
add_sckt_list ($2);}
;
param_passing1:
formal_actual1 param_passing1 {make_pair_list ($1) ($2)}
| {(List.combine [] [])}
;
formal_actual1:
TokVar ASSIGN TokVar
{ (List.combine [$1] [$3])}
;
/*Handling Latches*/
latch1:
TokLatch TokVar TokVar TokEOL { }
;
/*Table and Reset Latch Handlers*/
tabvars1:
inList1 ARROW outList1 { }
| TokTabVar inList1 { }
| TokTabVar { }
;
inList1:
TokTabVar inList1 {}
| TokTabVar {}
| {} //(*FIXME not sure*)
;
outList1:
TokTabVar outList1 {}
| TokTabVar {}
;
relations1:
vdefault relations1 { }
| relation1 relations1 {}
| {}
;
vdefault1:
TokTabDef valList1 TokEOL {}
;
relation1:
valList1 TokEOL {}
;
valList1:
valb1 valList1 { }
| valb1 { }
;
valb1:
TokTabVal {}
| TokTabVar {}
| ASSIGN TokTabVar {}
| HYPHEN {}
| LBRACE TokTabVal HYPHEN TokTabVal RBRACE {}
| LPAREN vals1 RPAREN {}
| NOT valb1 {}
;
vals1:
TokTabVal COMMA vals1 {}
| TokTabVal {}
;
/* second parser */
main:
models TokEOF
{ print_string("parse2\n");
emit_license();
emit_all_subckts();
exit 0
}
;
models:
model models {}
| {}
;
model:
head decl body TokEnd TokEOL
{ add_hidelist();
emit_module_name ();
emit_io_stmts (); clear_io_list ();
emit_private_vars();
emit_atoms();
emit_module_end ();
(*add_subcktTab ();*)
clear_subckt();
}
;
head:
TokModel TokVar TokEOL
{ clear_all_list ();
set_module_name ($2);
(*to take care of type gadbad*) }
;
decl:
vdecl {}
| {}
;
vdecl:
vdecl input{}
| input {}
| vdecl output{}
| output {}
;
input:
TokInputs iovals TokEOL
{ add_i_list ($2); List.iter add_i_sym_tab ($2) }
;
output:
TokOutputs iovals TokEOL
{ add_o_list ($2); List.iter add_o_sym_tab ($2) }
;
iovals:
TokVar iovals {List.append [$1] ($2)}
| TokVar {[$1]}
;
body:
/*(* TokNo body {}*): Give lexical error*/
table body {}
| subckt body {}
| mv body {}
| reset body {}
| latch body {}
| {}
;
/*Handling tables*/
table:
TokTable tabvars TokEOL relations
{
add_tableatom_to_symTab ();
clear_relations ();
clear_inout_list ();
}
;
/*Handling MV*/
mv:
TokMV mvvars TokVal values TokEOL
{
let add_in a =
match ($4) with
[]-> add_sym_tab a (MvRange(int_of_string($3)))
| _ ->
if (List.length ($4) == int_of_string($3)) then
add_sym_tab a (Mv([$3]@($4)))
else
raise (Failure (a ^" has unmatched number of values"));
in
List.iter add_in ($2)
}
;
mvvars:
TokVar COMMA mvvars {List.append [$1] ($3)}
| TokVar {[$1]}
values:
TokVar values {List.append [$1] ($2)}
| TokVal values {List.append [$1] ($2)}
| {[]}
;
/*Handling Resets*/
reset:
TokReset tabvars TokEOL relations
{ add_resetatom_to_symTab ();
clear_relations ();
clear_inout_list ();
}
;
/*Handling Subckt*/
subckt:
TokSubckt TokVar TokVar param_passing TokEOL
{ io_analysis ($2) ($3) ($4);
make_subckt ($2) ($3) ($4) ;}
;
param_passing:
formal_actual param_passing {make_pair_list ($1) ($2)}
| {(List.combine [] [])}
;
formal_actual:
TokVar ASSIGN TokVar
{ (*interface_analysis ($3);*) (List.combine [$1] [$3]);}
;
/*Handling Latches*/
latch:
TokLatch TokVar TokVar TokEOL
{ add_sym_tab ($2) (Bool);add_sym_tab ($3) (Bool);
add_latchatom_to_symTab ($2) ($3);
}
;
/*Table and Reset Latch Handlers*/
tabvars:
inList ARROW outList { add_in_list ($1);
add_out_list ($3)}
| TokTabVar inList
{ add_sym_tab ($1) (Bool);
add_in_list ([$1]@( List.rev (List.tl (List.rev $2))));
add_out_list ([(List.hd (List.rev ($2)) )])
}
| TokTabVar { add_sym_tab ($1) (Bool); add_out_list ([$1]); }
;
inList:
TokTabVar inList {add_sym_tab ($1) (Bool); List.append [$1] ($2)}
| TokTabVar {add_sym_tab ($1) (Bool); [$1]}
| {[]} //(*FIXME not sure*)
;
outList:
TokTabVar outList {add_sym_tab ($1) (Bool); List.append [$1] ($2) }
| TokTabVar {add_sym_tab ($1) (Bool); [$1]}
;
relations:
vdefault relations { add_def_relation (); }
| relation relations { add_relation ($1); }
| {}
;
vdefault:
TokTabDef valList TokEOL { make_def_relation ($2) }
;
relation:
valList TokEOL { ($1) }
;
valList:
valb valList { ([$1]@($2)) }
| valb { [$1] }
;
valb:
TokTabVal { Cmp(($1)) }
| TokTabVar { Cmp(($1)) }
| ASSIGN TokTabVar {(*check it in io*) Cmp(($2)^"'") }
| HYPHEN { Hyp }
| LBRACE TokTabVal HYPHEN TokTabVal RBRACE { Range(($2),($4)) }
| LPAREN vals RPAREN { Set(($2)) }
| NOT valb { Not(($2)) }
;
vals:
TokTabVal COMMA vals {([$1]@($3))}
| TokTabVal {([$1])}
;
%%