xref: /linux/tools/perf/util/parse-events.y (revision eabd4523395e4a8f2b049165642801f2ab8ff893)
1fc8c0a99SJiri Olsa %define api.pure full
25d9cdc11SArnaldo Carvalho de Melo %parse-param {void *_parse_state}
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 
11b2b9d3a3SAgustin Vega-Frias #include <fnmatch.h>
12bd704620SArnaldo Carvalho de Melo #include <stdio.h>
1389812fc8SJiri Olsa #include <linux/compiler.h>
14d944c4eeSBorislav Petkov #include <linux/types.h>
15f2a8ecd8SIan Rogers #include <linux/zalloc.h>
16231bb2aaSAndi Kleen #include "pmu.h"
17f0fbb114SAndi Kleen #include "evsel.h"
1889812fc8SJiri Olsa #include "parse-events.h"
19ac20de6fSZheng Yan #include "parse-events-bison.h"
2089812fc8SJiri Olsa 
215d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
2234a0548fSArnaldo Carvalho de Melo 
2389812fc8SJiri Olsa #define ABORT_ON(val) \
2489812fc8SJiri Olsa do { \
2589812fc8SJiri Olsa 	if (val) \
2689812fc8SJiri Olsa 		YYABORT; \
2789812fc8SJiri Olsa } while (0)
2889812fc8SJiri Olsa 
29ffaecd7dSIan Rogers static struct list_head* alloc_list(void)
30a26e4716SIan Rogers {
31a26e4716SIan Rogers 	struct list_head *list;
32a26e4716SIan Rogers 
33a26e4716SIan Rogers 	list = malloc(sizeof(*list));
34a26e4716SIan Rogers 	if (!list)
35a26e4716SIan Rogers 		return NULL;
36a26e4716SIan Rogers 
37a26e4716SIan Rogers 	INIT_LIST_HEAD(list);
38a26e4716SIan Rogers 	return list;
39a26e4716SIan Rogers }
40c5cd8ac0SDavid Ahern 
41f2a8ecd8SIan Rogers static void free_list_evsel(struct list_head* list_evsel)
42f2a8ecd8SIan Rogers {
43f2a8ecd8SIan Rogers 	struct evsel *evsel, *tmp;
44f2a8ecd8SIan Rogers 
45f2a8ecd8SIan Rogers 	list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) {
46f2a8ecd8SIan Rogers 		list_del_init(&evsel->core.node);
47672f707eSIan Rogers 		evsel__delete(evsel);
48f2a8ecd8SIan Rogers 	}
49f2a8ecd8SIan Rogers 	free(list_evsel);
50f2a8ecd8SIan Rogers }
51f2a8ecd8SIan Rogers 
5207ef7574SColin Ian King static void inc_group_count(struct list_head *list,
535d9cdc11SArnaldo Carvalho de Melo 		       struct parse_events_state *parse_state)
5497f63e4aSNamhyung Kim {
5597f63e4aSNamhyung Kim 	/* Count groups only have more than 1 members */
5697f63e4aSNamhyung Kim 	if (!list_is_last(list->next, list))
575d9cdc11SArnaldo Carvalho de Melo 		parse_state->nr_groups++;
5897f63e4aSNamhyung Kim }
5997f63e4aSNamhyung Kim 
6089812fc8SJiri Olsa %}
6189812fc8SJiri Olsa 
6290e2b22dSJiri Olsa %token PE_START_EVENTS PE_START_TERMS
63cf3506dcSJiri Olsa %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
64f0fbb114SAndi Kleen %token PE_VALUE_SYM_TOOL
65ac2ba9f3SRobert Richter %token PE_EVENT_NAME
6689812fc8SJiri Olsa %token PE_NAME
67d509db04SWang Nan %token PE_BPF_OBJECT PE_BPF_SOURCE
6889812fc8SJiri Olsa %token PE_MODIFIER_EVENT PE_MODIFIER_BP
6989812fc8SJiri Olsa %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
7089efb029SJiri Olsa %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
7189812fc8SJiri Olsa %token PE_ERROR
72387ad33fSJiri Olsa %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
73e571e029SWang Nan %token PE_ARRAY_ALL PE_ARRAY_RANGE
74dd60fba7SMathieu Poirier %token PE_DRV_CFG_TERM
7589812fc8SJiri Olsa %type <num> PE_VALUE
76cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_HW
77cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_SW
78f0fbb114SAndi Kleen %type <num> PE_VALUE_SYM_TOOL
7989812fc8SJiri Olsa %type <num> PE_RAW
808f707d84SJiri Olsa %type <num> PE_TERM
81f2a8ecd8SIan Rogers %type <num> value_sym
8289812fc8SJiri Olsa %type <str> PE_NAME
8384c86ca1SWang Nan %type <str> PE_BPF_OBJECT
84d509db04SWang Nan %type <str> PE_BPF_SOURCE
8589812fc8SJiri Olsa %type <str> PE_NAME_CACHE_TYPE
8689812fc8SJiri Olsa %type <str> PE_NAME_CACHE_OP_RESULT
8789812fc8SJiri Olsa %type <str> PE_MODIFIER_EVENT
8889812fc8SJiri Olsa %type <str> PE_MODIFIER_BP
89ac2ba9f3SRobert Richter %type <str> PE_EVENT_NAME
90387ad33fSJiri Olsa %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
91dd60fba7SMathieu Poirier %type <str> PE_DRV_CFG_TERM
9284ea6036SJiri Olsa %type <str> event_pmu_name
93f2a8ecd8SIan Rogers %destructor { free ($$); } <str>
948f707d84SJiri Olsa %type <term> event_term
951dc92556SIan Rogers %destructor { parse_events_term__delete ($$); } <term>
96f2a8ecd8SIan Rogers %type <list_terms> event_config
97f2a8ecd8SIan Rogers %type <list_terms> opt_event_config
98f2a8ecd8SIan Rogers %type <list_terms> opt_pmu_config
99f2a8ecd8SIan Rogers %destructor { parse_events_terms__delete ($$); } <list_terms>
100f2a8ecd8SIan Rogers %type <list_evsel> event_pmu
101f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_symbol
102f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_cache
103f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_mem
104f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_tracepoint
105f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_numeric
106f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_raw
107f2a8ecd8SIan Rogers %type <list_evsel> event_bpf_file
108f2a8ecd8SIan Rogers %type <list_evsel> event_def
109f2a8ecd8SIan Rogers %type <list_evsel> event_mod
110f2a8ecd8SIan Rogers %type <list_evsel> event_name
111f2a8ecd8SIan Rogers %type <list_evsel> event
112f2a8ecd8SIan Rogers %type <list_evsel> events
113f2a8ecd8SIan Rogers %type <list_evsel> group_def
114f2a8ecd8SIan Rogers %type <list_evsel> group
115f2a8ecd8SIan Rogers %type <list_evsel> groups
116f2a8ecd8SIan Rogers %destructor { free_list_evsel ($$); } <list_evsel>
117865582c3SHe Kuang %type <tracepoint_name> tracepoint_name
118f2a8ecd8SIan Rogers %destructor { free ($$.sys); free ($$.event); } <tracepoint_name>
119e571e029SWang Nan %type <array> array
120e571e029SWang Nan %type <array> array_term
121e571e029SWang Nan %type <array> array_terms
122f2a8ecd8SIan Rogers %destructor { free ($$.ranges); } <array>
12389812fc8SJiri Olsa 
12489812fc8SJiri Olsa %union
12589812fc8SJiri Olsa {
12689812fc8SJiri Olsa 	char *str;
127b527bab5SRobert Richter 	u64 num;
128f2a8ecd8SIan Rogers 	struct list_head *list_evsel;
129f2a8ecd8SIan Rogers 	struct list_head *list_terms;
1306cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
131865582c3SHe Kuang 	struct tracepoint_name {
132865582c3SHe Kuang 		char *sys;
133865582c3SHe Kuang 		char *event;
134865582c3SHe Kuang 	} tracepoint_name;
135e571e029SWang Nan 	struct parse_events_array array;
13689812fc8SJiri Olsa }
13789812fc8SJiri Olsa %%
13889812fc8SJiri Olsa 
13990e2b22dSJiri Olsa start:
14089efb029SJiri Olsa PE_START_EVENTS start_events
14190e2b22dSJiri Olsa |
14289efb029SJiri Olsa PE_START_TERMS  start_terms
14389efb029SJiri Olsa 
14489efb029SJiri Olsa start_events: groups
14589efb029SJiri Olsa {
1465d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
14789efb029SJiri Olsa 
148cabbf268SIan Rogers 	/* frees $1 */
1495d9cdc11SArnaldo Carvalho de Melo 	parse_events_update_lists($1, &parse_state->list);
15089efb029SJiri Olsa }
15189efb029SJiri Olsa 
15289efb029SJiri Olsa groups:
15389efb029SJiri Olsa groups ',' group
15489efb029SJiri Olsa {
15589efb029SJiri Olsa 	struct list_head *list  = $1;
15689efb029SJiri Olsa 	struct list_head *group = $3;
15789efb029SJiri Olsa 
158cabbf268SIan Rogers 	/* frees $3 */
15989efb029SJiri Olsa 	parse_events_update_lists(group, list);
16089efb029SJiri Olsa 	$$ = list;
16189efb029SJiri Olsa }
16289efb029SJiri Olsa |
16389efb029SJiri Olsa groups ',' event
16489efb029SJiri Olsa {
16589efb029SJiri Olsa 	struct list_head *list  = $1;
16689efb029SJiri Olsa 	struct list_head *event = $3;
16789efb029SJiri Olsa 
168cabbf268SIan Rogers 	/* frees $3 */
16989efb029SJiri Olsa 	parse_events_update_lists(event, list);
17089efb029SJiri Olsa 	$$ = list;
17189efb029SJiri Olsa }
17289efb029SJiri Olsa |
17389efb029SJiri Olsa group
17489efb029SJiri Olsa |
17589efb029SJiri Olsa event
17689efb029SJiri Olsa 
17789efb029SJiri Olsa group:
17889efb029SJiri Olsa group_def ':' PE_MODIFIER_EVENT
17989efb029SJiri Olsa {
18089efb029SJiri Olsa 	struct list_head *list = $1;
181cabbf268SIan Rogers 	int err;
18289efb029SJiri Olsa 
183cabbf268SIan Rogers 	err = parse_events__modifier_group(list, $3);
184cabbf268SIan Rogers 	free($3);
185cabbf268SIan Rogers 	if (err) {
186*eabd4523SIan Rogers 		struct parse_events_state *parse_state = _parse_state;
187*eabd4523SIan Rogers 		struct parse_events_error *error = parse_state->error;
188*eabd4523SIan Rogers 
189*eabd4523SIan Rogers 		parse_events__handle_error(error, @3.first_column,
190*eabd4523SIan Rogers 					   strdup("Bad modifier"), NULL);
191cabbf268SIan Rogers 		free_list_evsel(list);
192cabbf268SIan Rogers 		YYABORT;
193cabbf268SIan Rogers 	}
19489efb029SJiri Olsa 	$$ = list;
19589efb029SJiri Olsa }
19689efb029SJiri Olsa |
19789efb029SJiri Olsa group_def
19889efb029SJiri Olsa 
19989efb029SJiri Olsa group_def:
20089efb029SJiri Olsa PE_NAME '{' events '}'
20189efb029SJiri Olsa {
20289efb029SJiri Olsa 	struct list_head *list = $3;
20389efb029SJiri Olsa 
2045d9cdc11SArnaldo Carvalho de Melo 	inc_group_count(list, _parse_state);
2053cdc5c2cSKan Liang 	parse_events__set_leader($1, list, _parse_state);
206cabbf268SIan Rogers 	free($1);
20789efb029SJiri Olsa 	$$ = list;
20889efb029SJiri Olsa }
20989efb029SJiri Olsa |
21089efb029SJiri Olsa '{' events '}'
21189efb029SJiri Olsa {
21289efb029SJiri Olsa 	struct list_head *list = $2;
21389efb029SJiri Olsa 
2145d9cdc11SArnaldo Carvalho de Melo 	inc_group_count(list, _parse_state);
2153cdc5c2cSKan Liang 	parse_events__set_leader(NULL, list, _parse_state);
21689efb029SJiri Olsa 	$$ = list;
21789efb029SJiri Olsa }
21890e2b22dSJiri Olsa 
21989812fc8SJiri Olsa events:
22089efb029SJiri Olsa events ',' event
22189efb029SJiri Olsa {
22289efb029SJiri Olsa 	struct list_head *event = $3;
22389efb029SJiri Olsa 	struct list_head *list  = $1;
22489efb029SJiri Olsa 
225cabbf268SIan Rogers 	/* frees $3 */
22689efb029SJiri Olsa 	parse_events_update_lists(event, list);
22789efb029SJiri Olsa 	$$ = list;
22889efb029SJiri Olsa }
22989efb029SJiri Olsa |
23089efb029SJiri Olsa event
23189812fc8SJiri Olsa 
232ac2ba9f3SRobert Richter event: event_mod
233ac2ba9f3SRobert Richter 
234ac2ba9f3SRobert Richter event_mod:
235ac2ba9f3SRobert Richter event_name PE_MODIFIER_EVENT
23689812fc8SJiri Olsa {
23789efb029SJiri Olsa 	struct list_head *list = $1;
238cabbf268SIan Rogers 	int err;
23946010ab2SJiri Olsa 
2405d7be90eSJiri Olsa 	/*
2415d7be90eSJiri Olsa 	 * Apply modifier on all events added by single event definition
2425d7be90eSJiri Olsa 	 * (there could be more events added for multiple tracepoint
2435d7be90eSJiri Olsa 	 * definitions via '*?'.
2445d7be90eSJiri Olsa 	 */
245cabbf268SIan Rogers 	err = parse_events__modifier_event(list, $2, false);
246cabbf268SIan Rogers 	free($2);
247cabbf268SIan Rogers 	if (err) {
248*eabd4523SIan Rogers 		struct parse_events_state *parse_state = _parse_state;
249*eabd4523SIan Rogers 		struct parse_events_error *error = parse_state->error;
250*eabd4523SIan Rogers 
251*eabd4523SIan Rogers 		parse_events__handle_error(error, @2.first_column,
252*eabd4523SIan Rogers 					   strdup("Bad modifier"), NULL);
253cabbf268SIan Rogers 		free_list_evsel(list);
254cabbf268SIan Rogers 		YYABORT;
255cabbf268SIan Rogers 	}
25689efb029SJiri Olsa 	$$ = list;
25789812fc8SJiri Olsa }
25889812fc8SJiri Olsa |
259ac2ba9f3SRobert Richter event_name
260ac2ba9f3SRobert Richter 
261ac2ba9f3SRobert Richter event_name:
262ac2ba9f3SRobert Richter PE_EVENT_NAME event_def
263ac2ba9f3SRobert Richter {
264cabbf268SIan Rogers 	int err;
265cabbf268SIan Rogers 
266cabbf268SIan Rogers 	err = parse_events_name($2, $1);
267ac2ba9f3SRobert Richter 	free($1);
268cabbf268SIan Rogers 	if (err) {
269cabbf268SIan Rogers 		free_list_evsel($2);
270cabbf268SIan Rogers 		YYABORT;
271cabbf268SIan Rogers 	}
272ac2ba9f3SRobert Richter 	$$ = $2;
273ac2ba9f3SRobert Richter }
274ac2ba9f3SRobert Richter |
27589812fc8SJiri Olsa event_def
27689812fc8SJiri Olsa 
2775f537a26SJiri Olsa event_def: event_pmu |
2785f537a26SJiri Olsa 	   event_legacy_symbol |
27989812fc8SJiri Olsa 	   event_legacy_cache sep_dc |
28089812fc8SJiri Olsa 	   event_legacy_mem |
28189812fc8SJiri Olsa 	   event_legacy_tracepoint sep_dc |
28289812fc8SJiri Olsa 	   event_legacy_numeric sep_dc |
28384c86ca1SWang Nan 	   event_legacy_raw sep_dc |
28484c86ca1SWang Nan 	   event_bpf_file
28589812fc8SJiri Olsa 
28684ea6036SJiri Olsa event_pmu_name:
28784ea6036SJiri Olsa PE_NAME | PE_PMU_EVENT_PRE
28884ea6036SJiri Olsa 
2895f537a26SJiri Olsa event_pmu:
29084ea6036SJiri Olsa event_pmu_name opt_pmu_config
2915f537a26SJiri Olsa {
292f7fa827fSJiri Olsa 	struct parse_events_state *parse_state = _parse_state;
293f7fa827fSJiri Olsa 	struct parse_events_error *error = parse_state->error;
294cabbf268SIan Rogers 	struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL;
295cabbf268SIan Rogers 	char *pattern = NULL;
296cabbf268SIan Rogers 
297cabbf268SIan Rogers #define CLEANUP_YYABORT					\
298cabbf268SIan Rogers 	do {						\
299cabbf268SIan Rogers 		parse_events_terms__delete($2);		\
300cabbf268SIan Rogers 		parse_events_terms__delete(orig_terms);	\
301e1e9b78dSIan Rogers 		free(list);				\
302cabbf268SIan Rogers 		free($1);				\
303cabbf268SIan Rogers 		free(pattern);				\
304cabbf268SIan Rogers 		YYABORT;				\
305cabbf268SIan Rogers 	} while(0)
3068255718fSAndi Kleen 
3074a35a902SArnaldo Carvalho de Melo 	if (parse_events_copy_term_list($2, &orig_terms))
308cabbf268SIan Rogers 		CLEANUP_YYABORT;
309b847cbdcSJiri Olsa 
310f7fa827fSJiri Olsa 	if (error)
311f7fa827fSJiri Olsa 		error->idx = @1.first_column;
312f7fa827fSJiri Olsa 
313a26e4716SIan Rogers 	list = alloc_list();
314cabbf268SIan Rogers 	if (!list)
315cabbf268SIan Rogers 		CLEANUP_YYABORT;
3163cdc5c2cSKan Liang 	if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
3178255718fSAndi Kleen 		struct perf_pmu *pmu = NULL;
3188255718fSAndi Kleen 		int ok = 0;
319b2b9d3a3SAgustin Vega-Frias 
320b2b9d3a3SAgustin Vega-Frias 		if (asprintf(&pattern, "%s*", $1) < 0)
321cabbf268SIan Rogers 			CLEANUP_YYABORT;
3228255718fSAndi Kleen 
3238255718fSAndi Kleen 		while ((pmu = perf_pmu__scan(pmu)) != NULL) {
3248255718fSAndi Kleen 			char *name = pmu->name;
3258255718fSAndi Kleen 
326a820e335SAndi Kleen 			if (!strncmp(name, "uncore_", 7) &&
327a820e335SAndi Kleen 			    strncmp($1, "uncore_", 7))
328a820e335SAndi Kleen 				name += 7;
32913d60ba0SKan Liang 			if (!perf_pmu__match(pattern, name, $1) ||
33013d60ba0SKan Liang 			    !perf_pmu__match(pattern, pmu->alias_name, $1)) {
331cabbf268SIan Rogers 				if (parse_events_copy_term_list(orig_terms, &terms))
332cabbf268SIan Rogers 					CLEANUP_YYABORT;
3333cdc5c2cSKan Liang 				if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
3348255718fSAndi Kleen 					ok++;
3358255718fSAndi Kleen 				parse_events_terms__delete(terms);
3368255718fSAndi Kleen 			}
3378255718fSAndi Kleen 		}
338b2b9d3a3SAgustin Vega-Frias 
3398255718fSAndi Kleen 		if (!ok)
340cabbf268SIan Rogers 			CLEANUP_YYABORT;
3418255718fSAndi Kleen 	}
3424a35a902SArnaldo Carvalho de Melo 	parse_events_terms__delete($2);
3438255718fSAndi Kleen 	parse_events_terms__delete(orig_terms);
344ba08829aSIan Rogers 	free(pattern);
345cabbf268SIan Rogers 	free($1);
346b847cbdcSJiri Olsa 	$$ = list;
347cabbf268SIan Rogers #undef CLEANUP_YYABORT
3485f537a26SJiri Olsa }
349ad962273SAdrian Hunter |
350ba32a451SKan Liang PE_KERNEL_PMU_EVENT sep_dc
351ba32a451SKan Liang {
352ba32a451SKan Liang 	struct list_head *list;
353cabbf268SIan Rogers 	int err;
354ba32a451SKan Liang 
355fb081153SIan Rogers 	err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
356fb081153SIan Rogers 	free($1);
357fb081153SIan Rogers 	if (err < 0)
358fb081153SIan Rogers 		YYABORT;
359fb081153SIan Rogers 	$$ = list;
360fb081153SIan Rogers }
361fb081153SIan Rogers |
362fb081153SIan Rogers PE_KERNEL_PMU_EVENT opt_pmu_config
363fb081153SIan Rogers {
364fb081153SIan Rogers 	struct list_head *list;
365fb081153SIan Rogers 	int err;
366fb081153SIan Rogers 
367fb081153SIan Rogers 	/* frees $2 */
368fb081153SIan Rogers 	err = parse_events_multi_pmu_add(_parse_state, $1, $2, &list);
369cabbf268SIan Rogers 	free($1);
370cabbf268SIan Rogers 	if (err < 0)
371231bb2aaSAndi Kleen 		YYABORT;
372ba32a451SKan Liang 	$$ = list;
373ba32a451SKan Liang }
374ba32a451SKan Liang |
375ba32a451SKan Liang PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
376ba32a451SKan Liang {
377ba32a451SKan Liang 	struct list_head *list;
378ba32a451SKan Liang 	char pmu_name[128];
3798255718fSAndi Kleen 
380c2412faeSIan Rogers 	snprintf(pmu_name, sizeof(pmu_name), "%s-%s", $1, $3);
381cabbf268SIan Rogers 	free($1);
382cabbf268SIan Rogers 	free($3);
383fb081153SIan Rogers 	if (parse_events_multi_pmu_add(_parse_state, pmu_name, NULL, &list) < 0)
3848255718fSAndi Kleen 		YYABORT;
385ba32a451SKan Liang 	$$ = list;
386ba32a451SKan Liang }
387387ad33fSJiri Olsa |
388387ad33fSJiri Olsa PE_PMU_EVENT_FAKE sep_dc
389387ad33fSJiri Olsa {
390387ad33fSJiri Olsa 	struct list_head *list;
391387ad33fSJiri Olsa 	int err;
392387ad33fSJiri Olsa 
393387ad33fSJiri Olsa 	list = alloc_list();
394387ad33fSJiri Olsa 	if (!list)
395387ad33fSJiri Olsa 		YYABORT;
396387ad33fSJiri Olsa 
397387ad33fSJiri Olsa 	err = parse_events_add_pmu(_parse_state, list, $1, NULL, false, false);
398387ad33fSJiri Olsa 	free($1);
399387ad33fSJiri Olsa 	if (err < 0) {
400387ad33fSJiri Olsa 		free(list);
401387ad33fSJiri Olsa 		YYABORT;
402387ad33fSJiri Olsa 	}
403387ad33fSJiri Olsa 	$$ = list;
404387ad33fSJiri Olsa }
405387ad33fSJiri Olsa |
406387ad33fSJiri Olsa PE_PMU_EVENT_FAKE opt_pmu_config
407387ad33fSJiri Olsa {
408387ad33fSJiri Olsa 	struct list_head *list;
409387ad33fSJiri Olsa 	int err;
410387ad33fSJiri Olsa 
411387ad33fSJiri Olsa 	list = alloc_list();
412387ad33fSJiri Olsa 	if (!list)
413387ad33fSJiri Olsa 		YYABORT;
414387ad33fSJiri Olsa 
415387ad33fSJiri Olsa 	err = parse_events_add_pmu(_parse_state, list, $1, $2, false, false);
416387ad33fSJiri Olsa 	free($1);
417387ad33fSJiri Olsa 	parse_events_terms__delete($2);
418387ad33fSJiri Olsa 	if (err < 0) {
419387ad33fSJiri Olsa 		free(list);
420387ad33fSJiri Olsa 		YYABORT;
421387ad33fSJiri Olsa 	}
422387ad33fSJiri Olsa 	$$ = list;
423387ad33fSJiri Olsa }
4245f537a26SJiri Olsa 
425cf3506dcSJiri Olsa value_sym:
426cf3506dcSJiri Olsa PE_VALUE_SYM_HW
427cf3506dcSJiri Olsa |
428cf3506dcSJiri Olsa PE_VALUE_SYM_SW
429cf3506dcSJiri Olsa 
43089812fc8SJiri Olsa event_legacy_symbol:
431cf3506dcSJiri Olsa value_sym '/' event_config '/'
43289812fc8SJiri Olsa {
433c5cd8ac0SDavid Ahern 	struct list_head *list;
43489812fc8SJiri Olsa 	int type = $1 >> 16;
43589812fc8SJiri Olsa 	int config = $1 & 255;
436cabbf268SIan Rogers 	int err;
43789812fc8SJiri Olsa 
438a26e4716SIan Rogers 	list = alloc_list();
439a26e4716SIan Rogers 	ABORT_ON(!list);
440cabbf268SIan Rogers 	err = parse_events_add_numeric(_parse_state, list, type, config, $3);
4412146afc6SArnaldo Carvalho de Melo 	parse_events_terms__delete($3);
442cabbf268SIan Rogers 	if (err) {
443cabbf268SIan Rogers 		free_list_evsel(list);
444cabbf268SIan Rogers 		YYABORT;
445cabbf268SIan Rogers 	}
446b847cbdcSJiri Olsa 	$$ = list;
4478f707d84SJiri Olsa }
4488f707d84SJiri Olsa |
449714a92d8SJiri Olsa value_sym sep_slash_slash_dc
4508f707d84SJiri Olsa {
451c5cd8ac0SDavid Ahern 	struct list_head *list;
4528f707d84SJiri Olsa 	int type = $1 >> 16;
4538f707d84SJiri Olsa 	int config = $1 & 255;
4548f707d84SJiri Olsa 
455a26e4716SIan Rogers 	list = alloc_list();
456a26e4716SIan Rogers 	ABORT_ON(!list);
4575d9cdc11SArnaldo Carvalho de Melo 	ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
458b847cbdcSJiri Olsa 	$$ = list;
45989812fc8SJiri Olsa }
460f0fbb114SAndi Kleen |
461f0fbb114SAndi Kleen PE_VALUE_SYM_TOOL sep_slash_slash_dc
462f0fbb114SAndi Kleen {
463f0fbb114SAndi Kleen 	struct list_head *list;
464f0fbb114SAndi Kleen 
465a26e4716SIan Rogers 	list = alloc_list();
466a26e4716SIan Rogers 	ABORT_ON(!list);
467f0fbb114SAndi Kleen 	ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
468f0fbb114SAndi Kleen 	$$ = list;
469f0fbb114SAndi Kleen }
47089812fc8SJiri Olsa 
47189812fc8SJiri Olsa event_legacy_cache:
47243d0b978SWang Nan PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
47389812fc8SJiri Olsa {
4745d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
4755d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_error *error = parse_state->error;
476c5cd8ac0SDavid Ahern 	struct list_head *list;
477cabbf268SIan Rogers 	int err;
478b847cbdcSJiri Olsa 
479a26e4716SIan Rogers 	list = alloc_list();
480a26e4716SIan Rogers 	ABORT_ON(!list);
481c93afadcSJin Yao 	err = parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6,
482c93afadcSJin Yao 				     parse_state);
48343d0b978SWang Nan 	parse_events_terms__delete($6);
484cabbf268SIan Rogers 	free($1);
485cabbf268SIan Rogers 	free($3);
486cabbf268SIan Rogers 	free($5);
487cabbf268SIan Rogers 	if (err) {
488cabbf268SIan Rogers 		free_list_evsel(list);
489cabbf268SIan Rogers 		YYABORT;
490cabbf268SIan Rogers 	}
491b847cbdcSJiri Olsa 	$$ = list;
49289812fc8SJiri Olsa }
49389812fc8SJiri Olsa |
49443d0b978SWang Nan PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
49589812fc8SJiri Olsa {
4965d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
4975d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_error *error = parse_state->error;
498c5cd8ac0SDavid Ahern 	struct list_head *list;
499cabbf268SIan Rogers 	int err;
500b847cbdcSJiri Olsa 
501a26e4716SIan Rogers 	list = alloc_list();
502a26e4716SIan Rogers 	ABORT_ON(!list);
503c93afadcSJin Yao 	err = parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4,
504c93afadcSJin Yao 				     parse_state);
50543d0b978SWang Nan 	parse_events_terms__delete($4);
506cabbf268SIan Rogers 	free($1);
507cabbf268SIan Rogers 	free($3);
508cabbf268SIan Rogers 	if (err) {
509cabbf268SIan Rogers 		free_list_evsel(list);
510cabbf268SIan Rogers 		YYABORT;
511cabbf268SIan Rogers 	}
512b847cbdcSJiri Olsa 	$$ = list;
51389812fc8SJiri Olsa }
51489812fc8SJiri Olsa |
51543d0b978SWang Nan PE_NAME_CACHE_TYPE opt_event_config
51689812fc8SJiri Olsa {
5175d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
5185d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_error *error = parse_state->error;
519c5cd8ac0SDavid Ahern 	struct list_head *list;
520cabbf268SIan Rogers 	int err;
521b847cbdcSJiri Olsa 
522a26e4716SIan Rogers 	list = alloc_list();
523a26e4716SIan Rogers 	ABORT_ON(!list);
524c93afadcSJin Yao 	err = parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2,
525c93afadcSJin Yao 				     parse_state);
52643d0b978SWang Nan 	parse_events_terms__delete($2);
527cabbf268SIan Rogers 	free($1);
528cabbf268SIan Rogers 	if (err) {
529cabbf268SIan Rogers 		free_list_evsel(list);
530cabbf268SIan Rogers 		YYABORT;
531cabbf268SIan Rogers 	}
532b847cbdcSJiri Olsa 	$$ = list;
53389812fc8SJiri Olsa }
53489812fc8SJiri Olsa 
53589812fc8SJiri Olsa event_legacy_mem:
5363741eb9fSJacob Shin PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
5373741eb9fSJacob Shin {
5385d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
5393741eb9fSJacob Shin 	struct list_head *list;
540cabbf268SIan Rogers 	int err;
5413741eb9fSJacob Shin 
542a26e4716SIan Rogers 	list = alloc_list();
543a26e4716SIan Rogers 	ABORT_ON(!list);
544cabbf268SIan Rogers 	err = parse_events_add_breakpoint(list, &parse_state->idx,
545aa98d848SIan Rogers 					  $2, $6, $4);
546cabbf268SIan Rogers 	free($6);
547cabbf268SIan Rogers 	if (err) {
548cabbf268SIan Rogers 		free(list);
549cabbf268SIan Rogers 		YYABORT;
550cabbf268SIan Rogers 	}
5513741eb9fSJacob Shin 	$$ = list;
5523741eb9fSJacob Shin }
5533741eb9fSJacob Shin |
5543741eb9fSJacob Shin PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
5553741eb9fSJacob Shin {
5565d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
5573741eb9fSJacob Shin 	struct list_head *list;
5583741eb9fSJacob Shin 
559a26e4716SIan Rogers 	list = alloc_list();
560a26e4716SIan Rogers 	ABORT_ON(!list);
561cabbf268SIan Rogers 	if (parse_events_add_breakpoint(list, &parse_state->idx,
562aa98d848SIan Rogers 					$2, NULL, $4)) {
563cabbf268SIan Rogers 		free(list);
564cabbf268SIan Rogers 		YYABORT;
565cabbf268SIan Rogers 	}
5663741eb9fSJacob Shin 	$$ = list;
5673741eb9fSJacob Shin }
5683741eb9fSJacob Shin |
56989812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
57089812fc8SJiri Olsa {
5715d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
572c5cd8ac0SDavid Ahern 	struct list_head *list;
573cabbf268SIan Rogers 	int err;
574b847cbdcSJiri Olsa 
575a26e4716SIan Rogers 	list = alloc_list();
576a26e4716SIan Rogers 	ABORT_ON(!list);
577cabbf268SIan Rogers 	err = parse_events_add_breakpoint(list, &parse_state->idx,
578aa98d848SIan Rogers 					  $2, $4, 0);
579cabbf268SIan Rogers 	free($4);
580cabbf268SIan Rogers 	if (err) {
581cabbf268SIan Rogers 		free(list);
582cabbf268SIan Rogers 		YYABORT;
583cabbf268SIan Rogers 	}
584b847cbdcSJiri Olsa 	$$ = list;
58589812fc8SJiri Olsa }
58689812fc8SJiri Olsa |
58789812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE sep_dc
58889812fc8SJiri Olsa {
5895d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
590c5cd8ac0SDavid Ahern 	struct list_head *list;
591b847cbdcSJiri Olsa 
592a26e4716SIan Rogers 	list = alloc_list();
593a26e4716SIan Rogers 	ABORT_ON(!list);
594cabbf268SIan Rogers 	if (parse_events_add_breakpoint(list, &parse_state->idx,
595aa98d848SIan Rogers 					$2, NULL, 0)) {
596cabbf268SIan Rogers 		free(list);
597cabbf268SIan Rogers 		YYABORT;
598cabbf268SIan Rogers 	}
599b847cbdcSJiri Olsa 	$$ = list;
60089812fc8SJiri Olsa }
60189812fc8SJiri Olsa 
60289812fc8SJiri Olsa event_legacy_tracepoint:
6031d55e8efSArnaldo Carvalho de Melo tracepoint_name opt_event_config
6042b9032e0SAlexander Yarygin {
6055d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
6065d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_error *error = parse_state->error;
6072b9032e0SAlexander Yarygin 	struct list_head *list;
608cabbf268SIan Rogers 	int err;
6092b9032e0SAlexander Yarygin 
610a26e4716SIan Rogers 	list = alloc_list();
611a26e4716SIan Rogers 	ABORT_ON(!list);
61219658171SJiri Olsa 	if (error)
61319658171SJiri Olsa 		error->idx = @1.first_column;
614e637d177SHe Kuang 
615cabbf268SIan Rogers 	err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
616cabbf268SIan Rogers 					error, $2);
617e637d177SHe Kuang 
618cabbf268SIan Rogers 	parse_events_terms__delete($2);
619cabbf268SIan Rogers 	free($1.sys);
620cabbf268SIan Rogers 	free($1.event);
621cabbf268SIan Rogers 	if (err) {
622cabbf268SIan Rogers 		free(list);
623e1e9b78dSIan Rogers 		YYABORT;
624cabbf268SIan Rogers 	}
6252b9032e0SAlexander Yarygin 	$$ = list;
6262b9032e0SAlexander Yarygin }
627865582c3SHe Kuang 
628865582c3SHe Kuang tracepoint_name:
629865582c3SHe Kuang PE_NAME '-' PE_NAME ':' PE_NAME
630865582c3SHe Kuang {
631865582c3SHe Kuang 	struct tracepoint_name tracepoint;
632865582c3SHe Kuang 
633cabbf268SIan Rogers 	ABORT_ON(asprintf(&tracepoint.sys, "%s-%s", $1, $3) < 0);
634865582c3SHe Kuang 	tracepoint.event = $5;
635cabbf268SIan Rogers 	free($1);
636cabbf268SIan Rogers 	free($3);
637865582c3SHe Kuang 	$$ = tracepoint;
638865582c3SHe Kuang }
6392b9032e0SAlexander Yarygin |
64089812fc8SJiri Olsa PE_NAME ':' PE_NAME
64189812fc8SJiri Olsa {
642865582c3SHe Kuang 	struct tracepoint_name tracepoint = {$1, $3};
643b847cbdcSJiri Olsa 
644865582c3SHe Kuang 	$$ = tracepoint;
64589812fc8SJiri Olsa }
64689812fc8SJiri Olsa 
64789812fc8SJiri Olsa event_legacy_numeric:
64810bf358aSWang Nan PE_VALUE ':' PE_VALUE opt_event_config
64989812fc8SJiri Olsa {
650c5cd8ac0SDavid Ahern 	struct list_head *list;
651cabbf268SIan Rogers 	int err;
652b847cbdcSJiri Olsa 
653a26e4716SIan Rogers 	list = alloc_list();
654a26e4716SIan Rogers 	ABORT_ON(!list);
655cabbf268SIan Rogers 	err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4);
65610bf358aSWang Nan 	parse_events_terms__delete($4);
657cabbf268SIan Rogers 	if (err) {
658cabbf268SIan Rogers 		free(list);
659cabbf268SIan Rogers 		YYABORT;
660cabbf268SIan Rogers 	}
661b847cbdcSJiri Olsa 	$$ = list;
66289812fc8SJiri Olsa }
66389812fc8SJiri Olsa 
66489812fc8SJiri Olsa event_legacy_raw:
66510bf358aSWang Nan PE_RAW opt_event_config
66689812fc8SJiri Olsa {
667c5cd8ac0SDavid Ahern 	struct list_head *list;
668cabbf268SIan Rogers 	int err;
669b847cbdcSJiri Olsa 
670a26e4716SIan Rogers 	list = alloc_list();
671a26e4716SIan Rogers 	ABORT_ON(!list);
672cabbf268SIan Rogers 	err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2);
67310bf358aSWang Nan 	parse_events_terms__delete($2);
674cabbf268SIan Rogers 	if (err) {
675cabbf268SIan Rogers 		free(list);
676cabbf268SIan Rogers 		YYABORT;
677cabbf268SIan Rogers 	}
678b847cbdcSJiri Olsa 	$$ = list;
6798f707d84SJiri Olsa }
6808f707d84SJiri Olsa 
68184c86ca1SWang Nan event_bpf_file:
682a34f3be7SWang Nan PE_BPF_OBJECT opt_event_config
68384c86ca1SWang Nan {
6845d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
68584c86ca1SWang Nan 	struct list_head *list;
686cabbf268SIan Rogers 	int err;
68784c86ca1SWang Nan 
688a26e4716SIan Rogers 	list = alloc_list();
689a26e4716SIan Rogers 	ABORT_ON(!list);
690cabbf268SIan Rogers 	err = parse_events_load_bpf(parse_state, list, $1, false, $2);
691a34f3be7SWang Nan 	parse_events_terms__delete($2);
692cabbf268SIan Rogers 	free($1);
693cabbf268SIan Rogers 	if (err) {
694cabbf268SIan Rogers 		free(list);
695cabbf268SIan Rogers 		YYABORT;
696cabbf268SIan Rogers 	}
697d509db04SWang Nan 	$$ = list;
698d509db04SWang Nan }
699d509db04SWang Nan |
700a34f3be7SWang Nan PE_BPF_SOURCE opt_event_config
701d509db04SWang Nan {
702d509db04SWang Nan 	struct list_head *list;
703cabbf268SIan Rogers 	int err;
704d509db04SWang Nan 
705a26e4716SIan Rogers 	list = alloc_list();
706a26e4716SIan Rogers 	ABORT_ON(!list);
707cabbf268SIan Rogers 	err = parse_events_load_bpf(_parse_state, list, $1, true, $2);
708a34f3be7SWang Nan 	parse_events_terms__delete($2);
709cabbf268SIan Rogers 	if (err) {
710cabbf268SIan Rogers 		free(list);
711cabbf268SIan Rogers 		YYABORT;
712cabbf268SIan Rogers 	}
71384c86ca1SWang Nan 	$$ = list;
71484c86ca1SWang Nan }
71584c86ca1SWang Nan 
7161d55e8efSArnaldo Carvalho de Melo opt_event_config:
7171d55e8efSArnaldo Carvalho de Melo '/' event_config '/'
7181d55e8efSArnaldo Carvalho de Melo {
7191d55e8efSArnaldo Carvalho de Melo 	$$ = $2;
7201d55e8efSArnaldo Carvalho de Melo }
7211d55e8efSArnaldo Carvalho de Melo |
7221d55e8efSArnaldo Carvalho de Melo '/' '/'
7231d55e8efSArnaldo Carvalho de Melo {
7241d55e8efSArnaldo Carvalho de Melo 	$$ = NULL;
7251d55e8efSArnaldo Carvalho de Melo }
7261d55e8efSArnaldo Carvalho de Melo |
7271d55e8efSArnaldo Carvalho de Melo {
7281d55e8efSArnaldo Carvalho de Melo 	$$ = NULL;
7291d55e8efSArnaldo Carvalho de Melo }
7301d55e8efSArnaldo Carvalho de Melo 
731ceac7b79SJiri Olsa opt_pmu_config:
732ceac7b79SJiri Olsa '/' event_config '/'
733ceac7b79SJiri Olsa {
734ceac7b79SJiri Olsa 	$$ = $2;
735ceac7b79SJiri Olsa }
736ceac7b79SJiri Olsa |
737ceac7b79SJiri Olsa '/' '/'
738ceac7b79SJiri Olsa {
739ceac7b79SJiri Olsa 	$$ = NULL;
740ceac7b79SJiri Olsa }
741ceac7b79SJiri Olsa 
74289efb029SJiri Olsa start_terms: event_config
74390e2b22dSJiri Olsa {
7445d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
745cabbf268SIan Rogers 	if (parse_state->terms) {
746cabbf268SIan Rogers 		parse_events_terms__delete ($1);
747cabbf268SIan Rogers 		YYABORT;
748cabbf268SIan Rogers 	}
7495d9cdc11SArnaldo Carvalho de Melo 	parse_state->terms = $1;
75090e2b22dSJiri Olsa }
75190e2b22dSJiri Olsa 
7528f707d84SJiri Olsa event_config:
7538f707d84SJiri Olsa event_config ',' event_term
7548f707d84SJiri Olsa {
7558f707d84SJiri Olsa 	struct list_head *head = $1;
7566cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term = $3;
7578f707d84SJiri Olsa 
758cabbf268SIan Rogers 	if (!head) {
7591dc92556SIan Rogers 		parse_events_term__delete(term);
760cabbf268SIan Rogers 		YYABORT;
761cabbf268SIan Rogers 	}
7628f707d84SJiri Olsa 	list_add_tail(&term->list, head);
7638f707d84SJiri Olsa 	$$ = $1;
7648f707d84SJiri Olsa }
7658f707d84SJiri Olsa |
7668f707d84SJiri Olsa event_term
7678f707d84SJiri Olsa {
7688f707d84SJiri Olsa 	struct list_head *head = malloc(sizeof(*head));
7696cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term = $1;
7708f707d84SJiri Olsa 
7718f707d84SJiri Olsa 	ABORT_ON(!head);
7728f707d84SJiri Olsa 	INIT_LIST_HEAD(head);
7738f707d84SJiri Olsa 	list_add_tail(&term->list, head);
7748f707d84SJiri Olsa 	$$ = head;
7758f707d84SJiri Olsa }
7768f707d84SJiri Olsa 
7778f707d84SJiri Olsa event_term:
7783a6c51e4SJiri Olsa PE_RAW
7793a6c51e4SJiri Olsa {
7803a6c51e4SJiri Olsa 	struct parse_events_term *term;
7813a6c51e4SJiri Olsa 
7823a6c51e4SJiri Olsa 	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_CONFIG,
7833a6c51e4SJiri Olsa 					NULL, $1, false, &@1, NULL));
7843a6c51e4SJiri Olsa 	$$ = term;
7853a6c51e4SJiri Olsa }
7863a6c51e4SJiri Olsa |
7878f707d84SJiri Olsa PE_NAME '=' PE_NAME
7888f707d84SJiri Olsa {
7896cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
7908f707d84SJiri Olsa 
791cabbf268SIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
792cabbf268SIan Rogers 					$1, $3, &@1, &@3)) {
793cabbf268SIan Rogers 		free($1);
794cabbf268SIan Rogers 		free($3);
795cabbf268SIan Rogers 		YYABORT;
796cabbf268SIan Rogers 	}
7978f707d84SJiri Olsa 	$$ = term;
7988f707d84SJiri Olsa }
7998f707d84SJiri Olsa |
8008f707d84SJiri Olsa PE_NAME '=' PE_VALUE
8018f707d84SJiri Olsa {
8026cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8038f707d84SJiri Olsa 
804cabbf268SIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
805cabbf268SIan Rogers 					$1, $3, false, &@1, &@3)) {
806cabbf268SIan Rogers 		free($1);
807cabbf268SIan Rogers 		YYABORT;
808cabbf268SIan Rogers 	}
8098f707d84SJiri Olsa 	$$ = term;
8108f707d84SJiri Olsa }
8118f707d84SJiri Olsa |
8121d33d6dcSJiri Olsa PE_NAME '=' PE_VALUE_SYM_HW
8131d33d6dcSJiri Olsa {
8146cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8151d33d6dcSJiri Olsa 	int config = $3 & 255;
8161d33d6dcSJiri Olsa 
817cabbf268SIan Rogers 	if (parse_events_term__sym_hw(&term, $1, config)) {
818cabbf268SIan Rogers 		free($1);
819cabbf268SIan Rogers 		YYABORT;
820cabbf268SIan Rogers 	}
8211d33d6dcSJiri Olsa 	$$ = term;
8221d33d6dcSJiri Olsa }
8231d33d6dcSJiri Olsa |
8248f707d84SJiri Olsa PE_NAME
8258f707d84SJiri Olsa {
8266cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8278f707d84SJiri Olsa 
828cabbf268SIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
829cabbf268SIan Rogers 					$1, 1, true, &@1, NULL)) {
830cabbf268SIan Rogers 		free($1);
831cabbf268SIan Rogers 		YYABORT;
832cabbf268SIan Rogers 	}
8338f707d84SJiri Olsa 	$$ = term;
8348f707d84SJiri Olsa }
8358f707d84SJiri Olsa |
8361d33d6dcSJiri Olsa PE_VALUE_SYM_HW
8371d33d6dcSJiri Olsa {
8386cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8391d33d6dcSJiri Olsa 	int config = $1 & 255;
8401d33d6dcSJiri Olsa 
8416cee6cd3SArnaldo Carvalho de Melo 	ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
8421d33d6dcSJiri Olsa 	$$ = term;
8431d33d6dcSJiri Olsa }
8441d33d6dcSJiri Olsa |
8456b5fc39bSJiri Olsa PE_TERM '=' PE_NAME
8466b5fc39bSJiri Olsa {
8476cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8486b5fc39bSJiri Olsa 
849cabbf268SIan Rogers 	if (parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)) {
850cabbf268SIan Rogers 		free($3);
851cabbf268SIan Rogers 		YYABORT;
852cabbf268SIan Rogers 	}
8536b5fc39bSJiri Olsa 	$$ = term;
8546b5fc39bSJiri Olsa }
8556b5fc39bSJiri Olsa |
8568f707d84SJiri Olsa PE_TERM '=' PE_VALUE
8578f707d84SJiri Olsa {
8586cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8598f707d84SJiri Olsa 
86099e7138eSJiri Olsa 	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
8618f707d84SJiri Olsa 	$$ = term;
8628f707d84SJiri Olsa }
8638f707d84SJiri Olsa |
8648f707d84SJiri Olsa PE_TERM
8658f707d84SJiri Olsa {
8666cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8678f707d84SJiri Olsa 
86899e7138eSJiri Olsa 	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
8698f707d84SJiri Olsa 	$$ = term;
87089812fc8SJiri Olsa }
871e571e029SWang Nan |
872e571e029SWang Nan PE_NAME array '=' PE_NAME
873e571e029SWang Nan {
874e571e029SWang Nan 	struct parse_events_term *term;
875e571e029SWang Nan 
876cabbf268SIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
877cabbf268SIan Rogers 					$1, $4, &@1, &@4)) {
878cabbf268SIan Rogers 		free($1);
879cabbf268SIan Rogers 		free($4);
880cabbf268SIan Rogers 		free($2.ranges);
881cabbf268SIan Rogers 		YYABORT;
882cabbf268SIan Rogers 	}
883e571e029SWang Nan 	term->array = $2;
884e571e029SWang Nan 	$$ = term;
885e571e029SWang Nan }
886e571e029SWang Nan |
887e571e029SWang Nan PE_NAME array '=' PE_VALUE
888e571e029SWang Nan {
889e571e029SWang Nan 	struct parse_events_term *term;
890e571e029SWang Nan 
891cabbf268SIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
892cabbf268SIan Rogers 					$1, $4, false, &@1, &@4)) {
893cabbf268SIan Rogers 		free($1);
894cabbf268SIan Rogers 		free($2.ranges);
895cabbf268SIan Rogers 		YYABORT;
896cabbf268SIan Rogers 	}
897e571e029SWang Nan 	term->array = $2;
898e571e029SWang Nan 	$$ = term;
899e571e029SWang Nan }
900dd60fba7SMathieu Poirier |
901dd60fba7SMathieu Poirier PE_DRV_CFG_TERM
902dd60fba7SMathieu Poirier {
903dd60fba7SMathieu Poirier 	struct parse_events_term *term;
904b6645a72SIan Rogers 	char *config = strdup($1);
905dd60fba7SMathieu Poirier 
906b6645a72SIan Rogers 	ABORT_ON(!config);
907cabbf268SIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
908cabbf268SIan Rogers 					config, $1, &@1, NULL)) {
909cabbf268SIan Rogers 		free($1);
910cabbf268SIan Rogers 		free(config);
911cabbf268SIan Rogers 		YYABORT;
912cabbf268SIan Rogers 	}
913dd60fba7SMathieu Poirier 	$$ = term;
914dd60fba7SMathieu Poirier }
915e571e029SWang Nan 
916e571e029SWang Nan array:
917e571e029SWang Nan '[' array_terms ']'
918e571e029SWang Nan {
919e571e029SWang Nan 	$$ = $2;
920e571e029SWang Nan }
921e571e029SWang Nan |
922e571e029SWang Nan PE_ARRAY_ALL
923e571e029SWang Nan {
924e571e029SWang Nan 	$$.nr_ranges = 0;
925e571e029SWang Nan 	$$.ranges = NULL;
926e571e029SWang Nan }
927e571e029SWang Nan 
928e571e029SWang Nan array_terms:
929e571e029SWang Nan array_terms ',' array_term
930e571e029SWang Nan {
931e571e029SWang Nan 	struct parse_events_array new_array;
932e571e029SWang Nan 
933e571e029SWang Nan 	new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
934826100a7SIan Rogers 	new_array.ranges = realloc($1.ranges,
935826100a7SIan Rogers 				sizeof(new_array.ranges[0]) *
936e571e029SWang Nan 				new_array.nr_ranges);
937e571e029SWang Nan 	ABORT_ON(!new_array.ranges);
938e571e029SWang Nan 	memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
939e571e029SWang Nan 	       $3.nr_ranges * sizeof(new_array.ranges[0]));
940e571e029SWang Nan 	free($3.ranges);
941e571e029SWang Nan 	$$ = new_array;
942e571e029SWang Nan }
943e571e029SWang Nan |
944e571e029SWang Nan array_term
945e571e029SWang Nan 
946e571e029SWang Nan array_term:
947e571e029SWang Nan PE_VALUE
948e571e029SWang Nan {
949e571e029SWang Nan 	struct parse_events_array array;
950e571e029SWang Nan 
951e571e029SWang Nan 	array.nr_ranges = 1;
952e571e029SWang Nan 	array.ranges = malloc(sizeof(array.ranges[0]));
953e571e029SWang Nan 	ABORT_ON(!array.ranges);
954e571e029SWang Nan 	array.ranges[0].start = $1;
955e571e029SWang Nan 	array.ranges[0].length = 1;
956e571e029SWang Nan 	$$ = array;
957e571e029SWang Nan }
958e571e029SWang Nan |
959e571e029SWang Nan PE_VALUE PE_ARRAY_RANGE PE_VALUE
960e571e029SWang Nan {
961e571e029SWang Nan 	struct parse_events_array array;
962e571e029SWang Nan 
963e571e029SWang Nan 	ABORT_ON($3 < $1);
964e571e029SWang Nan 	array.nr_ranges = 1;
965e571e029SWang Nan 	array.ranges = malloc(sizeof(array.ranges[0]));
966e571e029SWang Nan 	ABORT_ON(!array.ranges);
967e571e029SWang Nan 	array.ranges[0].start = $1;
968e571e029SWang Nan 	array.ranges[0].length = $3 - $1 + 1;
969e571e029SWang Nan 	$$ = array;
970e571e029SWang Nan }
97189812fc8SJiri Olsa 
97289812fc8SJiri Olsa sep_dc: ':' |
97389812fc8SJiri Olsa 
974714a92d8SJiri Olsa sep_slash_slash_dc: '/' '/' | ':' |
9758f707d84SJiri Olsa 
97689812fc8SJiri Olsa %%
97789812fc8SJiri Olsa 
9785d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state,
9796297d423SJiri Olsa 			void *scanner __maybe_unused,
9801d037ca1SIrina Tirdea 			char const *msg __maybe_unused)
98189812fc8SJiri Olsa {
9825d9cdc11SArnaldo Carvalho de Melo 	parse_events_evlist_error(parse_state, loc->last_column, "parser error");
98389812fc8SJiri Olsa }
984