-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathverilog.yapp
1963 lines (1573 loc) · 93.8 KB
/
verilog.yapp
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
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
%{
use VP3::Lexer;
use VP3::ParseTree;
# Shortcut to VP3::ParseTree::factory for use in semantic actions
*f = \&VP3::ParseTree::factory;
sub null { f ("null"); }
sub list
{
$_[0]->append_children ($_[1]);
# returns $_[0]
}
sub list_delim
{
$_[2]->prepend_text ($_[1]);
$_[0]->append_children ($_[2]);
# returns $_[0]
}
sub scope
{
if ($_[1]) {
$_[0]->YYData->{scope} = $_[1];
} else {
$_[0]->YYData->{scope};
}
}
sub decl
{
my ($self, $obj) = @_;
$obj->can ("decls") or VP3::fatal ("Don't know how to add object of type " . $obj->type . " to symbol table");
my %decls = $obj->decls;
while (my ($k, $v) = each %decls) {
$self->scope->symtab->insert ($k => $v);
}
$obj;
}
sub binop
{
$_[4]->prepend_text ($_[3]);
f ("binary_operator_expression", @_[1,2,4]);
}
sub drive_strength
{
$_[2]->prepend_text ($_[1]);
$_[2]->append_text ($_[3]);
$_[4]->append_text ($_[5]);
f ("drive_strength", @_[2,4]);
}
sub charge_strength
{
$_[2]->prepend_text ($_[1]);
$_[2]->append_text ($_[3]);
f ("charge_strength", $_[2]);
}
sub default_yyerror
{
my ($p) = @_;
$p->YYData->{error} = "Parse error at " . $p->YYCurtok . " on line " . $p->YYCurval->line;
$p->YYAbort;
};
%}
# 2005 spec has best info on operator precedence
# add {} and {{}} here?
%right '?' ':'
%left '||'
%left '&&'
%left '|'
%left '^' '^~' '~^'
%left '&'
%left '==' '!=' '===' '!=='
%left '<' '<=' '>' '>='
%left '<<' '>>' '<<<' '>>>'
%left '+' '-'
%left '*' '/' '%'
%left '**'
# Shift/reduce conflict in rule "conditional_statement"
# Shift/reduce conflict in rule "generate_conditional_statement"
%expect 2
%start vp3_parse_start
%%
# General-use grammar items not part of spec
opt_arguments: { null }
| '(' expressions ')' { $_[2]->prepend_text ($_[1])->append_text ($_[3]) }
;
opt_reg: { null }
| 'reg'
;
opt_signed: { null }
| 'signed'
;
opt_automatic: { null }
| 'automatic'
;
opt_expression: { null }
| expression
;
opt_bracket_expression: { null }
| bracket_expression
;
bracket_expression: '[' expression ']' { $_[2]->prepend_text ($_[1])->append_text ($_[3]); f ("subscripts", $_[2]) }
;
bracket_expressions: bracket_expression { $_[1] }
| bracket_expressions bracket_expression { $_[1]->append_children ($_[2]) }
;
subscripts: bracket_expressions { $_[1] }
| bracket_expressions '[' range_expression_colon ']' { $_[3]->prepend_text ($_[2])->append_text ($_[4]); $_[1]->append_children ($_[3]) }
| '[' range_expression_colon ']' { $_[2]->prepend_text ($_[1])->append_text ($_[3]); f ("subscripts", $_[2]) }
;
pip: port_identifier ')' { $_[1]->append_text ($_[2]) }
;
pics: pic { f ("list_of_port_identifiers", $_[1]) }
| pics pic { $_[1]->append_children ($_[2]) }
;
pic: port_identifier ',' { $_[1]->append_text ($_[2]) }
;
vpip: variable_port_identifier ')' { $_[1]->append_text ($_[2]) }
;
vpics: vpic { f ("list_of_variable_port_identifiers", $_[1]) }
| vpics vpic { $_[1]->append_children ($_[2]) }
;
vpic: variable_port_identifier ',' { $_[1]->append_text ($_[2]) }
;
# 1.1 Library source text
# (not supported)
# 1.2 Configuration source text
# (not supported)
# 1.3 Module and primitive source text
source_text: { f ("source_text") }
| module_none_declaration { f ("source_text", $_[1]) }
| descriptions
;
descriptions: description { f ("source_text", $_[1]) }
| descriptions description { $_[1]->append_children ($_[2]) }
;
description: module_declaration
| udp_declaration
;
# Artificial, to avoid reduce/reduce conflict between the two module syntaxes
module_preamble: attr # 1
module_keyword # 2
module_identifier # 3
{
$_[2]->prepend_text ($_[1]);
my $obj = f ("module_declaration", @_[2,3]);
$_[0]->scope ($obj);
$obj;
} # 4
opt_module_parameter_port_list # 5
{
$_[4]->append_children ($_[5]);
$_[4];
}
;
noport_module_header: module_preamble ';' # 1,2
{
$_[1]->append_text ($_[2]);
$_[1]->append_children (null); # port list
}
;
# !!! should be "list_of_ports" (complex ports syntax)
traditional_module_header: module_preamble # 1
'(' list_of_port_identifiers ')' ';' # 2,3,4,5
{
$_[3]->prepend_text ($_[2]);
$_[3]->append_text ($_[4]);
$_[3]->append_text ($_[5]);
$_[1]->append_children ($_[3]);
}
;
v2k_module_header: module_preamble # 1
'(' list_of_port_declarations ';' # 2,3,4
{
$_[3]->prepend_text ($_[2]);
$_[3]->append_text ($_[4]);
$_[1]->append_children ($_[3]);
}
;
# Note that the *_module_header versions all ultimately use the module_preamble
# rule, and accept an attribute, while vp3_module_directive does not accept an
# attribute. (To specify attributes in that case, use the -attr option to the
# @Module directive.)
module_declaration: traditional_module_header # 1
opt_module_items # 2
'endmodule' # 3
{
$_[0]->scope (undef);
$_[1]->append_children (@_[2,3]);
}
| v2k_module_header # 1
opt_non_port_module_items # 2
'endmodule' # 3
{
$_[0]->scope (undef);
$_[1]->append_children (@_[2,3]);
}
| noport_module_header # 1
opt_non_port_module_items # 2
'endmodule' # 3
{
$_[0]->scope (undef);
$_[1]->append_children (@_[2,3]);
}
| vp3_module_directive # 1
{
my $obj = f ("vp3_module_declaration", $_[1]);
$_[0]->scope ($obj);
$obj;
} # 2
opt_module_items # 3
'endmodule' # 4
{
$_[0]->scope (undef);
$_[2]->append_children (@_[3,4]);
}
;
module_none_declaration:
vp3_module_directive # 1
{
my $obj = f ("vp3_module_declaration", $_[1]);
$_[0]->scope ($obj);
$obj;
} # 2
VP3_PARSE_MODE_MODULE_NONE # 3
opt_module_items # 4
{
$_[0]->scope (undef);
$_[2]->append_children ($_[4], null);
}
;
module_keyword: 'module' | 'macromodule' ;
# 1.4 Module parameters and ports
# !!! list_of_ports, port, port_expression, port_reference (complex ports syntax)
pdp_parameter_declarations: pdp_parameter_declaration { f ("list_of_parameter_declarations", $_[1]) }
| pdc_parameter_declarations pdp_parameter_declaration { $_[1]->append_children ($_[2]) }
;
pdc_parameter_declarations: pdc_parameter_declaration { f ("list_of_parameter_declarations", $_[1]) }
| pdc_parameter_declarations pdc_parameter_declaration { $_[1]->append_children ($_[2]) }
;
opt_module_parameter_port_list: { null }
| module_parameter_port_list
;
module_parameter_port_list: '#' '(' pdp_parameter_declarations { $_[3]->prepend_text ($_[2])->prepend_text ($_[1]); $_[3] }
;
list_of_port_declarations: ')' { f ("list_of_port_declarations", "")->append_text ($_[1]) }
| pip_port_declaration { f ("list_of_port_declarations", $_[1]) }
| pic_port_declarations pip_port_declaration { $_[1]->append_children ($_[2]) }
;
pip_port_declaration: attr pip_inout_declaration { $_[2]->prepend_text ($_[1]) }
| attr pip_input_declaration { $_[2]->prepend_text ($_[1]) }
| attr pip_output_declaration { $_[2]->prepend_text ($_[1]) }
;
pic_port_declarations: pic_port_declaration { f ("list_of_port_declarations", $_[1]) }
| pic_port_declarations pic_port_declaration { $_[1]->append_children ($_[2]) }
;
pic_port_declaration: attr pic_inout_declaration { $_[2]->prepend_text ($_[1]) }
| attr pic_input_declaration { $_[2]->prepend_text ($_[1]) }
| attr pic_output_declaration { $_[2]->prepend_text ($_[1]) }
;
port_declaration: attr inout_declaration { $_[2]->prepend_text ($_[1]) }
| attr input_declaration { $_[2]->prepend_text ($_[1]) }
| attr output_declaration { $_[2]->prepend_text ($_[1]) }
;
# 1.5 Module items
opt_module_items: { null }
| module_items
;
module_items: module_item { f ("module_items", $_[1]) }
| module_items module_item { list (@_[1..$#_]) }
;
module_item: port_declaration ';' { $_[1]->append_text ($_[2]) }
| non_port_module_item
;
# !!! gate_instantiation, udp_instantiation
module_or_generate_item: attr module_or_generate_item_declaration { $_[2]->prepend_text ($_[1]) }
| attr parameter_override { $_[2]->prepend_text ($_[1]) }
| attr continuous_assign { $_[2]->prepend_text ($_[1]) }
| attr module_instantiation { $_[2]->prepend_text ($_[1]) }
| attr initial_construct { $_[2]->prepend_text ($_[1]) }
| attr always_construct { $_[2]->prepend_text ($_[1]) }
| vp3_module_item
;
module_or_generate_item_declaration: net_declaration
| reg_declaration
| integer_declaration
| real_declaration
| time_declaration
| realtime_declaration
| event_declaration
| genvar_declaration
| task_declaration
| function_declaration
;
opt_non_port_module_items: { null }
| non_port_module_items
;
non_port_module_items: non_port_module_item { VP3::ParseTree->factory ("module_items", $_[1]) }
| non_port_module_items non_port_module_item { $_[1]->append_children ($_[2]) }
;
# The spec has a semicolon after parameter_declaration and
# local_parameter_declaration here. We consume the semicolon within the rules
# for shift/reduce conflict avoidance.
non_port_module_item: module_or_generate_item
| specify_block
| generated_instantiation
| attr local_parameter_declaration { $_[2]->prepend_text ($_[1]) }
| attr pds_parameter_declaration { $_[2]->prepend_text ($_[1]) }
| attr specparam_declaration { $_[2]->prepend_text ($_[1]) }
;
parameter_override: 'defparam' list_of_defparam_assignments ';' { $_[2]->prepend_text ($_[1])->append_text ($_[3]); f ("parameter_override", $_[2]) }
;
# 2 Declarations
# 2.1 Declaration types
# 2.1.1 Module parameter declarations
# Perhaps these could be consolidated somehow?
local_parameter_declaration: 'localparam' # 1
opt_signed # 2
opt_range # 3
pas_param_assignments # 4
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "localparam", @_[2,3,4]));
}
| 'localparam' # 1
parameter_type # 2
pas_param_assignments # 3
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "localparam", $_[2], null, $_[3]));
}
;
# PDC = Parameter Declaration + Comma
# PDP = Parameter Declaration + (close) Paren
# PDS = Parameter Declaration + Semicolon
# For shift/reduce conflict avoidance, similar to the port list case explained in 2.1.2.
pdc_parameter_declaration: 'parameter' # 1
opt_signed # 2
opt_range # 3
pac_param_assignments # 4
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "parameter", @_[2,3,4]));
}
| 'parameter' # 1
parameter_type # 2
pac_param_assignments # 3
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "parameter", $_[2], null, $_[3]));
}
;
pdp_parameter_declaration: 'parameter' # 1
opt_signed # 2
opt_range # 3
pap_param_assignments # 4
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "parameter", @_[2,3,4]));
}
| 'parameter' # 1
parameter_type # 2
pap_param_assignments # 3
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "parameter", $_[2], null, $_[3]));
}
;
pds_parameter_declaration: 'parameter' # 1
opt_signed # 2
opt_range # 3
pas_param_assignments # 4
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "parameter", @_[2,3,4]));
}
| 'parameter' # 1
parameter_type # 2
pas_param_assignments # 3
{
$_[2]->prepend_text ($_[1]);
$_[0]->decl (f ("parameter_declaration", "parameter", $_[2], null, $_[3]));
}
;
specparam_declaration: 'specparam' opt_range list_of_specparam_assignments ';' { $_[2]->prepend_text ($_[1]);
$_[3]->append_text ($_[4]);
f ("specparam_declaration", @_[2,3]) }
;
parameter_type: 'integer' | 'real' | 'realtime' | 'time';
# 2.1.2 Port declarations
# PIC = Port Identifier + Comma. PIP = Port Identifer + (close) Paren
# Needed to avoid Shift/Reduce conflict parsing ANSI C-style module headers.
# "output a, b, input c". When the parser has consumed "b" and is looking ahead
# at the comma, it doesn't know whether the token after the comma is another
# identifier (in which case it should shift) or a port type keyword (in which
# case it should reduce).
# Used for inputs and inouts
input_type: opt_signed opt_range { f ("input_type", null , $_[1], $_[2]) }
| net_type opt_signed opt_range { f ("input_type", $_[1], $_[2], $_[3]) }
;
pip_input_declaration: 'input' input_type pip
{
$_[3] = f ("list_of_port_identifiers", $_[3]);
$_[0]->decl (f ("input_declaration", @_[1..3]));
}
| 'input' input_type pics pip
{
$_[3]->append_children ($_[4]);
$_[0]->decl (f ("input_declaration", @_[1..3]));
}
;
pic_input_declaration: 'input' input_type pics { $_[0]->decl (f ("input_declaration", @_[1..$#_])); }
;
input_declaration: 'input' input_type list_of_port_identifiers { $_[0]->decl (f ("input_declaration", @_[1..$#_])) }
;
pip_inout_declaration: 'inout' input_type pip
{
$_[3] = f ("list_of_port_identifiers", $_[3]);
$_[0]->decl (f ("inout_declaration", @_[1..3]));
}
| 'inout' input_type pics pip
{
$_[3]->append_children ($_[4]);
$_[0]->decl (f ("inout_declaration", @_[1..3]));
}
;
pic_inout_declaration: 'inout' input_type pics { $_[0]->decl (f ("inout_declaration", @_[1..$#_])); }
;
inout_declaration: 'inout' input_type list_of_port_identifiers { $_[0]->decl (f ("inout_declaration", @_[1..$#_])) }
;
output_net_type: opt_signed opt_range { f ("output_type", null , $_[1], $_[2]) }
| net_type opt_signed opt_range { f ("output_type", $_[1], $_[2], $_[3]) }
;
output_var_type: 'reg' opt_signed opt_range { f ("output_type", $_[1], $_[2], $_[3]) }
| 'integer' { f ("output_type", $_[1], null , null ) }
| 'time' { f ("output_type", $_[1], null , null ) }
;
pip_output_declaration: 'output' output_net_type pip
{
$_[3] = f ("list_of_port_identifiers", $_[3]);
$_[0]->decl (f ("output_declaration", @_[1..3]));
}
| 'output' output_var_type vpip
{
$_[3] = f ("list_of_variable_port_identifiers", $_[3]);
$_[0]->decl (f ("output_declaration", @_[1..3]));
}
| 'output' output_net_type pics pip
{
$_[3]->append_children ($_[4]);
$_[0]->decl (f ("output_declaration", @_[1..3]));
}
| 'output' output_var_type vpics vpip
{
$_[3]->append_children ($_[4]);
$_[0]->decl (f ("output_declaration", @_[1..3]));
}
;
pic_output_declaration: 'output' output_net_type pics { $_[0]->decl (f ("output_declaration", @_[1..$#_])) }
| 'output' output_var_type vpics { $_[0]->decl (f ("output_declaration", @_[1..$#_])) }
;
output_declaration: 'output' output_net_type list_of_port_identifiers { $_[0]->decl (f ("output_declaration", @_[1..$#_])) }
| 'output' output_var_type list_of_variable_port_identifiers { $_[0]->decl (f ("output_declaration", @_[1..$#_])) }
;
# 2.1.3 Type declarations
event_declaration: 'event' list_of_event_identifiers ';' { $_[2]->prepend_text ($_[1])->append_text ($_[3]);
$_[0]->decl (f ("event_declaration", $_[2])) }
;
genvar_declaration: 'genvar' list_of_genvar_identifiers ';'
{
$_[2]->prepend_text ($_[1]);
$_[2]->append_text ($_[3]);
$_[0]->decl (f ("genvar_declaration", $_[2]))
}
;
integer_declaration: 'integer' list_of_variable_identifiers ';' { $_[2]->prepend_text ($_[1])->append_text ($_[3]);
$_[0]->decl (f ("integer_declaration", $_[2])) }
;
vectored_or_scalared: 'vectored'
| 'scalared'
;
net_declaration: net_type opt_signed opt_delay3 list_of_net_identifiers ';' { $_[4]->append_text ($_[5]); $_[0]->decl (f ("net_declaration", $_[1], null, null, $_[2], null, $_[3], $_[4])); }
| net_type opt_signed opt_delay3 list_of_net_decl_assignments ';' { $_[4]->append_text ($_[5]); $_[0]->decl (f ("net_declaration", $_[1], null, null, $_[2], null, $_[3], $_[4])); }
| net_type drive_strength opt_signed opt_delay3 list_of_net_decl_assignments ';' { $_[5]->append_text ($_[6]); $_[0]->decl (f ("net_declaration", $_[1], $_[2], null, $_[3], null, $_[4], $_[5])); }
| net_type opt_signed range opt_delay3 list_of_net_identifiers ';' { $_[5]->append_text ($_[6]); $_[0]->decl (f ("net_declaration", $_[1], null, null, $_[2], $_[3], $_[4], $_[5])); }
| net_type vectored_or_scalared opt_signed range opt_delay3 list_of_net_identifiers ';' { $_[6]->append_text ($_[7]); $_[0]->decl (f ("net_declaration", $_[1], null, $_[2], $_[3], $_[4], $_[5], $_[6])); }
| net_type opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[5]->append_text ($_[6]); $_[0]->decl (f ("net_declaration", $_[1], null, null, $_[2], $_[3], $_[4], $_[5])); }
| net_type drive_strength opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[6]->append_text ($_[7]); $_[0]->decl (f ("net_declaration", $_[1], $_[2], null, $_[3], $_[4], $_[5], $_[6])); }
| net_type vectored_or_scalared opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[6]->append_text ($_[7]); $_[0]->decl (f ("net_declaration", $_[1], null, $_[2], $_[3], $_[4], $_[5], $_[6])); }
| net_type drive_strength vectored_or_scalared opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[7]->append_text ($_[8]); $_[0]->decl (f ("net_declaration", $_[1], $_[2], $_[3], $_[4], $_[5], $_[6], $_[7])); }
| 'trireg' opt_signed opt_delay3 list_of_net_identifiers ';' { $_[2]->prepend_text ($_[1]); $_[4]->append_text ($_[5]); $_[0]->decl (f ("trireg_declaration", null, null, null, $_[2], null, $_[3], $_[4])) }
| 'trireg' charge_strength opt_signed opt_delay3 list_of_net_identifiers ';' { $_[2]->prepend_text ($_[1]); $_[5]->append_text ($_[6]); $_[0]->decl (f ("trireg_declaration", null, $_[2], null, $_[3], null, $_[4], $_[5])) }
| 'trireg' opt_signed opt_delay3 list_of_net_decl_assignments ';' { $_[2]->prepend_text ($_[1]); $_[4]->append_text ($_[5]); $_[0]->decl (f ("trireg_declaration", null, null, null, $_[2], null, $_[3], $_[4])) }
| 'trireg' drive_strength opt_signed opt_delay3 list_of_net_decl_assignments ';' { $_[2]->prepend_text ($_[1]); $_[5]->append_text ($_[6]); $_[0]->decl (f ("trireg_declaration", $_[2], null, null, $_[3], null, $_[4], $_[5])) }
| 'trireg' opt_signed range opt_delay3 list_of_net_identifiers ';' { $_[2]->prepend_text ($_[1]); $_[5]->append_text ($_[6]); $_[0]->decl (f ("trireg_declaration", null, null, null, $_[2], $_[3], $_[4], $_[5])) }
| 'trireg' charge_strength opt_signed range opt_delay3 list_of_net_identifiers ';' { $_[2]->prepend_text ($_[1]); $_[6]->append_text ($_[7]); $_[0]->decl (f ("trireg_declaration", null, $_[2], null, $_[3], $_[4], $_[5], $_[6])) }
| 'trireg' vectored_or_scalared opt_signed range opt_delay3 list_of_net_identifiers ';' { $_[2]->prepend_text ($_[1]); $_[6]->append_text ($_[7]); $_[0]->decl (f ("trireg_declaration", null, null, $_[2], $_[3], $_[4], $_[5], $_[6])) }
| 'trireg' charge_strength vectored_or_scalared opt_signed range opt_delay3 list_of_net_identifiers ';' { $_[2]->prepend_text ($_[1]); $_[7]->append_text ($_[8]); $_[0]->decl (f ("trireg_declaration", null, $_[2], $_[3], $_[4], $_[5], $_[6], $_[7])) }
| 'trireg' opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[2]->prepend_text ($_[1]); $_[5]->append_text ($_[6]); $_[0]->decl (f ("trireg_declaration", null, null, null, $_[2], $_[3], $_[4], $_[5])) }
| 'trireg' drive_strength opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[2]->prepend_text ($_[1]); $_[6]->append_text ($_[7]); $_[0]->decl (f ("trireg_declaration", $_[2], null, null, $_[3], $_[4], $_[5], $_[6])) }
| 'trireg' vectored_or_scalared opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[2]->prepend_text ($_[1]); $_[6]->append_text ($_[7]); $_[0]->decl (f ("trireg_declaration", null, null, $_[2], $_[3], $_[4], $_[5], $_[6])) }
| 'trireg' drive_strength vectored_or_scalared opt_signed range opt_delay3 list_of_net_decl_assignments ';' { $_[2]->prepend_text ($_[1]); $_[7]->append_text ($_[8]); $_[0]->decl (f ("trireg_declaration", $_[2], null, $_[3], $_[4], $_[5], $_[6], $_[7])) }
;
real_declaration: 'real' list_of_real_identifiers ';'
{
$_[2]->prepend_text ($_[1]);
$_[2]->append_text ($_[3]);
$_[0]->decl (f ("real_declaration", $_[2]))
}
;
realtime_declaration: 'realtime' list_of_real_identifiers ';'
{
$_[2]->prepend_text ($_[1]);
$_[2]->append_text ($_[3]);
$_[0]->decl (f ("realtime_declaration", $_[2]))
}
;
reg_declaration: 'reg' opt_signed opt_range list_of_variable_identifiers ';'
{
$_[2]->prepend_text ($_[1]);
$_[4]->append_text ($_[5]);
$_[0]->decl (f ("reg_declaration", @_[2,3,4]));;
}
;
time_declaration: 'time' list_of_variable_identifiers ';'
{
$_[2]->prepend_text ($_[1]);
$_[2]->append_text ($_[3]);
$_[0]->decl (f ("time_declaration", $_[2]))
}
;
# 2.2 Declaration data types
# 2.2.1 Net and variable types
net_type: 'supply0' | 'supply1' | 'tri' | 'triand' | 'trior' | 'tri0' | 'tri1' | 'wire' | 'wand' | 'wor';
# output_variable_type replaced by slightly different output_var_type, defined in 2.1.2
opt_constant_assignment: { null }
| '=' constant_expression { $_[2]->prepend_text ($_[1]) }
;
real_type: real_identifier opt_constant_assignment { f ("real_type", @_[1..$#_]) }
| real_identifier dimensions { f ("real_type", @_[1..$#_]) }
;
variable_type: variable_identifier opt_constant_assignment { f ("variable_type", @_[1..$#_]) }
| variable_identifier dimensions { f ("variable_type", @_[1..$#_]) }
;
# 2.2.2 Strengths
opt_drive_strength: { null }
| drive_strength
;
drive_strength: '(' strength0 ',' strength1 ')' { drive_strength (@_) }
| '(' strength1 ',' strength0 ')' { drive_strength (@_) }
| '(' strength0 ',' 'highz1' ')' { drive_strength (@_) }
| '(' strength1 ',' 'highz0' ')' { drive_strength (@_) }
| '(' 'highz0' ',' strength1 ')' { drive_strength (@_) }
| '(' 'highz1' ',' strength0 ')' { drive_strength (@_) }
;
strength0: 'supply0' | 'strong0' | 'pull0' | 'weak0'
;
strength1: 'supply1' | 'strong1' | 'pull1' | 'weak1'
;
#opt_charge_strength: { null }
# | charge_strength
# ;
charge_strength: '(' 'small' ')' { charge_strength (@_) }
| '(' 'medium' ')' { charge_strength (@_) }
| '(' 'large' ')' { charge_strength (@_) }
;
# 2.2.3 Delays
opt_delay3: { null }
| delay3
;
delay3: '#' delay_value { $_[2]->prepend_text ($_[1]); f ("delay", $_[2]) }
| '#' '(' mintypmax_expression ')' { $_[3]->prepend_text ($_[2])->prepend_text ($_[1]); $_[3]->append_text ($_[4]); f ("delay", $_[3] ) }
| '#' '(' mintypmax_expression ',' mintypmax_expression ')' { $_[3]->prepend_text ($_[2])->prepend_text ($_[1]); $_[3]->append_text ($_[4]); $_[5]->append_text ($_[6]); f ("delay", @_[3,5] ) }
| '#' '(' mintypmax_expression ',' mintypmax_expression ',' mintypmax_expression ')' { $_[3]->prepend_text ($_[2])->prepend_text ($_[1]); $_[3]->append_text ($_[4]); $_[5]->append_text ($_[6]); $_[7]->append_text ($_[8]); f ("delay", @_[3,5,7]) }
;
# Used by gate_instantiation (3.1), udp_instantiation (5.4)
#opt_delay2: { null }
# | delay2
# ;
#
#delay2: '#' delay_value
# | '#' '(' mintypmax_expression ')'
# | '#' '(' mintypmax_expression ',' mintypmax_expression ')'
# ;
delay_value: UNSIGNED_NUMBER
| real_number
| IDENTIFIER
;
# 2.3 Declaration lists
list_of_defparam_assignments: defparam_assignment { f ("list_of_defparam_assignments", $_[1]) }
| list_of_defparam_assignments ',' defparam_assignment { list_delim (@_[1..$#_]) }
;
event_identifier_dimensions: event_identifier opt_dimensions { f ("event_identifier_dimensions", @_[1..$#_]) }
;
list_of_event_identifiers: event_identifier_dimensions { f ("list_of_event_identifiers", $_[1]) }
| list_of_event_identifiers ',' event_identifier_dimensions { list_delim (@_[1..$#_]) }
;
list_of_genvar_identifiers: genvar_identifier { f ("list_of_genvar_identifiers", $_[1]) }
| list_of_genvar_identifiers ',' genvar_identifier { list_delim (@_[1..$#_]) }
;
list_of_net_decl_assignments: net_decl_assignment { f ("list_of_net_decl_assignments", $_[1]) }
| list_of_net_decl_assignments ',' net_decl_assignment { list_delim (@_[1..$#_]) }
;
net_identifier_dimensions: net_identifier opt_dimensions { f ("net_identifier_dimensions", @_[1..$#_]) }
;
list_of_net_identifiers: net_identifier_dimensions { f ("list_of_net_identifiers", $_[1]) }
| list_of_net_identifiers ',' net_identifier_dimensions { list_delim (@_[1..$#_]) }
;
# Implementation of list_of_param_assignments is done this way for shift/reduce
# conflict avoidance, similar to the port list case explained in 2.1.2.
# PAC = Param Assignment + Comma
# PAP = Param Assignment + (close) Paren
# PAS = Param Assignment + Semicolon
pac_param_assignment: param_assignment ',' { $_[1]->append_text ($_[2]) }
;
pac_param_assignments: pac_param_assignment { f ("list_of_param_assignments", $_[1]) }
| pac_param_assignments pac_param_assignment { list (@_[1..$#_]) }
;
pap_param_assignment: param_assignment ')' { $_[1]->append_text ($_[2]) }
;
pap_param_assignments: pap_param_assignment { f ("list_of_param_assignments", $_[1]) }
| pac_param_assignments pap_param_assignment { $_[1]->append_children ($_[2]) }
;
pas_param_assignment: param_assignment ';' { $_[1]->append_text ($_[2]) }
;
pas_param_assignments: pas_param_assignment { f ("list_of_param_assignments", $_[1]) }
| pac_param_assignments pas_param_assignment { $_[1]->append_children ($_[2]) }
;
#list_of_param_assignments: param_assignment { f ("list_of_param_assignments", $_[1]) }
# | list_of_param_assignments ',' param_assignment { $_[3]->prepend_text ($_[2]); $_[1]->append_children ($_[3]) }
# ;
list_of_port_identifiers: port_identifier { f ("list_of_port_identifiers", $_[1]) }
| list_of_port_identifiers ',' port_identifier { list_delim (@_[1..$#_]) }
;
list_of_real_identifiers: real_type { f ("list_of_real_identifiers", $_[1]) }
| list_of_real_identifiers ',' real_type { list_delim (@_[1..$#_]) }
;
list_of_specparam_assignments: specparam_assignment { f ("list_of_specparam_assignments", $_[1]) }
| list_of_specparam_assignments ',' specparam_assignment { list_delim (@_[1..$#_]) }
;
list_of_variable_identifiers: variable_type { f ("list_of_variable_identifiers", $_[1]) }
| list_of_variable_identifiers ',' variable_type { list_delim (@_[1..$#_]) }
;
variable_port_identifier: port_identifier opt_constant_assignment { f ("variable_port_identifier", @_[1,2]) }
;
list_of_variable_port_identifiers: variable_port_identifier { f ("list_of_variable_port_identifiers", $_[1]) }
| list_of_variable_port_identifiers ',' variable_port_identifier { list_delim (@_[1..$#_]) }
;
# 2.4 Declaration assignments
defparam_assignment: hierarchical_parameter_identifier '=' constant_mintypmax_expression { $_[1]->append_text ($_[2]); f ("defparam_assignment", @_[1,3]) }
;
net_decl_assignment: net_identifier '=' expression { $_[1]->append_text ($_[2]); f ("assignment", "continuous", $_[1], null, $_[3]) }
;
param_assignment: parameter_identifier '=' constant_expression { $_[1]->append_text ($_[2]); f ("param_assignment", $_[1], $_[3]); }
;
specparam_assignment: specparam_identifier '=' constant_mintypmax_expression { $_[1]->append_text ($_[2]); f ("specparam_assignment", @_[1,3]) }
| pulse_control_specparam
;
# Not sure why this is defined in this section rather than with other specify
# constructs, but anyways...
pulse_control_specparam: 'PATHPULSE$' '=' '(' reject_limit_value ')' ';' { $_[4]->prepend_text ($_[3])->prepend_text ($_[2])->prepend_text ($_[1]);
$_[4]->append_text ($_[5])->append_text ($_[6]);
f ("pulse_control_specparam", null , null , $_[4], null ) }
| 'PATHPULSE$' '=' '(' reject_limit_value ',' error_limit_value ')' ';' { $_[4]->prepend_text ($_[3])->prepend_text ($_[2])->prepend_text ($_[1]);
$_[4]->append_text ($_[5]);
$_[6]->append_text ($_[7])->append_text ($_[8]);
f ("pulse_control_specparam", null , null , $_[4], $_[6]) }
| 'PATHPULSE$' specify_input_terminal_descriptor '$' specify_output_terminal_descriptor '=' '(' reject_limit_value ')' ';' { $_[2]->prepend_text ($_[1]);
$_[4]->prepend_text ($_[3]);
$_[7]->prepend_text ($_[6])->prepend_text ($_[5]);
$_[7]->append_text ($_[8])->append_text ($_[9]);
f ("pulse_control_specparam", $_[2], $_[4], $_[7], null ) }
| 'PATHPULSE$' specify_input_terminal_descriptor '$' specify_output_terminal_descriptor '=' '(' reject_limit_value ',' error_limit_value ')' ';' { $_[2]->prepend_text ($_[1]);
$_[4]->prepend_text ($_[3]);
$_[7]->prepend_text ($_[6])->prepend_text ($_[5]);
$_[7]->append_text ($_[8]);
$_[9]->append_text ($_[10])->append_text ($_[11]);
f ("pulse_control_specparam", $_[2], $_[4], $_[7], $_[9]) }
;
error_limit_value: limit_value;
reject_limit_value: limit_value;
limit_value: constant_mintypmax_expression;
# 2.5 Declaration ranges
opt_dimensions: { null }
| dimensions
;
dimensions: dimension { f ("dimensions", $_[1]) }
| dimensions dimension { $_[1]->append_children ($_[2]) }
;
dimension: '[' dimension_constant_expression ':' dimension_constant_expression ']' { $_[2]->prepend_text ($_[1]);
$_[4]->prepend_text ($_[3]);
$_[4]->append_text ($_[5]);
f ("dimension", @_[2,4]) }
;
opt_range: { null }
| range
;
# Declaration ranges always are in the form [MSB:LSB], never [BIT], [BIT+:WIDTH], or [BIT-:WIDTH]
range: '[' msb_constant_expression ':' lsb_constant_expression ']' { $_[2]->prepend_text ($_[1])->append_text ($_[3]);
$_[4]->append_text ($_[5]);
f ("range", @_[2,4]) }
;
# 2.6 Function declarations
# The second and third forms are split (rather than use an
# opt_block_item_declarations rule) to avoid a shift/reduce conflict where the
# parser sees the start of an attribute and doesn't know whether it is a
# block_item_declaration or a statement.
function_declaration: 'function' opt_automatic opt_signed opt_range_or_type function_identifier ';' # 1-6
function_item_declarations # 7
function_statement # 8
'endfunction' # 9
{
$_[2]->prepend_text ($_[1]);
$_[5]->append_text ($_[6]);
$_[8]->append_text ($_[9]);
f ("function_declaration", @_[2,3,4,5], null, @_[7,8])
}
| 'function' opt_automatic opt_signed opt_range_or_type function_identifier # 1-5
'(' function_port_list ';' # 6-8
function_statement # 9
'endfunction' # 10
{
$_[2]->prepend_text ($_[1]);
$_[7]->prepend_text ($_[6]);
$_[7]->append_text ($_[8]);
$_[9]->append_text ($_[10]);
f ("function_declaration", @_[2,3,4,5,7], null, $_[9])
}
| 'function' opt_automatic opt_signed opt_range_or_type function_identifier # 1-5
'(' function_port_list ';' # 6-8
block_item_declarations # 9
function_statement # 10
'endfunction' # 11
{
$_[2]->prepend_text ($_[1]);
$_[7]->prepend_text ($_[6]);
$_[7]->append_text ($_[8]);
$_[10]->append_text ($_[11]);
f ("function_declaration", @_[2,3,4,5,7,9,10])
}
;
function_item_declarations: function_item_declaration { f ("function_item_declarations", $_[1]) }
| function_item_declarations function_item_declaration { list (@_[1..$#_]) }
;
function_item_declaration: block_item_declaration
| attr tf_input_declaration ';' { $_[2]->prepend_text ($_[1])->append_text ($_[3]) }
;
# function_port_list may not be empty
function_port_list: pip_function_port { f ("function_port_list", $_[1]) }
| pic_function_ports pip_function_port { list (@_[1,2]) }
;
#function_port: attr tf_input_declaration { $_[2]->prepend_text ($_[1]) }
# ;
pip_function_port: attr pip_tf_input_declaration { $_[2]->prepend_text ($_[1]) }
;
pic_function_ports: pic_function_port { f ("function_port_list", $_[1]) }
| pic_function_ports pic_function_port { list (@_[1,2]) }
;
pic_function_port: attr pic_tf_input_declaration { $_[2]->prepend_text ($_[1]) }
;
opt_range_or_type: { null }
| range_or_type
;
range_or_type: range
| 'integer'
| 'real'
| 'realtime'
| 'time'
;
# 2.7 Task declarations
# Second and third forms are split for same reason as in function_declaration
task_declaration: 'task' opt_automatic task_identifier ';' # 1-4
task_item_declarations # 5
statement_or_null # 6
'endtask' # 7
{
$_[2]->prepend_text ($_[1]);
$_[3]->append_text ($_[4]);
$_[6]->append_text ($_[7]);
f ("task_declaration", @_[2,3], null, @_[5,6])
}
| 'task' opt_automatic task_identifier '(' task_port_list ';' # 1-6
statement_or_null # 7
'endtask' # 8
{
$_[2]->prepend_text ($_[1]);
$_[5]->prepend_text ($_[4]);
$_[5]->append_text ($_[6]);
$_[7]->append_text ($_[8]);
f ("task_declaration", @_[2,3,5], null, $_[7])
}
| 'task' opt_automatic task_identifier '(' task_port_list ';' # 1-6
block_item_declarations # 7
statement_or_null # 8
'endtask' # 9
{
$_[2]->prepend_text ($_[1]);
$_[5]->prepend_text ($_[4]);
$_[5]->append_text ($_[6]);
$_[8]->append_text ($_[9]);
f ("task_declaration", @_[2,3,5,7,8])
}
;
task_item_declarations: task_item_declaration { f ("task_item_declarations", $_[1]) }
| task_item_declarations task_item_declaration { list (@_[1..$#_]) }
;
task_item_declaration: block_item_declaration
| attr tf_input_declaration ';' { $_[2]->prepend_text ($_[1])->append_text ($_[3]) }
| attr tf_output_declaration ';' { $_[2]->prepend_text ($_[1])->append_text ($_[3]) }
| attr tf_inout_declaration ';' { $_[2]->prepend_text ($_[1])->append_text ($_[3]) }
;
# task_port_list may be empty
task_port_list: ')' { f ("task_port_list", "")->append_text ($_[1]) }
| pip_task_port_item { f ("task_port_list", $_[1]) }
| pic_task_port_items pip_task_port_item { list (@_[1..2]) }
;