-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathSVParser.g4
More file actions
3332 lines (2741 loc) · 87.1 KB
/
SVParser.g4
File metadata and controls
3332 lines (2741 loc) · 87.1 KB
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
/*
NOTE: some stuff here have been taken from:
- https://raw2.github.com/antlr/grammars-v4/master/verilog/Verilog2001.g4
- https://github.com/gburdell/parser
Thanks go to Terrence Parr and Sam Harwell for making ANTLR and answering questions.
Thanks go also to gburdell for making a nice grammar that I could steal from.
Bug or misfeatures present in this grammar are my own.
TODO: currently skipping a lot of stuff inside modules/classes/interfaces/packages.
*/
parser grammar SVParser;
options {
tokenVocab=SVLexer;
TokenLabelType=SVToken;
}
@header {
package com.github.svstuff.systemverilog.generated;
}
// TODO this is not according to the LRM grammar.
// Note that package_import_declaration is handled by
// description.package_item.XYZ.data_declaration.package_import_declaration
root_element
: TIMESCALE | description | EOF
;
description
: attribute_instances package_item
| module_declaration
| interface_declaration
| program_declaration
| package_declaration
| attribute_instances bind_directive
// TODO udp_declaration
// TODO config_declaration
;
// Note: LRM is wrong, can't have ; here
bind_directive
: KW_BIND bind_target_scope COLON bind_target_instance_list bind_instantiation
| KW_BIND bind_target_instance bind_instantiation
;
bind_target_scope
: module_identifier
| interface_identifier
;
bind_target_instance
: hierarchical_identifier constant_bit_select*
;
bind_target_instance_list
: bind_target_instance (COMMA bind_target_instance)*
;
bind_instantiation
: element_instantiation
| checker_instantiation
;
// module, interface, program instantiation
element_instantiation
: identifier (parameter_value_assignment)? hierarchical_instance
(COMMA hierarchical_instance)* SEMI
;
// Note: the LRM has an optional block for list_of_port_connections, but that's
// redundant since one of the alternatives is empty anyway.
hierarchical_instance
: name_of_instance LPAREN list_of_port_connections RPAREN
;
list_of_port_connections
: ordered_port_connection (COMMA ordered_port_connection)*
| named_port_connection (COMMA named_port_connection)*
;
ordered_port_connection
: attribute_instances expression?
;
named_port_connection
: attribute_instances DOT port_identifier (LPAREN expression? RPAREN)?
| attribute_instances DOT MUL
;
class_declaration
: KW_VIRTUAL? KW_CLASS lifetime? class_identifier parameter_port_list?
class_inherit?
class_implement?
SEMI
class_body
KW_ENDCLASS (COLON class_identifier)?
;
class_inherit
: KW_EXTENDS class_type (LPAREN list_of_arguments RPAREN)?
;
class_implement
: KW_IMPLEMENTS interface_class_type (COMMA interface_class_type)*
;
class_body
: class_item*
;
class_item
: attribute_instances class_property
| attribute_instances class_method
| attribute_instances class_constraint
| attribute_instances class_declaration
| attribute_instances covergroup_declaration
| local_parameter_declaration SEMI
| parameter_declaration SEMI
| SEMI
;
class_property
: property_qualifier* class_data_declaration
;
class_method
: method_qualifier* function_declaration
| method_qualifier* task_declaration
| KW_PURE KW_VIRTUAL class_item_qualifier* method_prototype SEMI
| KW_EXTERN method_qualifier* method_prototype SEMI
;
task_declaration
: KW_TASK lifetime? task_name_qualifier? task_identifier
task_body_declaration
KW_ENDTASK ( COLON task_identifier )?
;
task_body_declaration
: SEMI task_body_no_arglist
| LPAREN tf_port_list? RPAREN SEMI task_body_arglist
;
// Parameters specified in body instead of in parenthesized list
// NOTE: see comment in function_body_arglist.
task_body_no_arglist
: (tf_item_declaration | statement_or_null)*
;
// Parameters specified in parenthesized list
// NOTE: see comment in function_body_arglist.
task_body_arglist
: (block_item_declaration | statement_or_null)*
;
task_name_qualifier
: function_name_qualifier
;
// [LRM]
// When the implicit syntax is used, the return type is the same as if the implicit syntax had been
// immediately preceded by the logic keyword. In particular, the implicit syntax can be empty, in which case
// the return type is a logic scalar.
function_declaration
: KW_FUNCTION lifetime? function_data_type_or_implicit function_name_qualifier? function_identifier
function_body_declaration
KW_ENDFUNCTION ( COLON function_identifier )?
;
function_name_qualifier
: interface_identifier DOT
| (package_scope parameter_value_assignment?)? (class_identifier parameter_value_assignment? COLON2)+
;
// [LRM]
// A function declaration has the formal arguments either in parentheses (like ANSI C) or in declarations and
// directions.
function_body_declaration
: SEMI function_body_no_arglist
| LPAREN tf_port_list? RPAREN SEMI function_body_arglist
;
// Parameters specified in body instead of in parenthesized list
// NOTE: see comment in function_body_arglist.
function_body_no_arglist
: (tf_item_declaration | function_statement_or_null)*
;
// TODO this rule is specified thusly in the LRM grammar:
// function_body_arglist : block_item_declaration* function_statement_or_null*
// This is not context free, because e.g. "a = b;" can be either a data_declaration (with implicit type)
// or a statement. This is for now handled by relaxing the grammar to allow interleaved declarations and
// statements. It is easier to check this requirement in the semantic phase.
function_body_arglist
: (block_item_declaration | function_statement_or_null)*
;
tf_item_declaration
: block_item_declaration
| tf_port_declaration
;
tf_port_declaration
: attribute_instances tf_port_direction KW_VAR? data_type_or_implicit list_of_tf_variable_identifiers SEMI
;
block_item_declaration
: attribute_instances data_declaration
| attribute_instances local_parameter_declaration SEMI
| attribute_instances parameter_declaration SEMI
| attribute_instances overload_declaration
| attribute_instances let_declaration
;
// TODO make sure we treat "a = b;" as an assignment statement rather than a
// vardecl with implicit type. Otherwise we have an ambiguity between vardecl and
// assignment statement.
variable_declaration
: KW_CONST KW_VAR? lifetime? data_type_or_implicit
list_of_variable_decl_assignments SEMI
| KW_VAR lifetime? data_type_or_implicit list_of_variable_decl_assignments SEMI
| lifetime data_type_or_implicit list_of_variable_decl_assignments SEMI
| data_type list_of_variable_decl_assignments SEMI
;
// Duplicated variable_declaration where lifetime cannot be first token.
// That would be ambiguous in a class property context (due to STATIC).
class_variable_declaration
: KW_CONST KW_VAR? lifetime? data_type_or_implicit
list_of_variable_decl_assignments SEMI
| KW_VAR lifetime? data_type_or_implicit list_of_variable_decl_assignments SEMI
| data_type_or_implicit list_of_variable_decl_assignments SEMI
;
// Duplicated data_declaration to avoid ambiguity due to STATIC.
class_data_declaration
: class_variable_declaration
| type_declaration
| package_import_declaration
| net_type_declaration
;
function_prototype
: KW_FUNCTION function_data_type_or_implicit function_identifier ( LPAREN tf_port_list? RPAREN )?
;
function_data_type_or_implicit
: data_type_or_void | implicit_data_type
;
class_constraint
: constraint_prototype
| constraint_declaration
;
constraint_prototype
: constraint_prototype_qualifier? KW_STATIC? KW_CONSTRAINT constraint_identifier SEMI
;
cover_cross
: (cross_identifier COLON)? KW_CROSS list_of_cross_items (KW_IFF LPAREN expression RPAREN)? cross_body
;
list_of_cross_items
: cross_item COMMA cross_item (COMMA cross_item)*
;
cross_item
: identifier
;
cross_body
: LCURLY cross_body_item* RCURLY // NOTE: bug in spec, can't have ; here.
| SEMI
;
cross_body_item
: function_declaration
| bins_selection_or_option SEMI
;
constraint_prototype_qualifier
: KW_EXTERN | KW_PURE
;
class_item_qualifier
: KW_STATIC
| KW_PROTECTED
| KW_LOCAL
;
property_qualifier
: random_qualifier
| class_item_qualifier
;
method_qualifier
: KW_PURE? KW_VIRTUAL
| class_item_qualifier
;
method_prototype
: task_prototype
| function_prototype
;
constraint_declaration
: KW_STATIC? KW_CONSTRAINT constraint_identifier constraint_block
;
interface_class_type
: ps_class_identifier parameter_value_assignment?
;
list_of_arguments
: expression? (COMMA expression?)* (COMMA DOT identifier LPAREN expression? RPAREN)*
| DOT identifier LPAREN expression? RPAREN (COMMA DOT identifier LPAREN expression? RPAREN)*
;
program_declaration
: program_nonansi_header timeunits_declaration? program_item* KW_ENDPROGRAM (COLON program_identifier)?
| program_ansi_header timeunits_declaration? non_port_program_item* KW_ENDPROGRAM (COLON program_identifier)?
| attribute_instances KW_PROGRAM program_identifier LPAREN DOT MUL RPAREN SEMI timeunits_declaration? program_item* KW_ENDPROGRAM (COLON program_identifier)?
| KW_EXTERN program_nonansi_header
| KW_EXTERN program_ansi_header
;
program_nonansi_header
: attribute_instances KW_PROGRAM lifetime? program_identifier package_import_declaration* parameter_port_list? list_of_ports SEMI
;
program_ansi_header
: attribute_instances KW_PROGRAM lifetime? program_identifier package_import_declaration* parameter_port_list? list_of_port_declarations? SEMI
;
program_item
: port_declaration SEMI
| non_port_program_item
;
non_port_program_item
: attribute_instances continuous_assign
| attribute_instances module_or_generate_item_declaration
| attribute_instances initial_construct
| attribute_instances final_construct
| attribute_instances concurrent_assertion_item
| timeunits_declaration
| program_generate_item
;
program_generate_item
: loop_generate_construct
| conditional_generate_construct
;
package_declaration
: attribute_instances KW_PACKAGE lifetime? package_identifier SEMI
timeunits_declaration? package_item* KW_ENDPACKAGE ( COLON package_identifier )?
;
package_item
: package_or_generate_item_declaration
;
package_or_generate_item_declaration
: net_declaration
| data_declaration
| task_declaration
| function_declaration
| checker_declaration
| dpi_import_export
| extern_constraint_declaration
| class_declaration
| local_parameter_declaration SEMI
| parameter_declaration SEMI
| covergroup_declaration
| overload_declaration
| assertion_item_declaration
| SEMI
;
// NOTE delay_control is optional, however when missing this alternative overlaps
// with data_declaration.
net_declaration
: net_type (drive_strength | charge_strength)? (KW_VECTORED | KW_SCALARED)?
data_type_or_implicit delay3? list_of_net_decl_assignments SEMI
| KW_INTERCONNECT implicit_data_type (HASH delay_value)? net_identifier
unpacked_dimension* (COMMA net_identifier unpacked_dimension*)? SEMI
| net_type_identifier delay_control list_of_net_decl_assignments SEMI
;
extern_constraint_declaration
: KW_STATIC? KW_CONSTRAINT class_scope constraint_identifier constraint_block
;
list_of_net_decl_assignments
: net_decl_assignment (COMMA net_decl_assignment)*
;
net_decl_assignment
: net_identifier unpacked_dimension* (EQ expression)?
;
specify_block
: KW_SPECIFY specify_item* KW_ENDSPECIFY
;
specify_item
: specparam_declaration
| pulsestyle_declaration
| showcancelled_declaration
| path_declaration
| system_timing_check
;
pulsestyle_declaration
: KW_PULSESTYLE_ONEVENT list_of_path_outputs SEMI
| KW_PULSESTYLE_ONDETECT list_of_path_outputs SEMI
;
showcancelled_declaration
: KW_SHOWCANCELLED list_of_path_outputs SEMI
| KW_NOSHOWCANCELLED list_of_path_outputs SEMI
;
path_declaration
: simple_path_declaration SEMI
| edge_sensitive_path_declaration SEMI
| state_dependent_path_declaration SEMI
;
simple_path_declaration
: parallel_path_description EQ path_delay_value
| full_path_description EQ path_delay_value
;
parallel_path_description
: LPAREN specify_input_terminal_descriptor polarity_operator? EQ_GT specify_output_terminal_descriptor RPAREN
;
full_path_description
: LPAREN list_of_path_inputs polarity_operator? MUL_GT list_of_path_outputs RPAREN
;
list_of_path_inputs
: specify_input_terminal_descriptor (COMMA specify_input_terminal_descriptor)*
;
list_of_path_outputs
: specify_output_terminal_descriptor (COMMA specify_output_terminal_descriptor)*
;
specify_input_terminal_descriptor
: input_identifier (LSQUARE constant_range_expression RSQUARE)?
;
specify_output_terminal_descriptor
: output_identifier (LSQUARE constant_range_expression RSQUARE)?
;
input_identifier
: input_port_identifier
| inout_port_identifier
| interface_identifier DOT port_identifier
;
output_identifier
: output_port_identifier
| inout_port_identifier
| interface_identifier DOT port_identifier
;
path_delay_value
: list_of_path_delay_expressions
| LPAREN list_of_path_delay_expressions RPAREN
;
list_of_path_delay_expressions
: t_path_delay_expression
| trise_path_delay_expression COMMA tfall_path_delay_expression
| trise_path_delay_expression COMMA tfall_path_delay_expression COMMA tz_path_delay_expression
| t01_path_delay_expression COMMA t10_path_delay_expression COMMA t0z_path_delay_expression COMMA tz1_path_delay_expression COMMA t1z_path_delay_expression COMMA tz0_path_delay_expression
| t01_path_delay_expression COMMA t10_path_delay_expression COMMA t0z_path_delay_expression COMMA tz1_path_delay_expression COMMA t1z_path_delay_expression COMMA tz0_path_delay_expression COMMA t0x_path_delay_expression COMMA tx1_path_delay_expression COMMA t1x_path_delay_expression COMMA tx0_path_delay_expression COMMA txz_path_delay_expression COMMA tzx_path_delay_expression
;
t_path_delay_expression : path_delay_expression ;
trise_path_delay_expression : path_delay_expression ;
tfall_path_delay_expression : path_delay_expression ;
tz_path_delay_expression : path_delay_expression ;
t01_path_delay_expression : path_delay_expression ;
t10_path_delay_expression : path_delay_expression ;
t0z_path_delay_expression : path_delay_expression ;
tz1_path_delay_expression : path_delay_expression ;
t1z_path_delay_expression : path_delay_expression ;
tz0_path_delay_expression : path_delay_expression ;
t0x_path_delay_expression : path_delay_expression ;
tx1_path_delay_expression : path_delay_expression ;
t1x_path_delay_expression : path_delay_expression ;
tx0_path_delay_expression : path_delay_expression ;
txz_path_delay_expression : path_delay_expression ;
tzx_path_delay_expression : path_delay_expression ;
path_delay_expression : constant_mintypmax_expression ;
edge_sensitive_path_declaration
: parallel_edge_sensitive_path_description EQ path_delay_value
| full_edge_sensitive_path_description EQ path_delay_value
;
parallel_edge_sensitive_path_description
: LPAREN edge_identifier? specify_input_terminal_descriptor polarity_operator? EQ_GT LPAREN specify_output_terminal_descriptor polarity_operator? COLON data_source_expression RPAREN RPAREN
;
full_edge_sensitive_path_description
: LPAREN edge_identifier? list_of_path_inputs polarity_operator? MUL_GT LPAREN list_of_path_outputs polarity_operator? COLON data_source_expression RPAREN RPAREN
;
data_source_expression : expression ;
state_dependent_path_declaration
: KW_IF LPAREN module_path_expression RPAREN simple_path_declaration
| KW_IF LPAREN module_path_expression RPAREN edge_sensitive_path_declaration
| KW_IFNONE simple_path_declaration
;
polarity_operator : ADD | SUB ;
system_timing_check
: setup_timing_check
| hold_timing_check
| setuphold_timing_check
| recovery_timing_check
| removal_timing_check
| recrem_timing_check
| skew_timing_check
| timeskew_timing_check
| fullskew_timing_check
| period_timing_check
| width_timing_check
| nochange_timing_check
;
setup_timing_check
: DOLLAR_SETUP LPAREN data_event COMMA reference_event COMMA timing_check_limit (COMMA notifier?)? RPAREN SEMI
;
hold_timing_check
: DOLLAR_HOLD LPAREN reference_event COMMA data_event COMMA timing_check_limit (COMMA notifier?)? RPAREN SEMI
;
setuphold_timing_check
: DOLLAR_SETUPHOLD LPAREN reference_event COMMA data_event COMMA timing_check_limit COMMA timing_check_limit (COMMA notifier? (COMMA timestamp_condition? (COMMA timecheck_condition? (COMMA delayed_reference? (COMMA delayed_data? )? )? )? )? )? RPAREN SEMI
;
recovery_timing_check
: DOLLAR_RECOVERY LPAREN reference_event COMMA data_event COMMA timing_check_limit (COMMA notifier? )? RPAREN SEMI
;
removal_timing_check
: DOLLAR_REMOVAL LPAREN reference_event COMMA data_event COMMA timing_check_limit (COMMA notifier? )? RPAREN SEMI
;
recrem_timing_check
: DOLLAR_RECREM LPAREN reference_event COMMA data_event COMMA timing_check_limit COMMA timing_check_limit (COMMA notifier? (COMMA timestamp_condition? (COMMA timecheck_condition? (COMMA delayed_reference? (COMMA delayed_data? )? )? )? )? )? RPAREN SEMI
;
skew_timing_check
: DOLLAR_SKEW LPAREN reference_event COMMA data_event COMMA timing_check_limit (COMMA notifier? )? RPAREN SEMI
;
timeskew_timing_check
: DOLLAR_TIMESKEW LPAREN reference_event COMMA data_event COMMA timing_check_limit (COMMA notifier? (COMMA event_based_flag? (COMMA remain_active_flag? )? )? )? RPAREN SEMI
;
fullskew_timing_check
: DOLLAR_FULLSKEW LPAREN reference_event COMMA data_event COMMA timing_check_limit COMMA timing_check_limit (COMMA notifier? (COMMA event_based_flag? (COMMA remain_active_flag?)? )? )? RPAREN SEMI
;
period_timing_check
: DOLLAR_PERIOD LPAREN controlled_reference_event COMMA timing_check_limit (COMMA notifier?)? RPAREN SEMI
;
width_timing_check
: DOLLAR_WIDTH LPAREN controlled_reference_event COMMA timing_check_limit COMMA threshold (COMMA notifier?)? RPAREN SEMI
;
nochange_timing_check
: DOLLAR_NOCHANGE LPAREN reference_event COMMA data_event COMMA start_edge_offset COMMA end_edge_offset (COMMA notifier?)? RPAREN SEMI
;
timecheck_condition : mintypmax_expression ;
timestamp_condition : mintypmax_expression ;
timing_check_limit : expression ;
controlled_reference_event : controlled_timing_check_event ;
data_event : timing_check_event ;
end_edge_offset : mintypmax_expression ;
event_based_flag : constant_expression ;
notifier : variable_identifier ;
reference_event : timing_check_event ;
remain_active_flag : constant_mintypmax_expression ;
start_edge_offset : mintypmax_expression ;
threshold : constant_expression ;
delayed_data
: terminal_identifier
| terminal_identifier LSQUARE constant_mintypmax_expression RSQUARE
;
delayed_reference
: terminal_identifier
| terminal_identifier LSQUARE constant_mintypmax_expression RSQUARE
;
timing_check_event
: timing_check_event_control? specify_terminal_descriptor (AND3 timing_check_condition)?
;
controlled_timing_check_event
: timing_check_event_control specify_terminal_descriptor (AND3 timing_check_condition)?
;
timing_check_event_control
: KW_POSEDGE
| KW_NEGEDGE
| KW_EDGE
| edge_control_specifier
;
specify_terminal_descriptor
: specify_input_terminal_descriptor
| specify_output_terminal_descriptor
;
edge_control_specifier
: KW_EDGE LSQUARE edge_descriptor (COMMA edge_descriptor)* RSQUARE
;
// TODO get real examples of this stuff...
edge_descriptor
: {_input.LT(1).getText().matches("01")}? LIT_NUM
| {_input.LT(1).getText().matches("10")}? LIT_NUM
| z_or_x zero_or_one
| zero_or_one z_or_x
;
zero_or_one
: {_input.LT(1).getText().matches("0")}? LIT_NUM
| {_input.LT(1).getText().matches("1")}? LIT_NUM
;
z_or_x
: {_input.LT(1).getText().matches("x")}? LIT_STRING
| {_input.LT(1).getText().matches("X")}? LIT_STRING
| {_input.LT(1).getText().matches("z")}? LIT_STRING
| {_input.LT(1).getText().matches("Z")}? LIT_STRING
;
timing_check_condition
: scalar_timing_check_condition
| LPAREN scalar_timing_check_condition RPAREN
;
scalar_timing_check_condition
: expression
| INV expression
| expression EQ2 scalar_constant
| expression EQ3 scalar_constant
| expression NOT_EQ scalar_constant
| expression NOT_EQ2 scalar_constant
;
scalar_constant
// TODO : 1'b0 | 1'b1 | 1'B0 | 1'B1 | 'b0 | 'b1 | 'B0 | 'B1 | 1 | 0
: LIT_NUM
;
sequence_declaration
: KW_SEQUENCE sequence_identifier (LPAREN sequence_port_list? RPAREN)? SEMI assertion_variable_declaration* sequence_expr SEMI? KW_ENDSEQUENCE (COLON sequence_identifier)?
;
sequence_port_list
: sequence_port_item (COMMA sequence_port_item)*
;
sequence_port_item
: attribute_instances (KW_LOCAL sequence_lvar_port_direction?)? sequence_formal_type formal_port_identifier variable_dimension* (EQ sequence_actual_arg)?
;
sequence_lvar_port_direction : KW_INPUT | KW_INOUT | KW_OUTPUT ;
sequence_formal_type
: data_type_or_implicit
| KW_SEQUENCE
| KW_UNTYPED
;
assertion_variable_declaration
: var_data_type list_of_variable_decl_assignments SEMI
;
assertion_item_declaration
: property_declaration
| sequence_declaration
| let_declaration
;
property_declaration
: KW_PROPERTY property_identifier (LPAREN property_port_list? RPAREN)? SEMI assertion_variable_declaration* property_spec SEMI? KW_ENDPROPERTY (COLON property_identifier)?
;
property_port_list
: property_port_item (COMMA property_port_item)*
;
property_port_item
: attribute_instances (KW_LOCAL property_lvar_port_direction?)? property_formal_type formal_port_identifier variable_dimension* (EQ property_actual_arg)?
;
property_lvar_port_direction : KW_INPUT ;
property_formal_type
: sequence_formal_type
| KW_PROPERTY
;
covergroup_declaration
: KW_COVERGROUP covergroup_identifier (LPAREN tf_port_list? RPAREN)? coverage_event? SEMI
coverage_spec_or_option*
KW_ENDGROUP (COLON covergroup_identifier)?
;
coverage_spec_or_option
: attribute_instances coverage_spec
| attribute_instances coverage_option SEMI
;
coverage_option
: KW_OPTION DOT member_identifier EQ expression
| KW_TYPE_OPTION DOT member_identifier EQ constant_expression
;
coverage_spec
: cover_point
| cover_cross
;
coverage_event
: clocking_event
;
// NOTE: in the spec data_type_or_implicit is optional. It has an empty alternative however.
cover_point
: (data_type_or_implicit cover_point_identifier COLON)? KW_COVERPOINT expression
(KW_IFF LPAREN expression RPAREN)?
bins_or_empty
;
bins_or_empty
: LCURLY attribute_instances (bins_or_options SEMI)* RCURLY
| SEMI
;
bins_or_options
: coverage_option
| KW_WILDCARD? bins_keyword bin_identifier (LSQUARE covergroup_expression? RSQUARE)? EQ
LCURLY covergroup_value_range (COMMA covergroup_value_range)* RCURLY (KW_WITH LPAREN with_covergroup_expression RPAREN)?
(KW_IFF LPAREN expression RPAREN)?
| KW_WILDCARD? bins_keyword bin_identifier (LSQUARE covergroup_expression? RSQUARE)? EQ
cover_point_identifier (KW_WITH LPAREN with_covergroup_expression RPAREN)? (KW_IFF LPAREN expression RPAREN)?
| KW_WILDCARD? bins_keyword bin_identifier (LSQUARE RSQUARE)? EQ trans_list (KW_IFF LPAREN expression RPAREN)?
| bins_keyword bin_identifier (LSQUARE covergroup_expression? RSQUARE)? EQ KW_DEFAULT (KW_IFF RPAREN expression RPAREN)?
| bins_keyword bin_identifier EQ KW_DEFAULT KW_SEQUENCE (KW_IFF LPAREN expression RPAREN)?
;
bins_selection_or_option
: attribute_instance* coverage_option
| attribute_instance* bins_selection
;
bins_selection
: bins_keyword bin_identifier EQ select_expression (KW_IFF LPAREN expression RPAREN)?
;
select_expression
: select_condition
| NOT select_condition
| select_expression AND2 select_expression
| select_expression OR2 select_expression
| LPAREN select_expression RPAREN
| select_expression KW_WITH LPAREN with_covergroup_expression RPAREN (KW_MATCHES integer_covergroup_expression)?
| cross_identifier
| cross_set_expression (KW_MATCHES integer_covergroup_expression)?
;
select_condition
: KW_BINSOF LPAREN bins_expression RPAREN (KW_INTERSECT LCURLY covergroup_range_list RCURLY)?
;
bins_expression
: identifier (DOT bin_identifier)?
;
covergroup_range_list
: covergroup_value_range (COMMA covergroup_value_range)*
;
covergroup_value_range
: covergroup_expression
| LSQUARE covergroup_expression COLON covergroup_expression RSQUARE
;
set_covergroup_expression
: covergroup_expression
;
with_covergroup_expression
: covergroup_expression
;
integer_covergroup_expression
: covergroup_expression
;
cross_set_expression
: covergroup_expression
;
covergroup_expression
: expression
;
trans_list
: LPAREN trans_set RPAREN (COMMA LPAREN trans_set RPAREN)*
;
trans_set
: trans_range_list (EQ_GT trans_range_list)*
;
trans_range_list
: trans_item
| trans_item LSQUARE * repeat_range RSQUARE
| trans_item LSQUARE SUB_GT repeat_range RSQUARE
| trans_item LSQUARE EQ repeat_range RSQUARE
;
repeat_range
: covergroup_expression
| covergroup_expression COLON covergroup_expression
;
trans_item
: covergroup_range_list
;
bins_keyword
: KW_BINS | KW_ILLEGAL_BINS | KW_IGNORE_BINS
;
data_declaration
: variable_declaration
| type_declaration
| package_import_declaration
| net_type_declaration
;
net_type_declaration
: KW_NETTYPE data_type net_type_identifier (KW_WITH (package_scope | class_scope)? tf_identifier)? SEMI
| KW_NETTYPE (package_scope | class_scope)? net_type_identifier net_type_identifier SEMI
;
list_of_variable_decl_assignments
: variable_decl_assignment (COMMA variable_decl_assignment)*
;
variable_decl_assignment
: variable_identifier variable_dimension* (EQ (dynamic_array_new | expression))?
| class_variable_identifier EQ class_new
;
class_new
: class_scope? KW_NEW
(LPAREN list_of_arguments RPAREN | {_input.LA(1) != LPAREN}? expression)?
;
dynamic_array_new
: KW_NEW LSQUARE expression RSQUARE (LPAREN expression RPAREN)?
;
let_declaration
: KW_LET let_identifier ( LPAREN let_port_list? RPAREN )? EQ expression SEMI
;
let_identifier
: identifier
;
let_port_list
: let_port_item ( COMMA let_port_item )*
;
let_port_item
: attribute_instances let_formal_type formal_port_identifier ( EQ expression )?
;
let_formal_type
: data_type_or_implicit
| KW_UNTYPED
;
let_expression
// : package_scope? let_identifier ( LPAREN let_list_of_arguments? RPAREN )? // TODO
: package_scope? let_identifier
;
let_list_of_arguments
: let_actual_arg? ( COMMA let_actual_arg? )* ( COMMA DOT identifier LPAREN let_actual_arg? RPAREN )*
| DOT identifier LPAREN let_actual_arg? RPAREN ( COMMA DOT identifier LPAREN let_actual_arg? RPAREN )*
;
let_actual_arg
: expression
;
overload_declaration
: KW_BIND overload_operator KW_FUNCTION data_type function_identifier
LPAREN overload_proto_formals RPAREN SEMI
;
overload_operator
: ADD | ADD2 | SUB | SUB2 | MUL | MUL2 | DIV | MOD | EQ2 | NOT_EQ
| LT | LT_EQ | GT | GT_EQ | EQ
;
overload_proto_formals
: data_type ( COMMA data_type )*
;
local_parameter_declaration
: KW_LOCALPARAM data_type_or_implicit list_of_param_assignments
| KW_LOCALPARAM KW_TYPE list_of_type_assignments
;
parameter_declaration
: KW_PARAMETER data_type_or_implicit list_of_param_assignments
| KW_PARAMETER KW_TYPE list_of_type_assignments
;
specparam_declaration
: KW_SPECPARAM packed_dimension? list_of_specparam_assignments SEMI
;
list_of_type_assignments
: type_assignment ( COMMA type_assignment )*
;
list_of_specparam_assignments
: specparam_assignment ( COMMA specparam_assignment )*
;
specparam_assignment
: specparam_identifier EQ constant_mintypmax_expression
// | pulse_control_specparam // TODO
;
type_assignment
: type_identifier ( EQ data_type )?
;
statement_or_null
: statement
| attribute_instances SEMI
;
statement
: (block_identifier COLON)? attribute_instances statement_item
;
statement_item
: procedural_continuous_assignment SEMI
| case_statement
| conditional_statement
| disable_statement
| event_trigger
| loop_statement
| jump_statement
| par_block
| procedural_timing_control_statement
| seq_block
| wait_statement
| procedural_assertion_statement
| clocking_drive_statement
| randsequence_statement
| randcase_statement
| expect_property_statement
// NOTE this is too relaxed. The grammar allows just a couple of expressions to be statements.