1 /* Header file for internal GCC plugin mechanism. 2 Copyright (C) 2009-2018 Free Software Foundation, Inc. 3 4 This file is part of GCC. 5 6 GCC is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 3, or (at your option) 9 any later version. 10 11 GCC is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with GCC; see the file COPYING3. If not see 18 <http://www.gnu.org/licenses/>. */ 19 20 #ifndef PLUGIN_H 21 #define PLUGIN_H 22 23 #include "highlev-plugin-common.h" 24 25 /* Event names. */ 26 enum plugin_event 27 { 28 # define DEFEVENT(NAME) NAME, 29 # include "plugin.def" 30 # undef DEFEVENT 31 PLUGIN_EVENT_FIRST_DYNAMIC 32 }; 33 34 /* All globals declared here have C linkage to reduce link compatibility 35 issues with implementation language choice and mangling. */ 36 #ifdef __cplusplus 37 extern "C" { 38 #endif 39 40 extern const char **plugin_event_name; 41 42 struct plugin_argument 43 { 44 char *key; /* key of the argument. */ 45 char *value; /* value is optional and can be NULL. */ 46 }; 47 48 /* Additional information about the plugin. Used by --help and --version. */ 49 50 struct plugin_info 51 { 52 const char *version; 53 const char *help; 54 }; 55 56 /* Represents the gcc version. Used to avoid using an incompatible plugin. */ 57 58 struct plugin_gcc_version 59 { 60 const char *basever; 61 const char *datestamp; 62 const char *devphase; 63 const char *revision; 64 const char *configuration_arguments; 65 }; 66 67 /* Object that keeps track of the plugin name and its arguments. */ 68 struct plugin_name_args 69 { 70 char *base_name; /* Short name of the plugin (filename without 71 .so suffix). */ 72 const char *full_name; /* Path to the plugin as specified with 73 -fplugin=. */ 74 int argc; /* Number of arguments specified with 75 -fplugin-arg-... */ 76 struct plugin_argument *argv; /* Array of ARGC key-value pairs. */ 77 const char *version; /* Version string provided by plugin. */ 78 const char *help; /* Help string provided by plugin. */ 79 }; 80 81 /* The default version check. Compares every field in VERSION. */ 82 83 extern bool plugin_default_version_check (struct plugin_gcc_version *, 84 struct plugin_gcc_version *); 85 86 /* Function type for the plugin initialization routine. Each plugin module 87 should define this as an externally-visible function with name 88 "plugin_init." 89 90 PLUGIN_INFO - plugin invocation information. 91 VERSION - the plugin_gcc_version symbol of GCC. 92 93 Returns 0 if initialization finishes successfully. */ 94 95 typedef int (*plugin_init_func) (struct plugin_name_args *plugin_info, 96 struct plugin_gcc_version *version); 97 98 /* Declaration for "plugin_init" function so that it doesn't need to be 99 duplicated in every plugin. */ 100 extern int plugin_init (struct plugin_name_args *plugin_info, 101 struct plugin_gcc_version *version); 102 103 /* Function type for a plugin callback routine. 104 105 GCC_DATA - event-specific data provided by GCC 106 USER_DATA - plugin-specific data provided by the plugin */ 107 108 typedef void (*plugin_callback_func) (void *gcc_data, void *user_data); 109 110 /* Called from the plugin's initialization code. Register a single callback. 111 This function can be called multiple times. 112 113 PLUGIN_NAME - display name for this plugin 114 EVENT - which event the callback is for 115 CALLBACK - the callback to be called at the event 116 USER_DATA - plugin-provided data. 117 */ 118 119 /* Number of event ids / names registered so far. */ 120 121 extern int get_event_last (void); 122 123 int get_named_event_id (const char *name, enum insert_option insert); 124 125 /* This is also called without a callback routine for the 126 PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO and PLUGIN_REGISTER_GGC_ROOTS 127 pseudo-events, with a specific user_data. 128 */ 129 130 extern void register_callback (const char *plugin_name, 131 int event, 132 plugin_callback_func callback, 133 void *user_data); 134 135 extern int unregister_callback (const char *plugin_name, int event); 136 137 138 /* Retrieve the plugin directory name, as returned by the 139 -fprint-file-name=plugin argument to the gcc program, which is the 140 -iplugindir program argument to cc1. */ 141 extern const char* default_plugin_dir_name (void); 142 143 #ifdef __cplusplus 144 } 145 #endif 146 147 /* In case the C++ compiler does name mangling for globals, declare 148 plugin_is_GPL_compatible extern "C" so that a later definition 149 in a plugin file will have this linkage. */ 150 #ifdef __cplusplus 151 extern "C" { 152 #endif 153 extern int plugin_is_GPL_compatible; 154 #ifdef __cplusplus 155 } 156 #endif 157 158 159 struct attribute_spec; 160 struct scoped_attributes; 161 162 extern void add_new_plugin (const char *); 163 extern void parse_plugin_arg_opt (const char *); 164 extern int invoke_plugin_callbacks_full (int, void *); 165 extern void initialize_plugins (void); 166 extern bool plugins_active_p (void); 167 extern void dump_active_plugins (FILE *); 168 extern void debug_active_plugins (void); 169 extern void warn_if_plugins (void); 170 extern void print_plugins_versions (FILE *file, const char *indent); 171 extern void print_plugins_help (FILE *file, const char *indent); 172 extern void finalize_plugins (void); 173 174 extern bool flag_plugin_added; 175 176 /* Called from inside GCC. Invoke all plugin callbacks registered with 177 the specified event. 178 Return PLUGEVT_SUCCESS if at least one callback was called, 179 PLUGEVT_NO_CALLBACK if there was no callback. 180 181 EVENT - the event identifier 182 GCC_DATA - event-specific data provided by the compiler */ 183 184 static inline int 185 invoke_plugin_callbacks (int event ATTRIBUTE_UNUSED, 186 void *gcc_data ATTRIBUTE_UNUSED) 187 { 188 #ifdef ENABLE_PLUGIN 189 /* True iff at least one plugin has been added. */ 190 if (flag_plugin_added) 191 return invoke_plugin_callbacks_full (event, gcc_data); 192 #endif 193 194 return PLUGEVT_NO_CALLBACK; 195 } 196 197 /* In attribs.c. */ 198 199 extern void register_attribute (const struct attribute_spec *attr); 200 extern struct scoped_attributes* register_scoped_attributes (const struct attribute_spec *, 201 const char *); 202 203 #endif /* PLUGIN_H */ 204