]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/config/avr/gen-avr-mmcu-texi.c
1 /* Copyright (C) 2012-2021 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 #include "avr-devices.c"
28 static const avr_mcu_t
*
29 mcus
[sizeof avr_mcu_types
/ sizeof avr_mcu_types
[0]];
31 static int letter (char c
)
33 return c
>= 'a' && c
<= 'z';
36 static int digit (char c
)
38 return c
>= '0' && c
<= '9';
42 str_prefix_p (const char *str
, const char *prefix
)
44 return strncmp (str
, prefix
, strlen (prefix
)) == 0;
48 /* Used by string comparator to group MCUs by their
49 name prefix like "attiny" or "atmega". */
52 c_prefix (const char *str
)
54 static const char *const prefixes
[] =
56 "attiny", "atmega", "atxmega", "ata", "at90"
59 int i
, n
= (int) (sizeof (prefixes
) / sizeof (*prefixes
));
61 for (i
= 0; i
< n
; i
++)
62 if (str_prefix_p (str
, prefixes
[i
]))
69 /* If A starts a group of digits, return their value as a number. */
72 c_number (const char *a
)
76 if (digit (*a
) && ! digit (*(a
-1)))
79 val
= 10 * val
+ (*a
++) - '0';
86 /* Compare two MCUs and order them for easy lookup. */
89 comparator (const void *va
, const void *vb
)
91 const avr_mcu_t
*mcu_a
= *(const avr_mcu_t
* const*) va
;
92 const avr_mcu_t
*mcu_b
= *(const avr_mcu_t
* const*) vb
;
93 const char *a
= mcu_a
->name
;
94 const char *b
= mcu_b
->name
;
96 // First, group MCUs according to their pure-letter prefix.
98 int c
= c_prefix (a
) - c_prefix (b
);
102 // Second, if their prefixes are the same, group according to
105 c
= (int) mcu_a
->flash_size
- (int) mcu_b
->flash_size
;
109 // Third, group according to aligned groups of digits.
113 c
= c_number (a
) - c_number (b
);
128 print_mcus (size_t n_mcus
)
136 qsort (mcus
, n_mcus
, sizeof (avr_mcu_t
*), comparator
);
138 printf ("@*@var{mcu}@tie{}=");
140 for (i
= 0; i
< n_mcus
; i
++)
142 printf (" @code{%s}%s", mcus
[i
]->name
, i
== n_mcus
-1 ? ".\n\n" : ",");
144 if (i
&& !strcmp (mcus
[i
]->name
, mcus
[i
-1]->name
))
146 // Sanity-check: Fail on devices that are present more than once.
149 fprintf (stderr
, "error: duplicate device: %s\n", mcus
[i
]->name
);
159 enum avr_arch_id arch_id
= ARCH_UNKNOWN
;
160 size_t i
, n_mcus
= 0;
161 const avr_mcu_t
*mcu
;
163 printf ("@c Copyright (C) 2012-2021 Free Software Foundation, Inc.\n");
164 printf ("@c This is part of the GCC manual.\n");
165 printf ("@c For copying conditions, see the file "
166 "gcc/doc/include/fdl.texi.\n\n");
168 printf ("@c This file is generated automatically using\n");
169 printf ("@c gcc/config/avr/gen-avr-mmcu-texi.c from:\n");
170 printf ("@c gcc/config/avr/avr-arch.h\n");
171 printf ("@c gcc/config/avr/avr-devices.c\n");
172 printf ("@c gcc/config/avr/avr-mcus.def\n\n");
174 printf ("@c Please do not edit manually.\n\n");
176 printf ("@table @code\n\n");
178 for (mcu
= avr_mcu_types
; mcu
->name
; mcu
++)
180 if (mcu
->macro
== NULL
)
182 arch_id
= mcu
->arch_id
;
184 // Start a new architecture: Flush the MCUs collected so far.
188 for (i
= 0; i
< sizeof (avr_texinfo
) / sizeof (*avr_texinfo
); i
++)
189 if (arch_id
== avr_texinfo
[i
].arch_id
)
190 printf ("@item %s\n%s\n", mcu
->name
, avr_texinfo
[i
].texinfo
);
192 else if (arch_id
== (enum avr_arch_id
) mcu
->arch_id
)
194 mcus
[n_mcus
++] = mcu
;
199 printf ("@end table\n");