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