name_codelets.cocci 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. /* StarPU --- Runtime system for heterogeneous multicore architectures.
  2. *
  3. * Copyright (C) 2012-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. /*
  17. * Codelets have a "name" attribute that is really useful for debugging
  18. * purposes. Lots of codelets do not use this attribute though, mostly because
  19. * they were written when it was not available.
  20. *
  21. * This semantic patch tries to add a "name" attribute when it is necessary.
  22. * The chosen name is the name of the codelet variable : it should be good
  23. * enough for debugging.
  24. */
  25. virtual context
  26. virtual org
  27. virtual patch
  28. virtual report
  29. @initialize:python depends on org || report@
  30. msg = "Warning: %s has no attribute name"
  31. from re import sub
  32. orgmsg = sub(r'(%[a-z])', r'=\1=', msg)
  33. @found@
  34. identifier cl;
  35. position p;
  36. @@
  37. struct starpu_codelet cl@p = {
  38. ...
  39. };
  40. @named depends on found@
  41. position found.p;
  42. identifier found.cl;
  43. expression E;
  44. @@
  45. struct starpu_codelet cl@p = {
  46. .name = E,
  47. };
  48. // Context mode.
  49. @depends on found && !named && context@
  50. identifier found.cl;
  51. position found.p;
  52. @@
  53. *struct starpu_codelet cl@p = {...};
  54. // Org mode.
  55. @script:python depends on found && !named && org@
  56. cl << found.cl;
  57. p << found.p;
  58. @@
  59. coccilib.org.print_todo(p[0], orgmsg % cl)
  60. // Patch mode.
  61. @script:python stringify depends on found && !named && patch@
  62. cl_name << found.cl;
  63. guess;
  64. @@
  65. coccinelle.guess = '"' + str(cl_name) + '"'
  66. @depends on found && !named && patch@
  67. position found.p;
  68. identifier found.cl;
  69. identifier stringify.guess;
  70. @@
  71. struct starpu_codelet cl@p = {
  72. +.name = guess,
  73. };
  74. // Report mode.
  75. @script:python depends on found && !named && report@
  76. cl << found.cl;
  77. p << found.p;
  78. @@
  79. coccilib.report.print_report(p[0], msg % cl)