Fix bootstrap/PR63632
[official-gcc.git] / gcc / gcc-plugin.h
blob7b019ad52b95b24941684343752edfb5859df5ec
1 /* Public header file for plugins to include.
2 Copyright (C) 2009-2014 Free Software Foundation, Inc.
4 This file is part of GCC.
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.
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.
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/>. */
20 #ifndef GCC_PLUGIN_H
21 #define GCC_PLUGIN_H
23 #ifndef IN_GCC
24 #define IN_GCC
25 #endif
27 #include "config.h"
28 #include "system.h"
29 #include "coretypes.h"
30 #include "highlev-plugin-common.h"
31 #include "tm.h"
32 #include "hashtab.h"
33 #include "hash-set.h"
34 #include "vec.h"
35 #include "machmode.h"
36 #include "hard-reg-set.h"
37 #include "input.h"
39 /* Event names. */
40 enum plugin_event
42 # define DEFEVENT(NAME) NAME,
43 # include "plugin.def"
44 # undef DEFEVENT
45 PLUGIN_EVENT_FIRST_DYNAMIC
48 /* All globals declared here have C linkage to reduce link compatibility
49 issues with implementation language choice and mangling. */
50 #ifdef __cplusplus
51 extern "C" {
52 #endif
54 extern const char **plugin_event_name;
56 struct plugin_argument
58 char *key; /* key of the argument. */
59 char *value; /* value is optional and can be NULL. */
62 /* Additional information about the plugin. Used by --help and --version. */
64 struct plugin_info
66 const char *version;
67 const char *help;
70 /* Represents the gcc version. Used to avoid using an incompatible plugin. */
72 struct plugin_gcc_version
74 const char *basever;
75 const char *datestamp;
76 const char *devphase;
77 const char *revision;
78 const char *configuration_arguments;
81 /* Object that keeps track of the plugin name and its arguments. */
82 struct plugin_name_args
84 char *base_name; /* Short name of the plugin (filename without
85 .so suffix). */
86 const char *full_name; /* Path to the plugin as specified with
87 -fplugin=. */
88 int argc; /* Number of arguments specified with
89 -fplugin-arg-... */
90 struct plugin_argument *argv; /* Array of ARGC key-value pairs. */
91 const char *version; /* Version string provided by plugin. */
92 const char *help; /* Help string provided by plugin. */
95 /* The default version check. Compares every field in VERSION. */
97 extern bool plugin_default_version_check (struct plugin_gcc_version *,
98 struct plugin_gcc_version *);
100 /* Function type for the plugin initialization routine. Each plugin module
101 should define this as an externally-visible function with name
102 "plugin_init."
104 PLUGIN_INFO - plugin invocation information.
105 VERSION - the plugin_gcc_version symbol of GCC.
107 Returns 0 if initialization finishes successfully. */
109 typedef int (*plugin_init_func) (struct plugin_name_args *plugin_info,
110 struct plugin_gcc_version *version);
112 /* Declaration for "plugin_init" function so that it doesn't need to be
113 duplicated in every plugin. */
114 extern int plugin_init (struct plugin_name_args *plugin_info,
115 struct plugin_gcc_version *version);
117 /* Function type for a plugin callback routine.
119 GCC_DATA - event-specific data provided by GCC
120 USER_DATA - plugin-specific data provided by the plugin */
122 typedef void (*plugin_callback_func) (void *gcc_data, void *user_data);
124 /* Called from the plugin's initialization code. Register a single callback.
125 This function can be called multiple times.
127 PLUGIN_NAME - display name for this plugin
128 EVENT - which event the callback is for
129 CALLBACK - the callback to be called at the event
130 USER_DATA - plugin-provided data.
133 /* Number of event ids / names registered so far. */
135 extern int get_event_last (void);
137 int get_named_event_id (const char *name, enum insert_option insert);
139 /* This is also called without a callback routine for the
140 PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PLUGIN_REGISTER_GGC_ROOTS and
141 PLUGIN_REGISTER_GGC_CACHES pseudo-events, with a specific user_data.
144 extern void register_callback (const char *plugin_name,
145 int event,
146 plugin_callback_func callback,
147 void *user_data);
149 extern int unregister_callback (const char *plugin_name, int event);
152 /* Retrieve the plugin directory name, as returned by the
153 -fprint-file-name=plugin argument to the gcc program, which is the
154 -iplugindir program argument to cc1. */
155 extern const char* default_plugin_dir_name (void);
157 #ifdef __cplusplus
159 #endif
161 /* In case the C++ compiler does name mangling for globals, declare
162 plugin_is_GPL_compatible extern "C" so that a later definition
163 in a plugin file will have this linkage. */
164 #ifdef __cplusplus
165 extern "C" {
166 #endif
167 extern int plugin_is_GPL_compatible;
168 #ifdef __cplusplus
170 #endif
172 #endif /* GCC_PLUGIN_H */