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