+static void
+maint_print_c_tdesc_cmd (char *args, int from_tty)
+{
+ const struct target_desc *tdesc;
+ const struct bfd_arch_info *compatible;
+ const char *filename, *inp;
+ char *function, *outp;
+ struct property *prop;
+ struct tdesc_feature *feature;
+ struct tdesc_reg *reg;
+ struct tdesc_type *type;
+ struct tdesc_type_field *f;
+ struct tdesc_type_flag *flag;
+ int ix, ix2, ix3;
+ int printed_field_type = 0;
+
+ /* Use the global target-supplied description, not the current
+ architecture's. This lets a GDB for one architecture generate C
+ for another architecture's description, even though the gdbarch
+ initialization code will reject the new description. */
+ tdesc = current_target_desc;
+ if (tdesc == NULL)
+ error (_("There is no target description to print."));
+
+ if (target_description_filename == NULL)
+ error (_("The current target description did not come from an XML file."));
+
+ filename = lbasename (target_description_filename);
+ function = alloca (strlen (filename) + 1);
+ for (inp = filename, outp = function; *inp != '\0'; inp++)
+ if (*inp == '.')
+ break;
+ else if (*inp == '-')
+ *outp++ = '_';
+ else
+ *outp++ = *inp;
+ *outp = '\0';
+
+ /* Standard boilerplate. */
+ printf_unfiltered ("/* THIS FILE IS GENERATED. "
+ "-*- buffer-read-only: t -*- vi"
+ ":set ro:\n");
+ printf_unfiltered (" Original: %s */\n\n", filename);
+ printf_unfiltered ("#include \"defs.h\"\n");
+ printf_unfiltered ("#include \"osabi.h\"\n");
+ printf_unfiltered ("#include \"target-descriptions.h\"\n");
+ printf_unfiltered ("\n");
+
+ printf_unfiltered ("struct target_desc *tdesc_%s;\n", function);
+ printf_unfiltered ("static void\n");
+ printf_unfiltered ("initialize_tdesc_%s (void)\n", function);
+ printf_unfiltered ("{\n");
+ printf_unfiltered
+ (" struct target_desc *result = allocate_target_description ();\n");
+ printf_unfiltered (" struct tdesc_feature *feature;\n");
+
+ /* Now we do some "filtering" in order to know which variables to
+ declare. This is needed because otherwise we would declare unused
+ variables `field_type' and `type'. */
+ for (ix = 0;
+ VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
+ ix++)
+ {
+ int printed_desc_type = 0;
+
+ for (ix2 = 0;
+ VEC_iterate (tdesc_type_p, feature->types, ix2, type);
+ ix2++)
+ {
+ if (!printed_field_type)
+ {
+ printf_unfiltered (" struct tdesc_type *field_type;\n");
+ printed_field_type = 1;
+ }
+
+ if ((type->kind == TDESC_TYPE_UNION
+ || type->kind == TDESC_TYPE_STRUCT)
+ && VEC_length (tdesc_type_field, type->u.u.fields) > 0)
+ {
+ printf_unfiltered (" struct tdesc_type *type;\n");
+ printed_desc_type = 1;
+ break;
+ }
+ }
+
+ if (printed_desc_type)
+ break;
+ }
+
+ printf_unfiltered ("\n");
+
+ if (tdesc_architecture (tdesc) != NULL)
+ {
+ printf_unfiltered
+ (" set_tdesc_architecture (result, bfd_scan_arch (\"%s\"));\n",
+ tdesc_architecture (tdesc)->printable_name);
+ printf_unfiltered ("\n");
+ }
+
+ if (tdesc_osabi (tdesc) > GDB_OSABI_UNKNOWN
+ && tdesc_osabi (tdesc) < GDB_OSABI_INVALID)
+ {
+ printf_unfiltered
+ (" set_tdesc_osabi (result, osabi_from_tdesc_string (\"%s\"));\n",
+ gdbarch_osabi_name (tdesc_osabi (tdesc)));
+ printf_unfiltered ("\n");
+ }
+
+ for (ix = 0; VEC_iterate (arch_p, tdesc->compatible, ix, compatible);
+ ix++)
+ {
+ printf_unfiltered
+ (" tdesc_add_compatible (result, bfd_scan_arch (\"%s\"));\n",
+ compatible->printable_name);
+ }
+ if (ix)
+ printf_unfiltered ("\n");
+
+ for (ix = 0; VEC_iterate (property_s, tdesc->properties, ix, prop);
+ ix++)
+ {
+ printf_unfiltered (" set_tdesc_property (result, \"%s\", \"%s\");\n",
+ prop->key, prop->value);
+ }
+
+ for (ix = 0;
+ VEC_iterate (tdesc_feature_p, tdesc->features, ix, feature);
+ ix++)
+ {
+ printf_unfiltered (" \
+feature = tdesc_create_feature (result, \"%s\");\n",
+ feature->name);
+
+ for (ix2 = 0;
+ VEC_iterate (tdesc_type_p, feature->types, ix2, type);
+ ix2++)
+ {
+ switch (type->kind)
+ {
+ case TDESC_TYPE_VECTOR:
+ printf_unfiltered
+ (" field_type = tdesc_named_type (feature, \"%s\");\n",
+ type->u.v.type->name);
+ printf_unfiltered
+ (" tdesc_create_vector (feature, \"%s\", field_type, %d);\n",
+ type->name, type->u.v.count);
+ break;
+ case TDESC_TYPE_STRUCT:
+ printf_unfiltered
+ (" type = tdesc_create_struct (feature, \"%s\");\n",
+ type->name);
+ if (type->u.u.size != 0)
+ printf_unfiltered
+ (" tdesc_set_struct_size (type, %s);\n",
+ plongest (type->u.u.size));
+ for (ix3 = 0;
+ VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
+ ix3++)
+ {
+ /* Going first for implicitly sized types, else part handles
+ bitfields. As reported on xml-tdesc.c implicitly sized types
+ cannot contain a bitfield. */
+ if (f->start == 0 && f->end == 0)
+ {
+ printf_unfiltered
+ (" field_type = tdesc_named_type (feature, \"%s\");\n",
+ f->type->name);
+ printf_unfiltered
+ (" tdesc_add_field (type, \"%s\", field_type);\n",
+ f->name);
+ }
+ else
+ printf_unfiltered
+ (" tdesc_add_bitfield (type, \"%s\", %d, %d);\n",
+ f->name, f->start, f->end);
+ }
+ break;
+ case TDESC_TYPE_UNION:
+ printf_unfiltered
+ (" type = tdesc_create_union (feature, \"%s\");\n",
+ type->name);
+ for (ix3 = 0;
+ VEC_iterate (tdesc_type_field, type->u.u.fields, ix3, f);
+ ix3++)
+ {
+ printf_unfiltered
+ (" field_type = tdesc_named_type (feature, \"%s\");\n",
+ f->type->name);
+ printf_unfiltered
+ (" tdesc_add_field (type, \"%s\", field_type);\n",
+ f->name);
+ }
+ break;
+ case TDESC_TYPE_FLAGS:
+ printf_unfiltered
+ (" field_type = tdesc_create_flags (feature, \"%s\", %d);\n",
+ type->name, (int) type->u.f.size);
+ for (ix3 = 0;
+ VEC_iterate (tdesc_type_flag, type->u.f.flags, ix3,
+ flag);
+ ix3++)
+ printf_unfiltered
+ (" tdesc_add_flag (field_type, %d, \"%s\");\n",
+ flag->start, flag->name);
+ break;
+ default:
+ error (_("C output is not supported type \"%s\"."), type->name);
+ }
+ printf_unfiltered ("\n");
+ }
+
+ for (ix2 = 0;
+ VEC_iterate (tdesc_reg_p, feature->registers, ix2, reg);
+ ix2++)
+ {
+ printf_unfiltered (" tdesc_create_reg (feature, \"%s\", %ld, %d, ",
+ reg->name, reg->target_regnum, reg->save_restore);
+ if (reg->group)
+ printf_unfiltered ("\"%s\", ", reg->group);
+ else
+ printf_unfiltered ("NULL, ");
+ printf_unfiltered ("%d, \"%s\");\n", reg->bitsize, reg->type);
+ }
+
+ printf_unfiltered ("\n");
+ }
+
+ printf_unfiltered (" tdesc_%s = result;\n", function);
+ printf_unfiltered ("}\n");
+}
+
+/* Provide a prototype to silence -Wmissing-prototypes. */
+extern initialize_file_ftype _initialize_target_descriptions;
+