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