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" 181eaf496eSIan Rogers #include "pmus.h" 19f0fbb114SAndi Kleen #include "evsel.h" 2089812fc8SJiri Olsa #include "parse-events.h" 21ac20de6fSZheng Yan #include "parse-events-bison.h" 2289812fc8SJiri Olsa 235d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); 2434a0548fSArnaldo Carvalho de Melo 2589812fc8SJiri Olsa #define ABORT_ON(val) \ 2689812fc8SJiri Olsa do { \ 2789812fc8SJiri Olsa if (val) \ 2889812fc8SJiri Olsa YYABORT; \ 2989812fc8SJiri Olsa } while (0) 3089812fc8SJiri Olsa 31b52cb995SIan Rogers #define PE_ABORT(val) \ 32b52cb995SIan Rogers do { \ 33b52cb995SIan Rogers if (val == -ENOMEM) \ 34b52cb995SIan Rogers YYNOMEM; \ 35b52cb995SIan Rogers YYABORT; \ 36b52cb995SIan Rogers } while (0) 37b52cb995SIan Rogers 38ffaecd7dSIan Rogers static struct list_head* alloc_list(void) 39a26e4716SIan Rogers { 40a26e4716SIan Rogers struct list_head *list; 41a26e4716SIan Rogers 42a26e4716SIan Rogers list = malloc(sizeof(*list)); 43a26e4716SIan Rogers if (!list) 44a26e4716SIan Rogers return NULL; 45a26e4716SIan Rogers 46a26e4716SIan Rogers INIT_LIST_HEAD(list); 47a26e4716SIan Rogers return list; 48a26e4716SIan Rogers } 49c5cd8ac0SDavid Ahern 50f2a8ecd8SIan Rogers static void free_list_evsel(struct list_head* list_evsel) 51f2a8ecd8SIan Rogers { 52f2a8ecd8SIan Rogers struct evsel *evsel, *tmp; 53f2a8ecd8SIan Rogers 54f2a8ecd8SIan Rogers list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) { 55f2a8ecd8SIan Rogers list_del_init(&evsel->core.node); 56672f707eSIan Rogers evsel__delete(evsel); 57f2a8ecd8SIan Rogers } 58f2a8ecd8SIan Rogers free(list_evsel); 59f2a8ecd8SIan Rogers } 60f2a8ecd8SIan Rogers 6189812fc8SJiri Olsa %} 6289812fc8SJiri Olsa 6390e2b22dSJiri Olsa %token PE_START_EVENTS PE_START_TERMS 6470c90e4aSIan Rogers %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM 65f0fbb114SAndi Kleen %token PE_VALUE_SYM_TOOL 66ac2ba9f3SRobert Richter %token PE_EVENT_NAME 6770c90e4aSIan Rogers %token PE_RAW PE_NAME 68d509db04SWang Nan %token PE_BPF_OBJECT PE_BPF_SOURCE 69f0617f52SAdrian Hunter %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH 7070c90e4aSIan Rogers %token PE_LEGACY_CACHE 717e34daa5SIan Rogers %token PE_PREFIX_MEM 7289812fc8SJiri Olsa %token PE_ERROR 73e571e029SWang Nan %token PE_ARRAY_ALL PE_ARRAY_RANGE 74dd60fba7SMathieu Poirier %token PE_DRV_CFG_TERM 755ea8f2ccSIan Rogers %token PE_TERM_HW 7689812fc8SJiri Olsa %type <num> PE_VALUE 77cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_HW 78cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_SW 79f0fbb114SAndi Kleen %type <num> PE_VALUE_SYM_TOOL 808f707d84SJiri Olsa %type <num> PE_TERM 81f2a8ecd8SIan Rogers %type <num> value_sym 8270c90e4aSIan Rogers %type <str> PE_RAW 8389812fc8SJiri Olsa %type <str> PE_NAME 8484c86ca1SWang Nan %type <str> PE_BPF_OBJECT 85d509db04SWang Nan %type <str> PE_BPF_SOURCE 8670c90e4aSIan Rogers %type <str> PE_LEGACY_CACHE 8789812fc8SJiri Olsa %type <str> PE_MODIFIER_EVENT 8889812fc8SJiri Olsa %type <str> PE_MODIFIER_BP 89ac2ba9f3SRobert Richter %type <str> PE_EVENT_NAME 90dd60fba7SMathieu Poirier %type <str> PE_DRV_CFG_TERM 912aadca4bSIan Rogers %type <str> name_or_raw name_or_legacy 92f2a8ecd8SIan Rogers %destructor { free ($$); } <str> 938f707d84SJiri Olsa %type <term> event_term 941dc92556SIan Rogers %destructor { parse_events_term__delete ($$); } <term> 95f2a8ecd8SIan Rogers %type <list_terms> event_config 96f2a8ecd8SIan Rogers %type <list_terms> opt_event_config 97f2a8ecd8SIan Rogers %type <list_terms> opt_pmu_config 98f2a8ecd8SIan Rogers %destructor { parse_events_terms__delete ($$); } <list_terms> 99f2a8ecd8SIan Rogers %type <list_evsel> event_pmu 100f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_symbol 101f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_cache 102f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_mem 103f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_tracepoint 104f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_numeric 105f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_raw 106f2a8ecd8SIan Rogers %type <list_evsel> event_bpf_file 107f2a8ecd8SIan Rogers %type <list_evsel> event_def 108f2a8ecd8SIan Rogers %type <list_evsel> event_mod 109f2a8ecd8SIan Rogers %type <list_evsel> event_name 110f2a8ecd8SIan Rogers %type <list_evsel> event 111f2a8ecd8SIan Rogers %type <list_evsel> events 112f2a8ecd8SIan Rogers %type <list_evsel> group_def 113f2a8ecd8SIan Rogers %type <list_evsel> group 114f2a8ecd8SIan Rogers %type <list_evsel> groups 115f2a8ecd8SIan Rogers %destructor { free_list_evsel ($$); } <list_evsel> 116865582c3SHe Kuang %type <tracepoint_name> tracepoint_name 117f2a8ecd8SIan Rogers %destructor { free ($$.sys); free ($$.event); } <tracepoint_name> 118e571e029SWang Nan %type <array> array 119e571e029SWang Nan %type <array> array_term 120e571e029SWang Nan %type <array> array_terms 121f2a8ecd8SIan Rogers %destructor { free ($$.ranges); } <array> 1225ea8f2ccSIan Rogers %type <hardware_term> PE_TERM_HW 1235ea8f2ccSIan Rogers %destructor { free ($$.str); } <hardware_term> 12489812fc8SJiri Olsa 12589812fc8SJiri Olsa %union 12689812fc8SJiri Olsa { 12789812fc8SJiri Olsa char *str; 128b527bab5SRobert Richter u64 num; 129f2a8ecd8SIan Rogers struct list_head *list_evsel; 130f2a8ecd8SIan Rogers struct list_head *list_terms; 1316cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 132865582c3SHe Kuang struct tracepoint_name { 133865582c3SHe Kuang char *sys; 134865582c3SHe Kuang char *event; 135865582c3SHe Kuang } tracepoint_name; 136e571e029SWang Nan struct parse_events_array array; 1375ea8f2ccSIan Rogers struct hardware_term { 1385ea8f2ccSIan Rogers char *str; 1395ea8f2ccSIan Rogers u64 num; 1405ea8f2ccSIan Rogers } hardware_term; 14189812fc8SJiri Olsa } 14289812fc8SJiri Olsa %% 14389812fc8SJiri Olsa 14490e2b22dSJiri Olsa start: 14589efb029SJiri Olsa PE_START_EVENTS start_events 14690e2b22dSJiri Olsa | 14789efb029SJiri Olsa PE_START_TERMS start_terms 14889efb029SJiri Olsa 14989efb029SJiri Olsa start_events: groups 15089efb029SJiri Olsa { 1515d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 15289efb029SJiri Olsa 153cabbf268SIan Rogers /* frees $1 */ 1545d9cdc11SArnaldo Carvalho de Melo parse_events_update_lists($1, &parse_state->list); 15589efb029SJiri Olsa } 15689efb029SJiri Olsa 15789efb029SJiri Olsa groups: 15889efb029SJiri Olsa groups ',' group 15989efb029SJiri Olsa { 16089efb029SJiri Olsa struct list_head *list = $1; 16189efb029SJiri Olsa struct list_head *group = $3; 16289efb029SJiri Olsa 163cabbf268SIan Rogers /* frees $3 */ 16489efb029SJiri Olsa parse_events_update_lists(group, list); 16589efb029SJiri Olsa $$ = list; 16689efb029SJiri Olsa } 16789efb029SJiri Olsa | 16889efb029SJiri Olsa groups ',' event 16989efb029SJiri Olsa { 17089efb029SJiri Olsa struct list_head *list = $1; 17189efb029SJiri Olsa struct list_head *event = $3; 17289efb029SJiri Olsa 173cabbf268SIan Rogers /* frees $3 */ 17489efb029SJiri Olsa parse_events_update_lists(event, list); 17589efb029SJiri Olsa $$ = list; 17689efb029SJiri Olsa } 17789efb029SJiri Olsa | 17889efb029SJiri Olsa group 17989efb029SJiri Olsa | 18089efb029SJiri Olsa event 18189efb029SJiri Olsa 18289efb029SJiri Olsa group: 18389efb029SJiri Olsa group_def ':' PE_MODIFIER_EVENT 18489efb029SJiri Olsa { 18589efb029SJiri Olsa struct list_head *list = $1; 186cabbf268SIan Rogers int err; 18789efb029SJiri Olsa 188cabbf268SIan Rogers err = parse_events__modifier_group(list, $3); 189cabbf268SIan Rogers free($3); 190cabbf268SIan Rogers if (err) { 191eabd4523SIan Rogers struct parse_events_state *parse_state = _parse_state; 192eabd4523SIan Rogers struct parse_events_error *error = parse_state->error; 193eabd4523SIan Rogers 1946c191289SIan Rogers parse_events_error__handle(error, @3.first_column, 195eabd4523SIan Rogers strdup("Bad modifier"), NULL); 196cabbf268SIan Rogers free_list_evsel(list); 197cabbf268SIan Rogers YYABORT; 198cabbf268SIan Rogers } 19989efb029SJiri Olsa $$ = list; 20089efb029SJiri Olsa } 20189efb029SJiri Olsa | 20289efb029SJiri Olsa group_def 20389efb029SJiri Olsa 20489efb029SJiri Olsa group_def: 20589efb029SJiri Olsa PE_NAME '{' events '}' 20689efb029SJiri Olsa { 20789efb029SJiri Olsa struct list_head *list = $3; 20889efb029SJiri Olsa 2094bb311b2SIan Rogers /* Takes ownership of $1. */ 210347c2f0aSIan Rogers parse_events__set_leader($1, list); 21189efb029SJiri Olsa $$ = list; 21289efb029SJiri Olsa } 21389efb029SJiri Olsa | 21489efb029SJiri Olsa '{' events '}' 21589efb029SJiri Olsa { 21689efb029SJiri Olsa struct list_head *list = $2; 21789efb029SJiri Olsa 218347c2f0aSIan Rogers parse_events__set_leader(NULL, list); 21989efb029SJiri Olsa $$ = list; 22089efb029SJiri Olsa } 22190e2b22dSJiri Olsa 22289812fc8SJiri Olsa events: 22389efb029SJiri Olsa events ',' event 22489efb029SJiri Olsa { 22589efb029SJiri Olsa struct list_head *event = $3; 22689efb029SJiri Olsa struct list_head *list = $1; 22789efb029SJiri Olsa 228cabbf268SIan Rogers /* frees $3 */ 22989efb029SJiri Olsa parse_events_update_lists(event, list); 23089efb029SJiri Olsa $$ = list; 23189efb029SJiri Olsa } 23289efb029SJiri Olsa | 23389efb029SJiri Olsa event 23489812fc8SJiri Olsa 235ac2ba9f3SRobert Richter event: event_mod 236ac2ba9f3SRobert Richter 237ac2ba9f3SRobert Richter event_mod: 238ac2ba9f3SRobert Richter event_name PE_MODIFIER_EVENT 23989812fc8SJiri Olsa { 24089efb029SJiri Olsa struct list_head *list = $1; 241cabbf268SIan Rogers int err; 24246010ab2SJiri Olsa 2435d7be90eSJiri Olsa /* 2445d7be90eSJiri Olsa * Apply modifier on all events added by single event definition 2455d7be90eSJiri Olsa * (there could be more events added for multiple tracepoint 2465d7be90eSJiri Olsa * definitions via '*?'. 2475d7be90eSJiri Olsa */ 248cabbf268SIan Rogers err = parse_events__modifier_event(list, $2, false); 249cabbf268SIan Rogers free($2); 250cabbf268SIan Rogers if (err) { 251eabd4523SIan Rogers struct parse_events_state *parse_state = _parse_state; 252eabd4523SIan Rogers struct parse_events_error *error = parse_state->error; 253eabd4523SIan Rogers 2546c191289SIan Rogers parse_events_error__handle(error, @2.first_column, 255eabd4523SIan Rogers strdup("Bad modifier"), NULL); 256cabbf268SIan Rogers free_list_evsel(list); 257cabbf268SIan Rogers YYABORT; 258cabbf268SIan Rogers } 25989efb029SJiri Olsa $$ = list; 26089812fc8SJiri Olsa } 26189812fc8SJiri Olsa | 262ac2ba9f3SRobert Richter event_name 263ac2ba9f3SRobert Richter 264ac2ba9f3SRobert Richter event_name: 265ac2ba9f3SRobert Richter PE_EVENT_NAME event_def 266ac2ba9f3SRobert Richter { 267cabbf268SIan Rogers int err; 268cabbf268SIan Rogers 269cabbf268SIan Rogers err = parse_events_name($2, $1); 270ac2ba9f3SRobert Richter free($1); 271cabbf268SIan Rogers if (err) { 272cabbf268SIan Rogers free_list_evsel($2); 2739462e4deSIan Rogers YYNOMEM; 274cabbf268SIan Rogers } 275ac2ba9f3SRobert Richter $$ = $2; 276ac2ba9f3SRobert Richter } 277ac2ba9f3SRobert Richter | 27889812fc8SJiri Olsa event_def 27989812fc8SJiri Olsa 2805f537a26SJiri Olsa event_def: event_pmu | 2815f537a26SJiri Olsa event_legacy_symbol | 28289812fc8SJiri Olsa event_legacy_cache sep_dc | 283f0617f52SAdrian Hunter event_legacy_mem sep_dc | 28489812fc8SJiri Olsa event_legacy_tracepoint sep_dc | 28589812fc8SJiri Olsa event_legacy_numeric sep_dc | 28684c86ca1SWang Nan event_legacy_raw sep_dc | 28784c86ca1SWang Nan event_bpf_file 28889812fc8SJiri Olsa 2895f537a26SJiri Olsa event_pmu: 29070c90e4aSIan Rogers PE_NAME opt_pmu_config 2915f537a26SJiri Olsa { 292f7fa827fSJiri Olsa struct parse_events_state *parse_state = _parse_state; 293cabbf268SIan Rogers struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL; 294cabbf268SIan Rogers char *pattern = NULL; 295cabbf268SIan Rogers 296a7a3252dSIan Rogers #define CLEANUP \ 297cabbf268SIan Rogers do { \ 298cabbf268SIan Rogers parse_events_terms__delete($2); \ 299cabbf268SIan Rogers parse_events_terms__delete(orig_terms); \ 300e1e9b78dSIan Rogers free(list); \ 301cabbf268SIan Rogers free($1); \ 302cabbf268SIan Rogers free(pattern); \ 303cabbf268SIan Rogers } while(0) 3048255718fSAndi Kleen 305a7a3252dSIan Rogers if (parse_events_copy_term_list($2, &orig_terms)) { 306a7a3252dSIan Rogers CLEANUP; 307a7a3252dSIan Rogers YYNOMEM; 308a7a3252dSIan Rogers } 309a7a3252dSIan Rogers 310a26e4716SIan Rogers list = alloc_list(); 311a7a3252dSIan Rogers if (!list) { 312a7a3252dSIan Rogers CLEANUP; 313a7a3252dSIan Rogers YYNOMEM; 314a7a3252dSIan Rogers } 31570c90e4aSIan Rogers /* Attempt to add to list assuming $1 is a PMU name. */ 316*81a4e31fSIan Rogers if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false, &@1)) { 3178255718fSAndi Kleen struct perf_pmu *pmu = NULL; 3188255718fSAndi Kleen int ok = 0; 319b2b9d3a3SAgustin Vega-Frias 32070c90e4aSIan Rogers /* Failure to add, try wildcard expansion of $1 as a PMU name. */ 321a7a3252dSIan Rogers if (asprintf(&pattern, "%s*", $1) < 0) { 322a7a3252dSIan Rogers CLEANUP; 323a7a3252dSIan Rogers YYNOMEM; 324a7a3252dSIan Rogers } 3258255718fSAndi Kleen 3261eaf496eSIan Rogers while ((pmu = perf_pmus__scan(pmu)) != NULL) { 3278255718fSAndi Kleen char *name = pmu->name; 3288255718fSAndi Kleen 329411ad22eSIan Rogers if (parse_events__filter_pmu(parse_state, pmu)) 330411ad22eSIan Rogers continue; 331411ad22eSIan Rogers 332a820e335SAndi Kleen if (!strncmp(name, "uncore_", 7) && 333a820e335SAndi Kleen strncmp($1, "uncore_", 7)) 334a820e335SAndi Kleen name += 7; 33513d60ba0SKan Liang if (!perf_pmu__match(pattern, name, $1) || 33613d60ba0SKan Liang !perf_pmu__match(pattern, pmu->alias_name, $1)) { 33752c7b4d3SIan Rogers bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); 33852c7b4d3SIan Rogers 339a7a3252dSIan Rogers if (parse_events_copy_term_list(orig_terms, &terms)) { 340a7a3252dSIan Rogers CLEANUP; 341a7a3252dSIan Rogers YYNOMEM; 342a7a3252dSIan Rogers } 34324d80818SIan Rogers if (!parse_events_add_pmu(parse_state, list, pmu->name, terms, 344*81a4e31fSIan Rogers auto_merge_stats, &@1)) { 3458255718fSAndi Kleen ok++; 346a4c7d7c5SIan Rogers parse_state->wild_card_pmus = true; 347e733f87eSIan Rogers } 3488255718fSAndi Kleen parse_events_terms__delete(terms); 3498255718fSAndi Kleen } 3508255718fSAndi Kleen } 351b2b9d3a3SAgustin Vega-Frias 35270c90e4aSIan Rogers if (!ok) { 35370c90e4aSIan Rogers /* Failure to add, assume $1 is an event name. */ 35470c90e4aSIan Rogers zfree(&list); 355*81a4e31fSIan Rogers ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list, &@1); 35670c90e4aSIan Rogers $2 = NULL; 35770c90e4aSIan Rogers } 358a7a3252dSIan Rogers if (!ok) { 359b30d4f0bSIan Rogers struct parse_events_error *error = parse_state->error; 360b30d4f0bSIan Rogers char *help; 361b30d4f0bSIan Rogers 362b30d4f0bSIan Rogers if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0) 363b30d4f0bSIan Rogers help = NULL; 364b30d4f0bSIan Rogers parse_events_error__handle(error, @1.first_column, 365b30d4f0bSIan Rogers strdup("Bad event or PMU"), 366b30d4f0bSIan Rogers help); 367a7a3252dSIan Rogers CLEANUP; 368a7a3252dSIan Rogers YYABORT; 3698255718fSAndi Kleen } 370a7a3252dSIan Rogers } 371b847cbdcSJiri Olsa $$ = list; 372a7a3252dSIan Rogers list = NULL; 373a7a3252dSIan Rogers CLEANUP; 374a7a3252dSIan Rogers #undef CLEANUP 3755f537a26SJiri Olsa } 376ad962273SAdrian Hunter | 37770c90e4aSIan Rogers PE_NAME sep_dc 37870c90e4aSIan Rogers { 37970c90e4aSIan Rogers struct list_head *list; 38070c90e4aSIan Rogers int err; 38170c90e4aSIan Rogers 382*81a4e31fSIan Rogers err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list, &@1); 383b30d4f0bSIan Rogers if (err < 0) { 384b30d4f0bSIan Rogers struct parse_events_state *parse_state = _parse_state; 385b30d4f0bSIan Rogers struct parse_events_error *error = parse_state->error; 386b30d4f0bSIan Rogers char *help; 387b30d4f0bSIan Rogers 388b30d4f0bSIan Rogers if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0) 389b30d4f0bSIan Rogers help = NULL; 390b30d4f0bSIan Rogers parse_events_error__handle(error, @1.first_column, strdup("Bad event name"), help); 39170c90e4aSIan Rogers free($1); 392b52cb995SIan Rogers PE_ABORT(err); 393b30d4f0bSIan Rogers } 394b30d4f0bSIan Rogers free($1); 39570c90e4aSIan Rogers $$ = list; 39670c90e4aSIan Rogers } 3975f537a26SJiri Olsa 398cf3506dcSJiri Olsa value_sym: 399cf3506dcSJiri Olsa PE_VALUE_SYM_HW 400cf3506dcSJiri Olsa | 401cf3506dcSJiri Olsa PE_VALUE_SYM_SW 402cf3506dcSJiri Olsa 40389812fc8SJiri Olsa event_legacy_symbol: 404cf3506dcSJiri Olsa value_sym '/' event_config '/' 40589812fc8SJiri Olsa { 406c5cd8ac0SDavid Ahern struct list_head *list; 40789812fc8SJiri Olsa int type = $1 >> 16; 40889812fc8SJiri Olsa int config = $1 & 255; 409cabbf268SIan Rogers int err; 410251aa040SIan Rogers bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); 41189812fc8SJiri Olsa 412a26e4716SIan Rogers list = alloc_list(); 41377cdd787SIan Rogers if (!list) 41477cdd787SIan Rogers YYNOMEM; 415251aa040SIan Rogers err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard); 4162146afc6SArnaldo Carvalho de Melo parse_events_terms__delete($3); 417cabbf268SIan Rogers if (err) { 418cabbf268SIan Rogers free_list_evsel(list); 419b52cb995SIan Rogers PE_ABORT(err); 420cabbf268SIan Rogers } 421b847cbdcSJiri Olsa $$ = list; 4228f707d84SJiri Olsa } 4238f707d84SJiri Olsa | 424714a92d8SJiri Olsa value_sym sep_slash_slash_dc 4258f707d84SJiri Olsa { 426c5cd8ac0SDavid Ahern struct list_head *list; 4278f707d84SJiri Olsa int type = $1 >> 16; 4288f707d84SJiri Olsa int config = $1 & 255; 429251aa040SIan Rogers bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); 430b52cb995SIan Rogers int err; 4318f707d84SJiri Olsa 432a26e4716SIan Rogers list = alloc_list(); 43377cdd787SIan Rogers if (!list) 43477cdd787SIan Rogers YYNOMEM; 435b52cb995SIan Rogers err = parse_events_add_numeric(_parse_state, list, type, config, /*head_config=*/NULL, wildcard); 436b52cb995SIan Rogers if (err) 437b52cb995SIan Rogers PE_ABORT(err); 438b847cbdcSJiri Olsa $$ = list; 43989812fc8SJiri Olsa } 440f0fbb114SAndi Kleen | 441f0fbb114SAndi Kleen PE_VALUE_SYM_TOOL sep_slash_slash_dc 442f0fbb114SAndi Kleen { 443f0fbb114SAndi Kleen struct list_head *list; 444b52cb995SIan Rogers int err; 445f0fbb114SAndi Kleen 446a26e4716SIan Rogers list = alloc_list(); 44777cdd787SIan Rogers if (!list) 44877cdd787SIan Rogers YYNOMEM; 449b52cb995SIan Rogers err = parse_events_add_tool(_parse_state, list, $1); 450b52cb995SIan Rogers if (err) 451b52cb995SIan Rogers YYNOMEM; 452f0fbb114SAndi Kleen $$ = list; 453f0fbb114SAndi Kleen } 45489812fc8SJiri Olsa 45589812fc8SJiri Olsa event_legacy_cache: 45670c90e4aSIan Rogers PE_LEGACY_CACHE opt_event_config 45789812fc8SJiri Olsa { 4585d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 459c5cd8ac0SDavid Ahern struct list_head *list; 460cabbf268SIan Rogers int err; 461b847cbdcSJiri Olsa 462a26e4716SIan Rogers list = alloc_list(); 46377cdd787SIan Rogers if (!list) 46477cdd787SIan Rogers YYNOMEM; 46577cdd787SIan Rogers 466411ad22eSIan Rogers err = parse_events_add_cache(list, &parse_state->idx, $1, parse_state, $2); 467b847cbdcSJiri Olsa 46843d0b978SWang Nan parse_events_terms__delete($2); 469cabbf268SIan Rogers free($1); 470cabbf268SIan Rogers if (err) { 471cabbf268SIan Rogers free_list_evsel(list); 472b52cb995SIan Rogers PE_ABORT(err); 473cabbf268SIan Rogers } 474b847cbdcSJiri Olsa $$ = list; 47589812fc8SJiri Olsa } 47689812fc8SJiri Olsa 47789812fc8SJiri Olsa event_legacy_mem: 478f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config 4793741eb9fSJacob Shin { 4803741eb9fSJacob Shin struct list_head *list; 481cabbf268SIan Rogers int err; 4823741eb9fSJacob Shin 483a26e4716SIan Rogers list = alloc_list(); 48477cdd787SIan Rogers if (!list) 48577cdd787SIan Rogers YYNOMEM; 48677cdd787SIan Rogers 487f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 488f0617f52SAdrian Hunter $2, $6, $4, $7); 489f0617f52SAdrian Hunter parse_events_terms__delete($7); 490cabbf268SIan Rogers free($6); 491cabbf268SIan Rogers if (err) { 492cabbf268SIan Rogers free(list); 493b52cb995SIan Rogers PE_ABORT(err); 494cabbf268SIan Rogers } 4953741eb9fSJacob Shin $$ = list; 4963741eb9fSJacob Shin } 4973741eb9fSJacob Shin | 498f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE opt_event_config 4993741eb9fSJacob Shin { 5003741eb9fSJacob Shin struct list_head *list; 501f0617f52SAdrian Hunter int err; 502f0617f52SAdrian Hunter 503a26e4716SIan Rogers list = alloc_list(); 50477cdd787SIan Rogers if (!list) 50577cdd787SIan Rogers YYNOMEM; 50677cdd787SIan Rogers 507f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 508f0617f52SAdrian Hunter $2, NULL, $4, $5); 509f0617f52SAdrian Hunter parse_events_terms__delete($5); 510f0617f52SAdrian Hunter if (err) { 511cabbf268SIan Rogers free(list); 512b52cb995SIan Rogers PE_ABORT(err); 513cabbf268SIan Rogers } 5143741eb9fSJacob Shin $$ = list; 5153741eb9fSJacob Shin } 5163741eb9fSJacob Shin | 517f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config 51889812fc8SJiri Olsa { 519c5cd8ac0SDavid Ahern struct list_head *list; 520cabbf268SIan Rogers int err; 521b847cbdcSJiri Olsa 522a26e4716SIan Rogers list = alloc_list(); 52377cdd787SIan Rogers if (!list) 52477cdd787SIan Rogers YYNOMEM; 52577cdd787SIan Rogers 526f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 527f0617f52SAdrian Hunter $2, $4, 0, $5); 528f0617f52SAdrian Hunter parse_events_terms__delete($5); 529cabbf268SIan Rogers free($4); 530cabbf268SIan Rogers if (err) { 531cabbf268SIan Rogers free(list); 532b52cb995SIan Rogers PE_ABORT(err); 533cabbf268SIan Rogers } 534b847cbdcSJiri Olsa $$ = list; 53589812fc8SJiri Olsa } 53689812fc8SJiri Olsa | 537f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE opt_event_config 53889812fc8SJiri Olsa { 539c5cd8ac0SDavid Ahern struct list_head *list; 540f0617f52SAdrian Hunter int err; 541b847cbdcSJiri Olsa 542a26e4716SIan Rogers list = alloc_list(); 54377cdd787SIan Rogers if (!list) 54477cdd787SIan Rogers YYNOMEM; 545f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 546f0617f52SAdrian Hunter $2, NULL, 0, $3); 547f0617f52SAdrian Hunter parse_events_terms__delete($3); 548f0617f52SAdrian Hunter if (err) { 549cabbf268SIan Rogers free(list); 550b52cb995SIan Rogers PE_ABORT(err); 551cabbf268SIan Rogers } 552b847cbdcSJiri Olsa $$ = list; 55389812fc8SJiri Olsa } 55489812fc8SJiri Olsa 55589812fc8SJiri Olsa event_legacy_tracepoint: 5561d55e8efSArnaldo Carvalho de Melo tracepoint_name opt_event_config 5572b9032e0SAlexander Yarygin { 5585d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 5595d9cdc11SArnaldo Carvalho de Melo struct parse_events_error *error = parse_state->error; 5602b9032e0SAlexander Yarygin struct list_head *list; 561cabbf268SIan Rogers int err; 5622b9032e0SAlexander Yarygin 563a26e4716SIan Rogers list = alloc_list(); 56477cdd787SIan Rogers if (!list) 56577cdd787SIan Rogers YYNOMEM; 56619658171SJiri Olsa if (error) 56719658171SJiri Olsa error->idx = @1.first_column; 568e637d177SHe Kuang 569cabbf268SIan Rogers err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, 570d81fa63bSIan Rogers error, $2, &@1); 571e637d177SHe Kuang 572cabbf268SIan Rogers parse_events_terms__delete($2); 573cabbf268SIan Rogers free($1.sys); 574cabbf268SIan Rogers free($1.event); 575cabbf268SIan Rogers if (err) { 576cabbf268SIan Rogers free(list); 577b52cb995SIan Rogers PE_ABORT(err); 578cabbf268SIan Rogers } 5792b9032e0SAlexander Yarygin $$ = list; 5802b9032e0SAlexander Yarygin } 581865582c3SHe Kuang 582865582c3SHe Kuang tracepoint_name: 58389812fc8SJiri Olsa PE_NAME ':' PE_NAME 58489812fc8SJiri Olsa { 585865582c3SHe Kuang struct tracepoint_name tracepoint = {$1, $3}; 586b847cbdcSJiri Olsa 587865582c3SHe Kuang $$ = tracepoint; 58889812fc8SJiri Olsa } 58989812fc8SJiri Olsa 59089812fc8SJiri Olsa event_legacy_numeric: 59110bf358aSWang Nan PE_VALUE ':' PE_VALUE opt_event_config 59289812fc8SJiri Olsa { 593c5cd8ac0SDavid Ahern struct list_head *list; 594cabbf268SIan Rogers int err; 595b847cbdcSJiri Olsa 596a26e4716SIan Rogers list = alloc_list(); 59777cdd787SIan Rogers if (!list) 59877cdd787SIan Rogers YYNOMEM; 5998bc75f69SIan Rogers err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4, 6008bc75f69SIan Rogers /*wildcard=*/false); 60110bf358aSWang Nan parse_events_terms__delete($4); 602cabbf268SIan Rogers if (err) { 603cabbf268SIan Rogers free(list); 604b52cb995SIan Rogers PE_ABORT(err); 605cabbf268SIan Rogers } 606b847cbdcSJiri Olsa $$ = list; 60789812fc8SJiri Olsa } 60889812fc8SJiri Olsa 60989812fc8SJiri Olsa event_legacy_raw: 61010bf358aSWang Nan PE_RAW opt_event_config 61189812fc8SJiri Olsa { 612c5cd8ac0SDavid Ahern struct list_head *list; 613cabbf268SIan Rogers int err; 61470c90e4aSIan Rogers u64 num; 615b847cbdcSJiri Olsa 616a26e4716SIan Rogers list = alloc_list(); 61777cdd787SIan Rogers if (!list) 61877cdd787SIan Rogers YYNOMEM; 61970c90e4aSIan Rogers errno = 0; 62070c90e4aSIan Rogers num = strtoull($1 + 1, NULL, 16); 62170c90e4aSIan Rogers ABORT_ON(errno); 62270c90e4aSIan Rogers free($1); 6238bc75f69SIan Rogers err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, 624251aa040SIan Rogers /*wildcard=*/false); 62510bf358aSWang Nan parse_events_terms__delete($2); 626cabbf268SIan Rogers if (err) { 627cabbf268SIan Rogers free(list); 628b52cb995SIan Rogers PE_ABORT(err); 629cabbf268SIan Rogers } 630b847cbdcSJiri Olsa $$ = list; 6318f707d84SJiri Olsa } 6328f707d84SJiri Olsa 63384c86ca1SWang Nan event_bpf_file: 634a34f3be7SWang Nan PE_BPF_OBJECT opt_event_config 63584c86ca1SWang Nan { 6365d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 63784c86ca1SWang Nan struct list_head *list; 638cabbf268SIan Rogers int err; 63984c86ca1SWang Nan 640a26e4716SIan Rogers list = alloc_list(); 64177cdd787SIan Rogers if (!list) 64277cdd787SIan Rogers YYNOMEM; 643d81fa63bSIan Rogers err = parse_events_load_bpf(parse_state, list, $1, false, $2, &@1); 644a34f3be7SWang Nan parse_events_terms__delete($2); 645cabbf268SIan Rogers free($1); 646cabbf268SIan Rogers if (err) { 647cabbf268SIan Rogers free(list); 648b52cb995SIan Rogers PE_ABORT(err); 649cabbf268SIan Rogers } 650d509db04SWang Nan $$ = list; 651d509db04SWang Nan } 652d509db04SWang Nan | 653a34f3be7SWang Nan PE_BPF_SOURCE opt_event_config 654d509db04SWang Nan { 655d509db04SWang Nan struct list_head *list; 656cabbf268SIan Rogers int err; 657d509db04SWang Nan 658a26e4716SIan Rogers list = alloc_list(); 65977cdd787SIan Rogers if (!list) 66077cdd787SIan Rogers YYNOMEM; 661d81fa63bSIan Rogers err = parse_events_load_bpf(_parse_state, list, $1, true, $2, &@1); 662a34f3be7SWang Nan parse_events_terms__delete($2); 663cabbf268SIan Rogers if (err) { 664cabbf268SIan Rogers free(list); 665b52cb995SIan Rogers PE_ABORT(err); 666cabbf268SIan Rogers } 66784c86ca1SWang Nan $$ = list; 66884c86ca1SWang Nan } 66984c86ca1SWang Nan 6701d55e8efSArnaldo Carvalho de Melo opt_event_config: 6711d55e8efSArnaldo Carvalho de Melo '/' event_config '/' 6721d55e8efSArnaldo Carvalho de Melo { 6731d55e8efSArnaldo Carvalho de Melo $$ = $2; 6741d55e8efSArnaldo Carvalho de Melo } 6751d55e8efSArnaldo Carvalho de Melo | 6761d55e8efSArnaldo Carvalho de Melo '/' '/' 6771d55e8efSArnaldo Carvalho de Melo { 6781d55e8efSArnaldo Carvalho de Melo $$ = NULL; 6791d55e8efSArnaldo Carvalho de Melo } 6801d55e8efSArnaldo Carvalho de Melo | 6811d55e8efSArnaldo Carvalho de Melo { 6821d55e8efSArnaldo Carvalho de Melo $$ = NULL; 6831d55e8efSArnaldo Carvalho de Melo } 6841d55e8efSArnaldo Carvalho de Melo 685ceac7b79SJiri Olsa opt_pmu_config: 686ceac7b79SJiri Olsa '/' event_config '/' 687ceac7b79SJiri Olsa { 688ceac7b79SJiri Olsa $$ = $2; 689ceac7b79SJiri Olsa } 690ceac7b79SJiri Olsa | 691ceac7b79SJiri Olsa '/' '/' 692ceac7b79SJiri Olsa { 693ceac7b79SJiri Olsa $$ = NULL; 694ceac7b79SJiri Olsa } 695ceac7b79SJiri Olsa 69689efb029SJiri Olsa start_terms: event_config 69790e2b22dSJiri Olsa { 6985d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 699cabbf268SIan Rogers if (parse_state->terms) { 700cabbf268SIan Rogers parse_events_terms__delete ($1); 701cabbf268SIan Rogers YYABORT; 702cabbf268SIan Rogers } 7035d9cdc11SArnaldo Carvalho de Melo parse_state->terms = $1; 70490e2b22dSJiri Olsa } 70590e2b22dSJiri Olsa 7068f707d84SJiri Olsa event_config: 7078f707d84SJiri Olsa event_config ',' event_term 7088f707d84SJiri Olsa { 7098f707d84SJiri Olsa struct list_head *head = $1; 7106cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term = $3; 7118f707d84SJiri Olsa 712cabbf268SIan Rogers if (!head) { 7131dc92556SIan Rogers parse_events_term__delete(term); 714cabbf268SIan Rogers YYABORT; 715cabbf268SIan Rogers } 7168f707d84SJiri Olsa list_add_tail(&term->list, head); 7178f707d84SJiri Olsa $$ = $1; 7188f707d84SJiri Olsa } 7198f707d84SJiri Olsa | 7208f707d84SJiri Olsa event_term 7218f707d84SJiri Olsa { 7228f707d84SJiri Olsa struct list_head *head = malloc(sizeof(*head)); 7236cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term = $1; 7248f707d84SJiri Olsa 72577cdd787SIan Rogers if (!head) 72677cdd787SIan Rogers YYNOMEM; 7278f707d84SJiri Olsa INIT_LIST_HEAD(head); 7288f707d84SJiri Olsa list_add_tail(&term->list, head); 7298f707d84SJiri Olsa $$ = head; 7308f707d84SJiri Olsa } 7318f707d84SJiri Olsa 7326fd1e519SIan Rogers name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACHE 73370c90e4aSIan Rogers 7342aadca4bSIan Rogers name_or_legacy: PE_NAME | PE_LEGACY_CACHE 7352aadca4bSIan Rogers 7368f707d84SJiri Olsa event_term: 7373a6c51e4SJiri Olsa PE_RAW 7383a6c51e4SJiri Olsa { 7393a6c51e4SJiri Olsa struct parse_events_term *term; 740b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_RAW, 741b52cb995SIan Rogers strdup("raw"), $1, &@1, &@1); 7423a6c51e4SJiri Olsa 743b52cb995SIan Rogers if (err) { 74470c90e4aSIan Rogers free($1); 745b52cb995SIan Rogers PE_ABORT(err); 74670c90e4aSIan Rogers } 7473a6c51e4SJiri Olsa $$ = term; 7483a6c51e4SJiri Olsa } 7493a6c51e4SJiri Olsa | 7502aadca4bSIan Rogers name_or_raw '=' name_or_legacy 7518f707d84SJiri Olsa { 7526cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 753b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $3, &@1, &@3); 7548f707d84SJiri Olsa 755b52cb995SIan Rogers if (err) { 756cabbf268SIan Rogers free($1); 757cabbf268SIan Rogers free($3); 758b52cb995SIan Rogers PE_ABORT(err); 759cabbf268SIan Rogers } 7608f707d84SJiri Olsa $$ = term; 7618f707d84SJiri Olsa } 7628f707d84SJiri Olsa | 76370c90e4aSIan Rogers name_or_raw '=' PE_VALUE 7648f707d84SJiri Olsa { 7656cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 766b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 767b52cb995SIan Rogers $1, $3, false, &@1, &@3); 7688f707d84SJiri Olsa 769b52cb995SIan Rogers if (err) { 770cabbf268SIan Rogers free($1); 771b52cb995SIan Rogers PE_ABORT(err); 772cabbf268SIan Rogers } 7738f707d84SJiri Olsa $$ = term; 7748f707d84SJiri Olsa } 7758f707d84SJiri Olsa | 7765ea8f2ccSIan Rogers name_or_raw '=' PE_TERM_HW 7771d33d6dcSJiri Olsa { 7786cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 779b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 780b52cb995SIan Rogers $1, $3.str, &@1, &@3); 7811d33d6dcSJiri Olsa 782b52cb995SIan Rogers if (err) { 783cabbf268SIan Rogers free($1); 7845ea8f2ccSIan Rogers free($3.str); 785b52cb995SIan Rogers PE_ABORT(err); 786cabbf268SIan Rogers } 7871d33d6dcSJiri Olsa $$ = term; 7881d33d6dcSJiri Olsa } 7891d33d6dcSJiri Olsa | 7906fd1e519SIan Rogers PE_LEGACY_CACHE 7916fd1e519SIan Rogers { 7926fd1e519SIan Rogers struct parse_events_term *term; 793b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE, 794b52cb995SIan Rogers $1, 1, true, &@1, NULL); 7956fd1e519SIan Rogers 796b52cb995SIan Rogers if (err) { 7976fd1e519SIan Rogers free($1); 798b52cb995SIan Rogers PE_ABORT(err); 7996fd1e519SIan Rogers } 8006fd1e519SIan Rogers $$ = term; 8016fd1e519SIan Rogers } 8026fd1e519SIan Rogers | 8038f707d84SJiri Olsa PE_NAME 8048f707d84SJiri Olsa { 8056cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 806b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 807b52cb995SIan Rogers $1, 1, true, &@1, NULL); 8088f707d84SJiri Olsa 809b52cb995SIan Rogers if (err) { 810cabbf268SIan Rogers free($1); 811b52cb995SIan Rogers PE_ABORT(err); 812cabbf268SIan Rogers } 8138f707d84SJiri Olsa $$ = term; 8148f707d84SJiri Olsa } 8158f707d84SJiri Olsa | 8165ea8f2ccSIan Rogers PE_TERM_HW 8171d33d6dcSJiri Olsa { 8186cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 819b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_HARDWARE, 820b52cb995SIan Rogers $1.str, $1.num & 255, false, &@1, NULL); 8211d33d6dcSJiri Olsa 822b52cb995SIan Rogers if (err) { 8235ea8f2ccSIan Rogers free($1.str); 824b52cb995SIan Rogers PE_ABORT(err); 8255ea8f2ccSIan Rogers } 8261d33d6dcSJiri Olsa $$ = term; 8271d33d6dcSJiri Olsa } 8281d33d6dcSJiri Olsa | 8292aadca4bSIan Rogers PE_TERM '=' name_or_legacy 8306b5fc39bSJiri Olsa { 8316cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 832b52cb995SIan Rogers int err = parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3); 8336b5fc39bSJiri Olsa 834b52cb995SIan Rogers if (err) { 835cabbf268SIan Rogers free($3); 836b52cb995SIan Rogers PE_ABORT(err); 837cabbf268SIan Rogers } 8386b5fc39bSJiri Olsa $$ = term; 8396b5fc39bSJiri Olsa } 8406b5fc39bSJiri Olsa | 8415ea8f2ccSIan Rogers PE_TERM '=' PE_TERM_HW 8425ea8f2ccSIan Rogers { 8435ea8f2ccSIan Rogers struct parse_events_term *term; 844b52cb995SIan Rogers int err = parse_events_term__str(&term, (int)$1, NULL, $3.str, &@1, &@3); 8455ea8f2ccSIan Rogers 846b52cb995SIan Rogers if (err) { 8475ea8f2ccSIan Rogers free($3.str); 848b52cb995SIan Rogers PE_ABORT(err); 8495ea8f2ccSIan Rogers } 8505ea8f2ccSIan Rogers $$ = term; 8515ea8f2ccSIan Rogers } 8525ea8f2ccSIan Rogers | 853e831f3ccSIan Rogers PE_TERM '=' PE_TERM 854e831f3ccSIan Rogers { 855e831f3ccSIan Rogers struct parse_events_term *term; 856b52cb995SIan Rogers int err = parse_events_term__term(&term, (int)$1, (int)$3, &@1, &@3); 857e831f3ccSIan Rogers 858b52cb995SIan Rogers if (err) 859b52cb995SIan Rogers PE_ABORT(err); 860b52cb995SIan Rogers 861e831f3ccSIan Rogers $$ = term; 862e831f3ccSIan Rogers } 863e831f3ccSIan Rogers | 8648f707d84SJiri Olsa PE_TERM '=' PE_VALUE 8658f707d84SJiri Olsa { 8666cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 867b52cb995SIan Rogers int err = parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3); 8688f707d84SJiri Olsa 869b52cb995SIan Rogers if (err) 870b52cb995SIan Rogers PE_ABORT(err); 871b52cb995SIan Rogers 8728f707d84SJiri Olsa $$ = term; 8738f707d84SJiri Olsa } 8748f707d84SJiri Olsa | 8758f707d84SJiri Olsa PE_TERM 8768f707d84SJiri Olsa { 8776cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 878b52cb995SIan Rogers int err = parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL); 8798f707d84SJiri Olsa 880b52cb995SIan Rogers if (err) 881b52cb995SIan Rogers PE_ABORT(err); 882b52cb995SIan Rogers 8838f707d84SJiri Olsa $$ = term; 88489812fc8SJiri Olsa } 885e571e029SWang Nan | 8862aadca4bSIan Rogers name_or_raw array '=' name_or_legacy 887e571e029SWang Nan { 888e571e029SWang Nan struct parse_events_term *term; 889b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, &@1, &@4); 890e571e029SWang Nan 891b52cb995SIan Rogers if (err) { 892cabbf268SIan Rogers free($1); 893cabbf268SIan Rogers free($4); 894cabbf268SIan Rogers free($2.ranges); 895b52cb995SIan Rogers PE_ABORT(err); 896cabbf268SIan Rogers } 897e571e029SWang Nan term->array = $2; 898e571e029SWang Nan $$ = term; 899e571e029SWang Nan } 900e571e029SWang Nan | 90170c90e4aSIan Rogers name_or_raw array '=' PE_VALUE 902e571e029SWang Nan { 903e571e029SWang Nan struct parse_events_term *term; 904b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, false, &@1, &@4); 905e571e029SWang Nan 906b52cb995SIan Rogers if (err) { 907cabbf268SIan Rogers free($1); 908cabbf268SIan Rogers free($2.ranges); 909b52cb995SIan Rogers PE_ABORT(err); 910cabbf268SIan Rogers } 911e571e029SWang Nan term->array = $2; 912e571e029SWang Nan $$ = term; 913e571e029SWang Nan } 914dd60fba7SMathieu Poirier | 915dd60fba7SMathieu Poirier PE_DRV_CFG_TERM 916dd60fba7SMathieu Poirier { 917dd60fba7SMathieu Poirier struct parse_events_term *term; 918b6645a72SIan Rogers char *config = strdup($1); 919b52cb995SIan Rogers int err; 920dd60fba7SMathieu Poirier 92177cdd787SIan Rogers if (!config) 92277cdd787SIan Rogers YYNOMEM; 923b52cb995SIan Rogers err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, config, $1, &@1, NULL); 924b52cb995SIan Rogers if (err) { 925cabbf268SIan Rogers free($1); 926cabbf268SIan Rogers free(config); 927b52cb995SIan Rogers PE_ABORT(err); 928cabbf268SIan Rogers } 929dd60fba7SMathieu Poirier $$ = term; 930dd60fba7SMathieu Poirier } 931e571e029SWang Nan 932e571e029SWang Nan array: 933e571e029SWang Nan '[' array_terms ']' 934e571e029SWang Nan { 935e571e029SWang Nan $$ = $2; 936e571e029SWang Nan } 937e571e029SWang Nan | 938e571e029SWang Nan PE_ARRAY_ALL 939e571e029SWang Nan { 940e571e029SWang Nan $$.nr_ranges = 0; 941e571e029SWang Nan $$.ranges = NULL; 942e571e029SWang Nan } 943e571e029SWang Nan 944e571e029SWang Nan array_terms: 945e571e029SWang Nan array_terms ',' array_term 946e571e029SWang Nan { 947e571e029SWang Nan struct parse_events_array new_array; 948e571e029SWang Nan 949e571e029SWang Nan new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; 950826100a7SIan Rogers new_array.ranges = realloc($1.ranges, 951826100a7SIan Rogers sizeof(new_array.ranges[0]) * 952e571e029SWang Nan new_array.nr_ranges); 95377cdd787SIan Rogers if (!new_array.ranges) 95477cdd787SIan Rogers YYNOMEM; 955e571e029SWang Nan memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, 956e571e029SWang Nan $3.nr_ranges * sizeof(new_array.ranges[0])); 957e571e029SWang Nan free($3.ranges); 958e571e029SWang Nan $$ = new_array; 959e571e029SWang Nan } 960e571e029SWang Nan | 961e571e029SWang Nan array_term 962e571e029SWang Nan 963e571e029SWang Nan array_term: 964e571e029SWang Nan PE_VALUE 965e571e029SWang Nan { 966e571e029SWang Nan struct parse_events_array array; 967e571e029SWang Nan 968e571e029SWang Nan array.nr_ranges = 1; 969e571e029SWang Nan array.ranges = malloc(sizeof(array.ranges[0])); 97077cdd787SIan Rogers if (!array.ranges) 97177cdd787SIan Rogers YYNOMEM; 972e571e029SWang Nan array.ranges[0].start = $1; 973e571e029SWang Nan array.ranges[0].length = 1; 974e571e029SWang Nan $$ = array; 975e571e029SWang Nan } 976e571e029SWang Nan | 977e571e029SWang Nan PE_VALUE PE_ARRAY_RANGE PE_VALUE 978e571e029SWang Nan { 979e571e029SWang Nan struct parse_events_array array; 980e571e029SWang Nan 981e571e029SWang Nan ABORT_ON($3 < $1); 982e571e029SWang Nan array.nr_ranges = 1; 983e571e029SWang Nan array.ranges = malloc(sizeof(array.ranges[0])); 98477cdd787SIan Rogers if (!array.ranges) 98577cdd787SIan Rogers YYNOMEM; 986e571e029SWang Nan array.ranges[0].start = $1; 987e571e029SWang Nan array.ranges[0].length = $3 - $1 + 1; 988e571e029SWang Nan $$ = array; 989e571e029SWang Nan } 99089812fc8SJiri Olsa 99189812fc8SJiri Olsa sep_dc: ':' | 99289812fc8SJiri Olsa 993714a92d8SJiri Olsa sep_slash_slash_dc: '/' '/' | ':' | 9948f707d84SJiri Olsa 99589812fc8SJiri Olsa %% 99689812fc8SJiri Olsa 9975d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state, 9986297d423SJiri Olsa void *scanner __maybe_unused, 9991d037ca1SIrina Tirdea char const *msg __maybe_unused) 100089812fc8SJiri Olsa { 10015d9cdc11SArnaldo Carvalho de Melo parse_events_evlist_error(parse_state, loc->last_column, "parser error"); 100289812fc8SJiri Olsa } 1003