+2018-04-18 Alan Hayward <alan.hayward@arm.com>
+
+ * common/tdesc.c (tdesc_predefined_type): Move to here.
+ (tdesc_named_type): Likewise.
+ (tdesc_create_vector): Likewise.
+ (tdesc_create_struct): Likewise.
+ (tdesc_set_struct_size): Likewise.
+ (tdesc_create_union): Likewise.
+ (tdesc_create_flags): Likewise.
+ (tdesc_create_enum): Likewise.
+ (tdesc_add_field): Likewise.
+ (tdesc_add_typed_bitfield): Likewise.
+ (tdesc_add_bitfield): Likewise.
+ (tdesc_add_flag): Likewise.
+ (tdesc_add_enum_value): Likewise.
+ * common/tdesc.h (struct tdesc_type_builtin): Likewise.
+ (struct tdesc_type_vector): Likewise.
+ (struct tdesc_type_field): Likewise.
+ (struct tdesc_type_with_fields): Likewise.
+ (tdesc_create_enum): Add declaration.
+ (tdesc_add_typed_bitfield): Likewise.
+ (tdesc_add_enum_value): Likewise.
+ * target-descriptions.c (tdesc_type_field): Move from here.
+ (tdesc_type_builtin): Likewise.
+ (tdesc_type_vector): Likewise.
+ (tdesc_type_with_fields): Likewise.
+ (tdesc_predefined_types): Likewise.
+ (tdesc_named_type): Likewise.
+ (tdesc_create_vector): Likewise.
+ (tdesc_create_struct): Likewise.
+ (tdesc_set_struct_size): Likewise.
+ (tdesc_create_union): Likewise.
+ (tdesc_create_flags): Likewise.
+ (tdesc_create_enum): Likewise.
+ (tdesc_add_field): Likewise.
+ (tdesc_add_typed_bitfield): Likewise.
+ (tdesc_add_bitfield): Likewise.
+ (tdesc_add_flag): Likewise.
+ (tdesc_add_enum_value): Likewise.
+ * gdb/target-descriptions.h (tdesc_create_enum): Likewise.
+ (tdesc_add_typed_bitfield): Likewise.
+ (tdesc_add_enum_value): Likewise.
+
2018-04-18 Alan Hayward <alan.hayward@arm.com>
* common/tdesc.c (tdesc_feature::accept): Move to here.
tdesc_type = tdesc_named_type (feature, type.c_str ());
}
+/* Predefined types. */
+static tdesc_type_builtin tdesc_predefined_types[] =
+{
+ { "bool", TDESC_TYPE_BOOL },
+ { "int8", TDESC_TYPE_INT8 },
+ { "int16", TDESC_TYPE_INT16 },
+ { "int32", TDESC_TYPE_INT32 },
+ { "int64", TDESC_TYPE_INT64 },
+ { "int128", TDESC_TYPE_INT128 },
+ { "uint8", TDESC_TYPE_UINT8 },
+ { "uint16", TDESC_TYPE_UINT16 },
+ { "uint32", TDESC_TYPE_UINT32 },
+ { "uint64", TDESC_TYPE_UINT64 },
+ { "uint128", TDESC_TYPE_UINT128 },
+ { "code_ptr", TDESC_TYPE_CODE_PTR },
+ { "data_ptr", TDESC_TYPE_DATA_PTR },
+ { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
+ { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
+ { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
+ { "i387_ext", TDESC_TYPE_I387_EXT }
+};
+
void tdesc_feature::accept (tdesc_element_visitor &v) const
{
v.visit_pre (this);
return true;
}
+/* Lookup a predefined type. */
+
+static struct tdesc_type *
+tdesc_predefined_type (enum tdesc_type_kind kind)
+{
+ for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
+ if (tdesc_predefined_types[ix].kind == kind)
+ return &tdesc_predefined_types[ix];
+
+ gdb_assert_not_reached ("bad predefined tdesc type");
+}
+
+/* See common/tdesc.h. */
+
+struct tdesc_type *
+tdesc_named_type (const struct tdesc_feature *feature, const char *id)
+{
+ /* First try target-defined types. */
+ for (const tdesc_type_up &type : feature->types)
+ if (type->name == id)
+ return type.get ();
+
+ /* Next try the predefined types. */
+ for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
+ if (tdesc_predefined_types[ix].name == id)
+ return &tdesc_predefined_types[ix];
+
+ return NULL;
+}
+
/* See common/tdesc.h. */
void
feature->registers.emplace_back (reg);
}
+
+/* See common/tdesc.h. */
+
+struct tdesc_type *
+tdesc_create_vector (struct tdesc_feature *feature, const char *name,
+ struct tdesc_type *field_type, int count)
+{
+ tdesc_type_vector *type = new tdesc_type_vector (name, field_type, count);
+ feature->types.emplace_back (type);
+
+ return type;
+}
+
+/* See common/tdesc.h. */
+
+tdesc_type_with_fields *
+tdesc_create_struct (struct tdesc_feature *feature, const char *name)
+{
+ tdesc_type_with_fields *type
+ = new tdesc_type_with_fields (name, TDESC_TYPE_STRUCT);
+ feature->types.emplace_back (type);
+
+ return type;
+}
+
+/* See common/tdesc.h. */
+
+void
+tdesc_set_struct_size (tdesc_type_with_fields *type, int size)
+{
+ gdb_assert (type->kind == TDESC_TYPE_STRUCT);
+ gdb_assert (size > 0);
+ type->size = size;
+}
+
+/* See common/tdesc.h. */
+
+tdesc_type_with_fields *
+tdesc_create_union (struct tdesc_feature *feature, const char *name)
+{
+ tdesc_type_with_fields *type
+ = new tdesc_type_with_fields (name, TDESC_TYPE_UNION);
+ feature->types.emplace_back (type);
+
+ return type;
+}
+
+/* See common/tdesc.h. */
+
+tdesc_type_with_fields *
+tdesc_create_flags (struct tdesc_feature *feature, const char *name,
+ int size)
+{
+ gdb_assert (size > 0);
+
+ tdesc_type_with_fields *type
+ = new tdesc_type_with_fields (name, TDESC_TYPE_FLAGS, size);
+ feature->types.emplace_back (type);
+
+ return type;
+}
+
+/* See common/tdesc.h. */
+
+tdesc_type_with_fields *
+tdesc_create_enum (struct tdesc_feature *feature, const char *name,
+ int size)
+{
+ gdb_assert (size > 0);
+
+ tdesc_type_with_fields *type
+ = new tdesc_type_with_fields (name, TDESC_TYPE_ENUM, size);
+ feature->types.emplace_back (type);
+
+ return type;
+}
+
+/* See common/tdesc.h. */
+
+void
+tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
+ struct tdesc_type *field_type)
+{
+ gdb_assert (type->kind == TDESC_TYPE_UNION
+ || type->kind == TDESC_TYPE_STRUCT);
+
+ /* Initialize start and end so we know this is not a bit-field
+ when we print-c-tdesc. */
+ type->fields.emplace_back (field_name, field_type, -1, -1);
+}
+
+/* See common/tdesc.h. */
+
+void
+tdesc_add_typed_bitfield (tdesc_type_with_fields *type, const char *field_name,
+ int start, int end, struct tdesc_type *field_type)
+{
+ gdb_assert (type->kind == TDESC_TYPE_STRUCT
+ || type->kind == TDESC_TYPE_FLAGS);
+ gdb_assert (start >= 0 && end >= start);
+
+ type->fields.emplace_back (field_name, field_type, start, end);
+}
+
+/* See common/tdesc.h. */
+
+void
+tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name,
+ int start, int end)
+{
+ struct tdesc_type *field_type;
+
+ gdb_assert (start >= 0 && end >= start);
+
+ if (type->size > 4)
+ field_type = tdesc_predefined_type (TDESC_TYPE_UINT64);
+ else
+ field_type = tdesc_predefined_type (TDESC_TYPE_UINT32);
+
+ tdesc_add_typed_bitfield (type, field_name, start, end, field_type);
+}
+
+/* See common/tdesc.h. */
+
+void
+tdesc_add_flag (tdesc_type_with_fields *type, int start,
+ const char *flag_name)
+{
+ gdb_assert (type->kind == TDESC_TYPE_FLAGS
+ || type->kind == TDESC_TYPE_STRUCT);
+
+ type->fields.emplace_back (flag_name,
+ tdesc_predefined_type (TDESC_TYPE_BOOL),
+ start, start);
+}
+
+/* See common/tdesc.h. */
+
+void
+tdesc_add_enum_value (tdesc_type_with_fields *type, int value,
+ const char *name)
+{
+ gdb_assert (type->kind == TDESC_TYPE_ENUM);
+ type->fields.emplace_back (name,
+ tdesc_predefined_type (TDESC_TYPE_INT32),
+ value, -1);
+}
typedef std::unique_ptr<tdesc_type> tdesc_type_up;
+struct tdesc_type_builtin : tdesc_type
+{
+ tdesc_type_builtin (const std::string &name, enum tdesc_type_kind kind)
+ : tdesc_type (name, kind)
+ {}
+
+ void accept (tdesc_element_visitor &v) const override
+ {
+ v.visit (this);
+ }
+};
+
+/* tdesc_type for vector types. */
+
+struct tdesc_type_vector : tdesc_type
+{
+ tdesc_type_vector (const std::string &name, tdesc_type *element_type_,
+ int count_)
+ : tdesc_type (name, TDESC_TYPE_VECTOR),
+ element_type (element_type_), count (count_)
+ {}
+
+ void accept (tdesc_element_visitor &v) const override
+ {
+ v.visit (this);
+ }
+
+ struct tdesc_type *element_type;
+ int count;
+};
+
+/* A named type from a target description. */
+
+struct tdesc_type_field
+{
+ tdesc_type_field (const std::string &name_, tdesc_type *type_,
+ int start_, int end_)
+ : name (name_), type (type_), start (start_), end (end_)
+ {}
+
+ std::string name;
+ struct tdesc_type *type;
+ /* For non-enum-values, either both are -1 (non-bitfield), or both are
+ not -1 (bitfield). For enum values, start is the value (which could be
+ -1), end is -1. */
+ int start, end;
+};
+
+/* tdesc_type for struct, union, flags, and enum types. */
+
+struct tdesc_type_with_fields : tdesc_type
+{
+ tdesc_type_with_fields (const std::string &name, tdesc_type_kind kind,
+ int size_ = 0)
+ : tdesc_type (name, kind), size (size_)
+ {}
+
+ void accept (tdesc_element_visitor &v) const override
+ {
+ v.visit (this);
+ }
+
+ std::vector<tdesc_type_field> fields;
+ int size;
+};
+
/* A feature from a target description. Each feature is a collection
of other elements, e.g. registers and types. */
const char *name,
int size);
+/* Return the created enum tdesc_type named NAME in FEATURE. */
+tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature,
+ const char *name,
+ int size);
+
/* Add a new field to TYPE. FIELD_NAME is its name, and FIELD_TYPE is
its type. */
void tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
struct tdesc_type *field_type);
+/* Add a new bitfield to TYPE, with range START to END. FIELD_NAME is its name,
+ and FIELD_TYPE is its type. */
+void tdesc_add_typed_bitfield (tdesc_type_with_fields *type,
+ const char *field_name,
+ int start, int end,
+ struct tdesc_type *field_type);
+
/* Set the total length of TYPE. Structs which contain bitfields may
omit the reserved bits, so the end of the last field may not
suffice. */
void tdesc_add_flag (tdesc_type_with_fields *type, int start,
const char *flag_name);
+/* Add field with VALUE and NAME to the enum TYPE. */
+void tdesc_add_enum_value (tdesc_type_with_fields *type, int value,
+ const char *name);
+
/* Create a register in feature FEATURE. */
void tdesc_create_reg (struct tdesc_feature *feature, const char *name,
int regnum, int save_restore, const char *group,
+2018-04-18 Alan Hayward <alan.hayward@arm.com>
+
+ * tdesc.c (tdesc_create_flags): Remove.
+ (tdesc_add_flag): Likewise.
+ (tdesc_named_type): Likewise.
+ (tdesc_create_union): Likewise.
+ (tdesc_create_struct): Likewise.
+ (tdesc_create_vector): Likewise.
+ (tdesc_add_bitfield): Likewise.
+ (tdesc_add_field): Likewise.
+ (tdesc_set_struct_size): Likewise.
+
2018-04-18 Alan Hayward <alan.hayward@arm.com>
* tdesc.c (~target_desc): Remove implictly deleted items.
tdesc->features.emplace_back (new_feature);
return new_feature;
}
-
-/* See common/tdesc.h. */
-
-tdesc_type_with_fields *
-tdesc_create_flags (struct tdesc_feature *feature, const char *name,
- int size)
-{
- return NULL;
-}
-
-/* See common/tdesc.h. */
-
-void
-tdesc_add_flag (tdesc_type_with_fields *type, int start,
- const char *flag_name)
-{}
-
-/* See common/tdesc.h. */
-
-struct tdesc_type *
-tdesc_named_type (const struct tdesc_feature *feature, const char *id)
-{
- return NULL;
-}
-
-/* See common/tdesc.h. */
-
-tdesc_type_with_fields *
-tdesc_create_union (struct tdesc_feature *feature, const char *id)
-{
- return NULL;
-}
-
-/* See common/tdesc.h. */
-
-tdesc_type_with_fields *
-tdesc_create_struct (struct tdesc_feature *feature, const char *id)
-{
- return NULL;
-}
-
-/* See common/tdesc.h. */
-
-struct tdesc_type *
-tdesc_create_vector (struct tdesc_feature *feature, const char *name,
- struct tdesc_type *field_type, int count)
-{
- return NULL;
-}
-
-void
-tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name,
- int start, int end)
-{}
-
-/* See common/tdesc.h. */
-
-void
-tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
- struct tdesc_type *field_type)
-{}
-
-/* See common/tdesc.h. */
-
-void
-tdesc_set_struct_size (tdesc_type_with_fields *type, int size)
-{
-}
std::string value;
};
-/* A named type from a target description. */
-
-struct tdesc_type_field
-{
- tdesc_type_field (const std::string &name_, tdesc_type *type_,
- int start_, int end_)
- : name (name_), type (type_), start (start_), end (end_)
- {}
-
- std::string name;
- struct tdesc_type *type;
- /* For non-enum-values, either both are -1 (non-bitfield), or both are
- not -1 (bitfield). For enum values, start is the value (which could be
- -1), end is -1. */
- int start, end;
-};
-
-struct tdesc_type_builtin : tdesc_type
-{
- tdesc_type_builtin (const std::string &name, enum tdesc_type_kind kind)
- : tdesc_type (name, kind)
- {}
-
- void accept (tdesc_element_visitor &v) const override
- {
- v.visit (this);
- }
-};
-
-/* tdesc_type for vector types. */
-
-struct tdesc_type_vector : tdesc_type
-{
- tdesc_type_vector (const std::string &name, tdesc_type *element_type_, int count_)
- : tdesc_type (name, TDESC_TYPE_VECTOR),
- element_type (element_type_), count (count_)
- {}
-
- void accept (tdesc_element_visitor &v) const override
- {
- v.visit (this);
- }
-
- struct tdesc_type *element_type;
- int count;
-};
-
-/* tdesc_type for struct, union, flags, and enum types. */
-
-struct tdesc_type_with_fields : tdesc_type
-{
- tdesc_type_with_fields (const std::string &name, tdesc_type_kind kind,
- int size_ = 0)
- : tdesc_type (name, kind), size (size_)
- {}
-
- void accept (tdesc_element_visitor &v) const override
- {
- v.visit (this);
- }
-
- std::vector<tdesc_type_field> fields;
- int size;
-};
-
/* Convert a tdesc_type to a gdb type. */
static type *
return feature->name.c_str ();
}
-/* Predefined types. */
-static tdesc_type_builtin tdesc_predefined_types[] =
-{
- { "bool", TDESC_TYPE_BOOL },
- { "int8", TDESC_TYPE_INT8 },
- { "int16", TDESC_TYPE_INT16 },
- { "int32", TDESC_TYPE_INT32 },
- { "int64", TDESC_TYPE_INT64 },
- { "int128", TDESC_TYPE_INT128 },
- { "uint8", TDESC_TYPE_UINT8 },
- { "uint16", TDESC_TYPE_UINT16 },
- { "uint32", TDESC_TYPE_UINT32 },
- { "uint64", TDESC_TYPE_UINT64 },
- { "uint128", TDESC_TYPE_UINT128 },
- { "code_ptr", TDESC_TYPE_CODE_PTR },
- { "data_ptr", TDESC_TYPE_DATA_PTR },
- { "ieee_single", TDESC_TYPE_IEEE_SINGLE },
- { "ieee_double", TDESC_TYPE_IEEE_DOUBLE },
- { "arm_fpa_ext", TDESC_TYPE_ARM_FPA_EXT },
- { "i387_ext", TDESC_TYPE_I387_EXT }
-};
-
-/* Lookup a predefined type. */
-
-static struct tdesc_type *
-tdesc_predefined_type (enum tdesc_type_kind kind)
-{
- for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
- if (tdesc_predefined_types[ix].kind == kind)
- return &tdesc_predefined_types[ix];
-
- gdb_assert_not_reached ("bad predefined tdesc type");
-}
-
-/* See common/tdesc.h. */
-
-struct tdesc_type *
-tdesc_named_type (const struct tdesc_feature *feature, const char *id)
-{
- /* First try target-defined types. */
- for (const tdesc_type_up &type : feature->types)
- if (type->name == id)
- return type.get ();
-
- /* Next try the predefined types. */
- for (int ix = 0; ix < ARRAY_SIZE (tdesc_predefined_types); ix++)
- if (tdesc_predefined_types[ix].name == id)
- return &tdesc_predefined_types[ix];
-
- return NULL;
-}
-
/* Lookup type associated with ID. */
struct type *
/* See common/tdesc.h. */
-struct tdesc_type *
-tdesc_create_vector (struct tdesc_feature *feature, const char *name,
- struct tdesc_type *field_type, int count)
-{
- tdesc_type_vector *type = new tdesc_type_vector (name, field_type, count);
- feature->types.emplace_back (type);
-
- return type;
-}
-
-/* See common/tdesc.h. */
-
-tdesc_type_with_fields *
-tdesc_create_struct (struct tdesc_feature *feature, const char *name)
-{
- tdesc_type_with_fields *type
- = new tdesc_type_with_fields (name, TDESC_TYPE_STRUCT);
- feature->types.emplace_back (type);
-
- return type;
-}
-
-/* See common/tdesc.h. */
-
-void
-tdesc_set_struct_size (tdesc_type_with_fields *type, int size)
-{
- gdb_assert (type->kind == TDESC_TYPE_STRUCT);
- gdb_assert (size > 0);
- type->size = size;
-}
-
-/* See common/tdesc.h. */
-
-tdesc_type_with_fields *
-tdesc_create_union (struct tdesc_feature *feature, const char *name)
-{
- tdesc_type_with_fields *type
- = new tdesc_type_with_fields (name, TDESC_TYPE_UNION);
- feature->types.emplace_back (type);
-
- return type;
-}
-
-/* See common/tdesc.h. */
-
-tdesc_type_with_fields *
-tdesc_create_flags (struct tdesc_feature *feature, const char *name,
- int size)
-{
- gdb_assert (size > 0);
-
- tdesc_type_with_fields *type
- = new tdesc_type_with_fields (name, TDESC_TYPE_FLAGS, size);
- feature->types.emplace_back (type);
-
- return type;
-}
-
-tdesc_type_with_fields *
-tdesc_create_enum (struct tdesc_feature *feature, const char *name,
- int size)
-{
- gdb_assert (size > 0);
-
- tdesc_type_with_fields *type
- = new tdesc_type_with_fields (name, TDESC_TYPE_ENUM, size);
- feature->types.emplace_back (type);
-
- return type;
-}
-
-/* See common/tdesc.h. */
-
-void
-tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
- struct tdesc_type *field_type)
-{
- gdb_assert (type->kind == TDESC_TYPE_UNION
- || type->kind == TDESC_TYPE_STRUCT);
-
- /* Initialize start and end so we know this is not a bit-field
- when we print-c-tdesc. */
- type->fields.emplace_back (field_name, field_type, -1, -1);
-}
-
-void
-tdesc_add_typed_bitfield (tdesc_type_with_fields *type, const char *field_name,
- int start, int end, struct tdesc_type *field_type)
-{
- gdb_assert (type->kind == TDESC_TYPE_STRUCT
- || type->kind == TDESC_TYPE_FLAGS);
- gdb_assert (start >= 0 && end >= start);
-
- type->fields.emplace_back (field_name, field_type, start, end);
-}
-
-/* See common/tdesc.h. */
-
-void
-tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name,
- int start, int end)
-{
- struct tdesc_type *field_type;
-
- gdb_assert (start >= 0 && end >= start);
-
- if (type->size > 4)
- field_type = tdesc_predefined_type (TDESC_TYPE_UINT64);
- else
- field_type = tdesc_predefined_type (TDESC_TYPE_UINT32);
-
- tdesc_add_typed_bitfield (type, field_name, start, end, field_type);
-}
-
-/* See common/tdesc.h. */
-
-void
-tdesc_add_flag (tdesc_type_with_fields *type, int start,
- const char *flag_name)
-{
- gdb_assert (type->kind == TDESC_TYPE_FLAGS
- || type->kind == TDESC_TYPE_STRUCT);
-
- type->fields.emplace_back (flag_name,
- tdesc_predefined_type (TDESC_TYPE_BOOL),
- start, start);
-}
-
-void
-tdesc_add_enum_value (tdesc_type_with_fields *type, int value,
- const char *name)
-{
- gdb_assert (type->kind == TDESC_TYPE_ENUM);
- type->fields.emplace_back (name,
- tdesc_predefined_type (TDESC_TYPE_INT32),
- value, -1);
-}
-
-/* See common/tdesc.h. */
-
struct tdesc_feature *
tdesc_create_feature (struct target_desc *tdesc, const char *name,
const char *xml)
const char *key, const char *value);
void tdesc_add_compatible (struct target_desc *,
const struct bfd_arch_info *);
-tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature,
- const char *name,
- int size);
-void tdesc_add_typed_bitfield (tdesc_type_with_fields *type, const char *field_name,
- int start, int end,
- struct tdesc_type *field_type);
-void tdesc_add_enum_value (tdesc_type_with_fields *type, int value,
- const char *name);
#if GDB_SELF_TEST
namespace selftests {