summaryrefslogtreecommitdiffstats
path: root/src/usr/diag/prdf/common/rule/prdrCompile.y
blob: 9697fe36290740f826d30f598b7df41a489c473c (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
/* IBM_PROLOG_BEGIN_TAG                                                   */
/* This is an automatically generated prolog.                             */
/*                                                                        */
/* $Source: src/usr/diag/prdf/common/rule/prdrCompile.y $                 */
/*                                                                        */
/* OpenPOWER HostBoot Project                                             */
/*                                                                        */
/* Contributors Listed Below - COPYRIGHT 2016,2017                        */
/* [+] International Business Machines Corp.                              */
/*                                                                        */
/*                                                                        */
/* Licensed under the Apache License, Version 2.0 (the "License");        */
/* you may not use this file except in compliance with the License.       */
/* You may obtain a copy of the License at                                */
/*                                                                        */
/*     http://www.apache.org/licenses/LICENSE-2.0                         */
/*                                                                        */
/* Unless required by applicable law or agreed to in writing, software    */
/* distributed under the License is distributed on an "AS IS" BASIS,      */
/* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or        */
/* implied. See the License for the specific language governing           */
/* permissions and limitations under the License.                         */
/*                                                                        */
/* IBM_PROLOG_END_TAG                                                     */

/* chip.y */

/** @file prdrCompile.y
 *
 *  This file contains all of the yacc code for parsing rule-table syntax and
 *  creating the abstract-syntax tree.
 *
 *  None of this code is ran on the FSP.  It is all used to generate data
 *  files.
 *
 *  Important background:
 *
 *  Compilers, such as yacc/bison, have the concept of a terminal vs.
 *  non-terminal token.  A terminal token is one which is not built from others,
 *  such as a keyword.  A non-terminal token is one that has syntax associated
 *  with it, such as an "expression" token that is made up of many sub-tokens.
 *
 *  Suggested reading material on parsers/compilers would be
 *          http://en.wikipedia.org/wiki/Backus-Naur_form
 */

/* Pre C stuff: headers, etc. */
%{
#include <prdrToken.H>
#include <prdrCommon.H>

#include <string>

#include <prdrRegister.H> // REVIEW NOTE: Move to token.h?

using namespace PRDR_COMPILER;

%}


/* Union for the 'yylval' variable in lex or $$ variables in yacc code.  Used
 * to store the data associated with a parsed token.
 */
%union{

    /* NOTE: Though we will read from rule file every integer as 64 bit number,
     *       when creating prf file we will use, 64 bit number only for
     *       registers. For other we will use it as per need (mostly 32 bit) and
     *       number will be truncated. It will be dictated by code defined in
     *       prdrExpr.H and other rule parsing classes. */

    /** 64 bit unsigned integer value from a token. */
    uint64_t long_integer;

    /** string value from a token. */
    std::string * str_ptr;
    /** Parsed list of registers. */
    PRDR_COMPILER::RegisterList * reglist;
    /** A single parsed register. */
    PRDR_COMPILER::Register * reg;
    /** A structure for the reset / mask keywords. */
    PRDR_COMPILER::ResetOrMaskStruct * reg_mask;
    /** A chip object */
    PRDR_COMPILER::Chip * chip;
    /** A sub-expression token. */
    PRDR_COMPILER::Expr * expr;
    /** A parsed group of bit-operation / action pairs */
    PRDR_COMPILER::Group * grp;
    /** A list of strings */
    std::list<std::string *>* strlist;
    /** A list of filters */
    std::list<PRDR_COMPILER::Group_Filter *>* filterlist;
}

    /* Indicates the name for the start symbol. (non-terminal) */
%start input

    /* Define a number of terminal symbols and the portion of the union
     * associated with each of them.
     */
%token <long_integer> PRDR_INTEGER
%token <str_ptr> PRDR_ID
%token <str_ptr> PRDR_STRING
%token <str_ptr> PRDR_BIT_STRING

    /* Define a number of terminal symbols without associated data:
     * the keywords.
     */
%token PRDR_CHIP
%token PRDR_GROUP
%token PRDR_TYPE
%token PRDR_ACTIONCLASS
%token PRDR_RULE

%token PRDR_CHIPID
%token PRDR_TARGETTYPE
%token PRDR_SIGNATURE_OFFSET
%token PRDR_SIGNATURE_EXTRA
%token PRDR_REGISTER
%token PRDR_NAME_KW
%token PRDR_SCOMADDR
%token PRDR_SCOMLEN
%token PRDR_REGISTER_ACCESS
%token PRDR_REGISTER_READ_ACCESS
%token PRDR_REGISTER_WRITE_ACCESS
%token PRDR_REGISTER_NO_ACCESS
%token PRDR_RESET_ADDR
%token PRDR_MASK_ADDR
%token PRDR_BIT_KW
%token PRDR_OP_LEFTSHIFT
%token PRDR_OP_RIGHTSHIFT
%token PRDR_SUMMARY

%token PRDR_ACT_THRESHOLD
%token PRDR_ACT_ANALYSE
%token PRDR_ACT_TRY
%token PRDR_ACT_DUMP
%token PRDR_ACT_FUNCCALL
%token PRDR_ACT_CALLOUT
%token PRDR_ACT_FLAG
%token PRDR_ACT_CAPTURE

%token PRDR_CONNECTED
%token PRDR_CONNECTED_PEER
%token PRDR_ACT_NONZERO
%token PRDR_ALTERNATE
%token PRDR_PROCEDURE

%token PRDR_ATTNTYPE
%token PRDR_SHARED_KW
%token PRDR_REQUIRED_KW
%token PRDR_MFG_KW
%token PRDR_FLD_KW
%token PRDR_MFG_FILE_KW
%token PRDR_TIME_SEC
%token PRDR_TIME_MIN
%token PRDR_TIME_HOUR
%token PRDR_TIME_DAY
%token PRDR_FILTER

%token PRDR_FILTER_SINGLE_BIT
%token PRDR_FILTER_PRIORITY
%token PRDR_FILTER_CS_ROOT_CAUSE

    /* Terminal tokens for Doxygen-style comments */
%token <str_ptr> PRDR_DOX_COMMENT
%token <str_ptr> PRDR_DOX_ENDL

    /* Non-terminal tokens and the data-type associated with them. */
%type <reg> register reglines regline
%type <reg_mask> register_mask
%type <chip> chiplines chipline
%type <expr> ruleexpr ruleexpr_small ruleexpr_shift ruleop1 ruleop2 summary
%type <expr> bitgroup bitandlist bitorlist
%type <expr> time_units
%type <grp> grouplines groupline
%type <grp> actionlines

%type <expr> actionline
%type <expr> action_threshold action_shared_threshold action_analyse
%type <expr> action_analyse_conn action_try action_capture
%type <expr> action_dump action_callout action_funccall action_flag
%type <expr> action_callout_alt

%type <strlist> grpattns grpattns_item
%type <filterlist> grpfilters grpfilt_items grpfilt_item

%type <str_ptr> dox_comment dox_commentline dox_commentblk

%%
/* Grammars */

    /* The 'input' (or start token) is simply any number of lines. */
input:
        | input line
;

    /* Lines can be a full chip, group, rule, or actionclass.  */
line:   chip
        | group
        | rule
        | actionclass
;

    /* A chip is a chip-keyword, id, and any number of "lines" */
chip:   PRDR_CHIP PRDR_ID '{' chiplines '}' ';'
    {
        // Create a default chip object is chiplines are empty.
        if (NULL == $4)
            $4 = new Chip();

        // Assign chip's shortname from ID.
        $4->cv_sname = $2;

        // Set current chip to be this chip.
        g_currentChip = $4;
    }
;

    /* Any number of lines can make up a chiplines token.  */
chiplines:  { $$ = NULL; }  // empty line.
        | chiplines chipline ';'
    {
        // Merge the chip lines together into a single object as needed.
        if (NULL != $1)
        {
            if (NULL == $2)
                $$ = NULL;
            else
            {
                // Both are non-NULL, merge.
                Chip::merge($1, $2);
                $$ = $1;
                delete $2;
            }
        }
        else
        {
            if (NULL == $2)
                $$ = NULL;
            else
                $$ = $2;
        }
    }

;

    /* Create a chip object based on the contents of the line. */
chipline:   { $$ = NULL; } // allow a free ;.
        | PRDR_CHIPID PRDR_INTEGER
    {
        $$ = new Chip();
        $$->cv_chipid = $2;
    }
        | PRDR_SIGNATURE_OFFSET PRDR_INTEGER
    {
        $$ = new Chip();
        $$->cv_signatureOffset = $2;
    }
        | PRDR_SIGNATURE_EXTRA '(' PRDR_ID ',' PRDR_INTEGER ','
            PRDR_STRING ',' PRDR_STRING ')'
    {
        $$ = new Chip();
        $$->cv_sigExtras.push_back(ExtraSignature($5, $7, $9));
    }
        | PRDR_TARGETTYPE PRDR_ID
    {
        $$ = new Chip();
        $$->cv_targetType = prdrActionArgMap(*$2);
    }
        | PRDR_NAME_KW PRDR_STRING
    {
        $$ = new Chip();
        $$->cv_name = $2;
    }
        | register        // register non-terminal token.
    {
        $$ = new Chip();
        $$->cv_reglist.push_back($1);
    }
        | PRDR_SCOMLEN PRDR_INTEGER
    {
        $$ = new Chip();
        $$->cv_scomlen = $2;
    }
        | PRDR_ACT_DUMP PRDR_ID                        //@ecdf
    {
        $$ = new Chip();
        $$->cv_dumptype = prdrActionArgMap(*$2);
    }
;

    /* A register is the register-keyword, id, and a number of "lines". */
register: PRDR_REGISTER PRDR_ID '{' reglines '}'
    {
        // Create register object as needed.
        if (NULL == $4)
            $$ = new Register();
        else
            $$ = $4;

        // Assign short-name.
        $$->cv_sname = $2;
    }
;
    /* Any number of lines can make up a reglines token.  */
reglines:   { $$ = NULL; }
        | reglines regline ';'
    {
        // Merge register lines as needed.
        if (NULL != $1)
        {
            if (NULL == $2)
                $$ = NULL;
            else
            {
                // Both are non-NULL, merge.
                Register::merge($1, $2);
                $$ = $1;
                delete $2;
            }
        }
        else
        {
            if (NULL == $2)
                $$ = NULL;
            else
                $$ = $2;
        }
    }
;

    /* Define all of the lines (expressions) that can be found in a register */
regline:    { $$ = NULL; }
        | PRDR_NAME_KW PRDR_STRING
    {
        $$ = new Register();
        $$->cv_name = $2;
    }
        | PRDR_NAME_KW PRDR_ID
    {
        $$ = new Register();
        $$->cv_name = $2;
    }
        | PRDR_SCOMADDR PRDR_INTEGER
    {
        $$ = new Register();
        $$->cv_scomaddr = $2;
    }
        | PRDR_SCOMLEN PRDR_INTEGER
    {
        $$ = new Register();
        $$->cv_scomlen = $2;

        // Indicate that the register contains a non-default scomlen.
        $$->cv_flags |= Prdr::PRDR_REGISTER_SCOMLEN;
    }
        | PRDR_RESET_ADDR '(' register_mask ')'
    {
        $$ = new Register();

        // Add reset register to list.
        $$->cv_resets.push_back(*$3);
        delete $3;
    }
        | PRDR_MASK_ADDR '(' register_mask ')'
    {
        $$ = new Register();

        // Add mask register to list.
        $$->cv_masks.push_back(*$3);
        delete $3;
    }
        | PRDR_ACT_CAPTURE PRDR_GROUP PRDR_ID
    {
        $$ = new Register();

        // Define capture group.
        CaptureReqStruct tmp;
        tmp.type = CaptureReqStruct::PRDR_CAPTURE_GROUPID;
        tmp.data[0] = prdrCaptureGroupMap(*$3);

        $$->cv_captures.push_back(tmp);
    }
//@jl04 Add  a new capture "type" here for regsiters.
        | PRDR_ACT_CAPTURE PRDR_TYPE PRDR_ID
    {
        $$ = new Register();

        // Define capture type.
        CaptureReqStruct tmp;
        tmp.type = CaptureReqStruct::PRDR_CAPTURE_TYPE;
        tmp.data[0] = prdrCaptureTypeMap(*$3);
        $$->cv_captures.push_back(tmp);
    }
//@jl04 End.

        |  PRDR_ACT_CAPTURE PRDR_REQUIRED_KW PRDR_CONNECTED '(' PRDR_ID  ')'
    {
        $$ = new Register();

        // Define capture "connected" requirement.
        CaptureReqStruct tmp;
        tmp.type = CaptureReqStruct::PRDR_CAPTURE_CONN;
        tmp.data[0] = prdrActionArgMap(*$5);
        tmp.data[1] = 0;

        $$->cv_captures.push_back(tmp);
    }
        | PRDR_ACT_CAPTURE PRDR_REQUIRED_KW PRDR_CONNECTED '(' PRDR_ID ',' PRDR_INTEGER ')'
    {
        $$ = new Register();

        // Define capture "connected" requirement.
        CaptureReqStruct tmp;
        tmp.type = CaptureReqStruct::PRDR_CAPTURE_CONN;
        tmp.data[0] = prdrActionArgMap(*$5);
        tmp.data[1] = $7;

        $$->cv_captures.push_back(tmp);
    }
        | PRDR_ACT_CAPTURE PRDR_REQUIRED_KW PRDR_ACT_FUNCCALL '(' PRDR_STRING ')'
    {
        $$ = new Register();

        // Define funccall requirement.
        CaptureReqStruct tmp;
        tmp.type = CaptureReqStruct::PRDR_CAPTURE_FUNC;
        tmp.str = *$5;

        $$->cv_captures.push_back(tmp);
    }
        | PRDR_ACT_CAPTURE PRDR_REQUIRED_KW PRDR_ACT_NONZERO '(' PRDR_STRING ')'
    {
        $$ = new Register();

        CaptureReqStruct tmp;
        tmp.type = CaptureReqStruct::PRDR_CAPTURE_NONZERO;
        tmp.str = *$5;

        $$->cv_captures.push_back(tmp);
    }
        | PRDR_REGISTER_ACCESS PRDR_REGISTER_READ_ACCESS
    {
        $$ = new Register();
        $$->cv_flags |= Prdr::PRDR_REGISTER_READ;
    }
        | PRDR_REGISTER_ACCESS PRDR_REGISTER_WRITE_ACCESS
    {
        $$ = new Register();
        $$->cv_flags |= Prdr::PRDR_REGISTER_WRITE;
    }
        | PRDR_REGISTER_ACCESS PRDR_REGISTER_NO_ACCESS
    {
        $$ = new Register();
        $$->cv_flags |= Prdr::PRDR_REGISTER_ACCESS_NIL;
    }
;

    /* Define the possible reset/mask instructions. */
register_mask: '|' ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '|';
        $$->addr_r = $3;
        $$->addr_w = $3;
    }
        | '|' ',' PRDR_INTEGER ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '|';
        $$->addr_r = $3;
        $$->addr_w = $5;
    }
        |  '&' ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '&';
        $$->addr_r = $3;
        $$->addr_w = $3;
    }
        | '&' ',' PRDR_INTEGER ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '&';
        $$->addr_r = $3;
        $$->addr_w = $5;
    }
        |  '^' ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '^';
        $$->addr_r = $3;
        $$->addr_w = $3;
    }
        | '^' ',' PRDR_INTEGER ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '^';
        $$->addr_r = $3;
        $$->addr_w = $5;
    }
        |  '~' ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '~';
        $$->addr_r = $3;
        $$->addr_w = $3;
    }
        | '~' ',' PRDR_INTEGER ',' PRDR_INTEGER
    {
        $$ = new ResetOrMaskStruct();
        $$->type = '~';
        $$->addr_r = $3;
        $$->addr_w = $5;
    }
;

    /* Define a group object. */
group:  PRDR_GROUP PRDR_ID grpattns grpfilters '{' grouplines '}' ';'
    {
        // Add to group map.
        g_groups[*$2] = $6;

        // Add attentions to attention start list.
        if (NULL != $3)
        {
            for (std::list<std::string *>::iterator i = $3->begin();
                 i != $3->end();
                 ++i)
            {
                g_attentionStartGroup[*(*i)] = *$2;
                delete (*i);
            }
        }

        // Add filters to group.
        if (NULL != $4)
        {
            for (std::list<Group_Filter *>::iterator i = $4->begin();
                 i != $4->end();
                 ++i)
            {
                (*i)->AddFilter($6);
                delete (*i);
            }
        }

        // Free string for group name.
        delete $2;
    }
;

    /* Definitions for attention directives. */
grpattns:   { $$ = NULL; }
        | PRDR_ATTNTYPE grpattns_item        { $$ = $2; }
;

    /* Individual attention types defined for group. */
grpattns_item: grpattns_item ',' PRDR_ID
    {
        $$ = $1;
        $$->push_back($3);
    }
        | PRDR_ID
    {
        $$ = new std::list<std::string *>;
        $$->push_back($1);
    }
;

    /* Definitions for filter directives. */
grpfilters:     { $$ = NULL; }
        | PRDR_FILTER grpfilt_items        { $$ = $2; }
;

    /* Individual filter types defined for group. */
grpfilt_items: grpfilt_items ',' grpfilt_item
    {
        $$ = $1;
        $$->push_back(*($3->begin()));
    }
        | grpfilt_item
    {
        $$ = $1;
    }
;

grpfilt_item: PRDR_FILTER_SINGLE_BIT
    {
        $$ = new std::list<Group_Filter *>;
        $$->push_back(new Group_Filter_SingleBit);
    }
;

grpfilt_item: PRDR_FILTER_PRIORITY '(' bitandlist ')'
    {
        $$ = new std::list<Group_Filter *>;
        $$->push_back(new Group_Filter_Priority($3));
    }
;

grpfilt_item: PRDR_FILTER_CS_ROOT_CAUSE '(' bitandlist ')'
    {
        $$ = new std::list<Group_Filter *>;
        $$->push_back(new Group_Filter_CS_Root_Cause($3));
    }
;

grpfilt_item: PRDR_FILTER_CS_ROOT_CAUSE
    {
        $$ = new std::list<Group_Filter *>;
        $$->push_back(new Group_Filter_CS_Root_Cause_Null);
    }
;

grouplines:     { $$ = new Group(); }
        | grouplines groupline ';'
    {
        Group::merge($1,$2);
        $$ = $1;
        delete $2;
    }        | grouplines dox_comment groupline ';'
    {
        $3->setComment(*$2);
        Group::merge($1,$3);
        $$ = $1;
        delete $3;
    }
;

groupline:      { $$ = new Group(); }
        | '(' PRDR_ID ',' bitgroup ')' '?' PRDR_ID
    {
        $$ = new Group();
        $$->cv_rules.push_front(new ExprRule($2,$4,$7));
        g_references.push_front(RefPair("r",*$2));
        g_references.push_front(RefPair("a",*$7));
    }
        | '(' PRDR_ID ',' bitgroup ')' '?' action_analyse
    {
        $$ = new Group();
        $$->cv_rules.push_front(new ExprRule($2,$4,static_cast<ExprRef *>($7)->cv_name));
        g_references.push_front(RefPair("r",*$2));
        g_references.push_front(RefPair("g",*static_cast<ExprRef *>($7)->cv_name));
    }
        | PRDR_ID
    {
        $$ = new Group();
        $$->cv_rules.push_front(new ExprRef($1));
        g_references.push_front(RefPair("g",*$1));
    }
;

bitgroup: PRDR_BIT_KW '(' bitandlist ')'        { $$ = $3; }
        | PRDR_BIT_KW '(' bitorlist ')'                { $$ = $3; }
;

bitandlist: bitandlist ',' PRDR_INTEGER
    {
        $$ = new ExprOp2(Prdr::AND,
                             $1,
                             new ExprInt($3, Prdr::INT_SHORT));
    }
        | PRDR_INTEGER
    {
        $$ = new ExprInt($1, Prdr::INT_SHORT);
    }
;

bitorlist: bitorlist '|' PRDR_INTEGER
    {
        $$ = new ExprOp2(Prdr::OR,
                             $1,
                             new ExprInt($3, Prdr::INT_SHORT));
    }
        | PRDR_INTEGER '|' PRDR_INTEGER
    {
        $$ = new ExprOp2(Prdr::OR,
                             new ExprInt($1, Prdr::INT_SHORT),
                             new ExprInt($3, Prdr::INT_SHORT));
    }
;

rule: PRDR_RULE PRDR_ID '{' ruleexpr ';' '}' ';'
    {
        g_rules[*$2] = new ExprOp1(Prdr::RULE, $4);
        delete $2;
    }
    | PRDR_RULE PRDR_ID '{' PRDR_ID ':' ruleexpr ';' '}' ';'
    {
        g_rules[*$2] = new ExprOp1(Prdr::RULE,
                       new ExprAttnLink($4, $6, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL));
        delete $2;
        delete $4;
    }
    | PRDR_RULE PRDR_ID '{' PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                        '}' ';'
    {
        g_rules[*$2] = new ExprOp1(Prdr::RULE,
                       new ExprAttnLink($4, $6, $8, $10, NULL, NULL, NULL, NULL, NULL, NULL));
        delete $2;
        delete $4;
        delete $8;
    }
    | PRDR_RULE PRDR_ID '{' PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                        '}' ';'
    {
        g_rules[*$2] = new ExprOp1(Prdr::RULE,
                       new ExprAttnLink($4, $6, $8, $10, $12, $14, NULL, NULL, NULL, NULL));
        delete $2;
        delete $4;
        delete $8;
        delete $12;
    }
    | PRDR_RULE PRDR_ID '{' PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                        '}' ';'
    {
        g_rules[*$2] = new ExprOp1(Prdr::RULE,
                       new ExprAttnLink($4, $6, $8, $10, $12, $14, $16, $18, NULL, NULL));
        delete $2;
        delete $4;
        delete $8;
        delete $12;
        delete $16;
    }
    | PRDR_RULE PRDR_ID '{' PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                            PRDR_ID ':' ruleexpr ';'
                        '}' ';'
    {
        g_rules[*$2] = new ExprOp1(Prdr::RULE,
                       new ExprAttnLink($4, $6, $8, $10, $12, $14, $16, $18, $20, $22));
        delete $2;
        delete $4;
        delete $8;
        delete $12;
        delete $16;
        delete $20;
    }
;

ruleexpr: ruleexpr_small                { $$ = $1; }
        | ruleexpr_small ruleop2 ruleexpr
    {
        $$ = $2;
        static_cast<ExprOp2 *>($$)->cv_arg[0] = $1;
        static_cast<ExprOp2 *>($$)->cv_arg[1] = $3;
    }
        | ruleexpr_shift                { $$ = $1; }
;

ruleexpr_small: '(' ruleexpr ')'        { $$ = $2; }
        | PRDR_ID
    {
        $$ = new ExprRef($1);
        g_references.push_front(RefPair("re", *$1));
    }
        | ruleop1 ruleexpr_small
    {
        $$ = $1;
        static_cast<ExprOp1 *>($$)->cv_arg = $2;
    }
        | PRDR_BIT_STRING
    {
        $$ = new ExprBitString(*$1);
        delete $1;
    }
        | summary
    {
        $$ = $1;
    }
;

summary: PRDR_SUMMARY '(' PRDR_INTEGER ',' PRDR_ID ')'
    {
        $$ = new ExprOp2(Prdr::SUMMARY, new ExprInt($3, Prdr::INT_SHORT),
                new ExprRef($5));
        g_references.push_front(RefPair("r", *$5));
    }
;

ruleexpr_shift: ruleexpr_small PRDR_OP_LEFTSHIFT PRDR_INTEGER
    {
        $$ = new ExprOp2(Prdr::LSHIFT,
                             $1,
                             new ExprInt($3));

    }
        | ruleexpr_small PRDR_OP_RIGHTSHIFT PRDR_INTEGER
    {
        $$ = new ExprOp2(Prdr::RSHIFT,
                             $1,
                             new ExprInt($3, Prdr::INT_SHORT));
    }
;

ruleop1: '~'
    {
        $$ = new ExprOp1(Prdr::NOT);
    }
;

ruleop2: '|'
    {
        $$ = new ExprOp2(Prdr::OR);
    }
        | '&'
    {
        $$ = new ExprOp2(Prdr::AND);
    }
        | '^'
    {
        $$ = new ExprOp2(Prdr::XOR);
    }
;

actionclass: PRDR_ACTIONCLASS PRDR_ID '{' actionlines '}' ';'
    {
        g_actionclasses[*$2] = $4;
        delete $2;
    }
    | dox_comment PRDR_ACTIONCLASS PRDR_ID '{' actionlines '}' ';'
    {
        $5->setComment(*$1);
        g_actionclasses[*$3] = $5;
        delete $3;
    }
;

actionlines:
    {
        $$ = new Group(Prdr::ACTION);
    }
        | actionlines actionline ';'
    {
        if (NULL != $2)
            $1->cv_rules.push_back($2);
        $$ = $1;
    }
;

actionline:
    {
        $$ = NULL;
    }
        | PRDR_ID
    {
        $$ = new ExprRef($1);
        g_references.push_front(RefPair("a", *$1));
    }
        | action_threshold          { $$ = $1; }
        | action_shared_threshold   { $$ = $1; }
        | action_analyse            { $$ = $1; }
        | action_analyse_conn       { $$ = $1; }
        | action_try                { $$ = $1; }
        | action_dump               { $$ = $1; }
        | action_callout            { $$ = $1; }
        | action_funccall           { $$ = $1; }
        | action_flag               { $$ = $1; }
        | action_capture            { $$ = $1; }
;

action_threshold: PRDR_ACT_THRESHOLD '(' ')'
    {
        $$ = new ExprAct_Thresh();
    }
    | PRDR_ACT_THRESHOLD '(' PRDR_FLD_KW '(' PRDR_INTEGER  time_units ')' ')'
    {
        $$ = new ExprAct_Thresh($5, $6);
    }
    | PRDR_ACT_THRESHOLD '(' PRDR_FLD_KW '(' PRDR_INTEGER  time_units ')' ','  PRDR_MFG_KW '(' PRDR_INTEGER  time_units ')' ')'
    {
        $$ = new ExprAct_Thresh($5, $6, $11, $12);
    }
    | PRDR_ACT_THRESHOLD '(' PRDR_FLD_KW '(' PRDR_INTEGER  time_units ')' ','  PRDR_MFG_FILE_KW  '(' PRDR_ID ')' ')'
    {
        $$ = new ExprAct_Thresh($5, $6, 0, NULL, $11);
    }
;

action_shared_threshold: action_threshold PRDR_SHARED_KW '(' PRDR_INTEGER ')'
    {
        static_cast<ExprAct_Thresh *>($1)->cv_3 = $4;
        $$ = $1;
    }
;

time_units:
    {
        $$ = new ExprTime(0xffffffff, Prdr::PRDR_TIME_BASE_SEC);
    }
    // FIXME: (RTC 51218) It is impossible to reach a theshold of 1000 per
    //        second because PRD cannot respond to attentions that quickly (at
    //        least on the FSP). Need to add code to check if the threshold is
    //        possible to based on the reaction type per attention ratio.
    | '/' PRDR_TIME_SEC
    {
        $$ = new ExprTime(1, Prdr::PRDR_TIME_BASE_SEC);
    }
    | '/' PRDR_TIME_MIN
    {
        $$ = new ExprTime(1, Prdr::PRDR_TIME_BASE_MIN);
    }
    | '/' PRDR_TIME_HOUR
    {
        $$ = new ExprTime(1, Prdr::PRDR_TIME_BASE_HOUR);
    }
    | '/' PRDR_TIME_DAY
    {
        $$ = new ExprTime(1, Prdr::PRDR_TIME_BASE_DAY);
    }
    | '/' PRDR_INTEGER PRDR_TIME_SEC
    {
        $$ = new ExprTime($2, Prdr::PRDR_TIME_BASE_SEC);
    }
    | '/' PRDR_INTEGER PRDR_TIME_MIN
    {
        $$ = new ExprTime($2, Prdr::PRDR_TIME_BASE_MIN);
    }
    | '/' PRDR_INTEGER PRDR_TIME_HOUR
    {
        $$ = new ExprTime($2, Prdr::PRDR_TIME_BASE_HOUR);
    }
    | '/' PRDR_INTEGER PRDR_TIME_DAY
    {
        $$ = new ExprTime($2, Prdr::PRDR_TIME_BASE_DAY);
    }
;

action_analyse: PRDR_ACT_ANALYSE '(' PRDR_ID ')'
    {
        $$ = new ExprRef($3);
        g_references.push_front(RefPair("g",*$3));
    }
;

action_analyse_conn: PRDR_ACT_ANALYSE '(' PRDR_CONNECTED '(' PRDR_ID ')' ')'
    {
        $$ = new ExprAct_Analyse($5);
    }
;

action_analyse_conn: PRDR_ACT_ANALYSE '(' PRDR_CONNECTED '(' PRDR_ID ','  PRDR_INTEGER ')' ')'
    {
        $$ = new ExprAct_Analyse($5, $7);
    }
;

action_try: PRDR_ACT_TRY '(' actionline ',' actionline ')'
    {
        $$ = new ExprAct_Try($3,$5);
    }
;

action_dump: PRDR_ACT_DUMP '(' PRDR_ID ')'
    {
        $$ = new ExprAct_Dump($3);
    }
;

action_callout: PRDR_ACT_CALLOUT '(' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($3);
    }
        | PRDR_ACT_CALLOUT '(' PRDR_CONNECTED '(' PRDR_ID  action_callout_alt ')' ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($9, $5, Prdr::CALLOUT_GARD_CHIP, 0xffffffff, $6 );
    }
        | PRDR_ACT_CALLOUT '(' PRDR_CONNECTED '(' PRDR_ID  ',' PRDR_INTEGER action_callout_alt ')' ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($11, $5, Prdr::CALLOUT_GARD_CHIP, $7, $8);
    }

        | PRDR_ACT_CALLOUT '(' PRDR_PROCEDURE '(' PRDR_ID ')' ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($8, $5, Prdr::CALLOUT_PROC );
    }
        | PRDR_ACT_CALLOUT '(' PRDR_CONNECTED_PEER '(' PRDR_ID  ',' PRDR_INTEGER  action_callout_alt ')' ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($11, $5, Prdr::CALLOUT_GARD_PEER, $7, $8 );
    }
        | PRDR_ACT_CALLOUT '(' PRDR_ID ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($3, NULL, Prdr::CALLOUT_GARD_SELF, 0xffffffff, NULL, $5);
    }

        | PRDR_ACT_CALLOUT '(' PRDR_CONNECTED '(' PRDR_ID  action_callout_alt')' ',' PRDR_ID ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($9, $5, Prdr::CALLOUT_GARD_CHIP, 0xffffffff, $6, $11 );
    }

        | PRDR_ACT_CALLOUT '(' PRDR_CONNECTED '(' PRDR_ID  ',' PRDR_INTEGER action_callout_alt ')' ',' PRDR_ID ',' PRDR_ID  ')'
    {
        $$ = new ExprAct_Callout($11, $5, Prdr::CALLOUT_GARD_CHIP, $7, $8, $13 );
    }

        | PRDR_ACT_CALLOUT '(' PRDR_CONNECTED_PEER '(' PRDR_ID  ',' PRDR_INTEGER  action_callout_alt ')' ',' PRDR_ID ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Callout($11, $5, Prdr::CALLOUT_GARD_PEER, $7, $8, $13 );
    }
;

action_callout_alt:
    {
        $$ = NULL;
    }
        | ',' PRDR_ALTERNATE '(' actionline ')'
    {
        $$ = $4;
    }
;

action_funccall: PRDR_ACT_FUNCCALL '(' PRDR_STRING ')'
    {
        $$ = new ExprAct_Funccall($3);
    }
        | PRDR_ACT_FUNCCALL '(' PRDR_STRING ',' PRDR_ID ')'
    {
        $$ = new ExprAct_Funccall($3, $5);
    }
;

action_flag: PRDR_ACT_FLAG '(' PRDR_ID ')'
    {
        $$ = new ExprAct_Flag($3);
    }
;

action_capture: PRDR_ACT_CAPTURE '(' PRDR_ID ')'
    {
        $$ = new ExprAct_Capture($3);
    }
;


dox_comment: dox_commentblk
    {
        $$ = $1;
    }
        | dox_commentblk dox_comment
    {
        (*$1) += (*$2);
        $$ = $1;
    }
;

dox_commentblk: dox_commentline
    {
        $$ = $1;
    }
        | PRDR_DOX_ENDL
    {
        $$ = new std::string("\n");
    }
;

dox_commentline: PRDR_DOX_COMMENT
    {
        $$ = $1;
    }
;

%%
/* Additional C Code */

void yyerror(const char * s)
{
    if (yyincfiles.empty())
        fprintf(stderr, "Line %d: %s\n", yyline, s);
    else
        fprintf(stderr, "File %s Line %d: %s\n",
                yyincfiles.top().first.c_str(),
                yyline,
                s);

    g_hadError = true;
}

OpenPOWER on IntegriCloud