]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/config/avr/gen-avr-mmcu-texi.c
mpx-dg.exp (mpx_link_flags): Set path to wrappers library.
[thirdparty/gcc.git] / gcc / config / avr / gen-avr-mmcu-texi.c
CommitLineData
5624e564 1/* Copyright (C) 2012-2015 Free Software Foundation, Inc.
04d170d2
GJL
2 Contributed by Georg-Johann Lay (avr@gjlay.de)
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
e3cf7a95
GJL
20#include <stdlib.h>
21#include <stdio.h>
22
23#define IN_GEN_AVR_MMCU_TEXI
24
25#include "avr-arch.h"
04d170d2
GJL
26#include "avr-devices.c"
27
5be35a61
GJL
28static const char*
29mcu_name[sizeof avr_mcu_types / sizeof avr_mcu_types[0]];
30
e3cf7a95
GJL
31static int letter (char c)
32{
33 return c >= 'a' && c <= 'z';
34}
35
36static int digit (char c)
37{
38 return c >= '0' && c <= '9';
39}
40
5be35a61
GJL
41static int
42comparator (const void *va, const void *vb)
43{
e3cf7a95
GJL
44 const char *a = *(const char* const*) va;
45 const char *b = *(const char* const*) vb;
46
47 while (*a && *b)
48 {
49 /* Make letters smaller than digits so that `atmega16a' follows
50 `atmega16' without `atmega161' etc. between them. */
51
52 if (letter (*a) && digit (*b))
53 return -1;
54
55 if (digit (*a) && letter (*b))
56 return 1;
57
58 if (*a != *b)
59 return *a - *b;
60
61 a++;
62 b++;
63 }
5be35a61 64
e3cf7a95 65 return *a - *b;
5be35a61
GJL
66}
67
68static void
69print_mcus (size_t n_mcus)
70{
5219b232 71 int duplicate = 0;
5be35a61
GJL
72 size_t i;
73
74 if (!n_mcus)
75 return;
76
77 qsort (mcu_name, n_mcus, sizeof (char*), comparator);
78
79 printf ("@*@var{mcu}@tie{}=");
80
81 for (i = 0; i < n_mcus; i++)
5219b232
GJL
82 {
83 printf (" @code{%s}%s", mcu_name[i], i == n_mcus-1 ? ".\n\n" : ",");
84
85 if (i && !strcmp (mcu_name[i], mcu_name[i-1]))
86 {
87 /* Sanity-check: Fail on devices that are present more than once. */
88
89 duplicate = 1;
90 fprintf (stderr, "error: duplicate device: %s\n", mcu_name[i]);
91 }
92 }
93
94 if (duplicate)
95 exit (1);
5be35a61
GJL
96}
97
04d170d2
GJL
98int main (void)
99{
92f7f5fd 100 enum avr_arch arch = ARCH_UNKNOWN;
5be35a61 101 size_t i, n_mcus = 0;
1c494c6a 102 const avr_mcu_t *mcu;
04d170d2 103
5624e564 104 printf ("@c Copyright (C) 2012-2015 Free Software Foundation, Inc.\n");
04d170d2
GJL
105 printf ("@c This is part of the GCC manual.\n");
106 printf ("@c For copying conditions, see the file "
107 "gcc/doc/include/fdl.texi.\n\n");
108
109 printf ("@c This file is generated automatically using\n");
110 printf ("@c gcc/config/avr/gen-avr-mmcu-texi.c from:\n");
e3cf7a95 111 printf ("@c gcc/config/avr/avr-arch.h\n");
04d170d2
GJL
112 printf ("@c gcc/config/avr/avr-devices.c\n");
113 printf ("@c gcc/config/avr/avr-mcus.def\n\n");
114
115 printf ("@c Please do not edit manually.\n\n");
116
117 printf ("@table @code\n\n");
118
119 for (mcu = avr_mcu_types; mcu->name; mcu++)
120 {
121 if (mcu->macro == NULL)
122 {
123 arch = mcu->arch;
124
5be35a61
GJL
125 /* Start a new architecture: Flush the MCUs collected so far. */
126
127 print_mcus (n_mcus);
128 n_mcus = 0;
129
04d170d2 130 for (i = 0; i < sizeof (avr_texinfo) / sizeof (*avr_texinfo); i++)
5be35a61
GJL
131 if (arch == avr_texinfo[i].arch)
132 printf ("@item %s\n%s\n", mcu->name, avr_texinfo[i].texinfo);
04d170d2
GJL
133 }
134 else if (arch == (enum avr_arch) mcu->arch)
135 {
5be35a61 136 mcu_name[n_mcus++] = mcu->name;
04d170d2
GJL
137 }
138 }
139
5be35a61 140 print_mcus (n_mcus);
04d170d2
GJL
141 printf ("@end table\n");
142
143 return EXIT_SUCCESS;
144}