gcc-plugin.h 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /* Public header file for plugins to include.
  2. Copyright (C) 2009-2015 Free Software Foundation, Inc.
  3. This file is part of GCC.
  4. GCC is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3, or (at your option)
  7. any later version.
  8. GCC is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GCC; see the file COPYING3. If not see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef GCC_PLUGIN_H
  16. #define GCC_PLUGIN_H
  17. #ifndef IN_GCC
  18. #define IN_GCC
  19. #endif
  20. #include "config.h"
  21. #include "system.h"
  22. #include "coretypes.h"
  23. #include "highlev-plugin-common.h"
  24. #include "tm.h"
  25. #include "hashtab.h"
  26. #include "hash-set.h"
  27. #include "vec.h"
  28. #include "machmode.h"
  29. #include "hard-reg-set.h"
  30. #include "input.h"
  31. #include "function.h"
  32. #include "predict.h"
  33. #include "dominance.h"
  34. #include "cfg.h"
  35. #include "cfgrtl.h"
  36. #include "cfganal.h"
  37. #include "lcm.h"
  38. #include "cfgbuild.h"
  39. #include "cfgcleanup.h"
  40. #include "hash-map.h"
  41. #include "is-a.h"
  42. #include "plugin-api.h"
  43. #include "ipa-ref.h"
  44. #include "statistics.h"
  45. #include "double-int.h"
  46. #include "real.h"
  47. #include "fixed-value.h"
  48. #include "alias.h"
  49. #include "flags.h"
  50. #include "symtab.h"
  51. #include "tree-core.h"
  52. #include "hash-set.h"
  53. #include "wide-int.h"
  54. #include "inchash.h"
  55. #include "fold-const.h"
  56. #include "tree-check.h"
  57. /* Event names. */
  58. enum plugin_event
  59. {
  60. # define DEFEVENT(NAME) NAME,
  61. # include "plugin.def"
  62. # undef DEFEVENT
  63. PLUGIN_EVENT_FIRST_DYNAMIC
  64. };
  65. /* All globals declared here have C linkage to reduce link compatibility
  66. issues with implementation language choice and mangling. */
  67. #ifdef __cplusplus
  68. extern "C" {
  69. #endif
  70. extern const char **plugin_event_name;
  71. struct plugin_argument
  72. {
  73. char *key; /* key of the argument. */
  74. char *value; /* value is optional and can be NULL. */
  75. };
  76. /* Additional information about the plugin. Used by --help and --version. */
  77. struct plugin_info
  78. {
  79. const char *version;
  80. const char *help;
  81. };
  82. /* Represents the gcc version. Used to avoid using an incompatible plugin. */
  83. struct plugin_gcc_version
  84. {
  85. const char *basever;
  86. const char *datestamp;
  87. const char *devphase;
  88. const char *revision;
  89. const char *configuration_arguments;
  90. };
  91. /* Object that keeps track of the plugin name and its arguments. */
  92. struct plugin_name_args
  93. {
  94. char *base_name; /* Short name of the plugin (filename without
  95. .so suffix). */
  96. const char *full_name; /* Path to the plugin as specified with
  97. -fplugin=. */
  98. int argc; /* Number of arguments specified with
  99. -fplugin-arg-... */
  100. struct plugin_argument *argv; /* Array of ARGC key-value pairs. */
  101. const char *version; /* Version string provided by plugin. */
  102. const char *help; /* Help string provided by plugin. */
  103. };
  104. /* The default version check. Compares every field in VERSION. */
  105. extern bool plugin_default_version_check (struct plugin_gcc_version *,
  106. struct plugin_gcc_version *);
  107. /* Function type for the plugin initialization routine. Each plugin module
  108. should define this as an externally-visible function with name
  109. "plugin_init."
  110. PLUGIN_INFO - plugin invocation information.
  111. VERSION - the plugin_gcc_version symbol of GCC.
  112. Returns 0 if initialization finishes successfully. */
  113. typedef int (*plugin_init_func) (struct plugin_name_args *plugin_info,
  114. struct plugin_gcc_version *version);
  115. /* Declaration for "plugin_init" function so that it doesn't need to be
  116. duplicated in every plugin. */
  117. extern int plugin_init (struct plugin_name_args *plugin_info,
  118. struct plugin_gcc_version *version);
  119. /* Function type for a plugin callback routine.
  120. GCC_DATA - event-specific data provided by GCC
  121. USER_DATA - plugin-specific data provided by the plugin */
  122. typedef void (*plugin_callback_func) (void *gcc_data, void *user_data);
  123. /* Called from the plugin's initialization code. Register a single callback.
  124. This function can be called multiple times.
  125. PLUGIN_NAME - display name for this plugin
  126. EVENT - which event the callback is for
  127. CALLBACK - the callback to be called at the event
  128. USER_DATA - plugin-provided data.
  129. */
  130. /* Number of event ids / names registered so far. */
  131. extern int get_event_last (void);
  132. int get_named_event_id (const char *name, enum insert_option insert);
  133. /* This is also called without a callback routine for the
  134. PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO and PLUGIN_REGISTER_GGC_ROOTS
  135. pseudo-events, with a specific user_data.
  136. */
  137. extern void register_callback (const char *plugin_name,
  138. int event,
  139. plugin_callback_func callback,
  140. void *user_data);
  141. extern int unregister_callback (const char *plugin_name, int event);
  142. /* Retrieve the plugin directory name, as returned by the
  143. -fprint-file-name=plugin argument to the gcc program, which is the
  144. -iplugindir program argument to cc1. */
  145. extern const char* default_plugin_dir_name (void);
  146. #ifdef __cplusplus
  147. }
  148. #endif
  149. /* In case the C++ compiler does name mangling for globals, declare
  150. plugin_is_GPL_compatible extern "C" so that a later definition
  151. in a plugin file will have this linkage. */
  152. #ifdef __cplusplus
  153. extern "C" {
  154. #endif
  155. extern int plugin_is_GPL_compatible;
  156. #ifdef __cplusplus
  157. }
  158. #endif
  159. #endif /* GCC_PLUGIN_H */