#include "bcache.h"
#include "dwarf2loc.h"
#include "gdbcore.h"
+#include "floatformat.h"
/* Initialize BADNESS constants. */
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.
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;
}
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;
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;
}