aarch64: Add comment about thunderxt81/t83 being aliases
[official-gcc.git] / gcc / config / avr / gen-avr-mmcu-texi.cc
blob70aa430902ebfec2ee8fdef8fe2e8b3150d85c44
1 /* Copyright (C) 2012-2024 Free Software Foundation, Inc.
2 Contributed by Georg-Johann Lay (avr@gjlay.de)
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3, or (at your option)
9 any later version.
11 GCC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <string.h>
24 #define IN_GEN_AVR_MMCU_TEXI
26 #define ARRAY_SIZE(a) (sizeof (a) / sizeof ((a)[0]))
28 #include "avr-devices.cc"
30 static const avr_mcu_t*
31 mcus[ARRAY_SIZE (avr_mcu_types)];
33 static int letter (char c)
35 return c >= 'a' && c <= 'z';
38 static int digit (char c)
40 return c >= '0' && c <= '9';
43 static int
44 str_prefix_p (const char *str, const char *prefix)
46 return strncmp (str, prefix, strlen (prefix)) == 0;
50 /* Used by string comparator to group MCUs by their
51 name prefix like "attiny" or "atmega". */
53 static int
54 c_prefix (const char *str)
56 static const char *const prefixes[] =
58 "attiny", "atmega", "atxmega", "ata", "at90", "avr"
61 int i, n = (int) (ARRAY_SIZE (prefixes));
63 for (i = 0; i < n; i++)
64 if (str_prefix_p (str, prefixes[i]))
65 return i;
67 return n;
71 /* If A starts a group of digits, return their value as a number. */
73 static int
74 c_number (const char *a)
76 int val = 0;
78 if (digit (*a) && ! digit (*(a-1)))
80 while (digit (*a))
81 val = 10 * val + (*a++) - '0';
84 return val;
88 /* Compare two MCUs and order them for easy lookup. */
90 static int
91 comparator (const void *va, const void *vb)
93 const avr_mcu_t *mcu_a = *(const avr_mcu_t* const*) va;
94 const avr_mcu_t *mcu_b = *(const avr_mcu_t* const*) vb;
95 const char *a = mcu_a->name;
96 const char *b = mcu_b->name;
98 // First, group MCUs according to their pure-letter prefix.
100 int c = c_prefix (a) - c_prefix (b);
101 if (c)
102 return c;
104 // Second, if their prefixes are the same, group according to
105 // their flash size.
107 c = (int) mcu_a->flash_size - (int) mcu_b->flash_size;
108 if (c)
109 return c;
111 // Third, group according to aligned groups of digits.
113 while (*a && *b)
115 c = c_number (a) - c_number (b);
116 if (c)
117 return c;
119 if (*a != *b)
120 return *a - *b;
122 a++;
123 b++;
126 return *a - *b;
129 static void
130 print_mcus (size_t n_mcus)
132 int duplicate = 0;
133 size_t i;
135 if (!n_mcus)
136 return;
138 qsort (mcus, n_mcus, sizeof (avr_mcu_t*), comparator);
140 printf ("@*@var{mcu}@tie{}=");
142 for (i = 0; i < n_mcus; i++)
144 printf (" @code{%s}%s", mcus[i]->name, i == n_mcus-1 ? ".\n\n" : ",");
146 if (i && !strcmp (mcus[i]->name, mcus[i-1]->name))
148 // Sanity-check: Fail on devices that are present more than once.
150 duplicate = 1;
151 fprintf (stderr, "error: duplicate device: %s\n", mcus[i]->name);
155 if (duplicate)
156 exit (1);
159 int main (void)
161 enum avr_arch_id arch_id = ARCH_UNKNOWN;
162 size_t i, n_mcus = 0;
163 const avr_mcu_t *mcu;
165 printf ("@c Copyright (C) 2012-2024 Free Software Foundation, Inc.\n");
166 printf ("@c This is part of the GCC manual.\n");
167 printf ("@c For copying conditions, see the file "
168 "gcc/doc/include/fdl.texi.\n\n");
170 printf ("@c This file is generated automatically using\n");
171 printf ("@c gcc/config/avr/gen-avr-mmcu-texi.cc from:\n");
172 printf ("@c gcc/config/avr/avr-arch.h\n");
173 printf ("@c gcc/config/avr/avr-devices.cc\n");
174 printf ("@c gcc/config/avr/avr-mcus.def\n\n");
176 printf ("@c Please do not edit manually.\n\n");
178 printf ("@table @code\n\n");
180 for (mcu = avr_mcu_types; mcu->name; mcu++)
182 if (mcu->macro == NULL)
184 arch_id = mcu->arch_id;
186 // Start a new architecture: Flush the MCUs collected so far.
187 print_mcus (n_mcus);
188 n_mcus = 0;
190 for (i = 0; i < ARRAY_SIZE (avr_texinfo); i++)
191 if (arch_id == avr_texinfo[i].arch_id)
192 printf ("@item @anchor{%s}%s\n%s\n", mcu->name, mcu->name,
193 avr_texinfo[i].texinfo);
195 else if (arch_id == (enum avr_arch_id) mcu->arch_id)
197 mcus[n_mcus++] = mcu;
201 print_mcus (n_mcus);
202 printf ("@end table\n");
204 return EXIT_SUCCESS;