blob: 2bc5fbff2b5d2b101ac4b65cb9623c5d7ff24326 [file] [log] [blame]
Zheng Yanac20de6f2012-06-15 14:31:39 +08001%pure-parser
Jiri Olsa89812fc2012-03-15 20:09:15 +01002%name-prefix "parse_events_"
Jiri Olsa46010ab2012-06-15 14:31:38 +08003%parse-param {void *_data}
Zheng Yanac20de6f2012-06-15 14:31:39 +08004%parse-param {void *scanner}
5%lex-param {void* scanner}
Jiri Olsa89812fc2012-03-15 20:09:15 +01006
7%{
8
9#define YYDEBUG 1
10
11#include <linux/compiler.h>
12#include <linux/list.h>
13#include "types.h"
14#include "util.h"
15#include "parse-events.h"
Zheng Yanac20de6f2012-06-15 14:31:39 +080016#include "parse-events-bison.h"
Jiri Olsa89812fc2012-03-15 20:09:15 +010017
Zheng Yanac20de6f2012-06-15 14:31:39 +080018extern int parse_events_lex (YYSTYPE* lvalp, void* scanner);
Jiri Olsa89812fc2012-03-15 20:09:15 +010019
20#define ABORT_ON(val) \
21do { \
22 if (val) \
23 YYABORT; \
24} while (0)
25
26%}
27
Jiri Olsa90e2b222012-06-15 14:31:40 +080028%token PE_START_EVENTS PE_START_TERMS
Jiri Olsacf3506d2012-07-04 00:00:43 +020029%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010030%token PE_NAME
31%token PE_MODIFIER_EVENT PE_MODIFIER_BP
32%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
33%token PE_PREFIX_MEM PE_PREFIX_RAW
34%token PE_ERROR
35%type <num> PE_VALUE
Jiri Olsacf3506d2012-07-04 00:00:43 +020036%type <num> PE_VALUE_SYM_HW
37%type <num> PE_VALUE_SYM_SW
Jiri Olsa89812fc2012-03-15 20:09:15 +010038%type <num> PE_RAW
Jiri Olsa8f707d82012-03-15 20:09:16 +010039%type <num> PE_TERM
Jiri Olsa89812fc2012-03-15 20:09:15 +010040%type <str> PE_NAME
41%type <str> PE_NAME_CACHE_TYPE
42%type <str> PE_NAME_CACHE_OP_RESULT
43%type <str> PE_MODIFIER_EVENT
44%type <str> PE_MODIFIER_BP
Jiri Olsacf3506d2012-07-04 00:00:43 +020045%type <num> value_sym
Jiri Olsa8f707d82012-03-15 20:09:16 +010046%type <head> event_config
47%type <term> event_term
Jiri Olsab847cbd2012-05-21 09:12:51 +020048%type <head> event_pmu
49%type <head> event_legacy_symbol
50%type <head> event_legacy_cache
51%type <head> event_legacy_mem
52%type <head> event_legacy_tracepoint
53%type <head> event_legacy_numeric
54%type <head> event_legacy_raw
55%type <head> event_def
Jiri Olsa89812fc2012-03-15 20:09:15 +010056
57%union
58{
59 char *str;
60 unsigned long num;
Jiri Olsa8f707d82012-03-15 20:09:16 +010061 struct list_head *head;
62 struct parse_events__term *term;
Jiri Olsa89812fc2012-03-15 20:09:15 +010063}
64%%
65
Jiri Olsa90e2b222012-06-15 14:31:40 +080066start:
67PE_START_EVENTS events
68|
69PE_START_TERMS terms
70
Jiri Olsa89812fc2012-03-15 20:09:15 +010071events:
72events ',' event | event
73
74event:
75event_def PE_MODIFIER_EVENT
76{
Jiri Olsa46010ab2012-06-15 14:31:38 +080077 struct parse_events_data__events *data = _data;
78
Jiri Olsa5d7be902012-03-20 19:15:40 +010079 /*
80 * Apply modifier on all events added by single event definition
81 * (there could be more events added for multiple tracepoint
82 * definitions via '*?'.
83 */
Jiri Olsab847cbd2012-05-21 09:12:51 +020084 ABORT_ON(parse_events_modifier($1, $2));
Jiri Olsa46010ab2012-06-15 14:31:38 +080085 parse_events_update_lists($1, &data->list);
Jiri Olsa89812fc2012-03-15 20:09:15 +010086}
87|
88event_def
Jiri Olsa5d7be902012-03-20 19:15:40 +010089{
Jiri Olsa46010ab2012-06-15 14:31:38 +080090 struct parse_events_data__events *data = _data;
91
92 parse_events_update_lists($1, &data->list);
Jiri Olsa5d7be902012-03-20 19:15:40 +010093}
Jiri Olsa89812fc2012-03-15 20:09:15 +010094
Jiri Olsa5f537a22012-03-15 20:09:18 +010095event_def: event_pmu |
96 event_legacy_symbol |
Jiri Olsa89812fc2012-03-15 20:09:15 +010097 event_legacy_cache sep_dc |
98 event_legacy_mem |
99 event_legacy_tracepoint sep_dc |
100 event_legacy_numeric sep_dc |
101 event_legacy_raw sep_dc
102
Jiri Olsa5f537a22012-03-15 20:09:18 +0100103event_pmu:
104PE_NAME '/' event_config '/'
105{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800106 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200107 struct list_head *list = NULL;
108
Jiri Olsa46010ab2012-06-15 14:31:38 +0800109 ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
Jiri Olsa5f537a22012-03-15 20:09:18 +0100110 parse_events__free_terms($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200111 $$ = list;
Jiri Olsa5f537a22012-03-15 20:09:18 +0100112}
113
Jiri Olsacf3506d2012-07-04 00:00:43 +0200114value_sym:
115PE_VALUE_SYM_HW
116|
117PE_VALUE_SYM_SW
118
Jiri Olsa89812fc2012-03-15 20:09:15 +0100119event_legacy_symbol:
Jiri Olsacf3506d2012-07-04 00:00:43 +0200120value_sym '/' event_config '/'
Jiri Olsa89812fc2012-03-15 20:09:15 +0100121{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800122 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200123 struct list_head *list = NULL;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100124 int type = $1 >> 16;
125 int config = $1 & 255;
126
Jiri Olsa46010ab2012-06-15 14:31:38 +0800127 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
128 type, config, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100129 parse_events__free_terms($3);
Jiri Olsab847cbd2012-05-21 09:12:51 +0200130 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100131}
132|
Jiri Olsacf3506d2012-07-04 00:00:43 +0200133value_sym sep_slash_dc
Jiri Olsa8f707d82012-03-15 20:09:16 +0100134{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800135 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200136 struct list_head *list = NULL;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100137 int type = $1 >> 16;
138 int config = $1 & 255;
139
Jiri Olsa46010ab2012-06-15 14:31:38 +0800140 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
141 type, config, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200142 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100143}
144
145event_legacy_cache:
146PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
147{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800148 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200149 struct list_head *list = NULL;
150
Jiri Olsa46010ab2012-06-15 14:31:38 +0800151 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200152 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100153}
154|
155PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
156{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800157 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200158 struct list_head *list = NULL;
159
Jiri Olsa46010ab2012-06-15 14:31:38 +0800160 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200161 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100162}
163|
164PE_NAME_CACHE_TYPE
165{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800166 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200167 struct list_head *list = NULL;
168
Jiri Olsa46010ab2012-06-15 14:31:38 +0800169 ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200170 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100171}
172
173event_legacy_mem:
174PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
175{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800176 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200177 struct list_head *list = NULL;
178
Jiri Olsa46010ab2012-06-15 14:31:38 +0800179 ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
180 (void *) $2, $4));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200181 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100182}
183|
184PE_PREFIX_MEM PE_VALUE sep_dc
185{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800186 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200187 struct list_head *list = NULL;
188
Jiri Olsa46010ab2012-06-15 14:31:38 +0800189 ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
190 (void *) $2, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200191 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100192}
193
194event_legacy_tracepoint:
195PE_NAME ':' PE_NAME
196{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800197 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200198 struct list_head *list = NULL;
199
Jiri Olsa46010ab2012-06-15 14:31:38 +0800200 ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200201 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100202}
203
204event_legacy_numeric:
205PE_VALUE ':' PE_VALUE
206{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800207 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200208 struct list_head *list = NULL;
209
Jiri Olsa46010ab2012-06-15 14:31:38 +0800210 ABORT_ON(parse_events_add_numeric(&list, &data->idx, $1, $3, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200211 $$ = list;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100212}
213
214event_legacy_raw:
215PE_RAW
216{
Jiri Olsa46010ab2012-06-15 14:31:38 +0800217 struct parse_events_data__events *data = _data;
Jiri Olsab847cbd2012-05-21 09:12:51 +0200218 struct list_head *list = NULL;
219
Jiri Olsa46010ab2012-06-15 14:31:38 +0800220 ABORT_ON(parse_events_add_numeric(&list, &data->idx,
221 PERF_TYPE_RAW, $1, NULL));
Jiri Olsab847cbd2012-05-21 09:12:51 +0200222 $$ = list;
Jiri Olsa8f707d82012-03-15 20:09:16 +0100223}
224
Jiri Olsa90e2b222012-06-15 14:31:40 +0800225terms: event_config
226{
227 struct parse_events_data__terms *data = _data;
228 data->terms = $1;
229}
230
Jiri Olsa8f707d82012-03-15 20:09:16 +0100231event_config:
232event_config ',' event_term
233{
234 struct list_head *head = $1;
235 struct parse_events__term *term = $3;
236
237 ABORT_ON(!head);
238 list_add_tail(&term->list, head);
239 $$ = $1;
240}
241|
242event_term
243{
244 struct list_head *head = malloc(sizeof(*head));
245 struct parse_events__term *term = $1;
246
247 ABORT_ON(!head);
248 INIT_LIST_HEAD(head);
249 list_add_tail(&term->list, head);
250 $$ = head;
251}
252
253event_term:
254PE_NAME '=' PE_NAME
255{
256 struct parse_events__term *term;
257
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200258 ABORT_ON(parse_events__term_str(&term, PARSE_EVENTS__TERM_TYPE_USER,
259 $1, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100260 $$ = term;
261}
262|
263PE_NAME '=' PE_VALUE
264{
265 struct parse_events__term *term;
266
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200267 ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
268 $1, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100269 $$ = term;
270}
271|
272PE_NAME
273{
274 struct parse_events__term *term;
275
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200276 ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
277 $1, 1));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100278 $$ = term;
279}
280|
Jiri Olsa6b5fc392012-05-21 09:12:53 +0200281PE_TERM '=' PE_NAME
282{
283 struct parse_events__term *term;
284
285 ABORT_ON(parse_events__term_str(&term, $1, NULL, $3));
286 $$ = term;
287}
288|
Jiri Olsa8f707d82012-03-15 20:09:16 +0100289PE_TERM '=' PE_VALUE
290{
291 struct parse_events__term *term;
292
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200293 ABORT_ON(parse_events__term_num(&term, $1, NULL, $3));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100294 $$ = term;
295}
296|
297PE_TERM
298{
299 struct parse_events__term *term;
300
Jiri Olsa16fa7e82012-04-25 18:24:57 +0200301 ABORT_ON(parse_events__term_num(&term, $1, NULL, 1));
Jiri Olsa8f707d82012-03-15 20:09:16 +0100302 $$ = term;
Jiri Olsa89812fc2012-03-15 20:09:15 +0100303}
304
305sep_dc: ':' |
306
Jiri Olsa8f707d82012-03-15 20:09:16 +0100307sep_slash_dc: '/' | ':' |
308
Jiri Olsa89812fc2012-03-15 20:09:15 +0100309%%
310
Zheng Yanac20de6f2012-06-15 14:31:39 +0800311void parse_events_error(void *data __used, void *scanner __used,
Jiri Olsa89812fc2012-03-15 20:09:15 +0100312 char const *msg __used)
313{
314}