aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/tools/perf/util/bpf-filter.y
blob: 0e4d6de3c2ad994db8978d8bab13946f0416fcc8 (plain) (blame)
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
%parse-param {struct list_head *expr_head}
%define parse.error verbose

%{

#ifndef NDEBUG
#define YYDEBUG 1
#endif

#include <stdio.h>
#include <string.h>
#include <linux/compiler.h>
#include <linux/list.h>
#include "bpf-filter.h"

int perf_bpf_filter_lex(void);

static void perf_bpf_filter_error(struct list_head *expr __maybe_unused,
				  char const *msg)
{
	printf("perf_bpf_filter: %s\n", msg);
}

%}

%union
{
	unsigned long num;
	struct {
		unsigned long type;
		int part;
	} sample;
	enum perf_bpf_filter_op op;
	struct perf_bpf_filter_expr *expr;
}

%token BFT_SAMPLE BFT_OP BFT_ERROR BFT_NUM BFT_LOGICAL_OR
%type <expr> filter_term filter_expr
%destructor { free ($$); } <expr>
%type <sample> BFT_SAMPLE
%type <op> BFT_OP
%type <num> BFT_NUM

%%

filter:
filter ',' filter_term
{
	list_add_tail(&$3->list, expr_head);
}
|
filter_term
{
	list_add_tail(&$1->list, expr_head);
}

filter_term:
filter_term BFT_LOGICAL_OR filter_expr
{
	struct perf_bpf_filter_expr *expr;

	if ($1->op == PBF_OP_GROUP_BEGIN) {
		expr = $1;
	} else {
		expr = perf_bpf_filter_expr__new(0, 0, PBF_OP_GROUP_BEGIN, 1);
		list_add_tail(&$1->list, &expr->groups);
	}
	expr->val++;
	list_add_tail(&$3->list, &expr->groups);
	$$ = expr;
}
|
filter_expr
{
	$$ = $1;
}

filter_expr:
BFT_SAMPLE BFT_OP BFT_NUM
{
	$$ = perf_bpf_filter_expr__new($1.type, $1.part, $2, $3);
}

%%