-
Notifications
You must be signed in to change notification settings - Fork 0
/
VParseBison.y
4620 lines (4019 loc) · 165 KB
/
VParseBison.y
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
// -*- C++ -*-
//*************************************************************************
// DESCRIPTION: Verilog-Perl bison parser
//
// This file is part of Verilog-Perl.
//
// Author: Wilson Snyder <wsnyder@wsnyder.org>
//
// Code available from: http://www.veripool.org/systemperl
//
//*************************************************************************
//
// Copyright 2001-2012 by Wilson Snyder. This program is free software;
// you can redistribute it and/or modify it under the terms of either the GNU
// Lesser General Public License Version 3 or the Perl Artistic License Version 2.0.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
//*************************************************************************
%{
#include <cstdio>
#include <fstream>
#include <stack>
#include <vector>
#include <map>
#include <deque>
#include <cassert>
#include "VParse.h"
#include "VParseGrammar.h"
#define YYERROR_VERBOSE 1
#define YYINITDEPTH 5000 // Large as the stack won't grow, since YYSTYPE_IS_TRIVIAL isn't defined
#define YYMAXDEPTH 5000
// See VParseGrammar.h for the C++ interface to this parser
// Include that instead of VParseBison.h
//*************************************************************************
#define GRAMMARP VParseGrammar::staticGrammarp()
#define PARSEP VParseGrammar::staticParsep()
#define NEWSTRING(text) (string((text)))
#define SPACED(a,b) ((a)+(((a)=="" || (b)=="")?"":" ")+(b))
#define VARRESET_LIST(decl) { GRAMMARP->pinNum(1); VARRESET(); VARDECL(decl); } // Start of pinlist
#define VARRESET_NONLIST(decl) { GRAMMARP->pinNum(0); VARRESET(); VARDECL(decl); } // Not in a pinlist
#define VARRESET() { VARDECL(""); VARIO(""); VARNET(""); VARDTYPE(""); } // Start of one variable decl
// VARDECL("") indicates inside a port list or IO list and we shouldn't declare the variable
#define VARDECL(type) { GRAMMARP->m_varDecl = (type); } // genvar, parameter, localparam
#define VARIO(type) { GRAMMARP->m_varIO = (type); } // input, output, inout, ref, const ref
#define VARNET(type) { GRAMMARP->m_varNet = (type); } // supply*,wire,tri
#define VARDTYPE(type) { GRAMMARP->m_varDType = (type); } // "signed", "int", etc
#define PINNUMINC() { GRAMMARP->pinNumInc(); }
#define INSTPREP(cellmod,cellparam) { GRAMMARP->pinNum(1); GRAMMARP->m_cellMod=(cellmod); GRAMMARP->m_cellParam=(cellparam); }
static void VARDONE(VFileLine* fl, const string& name, const string& array, const string& value) {
if (GRAMMARP->m_varIO!="" && GRAMMARP->m_varDecl=="") GRAMMARP->m_varDecl="port";
if (GRAMMARP->m_varDecl!="") {
PARSEP->varCb(fl, GRAMMARP->m_varDecl, name, PARSEP->symObjofUpward(), GRAMMARP->m_varNet,
GRAMMARP->m_varDType, array, value);
}
if (GRAMMARP->m_varIO!="" || GRAMMARP->pinNum()) {
PARSEP->portCb(fl, name, PARSEP->symObjofUpward(),
GRAMMARP->m_varIO, GRAMMARP->m_varDType, array, GRAMMARP->pinNum());
}
if (GRAMMARP->m_varDType == "type") {
PARSEP->syms().replaceInsert(VAstType::TYPE,name);
}
}
static void VARDONETYPEDEF(VFileLine* fl, const string& name, const string& type, const string& array) {
VARRESET(); VARDECL("typedef"); VARDTYPE(type);
VARDONE(fl,name,array,"");
// TYPE shouldn't override a more specific node type, as often is forward reference
PARSEP->syms().replaceInsert(VAstType::TYPE,name);
}
static void PINDONE(VFileLine* fl, const string& name, const string& expr) {
if (GRAMMARP->m_cellParam) {
// Stack them until we create the instance itself
GRAMMARP->m_pinStack.push_back(VParseGPin(fl, name, expr, GRAMMARP->pinNum()));
} else {
PARSEP->pinCb(fl, name, expr, GRAMMARP->pinNum());
}
}
static void PINPARAMS() {
// Throw out all the pins we found before we could do instanceCb
while (!GRAMMARP->m_pinStack.empty()) {
VParseGPin& pinr = GRAMMARP->m_pinStack.front();
PARSEP->parampinCb(pinr.m_fl, pinr.m_name, pinr.m_conn, pinr.m_number);
GRAMMARP->m_pinStack.pop_front();
}
}
/* Yacc */
static int VParseBisonlex(VParseBisonYYSType* yylvalp) { return PARSEP->lexToBison(yylvalp); }
static void VParseBisonerror(const char *s) { VParseGrammar::bisonError(s); }
static void ERRSVKWD(VFileLine* fileline, const string& tokname) {
static int toldonce = 0;
fileline->error((string)"Unexpected \""+tokname+"\": \""+tokname+"\" is a SystemVerilog keyword misused as an identifier.");
if (!toldonce++) fileline->error("Modify the Verilog-2001 code to avoid SV keywords, or use `begin_keywords or --language.");
}
static void NEED_S09(VFileLine*, const string&) {
//Let lint tools worry about it
//fileline->error((string)"Advanced feature: \""+tokname+"\" is a 1800-2009 construct, but used under --lanugage 1800-2005 or earlier.");
}
%}
%pure_parser
%token_table
BISONPRE_VERSION(2.4, %define lr.keep_unreachable_states)
// When writing Bison patterns we use yTOKEN instead of "token",
// so Bison will error out on unknown "token"s.
// Generic lexer tokens, for example a number
// IEEE: real_number
%token<str> yaFLOATNUM "FLOATING-POINT NUMBER"
// IEEE: identifier, class_identifier, class_variable_identifier,
// covergroup_variable_identifier, dynamic_array_variable_identifier,
// enum_identifier, interface_identifier, interface_instance_identifier,
// package_identifier, type_identifier, variable_identifier,
%token<str> yaID__ETC "IDENTIFIER"
%token<str> yaID__LEX "IDENTIFIER-in-lex"
%token<str> yaID__aCLASS "CLASS-IDENTIFIER"
%token<str> yaID__aCOVERGROUP "COVERGROUP-IDENTIFIER"
%token<str> yaID__aPACKAGE "PACKAGE-IDENTIFIER"
%token<str> yaID__aTYPE "TYPE-IDENTIFIER"
// Can't predecode aFUNCTION, can declare after use
// Can't predecode aINTERFACE, can declare after use
// Can't predecode aTASK, can declare after use
// IEEE: integral_number
%token<str> yaINTNUM "INTEGER NUMBER"
// IEEE: time_literal + time_unit
%token<str> yaTIMENUM "TIME NUMBER"
// IEEE: string_literal
%token<str> yaSTRING "STRING"
%token<str> yaSTRING__IGNORE "STRING-ignored" // Used when expr:string not allowed
%token<str> yaTIMINGSPEC "TIMING SPEC ELEMENT"
%token<str> ygenGATE "GATE keyword"
%token<str> ygenCONFIGKEYWORD "CONFIG keyword (cell/use/design/etc)"
%token<str> ygenOPERATOR "OPERATOR"
%token<str> ygenSTRENGTH "STRENGTH keyword (strong1/etc)"
%token<str> ygenSYSCALL "SYSCALL"
%token<str> '!'
%token<str> '#'
%token<str> '%'
%token<str> '&'
%token<str> '('
%token<str> ')'
%token<str> '*'
%token<str> '+'
%token<str> ','
%token<str> '-'
%token<str> '.'
%token<str> '/'
%token<str> ':'
%token<str> ';'
%token<str> '<'
%token<str> '='
%token<str> '>'
%token<str> '?'
%token<str> '@'
%token<str> '['
%token<str> ']'
%token<str> '^'
%token<str> '{'
%token<str> '|'
%token<str> '}'
%token<str> '~'
// Specific keywords
// yKEYWORD means match "keyword"
// Other cases are yXX_KEYWORD where XX makes it unique,
// for example yP_ for punctuation based operators.
// Double underscores "yX__Y" means token X followed by Y,
// and "yX__ETC" means X folled by everything but Y(s).
%token<str> yACCEPT_ON "accept_on"
%token<str> yALIAS "alias"
%token<str> yALWAYS "always"
%token<str> yAND "and"
%token<str> yASSERT "assert"
%token<str> yASSIGN "assign"
%token<str> yASSUME "assume"
%token<str> yAUTOMATIC "automatic"
%token<str> yBEFORE "before"
%token<str> yBEGIN "begin"
%token<str> yBIND "bind"
%token<str> yBINS "bins"
%token<str> yBINSOF "binsof"
%token<str> yBIT "bit"
%token<str> yBREAK "break"
%token<str> yBUF "buf"
%token<str> yBYTE "byte"
%token<str> yCASE "case"
%token<str> yCASEX "casex"
%token<str> yCASEZ "casez"
%token<str> yCHANDLE "chandle"
%token<str> yCHECKER "checker"
%token<str> yCLASS "class"
%token<str> yCLOCK "clock"
%token<str> yCLOCKING "clocking"
%token<str> yCONSTRAINT "constraint"
%token<str> yCONST__ETC "const"
%token<str> yCONST__LEX "const-in-lex"
%token<str> yCONST__LOCAL "const-then-local"
%token<str> yCONST__REF "const-then-ref"
%token<str> yCONTEXT "context"
%token<str> yCONTINUE "continue"
%token<str> yCOVER "cover"
%token<str> yCOVERGROUP "covergroup"
%token<str> yCOVERPOINT "coverpoint"
%token<str> yCROSS "cross"
%token<str> yDEASSIGN "deassign"
%token<str> yDEFAULT "default"
%token<str> yDEFPARAM "defparam"
%token<str> yDISABLE "disable"
%token<str> yDIST "dist"
%token<str> yDO "do"
%token<str> yEDGE "edge"
%token<str> yELSE "else"
%token<str> yEND "end"
%token<str> yENDCASE "endcase"
%token<str> yENDCHECKER "endchecker"
%token<str> yENDCLASS "endclass"
%token<str> yENDCLOCKING "endclocking"
%token<str> yENDFUNCTION "endfunction"
%token<str> yENDGENERATE "endgenerate"
%token<str> yENDGROUP "endgroup"
%token<str> yENDINTERFACE "endinterface"
%token<str> yENDMODULE "endmodule"
%token<str> yENDPACKAGE "endpackage"
%token<str> yENDPROGRAM "endprogram"
%token<str> yENDPROPERTY "endproperty"
%token<str> yENDSEQUENCE "endsequence"
%token<str> yENDSPECIFY "endspecify"
%token<str> yENDTABLE "endtable"
%token<str> yENDTASK "endtask"
%token<str> yENUM "enum"
%token<str> yEVENT "event"
%token<str> yEVENTUALLY "eventually"
%token<str> yEXPECT "expect"
%token<str> yEXPORT "export"
%token<str> yEXTENDS "extends"
%token<str> yEXTERN "extern"
%token<str> yFINAL "final"
%token<str> yFIRST_MATCH "first_match"
%token<str> yFOR "for"
%token<str> yFORCE "force"
%token<str> yFOREACH "foreach"
%token<str> yFOREVER "forever"
%token<str> yFORK "fork"
%token<str> yFORKJOIN "forkjoin"
%token<str> yFUNCTION__ETC "function"
%token<str> yFUNCTION__LEX "function-in-lex"
%token<str> yFUNCTION__aPUREV "function-is-pure-virtual"
%token<str> yGENERATE "generate"
%token<str> yGENVAR "genvar"
%token<str> yGLOBAL__CLOCKING "global-then-clocking"
%token<str> yGLOBAL__LEX "global-in-lex"
%token<str> yIF "if"
%token<str> yIFF "iff"
%token<str> yIGNORE_BINS "ignore_bins"
%token<str> yILLEGAL_BINS "illegal_bins"
%token<str> yIMPLIES "implies"
%token<str> yIMPORT "import"
%token<str> yINITIAL "initial"
%token<str> yINOUT "inout"
%token<str> yINPUT "input"
%token<str> yINSIDE "inside"
%token<str> yINT "int"
%token<str> yINTEGER "integer"
%token<str> yINTERFACE "interface"
%token<str> yINTERSECT "intersect"
%token<str> yJOIN "join"
%token<str> yLET "let"
%token<str> yLOCAL__COLONCOLON "local-then-::"
%token<str> yLOCAL__ETC "local"
%token<str> yLOCAL__LEX "local-in-lex"
%token<str> yLOCALPARAM "localparam"
%token<str> yLOGIC "logic"
%token<str> yLONGINT "longint"
%token<str> yMATCHES "matches"
%token<str> yMODPORT "modport"
%token<str> yMODULE "module"
%token<str> yNAND "nand"
%token<str> yNEGEDGE "negedge"
%token<str> yNEW__ETC "new"
%token<str> yNEW__LEX "new-in-lex"
%token<str> yNEW__PAREN "new-then-paren"
%token<str> yNEXTTIME "nexttime"
%token<str> yNOR "nor"
%token<str> yNOT "not"
%token<str> yNULL "null"
%token<str> yOR "or"
%token<str> yOUTPUT "output"
%token<str> yPACKAGE "package"
%token<str> yPACKED "packed"
%token<str> yPARAMETER "parameter"
%token<str> yPOSEDGE "posedge"
%token<str> yPRIORITY "priority"
%token<str> yPROGRAM "program"
%token<str> yPROPERTY "property"
%token<str> yPROTECTED "protected"
%token<str> yPURE "pure"
%token<str> yRAND "rand"
%token<str> yRANDC "randc"
%token<str> yRANDCASE "randcase"
%token<str> yRANDSEQUENCE "randsequence"
%token<str> yREAL "real"
%token<str> yREALTIME "realtime"
%token<str> yREF "ref"
%token<str> yREG "reg"
%token<str> yREJECT_ON "reject_on"
%token<str> yRELEASE "release"
%token<str> yREPEAT "repeat"
%token<str> yRESTRICT "restrict"
%token<str> yRETURN "return"
%token<str> ySCALARED "scalared"
%token<str> ySEQUENCE "sequence"
%token<str> ySHORTINT "shortint"
%token<str> ySHORTREAL "shortreal"
%token<str> ySIGNED "signed"
%token<str> ySOLVE "solve"
%token<str> ySPECIFY "specify"
%token<str> ySPECPARAM "specparam"
%token<str> ySTATIC__CONSTRAINT "static-then-constraint"
%token<str> ySTATIC__ETC "static"
%token<str> ySTATIC__LEX "static-in-lex"
%token<str> ySTRING "string"
%token<str> ySTRONG "strong"
%token<str> ySTRUCT "struct"
%token<str> ySUPER "super"
%token<str> ySUPPLY0 "supply0"
%token<str> ySUPPLY1 "supply1"
%token<str> ySYNC_ACCEPT_ON "sync_accept_on"
%token<str> ySYNC_REJECT_ON "sync_reject_on"
%token<str> yS_ALWAYS "s_always"
%token<str> yS_EVENTUALLY "s_eventually"
%token<str> yS_NEXTTIME "s_nexttime"
%token<str> yS_UNTIL "s_until"
%token<str> yS_UNTIL_WITH "s_until_with"
%token<str> yTABLE "table"
%token<str> yTAGGED "tagged"
%token<str> yTASK__ETC "task"
%token<str> yTASK__LEX "task-in-lex"
%token<str> yTASK__aPUREV "task-is-pure-virtual"
%token<str> yTHIS "this"
%token<str> yTHROUGHOUT "throughout"
%token<str> yTIME "time"
%token<str> yTIMEPRECISION "timeprecision"
%token<str> yTIMEUNIT "timeunit"
%token<str> yTRI "tri"
%token<str> yTRI0 "tri0"
%token<str> yTRI1 "tri1"
%token<str> yTRIAND "triand"
%token<str> yTRIOR "trior"
%token<str> yTRIREG "trireg"
%token<str> yTYPE "type"
%token<str> yTYPEDEF "typedef"
%token<str> yUNION "union"
%token<str> yUNIQUE "unique"
%token<str> yUNIQUE0 "unique0"
%token<str> yUNSIGNED "unsigned"
%token<str> yUNTIL "until"
%token<str> yUNTIL_WITH "until_with"
%token<str> yUNTYPED "untyped"
%token<str> yVAR "var"
%token<str> yVECTORED "vectored"
%token<str> yVIRTUAL__CLASS "virtual-then-class"
%token<str> yVIRTUAL__ETC "virtual"
%token<str> yVIRTUAL__INTERFACE "virtual-then-interface"
%token<str> yVIRTUAL__LEX "virtual-in-lex"
%token<str> yVIRTUAL__anyID "virtual-then-identifier"
%token<str> yVOID "void"
%token<str> yWAIT "wait"
%token<str> yWAIT_ORDER "wait_order"
%token<str> yWAND "wand"
%token<str> yWEAK "weak"
%token<str> yWHILE "while"
%token<str> yWILDCARD "wildcard"
%token<str> yWIRE "wire"
%token<str> yWITHIN "within"
%token<str> yWITH__BRA "with-then-["
%token<str> yWITH__CUR "with-then-{"
%token<str> yWITH__ETC "with"
%token<str> yWITH__LEX "with-in-lex"
%token<str> yWITH__PAREN "with-then-("
%token<str> yWOR "wor"
%token<str> yXNOR "xnor"
%token<str> yXOR "xor"
%token<str> yD_ERROR "$error"
%token<str> yD_FATAL "$fatal"
%token<str> yD_INFO "$info"
%token<str> yD_ROOT "$root"
%token<str> yD_UNIT "$unit"
%token<str> yD_WARNING "$warning"
%token<str> yP_TICK "'"
%token<str> yP_TICKBRA "'{"
%token<str> yP_OROR "||"
%token<str> yP_ANDAND "&&"
%token<str> yP_NOR "~|"
%token<str> yP_XNOR "^~"
%token<str> yP_NAND "~&"
%token<str> yP_EQUAL "=="
%token<str> yP_NOTEQUAL "!="
%token<str> yP_CASEEQUAL "==="
%token<str> yP_CASENOTEQUAL "!=="
%token<str> yP_WILDEQUAL "==?"
%token<str> yP_WILDNOTEQUAL "!=?"
%token<str> yP_GTE ">="
%token<str> yP_LTE "<="
%token<str> yP_LTE__IGNORE "<=-ignored" // Used when expr:<= means assignment
%token<str> yP_SLEFT "<<"
%token<str> yP_SRIGHT ">>"
%token<str> yP_SSRIGHT ">>>"
%token<str> yP_POW "**"
%token<str> yP_PAR__IGNORE "(-ignored" // Used when sequence_expr:expr:( is ignored
%token<str> yP_PAR__STRENGTH "(-for-strength"
%token<str> yP_LTMINUSGT "<->"
%token<str> yP_PLUSCOLON "+:"
%token<str> yP_MINUSCOLON "-:"
%token<str> yP_MINUSGT "->"
%token<str> yP_MINUSGTGT "->>"
%token<str> yP_EQGT "=>"
%token<str> yP_ASTGT "*>"
%token<str> yP_ANDANDAND "&&&"
%token<str> yP_POUNDPOUND "##"
%token<str> yP_POUNDMINUSPD "#-#"
%token<str> yP_POUNDEQPD "#=#"
%token<str> yP_DOTSTAR ".*"
%token<str> yP_ATAT "@@"
%token<str> yP_COLONCOLON "::"
%token<str> yP_COLONEQ ":="
%token<str> yP_COLONDIV ":/"
%token<str> yP_ORMINUSGT "|->"
%token<str> yP_OREQGT "|=>"
%token<str> yP_BRASTAR "[*"
%token<str> yP_BRAEQ "[="
%token<str> yP_BRAMINUSGT "[->"
%token<str> yP_BRAPLUSKET "[+]"
%token<str> yP_PLUSPLUS "++"
%token<str> yP_MINUSMINUS "--"
%token<str> yP_PLUSEQ "+="
%token<str> yP_MINUSEQ "-="
%token<str> yP_TIMESEQ "*="
%token<str> yP_DIVEQ "/="
%token<str> yP_MODEQ "%="
%token<str> yP_ANDEQ "&="
%token<str> yP_OREQ "|="
%token<str> yP_XOREQ "^="
%token<str> yP_SLEFTEQ "<<="
%token<str> yP_SRIGHTEQ ">>="
%token<str> yP_SSRIGHTEQ ">>>="
// '( is not a operator, as "' (" is legal
//********************
// Verilog op precedence
%token<str> prUNARYARITH
%token<str> prREDUCTION
%token<str> prNEGATION
%token<str> prEVENTBEGIN
%token<str> prTAGGED
// These prevent other conflicts
%left yP_ANDANDAND
%left yMATCHES
%left prTAGGED
%left prSEQ_CLOCKING
// Lowest precedence
// These are in IEEE 17.7.1
%nonassoc yALWAYS yS_ALWAYS yEVENTUALLY yS_EVENTUALLY yACCEPT_ON yREJECT_ON ySYNC_ACCEPT_ON ySYNC_REJECT_ON
%right yP_ORMINUSGT yP_OREQGT yP_POUNDMINUSPD yP_POUNDEQPD
%right yUNTIL yS_UNTIL yUNTIL_WITH yS_UNTIL_WITH yIMPLIES
%right yIFF
%left yOR
%left yAND
%nonassoc yNOT yNEXTTIME yS_NEXTTIME
%left yINTERSECT
%left yWITHIN
%right yTHROUGHOUT
%left prPOUNDPOUND_MULTI
%left yP_POUNDPOUND
%left yP_BRASTAR yP_BRAEQ yP_BRAMINUSGT yP_BRAPLUSKET
// Not specified, but needed higher than yOR, lower than normal non-pexpr expressions
%left yPOSEDGE yNEGEDGE yEDGE
%left '{' '}'
//%nonassoc '=' yP_PLUSEQ yP_MINUSEQ yP_TIMESEQ yP_DIVEQ yP_MODEQ yP_ANDEQ yP_OREQ yP_XOREQ yP_SLEFTEQ yP_SRIGHTEQ yP_SSRIGHTEQ yP_COLONEQ yP_COLONDIV yP_LTE
%right yP_MINUSGT yP_LTMINUSGT
%right '?' ':'
%left yP_OROR
%left yP_ANDAND
%left '|' yP_NOR
%left '^' yP_XNOR
%left '&' yP_NAND
%left yP_EQUAL yP_NOTEQUAL yP_CASEEQUAL yP_CASENOTEQUAL yP_WILDEQUAL yP_WILDNOTEQUAL
%left '>' '<' yP_GTE yP_LTE yP_LTE__IGNORE yINSIDE yDIST
%left yP_SLEFT yP_SRIGHT yP_SSRIGHT
%left '+' '-'
%left '*' '/' '%'
%left yP_POW
%left prUNARYARITH yP_MINUSMINUS yP_PLUSPLUS prREDUCTION prNEGATION
%left '.'
// Not in IEEE, but need to avoid conflicts; TICK should bind tightly just lower than COLONCOLON
%left yP_TICK
//%left '(' ')' '[' ']' yP_COLONCOLON '.'
%nonassoc prLOWER_THAN_ELSE
%nonassoc yELSE
//BISONPRE_TYPES
// Blank lines for type insertion
// Blank lines for type insertion
// Blank lines for type insertion
// Blank lines for type insertion
// Blank lines for type insertion
// Blank lines for type insertion
%start source_text
%%
//**********************************************************************
// Feedback to the Lexer
// Note we read a parenthesis ahead, so this may not change the lexer at the right point.
statePushVlg: // For PSL lexing, escape current state into Verilog state
/* empty */ { }
;
statePop: // Return to previous lexing state
/* empty */ { }
;
//**********************************************************************
// Files
source_text: // ==IEEE: source_text
/* empty */ { }
// // timeunits_declaration moved into description:package_item
| descriptionList { }
;
descriptionList: // IEEE: part of source_text
description { }
| descriptionList description { }
;
description: // ==IEEE: description
module_declaration { }
// // udp_declaration moved into module_declaration
| interface_declaration { }
| program_declaration { }
| package_declaration { }
| package_item { }
| bind_directive { }
// unsupported // IEEE: config_declaration
| error { }
;
timeunits_declaration: // ==IEEE: timeunits_declaration
yTIMEUNIT yaTIMENUM ';' { }
| yTIMEUNIT yaTIMENUM '/' yaTIMENUM ';' { NEED_S09($<fl>1,"timeunit /"); }
| yTIMEPRECISION yaTIMENUM ';' { }
;
//**********************************************************************
// Packages
package_declaration: // ==IEEE: package_declaration
packageFront package_itemListE yENDPACKAGE endLabelE
{ PARSEP->endpackageCb($<fl>3,$3);
PARSEP->symPopScope(VAstType::PACKAGE); }
;
packageFront:
// // Lifetime is 1800-2009
yPACKAGE lifetimeE idAny ';'
{ PARSEP->symPushNew(VAstType::PACKAGE, $3);
PARSEP->packageCb($<fl>1,$1, $3); }
;
package_itemListE: // IEEE: [{ package_item }]
/* empty */ { }
| package_itemList { }
;
package_itemList: // IEEE: { package_item }
package_item { }
| package_itemList package_item { }
;
package_item: // ==IEEE: package_item
package_or_generate_item_declaration { }
| anonymous_program { }
| package_export_declaration { }
| timeunits_declaration { }
;
package_or_generate_item_declaration: // ==IEEE: package_or_generate_item_declaration
net_declaration { }
| data_declaration { }
| task_declaration { }
| function_declaration { }
| checker_declaration { }
| dpi_import_export { }
| extern_constraint_declaration { }
| class_declaration { }
// // class_constructor_declaration is part of function_declaration
| local_parameter_declaration ';' { }
| parameter_declaration ';' { }
| covergroup_declaration { }
| overload_declaration { }
| assertion_item_declaration { }
| ';' { }
;
package_import_declarationList:
package_import_declaration { }
| package_import_declarationList ',' package_import_declaration { }
;
package_import_declaration: // ==IEEE: package_import_declaration
yIMPORT package_import_itemList ';' { }
;
package_import_itemList:
package_import_item { }
| package_import_itemList ',' package_import_item { }
;
package_import_item: // ==IEEE: package_import_item
yaID__aPACKAGE yP_COLONCOLON package_import_itemObj
{ PARSEP->syms().import($<fl>1,$1,$3);
PARSEP->importCb($<fl>1,$1,$3); }
;
package_import_itemObj<str>: // IEEE: part of package_import_item
idAny { $<fl>$=$<fl>1; $$=$1; }
| '*' { $<fl>$=$<fl>1; $$=$1; }
;
package_export_declaration<str>: // IEEE: package_export_declaration
yEXPORT '*' yP_COLONCOLON '*' ';' { }
| yEXPORT package_import_itemList ';' { }
;
//**********************************************************************
// Module headers
module_declaration: // ==IEEE: module_declaration
// // timeunits_declaration instead in module_item
// // IEEE: module_nonansi_header + module_ansi_header
modFront importsAndParametersE portsStarE ';'
module_itemListE yENDMODULE endLabelE
{ PARSEP->endmoduleCb($<fl>6,$6);
PARSEP->symPopScope(VAstType::MODULE); }
//
| yEXTERN modFront importsAndParametersE portsStarE ';'
{ PARSEP->symPopScope(VAstType::MODULE); }
;
modFront:
// // General note: all *Front functions must call symPushNew before
// // any formal arguments, as the arguments must land in the new scope.
yMODULE lifetimeE idAny
{ PARSEP->symPushNew(VAstType::MODULE, $3);
PARSEP->moduleCb($<fl>1,$1,$3,false,PARSEP->inCellDefine()); }
;
importsAndParametersE: // IEEE: common part of module_declaration, interface_declaration, program_declaration
// // { package_import_declaration } [ parameter_port_list ]
parameter_port_listE { }
| package_import_declarationList parameter_port_listE { }
;
parameter_value_assignmentE: // IEEE: [ parameter_value_assignment ]
/* empty */ { }
| '#' '(' cellpinList ')' { }
// // Side effect of combining *_instantiations
| '#' delay_value { }
;
parameter_port_listE: // IEEE: parameter_port_list + empty == parameter_value_assignment
/* empty */ { }
| '#' '(' ')' { }
// // IEEE: '#' '(' list_of_param_assignments { ',' parameter_port_declaration } ')'
// // IEEE: '#' '(' parameter_port_declaration { ',' parameter_port_declaration } ')'
// // Can't just do that as "," conflicts with between vars and between stmts, so
// // split into pre-comma and post-comma parts
| '#' '(' {VARRESET_LIST("parameter");} paramPortDeclOrArgList ')' { VARRESET_NONLIST(""); }
// // Note legal to start with "a=b" with no parameter statement
;
paramPortDeclOrArgList: // IEEE: list_of_param_assignments + { parameter_port_declaration }
paramPortDeclOrArg { }
| paramPortDeclOrArgList ',' paramPortDeclOrArg { }
;
paramPortDeclOrArg: // IEEE: param_assignment + parameter_port_declaration
// // We combine the two as we can't tell which follows a comma
param_assignment { }
| parameter_port_declarationFront param_assignment { }
;
portsStarE: // IEEE: .* + list_of_ports + list_of_port_declarations + empty
/* empty */ { }
// // .* expanded from module_declaration
// // '(' ')' handled by list_of_ports:portE
| '(' yP_DOTSTAR ')' { }
| '(' {VARRESET_LIST("");} list_of_portsE ')' { VARRESET_NONLIST(""); }
;
list_of_portsE: // IEEE: list_of_ports + list_of_port_declarations
portE { }
| list_of_portsE ',' portE { }
;
portE: // ==IEEE: [ port ]
// // Though not type for interfaces, we factor out the port direction and type
// // so we can simply handle it in one place
//
// // IEEE: interface_port_header port_identifier { unpacked_dimension }
// // Expanded interface_port_header
// // We use instantCb here because the non-port form looks just like a module instantiation
/* empty */ { }
| portDirNetE id/*interface*/ idAny/*port*/ rangeListE sigAttrListE
{ VARDTYPE($2); VARIO("interface"); VARDONE($<fl>2, $3, $4, ""); PINNUMINC();
PARSEP->instantCb($<fl>2, $2, $3, $4); PARSEP->endcellCb($<fl>2,""); }
| portDirNetE yINTERFACE idAny/*port*/ rangeListE sigAttrListE
{ VARDTYPE($2); VARIO("interface"); VARDONE($<fl>2, $3, $4, ""); PINNUMINC(); }
| portDirNetE id/*interface*/ '.' idAny/*modport*/ idAny/*port*/ rangeListE sigAttrListE
{ VARDTYPE($2+"."+$4); VARIO("interface"); VARDONE($<fl>2, $5, $6, ""); PINNUMINC();
PARSEP->instantCb($<fl>2, $2, $5, $6); PARSEP->endcellCb($<fl>2,""); }
| portDirNetE yINTERFACE '.' idAny/*modport*/ idAny/*port*/ rangeListE sigAttrListE
{ VARDTYPE($2+"."+$4); VARIO("interface"); VARDONE($<fl>2, $5, $6, ""); PINNUMINC(); }
//
// // IEEE: ansi_port_declaration, with [port_direction] removed
// // IEEE: [ net_port_header | interface_port_header ] port_identifier { unpacked_dimension } [ '=' constant_expression ]
// // IEEE: [ net_port_header | variable_port_header ] '.' port_identifier '(' [ expression ] ')'
// // IEEE: [ variable_port_header ] port_identifier { variable_dimension } [ '=' constant_expression ]
// // Substitute net_port_header = [ port_direction ] net_port_type
// // Substitute variable_port_header = [ port_direction ] variable_port_type
// // Substitute net_port_type = [ net_type ] data_type_or_implicit
// // Substitute variable_port_type = var_data_type
// // [ [ port_direction ] net_port_type | interface_port_header ] port_identifier { unpacked_dimension }
// // [ [ port_direction ] var_data_type ] port_identifier variable_dimensionListE [ '=' constant_expression ]
// // [ [ port_direction ] net_port_type | [ port_direction ] var_data_type ] '.' port_identifier '(' [ expression ] ')'
//
// // Remove optional '[...] id' is in portAssignment
// // Remove optional '[port_direction]' is in port
// // net_port_type | interface_port_header port_identifier { unpacked_dimension }
// // net_port_type | interface_port_header port_identifier { unpacked_dimension }
// // var_data_type port_identifier variable_dimensionListE [ '=' constExpr ]
// // net_port_type | [ port_direction ] var_data_type '.' port_identifier '(' [ expr ] ')'
// // Expand implicit_type
//
// // variable_dimensionListE instead of rangeListE to avoid conflicts
//
// // Note implicit rules looks just line declaring additional followon port
// // No VARDECL("port") for implicit, as we don't want to declare variables for them
| portDirNetE var_data_type '.' portSig '(' portAssignExprE ')' sigAttrListE { VARDTYPE($2); VARDONE($<fl>4, $4, "", ""); PINNUMINC(); }
| portDirNetE signingE rangeList '.' portSig '(' portAssignExprE ')' sigAttrListE { VARDTYPE(SPACED($2,$3)); VARDONE($<fl>5, $5, "", ""); PINNUMINC(); }
| portDirNetE /*implicit*/ '.' portSig '(' portAssignExprE ')' sigAttrListE { /*VARDTYPE-same*/ VARDONE($<fl>3, $3, "", ""); PINNUMINC(); }
//
| portDirNetE var_data_type portSig variable_dimensionListE sigAttrListE { VARDTYPE($2); VARDONE($<fl>3, $3, $4, ""); PINNUMINC(); }
| portDirNetE signingE rangeList portSig variable_dimensionListE sigAttrListE { VARDTYPE(SPACED($2,$3)); VARDONE($<fl>4, $4, $5, ""); PINNUMINC(); }
| portDirNetE /*implicit*/ portSig variable_dimensionListE sigAttrListE { /*VARDTYPE-same*/ VARDONE($<fl>2, $2, $3, ""); PINNUMINC(); }
//
| portDirNetE var_data_type portSig variable_dimensionListE sigAttrListE '=' constExpr { VARDTYPE($2); VARDONE($<fl>3, $3, $4, $7); PINNUMINC(); }
| portDirNetE signingE rangeList portSig variable_dimensionListE sigAttrListE '=' constExpr { VARDTYPE(SPACED($2,$3)); VARDONE($<fl>4, $4, $5, $8); PINNUMINC(); }
| portDirNetE /*implicit*/ portSig variable_dimensionListE sigAttrListE '=' constExpr { /*VARDTYPE-same*/ VARDONE($<fl>2, $2, $3, $6); PINNUMINC(); }
//
| '{' list_of_portsE '}' { }
;
portDirNetE: // IEEE: part of port, optional net type and/or direction
/* empty */ { }
// // Per spec, if direction given default the nettype.
// // The higher level rule may override this VARDTYPE with one later in the parse.
| port_direction { VARDTYPE(""/*default_nettype*/); }
| port_direction net_type { VARDTYPE(""/*default_nettype*/); } // net_type calls VARNET
| net_type { } // net_type calls VARNET
;
port_declNetE: // IEEE: part of port_declaration, optional net type
/* empty */ { }
| net_type { } // net_type calls VARNET
;
portAssignExprE: // IEEE: part of port, optional expression
/* empty */ { }
| expr { }
;
portSig<str>:
id/*port*/ { $<fl>$=$<fl>1; $$=$1; }
| idSVKwd { $<fl>$=$<fl>1; $$=$1; }
;
//**********************************************************************
// Interface headers
interface_declaration: // IEEE: interface_declaration + interface_nonansi_header + interface_ansi_header:
// // timeunits_delcarationE is instead in interface_item
intFront importsAndParametersE portsStarE ';'
interface_itemListE yENDINTERFACE endLabelE
{ PARSEP->endinterfaceCb($<fl>6, $6);
PARSEP->symPopScope(VAstType::INTERFACE); }
| yEXTERN intFront importsAndParametersE portsStarE ';' { }
;
intFront:
yINTERFACE lifetimeE idAny/*new_interface*/
{ PARSEP->symPushNew(VAstType::INTERFACE,$3);
PARSEP->interfaceCb($<fl>1,$1,$3); }
;
interface_itemListE:
/* empty */ { }
| interface_itemList { }
;
interface_itemList:
interface_item { }
| interface_itemList interface_item { }
;
interface_item: // IEEE: interface_item + non_port_interface_item
port_declaration ';' { }
// // IEEE: non_port_interface_item
| generate_region { }
| interface_or_generate_item { }
| program_declaration { }
| interface_declaration { }
| timeunits_declaration { }
// // See note in interface_or_generate item
| module_common_item { }
;
interface_or_generate_item: // ==IEEE: interface_or_generate_item
// // module_common_item in interface_item, as otherwise duplicated
// // with module_or_generate_item:module_common_item
modport_declaration { }
| extern_tf_declaration { }
;
//**********************************************************************
// Program headers
anonymous_program: // ==IEEE: anonymous_program
// // See the spec - this doesn't change the scope, items still go up "top"
yPROGRAM ';' anonymous_program_itemListE yENDPROGRAM { }
;
anonymous_program_itemListE: // IEEE: { anonymous_program_item }
/* empty */ { }
| anonymous_program_itemList { }
;
anonymous_program_itemList: // IEEE: { anonymous_program_item }
anonymous_program_item { }
| anonymous_program_itemList anonymous_program_item { }
;
anonymous_program_item: // ==IEEE: anonymous_program_item
task_declaration { }
| function_declaration { }
| class_declaration { }
| covergroup_declaration { }
// // class_constructor_declaration is part of function_declaration
| ';' { }
;
program_declaration: // IEEE: program_declaration + program_nonansi_header + program_ansi_header:
// // timeunits_delcarationE is instead in program_item
pgmFront importsAndParametersE portsStarE ';'
program_itemListE yENDPROGRAM endLabelE
{ PARSEP->endprogramCb($<fl>6,$6);
PARSEP->symPopScope(VAstType::PROGRAM); }
| yEXTERN pgmFront importsAndParametersE portsStarE ';'
{ PARSEP->symPopScope(VAstType::PROGRAM); }
;
pgmFront:
yPROGRAM lifetimeE idAny/*new_program*/
{ PARSEP->symPushNew(VAstType::PROGRAM,$3);
PARSEP->programCb($<fl>1,$1, $3);
}
;
program_itemListE: // ==IEEE: [{ program_item }]
/* empty */ { }
| program_itemList { }
;
program_itemList: // ==IEEE: { program_item }
program_item { }
| program_itemList program_item { }
;
program_item: // ==IEEE: program_item
port_declaration ';' { }
| non_port_program_item { }
;
non_port_program_item: // ==IEEE: non_port_program_item
continuous_assign { }
| module_or_generate_item_declaration { }
| initial_construct { }
| final_construct { }
| concurrent_assertion_item { }
| timeunits_declaration { }
| program_generate_item { }
;
program_generate_item: // ==IEEE: program_generate_item
loop_generate_construct { }
| conditional_generate_construct { }
| generate_region { }
| elaboration_system_task { }
;
extern_tf_declaration: // ==IEEE: extern_tf_declaration
yEXTERN task_prototype ';' { }
| yEXTERN function_prototype ';' { }
| yEXTERN yFORKJOIN task_prototype ';' { }
;
modport_declaration: // ==IEEE: modport_declaration
yMODPORT modport_itemList ';' { }
;
modport_itemList: // IEEE: part of modport_declaration
modport_item { }
| modport_itemList ',' modport_item { }
;
modport_item: // ==IEEE: modport_item
modport_idFront '(' {VARRESET_LIST("");} modportPortsDeclList ')'
{ VARRESET_NONLIST("");
PARSEP->endmodportCb($<fl>1, "endmodport");
PARSEP->symPopScope(VAstType::MODPORT); }
;
modport_idFront:
id/*new-modport*/
{ PARSEP->symPushNew(VAstType::MODPORT,$1);
PARSEP->modportCb($<fl>1,"modport",$1); }
;
modportPortsDeclList:
modportPortsDecl { }
| modportPortsDeclList ',' modportPortsDecl { }
;
// IEEE: modport_ports_declaration + modport_simple_ports_declaration
// + (modport_tf_ports_declaration+import_export) + modport_clocking_declaration
// We've expanded the lists each take to instead just have standalone ID ports.
// We track the type as with the V2k series of defines, then create as each ID is seen.
modportPortsDecl:
// // IEEE: modport_simple_ports_declaration
port_direction modportSimplePort { }
// // IEEE: modport_clocking_declaration
| yCLOCKING idAny/*clocking_identifier*/ { }
| yIMPORT modport_tf_port { }
| yEXPORT modport_tf_port { }
// Continuations of above after a comma.
// // IEEE: modport_simple_ports_declaration
| modportSimplePort { }