forked from chipsalliance/verible
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verilog_parser_unittest.cc
6525 lines (6435 loc) · 185 KB
/
verilog_parser_unittest.cc
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
// Copyright 2017-2020 The Verible Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// Verilog parser unit tests
#include <algorithm>
#include <cstddef>
#include <initializer_list>
#include <string>
#include "absl/status/status.h"
#include "absl/strings/str_cat.h"
#include "common/parser/bison_parser_common.h"
#include "common/parser/parser_test_util.h"
#include "common/text/constants.h"
#include "common/text/symbol.h"
#include "common/text/token_info.h"
#include "common/text/token_info_test_util.h"
#include "gtest/gtest.h"
#include "verilog/CST/verilog_nonterminals.h"
#include "verilog/analysis/verilog_analyzer.h"
#include "verilog/analysis/verilog_excerpt_parse.h"
#include "verilog/parser/verilog_token_enum.h"
namespace verilog {
using ParserTestData = verible::TokenInfoTestData;
using ParserTestCaseArray = std::initializer_list<const char*>;
// No syntax tree expected from these inputs.
static const ParserTestCaseArray kEmptyTests = {
"", " ", "\t\t\t", "\n\n", "// comment\n", "/* comment */\n",
};
static const ParserTestCaseArray kPreprocessorTests = {
"`define TRUTH\n", // definition without value
"`define FOO BAR-1\n", // definition with value
"`include \"foo.svh\"\n" // include directive
"`ifndef SANITY\n"
"`define SANITY\n"
"`endif\n",
"`include `EXPAND_TO_STRING\n" // include directive
"`include `EXPAND_TO_PATH // path\n"
"`define SANITY 1+1\n"
"`ifdef INSANITY\n"
"`undef INSANITY\n" // undefine
"`define INSANITY\n"
"`endif\n",
"`ifdef INSANITY\n" // definition also in else clause
"`define INSANITY // comment\n" // definition with comment
"`else\n"
"`define SANITY 1\n"
"`endif\n",
"`define INCEPTION(a, b, c)\n", // with parameters, no body
"`define INCEPTION(a, b, c) (a*b-c)\n", // with parameters, body
"`define INCEPTION(a, b, c) \\\n" // with line-conitnuation
" (a*b-c)\n",
"`define INCEPTION(xyz) \\\n" // definition that defines
" `define DEEPER (xyz)\n",
"`define LONG_MACRO(\n"
" a, b, c)\n", // parameters span multiple lines
"`define LONG_MACRO(\n"
" a,\n" // parameters span multiple lines without continuation
" b, c) text goes here\n",
"`define LONG_MACRO(\n"
" a,\n" // parameters span multiple lines without continuation
" b\n"
", c\n"
") \\\n"
"more text c, b, a \\\n"
"blah blah macro ends here\n",
"`define LONG_MACRO(\n"
" a, b=2, c=42) \\\n" // parameters with defaults
"a + b /c +345\n",
"`define LONG_MACRO(\n"
" a, b=\"(3,2)\", c=(3,2)) \\\n" // parameters with defaults
"a + b /c +345\n",
// escaped identifier macro call argument
"`FOO(\\BAR )\n", //
"`FOO(\\BAR\t)\n", //
"`FOO(\\BAR\n)\n", //
"`FOO(\\BAR.BAZ )\n", //
"`FOO(\\BAR , \\BAZ )\n", //
"`WE(`MUST(`GO(\\deeper )))\n", //
"`MACRO()\n", //
"`MACRO(123badid)\n", // call arg contains a lexical error, but remains
// unlexed
"`MACRO(`)\n", // call arg contains a lexical error, but remains unlexed
"`MACRO(` )\n", // call arg contains a lexical error, but remains unlexed
"`MACRO(`DEEPER(`))\n", // call arg contains a lexical error, but remains
// unlexed
"`c(;d());\n" // ";d()" remains unlexed
};
// Make sure line continuations, newlines and spaces get filtered out
static const ParserTestCaseArray kLexerFilterTests = {
"parameter \tfoo =\t\t0;",
"parameter\n\nfoo =\n 0;",
"parameter \\\nfoo =\\\n 0;",
"//comment with line-continuation\\\n",
"//comment1 with line-continuation\\\n"
"//comment2 with line-continuation\\\n",
};
// Numbers are parsed as ([width], [signed]base, digits)
static const ParserTestCaseArray kNumberTests = {
"parameter foo = 0;",
"parameter int foo = 0;",
"parameter int foo = '0;",
"parameter int foo = '1;",
// binary
"parameter int foo = 'b0;",
"parameter int foo = 'b 0;",
"parameter int foo = 1'b0;",
"parameter int foo = 1'B0;",
"parameter int foo = 1 'b 0;",
"parameter int foo = 1'b1;",
"parameter int foo = 1'bx;",
"parameter int foo = 1 'b x;",
"parameter int foo = 1'bz;",
"parameter int foo = 4'bxxxx;",
"parameter int foo = 4'bzzzz;",
"parameter int foo = 4'sb1111;",
"parameter int foo = 4'Sb0000;",
"parameter int foo = 16'b`DIGITS;",
"parameter int foo = 16'b`DIGITS();",
"parameter int foo = 16'b`DIGITS(bar);",
"parameter int foo = 16'b`DIGITS(bar, baz);",
"parameter int foo = 16 'b `DIGITS;",
"parameter int foo = 16 'b `DIGITS();",
"parameter int foo = `WIDTH'b`DIGITS;",
// decimal
"parameter int foo = 'd0;",
"parameter int foo = 'd 0;",
"parameter int foo = 32'd1;",
"parameter int foo = 32'D1;",
"parameter int foo = 32 'd 1;",
"parameter int foo = 32'sd1;",
"parameter int foo = 32'Sd1;",
"parameter int foo = 32'dx;",
"parameter int foo = 32'dx_;",
"parameter int foo = 32'dx__;",
"parameter int foo = 32'dX;",
"parameter int foo = 32'dz;",
"parameter int foo = 32'dZ;",
"parameter int foo = 32'd`DIGITS;",
"parameter int foo = 32 'd `DIGITS;",
"parameter int foo = 32'd`DIGITS();",
"parameter int foo = 32'd`DIGITS(bar);",
"parameter int foo = `WIDTH'd`DIGITS;",
// octal
"parameter int foo = 'o0;",
"parameter int foo = 'o 0;",
"parameter int foo = 32'o7;",
"parameter int foo = 32'o7_7_7;",
"parameter int foo = 32'O7;",
"parameter int foo = 32 'o 7;",
"parameter int foo = 32'so7;",
"parameter int foo = 32'So7;",
"parameter int foo = 32'oxxx;",
"parameter int foo = 32'oXX;",
"parameter int foo = 32'ozz;",
"parameter int foo = 32'oZZ;",
"parameter int foo = 32'o`DIGITS;",
"parameter int foo = 32 'o `DIGITS;",
"parameter int foo = 32'o`DIGITS();",
"parameter int foo = 32'o`DIGITS(bar);",
"parameter int foo = `WIDTH'o`DIGITS;",
// hexadecimal
"parameter int foo = 'h0;",
"parameter int foo = 'h 0;",
"parameter int foo = 32'h7;",
"parameter int foo = 32'H7fFF;",
"parameter int foo = 32'H_7f_FF_;",
"parameter int foo = 32'hdeadbeef;",
"parameter int foo = 32'hFEEDFACE;",
"parameter int foo = 32 'h 7;",
"parameter int foo = 32'sh7;",
"parameter int foo = 32'Sh7;",
"parameter int foo = 32'hxxx;",
"parameter int foo = 32'hXX;",
"parameter int foo = 32'hzz;",
"parameter int foo = 32'hZZ;",
"parameter int foo = 32'h`DIGITS;",
"parameter int foo = 32 'h `DIGITS;",
"parameter int foo = 32'h`DIGITS();",
"parameter int foo = 32'h`DIGITS(bar);",
"parameter int foo = `WIDTH'h`DIGITS;",
};
// classes are a System Verilog construct
static const ParserTestCaseArray kClassTests = {
"class semicolon_classy; ; ;;; ; ; ;endclass",
"class Foo; endclass",
"class static Foo; endclass",
"class automatic Foo; endclass",
"virtual class Foo; endclass",
"virtual class automatic Foo; endclass",
"class Foo extends Bar; endclass",
"class Foo extends Package::Bar; endclass",
"class Foo extends Bar #(x,y,z); endclass",
"class Foo #(int N);\n" // parameter without default value
"endclass",
"class Foo #(int N, P);\n"
"endclass",
"class Foo #(int N, int P);\n"
"endclass",
"class Foo #(int N=1, int P=2) extends Bar #(x,y,z);\n"
"endclass",
"class Foo #(int W=8, type Int=int) extends Bar #(x,y,z);\n"
"endclass",
"class Foo #(T=int);\n" // default type
"endclass",
"class Foo #(type KeyType=int, Int=int);\n" // default type
"endclass",
"class Foo #(IFType=virtual x_if);\n" // interface type
"endclass",
"class Foo #(type IFType=virtual x_if);\n" // interface type
"endclass",
"class Foo #(type IFType=virtual interface x_if);\n"
"endclass",
"class Foo extends Package::Bar #(x,y,z); endclass",
"class Foo extends Package::Bar #(.v1(x),.v2(y)); endclass",
"class Foo extends Package::Bar #(x,y,z); endclass",
"class Foo extends Package::Bar #(.v1(x),.v2(y)); endclass",
"class Foo implements Bar; endclass",
"class Foo implements Bar, Blah, Baz; endclass",
"class Foo implements Package::Bar; endclass",
"class Foo implements Bar#(N); endclass",
"class Foo implements Package::Bar#(1, 2); endclass",
"class Foo extends Base implements Bar; endclass",
"class Foo extends Base implements Pkg::Bar, Baz; endclass",
"class Foo;\n"
"integer size;\n"
"function new (integer size);\n"
" begin\n"
" this.size = size;\n"
" end\n"
"endfunction\n"
"task print();\n"
" begin\n"
" $write(\"Hello, world!\");\n"
" end\n"
"endtask\n"
"endclass",
"typedef class myclass_fwd;",
"class zzxx;\n"
"extern function void set_port(analysis_port #(1) ap);\n"
"endclass",
"class zzxy;\n"
"extern function void set_port(dbg_pkg::analysis_port app);\n"
"endclass",
"class zzyyy;\n"
"extern function void set_port(dbg_pkg::analysis_port #(1,N) apb);\n"
"endclass",
"class zzxx;\n"
"extern function automatic void set_port(int ap);\n"
"endclass",
// import declarations
"class foo;\n"
" import fedex_pkg::box;\n"
" import fedex_pkg::*;\n"
"endclass",
"virtual class foo extends bar;\n"
" import fedex_pkg::box;\n"
" import fedex_pkg::*;\n"
"endclass",
// macros as class items
"class macros_as_class_item;\n"
" `moobar()\n"
" `zoobar( )\n"
" `zootar(\n)\n"
"endclass",
"class macros_as_class_item;\n"
" `moobar(,)\n"
" `zoobar( , )\n"
" `zootar(12,)\n"
" `zoojar(,34)\n"
"endclass",
"class macros_as_class_item;\n"
" `uvm_object_registry(myclass, \"class_name\")\n"
"endclass",
"class macros_as_class_item;\n"
" `uvm_object_utils(stress_seq)\n"
" `uvm_object_registry(myclass, \"class_name\")\n"
" `uvm_sweets(dessert)\n"
" `non_uvm_macro(apple, `banana, \"cherry\")\n"
"endclass",
"class macros_as_class_item;\n"
" `uvm_object_utils_begin(foobar)\n"
" `uvm_object_utils(blah)\n"
" `uvm_object_utils_end\n" // macro-id alone treated as call
"endclass",
"class macros_as_class_item;\n"
" `uvm_object_utils_begin(foobar)\n"
" `uvm_field_int(node, UVM_DEFAULT);\n" // with semicolon
" `uvm_field_int(foo::bar_t, UVM_DEFAULT);\n" // with semicolon
" `uvm_field_enum(offset, UVM_DEFAULT)\n" // without semicolon
" `uvm_object_utils_end\n" // macro-id alone treated as call
"endclass",
"class macros_as_class_item;\n"
" `uvm_field_utils_begin(my_class)\n"
" `uvm_field_int(blah1, flag1)\n"
" `uvm_field_real(blah2, flag2)\n"
" `uvm_field_enum(blah3, flag3)\n"
" `uvm_field_object(blah4, flag4)\n"
" `uvm_field_event(blah5, flag5)\n"
" `uvm_field_string(blah6, flag6)\n"
" `uvm_field_array_int(blah7, flag7)\n"
" `uvm_field_sarray_int(blah8, flag8)\n"
" `uvm_field_aa_int_string(blah9, flag9)\n"
" `uvm_field_utils_end\n" // macro-id alone treated as call
"endclass",
"class macros_as_class_item;\n"
" `uvm_object_param_utils_begin(my_class)\n"
" `uvm_field_int(blah1, F1)\n"
" `uvm_field_real(blah2, F2)\n"
" `uvm_field_enum(blah3, F3)\n"
" `uvm_object_utils_end\n" // macro-id alone treated as call
"endclass",
"class macros_as_class_item;\n"
" `uvm_component_utils(my_type)\n"
" `uvm_component_utils_begin(my_type)\n"
" `uvm_field_object(blah1, F1)\n"
" `uvm_field_event(blah2, F2)\n"
" `uvm_field_string(blah3, F3)\n"
" `uvm_component_utils_end\n" // macro-id alone treated as call
"endclass",
"class macros_id_as_call;\n"
" `uvm_new_func\n"
" `uvm_new_func2 // comment\n"
" `uvm_new_func3 /* comment */\n"
"endclass",
"class pp_as_class_item;\n"
" `undef EVIL_MACRO\n"
"endclass",
// parameters and local parameters
"class params_as_class_item;\n"
" parameter N = 2;\n"
" parameter reg P = '1;\n"
" localparam M = f(glb::arr[N]) + 1;\n"
"endclass",
"class params_as_class_item;\n"
" localparam M = {\"hello\", \"world\"}, X = \"spot\";\n"
" parameter int N = 2, P = Q(R), S = T[U];\n"
"endclass",
"class how_wide;\n"
" localparam Max_int = {$bits(int) - 1{1'b1}};\n"
"endclass",
"class how_wide #(type DT=int) extends uvm_sequence_item;\n"
" localparam Max_int = {$bits(DT) - 1{1'b1}};\n"
" localparam Min_int = {$bits(int) - $bits(DT){1'b1}};\n"
"endclass",
"class param_types_as_class_item;\n"
" parameter type AT;\n"
" parameter type BT = BrickType;\n"
" parameter type CT1 = Ctype1, CT2 = Ctype2;\n"
" localparam type GT = mypkg::GlueType, GT2;\n"
" localparam type HT1, HT2 = mypkg::ModuleType#(N+M);\n"
"endclass",
// event declaration
"class event_calendar;\n"
" event birthday;\n"
" event first_date, anniversary;\n"
" event revolution[4:0], independence[2:0];\n"
"endclass",
// associative array declaration
"class Driver;\n"
" Packet pNP [*];\n"
" Packet pNP1 [* ];\n"
" Packet pNP2 [ *];\n"
" Packet pNP3 [ * ];\n"
"endclass",
// class property declarations
"class c;\n"
" foo bar;\n"
"endclass\n",
"class c;\n"
" const foo bar;\n"
"endclass\n",
"class c;\n"
" protected int count;\n"
"endclass\n",
"class c;\n"
" foo #(.baz) bar;\n"
"endclass\n",
"class c;\n"
" foo #(.baz(bah)) bar;\n"
"endclass\n",
"class c;\n"
" foo #(.baz) bar1, bar2;\n"
"endclass\n",
"class Driver;\n"
" data_type_or_module_type foo1;\n"
" data_type_or_module_type foo2 = 1'b1;\n"
" data_type_or_module_type foo3, foo4;\n"
" data_type_or_module_type foo5 = 5, foo6 = 6;\n"
"endclass",
"class fields_with_modifiers;\n"
" const data_type_or_module_type foo1 = 4'hf;\n"
" static data_type_or_module_type foo3, foo4;\n"
"endclass",
"class fields_with_modifiers;\n"
" const static data_type_or_module_type foo1 = 4'hf;\n"
" static const data_type_or_module_type foo3, foo4;\n"
"endclass",
// preprocessor balanced class items
"class pp_class;\n"
"`ifdef DEBUGGER\n" // empty
"`endif\n"
"endclass",
"class pp_class;\n"
"`ifdef DEBUGGER\n"
"`ifdef VERBOSE\n" // nested, empty
"`endif\n"
"`endif\n"
"endclass",
"class pp_class;\n"
"`ifndef DEBUGGER\n" // `ifndef
"`endif\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
"`endif\n"
" int router_size;\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
" string source_name;\n" // single item
"`endif\n"
" int router_size;\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
" string source_name;\n" // multiple items
" string dest_name;\n"
"`endif\n"
" int router_size;\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
" string source_name;\n"
" string dest_name;\n"
"`else\n" // `else empty
"`endif\n"
" int router_size;\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
" string source_name;\n"
" string dest_name;\n"
"`elsif LAZY\n" // `elsif empty
"`endif\n"
" int router_size;\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
"`elsif LAZY\n" // `elsif with multiple items
" string source_name;\n"
" string dest_name;\n"
"`endif\n"
" int router_size;\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
"`elsif BORED\n"
" string source_name;\n"
" string dest_name;\n"
"`elsif LAZY\n" // second `elsif
"`endif\n"
" int router_size;\n"
"endclass",
"class pp_class;\n"
" int num_packets;\n"
"`ifdef DEBUGGER\n"
"`elsif BORED\n"
"`else\n" // `else with multiple items
" string source_name;\n"
" string dest_name;\n"
"`endif\n"
" int router_size;\n"
"endclass",
};
static const ParserTestCaseArray kFunctionTests = {
"function integer add;\n"
"input a, b;\n"
"begin\n"
" add = (a+b);\n"
"end\n"
"endfunction",
"function integer mini_me;\n"
"input a, b;\n"
"mini_me = (a<b) ? a:b;\n"
"endfunction",
"function myclass::numtype mini_me;\n"
"input a, b;\n"
"mini_me = (a<b) ? a:b;\n"
"endfunction",
"function mypkg::myclass::numtype mini_me;\n"
"input a, b;\n"
"mini_me = (a<b) ? a:b;\n"
"endfunction",
"function myclass::numtype #(W) mini_me;\n"
"input a, b;\n"
"mini_me = (a<b) ? a:b;\n"
"endfunction",
"function void compare;\n"
"input int a, b;\n"
"output bit c;\n"
"c = (a == b);\n"
"endfunction",
"function void vcompare;\n"
"input int a, b;\n"
"output bit [N:0] c;\n"
"c = (a ^ b);\n"
"endfunction",
"function void nonsense;\n"
"input int a[3:0], b[M:0];\n"
"output bit [N:0] c [11:0];\n"
"c = (a ^ b);\n"
"endfunction",
"function integer twiddle;\n"
"input a, b;\n"
"`MACRO(a, b);\n"
"endfunction",
"function integer twiddle;\n"
"input a, b;\n"
"`undef MACRO\n"
"endfunction",
// const ref formals
"function integer reader(const ref rw);\n"
"endfunction",
"function void reader(\n"
" const ref in_value, ref out_value\n"
");\n"
"endfunction",
// preprocessor directives in ports
"function void twiddle(\n"
"`ifdef ASDF\n"
" string a,\n"
"`else\n"
" int bb,\n"
"`endif\n"
" bit cc\n"
");\n"
"endfunction",
"function void processor(\n"
" string a,\n"
"`ifdef ASDF\n"
" bit cc\n"
"`else\n"
" int bb\n"
"`endif\n"
");\n"
"endfunction",
// local variables, various qualifiers
"function void declare_stuff;\n"
"int a_count;\n"
"const int b_count;\n"
"var int c_count;\n"
"static foo::int_t d_count;\n"
"automatic bool e_enabled;\n"
"const static string incantation;\n"
"static const string curse = \"dang nabbit\";\n"
"const var automatic string password;\n"
"endfunction",
// let declaration
"function void declare_stuff;\n"
"let Max(a,b) = (a > b) ? a : b;\n"
"endfunction",
// with no function_items
"function void twiddle;\n"
" `MACRO(a, b);\n"
"endfunction",
"function void twiddle;\n"
" if (enable_stats) begin\n"
" $display(\"stuff\");\n"
" end\n"
"endfunction",
// array return types
"function integer[1:0] twiddle;\n"
"input integer a, b;\n"
"endfunction",
"function integer[1:0][3:0] twiddle;\n"
"input integer a, b;\n"
"endfunction",
"function string[2:0] twiddle;\n"
"input bit b [4:0];\n"
"endfunction",
"function monster[n:0] twiddle;\n"
"input integer a[n:0];\n"
"endfunction",
"function scope_name::type_name[n:0] twiddle;\n"
"input integer a[n:0];\n"
"endfunction",
"function scope_name::type_name #(M) [n:0] twiddle;\n"
"input integer a[n:0];\n"
"endfunction",
// streaming concatenation lvalue
"function void unpack_id(int nums);\n"
"{>>8 {foo, bar}} = nums;\n"
"endfunction",
"function void unpack_id(utils_pkg::bytestream_t bytes);\n"
"{<< byte {this.reserved, this.id}} = bytes;\n"
"endfunction",
// concatenation lvalue
"module foo;\n"
" initial begin\n"
" {A, B, C} = bar;\n"
" end\n"
"endmodule\n",
// nested concatenation lvalue
"module foo;\n"
" initial begin\n"
" {{A, B}, {C, D}} = bar;\n"
" end\n"
"endmodule\n",
// assignment pattern lvalue
"module foo;\n"
" initial begin\n"
" '{A, B, C} = bar;\n"
" end\n"
"endmodule\n",
// assignment pattern lvalue and rvalue
"module foo;\n"
" initial begin\n"
" '{A, B, C} = '{D, E, F};\n"
" end\n"
"endmodule\n",
// nested assignment pattern lvalue
"module foo;\n"
" initial begin\n"
" '{'{A, B}, '{C, D}} = bar;\n"
" end\n"
"endmodule\n",
// mixed nested lvalue
"module foo;\n"
" initial begin\n"
" '{{A, B}, {C, D}} = bar1;\n"
" {'{E, F}, '{G, H}} = bar2;\n"
" end\n"
"endmodule\n",
// qualified expressions
"function void scoper;\n"
" a = b::c;\n"
" d = $unit::c;\n"
" e = $unit::xx::yy + zz::ww;\n"
"endfunction",
// cast expressions
"function void caster(int foo);\n"
" ret = ($bits(mux::info_t))'(ctrl_info);\n"
" rdata_address[$clog2(Aspect_ratio)-1:0] =\n"
" $unsigned(($clog2(Aspect_ratio))'(rndx));\n"
" credit = ($bits(credit))'(sq_ub::chunks_per_bank);\n"
"endfunction",
// various index expressions
"function void dollar(utils_pkg::bytestream_t bytes);\n"
" return bar[num_bytes:$];\n"
"endfunction",
// builtin functions
"function int optimize();\n"
" return max(a, b) / min(c, d);\n"
"endfunction",
"function num_pkg::float64_t tangent();\n"
" return sin(angle) / cos(angle);\n"
"endfunction",
// out-of-line method (class member function) definitions
"function void my_class::method_name();\n"
" idle();\n"
"endfunction",
"function my_class::m_name();\n" // implicit return type
"endfunction : m_name",
"function return_type my_class::method_name();\n"
" return to_sender;\n"
"endfunction",
"function qualified::return_type my_class::method_name();\n"
" return to_sender;\n"
"endfunction",
"function return_type[K:0] my_class::method_name();\n"
" return to_sender;\n"
"endfunction",
// out-of-line constructor definitions
"function my_class::new;\n"
"endfunction",
"function my_class::new();\n"
"endfunction",
"function my_class::new;\n"
"endfunction : new",
"function my_class::nested::new;\n"
"endfunction",
"function foo::new (string name, uvm_component parent);\n"
" super.new(name, parent);\n"
"endfunction : new",
// calling array-locator methods
"function void finder;\n"
" a0 = b.find;\n"
" a1 = b.find();\n"
" a2 = x.b.find() with (x < 1);\n"
" a3 = c[j].b.find(x) with (x != 0 && y > 2);\n"
" a4 = x.b.find with (x+y < 1);\n"
" a5 = x.b. find with (x.y < 1);\n"
"endfunction",
"function void finder;\n"
" a1 = b.find_index;\n"
" a2 = x.b.find_index with (x < 1);\n"
" a3 = x.b.find_index() with (x < 1);\n"
" a4 = d.c[j].find_index(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b.find_first with (x.y.z);\n"
" a1 = b.find_first();\n"
" a2 = x.b.find_first(item) with (item.count > 1);\n"
" a3 = d.c[j].find_first(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b.find_first_index with (x.y.z);\n"
" a1 = b.find_first_index();\n"
" a2 = x.b.find_first_index(item) with (item.count > 1);\n"
" a3 = d.c[j].find_first_index(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b.find_last with (x.y.z);\n"
" a1 = b.find_last();\n"
" a2 = x.b.find_last(item) with (item.count > 1);\n"
" a3 = d.c[j].find_last(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b.find_last_index with (x.y.z);\n"
" a1 = b.find_last_index();\n"
" a2 = x.b.find_last_index(item) with (item.count > 1);\n"
" a3 = d.c[j].find_last_index(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b. min with (x.y.z);\n"
" a1 = b. min();\n"
" a2 = x.b.min(item) with (item.count > 1);\n"
" a3 = d.c[j].min(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b. max with (x.y.z);\n"
" a1 = b. max();\n"
" a2 = x.b.max(item) with (item.count > 1);\n"
" a3 = d.c[j].max(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b. unique with (x.y.z);\n"
" a1 = b. unique();\n"
" a2 = x.b.unique(item) with (item.count > 1);\n"
" a3 = d.c[j].unique(x) with (x != z && y > 2);\n"
"endfunction",
"function void finder;\n"
" a0 = b. unique_index with (x.y.z);\n"
" a1 = b. unique_index();\n"
" a2 = x.b.unique_index(item) with (item.count > 1);\n"
" a3 = d.c[j].unique_index(x) with (x != z && y > 2);\n"
"endfunction",
"function void sorter;\n"
" b. sort;\n"
" b. sort();\n"
" x.b.sort with (item.count);\n"
" d.c[j].sort(x) with (x + 2);\n"
"endfunction",
"function void rsorter;\n"
" b. rsort;\n"
" b. rsort();\n"
" x.b.rsort with (item.count);\n"
" d.c[j].rsort(x) with (x + 2);\n"
"endfunction",
"function void reverser;\n"
" b. reverse;\n"
" b. reverse();\n"
"endfunction",
"function void shuffler;\n"
" b. shuffle;\n"
" b. shuffle();\n"
"endfunction",
"function void summer;\n"
" a0 = b. sum;\n"
" a1 = b. sum();\n"
" a2 = x.b.sum with (item.count);\n"
" a3 = d.c[j].sum(x) with (x + 2);\n"
"endfunction",
"function void multiplier;\n"
" a0 = b. product;\n"
" a1 = b. product();\n"
" a2 = x.b.product with (item.count);\n"
" a3 = d.c[j].product(x) with (x - 2);\n"
"endfunction",
"function void ander;\n"
" a0 = b. and;\n"
" a1 = b. and();\n"
" a2 = x.b.and with (item.predicate);\n"
" a3 = d.c[j].and(x) with (~x);\n"
"endfunction",
"function void orer;\n"
" a0 = b. or;\n"
" a1 = b. or();\n"
" a2 = x.b.or with (item.predicate);\n"
" a3 = d.c[j].or(x) with (~x);\n"
"endfunction",
"function void xorer;\n"
" a0 = b. xor;\n"
" a1 = b. xor();\n"
" a2 = x.b.xor with (item.predicate);\n"
" a3 = d.c[j].xor(x) with (~x);\n"
"endfunction",
// testing for preprocessor-balanced statements
"function void preprocess_statement_test();\n"
" a0 = b.x;\n"
"`ifdef POINTLESS\n" // empty `ifdef
"`endif\n"
" a1 = b.x;\n"
"endfunction",
"function void preprocess_statement_test();\n"
" a0 = b.x;\n"
"`ifdef POINTLESS\n" // and empty `else
"`else\n"
"`endif\n"
" a1 = b.x;\n"
"endfunction",
"function void preprocess_statement_test();\n"
" a0 = b.x;\n"
"`ifdef POINTLESS\n"
"`elsif DUMB\n" // empty `elsif's
"`elsif DUMBER\n"
"`else\n"
"`endif\n"
" a1 = b.x;\n"
"endfunction",
"function void preprocess_statement_test();\n"
" a0 = b.x;\n"
"`ifdef POINTLESS\n"
" b0 = f(x, y, z);\n" // one statement in clause
"`endif\n"
" a1 = b.x;\n"
"endfunction",
"function void preprocess_statement_test();\n"
" a0 = b.x;\n"
"`ifdef POINTLESS\n"
" b0 = f(x, y, z);\n" // multiple statements in clause
" b1 = g(y, x, z);\n"
"`endif\n"
" a1 = b.x;\n"
"endfunction",
"function void preprocess_statement_test();\n"
" a0 = b.x;\n"
"`ifdef POINTLESS\n"
" b0 = f(x, y, z);\n" // multiple statements in clause
" b1 = g(y, x, z);\n"
"`elsif DUMB\n"
" c0 = pp(x, y);\n" // multiple statements in clause
" c1 = qq(y, x);\n"
"`else\n"
" d0 = fg(\"error\");\n" // multiple statements in clause
" d1 = gf(13);\n"
"`endif\n"
" a1 = b.x;\n"
"endfunction",
"function net_type_decls;\n"
" nettype shortreal analog_wire;\n"
"endfunction\n",
"function net_type_decls;\n"
" nettype foo::bar[1:0] analog_wire with fire;\n"
"endfunction\n",
};
static const ParserTestCaseArray kTaskTests = {
"task task_a;\n"
"endtask",
"task static task_a;\n"
"endtask",
"task automatic task_a;\n"
"endtask",
"task flask;\n"
"input [7:0] intake;\n"
"output [7:0] outtake [3:0];\n"
"endtask",
"task convertCtoF;\n"
"input [7:0] temp_in;\n"
"output [7:0] temp_out;\n"
"begin\n"
" temp_out = ((9/5) *temp_in) + 32;\n"
"end\n"
"endtask",
// interface task
"task intf.task1();\n"
"endtask",
// package import declaration
"task task_a;\n"
" import tb_pkg::*;\n"
"endtask",
"task task_b();\n"
" import tb_pkg::*;\n"
" w_cell cell_q[$];\n"
"endtask",
// various port types
"task spindle;\n"
"input string intake;\n"
"output string [7:0] outtake [3:0];\n"
"endtask",
"task spindle;\n"
"input spkg::StringN#(N) intake;\n"
"output spkg::StringN#(K) [7:0] outtake [3:0];\n"
"endtask",
"task spindle;\n"
"const ref StringType intake;\n" // const ref
"ref StringType [7:0] outtake [3:0];\n" // ref
"endtask",
"task t(virtual foo_if vif);\n"
"endtask\n",
"task t(virtual foo_if#(12) vif);\n"
"endtask\n",
"task t(virtual foo_if#(.W(12)) vif);\n"
"endtask\n",
"task t(virtual interface foo_if vif);\n"
"endtask\n",
"task t(ref virtual foo_if vif);\n"
"endtask\n",
"task t(ref virtual foo_if vifs[]);\n"
"endtask\n",
"task t(ref virtual foo_if vifs[N]);\n"
"endtask\n",
"task t(ref virtual foo_if vifs[N:M]);\n"
"endtask\n",
"task t(ref virtual foo_if vifs[N:M][X:Y]);\n"
"endtask\n",
"task t(ref virtual interface foo_if#(P,Q,R) vifs[N:M][X:Y]);\n"
"endtask\n",
// macro
"task stringer;\n"
" `uvm_error(`gtn, \"frownie =(\")\n" // string with balance character
"endtask",
"task stringer;\n"
" `undef ERROR\n" // preprocessor
"endtask",
// local variables, various qualifiers
"task variable_soup;\n"
"int a_count;\n"
"const int b_count;\n"
"var int c_count;\n"
"static int d_count;\n"
"automatic bool e_enabled;\n"
"const static string incantation;\n"
"static const string cheer = \"Go!\";\n"
"const var automatic string password;\n"
"endtask",
// example referencing globals
"reg [7:0] tempC;\n"
"reg [7:0] tempF;\n"
"task convertCtoF;\n"
"begin\n"
" tempF = ((9/5) *tempC) + 32;\n"
"end\n"
"endtask",
"task swap;\n"
"inout a, b;\n"
"reg temp;\n"
"begin\n"
" temp = a;\n"
" a = b;\n"
" b = temp;\n"
"end\n"
"endtask",
// queue reference
"task queue_or_not_to_queue;\n"
" if(item_to_queue.count < request_queue[$].count) begin\n"
" end\n"
"endtask",
"task queue_or_not_to_queue;\n"
" x_fifo = x_fifo[$-Line_width/2:$];\n"
" t_fifo[line] = t_fifo[line][0:$-Line_width/2];\n"
"endtask",
// expect property statements
"task great_expectations;\n"
" expect ( B |-> C );\n"
" expect ( C |-> A ) else sleep();\n"
"endtask",
// case statements
"task mysterious_case;\n"
"input a;\n"