parse-events.y 5.7 KB

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