use_starpu_macros.cocci 2.9 KB

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