parse-events.y 6.0 KB

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