parse-events.y 6.0 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_START_EVENTS PE_START_TERMS
29
%token PE_VALUE PE_VALUE_SYM_HW PE_VALUE_SYM_SW PE_RAW PE_TERM
30 31 32 33 34 35
%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
36 37
%type <num> PE_VALUE_SYM_HW
%type <num> PE_VALUE_SYM_SW
38
%type <num> PE_RAW
39
%type <num> PE_TERM
40 41 42 43 44
%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
45
%type <num> value_sym
46 47
%type <head> event_config
%type <term> event_term
48 49 50 51 52 53 54 55
%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
56 57 58 59

%union
{
	char *str;
60
	u64 num;
61 62
	struct list_head *head;
	struct parse_events__term *term;
63 64 65
}
%%

66 67 68 69 70
start:
PE_START_EVENTS events
|
PE_START_TERMS  terms

71 72 73 74 75 76
events:
events ',' event | event

event:
event_def PE_MODIFIER_EVENT
{
77 78
	struct parse_events_data__events *data = _data;

79 80 81 82 83
	/*
	 * Apply modifier on all events added by single event definition
	 * (there could be more events added for multiple tracepoint
	 * definitions via '*?'.
	 */
84
	ABORT_ON(parse_events_modifier($1, $2));
85
	parse_events_update_lists($1, &data->list);
86 87 88
}
|
event_def
89
{
90 91 92
	struct parse_events_data__events *data = _data;

	parse_events_update_lists($1, &data->list);
93
}
94

95 96
event_def: event_pmu |
	   event_legacy_symbol |
97 98 99 100 101 102
	   event_legacy_cache sep_dc |
	   event_legacy_mem |
	   event_legacy_tracepoint sep_dc |
	   event_legacy_numeric sep_dc |
	   event_legacy_raw sep_dc

103 104 105
event_pmu:
PE_NAME '/' event_config '/'
{
106
	struct parse_events_data__events *data = _data;
107 108
	struct list_head *list = NULL;

109
	ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
110
	parse_events__free_terms($3);
111
	$$ = list;
112 113
}

114 115 116 117 118
value_sym:
PE_VALUE_SYM_HW
|
PE_VALUE_SYM_SW

119
event_legacy_symbol:
120
value_sym '/' event_config '/'
121
{
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, $3));
129
	parse_events__free_terms($3);
130
	$$ = list;
131 132
}
|
133
value_sym sep_slash_dc
134
{
135
	struct parse_events_data__events *data = _data;
136
	struct list_head *list = NULL;
137 138 139
	int type = $1 >> 16;
	int config = $1 & 255;

140 141
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  type, config, NULL));
142
	$$ = list;
143 144 145 146 147
}

event_legacy_cache:
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
{
148
	struct parse_events_data__events *data = _data;
149 150
	struct list_head *list = NULL;

151
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
152
	$$ = list;
153 154 155 156
}
|
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
{
157
	struct parse_events_data__events *data = _data;
158 159
	struct list_head *list = NULL;

160
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
161
	$$ = list;
162 163 164 165
}
|
PE_NAME_CACHE_TYPE
{
166
	struct parse_events_data__events *data = _data;
167 168
	struct list_head *list = NULL;

169
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
170
	$$ = list;
171 172 173 174 175
}

event_legacy_mem:
PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
176
	struct parse_events_data__events *data = _data;
177 178
	struct list_head *list = NULL;

179 180
	ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
					     (void *) $2, $4));
181
	$$ = list;
182 183 184 185
}
|
PE_PREFIX_MEM PE_VALUE sep_dc
{
186
	struct parse_events_data__events *data = _data;
187 188
	struct list_head *list = NULL;

189 190
	ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
					     (void *) $2, NULL));
191
	$$ = list;
192 193 194 195 196
}

event_legacy_tracepoint:
PE_NAME ':' PE_NAME
{
197
	struct parse_events_data__events *data = _data;
198 199
	struct list_head *list = NULL;

200
	ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
201
	$$ = list;
202 203 204 205 206
}

event_legacy_numeric:
PE_VALUE ':' PE_VALUE
{
207
	struct parse_events_data__events *data = _data;
208 209
	struct list_head *list = NULL;

210
	ABORT_ON(parse_events_add_numeric(&list, &data->idx, (u32)$1, $3, NULL));
211
	$$ = list;
212 213 214 215 216
}

event_legacy_raw:
PE_RAW
{
217
	struct parse_events_data__events *data = _data;
218 219
	struct list_head *list = NULL;

220 221
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  PERF_TYPE_RAW, $1, NULL));
222
	$$ = list;
223 224
}

225 226 227 228 229 230
terms: event_config
{
	struct parse_events_data__terms *data = _data;
	data->terms = $1;
}

231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257
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;

258 259
	ABORT_ON(parse_events__term_str(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $3));
260 261 262 263 264 265 266
	$$ = term;
}
|
PE_NAME '=' PE_VALUE
{
	struct parse_events__term *term;

267 268
	ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, $3));
269 270 271 272 273 274 275
	$$ = term;
}
|
PE_NAME
{
	struct parse_events__term *term;

276 277
	ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
					$1, 1));
278 279 280
	$$ = term;
}
|
281 282 283 284
PE_TERM '=' PE_NAME
{
	struct parse_events__term *term;

285
	ABORT_ON(parse_events__term_str(&term, (int)$1, NULL, $3));
286 287 288
	$$ = term;
}
|
289 290 291 292
PE_TERM '=' PE_VALUE
{
	struct parse_events__term *term;

293
	ABORT_ON(parse_events__term_num(&term, (int)$1, NULL, $3));
294 295 296 297 298 299 300
	$$ = term;
}
|
PE_TERM
{
	struct parse_events__term *term;

301
	ABORT_ON(parse_events__term_num(&term, (int)$1, NULL, 1));
302
	$$ = term;
303 304 305 306
}

sep_dc: ':' |

307 308
sep_slash_dc: '/' | ':' |

309 310
%%

311
void parse_events_error(void *data __used, void *scanner __used,
312 313 314
			char const *msg __used)
{
}