OSDN Git Service

a162dee42a46cb3e74a3fff15b9a1bd1c5f37a49
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / compat / struct-layout-1_generate.c
1 /* Structure layout test generator.
2    Copyright (C) 2004, 2005, 2007, 2008 Free Software Foundation, Inc.
3    Contributed by Jakub Jelinek <jakub@redhat.com>.
4
5 This file is part of GCC.
6
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
10 version.
11
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING3.  If not see
19 <http://www.gnu.org/licenses/>.  */
20
21
22 /* Compile with gcc -o struct-layout-1_generate{,.c} generate_random{,_r}.c */
23
24 /* N.B. -- This program cannot use libiberty as that will not work
25    when testing an installed compiler.  */
26 #include <limits.h>
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <string.h>
30 #include <stddef.h>
31 /* We use our own pseudo-random number generator, so that it gives the same
32    values on all hosts.  */
33 #include "generate-random.h"
34
35 #if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL
36 # error Need 64-bit long long
37 #endif
38
39 #if defined __MSVCRT__ 
40 #define COMPAT_PRLL "I64"
41 #else 
42 #define COMPAT_PRLL "ll"
43 #endif
44
45 const char *dg_options[] = {
46 "/* { dg-options \"%s-I%s\" } */\n",
47 "/* { dg-options \"%s-I%s -mno-mmx\" { target i?86-*-* x86_64-*-* } } */\n",
48 "/* { dg-options \"%s-I%s -fno-common\" { target hppa*-*-hpux* powerpc*-*-darwin* *-*-mingw32* *-*-cygwin* } } */\n",
49 "/* { dg-options \"%s-I%s -mno-mmx -fno-common\" { target i?86-*-darwin* x86_64-*-darwin* } } */\n",
50 "/* { dg-options \"%s-I%s -mno-base-addresses\" { target mmix-*-* } } */\n",
51 "/* { dg-options \"%s-I%s -mlongcalls -mtext-section-literals\" { target xtensa*-*-* } } */\n"
52 #define NDG_OPTIONS (sizeof (dg_options) / sizeof (dg_options[0]))
53 };
54
55 typedef unsigned int hashval_t;
56
57 enum TYPE
58 {
59   TYPE_INT,
60   TYPE_UINT,
61   TYPE_CINT,
62   TYPE_CUINT,
63   TYPE_FLOAT,
64   TYPE_CFLOAT,
65   TYPE_DEC_FLOAT,
66   TYPE_SENUM,
67   TYPE_UENUM,
68   TYPE_PTR,
69   TYPE_FNPTR,
70   TYPE_OTHER
71 };
72
73 struct types
74 {
75   const char *name;
76   enum TYPE type;
77   unsigned long long int maxval;
78   char bitfld;
79 };
80
81 struct types base_types[] = {
82 /* As we don't know whether char will be signed or not, just limit ourselves
83    to unsigned values less than maximum signed char value.  */
84 { "char", TYPE_UINT, 127, 'C' },
85 { "signed char", TYPE_INT, 127, 'C' },
86 { "unsigned char", TYPE_UINT, 255, 'C' },
87 { "short int", TYPE_INT, 32767, 'S' },
88 { "unsigned short int", TYPE_UINT, 65535, 'S' },
89 { "int", TYPE_INT, 2147483647, 'I' },
90 { "unsigned int", TYPE_UINT, 4294967295U, 'I' },
91 { "long int", TYPE_INT, 9223372036854775807LL, 'L' },
92 { "unsigned long int", TYPE_UINT, 18446744073709551615ULL, 'L' },
93 { "long long int", TYPE_INT, 9223372036854775807LL, 'Q' },
94 { "unsigned long long int", TYPE_UINT, 18446744073709551615ULL, 'Q' },
95 { "bool", TYPE_UINT, 1, 'B' },
96 { "void *", TYPE_PTR, 0, 0 },
97 { "char *", TYPE_PTR, 0, 0 },
98 { "int *", TYPE_PTR, 0, 0 },
99 { "float", TYPE_FLOAT, 0, 0 },
100 { "double", TYPE_FLOAT, 0, 0 },
101 { "long double", TYPE_FLOAT, 0, 0 },
102 #ifndef SKIP_DECIMAL_FLOAT
103 { "_Decimal32", TYPE_DEC_FLOAT, 0, 0 },
104 { "_Decimal64", TYPE_DEC_FLOAT, 0, 0 },
105 { "_Decimal128", TYPE_DEC_FLOAT, 0, 0 },
106 #define NTYPES1 21
107 #else
108 #define NTYPES1 18
109 #endif
110 { "Tchar", TYPE_UINT, 127, 'C' },
111 { "Tschar", TYPE_INT, 127, 'C' },
112 { "Tuchar", TYPE_UINT, 255, 'C' },
113 { "Tshort", TYPE_INT, 32767, 'S' },
114 { "Tushort", TYPE_UINT, 65535, 'S' },
115 { "Tint", TYPE_INT, 2147483647, 'I' },
116 { "Tuint", TYPE_UINT, 4294967295U, 'I' },
117 { "Tlong", TYPE_INT, 9223372036854775807LL, 'L' },
118 { "Tulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
119 { "Tllong", TYPE_INT, 9223372036854775807LL, 'Q' },
120 { "Tullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
121 { "Tbool", TYPE_UINT, 1, 'B' },
122 { "size_t", TYPE_UINT, 18446744073709551615ULL, 0 },
123 { "Tptr", TYPE_PTR, 0, 0 },
124 { "Tcptr", TYPE_PTR, 0, 0 },
125 { "Tiptr", TYPE_PTR, 0, 0 },
126 { "Tfnptr", TYPE_FNPTR, 0, 0 },
127 { "Tfloat", TYPE_FLOAT, 0, 0 },
128 { "Tdouble", TYPE_FLOAT, 0, 0 },
129 { "Tldouble", TYPE_FLOAT, 0, 0 },
130 #ifndef SKIP_DECIMAL_FLOAT
131 { "TDecimal32", TYPE_DEC_FLOAT, 0, 0 },
132 { "TDecimal64", TYPE_DEC_FLOAT, 0, 0 },
133 { "TDecimal128", TYPE_DEC_FLOAT, 0, 0 },
134 #endif
135 { "enum E0", TYPE_UENUM, 0, ' ' },
136 { "enum E1", TYPE_UENUM, 1, ' ' },
137 { "enum E2", TYPE_SENUM, 3, ' ' },
138 { "enum E3", TYPE_SENUM, 127, ' ' },
139 { "enum E4", TYPE_UENUM, 255, ' ' },
140 { "enum E5", TYPE_SENUM, 32767, ' ' },
141 { "enum E6", TYPE_UENUM, 65535, ' ' },
142 { "enum E7", TYPE_SENUM, 2147483647, ' ' },
143 { "enum E8", TYPE_UENUM, 4294967295U, ' ' },
144 { "enum E9", TYPE_SENUM, 1099511627775LL, ' ' },
145 { "TE0", TYPE_UENUM, 0, ' ' },
146 { "TE1", TYPE_UENUM, 1, ' ' },
147 { "TE2", TYPE_SENUM, 3, ' ' },
148 { "TE3", TYPE_SENUM, 127, ' ' },
149 { "TE4", TYPE_UENUM, 255, ' ' },
150 { "TE5", TYPE_SENUM, 32767, ' ' },
151 { "TE6", TYPE_UENUM, 65535, ' ' },
152 { "TE7", TYPE_SENUM, 2147483647, ' ' },
153 { "TE8", TYPE_UENUM, 4294967295U, ' ' },
154 { "TE9", TYPE_SENUM, 1099511627775LL, ' ' },
155 /* vector-defs.h typedefs */
156 { "qi", TYPE_INT, 127, 0 },
157 { "hi", TYPE_INT, 32767, 0 },
158 { "si", TYPE_INT, 2147483647, 0 },
159 { "di", TYPE_INT, 9223372036854775807LL, 0 },
160 { "sf", TYPE_FLOAT, 0, 0 },
161 { "df", TYPE_FLOAT, 0, 0 }
162 #define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
163 };
164 struct types complex_types[] = {
165 { "_Complex char", TYPE_CUINT, 127, 0 },
166 { "_Complex signed char", TYPE_CINT, 127, 0 },
167 { "_Complex unsigned char", TYPE_CUINT, 255, 0 },
168 { "_Complex short int", TYPE_CINT, 32767, 0 },
169 { "_Complex unsigned short int", TYPE_CUINT, 65535, 0 },
170 { "_Complex int", TYPE_CINT, 2147483647, 0 },
171 { "_Complex unsigned int", TYPE_CUINT, 4294967295U, 0 },
172 { "_Complex long int", TYPE_CINT, 9223372036854775807LL, 0 },
173 { "_Complex unsigned long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
174 { "_Complex long long int", TYPE_CINT, 9223372036854775807LL, 0 },
175 { "_Complex unsigned long long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
176 { "_Complex float", TYPE_CFLOAT, 0, 0 },
177 { "_Complex double", TYPE_CFLOAT, 0, 0 },
178 { "_Complex long double", TYPE_CFLOAT, 0, 0 },
179 { "Tcchar", TYPE_CUINT, 127, 0 },
180 { "Tcschar", TYPE_CINT, 127, 0 },
181 { "Tcuchar", TYPE_CUINT, 255, 0 },
182 { "Tcshort", TYPE_CINT, 32767, 0 },
183 { "Tcushort", TYPE_CUINT, 65535, 0 },
184 { "Tcint", TYPE_CINT, 2147483647, 0 },
185 { "Tcuint", TYPE_CUINT, 4294967295U, 0 },
186 { "Tclong", TYPE_CINT, 9223372036854775807LL, 0 },
187 { "Tculong", TYPE_CUINT, 18446744073709551615ULL, 0 },
188 { "Tcllong", TYPE_CINT, 9223372036854775807LL, 0 },
189 { "Tcullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
190 { "Tcfloat", TYPE_CFLOAT, 0, 0 },
191 { "Tcdouble", TYPE_CFLOAT, 0, 0 },
192 { "Tcldouble", TYPE_CFLOAT, 0, 0 }
193 #define NCTYPES2 (sizeof (complex_types) / sizeof (complex_types[0]))
194 };
195 struct types vector_types[] = {
196 /* vector-defs.h typedefs */
197 { "v8qi", TYPE_OTHER, 0, 0 },
198 { "v16qi", TYPE_OTHER, 0, 0 },
199 { "v32qi", TYPE_OTHER, 0, 0 },
200 { "v2hi", TYPE_OTHER, 0, 0 },
201 { "v4hi", TYPE_OTHER, 0, 0 },
202 { "v8hi", TYPE_OTHER, 0, 0 },
203 { "v16hi", TYPE_OTHER, 0, 0 },
204 { "v2si", TYPE_OTHER, 0, 0 },
205 { "v4si", TYPE_OTHER, 0, 0 },
206 { "v8si", TYPE_OTHER, 0, 0 },
207 { "v1di", TYPE_OTHER, 0, 0 },
208 { "v2di", TYPE_OTHER, 0, 0 },
209 { "v4di", TYPE_OTHER, 0, 0 },
210 { "v2sf", TYPE_OTHER, 0, 0 },
211 { "v4sf", TYPE_OTHER, 0, 0 },
212 { "v8sf", TYPE_OTHER, 0, 0 },
213 { "v16sf", TYPE_OTHER, 0, 0 },
214 { "v2df", TYPE_OTHER, 0, 0 },
215 { "v4df", TYPE_OTHER, 0, 0 },
216 { "u8qi", TYPE_OTHER, 0, 0 },
217 { "u16qi", TYPE_OTHER, 0, 0 },
218 { "u32qi", TYPE_OTHER, 0, 0 },
219 { "u2hi", TYPE_OTHER, 0, 0 },
220 { "u4hi", TYPE_OTHER, 0, 0 },
221 { "u8hi", TYPE_OTHER, 0, 0 },
222 { "u16hi", TYPE_OTHER, 0, 0 },
223 { "u2si", TYPE_OTHER, 0, 0 },
224 { "u4si", TYPE_OTHER, 0, 0 },
225 { "u8si", TYPE_OTHER, 0, 0 },
226 { "u1di", TYPE_OTHER, 0, 0 },
227 { "u2di", TYPE_OTHER, 0, 0 },
228 { "u4di", TYPE_OTHER, 0, 0 },
229 { "u2sf", TYPE_OTHER, 0, 0 },
230 { "u4sf", TYPE_OTHER, 0, 0 },
231 { "u8sf", TYPE_OTHER, 0, 0 },
232 { "u16sf", TYPE_OTHER, 0, 0 },
233 { "u2df", TYPE_OTHER, 0, 0 },
234 { "u4df", TYPE_OTHER, 0, 0 },
235 { "__m64", TYPE_OTHER, 0, 0 },
236 { "__m128", TYPE_OTHER, 0, 0 }
237 #define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
238 };
239 struct types attrib_types[] = {
240 { "Talchar", TYPE_UINT, 127, 'C' },
241 { "Talschar", TYPE_INT, 127, 'C' },
242 { "Taluchar", TYPE_UINT, 255, 'C' },
243 { "Talshort", TYPE_INT, 32767, 'S' },
244 { "Talushort", TYPE_UINT, 65535, 'S' },
245 { "Talint", TYPE_INT, 2147483647, 'I' },
246 { "Taluint", TYPE_UINT, 4294967295U, 'I' },
247 { "Tallong", TYPE_INT, 9223372036854775807LL, 'L' },
248 { "Talulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
249 { "Talllong", TYPE_INT, 9223372036854775807LL, 'Q' },
250 { "Talullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
251 { "Talbool", TYPE_UINT, 1, 'B' },
252 { "Talptr", TYPE_PTR, 0, 0 },
253 { "Talcptr", TYPE_PTR, 0, 0 },
254 { "Taliptr", TYPE_PTR, 0, 0 },
255 { "Talfloat", TYPE_FLOAT, 0, 0 },
256 { "Taldouble", TYPE_FLOAT, 0, 0 },
257 { "Talldouble", TYPE_FLOAT, 0, 0 },
258 #ifndef SKIP_DECIMAL_FLOAT
259 { "TalDecimal32", TYPE_DEC_FLOAT, 0, 0 },
260 { "TalDecimal64", TYPE_DEC_FLOAT, 0, 0 },
261 { "TalDecimal128", TYPE_DEC_FLOAT, 0, 0 },
262 #endif
263 { "TalE0", TYPE_UENUM, 0, ' ' },
264 { "TalE1", TYPE_UENUM, 1, ' ' },
265 { "TalE2", TYPE_SENUM, 3, ' ' },
266 { "TalE3", TYPE_SENUM, 127, ' ' },
267 { "TalE4", TYPE_UENUM, 255, ' ' },
268 { "TalE5", TYPE_SENUM, 32767, ' ' },
269 { "TalE6", TYPE_UENUM, 65535, ' ' },
270 { "TalE7", TYPE_SENUM, 2147483647, ' ' },
271 { "TalE8", TYPE_UENUM, 4294967295U, ' ' },
272 { "TalE9", TYPE_SENUM, 1099511627775LL, ' ' },
273 { "Tal1char", TYPE_UINT, 127, 'C' },
274 { "Tal1schar", TYPE_INT, 127, 'C' },
275 { "Tal1uchar", TYPE_UINT, 255, 'C' },
276 { "Tal1short", TYPE_INT, 32767, 'S' },
277 { "Tal1ushort", TYPE_UINT, 65535, 'S' },
278 { "Tal1int", TYPE_INT, 2147483647, 'I' },
279 { "Tal1uint", TYPE_UINT, 4294967295U, 'I' },
280 { "Tal1long", TYPE_INT, 9223372036854775807LL, 'L' },
281 { "Tal1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
282 { "Tal1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
283 { "Tal1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
284 { "Tal1bool", TYPE_UINT, 1, 'B' },
285 { "Tal1ptr", TYPE_PTR, 0, 0 },
286 { "Tal1cptr", TYPE_PTR, 0, 0 },
287 { "Tal1iptr", TYPE_PTR, 0, 0 },
288 { "Tal1float", TYPE_FLOAT, 0, 0 },
289 { "Tal1double", TYPE_FLOAT, 0, 0 },
290 { "Tal1ldouble", TYPE_FLOAT, 0, 0 },
291 #ifndef SKIP_DECIMAL_FLOAT
292 { "Tal1Decimal32", TYPE_DEC_FLOAT, 0, 0},
293 { "Tal1Decimal64", TYPE_DEC_FLOAT, 0, 0},
294 { "Tal1Decimal128", TYPE_DEC_FLOAT, 0, 0},
295 #endif
296 { "Tal1E0", TYPE_UENUM, 0, ' ' },
297 { "Tal1E1", TYPE_UENUM, 1, ' ' },
298 { "Tal1E2", TYPE_SENUM, 3, ' ' },
299 { "Tal1E3", TYPE_SENUM, 127, ' ' },
300 { "Tal1E4", TYPE_UENUM, 255, ' ' },
301 { "Tal1E5", TYPE_SENUM, 32767, ' ' },
302 { "Tal1E6", TYPE_UENUM, 65535, ' ' },
303 { "Tal1E7", TYPE_SENUM, 2147483647, ' ' },
304 { "Tal1E8", TYPE_UENUM, 4294967295U, ' ' },
305 { "Tal1E9", TYPE_SENUM, 1099511627775LL, ' ' },
306 { "Tal2char", TYPE_UINT, 127, 'C' },
307 { "Tal2schar", TYPE_INT, 127, 'C' },
308 { "Tal2uchar", TYPE_UINT, 255, 'C' },
309 { "Tal2short", TYPE_INT, 32767, 'S' },
310 { "Tal2ushort", TYPE_UINT, 65535, 'S' },
311 { "Tal2int", TYPE_INT, 2147483647, 'I' },
312 { "Tal2uint", TYPE_UINT, 4294967295U, 'I' },
313 { "Tal2long", TYPE_INT, 9223372036854775807LL, 'L' },
314 { "Tal2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
315 { "Tal2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
316 { "Tal2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
317 { "Tal2bool", TYPE_UINT, 1, 'B' },
318 { "Tal2ptr", TYPE_PTR, 0, 0 },
319 { "Tal2cptr", TYPE_PTR, 0, 0 },
320 { "Tal2iptr", TYPE_PTR, 0, 0 },
321 { "Tal2float", TYPE_FLOAT, 0, 0 },
322 { "Tal2double", TYPE_FLOAT, 0, 0 },
323 { "Tal2ldouble", TYPE_FLOAT, 0, 0 },
324 #ifndef SKIP_DECIMAL_FLOAT
325 { "Tal2Decimal32", TYPE_DEC_FLOAT, 0, 0 },
326 { "Tal2Decimal64", TYPE_DEC_FLOAT, 0, 0 },
327 { "Tal2Decimal128", TYPE_DEC_FLOAT, 0, 0 },
328 #endif
329 { "Tal2E0", TYPE_UENUM, 0, ' ' },
330 { "Tal2E1", TYPE_UENUM, 1, ' ' },
331 { "Tal2E2", TYPE_SENUM, 3, ' ' },
332 { "Tal2E3", TYPE_SENUM, 127, ' ' },
333 { "Tal2E4", TYPE_UENUM, 255, ' ' },
334 { "Tal2E5", TYPE_SENUM, 32767, ' ' },
335 { "Tal2E6", TYPE_UENUM, 65535, ' ' },
336 { "Tal2E7", TYPE_SENUM, 2147483647, ' ' },
337 { "Tal2E8", TYPE_UENUM, 4294967295U, ' ' },
338 { "Tal2E9", TYPE_SENUM, 1099511627775LL, ' ' },
339 { "Tal4char", TYPE_UINT, 127, 'C' },
340 { "Tal4schar", TYPE_INT, 127, 'C' },
341 { "Tal4uchar", TYPE_UINT, 255, 'C' },
342 { "Tal4short", TYPE_INT, 32767, 'S' },
343 { "Tal4ushort", TYPE_UINT, 65535, 'S' },
344 { "Tal4int", TYPE_INT, 2147483647, 'I' },
345 { "Tal4uint", TYPE_UINT, 4294967295U, 'I' },
346 { "Tal4long", TYPE_INT, 9223372036854775807LL, 'L' },
347 { "Tal4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
348 { "Tal4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
349 { "Tal4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
350 { "Tal4bool", TYPE_UINT, 1, 'B' },
351 { "Tal4ptr", TYPE_PTR, 0, 0 },
352 { "Tal4cptr", TYPE_PTR, 0, 0 },
353 { "Tal4iptr", TYPE_PTR, 0, 0 },
354 { "Tal4float", TYPE_FLOAT, 0, 0 },
355 { "Tal4double", TYPE_FLOAT, 0, 0 },
356 { "Tal4ldouble", TYPE_FLOAT, 0, 0 },
357 #ifndef SKIP_DECIMAL_FLOAT
358 { "Tal4Decimal32", TYPE_DEC_FLOAT, 0, 0 },
359 { "Tal4Decimal64", TYPE_DEC_FLOAT, 0, 0 },
360 { "Tal4Decimal128", TYPE_DEC_FLOAT, 0, 0 },
361 #endif
362 { "Tal4E0", TYPE_UENUM, 0, ' ' },
363 { "Tal4E1", TYPE_UENUM, 1, ' ' },
364 { "Tal4E2", TYPE_SENUM, 3, ' ' },
365 { "Tal4E3", TYPE_SENUM, 127, ' ' },
366 { "Tal4E4", TYPE_UENUM, 255, ' ' },
367 { "Tal4E5", TYPE_SENUM, 32767, ' ' },
368 { "Tal4E6", TYPE_UENUM, 65535, ' ' },
369 { "Tal4E7", TYPE_SENUM, 2147483647, ' ' },
370 { "Tal4E8", TYPE_UENUM, 4294967295U, ' ' },
371 { "Tal4E9", TYPE_SENUM, 1099511627775LL, ' ' },
372 { "Tal8char", TYPE_UINT, 127, 'C' },
373 { "Tal8schar", TYPE_INT, 127, 'C' },
374 { "Tal8uchar", TYPE_UINT, 255, 'C' },
375 { "Tal8short", TYPE_INT, 32767, 'S' },
376 { "Tal8ushort", TYPE_UINT, 65535, 'S' },
377 { "Tal8int", TYPE_INT, 2147483647, 'I' },
378 { "Tal8uint", TYPE_UINT, 4294967295U, 'I' },
379 { "Tal8long", TYPE_INT, 9223372036854775807LL, 'L' },
380 { "Tal8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
381 { "Tal8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
382 { "Tal8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
383 { "Tal8bool", TYPE_UINT, 1, 'B' },
384 { "Tal8ptr", TYPE_PTR, 0, 0 },
385 { "Tal8cptr", TYPE_PTR, 0, 0 },
386 { "Tal8iptr", TYPE_PTR, 0, 0 },
387 { "Tal8float", TYPE_FLOAT, 0, 0 },
388 { "Tal8double", TYPE_FLOAT, 0, 0 },
389 { "Tal8ldouble", TYPE_FLOAT, 0, 0 },
390 #ifndef SKIP_DECIMAL_FLOAT
391 { "Tal8Decimal32", TYPE_DEC_FLOAT, 0, 0 },
392 { "Tal8Decimal64", TYPE_DEC_FLOAT, 0, 0 },
393 { "Tal8Decimal128", TYPE_DEC_FLOAT, 0, 0 },
394 #endif
395 { "Tal8E0", TYPE_UENUM, 0, ' ' },
396 { "Tal8E1", TYPE_UENUM, 1, ' ' },
397 { "Tal8E2", TYPE_SENUM, 3, ' ' },
398 { "Tal8E3", TYPE_SENUM, 127, ' ' },
399 { "Tal8E4", TYPE_UENUM, 255, ' ' },
400 { "Tal8E5", TYPE_SENUM, 32767, ' ' },
401 { "Tal8E6", TYPE_UENUM, 65535, ' ' },
402 { "Tal8E7", TYPE_SENUM, 2147483647, ' ' },
403 { "Tal8E8", TYPE_UENUM, 4294967295U, ' ' },
404 { "Tal8E9", TYPE_SENUM, 1099511627775LL, ' ' },
405 { "Tal16char", TYPE_UINT, 127, 'C' },
406 { "Tal16schar", TYPE_INT, 127, 'C' },
407 { "Tal16uchar", TYPE_UINT, 255, 'C' },
408 { "Tal16short", TYPE_INT, 32767, 'S' },
409 { "Tal16ushort", TYPE_UINT, 65535, 'S' },
410 { "Tal16int", TYPE_INT, 2147483647, 'I' },
411 { "Tal16uint", TYPE_UINT, 4294967295U, 'I' },
412 { "Tal16long", TYPE_INT, 9223372036854775807LL, 'L' },
413 { "Tal16ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
414 { "Tal16llong", TYPE_INT, 9223372036854775807LL, 'Q' },
415 { "Tal16ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
416 { "Tal16bool", TYPE_UINT, 1, 'B' },
417 { "Tal16ptr", TYPE_PTR, 0, 0 },
418 { "Tal16cptr", TYPE_PTR, 0, 0 },
419 { "Tal16iptr", TYPE_PTR, 0, 0 },
420 { "Tal16float", TYPE_FLOAT, 0, 0 },
421 { "Tal16double", TYPE_FLOAT, 0, 0 },
422 { "Tal16ldouble", TYPE_FLOAT, 0, 0 },
423 #ifndef SKIP_DECIMAL_FLOAT
424 { "Tal16Decimal32", TYPE_DEC_FLOAT, 0, 0 },
425 { "Tal16Decimal64", TYPE_DEC_FLOAT, 0, 0 },
426 { "Tal16Decimal128", TYPE_DEC_FLOAT, 0, 0 },
427 #endif
428 { "Tal16E0", TYPE_UENUM, 0, ' ' },
429 { "Tal16E1", TYPE_UENUM, 1, ' ' },
430 { "Tal16E2", TYPE_SENUM, 3, ' ' },
431 { "Tal16E3", TYPE_SENUM, 127, ' ' },
432 { "Tal16E4", TYPE_UENUM, 255, ' ' },
433 { "Tal16E5", TYPE_SENUM, 32767, ' ' },
434 { "Tal16E6", TYPE_UENUM, 65535, ' ' },
435 { "Tal16E7", TYPE_SENUM, 2147483647, ' ' },
436 { "Tal16E8", TYPE_UENUM, 4294967295U, ' ' },
437 { "Tal16E9", TYPE_SENUM, 1099511627775LL, ' ' }
438 #define NATYPES2 (sizeof (attrib_types) / sizeof (attrib_types[0]))
439 };
440 struct types complex_attrib_types[] = {
441 { "Talcchar", TYPE_CUINT, 127, 0 },
442 { "Talcschar", TYPE_CINT, 127, 0 },
443 { "Talcuchar", TYPE_CUINT, 255, 0 },
444 { "Talcshort", TYPE_CINT, 32767, 0 },
445 { "Talcushort", TYPE_CUINT, 65535, 0 },
446 { "Talcint", TYPE_CINT, 2147483647, 0 },
447 { "Talcuint", TYPE_CUINT, 4294967295U, 0 },
448 { "Talclong", TYPE_CINT, 9223372036854775807LL, 0 },
449 { "Talculong", TYPE_CUINT, 18446744073709551615ULL, 0 },
450 { "Talcllong", TYPE_CINT, 9223372036854775807LL, 0 },
451 { "Talcullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
452 { "Talcfloat", TYPE_CFLOAT, 0, 0 },
453 { "Talcdouble", TYPE_CFLOAT, 0, 0 },
454 { "Talcldouble", TYPE_CFLOAT, 0, 0 },
455 { "Tal1cchar", TYPE_CUINT, 127, 0 },
456 { "Tal1cschar", TYPE_CINT, 127, 0 },
457 { "Tal1cuchar", TYPE_CUINT, 255, 0 },
458 { "Tal1cshort", TYPE_CINT, 32767, 0 },
459 { "Tal1cushort", TYPE_CUINT, 65535, 0 },
460 { "Tal1cint", TYPE_CINT, 2147483647, 0 },
461 { "Tal1cuint", TYPE_CUINT, 4294967295U, 0 },
462 { "Tal1clong", TYPE_CINT, 9223372036854775807LL, 0 },
463 { "Tal1culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
464 { "Tal1cllong", TYPE_CINT, 9223372036854775807LL, 0 },
465 { "Tal1cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
466 { "Tal1cfloat", TYPE_CFLOAT, 0, 0 },
467 { "Tal1cdouble", TYPE_CFLOAT, 0, 0 },
468 { "Tal1cldouble", TYPE_CFLOAT, 0, 0 },
469 { "Tal2cchar", TYPE_CUINT, 127, 0 },
470 { "Tal2cschar", TYPE_CINT, 127, 0 },
471 { "Tal2cuchar", TYPE_CUINT, 255, 0 },
472 { "Tal2cshort", TYPE_CINT, 32767, 0 },
473 { "Tal2cushort", TYPE_CUINT, 65535, 0 },
474 { "Tal2cint", TYPE_CINT, 2147483647, 0 },
475 { "Tal2cuint", TYPE_CUINT, 4294967295U, 0 },
476 { "Tal2clong", TYPE_CINT, 9223372036854775807LL, 0 },
477 { "Tal2culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
478 { "Tal2cllong", TYPE_CINT, 9223372036854775807LL, 0 },
479 { "Tal2cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
480 { "Tal2cfloat", TYPE_CFLOAT, 0, 0 },
481 { "Tal2cdouble", TYPE_CFLOAT, 0, 0 },
482 { "Tal2cldouble", TYPE_CFLOAT, 0, 0 },
483 { "Tal4cchar", TYPE_CUINT, 127, 0 },
484 { "Tal4cschar", TYPE_CINT, 127, 0 },
485 { "Tal4cuchar", TYPE_CUINT, 255, 0 },
486 { "Tal4cshort", TYPE_CINT, 32767, 0 },
487 { "Tal4cushort", TYPE_CUINT, 65535, 0 },
488 { "Tal4cint", TYPE_CINT, 2147483647, 0 },
489 { "Tal4cuint", TYPE_CUINT, 4294967295U, 0 },
490 { "Tal4clong", TYPE_CINT, 9223372036854775807LL, 0 },
491 { "Tal4culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
492 { "Tal4cllong", TYPE_CINT, 9223372036854775807LL, 0 },
493 { "Tal4cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
494 { "Tal4cfloat", TYPE_CFLOAT, 0, 0 },
495 { "Tal4cdouble", TYPE_CFLOAT, 0, 0 },
496 { "Tal4cldouble", TYPE_CFLOAT, 0, 0 },
497 { "Tal8cchar", TYPE_CUINT, 127, 0 },
498 { "Tal8cschar", TYPE_CINT, 127, 0 },
499 { "Tal8cuchar", TYPE_CUINT, 255, 0 },
500 { "Tal8cshort", TYPE_CINT, 32767, 0 },
501 { "Tal8cushort", TYPE_CUINT, 65535, 0 },
502 { "Tal8cint", TYPE_CINT, 2147483647, 0 },
503 { "Tal8cuint", TYPE_CUINT, 4294967295U, 0 },
504 { "Tal8clong", TYPE_CINT, 9223372036854775807LL, 0 },
505 { "Tal8culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
506 { "Tal8cllong", TYPE_CINT, 9223372036854775807LL, 0 },
507 { "Tal8cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
508 { "Tal8cfloat", TYPE_CFLOAT, 0, 0 },
509 { "Tal8cdouble", TYPE_CFLOAT, 0, 0 },
510 { "Tal8cldouble", TYPE_CFLOAT, 0, 0 },
511 { "Tal16cchar", TYPE_CUINT, 127, 0 },
512 { "Tal16cschar", TYPE_CINT, 127, 0 },
513 { "Tal16cuchar", TYPE_CUINT, 255, 0 },
514 { "Tal16cshort", TYPE_CINT, 32767, 0 },
515 { "Tal16cushort", TYPE_CUINT, 65535, 0 },
516 { "Tal16cint", TYPE_CINT, 2147483647, 0 },
517 { "Tal16cuint", TYPE_CUINT, 4294967295U, 0 },
518 { "Tal16clong", TYPE_CINT, 9223372036854775807LL, 0 },
519 { "Tal16culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
520 { "Tal16cllong", TYPE_CINT, 9223372036854775807LL, 0 },
521 { "Tal16cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
522 { "Tal16cfloat", TYPE_CFLOAT, 0, 0 },
523 { "Tal16cdouble", TYPE_CFLOAT, 0, 0 },
524 { "Tal16cldouble", TYPE_CFLOAT, 0, 0 }
525 #define NCATYPES2 (sizeof (complex_attrib_types) / sizeof (complex_attrib_types[0]))
526 };
527 struct types attrib_array_types[] = {
528 { "Talx1char", TYPE_UINT, 127, 'C' },
529 { "Talx1schar", TYPE_INT, 127, 'C' },
530 { "Talx1uchar", TYPE_UINT, 255, 'C' },
531 { "Talx1short", TYPE_INT, 32767, 'S' },
532 { "Talx1ushort", TYPE_UINT, 65535, 'S' },
533 { "Talx1int", TYPE_INT, 2147483647, 'I' },
534 { "Talx1uint", TYPE_UINT, 4294967295U, 'I' },
535 { "Talx1long", TYPE_INT, 9223372036854775807LL, 'L' },
536 { "Talx1ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
537 { "Talx1llong", TYPE_INT, 9223372036854775807LL, 'Q' },
538 { "Talx1ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
539 { "Talx1bool", TYPE_UINT, 1, 'B' },
540 { "Talx1ptr", TYPE_PTR, 0, 0 },
541 { "Talx1cptr", TYPE_PTR, 0, 0 },
542 { "Talx1iptr", TYPE_PTR, 0, 0 },
543 { "Talx1float", TYPE_FLOAT, 0, 0 },
544 { "Talx1double", TYPE_FLOAT, 0, 0 },
545 { "Talx1ldouble", TYPE_FLOAT, 0, 0 },
546 #ifndef SKIP_DECIMAL_FLOAT
547 { "Talx1Decimal32", TYPE_DEC_FLOAT, 0 ,0 },
548 { "Talx1Decimal64", TYPE_DEC_FLOAT, 0 ,0 },
549 { "Talx1Decimal128", TYPE_DEC_FLOAT, 0 ,0 },
550 #endif
551 { "Talx1E0", TYPE_UENUM, 0, ' ' },
552 { "Talx1E1", TYPE_UENUM, 1, ' ' },
553 { "Talx1E2", TYPE_SENUM, 3, ' ' },
554 { "Talx1E3", TYPE_SENUM, 127, ' ' },
555 { "Talx1E4", TYPE_UENUM, 255, ' ' },
556 { "Talx1E5", TYPE_SENUM, 32767, ' ' },
557 { "Talx1E6", TYPE_UENUM, 65535, ' ' },
558 { "Talx1E7", TYPE_SENUM, 2147483647, ' ' },
559 { "Talx1E8", TYPE_UENUM, 4294967295U, ' ' },
560 { "Talx1E9", TYPE_SENUM, 1099511627775LL, ' ' },
561 { "Talx2short", TYPE_INT, 32767, 'S' },
562 { "Talx2ushort", TYPE_UINT, 65535, 'S' },
563 { "Talx2int", TYPE_INT, 2147483647, 'I' },
564 { "Talx2uint", TYPE_UINT, 4294967295U, 'I' },
565 { "Talx2long", TYPE_INT, 9223372036854775807LL, 'L' },
566 { "Talx2ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
567 { "Talx2llong", TYPE_INT, 9223372036854775807LL, 'Q' },
568 { "Talx2ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
569 { "Talx2ptr", TYPE_PTR, 0, 0 },
570 { "Talx2cptr", TYPE_PTR, 0, 0 },
571 { "Talx2iptr", TYPE_PTR, 0, 0 },
572 { "Talx2float", TYPE_FLOAT, 0, 0 },
573 { "Talx2double", TYPE_FLOAT, 0, 0 },
574 { "Talx2ldouble", TYPE_FLOAT, 0, 0 },
575 #ifndef SKIP_DECIMAL_FLOAT
576 { "Talx2Decimal32", TYPE_DEC_FLOAT, 0 , 0 },
577 { "Talx2Decimal64", TYPE_DEC_FLOAT, 0 , 0 },
578 { "Talx2Decimal128", TYPE_DEC_FLOAT, 0 , 0 },
579 #endif
580 { "Talx2E0", TYPE_UENUM, 0, ' ' },
581 { "Talx2E1", TYPE_UENUM, 1, ' ' },
582 { "Talx2E2", TYPE_SENUM, 3, ' ' },
583 { "Talx2E3", TYPE_SENUM, 127, ' ' },
584 { "Talx2E4", TYPE_UENUM, 255, ' ' },
585 { "Talx2E5", TYPE_SENUM, 32767, ' ' },
586 { "Talx2E6", TYPE_UENUM, 65535, ' ' },
587 { "Talx2E7", TYPE_SENUM, 2147483647, ' ' },
588 { "Talx2E8", TYPE_UENUM, 4294967295U, ' ' },
589 { "Talx2E9", TYPE_SENUM, 1099511627775LL, ' ' },
590 { "Talx4int", TYPE_INT, 2147483647, 'I' },
591 { "Talx4uint", TYPE_UINT, 4294967295U, 'I' },
592 { "Talx4long", TYPE_INT, 9223372036854775807LL, 'L' },
593 { "Talx4ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
594 { "Talx4llong", TYPE_INT, 9223372036854775807LL, 'Q' },
595 { "Talx4ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
596 { "Talx4ptr", TYPE_PTR, 0, 0 },
597 { "Talx4cptr", TYPE_PTR, 0, 0 },
598 { "Talx4iptr", TYPE_PTR, 0, 0 },
599 { "Talx4float", TYPE_FLOAT, 0, 0 },
600 { "Talx4double", TYPE_FLOAT, 0, 0 },
601 { "Talx4ldouble", TYPE_FLOAT, 0, 0 },
602 #ifndef SKIP_DECIMAL_FLOAT
603 { "Talx4Decimal32", TYPE_DEC_FLOAT, 0 , 0 },
604 { "Talx4Decimal64", TYPE_DEC_FLOAT, 0 , 0 },
605 { "Talx4Decimal128", TYPE_DEC_FLOAT, 0 , 0 },
606 #endif
607 { "Talx4E0", TYPE_UENUM, 0, ' ' },
608 { "Talx4E1", TYPE_UENUM, 1, ' ' },
609 { "Talx4E2", TYPE_SENUM, 3, ' ' },
610 { "Talx4E3", TYPE_SENUM, 127, ' ' },
611 { "Talx4E4", TYPE_UENUM, 255, ' ' },
612 { "Talx4E5", TYPE_SENUM, 32767, ' ' },
613 { "Talx4E6", TYPE_UENUM, 65535, ' ' },
614 { "Talx4E7", TYPE_SENUM, 2147483647, ' ' },
615 { "Talx4E8", TYPE_UENUM, 4294967295U, ' ' },
616 { "Talx4E9", TYPE_SENUM, 1099511627775LL, ' ' },
617 { "Taly8long", TYPE_INT, 9223372036854775807LL, 'L' },
618 { "Taly8ulong", TYPE_UINT, 18446744073709551615ULL, 'L' },
619 { "Talx8llong", TYPE_INT, 9223372036854775807LL, 'Q' },
620 { "Talx8ullong", TYPE_UINT, 18446744073709551615ULL, 'Q' },
621 { "Taly8ptr", TYPE_PTR, 0, 0 },
622 { "Taly8cptr", TYPE_PTR, 0, 0 },
623 { "Taly8iptr", TYPE_PTR, 0, 0 },
624 { "Talx8double", TYPE_FLOAT, 0, 0 },
625 { "Talx8ldouble", TYPE_FLOAT, 0, 0 },
626 #ifndef SKIP_DECIMAL_FLOAT
627 { "Talx8Decimal64", TYPE_DEC_FLOAT, 0, 0 },
628 { "Talx8Decimal128", TYPE_DEC_FLOAT, 0, 0 }
629 #endif
630 #define NAATYPES2 (sizeof (attrib_array_types) / sizeof (attrib_array_types[0]))
631 };
632 struct types complex_attrib_array_types[] = {
633 { "Talx1cchar", TYPE_CUINT, 127, 0 },
634 { "Talx1cschar", TYPE_CINT, 127, 0 },
635 { "Talx1cuchar", TYPE_CUINT, 255, 0 },
636 { "Talx1cshort", TYPE_CINT, 32767, 0 },
637 { "Talx1cushort", TYPE_CUINT, 65535, 0 },
638 { "Talx1cint", TYPE_CINT, 2147483647, 0 },
639 { "Talx1cuint", TYPE_CUINT, 4294967295U, 0 },
640 { "Talx1clong", TYPE_CINT, 9223372036854775807LL, 0 },
641 { "Talx1culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
642 { "Talx1cllong", TYPE_CINT, 9223372036854775807LL, 0 },
643 { "Talx1cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
644 { "Talx1cfloat", TYPE_CFLOAT, 0, 0 },
645 { "Talx1cdouble", TYPE_CFLOAT, 0, 0 },
646 { "Talx1cldouble", TYPE_CFLOAT, 0, 0 },
647 { "Talx2cchar", TYPE_CUINT, 127, 0 },
648 { "Talx2cschar", TYPE_CINT, 127, 0 },
649 { "Talx2cuchar", TYPE_CUINT, 255, 0 },
650 { "Talx2cshort", TYPE_CINT, 32767, 0 },
651 { "Talx2cushort", TYPE_CUINT, 65535, 0 },
652 { "Talx2cint", TYPE_CINT, 2147483647, 0 },
653 { "Talx2cuint", TYPE_CUINT, 4294967295U, 0 },
654 { "Talx2clong", TYPE_CINT, 9223372036854775807LL, 0 },
655 { "Talx2culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
656 { "Talx2cllong", TYPE_CINT, 9223372036854775807LL, 0 },
657 { "Talx2cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
658 { "Talx2cfloat", TYPE_CFLOAT, 0, 0 },
659 { "Talx2cdouble", TYPE_CFLOAT, 0, 0 },
660 { "Talx2cldouble", TYPE_CFLOAT, 0, 0 },
661 { "Talx4cshort", TYPE_CINT, 32767, 0 },
662 { "Talx4cushort", TYPE_CUINT, 65535, 0 },
663 { "Talx4cint", TYPE_CINT, 2147483647, 0 },
664 { "Talx4cuint", TYPE_CUINT, 4294967295U, 0 },
665 { "Talx4clong", TYPE_CINT, 9223372036854775807LL, 0 },
666 { "Talx4culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
667 { "Talx4cllong", TYPE_CINT, 9223372036854775807LL, 0 },
668 { "Talx4cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
669 { "Talx4cfloat", TYPE_CFLOAT, 0, 0 },
670 { "Talx4cdouble", TYPE_CFLOAT, 0, 0 },
671 { "Talx4cldouble", TYPE_CFLOAT, 0, 0 },
672 { "Talx8cint", TYPE_CINT, 2147483647, 0 },
673 { "Talx8cuint", TYPE_CUINT, 4294967295U, 0 },
674 { "Talx8clong", TYPE_CINT, 9223372036854775807LL, 0 },
675 { "Talx8culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
676 { "Talx8cllong", TYPE_CINT, 9223372036854775807LL, 0 },
677 { "Talx8cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
678 { "Talx8cfloat", TYPE_CFLOAT, 0, 0 },
679 { "Talx8cdouble", TYPE_CFLOAT, 0, 0 },
680 { "Talx8cldouble", TYPE_CFLOAT, 0, 0 },
681 { "Taly16clong", TYPE_CINT, 9223372036854775807LL, 0 },
682 { "Taly16culong", TYPE_CUINT, 18446744073709551615ULL, 0 },
683 { "Talx16cllong", TYPE_CINT, 9223372036854775807LL, 0 },
684 { "Talx16cullong", TYPE_CUINT, 18446744073709551615ULL, 0 },
685 { "Talx16cdouble", TYPE_CFLOAT, 0, 0 },
686 { "Talx16cldouble", TYPE_CFLOAT, 0, 0 }
687 #define NCAATYPES2 (sizeof (complex_attrib_array_types) / sizeof (complex_attrib_array_types[0]))
688 };
689
690 struct types bitfld_types[NTYPES2];
691 int n_bitfld_types;
692 struct types aligned_bitfld_types[NATYPES2];
693 int n_aligned_bitfld_types;
694
695 const char *attributes[] = {
696 "atal", 
697 "atpa", 
698 "atal1", 
699 "atal2", 
700 "atal4", 
701 "atal8", 
702 "atal16", 
703 #define NATTRIBS1 7
704 "atalpa", 
705 "atpaal", 
706 "atal1pa", 
707 "atal2pa", 
708 "atal4pa", 
709 "atal8pa", 
710 "atal16pa", 
711 "atpaal1", 
712 "atpaal2", 
713 "atpaal4", 
714 "atpaal8", 
715 "atpaal16"
716 #define NATTRIBS2 (sizeof (attributes) / sizeof (attributes[0]))
717 };
718
719 enum ETYPE
720 {
721   ETYPE_TYPE,
722   ETYPE_ARRAY,
723   ETYPE_BITFLD,
724   ETYPE_STRUCT,
725   ETYPE_UNION,
726   ETYPE_STRUCT_ARRAY,
727   ETYPE_UNION_ARRAY
728 };
729
730 struct entry
731 {
732 #ifdef __GNUC__
733   enum ETYPE etype : 8;
734 #else
735   unsigned char etype;
736 #endif
737   unsigned short len;
738   unsigned char arr_len;
739   struct types *type;
740   const char *attrib;
741   /* Used to chain together entries in the hash table.  */
742   struct entry *next;
743 };
744
745 /* A prime number giving the number of slots in the hash table.  */ 
746 #define HASH_SIZE 32749 
747 static struct entry *hash_table[HASH_SIZE];
748
749 static int idx, limidx, output_one, short_enums;
750 static const char *destdir;
751 static const char *srcdir;
752 static const char *srcdir_safe;
753 FILE *outfile;
754
755 void
756 switchfiles (int fields)
757 {
758   static int filecnt;
759   static char *destbuf, *destptr;
760   int i;
761
762   ++filecnt;
763   if (outfile)
764     fclose (outfile);
765   if (output_one)
766     {
767       outfile = stdout;
768       return;
769     }
770   if (destbuf == NULL)
771     {
772       size_t len = strlen (destdir);
773       destbuf = malloc (len + 20);
774       if (!destbuf)
775         abort ();
776       memcpy (destbuf, destdir, len);
777       if (!len || destbuf[len - 1] != '/')
778         destbuf[len++] = '/';
779       destptr = destbuf + len;
780     }
781   sprintf (destptr, "t%03d_main.c", filecnt);
782   outfile = fopen (destbuf, "w");
783   if (outfile == NULL)
784     {
785     fail:
786       fputs ("failed to create test files\n", stderr);
787       exit (1);
788     }
789   fprintf (outfile, "/* { dg-require-effective-target int32plus } */\n");
790   for (i = 0; i < NDG_OPTIONS; i++)
791     fprintf (outfile, dg_options[i], "", srcdir_safe);
792   fprintf (outfile, "\
793 #include \"struct-layout-1.h\"\n\
794 \n\
795 #define TX(n, type, attrs, fields, ops) extern void test##n (void);\n\
796 #include \"t%03d_test.h\"\n\
797 #undef TX\n\
798 \n\
799 int main (void)\n\
800 {\n\
801 #define TX(n, type, attrs, fields, ops)   test##n ();\n\
802 #include \"t%03d_test.h\"\n\
803 #undef TX\n\
804   if (fails)\n\
805     {\n\
806       fflush (stdout);\n\
807       abort ();\n\
808     }\n\
809   exit (0);\n\
810 }\n", filecnt, filecnt);
811   fclose (outfile);
812   sprintf (destptr, "t%03d_x.c", filecnt);
813   outfile = fopen (destbuf, "w");
814   if (outfile == NULL)
815     goto fail;
816   for (i = 0; i < NDG_OPTIONS; i++)
817     fprintf (outfile, dg_options[i], "-w ", srcdir_safe);
818   fprintf (outfile, "\
819 #include \"struct-layout-1_x1.h\"\n\
820 #include \"t%03d_test.h\"\n\
821 #include \"struct-layout-1_x2.h\"\n\
822 #include \"t%03d_test.h\"\n", filecnt, filecnt);
823   fclose (outfile);
824   sprintf (destptr, "t%03d_y.c", filecnt);
825   outfile = fopen (destbuf, "w");
826   if (outfile == NULL)
827     goto fail;
828   for (i = 0; i < NDG_OPTIONS; i++)
829     fprintf (outfile, dg_options[i], "-w ", srcdir_safe);
830   fprintf (outfile, "\
831 #include \"struct-layout-1_y1.h\"\n\
832 #include \"t%03d_test.h\"\n\
833 #include \"struct-layout-1_y2.h\"\n\
834 #include \"t%03d_test.h\"\n", filecnt, filecnt);
835   fclose (outfile);
836   sprintf (destptr, "t%03d_test.h", filecnt);
837   outfile = fopen (destbuf, "w");
838   if (outfile == NULL)
839     goto fail;
840   if (fields <= 2)
841     limidx = idx + 300;
842   else if (fields <= 4)
843     limidx = idx + 200;
844   else if (fields <= 6)
845     limidx = idx + 100;
846   else
847     limidx = idx + 50;
848 }
849
850 unsigned long long int
851 getrandll (void)
852 {
853   unsigned long long int ret;
854   ret = generate_random () & 0xffffff;
855   ret |= (generate_random () & 0xffffffLL) << 24;
856   ret |= ((unsigned long long int) generate_random ()) << 48;
857   return ret;
858 }
859
860 int
861 subfield (struct entry *e, char *letter)
862 {
863   int i, type;
864   char buf[20];
865   const char *p;
866   switch (e[0].etype)
867     {
868     case ETYPE_STRUCT:
869     case ETYPE_UNION:
870     case ETYPE_STRUCT_ARRAY:
871     case ETYPE_UNION_ARRAY:
872       type = e[0].attrib ? 1 + (generate_random () & 3) : 0;
873       if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY)
874         p = "struct";
875       else
876         p = "union";
877       if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY)
878         {
879           if (e[0].arr_len == 255)
880             snprintf (buf, 20, "%c[]", *letter);
881           else
882             snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
883           /* If this is an array type, do not put aligned attributes on
884              elements.  Aligning elements to a value greater than their
885              size will result in a compiler error.  */
886           if (type == 1
887               && ((strncmp (e[0].attrib, "atal", 4) == 0)
888                    || strncmp (e[0].attrib, "atpaal", 6) == 0))
889             type = 2;
890         }
891       else
892         {
893           buf[0] = *letter;
894           buf[1] = '\0';
895         }
896       ++*letter;
897       switch (type)
898         {
899         case 0:
900         case 3:
901         case 4:
902           fprintf (outfile, "%s{", p);
903           break;
904         case 1:
905           fprintf (outfile, "%s %s{", e[0].attrib, p);
906           break;
907         case 2:
908           fprintf (outfile, "%s %s{", p, e[0].attrib);
909           break;
910         }
911
912       for (i = 1; i <= e[0].len; )
913         i += subfield (e + i, letter);
914
915       switch (type)
916         {
917         case 0:
918         case 1:
919         case 2:
920           fprintf (outfile, "}%s;", buf);
921           break;
922         case 3:
923           fprintf (outfile, "}%s %s;", e[0].attrib, buf);
924           break;
925         case 4:
926           fprintf (outfile, "}%s %s;", buf, e[0].attrib);
927           break;
928         }
929       return 1 + e[0].len;
930     case ETYPE_TYPE:
931     case ETYPE_ARRAY:
932       if (e[0].etype == ETYPE_ARRAY)
933         {
934           if (e[0].arr_len == 255)
935             snprintf (buf, 20, "%c[]", *letter);
936           else
937             snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
938         }
939       else
940         {
941           buf[0] = *letter;
942           buf[1] = '\0';
943         }
944       ++*letter;
945       if (e[0].attrib)
946         {
947           /* If this is an array type, do not put aligned attributes on
948              elements.  Aligning elements to a value greater than their
949              size will result in a compiler error.  */
950           if (e[0].etype == ETYPE_ARRAY
951               && ((strncmp (e[0].attrib, "atal", 4) == 0)
952                    || strncmp (e[0].attrib, "atpaal", 6) == 0))
953             type = 2;
954           else
955             type = generate_random () % 3;
956           switch (type)
957             {
958             case 0:
959               fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name,
960                        buf);
961               break;
962             case 1:
963               fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib,
964                        buf);
965               break;
966             case 2:
967               fprintf (outfile, "%s %s %s;", e[0].type->name, buf,
968                        e[0].attrib);
969               break;
970             }
971         }
972       else
973         fprintf (outfile, "%s %s;", e[0].type->name, buf);
974       return 1;
975     case ETYPE_BITFLD:
976       if (e[0].len == 0)
977         {
978           if (e[0].attrib)
979             switch (generate_random () % 3)
980               {
981               case 0:
982                 fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name);
983                 break;
984               case 1:
985                 fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib);
986                 break;
987               case 2:
988                 fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib);
989                 break;
990               }
991           else
992             fprintf (outfile, "%s:0;", e[0].type->name);
993           ++*letter;
994           return 1;
995         }
996       switch (e[0].type->bitfld)
997         {
998         case 'C':
999         case 'S':
1000         case 'I':
1001         case 'L':
1002         case 'Q':
1003           snprintf (buf, 20, "B%cN(%d)", e[0].type->bitfld, e[0].len);
1004           break;
1005         case 'B':
1006         case ' ':
1007           snprintf (buf, 20, "%d", e[0].len);
1008           break;
1009         default:
1010           abort ();
1011         }
1012       if (e[0].attrib)
1013         switch (generate_random () % 3)
1014           {
1015           case 0:
1016             fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name,
1017                      *letter, buf);
1018             break;
1019           case 1:
1020             fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib,
1021                      *letter, buf);
1022             break;
1023           case 2:
1024             fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter,
1025                      buf, e[0].attrib);
1026             break;
1027           }
1028       else
1029         fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf);
1030       ++*letter;
1031       return 1;
1032     default:
1033       abort ();
1034   }
1035 }
1036
1037 char namebuf[1024];
1038
1039 void
1040 output_FNB (char mode, struct entry *e)
1041 {
1042   unsigned long long int l1, l2, m;
1043   int signs = 0;
1044 #ifndef SKIP_DECIMAL_FLOAT
1045   int suffix = 0;
1046   char DEC_SUFFIX[3][3]={"DF","DD","DL"};
1047 #endif
1048   
1049   const char *p, *q;
1050
1051   if (e->type->type == TYPE_OTHER)
1052     {
1053       if (mode == 'B')
1054         abort ();
1055       fprintf (outfile, "N(%d,%s)", idx, namebuf);
1056       return;
1057     }
1058   fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf);
1059   l1 = getrandll ();
1060   l2 = getrandll ();
1061   switch (e->type->type)
1062     {
1063     case TYPE_INT:
1064       signs = generate_random () & 3;
1065       m = e->type->maxval;
1066       if (mode == 'B')
1067         m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1;
1068       l1 &= m;
1069       l2 &= m;
1070       fprintf (outfile, "%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s",
1071                (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1072                (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1073       break;
1074     case TYPE_UINT:
1075       m = e->type->maxval;
1076       if (mode == 'B')
1077         m &= (1ULL << e->len) - 1;
1078       l1 &= m;
1079       l2 &= m;
1080       fprintf (outfile, "%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s",
1081                l1, l1 > 4294967295U ? "LL" : "",
1082                l2, l2 > 4294967295U ? "LL" : "");
1083       break;
1084     case TYPE_FLOAT:
1085       l1 &= 0xffffff;
1086       l2 &= 0xffffff;
1087       signs = generate_random () & 3;
1088       fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "",
1089                ((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64);
1090       break;
1091 #ifndef SKIP_DECIMAL_FLOAT
1092     case TYPE_DEC_FLOAT:
1093       l1 &= 0xffffff;
1094       l2 &= 0xffffff;
1095       signs = generate_random () & 3;
1096       
1097       /* Get the suffix of Decimal Floting Points per 
1098          e->type->name.  Distinguish these three DFP types by
1099          e->type->name.  */
1100       if (strstr(e->type->name, "Decimal32")) suffix=0;
1101       else if (strstr(e->type->name, "Decimal64")) suffix=1;
1102       else if (strstr(e->type->name, "Decimal128")) suffix=2;
1103       else
1104         abort ();
1105
1106       /* Formatted input/output specifiers for DFP types have not been
1107          implemented in GLIBC.  %f here used in fprintf is just to 
1108          dump the numbers to outfile.  */
1109       fprintf (outfile, "%s%f%s,%s%f%s", 
1110                (signs & 1) ? "-" : "", ((double) l1) / 64, DEC_SUFFIX[suffix], 
1111                (signs & 2) ? "-" : "", ((double) l2) / 64, DEC_SUFFIX[suffix]);
1112       break;
1113 #endif
1114     case TYPE_CINT:
1115       signs = generate_random () & 3;
1116       l1 &= e->type->maxval;
1117       l2 &= e->type->maxval;
1118       fprintf (outfile,
1119                "CINT(%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s),",
1120                (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1121                (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1122       signs = generate_random () & 3;
1123       l1 = getrandll ();
1124       l2 = getrandll ();
1125       l1 &= e->type->maxval;
1126       l2 &= e->type->maxval;
1127       fprintf (outfile,
1128                "CINT(%s%" COMPAT_PRLL "u%s,%s%" COMPAT_PRLL "u%s)",
1129                (signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
1130                (signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
1131       break;
1132     case TYPE_CUINT:
1133       l1 &= e->type->maxval;
1134       l2 &= e->type->maxval;
1135       fprintf (outfile,
1136                "CINT(%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s),",
1137                l1, l1 > 4294967295U ? "LL" : "",
1138                l2, l2 > 4294967295U ? "LL" : "");
1139       l1 = getrandll ();
1140       l2 = getrandll ();
1141       l1 &= e->type->maxval;
1142       l2 &= e->type->maxval;
1143       fprintf (outfile,
1144                "CINT(%" COMPAT_PRLL "uU%s,%" COMPAT_PRLL "uU%s)",
1145                l1, l1 > 4294967295U ? "LL" : "",
1146                l2, l2 > 4294967295U ? "LL" : "");
1147       break;
1148     case TYPE_CFLOAT:
1149       l1 &= 0xffffff;
1150       l2 &= 0xffffff;
1151       signs = generate_random () & 3;
1152       fprintf (outfile, "CDBL(%s%f,%s%f),",
1153                (signs & 1) ? "-" : "", ((double) l1) / 64,
1154                (signs & 2) ? "-" : "", ((double) l2) / 64);
1155       l1 = getrandll ();
1156       l2 = getrandll ();
1157       l1 &= 0xffffff;
1158       l2 &= 0xffffff;
1159       signs = generate_random () & 3;
1160       fprintf (outfile, "CDBL(%s%f,%s%f)",
1161                (signs & 1) ? "-" : "", ((double) l1) / 64,
1162                (signs & 2) ? "-" : "", ((double) l2) / 64);
1163       break;
1164     case TYPE_UENUM:
1165       if (e->type->maxval == 0)
1166         fputs ("e0_0,e0_0", outfile);
1167       else if (e->type->maxval == 1)
1168         fprintf (outfile, "e1_%" COMPAT_PRLL "d,e1_%" COMPAT_PRLL "d",
1169                  l1 & 1, l2 & 1);
1170       else
1171         {
1172           p = strchr (e->type->name, '\0');
1173           while (--p >= e->type->name && *p >= '0' && *p <= '9');
1174           p++;
1175           l1 %= 7;
1176           l2 %= 7;
1177           if (l1 > 3)
1178             l1 += e->type->maxval - 6;
1179           if (l2 > 3)
1180             l2 += e->type->maxval - 6;
1181           fprintf (outfile, "e%s_%" COMPAT_PRLL "d,e%s_%" COMPAT_PRLL "d",
1182                    p, l1, p, l2);
1183         }
1184       break;
1185     case TYPE_SENUM:
1186       p = strchr (e->type->name, '\0');
1187       while (--p >= e->type->name && *p >= '0' && *p <= '9');
1188       p++;
1189       l1 %= 7;
1190       l2 %= 7;
1191       fprintf (outfile, "e%s_%s%" COMPAT_PRLL "d,e%s_%s%" COMPAT_PRLL "d",
1192                p, l1 < 3 ? "m" : "",
1193                l1 == 3 ? 0LL : e->type->maxval - (l1 & 3),
1194                p, l2 < 3 ? "m" : "",
1195                l2 == 3 ? 0LL : e->type->maxval - (l2 & 3));
1196       break;
1197     case TYPE_PTR:
1198       l1 %= 256;
1199       l2 %= 256;
1200       fprintf (outfile,
1201                "(%s)&intarray[%" COMPAT_PRLL "d], (%s)&intarray[%" COMPAT_PRLL "d]",
1202                e->type->name, l1, e->type->name, l2);
1203       break;
1204     case TYPE_FNPTR:
1205       l1 %= 10;
1206       l2 %= 10;
1207       fprintf (outfile, "fn%" COMPAT_PRLL "d,fn%" COMPAT_PRLL "d", l1, l2);
1208       break;
1209     default:
1210       abort ();
1211     }
1212   fputs (")", outfile);
1213 }
1214
1215 int
1216 subvalues (struct entry *e, char *p, char *letter)
1217 {
1218   int i, j;
1219   char *q;
1220   if (p >= namebuf + sizeof (namebuf) - 32)
1221     abort ();
1222   p[0] = *letter;
1223   p[1] = '\0';
1224   q = p + 1;
1225   switch (e[0].etype)
1226     {
1227     case ETYPE_STRUCT_ARRAY:
1228     case ETYPE_UNION_ARRAY:
1229       if (e[0].arr_len == 0 || e[0].arr_len == 255)
1230         {
1231           *letter += 1 + e[0].len;
1232           return 1 + e[0].len;
1233         }
1234       i = generate_random () % e[0].arr_len;
1235       snprintf (p, sizeof (namebuf) - (p - namebuf) - 1,
1236                 "%c[%d]", *letter, i);
1237       q = strchr (p, '\0');
1238       /* FALLTHROUGH */
1239     case ETYPE_STRUCT:
1240     case ETYPE_UNION:
1241       *q++ = '.';
1242       ++*letter;
1243       for (i = 1; i <= e[0].len; )
1244         {
1245           i += subvalues (e + i, q, letter);
1246           if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY)
1247             {
1248               *letter += e[0].len - i + 1;
1249               break;
1250             }
1251         }
1252       return 1 + e[0].len;
1253     case ETYPE_TYPE:
1254       ++*letter;
1255       output_FNB ('F', e);
1256       return 1;
1257     case ETYPE_ARRAY:
1258       if (e[0].arr_len == 0 || e[0].arr_len == 255)
1259         {
1260           ++*letter;
1261           return 1;
1262         }
1263       i = generate_random () % e[0].arr_len;
1264       snprintf (p, sizeof (namebuf) - (p - namebuf),
1265                 "%c[%d]", *letter, i);
1266       output_FNB ('F', e);
1267       if ((generate_random () & 7) == 0)
1268         {
1269           j = generate_random () % e[0].arr_len;
1270           if (i != j)
1271             {
1272               snprintf (p, sizeof (namebuf) - (p - namebuf),
1273                         "%c[%d]", *letter, j);
1274               output_FNB ('F', e);
1275             }
1276         }
1277       ++*letter;
1278       return 1;
1279     case ETYPE_BITFLD:
1280       ++*letter;
1281       if (e[0].len != 0)
1282         output_FNB ('B', e);
1283       return 1;
1284     }
1285 }
1286
1287 /* DERIVED FROM:
1288 --------------------------------------------------------------------
1289 lookup2.c, by Bob Jenkins, December 1996, Public Domain.
1290 hash(), hash2(), hash3, and mix() are externally useful functions.
1291 Routines to test the hash are included if SELF_TEST is defined.
1292 You can use this free for any purpose.  It has no warranty.
1293 --------------------------------------------------------------------
1294 */
1295
1296 /*
1297 --------------------------------------------------------------------
1298 mix -- mix 3 32-bit values reversibly.
1299 For every delta with one or two bit set, and the deltas of all three
1300   high bits or all three low bits, whether the original value of a,b,c
1301   is almost all zero or is uniformly distributed,
1302 * If mix() is run forward or backward, at least 32 bits in a,b,c
1303   have at least 1/4 probability of changing.
1304 * If mix() is run forward, every bit of c will change between 1/3 and
1305   2/3 of the time.  (Well, 22/100 and 78/100 for some 2-bit deltas.)
1306 mix() was built out of 36 single-cycle latency instructions in a 
1307   structure that could supported 2x parallelism, like so:
1308       a -= b; 
1309       a -= c; x = (c>>13);
1310       b -= c; a ^= x;
1311       b -= a; x = (a<<8);
1312       c -= a; b ^= x;
1313       c -= b; x = (b>>13);
1314       ...
1315   Unfortunately, superscalar Pentiums and Sparcs can't take advantage 
1316   of that parallelism.  They've also turned some of those single-cycle
1317   latency instructions into multi-cycle latency instructions.  Still,
1318   this is the fastest good hash I could find.  There were about 2^^68
1319   to choose from.  I only looked at a billion or so.
1320 --------------------------------------------------------------------
1321 */
1322 /* same, but slower, works on systems that might have 8 byte hashval_t's */
1323 #define mix(a,b,c) \
1324 { \
1325   a -= b; a -= c; a ^= (c>>13); \
1326   b -= c; b -= a; b ^= (a<< 8); \
1327   c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
1328   a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
1329   b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
1330   c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
1331   a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
1332   b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
1333   c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
1334 }
1335
1336 /*
1337 --------------------------------------------------------------------
1338 hash() -- hash a variable-length key into a 32-bit value
1339   k     : the key (the unaligned variable-length array of bytes)
1340   len   : the length of the key, counting by bytes
1341   level : can be any 4-byte value
1342 Returns a 32-bit value.  Every bit of the key affects every bit of
1343 the return value.  Every 1-bit and 2-bit delta achieves avalanche.
1344 About 36+6len instructions.
1345
1346 The best hash table sizes are powers of 2.  There is no need to do
1347 mod a prime (mod is sooo slow!).  If you need less than 32 bits,
1348 use a bitmask.  For example, if you need only 10 bits, do
1349   h = (h & hashmask(10));
1350 In which case, the hash table should have hashsize(10) elements.
1351
1352 If you are hashing n strings (ub1 **)k, do it like this:
1353   for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
1354
1355 By Bob Jenkins, 1996.  bob_jenkins@burtleburtle.net.  You may use this
1356 code any way you wish, private, educational, or commercial.  It's free.
1357
1358 See http://burtleburtle.net/bob/hash/evahash.html
1359 Use for hash table lookup, or anything where one collision in 2^32 is
1360 acceptable.  Do NOT use for cryptographic purposes.
1361 --------------------------------------------------------------------
1362 */
1363
1364 static hashval_t
1365 iterative_hash (const void *k_in /* the key */,
1366                 register size_t  length /* the length of the key */,
1367                 register hashval_t initval /* the previous hash, or
1368                                               an arbitrary value */)
1369 {
1370   register const unsigned char *k = (const unsigned char *)k_in;
1371   register hashval_t a,b,c,len;
1372
1373   /* Set up the internal state */
1374   len = length;
1375   a = b = 0x9e3779b9;  /* the golden ratio; an arbitrary value */
1376   c = initval;           /* the previous hash value */
1377
1378   /*---------------------------------------- handle most of the key */
1379     while (len >= 12)
1380       {
1381         a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24));
1382         b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24));
1383         c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24));
1384         mix(a,b,c);
1385         k += 12; len -= 12;
1386       }
1387
1388   /*------------------------------------- handle the last 11 bytes */
1389   c += length;
1390   switch(len)              /* all the case statements fall through */
1391     {
1392     case 11: c+=((hashval_t)k[10]<<24);
1393     case 10: c+=((hashval_t)k[9]<<16);
1394     case 9 : c+=((hashval_t)k[8]<<8);
1395       /* the first byte of c is reserved for the length */
1396     case 8 : b+=((hashval_t)k[7]<<24);
1397     case 7 : b+=((hashval_t)k[6]<<16);
1398     case 6 : b+=((hashval_t)k[5]<<8);
1399     case 5 : b+=k[4];
1400     case 4 : a+=((hashval_t)k[3]<<24);
1401     case 3 : a+=((hashval_t)k[2]<<16);
1402     case 2 : a+=((hashval_t)k[1]<<8);
1403     case 1 : a+=k[0];
1404       /* case 0: nothing left to add */
1405     }
1406   mix(a,b,c);
1407   /*-------------------------------------------- report the result */
1408   return c;
1409 }
1410
1411 hashval_t
1412 e_hash (const void *a)
1413 {
1414   const struct entry *e = a;
1415   hashval_t ret = 0;
1416   int i;
1417
1418   if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1419     abort ();
1420   for (i = 0; i <= e[0].len; ++i)
1421     {
1422       int attriblen;
1423       ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret);
1424       attriblen = e[i].attrib ? strlen (e[i].attrib) : -1;
1425       ret = iterative_hash (&attriblen, sizeof (int), ret);
1426       if (e[i].attrib)
1427         ret = iterative_hash (e[i].attrib, attriblen, ret);
1428     }
1429   return ret;
1430 }
1431
1432 int
1433 e_eq (const void *a, const void *b)
1434 {
1435   const struct entry *ea = a, *eb = b;
1436   int i;
1437   if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION)
1438     abort ();
1439   if (ea[0].len != eb[0].len)
1440     return 0;
1441   for (i = 0; i <= ea[0].len; ++i)
1442     {
1443       if (ea[i].etype != eb[i].etype
1444           || ea[i].len != eb[i].len
1445           || ea[i].arr_len != eb[i].arr_len
1446           || ea[i].type != eb[i].type)
1447         return 0;
1448       if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL))
1449         return 0;
1450       if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0)
1451         return 0;
1452     }
1453   return 1;
1454 }
1455
1456 static int 
1457 e_exists (const struct entry *e) 
1458 {
1459   struct entry *h;
1460   hashval_t hval;
1461
1462   hval = e_hash (e);
1463   for (h = hash_table[hval % HASH_SIZE]; h; h = h->next)
1464     if (e_eq (e, h))
1465       return 1;
1466   return 0;
1467 }
1468
1469 static void
1470 e_insert (struct entry *e)
1471 {
1472   hashval_t hval;
1473
1474   hval = e_hash (e);
1475   e->next = hash_table[hval % HASH_SIZE];
1476   hash_table[hval % HASH_SIZE] = e;
1477 }
1478
1479 void
1480 output (struct entry *e)
1481 {
1482   int i;
1483   char c;
1484   struct entry *n;
1485   const char *skip_cint = "";
1486
1487   if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
1488     abort ();
1489
1490   if (e_exists (e))
1491     return;
1492
1493   n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry));
1494   memcpy (n, e, (e[0].len + 1) * sizeof (struct entry));
1495   e_insert (n);
1496
1497   if (idx == limidx)
1498     switchfiles (e[0].len);
1499
1500   for (i = 1; i <= e[0].len; ++i)
1501     if ((e[i].etype == ETYPE_TYPE || e[i].etype == ETYPE_ARRAY)
1502         && (e[i].type->type == TYPE_CINT || e[i].type->type == TYPE_CUINT))
1503       break;
1504   if (i <= e[0].len)
1505     skip_cint = "CI";
1506   if (e[0].attrib)
1507     fprintf (outfile, (generate_random () & 1)
1508              ? "TX%s(%d,%s %s,," : "TX%s(%d,%s,%s,", skip_cint,
1509              idx, e[0].etype == ETYPE_STRUCT ? "struct" : "union",
1510              e[0].attrib);
1511   else if (e[0].etype == ETYPE_STRUCT)
1512     fprintf (outfile, "T%s(%d,", skip_cint, idx);
1513   else
1514     fprintf (outfile, "U%s(%d,", skip_cint, idx);
1515   c = 'a';
1516   for (i = 1; i <= e[0].len; )
1517     i += subfield (e + i, &c);
1518   fputs (",", outfile);
1519   c = 'a';
1520   for (i = 1; i <= e[0].len; )
1521     {
1522       i += subvalues (e + i, namebuf, &c);
1523       if (e[0].etype == ETYPE_UNION)
1524         break;
1525     }
1526   fputs (")\n", outfile);
1527   if (output_one && idx == limidx)
1528     exit (0);
1529   ++idx;
1530 }
1531
1532 enum FEATURE
1533 {
1534   FEATURE_VECTOR = 1,
1535   FEATURE_COMPLEX = 2,
1536   FEATURE_ALIGNEDPACKED = 4,
1537   FEATURE_ZEROARRAY = 8,
1538   FEATURE_ZEROBITFLD = 16,
1539   ALL_FEATURES = FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1540                  | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD
1541 };
1542
1543 void
1544 singles (enum FEATURE features)
1545 {
1546   struct entry e[2];
1547   int i;
1548   memset (e, 0, sizeof (e));
1549   e[0].etype = ETYPE_STRUCT;
1550   output (e);
1551   e[0].etype = ETYPE_UNION;
1552   output (e);
1553   for (i = 0;
1554        i < ((features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1);
1555        ++i)
1556     {
1557       e[0].attrib = attributes[i];
1558       e[0].etype = ETYPE_STRUCT;
1559       output (e);
1560       e[0].etype = ETYPE_UNION;
1561       output (e);
1562     }
1563   e[0].len = 1;
1564   e[0].attrib = NULL;
1565   for (i = 0; i < NTYPES2; ++i)
1566     {
1567       e[0].etype = ETYPE_STRUCT;
1568       e[1].etype = ETYPE_TYPE;
1569       e[1].type = &base_types[i];
1570       output (e);
1571       e[0].etype = ETYPE_UNION;
1572       output (e);
1573     }
1574   if (features & FEATURE_COMPLEX)
1575     for (i = 0; i < NCTYPES2; ++i)
1576       {
1577         e[0].etype = ETYPE_STRUCT;
1578         e[1].etype = ETYPE_TYPE;
1579         e[1].type = &complex_types[i];
1580         output (e);
1581         e[0].etype = ETYPE_UNION;
1582         output (e);
1583       }
1584   if (features & FEATURE_VECTOR)
1585     for (i = 0; i < NVTYPES2; ++i)
1586       {
1587         e[0].etype = ETYPE_STRUCT;
1588         e[1].etype = ETYPE_TYPE;
1589         e[1].type = &vector_types[i];
1590         output (e);
1591         e[0].etype = ETYPE_UNION;
1592         output (e);
1593       }
1594 }
1595
1596 void
1597 choose_type (enum FEATURE features, struct entry *e, int r, int in_array)
1598 {
1599   int i;
1600
1601   i = NTYPES2 - NTYPES1;
1602   if (features & FEATURE_COMPLEX)
1603     i += NCTYPES2;
1604   if (features & FEATURE_VECTOR)
1605     i += NVTYPES2;
1606   if ((r & 3) == 0)
1607     {
1608       if (in_array)
1609         {
1610           i += NAATYPES2;
1611           if (features & FEATURE_COMPLEX)
1612             i += NCAATYPES2;
1613         }
1614       else
1615         {
1616           i += NATYPES2;
1617           if (features & FEATURE_COMPLEX)
1618             i += NCATYPES2;
1619         }
1620     }
1621   r >>= 2;
1622   r %= i;
1623   if (r < NTYPES2 - NTYPES1)
1624     e->type = &base_types[r + NTYPES1];
1625   r -= NTYPES2 - NTYPES1;
1626   if (e->type == NULL && (features & FEATURE_COMPLEX))
1627     {
1628       if (r < NCTYPES2)
1629         e->type = &complex_types[r];
1630       r -= NCTYPES2;
1631     }
1632   if (e->type == NULL && (features & FEATURE_VECTOR))
1633     {
1634       if (r < NVTYPES2)
1635         e->type = &vector_types[r];
1636       r -= NVTYPES2;
1637     }
1638   if (e->type == NULL && !in_array)
1639     {
1640       if (r < NATYPES2)
1641         e->type = &attrib_types[r];
1642       r -= NATYPES2;
1643     }
1644   if (e->type == NULL && !in_array && (features & FEATURE_COMPLEX))
1645     {
1646       if (r < NCATYPES2)
1647         e->type = &complex_attrib_types[r];
1648       r -= NCATYPES2;
1649     }
1650   if (e->type == NULL && in_array)
1651     {
1652       if (r < NAATYPES2)
1653         e->type = &attrib_array_types[r];
1654       r -= NAATYPES2;
1655     }
1656   if (e->type == NULL && in_array && (features & FEATURE_COMPLEX))
1657     {
1658       if (r < NCAATYPES2)
1659         e->type = &complex_attrib_array_types[r];
1660       r -= NCAATYPES2;
1661     }
1662   if (e->type == NULL)
1663     abort ();
1664 }
1665
1666 /* This is from gcc.c-torture/execute/builtin-bitops-1.c.  */
1667 static int
1668 my_ffsll (unsigned long long x)
1669 {
1670   int i;
1671   if (x == 0)
1672     return 0;
1673   /* We've tested LLONG_MAX for 64 bits so this should be safe.  */
1674   for (i = 0; i < 64; i++)
1675     if (x & (1ULL << i))
1676       break;
1677   return i + 1;
1678 }
1679
1680 void
1681 generate_fields (enum FEATURE features, struct entry *e, struct entry *parent,
1682                  int len)
1683 {
1684   int r, i, j, ret = 1, n, incr, sametype;
1685
1686   for (n = 0; n < len; n += incr)
1687     {
1688       r = generate_random ();
1689       /* 50% ETYPE_TYPE base_types NTYPES1
1690          12.5% ETYPE_TYPE other
1691          12.5% ETYPE_ARRAY
1692          12.5% ETYPE_BITFLD
1693          12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
1694       i = (r & 7);
1695       r >>= 3;
1696       incr = 1;
1697       switch (i)
1698         {
1699         case 0:
1700         case 1:
1701         case 2:
1702         case 3:
1703           e[n].etype = ETYPE_TYPE;
1704           e[n].type = &base_types[r % NTYPES1];
1705           break;
1706         case 4:
1707           e[n].etype = ETYPE_TYPE;
1708           choose_type (features, &e[n], r, 0);
1709           break;
1710         case 5:
1711           e[n].etype = ETYPE_ARRAY;
1712           i = r & 1;
1713           r >>= 1;
1714           if (i)
1715             e[n].type = &base_types[r % NTYPES1];
1716           else
1717             choose_type (features, &e[n], r, 1);
1718           r = generate_random ();
1719           if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1720             {
1721               e[n].arr_len = 0;
1722               if (n == len - 1 && (r & 4)
1723                   && (parent->etype == ETYPE_STRUCT
1724                       || parent->etype == ETYPE_STRUCT_ARRAY))
1725                 {
1726                   int k;
1727                   for (k = 0; k < n; ++k)
1728                     if (e[k].etype != ETYPE_BITFLD || e[k].len)
1729                       {
1730                         e[n].arr_len = 255;
1731                         break;
1732                       }
1733                 }
1734             }
1735           else if ((r & 3) != 3)
1736             e[n].arr_len = (r >> 2) & 7;
1737           else
1738             e[n].arr_len = (r >> 2) & 31;
1739           break;
1740         case 6:
1741           sametype = 1;
1742           switch (r & 7)
1743             {
1744             case 0:
1745             case 1:
1746             case 2:
1747               break;
1748             case 3:
1749             case 4:
1750             case 5:
1751               incr = 1 + (r >> 3) % (len - n);
1752               break;
1753             case 6:
1754             case 7:
1755               sametype = 0;
1756               incr = 1 + (r >> 3) % (len - n);
1757               break;
1758             }
1759           for (j = n; j < n + incr; ++j)
1760             {
1761               int mi, ma;
1762
1763               e[j].etype = ETYPE_BITFLD;
1764               if (j == n || !sametype)
1765                 {
1766                   int k;
1767                   r = generate_random ();
1768                   k = r & 3;
1769                   r >>= 2;
1770                   if (!k)
1771                     e[j].type
1772                       = &aligned_bitfld_types[r % n_aligned_bitfld_types];
1773                   else
1774                     e[j].type
1775                       = &bitfld_types[r % n_bitfld_types];
1776                 }
1777               else
1778                 e[j].type = e[n].type;
1779               r = generate_random ();
1780               mi = 0;
1781               ma = 0;
1782               switch (e[j].type->bitfld)
1783                 {
1784                 case 'C': ma = 8; break;
1785                 case 'S': ma = 16; break;
1786                 case 'I': ma = 32; break;
1787                 case 'L':
1788                 case 'Q': ma = 64; break;
1789                 case 'B': ma = 1; break;
1790                 case ' ':
1791                   if (e[j].type->type == TYPE_UENUM)
1792                     mi = my_ffsll (e[j].type->maxval + 1) - 1;
1793                   else if (e[j].type->type == TYPE_SENUM)
1794                     mi = my_ffsll (e[j].type->maxval + 1);
1795                   else
1796                     abort ();
1797                   if (!mi)
1798                     mi = 1;
1799                   if (mi > 32)
1800                     ma = 64;
1801                   else if (mi > 16 || !short_enums)
1802                     ma = 32;
1803                   else if (mi > 8)
1804                     ma = 16;
1805                   else
1806                     ma = 8;
1807                   break;
1808                 default:
1809                   abort ();
1810                 }
1811               e[j].len = ma + 1;
1812               if (sametype && (r & 3) == 0 && ma > 1)
1813                 {
1814                   int sum = 0, k;
1815                   for (k = n; k < j; ++k)
1816                     sum += e[k].len;
1817                   sum %= ma;
1818                   e[j].len = sum ? ma - sum : ma;
1819                 }
1820               r >>= 2;
1821               if (! (features & FEATURE_ZEROBITFLD) && mi == 0)
1822                 mi = 1;
1823               if (e[j].len < mi || e[j].len > ma)
1824                 e[j].len = mi + (r % (ma + 1 - mi));
1825               r >>= 6;
1826               if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0
1827                   && mi == 0)
1828                 e[j].len = 0;
1829             }
1830           break;
1831         case 7:
1832           switch (r & 7)
1833             {
1834             case 0:
1835             case 1:
1836             case 2:
1837               e[n].etype = ETYPE_STRUCT;
1838               break;
1839             case 3:
1840             case 4:
1841               e[n].etype = ETYPE_UNION;
1842               break;
1843             case 5:
1844             case 6:
1845               e[n].etype = ETYPE_STRUCT_ARRAY;
1846               break;
1847             case 7:
1848               e[n].etype = ETYPE_UNION_ARRAY;
1849               break;
1850             }
1851           r >>= 3;
1852           e[n].len = r % (len - n);
1853           incr = 1 + e[n].len;
1854           generate_fields (features, &e[n + 1], &e[n], e[n].len);
1855           if (e[n].etype == ETYPE_STRUCT_ARRAY
1856               || e[n].etype == ETYPE_UNION_ARRAY)
1857             {
1858               r = generate_random ();
1859               if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
1860                 {
1861                   e[n].arr_len = 0;
1862                   if (n + incr == len && (r & 4)
1863                       && (parent->etype == ETYPE_STRUCT
1864                           || parent->etype == ETYPE_STRUCT_ARRAY))
1865                     {
1866                       int k;
1867                       for (k = 0; k < n; ++k)
1868                         if (e[k].etype != ETYPE_BITFLD || e[k].len)
1869                           {
1870                             e[n].arr_len = 255;
1871                             break;
1872                           }
1873                     }
1874                 }
1875               else if ((r & 3) != 3)
1876                 e[n].arr_len = (r >> 2) & 7;
1877               else
1878                 e[n].arr_len = (r >> 2) & 31;
1879             }
1880           break;
1881         }
1882       r = generate_random ();
1883       if ((r & 7) == 0)
1884         {
1885           r >>= 3;
1886           i = (features & FEATURE_ALIGNEDPACKED) ? NATTRIBS2 : NATTRIBS1;
1887           e[n].attrib = attributes[r % i];
1888           if (! (features & FEATURE_ALIGNEDPACKED)
1889               && strcmp (e[n].attrib, "atpa") == 0
1890               && ((e[n].type >= &attrib_types[0]
1891                    && e[n].type < &attrib_types[NATYPES2])
1892                   || (e[n].type >= &complex_attrib_types[0]
1893                       && e[n].type < &complex_attrib_types[NCATYPES2])
1894                   || (e[n].type >= &attrib_array_types[0]
1895                       && e[n].type < &attrib_array_types[NAATYPES2])
1896                   || (e[n].type >= &complex_attrib_array_types[0]
1897                       && e[n].type < &complex_attrib_array_types[NAATYPES2])
1898                   || (e[n].type >= &aligned_bitfld_types[0]
1899                       && e[n].type < &aligned_bitfld_types[n_aligned_bitfld_types])))
1900             e[n].attrib = NULL;
1901         }
1902     }
1903 }
1904
1905 void
1906 generate_random_tests (enum FEATURE features, int len)
1907 {
1908   struct entry e[len + 1];
1909   int i, r;
1910   if (len > 'z' - 'a' + 1)
1911     abort ();
1912   memset (e, 0, sizeof (e));
1913   r = generate_random ();
1914   if ((r & 7) == 0)
1915     e[0].etype = ETYPE_UNION;
1916   else
1917     e[0].etype = ETYPE_STRUCT;
1918   r >>= 3;
1919   e[0].len = len;
1920   if ((r & 31) == 0)
1921     {
1922       r >>= 5;
1923       if (features & FEATURE_ALIGNEDPACKED)
1924         r %= NATTRIBS2;
1925       else
1926         r %= NATTRIBS1;
1927       e[0].attrib = attributes[r];
1928     }
1929   generate_fields (features, &e[1], &e[0], len);
1930   output (e);
1931 }
1932
1933 struct { const char *name; enum FEATURE f; }
1934 features[] = {
1935 { "normal", 0 },
1936 { "complex", FEATURE_COMPLEX },
1937 { "vector", FEATURE_VECTOR },
1938 { "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD },
1939 { "complex vector [0]",
1940   FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY },
1941 { "aligned packed complex vector [0] :0",
1942   FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
1943   | FEATURE_ALIGNEDPACKED | FEATURE_ZEROBITFLD },
1944 };
1945
1946 int
1947 main (int argc, char **argv)
1948 {
1949   int i, j, count, c, n = 3000;
1950   char *optarg;
1951
1952   if (sizeof (int) != 4 || sizeof (long long) != 8)
1953     return 1;
1954   
1955   i = 1;
1956   while (i < argc) 
1957     {
1958       c = '\0';
1959       if (argv[i][0] == '-' && argv[i][2] == '\0')
1960         c = argv[i][1];
1961       optarg = argv[i + 1];
1962       if (!optarg)
1963         goto usage;
1964       switch (c)
1965         {
1966         case 'n':
1967           n = atoi (optarg);
1968           break;
1969         case 'd':
1970           destdir = optarg;
1971           break;
1972         case 's':
1973           srcdir = optarg;
1974           break;
1975         case 'i':
1976           output_one = 1;
1977           limidx = atoi (optarg);
1978           break;
1979         case 'e':
1980           short_enums = 1;
1981           i--;
1982           break;
1983         default:
1984           fprintf (stderr, "unrecognized option %s\n", argv[i]);
1985           goto usage;
1986       }
1987       i += 2;
1988     }
1989
1990   if (output_one)
1991     {
1992       outfile = fopen ("/dev/null", "w");
1993       if (outfile == NULL)
1994         {
1995           fputs ("could not open /dev/null", stderr);
1996           return 1;
1997         }
1998       n = limidx + 1;
1999     }
2000
2001   if (destdir == NULL && !output_one)
2002     {
2003     usage:
2004       fprintf (stderr, "Usage:\n\
2005 %s [-e] [-s srcdir -d destdir] [-n count] [-i idx]\n\
2006 Either -s srcdir -d destdir or -i idx must be used\n", argv[0]);
2007       return 1;
2008     }
2009
2010   if (srcdir == NULL && !output_one)
2011     goto usage;
2012
2013   if (srcdir != NULL)
2014     {
2015       const char *s = srcdir;
2016       char *ss, *t;
2017       t = ss = malloc (strlen (srcdir) + 1);
2018       if (!ss)
2019         abort ();
2020       do {
2021         if (*s == '\\')
2022           *t++ = '/';
2023         else
2024           *t++ = *s;
2025       } while (*s++);
2026       srcdir_safe = ss;
2027     }
2028
2029   for (i = 0; i < NTYPES2; ++i)
2030     if (base_types[i].bitfld)
2031       bitfld_types[n_bitfld_types++] = base_types[i];
2032   for (i = 0; i < NATYPES2; ++i)
2033     if (attrib_types[i].bitfld)
2034       aligned_bitfld_types[n_aligned_bitfld_types++] = attrib_types[i];
2035   for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i)
2036     {
2037       int startidx = idx;
2038       if (! output_one)
2039         limidx = idx;
2040       if (!i)
2041         count = 200;
2042       else
2043         count = 20;
2044       for (j = 1; j <= 9; ++j)
2045         while (idx < startidx + j * count)
2046           generate_random_tests (features[i].f, j);
2047       while (idx < startidx + count * 10)
2048         generate_random_tests (features[i].f, 10 + (generate_random () % 16));
2049     }
2050   for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i)
2051     {
2052       int startidx;
2053       startidx = idx;
2054       if (! output_one)
2055         limidx = idx;
2056       singles (features[i].f);
2057       if (!i)
2058         {
2059           count = 1000;
2060           while (idx < startidx + 1000)
2061             generate_random_tests (features[i].f, 1);
2062         }
2063       else
2064         {
2065           startidx = idx;
2066           count = 100;
2067           while (idx < startidx + 100)
2068             generate_random_tests (features[i].f, 1);
2069         }
2070       startidx = idx;
2071       for (j = 2; j <= 9; ++j)
2072         while (idx < startidx + (j - 1) * count)
2073           generate_random_tests (features[i].f, j);
2074       while (idx < startidx + count * 9)
2075         generate_random_tests (features[i].f, 10 + (generate_random () % 16));
2076     }
2077   if (! output_one)
2078     limidx = idx;
2079   while (idx < n)
2080     generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25));
2081   fclose (outfile);
2082   return 0;
2083 }