pmu.y 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. %define api.pure full
  2. %parse-param {void *format}
  3. %parse-param {void *scanner}
  4. %lex-param {void* scanner}
  5. %{
  6. #ifndef NDEBUG
  7. #define YYDEBUG 1
  8. #endif
  9. #include <linux/compiler.h>
  10. #include <linux/list.h>
  11. #include <linux/bitmap.h>
  12. #include <string.h>
  13. #include "pmu.h"
  14. #include "pmu-bison.h"
  15. int perf_pmu_lex(YYSTYPE * yylval_param , void *yyscanner);
  16. #define ABORT_ON(val) \
  17. do { \
  18. if (val) \
  19. YYABORT; \
  20. } while (0)
  21. static void perf_pmu_error(void *format, void *scanner, const char *msg);
  22. static void perf_pmu__set_format(unsigned long *bits, long from, long to)
  23. {
  24. long b;
  25. if (!to)
  26. to = from;
  27. memset(bits, 0, BITS_TO_BYTES(PERF_PMU_FORMAT_BITS));
  28. for (b = from; b <= to; b++)
  29. __set_bit(b, bits);
  30. }
  31. %}
  32. %token PP_CONFIG
  33. %token PP_VALUE PP_ERROR
  34. %type <num> PP_VALUE
  35. %type <bits> bit_term
  36. %type <bits> bits
  37. %union
  38. {
  39. unsigned long num;
  40. DECLARE_BITMAP(bits, PERF_PMU_FORMAT_BITS);
  41. }
  42. %%
  43. format:
  44. format format_term
  45. |
  46. format_term
  47. format_term:
  48. PP_CONFIG ':' bits
  49. {
  50. perf_pmu_format__set_value(format, PERF_PMU_FORMAT_VALUE_CONFIG, $3);
  51. }
  52. |
  53. PP_CONFIG PP_VALUE ':' bits
  54. {
  55. perf_pmu_format__set_value(format, $2, $4);
  56. }
  57. bits:
  58. bits ',' bit_term
  59. {
  60. bitmap_or($$, $1, $3, 64);
  61. }
  62. |
  63. bit_term
  64. {
  65. memcpy($$, $1, sizeof($1));
  66. }
  67. bit_term:
  68. PP_VALUE '-' PP_VALUE
  69. {
  70. perf_pmu__set_format($$, $1, $3);
  71. }
  72. |
  73. PP_VALUE
  74. {
  75. perf_pmu__set_format($$, $1, 0);
  76. }
  77. %%
  78. static void perf_pmu_error(void *format __maybe_unused,
  79. void *scanner __maybe_unused,
  80. const char *msg __maybe_unused)
  81. {
  82. }