plugin.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. /* Header file for internal GCC plugin mechanism.
  2. Copyright (C) 2009-2019 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 PLUGIN_H
  16. #define PLUGIN_H
  17. #include "highlev-plugin-common.h"
  18. /* Event names. */
  19. enum plugin_event
  20. {
  21. # define DEFEVENT(NAME) NAME,
  22. # include "plugin.def"
  23. # undef DEFEVENT
  24. PLUGIN_EVENT_FIRST_DYNAMIC
  25. };
  26. /* All globals declared here have C linkage to reduce link compatibility
  27. issues with implementation language choice and mangling. */
  28. #ifdef __cplusplus
  29. extern "C" {
  30. #endif
  31. extern const char **plugin_event_name;
  32. struct plugin_argument
  33. {
  34. char *key; /* key of the argument. */
  35. char *value; /* value is optional and can be NULL. */
  36. };
  37. /* Additional information about the plugin. Used by --help and --version. */
  38. struct plugin_info
  39. {
  40. const char *version;
  41. const char *help;
  42. };
  43. /* Represents the gcc version. Used to avoid using an incompatible plugin. */
  44. struct plugin_gcc_version
  45. {
  46. const char *basever;
  47. const char *datestamp;
  48. const char *devphase;
  49. const char *revision;
  50. const char *configuration_arguments;
  51. };
  52. /* Object that keeps track of the plugin name and its arguments. */
  53. struct plugin_name_args
  54. {
  55. char *base_name; /* Short name of the plugin (filename without
  56. .so suffix). */
  57. const char *full_name; /* Path to the plugin as specified with
  58. -fplugin=. */
  59. int argc; /* Number of arguments specified with
  60. -fplugin-arg-... */
  61. struct plugin_argument *argv; /* Array of ARGC key-value pairs. */
  62. const char *version; /* Version string provided by plugin. */
  63. const char *help; /* Help string provided by plugin. */
  64. };
  65. /* The default version check. Compares every field in VERSION. */
  66. extern bool plugin_default_version_check (struct plugin_gcc_version *,
  67. struct plugin_gcc_version *);
  68. /* Function type for the plugin initialization routine. Each plugin module
  69. should define this as an externally-visible function with name
  70. "plugin_init."
  71. PLUGIN_INFO - plugin invocation information.
  72. VERSION - the plugin_gcc_version symbol of GCC.
  73. Returns 0 if initialization finishes successfully. */
  74. typedef int (*plugin_init_func) (struct plugin_name_args *plugin_info,
  75. struct plugin_gcc_version *version);
  76. /* Declaration for "plugin_init" function so that it doesn't need to be
  77. duplicated in every plugin. */
  78. extern int plugin_init (struct plugin_name_args *plugin_info,
  79. struct plugin_gcc_version *version);
  80. /* Function type for a plugin callback routine.
  81. GCC_DATA - event-specific data provided by GCC
  82. USER_DATA - plugin-specific data provided by the plugin */
  83. typedef void (*plugin_callback_func) (void *gcc_data, void *user_data);
  84. /* Called from the plugin's initialization code. Register a single callback.
  85. This function can be called multiple times.
  86. PLUGIN_NAME - display name for this plugin
  87. EVENT - which event the callback is for
  88. CALLBACK - the callback to be called at the event
  89. USER_DATA - plugin-provided data.
  90. */
  91. /* Number of event ids / names registered so far. */
  92. extern int get_event_last (void);
  93. int get_named_event_id (const char *name, enum insert_option insert);
  94. /* This is also called without a callback routine for the
  95. PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO and PLUGIN_REGISTER_GGC_ROOTS
  96. pseudo-events, with a specific user_data.
  97. */
  98. extern void register_callback (const char *plugin_name,
  99. int event,
  100. plugin_callback_func callback,
  101. void *user_data);
  102. extern int unregister_callback (const char *plugin_name, int event);
  103. /* Retrieve the plugin directory name, as returned by the
  104. -fprint-file-name=plugin argument to the gcc program, which is the
  105. -iplugindir program argument to cc1. */
  106. extern const char* default_plugin_dir_name (void);
  107. #ifdef __cplusplus
  108. }
  109. #endif
  110. /* In case the C++ compiler does name mangling for globals, declare
  111. plugin_is_GPL_compatible extern "C" so that a later definition
  112. in a plugin file will have this linkage. */
  113. #ifdef __cplusplus
  114. extern "C" {
  115. #endif
  116. extern int plugin_is_GPL_compatible;
  117. #ifdef __cplusplus
  118. }
  119. #endif
  120. struct attribute_spec;
  121. struct scoped_attributes;
  122. extern void add_new_plugin (const char *);
  123. extern void parse_plugin_arg_opt (const char *);
  124. extern int invoke_plugin_callbacks_full (int, void *);
  125. extern void initialize_plugins (void);
  126. extern bool plugins_active_p (void);
  127. extern void dump_active_plugins (FILE *);
  128. extern void debug_active_plugins (void);
  129. extern void warn_if_plugins (void);
  130. extern void print_plugins_versions (FILE *file, const char *indent);
  131. extern void print_plugins_help (FILE *file, const char *indent);
  132. extern void finalize_plugins (void);
  133. extern bool flag_plugin_added;
  134. /* Called from inside GCC. Invoke all plugin callbacks registered with
  135. the specified event.
  136. Return PLUGEVT_SUCCESS if at least one callback was called,
  137. PLUGEVT_NO_CALLBACK if there was no callback.
  138. EVENT - the event identifier
  139. GCC_DATA - event-specific data provided by the compiler */
  140. static inline int
  141. invoke_plugin_callbacks (int event ATTRIBUTE_UNUSED,
  142. void *gcc_data ATTRIBUTE_UNUSED)
  143. {
  144. #ifdef ENABLE_PLUGIN
  145. /* True iff at least one plugin has been added. */
  146. if (flag_plugin_added)
  147. return invoke_plugin_callbacks_full (event, gcc_data);
  148. #endif
  149. return PLUGEVT_NO_CALLBACK;
  150. }
  151. /* In attribs.c. */
  152. extern void register_attribute (const struct attribute_spec *attr);
  153. extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *,
  154. const char *);
  155. #endif /* PLUGIN_H */