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 23*ddc8e4c9SIan Rogers int parse_events_lex(YYSTYPE * yylval_param, YYLTYPE * yylloc_param , void *yyscanner); 245d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); 2534a0548fSArnaldo Carvalho de Melo 26b52cb995SIan Rogers #define PE_ABORT(val) \ 27b52cb995SIan Rogers do { \ 28b52cb995SIan Rogers if (val == -ENOMEM) \ 29b52cb995SIan Rogers YYNOMEM; \ 30b52cb995SIan Rogers YYABORT; \ 31b52cb995SIan Rogers } while (0) 32b52cb995SIan Rogers 33ffaecd7dSIan Rogers static struct list_head* alloc_list(void) 34a26e4716SIan Rogers { 35a26e4716SIan Rogers struct list_head *list; 36a26e4716SIan Rogers 37a26e4716SIan Rogers list = malloc(sizeof(*list)); 38a26e4716SIan Rogers if (!list) 39a26e4716SIan Rogers return NULL; 40a26e4716SIan Rogers 41a26e4716SIan Rogers INIT_LIST_HEAD(list); 42a26e4716SIan Rogers return list; 43a26e4716SIan Rogers } 44c5cd8ac0SDavid Ahern 45f2a8ecd8SIan Rogers static void free_list_evsel(struct list_head* list_evsel) 46f2a8ecd8SIan Rogers { 47f2a8ecd8SIan Rogers struct evsel *evsel, *tmp; 48f2a8ecd8SIan Rogers 49f2a8ecd8SIan Rogers list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) { 50f2a8ecd8SIan Rogers list_del_init(&evsel->core.node); 51672f707eSIan Rogers evsel__delete(evsel); 52f2a8ecd8SIan Rogers } 53f2a8ecd8SIan Rogers free(list_evsel); 54f2a8ecd8SIan Rogers } 55f2a8ecd8SIan Rogers 5689812fc8SJiri Olsa %} 5789812fc8SJiri Olsa 5890e2b22dSJiri Olsa %token PE_START_EVENTS PE_START_TERMS 5970c90e4aSIan Rogers %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_TERM 60f0fbb114SAndi Kleen %token PE_VALUE_SYM_TOOL 61ac2ba9f3SRobert Richter %token PE_EVENT_NAME 6270c90e4aSIan Rogers %token PE_RAW PE_NAME 63d509db04SWang Nan %token PE_BPF_OBJECT PE_BPF_SOURCE 64f0617f52SAdrian Hunter %token PE_MODIFIER_EVENT PE_MODIFIER_BP PE_BP_COLON PE_BP_SLASH 6570c90e4aSIan Rogers %token PE_LEGACY_CACHE 667e34daa5SIan Rogers %token PE_PREFIX_MEM 6789812fc8SJiri Olsa %token PE_ERROR 68e571e029SWang Nan %token PE_ARRAY_ALL PE_ARRAY_RANGE 69dd60fba7SMathieu Poirier %token PE_DRV_CFG_TERM 705ea8f2ccSIan Rogers %token PE_TERM_HW 7189812fc8SJiri Olsa %type <num> PE_VALUE 72cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_HW 73cf3506dcSJiri Olsa %type <num> PE_VALUE_SYM_SW 74f0fbb114SAndi Kleen %type <num> PE_VALUE_SYM_TOOL 758f707d84SJiri Olsa %type <num> PE_TERM 76f2a8ecd8SIan Rogers %type <num> value_sym 7770c90e4aSIan Rogers %type <str> PE_RAW 7889812fc8SJiri Olsa %type <str> PE_NAME 7984c86ca1SWang Nan %type <str> PE_BPF_OBJECT 80d509db04SWang Nan %type <str> PE_BPF_SOURCE 8170c90e4aSIan Rogers %type <str> PE_LEGACY_CACHE 8289812fc8SJiri Olsa %type <str> PE_MODIFIER_EVENT 8389812fc8SJiri Olsa %type <str> PE_MODIFIER_BP 84ac2ba9f3SRobert Richter %type <str> PE_EVENT_NAME 85dd60fba7SMathieu Poirier %type <str> PE_DRV_CFG_TERM 862aadca4bSIan Rogers %type <str> name_or_raw name_or_legacy 87f2a8ecd8SIan Rogers %destructor { free ($$); } <str> 888f707d84SJiri Olsa %type <term> event_term 891dc92556SIan Rogers %destructor { parse_events_term__delete ($$); } <term> 90f2a8ecd8SIan Rogers %type <list_terms> event_config 91f2a8ecd8SIan Rogers %type <list_terms> opt_event_config 92f2a8ecd8SIan Rogers %type <list_terms> opt_pmu_config 93f2a8ecd8SIan Rogers %destructor { parse_events_terms__delete ($$); } <list_terms> 94f2a8ecd8SIan Rogers %type <list_evsel> event_pmu 95f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_symbol 96f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_cache 97f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_mem 98f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_tracepoint 99f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_numeric 100f2a8ecd8SIan Rogers %type <list_evsel> event_legacy_raw 101f2a8ecd8SIan Rogers %type <list_evsel> event_bpf_file 102f2a8ecd8SIan Rogers %type <list_evsel> event_def 103f2a8ecd8SIan Rogers %type <list_evsel> event_mod 104f2a8ecd8SIan Rogers %type <list_evsel> event_name 105f2a8ecd8SIan Rogers %type <list_evsel> event 106f2a8ecd8SIan Rogers %type <list_evsel> events 107f2a8ecd8SIan Rogers %type <list_evsel> group_def 108f2a8ecd8SIan Rogers %type <list_evsel> group 109f2a8ecd8SIan Rogers %type <list_evsel> groups 110f2a8ecd8SIan Rogers %destructor { free_list_evsel ($$); } <list_evsel> 111865582c3SHe Kuang %type <tracepoint_name> tracepoint_name 112f2a8ecd8SIan Rogers %destructor { free ($$.sys); free ($$.event); } <tracepoint_name> 113e571e029SWang Nan %type <array> array 114e571e029SWang Nan %type <array> array_term 115e571e029SWang Nan %type <array> array_terms 116f2a8ecd8SIan Rogers %destructor { free ($$.ranges); } <array> 1175ea8f2ccSIan Rogers %type <hardware_term> PE_TERM_HW 1185ea8f2ccSIan Rogers %destructor { free ($$.str); } <hardware_term> 11989812fc8SJiri Olsa 12089812fc8SJiri Olsa %union 12189812fc8SJiri Olsa { 12289812fc8SJiri Olsa char *str; 123b527bab5SRobert Richter u64 num; 124f2a8ecd8SIan Rogers struct list_head *list_evsel; 125f2a8ecd8SIan Rogers struct list_head *list_terms; 1266cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 127865582c3SHe Kuang struct tracepoint_name { 128865582c3SHe Kuang char *sys; 129865582c3SHe Kuang char *event; 130865582c3SHe Kuang } tracepoint_name; 131e571e029SWang Nan struct parse_events_array array; 1325ea8f2ccSIan Rogers struct hardware_term { 1335ea8f2ccSIan Rogers char *str; 1345ea8f2ccSIan Rogers u64 num; 1355ea8f2ccSIan Rogers } hardware_term; 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) { 186eabd4523SIan Rogers struct parse_events_state *parse_state = _parse_state; 187eabd4523SIan Rogers struct parse_events_error *error = parse_state->error; 188eabd4523SIan Rogers 1896c191289SIan Rogers parse_events_error__handle(error, @3.first_column, 190eabd4523SIan 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 2044bb311b2SIan Rogers /* Takes ownership of $1. */ 205347c2f0aSIan Rogers parse_events__set_leader($1, list); 20689efb029SJiri Olsa $$ = list; 20789efb029SJiri Olsa } 20889efb029SJiri Olsa | 20989efb029SJiri Olsa '{' events '}' 21089efb029SJiri Olsa { 21189efb029SJiri Olsa struct list_head *list = $2; 21289efb029SJiri Olsa 213347c2f0aSIan Rogers parse_events__set_leader(NULL, list); 21489efb029SJiri Olsa $$ = list; 21589efb029SJiri Olsa } 21690e2b22dSJiri Olsa 21789812fc8SJiri Olsa events: 21889efb029SJiri Olsa events ',' event 21989efb029SJiri Olsa { 22089efb029SJiri Olsa struct list_head *event = $3; 22189efb029SJiri Olsa struct list_head *list = $1; 22289efb029SJiri Olsa 223cabbf268SIan Rogers /* frees $3 */ 22489efb029SJiri Olsa parse_events_update_lists(event, list); 22589efb029SJiri Olsa $$ = list; 22689efb029SJiri Olsa } 22789efb029SJiri Olsa | 22889efb029SJiri Olsa event 22989812fc8SJiri Olsa 230ac2ba9f3SRobert Richter event: event_mod 231ac2ba9f3SRobert Richter 232ac2ba9f3SRobert Richter event_mod: 233ac2ba9f3SRobert Richter event_name PE_MODIFIER_EVENT 23489812fc8SJiri Olsa { 23589efb029SJiri Olsa struct list_head *list = $1; 236cabbf268SIan Rogers int err; 23746010ab2SJiri Olsa 2385d7be90eSJiri Olsa /* 2395d7be90eSJiri Olsa * Apply modifier on all events added by single event definition 2405d7be90eSJiri Olsa * (there could be more events added for multiple tracepoint 2415d7be90eSJiri Olsa * definitions via '*?'. 2425d7be90eSJiri Olsa */ 243cabbf268SIan Rogers err = parse_events__modifier_event(list, $2, false); 244cabbf268SIan Rogers free($2); 245cabbf268SIan Rogers if (err) { 246eabd4523SIan Rogers struct parse_events_state *parse_state = _parse_state; 247eabd4523SIan Rogers struct parse_events_error *error = parse_state->error; 248eabd4523SIan Rogers 2496c191289SIan Rogers parse_events_error__handle(error, @2.first_column, 250eabd4523SIan Rogers strdup("Bad modifier"), NULL); 251cabbf268SIan Rogers free_list_evsel(list); 252cabbf268SIan Rogers YYABORT; 253cabbf268SIan Rogers } 25489efb029SJiri Olsa $$ = list; 25589812fc8SJiri Olsa } 25689812fc8SJiri Olsa | 257ac2ba9f3SRobert Richter event_name 258ac2ba9f3SRobert Richter 259ac2ba9f3SRobert Richter event_name: 260ac2ba9f3SRobert Richter PE_EVENT_NAME event_def 261ac2ba9f3SRobert Richter { 262cabbf268SIan Rogers int err; 263cabbf268SIan Rogers 264cabbf268SIan Rogers err = parse_events_name($2, $1); 265ac2ba9f3SRobert Richter free($1); 266cabbf268SIan Rogers if (err) { 267cabbf268SIan Rogers free_list_evsel($2); 2689462e4deSIan Rogers YYNOMEM; 269cabbf268SIan Rogers } 270ac2ba9f3SRobert Richter $$ = $2; 271ac2ba9f3SRobert Richter } 272ac2ba9f3SRobert Richter | 27389812fc8SJiri Olsa event_def 27489812fc8SJiri Olsa 2755f537a26SJiri Olsa event_def: event_pmu | 2765f537a26SJiri Olsa event_legacy_symbol | 27789812fc8SJiri Olsa event_legacy_cache sep_dc | 278f0617f52SAdrian Hunter event_legacy_mem sep_dc | 27989812fc8SJiri Olsa event_legacy_tracepoint sep_dc | 28089812fc8SJiri Olsa event_legacy_numeric sep_dc | 28184c86ca1SWang Nan event_legacy_raw sep_dc | 28284c86ca1SWang Nan event_bpf_file 28389812fc8SJiri Olsa 2845f537a26SJiri Olsa event_pmu: 28570c90e4aSIan Rogers PE_NAME opt_pmu_config 2865f537a26SJiri Olsa { 287f7fa827fSJiri Olsa struct parse_events_state *parse_state = _parse_state; 288cabbf268SIan Rogers struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL; 289cabbf268SIan Rogers char *pattern = NULL; 290cabbf268SIan Rogers 291a7a3252dSIan Rogers #define CLEANUP \ 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 } while(0) 2998255718fSAndi Kleen 300a7a3252dSIan Rogers if (parse_events_copy_term_list($2, &orig_terms)) { 301a7a3252dSIan Rogers CLEANUP; 302a7a3252dSIan Rogers YYNOMEM; 303a7a3252dSIan Rogers } 304a7a3252dSIan Rogers 305a26e4716SIan Rogers list = alloc_list(); 306a7a3252dSIan Rogers if (!list) { 307a7a3252dSIan Rogers CLEANUP; 308a7a3252dSIan Rogers YYNOMEM; 309a7a3252dSIan Rogers } 31070c90e4aSIan Rogers /* Attempt to add to list assuming $1 is a PMU name. */ 31181a4e31fSIan Rogers if (parse_events_add_pmu(parse_state, list, $1, $2, /*auto_merge_stats=*/false, &@1)) { 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. */ 316a7a3252dSIan Rogers if (asprintf(&pattern, "%s*", $1) < 0) { 317a7a3252dSIan Rogers CLEANUP; 318a7a3252dSIan Rogers YYNOMEM; 319a7a3252dSIan Rogers } 3208255718fSAndi Kleen 3211eaf496eSIan Rogers while ((pmu = perf_pmus__scan(pmu)) != NULL) { 3228255718fSAndi Kleen char *name = pmu->name; 3238255718fSAndi Kleen 324411ad22eSIan Rogers if (parse_events__filter_pmu(parse_state, pmu)) 325411ad22eSIan Rogers continue; 326411ad22eSIan Rogers 327a820e335SAndi Kleen if (!strncmp(name, "uncore_", 7) && 328a820e335SAndi Kleen strncmp($1, "uncore_", 7)) 329a820e335SAndi Kleen name += 7; 33013d60ba0SKan Liang if (!perf_pmu__match(pattern, name, $1) || 33113d60ba0SKan Liang !perf_pmu__match(pattern, pmu->alias_name, $1)) { 33252c7b4d3SIan Rogers bool auto_merge_stats = perf_pmu__auto_merge_stats(pmu); 33352c7b4d3SIan Rogers 334a7a3252dSIan Rogers if (parse_events_copy_term_list(orig_terms, &terms)) { 335a7a3252dSIan Rogers CLEANUP; 336a7a3252dSIan Rogers YYNOMEM; 337a7a3252dSIan Rogers } 33824d80818SIan Rogers if (!parse_events_add_pmu(parse_state, list, pmu->name, terms, 33981a4e31fSIan Rogers auto_merge_stats, &@1)) { 3408255718fSAndi Kleen ok++; 341a4c7d7c5SIan Rogers parse_state->wild_card_pmus = true; 342e733f87eSIan Rogers } 3438255718fSAndi Kleen parse_events_terms__delete(terms); 3448255718fSAndi Kleen } 3458255718fSAndi Kleen } 346b2b9d3a3SAgustin Vega-Frias 34770c90e4aSIan Rogers if (!ok) { 34870c90e4aSIan Rogers /* Failure to add, assume $1 is an event name. */ 34970c90e4aSIan Rogers zfree(&list); 35081a4e31fSIan Rogers ok = !parse_events_multi_pmu_add(parse_state, $1, $2, &list, &@1); 35170c90e4aSIan Rogers $2 = NULL; 35270c90e4aSIan Rogers } 353a7a3252dSIan Rogers if (!ok) { 354b30d4f0bSIan Rogers struct parse_events_error *error = parse_state->error; 355b30d4f0bSIan Rogers char *help; 356b30d4f0bSIan Rogers 357b30d4f0bSIan Rogers if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0) 358b30d4f0bSIan Rogers help = NULL; 359b30d4f0bSIan Rogers parse_events_error__handle(error, @1.first_column, 360b30d4f0bSIan Rogers strdup("Bad event or PMU"), 361b30d4f0bSIan Rogers help); 362a7a3252dSIan Rogers CLEANUP; 363a7a3252dSIan Rogers YYABORT; 3648255718fSAndi Kleen } 365a7a3252dSIan Rogers } 366b847cbdcSJiri Olsa $$ = list; 367a7a3252dSIan Rogers list = NULL; 368a7a3252dSIan Rogers CLEANUP; 369a7a3252dSIan Rogers #undef CLEANUP 3705f537a26SJiri Olsa } 371ad962273SAdrian Hunter | 37270c90e4aSIan Rogers PE_NAME sep_dc 37370c90e4aSIan Rogers { 37470c90e4aSIan Rogers struct list_head *list; 37570c90e4aSIan Rogers int err; 37670c90e4aSIan Rogers 37781a4e31fSIan Rogers err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list, &@1); 378b30d4f0bSIan Rogers if (err < 0) { 379b30d4f0bSIan Rogers struct parse_events_state *parse_state = _parse_state; 380b30d4f0bSIan Rogers struct parse_events_error *error = parse_state->error; 381b30d4f0bSIan Rogers char *help; 382b30d4f0bSIan Rogers 383b30d4f0bSIan Rogers if (asprintf(&help, "Unabled to find PMU or event on a PMU of '%s'", $1) < 0) 384b30d4f0bSIan Rogers help = NULL; 385b30d4f0bSIan Rogers parse_events_error__handle(error, @1.first_column, strdup("Bad event name"), help); 38670c90e4aSIan Rogers free($1); 387b52cb995SIan Rogers PE_ABORT(err); 388b30d4f0bSIan Rogers } 389b30d4f0bSIan Rogers free($1); 39070c90e4aSIan Rogers $$ = list; 39170c90e4aSIan Rogers } 3925f537a26SJiri Olsa 393cf3506dcSJiri Olsa value_sym: 394cf3506dcSJiri Olsa PE_VALUE_SYM_HW 395cf3506dcSJiri Olsa | 396cf3506dcSJiri Olsa PE_VALUE_SYM_SW 397cf3506dcSJiri Olsa 39889812fc8SJiri Olsa event_legacy_symbol: 399cf3506dcSJiri Olsa value_sym '/' event_config '/' 40089812fc8SJiri Olsa { 401c5cd8ac0SDavid Ahern struct list_head *list; 40289812fc8SJiri Olsa int type = $1 >> 16; 40389812fc8SJiri Olsa int config = $1 & 255; 404cabbf268SIan Rogers int err; 405251aa040SIan Rogers bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); 40689812fc8SJiri Olsa 407a26e4716SIan Rogers list = alloc_list(); 40877cdd787SIan Rogers if (!list) 40977cdd787SIan Rogers YYNOMEM; 410251aa040SIan Rogers err = parse_events_add_numeric(_parse_state, list, type, config, $3, wildcard); 4112146afc6SArnaldo Carvalho de Melo parse_events_terms__delete($3); 412cabbf268SIan Rogers if (err) { 413cabbf268SIan Rogers free_list_evsel(list); 414b52cb995SIan Rogers PE_ABORT(err); 415cabbf268SIan Rogers } 416b847cbdcSJiri Olsa $$ = list; 4178f707d84SJiri Olsa } 4188f707d84SJiri Olsa | 419714a92d8SJiri Olsa value_sym sep_slash_slash_dc 4208f707d84SJiri Olsa { 421c5cd8ac0SDavid Ahern struct list_head *list; 4228f707d84SJiri Olsa int type = $1 >> 16; 4238f707d84SJiri Olsa int config = $1 & 255; 424251aa040SIan Rogers bool wildcard = (type == PERF_TYPE_HARDWARE || type == PERF_TYPE_HW_CACHE); 425b52cb995SIan Rogers int err; 4268f707d84SJiri Olsa 427a26e4716SIan Rogers list = alloc_list(); 42877cdd787SIan Rogers if (!list) 42977cdd787SIan Rogers YYNOMEM; 430b52cb995SIan Rogers err = parse_events_add_numeric(_parse_state, list, type, config, /*head_config=*/NULL, wildcard); 431b52cb995SIan Rogers if (err) 432b52cb995SIan Rogers PE_ABORT(err); 433b847cbdcSJiri Olsa $$ = list; 43489812fc8SJiri Olsa } 435f0fbb114SAndi Kleen | 436f0fbb114SAndi Kleen PE_VALUE_SYM_TOOL sep_slash_slash_dc 437f0fbb114SAndi Kleen { 438f0fbb114SAndi Kleen struct list_head *list; 439b52cb995SIan Rogers int err; 440f0fbb114SAndi Kleen 441a26e4716SIan Rogers list = alloc_list(); 44277cdd787SIan Rogers if (!list) 44377cdd787SIan Rogers YYNOMEM; 444b52cb995SIan Rogers err = parse_events_add_tool(_parse_state, list, $1); 445b52cb995SIan Rogers if (err) 446b52cb995SIan Rogers YYNOMEM; 447f0fbb114SAndi Kleen $$ = list; 448f0fbb114SAndi Kleen } 44989812fc8SJiri Olsa 45089812fc8SJiri Olsa event_legacy_cache: 45170c90e4aSIan Rogers PE_LEGACY_CACHE opt_event_config 45289812fc8SJiri Olsa { 4535d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 454c5cd8ac0SDavid Ahern struct list_head *list; 455cabbf268SIan Rogers int err; 456b847cbdcSJiri Olsa 457a26e4716SIan Rogers list = alloc_list(); 45877cdd787SIan Rogers if (!list) 45977cdd787SIan Rogers YYNOMEM; 46077cdd787SIan Rogers 461411ad22eSIan Rogers err = parse_events_add_cache(list, &parse_state->idx, $1, parse_state, $2); 462b847cbdcSJiri Olsa 46343d0b978SWang Nan parse_events_terms__delete($2); 464cabbf268SIan Rogers free($1); 465cabbf268SIan Rogers if (err) { 466cabbf268SIan Rogers free_list_evsel(list); 467b52cb995SIan Rogers PE_ABORT(err); 468cabbf268SIan Rogers } 469b847cbdcSJiri Olsa $$ = list; 47089812fc8SJiri Olsa } 47189812fc8SJiri Olsa 47289812fc8SJiri Olsa event_legacy_mem: 473f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config 4743741eb9fSJacob Shin { 4753741eb9fSJacob Shin struct list_head *list; 476cabbf268SIan Rogers int err; 4773741eb9fSJacob Shin 478a26e4716SIan Rogers list = alloc_list(); 47977cdd787SIan Rogers if (!list) 48077cdd787SIan Rogers YYNOMEM; 48177cdd787SIan Rogers 482f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 483f0617f52SAdrian Hunter $2, $6, $4, $7); 484f0617f52SAdrian Hunter parse_events_terms__delete($7); 485cabbf268SIan Rogers free($6); 486cabbf268SIan Rogers if (err) { 487cabbf268SIan Rogers free(list); 488b52cb995SIan Rogers PE_ABORT(err); 489cabbf268SIan Rogers } 4903741eb9fSJacob Shin $$ = list; 4913741eb9fSJacob Shin } 4923741eb9fSJacob Shin | 493f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE PE_BP_SLASH PE_VALUE opt_event_config 4943741eb9fSJacob Shin { 4953741eb9fSJacob Shin struct list_head *list; 496f0617f52SAdrian Hunter int err; 497f0617f52SAdrian Hunter 498a26e4716SIan Rogers list = alloc_list(); 49977cdd787SIan Rogers if (!list) 50077cdd787SIan Rogers YYNOMEM; 50177cdd787SIan Rogers 502f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 503f0617f52SAdrian Hunter $2, NULL, $4, $5); 504f0617f52SAdrian Hunter parse_events_terms__delete($5); 505f0617f52SAdrian Hunter if (err) { 506cabbf268SIan Rogers free(list); 507b52cb995SIan Rogers PE_ABORT(err); 508cabbf268SIan Rogers } 5093741eb9fSJacob Shin $$ = list; 5103741eb9fSJacob Shin } 5113741eb9fSJacob Shin | 512f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE PE_BP_COLON PE_MODIFIER_BP opt_event_config 51389812fc8SJiri Olsa { 514c5cd8ac0SDavid Ahern struct list_head *list; 515cabbf268SIan Rogers int err; 516b847cbdcSJiri Olsa 517a26e4716SIan Rogers list = alloc_list(); 51877cdd787SIan Rogers if (!list) 51977cdd787SIan Rogers YYNOMEM; 52077cdd787SIan Rogers 521f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 522f0617f52SAdrian Hunter $2, $4, 0, $5); 523f0617f52SAdrian Hunter parse_events_terms__delete($5); 524cabbf268SIan Rogers free($4); 525cabbf268SIan Rogers if (err) { 526cabbf268SIan Rogers free(list); 527b52cb995SIan Rogers PE_ABORT(err); 528cabbf268SIan Rogers } 529b847cbdcSJiri Olsa $$ = list; 53089812fc8SJiri Olsa } 53189812fc8SJiri Olsa | 532f0617f52SAdrian Hunter PE_PREFIX_MEM PE_VALUE opt_event_config 53389812fc8SJiri Olsa { 534c5cd8ac0SDavid Ahern struct list_head *list; 535f0617f52SAdrian Hunter int err; 536b847cbdcSJiri Olsa 537a26e4716SIan Rogers list = alloc_list(); 53877cdd787SIan Rogers if (!list) 53977cdd787SIan Rogers YYNOMEM; 540f0617f52SAdrian Hunter err = parse_events_add_breakpoint(_parse_state, list, 541f0617f52SAdrian Hunter $2, NULL, 0, $3); 542f0617f52SAdrian Hunter parse_events_terms__delete($3); 543f0617f52SAdrian Hunter if (err) { 544cabbf268SIan Rogers free(list); 545b52cb995SIan Rogers PE_ABORT(err); 546cabbf268SIan Rogers } 547b847cbdcSJiri Olsa $$ = list; 54889812fc8SJiri Olsa } 54989812fc8SJiri Olsa 55089812fc8SJiri Olsa event_legacy_tracepoint: 5511d55e8efSArnaldo Carvalho de Melo tracepoint_name opt_event_config 5522b9032e0SAlexander Yarygin { 5535d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 5545d9cdc11SArnaldo Carvalho de Melo struct parse_events_error *error = parse_state->error; 5552b9032e0SAlexander Yarygin struct list_head *list; 556cabbf268SIan Rogers int err; 5572b9032e0SAlexander Yarygin 558a26e4716SIan Rogers list = alloc_list(); 55977cdd787SIan Rogers if (!list) 56077cdd787SIan Rogers YYNOMEM; 56119658171SJiri Olsa if (error) 56219658171SJiri Olsa error->idx = @1.first_column; 563e637d177SHe Kuang 564cabbf268SIan Rogers err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, 565d81fa63bSIan Rogers error, $2, &@1); 566e637d177SHe Kuang 567cabbf268SIan Rogers parse_events_terms__delete($2); 568cabbf268SIan Rogers free($1.sys); 569cabbf268SIan Rogers free($1.event); 570cabbf268SIan Rogers if (err) { 571cabbf268SIan Rogers free(list); 572b52cb995SIan Rogers PE_ABORT(err); 573cabbf268SIan Rogers } 5742b9032e0SAlexander Yarygin $$ = list; 5752b9032e0SAlexander Yarygin } 576865582c3SHe Kuang 577865582c3SHe Kuang tracepoint_name: 57889812fc8SJiri Olsa PE_NAME ':' PE_NAME 57989812fc8SJiri Olsa { 580865582c3SHe Kuang struct tracepoint_name tracepoint = {$1, $3}; 581b847cbdcSJiri Olsa 582865582c3SHe Kuang $$ = tracepoint; 58389812fc8SJiri Olsa } 58489812fc8SJiri Olsa 58589812fc8SJiri Olsa event_legacy_numeric: 58610bf358aSWang Nan PE_VALUE ':' PE_VALUE opt_event_config 58789812fc8SJiri Olsa { 588c5cd8ac0SDavid Ahern struct list_head *list; 589cabbf268SIan Rogers int err; 590b847cbdcSJiri Olsa 591a26e4716SIan Rogers list = alloc_list(); 59277cdd787SIan Rogers if (!list) 59377cdd787SIan Rogers YYNOMEM; 5948bc75f69SIan Rogers err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4, 5958bc75f69SIan Rogers /*wildcard=*/false); 59610bf358aSWang Nan parse_events_terms__delete($4); 597cabbf268SIan Rogers if (err) { 598cabbf268SIan Rogers free(list); 599b52cb995SIan Rogers PE_ABORT(err); 600cabbf268SIan Rogers } 601b847cbdcSJiri Olsa $$ = list; 60289812fc8SJiri Olsa } 60389812fc8SJiri Olsa 60489812fc8SJiri Olsa event_legacy_raw: 60510bf358aSWang Nan PE_RAW opt_event_config 60689812fc8SJiri Olsa { 607c5cd8ac0SDavid Ahern struct list_head *list; 608cabbf268SIan Rogers int err; 60970c90e4aSIan Rogers u64 num; 610b847cbdcSJiri Olsa 611a26e4716SIan Rogers list = alloc_list(); 61277cdd787SIan Rogers if (!list) 61377cdd787SIan Rogers YYNOMEM; 61470c90e4aSIan Rogers errno = 0; 61570c90e4aSIan Rogers num = strtoull($1 + 1, NULL, 16); 6164c11adffSIan Rogers /* Given the lexer will only give [a-fA-F0-9]+ a failure here should be impossible. */ 6174c11adffSIan Rogers if (errno) 6184c11adffSIan Rogers YYABORT; 61970c90e4aSIan Rogers free($1); 6208bc75f69SIan Rogers err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, num, $2, 621251aa040SIan Rogers /*wildcard=*/false); 62210bf358aSWang Nan parse_events_terms__delete($2); 623cabbf268SIan Rogers if (err) { 624cabbf268SIan Rogers free(list); 625b52cb995SIan Rogers PE_ABORT(err); 626cabbf268SIan Rogers } 627b847cbdcSJiri Olsa $$ = list; 6288f707d84SJiri Olsa } 6298f707d84SJiri Olsa 63084c86ca1SWang Nan event_bpf_file: 631a34f3be7SWang Nan PE_BPF_OBJECT opt_event_config 63284c86ca1SWang Nan { 6335d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 63484c86ca1SWang Nan struct list_head *list; 635cabbf268SIan Rogers int err; 63684c86ca1SWang Nan 637a26e4716SIan Rogers list = alloc_list(); 63877cdd787SIan Rogers if (!list) 63977cdd787SIan Rogers YYNOMEM; 640d81fa63bSIan Rogers err = parse_events_load_bpf(parse_state, list, $1, false, $2, &@1); 641a34f3be7SWang Nan parse_events_terms__delete($2); 642cabbf268SIan Rogers free($1); 643cabbf268SIan Rogers if (err) { 644cabbf268SIan Rogers free(list); 645b52cb995SIan Rogers PE_ABORT(err); 646cabbf268SIan Rogers } 647d509db04SWang Nan $$ = list; 648d509db04SWang Nan } 649d509db04SWang Nan | 650a34f3be7SWang Nan PE_BPF_SOURCE opt_event_config 651d509db04SWang Nan { 652d509db04SWang Nan struct list_head *list; 653cabbf268SIan Rogers int err; 654d509db04SWang Nan 655a26e4716SIan Rogers list = alloc_list(); 65677cdd787SIan Rogers if (!list) 65777cdd787SIan Rogers YYNOMEM; 658d81fa63bSIan Rogers err = parse_events_load_bpf(_parse_state, list, $1, true, $2, &@1); 659a34f3be7SWang Nan parse_events_terms__delete($2); 660cabbf268SIan Rogers if (err) { 661cabbf268SIan Rogers free(list); 662b52cb995SIan Rogers PE_ABORT(err); 663cabbf268SIan Rogers } 66484c86ca1SWang Nan $$ = list; 66584c86ca1SWang Nan } 66684c86ca1SWang Nan 6671d55e8efSArnaldo Carvalho de Melo opt_event_config: 6681d55e8efSArnaldo Carvalho de Melo '/' event_config '/' 6691d55e8efSArnaldo Carvalho de Melo { 6701d55e8efSArnaldo Carvalho de Melo $$ = $2; 6711d55e8efSArnaldo Carvalho de Melo } 6721d55e8efSArnaldo Carvalho de Melo | 6731d55e8efSArnaldo Carvalho de Melo '/' '/' 6741d55e8efSArnaldo Carvalho de Melo { 6751d55e8efSArnaldo Carvalho de Melo $$ = NULL; 6761d55e8efSArnaldo Carvalho de Melo } 6771d55e8efSArnaldo Carvalho de Melo | 6781d55e8efSArnaldo Carvalho de Melo { 6791d55e8efSArnaldo Carvalho de Melo $$ = NULL; 6801d55e8efSArnaldo Carvalho de Melo } 6811d55e8efSArnaldo Carvalho de Melo 682ceac7b79SJiri Olsa opt_pmu_config: 683ceac7b79SJiri Olsa '/' event_config '/' 684ceac7b79SJiri Olsa { 685ceac7b79SJiri Olsa $$ = $2; 686ceac7b79SJiri Olsa } 687ceac7b79SJiri Olsa | 688ceac7b79SJiri Olsa '/' '/' 689ceac7b79SJiri Olsa { 690ceac7b79SJiri Olsa $$ = NULL; 691ceac7b79SJiri Olsa } 692ceac7b79SJiri Olsa 69389efb029SJiri Olsa start_terms: event_config 69490e2b22dSJiri Olsa { 6955d9cdc11SArnaldo Carvalho de Melo struct parse_events_state *parse_state = _parse_state; 696cabbf268SIan Rogers if (parse_state->terms) { 697cabbf268SIan Rogers parse_events_terms__delete ($1); 698cabbf268SIan Rogers YYABORT; 699cabbf268SIan Rogers } 7005d9cdc11SArnaldo Carvalho de Melo parse_state->terms = $1; 70190e2b22dSJiri Olsa } 70290e2b22dSJiri Olsa 7038f707d84SJiri Olsa event_config: 7048f707d84SJiri Olsa event_config ',' event_term 7058f707d84SJiri Olsa { 7068f707d84SJiri Olsa struct list_head *head = $1; 7076cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term = $3; 7088f707d84SJiri Olsa 709cabbf268SIan Rogers if (!head) { 7101dc92556SIan Rogers parse_events_term__delete(term); 711cabbf268SIan Rogers YYABORT; 712cabbf268SIan Rogers } 7138f707d84SJiri Olsa list_add_tail(&term->list, head); 7148f707d84SJiri Olsa $$ = $1; 7158f707d84SJiri Olsa } 7168f707d84SJiri Olsa | 7178f707d84SJiri Olsa event_term 7188f707d84SJiri Olsa { 7198f707d84SJiri Olsa struct list_head *head = malloc(sizeof(*head)); 7206cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term = $1; 7218f707d84SJiri Olsa 72277cdd787SIan Rogers if (!head) 72377cdd787SIan Rogers YYNOMEM; 7248f707d84SJiri Olsa INIT_LIST_HEAD(head); 7258f707d84SJiri Olsa list_add_tail(&term->list, head); 7268f707d84SJiri Olsa $$ = head; 7278f707d84SJiri Olsa } 7288f707d84SJiri Olsa 7296fd1e519SIan Rogers name_or_raw: PE_RAW | PE_NAME | PE_LEGACY_CACHE 73070c90e4aSIan Rogers 7312aadca4bSIan Rogers name_or_legacy: PE_NAME | PE_LEGACY_CACHE 7322aadca4bSIan Rogers 7338f707d84SJiri Olsa event_term: 7343a6c51e4SJiri Olsa PE_RAW 7353a6c51e4SJiri Olsa { 7363a6c51e4SJiri Olsa struct parse_events_term *term; 737b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_RAW, 738b52cb995SIan Rogers strdup("raw"), $1, &@1, &@1); 7393a6c51e4SJiri Olsa 740b52cb995SIan Rogers if (err) { 74170c90e4aSIan Rogers free($1); 742b52cb995SIan Rogers PE_ABORT(err); 74370c90e4aSIan Rogers } 7443a6c51e4SJiri Olsa $$ = term; 7453a6c51e4SJiri Olsa } 7463a6c51e4SJiri Olsa | 7472aadca4bSIan Rogers name_or_raw '=' name_or_legacy 7488f707d84SJiri Olsa { 7496cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 750b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $3, &@1, &@3); 7518f707d84SJiri Olsa 752b52cb995SIan Rogers if (err) { 753cabbf268SIan Rogers free($1); 754cabbf268SIan Rogers free($3); 755b52cb995SIan Rogers PE_ABORT(err); 756cabbf268SIan Rogers } 7578f707d84SJiri Olsa $$ = term; 7588f707d84SJiri Olsa } 7598f707d84SJiri Olsa | 76070c90e4aSIan Rogers name_or_raw '=' PE_VALUE 7618f707d84SJiri Olsa { 7626cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 763b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 764b52cb995SIan Rogers $1, $3, false, &@1, &@3); 7658f707d84SJiri Olsa 766b52cb995SIan Rogers if (err) { 767cabbf268SIan Rogers free($1); 768b52cb995SIan Rogers PE_ABORT(err); 769cabbf268SIan Rogers } 7708f707d84SJiri Olsa $$ = term; 7718f707d84SJiri Olsa } 7728f707d84SJiri Olsa | 7735ea8f2ccSIan Rogers name_or_raw '=' PE_TERM_HW 7741d33d6dcSJiri Olsa { 7756cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 776b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, 777b52cb995SIan Rogers $1, $3.str, &@1, &@3); 7781d33d6dcSJiri Olsa 779b52cb995SIan Rogers if (err) { 780cabbf268SIan Rogers free($1); 7815ea8f2ccSIan Rogers free($3.str); 782b52cb995SIan Rogers PE_ABORT(err); 783cabbf268SIan Rogers } 7841d33d6dcSJiri Olsa $$ = term; 7851d33d6dcSJiri Olsa } 7861d33d6dcSJiri Olsa | 7876fd1e519SIan Rogers PE_LEGACY_CACHE 7886fd1e519SIan Rogers { 7896fd1e519SIan Rogers struct parse_events_term *term; 790b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_LEGACY_CACHE, 791b52cb995SIan Rogers $1, 1, true, &@1, NULL); 7926fd1e519SIan Rogers 793b52cb995SIan Rogers if (err) { 7946fd1e519SIan Rogers free($1); 795b52cb995SIan Rogers PE_ABORT(err); 7966fd1e519SIan Rogers } 7976fd1e519SIan Rogers $$ = term; 7986fd1e519SIan Rogers } 7996fd1e519SIan Rogers | 8008f707d84SJiri Olsa PE_NAME 8018f707d84SJiri Olsa { 8026cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 803b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, 804b52cb995SIan Rogers $1, 1, true, &@1, NULL); 8058f707d84SJiri Olsa 806b52cb995SIan Rogers if (err) { 807cabbf268SIan Rogers free($1); 808b52cb995SIan Rogers PE_ABORT(err); 809cabbf268SIan Rogers } 8108f707d84SJiri Olsa $$ = term; 8118f707d84SJiri Olsa } 8128f707d84SJiri Olsa | 8135ea8f2ccSIan Rogers PE_TERM_HW 8141d33d6dcSJiri Olsa { 8156cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 816b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_HARDWARE, 817b52cb995SIan Rogers $1.str, $1.num & 255, false, &@1, NULL); 8181d33d6dcSJiri Olsa 819b52cb995SIan Rogers if (err) { 8205ea8f2ccSIan Rogers free($1.str); 821b52cb995SIan Rogers PE_ABORT(err); 8225ea8f2ccSIan Rogers } 8231d33d6dcSJiri Olsa $$ = term; 8241d33d6dcSJiri Olsa } 8251d33d6dcSJiri Olsa | 8262aadca4bSIan Rogers PE_TERM '=' name_or_legacy 8276b5fc39bSJiri Olsa { 8286cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 829b52cb995SIan Rogers int err = parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3); 8306b5fc39bSJiri Olsa 831b52cb995SIan Rogers if (err) { 832cabbf268SIan Rogers free($3); 833b52cb995SIan Rogers PE_ABORT(err); 834cabbf268SIan Rogers } 8356b5fc39bSJiri Olsa $$ = term; 8366b5fc39bSJiri Olsa } 8376b5fc39bSJiri Olsa | 8385ea8f2ccSIan Rogers PE_TERM '=' PE_TERM_HW 8395ea8f2ccSIan Rogers { 8405ea8f2ccSIan Rogers struct parse_events_term *term; 841b52cb995SIan Rogers int err = parse_events_term__str(&term, (int)$1, NULL, $3.str, &@1, &@3); 8425ea8f2ccSIan Rogers 843b52cb995SIan Rogers if (err) { 8445ea8f2ccSIan Rogers free($3.str); 845b52cb995SIan Rogers PE_ABORT(err); 8465ea8f2ccSIan Rogers } 8475ea8f2ccSIan Rogers $$ = term; 8485ea8f2ccSIan Rogers } 8495ea8f2ccSIan Rogers | 850e831f3ccSIan Rogers PE_TERM '=' PE_TERM 851e831f3ccSIan Rogers { 852e831f3ccSIan Rogers struct parse_events_term *term; 853b52cb995SIan Rogers int err = parse_events_term__term(&term, (int)$1, (int)$3, &@1, &@3); 854e831f3ccSIan Rogers 855b52cb995SIan Rogers if (err) 856b52cb995SIan Rogers PE_ABORT(err); 857b52cb995SIan Rogers 858e831f3ccSIan Rogers $$ = term; 859e831f3ccSIan Rogers } 860e831f3ccSIan Rogers | 8618f707d84SJiri Olsa PE_TERM '=' PE_VALUE 8628f707d84SJiri Olsa { 8636cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 864b52cb995SIan Rogers int err = parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3); 8658f707d84SJiri Olsa 866b52cb995SIan Rogers if (err) 867b52cb995SIan Rogers PE_ABORT(err); 868b52cb995SIan Rogers 8698f707d84SJiri Olsa $$ = term; 8708f707d84SJiri Olsa } 8718f707d84SJiri Olsa | 8728f707d84SJiri Olsa PE_TERM 8738f707d84SJiri Olsa { 8746cee6cd3SArnaldo Carvalho de Melo struct parse_events_term *term; 875b52cb995SIan Rogers int err = parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL); 8768f707d84SJiri Olsa 877b52cb995SIan Rogers if (err) 878b52cb995SIan Rogers PE_ABORT(err); 879b52cb995SIan Rogers 8808f707d84SJiri Olsa $$ = term; 88189812fc8SJiri Olsa } 882e571e029SWang Nan | 8832aadca4bSIan Rogers name_or_raw array '=' name_or_legacy 884e571e029SWang Nan { 885e571e029SWang Nan struct parse_events_term *term; 886b52cb995SIan Rogers int err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, &@1, &@4); 887e571e029SWang Nan 888b52cb995SIan Rogers if (err) { 889cabbf268SIan Rogers free($1); 890cabbf268SIan Rogers free($4); 891cabbf268SIan Rogers free($2.ranges); 892b52cb995SIan Rogers PE_ABORT(err); 893cabbf268SIan Rogers } 894e571e029SWang Nan term->array = $2; 895e571e029SWang Nan $$ = term; 896e571e029SWang Nan } 897e571e029SWang Nan | 89870c90e4aSIan Rogers name_or_raw array '=' PE_VALUE 899e571e029SWang Nan { 900e571e029SWang Nan struct parse_events_term *term; 901b52cb995SIan Rogers int err = parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, $1, $4, false, &@1, &@4); 902e571e029SWang Nan 903b52cb995SIan Rogers if (err) { 904cabbf268SIan Rogers free($1); 905cabbf268SIan Rogers free($2.ranges); 906b52cb995SIan Rogers PE_ABORT(err); 907cabbf268SIan Rogers } 908e571e029SWang Nan term->array = $2; 909e571e029SWang Nan $$ = term; 910e571e029SWang Nan } 911dd60fba7SMathieu Poirier | 912dd60fba7SMathieu Poirier PE_DRV_CFG_TERM 913dd60fba7SMathieu Poirier { 914dd60fba7SMathieu Poirier struct parse_events_term *term; 915b6645a72SIan Rogers char *config = strdup($1); 916b52cb995SIan Rogers int err; 917dd60fba7SMathieu Poirier 91877cdd787SIan Rogers if (!config) 91977cdd787SIan Rogers YYNOMEM; 920b52cb995SIan Rogers err = parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, config, $1, &@1, NULL); 921b52cb995SIan Rogers if (err) { 922cabbf268SIan Rogers free($1); 923cabbf268SIan Rogers free(config); 924b52cb995SIan Rogers PE_ABORT(err); 925cabbf268SIan Rogers } 926dd60fba7SMathieu Poirier $$ = term; 927dd60fba7SMathieu Poirier } 928e571e029SWang Nan 929e571e029SWang Nan array: 930e571e029SWang Nan '[' array_terms ']' 931e571e029SWang Nan { 932e571e029SWang Nan $$ = $2; 933e571e029SWang Nan } 934e571e029SWang Nan | 935e571e029SWang Nan PE_ARRAY_ALL 936e571e029SWang Nan { 937e571e029SWang Nan $$.nr_ranges = 0; 938e571e029SWang Nan $$.ranges = NULL; 939e571e029SWang Nan } 940e571e029SWang Nan 941e571e029SWang Nan array_terms: 942e571e029SWang Nan array_terms ',' array_term 943e571e029SWang Nan { 944e571e029SWang Nan struct parse_events_array new_array; 945e571e029SWang Nan 946e571e029SWang Nan new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; 947826100a7SIan Rogers new_array.ranges = realloc($1.ranges, 948826100a7SIan Rogers sizeof(new_array.ranges[0]) * 949e571e029SWang Nan new_array.nr_ranges); 95077cdd787SIan Rogers if (!new_array.ranges) 95177cdd787SIan Rogers YYNOMEM; 952e571e029SWang Nan memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, 953e571e029SWang Nan $3.nr_ranges * sizeof(new_array.ranges[0])); 954e571e029SWang Nan free($3.ranges); 955e571e029SWang Nan $$ = new_array; 956e571e029SWang Nan } 957e571e029SWang Nan | 958e571e029SWang Nan array_term 959e571e029SWang Nan 960e571e029SWang Nan array_term: 961e571e029SWang Nan PE_VALUE 962e571e029SWang Nan { 963e571e029SWang Nan struct parse_events_array array; 964e571e029SWang Nan 965e571e029SWang Nan array.nr_ranges = 1; 966e571e029SWang Nan array.ranges = malloc(sizeof(array.ranges[0])); 96777cdd787SIan Rogers if (!array.ranges) 96877cdd787SIan Rogers YYNOMEM; 969e571e029SWang Nan array.ranges[0].start = $1; 970e571e029SWang Nan array.ranges[0].length = 1; 971e571e029SWang Nan $$ = array; 972e571e029SWang Nan } 973e571e029SWang Nan | 974e571e029SWang Nan PE_VALUE PE_ARRAY_RANGE PE_VALUE 975e571e029SWang Nan { 976e571e029SWang Nan struct parse_events_array array; 977e571e029SWang Nan 9784c11adffSIan Rogers if ($3 < $1) { 9794c11adffSIan Rogers struct parse_events_state *parse_state = _parse_state; 9804c11adffSIan Rogers struct parse_events_error *error = parse_state->error; 9814c11adffSIan Rogers char *err_str; 9824c11adffSIan Rogers 9834c11adffSIan Rogers if (asprintf(&err_str, "Expected '%ld' to be less-than '%ld'", $3, $1) < 0) 9844c11adffSIan Rogers err_str = NULL; 9854c11adffSIan Rogers 9864c11adffSIan Rogers parse_events_error__handle(error, @1.first_column, err_str, NULL); 9874c11adffSIan Rogers YYABORT; 9884c11adffSIan Rogers } 989e571e029SWang Nan array.nr_ranges = 1; 990e571e029SWang Nan array.ranges = malloc(sizeof(array.ranges[0])); 99177cdd787SIan Rogers if (!array.ranges) 99277cdd787SIan Rogers YYNOMEM; 993e571e029SWang Nan array.ranges[0].start = $1; 994e571e029SWang Nan array.ranges[0].length = $3 - $1 + 1; 995e571e029SWang Nan $$ = array; 996e571e029SWang Nan } 99789812fc8SJiri Olsa 99889812fc8SJiri Olsa sep_dc: ':' | 99989812fc8SJiri Olsa 1000714a92d8SJiri Olsa sep_slash_slash_dc: '/' '/' | ':' | 10018f707d84SJiri Olsa 100289812fc8SJiri Olsa %% 100389812fc8SJiri Olsa 10045d9cdc11SArnaldo Carvalho de Melo void parse_events_error(YYLTYPE *loc, void *parse_state, 10056297d423SJiri Olsa void *scanner __maybe_unused, 10061d037ca1SIrina Tirdea char const *msg __maybe_unused) 100789812fc8SJiri Olsa { 10085d9cdc11SArnaldo Carvalho de Melo parse_events_evlist_error(parse_state, loc->last_column, "parser error"); 100989812fc8SJiri Olsa } 1010