Commit | Line | Data |
---|---|---|
bb2ec1b3 | 1 | /* Header file for GDB compile command and supporting functions. |
42a4f53d | 2 | Copyright (C) 2014-2019 Free Software Foundation, Inc. |
bb2ec1b3 TT |
3 | |
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 | ||
9 | This program is distributed in the hope that it will be useful, | |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | GNU General Public License for more details. | |
13 | ||
14 | You should have received a copy of the GNU General Public License | |
15 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ | |
16 | ||
1a5c2598 TT |
17 | #ifndef COMPILE_COMPILE_INTERNAL_H |
18 | #define COMPILE_COMPILE_INTERNAL_H | |
bb2ec1b3 | 19 | |
bb2ec1b3 TT |
20 | #include "gcc-c-interface.h" |
21 | ||
22 | /* Debugging flag for the "compile" family of commands. */ | |
23 | ||
491144b5 | 24 | extern bool compile_debug; |
bb2ec1b3 TT |
25 | |
26 | struct block; | |
27 | ||
946d3d10 KS |
28 | /* An object that maps a gdb type to a gcc type. */ |
29 | ||
30 | struct type_map_instance | |
31 | { | |
32 | /* The gdb type. */ | |
33 | ||
34 | struct type *type; | |
35 | ||
36 | /* The corresponding gcc type handle. */ | |
37 | ||
38 | gcc_type gcc_type_handle; | |
39 | }; | |
40 | ||
bb2ec1b3 TT |
41 | /* An object of this type holds state associated with a given |
42 | compilation job. */ | |
43 | ||
9cdfd9a2 | 44 | class compile_instance |
bb2ec1b3 | 45 | { |
9cdfd9a2 KS |
46 | public: |
47 | compile_instance (struct gcc_base_context *gcc_fe, const char *options); | |
bb2ec1b3 | 48 | |
9cdfd9a2 KS |
49 | virtual ~compile_instance () |
50 | { | |
51 | m_gcc_fe->ops->destroy (m_gcc_fe); | |
9cdfd9a2 | 52 | } |
bb2ec1b3 | 53 | |
9cdfd9a2 KS |
54 | /* Returns the GCC options to be passed during compilation. */ |
55 | const std::string &gcc_target_options () const | |
56 | { | |
57 | return m_gcc_target_options; | |
58 | } | |
bb2ec1b3 | 59 | |
9cdfd9a2 KS |
60 | /* Query the type cache for TYPE, returning the compiler's |
61 | type for it in RET. */ | |
d82b3862 | 62 | bool get_cached_type (struct type *type, gcc_type *ret) const; |
bb2ec1b3 | 63 | |
9cdfd9a2 KS |
64 | /* Insert GCC_TYPE into the type cache for TYPE. |
65 | ||
66 | It is ok for a given type to be inserted more than once, provided that | |
67 | the exact same association is made each time. */ | |
68 | void insert_type (struct type *type, gcc_type gcc_type); | |
69 | ||
70 | /* Associate SYMBOL with some error text. */ | |
71 | void insert_symbol_error (const struct symbol *sym, const char *text); | |
72 | ||
73 | /* Emit the error message corresponding to SYM, if one exists, and | |
74 | arrange for it not to be emitted again. */ | |
75 | void error_symbol_once (const struct symbol *sym); | |
76 | ||
77 | /* These currently just forward to the underlying ops | |
78 | vtable. */ | |
79 | ||
80 | /* Set the plug-in print callback. */ | |
81 | void set_print_callback (void (*print_function) (void *, const char *), | |
82 | void *datum); | |
83 | ||
84 | /* Return the plug-in's front-end version. */ | |
85 | unsigned int version () const; | |
86 | ||
87 | /* Set the plug-in's verbosity level. Nop for GCC_FE_VERSION_0. */ | |
88 | void set_verbose (int level); | |
89 | ||
90 | /* Set the plug-in driver program. Nop for GCC_FE_VERSION_0. */ | |
91 | void set_driver_filename (const char *filename); | |
92 | ||
93 | /* Set the regular expression used to match the configury triplet | |
94 | prefix to the compiler. Nop for GCC_FE_VERSION_0. */ | |
95 | void set_triplet_regexp (const char *regexp); | |
96 | ||
97 | /* Set compilation arguments. REGEXP is only used for protocol | |
98 | version GCC_FE_VERSION_0. */ | |
99 | char *set_arguments (int argc, char **argv, const char *regexp = NULL); | |
100 | ||
101 | /* Set the filename of the program to compile. Nop for GCC_FE_VERSION_0. */ | |
102 | void set_source_file (const char *filename); | |
103 | ||
104 | /* Compile the previously specified source file to FILENAME. | |
105 | VERBOSE_LEVEL is only used for protocol version GCC_FE_VERSION_0. */ | |
106 | bool compile (const char *filename, int verbose_level = -1); | |
bb2ec1b3 | 107 | |
9cdfd9a2 KS |
108 | /* Set the scope type for this compile. */ |
109 | void set_scope (enum compile_i_scope_types scope) | |
110 | { | |
111 | m_scope = scope; | |
112 | } | |
113 | ||
114 | /* Return the scope type. */ | |
115 | enum compile_i_scope_types scope () const | |
116 | { | |
117 | return m_scope; | |
118 | } | |
119 | ||
120 | /* Set the block to be used for symbol searches. */ | |
121 | void set_block (const struct block *block) | |
122 | { | |
123 | m_block = block; | |
124 | } | |
125 | ||
126 | /* Return the search block. */ | |
127 | const struct block *block () const | |
128 | { | |
129 | return m_block; | |
130 | } | |
131 | ||
132 | protected: | |
133 | ||
134 | /* The GCC front end. */ | |
135 | struct gcc_base_context *m_gcc_fe; | |
136 | ||
137 | /* The "scope" of this compilation. */ | |
138 | enum compile_i_scope_types m_scope; | |
139 | ||
140 | /* The block in which an expression is being parsed. */ | |
141 | const struct block *m_block; | |
bb2ec1b3 TT |
142 | |
143 | /* Specify "-std=gnu11", "-std=gnu++11" or similar. These options are put | |
144 | after CU's DW_AT_producer compilation options to override them. */ | |
9cdfd9a2 | 145 | std::string m_gcc_target_options; |
bb2ec1b3 | 146 | |
9cdfd9a2 | 147 | /* Map from gdb types to gcc types. */ |
0cfbf430 | 148 | htab_up m_type_map; |
bb2ec1b3 | 149 | |
9cdfd9a2 | 150 | /* Map from gdb symbols to gcc error messages to emit. */ |
0cfbf430 | 151 | htab_up m_symbol_err_map; |
bb2ec1b3 TT |
152 | }; |
153 | ||
bb2ec1b3 TT |
154 | /* Define header and footers for different scopes. */ |
155 | ||
156 | /* A simple scope just declares a function named "_gdb_expr", takes no | |
157 | arguments and returns no value. */ | |
158 | ||
159 | #define COMPILE_I_SIMPLE_REGISTER_STRUCT_TAG "__gdb_regs" | |
160 | #define COMPILE_I_SIMPLE_REGISTER_ARG_NAME "__regs" | |
161 | #define COMPILE_I_SIMPLE_REGISTER_DUMMY "_dummy" | |
36de76f9 JK |
162 | #define COMPILE_I_PRINT_OUT_ARG_TYPE "void *" |
163 | #define COMPILE_I_PRINT_OUT_ARG "__gdb_out_param" | |
164 | #define COMPILE_I_EXPR_VAL "__gdb_expr_val" | |
165 | #define COMPILE_I_EXPR_PTR_TYPE "__gdb_expr_ptr_type" | |
bb2ec1b3 | 166 | |
078a0207 KS |
167 | /* A "type" to indicate a NULL type. */ |
168 | ||
169 | const gcc_type GCC_TYPE_NONE = (gcc_type) -1; | |
170 | ||
bb2ec1b3 TT |
171 | /* Call gdbarch_register_name (GDBARCH, REGNUM) and convert its result |
172 | to a form suitable for the compiler source. The register names | |
8f84fb0e | 173 | should not clash with inferior defined macros. */ |
bb2ec1b3 | 174 | |
8f84fb0e TT |
175 | extern std::string compile_register_name_mangled (struct gdbarch *gdbarch, |
176 | int regnum); | |
bb2ec1b3 TT |
177 | |
178 | /* Convert compiler source register name to register number of | |
179 | GDBARCH. Returned value is always >= 0, function throws an error | |
180 | for non-matching REG_NAME. */ | |
181 | ||
182 | extern int compile_register_name_demangle (struct gdbarch *gdbarch, | |
183 | const char *reg_name); | |
184 | ||
aaee65ae PA |
185 | /* Type used to hold and pass around the source and object file names |
186 | to use for compilation. */ | |
187 | class compile_file_names | |
188 | { | |
189 | public: | |
190 | compile_file_names (std::string source_file, std::string object_file) | |
191 | : m_source_file (source_file), m_object_file (object_file) | |
192 | {} | |
193 | ||
194 | /* Provide read-only views only. Return 'const char *' instead of | |
195 | std::string to avoid having to use c_str() everywhere in client | |
196 | code. */ | |
197 | ||
198 | const char *source_file () const | |
199 | { return m_source_file.c_str (); } | |
200 | ||
201 | const char *object_file () const | |
202 | { return m_object_file.c_str (); } | |
203 | ||
204 | private: | |
205 | /* Storage for the file names. */ | |
206 | std::string m_source_file; | |
207 | std::string m_object_file; | |
208 | }; | |
209 | ||
1a5c2598 | 210 | #endif /* COMPILE_COMPILE_INTERNAL_H */ |