parse-events.y 5.7 KB
Newer Older
1
%pure-parser
2
%name-prefix "parse_events_"
3
%parse-param {void *_data}
4 5
%parse-param {void *scanner}
%lex-param {void* scanner}
6 7 8 9 10 11 12 13 14 15

%{

#define YYDEBUG 1

#include <linux/compiler.h>
#include <linux/list.h>
#include "types.h"
#include "util.h"
#include "parse-events.h"
16
#include "parse-events-bison.h"
17

18
extern int parse_events_lex (YYSTYPE* lvalp, void* scanner);
19 20 21 22 23 24 25 26 27

#define ABORT_ON(val) \
do { \
	if (val) \
		YYABORT; \
} while (0)

%}

28
%token PE_VALUE PE_VALUE_SYM PE_RAW PE_TERM
29 30 31 32 33 34 35 36
%token PE_NAME
%token PE_MODIFIER_EVENT PE_MODIFIER_BP
%token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
%token PE_PREFIX_MEM PE_PREFIX_RAW
%token PE_ERROR
%type <num> PE_VALUE
%type <num> PE_VALUE_SYM
%type <num> PE_RAW
37
%type <num> PE_TERM
38 39 40 41 42
%type <str> PE_NAME
%type <str> PE_NAME_CACHE_TYPE
%type <str> PE_NAME_CACHE_OP_RESULT
%type <str> PE_MODIFIER_EVENT
%type <str> PE_MODIFIER_BP
43 44
%type <head> event_config
%type <term> event_term
45 46 47 48 49 50 51 52
%type <head> event_pmu
%type <head> event_legacy_symbol
%type <head> event_legacy_cache
%type <head> event_legacy_mem
%type <head> event_legacy_tracepoint
%type <head> event_legacy_numeric
%type <head> event_legacy_raw
%type <head> event_def
53 54 55 56 57

%union
{
	char *str;
	unsigned long num;
58 59
	struct list_head *head;
	struct parse_events__term *term;
60 61 62 63 64 65 66 67 68
}
%%

events:
events ',' event | event

event:
event_def PE_MODIFIER_EVENT
{
69 70
	struct parse_events_data__events *data = _data;

71 72 73 74 75
	/*
	 * Apply modifier on all events added by single event definition
	 * (there could be more events added for multiple tracepoint
	 * definitions via '*?'.
	 */
76
	ABORT_ON(parse_events_modifier($1, $2));
77
	parse_events_update_lists($1, &data->list);
78 79 80
}
|
event_def
81
{
82 83 84
	struct parse_events_data__events *data = _data;

	parse_events_update_lists($1, &data->list);
85
}
86

87 88
event_def: event_pmu |
	   event_legacy_symbol |
89 90 91 92 93 94
	   event_legacy_cache sep_dc |
	   event_legacy_mem |
	   event_legacy_tracepoint sep_dc |
	   event_legacy_numeric sep_dc |
	   event_legacy_raw sep_dc

95 96 97
event_pmu:
PE_NAME '/' event_config '/'
{
98
	struct parse_events_data__events *data = _data;
99 100
	struct list_head *list = NULL;

101
	ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
102
	parse_events__free_terms($3);
103
	$$ = list;
104 105
}

106
event_legacy_symbol:
107
PE_VALUE_SYM '/' event_config '/'
108
{
109
	struct parse_events_data__events *data = _data;
110
	struct list_head *list = NULL;
111 112 113
	int type = $1 >> 16;
	int config = $1 & 255;

114 115
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  type, config, $3));
116
	parse_events__free_terms($3);
117
	$$ = list;
118 119 120 121
}
|
PE_VALUE_SYM sep_slash_dc
{
122
	struct parse_events_data__events *data = _data;
123
	struct list_head *list = NULL;
124 125 126
	int type = $1 >> 16;
	int config = $1 & 255;

127 128
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  type, config, NULL));
129
	$$ = list;
130 131 132 133 134
}

event_legacy_cache:
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
{
135
	struct parse_events_data__events *data = _data;
136 137
	struct list_head *list = NULL;

138
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
139
	$$ = list;
140 141 142 143
}
|
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
{
144
	struct parse_events_data__events *data = _data;
145 146
	struct list_head *list = NULL;

147
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
148
	$$ = list;
149 150 151 152
}
|
PE_NAME_CACHE_TYPE
{
153
	struct parse_events_data__events *data = _data;
154 155
	struct list_head *list = NULL;

156
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
157
	$$ = list;
158 159 160 161 162
}

event_legacy_mem:
PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
163
	struct parse_events_data__events *data = _data;
164 165
	struct list_head *list = NULL;

166 167
	ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
					     (void *) $2, $4));
168
	$$ = list;
169 170 171 172
}
|
PE_PREFIX_MEM PE_VALUE sep_dc
{
173
	struct parse_events_data__events *data = _data;
174 175
	struct list_head *list = NULL;

176 177
	ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
					     (void *) $2, NULL));
178
	$$ = list;
179 180 181 182 183
}

event_legacy_tracepoint:
PE_NAME ':' PE_NAME
{
184
	struct parse_events_data__events *data = _data;
185 186
	struct list_head *list = NULL;

187
	ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
188
	$$ = list;
189 190 191 192 193
}

event_legacy_numeric:
PE_VALUE ':' PE_VALUE
{
194
	struct parse_events_data__events *data = _data;
195 196
	struct list_head *list = NULL;

197
	ABORT_ON(parse_events_add_numeric(&list, &data->idx, $1, $3, NULL));
198
	$$ = list;
199 200 201 202 203
}

event_legacy_raw:
PE_RAW
{
204
	struct parse_events_data__events *data = _data;
205 206
	struct list_head *list = NULL;

207 208
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  PERF_TYPE_RAW, $1, NULL));
209
	$$ = list;
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
}

event_config:
event_config ',' event_term
{
	struct list_head *head = $1;
	struct parse_events__term *term = $3;

	ABORT_ON(!head);
	list_add_tail(&term->list, head);
	$$ = $1;
}
|
event_term
{
	struct list_head *head = malloc(sizeof(*head));
	struct parse_events__term *term = $1;

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

event_term:
PE_NAME '=' PE_NAME
{
	struct parse_events__term *term;

239 240
	ABORT_ON(parse_events__term_str(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $3));
241 242 243 244 245 246 247
	$$ = term;
}
|
PE_NAME '=' PE_VALUE
{
	struct parse_events__term *term;

248 249
	ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $3));
250 251 252 253 254 255 256
	$$ = term;
}
|
PE_NAME
{
	struct parse_events__term *term;

257 258
	ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, 1));
259 260 261
	$$ = term;
}
|
262 263 264 265 266 267 268 269
PE_TERM '=' PE_NAME
{
	struct parse_events__term *term;

	ABORT_ON(parse_events__term_str(&term, $1, NULL, $3));
	$$ = term;
}
|
270 271 272 273
PE_TERM '=' PE_VALUE
{
	struct parse_events__term *term;

274
	ABORT_ON(parse_events__term_num(&term, $1, NULL, $3));
275 276 277 278 279 280 281
	$$ = term;
}
|
PE_TERM
{
	struct parse_events__term *term;

282
	ABORT_ON(parse_events__term_num(&term, $1, NULL, 1));
283
	$$ = term;
284 285 286 287
}

sep_dc: ':' |

288 289
sep_slash_dc: '/' | ':' |

290 291
%%

292
void parse_events_error(void *data __used, void *scanner __used,
293 294 295
			char const *msg __used)
{
}