aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile/compile.c
diff options
context:
space:
mode:
authorKeith Seitz <keiths@redhat.com>2018-08-10 10:48:03 -0700
committerKeith Seitz <keiths@redhat.com>2018-08-10 11:14:25 -0700
commit9cdfd9a26ef63ef2fee58c0e7475b5373b61e5d1 (patch)
tree65edd204b72edbe64897ffef609af0e566c4db26 /gdb/compile/compile.c
parent18cdc6d8f8e8b55e84783e0a2b5a80b41a0e917b (diff)
downloadbinutils-9cdfd9a26ef63ef2fee58c0e7475b5373b61e5d1.zip
binutils-9cdfd9a26ef63ef2fee58c0e7475b5373b61e5d1.tar.gz
binutils-9cdfd9a26ef63ef2fee58c0e7475b5373b61e5d1.tar.bz2
Change compile_instance/compile_c_instance into classes
This patch changes structs compile_instance and compile_c_instance into classes. Because of the nature of the change, there are a number of unavoidably mechanical changes buried in here, such as turning variable access of the POD struct into method calls, removing the struct keyword, and changing access of the plugin from "c_plugin->operation()" to "plugin ().operation ()". There is one "non-trivial" change associated with this patch, though. The type cache and symbol error maps have been moved into the base class, believing these facilities would be used other language implementations. [They are indeed re-used by C++.] gdb/ChangeLog: * compile/compile-c-support.c (c_get_compile_context): Use `new' instead of `new_compile_instance'. * compile/compile-c-symbols.c (compile_instance::insert_symbol_error): Update description. If the symbol error map is not initialized, create it. (generate_c_for_for_one_symbol): Do not check/initialize the symbol error map. * compile/compile-c-types.c (compile_c_instance): Make a class. Update all callers. (compile_instance::compile_instance): Initialize the type cache. (get_cached_type): New function. (insert_type): Update description. (compile_c_instance::m_default_cflags): Define. (convert_type): Update description. Use get_cached_type. (delete_instance): Moved to destructor. (new_compile_instance): Moved to constructor. * compile/compile-c.h (compile_c_instance): Make class inheriting from compile_instance. <base>: Remove field. <type_map, symbol_err_map>: Move to base class. <c_plugin>: Rename to `m_plugin' and remove pointer type. * compile/compile-internal.h (compile_instance): Make class. <type_map_t, symbol_err_map_t>: Define. <fe>: Rename to `m_gcc_fe'. <scope, block, gcc_target_options>: Add `m_' prefix. <m_type_map, m_symbol_err_map>: New fields, moved from compile_c_instance. <destroy>: Remove. (convert_type, new_compile_instance): Remove. * compile/compile.c (cleanup_compile_instance): Remove. (compile_to_object): Use unique_ptr to eliminate cleanups. (compile_instance::set_print_callback, compile_instance::version) (compile_instance::set_verbose) (compile_instance::set_driver_filename) (compile_instance::set_triplet_regexp) (compile_instance::set_arguments) (compile_instance::set_source_file) (compile_instance::compile): Define.
Diffstat (limited to 'gdb/compile/compile.c')
-rw-r--r--gdb/compile/compile.c153
1 files changed, 102 insertions, 51 deletions
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 01c0bc4..845229b 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -415,7 +415,7 @@ filter_args (int *argcp, char **argv)
generated above. */
static void
-get_args (const struct compile_instance *compiler, struct gdbarch *gdbarch,
+get_args (const compile_instance *compiler, struct gdbarch *gdbarch,
int *argcp, char ***argvp)
{
const char *cs_producer_options;
@@ -437,7 +437,7 @@ get_args (const struct compile_instance *compiler, struct gdbarch *gdbarch,
freeargv (argv_producer);
}
- build_argc_argv (compiler->gcc_target_options,
+ build_argc_argv (compiler->gcc_target_options ().c_str (),
&argc_compiler, &argv_compiler);
append_args (argcp, argvp, argc_compiler, argv_compiler);
freeargv (argv_compiler);
@@ -445,16 +445,6 @@ get_args (const struct compile_instance *compiler, struct gdbarch *gdbarch,
append_args (argcp, argvp, compile_args_argc, compile_args_argv);
}
-/* A cleanup function to destroy a gdb_gcc_instance. */
-
-static void
-cleanup_compile_instance (void *arg)
-{
- struct compile_instance *inst = (struct compile_instance *) arg;
-
- inst->destroy (inst);
-}
-
/* A helper function suitable for use as the "print_callback" in the
compiler object. */
@@ -472,8 +462,6 @@ static compile_file_names
compile_to_object (struct command_line *cmd, const char *cmd_string,
enum compile_i_scope_types scope)
{
- struct compile_instance *compiler;
- struct cleanup *cleanup;
const struct block *expr_block;
CORE_ADDR trash_pc, expr_pc;
int argc;
@@ -481,7 +469,6 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
int ok;
struct gdbarch *gdbarch = get_current_arch ();
std::string triplet_rx;
- char *error_message;
if (!target_has_execution)
error (_("The program must be running for the compile command to "\
@@ -494,13 +481,13 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
if (current_language->la_get_compile_instance == NULL)
error (_("No compiler support for language %s."),
current_language->la_name);
- compiler = current_language->la_get_compile_instance ();
- cleanup = make_cleanup (cleanup_compile_instance, compiler);
- compiler->fe->ops->set_print_callback (compiler->fe, print_callback, NULL);
-
- compiler->scope = scope;
- compiler->block = expr_block;
+ compile_instance *compiler_instance
+ = current_language->la_get_compile_instance ();
+ std::unique_ptr<compile_instance> compiler (compiler_instance);
+ compiler->set_print_callback (print_callback, NULL);
+ compiler->set_scope (scope);
+ compiler->set_block (expr_block);
/* From the provided expression, build a scope to pass to the
compiler. */
@@ -526,21 +513,20 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
error (_("Neither a simple expression, or a multi-line specified."));
std::string code
- = current_language->la_compute_program (compiler, input, gdbarch,
+ = current_language->la_compute_program (compiler.get (), input, gdbarch,
expr_block, expr_pc);
if (compile_debug)
fprintf_unfiltered (gdb_stdlog, "debug output:\n\n%s", code.c_str ());
- if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
- compiler->fe->ops->set_verbose (compiler->fe, compile_debug);
+ compiler->set_verbose (compile_debug);
if (compile_gcc[0] != 0)
{
- if (compiler->fe->ops->version < GCC_FE_VERSION_1)
+ if (compiler->version () < GCC_FE_VERSION_1)
error (_("Command 'set compile-gcc' requires GCC version 6 or higher "
"(libcc1 interface version 1 or higher)"));
- compiler->fe->ops->set_driver_filename (compiler->fe, compile_gcc);
+ compiler->set_driver_filename (compile_gcc);
}
else
{
@@ -549,27 +535,19 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
/* Allow triplets with or without vendor set. */
triplet_rx = std::string (arch_rx) + "(-[^-]*)?-" + os_rx;
-
- if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
- compiler->fe->ops->set_triplet_regexp (compiler->fe,
- triplet_rx.c_str ());
+ compiler->set_triplet_regexp (triplet_rx.c_str ());
}
/* Set compiler command-line arguments. */
- get_args (compiler, gdbarch, &argc, &argv);
+ get_args (compiler.get (), gdbarch, &argc, &argv);
gdb_argv argv_holder (argv);
- if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
- error_message = compiler->fe->ops->set_arguments (compiler->fe, argc, argv);
- else
- error_message = compiler->fe->ops->set_arguments_v0 (compiler->fe,
- triplet_rx.c_str (),
- argc, argv);
+ gdb::unique_xmalloc_ptr<char> error_message;
+ error_message.reset (compiler->set_arguments (argc, argv,
+ triplet_rx.c_str ()));
+
if (error_message != NULL)
- {
- make_cleanup (xfree, error_message);
- error ("%s", error_message);
- }
+ error ("%s", error_message.get ());
if (compile_debug)
{
@@ -601,13 +579,8 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
fnames.source_file ());
/* Call the compiler and start the compilation process. */
- compiler->fe->ops->set_source_file (compiler->fe, fnames.source_file ());
-
- if (compiler->fe->ops->version >= GCC_FE_VERSION_1)
- ok = compiler->fe->ops->compile (compiler->fe, fnames.object_file ());
- else
- ok = compiler->fe->ops->compile_v0 (compiler->fe, fnames.object_file (),
- compile_debug);
+ compiler->set_source_file (fnames.source_file ());
+ ok = compiler->compile (fnames.object_file (), compile_debug);
if (!ok)
error (_("Compilation failed."));
@@ -617,9 +590,6 @@ compile_to_object (struct command_line *cmd, const char *cmd_string,
/* Keep the source file. */
source_remover->keep ();
-
- do_cleanups (cleanup);
-
return fnames;
}
@@ -691,6 +661,87 @@ compile_register_name_demangle (struct gdbarch *gdbarch,
error (_("Cannot find gdbarch register \"%s\"."), regname);
}
+/* Forwards to the plug-in. */
+
+#define FORWARD(OP,...) (m_gcc_fe->ops->OP (m_gcc_fe, ##__VA_ARGS__))
+
+/* See compile-internal.h. */
+
+void
+compile_instance::set_print_callback
+ (void (*print_function) (void *, const char *), void *datum)
+{
+ FORWARD (set_print_callback, print_function, datum);
+}
+
+/* See compile-internal.h. */
+
+unsigned int
+compile_instance::version () const
+{
+ return m_gcc_fe->ops->version;
+}
+
+/* See compile-internal.h. */
+
+void
+compile_instance::set_verbose (int level)
+{
+ if (version () >= GCC_FE_VERSION_1)
+ FORWARD (set_verbose, level);
+}
+
+/* See compile-internal.h. */
+
+void
+compile_instance::set_driver_filename (const char *filename)
+{
+ if (version () >= GCC_FE_VERSION_1)
+ FORWARD (set_driver_filename, filename);
+}
+
+/* See compile-internal.h. */
+
+void
+compile_instance::set_triplet_regexp (const char *regexp)
+{
+ if (version () >= GCC_FE_VERSION_1)
+ FORWARD (set_triplet_regexp, regexp);
+}
+
+/* See compile-internal.h. */
+
+char *
+compile_instance::set_arguments (int argc, char **argv, const char *regexp)
+{
+ if (version () >= GCC_FE_VERSION_1)
+ return FORWARD (set_arguments, argc, argv);
+ else
+ return FORWARD (set_arguments_v0, regexp, argc, argv);
+}
+
+/* See compile-internal.h. */
+
+void
+compile_instance::set_source_file (const char *filename)
+{
+ FORWARD (set_source_file, filename);
+}
+
+/* See compile-internal.h. */
+
+bool
+compile_instance::compile (const char *filename, int verbose_level)
+{
+ if (version () >= GCC_FE_VERSION_1)
+ return FORWARD (compile, filename);
+ else
+ return FORWARD (compile_v0, filename, verbose_level);
+}
+
+#undef FORWARD
+
+
void
_initialize_compile (void)
{