-
Notifications
You must be signed in to change notification settings - Fork 1
/
grammar.mly
2437 lines (2079 loc) · 72.8 KB
/
grammar.mly
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
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
//*****************************************************************************
//
// DESCRIPTION: Verilog parser ocamlyacc grammar file
//
//*****************************************************************************
//
// Copyright 2010 by Jonathan Kimmitt. This program is free software; you can
// redistribute it and/or modify it under the terms of either the GNU
// General Public License or the Perl Artistic License.
//
// This code 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.
//
//*****************************************************************************
// Based on verilator parser code by Paul Wasson, Duane Galbi and Wilson Snyder
//*****************************************************************************
// Generic void
%token EMPTY
// Generic double
%token<token*token> DOUBLE
// Generic triple
%token<token*token*token> TRIPLE
// Generic quadruple
%token<token*token*token*token> QUADRUPLE
// Generic quintuple
%token<token*token*token*token*token> QUINTUPLE
// Generic sextuple
%token<token*token*token*token*token*token> SEXTUPLE
// Generic septuple
%token<token*token*token*token*token*token*token> SEPTUPLE
// Generic octuple
%token<token*token*token*token*token*token*token*token> OCTUPLE
%token<token*token*token*token*token*token*token*token*token> NONUPLE
%token<token*token*token*token*token*token*token*token*token*token> DECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token> UNDECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token*token> DUODECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token*token*token*token> QUATTUORDECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> QUINDECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> SEXDECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> SEPTENDECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> OCTODECUPLE
%token<token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> NOVEMDECUPLE
%token <token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> VIGENUPLE
%token <token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> UNVIGENUPLE
%token <token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> DUOVIGENUPLE
%token <token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> TREVIGENUPLE
%token <token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> QUATTUORVIGENUPLE
%token <token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token*token> QUINVIGENUPLE
// non-keyword tokens
%token BITSEL
%token PARTSEL
%token IOPORT
%token SUBMODULE
%token SUBCCT
%token MODINST
%token PRIMINST
%token<token * token> RANGE
%token<token list> TLIST
// for undeclared wires
%token IMPLICIT
%token RECEIVER
%token DRIVER
%token BIDIR
// for dotted hierarchical paths (models only)
%token<token list> DOTTED
// pre-proc tokens
%token P_CELLDEFINE
%token P_DEFINE
%token P_DELAY_MODE_PATH
%token P_DISABLE_PORTFAULTS
%token P_ELSE
%token P_ENABLE_PORTFAULTS
%token P_ENDCELLDEFINE
%token P_ENDIF
%token P_IFDEF
%token P_IFNDEF
%token<string> P_INCLUDE
%token P_NOSUPPRESS_FAULTS
%token P_PROTECT
%token P_ENDPROTECT
%token P_RESETALL
%token P_SUPPRESS_FAULTS
%token<string> P_TIMESCALE
%token<string> PREPROC // some other token, not (yet) recognized
// for pragmatic comments e.g. black box models
%token<string> PRAGMATIC
// for named blocks
%token NAMED
// for generate item
%token GENITEM
// for unknown modules/primitives
%token UNKNOWN
// for invalid use
%token NOTCONST
// for scalar nets
%token SCALAR
// for empty types
%token VOID
// for special nets
%token SPECIAL
// for parameters
%token PARAMUSED
// for tasks/funcs/senslists
%token TASKUSED
%token FUNCUSED
%token SENSUSED
%token FUNCASSIGNED
// for memories
%token MEMORY
// for transistor level
%token NMOS
%token PMOS
%token TRAN
%token<string> TRANIF
// for function/task refs
%token TASKREF
%token FUNCREF
// for cell pins
%token CELLPIN
// for case statements
%token CASECOND
%token GENCASE
%token GENCASECOND
// for delay specs (models only)
%token MINTYPMAX
// for end labels
%token ENDLABEL
// for {a,b,c}
%token CONCAT
// for tables
%token<char*char> TEDGE
// Generic lexer tokens, for example a number
// IEEE: real_number
%token<float> FLOATNUM // "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<string> ID // "IDENTIFIER"
// IEEE: integral_number
%token<int> INT // "INTEGER NUMBER as int"
%token<string> INTNUM // "INTEGER NUMBER as string"
%token<string> BINNUM // "BINARY NUMBER"
%token<string> OCTNUM // "OCTAL NUMBER"
%token<string> DECNUM // "DECIMAL NUMBER"
%token<string> HEXNUM // "HEXADECIMAL NUMBER"
// IEEE: string_literal
%token<string> ASCNUM // "ASCII NUMBER / STRING"
%token<char> ILLEGAL
%token DOLLAR
%token EOF
// Specific keywords
%token AMPERSAND
%token AT
%token CARET
%token COLON
%token COMMA
%token DIVIDE
%token EQUALS
%token GREATER
%token HASH
%token LBRACK
%token LCURLY
%token LESS
%token LPAREN
%token MINUS
%token MODULO
%token DOT
%token PLING
%token PLUS
%token QUERY
%token RBRACK
%token RCURLY
%token RPAREN
%token SEMICOLON
%token TILDE
%token TIMES
%token VBAR
// KEYWORD means match // "keyword"
// Other cases are XX_KEYWORD where XX makes it unique,
// for example P_ for punctuation based operators.
%token ALWAYS // "always"
%token AND // "and"
%token ASSERT // "assert"
%token ASSIGN // "assign"
%token ASSIGNMENT // "= assignment"
%token DLYASSIGNMENT // "<= assignment"
%token AUTOMATIC // "automatic"
%token BEGIN // "begin"
%token BUF // "buf"
%token<string> BUFIF // "bufif"
%token CASE // "case"
%token CASEX // "casex"
%token CASEZ // "casez"
%token CLOCKING // "clocking"
%token COVER // "cover"
%token DEASSIGN // "deassign"
%token DEFAULT // "default"
%token DEFPARAM // "defparam"
%token DISABLE // "disable"
%token DO // "do"
%token ELSE // "else"
%token END // "end"
%token ENDCASE // "endcase"
%token ENDCLOCKING // "endclocking"
%token ENDFUNCTION // "endfunction"
%token ENDGENERATE // "endgenerate"
%token ENDMODULE // "endmodule"
%token ENDPRIMITIVE // "endprimitive"
%token ENDSPECIFY // "endspecify"
%token ENDTABLE // "endtable"
%token ENDTASK // "endtask"
%token EVENT // "event"
%token FINAL // "final"
%token FOR // "for"
%token FOREVER // "forever"
%token FUNCTION // "function"
%token GENERATE // "generate"
%token GENVAR // "genvar"
%token IF // "if"
%token IFF // "iff"
%token INITIAL // "initial"
%token INOUT // "inout"
%token INPUT // "input"
%token INTEGER // "integer"
%token LOCALPARAM // "localparam"
%token MODULE // "module"
%token NAND // "nand"
%token NEGEDGE // "negedge"
%token NOR // "nor"
%token NOT // "not"
%token<string> NOTIF // "notif"
%token OR // "or"
%token OUTPUT // "output"
%token PARAMETER // "parameter"
%token POSEDGE // "posedge"
%token PRIMITIVE // "primitive"
%token PROPERTY // "property"
%token PULLUP // "pullup"
%token REAL // "real"
%token REG // "reg"
%token REPEAT // "repeat"
%token SCALARED // "scalared"
%token SIGNED // "signed"
%token SPECIFY // "specify"
%token STATIC // "static"
%token SUPPLY0 // "supply0"
%token SUPPLY1 // "supply1"
%token TABLE // "table"
%token TASK // "task"
%token TRI0 // "tri0"
%token TRI1 // "tri0"
%token UNSIGNED // "unsigned"
%token VECTORED // "vectored"
%token<string> WEAK // "weak"
%token<string> PWEAK // "(weak"
%token WHILE // "while"
%token WIRE // "wire"
%token XNOR // "xnor"
%token XOR // "xor"
%token D_ATTRIBUTE // "$attribute"
%token D_BITS // "$bits"
%token D_C // "$c"
%token D_CLOG2 // "$clog2"
%token D_COUNTDRIVERS // "$countdrivers"
%token D_COUNTONES // "$countones"
%token D_DISPLAY // "$display"
%token D_ERROR // "$error"
%token D_FATAL // "$fatal"
%token D_FCLOSE // "$fclose"
%token D_FDISPLAY // "$fdisplay"
%token D_FEOF // "$feof"
%token D_FFLUSH // "$fflush"
%token D_FGETC // "$fgetc"
%token D_FGETS // "$fgets"
%token D_FINISH // "$finish"
%token D_FOPEN // "$fopen"
%token D_FSCANF // "$fscanf"
%token D_FWRITE // "$fwrite"
%token D_FWRITEH // "$fwriteh"
%token D_INFO // "$info"
%token D_ISUNKNOWN // "$isunknown"
%token D_MONITOR // "$monitor"
%token D_ONEHOT // "$onehot"
%token D_ONEHOT0 // "$onehot0"
%token D_RANDOM // "$random"
%token D_READMEMB // "$readmemb"
%token D_READMEMH // "$readmemh"
%token D_SIGNED // "$signed"
%token D_SSCANF // "$sscanf"
%token D_STIME // "$stime"
%token D_STOP // "$stop"
%token D_TEST_PLUSARGS // "$test$plusargs"
%token D_TIME // "$time"
%token D_UNSIGNED // "$unsigned"
%token D_WARNING // "$warning"
%token D_WRITE // "$write"
%token NOCHANGE // $nochange
%token D_HOLD // $hold
%token D_PERIOD // $period
%token D_RECOVERY // $recovery
%token D_RECREM // $recrem
%token D_REMOVAL // $removal
%token D_SETUPHOLD // $setuphold
%token D_SETUP // $setup
%token D_SKEW // $skew
%token D_TIMESKEW // $timeskew
%token D_WIDTH // $width
%token SHOWCANCELLED // showcancelled
%token NOSHOWCANCELLED // noshowcancelled
%token SPECPARAM // specparam
%token IF_NONE // ifnone
%token TILDE_VBAR // ~|
%token TOKEN_EDGE01 // 01
%token TOKEN_EDGE_10 // 10
%token TOKEN_ZERO // 0
%token TOKEN_ONE // 1
%token PATHPULSE // PATHPULSE$
%token FULLSKEW // $fullskew
%token PULSESTYLE_ONDETECT // pulsestyle_ondetect
%token PULSESTYLE_ONEVENT // pulsestyle_onevent
%token EDGE // edge
%token<string> Z_OR_X // z_or_x
%token P_NXOR // ~^
%token P_OROR // "||"
%token P_ANDAND // "&&"
%token P_NOR // "~|"
%token P_XNOR // "^~"
%token P_NAND // "~&"
%token P_EQUAL // "=="
%token P_NOTEQUAL // "!="
%token P_CASEEQUAL // "==="
%token P_CASENOTEQUAL // "!=="
%token P_WILDEQUAL // "==?"
%token P_WILDNOTEQUAL // "!=?"
%token P_GTE // ">="
%token P_LTE // "<="
%token P_SLEFT // "<<"
%token P_SRIGHT // ">>"
%token P_SSRIGHT // ">>>"
%token P_POW // "**"
%token P_PLUSCOLON // "+:"
%token P_MINUSCOLON // "-:"
%token P_EQGT // "=>"
%token P_ASTGT // "*>"
%token P_ANDANDAND // "&&&"
%token P_POUNDPOUND // "##"
%token P_DOTSTAR // ".*"
%token P_ATAT // "@@"
%token P_COLONCOLON // "::"
%token P_COLONEQ // ":="
%token P_COLONDIV // ":/"
%token P_ORMINUSGT // "|->"
%token P_OREQGT // "|=>"
%token P_PLUSEQ // "+="
%token P_MINUSEQ // "-="
%token P_TIMESEQ // "*="
%token P_DIVEQ // "/="
%token P_MODEQ // "%="
%token P_ANDEQ // "&="
%token P_OREQ // "|="
%token P_XOREQ // "^="
%token P_SLEFTEQ // "<<="
%token P_SRIGHTEQ // ">>="
%token P_SSRIGHTEQ // ">>>="
%token P_MINUSGT // "->"
%token ENDOFFILE
// Verilog op precedence
%left COLON
%left QUERY
%left P_OROR
%left P_ANDAND
%left VBAR P_NOR
%left CARET
%left P_XNOR
%left AMPERSAND P_NAND
%left P_EQUAL P_NOTEQUAL P_CASEEQUAL P_CASENOTEQUAL P_WILDEQUAL P_WILDNOTEQUAL
%left GREATER LESS P_GTE P_LTE
%left P_SLEFT P_SRIGHT P_SSRIGHT
%left PLUS MINUS
%left TIMES DIVIDE MODULO
%left P_POW
%left prUNARYARITH
%left prREDUCTION
%left prNEGATION
%nonassoc prLOWER_THAN_ELSE
%nonassoc ELSE
// Types are in same order as declarations.
// Naming:
// Trailing E indicates this type may have empty match
%start start
%type <char> edge1
%type <char*char> edge2
%type <token list> trowList
%type <token list> tinList
%type <token list> tregoutList
%type <token> Anyrange
%type <token> AssertStmt
%type <token list> AssignList
%type <token> AssignOne
%type <token> caseAttrE
%type <token list> caseCondList
%type <token list> caseList
%type <token> caseListE
%type <token> case
%type <token list> cateList
%type <token> cellpinItem
%type <token list> cellpinItList
%type <token list> cellpinList
%type <token> commaEListE
%type <token> commaVRDListE
%type <token list> concIdList
%type <token> constExpr
%type <token list> cStrList
%type <token list> defpList
%type <token> defpOne
%type <token> delay
%type <token> delayE
%type <token> delayrange
%type <token> delayStrength
%type <token> dlyTerm
%type <token> endLabelE
%type <token> eventControl
%type <token> expr
%type <token list> exprList
%type <token> exprNoStr
%type <token> exprStrText
%type <token> funcDecl
%type <token> funcArgs
%type <token> funcRef
%type <token> funcTypeE
%type <token> funcVar
%type <token list> funcVarList
%type <token> taskVar
%type <token list> taskVarList
%type <token> gateAnd
%type <token list> gateAndList
%type <token list> gateAndPinList
%type <token> gateBuf
%type <token list> gateBufList
%type <token> gateDecl
%type <token> gateIdE
%type <token> gateNand
%type <token list> gateNandList
%type <token> gateNor
%type <token list> gateNorList
%type <token> gateNot
%type <token list> gateNotList
%type <token> gateOr
%type <token list> gateOrList
%type <token list> gateOrPinList
%type <token> gateXnor
%type <token list> gateXnorList
%type <token> gateXor
%type <token list> gateXorList
%type <token list> gateXorPinList
%type <token list> genCaseList
%type <token> genCaseListE
%type <token> generateRegion
%type <token> genItem
%type <token> genItemBegin
%type <token> genItemBlock
%type <token list> genItemList
%type <token> genTopBlock
%type <token> idArrayed
%type <token> idDotted
%type <token> instDecl
%type <token list> instnameList
%type <token> instnameParen
%type <token> instRangeE
%type <token> labeledStmt
%type <token> lifetimeE
%type <token> minTypMax
%type <token> modItem
%type <token list> modItemListE
%type <token> modOrGenItem
%type <token list> modParArgs
%type <token> modParDecl
%type <token> modParE
%type <token list> modParList
%type <token> modParSecond
%type <token list> modPortsE
%type <token> netSig
%type <token list> netSigList
%type <token> param
%type <token list> paramList
%type <token> parenE
%type <token> Port
%type <token> PortDecl
%type <token> PortDirection
%type <token list> PortList
%type <token> PortRangeE
%type <token list> RangeList
%type <token> RangeListE
%type <token> regrangeE
%type <token> regsig
%type <token list> regsigList
%type <token> senitem
%type <token> senitemEdge
%type <token> senitemVar
%type <token list> senList
%type <token> sigAndAttr
%type <token> sigAttrListE
%type <token> sigId
%type <token> signingE
%type <token> start
%type <token> stateCaseForIf
%type <token> stmt
%type <token> stmtBlock
%type <token list> stmtList
%type <token> strAsInt
%type <token> strAsText
%type <token> taskDecl
%type <token> taskRef
%type <token> v2kVarDeclE
%type <token> varDecl
%type <token list> varDeclList
%type <token> varGenVar
%type <token> varGParam
%type <token> varLParam
%type <token> varNet
%type <token> varRefBase
%type <token> varRefDotBit
%type <token> varRefMem
%type <token> varReg
%type <token list> vrdList
%type <token> identifier
%type <token list> specify_block
%%
identifier: ID { ID $1 }
//**********************************************************************
//
start: ENDOFFILE { ENDOFFILE }
| modprimDecl { $1 }
;
modprimDecl: moduleDecl { $1 }
| primDecl { $1 }
| preproc { $1 }
;
// Pre-proc
preproc: P_CELLDEFINE { P_CELLDEFINE }
| P_DELAY_MODE_PATH { P_DELAY_MODE_PATH }
| P_DISABLE_PORTFAULTS { P_DISABLE_PORTFAULTS }
| P_ENABLE_PORTFAULTS { P_ENABLE_PORTFAULTS }
| P_SUPPRESS_FAULTS { P_SUPPRESS_FAULTS }
| P_PROTECT { P_PROTECT }
| P_RESETALL { P_RESETALL }
| P_TIMESCALE { P_TIMESCALE $1 }
| PREPROC { PREPROC $1 }
| PRAGMATIC { PRAGMATIC $1 }
| P_ENDCELLDEFINE { P_ENDCELLDEFINE }
| P_NOSUPPRESS_FAULTS { P_NOSUPPRESS_FAULTS }
| P_ENDPROTECT { P_ENDPROTECT }
//**********************************************************************
// Module headers
// IEEE: module_declaration:
moduleDecl: MODULE ID modParE modPortsE SEMICOLON modItemListE ENDMODULE
{
QUINTUPLE ( MODULE, ID $2, $3, TLIST $4, TLIST $6 )
}
// IEEE: primitive_declaration:
primDecl: PRIMITIVE ID modParE modPortsE SEMICOLON primItemList ENDPRIMITIVE
{
QUINTUPLE ( PRIMITIVE, ID $2, $3, TLIST $4, TLIST $6 )
}
primItemList:
primItem { [ $1 ] }
| primItem primItemList { $1 :: $2 }
;
primItem:
PortDecl { $1 }
| varDecl { $1 }
| tableDecl { $1 }
;
modParE:
/* empty */ { EMPTY }
| HASH LPAREN RPAREN { DOUBLE (HASH, EMPTY) }
| HASH LPAREN modParArgs RPAREN { DOUBLE (HASH, TLIST $3) }
;
modParArgs:
modParDecl { [ $1 ] }
| modParDecl COMMA modParList { $1 :: $3 }
;
modParList:
modParSecond { [ $1 ] }
| modParList COMMA modParSecond { $1 @ [ $3 ] }
;
// Called only after a comma in a v2k list, to allow parsing "parameter a,b, parameter x"
modParSecond:
modParDecl { $1 }
| param { $1 }
;
modPortsE:
/* empty */ { [] }
| LPAREN RPAREN { [] }
| LPAREN PortList RPAREN { $2 }
| LPAREN PortV2kArgs RPAREN { $2 }
;
PortList:
Port { [ $1 ] }
| Port COMMA PortList { $1 :: $3 }
;
Port:
identifier PortRangeE { $1 }
| DOT identifier LPAREN expr RPAREN { DOUBLE ( DOT, $2 ) }
;
PortV2kArgs:
PortV2kDecl { [ $1 ] }
| PortV2kDecl COMMA PortV2kList { $1 :: $3 }
;
PortV2kList:
PortV2kSecond { [ $1 ] }
| PortV2kSecond COMMA PortV2kList { $1 :: $3 }
;
// Called only after a comma in a v2k list, to allow parsing "input a,b"
PortV2kSecond:
PortV2kDecl { $1 }
| PortV2kInit { $1 }
;
PortV2kInit:
PortV2kSig { $1 }
| PortV2kSig EQUALS expr { TRIPLE (EQUALS, $1, $3 ) }
;
PortV2kSig:
sigAndAttr { $1 }
;
//************************************************
// Variable Declarations
varDeclListE:
/* empty */ { [ ] }
| varDeclList { $1 }
;
varDeclList:
varDecl { [ $1 ] }
| varDecl varDeclList { $1 :: $2 }
;
regsigList:
regsig { [ $1 ] }
| regsigList COMMA regsig { $1 @ [ $3 ] }
;
PortV2kDecl:
PortDirection v2kVarDeclE signingE regrangeE PortV2kInit
{ QUINTUPLE ( $1 , $2 , $3 , $4 , $5 ) }
;
// IEEE: Port_declaration - plus SEMICOLON
PortDecl:
PortDirection v2kVarDeclE signingE regrangeE regsigList SEMICOLON
{ QUINTUPLE ( $1, $2, $3, $4, TLIST $5 ) }
;
varDecl:
varReg signingE regrangeE regsigList SEMICOLON
{ QUADRUPLE ($1, $2, $3, TLIST $4 ) }
| varGParam signingE regrangeE paramList SEMICOLON
{ QUADRUPLE ($1, $2, $3, TLIST $4 ) }
| varLParam signingE regrangeE paramList SEMICOLON
{ QUADRUPLE ($1, $2, $3, TLIST $4 ) }
| varNet signingE delayrange netSigList SEMICOLON
{ QUADRUPLE ($1, $2, $3, TLIST $4 ) }
| varGenVar signingE regsigList SEMICOLON
{ TRIPLE ($1, $2, TLIST $3 ) }
;
modParDecl:
varGParam signingE regrangeE param
{ QUADRUPLE ($1, $2, $3, $4 ) }
;
varNet: SUPPLY0 { SUPPLY0 }
| SUPPLY1 { SUPPLY1 }
| WIRE { WIRE }
| TRI0 { TRI0 }
| TRI1 { TRI1 }
;
varGParam: PARAMETER { PARAMETER }
;
varLParam: LOCALPARAM { LOCALPARAM }
;
varGenVar: GENVAR { GENVAR }
;
varReg: REG { REG }
| REAL { REAL }
| INTEGER { INTEGER }
| EVENT { EVENT }
;
readmem: D_READMEMB { D_READMEMB }
| D_READMEMH { D_READMEMH }
;
//IEEE: Port_direction
PortDirection: INPUT { INPUT }
| OUTPUT { OUTPUT }
| INOUT { INOUT }
// | REF { REF }
;
// IEEE: signing - plus empty
signingE: /*empty*/ { EMPTY }
| SIGNED { SIGNED }
| UNSIGNED { UNSIGNED }
;
v2kVarDeclE: /*empty*/ { EMPTY }
| varNet { $1 }
| varReg { $1 }
;
//************************************************
// Module Items
modItemListE:
/* empty */ { [] }
| preproc modItemListE { $2 }
| modItem modItemListE { $1 :: $2 }
;
modItem:
modOrGenItem { $1 }
| generateRegion { $1 }
| SPECIFY specify_block ENDSPECIFY { DOUBLE (SPECIFY, TLIST $2 ) }
;
// IEEE: generate_region
generateRegion:
GENERATE genTopBlock ENDGENERATE { DOUBLE (GENERATE, $2 ) }
;
modOrGenItem:
ALWAYS stmtBlock { DOUBLE (ALWAYS, $2 ) }
| FINAL stmtBlock { DOUBLE (FINAL, $2 ) }
| INITIAL stmtBlock { DOUBLE ( INITIAL, $2 ) }
| ASSIGN delayStrength AssignList SEMICOLON { TRIPLE ( ASSIGN, $2, TLIST $3 ) }
| DEFPARAM defpList SEMICOLON { DOUBLE (DEFPARAM, TLIST $2 ) }
| instDecl { $1 }
| taskDecl { $1 }
| funcDecl { $1 }
| gateDecl { $1 }
| attrDecl { $1 }
| PortDecl { $1 }
| varDecl { $1 }
| tableDecl { $1 }
| concurrent_assertion_item { $1 } // IEEE puts in modItem; seems silly
| clocking_declaration { $1 }
;
//************************************************
// Generates
// Because genItemList includes variable declarations, we dont need beginNamed
genItemBlock:
genItem { $1 }
| genItemBegin { $1 }
;
genTopBlock:
genItemList { TLIST $1 }
| genItemBegin { $1 }
;
genItemBegin:
BEGIN genItemList END { TLIST $2 }
| BEGIN END { EMPTY }
| BEGIN COLON identifier genItemList END endLabelE { QUADRUPLE(GENITEM, $3, TLIST $4, $6) }
| BEGIN COLON identifier END endLabelE { QUADRUPLE(GENITEM, $3, EMPTY, $5) }
;
genItemList:
genItem { [ $1 ] }
| genItem genItemList { $1 :: $2 }
;
genItem:
modOrGenItem { $1 }
| CASE LPAREN expr RPAREN genCaseListE ENDCASE { TRIPLE (GENCASE, $3, $5) }
| IF LPAREN expr RPAREN genItemBlock %prec prLOWER_THAN_ELSE
{ TRIPLE (IF, $3, $5) }
| IF LPAREN expr RPAREN genItemBlock ELSE genItemBlock
{ QUADRUPLE (IF, $3, $5, $7) }
| FOR LPAREN varRefBase EQUALS expr SEMICOLON
expr SEMICOLON varRefBase EQUALS expr RPAREN genItemBlock
{ QUINTUPLE (FOR, TRIPLE (ASSIGNMENT, $3, $5), $7, TRIPLE (ASSIGNMENT, $9, $11), $13) }
;
genCaseListE:
/* empty */ { EMPTY }
| genCaseList { TLIST $1 }
;
genCaseList:
caseCondList COLON genItemBlock { [ TRIPLE (GENCASECOND, TLIST $1, $3 ) ] }
| DEFAULT COLON genItemBlock { [ DOUBLE (DEFAULT, $3 ) ] }
| DEFAULT genItemBlock { [ DOUBLE (DEFAULT, $2 ) ] }
| genCaseList caseCondList COLON genItemBlock { TRIPLE (GENCASECOND, TLIST $2, $4) :: $1 }
| genCaseList DEFAULT genItemBlock { DOUBLE (DEFAULT, $3 ) :: $1 }
| genCaseList DEFAULT COLON genItemBlock { DOUBLE (DEFAULT, $4) :: $1 }
;
//************************************************
// Assignments and register declarations
AssignList:
AssignOne { [ $1 ] }
| AssignList COMMA AssignOne { $1 @ [ $3 ] }
;
AssignOne:
varRefDotBit EQUALS expr { TRIPLE (ASSIGNMENT, $1, $3 ) }
| LCURLY concIdList RCURLY EQUALS expr { TRIPLE (ASSIGNMENT, DOUBLE (CONCAT,TLIST $2), $5) }
;
delayE: /* empty */ { EMPTY }
| delay { $1 } /* ignored */
;
strengthList:
/* empty */ { [] }
| COMMA WEAK strengthList { WEAK $2 :: $3 }
delay:
HASH dlyTerm
{ DOUBLE (HASH, $2 ) } /* ignored */
| HASH LPAREN minTypMax RPAREN
{ DOUBLE (HASH, $3 ) } /* ignored */
| HASH LPAREN minTypMax COMMA minTypMax RPAREN
{ TRIPLE (HASH, $3, $5) } /* ignored */
| HASH LPAREN minTypMax COMMA minTypMax COMMA minTypMax RPAREN
{ QUADRUPLE (HASH, $3, $5, $7) } /* ignored */
;
dlyTerm:
identifier { $1 }
| floatnum { $1 }
;
// IEEE: mintypmax_expression and constant_mintypmax_expression
minTypMax:
dlyTerm { $1 } /* ignored */
| dlyTerm COLON dlyTerm COLON dlyTerm { QUADRUPLE (MINTYPMAX, $1, $3, $5) } /* ignored */
;
sigAndAttr:
sigId sigAttrListE { DOUBLE ( $1, $2 ) }
;
netSigList:
netSig { [ $1 ] }
| netSigList COMMA netSig { $1 @ [ $3 ] }
;
netSig:
sigId sigAttrListE { DOUBLE ( $1, $2 ) }
| sigId sigAttrListE EQUALS expr { TRIPLE ( $1, $2, $4 ) }
| identifier RangeList sigAttrListE { TRIPLE ( $1, TLIST $2, $3 ) }
;
regsig:
identifier RangeListE sigAttrListE { TRIPLE ($1, $2, $3 ) }
| identifier RangeListE EQUALS constExpr sigAttrListE { QUADRUPLE ($1, $2, $4, $5 ) }
;
sigId: identifier { $1 }
;
sigAttrListE: /* empty */ { EMPTY }
;
RangeListE:
/* empty */ { EMPTY }
| RangeList { TLIST $1 }
;
RangeList:
Anyrange { [ $1 ] }
| RangeList Anyrange { $1 @ [ $2 ] }
;
regrangeE:
/* empty */ { EMPTY }
| Anyrange { $1 }
;
Anyrange:
LBRACK constExpr COLON constExpr RBRACK { RANGE( $2, $4) }
;
delayrange:
regrangeE delayE { TRIPLE (EMPTY, $1, $2 ) }
| SCALARED regrangeE delayE { TRIPLE (SCALARED, $2, $3 ) }
| VECTORED regrangeE delayE { TRIPLE (VECTORED, $2, $3 ) }
;
PortRangeE:
/* empty */ { SCALAR }
| LBRACK constExpr RBRACK { RANGE ($2, $2) }
| LBRACK constExpr COLON constExpr RBRACK { RANGE ($2, $4) }
;
//************************************************
// Parameters
param:
sigId sigAttrListE EQUALS expr { TRIPLE ( $1, $2, $4 ) }
;
paramList:
param { [ $1 ] }
| paramList COMMA param { $1 @ [ $3 ] }
;
// IEEE: list_of_defparam_assignments
defpList:
defpOne { [ $1 ] }
| defpList COMMA defpOne { $1 @ [ $3 ] }
;
defpOne:
identifier DOT identifier EQUALS expr { TRIPLE ($1, $3 , $5 ) }
;
//************************************************
// Instances
instDecl:
ID delayStrength instnameList SEMICOLON {
if (Hashtbl.mem Globals.modprims ($1) == false) then
begin
if (List.mem $1 !Globals.unresolved_list == false) then begin
Globals.unresolved_list := $1 :: !Globals.unresolved_list
end
end;
QUADRUPLE (MODINST, (ID $1), $2, TLIST $3 )
}
| ID delayStrength LPAREN varRefDotBit COMMA gateUdpPinList RPAREN SEMICOLON
{
if (Hashtbl.mem Globals.modprims ($1) == false) then
begin
if (List.mem $1 !Globals.unresolved_list == false) then begin
Globals.unresolved_list := $1 :: !Globals.unresolved_list
end
end;
QUADRUPLE (PRIMINST, (ID $1), $2, TLIST ($4::$6) )
}
;