xref: /linux/tools/perf/util/parse-events.y (revision 2aadca4b35427a7c65acc6aa415b38758128b22c)
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 
1170c90e4aSIan Rogers #include <errno.h>
12b2b9d3a3SAgustin Vega-Frias #include <fnmatch.h>
13bd704620SArnaldo Carvalho de Melo #include <stdio.h>
1489812fc8SJiri Olsa #include <linux/compiler.h>
15d944c4eeSBorislav Petkov #include <linux/types.h>
16f2a8ecd8SIan Rogers #include <linux/zalloc.h>
17231bb2aaSAndi Kleen #include "pmu.h"
18f0fbb114SAndi Kleen #include "evsel.h"
1989812fc8SJiri Olsa #include "parse-events.h"
20ac20de6fSZheng Yan #include "parse-events-bison.h"
2189812fc8SJiri Olsa 
225d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
2334a0548fSArnaldo Carvalho de Melo 
2489812fc8SJiri Olsa #define ABORT_ON(val) \
2589812fc8SJiri Olsa do { \
2689812fc8SJiri Olsa 	if (val) \
2789812fc8SJiri Olsa 		YYABORT; \
2889812fc8SJiri Olsa } while (0)
2989812fc8SJiri Olsa 
30ffaecd7dSIan Rogers static struct list_head* alloc_list(void)
31a26e4716SIan Rogers {
32a26e4716SIan Rogers 	struct list_head *list;
33a26e4716SIan Rogers 
34a26e4716SIan Rogers 	list = malloc(sizeof(*list));
35a26e4716SIan Rogers 	if (!list)
36a26e4716SIan Rogers 		return NULL;
37a26e4716SIan Rogers 
38a26e4716SIan Rogers 	INIT_LIST_HEAD(list);
39a26e4716SIan Rogers 	return list;
40a26e4716SIan Rogers }
41c5cd8ac0SDavid Ahern 
42f2a8ecd8SIan Rogers static void free_list_evsel(struct list_head* list_evsel)
43f2a8ecd8SIan Rogers {
44f2a8ecd8SIan Rogers 	struct evsel *evsel, *tmp;
45f2a8ecd8SIan Rogers 
46f2a8ecd8SIan Rogers 	list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) {
47f2a8ecd8SIan Rogers 		list_del_init(&evsel->core.node);
48672f707eSIan Rogers 		evsel__delete(evsel);
49f2a8ecd8SIan Rogers 	}
50f2a8ecd8SIan Rogers 	free(list_evsel);
51f2a8ecd8SIan Rogers }
52f2a8ecd8SIan Rogers 
5389812fc8SJiri Olsa %}
5489812fc8SJiri Olsa 
5590e2b22dSJiri Olsa %token PE_START_EVENTS PE_START_TERMS
5670c90e4aSIan Rogers %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM
57f0fbb114SAndi Kleen %token PE_VALUE_SYM_TOOL
58ac2ba9f3SRobert Richter %token PE_EVENT_NAME
5970c90e4aSIan Rogers %token PE_RAW PE_NAME
60d509db04SWang Nan %token PE_BPF_OBJECT PE_BPF_SOURCE
6189812fc8SJiri Olsa %token PE_MODIFIER_EVENT PE_MODIFIER_BP
6270c90e4aSIan Rogers %token PE_LEGACY_CACHE
6389efb029SJiri Olsa %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
6489812fc8SJiri Olsa %token PE_ERROR
6570c90e4aSIan Rogers %token PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
66e571e029SWang Nan %token PE_ARRAY_ALL PE_ARRAY_RANGE
67dd60fba7SMathieu Poirier %token PE_DRV_CFG_TERM
685ea8f2ccSIan Rogers %token PE_TERM_HW
6989812fc8SJiri Olsa %type <num> PE_VALUE
70cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_HW
71cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_SW
72f0fbb114SAndi Kleen %type <num> PE_VALUE_SYM_TOOL
738f707d84SJiri Olsa %type <num> PE_TERM
74f2a8ecd8SIan Rogers %type <num> value_sym
7570c90e4aSIan Rogers %type <str> PE_RAW
7689812fc8SJiri Olsa %type <str> PE_NAME
7784c86ca1SWang Nan %type <str> PE_BPF_OBJECT
78d509db04SWang Nan %type <str> PE_BPF_SOURCE
7970c90e4aSIan Rogers %type <str> PE_LEGACY_CACHE
8089812fc8SJiri Olsa %type <str> PE_MODIFIER_EVENT
8189812fc8SJiri Olsa %type <str> PE_MODIFIER_BP
82ac2ba9f3SRobert Richter %type <str> PE_EVENT_NAME
8370c90e4aSIan Rogers %type <str> PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
84dd60fba7SMathieu Poirier %type <str> PE_DRV_CFG_TERM
85*2aadca4bSIan Rogers %type <str> name_or_raw name_or_legacy
86f2a8ecd8SIan Rogers %destructor { free ($$); } <str>
878f707d84SJiri Olsa %type <term> event_term
881dc92556SIan Rogers %destructor { parse_events_term__delete ($$); } <term>
89f2a8ecd8SIan Rogers %type <list_terms> event_config
90f2a8ecd8SIan Rogers %type <list_terms> opt_event_config
91f2a8ecd8SIan Rogers %type <list_terms> opt_pmu_config
92f2a8ecd8SIan Rogers %destructor { parse_events_terms__delete ($$); } <list_terms>
93f2a8ecd8SIan Rogers %type <list_evsel> event_pmu
94f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_symbol
95f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_cache
96f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_mem
97f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_tracepoint
98f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_numeric
99f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_raw
100f2a8ecd8SIan Rogers %type <list_evsel> event_bpf_file
101f2a8ecd8SIan Rogers %type <list_evsel> event_def
102f2a8ecd8SIan Rogers %type <list_evsel> event_mod
103f2a8ecd8SIan Rogers %type <list_evsel> event_name
104f2a8ecd8SIan Rogers %type <list_evsel> event
105f2a8ecd8SIan Rogers %type <list_evsel> events
106f2a8ecd8SIan Rogers %type <list_evsel> group_def
107f2a8ecd8SIan Rogers %type <list_evsel> group
108f2a8ecd8SIan Rogers %type <list_evsel> groups
109f2a8ecd8SIan Rogers %destructor { free_list_evsel ($$); } <list_evsel>
110865582c3SHe Kuang %type <tracepoint_name> tracepoint_name
111f2a8ecd8SIan Rogers %destructor { free ($$.sys); free ($$.event); } <tracepoint_name>
112e571e029SWang Nan %type <array> array
113e571e029SWang Nan %type <array> array_term
114e571e029SWang Nan %type <array> array_terms
115f2a8ecd8SIan Rogers %destructor { free ($$.ranges); } <array>
1165ea8f2ccSIan Rogers %type <hardware_term> PE_TERM_HW
1175ea8f2ccSIan Rogers %destructor { free ($$.str); } <hardware_term>
11889812fc8SJiri Olsa 
11989812fc8SJiri Olsa %union
12089812fc8SJiri Olsa {
12189812fc8SJiri Olsa 	char *str;
122b527bab5SRobert Richter 	u64 num;
123f2a8ecd8SIan Rogers 	struct list_head *list_evsel;
124f2a8ecd8SIan Rogers 	struct list_head *list_terms;
1256cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
126865582c3SHe Kuang 	struct tracepoint_name {
127865582c3SHe Kuang 		char *sys;
128865582c3SHe Kuang 		char *event;
129865582c3SHe Kuang 	} tracepoint_name;
130e571e029SWang Nan 	struct parse_events_array array;
1315ea8f2ccSIan Rogers 	struct hardware_term {
1325ea8f2ccSIan Rogers 		char *str;
1335ea8f2ccSIan Rogers 		u64 num;
1345ea8f2ccSIan Rogers 	} hardware_term;
13589812fc8SJiri Olsa }
13689812fc8SJiri Olsa %%
13789812fc8SJiri Olsa 
13890e2b22dSJiri Olsa start:
13989efb029SJiri Olsa PE_START_EVENTS start_events
14090e2b22dSJiri Olsa |
14189efb029SJiri Olsa PE_START_TERMS  start_terms
14289efb029SJiri Olsa 
14389efb029SJiri Olsa start_events: groups
14489efb029SJiri Olsa {
1455d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
14689efb029SJiri Olsa 
147cabbf268SIan Rogers 	/* frees $1 */
1485d9cdc11SArnaldo Carvalho de Melo 	parse_events_update_lists($1, &parse_state->list);
14989efb029SJiri Olsa }
15089efb029SJiri Olsa 
15189efb029SJiri Olsa groups:
15289efb029SJiri Olsa groups ',' group
15389efb029SJiri Olsa {
15489efb029SJiri Olsa 	struct list_head *list  = $1;
15589efb029SJiri Olsa 	struct list_head *group = $3;
15689efb029SJiri Olsa 
157cabbf268SIan Rogers 	/* frees $3 */
15889efb029SJiri Olsa 	parse_events_update_lists(group, list);
15989efb029SJiri Olsa 	$$ = list;
16089efb029SJiri Olsa }
16189efb029SJiri Olsa |
16289efb029SJiri Olsa groups ',' event
16389efb029SJiri Olsa {
16489efb029SJiri Olsa 	struct list_head *list  = $1;
16589efb029SJiri Olsa 	struct list_head *event = $3;
16689efb029SJiri Olsa 
167cabbf268SIan Rogers 	/* frees $3 */
16889efb029SJiri Olsa 	parse_events_update_lists(event, list);
16989efb029SJiri Olsa 	$$ = list;
17089efb029SJiri Olsa }
17189efb029SJiri Olsa |
17289efb029SJiri Olsa group
17389efb029SJiri Olsa |
17489efb029SJiri Olsa event
17589efb029SJiri Olsa 
17689efb029SJiri Olsa group:
17789efb029SJiri Olsa group_def ':' PE_MODIFIER_EVENT
17889efb029SJiri Olsa {
17989efb029SJiri Olsa 	struct list_head *list = $1;
180cabbf268SIan Rogers 	int err;
18189efb029SJiri Olsa 
182cabbf268SIan Rogers 	err = parse_events__modifier_group(list, $3);
183cabbf268SIan Rogers 	free($3);
184cabbf268SIan Rogers 	if (err) {
185eabd4523SIan Rogers 		struct parse_events_state *parse_state = _parse_state;
186eabd4523SIan Rogers 		struct parse_events_error *error = parse_state->error;
187eabd4523SIan Rogers 
1886c191289SIan Rogers 		parse_events_error__handle(error, @3.first_column,
189eabd4523SIan Rogers 					   strdup("Bad modifier"), NULL);
190cabbf268SIan Rogers 		free_list_evsel(list);
191cabbf268SIan Rogers 		YYABORT;
192cabbf268SIan Rogers 	}
19389efb029SJiri Olsa 	$$ = list;
19489efb029SJiri Olsa }
19589efb029SJiri Olsa |
19689efb029SJiri Olsa group_def
19789efb029SJiri Olsa 
19889efb029SJiri Olsa group_def:
19989efb029SJiri Olsa PE_NAME '{' events '}'
20089efb029SJiri Olsa {
20189efb029SJiri Olsa 	struct list_head *list = $3;
20289efb029SJiri Olsa 
2034bb311b2SIan Rogers 	/* Takes ownership of $1. */
204347c2f0aSIan Rogers 	parse_events__set_leader($1, list);
20589efb029SJiri Olsa 	$$ = list;
20689efb029SJiri Olsa }
20789efb029SJiri Olsa |
20889efb029SJiri Olsa '{' events '}'
20989efb029SJiri Olsa {
21089efb029SJiri Olsa 	struct list_head *list = $2;
21189efb029SJiri Olsa 
212347c2f0aSIan Rogers 	parse_events__set_leader(NULL, list);
21389efb029SJiri Olsa 	$$ = list;
21489efb029SJiri Olsa }
21590e2b22dSJiri Olsa 
21689812fc8SJiri Olsa events:
21789efb029SJiri Olsa events ',' event
21889efb029SJiri Olsa {
21989efb029SJiri Olsa 	struct list_head *event = $3;
22089efb029SJiri Olsa 	struct list_head *list  = $1;
22189efb029SJiri Olsa 
222cabbf268SIan Rogers 	/* frees $3 */
22389efb029SJiri Olsa 	parse_events_update_lists(event, list);
22489efb029SJiri Olsa 	$$ = list;
22589efb029SJiri Olsa }
22689efb029SJiri Olsa |
22789efb029SJiri Olsa event
22889812fc8SJiri Olsa 
229ac2ba9f3SRobert Richter event: event_mod
230ac2ba9f3SRobert Richter 
231ac2ba9f3SRobert Richter event_mod:
232ac2ba9f3SRobert Richter event_name PE_MODIFIER_EVENT
23389812fc8SJiri Olsa {
23489efb029SJiri Olsa 	struct list_head *list = $1;
235cabbf268SIan Rogers 	int err;
23646010ab2SJiri Olsa 
2375d7be90eSJiri Olsa 	/*
2385d7be90eSJiri Olsa 	 * Apply modifier on all events added by single event definition
2395d7be90eSJiri Olsa 	 * (there could be more events added for multiple tracepoint
2405d7be90eSJiri Olsa 	 * definitions via '*?'.
2415d7be90eSJiri Olsa 	 */
242cabbf268SIan Rogers 	err = parse_events__modifier_event(list, $2, false);
243cabbf268SIan Rogers 	free($2);
244cabbf268SIan Rogers 	if (err) {
245eabd4523SIan Rogers 		struct parse_events_state *parse_state = _parse_state;
246eabd4523SIan Rogers 		struct parse_events_error *error = parse_state->error;
247eabd4523SIan Rogers 
2486c191289SIan Rogers 		parse_events_error__handle(error, @2.first_column,
249eabd4523SIan Rogers 					   strdup("Bad modifier"), NULL);
250cabbf268SIan Rogers 		free_list_evsel(list);
251cabbf268SIan Rogers 		YYABORT;
252cabbf268SIan Rogers 	}
25389efb029SJiri Olsa 	$$ = list;
25489812fc8SJiri Olsa }
25589812fc8SJiri Olsa |
256ac2ba9f3SRobert Richter event_name
257ac2ba9f3SRobert Richter 
258ac2ba9f3SRobert Richter event_name:
259ac2ba9f3SRobert Richter PE_EVENT_NAME event_def
260ac2ba9f3SRobert Richter {
261cabbf268SIan Rogers 	int err;
262cabbf268SIan Rogers 
263cabbf268SIan Rogers 	err = parse_events_name($2, $1);
264ac2ba9f3SRobert Richter 	free($1);
265cabbf268SIan Rogers 	if (err) {
266cabbf268SIan Rogers 		free_list_evsel($2);
267cabbf268SIan Rogers 		YYABORT;
268cabbf268SIan Rogers 	}
269ac2ba9f3SRobert Richter 	$$ = $2;
270ac2ba9f3SRobert Richter }
271ac2ba9f3SRobert Richter |
27289812fc8SJiri Olsa event_def
27389812fc8SJiri Olsa 
2745f537a26SJiri Olsa event_def: event_pmu |
2755f537a26SJiri Olsa 	   event_legacy_symbol |
27689812fc8SJiri Olsa 	   event_legacy_cache sep_dc |
27789812fc8SJiri Olsa 	   event_legacy_mem |
27889812fc8SJiri Olsa 	   event_legacy_tracepoint sep_dc |
27989812fc8SJiri Olsa 	   event_legacy_numeric sep_dc |
28084c86ca1SWang Nan 	   event_legacy_raw sep_dc |
28184c86ca1SWang Nan 	   event_bpf_file
28289812fc8SJiri Olsa 
2835f537a26SJiri Olsa event_pmu:
28470c90e4aSIan Rogers PE_NAME opt_pmu_config
2855f537a26SJiri Olsa {
286f7fa827fSJiri Olsa 	struct parse_events_state *parse_state = _parse_state;
287f7fa827fSJiri Olsa 	struct parse_events_error *error = parse_state->error;
288cabbf268SIan Rogers 	struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL;
289cabbf268SIan Rogers 	char *pattern = NULL;
290cabbf268SIan Rogers 
291cabbf268SIan Rogers #define CLEANUP_YYABORT					\
292cabbf268SIan Rogers 	do {						\
293cabbf268SIan Rogers 		parse_events_terms__delete($2);		\
294cabbf268SIan Rogers 		parse_events_terms__delete(orig_terms);	\
295e1e9b78dSIan Rogers 		free(list);				\
296cabbf268SIan Rogers 		free($1);				\
297cabbf268SIan Rogers 		free(pattern);				\
298cabbf268SIan Rogers 		YYABORT;				\
299cabbf268SIan Rogers 	} while(0)
3008255718fSAndi Kleen 
3014a35a902SArnaldo Carvalho de Melo 	if (parse_events_copy_term_list($2, &orig_terms))
302cabbf268SIan Rogers 		CLEANUP_YYABORT;
303b847cbdcSJiri Olsa 
304f7fa827fSJiri Olsa 	if (error)
305f7fa827fSJiri Olsa 		error->idx = @1.first_column;
306f7fa827fSJiri Olsa 
307a26e4716SIan Rogers 	list = alloc_list();
308cabbf268SIan Rogers 	if (!list)
309cabbf268SIan Rogers 		CLEANUP_YYABORT;
31070c90e4aSIan Rogers 	/* Attempt to add to list assuming $1 is a PMU name. */
31124d80818SIan Rogers 	if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false)) {
3128255718fSAndi Kleen 		struct perf_pmu *pmu = NULL;
3138255718fSAndi Kleen 		int ok = 0;
314b2b9d3a3SAgustin Vega-Frias 
31570c90e4aSIan Rogers 		/* Failure to add, try wildcard expansion of $1 as a PMU name. */
316b2b9d3a3SAgustin Vega-Frias 		if (asprintf(&pattern, "%s*", $1) < 0)
317cabbf268SIan Rogers 			CLEANUP_YYABORT;
3188255718fSAndi Kleen 
3198255718fSAndi Kleen 		while ((pmu = perf_pmu__scan(pmu)) != NULL) {
3208255718fSAndi Kleen 			char *name = pmu->name;
3218255718fSAndi Kleen 
322411ad22eSIan Rogers 			if (parse_events__filter_pmu(parse_state, pmu))
323411ad22eSIan Rogers 				continue;
324411ad22eSIan Rogers 
325a820e335SAndi Kleen 			if (!strncmp(name, "uncore_", 7) &&
326a820e335SAndi Kleen 			    strncmp($1, "uncore_", 7))
327a820e335SAndi Kleen 				name += 7;
32813d60ba0SKan Liang 			if (!perf_pmu__match(pattern, name, $1) ||
32913d60ba0SKan Liang 			    !perf_pmu__match(pattern, pmu->alias_name, $1)) {
330cabbf268SIan Rogers 				if (parse_events_copy_term_list(orig_terms, &terms))
331cabbf268SIan Rogers 					CLEANUP_YYABORT;
33224d80818SIan Rogers 				if (!parse_events_add_pmu(parse_state, list, pmu->name, terms,
333e733f87eSIan Rogers 							  /*auto_merge_stats=*/true)) {
3348255718fSAndi Kleen 					ok++;
335a4c7d7c5SIan Rogers 					parse_state->wild_card_pmus = true;
336e733f87eSIan Rogers 				}
3378255718fSAndi Kleen 				parse_events_terms__delete(terms);
3388255718fSAndi Kleen 			}
3398255718fSAndi Kleen 		}
340b2b9d3a3SAgustin Vega-Frias 
34170c90e4aSIan Rogers 		if (!ok) {
34270c90e4aSIan Rogers 			/* Failure to add, assume $1 is an event name. */
34370c90e4aSIan Rogers 			zfree(&list);
34424d80818SIan Rogers 			ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list);
34570c90e4aSIan Rogers 			$2 = NULL;
34670c90e4aSIan Rogers 		}
3478255718fSAndi Kleen 		if (!ok)
348cabbf268SIan Rogers 			CLEANUP_YYABORT;
3498255718fSAndi Kleen 	}
3504a35a902SArnaldo Carvalho de Melo 	parse_events_terms__delete($2);
3518255718fSAndi Kleen 	parse_events_terms__delete(orig_terms);
352ba08829aSIan Rogers 	free(pattern);
353cabbf268SIan Rogers 	free($1);
354b847cbdcSJiri Olsa 	$$ = list;
355cabbf268SIan Rogers #undef CLEANUP_YYABORT
3565f537a26SJiri Olsa }
357ad962273SAdrian Hunter |
358ba32a451SKan Liang PE_KERNEL_PMU_EVENT sep_dc
359ba32a451SKan Liang {
360ba32a451SKan Liang 	struct list_head *list;
361cabbf268SIan Rogers 	int err;
362ba32a451SKan Liang 
363fb081153SIan Rogers 	err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
364fb081153SIan Rogers 	free($1);
365fb081153SIan Rogers 	if (err < 0)
366fb081153SIan Rogers 		YYABORT;
367fb081153SIan Rogers 	$$ = list;
368fb081153SIan Rogers }
369fb081153SIan Rogers |
37070c90e4aSIan Rogers PE_NAME sep_dc
37170c90e4aSIan Rogers {
37270c90e4aSIan Rogers 	struct list_head *list;
37370c90e4aSIan Rogers 	int err;
37470c90e4aSIan Rogers 
37570c90e4aSIan Rogers 	err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
37670c90e4aSIan Rogers 	free($1);
37770c90e4aSIan Rogers 	if (err < 0)
37870c90e4aSIan Rogers 		YYABORT;
37970c90e4aSIan Rogers 	$$ = list;
38070c90e4aSIan Rogers }
38170c90e4aSIan Rogers |
382fb081153SIan Rogers PE_KERNEL_PMU_EVENT opt_pmu_config
383fb081153SIan Rogers {
384fb081153SIan Rogers 	struct list_head *list;
385fb081153SIan Rogers 	int err;
386fb081153SIan Rogers 
387fb081153SIan Rogers 	/* frees $2 */
388fb081153SIan Rogers 	err = parse_events_multi_pmu_add(_parse_state, $1, $2, &list);
389cabbf268SIan Rogers 	free($1);
390cabbf268SIan Rogers 	if (err < 0)
391231bb2aaSAndi Kleen 		YYABORT;
392ba32a451SKan Liang 	$$ = list;
393ba32a451SKan Liang }
394ba32a451SKan Liang |
395387ad33fSJiri Olsa PE_PMU_EVENT_FAKE sep_dc
396387ad33fSJiri Olsa {
397387ad33fSJiri Olsa 	struct list_head *list;
398387ad33fSJiri Olsa 	int err;
399387ad33fSJiri Olsa 
400387ad33fSJiri Olsa 	list = alloc_list();
401387ad33fSJiri Olsa 	if (!list)
402387ad33fSJiri Olsa 		YYABORT;
403387ad33fSJiri Olsa 
404e733f87eSIan Rogers 	err = parse_events_add_pmu(_parse_state, list, $1, /*head_config=*/NULL,
405e733f87eSIan Rogers 				   /*auto_merge_stats=*/false);
406387ad33fSJiri Olsa 	free($1);
407387ad33fSJiri Olsa 	if (err < 0) {
408387ad33fSJiri Olsa 		free(list);
409387ad33fSJiri Olsa 		YYABORT;
410387ad33fSJiri Olsa 	}
411387ad33fSJiri Olsa 	$$ = list;
412387ad33fSJiri Olsa }
413387ad33fSJiri Olsa |
414387ad33fSJiri Olsa PE_PMU_EVENT_FAKE opt_pmu_config
415387ad33fSJiri Olsa {
416387ad33fSJiri Olsa 	struct list_head *list;
417387ad33fSJiri Olsa 	int err;
418387ad33fSJiri Olsa 
419387ad33fSJiri Olsa 	list = alloc_list();
420387ad33fSJiri Olsa 	if (!list)
421387ad33fSJiri Olsa 		YYABORT;
422387ad33fSJiri Olsa 
423e733f87eSIan Rogers 	err = parse_events_add_pmu(_parse_state, list, $1, $2, /*auto_merge_stats=*/false);
424387ad33fSJiri Olsa 	free($1);
425387ad33fSJiri Olsa 	parse_events_terms__delete($2);
426387ad33fSJiri Olsa 	if (err < 0) {
427387ad33fSJiri Olsa 		free(list);
428387ad33fSJiri Olsa 		YYABORT;
429387ad33fSJiri Olsa 	}
430387ad33fSJiri Olsa 	$$ = list;
431387ad33fSJiri Olsa }
4325f537a26SJiri Olsa 
433cf3506dcSJiri Olsa value_sym:
434cf3506dcSJiri Olsa PE_VALUE_SYM_HW
435cf3506dcSJiri Olsa |
436cf3506dcSJiri Olsa PE_VALUE_SYM_SW
437cf3506dcSJiri Olsa 
43889812fc8SJiri Olsa event_legacy_symbol:
439cf3506dcSJiri Olsa value_sym '/' event_config '/'
44089812fc8SJiri Olsa {
441c5cd8ac0SDavid Ahern 	struct list_head *list;
44289812fc8SJiri Olsa 	int type = $1 >> 16;
44389812fc8SJiri Olsa 	int config = $1 & 255;
444cabbf268SIan Rogers 	int err;
44589812fc8SJiri Olsa 
446a26e4716SIan Rogers 	list = alloc_list();
447a26e4716SIan Rogers 	ABORT_ON(!list);
4488bc75f69SIan Rogers 	err = parse_events_add_numeric(_parse_state, list, type, config, $3,
4498bc75f69SIan Rogers 				       /*wildcard=*/false);
4502146afc6SArnaldo Carvalho de Melo 	parse_events_terms__delete($3);
451cabbf268SIan Rogers 	if (err) {
452cabbf268SIan Rogers 		free_list_evsel(list);
453cabbf268SIan Rogers 		YYABORT;
454cabbf268SIan Rogers 	}
455b847cbdcSJiri Olsa 	$$ = list;
4568f707d84SJiri Olsa }
4578f707d84SJiri Olsa |
458714a92d8SJiri Olsa value_sym sep_slash_slash_dc
4598f707d84SJiri Olsa {
460c5cd8ac0SDavid Ahern 	struct list_head *list;
4618f707d84SJiri Olsa 	int type = $1 >> 16;
4628f707d84SJiri Olsa 	int config = $1 & 255;
4638f707d84SJiri Olsa 
464a26e4716SIan Rogers 	list = alloc_list();
465a26e4716SIan Rogers 	ABORT_ON(!list);
4668bc75f69SIan Rogers 	ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config,
4678bc75f69SIan Rogers 					  /*head_config=*/NULL,
4688bc75f69SIan Rogers 					  /*wildcard=*/false));
469b847cbdcSJiri Olsa 	$$ = list;
47089812fc8SJiri Olsa }
471f0fbb114SAndi Kleen |
472f0fbb114SAndi Kleen PE_VALUE_SYM_TOOL sep_slash_slash_dc
473f0fbb114SAndi Kleen {
474f0fbb114SAndi Kleen 	struct list_head *list;
475f0fbb114SAndi Kleen 
476a26e4716SIan Rogers 	list = alloc_list();
477a26e4716SIan Rogers 	ABORT_ON(!list);
478f0fbb114SAndi Kleen 	ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
479f0fbb114SAndi Kleen 	$$ = list;
480f0fbb114SAndi Kleen }
48189812fc8SJiri Olsa 
48289812fc8SJiri Olsa event_legacy_cache:
48370c90e4aSIan Rogers PE_LEGACY_CACHE opt_event_config
48489812fc8SJiri Olsa {
4855d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
486c5cd8ac0SDavid Ahern 	struct list_head *list;
487cabbf268SIan Rogers 	int err;
488b847cbdcSJiri Olsa 
489a26e4716SIan Rogers 	list = alloc_list();
490a26e4716SIan Rogers 	ABORT_ON(!list);
491411ad22eSIan Rogers 	err = parse_events_add_cache(list, &parse_state->idx, $1, parse_state, $2);
492b847cbdcSJiri Olsa 
49343d0b978SWang Nan 	parse_events_terms__delete($2);
494cabbf268SIan Rogers 	free($1);
495cabbf268SIan Rogers 	if (err) {
496cabbf268SIan Rogers 		free_list_evsel(list);
497cabbf268SIan Rogers 		YYABORT;
498cabbf268SIan Rogers 	}
499b847cbdcSJiri Olsa 	$$ = list;
50089812fc8SJiri Olsa }
50189812fc8SJiri Olsa 
50289812fc8SJiri Olsa event_legacy_mem:
5033741eb9fSJacob Shin PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
5043741eb9fSJacob Shin {
5055d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
5063741eb9fSJacob Shin 	struct list_head *list;
507cabbf268SIan Rogers 	int err;
5083741eb9fSJacob Shin 
509a26e4716SIan Rogers 	list = alloc_list();
510a26e4716SIan Rogers 	ABORT_ON(!list);
511cabbf268SIan Rogers 	err = parse_events_add_breakpoint(list, &parse_state->idx,
512aa98d848SIan Rogers 					  $2, $6, $4);
513cabbf268SIan Rogers 	free($6);
514cabbf268SIan Rogers 	if (err) {
515cabbf268SIan Rogers 		free(list);
516cabbf268SIan Rogers 		YYABORT;
517cabbf268SIan Rogers 	}
5183741eb9fSJacob Shin 	$$ = list;
5193741eb9fSJacob Shin }
5203741eb9fSJacob Shin |
5213741eb9fSJacob Shin PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
5223741eb9fSJacob Shin {
5235d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
5243741eb9fSJacob Shin 	struct list_head *list;
5253741eb9fSJacob Shin 
526a26e4716SIan Rogers 	list = alloc_list();
527a26e4716SIan Rogers 	ABORT_ON(!list);
528cabbf268SIan Rogers 	if (parse_events_add_breakpoint(list, &parse_state->idx,
529aa98d848SIan Rogers 					$2, NULL, $4)) {
530cabbf268SIan Rogers 		free(list);
531cabbf268SIan Rogers 		YYABORT;
532cabbf268SIan Rogers 	}
5333741eb9fSJacob Shin 	$$ = list;
5343741eb9fSJacob Shin }
5353741eb9fSJacob Shin |
53689812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
53789812fc8SJiri Olsa {
5385d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
539c5cd8ac0SDavid Ahern 	struct list_head *list;
540cabbf268SIan Rogers 	int err;
541b847cbdcSJiri Olsa 
542a26e4716SIan Rogers 	list = alloc_list();
543a26e4716SIan Rogers 	ABORT_ON(!list);
544cabbf268SIan Rogers 	err = parse_events_add_breakpoint(list, &parse_state->idx,
545aa98d848SIan Rogers 					  $2, $4, 0);
546cabbf268SIan Rogers 	free($4);
547cabbf268SIan Rogers 	if (err) {
548cabbf268SIan Rogers 		free(list);
549cabbf268SIan Rogers 		YYABORT;
550cabbf268SIan Rogers 	}
551b847cbdcSJiri Olsa 	$$ = list;
55289812fc8SJiri Olsa }
55389812fc8SJiri Olsa |
55489812fc8SJiri Olsa PE_PREFIX_MEM PE_VALUE sep_dc
55589812fc8SJiri Olsa {
5565d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
557c5cd8ac0SDavid Ahern 	struct list_head *list;
558b847cbdcSJiri Olsa 
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, 0)) {
563cabbf268SIan Rogers 		free(list);
564cabbf268SIan Rogers 		YYABORT;
565cabbf268SIan Rogers 	}
566b847cbdcSJiri Olsa 	$$ = list;
56789812fc8SJiri Olsa }
56889812fc8SJiri Olsa 
56989812fc8SJiri Olsa event_legacy_tracepoint:
5701d55e8efSArnaldo Carvalho de Melo tracepoint_name opt_event_config
5712b9032e0SAlexander Yarygin {
5725d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
5735d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_error *error = parse_state->error;
5742b9032e0SAlexander Yarygin 	struct list_head *list;
575cabbf268SIan Rogers 	int err;
5762b9032e0SAlexander Yarygin 
577a26e4716SIan Rogers 	list = alloc_list();
578a26e4716SIan Rogers 	ABORT_ON(!list);
57919658171SJiri Olsa 	if (error)
58019658171SJiri Olsa 		error->idx = @1.first_column;
581e637d177SHe Kuang 
582cabbf268SIan Rogers 	err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
583cabbf268SIan Rogers 					error, $2);
584e637d177SHe Kuang 
585cabbf268SIan Rogers 	parse_events_terms__delete($2);
586cabbf268SIan Rogers 	free($1.sys);
587cabbf268SIan Rogers 	free($1.event);
588cabbf268SIan Rogers 	if (err) {
589cabbf268SIan Rogers 		free(list);
590e1e9b78dSIan Rogers 		YYABORT;
591cabbf268SIan Rogers 	}
5922b9032e0SAlexander Yarygin 	$$ = list;
5932b9032e0SAlexander Yarygin }
594865582c3SHe Kuang 
595865582c3SHe Kuang tracepoint_name:
59689812fc8SJiri Olsa PE_NAME ':' PE_NAME
59789812fc8SJiri Olsa {
598865582c3SHe Kuang 	struct tracepoint_name tracepoint = {$1, $3};
599b847cbdcSJiri Olsa 
600865582c3SHe Kuang 	$$ = tracepoint;
60189812fc8SJiri Olsa }
60289812fc8SJiri Olsa 
60389812fc8SJiri Olsa event_legacy_numeric:
60410bf358aSWang Nan PE_VALUE ':' PE_VALUE opt_event_config
60589812fc8SJiri Olsa {
606c5cd8ac0SDavid Ahern 	struct list_head *list;
607cabbf268SIan Rogers 	int err;
608b847cbdcSJiri Olsa 
609a26e4716SIan Rogers 	list = alloc_list();
610a26e4716SIan Rogers 	ABORT_ON(!list);
6118bc75f69SIan Rogers 	err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4,
6128bc75f69SIan Rogers 				       /*wildcard=*/false);
61310bf358aSWang Nan 	parse_events_terms__delete($4);
614cabbf268SIan Rogers 	if (err) {
615cabbf268SIan Rogers 		free(list);
616cabbf268SIan Rogers 		YYABORT;
617cabbf268SIan Rogers 	}
618b847cbdcSJiri Olsa 	$$ = list;
61989812fc8SJiri Olsa }
62089812fc8SJiri Olsa 
62189812fc8SJiri Olsa event_legacy_raw:
62210bf358aSWang Nan PE_RAW opt_event_config
62389812fc8SJiri Olsa {
624c5cd8ac0SDavid Ahern 	struct list_head *list;
625cabbf268SIan Rogers 	int err;
62670c90e4aSIan Rogers 	u64 num;
627b847cbdcSJiri Olsa 
628a26e4716SIan Rogers 	list = alloc_list();
629a26e4716SIan Rogers 	ABORT_ON(!list);
63070c90e4aSIan Rogers 	errno = 0;
63170c90e4aSIan Rogers 	num = strtoull($1 + 1, NULL, 16);
63270c90e4aSIan Rogers 	ABORT_ON(errno);
63370c90e4aSIan Rogers 	free($1);
6348bc75f69SIan Rogers 	err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2,
6358bc75f69SIan Rogers 				       /*wildcard=*/true);
63610bf358aSWang Nan 	parse_events_terms__delete($2);
637cabbf268SIan Rogers 	if (err) {
638cabbf268SIan Rogers 		free(list);
639cabbf268SIan Rogers 		YYABORT;
640cabbf268SIan Rogers 	}
641b847cbdcSJiri Olsa 	$$ = list;
6428f707d84SJiri Olsa }
6438f707d84SJiri Olsa 
64484c86ca1SWang Nan event_bpf_file:
645a34f3be7SWang Nan PE_BPF_OBJECT opt_event_config
64684c86ca1SWang Nan {
6475d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
64884c86ca1SWang Nan 	struct list_head *list;
649cabbf268SIan Rogers 	int err;
65084c86ca1SWang Nan 
651a26e4716SIan Rogers 	list = alloc_list();
652a26e4716SIan Rogers 	ABORT_ON(!list);
653cabbf268SIan Rogers 	err = parse_events_load_bpf(parse_state, list, $1, false, $2);
654a34f3be7SWang Nan 	parse_events_terms__delete($2);
655cabbf268SIan Rogers 	free($1);
656cabbf268SIan Rogers 	if (err) {
657cabbf268SIan Rogers 		free(list);
658cabbf268SIan Rogers 		YYABORT;
659cabbf268SIan Rogers 	}
660d509db04SWang Nan 	$$ = list;
661d509db04SWang Nan }
662d509db04SWang Nan |
663a34f3be7SWang Nan PE_BPF_SOURCE opt_event_config
664d509db04SWang Nan {
665d509db04SWang Nan 	struct list_head *list;
666cabbf268SIan Rogers 	int err;
667d509db04SWang Nan 
668a26e4716SIan Rogers 	list = alloc_list();
669a26e4716SIan Rogers 	ABORT_ON(!list);
670cabbf268SIan Rogers 	err = parse_events_load_bpf(_parse_state, list, $1, true, $2);
671a34f3be7SWang Nan 	parse_events_terms__delete($2);
672cabbf268SIan Rogers 	if (err) {
673cabbf268SIan Rogers 		free(list);
674cabbf268SIan Rogers 		YYABORT;
675cabbf268SIan Rogers 	}
67684c86ca1SWang Nan 	$$ = list;
67784c86ca1SWang Nan }
67884c86ca1SWang Nan 
6791d55e8efSArnaldo Carvalho de Melo opt_event_config:
6801d55e8efSArnaldo Carvalho de Melo '/' event_config '/'
6811d55e8efSArnaldo Carvalho de Melo {
6821d55e8efSArnaldo Carvalho de Melo 	$$ = $2;
6831d55e8efSArnaldo Carvalho de Melo }
6841d55e8efSArnaldo Carvalho de Melo |
6851d55e8efSArnaldo Carvalho de Melo '/' '/'
6861d55e8efSArnaldo Carvalho de Melo {
6871d55e8efSArnaldo Carvalho de Melo 	$$ = NULL;
6881d55e8efSArnaldo Carvalho de Melo }
6891d55e8efSArnaldo Carvalho de Melo |
6901d55e8efSArnaldo Carvalho de Melo {
6911d55e8efSArnaldo Carvalho de Melo 	$$ = NULL;
6921d55e8efSArnaldo Carvalho de Melo }
6931d55e8efSArnaldo Carvalho de Melo 
694ceac7b79SJiri Olsa opt_pmu_config:
695ceac7b79SJiri Olsa '/' event_config '/'
696ceac7b79SJiri Olsa {
697ceac7b79SJiri Olsa 	$$ = $2;
698ceac7b79SJiri Olsa }
699ceac7b79SJiri Olsa |
700ceac7b79SJiri Olsa '/' '/'
701ceac7b79SJiri Olsa {
702ceac7b79SJiri Olsa 	$$ = NULL;
703ceac7b79SJiri Olsa }
704ceac7b79SJiri Olsa 
70589efb029SJiri Olsa start_terms: event_config
70690e2b22dSJiri Olsa {
7075d9cdc11SArnaldo Carvalho de Melo 	struct parse_events_state *parse_state = _parse_state;
708cabbf268SIan Rogers 	if (parse_state->terms) {
709cabbf268SIan Rogers 		parse_events_terms__delete ($1);
710cabbf268SIan Rogers 		YYABORT;
711cabbf268SIan Rogers 	}
7125d9cdc11SArnaldo Carvalho de Melo 	parse_state->terms = $1;
71390e2b22dSJiri Olsa }
71490e2b22dSJiri Olsa 
7158f707d84SJiri Olsa event_config:
7168f707d84SJiri Olsa event_config ',' event_term
7178f707d84SJiri Olsa {
7188f707d84SJiri Olsa 	struct list_head *head = $1;
7196cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term = $3;
7208f707d84SJiri Olsa 
721cabbf268SIan Rogers 	if (!head) {
7221dc92556SIan Rogers 		parse_events_term__delete(term);
723cabbf268SIan Rogers 		YYABORT;
724cabbf268SIan Rogers 	}
7258f707d84SJiri Olsa 	list_add_tail(&term->list, head);
7268f707d84SJiri Olsa 	$$ = $1;
7278f707d84SJiri Olsa }
7288f707d84SJiri Olsa |
7298f707d84SJiri Olsa event_term
7308f707d84SJiri Olsa {
7318f707d84SJiri Olsa 	struct list_head *head = malloc(sizeof(*head));
7326cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term = $1;
7338f707d84SJiri Olsa 
7348f707d84SJiri Olsa 	ABORT_ON(!head);
7358f707d84SJiri Olsa 	INIT_LIST_HEAD(head);
7368f707d84SJiri Olsa 	list_add_tail(&term->list, head);
7378f707d84SJiri Olsa 	$$ = head;
7388f707d84SJiri Olsa }
7398f707d84SJiri Olsa 
7406fd1e519SIan Rogers name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACHE
74170c90e4aSIan Rogers 
742*2aadca4bSIan Rogers name_or_legacy: PE_NAME | PE_LEGACY_CACHE
743*2aadca4bSIan Rogers 
7448f707d84SJiri Olsa event_term:
7453a6c51e4SJiri Olsa PE_RAW
7463a6c51e4SJiri Olsa {
7473a6c51e4SJiri Olsa 	struct parse_events_term *term;
7483a6c51e4SJiri Olsa 
74970c90e4aSIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_RAW,
75070c90e4aSIan Rogers 					strdup("raw"), $1, &@1, &@1)) {
75170c90e4aSIan Rogers 		free($1);
75270c90e4aSIan Rogers 		YYABORT;
75370c90e4aSIan Rogers 	}
7543a6c51e4SJiri Olsa 	$$ = term;
7553a6c51e4SJiri Olsa }
7563a6c51e4SJiri Olsa |
757*2aadca4bSIan Rogers name_or_raw '=' name_or_legacy
7588f707d84SJiri Olsa {
7596cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
7608f707d84SJiri Olsa 
761cabbf268SIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
762cabbf268SIan Rogers 					$1, $3, &@1, &@3)) {
763cabbf268SIan Rogers 		free($1);
764cabbf268SIan Rogers 		free($3);
765cabbf268SIan Rogers 		YYABORT;
766cabbf268SIan Rogers 	}
7678f707d84SJiri Olsa 	$$ = term;
7688f707d84SJiri Olsa }
7698f707d84SJiri Olsa |
77070c90e4aSIan Rogers name_or_raw '=' PE_VALUE
7718f707d84SJiri Olsa {
7726cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
7738f707d84SJiri Olsa 
774cabbf268SIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
775cabbf268SIan Rogers 					$1, $3, false, &@1, &@3)) {
776cabbf268SIan Rogers 		free($1);
777cabbf268SIan Rogers 		YYABORT;
778cabbf268SIan Rogers 	}
7798f707d84SJiri Olsa 	$$ = term;
7808f707d84SJiri Olsa }
7818f707d84SJiri Olsa |
7825ea8f2ccSIan Rogers name_or_raw '=' PE_TERM_HW
7831d33d6dcSJiri Olsa {
7846cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
7851d33d6dcSJiri Olsa 
7865ea8f2ccSIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
7875ea8f2ccSIan Rogers 					$1, $3.str, &@1, &@3)) {
788cabbf268SIan Rogers 		free($1);
7895ea8f2ccSIan Rogers 		free($3.str);
790cabbf268SIan Rogers 		YYABORT;
791cabbf268SIan Rogers 	}
7921d33d6dcSJiri Olsa 	$$ = term;
7931d33d6dcSJiri Olsa }
7941d33d6dcSJiri Olsa |
7956fd1e519SIan Rogers PE_LEGACY_CACHE
7966fd1e519SIan Rogers {
7976fd1e519SIan Rogers 	struct parse_events_term *term;
7986fd1e519SIan Rogers 
7996fd1e519SIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE,
8006fd1e519SIan Rogers 					$1, 1, true, &@1, NULL)) {
8016fd1e519SIan Rogers 		free($1);
8026fd1e519SIan Rogers 		YYABORT;
8036fd1e519SIan Rogers 	}
8046fd1e519SIan Rogers 	$$ = term;
8056fd1e519SIan Rogers }
8066fd1e519SIan Rogers |
8078f707d84SJiri Olsa PE_NAME
8088f707d84SJiri Olsa {
8096cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8108f707d84SJiri Olsa 
811cabbf268SIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
812cabbf268SIan Rogers 					$1, 1, true, &@1, NULL)) {
813cabbf268SIan Rogers 		free($1);
814cabbf268SIan Rogers 		YYABORT;
815cabbf268SIan Rogers 	}
8168f707d84SJiri Olsa 	$$ = term;
8178f707d84SJiri Olsa }
8188f707d84SJiri Olsa |
8195ea8f2ccSIan Rogers PE_TERM_HW
8201d33d6dcSJiri Olsa {
8216cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8221d33d6dcSJiri Olsa 
8235ea8f2ccSIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_HARDWARE,
8245ea8f2ccSIan Rogers 				   $1.str, $1.num & 255, false, &@1, NULL)) {
8255ea8f2ccSIan Rogers 		free($1.str);
8265ea8f2ccSIan Rogers 		YYABORT;
8275ea8f2ccSIan Rogers 	}
8281d33d6dcSJiri Olsa 	$$ = term;
8291d33d6dcSJiri Olsa }
8301d33d6dcSJiri Olsa |
831*2aadca4bSIan Rogers PE_TERM '=' name_or_legacy
8326b5fc39bSJiri Olsa {
8336cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8346b5fc39bSJiri Olsa 
835cabbf268SIan Rogers 	if (parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)) {
836cabbf268SIan Rogers 		free($3);
837cabbf268SIan Rogers 		YYABORT;
838cabbf268SIan Rogers 	}
8396b5fc39bSJiri Olsa 	$$ = term;
8406b5fc39bSJiri Olsa }
8416b5fc39bSJiri Olsa |
8425ea8f2ccSIan Rogers PE_TERM '=' PE_TERM_HW
8435ea8f2ccSIan Rogers {
8445ea8f2ccSIan Rogers 	struct parse_events_term *term;
8455ea8f2ccSIan Rogers 
8465ea8f2ccSIan Rogers 	if (parse_events_term__str(&term, (int)$1, NULL, $3.str, &@1, &@3)) {
8475ea8f2ccSIan Rogers 		free($3.str);
8485ea8f2ccSIan Rogers 		YYABORT;
8495ea8f2ccSIan Rogers 	}
8505ea8f2ccSIan Rogers 	$$ = term;
8515ea8f2ccSIan Rogers }
8525ea8f2ccSIan Rogers |
853e831f3ccSIan Rogers PE_TERM '=' PE_TERM
854e831f3ccSIan Rogers {
855e831f3ccSIan Rogers 	struct parse_events_term *term;
856e831f3ccSIan Rogers 
857e831f3ccSIan Rogers 	ABORT_ON(parse_events_term__term(&term, (int)$1, (int)$3, &@1, &@3));
858e831f3ccSIan Rogers 	$$ = term;
859e831f3ccSIan Rogers }
860e831f3ccSIan Rogers |
8618f707d84SJiri Olsa PE_TERM '=' PE_VALUE
8628f707d84SJiri Olsa {
8636cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8648f707d84SJiri Olsa 
86599e7138eSJiri Olsa 	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
8668f707d84SJiri Olsa 	$$ = term;
8678f707d84SJiri Olsa }
8688f707d84SJiri Olsa |
8698f707d84SJiri Olsa PE_TERM
8708f707d84SJiri Olsa {
8716cee6cd3SArnaldo Carvalho de Melo 	struct parse_events_term *term;
8728f707d84SJiri Olsa 
87399e7138eSJiri Olsa 	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
8748f707d84SJiri Olsa 	$$ = term;
87589812fc8SJiri Olsa }
876e571e029SWang Nan |
877*2aadca4bSIan Rogers name_or_raw array '=' name_or_legacy
878e571e029SWang Nan {
879e571e029SWang Nan 	struct parse_events_term *term;
880e571e029SWang Nan 
881cabbf268SIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
882cabbf268SIan Rogers 					$1, $4, &@1, &@4)) {
883cabbf268SIan Rogers 		free($1);
884cabbf268SIan Rogers 		free($4);
885cabbf268SIan Rogers 		free($2.ranges);
886cabbf268SIan Rogers 		YYABORT;
887cabbf268SIan Rogers 	}
888e571e029SWang Nan 	term->array = $2;
889e571e029SWang Nan 	$$ = term;
890e571e029SWang Nan }
891e571e029SWang Nan |
89270c90e4aSIan Rogers name_or_raw array '=' PE_VALUE
893e571e029SWang Nan {
894e571e029SWang Nan 	struct parse_events_term *term;
895e571e029SWang Nan 
896cabbf268SIan Rogers 	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
897cabbf268SIan Rogers 					$1, $4, false, &@1, &@4)) {
898cabbf268SIan Rogers 		free($1);
899cabbf268SIan Rogers 		free($2.ranges);
900cabbf268SIan Rogers 		YYABORT;
901cabbf268SIan Rogers 	}
902e571e029SWang Nan 	term->array = $2;
903e571e029SWang Nan 	$$ = term;
904e571e029SWang Nan }
905dd60fba7SMathieu Poirier |
906dd60fba7SMathieu Poirier PE_DRV_CFG_TERM
907dd60fba7SMathieu Poirier {
908dd60fba7SMathieu Poirier 	struct parse_events_term *term;
909b6645a72SIan Rogers 	char *config = strdup($1);
910dd60fba7SMathieu Poirier 
911b6645a72SIan Rogers 	ABORT_ON(!config);
912cabbf268SIan Rogers 	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
913cabbf268SIan Rogers 					config, $1, &@1, NULL)) {
914cabbf268SIan Rogers 		free($1);
915cabbf268SIan Rogers 		free(config);
916cabbf268SIan Rogers 		YYABORT;
917cabbf268SIan Rogers 	}
918dd60fba7SMathieu Poirier 	$$ = term;
919dd60fba7SMathieu Poirier }
920e571e029SWang Nan 
921e571e029SWang Nan array:
922e571e029SWang Nan '[' array_terms ']'
923e571e029SWang Nan {
924e571e029SWang Nan 	$$ = $2;
925e571e029SWang Nan }
926e571e029SWang Nan |
927e571e029SWang Nan PE_ARRAY_ALL
928e571e029SWang Nan {
929e571e029SWang Nan 	$$.nr_ranges = 0;
930e571e029SWang Nan 	$$.ranges = NULL;
931e571e029SWang Nan }
932e571e029SWang Nan 
933e571e029SWang Nan array_terms:
934e571e029SWang Nan array_terms ',' array_term
935e571e029SWang Nan {
936e571e029SWang Nan 	struct parse_events_array new_array;
937e571e029SWang Nan 
938e571e029SWang Nan 	new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
939826100a7SIan Rogers 	new_array.ranges = realloc($1.ranges,
940826100a7SIan Rogers 				sizeof(new_array.ranges[0]) *
941e571e029SWang Nan 				new_array.nr_ranges);
942e571e029SWang Nan 	ABORT_ON(!new_array.ranges);
943e571e029SWang Nan 	memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
944e571e029SWang Nan 	       $3.nr_ranges * sizeof(new_array.ranges[0]));
945e571e029SWang Nan 	free($3.ranges);
946e571e029SWang Nan 	$$ = new_array;
947e571e029SWang Nan }
948e571e029SWang Nan |
949e571e029SWang Nan array_term
950e571e029SWang Nan 
951e571e029SWang Nan array_term:
952e571e029SWang Nan PE_VALUE
953e571e029SWang Nan {
954e571e029SWang Nan 	struct parse_events_array array;
955e571e029SWang Nan 
956e571e029SWang Nan 	array.nr_ranges = 1;
957e571e029SWang Nan 	array.ranges = malloc(sizeof(array.ranges[0]));
958e571e029SWang Nan 	ABORT_ON(!array.ranges);
959e571e029SWang Nan 	array.ranges[0].start = $1;
960e571e029SWang Nan 	array.ranges[0].length = 1;
961e571e029SWang Nan 	$$ = array;
962e571e029SWang Nan }
963e571e029SWang Nan |
964e571e029SWang Nan PE_VALUE PE_ARRAY_RANGE PE_VALUE
965e571e029SWang Nan {
966e571e029SWang Nan 	struct parse_events_array array;
967e571e029SWang Nan 
968e571e029SWang Nan 	ABORT_ON($3 < $1);
969e571e029SWang Nan 	array.nr_ranges = 1;
970e571e029SWang Nan 	array.ranges = malloc(sizeof(array.ranges[0]));
971e571e029SWang Nan 	ABORT_ON(!array.ranges);
972e571e029SWang Nan 	array.ranges[0].start = $1;
973e571e029SWang Nan 	array.ranges[0].length = $3 - $1 + 1;
974e571e029SWang Nan 	$$ = array;
975e571e029SWang Nan }
97689812fc8SJiri Olsa 
97789812fc8SJiri Olsa sep_dc: ':' |
97889812fc8SJiri Olsa 
979714a92d8SJiri Olsa sep_slash_slash_dc: '/' '/' | ':' |
9808f707d84SJiri Olsa 
98189812fc8SJiri Olsa %%
98289812fc8SJiri Olsa 
9835d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state,
9846297d423SJiri Olsa 			void *scanner __maybe_unused,
9851d037ca1SIrina Tirdea 			char const *msg __maybe_unused)
98689812fc8SJiri Olsa {
9875d9cdc11SArnaldo Carvalho de Melo 	parse_events_evlist_error(parse_state, loc->last_column, "parser error");
98889812fc8SJiri Olsa }
989