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 static void perf_bpf_filter_error(struct list_head *expr __maybe_unused, 13 char const *msg) 14 { 15 printf("perf_bpf_filter: %s\n", msg); 16 } 17 18 %} 19 20 %union 21 { 22 unsigned long num; 23 struct { 24 unsigned long type; 25 int part; 26 } sample; 27 enum perf_bpf_filter_op op; 28 struct perf_bpf_filter_expr *expr; 29 } 30 31 %token BFT_SAMPLE BFT_OP BFT_ERROR BFT_NUM BFT_LOGICAL_OR 32 %type <expr> filter_term filter_expr 33 %destructor { free ($$); } <expr> 34 %type <sample> BFT_SAMPLE 35 %type <op> BFT_OP 36 %type <num> BFT_NUM 37 38 %% 39 40 filter: 41 filter ',' filter_term 42 { 43 list_add_tail(&$3->list, expr_head); 44 } 45 | 46 filter_term 47 { 48 list_add_tail(&$1->list, expr_head); 49 } 50 51 filter_term: 52 filter_term BFT_LOGICAL_OR filter_expr 53 { 54 struct perf_bpf_filter_expr *expr; 55 56 if ($1->op == PBF_OP_GROUP_BEGIN) { 57 expr = $1; 58 } else { 59 expr = perf_bpf_filter_expr__new(0, 0, PBF_OP_GROUP_BEGIN, 1); 60 list_add_tail(&$1->list, &expr->groups); 61 } 62 expr->val++; 63 list_add_tail(&$3->list, &expr->groups); 64 $$ = expr; 65 } 66 | 67 filter_expr 68 { 69 $$ = $1; 70 } 71 72 filter_expr: 73 BFT_SAMPLE BFT_OP BFT_NUM 74 { 75 $$ = perf_bpf_filter_expr__new($1.type, $1.part, $2, $3); 76 } 77 78 %% 79