175fd0b74Schristos /* Generic interface between GCC and GDB 275fd0b74Schristos 3*e992f068Schristos Copyright (C) 2014-2022 Free Software Foundation, Inc. 475fd0b74Schristos 575fd0b74Schristos This file is part of GCC. 675fd0b74Schristos 775fd0b74Schristos This program is free software; you can redistribute it and/or modify 875fd0b74Schristos it under the terms of the GNU General Public License as published by 975fd0b74Schristos the Free Software Foundation; either version 3 of the License, or 1075fd0b74Schristos (at your option) any later version. 1175fd0b74Schristos 1275fd0b74Schristos This program is distributed in the hope that it will be useful, 1375fd0b74Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 1475fd0b74Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1575fd0b74Schristos GNU General Public License for more details. 1675fd0b74Schristos 1775fd0b74Schristos You should have received a copy of the GNU General Public License 1875fd0b74Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 1975fd0b74Schristos 2075fd0b74Schristos #ifndef GCC_INTERFACE_H 2175fd0b74Schristos #define GCC_INTERFACE_H 2275fd0b74Schristos 2375fd0b74Schristos /* This header defines the interface to the GCC API. It must be both 2475fd0b74Schristos valid C and valid C++, because it is included by both programs. */ 2575fd0b74Schristos 2675fd0b74Schristos #ifdef __cplusplus 2775fd0b74Schristos extern "C" { 2875fd0b74Schristos #endif 2975fd0b74Schristos 3075fd0b74Schristos /* Opaque typedefs for objects passed through the interface. */ 3175fd0b74Schristos 3275fd0b74Schristos typedef unsigned long long gcc_type; 3375fd0b74Schristos typedef unsigned long long gcc_decl; 3475fd0b74Schristos 3575fd0b74Schristos /* An address in the inferior. */ 3675fd0b74Schristos 3775fd0b74Schristos typedef unsigned long long gcc_address; 3875fd0b74Schristos 3975fd0b74Schristos /* Forward declaration. */ 4075fd0b74Schristos 4175fd0b74Schristos struct gcc_base_context; 4275fd0b74Schristos 4375fd0b74Schristos /* Defined versions of the generic API. */ 4475fd0b74Schristos 4575fd0b74Schristos enum gcc_base_api_version 4675fd0b74Schristos { 47ede78133Schristos GCC_FE_VERSION_0 = 0, 48ede78133Schristos 49ede78133Schristos /* Deprecated methods set_arguments_v0 and compile_v0. Added methods 50ede78133Schristos set_arguments, set_triplet_regexp, set_driver_filename, set_verbose and 51ede78133Schristos compile. */ 52ede78133Schristos GCC_FE_VERSION_1 = 1, 5375fd0b74Schristos }; 5475fd0b74Schristos 5575fd0b74Schristos /* The operations defined by the GCC base API. This is the vtable for 5675fd0b74Schristos the real context structure which is passed around. 5775fd0b74Schristos 5875fd0b74Schristos The "base" API is concerned with basics shared by all compiler 5975fd0b74Schristos front ends: setting command-line arguments, the file names, etc. 6075fd0b74Schristos 6175fd0b74Schristos Front-end-specific interfaces inherit from this one. */ 6275fd0b74Schristos 6375fd0b74Schristos struct gcc_base_vtable 6475fd0b74Schristos { 6575fd0b74Schristos /* The actual version implemented in this interface. This field can 6675fd0b74Schristos be relied on not to move, so users can always check it if they 6775fd0b74Schristos desire. The value is one of the gcc_base_api_version constants. 6875fd0b74Schristos */ 6975fd0b74Schristos 7075fd0b74Schristos unsigned int version; 7175fd0b74Schristos 72ede78133Schristos /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 73ede78133Schristos methods set_triplet_regexp and set_arguments. */ 7475fd0b74Schristos 75ede78133Schristos char *(*set_arguments_v0) (struct gcc_base_context *self, 7675fd0b74Schristos const char *triplet_regexp, 7775fd0b74Schristos int argc, char **argv); 7875fd0b74Schristos 7975fd0b74Schristos /* Set the file name of the program to compile. The string is 8075fd0b74Schristos copied by the method implementation, but the caller must 8175fd0b74Schristos guarantee that the file exists through the compilation. */ 8275fd0b74Schristos 8375fd0b74Schristos void (*set_source_file) (struct gcc_base_context *self, const char *file); 8475fd0b74Schristos 8575fd0b74Schristos /* Set a callback to use for printing error messages. DATUM is 8675fd0b74Schristos passed through to the callback unchanged. */ 8775fd0b74Schristos 8875fd0b74Schristos void (*set_print_callback) (struct gcc_base_context *self, 8975fd0b74Schristos void (*print_function) (void *datum, 9075fd0b74Schristos const char *message), 9175fd0b74Schristos void *datum); 9275fd0b74Schristos 93ede78133Schristos /* Deprecated GCC_FE_VERSION_0 variant of the GCC_FE_VERSION_1 94ede78133Schristos compile method. GCC_FE_VERSION_0 version verbose parameter has 95ede78133Schristos been replaced by the set_verbose method. */ 9675fd0b74Schristos 97ede78133Schristos int /* bool */ (*compile_v0) (struct gcc_base_context *self, 9875fd0b74Schristos const char *filename, 9975fd0b74Schristos int /* bool */ verbose); 10075fd0b74Schristos 10175fd0b74Schristos /* Destroy this object. */ 10275fd0b74Schristos 10375fd0b74Schristos void (*destroy) (struct gcc_base_context *self); 104ede78133Schristos 105ede78133Schristos /* VERBOSE can be set to non-zero to cause GCC to print some 106ede78133Schristos information as it works. Calling this method overrides its 107ede78133Schristos possible previous calls. 108ede78133Schristos 109ede78133Schristos This method is only available since GCC_FE_VERSION_1. */ 110ede78133Schristos 111ede78133Schristos void (*set_verbose) (struct gcc_base_context *self, 112ede78133Schristos int /* bool */ verbose); 113ede78133Schristos 114ede78133Schristos /* Perform the compilation. FILENAME is the name of the resulting 115ede78133Schristos object file. Either set_triplet_regexp or set_driver_filename must 116ede78133Schristos be called before. Returns true on success, false on error. 117ede78133Schristos 118ede78133Schristos This method is only available since GCC_FE_VERSION_1. */ 119ede78133Schristos 120ede78133Schristos int /* bool */ (*compile) (struct gcc_base_context *self, 121ede78133Schristos const char *filename); 122ede78133Schristos 123ede78133Schristos /* Set the compiler's command-line options for the next compilation. 124ede78133Schristos The arguments are copied by GCC. ARGV need not be 125ede78133Schristos NULL-terminated. The arguments must be set separately for each 126ede78133Schristos compilation; that is, after a compile is requested, the 127ede78133Schristos previously-set arguments cannot be reused. 128ede78133Schristos 129ede78133Schristos This returns NULL on success. On failure, returns a malloc()d 130ede78133Schristos error message. The caller is responsible for freeing it. 131ede78133Schristos 132ede78133Schristos This method is only available since GCC_FE_VERSION_1. */ 133ede78133Schristos 134ede78133Schristos char *(*set_arguments) (struct gcc_base_context *self, 135ede78133Schristos int argc, char **argv); 136ede78133Schristos 137ede78133Schristos /* Set TRIPLET_REGEXP as a regular expression that is used to match 138ede78133Schristos the configury triplet prefix to the compiler. Calling this method 139ede78133Schristos overrides possible previous call of itself or set_driver_filename. 140ede78133Schristos 141ede78133Schristos This returns NULL on success. On failure, returns a malloc()d 142ede78133Schristos error message. The caller is responsible for freeing it. 143ede78133Schristos 144ede78133Schristos This method is only available since GCC_FE_VERSION_1. */ 145ede78133Schristos 146ede78133Schristos char *(*set_triplet_regexp) (struct gcc_base_context *self, 147ede78133Schristos const char *triplet_regexp); 148ede78133Schristos 149ede78133Schristos /* DRIVER_FILENAME should be filename of the gcc compiler driver 150ede78133Schristos program. It will be searched in PATH components like 151ede78133Schristos TRIPLET_REGEXP. Calling this method overrides possible previous 152ede78133Schristos call of itself or set_triplet_regexp. 153ede78133Schristos 154ede78133Schristos This returns NULL on success. On failure, returns a malloc()d 155ede78133Schristos error message. The caller is responsible for freeing it. 156ede78133Schristos 157ede78133Schristos This method is only available since GCC_FE_VERSION_1. */ 158ede78133Schristos 159ede78133Schristos char *(*set_driver_filename) (struct gcc_base_context *self, 160ede78133Schristos const char *driver_filename); 16175fd0b74Schristos }; 16275fd0b74Schristos 16375fd0b74Schristos /* The GCC object. */ 16475fd0b74Schristos 16575fd0b74Schristos struct gcc_base_context 16675fd0b74Schristos { 16775fd0b74Schristos /* The virtual table. */ 16875fd0b74Schristos 16975fd0b74Schristos const struct gcc_base_vtable *ops; 17075fd0b74Schristos }; 17175fd0b74Schristos 172ede78133Schristos /* An array of types used for creating function types in multiple 173ede78133Schristos languages. */ 174ede78133Schristos 175ede78133Schristos struct gcc_type_array 176ede78133Schristos { 177ede78133Schristos /* Number of elements. */ 178ede78133Schristos 179ede78133Schristos int n_elements; 180ede78133Schristos 181ede78133Schristos /* The elements. */ 182ede78133Schristos 183ede78133Schristos gcc_type *elements; 184ede78133Schristos }; 185ede78133Schristos 18675fd0b74Schristos /* The name of the dummy wrapper function generated by gdb. */ 18775fd0b74Schristos 18875fd0b74Schristos #define GCC_FE_WRAPPER_FUNCTION "_gdb_expr" 18975fd0b74Schristos 19075fd0b74Schristos #ifdef __cplusplus 19175fd0b74Schristos } 19275fd0b74Schristos #endif 19375fd0b74Schristos 19475fd0b74Schristos #endif /* GCC_INTERFACE_H */ 195