Merge tag 'vfio-v6.9-rc1' of https://github.com/awilliam/linux-vfio
[linux-2.6-block.git] / tools / perf / util / bpf-filter.y
1 %parse-param {struct list_head *expr_head}
2 %define parse.error verbose
3
4 %{
5
6 #ifndef NDEBUG
7 #define YYDEBUG 1
8 #endif
9
10 #include <stdio.h>
11 #include <string.h>
12 #include <linux/compiler.h>
13 #include <linux/list.h>
14 #include "bpf-filter.h"
15
16 int perf_bpf_filter_lex(void);
17
18 static void perf_bpf_filter_error(struct list_head *expr __maybe_unused,
19                                   char const *msg)
20 {
21         printf("perf_bpf_filter: %s\n", msg);
22 }
23
24 %}
25
26 %union
27 {
28         unsigned long num;
29         struct {
30                 unsigned long type;
31                 int part;
32         } sample;
33         enum perf_bpf_filter_op op;
34         struct perf_bpf_filter_expr *expr;
35 }
36
37 %token BFT_SAMPLE BFT_OP BFT_ERROR BFT_NUM BFT_LOGICAL_OR
38 %type <expr> filter_term filter_expr
39 %destructor { free ($$); } <expr>
40 %type <sample> BFT_SAMPLE
41 %type <op> BFT_OP
42 %type <num> BFT_NUM
43
44 %%
45
46 filter:
47 filter ',' filter_term
48 {
49         list_add_tail(&$3->list, expr_head);
50 }
51 |
52 filter_term
53 {
54         list_add_tail(&$1->list, expr_head);
55 }
56
57 filter_term:
58 filter_term BFT_LOGICAL_OR filter_expr
59 {
60         struct perf_bpf_filter_expr *expr;
61
62         if ($1->op == PBF_OP_GROUP_BEGIN) {
63                 expr = $1;
64         } else {
65                 expr = perf_bpf_filter_expr__new(0, 0, PBF_OP_GROUP_BEGIN, 1);
66                 list_add_tail(&$1->list, &expr->groups);
67         }
68         expr->val++;
69         list_add_tail(&$3->list, &expr->groups);
70         $$ = expr;
71 }
72 |
73 filter_expr
74 {
75         $$ = $1;
76 }
77
78 filter_expr:
79 BFT_SAMPLE BFT_OP BFT_NUM
80 {
81         $$ = perf_bpf_filter_expr__new($1.type, $1.part, $2, $3);
82 }
83
84 %%