Simplify floatformat_from_type
authorUlrich Weigand <ulrich.weigand@de.ibm.com>
Wed, 27 Sep 2017 17:03:36 +0000 (19:03 +0200)
committerUlrich Weigand <ulrich.weigand@de.ibm.com>
Wed, 27 Sep 2017 17:03:36 +0000 (19:03 +0200)
For historical reasons, the TYPE_FLOATFORMAT element is still set to hold
an array of two floatformat structs, one for big-endian and the other for
little-endian.  When accessing the element via floatformat_from_type,
the code would check the type's byte order and return the appropriate
floatformat.

However, these days this is quite unnecessary, since the type's byte order
is already known at the time the type is allocated and the floatformat is
installed into TYPE_FLOATFORMAT.  Therefore, we can just install the correct
version here.

Also, moves the (now trivially simple) floatformat_from_type accessor to
gdbtypes.{c,h}, since it doesn't really need to be in doublest.c now.

gdb/ChangeLog
2017-09-27  Ulrich Weigand  <uweigand@de.ibm.com>

* doublest.h (floatformat_from_type): Move to gdbtypes.h.
* doublest.c (floatformat_from_type): Move to gdbtypes.c.

* gdbtypes.h (union type_specific): Make field floatformat hold
just a single struct floatformat, not an array.
(floatformat_from_type): Move here.
* gdbtypes.c (floatformat_from_type): Move here.  Update to
changed TYPE_FLOATFORMAT definition.
(verify_floatformat): Update to changed TYPE_FLOATFORMAT.
(recursive_dump_type): Likewise.
(init_float_type): Install correct floatformat for byte order.
(arch_float_type): Likewise.

gdb/ChangeLog
gdb/doublest.c
gdb/doublest.h
gdb/gdbtypes.c
gdb/gdbtypes.h

index 7de454209985ed65a127c9414957706ae67bdb90..478ec658be355359f38f2c4ec4376bf803aaf971 100644 (file)
@@ -1,3 +1,18 @@
+2017-09-27  Ulrich Weigand  <uweigand@de.ibm.com>
+
+       * doublest.h (floatformat_from_type): Move to gdbtypes.h.
+       * doublest.c (floatformat_from_type): Move to gdbtypes.c.
+
+       * gdbtypes.h (union type_specific): Make field floatformat hold
+       just a single struct floatformat, not an array.
+       (floatformat_from_type): Move here.
+       * gdbtypes.c (floatformat_from_type): Move here.  Update to
+       changed TYPE_FLOATFORMAT definition.
+       (verify_floatformat): Update to changed TYPE_FLOATFORMAT.
+       (recursive_dump_type): Likewise.
+       (init_float_type): Install correct floatformat for byte order.
+       (arch_float_type): Likewise.
+
 2017-09-27  Ulrich Weigand  <uweigand@de.ibm.com>
 
        * gdbtypes.c (init_type): Change incoming argument from
index e464177bcc77767b06935cbfc7adc32966f90488..2047087c3d6c1a50a8debb4fd23487dced04be76 100644 (file)
@@ -770,22 +770,6 @@ floatformat_from_doublest (const struct floatformat *fmt,
 }
 
 \f
-/* Return the floating-point format for a floating-point variable of
-   type TYPE.  */
-
-const struct floatformat *
-floatformat_from_type (const struct type *type)
-{
-  struct gdbarch *gdbarch = get_type_arch (type);
-  const struct floatformat *fmt;
-
-  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
-  gdb_assert (TYPE_FLOATFORMAT (type));
-  fmt = TYPE_FLOATFORMAT (type)[gdbarch_byte_order (gdbarch)];
-  gdb_assert (TYPE_LENGTH (type) >= floatformat_totalsize_bytes (fmt));
-  return fmt;
-}
-
 /* Extract a floating-point number of type TYPE from a target-order
    byte-stream at ADDR.  Returns the value as type DOUBLEST.  */
 
index 23c6ee5e8be7f7e5c6f78c1ddd116fe1eed48993..a22baef89ed6dde91dcb74e9efffe6c7add53248 100644 (file)
@@ -83,12 +83,6 @@ extern enum float_kind floatformat_classify (const struct floatformat *,
 extern const char *floatformat_mantissa (const struct floatformat *,
                                         const bfd_byte *);
 
-/* Given TYPE, return its floatformat.  TYPE_FLOATFORMAT() may return
-   NULL.  type_floatformat() detects that and returns a floatformat
-   based on the type size when FLOATFORMAT is NULL.  */
-
-const struct floatformat *floatformat_from_type (const struct type *type);
-
 /* Return the floatformat's total size in host bytes.  */
 
 extern size_t floatformat_totalsize_bytes (const struct floatformat *fmt);
index bec1fd5f2d08940c6d1b6c6178c57deff1cc10cf..57bc218d91d1c1e73bef6b455f14ed2afa84a0d7 100644 (file)
@@ -2734,22 +2734,30 @@ set_type_code (struct type *type, enum type_code code)
    determined by the floatformat.  Returns size to be used.  */
 
 static int
-verify_floatformat (int bit, const struct floatformat **floatformats)
+verify_floatformat (int bit, const struct floatformat *floatformat)
 {
-  gdb_assert (floatformats != NULL);
-  gdb_assert (floatformats[0] != NULL && floatformats[1] != NULL);
+  gdb_assert (floatformat != NULL);
 
   if (bit == -1)
-    bit = floatformats[0]->totalsize;
-  gdb_assert (bit >= 0);
+    bit = floatformat->totalsize;
 
-  size_t len = bit / TARGET_CHAR_BIT;
-  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[0]));
-  gdb_assert (len >= floatformat_totalsize_bytes (floatformats[1]));
+  gdb_assert (bit >= 0);
+  gdb_assert (bit >= floatformat->totalsize);
 
   return bit;
 }
 
+/* Return the floating-point format for a floating-point variable of
+   type TYPE.  */
+
+const struct floatformat *
+floatformat_from_type (const struct type *type)
+{
+  gdb_assert (TYPE_CODE (type) == TYPE_CODE_FLT);
+  gdb_assert (TYPE_FLOATFORMAT (type));
+  return TYPE_FLOATFORMAT (type);
+}
+
 /* Helper function to initialize the standard scalar types.
 
    If NAME is non-NULL, then it is used to initialize the type name.
@@ -2842,11 +2850,13 @@ init_float_type (struct objfile *objfile,
                 int bit, const char *name,
                 const struct floatformat **floatformats)
 {
+  struct gdbarch *gdbarch = get_objfile_arch (objfile);
+  const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
   struct type *t;
 
-  bit = verify_floatformat (bit, floatformats);
+  bit = verify_floatformat (bit, fmt);
   t = init_type (objfile, TYPE_CODE_FLT, bit, name);
-  TYPE_FLOATFORMAT (t) = floatformats;
+  TYPE_FLOATFORMAT (t) = fmt;
 
   return t;
 }
@@ -4544,26 +4554,11 @@ recursive_dump_type (struct type *type, int spaces)
 
       case TYPE_SPECIFIC_FLOATFORMAT:
        printfi_filtered (spaces, "floatformat ");
-       if (TYPE_FLOATFORMAT (type) == NULL)
+       if (TYPE_FLOATFORMAT (type) == NULL
+           || TYPE_FLOATFORMAT (type)->name == NULL)
          puts_filtered ("(null)");
        else
-         {
-           puts_filtered ("{ ");
-           if (TYPE_FLOATFORMAT (type)[0] == NULL
-               || TYPE_FLOATFORMAT (type)[0]->name == NULL)
-             puts_filtered ("(null)");
-           else
-             puts_filtered (TYPE_FLOATFORMAT (type)[0]->name);
-
-           puts_filtered (", ");
-           if (TYPE_FLOATFORMAT (type)[1] == NULL
-               || TYPE_FLOATFORMAT (type)[1]->name == NULL)
-             puts_filtered ("(null)");
-           else
-             puts_filtered (TYPE_FLOATFORMAT (type)[1]->name);
-
-           puts_filtered (" }");
-         }
+         puts_filtered (TYPE_FLOATFORMAT (type)->name);
        puts_filtered ("\n");
        break;
 
@@ -4908,11 +4903,12 @@ arch_float_type (struct gdbarch *gdbarch,
                 int bit, const char *name,
                 const struct floatformat **floatformats)
 {
+  const struct floatformat *fmt = floatformats[gdbarch_byte_order (gdbarch)];
   struct type *t;
 
-  bit = verify_floatformat (bit, floatformats);
+  bit = verify_floatformat (bit, fmt);
   t = arch_type (gdbarch, TYPE_CODE_FLT, bit, name);
-  TYPE_FLOATFORMAT (t) = floatformats;
+  TYPE_FLOATFORMAT (t) = fmt;
 
   return t;
 }
index c96a3287d32c92f58b168e43319c92bd55273b38..009cea90d93921034ae6984763c372175de6e19a 100644 (file)
@@ -571,12 +571,11 @@ union type_specific
 
   struct gnat_aux_type *gnat_stuff;
 
-  /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to two
-     floatformat objects that describe the floating-point value
-     that resides within the type.  The first is for big endian
-     targets and the second is for little endian targets.  */
+  /* * FLOATFORMAT is for TYPE_CODE_FLT.  It is a pointer to a
+     floatformat object that describes the floating-point value
+     that resides within the type.  */
 
-  const struct floatformat **floatformat;
+  const struct floatformat *floatformat;
 
   /* * For TYPE_CODE_FUNC and TYPE_CODE_METHOD types.  */
 
@@ -1434,6 +1433,9 @@ extern void set_type_vptr_basetype (struct type *, struct type *);
 #define TYPE_ERROR_NAME(type) \
   (TYPE_NAME (type) ? TYPE_NAME (type) : _("<error type>"))
 
+/* Given TYPE, return its floatformat.  */
+const struct floatformat *floatformat_from_type (const struct type *type);
+
 struct builtin_type
 {
   /* Integral types.  */
This page took 0.041356 seconds and 4 git commands to generate.