gcc-interface.h 6.0 KB

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