This is the mail archive of the gdb-cvs@sourceware.org mailing list for the GDB project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[binutils-gdb] Move compile_instance to compile.c


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=946d3d10e7609e074be30db8662cb9c4a3d8961d

commit 946d3d10e7609e074be30db8662cb9c4a3d8961d
Author: Keith Seitz <keiths@redhat.com>
Date:   Fri Aug 10 10:52:13 2018 -0700

    Move compile_instance to compile.c
    
    This simple patch moves any code related to compile_instance into
    compile.c, reserving compile-c-* files strictly for C language support.
    
    gdb/ChangeLog:
            * compile/compile-c-symbols.c (struct symbol_error)
            (hash_symbol_error, eq_symbol_error, del_symbol_error)
            (compile_instance::insert_symbol_error)
            (compile_instance::error_symbol_once): Move to ...
            * compile/compile.c: ... here.

Diff:
---
 gdb/ChangeLog                   |   8 ++
 gdb/compile/compile-c-symbols.c | 102 +----------------------
 gdb/compile/compile-c-types.c   |  92 ---------------------
 gdb/compile/compile-c.h         |   6 ++
 gdb/compile/compile-internal.h  |  13 +++
 gdb/compile/compile.c           | 175 ++++++++++++++++++++++++++++++++++++++++
 6 files changed, 203 insertions(+), 193 deletions(-)

diff --git a/gdb/ChangeLog b/gdb/ChangeLog
index e70a503..50adfcf 100644
--- a/gdb/ChangeLog
+++ b/gdb/ChangeLog
@@ -1,5 +1,13 @@
 2018-08-10  Keith Seitz  <keiths@redhat.com>
 
+	* compile/compile-c-symbols.c (struct symbol_error)
+	(hash_symbol_error, eq_symbol_error, del_symbol_error)
+	(compile_instance::insert_symbol_error)
+	(compile_instance::error_symbol_once): Move to ...
+	* compile/compile.c: ... here.
+
+2018-08-10  Keith Seitz  <keiths@redhat.com>
+
 	* 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):
diff --git a/gdb/compile/compile-c-symbols.c b/gdb/compile/compile-c-symbols.c
index b60b8dd..ecb0c16 100644
--- a/gdb/compile/compile-c-symbols.c
+++ b/gdb/compile/compile-c-symbols.c
@@ -33,110 +33,10 @@
 
 
 
-/* Object of this type are stored in the compiler's symbol_err_map.  */
-
-struct symbol_error
-{
-  /* The symbol.  */
-
-  const struct symbol *sym;
-
-  /* The error message to emit.  This is malloc'd and owned by the
-     hash table.  */
-
-  char *message;
-};
-
-/* Hash function for struct symbol_error.  */
-
-static hashval_t
-hash_symbol_error (const void *a)
-{
-  const struct symbol_error *se = (const struct symbol_error *) a;
-
-  return htab_hash_pointer (se->sym);
-}
-
-/* Equality function for struct symbol_error.  */
-
-static int
-eq_symbol_error (const void *a, const void *b)
-{
-  const struct symbol_error *sea = (const struct symbol_error *) a;
-  const struct symbol_error *seb = (const struct symbol_error *) b;
-
-  return sea->sym == seb->sym;
-}
-
-/* Deletion function for struct symbol_error.  */
-
-static void
-del_symbol_error (void *a)
-{
-  struct symbol_error *se = (struct symbol_error *) a;
-
-  xfree (se->message);
-  xfree (se);
-}
-
-/* See compile-internal.h.  */
-
-void
-compile_instance::insert_symbol_error (const struct symbol *sym,
-				       const char *text)
-{
-  struct symbol_error e;
-  void **slot;
-
-  if (m_symbol_err_map == NULL)
-    {
-      m_symbol_err_map = htab_create_alloc (10,
-					    hash_symbol_error,
-					    eq_symbol_error,
-					    del_symbol_error,
-					    xcalloc,
-					    xfree);
-    }
-
-  e.sym = sym;
-  slot = htab_find_slot (m_symbol_err_map, &e, INSERT);
-  if (*slot == NULL)
-    {
-      struct symbol_error *e = XNEW (struct symbol_error);
-
-      e->sym = sym;
-      e->message = xstrdup (text);
-      *slot = e;
-    }
-}
-
-/* See compile-internal.h.  */
-
-void
-compile_instance::error_symbol_once (const struct symbol *sym)
-{
-  struct symbol_error search;
-  struct symbol_error *err;
-
-  if (m_symbol_err_map == NULL)
-    return;
-
-  search.sym = sym;
-  err = (struct symbol_error *) htab_find (m_symbol_err_map, &search);
-  if (err == NULL || err->message == NULL)
-    return;
-
-  gdb::unique_xmalloc_ptr<char> message (err->message);
-  err->message = NULL;
-  error (_("%s"), message.get ());
-}
-
-
-
 /* Compute the name of the pointer representing a local symbol's
    address.  */
 
-static gdb::unique_xmalloc_ptr<char>
+gdb::unique_xmalloc_ptr<char>
 c_symbol_substitution_name (struct symbol *sym)
 {
   return gdb::unique_xmalloc_ptr<char>
diff --git a/gdb/compile/compile-c-types.c b/gdb/compile/compile-c-types.c
index bfc6ccf..30a4fcb 100644
--- a/gdb/compile/compile-c-types.c
+++ b/gdb/compile/compile-c-types.c
@@ -24,98 +24,6 @@
 #include "compile-c.h"
 #include "objfiles.h"
 
-/* An object that maps a gdb type to a gcc type.  */
-
-struct type_map_instance
-{
-  /* The gdb type.  */
-
-  struct type *type;
-
-  /* The corresponding gcc type handle.  */
-
-  gcc_type gcc_type_handle;
-};
-
-/* Hash a type_map_instance.  */
-
-static hashval_t
-hash_type_map_instance (const void *p)
-{
-  const struct type_map_instance *inst = (const struct type_map_instance *) p;
-
-  return htab_hash_pointer (inst->type);
-}
-
-/* Check two type_map_instance objects for equality.  */
-
-static int
-eq_type_map_instance (const void *a, const void *b)
-{
-  const struct type_map_instance *insta = (const struct type_map_instance *) a;
-  const struct type_map_instance *instb = (const struct type_map_instance *) b;
-
-  return insta->type == instb->type;
-}
-
-/* Constructor for compile_instance.  */
-
-compile_instance::compile_instance (struct gcc_base_context *gcc_fe,
-				    const char *options)
-  : m_gcc_fe (gcc_fe), m_gcc_target_options (options),
-    m_symbol_err_map (NULL)
-{
-  m_type_map = htab_create_alloc (10, hash_type_map_instance,
-				  eq_type_map_instance,
-				  xfree, xcalloc, xfree);
-}
-
-
-
-/* See compile-internal.h.  */
-
-bool
-compile_instance::get_cached_type (struct type *type, gcc_type &ret) const
-{
-  struct type_map_instance inst, *found;
-
-  inst.type = type;
-  found = (struct type_map_instance *) htab_find (m_type_map, &inst);
-  if (found != NULL)
-    {
-      ret = found->gcc_type_handle;
-      return true;
-    }
-
-  return false;
-}
-
-/* See compile-internal.h.  */
-
-void
-compile_instance::insert_type (struct type *type, gcc_type gcc_type)
-{
-  struct type_map_instance inst, *add;
-  void **slot;
-
-  inst.type = type;
-  inst.gcc_type_handle = gcc_type;
-  slot = htab_find_slot (m_type_map, &inst, INSERT);
-
-  add = (struct type_map_instance *) *slot;
-  /* The type might have already been inserted in order to handle
-     recursive types.  */
-  if (add != NULL && add->gcc_type_handle != gcc_type)
-    error (_("Unexpected type id from GCC, check you use recent enough GCC."));
-
-  if (add == NULL)
-    {
-      add = XNEW (struct type_map_instance);
-      *add = inst;
-      *slot = add;
-    }
-}
-
 /* Convert a pointer type to its gcc representation.  */
 
 static gcc_type
diff --git a/gdb/compile/compile-c.h b/gdb/compile/compile-c.h
index 4dece9c..18ff4d3 100644
--- a/gdb/compile/compile-c.h
+++ b/gdb/compile/compile-c.h
@@ -86,4 +86,10 @@ extern const char *c_get_mode_for_size (int size);
 struct dynamic_prop;
 extern std::string c_get_range_decl_name (const struct dynamic_prop *prop);
 
+/* Compute the name of the pointer representing a local symbol's
+   address.  */
+
+extern gdb::unique_xmalloc_ptr<char>
+  c_symbol_substitution_name (struct symbol *sym);
+
 #endif /* GDB_COMPILE_C_H  */
diff --git a/gdb/compile/compile-internal.h b/gdb/compile/compile-internal.h
index 89dd1e5..3916f84 100644
--- a/gdb/compile/compile-internal.h
+++ b/gdb/compile/compile-internal.h
@@ -25,6 +25,19 @@ extern int compile_debug;
 
 struct block;
 
+/* An object that maps a gdb type to a gcc type.  */
+
+struct type_map_instance
+{
+  /* The gdb type.  */
+
+  struct type *type;
+
+  /* The corresponding gcc type handle.  */
+
+  gcc_type gcc_type_handle;
+};
+
 /* An object of this type holds state associated with a given
    compilation job.  */
 
diff --git a/gdb/compile/compile.c b/gdb/compile/compile.c
index 845229b..308c82e 100644
--- a/gdb/compile/compile.c
+++ b/gdb/compile/compile.c
@@ -57,6 +57,181 @@ static struct cmd_list_element *compile_command_list;
 
 int compile_debug;
 
+/* Object of this type are stored in the compiler's symbol_err_map.  */
+
+struct symbol_error
+{
+  /* The symbol.  */
+
+  const struct symbol *sym;
+
+  /* The error message to emit.  This is malloc'd and owned by the
+     hash table.  */
+
+  char *message;
+};
+
+/* Hash a type_map_instance.  */
+
+static hashval_t
+hash_type_map_instance (const void *p)
+{
+  const struct type_map_instance *inst = (const struct type_map_instance *) p;
+
+  return htab_hash_pointer (inst->type);
+}
+
+/* Check two type_map_instance objects for equality.  */
+
+static int
+eq_type_map_instance (const void *a, const void *b)
+{
+  const struct type_map_instance *insta = (const struct type_map_instance *) a;
+  const struct type_map_instance *instb = (const struct type_map_instance *) b;
+
+  return insta->type == instb->type;
+}
+
+/* Hash function for struct symbol_error.  */
+
+static hashval_t
+hash_symbol_error (const void *a)
+{
+  const struct symbol_error *se = (const struct symbol_error *) a;
+
+  return htab_hash_pointer (se->sym);
+}
+
+/* Equality function for struct symbol_error.  */
+
+static int
+eq_symbol_error (const void *a, const void *b)
+{
+  const struct symbol_error *sea = (const struct symbol_error *) a;
+  const struct symbol_error *seb = (const struct symbol_error *) b;
+
+  return sea->sym == seb->sym;
+}
+
+/* Deletion function for struct symbol_error.  */
+
+static void
+del_symbol_error (void *a)
+{
+  struct symbol_error *se = (struct symbol_error *) a;
+
+  xfree (se->message);
+  xfree (se);
+}
+
+/* Constructor for compile_instance.  */
+
+compile_instance::compile_instance (struct gcc_base_context *gcc_fe,
+				    const char *options)
+  : m_gcc_fe (gcc_fe), m_gcc_target_options (options),
+    m_symbol_err_map (NULL)
+{
+  m_type_map = htab_create_alloc (10, hash_type_map_instance,
+				  eq_type_map_instance,
+				  xfree, xcalloc, xfree);
+}
+
+/* See compile-internal.h.  */
+
+bool
+compile_instance::get_cached_type (struct type *type, gcc_type &ret) const
+{
+  struct type_map_instance inst, *found;
+
+  inst.type = type;
+  found = (struct type_map_instance *) htab_find (m_type_map, &inst);
+  if (found != NULL)
+    {
+      ret = found->gcc_type_handle;
+      return true;
+    }
+
+  return false;
+}
+
+/* See compile-internal.h.  */
+
+void
+compile_instance::insert_type (struct type *type, gcc_type gcc_type)
+{
+  struct type_map_instance inst, *add;
+  void **slot;
+
+  inst.type = type;
+  inst.gcc_type_handle = gcc_type;
+  slot = htab_find_slot (m_type_map, &inst, INSERT);
+
+  add = (struct type_map_instance *) *slot;
+  /* The type might have already been inserted in order to handle
+     recursive types.  */
+  if (add != NULL && add->gcc_type_handle != gcc_type)
+    error (_("Unexpected type id from GCC, check you use recent enough GCC."));
+
+  if (add == NULL)
+    {
+      add = XNEW (struct type_map_instance);
+      *add = inst;
+      *slot = add;
+    }
+}
+
+/* See compile-internal.h.  */
+
+void
+compile_instance::insert_symbol_error (const struct symbol *sym,
+				       const char *text)
+{
+  struct symbol_error e;
+  void **slot;
+
+  if (m_symbol_err_map == NULL)
+    {
+      m_symbol_err_map = htab_create_alloc (10,
+					    hash_symbol_error,
+					    eq_symbol_error,
+					    del_symbol_error,
+					    xcalloc,
+					    xfree);
+    }
+
+  e.sym = sym;
+  slot = htab_find_slot (m_symbol_err_map, &e, INSERT);
+  if (*slot == NULL)
+    {
+      struct symbol_error *e = XNEW (struct symbol_error);
+
+      e->sym = sym;
+      e->message = xstrdup (text);
+      *slot = e;
+    }
+}
+
+/* See compile-internal.h.  */
+
+void
+compile_instance::error_symbol_once (const struct symbol *sym)
+{
+  struct symbol_error search;
+  struct symbol_error *err;
+
+  if (m_symbol_err_map == NULL)
+    return;
+
+  search.sym = sym;
+  err = (struct symbol_error *) htab_find (m_symbol_err_map, &search);
+  if (err == NULL || err->message == NULL)
+    return;
+
+  gdb::unique_xmalloc_ptr<char> message (err->message);
+  err->message = NULL;
+  error (_("%s"), message.get ());
+}
+
 /* Implement "show debug compile".  */
 
 static void


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]