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)
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/>. */
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';
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". */
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
]))
71 /* If A starts a group of digits, return their value as a number. */
74 c_number (const char *a
)
78 if (digit (*a
) && ! digit (*(a
-1)))
81 val
= 10 * val
+ (*a
++) - '0';
88 /* Compare two MCUs and order them for easy lookup. */
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
);
104 // Second, if their prefixes are the same, group according to
107 c
= (int) mcu_a
->flash_size
- (int) mcu_b
->flash_size
;
111 // Third, group according to aligned groups of digits.
115 c
= c_number (a
) - c_number (b
);
130 print_mcus (size_t n_mcus
)
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.
151 fprintf (stderr
, "error: duplicate device: %s\n", mcus
[i
]->name
);
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.
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
;
202 printf ("@end table\n");