name_codelets.cocci 2.1 KB

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