From d4a0e8b57d6f85e4ee4a31e0e6929ff5b4fd9823 Mon Sep 17 00:00:00 2001 From: Simon Marchi Date: Tue, 5 Dec 2017 16:30:28 -0500 Subject: Split tdesc_type into multiple classes This patch makes tdesc_type an abstract base class and creates three subclasses: - tdesc_type_builtin, for builtin types - tdesc_type_vector, for vector types - tdesc_type_with_fields, for struct, union, flag and enum types This allows getting rid of the union in tdesc_type and to not allow the std::vector separately. I tried to go further and create separate classes for struct, union, flag and enum, but it proved too difficult. One problem is that from the point of the of the target description code, the types tdesc_type_* are opaque (only forward-declared). Therefore, it doesn't know about inheritance relationship between those classes. This makes it impossible to make functions that accept a pointer to a base class and pass a pointer to a derived class, for example. I think this patch here is a good compromise, and if somebody wants to improve things further, the door is open. A make_gdb_type virtual pure method is added to tdesc_type, which replaces the current tdesc_gdb_type function. Calling this method on a tdesc_type returns the corresponding built gdb type. gdb/ChangeLog: * target-descriptions.c (struct tdesc_type): Use default destructor. : Remove. : Remove. (struct tdesc_type_builtin): New. (struct tdesc_type_vector): New. (struct tdesc_type_with_fields): New. (tdesc_predefined_types): Change type to tdesc_type_builtin[]. (tdesc_gdb_type): Remove. (tdesc_register_type): Adjust. (tdesc_create_vector): Create tdesc_type_vector. (tdesc_create_struct): Create tdesc_type_with_fields. (tdesc_set_struct_size): Change parameter type. (tdesc_create_union): Create tdesc_type_with_fields. (tdesc_create_flags): Likewise. (tdesc_create_enum): Likewise. (tdesc_add_field): Change parameter type. (tdesc_add_typed_bitfield): Likewise. (tdesc_add_bitfield): Likewise. (tdesc_add_flag): Likewise. (tdesc_add_enum_value): Likewise. (print_c_tdesc) : Remove overload with tdesc_type parameter, add overloads for tdesc_type_builtin, tdesc_type_with_fields and tdesc_type_vector. : Remove. : Add. * target-descriptions.h (tdesc_create_enum): Change return type. (tdesc_add_typed_bitfield): Change parameter type. (tdesc_add_enum_value): Change parameter type. * xml-tdesc.c (struct tdesc_parsing_data) : Change type to tdesc_type_with_fields. (tdesc_start_struct): Adjust. (tdesc_start_flags): Adjust. (tdesc_start_enum): Adjust. (tdesc_start_field): Adjust. * arch/tdesc.h (struct tdesc_type_builtin): Forward-declare. (struct tdesc_type_vector): Forward-declare. (struct tdesc_type_with_fields): Forward-declare. (tdesc_create_struct): Change return type. (tdesc_create_union): Likewise. (tdesc_create_flags): Likewise. (tdesc_add_field): Change parameter type. (tdesc_set_struct_size): Likewise. (tdesc_add_bitfield): Likewise. (tdesc_add_flag): Likewise. * features: Re-generate C files. gdb/gdbserver/ChangeLog: * tdesc.c (struct tdesc_type): Change return type. (tdesc_add_flag): Change parameter type. (tdesc_add_bitfield): Likewise. (tdesc_add_field): Likewise. (tdesc_set_struct_size): Likewise. --- gdb/features/arm/arm-with-iwmmxt.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'gdb/features/arm') diff --git a/gdb/features/arm/arm-with-iwmmxt.c b/gdb/features/arm/arm-with-iwmmxt.c index 5f839a0..5d6c357 100644 --- a/gdb/features/arm/arm-with-iwmmxt.c +++ b/gdb/features/arm/arm-with-iwmmxt.c @@ -34,26 +34,27 @@ initialize_tdesc_arm_with_iwmmxt (void) tdesc_create_reg (feature, "cpsr", 25, 1, NULL, 32, "int"); feature = tdesc_create_feature (result, "org.gnu.gdb.xscale.iwmmxt"); - struct tdesc_type *field_type; - field_type = tdesc_named_type (feature, "uint8"); - tdesc_create_vector (feature, "iwmmxt_v8u8", field_type, 8); + tdesc_type *element_type; + element_type = tdesc_named_type (feature, "uint8"); + tdesc_create_vector (feature, "iwmmxt_v8u8", element_type, 8); - field_type = tdesc_named_type (feature, "uint16"); - tdesc_create_vector (feature, "iwmmxt_v4u16", field_type, 4); + element_type = tdesc_named_type (feature, "uint16"); + tdesc_create_vector (feature, "iwmmxt_v4u16", element_type, 4); - field_type = tdesc_named_type (feature, "uint32"); - tdesc_create_vector (feature, "iwmmxt_v2u32", field_type, 2); + element_type = tdesc_named_type (feature, "uint32"); + tdesc_create_vector (feature, "iwmmxt_v2u32", element_type, 2); - struct tdesc_type *type; - type = tdesc_create_union (feature, "iwmmxt_vec64i"); + tdesc_type_with_fields *type_with_fields; + tdesc_type *field_type; + type_with_fields = tdesc_create_union (feature, "iwmmxt_vec64i"); field_type = tdesc_named_type (feature, "iwmmxt_v8u8"); - tdesc_add_field (type, "u8", field_type); + tdesc_add_field (type_with_fields, "u8", field_type); field_type = tdesc_named_type (feature, "iwmmxt_v4u16"); - tdesc_add_field (type, "u16", field_type); + tdesc_add_field (type_with_fields, "u16", field_type); field_type = tdesc_named_type (feature, "iwmmxt_v2u32"); - tdesc_add_field (type, "u32", field_type); + tdesc_add_field (type_with_fields, "u32", field_type); field_type = tdesc_named_type (feature, "uint64"); - tdesc_add_field (type, "u64", field_type); + tdesc_add_field (type_with_fields, "u64", field_type); tdesc_create_reg (feature, "wR0", 26, 1, NULL, 64, "iwmmxt_vec64i"); tdesc_create_reg (feature, "wR1", 27, 1, NULL, 64, "iwmmxt_vec64i"); -- cgit v1.1