xref: /netbsd-src/external/gpl3/gdb/dist/include/gcc-interface.h (revision e663ba6e3a60083e70de702e9d54bf486a57b6a7)
1968cf8f2Schristos /* Generic interface between GCC 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_INTERFACE_H
21968cf8f2Schristos #define GCC_INTERFACE_H
22968cf8f2Schristos 
23968cf8f2Schristos /* This header defines the interface to the GCC API.  It must be both
24968cf8f2Schristos    valid C and valid C++, because it is included by both programs.  */
25968cf8f2Schristos 
26968cf8f2Schristos #ifdef __cplusplus
27968cf8f2Schristos extern "C" {
28968cf8f2Schristos #endif
29968cf8f2Schristos 
30968cf8f2Schristos /* Opaque typedefs for objects passed through the interface.  */
31968cf8f2Schristos 
32968cf8f2Schristos typedef unsigned long long gcc_type;
33968cf8f2Schristos typedef unsigned long long gcc_decl;
34968cf8f2Schristos 
35968cf8f2Schristos /* An address in the inferior.  */
36968cf8f2Schristos 
37968cf8f2Schristos typedef unsigned long long gcc_address;
38968cf8f2Schristos 
39968cf8f2Schristos /* Forward declaration.  */
40968cf8f2Schristos 
41968cf8f2Schristos struct gcc_base_context;
42968cf8f2Schristos 
43968cf8f2Schristos /* Defined versions of the generic API.  */
44968cf8f2Schristos 
45968cf8f2Schristos enum gcc_base_api_version
46968cf8f2Schristos {
474559860eSchristos   GCC_FE_VERSION_0 = 0,
484559860eSchristos 
494559860eSchristos   /* Deprecated methods set_arguments_v0 and compile_v0.  Added methods
504559860eSchristos      set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and
514559860eSchristos      compile.  */
524559860eSchristos   GCC_FE_VERSION_1 = 1,
53968cf8f2Schristos };
54968cf8f2Schristos 
55968cf8f2Schristos /* The operations defined by the GCC base API.  This is the vtable for
56968cf8f2Schristos    the real context structure which is passed around.
57968cf8f2Schristos 
58968cf8f2Schristos    The "base" API is concerned with basics shared by all compiler
59968cf8f2Schristos    front ends: setting command-line arguments, the file names, etc.
60968cf8f2Schristos 
61968cf8f2Schristos    Front-end-specific interfaces inherit from this one.  */
62968cf8f2Schristos 
63968cf8f2Schristos struct gcc_base_vtable
64968cf8f2Schristos {
65968cf8f2Schristos   /* The actual version implemented in this interface.  This field can
66968cf8f2Schristos      be relied on not to move, so users can always check it if they
67968cf8f2Schristos      desire.  The value is one of the gcc_base_api_version constants.
68968cf8f2Schristos   */
69968cf8f2Schristos 
70968cf8f2Schristos   unsigned int version;
71968cf8f2Schristos 
724559860eSchristos   /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
734559860eSchristos      methods set_triplet_regexp and set_arguments.  */
74968cf8f2Schristos 
754559860eSchristos   char *(*set_arguments_v0) (struct gcc_base_context *self,
76968cf8f2Schristos 			     const char *triplet_regexp,
77968cf8f2Schristos 			     int argc, char **argv);
78968cf8f2Schristos 
79968cf8f2Schristos   /* Set the file name of the program to compile.  The string is
80968cf8f2Schristos      copied by the method implementation, but the caller must
81968cf8f2Schristos      guarantee that the file exists through the compilation.  */
82968cf8f2Schristos 
83968cf8f2Schristos   void (*set_source_file) (struct gcc_base_context *self, const char *file);
84968cf8f2Schristos 
85968cf8f2Schristos   /* Set a callback to use for printing error messages.  DATUM is
86968cf8f2Schristos      passed through to the callback unchanged.  */
87968cf8f2Schristos 
88968cf8f2Schristos   void (*set_print_callback) (struct gcc_base_context *self,
89968cf8f2Schristos 			      void (*print_function) (void *datum,
90968cf8f2Schristos 						      const char *message),
91968cf8f2Schristos 			      void *datum);
92968cf8f2Schristos 
934559860eSchristos   /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1
944559860eSchristos      compile method.  GCC_FE_VERSION_0 version verbose parameter has
954559860eSchristos      been replaced by the set_verbose method.  */
96968cf8f2Schristos 
974559860eSchristos   int /* bool */ (*compile_v0) (struct gcc_base_context *self,
98968cf8f2Schristos 				const char *filename,
99968cf8f2Schristos 				int /* bool */ verbose);
100968cf8f2Schristos 
101968cf8f2Schristos   /* Destroy this object.  */
102968cf8f2Schristos 
103968cf8f2Schristos   void (*destroy) (struct gcc_base_context *self);
1044559860eSchristos 
1054559860eSchristos   /* VERBOSE can be set to non-zero to cause GCC to print some
1064559860eSchristos      information as it works.  Calling this method overrides its
1074559860eSchristos      possible previous calls.
1084559860eSchristos 
1094559860eSchristos      This method is only available since GCC_FE_VERSION_1.  */
1104559860eSchristos 
1114559860eSchristos   void (*set_verbose) (struct gcc_base_context *self,
1124559860eSchristos 		       int /* bool */ verbose);
1134559860eSchristos 
1144559860eSchristos   /* Perform the compilation.  FILENAME is the name of the resulting
1154559860eSchristos      object file.  Either set_triplet_regexp or set_driver_filename must
1164559860eSchristos      be called before.  Returns true on success, false on error.
1174559860eSchristos 
1184559860eSchristos      This method is only available since GCC_FE_VERSION_1.  */
1194559860eSchristos 
1204559860eSchristos   int /* bool */ (*compile) (struct gcc_base_context *self,
1214559860eSchristos 			     const char *filename);
1224559860eSchristos 
1234559860eSchristos   /* Set the compiler's command-line options for the next compilation.
1244559860eSchristos      The arguments are copied by GCC.  ARGV need not be
1254559860eSchristos      NULL-terminated.  The arguments must be set separately for each
1264559860eSchristos      compilation; that is, after a compile is requested, the
1274559860eSchristos      previously-set arguments cannot be reused.
1284559860eSchristos 
1294559860eSchristos      This returns NULL on success.  On failure, returns a malloc()d
1304559860eSchristos      error message.  The caller is responsible for freeing it.
1314559860eSchristos 
1324559860eSchristos      This method is only available since GCC_FE_VERSION_1.  */
1334559860eSchristos 
1344559860eSchristos   char *(*set_arguments) (struct gcc_base_context *self,
1354559860eSchristos 			  int argc, char **argv);
1364559860eSchristos 
1374559860eSchristos   /* Set TRIPLET_REGEXP as a regular expression that is used to match
1384559860eSchristos      the configury triplet prefix to the compiler.  Calling this method
1394559860eSchristos      overrides possible previous call of itself or set_driver_filename.
1404559860eSchristos 
1414559860eSchristos      This returns NULL on success.  On failure, returns a malloc()d
1424559860eSchristos      error message.  The caller is responsible for freeing it.
1434559860eSchristos 
1444559860eSchristos      This method is only available since GCC_FE_VERSION_1.  */
1454559860eSchristos 
1464559860eSchristos   char *(*set_triplet_regexp) (struct gcc_base_context *self,
1474559860eSchristos 			       const char *triplet_regexp);
1484559860eSchristos 
1494559860eSchristos   /* DRIVER_FILENAME should be filename of the gcc compiler driver
1504559860eSchristos      program.  It will be searched in PATH components like
1514559860eSchristos      TRIPLET_REGEXP.  Calling this method overrides possible previous
1524559860eSchristos      call of itself or set_triplet_regexp.
1534559860eSchristos 
1544559860eSchristos      This returns NULL on success.  On failure, returns a malloc()d
1554559860eSchristos      error message.  The caller is responsible for freeing it.
1564559860eSchristos 
1574559860eSchristos      This method is only available since GCC_FE_VERSION_1.  */
1584559860eSchristos 
1594559860eSchristos   char *(*set_driver_filename) (struct gcc_base_context *self,
1604559860eSchristos 				const char *driver_filename);
161968cf8f2Schristos };
162968cf8f2Schristos 
163968cf8f2Schristos /* The GCC object.  */
164968cf8f2Schristos 
165968cf8f2Schristos struct gcc_base_context
166968cf8f2Schristos {
167968cf8f2Schristos   /* The virtual table.  */
168968cf8f2Schristos 
169968cf8f2Schristos   const struct gcc_base_vtable *ops;
170968cf8f2Schristos };
171968cf8f2Schristos 
1724559860eSchristos /* An array of types used for creating function types in multiple
1734559860eSchristos    languages.  */
1744559860eSchristos 
1754559860eSchristos struct gcc_type_array
1764559860eSchristos {
1774559860eSchristos   /* Number of elements.  */
1784559860eSchristos 
1794559860eSchristos   int n_elements;
1804559860eSchristos 
1814559860eSchristos   /* The elements.  */
1824559860eSchristos 
1834559860eSchristos   gcc_type *elements;
1844559860eSchristos };
1854559860eSchristos 
186968cf8f2Schristos /* The name of the dummy wrapper function generated by gdb.  */
187968cf8f2Schristos 
188968cf8f2Schristos #define GCC_FE_WRAPPER_FUNCTION "_gdb_expr"
189968cf8f2Schristos 
190968cf8f2Schristos #ifdef __cplusplus
191968cf8f2Schristos }
192968cf8f2Schristos #endif
193968cf8f2Schristos 
194968cf8f2Schristos #endif /* GCC_INTERFACE_H */
195