]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - tools/perf/util/parse-events.y
perf/tool: Use data struct for arg passing in event parse function
[mirror_ubuntu-bionic-kernel.git] / tools / perf / util / parse-events.y
CommitLineData
89812fc8
JO
1
2%name-prefix "parse_events_"
46010ab2 3%parse-param {void *_data}
89812fc8
JO
4
5%{
6
7#define YYDEBUG 1
8
9#include <linux/compiler.h>
10#include <linux/list.h>
11#include "types.h"
12#include "util.h"
13#include "parse-events.h"
14
15extern int parse_events_lex (void);
16
17#define ABORT_ON(val) \
18do { \
19 if (val) \
20 YYABORT; \
21} while (0)
22
23%}
24
8f707d84 25%token PE_VALUE PE_VALUE_SYM PE_RAW PE_TERM
89812fc8
JO
26%token PE_NAME
27%token PE_MODIFIER_EVENT PE_MODIFIER_BP
28%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
29%token PE_PREFIX_MEM PE_PREFIX_RAW
30%token PE_ERROR
31%type <num> PE_VALUE
32%type <num> PE_VALUE_SYM
33%type <num> PE_RAW
8f707d84 34%type <num> PE_TERM
89812fc8
JO
35%type <str> PE_NAME
36%type <str> PE_NAME_CACHE_TYPE
37%type <str> PE_NAME_CACHE_OP_RESULT
38%type <str> PE_MODIFIER_EVENT
39%type <str> PE_MODIFIER_BP
8f707d84
JO
40%type <head> event_config
41%type <term> event_term
b847cbdc
JO
42%type <head> event_pmu
43%type <head> event_legacy_symbol
44%type <head> event_legacy_cache
45%type <head> event_legacy_mem
46%type <head> event_legacy_tracepoint
47%type <head> event_legacy_numeric
48%type <head> event_legacy_raw
49%type <head> event_def
89812fc8
JO
50
51%union
52{
53 char *str;
54 unsigned long num;
8f707d84
JO
55 struct list_head *head;
56 struct parse_events__term *term;
89812fc8
JO
57}
58%%
59
60events:
61events ',' event | event
62
63event:
64event_def PE_MODIFIER_EVENT
65{
46010ab2
JO
66 struct parse_events_data__events *data = _data;
67
5d7be90e
JO
68 /*
69 * Apply modifier on all events added by single event definition
70 * (there could be more events added for multiple tracepoint
71 * definitions via '*?'.
72 */
b847cbdc 73 ABORT_ON(parse_events_modifier($1, $2));
46010ab2 74 parse_events_update_lists($1, &data->list);
89812fc8
JO
75}
76|
77event_def
5d7be90e 78{
46010ab2
JO
79 struct parse_events_data__events *data = _data;
80
81 parse_events_update_lists($1, &data->list);
5d7be90e 82}
89812fc8 83
5f537a26
JO
84event_def: event_pmu |
85 event_legacy_symbol |
89812fc8
JO
86 event_legacy_cache sep_dc |
87 event_legacy_mem |
88 event_legacy_tracepoint sep_dc |
89 event_legacy_numeric sep_dc |
90 event_legacy_raw sep_dc
91
5f537a26
JO
92event_pmu:
93PE_NAME '/' event_config '/'
94{
46010ab2 95 struct parse_events_data__events *data = _data;
b847cbdc
JO
96 struct list_head *list = NULL;
97
46010ab2 98 ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
5f537a26 99 parse_events__free_terms($3);
b847cbdc 100 $$ = list;
5f537a26
JO
101}
102
89812fc8 103event_legacy_symbol:
8f707d84 104PE_VALUE_SYM '/' event_config '/'
89812fc8 105{
46010ab2 106 struct parse_events_data__events *data = _data;
b847cbdc 107 struct list_head *list = NULL;
89812fc8
JO
108 int type = $1 >> 16;
109 int config = $1 & 255;
110
46010ab2
JO
111 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
112 type, config, $3));
8f707d84 113 parse_events__free_terms($3);
b847cbdc 114 $$ = list;
8f707d84
JO
115}
116|
117PE_VALUE_SYM sep_slash_dc
118{
46010ab2 119 struct parse_events_data__events *data = _data;
b847cbdc 120 struct list_head *list = NULL;
8f707d84
JO
121 int type = $1 >> 16;
122 int config = $1 & 255;
123
46010ab2
JO
124 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
125 type, config, NULL));
b847cbdc 126 $$ = list;
89812fc8
JO
127}
128
129event_legacy_cache:
130PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
131{
46010ab2 132 struct parse_events_data__events *data = _data;
b847cbdc
JO
133 struct list_head *list = NULL;
134
46010ab2 135 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
b847cbdc 136 $$ = list;
89812fc8
JO
137}
138|
139PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
140{
46010ab2 141 struct parse_events_data__events *data = _data;
b847cbdc
JO
142 struct list_head *list = NULL;
143
46010ab2 144 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
b847cbdc 145 $$ = list;
89812fc8
JO
146}
147|
148PE_NAME_CACHE_TYPE
149{
46010ab2 150 struct parse_events_data__events *data = _data;
b847cbdc
JO
151 struct list_head *list = NULL;
152
46010ab2 153 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
b847cbdc 154 $$ = list;
89812fc8
JO
155}
156
157event_legacy_mem:
158PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
159{
46010ab2 160 struct parse_events_data__events *data = _data;
b847cbdc
JO
161 struct list_head *list = NULL;
162
46010ab2
JO
163 ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
164 (void *) $2, $4));
b847cbdc 165 $$ = list;
89812fc8
JO
166}
167|
168PE_PREFIX_MEM PE_VALUE sep_dc
169{
46010ab2 170 struct parse_events_data__events *data = _data;
b847cbdc
JO
171 struct list_head *list = NULL;
172
46010ab2
JO
173 ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
174 (void *) $2, NULL));
b847cbdc 175 $$ = list;
89812fc8
JO
176}
177
178event_legacy_tracepoint:
179PE_NAME ':' PE_NAME
180{
46010ab2 181 struct parse_events_data__events *data = _data;
b847cbdc
JO
182 struct list_head *list = NULL;
183
46010ab2 184 ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
b847cbdc 185 $$ = list;
89812fc8
JO
186}
187
188event_legacy_numeric:
189PE_VALUE ':' PE_VALUE
190{
46010ab2 191 struct parse_events_data__events *data = _data;
b847cbdc
JO
192 struct list_head *list = NULL;
193
46010ab2 194 ABORT_ON(parse_events_add_numeric(&list, &data->idx, $1, $3, NULL));
b847cbdc 195 $$ = list;
89812fc8
JO
196}
197
198event_legacy_raw:
199PE_RAW
200{
46010ab2 201 struct parse_events_data__events *data = _data;
b847cbdc
JO
202 struct list_head *list = NULL;
203
46010ab2
JO
204 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
205 PERF_TYPE_RAW, $1, NULL));
b847cbdc 206 $$ = list;
8f707d84
JO
207}
208
209event_config:
210event_config ',' event_term
211{
212 struct list_head *head = $1;
213 struct parse_events__term *term = $3;
214
215 ABORT_ON(!head);
216 list_add_tail(&term->list, head);
217 $$ = $1;
218}
219|
220event_term
221{
222 struct list_head *head = malloc(sizeof(*head));
223 struct parse_events__term *term = $1;
224
225 ABORT_ON(!head);
226 INIT_LIST_HEAD(head);
227 list_add_tail(&term->list, head);
228 $$ = head;
229}
230
231event_term:
232PE_NAME '=' PE_NAME
233{
234 struct parse_events__term *term;
235
16fa7e82
JO
236 ABORT_ON(parse_events__term_str(&term, PARSE_EVENTS__TERM_TYPE_USER,
237 $1, $3));
8f707d84
JO
238 $$ = term;
239}
240|
241PE_NAME '=' PE_VALUE
242{
243 struct parse_events__term *term;
244
16fa7e82
JO
245 ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
246 $1, $3));
8f707d84
JO
247 $$ = term;
248}
249|
250PE_NAME
251{
252 struct parse_events__term *term;
253
16fa7e82
JO
254 ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
255 $1, 1));
8f707d84
JO
256 $$ = term;
257}
258|
6b5fc39b
JO
259PE_TERM '=' PE_NAME
260{
261 struct parse_events__term *term;
262
263 ABORT_ON(parse_events__term_str(&term, $1, NULL, $3));
264 $$ = term;
265}
266|
8f707d84
JO
267PE_TERM '=' PE_VALUE
268{
269 struct parse_events__term *term;
270
16fa7e82 271 ABORT_ON(parse_events__term_num(&term, $1, NULL, $3));
8f707d84
JO
272 $$ = term;
273}
274|
275PE_TERM
276{
277 struct parse_events__term *term;
278
16fa7e82 279 ABORT_ON(parse_events__term_num(&term, $1, NULL, 1));
8f707d84 280 $$ = term;
89812fc8
JO
281}
282
283sep_dc: ':' |
284
8f707d84
JO
285sep_slash_dc: '/' | ':' |
286
89812fc8
JO
287%%
288
46010ab2 289void parse_events_error(void *data __used,
89812fc8
JO
290 char const *msg __used)
291{
292}