parse-events.y 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. %name-prefix "parse_events_"
  2. %parse-param {struct list_head *list}
  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. %union
  36. {
  37. char *str;
  38. unsigned long num;
  39. struct list_head *head;
  40. struct parse_events__term *term;
  41. }
  42. %%
  43. events:
  44. events ',' event | event
  45. event:
  46. event_def PE_MODIFIER_EVENT
  47. {
  48. ABORT_ON(parse_events_modifier(list, $2));
  49. }
  50. |
  51. event_def
  52. event_def: event_pmu |
  53. event_legacy_symbol |
  54. event_legacy_cache sep_dc |
  55. event_legacy_mem |
  56. event_legacy_tracepoint sep_dc |
  57. event_legacy_numeric sep_dc |
  58. event_legacy_raw sep_dc
  59. event_pmu:
  60. PE_NAME '/' event_config '/'
  61. {
  62. ABORT_ON(parse_events_add_pmu(list, idx, $1, $3));
  63. parse_events__free_terms($3);
  64. }
  65. event_legacy_symbol:
  66. PE_VALUE_SYM '/' event_config '/'
  67. {
  68. int type = $1 >> 16;
  69. int config = $1 & 255;
  70. ABORT_ON(parse_events_add_numeric(list, idx, type, config, $3));
  71. parse_events__free_terms($3);
  72. }
  73. |
  74. PE_VALUE_SYM sep_slash_dc
  75. {
  76. int type = $1 >> 16;
  77. int config = $1 & 255;
  78. ABORT_ON(parse_events_add_numeric(list, idx, type, config, NULL));
  79. }
  80. event_legacy_cache:
  81. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT '-' PE_NAME_CACHE_OP_RESULT
  82. {
  83. ABORT_ON(parse_events_add_cache(list, idx, $1, $3, $5));
  84. }
  85. |
  86. PE_NAME_CACHE_TYPE '-' PE_NAME_CACHE_OP_RESULT
  87. {
  88. ABORT_ON(parse_events_add_cache(list, idx, $1, $3, NULL));
  89. }
  90. |
  91. PE_NAME_CACHE_TYPE
  92. {
  93. ABORT_ON(parse_events_add_cache(list, idx, $1, NULL, NULL));
  94. }
  95. event_legacy_mem:
  96. PE_PREFIX_MEM PE_VALUE ':' PE_MODIFIER_BP sep_dc
  97. {
  98. ABORT_ON(parse_events_add_breakpoint(list, idx, (void *) $2, $4));
  99. }
  100. |
  101. PE_PREFIX_MEM PE_VALUE sep_dc
  102. {
  103. ABORT_ON(parse_events_add_breakpoint(list, idx, (void *) $2, NULL));
  104. }
  105. event_legacy_tracepoint:
  106. PE_NAME ':' PE_NAME
  107. {
  108. ABORT_ON(parse_events_add_tracepoint(list, idx, $1, $3));
  109. }
  110. event_legacy_numeric:
  111. PE_VALUE ':' PE_VALUE
  112. {
  113. ABORT_ON(parse_events_add_numeric(list, idx, $1, $3, NULL));
  114. }
  115. event_legacy_raw:
  116. PE_RAW
  117. {
  118. ABORT_ON(parse_events_add_numeric(list, idx, PERF_TYPE_RAW, $1, NULL));
  119. }
  120. event_config:
  121. event_config ',' event_term
  122. {
  123. struct list_head *head = $1;
  124. struct parse_events__term *term = $3;
  125. ABORT_ON(!head);
  126. list_add_tail(&term->list, head);
  127. $$ = $1;
  128. }
  129. |
  130. event_term
  131. {
  132. struct list_head *head = malloc(sizeof(*head));
  133. struct parse_events__term *term = $1;
  134. ABORT_ON(!head);
  135. INIT_LIST_HEAD(head);
  136. list_add_tail(&term->list, head);
  137. $$ = head;
  138. }
  139. event_term:
  140. PE_NAME '=' PE_NAME
  141. {
  142. struct parse_events__term *term;
  143. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_STR,
  144. $1, $3, 0));
  145. $$ = term;
  146. }
  147. |
  148. PE_NAME '=' PE_VALUE
  149. {
  150. struct parse_events__term *term;
  151. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_NUM,
  152. $1, NULL, $3));
  153. $$ = term;
  154. }
  155. |
  156. PE_NAME
  157. {
  158. struct parse_events__term *term;
  159. ABORT_ON(parse_events__new_term(&term, PARSE_EVENTS__TERM_TYPE_NUM,
  160. $1, NULL, 1));
  161. $$ = term;
  162. }
  163. |
  164. PE_TERM '=' PE_VALUE
  165. {
  166. struct parse_events__term *term;
  167. ABORT_ON(parse_events__new_term(&term, $1, NULL, NULL, $3));
  168. $$ = term;
  169. }
  170. |
  171. PE_TERM
  172. {
  173. struct parse_events__term *term;
  174. ABORT_ON(parse_events__new_term(&term, $1, NULL, NULL, 1));
  175. $$ = term;
  176. }
  177. sep_dc: ':' |
  178. sep_slash_dc: '/' | ':' |
  179. %%
  180. void parse_events_error(struct list_head *list __used, int *idx __used,
  181. char const *msg __used)
  182. {
  183. }