xref: /linux/tools/perf/util/bpf-filter.y (revision 36ec807b627b4c0a0a382f0ae48eac7187d14b2b)
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 		enum perf_bpf_filter_term term;
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(PBF_TERM_NONE, /*part=*/0,
66 						 PBF_OP_GROUP_BEGIN, /*val=*/1);
67 		list_add_tail(&$1->list, &expr->groups);
68 	}
69 	expr->val++;
70 	list_add_tail(&$3->list, &expr->groups);
71 	$$ = expr;
72 }
73 |
74 filter_expr
75 {
76 	$$ = $1;
77 }
78 
79 filter_expr:
80 BFT_SAMPLE BFT_OP BFT_NUM
81 {
82 	$$ = perf_bpf_filter_expr__new($1.term, $1.part, $2, $3);
83 }
84 
85 %%
86