xref: /netbsd-src/external/gpl3/gdb/dist/include/gcc-c-interface.h (revision e663ba6e3a60083e70de702e9d54bf486a57b6a7)
1968cf8f2Schristos /* Interface between GCC C FE and GDB
2968cf8f2Schristos 
3*e663ba6eSchristos    Copyright (C) 2014-2024 Free Software Foundation, Inc.
4968cf8f2Schristos 
5968cf8f2Schristos    This file is part of GCC.
6968cf8f2Schristos 
7968cf8f2Schristos    This program is free software; you can redistribute it and/or modify
8968cf8f2Schristos    it under the terms of the GNU General Public License as published by
9968cf8f2Schristos    the Free Software Foundation; either version 3 of the License, or
10968cf8f2Schristos    (at your option) any later version.
11968cf8f2Schristos 
12968cf8f2Schristos    This program is distributed in the hope that it will be useful,
13968cf8f2Schristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
14968cf8f2Schristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15968cf8f2Schristos    GNU General Public License for more details.
16968cf8f2Schristos 
17968cf8f2Schristos    You should have received a copy of the GNU General Public License
18968cf8f2Schristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
19968cf8f2Schristos 
20968cf8f2Schristos #ifndef GCC_C_INTERFACE_H
21968cf8f2Schristos #define GCC_C_INTERFACE_H
22968cf8f2Schristos 
23968cf8f2Schristos #include "gcc-interface.h"
24968cf8f2Schristos 
25968cf8f2Schristos /* This header defines the interface to the GCC API.  It must be both
26968cf8f2Schristos    valid C and valid C++, because it is included by both programs.  */
27968cf8f2Schristos 
28968cf8f2Schristos #ifdef __cplusplus
29968cf8f2Schristos extern "C" {
30968cf8f2Schristos #endif
31968cf8f2Schristos 
32968cf8f2Schristos /* Forward declaration.  */
33968cf8f2Schristos 
34968cf8f2Schristos struct gcc_c_context;
35968cf8f2Schristos 
36968cf8f2Schristos /*
37968cf8f2Schristos  * Definitions and declarations for the C front end.
38968cf8f2Schristos  */
39968cf8f2Schristos 
40968cf8f2Schristos /* Defined versions of the C front-end API.  */
41968cf8f2Schristos 
42968cf8f2Schristos enum gcc_c_api_version
43968cf8f2Schristos {
444559860eSchristos   GCC_C_FE_VERSION_0 = 0,
454559860eSchristos 
464559860eSchristos   /* Added char_type.  Added new version of int_type and float_type,
474559860eSchristos      deprecated int_type_v0 and float_type_v0.  */
48*e663ba6eSchristos   GCC_C_FE_VERSION_1 = 1,
49*e663ba6eSchristos 
50*e663ba6eSchristos   /* Added finish_record_with_alignment method.  */
51*e663ba6eSchristos   GCC_C_FE_VERSION_2 = 2,
52968cf8f2Schristos };
53968cf8f2Schristos 
54968cf8f2Schristos /* Qualifiers.  */
55968cf8f2Schristos 
56968cf8f2Schristos enum gcc_qualifiers
57968cf8f2Schristos {
58968cf8f2Schristos   GCC_QUALIFIER_CONST = 1,
59968cf8f2Schristos   GCC_QUALIFIER_VOLATILE = 2,
60968cf8f2Schristos   GCC_QUALIFIER_RESTRICT = 4
61968cf8f2Schristos };
62968cf8f2Schristos 
63968cf8f2Schristos /* This enumerates the kinds of decls that GDB can create.  */
64968cf8f2Schristos 
65968cf8f2Schristos enum gcc_c_symbol_kind
66968cf8f2Schristos {
67968cf8f2Schristos   /* A function.  */
68968cf8f2Schristos 
69968cf8f2Schristos   GCC_C_SYMBOL_FUNCTION,
70968cf8f2Schristos 
71968cf8f2Schristos   /* A variable.  */
72968cf8f2Schristos 
73968cf8f2Schristos   GCC_C_SYMBOL_VARIABLE,
74968cf8f2Schristos 
75968cf8f2Schristos   /* A typedef.  */
76968cf8f2Schristos 
77968cf8f2Schristos   GCC_C_SYMBOL_TYPEDEF,
78968cf8f2Schristos 
79968cf8f2Schristos   /* A label.  */
80968cf8f2Schristos 
81968cf8f2Schristos   GCC_C_SYMBOL_LABEL
82968cf8f2Schristos };
83968cf8f2Schristos 
84968cf8f2Schristos /* This enumerates the types of symbols that GCC might request from
85968cf8f2Schristos    GDB.  */
86968cf8f2Schristos 
87968cf8f2Schristos enum gcc_c_oracle_request
88968cf8f2Schristos {
89968cf8f2Schristos   /* An ordinary symbol -- a variable, function, typedef, or enum
90968cf8f2Schristos      constant.  */
91968cf8f2Schristos 
92968cf8f2Schristos   GCC_C_ORACLE_SYMBOL,
93968cf8f2Schristos 
94968cf8f2Schristos   /* A struct, union, or enum tag.  */
95968cf8f2Schristos 
96968cf8f2Schristos   GCC_C_ORACLE_TAG,
97968cf8f2Schristos 
98968cf8f2Schristos   /* A label.  */
99968cf8f2Schristos 
100968cf8f2Schristos   GCC_C_ORACLE_LABEL
101968cf8f2Schristos };
102968cf8f2Schristos 
103968cf8f2Schristos /* The type of the function called by GCC to ask GDB for a symbol's
104968cf8f2Schristos    definition.  DATUM is an arbitrary value supplied when the oracle
105968cf8f2Schristos    function is registered.  CONTEXT is the GCC context in which the
106968cf8f2Schristos    request is being made.  REQUEST specifies what sort of symbol is
107968cf8f2Schristos    being requested, and IDENTIFIER is the name of the symbol.  */
108968cf8f2Schristos 
109968cf8f2Schristos typedef void gcc_c_oracle_function (void *datum,
110968cf8f2Schristos 				    struct gcc_c_context *context,
111968cf8f2Schristos 				    enum gcc_c_oracle_request request,
112968cf8f2Schristos 				    const char *identifier);
113968cf8f2Schristos 
114968cf8f2Schristos /* The type of the function called by GCC to ask GDB for a symbol's
115968cf8f2Schristos    address.  This should return 0 if the address is not known.  */
116968cf8f2Schristos 
117968cf8f2Schristos typedef gcc_address gcc_c_symbol_address_function (void *datum,
118968cf8f2Schristos 						   struct gcc_c_context *ctxt,
119968cf8f2Schristos 						   const char *identifier);
120968cf8f2Schristos 
121968cf8f2Schristos /* The vtable used by the C front end.  */
122968cf8f2Schristos 
123968cf8f2Schristos struct gcc_c_fe_vtable
124968cf8f2Schristos {
125968cf8f2Schristos   /* The version of the C interface.  The value is one of the
126968cf8f2Schristos      gcc_c_api_version constants.  */
127968cf8f2Schristos 
128968cf8f2Schristos   unsigned int c_version;
129968cf8f2Schristos 
130968cf8f2Schristos   /* Set the callbacks for this context.
131968cf8f2Schristos 
132968cf8f2Schristos      The binding oracle is called whenever the C parser needs to look
133968cf8f2Schristos      up a symbol.  This gives the caller a chance to lazily
134968cf8f2Schristos      instantiate symbols using other parts of the gcc_c_fe_interface
135968cf8f2Schristos      API.
136968cf8f2Schristos 
137968cf8f2Schristos      The address oracle is called whenever the C parser needs to look
138968cf8f2Schristos      up a symbol.  This is only called for symbols not provided by the
139968cf8f2Schristos      symbol oracle -- that is, just built-in functions where GCC
140968cf8f2Schristos      provides the declaration.
141968cf8f2Schristos 
142968cf8f2Schristos      DATUM is an arbitrary piece of data that is passed back verbatim
1434559860eSchristos      to the callbacks in requests.  */
144968cf8f2Schristos 
145968cf8f2Schristos   void (*set_callbacks) (struct gcc_c_context *self,
146968cf8f2Schristos 			 gcc_c_oracle_function *binding_oracle,
147968cf8f2Schristos 			 gcc_c_symbol_address_function *address_oracle,
148968cf8f2Schristos 			 void *datum);
149968cf8f2Schristos 
150968cf8f2Schristos #define GCC_METHOD0(R, N) \
151968cf8f2Schristos   R (*N) (struct gcc_c_context *);
152968cf8f2Schristos #define GCC_METHOD1(R, N, A) \
153968cf8f2Schristos   R (*N) (struct gcc_c_context *, A);
154968cf8f2Schristos #define GCC_METHOD2(R, N, A, B) \
155968cf8f2Schristos   R (*N) (struct gcc_c_context *, A, B);
156968cf8f2Schristos #define GCC_METHOD3(R, N, A, B, C) \
157968cf8f2Schristos   R (*N) (struct gcc_c_context *, A, B, C);
158968cf8f2Schristos #define GCC_METHOD4(R, N, A, B, C, D) \
159968cf8f2Schristos   R (*N) (struct gcc_c_context *, A, B, C, D);
160968cf8f2Schristos #define GCC_METHOD5(R, N, A, B, C, D, E) \
161968cf8f2Schristos   R (*N) (struct gcc_c_context *, A, B, C, D, E);
162968cf8f2Schristos #define GCC_METHOD7(R, N, A, B, C, D, E, F, G) \
163968cf8f2Schristos   R (*N) (struct gcc_c_context *, A, B, C, D, E, F, G);
164968cf8f2Schristos 
165968cf8f2Schristos #include "gcc-c-fe.def"
166968cf8f2Schristos 
167968cf8f2Schristos #undef GCC_METHOD0
168968cf8f2Schristos #undef GCC_METHOD1
169968cf8f2Schristos #undef GCC_METHOD2
170968cf8f2Schristos #undef GCC_METHOD3
171968cf8f2Schristos #undef GCC_METHOD4
172968cf8f2Schristos #undef GCC_METHOD5
173968cf8f2Schristos #undef GCC_METHOD7
174968cf8f2Schristos 
175968cf8f2Schristos };
176968cf8f2Schristos 
177968cf8f2Schristos /* The C front end object.  */
178968cf8f2Schristos 
179968cf8f2Schristos struct gcc_c_context
180968cf8f2Schristos {
181968cf8f2Schristos   /* Base class.  */
182968cf8f2Schristos 
183968cf8f2Schristos   struct gcc_base_context base;
184968cf8f2Schristos 
185968cf8f2Schristos   /* Our vtable.  This is a separate field because this is simpler
186968cf8f2Schristos      than implementing a vtable inheritance scheme in C.  */
187968cf8f2Schristos 
188968cf8f2Schristos   const struct gcc_c_fe_vtable *c_ops;
189968cf8f2Schristos };
190968cf8f2Schristos 
191968cf8f2Schristos /* The name of the .so that the compiler builds.  We dlopen this
192968cf8f2Schristos    later.  */
193968cf8f2Schristos 
194968cf8f2Schristos #define GCC_C_FE_LIBCC libcc1.so
195968cf8f2Schristos 
196968cf8f2Schristos /* The compiler exports a single initialization function.  This macro
197968cf8f2Schristos    holds its name as a symbol.  */
198968cf8f2Schristos 
199968cf8f2Schristos #define GCC_C_FE_CONTEXT gcc_c_fe_context
200968cf8f2Schristos 
201968cf8f2Schristos /* The type of the initialization function.  The caller passes in the
202968cf8f2Schristos    desired base version and desired C-specific version.  If the
203968cf8f2Schristos    request can be satisfied, a compatible gcc_context object will be
204*e663ba6eSchristos    returned.  In particular, this may return a context object with a higher
205*e663ba6eSchristos    actual version number than was requested, provided the higher version is
206*e663ba6eSchristos    fully compatible.  (As of GCC_C_FE_VERSION_2, this is always true.)
207*e663ba6eSchristos 
208*e663ba6eSchristos    Otherwise, the function returns NULL.  */
209968cf8f2Schristos 
210968cf8f2Schristos typedef struct gcc_c_context *gcc_c_fe_context_function
211968cf8f2Schristos     (enum gcc_base_api_version,
212968cf8f2Schristos      enum gcc_c_api_version);
213968cf8f2Schristos 
214968cf8f2Schristos #ifdef __cplusplus
215968cf8f2Schristos }
216968cf8f2Schristos #endif
217968cf8f2Schristos 
218968cf8f2Schristos #endif /* GCC_C_INTERFACE_H */
219