xref: /netbsd-src/external/gpl3/binutils/dist/include/gcc-interface.h (revision cb63e24e8d6aae7ddac1859a9015f48b1d8bd90e)
19573673dSchristos /* Generic interface between GCC and GDB
29573673dSchristos 
3*cb63e24eSchristos    Copyright (C) 2014-2024 Free Software Foundation, Inc.
49573673dSchristos 
59573673dSchristos    This file is part of GCC.
69573673dSchristos 
79573673dSchristos    This program is free software; you can redistribute it and/or modify
89573673dSchristos    it under the terms of the GNU General Public License as published by
99573673dSchristos    the Free Software Foundation; either version 3 of the License, or
109573673dSchristos    (at your option) any later version.
119573673dSchristos 
129573673dSchristos    This program is distributed in the hope that it will be useful,
139573673dSchristos    but WITHOUT ANY WARRANTY; without even the implied warranty of
149573673dSchristos    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
159573673dSchristos    GNU General Public License for more details.
169573673dSchristos 
179573673dSchristos    You should have received a copy of the GNU General Public License
189573673dSchristos    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
199573673dSchristos 
209573673dSchristos #ifndef GCC_INTERFACE_H
219573673dSchristos #define GCC_INTERFACE_H
229573673dSchristos 
239573673dSchristos /* This header defines the interface to the GCC API.  It must be both
249573673dSchristos    valid C and valid C++, because it is included by both programs.  */
259573673dSchristos 
269573673dSchristos #ifdef __cplusplus
279573673dSchristos extern "C" {
289573673dSchristos #endif
299573673dSchristos 
309573673dSchristos /* Opaque typedefs for objects passed through the interface.  */
319573673dSchristos 
329573673dSchristos typedef unsigned long long gcc_type;
339573673dSchristos typedef unsigned long long gcc_decl;
349573673dSchristos 
359573673dSchristos /* An address in the inferior.  */
369573673dSchristos 
379573673dSchristos typedef unsigned long long gcc_address;
389573673dSchristos 
399573673dSchristos /* Forward declaration.  */
409573673dSchristos 
419573673dSchristos struct gcc_base_context;
429573673dSchristos 
439573673dSchristos /* Defined versions of the generic API.  */
449573673dSchristos 
459573673dSchristos enum gcc_base_api_version
469573673dSchristos {
47fc4f4269Schristos   GCC_FE_VERSION_0 = 0,
48fc4f4269Schristos 
49fc4f4269Schristos   /* Deprecated methods set_arguments_v0 and compile_v0.  Added methods
50fc4f4269Schristos      set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and
51fc4f4269Schristos      compile.  */
52fc4f4269Schristos   GCC_FE_VERSION_1 = 1,
539573673dSchristos };
549573673dSchristos 
559573673dSchristos /* The operations defined by the GCC base API.  This is the vtable for
569573673dSchristos    the real context structure which is passed around.
579573673dSchristos 
589573673dSchristos    The "base" API is concerned with basics shared by all compiler
599573673dSchristos    front ends: setting command-line arguments, the file names, etc.
609573673dSchristos 
619573673dSchristos    Front-end-specific interfaces inherit from this one.  */
629573673dSchristos 
639573673dSchristos struct gcc_base_vtable
649573673dSchristos {
659573673dSchristos   /* The actual version implemented in this interface.  This field can
669573673dSchristos      be relied on not to move, so users can always check it if they
679573673dSchristos      desire.  The value is one of the gcc_base_api_version constants.
689573673dSchristos   */
699573673dSchristos 
709573673dSchristos   unsigned int version;
719573673dSchristos 
72fc4f4269Schristos   /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
73fc4f4269Schristos      methods set_triplet_regexp and set_arguments.  */
749573673dSchristos 
75fc4f4269Schristos   char *(*set_arguments_v0) (struct gcc_base_context *self,
769573673dSchristos 			     const char *triplet_regexp,
779573673dSchristos 			     int argc, char **argv);
789573673dSchristos 
799573673dSchristos   /* Set the file name of the program to compile.  The string is
809573673dSchristos      copied by the method implementation, but the caller must
819573673dSchristos      guarantee that the file exists through the compilation.  */
829573673dSchristos 
839573673dSchristos   void (*set_source_file) (struct gcc_base_context *self, const char *file);
849573673dSchristos 
859573673dSchristos   /* Set a callback to use for printing error messages.  DATUM is
869573673dSchristos      passed through to the callback unchanged.  */
879573673dSchristos 
889573673dSchristos   void (*set_print_callback) (struct gcc_base_context *self,
899573673dSchristos 			      void (*print_function) (void *datum,
909573673dSchristos 						      const char *message),
919573673dSchristos 			      void *datum);
929573673dSchristos 
93fc4f4269Schristos   /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
94fc4f4269Schristos      compile method.  GCC_FE_VERSION_0 version verbose parameter has
95fc4f4269Schristos      been replaced by the set_verbose method.  */
969573673dSchristos 
97fc4f4269Schristos   int /* bool */ (*compile_v0) (struct gcc_base_context *self,
989573673dSchristos 				const char *filename,
999573673dSchristos 				int /* bool */ verbose);
1009573673dSchristos 
1019573673dSchristos   /* Destroy this object.  */
1029573673dSchristos 
1039573673dSchristos   void (*destroy) (struct gcc_base_context *self);
104fc4f4269Schristos 
105fc4f4269Schristos   /* VERBOSE can be set to non-zero to cause GCC to print some
106fc4f4269Schristos      information as it works.  Calling this method overrides its
107fc4f4269Schristos      possible previous calls.
108fc4f4269Schristos 
109fc4f4269Schristos      This method is only available since GCC_FE_VERSION_1.  */
110fc4f4269Schristos 
111fc4f4269Schristos   void (*set_verbose) (struct gcc_base_context *self,
112fc4f4269Schristos 		       int /* bool */ verbose);
113fc4f4269Schristos 
114fc4f4269Schristos   /* Perform the compilation.  FILENAME is the name of the resulting
115fc4f4269Schristos      object file.  Either set_triplet_regexp or set_driver_filename must
116fc4f4269Schristos      be called before.  Returns true on success, false on error.
117fc4f4269Schristos 
118fc4f4269Schristos      This method is only available since GCC_FE_VERSION_1.  */
119fc4f4269Schristos 
120fc4f4269Schristos   int /* bool */ (*compile) (struct gcc_base_context *self,
121fc4f4269Schristos 			     const char *filename);
122fc4f4269Schristos 
123fc4f4269Schristos   /* Set the compiler's command-line options for the next compilation.
124fc4f4269Schristos      The arguments are copied by GCC.  ARGV need not be
125fc4f4269Schristos      NULL-terminated.  The arguments must be set separately for each
126fc4f4269Schristos      compilation; that is, after a compile is requested, the
127fc4f4269Schristos      previously-set arguments cannot be reused.
128fc4f4269Schristos 
129fc4f4269Schristos      This returns NULL on success.  On failure, returns a malloc()d
130fc4f4269Schristos      error message.  The caller is responsible for freeing it.
131fc4f4269Schristos 
132fc4f4269Schristos      This method is only available since GCC_FE_VERSION_1.  */
133fc4f4269Schristos 
134fc4f4269Schristos   char *(*set_arguments) (struct gcc_base_context *self,
135fc4f4269Schristos 			  int argc, char **argv);
136fc4f4269Schristos 
137fc4f4269Schristos   /* Set TRIPLET_REGEXP as a regular expression that is used to match
138fc4f4269Schristos      the configury triplet prefix to the compiler.  Calling this method
139fc4f4269Schristos      overrides possible previous call of itself or set_driver_filename.
140fc4f4269Schristos 
141fc4f4269Schristos      This returns NULL on success.  On failure, returns a malloc()d
142fc4f4269Schristos      error message.  The caller is responsible for freeing it.
143fc4f4269Schristos 
144fc4f4269Schristos      This method is only available since GCC_FE_VERSION_1.  */
145fc4f4269Schristos 
146fc4f4269Schristos   char *(*set_triplet_regexp) (struct gcc_base_context *self,
147fc4f4269Schristos 			       const char *triplet_regexp);
148fc4f4269Schristos 
149fc4f4269Schristos   /* DRIVER_FILENAME should be filename of the gcc compiler driver
150fc4f4269Schristos      program.  It will be searched in PATH components like
151fc4f4269Schristos      TRIPLET_REGEXP.  Calling this method overrides possible previous
152fc4f4269Schristos      call of itself or set_triplet_regexp.
153fc4f4269Schristos 
154fc4f4269Schristos      This returns NULL on success.  On failure, returns a malloc()d
155fc4f4269Schristos      error message.  The caller is responsible for freeing it.
156fc4f4269Schristos 
157fc4f4269Schristos      This method is only available since GCC_FE_VERSION_1.  */
158fc4f4269Schristos 
159fc4f4269Schristos   char *(*set_driver_filename) (struct gcc_base_context *self,
160fc4f4269Schristos 				const char *driver_filename);
1619573673dSchristos };
1629573673dSchristos 
1639573673dSchristos /* The GCC object.  */
1649573673dSchristos 
1659573673dSchristos struct gcc_base_context
1669573673dSchristos {
1679573673dSchristos   /* The virtual table.  */
1689573673dSchristos 
1699573673dSchristos   const struct gcc_base_vtable *ops;
1709573673dSchristos };
1719573673dSchristos 
172fc4f4269Schristos /* An array of types used for creating function types in multiple
173fc4f4269Schristos    languages.  */
174fc4f4269Schristos 
175fc4f4269Schristos struct gcc_type_array
176fc4f4269Schristos {
177fc4f4269Schristos   /* Number of elements.  */
178fc4f4269Schristos 
179fc4f4269Schristos   int n_elements;
180fc4f4269Schristos 
181fc4f4269Schristos   /* The elements.  */
182fc4f4269Schristos 
183fc4f4269Schristos   gcc_type *elements;
184fc4f4269Schristos };
185fc4f4269Schristos 
1869573673dSchristos /* The name of the dummy wrapper function generated by gdb.  */
1879573673dSchristos 
1889573673dSchristos #define GCC_FE_WRAPPER_FUNCTION "_gdb_expr"
1899573673dSchristos 
1909573673dSchristos #ifdef __cplusplus
1919573673dSchristos }
1929573673dSchristos #endif
1939573673dSchristos 
1949573673dSchristos #endif /* GCC_INTERFACE_H */
195