aboutsummaryrefslogtreecommitdiff
path: root/gdb/compile/compile-internal.h
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-internal.h
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-internal.h')
-rw-r--r--gdb/compile/compile-internal.h123
1 files changed, 100 insertions, 23 deletions
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
index afe20e5..89dd1e5 100644
--- a/gdb/compile/compile-internal.h
+++ b/gdb/compile/compile-internal.h
@@ -28,28 +28,117 @@ struct block;
/* An object of this type holds state associated with a given
compilation job. */
-struct compile_instance
+class compile_instance
{
- /* The GCC front end. */
+public:
+ compile_instance (struct gcc_base_context *gcc_fe, const char *options);
- struct gcc_base_context *fe;
+ virtual ~compile_instance ()
+ {
+ m_gcc_fe->ops->destroy (m_gcc_fe);
+ htab_delete (m_type_map);
+ if (m_symbol_err_map != NULL)
+ htab_delete (m_symbol_err_map);
+ }
- /* The "scope" of this compilation. */
+ /* Returns the GCC options to be passed during compilation. */
+ const std::string &gcc_target_options () const
+ {
+ return m_gcc_target_options;
+ }
- enum compile_i_scope_types scope;
+ /* Query the type cache for TYPE, returning the compiler's
+ type for it in RET. */
+ bool get_cached_type (struct type *type, gcc_type &ret) const;
- /* The block in which an expression is being parsed. */
+ /* Insert GCC_TYPE into the type cache for TYPE.
+
+ It is ok for a given type to be inserted more than once, provided that
+ the exact same association is made each time. */
+ void insert_type (struct type *type, gcc_type gcc_type);
+
+ /* Associate SYMBOL with some error text. */
+ void insert_symbol_error (const struct symbol *sym, const char *text);
+
+ /* Emit the error message corresponding to SYM, if one exists, and
+ arrange for it not to be emitted again. */
+ void error_symbol_once (const struct symbol *sym);
+
+ /* These currently just forward to the underlying ops
+ vtable. */
+
+ /* Set the plug-in print callback. */
+ void set_print_callback (void (*print_function) (void *, const char *),
+ void *datum);
+
+ /* Return the plug-in's front-end version. */
+ unsigned int version () const;
+
+ /* Set the plug-in's verbosity level. Nop for GCC_FE_VERSION_0. */
+ void set_verbose (int level);
+
+ /* Set the plug-in driver program. Nop for GCC_FE_VERSION_0. */
+ void set_driver_filename (const char *filename);
+
+ /* Set the regular expression used to match the configury triplet
+ prefix to the compiler. Nop for GCC_FE_VERSION_0. */
+ void set_triplet_regexp (const char *regexp);
+
+ /* Set compilation arguments. REGEXP is only used for protocol
+ version GCC_FE_VERSION_0. */
+ char *set_arguments (int argc, char **argv, const char *regexp = NULL);
+
+ /* Set the filename of the program to compile. Nop for GCC_FE_VERSION_0. */
+ void set_source_file (const char *filename);
+
+ /* Compile the previously specified source file to FILENAME.
+ VERBOSE_LEVEL is only used for protocol version GCC_FE_VERSION_0. */
+ bool compile (const char *filename, int verbose_level = -1);
- const struct block *block;
+ /* Set the scope type for this compile. */
+ void set_scope (enum compile_i_scope_types scope)
+ {
+ m_scope = scope;
+ }
+
+ /* Return the scope type. */
+ enum compile_i_scope_types scope () const
+ {
+ return m_scope;
+ }
+
+ /* Set the block to be used for symbol searches. */
+ void set_block (const struct block *block)
+ {
+ m_block = block;
+ }
+
+ /* Return the search block. */
+ const struct block *block () const
+ {
+ return m_block;
+ }
+
+protected:
+
+ /* The GCC front end. */
+ struct gcc_base_context *m_gcc_fe;
+
+ /* The "scope" of this compilation. */
+ enum compile_i_scope_types m_scope;
+
+ /* The block in which an expression is being parsed. */
+ const struct block *m_block;
/* Specify "-std=gnu11", "-std=gnu++11" or similar. These options are put
after CU's DW_AT_producer compilation options to override them. */
+ std::string m_gcc_target_options;
- const char *gcc_target_options;
+ /* Map from gdb types to gcc types. */
+ htab_t m_type_map;
- /* How to destroy this object. */
-
- void (*destroy) (struct compile_instance *);
+ /* Map from gdb symbols to gcc error messages to emit. */
+ htab_t m_symbol_err_map;
};
/* Define header and footers for different scopes. */
@@ -79,18 +168,6 @@ extern std::string compile_register_name_mangled (struct gdbarch *gdbarch,
extern int compile_register_name_demangle (struct gdbarch *gdbarch,
const char *reg_name);
-/* Convert a gdb type, TYPE, to a GCC type. CONTEXT is used to do the
- actual conversion. The new GCC type is returned. */
-
-struct type;
-extern gcc_type convert_type (struct compile_c_instance *context,
- struct type *type);
-
-/* Instantiate a GDB object holding state for the GCC context FE. The
- new object is returned. */
-
-extern struct compile_instance *new_compile_instance (struct gcc_c_context *fe);
-
/* Type used to hold and pass around the source and object file names
to use for compilation. */
class compile_file_names