#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.
least as long as OBJFILE. */
struct type *
-init_type (struct objfile *objfile, enum type_code code, int length,
+init_type (struct objfile *objfile, enum type_code code, int bit,
const char *name)
{
struct type *type;
type = alloc_type (objfile);
set_type_code (type, code);
- TYPE_LENGTH (type) = length;
+ gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
+ TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
TYPE_NAME (type) = name;
return type;
{
struct type *t;
- t = init_type (objfile, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
+ t = init_type (objfile, TYPE_CODE_INT, bit, name);
if (unsigned_p)
TYPE_UNSIGNED (t) = 1;
{
struct type *t;
- t = init_type (objfile, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
+ t = init_type (objfile, TYPE_CODE_CHAR, bit, name);
if (unsigned_p)
TYPE_UNSIGNED (t) = 1;
{
struct type *t;
- t = init_type (objfile, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
+ t = init_type (objfile, TYPE_CODE_BOOL, bit, name);
if (unsigned_p)
TYPE_UNSIGNED (t) = 1;
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);
- t = init_type (objfile, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
- TYPE_FLOATFORMAT (t) = floatformats;
+ bit = verify_floatformat (bit, fmt);
+ t = init_type (objfile, TYPE_CODE_FLT, bit, name);
+ TYPE_FLOATFORMAT (t) = fmt;
return t;
}
{
struct type *t;
- t = init_type (objfile, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
+ t = init_type (objfile, TYPE_CODE_DECFLOAT, bit, name);
return t;
}
struct type *t;
t = init_type (objfile, TYPE_CODE_COMPLEX,
- 2 * TYPE_LENGTH (target_type), name);
+ 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
TYPE_TARGET_TYPE (t) = target_type;
return t;
}
{
struct type *t;
- t = init_type (objfile, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
+ t = init_type (objfile, TYPE_CODE_PTR, bit, name);
TYPE_TARGET_TYPE (t) = target_type;
TYPE_UNSIGNED (t) = 1;
return t;
|| (TYPE_CODE (t) == TYPE_CODE_BOOL)));
}
+int
+is_floating_type (struct type *t)
+{
+ t = check_typedef (t);
+ return
+ ((t != NULL)
+ && ((TYPE_CODE (t) == TYPE_CODE_FLT)
+ || (TYPE_CODE (t) == TYPE_CODE_DECFLOAT)));
+}
+
/* Return true if TYPE is scalar. */
int
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;
struct type *
arch_type (struct gdbarch *gdbarch,
- enum type_code code, int length, const char *name)
+ enum type_code code, int bit, const char *name)
{
struct type *type;
type = alloc_type_arch (gdbarch);
set_type_code (type, code);
- TYPE_LENGTH (type) = length;
+ gdb_assert ((bit % TARGET_CHAR_BIT) == 0);
+ TYPE_LENGTH (type) = bit / TARGET_CHAR_BIT;
if (name)
TYPE_NAME (type) = gdbarch_obstack_strdup (gdbarch, name);
{
struct type *t;
- t = arch_type (gdbarch, TYPE_CODE_INT, bit / TARGET_CHAR_BIT, name);
+ t = arch_type (gdbarch, TYPE_CODE_INT, bit, name);
if (unsigned_p)
TYPE_UNSIGNED (t) = 1;
{
struct type *t;
- t = arch_type (gdbarch, TYPE_CODE_CHAR, bit / TARGET_CHAR_BIT, name);
+ t = arch_type (gdbarch, TYPE_CODE_CHAR, bit, name);
if (unsigned_p)
TYPE_UNSIGNED (t) = 1;
{
struct type *t;
- t = arch_type (gdbarch, TYPE_CODE_BOOL, bit / TARGET_CHAR_BIT, name);
+ t = arch_type (gdbarch, TYPE_CODE_BOOL, bit, name);
if (unsigned_p)
TYPE_UNSIGNED (t) = 1;
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);
- t = arch_type (gdbarch, TYPE_CODE_FLT, bit / TARGET_CHAR_BIT, name);
- TYPE_FLOATFORMAT (t) = floatformats;
+ bit = verify_floatformat (bit, fmt);
+ t = arch_type (gdbarch, TYPE_CODE_FLT, bit, name);
+ TYPE_FLOATFORMAT (t) = fmt;
return t;
}
{
struct type *t;
- t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit / TARGET_CHAR_BIT, name);
+ t = arch_type (gdbarch, TYPE_CODE_DECFLOAT, bit, name);
return t;
}
struct type *t;
t = arch_type (gdbarch, TYPE_CODE_COMPLEX,
- 2 * TYPE_LENGTH (target_type), name);
+ 2 * TYPE_LENGTH (target_type) * TARGET_CHAR_BIT, name);
TYPE_TARGET_TYPE (t) = target_type;
return t;
}
{
struct type *t;
- t = arch_type (gdbarch, TYPE_CODE_PTR, bit / TARGET_CHAR_BIT, name);
+ t = arch_type (gdbarch, TYPE_CODE_PTR, bit, name);
TYPE_TARGET_TYPE (t) = target_type;
TYPE_UNSIGNED (t) = 1;
return t;
}
/* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
- NAME is the type name. LENGTH is the size of the flag word in bytes. */
+ NAME is the type name. BIT is the size of the flag word in bits. */
struct type *
-arch_flags_type (struct gdbarch *gdbarch, const char *name, int length)
+arch_flags_type (struct gdbarch *gdbarch, const char *name, int bit)
{
- int max_nfields = length * TARGET_CHAR_BIT;
struct type *type;
- type = arch_type (gdbarch, TYPE_CODE_FLAGS, length, name);
+ type = arch_type (gdbarch, TYPE_CODE_FLAGS, bit, name);
TYPE_UNSIGNED (type) = 1;
TYPE_NFIELDS (type) = 0;
/* Pre-allocate enough space assuming every field is one bit. */
TYPE_FIELDS (type)
- = (struct field *) TYPE_ZALLOC (type, max_nfields * sizeof (struct field));
+ = (struct field *) TYPE_ZALLOC (type, bit * sizeof (struct field));
return type;
}
/* Basic types. */
builtin_type->builtin_void
- = arch_type (gdbarch, TYPE_CODE_VOID, 1, "void");
+ = arch_type (gdbarch, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
builtin_type->builtin_char
= arch_integer_type (gdbarch, TARGET_CHAR_BIT,
!gdbarch_char_signed (gdbarch), "char");
= arch_complex_type (gdbarch, "double complex",
builtin_type->builtin_double);
builtin_type->builtin_string
- = arch_type (gdbarch, TYPE_CODE_STRING, 1, "string");
+ = arch_type (gdbarch, TYPE_CODE_STRING, TARGET_CHAR_BIT, "string");
builtin_type->builtin_bool
- = arch_type (gdbarch, TYPE_CODE_BOOL, 1, "bool");
+ = arch_type (gdbarch, TYPE_CODE_BOOL, TARGET_CHAR_BIT, "bool");
/* The following three are about decimal floating point types, which
are 32-bits, 64-bits and 128-bits respectively. */
/* Basic types. */
objfile_type->builtin_void
- = init_type (objfile, TYPE_CODE_VOID, 1, "void");
+ = init_type (objfile, TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
objfile_type->builtin_char
= init_integer_type (objfile, TARGET_CHAR_BIT,
!gdbarch_char_signed (gdbarch), "char");
/* The following set of types is used for symbols with no
debug information. */
objfile_type->nodebug_text_symbol
- = init_type (objfile, TYPE_CODE_FUNC, 1,
+ = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
"<text variable, no debug info>");
objfile_type->nodebug_text_gnu_ifunc_symbol
- = init_type (objfile, TYPE_CODE_FUNC, 1,
+ = init_type (objfile, TYPE_CODE_FUNC, TARGET_CHAR_BIT,
"<text gnu-indirect-function variable, no debug info>");
/* Ifunc resolvers return a function address. */
TYPE_TARGET_TYPE (objfile_type->nodebug_text_gnu_ifunc_symbol)
return objfile_type;
}
-extern initialize_file_ftype _initialize_gdbtypes;
-
void
_initialize_gdbtypes (void)
{