- void accept (tdesc_element_visitor &v) const override
- {
- v.visit (this);
- }
-
- type *make_gdb_type (struct gdbarch *gdbarch) const override
- {
- type *vector_gdb_type = tdesc_find_type (gdbarch, this->name.c_str ());
- if (vector_gdb_type != NULL)
- return vector_gdb_type;
-
- type *element_gdb_type = this->element_type->make_gdb_type (gdbarch);
- vector_gdb_type = init_vector_type (element_gdb_type, this->count);
- TYPE_NAME (vector_gdb_type) = xstrdup (this->name.c_str ());
-
- return vector_gdb_type;
- }
-
- 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);
- }
-
- type *make_gdb_type_struct (struct gdbarch *gdbarch) const
- {
- type *struct_gdb_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_STRUCT);
- TYPE_NAME (struct_gdb_type) = xstrdup (this->name.c_str ());
- TYPE_TAG_NAME (struct_gdb_type) = TYPE_NAME (struct_gdb_type);
-
- for (const tdesc_type_field &f : this->fields)
- {
- if (f.start != -1 && f.end != -1)
- {
- /* Bitfield. */
- struct field *fld;
- struct type *field_gdb_type;
- int bitsize, total_size;
-
- /* This invariant should be preserved while creating types. */
- gdb_assert (this->size != 0);
- if (f.type != NULL)
- field_gdb_type = f.type->make_gdb_type (gdbarch);
- else if (this->size > 4)
- field_gdb_type = builtin_type (gdbarch)->builtin_uint64;
- else
- field_gdb_type = builtin_type (gdbarch)->builtin_uint32;
-
- fld = append_composite_type_field_raw
- (struct_gdb_type, xstrdup (f.name.c_str ()), field_gdb_type);
-
- /* For little-endian, BITPOS counts from the LSB of
- the structure and marks the LSB of the field. For
- big-endian, BITPOS counts from the MSB of the
- structure and marks the MSB of the field. Either
- way, it is the number of bits to the "left" of the
- field. To calculate this in big-endian, we need
- the total size of the structure. */
- bitsize = f.end - f.start + 1;
- total_size = this->size * TARGET_CHAR_BIT;
- if (gdbarch_bits_big_endian (gdbarch))
- SET_FIELD_BITPOS (fld[0], total_size - f.start - bitsize);
- else
- SET_FIELD_BITPOS (fld[0], f.start);
- FIELD_BITSIZE (fld[0]) = bitsize;
- }
- else
- {
- gdb_assert (f.start == -1 && f.end == -1);
- type *field_gdb_type = f.type->make_gdb_type (gdbarch);
- append_composite_type_field (struct_gdb_type,
- xstrdup (f.name.c_str ()),
- field_gdb_type);
- }
- }
-
- if (this->size != 0)
- TYPE_LENGTH (struct_gdb_type) = this->size;
-
- return struct_gdb_type;
- }
-
- type *make_gdb_type_union (struct gdbarch *gdbarch) const
- {
- type *union_gdb_type = arch_composite_type (gdbarch, NULL, TYPE_CODE_UNION);
- TYPE_NAME (union_gdb_type) = xstrdup (this->name.c_str ());
-
- for (const tdesc_type_field &f : this->fields)
- {
- type* field_gdb_type = f.type->make_gdb_type (gdbarch);
- append_composite_type_field (union_gdb_type, xstrdup (f.name.c_str ()),
- field_gdb_type);
-
- /* If any of the children of a union are vectors, flag the
- union as a vector also. This allows e.g. a union of two
- vector types to show up automatically in "info vector". */
- if (TYPE_VECTOR (field_gdb_type))
- TYPE_VECTOR (union_gdb_type) = 1;
- }
-
- return union_gdb_type;
- }
-
- type *make_gdb_type_flags (struct gdbarch *gdbarch) const
- {
- type *flags_gdb_type = arch_flags_type (gdbarch, this->name.c_str (),
- this->size * TARGET_CHAR_BIT);
-
- for (const tdesc_type_field &f : this->fields)
- {
- int bitsize = f.end - f.start + 1;
-
- gdb_assert (f.type != NULL);
- type *field_gdb_type = f.type->make_gdb_type (gdbarch);
- append_flags_type_field (flags_gdb_type, f.start, bitsize,
- field_gdb_type, f.name.c_str ());
- }
-
- return flags_gdb_type;
- }
-
- type *make_gdb_type_enum (struct gdbarch *gdbarch) const
- {
- type *enum_gdb_type = arch_type (gdbarch, TYPE_CODE_ENUM,
- this->size * TARGET_CHAR_BIT,
- this->name.c_str ());
-
- TYPE_UNSIGNED (enum_gdb_type) = 1;
- for (const tdesc_type_field &f : this->fields)
- {
- struct field *fld
- = append_composite_type_field_raw (enum_gdb_type,
- xstrdup (f.name.c_str ()),
- NULL);
-
- SET_FIELD_BITPOS (fld[0], f.start);
- }
-
- return enum_gdb_type;
- }
-
- type *make_gdb_type (struct gdbarch *gdbarch) const override
- {
- type *gdb_type = tdesc_find_type (gdbarch, this->name.c_str ());
- if (gdb_type != NULL)
- return gdb_type;
-
- switch (this->kind)