use_starpu_macros.cocci 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2011-2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. *
  5. * StarPU is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU Lesser General Public License as published by
  7. * the Free Software Foundation; either version 2.1 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * StarPU is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. *
  14. * See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. */
  16. virtual context
  17. virtual org
  18. virtual patch
  19. virtual report
  20. //
  21. // General stuff for org and report modes.
  22. //
  23. @initialize:python depends on report || org@
  24. d = { 'abort':'STARPU_ABORT', 'assert':'STARPU_ASSERT'}
  25. msg = "Please use %s rather than %s."
  26. from re import sub
  27. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  28. @r@
  29. identifier f =~ "abort|assert";
  30. position p;
  31. @@
  32. f@p(...);
  33. @min@
  34. expression E1,E2;
  35. identifier i;
  36. position p;
  37. @@
  38. (
  39. return@p E1<E2?E1:E2;
  40. |
  41. i =@p E1<E2?E1:E2
  42. )
  43. @max@
  44. expression E1, E2;
  45. identifier i;
  46. position p;
  47. @@
  48. (
  49. return@p E1>E2?E1:E2;
  50. |
  51. i =@p E1>E2?E1:E2
  52. )
  53. //
  54. // Context mode.
  55. //
  56. @depends on context@
  57. @@
  58. * abort();
  59. @depends on context@
  60. @@
  61. * assert(...);
  62. @depends on context@
  63. identifier i;
  64. expression E1, E2;
  65. @@
  66. (
  67. * return E1<E2?E1:E2;
  68. |
  69. * i = E1<E2?E1:E2 // No semi-colon at the end, so that it
  70. |
  71. * return E1>E2?E1:E2;
  72. |
  73. * i = E1>E2?E1:E2 // No semi-colon at the end, so that it
  74. )
  75. //
  76. // Org mode.
  77. //
  78. @script:python depends on r && org@
  79. p << r.p;
  80. f << r.f;
  81. @@
  82. coccilib.org.print_todo(p[0], orgmsg % (d[str(f)], f))
  83. @script:python depends on min && org@
  84. p << min.p;
  85. @@
  86. coccilib.org.print_todo(p[0], "Please use STARPU_MIN")
  87. @script:python depends on max && org@
  88. p << max.p;
  89. @@
  90. coccilib.org.print_todo(p[0], "Please use STARPU_MAX")
  91. //
  92. // Patch mode.
  93. //
  94. @depends on patch@
  95. @@
  96. - abort();
  97. + STARPU_ABORT();
  98. @depends on patch@
  99. @@
  100. - assert(
  101. + STARPU_ASSERT(
  102. ...)
  103. @depends on patch@
  104. identifier i;
  105. expression E1, E2;
  106. @@
  107. (
  108. - return E1<E2?E1:E2;
  109. + return STARPU_MIN(E1, E2);
  110. |
  111. - i = E1<E2?E1:E2 // No semi-colon at the end, so that it
  112. + i = STARPU_MIN(E1, E2) // matches both "i = ..." and "t i = ..."
  113. |
  114. - return E1>E2?E1:E2;
  115. + return STAPU_MAX(E1, E2);
  116. |
  117. - i = E1>E2?E1:E2 // No semi-colon at the end, so that it
  118. + i = STARPU_MAX(E1, E2) // matches both "i = ..." and "t i = ..."
  119. )
  120. //
  121. // Report mode.
  122. //
  123. @script:python depends on r && report@
  124. p << r.p;
  125. f << r.f;
  126. @@
  127. coccilib.report.print_report(p[0], msg % (d[str(f)], f))
  128. @script:python depends on min && report@
  129. p << min.p;
  130. @@
  131. coccilib.report.print_report(p[0], "Please use STARPU_MIN")
  132. @script:python depends on max && report@
  133. p << max.p;
  134. @@
  135. coccilib.report.print_report(p[0], "Please use STARPU_MAX")