Unify arch_pointer_type and init_pointer_type

This unifies arch_pointer_type and init_pointer_type by using a type
allocator.

Reviewed-By: Simon Marchi <simon.marchi@efficios.com>
This commit is contained in:
Tom Tromey 2023-03-13 12:25:27 -06:00
parent 0776344a33
commit 9c794d2d46
10 changed files with 33 additions and 48 deletions

View file

@ -1476,7 +1476,7 @@ avr_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
type_allocator alloc (gdbarch);
tdep->void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
tdep->func_void_type = make_function_type (tdep->void_type, NULL);
tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL,
tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL,
tdep->func_void_type);
set_gdbarch_short_bit (gdbarch, 2 * TARGET_CHAR_BIT);

View file

@ -15229,7 +15229,7 @@ read_base_type (struct die_info *die, struct dwarf2_cu *cu)
case DW_ATE_address:
/* Turn DW_ATE_address into a void * pointer. */
type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, NULL);
type = init_pointer_type (objfile, bits, name, type);
type = init_pointer_type (alloc, bits, name, type);
break;
case DW_ATE_boolean:
type = init_boolean_type (alloc, bits, 1, name);

View file

@ -576,7 +576,7 @@ ft32_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
type_allocator alloc (gdbarch);
void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
func_void_type = make_function_type (void_type, NULL);
tdep->pc_type = arch_pointer_type (gdbarch, 4 * TARGET_CHAR_BIT, NULL,
tdep->pc_type = init_pointer_type (alloc, 4 * TARGET_CHAR_BIT, NULL,
func_void_type);
tdep->pc_type->set_instance_flags (tdep->pc_type->instance_flags ()
| TYPE_INSTANCE_FLAG_ADDRESS_CLASS_1);

View file

@ -3526,18 +3526,15 @@ init_complex_type (const char *name, struct type *target_type)
return TYPE_MAIN_TYPE (target_type)->flds_bnds.complex_type;
}
/* Allocate a TYPE_CODE_PTR type structure associated with OBJFILE.
BIT is the pointer type size in bits. NAME is the type name.
TARGET_TYPE is the pointer target type. Always sets the pointer type's
TYPE_UNSIGNED flag. */
/* See gdbtypes.h. */
struct type *
init_pointer_type (struct objfile *objfile,
init_pointer_type (type_allocator &alloc,
int bit, const char *name, struct type *target_type)
{
struct type *t;
t = type_allocator (objfile).new_type (TYPE_CODE_PTR, bit, name);
t = alloc.new_type (TYPE_CODE_PTR, bit, name);
t->set_target_type (target_type);
t->set_is_unsigned (true);
return t;
@ -5740,23 +5737,6 @@ copy_type (const struct type *type)
/* Helper functions to initialize architecture-specific types. */
/* Allocate a TYPE_CODE_PTR type structure associated with GDBARCH.
BIT is the pointer type size in bits. NAME is the type name.
TARGET_TYPE is the pointer target type. Always sets the pointer type's
TYPE_UNSIGNED flag. */
struct type *
arch_pointer_type (struct gdbarch *gdbarch,
int bit, const char *name, struct type *target_type)
{
struct type *t;
t = type_allocator (gdbarch).new_type (TYPE_CODE_PTR, bit, name);
t->set_target_type (target_type);
t->set_is_unsigned (true);
return t;
}
/* Allocate a TYPE_CODE_FLAGS type structure associated with GDBARCH.
NAME is the type name. BIT is the size of the flag word in bits. */
@ -6227,7 +6207,7 @@ objfile_type (struct objfile *objfile)
objfile_type->nodebug_text_gnu_ifunc_symbol->set_is_gnu_ifunc (true);
objfile_type->nodebug_got_plt_symbol
= init_pointer_type (objfile, gdbarch_addr_bit (gdbarch),
= init_pointer_type (alloc, gdbarch_addr_bit (gdbarch),
"<text from jump slot in .got.plt, no debug info>",
objfile_type->nodebug_text_symbol);
objfile_type->nodebug_data_symbol

View file

@ -2335,15 +2335,19 @@ extern struct type *init_decfloat_type (type_allocator &alloc, int bit,
extern bool can_create_complex_type (struct type *);
extern struct type *init_complex_type (const char *, struct type *);
extern struct type *init_pointer_type (struct objfile *, int, const char *,
struct type *);
/* Allocate a TYPE_CODE_PTR type structure using ALLOC.
BIT is the pointer type size in bits. NAME is the type name.
TARGET_TYPE is the pointer target type. Always sets the pointer type's
TYPE_UNSIGNED flag. */
extern struct type *init_pointer_type (type_allocator &alloc, int bit,
const char *name,
struct type *target_type);
extern struct type *init_fixed_point_type (struct objfile *, int, int,
const char *);
/* Helper functions to construct architecture-owned types. */
extern struct type *arch_pointer_type (struct gdbarch *, int, const char *,
struct type *);
/* Helper functions to construct a struct or record type. An
initially empty type is created using arch_composite_type().
Fields are then added using append_composite_type_field*(). A union

View file

@ -188,18 +188,19 @@ make_types (struct gdbarch *arch)
type_allocator alloc (arch);
tdep->voyd = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT, "void");
tdep->ptr_voyd
= arch_pointer_type (arch, gdbarch_ptr_bit (arch), NULL, tdep->voyd);
= init_pointer_type (alloc, gdbarch_ptr_bit (arch), NULL, tdep->voyd);
tdep->func_voyd = lookup_function_type (tdep->voyd);
xsnprintf (type_name, sizeof (type_name), "%s_data_addr_t",
gdbarch_bfd_arch_info (arch)->printable_name);
tdep->data_addr_reg_type
= arch_pointer_type (arch, data_addr_reg_bits, type_name, tdep->voyd);
= init_pointer_type (alloc, data_addr_reg_bits, type_name, tdep->voyd);
xsnprintf (type_name, sizeof (type_name), "%s_code_addr_t",
gdbarch_bfd_arch_info (arch)->printable_name);
tdep->code_addr_reg_type
= arch_pointer_type (arch, code_addr_reg_bits, type_name, tdep->func_voyd);
= init_pointer_type (alloc, code_addr_reg_bits, type_name,
tdep->func_voyd);
tdep->uint8 = init_integer_type (alloc, 8, 1, "uint8_t");
tdep->uint16 = init_integer_type (alloc, 16, 1, "uint16_t");

View file

@ -1395,7 +1395,7 @@ basic_type (int bt, struct objfile *objfile)
break;
case btAdr:
tp = init_pointer_type (objfile, 32, "adr_32",
tp = init_pointer_type (alloc, 32, "adr_32",
objfile_type (objfile)->builtin_void);
break;
@ -1490,7 +1490,7 @@ basic_type (int bt, struct objfile *objfile)
break;
case btAdr64:
tp = init_pointer_type (objfile, 64, "adr_64",
tp = init_pointer_type (alloc, 64, "adr_64",
objfile_type (objfile)->builtin_void);
break;

View file

@ -1419,9 +1419,9 @@ rl78_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
tdep->rl78_int32 = init_integer_type (alloc, 32, 0, "int32_t");
tdep->rl78_data_pointer
= arch_pointer_type (gdbarch, 16, "rl78_data_addr_t", tdep->rl78_void);
= init_pointer_type (alloc, 16, "rl78_data_addr_t", tdep->rl78_void);
tdep->rl78_code_pointer
= arch_pointer_type (gdbarch, 32, "rl78_code_addr_t", tdep->rl78_void);
= init_pointer_type (alloc, 32, "rl78_code_addr_t", tdep->rl78_void);
/* Registers. */
set_gdbarch_num_regs (gdbarch, RL78_NUM_REGS);

View file

@ -225,8 +225,8 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
wchar_type = init_integer_type (alloc, 16,
1, "wchar_t");
void_ptr_type = lookup_pointer_type (builtin_type (gdbarch)->builtin_void);
wchar_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
NULL, wchar_type);
wchar_ptr_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch),
nullptr, wchar_type);
/* list entry */
@ -319,8 +319,8 @@ windows_get_tlb_type (struct gdbarch *gdbarch)
append_composite_type_field (rupp_type, "shell_info", uni_str_type);
append_composite_type_field (rupp_type, "runtime_data", uni_str_type);
rupp_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
NULL, rupp_type);
rupp_ptr_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch),
nullptr, rupp_type);
/* struct process environment block */
@ -813,7 +813,7 @@ windows_get_siginfo_type (struct gdbarch *gdbarch)
type_allocator alloc (gdbarch);
dword_type = init_integer_type (alloc, gdbarch_int_bit (gdbarch),
1, "DWORD");
pvoid_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch), "PVOID",
pvoid_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch), "PVOID",
builtin_type (gdbarch)->builtin_void);
ulongptr_type = init_integer_type (alloc, gdbarch_ptr_bit (gdbarch),
1, "ULONG_PTR");
@ -844,8 +844,8 @@ windows_get_siginfo_type (struct gdbarch *gdbarch)
siginfo_type = arch_composite_type (gdbarch, "EXCEPTION_RECORD",
TYPE_CODE_STRUCT);
siginfo_ptr_type = arch_pointer_type (gdbarch, gdbarch_ptr_bit (gdbarch),
NULL, siginfo_type);
siginfo_ptr_type = init_pointer_type (alloc, gdbarch_ptr_bit (gdbarch),
nullptr, siginfo_type);
/* ExceptionCode is documented as type DWORD, but here a helper
enum type is used instead to display a human-readable value. */

View file

@ -1143,7 +1143,7 @@ z80_gdbarch_init (struct gdbarch_info info, struct gdbarch_list *arches)
tdep->void_type = alloc.new_type (TYPE_CODE_VOID, TARGET_CHAR_BIT,
"void");
tdep->func_void_type = make_function_type (tdep->void_type, NULL);
tdep->pc_type = arch_pointer_type (gdbarch,
tdep->pc_type = init_pointer_type (alloc,
tdep->addr_length * TARGET_CHAR_BIT,
NULL, tdep->func_void_type);