gcc-interface.h revision 1.6 1 1.1 christos /* Generic interface between GCC and GDB
2 1.1 christos
3 1.6 christos Copyright (C) 2014-2019 Free Software Foundation, Inc.
4 1.1 christos
5 1.1 christos This file is part of GCC.
6 1.1 christos
7 1.1 christos This program is free software; you can redistribute it and/or modify
8 1.1 christos it under the terms of the GNU General Public License as published by
9 1.1 christos the Free Software Foundation; either version 3 of the License, or
10 1.1 christos (at your option) any later version.
11 1.1 christos
12 1.1 christos This program is distributed in the hope that it will be useful,
13 1.1 christos but WITHOUT ANY WARRANTY; without even the implied warranty of
14 1.1 christos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 1.1 christos GNU General Public License for more details.
16 1.1 christos
17 1.1 christos You should have received a copy of the GNU General Public License
18 1.1 christos along with this program. If not, see <http://www.gnu.org/licenses/>. */
19 1.1 christos
20 1.1 christos #ifndef GCC_INTERFACE_H
21 1.1 christos #define GCC_INTERFACE_H
22 1.1 christos
23 1.1 christos /* This header defines the interface to the GCC API. It must be both
24 1.1 christos valid C and valid C++, because it is included by both programs. */
25 1.1 christos
26 1.1 christos #ifdef __cplusplus
27 1.1 christos extern "C" {
28 1.1 christos #endif
29 1.1 christos
30 1.1 christos /* Opaque typedefs for objects passed through the interface. */
31 1.1 christos
32 1.1 christos typedef unsigned long long gcc_type;
33 1.1 christos typedef unsigned long long gcc_decl;
34 1.1 christos
35 1.1 christos /* An address in the inferior. */
36 1.1 christos
37 1.1 christos typedef unsigned long long gcc_address;
38 1.1 christos
39 1.1 christos /* Forward declaration. */
40 1.1 christos
41 1.1 christos struct gcc_base_context;
42 1.1 christos
43 1.1 christos /* Defined versions of the generic API. */
44 1.1 christos
45 1.1 christos enum gcc_base_api_version
46 1.1 christos {
47 1.6 christos GCC_FE_VERSION_0 = 0,
48 1.6 christos
49 1.6 christos /* Deprecated methods set_arguments_v0 and compile_v0. Added methods
50 1.6 christos set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and
51 1.6 christos compile. */
52 1.6 christos GCC_FE_VERSION_1 = 1,
53 1.1 christos };
54 1.1 christos
55 1.1 christos /* The operations defined by the GCC base API. This is the vtable for
56 1.1 christos the real context structure which is passed around.
57 1.1 christos
58 1.1 christos The "base" API is concerned with basics shared by all compiler
59 1.1 christos front ends: setting command-line arguments, the file names, etc.
60 1.1 christos
61 1.1 christos Front-end-specific interfaces inherit from this one. */
62 1.1 christos
63 1.1 christos struct gcc_base_vtable
64 1.1 christos {
65 1.1 christos /* The actual version implemented in this interface. This field can
66 1.1 christos be relied on not to move, so users can always check it if they
67 1.1 christos desire. The value is one of the gcc_base_api_version constants.
68 1.1 christos */
69 1.1 christos
70 1.1 christos unsigned int version;
71 1.1 christos
72 1.6 christos /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
73 1.6 christos methods set_triplet_regexp and set_arguments. */
74 1.1 christos
75 1.6 christos char *(*set_arguments_v0) (struct gcc_base_context *self,
76 1.6 christos const char *triplet_regexp,
77 1.6 christos int argc, char **argv);
78 1.1 christos
79 1.1 christos /* Set the file name of the program to compile. The string is
80 1.1 christos copied by the method implementation, but the caller must
81 1.1 christos guarantee that the file exists through the compilation. */
82 1.1 christos
83 1.1 christos void (*set_source_file) (struct gcc_base_context *self, const char *file);
84 1.1 christos
85 1.1 christos /* Set a callback to use for printing error messages. DATUM is
86 1.1 christos passed through to the callback unchanged. */
87 1.1 christos
88 1.1 christos void (*set_print_callback) (struct gcc_base_context *self,
89 1.1 christos void (*print_function) (void *datum,
90 1.1 christos const char *message),
91 1.1 christos void *datum);
92 1.1 christos
93 1.6 christos /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
94 1.6 christos compile method. GCC_FE_VERSION_0 version verbose parameter has
95 1.6 christos been replaced by the set_verbose method. */
96 1.6 christos
97 1.6 christos int /* bool */ (*compile_v0) (struct gcc_base_context *self,
98 1.6 christos const char *filename,
99 1.6 christos int /* bool */ verbose);
100 1.6 christos
101 1.6 christos /* Destroy this object. */
102 1.6 christos
103 1.6 christos void (*destroy) (struct gcc_base_context *self);
104 1.6 christos
105 1.6 christos /* VERBOSE can be set to non-zero to cause GCC to print some
106 1.6 christos information as it works. Calling this method overrides its
107 1.6 christos possible previous calls.
108 1.6 christos
109 1.6 christos This method is only available since GCC_FE_VERSION_1. */
110 1.6 christos
111 1.6 christos void (*set_verbose) (struct gcc_base_context *self,
112 1.6 christos int /* bool */ verbose);
113 1.6 christos
114 1.1 christos /* Perform the compilation. FILENAME is the name of the resulting
115 1.6 christos object file. Either set_triplet_regexp or set_driver_filename must
116 1.6 christos be called before. Returns true on success, false on error.
117 1.6 christos
118 1.6 christos This method is only available since GCC_FE_VERSION_1. */
119 1.1 christos
120 1.1 christos int /* bool */ (*compile) (struct gcc_base_context *self,
121 1.6 christos const char *filename);
122 1.6 christos
123 1.6 christos /* Set the compiler's command-line options for the next compilation.
124 1.6 christos The arguments are copied by GCC. ARGV need not be
125 1.6 christos NULL-terminated. The arguments must be set separately for each
126 1.6 christos compilation; that is, after a compile is requested, the
127 1.6 christos previously-set arguments cannot be reused.
128 1.6 christos
129 1.6 christos This returns NULL on success. On failure, returns a malloc()d
130 1.6 christos error message. The caller is responsible for freeing it.
131 1.6 christos
132 1.6 christos This method is only available since GCC_FE_VERSION_1. */
133 1.6 christos
134 1.6 christos char *(*set_arguments) (struct gcc_base_context *self,
135 1.6 christos int argc, char **argv);
136 1.6 christos
137 1.6 christos /* Set TRIPLET_REGEXP as a regular expression that is used to match
138 1.6 christos the configury triplet prefix to the compiler. Calling this method
139 1.6 christos overrides possible previous call of itself or set_driver_filename.
140 1.6 christos
141 1.6 christos This returns NULL on success. On failure, returns a malloc()d
142 1.6 christos error message. The caller is responsible for freeing it.
143 1.6 christos
144 1.6 christos This method is only available since GCC_FE_VERSION_1. */
145 1.6 christos
146 1.6 christos char *(*set_triplet_regexp) (struct gcc_base_context *self,
147 1.6 christos const char *triplet_regexp);
148 1.1 christos
149 1.6 christos /* DRIVER_FILENAME should be filename of the gcc compiler driver
150 1.6 christos program. It will be searched in PATH components like
151 1.6 christos TRIPLET_REGEXP. Calling this method overrides possible previous
152 1.6 christos call of itself or set_triplet_regexp.
153 1.6 christos
154 1.6 christos This returns NULL on success. On failure, returns a malloc()d
155 1.6 christos error message. The caller is responsible for freeing it.
156 1.6 christos
157 1.6 christos This method is only available since GCC_FE_VERSION_1. */
158 1.1 christos
159 1.6 christos char *(*set_driver_filename) (struct gcc_base_context *self,
160 1.6 christos const char *driver_filename);
161 1.1 christos };
162 1.1 christos
163 1.1 christos /* The GCC object. */
164 1.1 christos
165 1.1 christos struct gcc_base_context
166 1.1 christos {
167 1.1 christos /* The virtual table. */
168 1.1 christos
169 1.1 christos const struct gcc_base_vtable *ops;
170 1.1 christos };
171 1.1 christos
172 1.6 christos /* An array of types used for creating function types in multiple
173 1.6 christos languages. */
174 1.6 christos
175 1.6 christos struct gcc_type_array
176 1.6 christos {
177 1.6 christos /* Number of elements. */
178 1.6 christos
179 1.6 christos int n_elements;
180 1.6 christos
181 1.6 christos /* The elements. */
182 1.6 christos
183 1.6 christos gcc_type *elements;
184 1.6 christos };
185 1.6 christos
186 1.1 christos /* The name of the dummy wrapper function generated by gdb. */
187 1.1 christos
188 1.1 christos #define GCC_FE_WRAPPER_FUNCTION "_gdb_expr"
189 1.1 christos
190 1.1 christos #ifdef __cplusplus
191 1.1 christos }
192 1.1 christos #endif
193 1.1 christos
194 1.1 christos #endif /* GCC_INTERFACE_H */
195