parse-events.y 18.1 KB
Newer Older
1
%define api.pure full
2
%parse-param {void *_parse_state}
3 4
%parse-param {void *scanner}
%lex-param {void* scanner}
5
%locations
6 7 8 9 10

%{

#define YYDEBUG 1

11
#include <fnmatch.h>
12
#include <stdio.h>
13
#include <linux/compiler.h>
B
Borislav Petkov 已提交
14
#include <linux/types.h>
15
#include <linux/zalloc.h>
16
#include "pmu.h"
17
#include "evsel.h"
18
#include "parse-events.h"
19
#include "parse-events-bison.h"
20

21
void parse_events_error(YYLTYPE *loc, void *parse_state, void *scanner, char const *msg);
22

23 24 25 26 27 28
#define ABORT_ON(val) \
do { \
	if (val) \
		YYABORT; \
} while (0)

29
static struct list_head* alloc_list(void)
30 31 32 33 34 35 36 37 38 39
{
	struct list_head *list;

	list = malloc(sizeof(*list));
	if (!list)
		return NULL;

	INIT_LIST_HEAD(list);
	return list;
}
40

41 42 43 44 45 46
static void free_list_evsel(struct list_head* list_evsel)
{
	struct evsel *evsel, *tmp;

	list_for_each_entry_safe(evsel, tmp, list_evsel, core.node) {
		list_del_init(&evsel->core.node);
47
		evsel__delete(evsel);
48 49 50 51
	}
	free(list_evsel);
}

52
static void inc_group_count(struct list_head *list,
53
		       struct parse_events_state *parse_state)
54 55 56
{
	/* Count groups only have more than 1 members */
	if (!list_is_last(list->next, list))
57
		parse_state->nr_groups++;
58 59
}

60 61
%}

62
%token PE_START_EVENTS PE_START_TERMS
63
%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
64
%token PE_VALUE_SYM_TOOL
65
%token PE_EVENT_NAME
66
%token PE_NAME
67
%token PE_BPF_OBJECT PE_BPF_SOURCE
68 69
%token PE_MODIFIER_EVENT PE_MODIFIER_BP
%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
70
%token PE_PREFIX_MEM PE_PREFIX_RAW PE_PREFIX_GROUP
71
%token PE_ERROR
J
Jiri Olsa 已提交
72
%token PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
73
%token PE_ARRAY_ALL PE_ARRAY_RANGE
74
%token PE_DRV_CFG_TERM
75
%type <num> PE_VALUE
76 77
%type <num> PE_VALUE_SYM_HW
%type <num> PE_VALUE_SYM_SW
78
%type <num> PE_VALUE_SYM_TOOL
79
%type <num> PE_RAW
80
%type <num> PE_TERM
81
%type <num> value_sym
82
%type <str> PE_NAME
83
%type <str> PE_BPF_OBJECT
84
%type <str> PE_BPF_SOURCE
85 86 87 88
%type <str> PE_NAME_CACHE_TYPE
%type <str> PE_NAME_CACHE_OP_RESULT
%type <str> PE_MODIFIER_EVENT
%type <str> PE_MODIFIER_BP
89
%type <str> PE_EVENT_NAME
J
Jiri Olsa 已提交
90
%type <str> PE_PMU_EVENT_PRE PE_PMU_EVENT_SUF PE_KERNEL_PMU_EVENT PE_PMU_EVENT_FAKE
91
%type <str> PE_DRV_CFG_TERM
92
%type <str> event_pmu_name
93
%destructor { free ($$); } <str>
94
%type <term> event_term
95
%destructor { parse_events_term__delete ($$); } <term>
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
%type <list_terms> event_config
%type <list_terms> opt_event_config
%type <list_terms> opt_pmu_config
%destructor { parse_events_terms__delete ($$); } <list_terms>
%type <list_evsel> event_pmu
%type <list_evsel> event_legacy_symbol
%type <list_evsel> event_legacy_cache
%type <list_evsel> event_legacy_mem
%type <list_evsel> event_legacy_tracepoint
%type <list_evsel> event_legacy_numeric
%type <list_evsel> event_legacy_raw
%type <list_evsel> event_bpf_file
%type <list_evsel> event_def
%type <list_evsel> event_mod
%type <list_evsel> event_name
%type <list_evsel> event
%type <list_evsel> events
%type <list_evsel> group_def
%type <list_evsel> group
%type <list_evsel> groups
%destructor { free_list_evsel ($$); } <list_evsel>
117
%type <tracepoint_name> tracepoint_name
118
%destructor { free ($$.sys); free ($$.event); } <tracepoint_name>
119 120 121
%type <array> array
%type <array> array_term
%type <array> array_terms
122
%destructor { free ($$.ranges); } <array>
123 124 125 126

%union
{
	char *str;
127
	u64 num;
128 129
	struct list_head *list_evsel;
	struct list_head *list_terms;
130
	struct parse_events_term *term;
131 132 133 134
	struct tracepoint_name {
		char *sys;
		char *event;
	} tracepoint_name;
135
	struct parse_events_array array;
136 137 138
}
%%

139
start:
140
PE_START_EVENTS start_events
141
|
142 143 144 145
PE_START_TERMS  start_terms

start_events: groups
{
146
	struct parse_events_state *parse_state = _parse_state;
147

148
	/* frees $1 */
149
	parse_events_update_lists($1, &parse_state->list);
150 151 152 153 154 155 156 157
}

groups:
groups ',' group
{
	struct list_head *list  = $1;
	struct list_head *group = $3;

158
	/* frees $3 */
159 160 161 162 163 164 165 166 167
	parse_events_update_lists(group, list);
	$$ = list;
}
|
groups ',' event
{
	struct list_head *list  = $1;
	struct list_head *event = $3;

168
	/* frees $3 */
169 170 171 172 173 174 175 176 177 178 179 180
	parse_events_update_lists(event, list);
	$$ = list;
}
|
group
|
event

group:
group_def ':' PE_MODIFIER_EVENT
{
	struct list_head *list = $1;
181
	int err;
182

183 184 185
	err = parse_events__modifier_group(list, $3);
	free($3);
	if (err) {
186 187 188
		struct parse_events_state *parse_state = _parse_state;
		struct parse_events_error *error = parse_state->error;

189
		parse_events_error__handle(error, @3.first_column,
190
					   strdup("Bad modifier"), NULL);
191 192 193
		free_list_evsel(list);
		YYABORT;
	}
194 195 196 197 198 199 200 201 202 203
	$$ = list;
}
|
group_def

group_def:
PE_NAME '{' events '}'
{
	struct list_head *list = $3;

204
	inc_group_count(list, _parse_state);
205
	parse_events__set_leader($1, list, _parse_state);
206
	free($1);
207 208 209 210 211 212 213
	$$ = list;
}
|
'{' events '}'
{
	struct list_head *list = $2;

214
	inc_group_count(list, _parse_state);
215
	parse_events__set_leader(NULL, list, _parse_state);
216 217
	$$ = list;
}
218

219
events:
220 221 222 223 224
events ',' event
{
	struct list_head *event = $3;
	struct list_head *list  = $1;

225
	/* frees $3 */
226 227 228 229 230
	parse_events_update_lists(event, list);
	$$ = list;
}
|
event
231

232 233 234 235
event: event_mod

event_mod:
event_name PE_MODIFIER_EVENT
236
{
237
	struct list_head *list = $1;
238
	int err;
239

240 241 242 243 244
	/*
	 * Apply modifier on all events added by single event definition
	 * (there could be more events added for multiple tracepoint
	 * definitions via '*?'.
	 */
245 246 247
	err = parse_events__modifier_event(list, $2, false);
	free($2);
	if (err) {
248 249 250
		struct parse_events_state *parse_state = _parse_state;
		struct parse_events_error *error = parse_state->error;

251
		parse_events_error__handle(error, @2.first_column,
252
					   strdup("Bad modifier"), NULL);
253 254 255
		free_list_evsel(list);
		YYABORT;
	}
256
	$$ = list;
257 258
}
|
259 260 261 262 263
event_name

event_name:
PE_EVENT_NAME event_def
{
264 265 266
	int err;

	err = parse_events_name($2, $1);
267
	free($1);
268 269 270 271
	if (err) {
		free_list_evsel($2);
		YYABORT;
	}
272 273 274
	$$ = $2;
}
|
275 276
event_def

277 278
event_def: event_pmu |
	   event_legacy_symbol |
279 280 281 282
	   event_legacy_cache sep_dc |
	   event_legacy_mem |
	   event_legacy_tracepoint sep_dc |
	   event_legacy_numeric sep_dc |
283 284
	   event_legacy_raw sep_dc |
	   event_bpf_file
285

286 287 288
event_pmu_name:
PE_NAME | PE_PMU_EVENT_PRE

289
event_pmu:
290
event_pmu_name opt_pmu_config
291
{
292 293
	struct parse_events_state *parse_state = _parse_state;
	struct parse_events_error *error = parse_state->error;
294 295 296 297 298 299 300
	struct list_head *list = NULL, *orig_terms = NULL, *terms= NULL;
	char *pattern = NULL;

#define CLEANUP_YYABORT					\
	do {						\
		parse_events_terms__delete($2);		\
		parse_events_terms__delete(orig_terms);	\
301
		free(list);				\
302 303 304 305
		free($1);				\
		free(pattern);				\
		YYABORT;				\
	} while(0)
306

307
	if (parse_events_copy_term_list($2, &orig_terms))
308
		CLEANUP_YYABORT;
309

310 311 312
	if (error)
		error->idx = @1.first_column;

313
	list = alloc_list();
314 315
	if (!list)
		CLEANUP_YYABORT;
316
	if (parse_events_add_pmu(_parse_state, list, $1, $2, false, false)) {
317 318
		struct perf_pmu *pmu = NULL;
		int ok = 0;
319 320

		if (asprintf(&pattern, "%s*", $1) < 0)
321
			CLEANUP_YYABORT;
322 323 324 325

		while ((pmu = perf_pmu__scan(pmu)) != NULL) {
			char *name = pmu->name;

326 327 328
			if (!strncmp(name, "uncore_", 7) &&
			    strncmp($1, "uncore_", 7))
				name += 7;
K
Kan Liang 已提交
329 330
			if (!perf_pmu__match(pattern, name, $1) ||
			    !perf_pmu__match(pattern, pmu->alias_name, $1)) {
331 332
				if (parse_events_copy_term_list(orig_terms, &terms))
					CLEANUP_YYABORT;
333
				if (!parse_events_add_pmu(_parse_state, list, pmu->name, terms, true, false))
334 335 336 337
					ok++;
				parse_events_terms__delete(terms);
			}
		}
338

339
		if (!ok)
340
			CLEANUP_YYABORT;
341
	}
342
	parse_events_terms__delete($2);
343
	parse_events_terms__delete(orig_terms);
344
	free(pattern);
345
	free($1);
346
	$$ = list;
347
#undef CLEANUP_YYABORT
348
}
349
|
350 351 352
PE_KERNEL_PMU_EVENT sep_dc
{
	struct list_head *list;
353
	int err;
354

355 356 357 358 359 360 361 362 363 364 365 366 367 368
	err = parse_events_multi_pmu_add(_parse_state, $1, NULL, &list);
	free($1);
	if (err < 0)
		YYABORT;
	$$ = list;
}
|
PE_KERNEL_PMU_EVENT opt_pmu_config
{
	struct list_head *list;
	int err;

	/* frees $2 */
	err = parse_events_multi_pmu_add(_parse_state, $1, $2, &list);
369 370
	free($1);
	if (err < 0)
371
		YYABORT;
372 373 374 375 376 377 378 379
	$$ = list;
}
|
PE_PMU_EVENT_PRE '-' PE_PMU_EVENT_SUF sep_dc
{
	struct list_head *list;
	char pmu_name[128];

380
	snprintf(pmu_name, sizeof(pmu_name), "%s-%s", $1, $3);
381 382
	free($1);
	free($3);
383
	if (parse_events_multi_pmu_add(_parse_state, pmu_name, NULL, &list) < 0)
384
		YYABORT;
385 386
	$$ = list;
}
J
Jiri Olsa 已提交
387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423
|
PE_PMU_EVENT_FAKE sep_dc
{
	struct list_head *list;
	int err;

	list = alloc_list();
	if (!list)
		YYABORT;

	err = parse_events_add_pmu(_parse_state, list, $1, NULL, false, false);
	free($1);
	if (err < 0) {
		free(list);
		YYABORT;
	}
	$$ = list;
}
|
PE_PMU_EVENT_FAKE opt_pmu_config
{
	struct list_head *list;
	int err;

	list = alloc_list();
	if (!list)
		YYABORT;

	err = parse_events_add_pmu(_parse_state, list, $1, $2, false, false);
	free($1);
	parse_events_terms__delete($2);
	if (err < 0) {
		free(list);
		YYABORT;
	}
	$$ = list;
}
424

425 426 427 428 429
value_sym:
PE_VALUE_SYM_HW
|
PE_VALUE_SYM_SW

430
event_legacy_symbol:
431
value_sym '/' event_config '/'
432
{
433
	struct list_head *list;
434 435
	int type = $1 >> 16;
	int config = $1 & 255;
436
	int err;
437

438 439
	list = alloc_list();
	ABORT_ON(!list);
440
	err = parse_events_add_numeric(_parse_state, list, type, config, $3);
441
	parse_events_terms__delete($3);
442 443 444 445
	if (err) {
		free_list_evsel(list);
		YYABORT;
	}
446
	$$ = list;
447 448
}
|
449
value_sym sep_slash_slash_dc
450
{
451
	struct list_head *list;
452 453 454
	int type = $1 >> 16;
	int config = $1 & 255;

455 456
	list = alloc_list();
	ABORT_ON(!list);
457
	ABORT_ON(parse_events_add_numeric(_parse_state, list, type, config, NULL));
458
	$$ = list;
459
}
460 461 462 463 464
|
PE_VALUE_SYM_TOOL sep_slash_slash_dc
{
	struct list_head *list;

465 466
	list = alloc_list();
	ABORT_ON(!list);
467 468 469
	ABORT_ON(parse_events_add_tool(_parse_state, list, $1));
	$$ = list;
}
470 471

event_legacy_cache:
472
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT opt_event_config
473
{
474 475
	struct parse_events_state *parse_state = _parse_state;
	struct parse_events_error *error = parse_state->error;
476
	struct list_head *list;
477
	int err;
478

479 480
	list = alloc_list();
	ABORT_ON(!list);
481 482
	err = parse_events_add_cache(list, &parse_state->idx, $1, $3, $5, error, $6,
				     parse_state);
483
	parse_events_terms__delete($6);
484 485 486 487 488 489 490
	free($1);
	free($3);
	free($5);
	if (err) {
		free_list_evsel(list);
		YYABORT;
	}
491
	$$ = list;
492 493
}
|
494
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT opt_event_config
495
{
496 497
	struct parse_events_state *parse_state = _parse_state;
	struct parse_events_error *error = parse_state->error;
498
	struct list_head *list;
499
	int err;
500

501 502
	list = alloc_list();
	ABORT_ON(!list);
503 504
	err = parse_events_add_cache(list, &parse_state->idx, $1, $3, NULL, error, $4,
				     parse_state);
505
	parse_events_terms__delete($4);
506 507 508 509 510 511
	free($1);
	free($3);
	if (err) {
		free_list_evsel(list);
		YYABORT;
	}
512
	$$ = list;
513 514
}
|
515
PE_NAME_CACHE_TYPE opt_event_config
516
{
517 518
	struct parse_events_state *parse_state = _parse_state;
	struct parse_events_error *error = parse_state->error;
519
	struct list_head *list;
520
	int err;
521

522 523
	list = alloc_list();
	ABORT_ON(!list);
524 525
	err = parse_events_add_cache(list, &parse_state->idx, $1, NULL, NULL, error, $2,
				     parse_state);
526
	parse_events_terms__delete($2);
527 528 529 530 531
	free($1);
	if (err) {
		free_list_evsel(list);
		YYABORT;
	}
532
	$$ = list;
533 534 535
}

event_legacy_mem:
536 537
PE_PREFIX_MEM PE_VALUE '/' PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
538
	struct parse_events_state *parse_state = _parse_state;
539
	struct list_head *list;
540
	int err;
541

542 543
	list = alloc_list();
	ABORT_ON(!list);
544
	err = parse_events_add_breakpoint(list, &parse_state->idx,
545
					  $2, $6, $4);
546 547 548 549 550
	free($6);
	if (err) {
		free(list);
		YYABORT;
	}
551 552 553 554 555
	$$ = list;
}
|
PE_PREFIX_MEM PE_VALUE '/' PE_VALUE sep_dc
{
556
	struct parse_events_state *parse_state = _parse_state;
557 558
	struct list_head *list;

559 560
	list = alloc_list();
	ABORT_ON(!list);
561
	if (parse_events_add_breakpoint(list, &parse_state->idx,
562
					$2, NULL, $4)) {
563 564 565
		free(list);
		YYABORT;
	}
566 567 568
	$$ = list;
}
|
569 570
PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
571
	struct parse_events_state *parse_state = _parse_state;
572
	struct list_head *list;
573
	int err;
574

575 576
	list = alloc_list();
	ABORT_ON(!list);
577
	err = parse_events_add_breakpoint(list, &parse_state->idx,
578
					  $2, $4, 0);
579 580 581 582 583
	free($4);
	if (err) {
		free(list);
		YYABORT;
	}
584
	$$ = list;
585 586 587 588
}
|
PE_PREFIX_MEM PE_VALUE sep_dc
{
589
	struct parse_events_state *parse_state = _parse_state;
590
	struct list_head *list;
591

592 593
	list = alloc_list();
	ABORT_ON(!list);
594
	if (parse_events_add_breakpoint(list, &parse_state->idx,
595
					$2, NULL, 0)) {
596 597 598
		free(list);
		YYABORT;
	}
599
	$$ = list;
600 601 602
}

event_legacy_tracepoint:
603
tracepoint_name opt_event_config
604
{
605 606
	struct parse_events_state *parse_state = _parse_state;
	struct parse_events_error *error = parse_state->error;
607
	struct list_head *list;
608
	int err;
609

610 611
	list = alloc_list();
	ABORT_ON(!list);
612 613 614
	if (error)
		error->idx = @1.first_column;

615 616
	err = parse_events_add_tracepoint(list, &parse_state->idx, $1.sys, $1.event,
					error, $2);
617

618 619 620 621 622
	parse_events_terms__delete($2);
	free($1.sys);
	free($1.event);
	if (err) {
		free(list);
623
		YYABORT;
624
	}
625 626
	$$ = list;
}
627 628 629 630 631 632

tracepoint_name:
PE_NAME '-' PE_NAME ':' PE_NAME
{
	struct tracepoint_name tracepoint;

633
	ABORT_ON(asprintf(&tracepoint.sys, "%s-%s", $1, $3) < 0);
634
	tracepoint.event = $5;
635 636
	free($1);
	free($3);
637 638
	$$ = tracepoint;
}
639
|
640 641
PE_NAME ':' PE_NAME
{
642
	struct tracepoint_name tracepoint = {$1, $3};
643

644
	$$ = tracepoint;
645 646 647
}

event_legacy_numeric:
648
PE_VALUE ':' PE_VALUE opt_event_config
649
{
650
	struct list_head *list;
651
	int err;
652

653 654
	list = alloc_list();
	ABORT_ON(!list);
655
	err = parse_events_add_numeric(_parse_state, list, (u32)$1, $3, $4);
656
	parse_events_terms__delete($4);
657 658 659 660
	if (err) {
		free(list);
		YYABORT;
	}
661
	$$ = list;
662 663 664
}

event_legacy_raw:
665
PE_RAW opt_event_config
666
{
667
	struct list_head *list;
668
	int err;
669

670 671
	list = alloc_list();
	ABORT_ON(!list);
672
	err = parse_events_add_numeric(_parse_state, list, PERF_TYPE_RAW, $1, $2);
673
	parse_events_terms__delete($2);
674 675 676 677
	if (err) {
		free(list);
		YYABORT;
	}
678
	$$ = list;
679 680
}

681
event_bpf_file:
682
PE_BPF_OBJECT opt_event_config
683
{
684
	struct parse_events_state *parse_state = _parse_state;
685
	struct list_head *list;
686
	int err;
687

688 689
	list = alloc_list();
	ABORT_ON(!list);
690
	err = parse_events_load_bpf(parse_state, list, $1, false, $2);
691
	parse_events_terms__delete($2);
692 693 694 695 696
	free($1);
	if (err) {
		free(list);
		YYABORT;
	}
697 698 699
	$$ = list;
}
|
700
PE_BPF_SOURCE opt_event_config
701 702
{
	struct list_head *list;
703
	int err;
704

705 706
	list = alloc_list();
	ABORT_ON(!list);
707
	err = parse_events_load_bpf(_parse_state, list, $1, true, $2);
708
	parse_events_terms__delete($2);
709 710 711 712
	if (err) {
		free(list);
		YYABORT;
	}
713 714 715
	$$ = list;
}

716 717 718 719 720 721 722 723 724 725 726 727 728 729 730
opt_event_config:
'/' event_config '/'
{
	$$ = $2;
}
|
'/' '/'
{
	$$ = NULL;
}
|
{
	$$ = NULL;
}

731 732 733 734 735 736 737 738 739 740 741
opt_pmu_config:
'/' event_config '/'
{
	$$ = $2;
}
|
'/' '/'
{
	$$ = NULL;
}

742
start_terms: event_config
743
{
744
	struct parse_events_state *parse_state = _parse_state;
745 746 747 748
	if (parse_state->terms) {
		parse_events_terms__delete ($1);
		YYABORT;
	}
749
	parse_state->terms = $1;
750 751
}

752 753 754 755
event_config:
event_config ',' event_term
{
	struct list_head *head = $1;
756
	struct parse_events_term *term = $3;
757

758
	if (!head) {
759
		parse_events_term__delete(term);
760 761
		YYABORT;
	}
762 763 764 765 766 767 768
	list_add_tail(&term->list, head);
	$$ = $1;
}
|
event_term
{
	struct list_head *head = malloc(sizeof(*head));
769
	struct parse_events_term *term = $1;
770 771 772 773 774 775 776 777

	ABORT_ON(!head);
	INIT_LIST_HEAD(head);
	list_add_tail(&term->list, head);
	$$ = head;
}

event_term:
778 779 780 781 782 783 784 785 786
PE_RAW
{
	struct parse_events_term *term;

	ABORT_ON(parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_CONFIG,
					NULL, $1, false, &@1, NULL));
	$$ = term;
}
|
787 788
PE_NAME '=' PE_NAME
{
789
	struct parse_events_term *term;
790

791 792 793 794 795 796
	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $3, &@1, &@3)) {
		free($1);
		free($3);
		YYABORT;
	}
797 798 799 800 801
	$$ = term;
}
|
PE_NAME '=' PE_VALUE
{
802
	struct parse_events_term *term;
803

804 805 806 807 808
	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $3, false, &@1, &@3)) {
		free($1);
		YYABORT;
	}
809 810 811
	$$ = term;
}
|
812 813
PE_NAME '=' PE_VALUE_SYM_HW
{
814
	struct parse_events_term *term;
815 816
	int config = $3 & 255;

817 818 819 820
	if (parse_events_term__sym_hw(&term, $1, config)) {
		free($1);
		YYABORT;
	}
821 822 823
	$$ = term;
}
|
824 825
PE_NAME
{
826
	struct parse_events_term *term;
827

828 829 830 831 832
	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, 1, true, &@1, NULL)) {
		free($1);
		YYABORT;
	}
833 834 835
	$$ = term;
}
|
836 837
PE_VALUE_SYM_HW
{
838
	struct parse_events_term *term;
839 840
	int config = $1 & 255;

841
	ABORT_ON(parse_events_term__sym_hw(&term, NULL, config));
842 843 844
	$$ = term;
}
|
845 846
PE_TERM '=' PE_NAME
{
847
	struct parse_events_term *term;
848

849 850 851 852
	if (parse_events_term__str(&term, (int)$1, NULL, $3, &@1, &@3)) {
		free($3);
		YYABORT;
	}
853 854 855
	$$ = term;
}
|
856 857
PE_TERM '=' PE_VALUE
{
858
	struct parse_events_term *term;
859

860
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, $3, false, &@1, &@3));
861 862 863 864 865
	$$ = term;
}
|
PE_TERM
{
866
	struct parse_events_term *term;
867

868
	ABORT_ON(parse_events_term__num(&term, (int)$1, NULL, 1, true, &@1, NULL));
869
	$$ = term;
870
}
871 872 873 874 875
|
PE_NAME array '=' PE_NAME
{
	struct parse_events_term *term;

876 877 878 879 880 881 882
	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $4, &@1, &@4)) {
		free($1);
		free($4);
		free($2.ranges);
		YYABORT;
	}
883 884 885 886 887 888 889 890
	term->array = $2;
	$$ = term;
}
|
PE_NAME array '=' PE_VALUE
{
	struct parse_events_term *term;

891 892 893 894 895 896
	if (parse_events_term__num(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $4, false, &@1, &@4)) {
		free($1);
		free($2.ranges);
		YYABORT;
	}
897 898 899
	term->array = $2;
	$$ = term;
}
900 901 902 903
|
PE_DRV_CFG_TERM
{
	struct parse_events_term *term;
904
	char *config = strdup($1);
905

906
	ABORT_ON(!config);
907 908 909 910 911 912
	if (parse_events_term__str(&term, PARSE_EVENTS__TERM_TYPE_DRV_CFG,
					config, $1, &@1, NULL)) {
		free($1);
		free(config);
		YYABORT;
	}
913 914
	$$ = term;
}
915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933

array:
'[' array_terms ']'
{
	$$ = $2;
}
|
PE_ARRAY_ALL
{
	$$.nr_ranges = 0;
	$$.ranges = NULL;
}

array_terms:
array_terms ',' array_term
{
	struct parse_events_array new_array;

	new_array.nr_ranges = $1.nr_ranges + $3.nr_ranges;
934 935 936
	new_array.ranges = realloc($1.ranges,
				sizeof(new_array.ranges[0]) *
				new_array.nr_ranges);
937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970
	ABORT_ON(!new_array.ranges);
	memcpy(&new_array.ranges[$1.nr_ranges], $3.ranges,
	       $3.nr_ranges * sizeof(new_array.ranges[0]));
	free($3.ranges);
	$$ = new_array;
}
|
array_term

array_term:
PE_VALUE
{
	struct parse_events_array array;

	array.nr_ranges = 1;
	array.ranges = malloc(sizeof(array.ranges[0]));
	ABORT_ON(!array.ranges);
	array.ranges[0].start = $1;
	array.ranges[0].length = 1;
	$$ = array;
}
|
PE_VALUE PE_ARRAY_RANGE PE_VALUE
{
	struct parse_events_array array;

	ABORT_ON($3 < $1);
	array.nr_ranges = 1;
	array.ranges = malloc(sizeof(array.ranges[0]));
	ABORT_ON(!array.ranges);
	array.ranges[0].start = $1;
	array.ranges[0].length = $3 - $1 + 1;
	$$ = array;
}
971 972 973

sep_dc: ':' |

974
sep_slash_slash_dc: '/' '/' | ':' |
975

976 977
%%

978
void parse_events_error(YYLTYPE *loc, void *parse_state,
979
			void *scanner __maybe_unused,
980
			char const *msg __maybe_unused)
981
{
982
	parse_events_evlist_error(parse_state, loc->last_column, "parser error");
983
}