parse-events.y 4.9 KB

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