PR sanitizer/83987
[official-gcc.git] / include / gcc-c-interface.h
blobd14472aa7c46f7e71d5bd469aa58b10b23d64cb7
1 /* Interface between GCC C FE and GDB
3 Copyright (C) 2014-2018 Free Software Foundation, Inc.
5 This file is part of GCC.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #ifndef GCC_C_INTERFACE_H
21 #define GCC_C_INTERFACE_H
23 #include "gcc-interface.h"
25 /* This header defines the interface to the GCC API. It must be both
26 valid C and valid C++, because it is included by both programs. */
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
32 /* Forward declaration. */
34 struct gcc_c_context;
37 * Definitions and declarations for the C front end.
40 /* Defined versions of the C front-end API. */
42 enum gcc_c_api_version
44 GCC_C_FE_VERSION_0 = 0,
46 /* Added char_type. Added new version of int_type and float_type,
47 deprecated int_type_v0 and float_type_v0. */
48 GCC_C_FE_VERSION_1 = 1
51 /* Qualifiers. */
53 enum gcc_qualifiers
55 GCC_QUALIFIER_CONST = 1,
56 GCC_QUALIFIER_VOLATILE = 2,
57 GCC_QUALIFIER_RESTRICT = 4
60 /* This enumerates the kinds of decls that GDB can create. */
62 enum gcc_c_symbol_kind
64 /* A function. */
66 GCC_C_SYMBOL_FUNCTION,
68 /* A variable. */
70 GCC_C_SYMBOL_VARIABLE,
72 /* A typedef. */
74 GCC_C_SYMBOL_TYPEDEF,
76 /* A label. */
78 GCC_C_SYMBOL_LABEL
81 /* This enumerates the types of symbols that GCC might request from
82 GDB. */
84 enum gcc_c_oracle_request
86 /* An ordinary symbol -- a variable, function, typedef, or enum
87 constant. */
89 GCC_C_ORACLE_SYMBOL,
91 /* A struct, union, or enum tag. */
93 GCC_C_ORACLE_TAG,
95 /* A label. */
97 GCC_C_ORACLE_LABEL
100 /* The type of the function called by GCC to ask GDB for a symbol's
101 definition. DATUM is an arbitrary value supplied when the oracle
102 function is registered. CONTEXT is the GCC context in which the
103 request is being made. REQUEST specifies what sort of symbol is
104 being requested, and IDENTIFIER is the name of the symbol. */
106 typedef void gcc_c_oracle_function (void *datum,
107 struct gcc_c_context *context,
108 enum gcc_c_oracle_request request,
109 const char *identifier);
111 /* The type of the function called by GCC to ask GDB for a symbol's
112 address. This should return 0 if the address is not known. */
114 typedef gcc_address gcc_c_symbol_address_function (void *datum,
115 struct gcc_c_context *ctxt,
116 const char *identifier);
118 /* The vtable used by the C front end. */
120 struct gcc_c_fe_vtable
122 /* The version of the C interface. The value is one of the
123 gcc_c_api_version constants. */
125 unsigned int c_version;
127 /* Set the callbacks for this context.
129 The binding oracle is called whenever the C parser needs to look
130 up a symbol. This gives the caller a chance to lazily
131 instantiate symbols using other parts of the gcc_c_fe_interface
132 API.
134 The address oracle is called whenever the C parser needs to look
135 up a symbol. This is only called for symbols not provided by the
136 symbol oracle -- that is, just built-in functions where GCC
137 provides the declaration.
139 DATUM is an arbitrary piece of data that is passed back verbatim
140 to the callbacks in requests. */
142 void (*set_callbacks) (struct gcc_c_context *self,
143 gcc_c_oracle_function *binding_oracle,
144 gcc_c_symbol_address_function *address_oracle,
145 void *datum);
147 #define GCC_METHOD0(R, N) \
148 R (*N) (struct gcc_c_context *);
149 #define GCC_METHOD1(R, N, A) \
150 R (*N) (struct gcc_c_context *, A);
151 #define GCC_METHOD2(R, N, A, B) \
152 R (*N) (struct gcc_c_context *, A, B);
153 #define GCC_METHOD3(R, N, A, B, C) \
154 R (*N) (struct gcc_c_context *, A, B, C);
155 #define GCC_METHOD4(R, N, A, B, C, D) \
156 R (*N) (struct gcc_c_context *, A, B, C, D);
157 #define GCC_METHOD5(R, N, A, B, C, D, E) \
158 R (*N) (struct gcc_c_context *, A, B, C, D, E);
159 #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
160 R (*N) (struct gcc_c_context *, A, B, C, D, E, F, G);
162 #include "gcc-c-fe.def"
164 #undef GCC_METHOD0
165 #undef GCC_METHOD1
166 #undef GCC_METHOD2
167 #undef GCC_METHOD3
168 #undef GCC_METHOD4
169 #undef GCC_METHOD5
170 #undef GCC_METHOD7
174 /* The C front end object. */
176 struct gcc_c_context
178 /* Base class. */
180 struct gcc_base_context base;
182 /* Our vtable. This is a separate field because this is simpler
183 than implementing a vtable inheritance scheme in C. */
185 const struct gcc_c_fe_vtable *c_ops;
188 /* The name of the .so that the compiler builds. We dlopen this
189 later. */
191 #define GCC_C_FE_LIBCC libcc1.so
193 /* The compiler exports a single initialization function. This macro
194 holds its name as a symbol. */
196 #define GCC_C_FE_CONTEXT gcc_c_fe_context
198 /* The type of the initialization function. The caller passes in the
199 desired base version and desired C-specific version. If the
200 request can be satisfied, a compatible gcc_context object will be
201 returned. Otherwise, the function returns NULL. */
203 typedef struct gcc_c_context *gcc_c_fe_context_function
204 (enum gcc_base_api_version,
205 enum gcc_c_api_version);
207 #ifdef __cplusplus
209 #endif
211 #endif /* GCC_C_INTERFACE_H */