parse-events.y 3.7 KB

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