parse-events.y 5.6 KB
Newer Older
1 2

%name-prefix "parse_events_"
3
%parse-param {void *_data}
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24

%{

#define YYDEBUG 1

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

extern int parse_events_lex (void);

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

%}

25
%token PE_VALUE PE_VALUE_SYM PE_RAW PE_TERM
26 27 28 29 30 31 32 33
%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
34
%type <num> PE_TERM
35 36 37 38 39
%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
40 41
%type <head> event_config
%type <term> event_term
42 43 44 45 46 47 48 49
%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
50 51 52 53 54

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

events:
events ',' event | event

event:
event_def PE_MODIFIER_EVENT
{
66 67
	struct parse_events_data__events *data = _data;

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

	parse_events_update_lists($1, &data->list);
82
}
83

84 85
event_def: event_pmu |
	   event_legacy_symbol |
86 87 88 89 90 91
	   event_legacy_cache sep_dc |
	   event_legacy_mem |
	   event_legacy_tracepoint sep_dc |
	   event_legacy_numeric sep_dc |
	   event_legacy_raw sep_dc

92 93 94
event_pmu:
PE_NAME '/' event_config '/'
{
95
	struct parse_events_data__events *data = _data;
96 97
	struct list_head *list = NULL;

98
	ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
99
	parse_events__free_terms($3);
100
	$$ = list;
101 102
}

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

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

124 125
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  type, config, NULL));
126
	$$ = list;
127 128 129 130 131
}

event_legacy_cache:
PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
{
132
	struct parse_events_data__events *data = _data;
133 134
	struct list_head *list = NULL;

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

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

153
	ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
154
	$$ = list;
155 156 157 158 159
}

event_legacy_mem:
PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
{
160
	struct parse_events_data__events *data = _data;
161 162
	struct list_head *list = NULL;

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

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

event_legacy_tracepoint:
PE_NAME ':' PE_NAME
{
181
	struct parse_events_data__events *data = _data;
182 183
	struct list_head *list = NULL;

184
	ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
185
	$$ = list;
186 187 188 189 190
}

event_legacy_numeric:
PE_VALUE ':' PE_VALUE
{
191
	struct parse_events_data__events *data = _data;
192 193
	struct list_head *list = NULL;

194
	ABORT_ON(parse_events_add_numeric(&list, &data->idx, $1, $3, NULL));
195
	$$ = list;
196 197 198 199 200
}

event_legacy_raw:
PE_RAW
{
201
	struct parse_events_data__events *data = _data;
202 203
	struct list_head *list = NULL;

204 205
	ABORT_ON(parse_events_add_numeric(&list, &data->idx,
					  PERF_TYPE_RAW, $1, NULL));
206
	$$ = list;
207 208 209 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
}

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;

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

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

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

	ABORT_ON(parse_events__term_str(&term, $1, NULL, $3));
	$$ = term;
}
|
267 268 269 270
PE_TERM '=' PE_VALUE
{
	struct parse_events__term *term;

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

279
	ABORT_ON(parse_events__term_num(&term, $1, NULL, 1));
280
	$$ = term;
281 282 283 284
}

sep_dc: ':' |

285 286
sep_slash_dc: '/' | ':' |

287 288
%%

289
void parse_events_error(void *data __used,
290 291 292
			char const *msg __used)
{
}