/
parse.y
4303 lines (3876 loc) · 112 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-2008 Stephen Williams (steve@icarus.com)
*
* 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
*/
# include "config.h"
# include "parse_misc.h"
# include "compiler.h"
# include "pform.h"
# include "Statement.h"
# include "PSpec.h"
# include <stack>
# include <cstring>
# include <sstream>
class PSpecPath;
extern void lex_start_table();
extern void lex_end_table();
static svector<PExpr*>* param_active_range = 0;
static bool param_active_signed = false;
static ivl_variable_type_t param_active_type = IVL_VT_LOGIC;
/* Port declaration lists use this structure for context. */
static struct {
NetNet::Type port_net_type;
NetNet::PortType port_type;
ivl_variable_type_t var_type;
bool sign_flag;
svector<PExpr*>* range;
} port_declaration_context = {NetNet::NONE, NetNet::NOT_A_PORT,
IVL_VT_NO_TYPE, false, 0};
/* 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;
/* 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. */
# define YYLLOC_DEFAULT(Current, Rhs, N) do { \
(Current).first_line = (Rhs)[1].first_line; \
(Current).first_column = (Rhs)[1].first_column; \
(Current).last_line = (Rhs)[N].last_line; \
(Current).last_column = (Rhs)[N].last_column; \
(Current).text = (Rhs)[1].text; } while (0)
/*
* These are some common strength pairs that are used as defaults when
* the user is not otherwise specific.
*/
const static struct str_pair_t pull_strength = { PGate::PULL, PGate::PULL };
const static struct str_pair_t str_strength = { PGate::STRONG, PGate::STRONG };
static list<perm_string>* list_from_identifier(char*id)
{
list<perm_string>*tmp = new list<perm_string>;
tmp->push_back(lex_strings.make(id));
delete[]id;
return tmp;
}
static list<perm_string>* list_from_identifier(list<perm_string>*tmp, char*id)
{
tmp->push_back(lex_strings.make(id));
delete[]id;
return tmp;
}
static svector<PExpr*>* copy_range(svector<PExpr*>* orig)
{
svector<PExpr*>*copy = 0;
if (orig) {
copy = new svector<PExpr*>(2);
(*copy)[0] = (*orig)[0];
(*copy)[1] = (*orig)[1];
}
return copy;
}
/*
* 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)
{
svector<PExpr*> parms(1);
parms[0] = arg;
PECallFunction*tmp = new PECallFunction(tn, parms);
return tmp;
}
static PECallFunction*make_call_function(perm_string tn, PExpr*arg1, PExpr*arg2)
{
svector<PExpr*> parms(2);
parms[0] = arg1;
parms[1] = arg2;
PECallFunction*tmp = new PECallFunction(tn, parms);
return tmp;
}
%}
%union {
bool flag;
char letter;
/* text items are C strings allocated by the lexor using
strdup. They can be put into lists with the texts type. */
char*text;
list<perm_string>*perm_strings;
pform_name_t*pform_name;
discipline_t*discipline;
hname_t*hier;
list<string>*strings;
struct str_pair_t drive;
PCase::Item*citem;
svector<PCase::Item*>*citems;
lgate*gate;
svector<lgate>*gates;
Module::port_t *mport;
Module::range_t* value_range;
svector<Module::port_t*>*mports;
named_pexpr_t*named_pexpr;
svector<named_pexpr_t*>*named_pexprs;
struct parmvalue_t*parmvalue;
PExpr*expr;
svector<PExpr*>*exprs;
svector<PEEvent*>*event_expr;
NetNet::Type nettype;
PGBuiltin::Type gatetype;
NetNet::PortType porttype;
ivl_variable_type_t datatype;
PWire*wire;
svector<PWire*>*wires;
PEventStatement*event_statement;
Statement*statement;
svector<Statement*>*statement_list;
AStatement*astatement;
PTaskFuncArg function_type;
net_decl_assign_t*net_decl_assign;
verinum* number;
verireal* realtime;
PSpecPath* specpath;
list<index_component_t> *dimensions;
};
%token <text> IDENTIFIER SYSTEM_IDENTIFIER STRING
%token <discipline> DISCIPLINE_IDENTIFIER
%token <text> PATHPULSE_IDENTIFIER
%token <number> BASED_NUMBER DEC_NUMBER
%token <realtime> REALTIME
%token K_LE K_GE K_EG K_EQ K_NE K_CEQ K_CNE 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
%token K_LOR K_LAND K_NAND K_NOR K_NXOR K_TRIGGER
%token K_abs K_abstol K_access K_acos K_acosh K_asin K_analog K_asinh
%token K_atan K_atanh K_atan2
%token K_always K_and K_assign K_begin K_bool K_buf K_bufif0 K_bufif1 K_case
%token K_casex K_casez K_ceil K_cmos K_continuous K_cos K_cosh
%token K_ddt_nature K_deassign K_default K_defparam K_disable K_discrete
%token K_domain K_edge K_edge_descriptor K_discipline
%token K_else K_end K_endcase K_enddiscipline K_endfunction K_endgenerate
%token K_endmodule K_endnature
%token K_endprimitive K_endspecify K_endtable K_endtask K_event
%token K_exclude K_exp K_floor K_flow K_from
%token K_for K_force K_forever K_fork K_function K_generate K_genvar
%token K_ground K_highz0 K_highz1 K_hypot K_idt_nature K_if K_ifnone K_inf
%token K_initial K_inout K_input K_integer K_join K_large K_ln K_localparam
%token K_log K_logic K_macromodule K_max
%token K_medium K_min K_module K_nand K_nature K_negedge
%token K_nmos K_nor K_not K_notif0
%token K_notif1 K_or K_output K_parameter K_pmos K_posedge K_potential
%token K_pow K_primitive
%token K_pull0 K_pull1 K_pulldown K_pullup K_rcmos K_real K_realtime
%token K_reg K_release K_repeat
%token K_rnmos K_rpmos K_rtran K_rtranif0 K_rtranif1 K_scalared
%token K_signed K_sin K_sinh K_small K_specify
%token K_specparam K_sqrt K_string K_strong0 K_strong1 K_supply0 K_supply1
%token K_table
%token K_tan K_tanh K_task
%token K_time K_tran K_tranif0 K_tranif1 K_tri K_tri0 K_tri1 K_triand
%token K_trior K_trireg K_units K_vectored K_wait K_wand K_weak0 K_weak1
%token K_while K_wire
%token K_wone K_wor K_xnor K_xor
%token K_Shold K_Speriod K_Srecovery K_Srecrem K_Ssetup K_Swidth K_Ssetuphold
%token KK_attribute
%type <flag> from_exclude
%type <number> number
%type <flag> signed_opt 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 <perm_strings> udp_input_declaration_list
%type <strings> udp_entry_list udp_comb_entry_list udp_sequ_entry_list
%type <strings> udp_body
%type <perm_strings> udp_port_list
%type <wires> udp_port_decl udp_port_decls
%type <statement> udp_initial udp_init_opt
%type <expr> udp_initial_expr_opt
%type <text> register_variable net_variable real_variable
%type <perm_strings> register_variable_list net_variable_list real_variable_list list_of_identifiers
%type <net_decl_assign> net_decl_assign net_decl_assigns
%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
%type <value_range> parameter_value_range parameter_value_ranges
%type <value_range> parameter_value_ranges_opt
%type <expr> value_range_expression
%type <wires> task_item task_item_list task_item_list_opt
%type <wires> task_port_item task_port_decl task_port_decl_list
%type <wires> function_item function_item_list
%type <named_pexpr> port_name parameter_value_byname
%type <named_pexprs> port_name_list parameter_value_byname_list
%type <named_pexpr> attribute
%type <named_pexprs> attribute_list attribute_list_opt
%type <citem> case_item
%type <citems> case_items
%type <gate> gate_instance
%type <gates> gate_instance_list
%type <pform_name> hierarchy_identifier
%type <expr> expression expr_primary expr_mintypmax
%type <expr> lpvalue
%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 <exprs> range range_opt
%type <dimensions> dimensions_opt dimensions
%type <nettype> net_type var_type net_type_opt
%type <gatetype> gatetype
%type <porttype> port_type
%type <datatype> primitive_type primitive_type_opt
%type <parmvalue> parameter_value_opt
%type <function_type> function_range_or_type_opt
%type <event_expr> event_expression_list
%type <event_expr> event_expression
%type <event_statement> event_control
%type <statement> statement statement_or_null
%type <statement_list> statement_list
%type <astatement> analog_statement
%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
%token K_TAND
%right '?' ':'
%left K_LOR
%left K_LAND
%left '|'
%left '^' K_NXOR K_NOR
%left '&' K_NAND
%left K_EQ K_NE K_CEQ K_CNE
%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
%%
/* A degenerate source file can be completely empty. */
main : source_file | ;
source_file
: description
| source_file description
;
number : BASED_NUMBER
{ $$ = $1; based_size = 0;}
| DEC_NUMBER
{ $$ = $1; based_size = 0;}
| DEC_NUMBER BASED_NUMBER
{ $$ = pform_verinum_with_size($1,$2, @2.text, @2.first_line);
based_size = 0; }
;
/* Verilog-2001 supports attribute lists, which can be attached to a
variety of different objects. The syntax inside the (* *) is a
comma separated list of names or names with assigned values. */
attribute_list_opt
: K_PSTAR attribute_list K_STARP { $$ = $2; }
| K_PSTAR K_STARP { $$ = 0; }
| { $$ = 0; }
;
attribute_list
: attribute_list ',' attribute
{ svector<named_pexpr_t*>*tmp =
new svector<named_pexpr_t*>(*$1,$3);
delete $1;
$$ = tmp;
}
| attribute
{ svector<named_pexpr_t*>*tmp = new svector<named_pexpr_t*>(1);
(*tmp)[0] = $1;
$$ = tmp;
}
;
attribute
: IDENTIFIER
{ named_pexpr_t*tmp = new named_pexpr_t;
tmp->name = lex_strings.make($1);
tmp->parm = 0;
delete[]$1;
$$ = tmp;
}
| IDENTIFIER '=' expression
{ PExpr*tmp = $3;
if (!pform_expression_is_constant(tmp)) {
yyerror(@3, "error: attribute value "
"expression must be constant.");
delete tmp;
tmp = 0;
}
named_pexpr_t*tmp2 = new named_pexpr_t;
tmp2->name = lex_strings.make($1);
tmp2->parm = tmp;
delete[]$1;
$$ = tmp2;
}
;
/* The block_item_decl is used in function definitions, task
definitions, module definitions and named blocks. Wherever a new
scope is entered, the source may declare new registers and
integers. This rule matches those declarations. The containing
rule has presumably set up the scope. */
block_item_decl
: attribute_list_opt K_reg
primitive_type_opt signed_opt range
register_variable_list ';'
{ ivl_variable_type_t dtype = $3;
if (dtype == IVL_VT_NO_TYPE)
dtype = IVL_VT_LOGIC;
pform_set_net_range($6, $5, $4, dtype);
if ($1) delete $1;
}
/* This differs from the above pattern only in the absence of the
range. This is the rule for a scalar. */
| attribute_list_opt K_reg
primitive_type_opt signed_opt
register_variable_list ';'
{ ivl_variable_type_t dtype = $3;
if (dtype == IVL_VT_NO_TYPE)
dtype = IVL_VT_LOGIC;
pform_set_net_range($5, 0, $4, dtype);
if ($1) delete $1;
}
/* Integer declarations are simpler in that they do not have all the
trappings of a general variable declaration. All of that is
implicit in the "integer" of the declaration. */
| attribute_list_opt K_integer register_variable_list ';'
{ pform_set_reg_integer($3);
if ($1) delete $1;
}
| attribute_list_opt K_time register_variable_list ';'
{ pform_set_reg_time($3);
}
/* real declarations are fairly simple as there is no range of
signed flag in the declaration. Create the real as a NetNet::REG
with real value. Note that real and realtime are interchangeable
in this context. */
| attribute_list_opt K_real real_variable_list ';'
{ delete $3; }
| attribute_list_opt K_realtime real_variable_list ';'
{ delete $3; }
| K_parameter parameter_assign_decl ';'
| K_localparam localparam_assign_decl ';'
/* Recover from errors that happen within variable lists. Use the
trailing semi-colon to resync the parser. */
| attribute_list_opt K_reg error ';'
{ yyerror(@2, "error: syntax error in reg variable list.");
yyerrok;
if ($1) delete $1;
}
| attribute_list_opt K_integer error ';'
{ yyerror(@2, "error: syntax error in integer variable list.");
yyerrok;
if ($1) delete $1;
}
| attribute_list_opt K_time error ';'
{ yyerror(@2, "error: syntax error in time variable list.");
yyerrok;
}
| attribute_list_opt K_real error ';'
{ yyerror(@2, "error: syntax error in real variable list.");
yyerrok;
}
| attribute_list_opt K_realtime error ';'
{ yyerror(@2, "error: syntax error in realtime variable list.");
yyerrok;
}
| K_parameter error ';'
{ yyerror(@1, "error: syntax error in parameter list.");
yyerrok;
}
| K_localparam error ';'
{ yyerror(@1, "error: syntax error localparam list.");
yyerrok;
}
;
block_item_decls
: block_item_decl
| block_item_decls block_item_decl
;
block_item_decls_opt
: block_item_decls
|
;
case_item
: expression_list_proper ':' statement_or_null
{ PCase::Item*tmp = new PCase::Item;
tmp->expr = *$1;
tmp->stat = $3;
delete $1;
$$ = tmp;
}
| K_default ':' statement_or_null
{ PCase::Item*tmp = new PCase::Item;
tmp->stat = $3;
$$ = tmp;
}
| K_default statement_or_null
{ PCase::Item*tmp = new PCase::Item;
tmp->stat = $2;
$$ = tmp;
}
| error ':' statement_or_null
{ yyerror(@2, "error: Incomprehensible case expression.");
yyerrok;
}
;
case_items
: case_items case_item
{ svector<PCase::Item*>*tmp;
tmp = new svector<PCase::Item*>(*$1, $2);
delete $1;
$$ = tmp;
}
| case_item
{ svector<PCase::Item*>*tmp = new svector<PCase::Item*>(1);
(*tmp)[0] = $1;
$$ = tmp;
}
;
charge_strength
: '(' K_small ')'
| '(' K_medium ')'
| '(' K_large ')'
;
charge_strength_opt
: charge_strength
|
;
defparam_assign
: hierarchy_identifier '=' expression
{ PExpr*tmp = $3;
if (!pform_expression_is_constant(tmp)) {
yyerror(@3, "error: parameter value "
"must be constant.");
delete tmp;
tmp = 0;
}
pform_set_defparam(*$1, $3);
delete $1;
}
;
defparam_assign_list
: defparam_assign
| range defparam_assign
{ yyerror(@1, "error: defparam may not include a range.");
delete $1;
}
| defparam_assign_list ',' defparam_assign
;
delay1
: '#' delay_value_simple
{ svector<PExpr*>*tmp = new svector<PExpr*>(1);
(*tmp)[0] = $2;
$$ = tmp;
}
| '#' '(' delay_value ')'
{ svector<PExpr*>*tmp = new svector<PExpr*>(1);
(*tmp)[0] = $3;
$$ = tmp;
}
;
delay3
: '#' delay_value_simple
{ svector<PExpr*>*tmp = new svector<PExpr*>(1);
(*tmp)[0] = $2;
$$ = tmp;
}
| '#' '(' delay_value ')'
{ svector<PExpr*>*tmp = new svector<PExpr*>(1);
(*tmp)[0] = $3;
$$ = tmp;
}
| '#' '(' delay_value ',' delay_value ')'
{ svector<PExpr*>*tmp = new svector<PExpr*>(2);
(*tmp)[0] = $3;
(*tmp)[1] = $5;
$$ = tmp;
}
| '#' '(' delay_value ',' delay_value ',' delay_value ')'
{ svector<PExpr*>*tmp = new svector<PExpr*>(3);
(*tmp)[0] = $3;
(*tmp)[1] = $5;
(*tmp)[2] = $7;
$$ = tmp;
}
;
delay3_opt
: delay3 { $$ = $1; }
| { $$ = 0; }
;
delay_value_list
: delay_value
{ svector<PExpr*>*tmp = new svector<PExpr*>(1);
(*tmp)[0] = $1;
$$ = tmp;
}
| delay_value_list ',' delay_value
{ svector<PExpr*>*tmp = new svector<PExpr*>(*$1, $3);
delete $1;
$$ = tmp;
}
;
delay_value
: expression
{ PExpr*tmp = $1;
$$ = tmp;
}
| expression ':' expression ':' expression
{ $$ = pform_select_mtm_expr($1, $3, $5); }
;
delay_value_simple
: DEC_NUMBER
{ verinum*tmp = $1;
if (tmp == 0) {
yyerror(@1, "internal error: delay.");
$$ = 0;
} else {
$$ = new PENumber(tmp);
FILE_NAME($$, @1);
}
based_size = 0;
}
| REALTIME
{ verireal*tmp = $1;
if (tmp == 0) {
yyerror(@1, "internal error: delay.");
$$ = 0;
} else {
$$ = new PEFNumber(tmp);
FILE_NAME($$, @1);
}
}
| IDENTIFIER
{ PEIdent*tmp = new PEIdent(lex_strings.make($1));
FILE_NAME(tmp, @1);
$$ = tmp;
delete[]$1;
}
;
description
: module
| udp_primitive
| nature_declaration
| discipline_declaration
| KK_attribute '(' IDENTIFIER ',' STRING ',' STRING ')'
{ perm_string tmp3 = lex_strings.make($3);
pform_set_type_attrib(tmp3, $5, $7);
delete[]$3;
delete $5;
}
;
/* The discipline and nature declarations used to take no ';' after
the identifier. The 2.3 LRM adds the ';', but since there are
programs written to the 2.1 and 2.2 standard that don't, we
choose to make the ';' optional in this context. */
optional_semicolon : ';' | ;
discipline_declaration
: K_discipline IDENTIFIER optional_semicolon
{ pform_start_discipline($2); }
discipline_items K_enddiscipline
{ pform_end_discipline(@1); delete[] $2; }
;
discipline_items
: discipline_items discipline_item
| discipline_item
;
discipline_item
: K_domain K_discrete ';'
{ pform_discipline_domain(@1, DD_DISCRETE); }
| K_domain K_continuous ';'
{ pform_discipline_domain(@1, DD_CONTINUOUS); }
| K_potential IDENTIFIER ';'
{ pform_discipline_potential(@1, $2); delete[] $2; }
| K_flow IDENTIFIER ';'
{ pform_discipline_flow(@1, $2); delete[] $2; }
;
nature_declaration
: K_nature IDENTIFIER optional_semicolon
{ pform_start_nature($2); }
nature_items
K_endnature
{ pform_end_nature(@1); delete[] $2; }
;
nature_items
: nature_items nature_item
| nature_item
;
nature_item
: K_units '=' STRING ';'
{ delete[] $3; }
| K_abstol '=' expression ';'
| K_access '=' IDENTIFIER ';'
{ pform_nature_access(@1, $3); delete[] $3; }
| K_idt_nature '=' IDENTIFIER ';'
{ delete[] $3; }
| K_ddt_nature '=' IDENTIFIER ';'
{ delete[] $3; }
;
drive_strength
: '(' dr_strength0 ',' dr_strength1 ')'
{ $$.str0 = $2.str0;
$$.str1 = $4.str1;
}
| '(' dr_strength1 ',' dr_strength0 ')'
{ $$.str0 = $4.str0;
$$.str1 = $2.str1;
}
| '(' dr_strength0 ',' K_highz1 ')'
{ $$.str0 = $2.str0;
$$.str1 = PGate::HIGHZ;
}
| '(' dr_strength1 ',' K_highz0 ')'
{ $$.str0 = PGate::HIGHZ;
$$.str1 = $2.str1;
}
| '(' K_highz1 ',' dr_strength0 ')'
{ $$.str0 = $4.str0;
$$.str1 = PGate::HIGHZ;
}
| '(' K_highz0 ',' dr_strength1 ')'
{ $$.str0 = PGate::HIGHZ;
$$.str1 = $4.str1;
}
;
drive_strength_opt
: drive_strength { $$ = $1; }
| { $$.str0 = PGate::STRONG; $$.str1 = PGate::STRONG; }
;
dr_strength0
: K_supply0 { $$.str0 = PGate::SUPPLY; }
| K_strong0 { $$.str0 = PGate::STRONG; }
| K_pull0 { $$.str0 = PGate::PULL; }
| K_weak0 { $$.str0 = PGate::WEAK; }
;
dr_strength1
: K_supply1 { $$.str1 = PGate::SUPPLY; }
| K_strong1 { $$.str1 = PGate::STRONG; }
| K_pull1 { $$.str1 = PGate::PULL; }
| K_weak1 { $$.str1 = PGate::WEAK; }
;
event_control
: '@' hierarchy_identifier
{ PEIdent*tmpi = new PEIdent(*$2);
PEEvent*tmpe = new PEEvent(PEEvent::ANYEDGE, tmpi);
PEventStatement*tmps = new PEventStatement(tmpe);
FILE_NAME(tmps, @1);
$$ = tmps;
delete $2;
}
| '@' '(' event_expression_list ')'
{ PEventStatement*tmp = new PEventStatement(*$3);
FILE_NAME(tmp, @1);
delete $3;
$$ = tmp;
}
| '@' '(' error ')'
{ yyerror(@1, "error: Malformed event control expression.");
$$ = 0;
}
;
event_expression_list
: event_expression
{ $$ = $1; }
| event_expression_list K_or event_expression
{ svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
delete $1;
delete $3;
$$ = tmp;
}
| event_expression_list ',' event_expression
{ svector<PEEvent*>*tmp = new svector<PEEvent*>(*$1, *$3);
delete $1;
delete $3;
$$ = tmp;
}
;
event_expression
: K_posedge expression
{ PEEvent*tmp = new PEEvent(PEEvent::POSEDGE, $2);
FILE_NAME(tmp, @1);
svector<PEEvent*>*tl = new svector<PEEvent*>(1);
(*tl)[0] = tmp;
$$ = tl;
}
| K_negedge expression
{ PEEvent*tmp = new PEEvent(PEEvent::NEGEDGE, $2);
FILE_NAME(tmp, @1);
svector<PEEvent*>*tl = new svector<PEEvent*>(1);
(*tl)[0] = tmp;
$$ = tl;
}
| expression
{ PEEvent*tmp = new PEEvent(PEEvent::ANYEDGE, $1);
FILE_NAME(tmp, @1);
svector<PEEvent*>*tl = new svector<PEEvent*>(1);
(*tl)[0] = tmp;
$$ = tl;
}
;
/* A branch probe expression applies a probe function (potential or
flow) to a branch. The branch may be implicit as a pair of nets
or explicit as a named branch. Elaboration will check that the
function name really is a nature attribute identifier. */
branch_probe_expression
: IDENTIFIER '(' IDENTIFIER ',' IDENTIFIER ')'
| IDENTIFIER '(' IDENTIFIER ')'
;
expression
: expr_primary
{ $$ = $1; }
| '+' expr_primary %prec UNARY_PREC
{ $$ = $2; }
| '-' expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('-', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| '~' expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('~', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| '&' expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('&', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| '!' expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('!', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| '|' expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('|', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| '^' expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('^', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| K_NAND expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('A', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| K_NOR expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('N', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| K_NXOR expr_primary %prec UNARY_PREC
{ PEUnary*tmp = new PEUnary('X', $2);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| '!' error %prec UNARY_PREC
{ yyerror(@1, "error: Operand of unary ! "
"is not a primary expression.");
$$ = 0;
}
| '^' error %prec UNARY_PREC
{ yyerror(@1, "error: Operand of reduction ^ "
"is not a primary expression.");
$$ = 0;
}
| expression '^' expression
{ PEBinary*tmp = new PEBinary('^', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression K_POW expression
{ PEBinary*tmp = new PEBinary('p', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '*' expression
{ PEBinary*tmp = new PEBinary('*', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '/' expression
{ PEBinary*tmp = new PEBinary('/', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '%' expression
{ PEBinary*tmp = new PEBinary('%', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '+' expression
{ PEBinary*tmp = new PEBinary('+', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '-' expression
{ PEBinary*tmp = new PEBinary('-', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '&' expression
{ PEBinary*tmp = new PEBinary('&', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '|' expression
{ PEBinary*tmp = new PEBinary('|', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression K_NAND expression
{ PEBinary*tmp = new PEBinary('A', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression K_NOR expression
{ PEBinary*tmp = new PEBinary('O', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression K_NXOR expression
{ PEBinary*tmp = new PEBinary('X', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '<' expression
{ PEBinary*tmp = new PEBComp('<', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression '>' expression
{ PEBinary*tmp = new PEBComp('>', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression K_LS expression
{ PEBinary*tmp = new PEBShift('l', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression K_RS expression
{ PEBinary*tmp = new PEBShift('r', $1, $3);
FILE_NAME(tmp, @2);
$$ = tmp;
}
| expression K_RSS expression