]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/gcc-plugin.h
PR middle-end/40249
[thirdparty/gcc.git] / gcc / gcc-plugin.h
CommitLineData
9227b6fc 1/* Public header file for plugins to include.
2 Copyright (C) 2009 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 GCC_PLUGIN_H
21#define GCC_PLUGIN_H
22
23/* Event names. Keep in sync with plugin_event_name[]. */
24enum plugin_event
25{
26 PLUGIN_PASS_MANAGER_SETUP, /* To hook into pass manager. */
27 PLUGIN_FINISH_TYPE, /* After finishing parsing a type. */
28 PLUGIN_FINISH_UNIT, /* Useful for summary processing. */
29 PLUGIN_CXX_CP_PRE_GENERICIZE, /* Allows to see low level AST in C++ FE. */
30 PLUGIN_FINISH, /* Called before GCC exits. */
740cd0be 31 PLUGIN_INFO, /* Information about the plugin. */
32 PLUGIN_GGC_START, /* Called at start of GCC Garbage Collection. */
33 PLUGIN_GGC_MARKING, /* Extend the GGC marking. */
34 PLUGIN_GGC_END, /* Called at end of GGC. */
35 PLUGIN_REGISTER_GGC_ROOTS, /* Register an extra GGC root table. */
e3fced1a 36 PLUGIN_ATTRIBUTES, /* Called during attribute registration. */
9227b6fc 37 PLUGIN_EVENT_LAST /* Dummy event used for indexing callback
38 array. */
39};
40
41extern const char *plugin_event_name[];
42
43struct plugin_argument
44{
45 char *key; /* key of the argument. */
46 char *value; /* value is optional and can be NULL. */
47};
48
49enum pass_positioning_ops
50{
51 PASS_POS_INSERT_AFTER, /* Insert after the reference pass. */
52 PASS_POS_INSERT_BEFORE, /* Insert before the reference pass. */
53 PASS_POS_REPLACE /* Replace the reference pass. */
54};
55
56struct plugin_pass
57{
58 struct opt_pass *pass; /* New pass provided by the plugin. */
59 const char *reference_pass_name; /* Name of the reference pass for hooking
60 up the new pass. */
61 int ref_pass_instance_number; /* Insert the pass at the specified
62 instance number of the reference pass.
63 Do it for every instance if it is 0. */
64 enum pass_positioning_ops pos_op; /* how to insert the new pass. */
65};
66
e16288b4 67/* Additional information about the plugin. Used by --help and --version. */
68
69struct plugin_info
70{
71 const char *version;
2dfeb300 72 const char *help;
e16288b4 73};
74
c80cefd7 75/* Represents the gcc version. Used to avoid using an incompatible plugin. */
76
77struct plugin_gcc_version
78{
79 const char *basever;
80 const char *datestamp;
81 const char *devphase;
82 const char *revision;
83 const char *configuration_arguments;
84};
85
0b3a031a 86/* Object that keeps track of the plugin name and its arguments. */
87struct plugin_name_args
88{
89 char *base_name; /* Short name of the plugin (filename without
90 .so suffix). */
91 const char *full_name; /* Path to the plugin as specified with
92 -fplugin=. */
93 int argc; /* Number of arguments specified with
94 -fplugin-arg-... */
95 struct plugin_argument *argv; /* Array of ARGC key-value pairs. */
96 const char *version; /* Version string provided by plugin. */
97 const char *help; /* Help string provided by plugin. */
98};
99
c80cefd7 100/* The default version check. Compares every field in VERSION. */
101
e8ad34e4 102extern bool plugin_default_version_check (struct plugin_gcc_version *,
103 struct plugin_gcc_version *);
c80cefd7 104
9227b6fc 105/* Function type for the plugin initialization routine. Each plugin module
106 should define this as an externally-visible function with name
107 "plugin_init."
108
0b3a031a 109 PLUGIN_INFO - plugin invocation information.
110 VERSION - the plugin_gcc_version symbol of GCC.
9227b6fc 111
112 Returns 0 if initialization finishes successfully. */
113
0b3a031a 114typedef int (*plugin_init_func) (struct plugin_name_args *plugin_info,
115 struct plugin_gcc_version *version);
9227b6fc 116
117/* Declaration for "plugin_init" function so that it doesn't need to be
118 duplicated in every plugin. */
0b3a031a 119extern int plugin_init (struct plugin_name_args *plugin_info,
120 struct plugin_gcc_version *version);
9227b6fc 121
122/* Function type for a plugin callback routine.
123
124 GCC_DATA - event-specific data provided by GCC
125 USER_DATA - plugin-specific data provided by the plugin */
126
127typedef void (*plugin_callback_func) (void *gcc_data, void *user_data);
128
129/* Called from the plugin's initialization code. Register a single callback.
130 This function can be called multiple times.
131
132 PLUGIN_NAME - display name for this plugin
133 EVENT - which event the callback is for
134 CALLBACK - the callback to be called at the event
740cd0be 135 USER_DATA - plugin-provided data.
136*/
137
138/* This is also called without a callback routine for the
139 PLUGIN_PASS_MANAGER_SETUP, PLUGIN_INFO, PLUGIN_REGISTER_GGC_ROOTS
140 pseudo-events, with a specific user_data.
141 */
9227b6fc 142
143extern void register_callback (const char *plugin_name,
144 enum plugin_event event,
145 plugin_callback_func callback,
146 void *user_data);
147
148#endif /* GCC_PLUGIN_H */