GCC Middle and Back End API Reference
plugin.h
Go to the documentation of this file.
1/* Header file for internal GCC plugin mechanism.
2 Copyright (C) 2009-2024 Free Software Foundation, Inc.
3
4This file is part of GCC.
5
6GCC is free software; you can redistribute it and/or modify
7it under the terms of the GNU General Public License as published by
8the Free Software Foundation; either version 3, or (at your option)
9any later version.
10
11GCC is distributed in the hope that it will be useful,
12but WITHOUT ANY WARRANTY; without even the implied warranty of
13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14GNU General Public License for more details.
15
16You should have received a copy of the GNU General Public License
17along 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
24
25/* Event names. */
27{
28# define DEFEVENT(NAME) NAME,
29# include "plugin.def"
30# undef DEFEVENT
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
37extern "C" {
38#endif
39
40extern const char **plugin_event_name;
41
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
51{
52 const char *version;
53 const char *help;
54};
55
56/* Represents the gcc version. Used to avoid using an incompatible plugin. */
57
59{
60 const char *basever;
61 const char *datestamp;
62 const char *devphase;
63 const char *revision;
65};
66
67/* Object that keeps track of the plugin name and its arguments. */
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
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
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. */
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
108typedef 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
121extern int get_event_last (void);
122
123int 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
130extern void register_callback (const char *plugin_name,
131 int event,
132 plugin_callback_func callback,
133 void *user_data);
134
135extern 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. */
141extern 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
151extern "C" {
152#endif
153extern int plugin_is_GPL_compatible;
154#ifdef __cplusplus
155}
156#endif
157
158
159struct attribute_spec;
160struct scoped_attributes;
161
162extern void add_new_plugin (const char *);
163extern void parse_plugin_arg_opt (const char *);
164extern int invoke_plugin_callbacks_full (int, void *);
165extern void initialize_plugins (void);
166extern bool plugins_active_p (void);
167extern void dump_active_plugins (FILE *);
168extern void debug_active_plugins (void);
169extern void warn_if_plugins (void);
170extern void print_plugins_versions (FILE *file, const char *indent);
171extern void print_plugins_help (FILE *file, const char *indent);
172extern void finalize_plugins (void);
173extern void for_each_plugin (void (*cb) (const plugin_name_args *,
174 void *user_data),
175 void *user_data);
176
177extern bool flag_plugin_added;
178
179/* Called from inside GCC. Invoke all plugin callbacks registered with
180 the specified event.
181 Return PLUGEVT_SUCCESS if at least one callback was called,
182 PLUGEVT_NO_CALLBACK if there was no callback.
183
184 EVENT - the event identifier
185 GCC_DATA - event-specific data provided by the compiler */
186
187inline int
190{
191#ifdef ENABLE_PLUGIN
192 /* True iff at least one plugin has been added. */
195#endif
196
197 return PLUGEVT_NO_CALLBACK;
198}
199
200/* In attribs.cc. */
201
202extern void register_attribute (const struct attribute_spec *attr);
203/* The default argument for the third parameter is given in attribs.h. */
205 bool);
206
207#endif /* PLUGIN_H */
T * ggc_alloc(ALONE_CXX_MEM_STAT_INFO)
Definition ggc.h:184
#define PLUGEVT_NO_CALLBACK
Definition highlev-plugin-common.h:31
bool plugins_active_p(void)
Definition plugin.cc:942
void finalize_plugins(void)
Definition plugin.cc:802
int unregister_callback(const char *plugin_name, int event)
Definition plugin.cc:526
void dump_active_plugins(FILE *)
Definition plugin.cc:958
void debug_active_plugins(void)
Definition plugin.cc:984
int plugin_is_GPL_compatible
void register_callback(const char *plugin_name, int event, plugin_callback_func callback, void *user_data)
Definition plugin.cc:450
int(* plugin_init_func)(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
Definition plugin.h:95
void add_new_plugin(const char *)
Definition plugin.cc:170
void print_plugins_help(FILE *file, const char *indent)
Definition plugin.cc:926
void print_plugins_versions(FILE *file, const char *indent)
Definition plugin.cc:881
void parse_plugin_arg_opt(const char *)
Definition plugin.cc:253
void initialize_plugins(void)
Definition plugin.cc:773
void warn_if_plugins(void)
Definition plugin.cc:993
void(* plugin_callback_func)(void *gcc_data, void *user_data)
Definition plugin.h:108
plugin_event
Definition plugin.h:27
@ PLUGIN_EVENT_FIRST_DYNAMIC
Definition plugin.h:31
void register_attribute(const struct attribute_spec *attr)
Definition attribs.cc:342
int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
bool flag_plugin_added
Definition plugin.cc:116
const char ** plugin_event_name
Definition plugin.cc:62
const char * default_plugin_dir_name(void)
Definition plugin.cc:1044
int get_named_event_id(const char *name, enum insert_option insert)
Definition plugin.cc:390
int invoke_plugin_callbacks_full(int, void *)
Definition plugin.cc:546
bool plugin_default_version_check(struct plugin_gcc_version *, struct plugin_gcc_version *)
Definition plugin.cc:1008
struct scoped_attributes * register_scoped_attributes(const struct scoped_attribute_spec &, bool)
int get_event_last(void)
Definition plugin.cc:1034
void for_each_plugin(void(*cb)(const plugin_name_args *, void *user_data), void *user_data)
Definition plugin.cc:843
int invoke_plugin_callbacks(int event, void *gcc_data)
Definition plugin.h:188
Definition plugin.h:43
char * value
Definition plugin.h:45
char * key
Definition plugin.h:44
Definition plugin.h:59
const char * datestamp
Definition plugin.h:61
const char * revision
Definition plugin.h:63
const char * basever
Definition plugin.h:60
const char * configuration_arguments
Definition plugin.h:64
const char * devphase
Definition plugin.h:62
Definition plugin.h:51
const char * version
Definition plugin.h:52
const char * help
Definition plugin.h:53
Definition plugin.h:69
const char * full_name
Definition plugin.h:72
const char * version
Definition plugin.h:77
const char * help
Definition plugin.h:78
int argc
Definition plugin.h:74
char * base_name
Definition plugin.h:70
struct plugin_argument * argv
Definition plugin.h:76
Definition attribs.cc:87
static void insert(void)
Definition tree-ssa-pre.cc:3796