parse-events.y 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. %pure-parser
  2. %name-prefix "parse_events_"
  3. %parse-param {void *_data}
  4. %parse-param {void *scanner}
  5. %lex-param {void* scanner}
  6. %{
  7. #define YYDEBUG 1
  8. #include <linux/compiler.h>
  9. #include <linux/list.h>
  10. #include "types.h"
  11. #include "util.h"
  12. #include "parse-events.h"
  13. #include "parse-events-bison.h"
  14. extern int parse_events_lex (YYSTYPE* lvalp, void* scanner);
  15. #define ABORT_ON(val) \
  16. do { \
  17. if (val) \
  18. YYABORT; \
  19. } while (0)
  20. %}
  21. %token PE_START_EVENTS PE_START_TERMS
  22. %token PE_VALUE PE_VALUE_SYM PE_RAW PE_TERM
  23. %token PE_NAME
  24. %token PE_MODIFIER_EVENT PE_MODIFIER_BP
  25. %token PE_NAME_CACHE_TYPE PE_NAME_CACHE_OP_RESULT
  26. %token PE_PREFIX_MEM PE_PREFIX_RAW
  27. %token PE_ERROR
  28. %type <num> PE_VALUE
  29. %type <num> PE_VALUE_SYM
  30. %type <num> PE_RAW
  31. %type <num> PE_TERM
  32. %type <str> PE_NAME
  33. %type <str> PE_NAME_CACHE_TYPE
  34. %type <str> PE_NAME_CACHE_OP_RESULT
  35. %type <str> PE_MODIFIER_EVENT
  36. %type <str> PE_MODIFIER_BP
  37. %type <head> event_config
  38. %type <term> event_term
  39. %type <head> event_pmu
  40. %type <head> event_legacy_symbol
  41. %type <head> event_legacy_cache
  42. %type <head> event_legacy_mem
  43. %type <head> event_legacy_tracepoint
  44. %type <head> event_legacy_numeric
  45. %type <head> event_legacy_raw
  46. %type <head> event_def
  47. %union
  48. {
  49. char *str;
  50. unsigned long num;
  51. struct list_head *head;
  52. struct parse_events__term *term;
  53. }
  54. %%
  55. start:
  56. PE_START_EVENTS events
  57. |
  58. PE_START_TERMS terms
  59. events:
  60. events ',' event | event
  61. event:
  62. event_def PE_MODIFIER_EVENT
  63. {
  64. struct parse_events_data__events *data = _data;
  65. /*
  66. * Apply modifier on all events added by single event definition
  67. * (there could be more events added for multiple tracepoint
  68. * definitions via '*?'.
  69. */
  70. ABORT_ON(parse_events_modifier($1, $2));
  71. parse_events_update_lists($1, &data->list);
  72. }
  73. |
  74. event_def
  75. {
  76. struct parse_events_data__events *data = _data;
  77. parse_events_update_lists($1, &data->list);
  78. }
  79. event_def: event_pmu |
  80. event_legacy_symbol |
  81. event_legacy_cache sep_dc |
  82. event_legacy_mem |
  83. event_legacy_tracepoint sep_dc |
  84. event_legacy_numeric sep_dc |
  85. event_legacy_raw sep_dc
  86. event_pmu:
  87. PE_NAME '/' event_config '/'
  88. {
  89. struct parse_events_data__events *data = _data;
  90. struct list_head *list = NULL;
  91. ABORT_ON(parse_events_add_pmu(&list, &data->idx, $1, $3));
  92. parse_events__free_terms($3);
  93. $$ = list;
  94. }
  95. event_legacy_symbol:
  96. PE_VALUE_SYM '/' event_config '/'
  97. {
  98. struct parse_events_data__events *data = _data;
  99. struct list_head *list = NULL;
  100. int type = $1 >> 16;
  101. int config = $1 & 255;
  102. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  103. type, config, $3));
  104. parse_events__free_terms($3);
  105. $$ = list;
  106. }
  107. |
  108. PE_VALUE_SYM sep_slash_dc
  109. {
  110. struct parse_events_data__events *data = _data;
  111. struct list_head *list = NULL;
  112. int type = $1 >> 16;
  113. int config = $1 & 255;
  114. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  115. type, config, NULL));
  116. $$ = list;
  117. }
  118. event_legacy_cache:
  119. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
  120. {
  121. struct parse_events_data__events *data = _data;
  122. struct list_head *list = NULL;
  123. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, $5));
  124. $$ = list;
  125. }
  126. |
  127. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
  128. {
  129. struct parse_events_data__events *data = _data;
  130. struct list_head *list = NULL;
  131. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, $3, NULL));
  132. $$ = list;
  133. }
  134. |
  135. PE_NAME_CACHE_TYPE
  136. {
  137. struct parse_events_data__events *data = _data;
  138. struct list_head *list = NULL;
  139. ABORT_ON(parse_events_add_cache(&list, &data->idx, $1, NULL, NULL));
  140. $$ = list;
  141. }
  142. event_legacy_mem:
  143. PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
  144. {
  145. struct parse_events_data__events *data = _data;
  146. struct list_head *list = NULL;
  147. ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
  148. (void *) $2, $4));
  149. $$ = list;
  150. }
  151. |
  152. PE_PREFIX_MEM PE_VALUE sep_dc
  153. {
  154. struct parse_events_data__events *data = _data;
  155. struct list_head *list = NULL;
  156. ABORT_ON(parse_events_add_breakpoint(&list, &data->idx,
  157. (void *) $2, NULL));
  158. $$ = list;
  159. }
  160. event_legacy_tracepoint:
  161. PE_NAME ':' PE_NAME
  162. {
  163. struct parse_events_data__events *data = _data;
  164. struct list_head *list = NULL;
  165. ABORT_ON(parse_events_add_tracepoint(&list, &data->idx, $1, $3));
  166. $$ = list;
  167. }
  168. event_legacy_numeric:
  169. PE_VALUE ':' PE_VALUE
  170. {
  171. struct parse_events_data__events *data = _data;
  172. struct list_head *list = NULL;
  173. ABORT_ON(parse_events_add_numeric(&list, &data->idx, $1, $3, NULL));
  174. $$ = list;
  175. }
  176. event_legacy_raw:
  177. PE_RAW
  178. {
  179. struct parse_events_data__events *data = _data;
  180. struct list_head *list = NULL;
  181. ABORT_ON(parse_events_add_numeric(&list, &data->idx,
  182. PERF_TYPE_RAW, $1, NULL));
  183. $$ = list;
  184. }
  185. terms: event_config
  186. {
  187. struct parse_events_data__terms *data = _data;
  188. data->terms = $1;
  189. }
  190. event_config:
  191. event_config ',' event_term
  192. {
  193. struct list_head *head = $1;
  194. struct parse_events__term *term = $3;
  195. ABORT_ON(!head);
  196. list_add_tail(&term->list, head);
  197. $$ = $1;
  198. }
  199. |
  200. event_term
  201. {
  202. struct list_head *head = malloc(sizeof(*head));
  203. struct parse_events__term *term = $1;
  204. ABORT_ON(!head);
  205. INIT_LIST_HEAD(head);
  206. list_add_tail(&term->list, head);
  207. $$ = head;
  208. }
  209. event_term:
  210. PE_NAME '=' PE_NAME
  211. {
  212. struct parse_events__term *term;
  213. ABORT_ON(parse_events__term_str(&term, PARSE_EVENTS__TERM_TYPE_USER,
  214. $1, $3));
  215. $$ = term;
  216. }
  217. |
  218. PE_NAME '=' PE_VALUE
  219. {
  220. struct parse_events__term *term;
  221. ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
  222. $1, $3));
  223. $$ = term;
  224. }
  225. |
  226. PE_NAME
  227. {
  228. struct parse_events__term *term;
  229. ABORT_ON(parse_events__term_num(&term, PARSE_EVENTS__TERM_TYPE_USER,
  230. $1, 1));
  231. $$ = term;
  232. }
  233. |
  234. PE_TERM '=' PE_NAME
  235. {
  236. struct parse_events__term *term;
  237. ABORT_ON(parse_events__term_str(&term, $1, NULL, $3));
  238. $$ = term;
  239. }
  240. |
  241. PE_TERM '=' PE_VALUE
  242. {
  243. struct parse_events__term *term;
  244. ABORT_ON(parse_events__term_num(&term, $1, NULL, $3));
  245. $$ = term;
  246. }
  247. |
  248. PE_TERM
  249. {
  250. struct parse_events__term *term;
  251. ABORT_ON(parse_events__term_num(&term, $1, NULL, 1));
  252. $$ = term;
  253. }
  254. sep_dc: ':' |
  255. sep_slash_dc: '/' | ':' |
  256. %%
  257. void parse_events_error(void *data __used, void *scanner __used,
  258. char const *msg __used)
  259. {
  260. }