xref: /linux/tools/perf/util/parse-events.y (revision 8255718f4bedbfb3558fba10ff40a70934f2117d)
1ac20de6fSZheng Yan %pure-parser
246010ab2SJiri Olsa %parse-param {void *_data}
3ac20de6fSZheng Yan %parse-param {void *scanner}
4ac20de6fSZheng Yan %lex-param {void* scanner}
56297d423SJiri Olsa %locations
689812fc8SJiri Olsa 
789812fc8SJiri Olsa %{
889812fc8SJiri Olsa 
989812fc8SJiri Olsa #define YYDEBUG 1
1089812fc8SJiri Olsa 
1189812fc8SJiri Olsa #include <linux/compiler.h>
1289812fc8SJiri Olsa #include <linux/list.h>
13d944c4eeSBorislav Petkov #include <linux/types.h>
1489812fc8SJiri Olsa #include "util.h"
15231bb2aaSAndi Kleen #include "pmu.h"
16f2361024SAndi Kleen #include "debug.h"
1789812fc8SJiri Olsa #include "parse-events.h"
18ac20de6fSZheng Yan #include "parse-events-bison.h"
1989812fc8SJiri Olsa 
2034a0548fSArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *data, void *scanner, char const *msg);
2134a0548fSArnaldo Carvalho de Melo 
2289812fc8SJiri Olsa #define ABORT_ON(val) \
2389812fc8SJiri Olsa do { \
2489812fc8SJiri Olsa 	if (val) \
2589812fc8SJiri Olsa 		YYABORT; \
2689812fc8SJiri Olsa } while (0)
2789812fc8SJiri Olsa 
28c5cd8ac0SDavid Ahern #define ALLOC_LIST(list) \
29c5cd8ac0SDavid Ahern do { \
30c5cd8ac0SDavid Ahern 	list = malloc(sizeof(*list)); \
31c5cd8ac0SDavid Ahern 	ABORT_ON(!list);              \
32c5cd8ac0SDavid Ahern 	INIT_LIST_HEAD(list);         \
33c5cd8ac0SDavid Ahern } while (0)
34c5cd8ac0SDavid Ahern 
3507ef7574SColin Ian King static void inc_group_count(struct list_head *list,
3697f63e4aSNamhyung Kim 		       struct parse_events_evlist *data)
3797f63e4aSNamhyung Kim {
3897f63e4aSNamhyung Kim 	/* Count groups only have more than 1 members */
3997f63e4aSNamhyung Kim 	if (!list_is_last(list->next, list))
4097f63e4aSNamhyung Kim 		data->nr_groups++;
4197f63e4aSNamhyung Kim }
4297f63e4aSNamhyung Kim 
4389812fc8SJiri Olsa %}
4489812fc8SJiri Olsa 
4590e2b22dSJiri Olsa %token PE_START_EVENTS PE_START_TERMS
46cf3506dcSJiri Olsa %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
47ac2ba9f3SRobert Richter %token PE_EVENT_NAME
4889812fc8SJiri Olsa %token PE_NAME
49d509db04SWang Nan %token PE_BPF_OBJECT PE_BPF_SOURCE
5089812fc8SJiri Olsa %token PE_MODIFIER_EVENT PE_MODIFIER_BP
5189812fc8SJiri Olsa %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
5289efb029SJiri Olsa %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
5389812fc8SJiri Olsa %token PE_ERROR
54ba32a451SKan Liang %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
55e571e029SWang Nan %token PE_ARRAY_ALL PE_ARRAY_RANGE
56dd60fba7SMathieu Poirier %token PE_DRV_CFG_TERM
5789812fc8SJiri Olsa %type <num> PE_VALUE
58cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_HW
59cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_SW
6089812fc8SJiri Olsa %type <num> PE_RAW
618f707d84SJiri Olsa %type <num> PE_TERM
6289812fc8SJiri Olsa %type <str> PE_NAME
6384c86ca1SWang Nan %type <str> PE_BPF_OBJECT
64d509db04SWang Nan %type <str> PE_BPF_SOURCE
6589812fc8SJiri Olsa %type <str> PE_NAME_CACHE_TYPE
6689812fc8SJiri Olsa %type <str> PE_NAME_CACHE_OP_RESULT
6789812fc8SJiri Olsa %type <str> PE_MODIFIER_EVENT
6889812fc8SJiri Olsa %type <str> PE_MODIFIER_BP
69ac2ba9f3SRobert Richter %type <str> PE_EVENT_NAME
70ba32a451SKan Liang %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT
71dd60fba7SMathieu Poirier %type <str> PE_DRV_CFG_TERM
72cf3506dcSJiri Olsa %type <num> value_sym
738f707d84SJiri Olsa %type <head> event_config
741d55e8efSArnaldo Carvalho de Melo %type <head> opt_event_config
758f707d84SJiri Olsa %type <term> event_term
76b847cbdcSJiri Olsa %type <head> event_pmu
77b847cbdcSJiri Olsa %type <head> event_legacy_symbol
78b847cbdcSJiri Olsa %type <head> event_legacy_cache
79b847cbdcSJiri Olsa %type <head> event_legacy_mem
80b847cbdcSJiri Olsa %type <head> event_legacy_tracepoint
81865582c3SHe Kuang %type <tracepoint_name> tracepoint_name
82b847cbdcSJiri Olsa %type <head> event_legacy_numeric
83b847cbdcSJiri Olsa %type <head> event_legacy_raw
8484c86ca1SWang Nan %type <head> event_bpf_file
85b847cbdcSJiri Olsa %type <head> event_def
86ac2ba9f3SRobert Richter %type <head> event_mod
87ac2ba9f3SRobert Richter %type <head> event_name
8889efb029SJiri Olsa %type <head> event
8989efb029SJiri Olsa %type <head> events
9089efb029SJiri Olsa %type <head> group_def
9189efb029SJiri Olsa %type <head> group
9289efb029SJiri Olsa %type <head> groups
93e571e029SWang Nan %type <array> array
94e571e029SWang Nan %type <array> array_term
95e571e029SWang Nan %type <array> array_terms
9689812fc8SJiri Olsa 
9789812fc8SJiri Olsa %union
9889812fc8SJiri Olsa {
9989812fc8SJiri Olsa 	char *str;
100b527bab5SRobert Richter 	u64 num;
1018f707d84SJiri Olsa 	struct list_head *head;
1026cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
103865582c3SHe Kuang 	struct tracepoint_name {
104865582c3SHe Kuang 		char *sys;
105865582c3SHe Kuang 		char *event;
106865582c3SHe Kuang 	} tracepoint_name;
107e571e029SWang Nan 	struct parse_events_array array;
10889812fc8SJiri Olsa }
10989812fc8SJiri Olsa %%
11089812fc8SJiri Olsa 
11190e2b22dSJiri Olsa start:
11289efb029SJiri Olsa PE_START_EVENTS start_events
11390e2b22dSJiri Olsa |
11489efb029SJiri Olsa PE_START_TERMS  start_terms
11589efb029SJiri Olsa 
11689efb029SJiri Olsa start_events: groups
11789efb029SJiri Olsa {
11823b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
11989efb029SJiri Olsa 
12089efb029SJiri Olsa 	parse_events_update_lists($1, &data->list);
12189efb029SJiri Olsa }
12289efb029SJiri Olsa 
12389efb029SJiri Olsa groups:
12489efb029SJiri Olsa groups ',' group
12589efb029SJiri Olsa {
12689efb029SJiri Olsa 	struct list_head *list  = $1;
12789efb029SJiri Olsa 	struct list_head *group = $3;
12889efb029SJiri Olsa 
12989efb029SJiri Olsa 	parse_events_update_lists(group, list);
13089efb029SJiri Olsa 	$$ = list;
13189efb029SJiri Olsa }
13289efb029SJiri Olsa |
13389efb029SJiri Olsa groups ',' event
13489efb029SJiri Olsa {
13589efb029SJiri Olsa 	struct list_head *list  = $1;
13689efb029SJiri Olsa 	struct list_head *event = $3;
13789efb029SJiri Olsa 
13889efb029SJiri Olsa 	parse_events_update_lists(event, list);
13989efb029SJiri Olsa 	$$ = list;
14089efb029SJiri Olsa }
14189efb029SJiri Olsa |
14289efb029SJiri Olsa group
14389efb029SJiri Olsa |
14489efb029SJiri Olsa event
14589efb029SJiri Olsa 
14689efb029SJiri Olsa group:
14789efb029SJiri Olsa group_def ':' PE_MODIFIER_EVENT
14889efb029SJiri Olsa {
14989efb029SJiri Olsa 	struct list_head *list = $1;
15089efb029SJiri Olsa 
15189efb029SJiri Olsa 	ABORT_ON(parse_events__modifier_group(list, $3));
15289efb029SJiri Olsa 	$$ = list;
15389efb029SJiri Olsa }
15489efb029SJiri Olsa |
15589efb029SJiri Olsa group_def
15689efb029SJiri Olsa 
15789efb029SJiri Olsa group_def:
15889efb029SJiri Olsa PE_NAME '{' events '}'
15989efb029SJiri Olsa {
16089efb029SJiri Olsa 	struct list_head *list = $3;
16189efb029SJiri Olsa 
16297f63e4aSNamhyung Kim 	inc_group_count(list, _data);
16363dab225SArnaldo Carvalho de Melo 	parse_events__set_leader($1, list);
16489efb029SJiri Olsa 	$$ = list;
16589efb029SJiri Olsa }
16689efb029SJiri Olsa |
16789efb029SJiri Olsa '{' events '}'
16889efb029SJiri Olsa {
16989efb029SJiri Olsa 	struct list_head *list = $2;
17089efb029SJiri Olsa 
17197f63e4aSNamhyung Kim 	inc_group_count(list, _data);
17263dab225SArnaldo Carvalho de Melo 	parse_events__set_leader(NULL, list);
17389efb029SJiri Olsa 	$$ = list;
17489efb029SJiri Olsa }
17590e2b22dSJiri Olsa 
17689812fc8SJiri Olsa events:
17789efb029SJiri Olsa events ',' event
17889efb029SJiri Olsa {
17989efb029SJiri Olsa 	struct list_head *event = $3;
18089efb029SJiri Olsa 	struct list_head *list  = $1;
18189efb029SJiri Olsa 
18289efb029SJiri Olsa 	parse_events_update_lists(event, list);
18389efb029SJiri Olsa 	$$ = list;
18489efb029SJiri Olsa }
18589efb029SJiri Olsa |
18689efb029SJiri Olsa event
18789812fc8SJiri Olsa 
188ac2ba9f3SRobert Richter event: event_mod
189ac2ba9f3SRobert Richter 
190ac2ba9f3SRobert Richter event_mod:
191ac2ba9f3SRobert Richter event_name PE_MODIFIER_EVENT
19289812fc8SJiri Olsa {
19389efb029SJiri Olsa 	struct list_head *list = $1;
19446010ab2SJiri Olsa 
1955d7be90eSJiri Olsa 	/*
1965d7be90eSJiri Olsa 	 * Apply modifier on all events added by single event definition
1975d7be90eSJiri Olsa 	 * (there could be more events added for multiple tracepoint
1985d7be90eSJiri Olsa 	 * definitions via '*?'.
1995d7be90eSJiri Olsa 	 */
200f5b1135bSJiri Olsa 	ABORT_ON(parse_events__modifier_event(list, $2, false));
20189efb029SJiri Olsa 	$$ = list;
20289812fc8SJiri Olsa }
20389812fc8SJiri Olsa |
204ac2ba9f3SRobert Richter event_name
205ac2ba9f3SRobert Richter 
206ac2ba9f3SRobert Richter event_name:
207ac2ba9f3SRobert Richter PE_EVENT_NAME event_def
208ac2ba9f3SRobert Richter {
209ac2ba9f3SRobert Richter 	ABORT_ON(parse_events_name($2, $1));
210ac2ba9f3SRobert Richter 	free($1);
211ac2ba9f3SRobert Richter 	$$ = $2;
212ac2ba9f3SRobert Richter }
213ac2ba9f3SRobert Richter |
21489812fc8SJiri Olsa event_def
21589812fc8SJiri Olsa 
2165f537a26SJiri Olsa event_def: event_pmu |
2175f537a26SJiri Olsa 	   event_legacy_symbol |
21889812fc8SJiri Olsa 	   event_legacy_cache sep_dc |
21989812fc8SJiri Olsa 	   event_legacy_mem |
22089812fc8SJiri Olsa 	   event_legacy_tracepoint sep_dc |
22189812fc8SJiri Olsa 	   event_legacy_numeric sep_dc |
22284c86ca1SWang Nan 	   event_legacy_raw sep_dc |
22384c86ca1SWang Nan 	   event_bpf_file
22489812fc8SJiri Olsa 
2255f537a26SJiri Olsa event_pmu:
226bb109accSArnaldo Carvalho de Melo PE_NAME opt_event_config
2275f537a26SJiri Olsa {
22823b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
229*8255718fSAndi Kleen 	struct list_head *list, *orig_terms, *terms;
230*8255718fSAndi Kleen 
231*8255718fSAndi Kleen 	if (parse_events_copy_term_list($2, &orig_terms))
232*8255718fSAndi Kleen 		YYABORT;
233b847cbdcSJiri Olsa 
234c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
235*8255718fSAndi Kleen 	if (parse_events_add_pmu(data, list, $1, $2)) {
236*8255718fSAndi Kleen 		struct perf_pmu *pmu = NULL;
237*8255718fSAndi Kleen 		int ok = 0;
238*8255718fSAndi Kleen 
239*8255718fSAndi Kleen 		while ((pmu = perf_pmu__scan(pmu)) != NULL) {
240*8255718fSAndi Kleen 			char *name = pmu->name;
241*8255718fSAndi Kleen 
242*8255718fSAndi Kleen 			if (!strncmp($1, name, strlen($1))) {
243*8255718fSAndi Kleen 				if (parse_events_copy_term_list(orig_terms, &terms))
244*8255718fSAndi Kleen 					YYABORT;
245*8255718fSAndi Kleen 				if (!parse_events_add_pmu(data, list, pmu->name, terms))
246*8255718fSAndi Kleen 					ok++;
247*8255718fSAndi Kleen 				parse_events_terms__delete(terms);
248*8255718fSAndi Kleen 			}
249*8255718fSAndi Kleen 		}
250*8255718fSAndi Kleen 		if (!ok)
251*8255718fSAndi Kleen 			YYABORT;
252*8255718fSAndi Kleen 	}
253bb109accSArnaldo Carvalho de Melo 	parse_events_terms__delete($2);
254*8255718fSAndi Kleen 	parse_events_terms__delete(orig_terms);
255b847cbdcSJiri Olsa 	$$ = list;
2565f537a26SJiri Olsa }
257ad962273SAdrian Hunter |
258ba32a451SKan Liang PE_KERNEL_PMU_EVENT sep_dc
259ba32a451SKan Liang {
260ba32a451SKan Liang 	struct list_head *list;
261ba32a451SKan Liang 
2622073ad33SAndi Kleen 	if (parse_events_multi_pmu_add(_data, $1, &list) < 0)
263231bb2aaSAndi Kleen 		YYABORT;
264ba32a451SKan Liang 	$$ = list;
265ba32a451SKan Liang }
266ba32a451SKan Liang |
267ba32a451SKan Liang PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
268ba32a451SKan Liang {
269ba32a451SKan Liang 	struct list_head *list;
270ba32a451SKan Liang 	char pmu_name[128];
271*8255718fSAndi Kleen 
272ba32a451SKan Liang 	snprintf(&pmu_name, 128, "%s-%s", $1, $3);
273*8255718fSAndi Kleen 	if (parse_events_multi_pmu_add(_data, pmu_name, &list) < 0)
274*8255718fSAndi Kleen 		YYABORT;
275ba32a451SKan Liang 	$$ = list;
276ba32a451SKan Liang }
2775f537a26SJiri Olsa 
278cf3506dcSJiri Olsa value_sym:
279cf3506dcSJiri Olsa PE_VALUE_SYM_HW
280cf3506dcSJiri Olsa |
281cf3506dcSJiri Olsa PE_VALUE_SYM_SW
282cf3506dcSJiri Olsa 
28389812fc8SJiri Olsa event_legacy_symbol:
284cf3506dcSJiri Olsa value_sym '/' event_config '/'
28589812fc8SJiri Olsa {
28623b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
287c5cd8ac0SDavid Ahern 	struct list_head *list;
28889812fc8SJiri Olsa 	int type = $1 >> 16;
28989812fc8SJiri Olsa 	int config = $1 & 255;
29089812fc8SJiri Olsa 
291c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
29287d650beSJiri Olsa 	ABORT_ON(parse_events_add_numeric(data, list, type, config, $3));
2932146afc6SArnaldo Carvalho de Melo 	parse_events_terms__delete($3);
294b847cbdcSJiri Olsa 	$$ = list;
2958f707d84SJiri Olsa }
2968f707d84SJiri Olsa |
297cf3506dcSJiri Olsa value_sym sep_slash_dc
2988f707d84SJiri Olsa {
29923b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
300c5cd8ac0SDavid Ahern 	struct list_head *list;
3018f707d84SJiri Olsa 	int type = $1 >> 16;
3028f707d84SJiri Olsa 	int config = $1 & 255;
3038f707d84SJiri Olsa 
304c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
30587d650beSJiri Olsa 	ABORT_ON(parse_events_add_numeric(data, list, type, config, NULL));
306b847cbdcSJiri Olsa 	$$ = list;
30789812fc8SJiri Olsa }
30889812fc8SJiri Olsa 
30989812fc8SJiri Olsa event_legacy_cache:
31043d0b978SWang Nan PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
31189812fc8SJiri Olsa {
31223b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
31343d0b978SWang Nan 	struct parse_events_error *error = data->error;
314c5cd8ac0SDavid Ahern 	struct list_head *list;
315b847cbdcSJiri Olsa 
316c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
31743d0b978SWang Nan 	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, $5, error, $6));
31843d0b978SWang Nan 	parse_events_terms__delete($6);
319b847cbdcSJiri Olsa 	$$ = list;
32089812fc8SJiri Olsa }
32189812fc8SJiri Olsa |
32243d0b978SWang Nan PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
32389812fc8SJiri Olsa {
32423b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
32543d0b978SWang Nan 	struct parse_events_error *error = data->error;
326c5cd8ac0SDavid Ahern 	struct list_head *list;
327b847cbdcSJiri Olsa 
328c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
32943d0b978SWang Nan 	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, $3, NULL, error, $4));
33043d0b978SWang Nan 	parse_events_terms__delete($4);
331b847cbdcSJiri Olsa 	$$ = list;
33289812fc8SJiri Olsa }
33389812fc8SJiri Olsa |
33443d0b978SWang Nan PE_NAME_CACHE_TYPE opt_event_config
33589812fc8SJiri Olsa {
33623b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
33743d0b978SWang Nan 	struct parse_events_error *error = data->error;
338c5cd8ac0SDavid Ahern 	struct list_head *list;
339b847cbdcSJiri Olsa 
340c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
34143d0b978SWang Nan 	ABORT_ON(parse_events_add_cache(list, &data->idx, $1, NULL, NULL, error, $2));
34243d0b978SWang Nan 	parse_events_terms__delete($2);
343b847cbdcSJiri Olsa 	$$ = list;
34489812fc8SJiri Olsa }
34589812fc8SJiri Olsa 
34689812fc8SJiri Olsa event_legacy_mem:
3473741eb9fSJacob Shin PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
3483741eb9fSJacob Shin {
3493741eb9fSJacob Shin 	struct parse_events_evlist *data = _data;
3503741eb9fSJacob Shin 	struct list_head *list;
3513741eb9fSJacob Shin 
3523741eb9fSJacob Shin 	ALLOC_LIST(list);
3533741eb9fSJacob Shin 	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
3543741eb9fSJacob Shin 					     (void *) $2, $6, $4));
3553741eb9fSJacob Shin 	$$ = list;
3563741eb9fSJacob Shin }
3573741eb9fSJacob Shin |
3583741eb9fSJacob Shin PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
3593741eb9fSJacob Shin {
3603741eb9fSJacob Shin 	struct parse_events_evlist *data = _data;
3613741eb9fSJacob Shin 	struct list_head *list;
3623741eb9fSJacob Shin 
3633741eb9fSJacob Shin 	ALLOC_LIST(list);
3643741eb9fSJacob Shin 	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
3653741eb9fSJacob Shin 					     (void *) $2, NULL, $4));
3663741eb9fSJacob Shin 	$$ = list;
3673741eb9fSJacob Shin }
3683741eb9fSJacob Shin |
36989812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
37089812fc8SJiri Olsa {
37123b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
372c5cd8ac0SDavid Ahern 	struct list_head *list;
373b847cbdcSJiri Olsa 
374c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
375c5cd8ac0SDavid Ahern 	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
3763741eb9fSJacob Shin 					     (void *) $2, $4, 0));
377b847cbdcSJiri Olsa 	$$ = list;
37889812fc8SJiri Olsa }
37989812fc8SJiri Olsa |
38089812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE sep_dc
38189812fc8SJiri Olsa {
38223b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
383c5cd8ac0SDavid Ahern 	struct list_head *list;
384b847cbdcSJiri Olsa 
385c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
386c5cd8ac0SDavid Ahern 	ABORT_ON(parse_events_add_breakpoint(list, &data->idx,
3873741eb9fSJacob Shin 					     (void *) $2, NULL, 0));
388b847cbdcSJiri Olsa 	$$ = list;
38989812fc8SJiri Olsa }
39089812fc8SJiri Olsa 
39189812fc8SJiri Olsa event_legacy_tracepoint:
3921d55e8efSArnaldo Carvalho de Melo tracepoint_name opt_event_config
3932b9032e0SAlexander Yarygin {
3942b9032e0SAlexander Yarygin 	struct parse_events_evlist *data = _data;
39519658171SJiri Olsa 	struct parse_events_error *error = data->error;
3962b9032e0SAlexander Yarygin 	struct list_head *list;
3972b9032e0SAlexander Yarygin 
3982b9032e0SAlexander Yarygin 	ALLOC_LIST(list);
39919658171SJiri Olsa 	if (error)
40019658171SJiri Olsa 		error->idx = @1.first_column;
401e637d177SHe Kuang 
402e637d177SHe Kuang 	if (parse_events_add_tracepoint(list, &data->idx, $1.sys, $1.event,
4031d55e8efSArnaldo Carvalho de Melo 					error, $2))
404e637d177SHe Kuang 		return -1;
405e637d177SHe Kuang 
4062b9032e0SAlexander Yarygin 	$$ = list;
4072b9032e0SAlexander Yarygin }
408865582c3SHe Kuang 
409865582c3SHe Kuang tracepoint_name:
410865582c3SHe Kuang PE_NAME '-' PE_NAME ':' PE_NAME
411865582c3SHe Kuang {
412865582c3SHe Kuang 	char sys_name[128];
413865582c3SHe Kuang 	struct tracepoint_name tracepoint;
414865582c3SHe Kuang 
415865582c3SHe Kuang 	snprintf(&sys_name, 128, "%s-%s", $1, $3);
416865582c3SHe Kuang 	tracepoint.sys = &sys_name;
417865582c3SHe Kuang 	tracepoint.event = $5;
418865582c3SHe Kuang 
419865582c3SHe Kuang 	$$ = tracepoint;
420865582c3SHe Kuang }
4212b9032e0SAlexander Yarygin |
42289812fc8SJiri Olsa PE_NAME ':' PE_NAME
42389812fc8SJiri Olsa {
424865582c3SHe Kuang 	struct tracepoint_name tracepoint = {$1, $3};
425b847cbdcSJiri Olsa 
426865582c3SHe Kuang 	$$ = tracepoint;
42789812fc8SJiri Olsa }
42889812fc8SJiri Olsa 
42989812fc8SJiri Olsa event_legacy_numeric:
43010bf358aSWang Nan PE_VALUE ':' PE_VALUE opt_event_config
43189812fc8SJiri Olsa {
43223b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
433c5cd8ac0SDavid Ahern 	struct list_head *list;
434b847cbdcSJiri Olsa 
435c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
43610bf358aSWang Nan 	ABORT_ON(parse_events_add_numeric(data, list, (u32)$1, $3, $4));
43710bf358aSWang Nan 	parse_events_terms__delete($4);
438b847cbdcSJiri Olsa 	$$ = list;
43989812fc8SJiri Olsa }
44089812fc8SJiri Olsa 
44189812fc8SJiri Olsa event_legacy_raw:
44210bf358aSWang Nan PE_RAW opt_event_config
44389812fc8SJiri Olsa {
44423b6339bSArnaldo Carvalho de Melo 	struct parse_events_evlist *data = _data;
445c5cd8ac0SDavid Ahern 	struct list_head *list;
446b847cbdcSJiri Olsa 
447c5cd8ac0SDavid Ahern 	ALLOC_LIST(list);
44810bf358aSWang Nan 	ABORT_ON(parse_events_add_numeric(data, list, PERF_TYPE_RAW, $1, $2));
44910bf358aSWang Nan 	parse_events_terms__delete($2);
450b847cbdcSJiri Olsa 	$$ = list;
4518f707d84SJiri Olsa }
4528f707d84SJiri Olsa 
45384c86ca1SWang Nan event_bpf_file:
454a34f3be7SWang Nan PE_BPF_OBJECT opt_event_config
45584c86ca1SWang Nan {
45684c86ca1SWang Nan 	struct parse_events_evlist *data = _data;
45784c86ca1SWang Nan 	struct parse_events_error *error = data->error;
45884c86ca1SWang Nan 	struct list_head *list;
45984c86ca1SWang Nan 
46084c86ca1SWang Nan 	ALLOC_LIST(list);
461a34f3be7SWang Nan 	ABORT_ON(parse_events_load_bpf(data, list, $1, false, $2));
462a34f3be7SWang Nan 	parse_events_terms__delete($2);
463d509db04SWang Nan 	$$ = list;
464d509db04SWang Nan }
465d509db04SWang Nan |
466a34f3be7SWang Nan PE_BPF_SOURCE opt_event_config
467d509db04SWang Nan {
468d509db04SWang Nan 	struct parse_events_evlist *data = _data;
469d509db04SWang Nan 	struct list_head *list;
470d509db04SWang Nan 
471d509db04SWang Nan 	ALLOC_LIST(list);
472a34f3be7SWang Nan 	ABORT_ON(parse_events_load_bpf(data, list, $1, true, $2));
473a34f3be7SWang Nan 	parse_events_terms__delete($2);
47484c86ca1SWang Nan 	$$ = list;
47584c86ca1SWang Nan }
47684c86ca1SWang Nan 
4771d55e8efSArnaldo Carvalho de Melo opt_event_config:
4781d55e8efSArnaldo Carvalho de Melo '/' event_config '/'
4791d55e8efSArnaldo Carvalho de Melo {
4801d55e8efSArnaldo Carvalho de Melo 	$$ = $2;
4811d55e8efSArnaldo Carvalho de Melo }
4821d55e8efSArnaldo Carvalho de Melo |
4831d55e8efSArnaldo Carvalho de Melo '/' '/'
4841d55e8efSArnaldo Carvalho de Melo {
4851d55e8efSArnaldo Carvalho de Melo 	$$ = NULL;
4861d55e8efSArnaldo Carvalho de Melo }
4871d55e8efSArnaldo Carvalho de Melo |
4881d55e8efSArnaldo Carvalho de Melo {
4891d55e8efSArnaldo Carvalho de Melo 	$$ = NULL;
4901d55e8efSArnaldo Carvalho de Melo }
4911d55e8efSArnaldo Carvalho de Melo 
49289efb029SJiri Olsa start_terms: event_config
49390e2b22dSJiri Olsa {
49423b6339bSArnaldo Carvalho de Melo 	struct parse_events_terms *data = _data;
49590e2b22dSJiri Olsa 	data->terms = $1;
49690e2b22dSJiri Olsa }
49790e2b22dSJiri Olsa 
4988f707d84SJiri Olsa event_config:
4998f707d84SJiri Olsa event_config ',' event_term
5008f707d84SJiri Olsa {
5018f707d84SJiri Olsa 	struct list_head *head = $1;
5026cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term = $3;
5038f707d84SJiri Olsa 
5048f707d84SJiri Olsa 	ABORT_ON(!head);
5058f707d84SJiri Olsa 	list_add_tail(&term->list, head);
5068f707d84SJiri Olsa 	$$ = $1;
5078f707d84SJiri Olsa }
5088f707d84SJiri Olsa |
5098f707d84SJiri Olsa event_term
5108f707d84SJiri Olsa {
5118f707d84SJiri Olsa 	struct list_head *head = malloc(sizeof(*head));
5126cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term = $1;
5138f707d84SJiri Olsa 
5148f707d84SJiri Olsa 	ABORT_ON(!head);
5158f707d84SJiri Olsa 	INIT_LIST_HEAD(head);
5168f707d84SJiri Olsa 	list_add_tail(&term->list, head);
5178f707d84SJiri Olsa 	$$ = head;
5188f707d84SJiri Olsa }
5198f707d84SJiri Olsa 
5208f707d84SJiri Olsa event_term:
5218f707d84SJiri Olsa PE_NAME '=' PE_NAME
5228f707d84SJiri Olsa {
5236cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5248f707d84SJiri Olsa 
5256cee6cd3SArnaldo Carvalho de Melo 	ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
526cecf3a2eSJiri Olsa 					$1, $3, &@1, &@3));
5278f707d84SJiri Olsa 	$$ = term;
5288f707d84SJiri Olsa }
5298f707d84SJiri Olsa |
5308f707d84SJiri Olsa PE_NAME '=' PE_VALUE
5318f707d84SJiri Olsa {
5326cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5338f707d84SJiri Olsa 
5346cee6cd3SArnaldo Carvalho de Melo 	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
53599e7138eSJiri Olsa 					$1, $3, false, &@1, &@3));
5368f707d84SJiri Olsa 	$$ = term;
5378f707d84SJiri Olsa }
5388f707d84SJiri Olsa |
5391d33d6dcSJiri Olsa PE_NAME '=' PE_VALUE_SYM_HW
5401d33d6dcSJiri Olsa {
5416cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5421d33d6dcSJiri Olsa 	int config = $3 & 255;
5431d33d6dcSJiri Olsa 
5446cee6cd3SArnaldo Carvalho de Melo 	ABORT_ON(parse_events_term__sym_hw(&term, $1, config));
5451d33d6dcSJiri Olsa 	$$ = term;
5461d33d6dcSJiri Olsa }
5471d33d6dcSJiri Olsa |
5488f707d84SJiri Olsa PE_NAME
5498f707d84SJiri Olsa {
5506cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5518f707d84SJiri Olsa 
5526cee6cd3SArnaldo Carvalho de Melo 	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
55399e7138eSJiri Olsa 					$1, 1, true, &@1, NULL));
5548f707d84SJiri Olsa 	$$ = term;
5558f707d84SJiri Olsa }
5568f707d84SJiri Olsa |
5571d33d6dcSJiri Olsa PE_VALUE_SYM_HW
5581d33d6dcSJiri Olsa {
5596cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5601d33d6dcSJiri Olsa 	int config = $1 & 255;
5611d33d6dcSJiri Olsa 
5626cee6cd3SArnaldo Carvalho de Melo 	ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
5631d33d6dcSJiri Olsa 	$$ = term;
5641d33d6dcSJiri Olsa }
5651d33d6dcSJiri Olsa |
5666b5fc39bSJiri Olsa PE_TERM '=' PE_NAME
5676b5fc39bSJiri Olsa {
5686cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5696b5fc39bSJiri Olsa 
570cecf3a2eSJiri Olsa 	ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3));
5716b5fc39bSJiri Olsa 	$$ = term;
5726b5fc39bSJiri Olsa }
5736b5fc39bSJiri Olsa |
5748f707d84SJiri Olsa PE_TERM '=' PE_VALUE
5758f707d84SJiri Olsa {
5766cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5778f707d84SJiri Olsa 
57899e7138eSJiri Olsa 	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
5798f707d84SJiri Olsa 	$$ = term;
5808f707d84SJiri Olsa }
5818f707d84SJiri Olsa |
5828f707d84SJiri Olsa PE_TERM
5838f707d84SJiri Olsa {
5846cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
5858f707d84SJiri Olsa 
58699e7138eSJiri Olsa 	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
5878f707d84SJiri Olsa 	$$ = term;
58889812fc8SJiri Olsa }
589e571e029SWang Nan |
590e571e029SWang Nan PE_NAME array '=' PE_NAME
591e571e029SWang Nan {
592e571e029SWang Nan 	struct parse_events_term *term;
593e571e029SWang Nan 	int i;
594e571e029SWang Nan 
595e571e029SWang Nan 	ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
596e571e029SWang Nan 					$1, $4, &@1, &@4));
597e571e029SWang Nan 
598e571e029SWang Nan 	term->array = $2;
599e571e029SWang Nan 	$$ = term;
600e571e029SWang Nan }
601e571e029SWang Nan |
602e571e029SWang Nan PE_NAME array '=' PE_VALUE
603e571e029SWang Nan {
604e571e029SWang Nan 	struct parse_events_term *term;
605e571e029SWang Nan 
606e571e029SWang Nan 	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
60799e7138eSJiri Olsa 					$1, $4, false, &@1, &@4));
608e571e029SWang Nan 	term->array = $2;
609e571e029SWang Nan 	$$ = term;
610e571e029SWang Nan }
611dd60fba7SMathieu Poirier |
612dd60fba7SMathieu Poirier PE_DRV_CFG_TERM
613dd60fba7SMathieu Poirier {
614dd60fba7SMathieu Poirier 	struct parse_events_term *term;
615dd60fba7SMathieu Poirier 
616dd60fba7SMathieu Poirier 	ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
617dd60fba7SMathieu Poirier 					$1, $1, &@1, NULL));
618dd60fba7SMathieu Poirier 	$$ = term;
619dd60fba7SMathieu Poirier }
620e571e029SWang Nan 
621e571e029SWang Nan array:
622e571e029SWang Nan '[' array_terms ']'
623e571e029SWang Nan {
624e571e029SWang Nan 	$$ = $2;
625e571e029SWang Nan }
626e571e029SWang Nan |
627e571e029SWang Nan PE_ARRAY_ALL
628e571e029SWang Nan {
629e571e029SWang Nan 	$$.nr_ranges = 0;
630e571e029SWang Nan 	$$.ranges = NULL;
631e571e029SWang Nan }
632e571e029SWang Nan 
633e571e029SWang Nan array_terms:
634e571e029SWang Nan array_terms ',' array_term
635e571e029SWang Nan {
636e571e029SWang Nan 	struct parse_events_array new_array;
637e571e029SWang Nan 
638e571e029SWang Nan 	new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
639e571e029SWang Nan 	new_array.ranges = malloc(sizeof(new_array.ranges[0]) *
640e571e029SWang Nan 				  new_array.nr_ranges);
641e571e029SWang Nan 	ABORT_ON(!new_array.ranges);
642e571e029SWang Nan 	memcpy(&new_array.ranges[0], $1.ranges,
643e571e029SWang Nan 	       $1.nr_ranges * sizeof(new_array.ranges[0]));
644e571e029SWang Nan 	memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
645e571e029SWang Nan 	       $3.nr_ranges * sizeof(new_array.ranges[0]));
646e571e029SWang Nan 	free($1.ranges);
647e571e029SWang Nan 	free($3.ranges);
648e571e029SWang Nan 	$$ = new_array;
649e571e029SWang Nan }
650e571e029SWang Nan |
651e571e029SWang Nan array_term
652e571e029SWang Nan 
653e571e029SWang Nan array_term:
654e571e029SWang Nan PE_VALUE
655e571e029SWang Nan {
656e571e029SWang Nan 	struct parse_events_array array;
657e571e029SWang Nan 
658e571e029SWang Nan 	array.nr_ranges = 1;
659e571e029SWang Nan 	array.ranges = malloc(sizeof(array.ranges[0]));
660e571e029SWang Nan 	ABORT_ON(!array.ranges);
661e571e029SWang Nan 	array.ranges[0].start = $1;
662e571e029SWang Nan 	array.ranges[0].length = 1;
663e571e029SWang Nan 	$$ = array;
664e571e029SWang Nan }
665e571e029SWang Nan |
666e571e029SWang Nan PE_VALUE PE_ARRAY_RANGE PE_VALUE
667e571e029SWang Nan {
668e571e029SWang Nan 	struct parse_events_array array;
669e571e029SWang Nan 
670e571e029SWang Nan 	ABORT_ON($3 < $1);
671e571e029SWang Nan 	array.nr_ranges = 1;
672e571e029SWang Nan 	array.ranges = malloc(sizeof(array.ranges[0]));
673e571e029SWang Nan 	ABORT_ON(!array.ranges);
674e571e029SWang Nan 	array.ranges[0].start = $1;
675e571e029SWang Nan 	array.ranges[0].length = $3 - $1 + 1;
676e571e029SWang Nan 	$$ = array;
677e571e029SWang Nan }
67889812fc8SJiri Olsa 
67989812fc8SJiri Olsa sep_dc: ':' |
68089812fc8SJiri Olsa 
6818f707d84SJiri Olsa sep_slash_dc: '/' | ':' |
6828f707d84SJiri Olsa 
68389812fc8SJiri Olsa %%
68489812fc8SJiri Olsa 
6856297d423SJiri Olsa void parse_events_error(YYLTYPE *loc, void *data,
6866297d423SJiri Olsa 			void *scanner __maybe_unused,
6871d037ca1SIrina Tirdea 			char const *msg __maybe_unused)
68889812fc8SJiri Olsa {
6896297d423SJiri Olsa 	parse_events_evlist_error(data, loc->last_column, "parser error");
69089812fc8SJiri Olsa }
691