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