rjw | 1f88458 | 2022-01-06 17:20:42 +0800 | [diff] [blame^] | 1 | %pure-parser |
| 2 | %parse-param {void *_parse_state} |
| 3 | %parse-param {void *scanner} |
| 4 | %lex-param {void* scanner} |
| 5 | %locations |
| 6 | |
| 7 | %{ |
| 8 | |
| 9 | #define YYDEBUG 1 |
| 10 | |
| 11 | #include <linux/compiler.h> |
| 12 | #include <linux/list.h> |
| 13 | #include <linux/types.h> |
| 14 | #include "util.h" |
| 15 | #include "pmu.h" |
| 16 | #include "debug.h" |
| 17 | #include "parse-events.h" |
| 18 | #include "parse-events-bison.h" |
| 19 | |
| 20 | void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg); |
| 21 | |
| 22 | #define ABORT_ON(val) \ |
| 23 | do { \ |
| 24 | if (val) \ |
| 25 | YYABORT; \ |
| 26 | } while (0) |
| 27 | |
| 28 | #define ALLOC_LIST(list) \ |
| 29 | do { \ |
| 30 | list = malloc(sizeof(*list)); \ |
| 31 | ABORT_ON(!list); \ |
| 32 | INIT_LIST_HEAD(list); \ |
| 33 | } while (0) |
| 34 | |
| 35 | static void inc_group_count(struct list_head *list, |
| 36 | struct parse_events_state *parse_state) |
| 37 | { |
| 38 | /* Count groups only have more than 1 members */ |
| 39 | if (!list_is_last(list->next, list)) |
| 40 | parse_state->nr_groups++; |
| 41 | } |
| 42 | |
| 43 | %} |
| 44 | |
| 45 | %token PE_START_EVENTS PE_START_TERMS |
| 46 | %token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM |
| 47 | %token PE_EVENT_NAME |
| 48 | %token PE_NAME |
| 49 | %token PE_BPF_OBJECT PE_BPF_SOURCE |
| 50 | %token PE_MODIFIER_EVENT PE_MODIFIER_BP |
| 51 | %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT |
| 52 | %token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP |
| 53 | %token PE_ERROR |
| 54 | %token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT |
| 55 | %token PE_ARRAY_ALL PE_ARRAY_RANGE |
| 56 | %token PE_DRV_CFG_TERM |
| 57 | %type <num> PE_VALUE |
| 58 | %type <num> PE_VALUE_SYM_HW |
| 59 | %type <num> PE_VALUE_SYM_SW |
| 60 | %type <num> PE_RAW |
| 61 | %type <num> PE_TERM |
| 62 | %type <str> PE_NAME |
| 63 | %type <str> PE_BPF_OBJECT |
| 64 | %type <str> PE_BPF_SOURCE |
| 65 | %type <str> PE_NAME_CACHE_TYPE |
| 66 | %type <str> PE_NAME_CACHE_OP_RESULT |
| 67 | %type <str> PE_MODIFIER_EVENT |
| 68 | %type <str> PE_MODIFIER_BP |
| 69 | %type <str> PE_EVENT_NAME |
| 70 | %type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT |
| 71 | %type <str> PE_DRV_CFG_TERM |
| 72 | %type <num> value_sym |
| 73 | %type <head> event_config |
| 74 | %type <head> opt_event_config |
| 75 | %type <head> opt_pmu_config |
| 76 | %type <term> event_term |
| 77 | %type <head> event_pmu |
| 78 | %type <head> event_legacy_symbol |
| 79 | %type <head> event_legacy_cache |
| 80 | %type <head> event_legacy_mem |
| 81 | %type <head> event_legacy_tracepoint |
| 82 | %type <tracepoint_name> tracepoint_name |
| 83 | %type <head> event_legacy_numeric |
| 84 | %type <head> event_legacy_raw |
| 85 | %type <head> event_bpf_file |
| 86 | %type <head> event_def |
| 87 | %type <head> event_mod |
| 88 | %type <head> event_name |
| 89 | %type <head> event |
| 90 | %type <head> events |
| 91 | %type <head> group_def |
| 92 | %type <head> group |
| 93 | %type <head> groups |
| 94 | %type <array> array |
| 95 | %type <array> array_term |
| 96 | %type <array> array_terms |
| 97 | |
| 98 | %union |
| 99 | { |
| 100 | char *str; |
| 101 | u64 num; |
| 102 | struct list_head *head; |
| 103 | struct parse_events_term *term; |
| 104 | struct tracepoint_name { |
| 105 | char *sys; |
| 106 | char *event; |
| 107 | } tracepoint_name; |
| 108 | struct parse_events_array array; |
| 109 | } |
| 110 | %% |
| 111 | |
| 112 | start: |
| 113 | PE_START_EVENTS start_events |
| 114 | | |
| 115 | PE_START_TERMS start_terms |
| 116 | |
| 117 | start_events: groups |
| 118 | { |
| 119 | struct parse_events_state *parse_state = _parse_state; |
| 120 | |
| 121 | parse_events_update_lists($1, &parse_state->list); |
| 122 | } |
| 123 | |
| 124 | groups: |
| 125 | groups ',' group |
| 126 | { |
| 127 | struct list_head *list = $1; |
| 128 | struct list_head *group = $3; |
| 129 | |
| 130 | parse_events_update_lists(group, list); |
| 131 | $$ = list; |
| 132 | } |
| 133 | | |
| 134 | groups ',' event |
| 135 | { |
| 136 | struct list_head *list = $1; |
| 137 | struct list_head *event = $3; |
| 138 | |
| 139 | parse_events_update_lists(event, list); |
| 140 | $$ = list; |
| 141 | } |
| 142 | | |
| 143 | group |
| 144 | | |
| 145 | event |
| 146 | |
| 147 | group: |
| 148 | group_def ':' PE_MODIFIER_EVENT |
| 149 | { |
| 150 | struct list_head *list = $1; |
| 151 | |
| 152 | ABORT_ON(parse_events__modifier_group(list, $3)); |
| 153 | $$ = list; |
| 154 | } |
| 155 | | |
| 156 | group_def |
| 157 | |
| 158 | group_def: |
| 159 | PE_NAME '{' events '}' |
| 160 | { |
| 161 | struct list_head *list = $3; |
| 162 | |
| 163 | inc_group_count(list, _parse_state); |
| 164 | parse_events__set_leader($1, list); |
| 165 | $$ = list; |
| 166 | } |
| 167 | | |
| 168 | '{' events '}' |
| 169 | { |
| 170 | struct list_head *list = $2; |
| 171 | |
| 172 | inc_group_count(list, _parse_state); |
| 173 | parse_events__set_leader(NULL, list); |
| 174 | $$ = list; |
| 175 | } |
| 176 | |
| 177 | events: |
| 178 | events ',' event |
| 179 | { |
| 180 | struct list_head *event = $3; |
| 181 | struct list_head *list = $1; |
| 182 | |
| 183 | parse_events_update_lists(event, list); |
| 184 | $$ = list; |
| 185 | } |
| 186 | | |
| 187 | event |
| 188 | |
| 189 | event: event_mod |
| 190 | |
| 191 | event_mod: |
| 192 | event_name PE_MODIFIER_EVENT |
| 193 | { |
| 194 | struct list_head *list = $1; |
| 195 | |
| 196 | /* |
| 197 | * Apply modifier on all events added by single event definition |
| 198 | * (there could be more events added for multiple tracepoint |
| 199 | * definitions via '*?'. |
| 200 | */ |
| 201 | ABORT_ON(parse_events__modifier_event(list, $2, false)); |
| 202 | $$ = list; |
| 203 | } |
| 204 | | |
| 205 | event_name |
| 206 | |
| 207 | event_name: |
| 208 | PE_EVENT_NAME event_def |
| 209 | { |
| 210 | ABORT_ON(parse_events_name($2, $1)); |
| 211 | free($1); |
| 212 | $$ = $2; |
| 213 | } |
| 214 | | |
| 215 | event_def |
| 216 | |
| 217 | event_def: event_pmu | |
| 218 | event_legacy_symbol | |
| 219 | event_legacy_cache sep_dc | |
| 220 | event_legacy_mem | |
| 221 | event_legacy_tracepoint sep_dc | |
| 222 | event_legacy_numeric sep_dc | |
| 223 | event_legacy_raw sep_dc | |
| 224 | event_bpf_file |
| 225 | |
| 226 | event_pmu: |
| 227 | PE_NAME opt_pmu_config |
| 228 | { |
| 229 | struct parse_events_state *parse_state = _parse_state; |
| 230 | struct parse_events_error *error = parse_state->error; |
| 231 | struct list_head *list, *orig_terms, *terms; |
| 232 | |
| 233 | if (parse_events_copy_term_list($2, &orig_terms)) |
| 234 | YYABORT; |
| 235 | |
| 236 | if (error) |
| 237 | error->idx = @1.first_column; |
| 238 | |
| 239 | ALLOC_LIST(list); |
| 240 | if (parse_events_add_pmu(_parse_state, list, $1, $2)) { |
| 241 | struct perf_pmu *pmu = NULL; |
| 242 | int ok = 0; |
| 243 | |
| 244 | while ((pmu = perf_pmu__scan(pmu)) != NULL) { |
| 245 | char *name = pmu->name; |
| 246 | |
| 247 | if (!strncmp(name, "uncore_", 7) && |
| 248 | strncmp($1, "uncore_", 7)) |
| 249 | name += 7; |
| 250 | if (!strncmp($1, name, strlen($1))) { |
| 251 | if (parse_events_copy_term_list(orig_terms, &terms)) |
| 252 | YYABORT; |
| 253 | if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms)) |
| 254 | ok++; |
| 255 | parse_events_terms__delete(terms); |
| 256 | } |
| 257 | } |
| 258 | if (!ok) |
| 259 | YYABORT; |
| 260 | } |
| 261 | parse_events_terms__delete($2); |
| 262 | parse_events_terms__delete(orig_terms); |
| 263 | $$ = list; |
| 264 | } |
| 265 | | |
| 266 | PE_KERNEL_PMU_EVENT sep_dc |
| 267 | { |
| 268 | struct list_head *list; |
| 269 | |
| 270 | if (parse_events_multi_pmu_add(_parse_state, $1, &list) < 0) |
| 271 | YYABORT; |
| 272 | $$ = list; |
| 273 | } |
| 274 | | |
| 275 | PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc |
| 276 | { |
| 277 | struct list_head *list; |
| 278 | char pmu_name[128]; |
| 279 | |
| 280 | snprintf(&pmu_name, 128, "%s-%s", $1, $3); |
| 281 | if (parse_events_multi_pmu_add(_parse_state, pmu_name, &list) < 0) |
| 282 | YYABORT; |
| 283 | $$ = list; |
| 284 | } |
| 285 | |
| 286 | value_sym: |
| 287 | PE_VALUE_SYM_HW |
| 288 | | |
| 289 | PE_VALUE_SYM_SW |
| 290 | |
| 291 | event_legacy_symbol: |
| 292 | value_sym '/' event_config '/' |
| 293 | { |
| 294 | struct list_head *list; |
| 295 | int type = $1 >> 16; |
| 296 | int config = $1 & 255; |
| 297 | |
| 298 | ALLOC_LIST(list); |
| 299 | ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, $3)); |
| 300 | parse_events_terms__delete($3); |
| 301 | $$ = list; |
| 302 | } |
| 303 | | |
| 304 | value_sym sep_slash_dc |
| 305 | { |
| 306 | struct list_head *list; |
| 307 | int type = $1 >> 16; |
| 308 | int config = $1 & 255; |
| 309 | |
| 310 | ALLOC_LIST(list); |
| 311 | ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL)); |
| 312 | $$ = list; |
| 313 | } |
| 314 | |
| 315 | event_legacy_cache: |
| 316 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config |
| 317 | { |
| 318 | struct parse_events_state *parse_state = _parse_state; |
| 319 | struct parse_events_error *error = parse_state->error; |
| 320 | struct list_head *list; |
| 321 | |
| 322 | ALLOC_LIST(list); |
| 323 | ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6)); |
| 324 | parse_events_terms__delete($6); |
| 325 | $$ = list; |
| 326 | } |
| 327 | | |
| 328 | PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config |
| 329 | { |
| 330 | struct parse_events_state *parse_state = _parse_state; |
| 331 | struct parse_events_error *error = parse_state->error; |
| 332 | struct list_head *list; |
| 333 | |
| 334 | ALLOC_LIST(list); |
| 335 | ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4)); |
| 336 | parse_events_terms__delete($4); |
| 337 | $$ = list; |
| 338 | } |
| 339 | | |
| 340 | PE_NAME_CACHE_TYPE opt_event_config |
| 341 | { |
| 342 | struct parse_events_state *parse_state = _parse_state; |
| 343 | struct parse_events_error *error = parse_state->error; |
| 344 | struct list_head *list; |
| 345 | |
| 346 | ALLOC_LIST(list); |
| 347 | ABORT_ON(parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2)); |
| 348 | parse_events_terms__delete($2); |
| 349 | $$ = list; |
| 350 | } |
| 351 | |
| 352 | event_legacy_mem: |
| 353 | PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc |
| 354 | { |
| 355 | struct parse_events_state *parse_state = _parse_state; |
| 356 | struct list_head *list; |
| 357 | |
| 358 | ALLOC_LIST(list); |
| 359 | ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, |
| 360 | (void *) $2, $6, $4)); |
| 361 | $$ = list; |
| 362 | } |
| 363 | | |
| 364 | PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc |
| 365 | { |
| 366 | struct parse_events_state *parse_state = _parse_state; |
| 367 | struct list_head *list; |
| 368 | |
| 369 | ALLOC_LIST(list); |
| 370 | ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, |
| 371 | (void *) $2, NULL, $4)); |
| 372 | $$ = list; |
| 373 | } |
| 374 | | |
| 375 | PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc |
| 376 | { |
| 377 | struct parse_events_state *parse_state = _parse_state; |
| 378 | struct list_head *list; |
| 379 | |
| 380 | ALLOC_LIST(list); |
| 381 | ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, |
| 382 | (void *) $2, $4, 0)); |
| 383 | $$ = list; |
| 384 | } |
| 385 | | |
| 386 | PE_PREFIX_MEM PE_VALUE sep_dc |
| 387 | { |
| 388 | struct parse_events_state *parse_state = _parse_state; |
| 389 | struct list_head *list; |
| 390 | |
| 391 | ALLOC_LIST(list); |
| 392 | ABORT_ON(parse_events_add_breakpoint(list, &parse_state->idx, |
| 393 | (void *) $2, NULL, 0)); |
| 394 | $$ = list; |
| 395 | } |
| 396 | |
| 397 | event_legacy_tracepoint: |
| 398 | tracepoint_name opt_event_config |
| 399 | { |
| 400 | struct parse_events_state *parse_state = _parse_state; |
| 401 | struct parse_events_error *error = parse_state->error; |
| 402 | struct list_head *list; |
| 403 | |
| 404 | ALLOC_LIST(list); |
| 405 | if (error) |
| 406 | error->idx = @1.first_column; |
| 407 | |
| 408 | if (parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event, |
| 409 | error, $2)) |
| 410 | return -1; |
| 411 | |
| 412 | $$ = list; |
| 413 | } |
| 414 | |
| 415 | tracepoint_name: |
| 416 | PE_NAME '-' PE_NAME ':' PE_NAME |
| 417 | { |
| 418 | char sys_name[128]; |
| 419 | struct tracepoint_name tracepoint; |
| 420 | |
| 421 | snprintf(&sys_name, 128, "%s-%s", $1, $3); |
| 422 | tracepoint.sys = &sys_name; |
| 423 | tracepoint.event = $5; |
| 424 | |
| 425 | $$ = tracepoint; |
| 426 | } |
| 427 | | |
| 428 | PE_NAME ':' PE_NAME |
| 429 | { |
| 430 | struct tracepoint_name tracepoint = {$1, $3}; |
| 431 | |
| 432 | $$ = tracepoint; |
| 433 | } |
| 434 | |
| 435 | event_legacy_numeric: |
| 436 | PE_VALUE ':' PE_VALUE opt_event_config |
| 437 | { |
| 438 | struct list_head *list; |
| 439 | |
| 440 | ALLOC_LIST(list); |
| 441 | ABORT_ON(parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4)); |
| 442 | parse_events_terms__delete($4); |
| 443 | $$ = list; |
| 444 | } |
| 445 | |
| 446 | event_legacy_raw: |
| 447 | PE_RAW opt_event_config |
| 448 | { |
| 449 | struct list_head *list; |
| 450 | |
| 451 | ALLOC_LIST(list); |
| 452 | ABORT_ON(parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2)); |
| 453 | parse_events_terms__delete($2); |
| 454 | $$ = list; |
| 455 | } |
| 456 | |
| 457 | event_bpf_file: |
| 458 | PE_BPF_OBJECT opt_event_config |
| 459 | { |
| 460 | struct parse_events_state *parse_state = _parse_state; |
| 461 | struct parse_events_error *error = parse_state->error; |
| 462 | struct list_head *list; |
| 463 | |
| 464 | ALLOC_LIST(list); |
| 465 | ABORT_ON(parse_events_load_bpf(parse_state, list, $1, false, $2)); |
| 466 | parse_events_terms__delete($2); |
| 467 | $$ = list; |
| 468 | } |
| 469 | | |
| 470 | PE_BPF_SOURCE opt_event_config |
| 471 | { |
| 472 | struct list_head *list; |
| 473 | |
| 474 | ALLOC_LIST(list); |
| 475 | ABORT_ON(parse_events_load_bpf(_parse_state, list, $1, true, $2)); |
| 476 | parse_events_terms__delete($2); |
| 477 | $$ = list; |
| 478 | } |
| 479 | |
| 480 | opt_event_config: |
| 481 | '/' event_config '/' |
| 482 | { |
| 483 | $$ = $2; |
| 484 | } |
| 485 | | |
| 486 | '/' '/' |
| 487 | { |
| 488 | $$ = NULL; |
| 489 | } |
| 490 | | |
| 491 | { |
| 492 | $$ = NULL; |
| 493 | } |
| 494 | |
| 495 | opt_pmu_config: |
| 496 | '/' event_config '/' |
| 497 | { |
| 498 | $$ = $2; |
| 499 | } |
| 500 | | |
| 501 | '/' '/' |
| 502 | { |
| 503 | $$ = NULL; |
| 504 | } |
| 505 | |
| 506 | start_terms: event_config |
| 507 | { |
| 508 | struct parse_events_state *parse_state = _parse_state; |
| 509 | parse_state->terms = $1; |
| 510 | } |
| 511 | |
| 512 | event_config: |
| 513 | event_config ',' event_term |
| 514 | { |
| 515 | struct list_head *head = $1; |
| 516 | struct parse_events_term *term = $3; |
| 517 | |
| 518 | ABORT_ON(!head); |
| 519 | list_add_tail(&term->list, head); |
| 520 | $$ = $1; |
| 521 | } |
| 522 | | |
| 523 | event_term |
| 524 | { |
| 525 | struct list_head *head = malloc(sizeof(*head)); |
| 526 | struct parse_events_term *term = $1; |
| 527 | |
| 528 | ABORT_ON(!head); |
| 529 | INIT_LIST_HEAD(head); |
| 530 | list_add_tail(&term->list, head); |
| 531 | $$ = head; |
| 532 | } |
| 533 | |
| 534 | event_term: |
| 535 | PE_NAME '=' PE_NAME |
| 536 | { |
| 537 | struct parse_events_term *term; |
| 538 | |
| 539 | ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, |
| 540 | $1, $3, &@1, &@3)); |
| 541 | $$ = term; |
| 542 | } |
| 543 | | |
| 544 | PE_NAME '=' PE_VALUE |
| 545 | { |
| 546 | struct parse_events_term *term; |
| 547 | |
| 548 | ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, |
| 549 | $1, $3, false, &@1, &@3)); |
| 550 | $$ = term; |
| 551 | } |
| 552 | | |
| 553 | PE_NAME '=' PE_VALUE_SYM_HW |
| 554 | { |
| 555 | struct parse_events_term *term; |
| 556 | int config = $3 & 255; |
| 557 | |
| 558 | ABORT_ON(parse_events_term__sym_hw(&term, $1, config)); |
| 559 | $$ = term; |
| 560 | } |
| 561 | | |
| 562 | PE_NAME |
| 563 | { |
| 564 | struct parse_events_term *term; |
| 565 | |
| 566 | ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, |
| 567 | $1, 1, true, &@1, NULL)); |
| 568 | $$ = term; |
| 569 | } |
| 570 | | |
| 571 | PE_VALUE_SYM_HW |
| 572 | { |
| 573 | struct parse_events_term *term; |
| 574 | int config = $1 & 255; |
| 575 | |
| 576 | ABORT_ON(parse_events_term__sym_hw(&term, NULL, config)); |
| 577 | $$ = term; |
| 578 | } |
| 579 | | |
| 580 | PE_TERM '=' PE_NAME |
| 581 | { |
| 582 | struct parse_events_term *term; |
| 583 | |
| 584 | ABORT_ON(parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)); |
| 585 | $$ = term; |
| 586 | } |
| 587 | | |
| 588 | PE_TERM '=' PE_VALUE |
| 589 | { |
| 590 | struct parse_events_term *term; |
| 591 | |
| 592 | ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3)); |
| 593 | $$ = term; |
| 594 | } |
| 595 | | |
| 596 | PE_TERM |
| 597 | { |
| 598 | struct parse_events_term *term; |
| 599 | |
| 600 | ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL)); |
| 601 | $$ = term; |
| 602 | } |
| 603 | | |
| 604 | PE_NAME array '=' PE_NAME |
| 605 | { |
| 606 | struct parse_events_term *term; |
| 607 | int i; |
| 608 | |
| 609 | ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER, |
| 610 | $1, $4, &@1, &@4)); |
| 611 | |
| 612 | term->array = $2; |
| 613 | $$ = term; |
| 614 | } |
| 615 | | |
| 616 | PE_NAME array '=' PE_VALUE |
| 617 | { |
| 618 | struct parse_events_term *term; |
| 619 | |
| 620 | ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER, |
| 621 | $1, $4, false, &@1, &@4)); |
| 622 | term->array = $2; |
| 623 | $$ = term; |
| 624 | } |
| 625 | | |
| 626 | PE_DRV_CFG_TERM |
| 627 | { |
| 628 | struct parse_events_term *term; |
| 629 | |
| 630 | ABORT_ON(parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG, |
| 631 | $1, $1, &@1, NULL)); |
| 632 | $$ = term; |
| 633 | } |
| 634 | |
| 635 | array: |
| 636 | '[' array_terms ']' |
| 637 | { |
| 638 | $$ = $2; |
| 639 | } |
| 640 | | |
| 641 | PE_ARRAY_ALL |
| 642 | { |
| 643 | $$.nr_ranges = 0; |
| 644 | $$.ranges = NULL; |
| 645 | } |
| 646 | |
| 647 | array_terms: |
| 648 | array_terms ',' array_term |
| 649 | { |
| 650 | struct parse_events_array new_array; |
| 651 | |
| 652 | new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges; |
| 653 | new_array.ranges = malloc(sizeof(new_array.ranges[0]) * |
| 654 | new_array.nr_ranges); |
| 655 | ABORT_ON(!new_array.ranges); |
| 656 | memcpy(&new_array.ranges[0], $1.ranges, |
| 657 | $1.nr_ranges * sizeof(new_array.ranges[0])); |
| 658 | memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges, |
| 659 | $3.nr_ranges * sizeof(new_array.ranges[0])); |
| 660 | free($1.ranges); |
| 661 | free($3.ranges); |
| 662 | $$ = new_array; |
| 663 | } |
| 664 | | |
| 665 | array_term |
| 666 | |
| 667 | array_term: |
| 668 | PE_VALUE |
| 669 | { |
| 670 | struct parse_events_array array; |
| 671 | |
| 672 | array.nr_ranges = 1; |
| 673 | array.ranges = malloc(sizeof(array.ranges[0])); |
| 674 | ABORT_ON(!array.ranges); |
| 675 | array.ranges[0].start = $1; |
| 676 | array.ranges[0].length = 1; |
| 677 | $$ = array; |
| 678 | } |
| 679 | | |
| 680 | PE_VALUE PE_ARRAY_RANGE PE_VALUE |
| 681 | { |
| 682 | struct parse_events_array array; |
| 683 | |
| 684 | ABORT_ON($3 < $1); |
| 685 | array.nr_ranges = 1; |
| 686 | array.ranges = malloc(sizeof(array.ranges[0])); |
| 687 | ABORT_ON(!array.ranges); |
| 688 | array.ranges[0].start = $1; |
| 689 | array.ranges[0].length = $3 - $1 + 1; |
| 690 | $$ = array; |
| 691 | } |
| 692 | |
| 693 | sep_dc: ':' | |
| 694 | |
| 695 | sep_slash_dc: '/' | ':' | |
| 696 | |
| 697 | %% |
| 698 | |
| 699 | void parse_events_error(YYLTYPE *loc, void *parse_state, |
| 700 | void *scanner __maybe_unused, |
| 701 | char const *msg __maybe_unused) |
| 702 | { |
| 703 | parse_events_evlist_error(parse_state, loc->last_column, "parser error"); |
| 704 | } |