forked from steveicarus/iverilog
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparse.y
7411 lines (6599 loc) · 205 KB
/
parse.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
%{
/*
* Copyright (c) 1998-2024 Stephen Williams ([email protected])
* Copyright CERN 2012-2013 / Stephen Williams ([email protected])
*
* This source code is free software; you can redistribute it
* and/or modify it in source code form under the terms of the GNU
* General Public License as published by the Free Software
* Foundation; either version 2 of the License, or (at your option)
* any later version.
*
* 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.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
# include "config.h"
# include <climits>
# include <cstdarg>
# include "parse_misc.h"
# include "compiler.h"
# include "pform.h"
# include "Statement.h"
# include "PSpec.h"
# include "PTimingCheck.h"
# include "PPackage.h"
# include <stack>
# include <cstring>
# include <sstream>
# include <memory>
using namespace std;
class PSpecPath;
extern void lex_end_table();
static data_type_t* param_data_type = 0;
static bool param_is_local = false;
static bool param_is_type = false;
static std::list<pform_range_t>* specparam_active_range = 0;
/* Port declaration lists use this structure for context. */
static struct {
NetNet::Type port_net_type;
NetNet::PortType port_type;
data_type_t* data_type;
} port_declaration_context = {NetNet::NONE, NetNet::NOT_A_PORT, 0};
/* Modport port declaration lists use this structure for context. */
enum modport_port_type_t { MP_NONE, MP_SIMPLE, MP_TF, MP_CLOCKING };
static struct {
modport_port_type_t type;
union {
NetNet::PortType direction;
bool is_import;
};
} last_modport_port = { MP_NONE, {NetNet::NOT_A_PORT}};
/* The task and function rules need to briefly hold the pointer to the
task/function that is currently in progress. */
static PTask* current_task = 0;
static PFunction* current_function = 0;
static stack<PBlock*> current_block_stack;
/* The variable declaration rules need to know if a lifetime has been
specified. */
static LexicalScope::lifetime_t var_lifetime;
static pform_name_t* pform_create_this(void)
{
name_component_t name (perm_string::literal(THIS_TOKEN));
pform_name_t*res = new pform_name_t;
res->push_back(name);
return res;
}
static pform_name_t* pform_create_super(void)
{
name_component_t name (perm_string::literal(SUPER_TOKEN));
pform_name_t*res = new pform_name_t;
res->push_back(name);
return res;
}
/* The rules sometimes push attributes into a global context where
sub-rules may grab them. This makes parser rules a little easier to
write in some cases. */
static std::list<named_pexpr_t>*attributes_in_context = 0;
/* Later version of bison (including 1.35) will not compile in stack
extension if the output is compiled with C++ and either the YYSTYPE
or YYLTYPE are provided by the source code. However, I can get the
old behavior back by defining these symbols. */
# define YYSTYPE_IS_TRIVIAL 1
# define YYLTYPE_IS_TRIVIAL 1
/* Recent version of bison expect that the user supply a
YYLLOC_DEFAULT macro that makes up a yylloc value from existing
values. I need to supply an explicit version to account for the
text field, that otherwise won't be copied.
The YYLLOC_DEFAULT blends the file range for the tokens of Rhs
rule, which has N tokens.
*/
# define YYLLOC_DEFAULT(Current, Rhs, N) do { \
if (N) { \
(Current).first_line = YYRHSLOC (Rhs, 1).first_line; \
(Current).first_column = YYRHSLOC (Rhs, 1).first_column; \
(Current).last_line = YYRHSLOC (Rhs, N).last_line; \
(Current).last_column = YYRHSLOC (Rhs, N).last_column; \
(Current).lexical_pos = YYRHSLOC (Rhs, 1).lexical_pos; \
(Current).text = YYRHSLOC (Rhs, 1).text; \
} else { \
(Current).first_line = YYRHSLOC (Rhs, 0).last_line; \
(Current).first_column = YYRHSLOC (Rhs, 0).last_column; \
(Current).last_line = YYRHSLOC (Rhs, 0).last_line; \
(Current).last_column = YYRHSLOC (Rhs, 0).last_column; \
(Current).lexical_pos = YYRHSLOC (Rhs, 0).lexical_pos; \
(Current).text = YYRHSLOC (Rhs, 0).text; \
} \
} while (0)
/*
* These are some common strength pairs that are used as defaults when
* the user is not otherwise specific.
*/
static const struct str_pair_t pull_strength = { IVL_DR_PULL, IVL_DR_PULL };
static const struct str_pair_t str_strength = { IVL_DR_STRONG, IVL_DR_STRONG };
static std::list<pform_port_t>* make_port_list(char*id, unsigned idn,
std::list<pform_range_t>*udims,
PExpr*expr)
{
std::list<pform_port_t>*tmp = new std::list<pform_port_t>;
pform_ident_t tmp_name = { lex_strings.make(id), idn };
tmp->push_back(pform_port_t(tmp_name, udims, expr));
delete[]id;
return tmp;
}
static std::list<pform_port_t>* make_port_list(list<pform_port_t>*tmp,
char*id, unsigned idn,
std::list<pform_range_t>*udims,
PExpr*expr)
{
pform_ident_t tmp_name = { lex_strings.make(id), idn };
tmp->push_back(pform_port_t(tmp_name, udims, expr));
delete[]id;
return tmp;
}
static std::list<pform_ident_t>* list_from_identifier(char*id, unsigned idn)
{
std::list<pform_ident_t>*tmp = new std::list<pform_ident_t>;
tmp->push_back({ lex_strings.make(id), idn });
delete[]id;
return tmp;
}
static std::list<pform_ident_t>* list_from_identifier(list<pform_ident_t>*tmp,
char*id, unsigned idn)
{
tmp->push_back({ lex_strings.make(id), idn });
delete[]id;
return tmp;
}
template <class T> void append(vector<T>&out, const std::vector<T>&in)
{
for (size_t idx = 0 ; idx < in.size() ; idx += 1)
out.push_back(in[idx]);
}
/*
* The parser parses an empty argument list as an argument list with an single
* empty argument. Fix this up here and replace it with an empty list.
*/
static void argument_list_fixup(list<named_pexpr_t> *lst)
{
if (lst->size() == 1 && lst->front().name.nil() && !lst->front().parm)
lst->clear();
}
/*
* This is a shorthand for making a PECallFunction that takes a single
* arg. This is used by some of the code that detects built-ins.
*/
static PECallFunction*make_call_function(perm_string tn, PExpr*arg)
{
std::vector<named_pexpr_t> parms(1);
parms[0].parm = arg;
parms[0].set_line(*arg);
PECallFunction*tmp = new PECallFunction(tn, parms);
return tmp;
}
static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2)
{
std::vector<named_pexpr_t> parms(2);
parms[0].parm = arg1;
parms[0].set_line(*arg1);
parms[1].parm = arg2;
parms[1].set_line(*arg2);
PECallFunction*tmp = new PECallFunction(tn, parms);
return tmp;
}
static std::list<named_pexpr_t>* make_named_numbers(const struct vlltype &loc,
perm_string name,
long first, long last,
PExpr *val = nullptr)
{
std::list<named_pexpr_t>*lst = new std::list<named_pexpr_t>;
named_pexpr_t tmp;
// We are counting up.
if (first <= last) {
for (long idx = first ; idx <= last ; idx += 1) {
ostringstream buf;
buf << name.str() << idx << ends;
tmp.name = lex_strings.make(buf.str());
tmp.parm = val;
FILE_NAME(&tmp, loc);
val = 0;
lst->push_back(tmp);
}
// We are counting down.
} else {
for (long idx = first ; idx >= last ; idx -= 1) {
ostringstream buf;
buf << name.str() << idx << ends;
tmp.name = lex_strings.make(buf.str());
tmp.parm = val;
FILE_NAME(&tmp, loc);
val = 0;
lst->push_back(tmp);
}
}
return lst;
}
static std::list<named_pexpr_t>* make_named_number(const struct vlltype &loc,
perm_string name,
PExpr *val = nullptr)
{
std::list<named_pexpr_t>*lst = new std::list<named_pexpr_t>;
named_pexpr_t tmp;
tmp.name = name;
tmp.parm = val;
FILE_NAME(&tmp, loc);
lst->push_back(tmp);
return lst;
}
static long check_enum_seq_value(const YYLTYPE&loc, verinum *arg, bool zero_ok)
{
long value = 1;
// We can never have an undefined value in an enumeration name
// declaration sequence.
if (! arg->is_defined()) {
yyerror(loc, "error: Undefined value used in enum name sequence.");
// We can never have a negative value in an enumeration name
// declaration sequence.
} else if (arg->is_negative()) {
yyerror(loc, "error: Negative value used in enum name sequence.");
} else {
value = arg->as_ulong();
// We cannot have a zero enumeration name declaration count.
if (! zero_ok && (value == 0)) {
yyerror(loc, "error: Zero count used in enum name sequence.");
value = 1;
}
}
return value;
}
static void check_end_label(const struct vlltype&loc, const char *type,
const char *begin, const char *end)
{
if (!end)
return;
if (!begin)
yyerror(loc, "error: Unnamed %s must not have end label.", type);
else if (strcmp(begin, end) != 0)
yyerror(loc, "error: %s end label `%s` doesn't match %s name"
" `%s`.", type, end, type, begin);
if (!gn_system_verilog())
yyerror(loc, "error: %s end label requires SystemVerilog.", type);
delete[] end;
}
static void check_for_loop(const struct vlltype&loc, PExpr*init,
PExpr*cond, Statement*step)
{
if (generation_flag >= GN_VER2012)
return;
if (!init)
yyerror(loc, "error: null for-loop initialization requires "
"SystemVerilog 2012 or later.");
if (!cond)
yyerror(loc, "error: null for-loop termination requires "
"SystemVerilog 2012 or later.");
if (!step)
yyerror(loc, "error: null for-loop step requires "
"SystemVerilog 2012 or later.");
}
static void current_task_set_statement(const YYLTYPE&loc, std::vector<Statement*>*s)
{
if (s == 0) {
/* if the statement list is null, then the parser
detected the case that there are no statements in the
task. If this is SystemVerilog, handle it as an
an empty block. */
pform_requires_sv(loc, "Task body with no statements");
PBlock*tmp = new PBlock(PBlock::BL_SEQ);
FILE_NAME(tmp, loc);
current_task->set_statement(tmp);
return;
}
assert(s);
/* An empty vector represents one or more null statements. Handle
this as a simple null statement. */
if (s->empty())
return;
/* A vector of 1 is handled as a simple statement. */
if (s->size() == 1) {
current_task->set_statement((*s)[0]);
return;
}
pform_requires_sv(loc, "Task body with multiple statements");
PBlock*tmp = new PBlock(PBlock::BL_SEQ);
FILE_NAME(tmp, loc);
tmp->set_statement(*s);
current_task->set_statement(tmp);
}
static void current_function_set_statement(const YYLTYPE&loc, std::vector<Statement*>*s)
{
if (s == 0) {
/* if the statement list is null, then the parser
detected the case that there are no statements in the
task. If this is SystemVerilog, handle it as an
an empty block. */
pform_requires_sv(loc, "Function body with no statements");
PBlock*tmp = new PBlock(PBlock::BL_SEQ);
FILE_NAME(tmp, loc);
current_function->set_statement(tmp);
return;
}
assert(s);
/* An empty vector represents one or more null statements. Handle
this as a simple null statement. */
if (s->empty())
return;
/* A vector of 1 is handled as a simple statement. */
if (s->size() == 1) {
current_function->set_statement((*s)[0]);
return;
}
pform_requires_sv(loc, "Function body with multiple statements");
PBlock*tmp = new PBlock(PBlock::BL_SEQ);
FILE_NAME(tmp, loc);
tmp->set_statement(*s);
current_function->set_statement(tmp);
}
static void port_declaration_context_init(void)
{
port_declaration_context.port_type = NetNet::PINOUT;
port_declaration_context.port_net_type = NetNet::IMPLICIT;
port_declaration_context.data_type = nullptr;
}
Module::port_t *module_declare_port(const YYLTYPE&loc, char *id,
NetNet::PortType port_type,
NetNet::Type net_type,
data_type_t *data_type,
std::list<pform_range_t> *unpacked_dims,
PExpr *default_value,
std::list<named_pexpr_t> *attributes)
{
pform_ident_t name = { lex_strings.make(id), loc.lexical_pos };
delete[] id;
Module::port_t *port = pform_module_port_reference(loc, name.first);
switch (port_type) {
case NetNet::PINOUT:
if (default_value)
yyerror(loc, "error: Default port value not allowed for inout ports.");
if (unpacked_dims) {
yyerror(loc, "sorry: Inout ports with unpacked dimensions are not supported.");
delete unpacked_dims;
unpacked_dims = nullptr;
}
break;
case NetNet::PINPUT:
if (default_value) {
pform_requires_sv(loc, "Input port default value");
port->default_value = default_value;
}
break;
case NetNet::POUTPUT:
if (default_value)
pform_make_var_init(loc, name, default_value);
// Output types without an implicit net type but with a data type
// are variables. Unlike the other port types, which are nets in
// that case.
if (net_type == NetNet::IMPLICIT) {
if (vector_type_t*dtype = dynamic_cast<vector_type_t*> (data_type)) {
if (!dtype->implicit_flag)
net_type = NetNet::IMPLICIT_REG;
} else if (data_type) {
net_type = NetNet::IMPLICIT_REG;
}
}
break;
default:
break;
}
pform_module_define_port(loc, name, port_type, net_type, data_type,
unpacked_dims, attributes);
port_declaration_context.port_type = port_type;
port_declaration_context.port_net_type = net_type;
port_declaration_context.data_type = data_type;
return port;
}
%}
%union {
bool flag;
char letter;
int int_val;
enum atom_type_t::type_code atom_type;
/* text items are C strings allocated by the lexor using
strdup. They can be put into lists with the texts type. */
char*text;
std::list<perm_string>*perm_strings;
std::list<pform_ident_t>*identifiers;
std::list<pform_port_t>*port_list;
std::vector<pform_tf_port_t>* tf_ports;
pform_name_t*pform_name;
ivl_discipline_t discipline;
hname_t*hier;
std::list<std::string>*strings;
struct str_pair_t drive;
PCase::Item*citem;
std::vector<PCase::Item*>*citems;
lgate*gate;
std::vector<lgate>*gates;
Module::port_t *mport;
LexicalScope::range_t* value_range;
std::vector<Module::port_t*>*mports;
std::list<PLet::let_port_t*>*let_port_lst;
PLet::let_port_t*let_port_itm;
named_pexpr_t*named_pexpr;
std::list<named_pexpr_t>*named_pexprs;
struct parmvalue_t*parmvalue;
std::list<pform_range_t>*ranges;
PExpr*expr;
std::list<PExpr*>*exprs;
PEEvent*event_expr;
std::vector<PEEvent*>*event_exprs;
ivl_case_quality_t case_quality;
NetNet::Type nettype;
PGBuiltin::Type gatetype;
NetNet::PortType porttype;
ivl_variable_type_t vartype;
PBlock::BL_TYPE join_keyword;
PWire*wire;
std::vector<PWire*>*wires;
PCallTask *subroutine_call;
PEventStatement*event_statement;
Statement*statement;
std::vector<Statement*>*statement_list;
decl_assignment_t*decl_assignment;
std::list<decl_assignment_t*>*decl_assignments;
struct_member_t*struct_member;
std::list<struct_member_t*>*struct_members;
struct_type_t*struct_type;
data_type_t*data_type;
class_type_t*class_type;
real_type_t::type_t real_type;
property_qualifier_t property_qualifier;
PPackage*package;
struct {
char*text;
typedef_t*type;
} type_identifier;
struct {
data_type_t*type;
std::list<named_pexpr_t> *args;
} class_declaration_extends;
struct {
char*text;
PExpr*expr;
} genvar_iter;
struct {
bool packed_flag;
bool signed_flag;
} packed_signing;
verinum* number;
verireal* realtime;
PSpecPath* specpath;
std::list<index_component_t> *dimensions;
PTimingCheck::event_t* timing_check_event;
PTimingCheck::optional_args_t* spec_optional_args;
LexicalScope::lifetime_t lifetime;
enum typedef_t::basic_type typedef_basic_type;
};
%token <text> IDENTIFIER SYSTEM_IDENTIFIER STRING TIME_LITERAL
%token <type_identifier> TYPE_IDENTIFIER
%token <package> PACKAGE_IDENTIFIER
%token <discipline> DISCIPLINE_IDENTIFIER
%token <text> PATHPULSE_IDENTIFIER
%token <number> BASED_NUMBER DEC_NUMBER UNBASED_NUMBER
%token <realtime> REALTIME
%token K_PLUS_EQ K_MINUS_EQ K_INCR K_DECR
%token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE K_WEQ K_WNE K_LP K_LS K_RS K_RSS K_SG
/* K_CONTRIBUTE is <+, the contribution assign. */
%token K_CONTRIBUTE
%token K_PO_POS K_PO_NEG K_POW
%token K_PSTAR K_STARP K_DOTSTAR
%token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER K_NB_TRIGGER K_LEQUIV
%token K_SCOPE_RES
%token K_edge_descriptor
%token K_CONSTRAINT_IMPL
/* The base tokens from 1364-1995. */
%token K_always K_and K_assign K_begin K_buf K_bufif0 K_bufif1 K_case
%token K_casex K_casez K_cmos K_deassign K_default K_defparam K_disable
%token K_edge K_else K_end K_endcase K_endfunction K_endmodule
%token K_endprimitive K_endspecify K_endtable K_endtask K_event K_for
%token K_force K_forever K_fork K_function K_highz0 K_highz1 K_if
%token K_ifnone K_initial K_inout K_input K_integer K_join K_large
%token K_macromodule K_medium K_module K_nand K_negedge K_nmos K_nor
%token K_not K_notif0 K_notif1 K_or K_output K_parameter K_pmos K_posedge
%token K_primitive K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_real
%token K_realtime K_reg K_release K_repeat K_rnmos K_rpmos K_rtran
%token K_rtranif0 K_rtranif1 K_scalared K_small K_specify K_specparam
%token K_strong0 K_strong1 K_supply0 K_supply1 K_table K_task K_time
%token K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand K_trior
%token K_trireg K_vectored K_wait K_wand K_weak0 K_weak1 K_while K_wire
%token K_wor K_xnor K_xor
%token K_Shold K_Snochange K_Speriod K_Srecovery K_Ssetup K_Ssetuphold
%token K_Sskew K_Swidth
/* Icarus specific tokens. */
%token KK_attribute K_bool K_logic
/* The new tokens from 1364-2001. */
%token K_automatic K_endgenerate K_generate K_genvar K_localparam
%token K_noshowcancelled K_pulsestyle_onevent K_pulsestyle_ondetect
%token K_showcancelled K_signed K_unsigned
%token K_Sfullskew K_Srecrem K_Sremoval K_Stimeskew
/* The 1364-2001 configuration tokens. */
%token K_cell K_config K_design K_endconfig K_incdir K_include K_instance
%token K_liblist K_library K_use
/* The new tokens from 1364-2005. */
%token K_wone K_uwire
/* The new tokens from 1800-2005. */
%token K_alias K_always_comb K_always_ff K_always_latch K_assert
%token K_assume K_before K_bind K_bins K_binsof K_bit K_break K_byte
%token K_chandle K_class K_clocking K_const K_constraint K_context
%token K_continue K_cover K_covergroup K_coverpoint K_cross K_dist K_do
%token K_endclass K_endclocking K_endgroup K_endinterface K_endpackage
%token K_endprogram K_endproperty K_endsequence K_enum K_expect K_export
%token K_extends K_extern K_final K_first_match K_foreach K_forkjoin
%token K_iff K_ignore_bins K_illegal_bins K_import K_inside K_int
/* Icarus already has defined "logic" above! */
%token K_interface K_intersect K_join_any K_join_none K_local
%token K_longint K_matches K_modport K_new K_null K_package K_packed
%token K_priority K_program K_property K_protected K_pure K_rand K_randc
%token K_randcase K_randsequence K_ref K_return K_sequence K_shortint
%token K_shortreal K_solve K_static K_string K_struct K_super
%token K_tagged K_this K_throughout K_timeprecision K_timeunit K_type
%token K_typedef K_union K_unique K_var K_virtual K_void K_wait_order
%token K_wildcard K_with K_within
/* The new tokens from 1800-2009. */
%token K_accept_on K_checker K_endchecker K_eventually K_global K_implies
%token K_let K_nexttime K_reject_on K_restrict K_s_always K_s_eventually
%token K_s_nexttime K_s_until K_s_until_with K_strong K_sync_accept_on
%token K_sync_reject_on K_unique0 K_until K_until_with K_untyped K_weak
/* The new tokens from 1800-2012. */
%token K_implements K_interconnect K_nettype K_soft
/* The new tokens for Verilog-AMS 2.3. */
%token K_above K_abs K_absdelay K_abstol K_access K_acos K_acosh
/* 1800-2005 has defined "assert" above! */
%token K_ac_stim K_aliasparam K_analog K_analysis K_asin K_asinh
%token K_atan K_atan2 K_atanh K_branch K_ceil K_connect K_connectmodule
%token K_connectrules K_continuous K_cos K_cosh K_ddt K_ddt_nature K_ddx
%token K_discipline K_discrete K_domain K_driver_update K_endconnectrules
%token K_enddiscipline K_endnature K_endparamset K_exclude K_exp
%token K_final_step K_flicker_noise K_floor K_flow K_from K_ground
%token K_hypot K_idt K_idtmod K_idt_nature K_inf K_initial_step
%token K_laplace_nd K_laplace_np K_laplace_zd K_laplace_zp
%token K_last_crossing K_limexp K_ln K_log K_max K_merged K_min K_nature
%token K_net_resolution K_noise_table K_paramset K_potential K_pow
/* 1800-2005 has defined "string" above! */
%token K_resolveto K_sin K_sinh K_slew K_split K_sqrt K_tan K_tanh
%token K_timer K_transition K_units K_white_noise K_wreal
%token K_zi_nd K_zi_np K_zi_zd K_zi_zp
%type <flag> from_exclude block_item_decls_opt
%type <number> number pos_neg_number
%type <flag> signing unsigned_signed_opt signed_unsigned_opt
%type <flag> import_export
%type <flag> K_genvar_opt K_static_opt K_virtual_opt K_const_opt
%type <flag> udp_reg_opt edge_operator
%type <drive> drive_strength drive_strength_opt dr_strength0 dr_strength1
%type <letter> udp_input_sym udp_output_sym
%type <text> udp_input_list udp_sequ_entry udp_comb_entry
%type <identifiers> udp_input_declaration_list
%type <strings> udp_entry_list udp_comb_entry_list udp_sequ_entry_list
%type <strings> udp_body
%type <identifiers> udp_port_list
%type <wires> udp_port_decl udp_port_decls
%type <statement> udp_initial udp_init_opt
%type <wire> net_variable
%type <wires> net_variable_list
%type <text> event_variable label_opt class_declaration_endlabel_opt
%type <text> block_identifier_opt
%type <text> identifier_name
%type <identifiers> event_variable_list
%type <identifiers> list_of_identifiers
%type <perm_strings> loop_variables
%type <port_list> list_of_port_identifiers list_of_variable_port_identifiers
%type <decl_assignments> net_decl_assigns
%type <decl_assignment> net_decl_assign
%type <mport> port port_opt port_reference port_reference_list
%type <mport> port_declaration
%type <mports> list_of_ports module_port_list_opt list_of_port_declarations module_attribute_foreign
%type <value_range> parameter_value_range parameter_value_ranges
%type <value_range> parameter_value_ranges_opt
%type <expr> value_range_expression
%type <named_pexprs> enum_name_list enum_name
%type <data_type> enum_data_type enum_base_type
%type <tf_ports> tf_item_declaration tf_item_list tf_item_list_opt
%type <tf_ports> tf_port_declaration tf_port_item tf_port_item_list
%type <tf_ports> tf_port_list tf_port_list_opt tf_port_list_parens_opt
%type <named_pexpr> named_expression named_expression_opt port_name
%type <named_pexprs> port_name_list parameter_value_byname_list
%type <exprs> port_conn_expression_list_with_nuls
%type <named_pexpr> attribute
%type <named_pexprs> attribute_list attribute_instance_list attribute_list_opt
%type <named_pexpr> argument
%type <named_pexprs> argument_list
%type <named_pexprs> argument_list_parens argument_list_parens_opt
%type <citem> case_item
%type <citems> case_items
%type <gate> gate_instance
%type <gates> gate_instance_list
%type <let_port_lst> let_port_list_opt let_port_list
%type <let_port_itm> let_port_item
%type <pform_name> hierarchy_identifier implicit_class_handle class_hierarchy_identifier
%type <pform_name> spec_notifier_opt spec_notifier
%type <timing_check_event> spec_reference_event
%type <spec_optional_args> setuphold_opt_args recrem_opt_args setuphold_recrem_opt_notifier
%type <spec_optional_args> setuphold_recrem_opt_timestamp_cond setuphold_recrem_opt_timecheck_cond
%type <spec_optional_args> setuphold_recrem_opt_delayed_reference setuphold_recrem_opt_delayed_data
%type <spec_optional_args> timeskew_opt_args fullskew_opt_args
%type <spec_optional_args> timeskew_fullskew_opt_notifier timeskew_fullskew_opt_event_based_flag
%type <spec_optional_args> timeskew_fullskew_opt_remain_active_flag
%type <expr> assignment_pattern expression expression_opt expr_mintypmax
%type <expr> expr_primary_or_typename expr_primary
%type <expr> class_new dynamic_array_new
%type <expr> var_decl_initializer_opt initializer_opt
%type <expr> inc_or_dec_expression inside_expression lpvalue
%type <expr> branch_probe_expression streaming_concatenation
%type <expr> delay_value delay_value_simple
%type <exprs> delay1 delay3 delay3_opt delay_value_list
%type <exprs> expression_list_with_nuls expression_list_proper
%type <exprs> cont_assign cont_assign_list
%type <decl_assignment> variable_decl_assignment
%type <decl_assignments> list_of_variable_decl_assignments
%type <data_type> data_type data_type_opt data_type_or_implicit data_type_or_implicit_or_void
%type <data_type> data_type_or_implicit_no_opt
%type <data_type> simple_type_or_string let_formal_type
%type <data_type> packed_array_data_type
%type <data_type> ps_type_identifier
%type <data_type> simple_packed_type
%type <data_type> class_scope
%type <struct_member> struct_union_member
%type <struct_members> struct_union_member_list
%type <struct_type> struct_data_type
%type <packed_signing> packed_signing
%type <class_declaration_extends> class_declaration_extends_opt
%type <property_qualifier> class_item_qualifier property_qualifier
%type <property_qualifier> class_item_qualifier_list property_qualifier_list
%type <property_qualifier> class_item_qualifier_opt property_qualifier_opt
%type <property_qualifier> random_qualifier
%type <ranges> variable_dimension
%type <ranges> dimensions_opt dimensions
%type <nettype> net_type net_type_opt net_type_or_var net_type_or_var_opt
%type <gatetype> gatetype switchtype
%type <porttype> port_direction port_direction_opt
%type <vartype> integer_vector_type
%type <parmvalue> parameter_value_opt
%type <event_exprs> event_expression_list
%type <event_expr> event_expression
%type <event_statement> event_control
%type <statement> statement statement_item statement_or_null
%type <statement> compressed_statement
%type <statement> loop_statement for_step for_step_opt jump_statement
%type <statement> concurrent_assertion_statement
%type <statement> deferred_immediate_assertion_statement
%type <statement> simple_immediate_assertion_statement
%type <statement> procedural_assertion_statement
%type <statement_list> statement_or_null_list statement_or_null_list_opt
%type <statement> analog_statement
%type <subroutine_call> subroutine_call
%type <join_keyword> join_keyword
%type <letter> spec_polarity
%type <perm_strings> specify_path_identifiers
%type <specpath> specify_simple_path specify_simple_path_decl
%type <specpath> specify_edge_path specify_edge_path_decl
%type <real_type> non_integer_type
%type <int_val> assert_or_assume
%type <int_val> deferred_mode
%type <atom_type> atom_type
%type <int_val> module_start module_end
%type <lifetime> lifetime lifetime_opt
%type <case_quality> unique_priority
%type <genvar_iter> genvar_iteration
%type <package> package_scope
%type <letter> compressed_operator
%type <typedef_basic_type> typedef_basic_type
%token K_TAND
%nonassoc K_PLUS_EQ K_MINUS_EQ K_MUL_EQ K_DIV_EQ K_MOD_EQ K_AND_EQ K_OR_EQ
%nonassoc K_XOR_EQ K_LS_EQ K_RS_EQ K_RSS_EQ K_NB_TRIGGER
%right K_TRIGGER K_LEQUIV
%right '?' ':' K_inside
%left K_LOR
%left K_LAND
%left '|'
%left '^' K_NXOR K_NOR
%left '&' K_NAND
%left K_EQ K_NE K_CEQ K_CNE K_WEQ K_WNE
%left K_GE K_LE '<' '>'
%left K_LS K_RS K_RSS
%left '+' '-'
%left '*' '/' '%'
%left K_POW
%left UNARY_PREC
/* to resolve dangling else ambiguity. */
%nonassoc less_than_K_else
%nonassoc K_else
/* to resolve exclude (... ambiguity */
%nonassoc '('
%nonassoc K_exclude
/* to resolve timeunits declaration/redeclaration ambiguity */
%nonassoc no_timeunits_declaration
%nonassoc one_timeunits_declaration
%nonassoc K_timeunit K_timeprecision
%%
/* IEEE1800-2005: A.1.2 */
/* source_text ::= [ timeunits_declaration ] { description } */
source_text
: timeunits_declaration_opt
{ pform_set_scope_timescale(yyloc); }
description_list
| /* empty */
;
assert_or_assume
: K_assert
{ $$ = 1; } /* IEEE1800-2012: Table 20-7 */
| K_assume
{ $$ = 4; } /* IEEE1800-2012: Table 20-7 */
;
assertion_item /* IEEE1800-2012: A.6.10 */
: concurrent_assertion_item
| deferred_immediate_assertion_item
;
assignment_pattern /* IEEE1800-2005: A.6.7.1 */
: K_LP expression_list_proper '}'
{ PEAssignPattern*tmp = new PEAssignPattern(*$2);
FILE_NAME(tmp, @1);
delete $2;
$$ = tmp;
}
| K_LP '}'
{ PEAssignPattern*tmp = new PEAssignPattern;
FILE_NAME(tmp, @1);
$$ = tmp;
}
;
/* Some rules have a ... [ block_identifier ':' ] ... part. This
implements it in a LALR way. */
block_identifier_opt /* */
: IDENTIFIER ':'
{ $$ = $1; }
|
{ $$ = 0; }
;
class_declaration /* IEEE1800-2005: A.1.2 */
: K_virtual_opt K_class lifetime_opt identifier_name class_declaration_extends_opt ';'
{ /* Up to 1800-2017 the grammar in the LRM allowed an optional lifetime
* qualifier for class declarations. But the LRM never specified what
* this qualifier should do. Starting with 1800-2023 the qualifier has
* been removed from the grammar. Allow it for backwards compatibility,
* but print a warning.
*/
if ($3 != LexicalScope::INHERITED) {
cerr << @1 << ": warning: Class lifetime qualifier is deprecated "
"and has no effect." << endl;
warn_count += 1;
}
perm_string name = lex_strings.make($4);
class_type_t *class_type= new class_type_t(name);
FILE_NAME(class_type, @4);
pform_set_typedef(@4, name, class_type, nullptr);
pform_start_class_declaration(@2, class_type, $5.type, $5.args, $1);
}
class_items_opt K_endclass
{ // Process a class.
pform_end_class_declaration(@9);
}
class_declaration_endlabel_opt
{ // Wrap up the class.
check_end_label(@11, "class", $4, $11);
delete[] $4;
}
;
class_constraint /* IEEE1800-2005: A.1.8 */
: constraint_prototype
| constraint_declaration
;
// This is used in places where a new type can be declared or an existig type
// is referenced. E.g. typedefs.
identifier_name
: IDENTIFIER { $$ = $1; }
| TYPE_IDENTIFIER { $$ = $1.text; }
;
/* The endlabel after a class declaration is a little tricky because
the class name is detected by the lexor as a TYPE_IDENTIFIER if it
does indeed match a name. */
class_declaration_endlabel_opt
: ':' identifier_name { $$ = $2; }
| { $$ = 0; }
;
/* This rule implements [ extends class_type ] in the
class_declaration. It is not a rule of its own in the LRM.
Note that for this to be correct, the identifier after the
extends keyword must be a class name. Therefore, match
TYPE_IDENTIFIER instead of IDENTIFIER, and this rule will return
a data_type. */
class_declaration_extends_opt /* IEEE1800-2005: A.1.2 */
: K_extends ps_type_identifier argument_list_parens_opt
{ $$.type = $2;
$$.args = $3;
}
|
{ $$ = {nullptr, nullptr};
}
;
/* The class_items_opt and class_items rules together implement the
rule snippet { class_item } (zero or more class_item) of the
class_declaration. */
class_items_opt /* IEEE1800-2005: A.1.2 */
: class_items
|
;
class_items /* IEEE1800-2005: A.1.2 */
: class_items class_item
| class_item
;
class_item /* IEEE1800-2005: A.1.8 */
/* IEEE1800 A.1.8: class_constructor_declaration */
: method_qualifier_opt K_function K_new
{ assert(current_function==0);
current_function = pform_push_constructor_scope(@3);
}
tf_port_list_parens_opt ';'
block_item_decls_opt