Update copyright year range in all GDB files.
[binutils-gdb.git] / gdb / gdbsupport / tdesc.h
blob3b1f1f57ff8d3aca707f0d0b2e2b67367b7d97eb
1 /* Copyright (C) 2006-2020 Free Software Foundation, Inc.
3 This file is part of GDB.
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18 #ifndef COMMON_TDESC_H
19 #define COMMON_TDESC_H
21 struct tdesc_feature;
22 struct tdesc_type;
23 struct tdesc_type_builtin;
24 struct tdesc_type_vector;
25 struct tdesc_type_with_fields;
26 struct tdesc_reg;
27 struct target_desc;
29 /* The interface to visit different elements of target description. */
31 class tdesc_element_visitor
33 public:
34 virtual void visit_pre (const target_desc *e)
37 virtual void visit_post (const target_desc *e)
40 virtual void visit_pre (const tdesc_feature *e)
43 virtual void visit_post (const tdesc_feature *e)
46 virtual void visit (const tdesc_type_builtin *e)
49 virtual void visit (const tdesc_type_vector *e)
52 virtual void visit (const tdesc_type_with_fields *e)
55 virtual void visit (const tdesc_reg *e)
59 class tdesc_element
61 public:
62 virtual void accept (tdesc_element_visitor &v) const = 0;
65 /* An individual register from a target description. */
67 struct tdesc_reg : tdesc_element
69 tdesc_reg (struct tdesc_feature *feature, const std::string &name_,
70 int regnum, int save_restore_, const char *group_,
71 int bitsize_, const char *type_);
73 virtual ~tdesc_reg () = default;
75 DISABLE_COPY_AND_ASSIGN (tdesc_reg);
77 /* The name of this register. In standard features, it may be
78 recognized by the architecture support code, or it may be purely
79 for the user. */
80 std::string name;
82 /* The register number used by this target to refer to this
83 register. This is used for remote p/P packets and to determine
84 the ordering of registers in the remote g/G packets. */
85 long target_regnum;
87 /* If this flag is set, GDB should save and restore this register
88 around calls to an inferior function. */
89 int save_restore;
91 /* The name of the register group containing this register, or empty
92 if the group should be automatically determined from the
93 register's type. If this is "general", "float", or "vector", the
94 corresponding "info" command should display this register's
95 value. It can be an arbitrary string, but should be limited to
96 alphanumeric characters and internal hyphens. Currently other
97 strings are ignored (treated as empty). */
98 std::string group;
100 /* The size of the register, in bits. */
101 int bitsize;
103 /* The type of the register. This string corresponds to either
104 a named type from the target description or a predefined
105 type from GDB. */
106 std::string type;
108 /* The target-described type corresponding to TYPE, if found. */
109 struct tdesc_type *tdesc_type;
111 void accept (tdesc_element_visitor &v) const override
113 v.visit (this);
116 bool operator== (const tdesc_reg &other) const
118 return (name == other.name
119 && target_regnum == other.target_regnum
120 && save_restore == other.save_restore
121 && bitsize == other.bitsize
122 && group == other.group
123 && type == other.type);
126 bool operator!= (const tdesc_reg &other) const
128 return !(*this == other);
132 typedef std::unique_ptr<tdesc_reg> tdesc_reg_up;
134 enum tdesc_type_kind
136 /* Predefined types. */
137 TDESC_TYPE_BOOL,
138 TDESC_TYPE_INT8,
139 TDESC_TYPE_INT16,
140 TDESC_TYPE_INT32,
141 TDESC_TYPE_INT64,
142 TDESC_TYPE_INT128,
143 TDESC_TYPE_UINT8,
144 TDESC_TYPE_UINT16,
145 TDESC_TYPE_UINT32,
146 TDESC_TYPE_UINT64,
147 TDESC_TYPE_UINT128,
148 TDESC_TYPE_CODE_PTR,
149 TDESC_TYPE_DATA_PTR,
150 TDESC_TYPE_IEEE_HALF,
151 TDESC_TYPE_IEEE_SINGLE,
152 TDESC_TYPE_IEEE_DOUBLE,
153 TDESC_TYPE_ARM_FPA_EXT,
154 TDESC_TYPE_I387_EXT,
156 /* Types defined by a target feature. */
157 TDESC_TYPE_VECTOR,
158 TDESC_TYPE_STRUCT,
159 TDESC_TYPE_UNION,
160 TDESC_TYPE_FLAGS,
161 TDESC_TYPE_ENUM
164 struct tdesc_type : tdesc_element
166 tdesc_type (const std::string &name_, enum tdesc_type_kind kind_)
167 : name (name_), kind (kind_)
170 virtual ~tdesc_type () = default;
172 DISABLE_COPY_AND_ASSIGN (tdesc_type);
174 /* The name of this type. */
175 std::string name;
177 /* Identify the kind of this type. */
178 enum tdesc_type_kind kind;
180 bool operator== (const tdesc_type &other) const
182 return name == other.name && kind == other.kind;
185 bool operator!= (const tdesc_type &other) const
187 return !(*this == other);
191 typedef std::unique_ptr<tdesc_type> tdesc_type_up;
193 struct tdesc_type_builtin : tdesc_type
195 tdesc_type_builtin (const std::string &name, enum tdesc_type_kind kind)
196 : tdesc_type (name, kind)
199 void accept (tdesc_element_visitor &v) const override
201 v.visit (this);
205 /* tdesc_type for vector types. */
207 struct tdesc_type_vector : tdesc_type
209 tdesc_type_vector (const std::string &name, tdesc_type *element_type_,
210 int count_)
211 : tdesc_type (name, TDESC_TYPE_VECTOR),
212 element_type (element_type_), count (count_)
215 void accept (tdesc_element_visitor &v) const override
217 v.visit (this);
220 struct tdesc_type *element_type;
221 int count;
224 /* A named type from a target description. */
226 struct tdesc_type_field
228 tdesc_type_field (const std::string &name_, tdesc_type *type_,
229 int start_, int end_)
230 : name (name_), type (type_), start (start_), end (end_)
233 std::string name;
234 struct tdesc_type *type;
235 /* For non-enum-values, either both are -1 (non-bitfield), or both are
236 not -1 (bitfield). For enum values, start is the value (which could be
237 -1), end is -1. */
238 int start, end;
241 /* tdesc_type for struct, union, flags, and enum types. */
243 struct tdesc_type_with_fields : tdesc_type
245 tdesc_type_with_fields (const std::string &name, tdesc_type_kind kind,
246 int size_ = 0)
247 : tdesc_type (name, kind), size (size_)
250 void accept (tdesc_element_visitor &v) const override
252 v.visit (this);
255 std::vector<tdesc_type_field> fields;
256 int size;
259 /* A feature from a target description. Each feature is a collection
260 of other elements, e.g. registers and types. */
262 struct tdesc_feature : tdesc_element
264 tdesc_feature (const std::string &name_)
265 : name (name_)
268 virtual ~tdesc_feature () = default;
270 DISABLE_COPY_AND_ASSIGN (tdesc_feature);
272 /* The name of this feature. It may be recognized by the architecture
273 support code. */
274 std::string name;
276 /* The registers associated with this feature. */
277 std::vector<tdesc_reg_up> registers;
279 /* The types associated with this feature. */
280 std::vector<tdesc_type_up> types;
282 void accept (tdesc_element_visitor &v) const override;
284 bool operator== (const tdesc_feature &other) const;
286 bool operator!= (const tdesc_feature &other) const
288 return !(*this == other);
292 typedef std::unique_ptr<tdesc_feature> tdesc_feature_up;
294 /* Allocate a new target_desc. */
295 target_desc *allocate_target_description (void);
297 /* Set TARGET_DESC's architecture by NAME. */
298 void set_tdesc_architecture (target_desc *target_desc,
299 const char *name);
301 /* Return the architecture associated with this target description as a string,
302 or NULL if no architecture was specified. */
303 const char *tdesc_architecture_name (const struct target_desc *target_desc);
305 /* Set TARGET_DESC's osabi by NAME. */
306 void set_tdesc_osabi (target_desc *target_desc, const char *name);
308 /* Return the osabi associated with this target description as a string,
309 or NULL if no osabi was specified. */
310 const char *tdesc_osabi_name (const struct target_desc *target_desc);
312 /* Return the type associated with ID in the context of FEATURE, or
313 NULL if none. */
314 struct tdesc_type *tdesc_named_type (const struct tdesc_feature *feature,
315 const char *id);
317 /* Return the created feature named NAME in target description TDESC. */
318 struct tdesc_feature *tdesc_create_feature (struct target_desc *tdesc,
319 const char *name);
321 /* Return the created vector tdesc_type named NAME in FEATURE. */
322 struct tdesc_type *tdesc_create_vector (struct tdesc_feature *feature,
323 const char *name,
324 struct tdesc_type *field_type,
325 int count);
327 /* Return the created struct tdesc_type named NAME in FEATURE. */
328 tdesc_type_with_fields *tdesc_create_struct (struct tdesc_feature *feature,
329 const char *name);
331 /* Return the created union tdesc_type named NAME in FEATURE. */
332 tdesc_type_with_fields *tdesc_create_union (struct tdesc_feature *feature,
333 const char *name);
335 /* Return the created flags tdesc_type named NAME in FEATURE. */
336 tdesc_type_with_fields *tdesc_create_flags (struct tdesc_feature *feature,
337 const char *name,
338 int size);
340 /* Return the created enum tdesc_type named NAME in FEATURE. */
341 tdesc_type_with_fields *tdesc_create_enum (struct tdesc_feature *feature,
342 const char *name,
343 int size);
345 /* Add a new field to TYPE. FIELD_NAME is its name, and FIELD_TYPE is
346 its type. */
347 void tdesc_add_field (tdesc_type_with_fields *type, const char *field_name,
348 struct tdesc_type *field_type);
350 /* Add a new bitfield to TYPE, with range START to END. FIELD_NAME is its name,
351 and FIELD_TYPE is its type. */
352 void tdesc_add_typed_bitfield (tdesc_type_with_fields *type,
353 const char *field_name,
354 int start, int end,
355 struct tdesc_type *field_type);
357 /* Set the total length of TYPE. Structs which contain bitfields may
358 omit the reserved bits, so the end of the last field may not
359 suffice. */
360 void tdesc_set_struct_size (tdesc_type_with_fields *type, int size);
362 /* Add a new untyped bitfield to TYPE.
363 Untyped bitfields become either uint32 or uint64 depending on the size
364 of the underlying type. */
365 void tdesc_add_bitfield (tdesc_type_with_fields *type, const char *field_name,
366 int start, int end);
368 /* A flag is just a typed(bool) single-bit bitfield.
369 This function is kept to minimize changes in generated files. */
370 void tdesc_add_flag (tdesc_type_with_fields *type, int start,
371 const char *flag_name);
373 /* Add field with VALUE and NAME to the enum TYPE. */
374 void tdesc_add_enum_value (tdesc_type_with_fields *type, int value,
375 const char *name);
377 /* Create a register in feature FEATURE. */
378 void tdesc_create_reg (struct tdesc_feature *feature, const char *name,
379 int regnum, int save_restore, const char *group,
380 int bitsize, const char *type);
382 /* Return the tdesc in string XML format. */
384 const char *tdesc_get_features_xml (const target_desc *tdesc);
386 /* Print target description as xml. */
388 class print_xml_feature : public tdesc_element_visitor
390 public:
391 print_xml_feature (std::string *buffer_)
392 : m_buffer (buffer_)
395 void visit_pre (const target_desc *e) override;
396 void visit_post (const target_desc *e) override;
397 void visit_pre (const tdesc_feature *e) override;
398 void visit_post (const tdesc_feature *e) override;
399 void visit (const tdesc_type_builtin *type) override;
400 void visit (const tdesc_type_vector *type) override;
401 void visit (const tdesc_type_with_fields *type) override;
402 void visit (const tdesc_reg *reg) override;
404 private:
405 std::string *m_buffer;
408 #endif /* COMMON_TDESC_H */