1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
|
/* Structure layout test generator.
Copyright (C) 2004, 2005, 2007, 2010, 2011 Free Software Foundation, Inc.
Contributed by Jakub Jelinek <jakub@redhat.com>.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under
the terms of the GNU General Public License as published by the Free
Software Foundation; either version 3, or (at your option) any later
version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
for more details.
You should have received a copy of the GNU General Public License
along with GCC; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
/* Compile with gcc -o struct-layout-1_generate{,.c} generate_random{,_r}.c */
/* N.B. -- This program cannot use libiberty as that will not work
when testing an installed compiler. */
#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stddef.h>
/* We use our own pseudo-random number generator, so that it gives the same
values on all hosts. */
#include "generate-random.h"
#if LLONG_MAX != 9223372036854775807LL && __LONG_LONG_MAX__ != 9223372036854775807LL
# error Need 64-bit long long
#endif
typedef unsigned int hashval_t;
enum TYPE
{
TYPE_INT,
TYPE_UINT,
TYPE_CINT,
TYPE_CUINT,
TYPE_FLOAT,
TYPE_CFLOAT,
TYPE_SENUM,
TYPE_UENUM,
TYPE_PTR,
TYPE_FNPTR,
TYPE_OTHER
};
struct types
{
const char *name;
enum TYPE type;
unsigned long long int maxval;
char bitfld;
};
struct types base_types[] = {
/* As we don't know whether char will be signed or not, just limit ourselves
to unsigned values less than maximum signed char value. */
{ "char", TYPE_UINT, 127, 'C' },
{ "signed char", TYPE_INT, 127, 'C' },
{ "unsigned char", TYPE_UINT, 255, 'C' },
{ "short int", TYPE_INT, 32767, 'S' },
{ "unsigned short int", TYPE_UINT, 65535, 'S' },
{ "int", TYPE_INT, 2147483647, 'I' },
{ "unsigned int", TYPE_UINT, 4294967295U, 'I' },
{ "long int", TYPE_INT, 9223372036854775807LL, 'L' },
{ "unsigned long int", TYPE_UINT, 18446744073709551615ULL, 'L' },
{ "long long int", TYPE_INT, 9223372036854775807LL, 'Q' },
{ "unsigned long long int", TYPE_UINT, 18446744073709551615ULL, 'Q' },
{ "bool", TYPE_UINT, 1, 'B' },
{ "void *", TYPE_PTR, 0, 0 },
{ "char *", TYPE_PTR, 0, 0 },
{ "int *", TYPE_PTR, 0, 0 },
{ "float", TYPE_FLOAT, 0, 0 },
{ "double", TYPE_FLOAT, 0, 0 },
/*{ "long double", TYPE_FLOAT, 0, 0 },*/
/* Disabled as double and long double
are encoded thee same, currently */
#define NTYPES1 16
#if 0
/* enums are disabled for now as it seems like their encoding is broken, we should
just encode them using their underlaying type but we don't. */
{ "enum E0", TYPE_UENUM, 0, ' ' },
{ "enum E1", TYPE_UENUM, 1, ' ' },
{ "enum E2", TYPE_SENUM, 3, ' ' },
{ "enum E3", TYPE_SENUM, 127, ' ' },
{ "enum E4", TYPE_UENUM, 255, ' ' },
{ "enum E5", TYPE_SENUM, 32767, ' ' },
{ "enum E6", TYPE_UENUM, 65535, ' ' },
{ "enum E7", TYPE_SENUM, 2147483647, ' ' },
{ "enum E8", TYPE_UENUM, 4294967295U, ' ' },
{ "enum E9", TYPE_SENUM, 1099511627775LL, ' ' },
#endif
#define NTYPES2 (sizeof (base_types) / sizeof (base_types[0]))
};
struct types complex_types[] = {
{ "_Complex char", TYPE_CUINT, 127, 0 },
{ "_Complex signed char", TYPE_CINT, 127, 0 },
{ "_Complex unsigned char", TYPE_CUINT, 255, 0 },
{ "_Complex short int", TYPE_CINT, 32767, 0 },
{ "_Complex unsigned short int", TYPE_CUINT, 65535, 0 },
{ "_Complex int", TYPE_CINT, 2147483647, 0 },
{ "_Complex unsigned int", TYPE_CUINT, 4294967295U, 0 },
{ "_Complex long int", TYPE_CINT, 9223372036854775807LL, 0 },
{ "_Complex unsigned long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
{ "_Complex long long int", TYPE_CINT, 9223372036854775807LL, 0 },
{ "_Complex unsigned long long int", TYPE_CUINT, 18446744073709551615ULL, 0 },
{ "_Complex float", TYPE_CFLOAT, 0, 0 },
{ "_Complex double", TYPE_CFLOAT, 0, 0 },
/*{ "_Complex long double", TYPE_CFLOAT, 0, 0 }, */
/* Disable until long doubles are encoded correctly. */
#define NCTYPES2 (sizeof (complex_types) / sizeof (complex_types[0]))
};
struct types vector_types[] = {
/* vector-defs.h typedefs */
{ "v8qi", TYPE_OTHER, 0, 0 },
{ "v16qi", TYPE_OTHER, 0, 0 },
{ "v2hi", TYPE_OTHER, 0, 0 },
{ "v4hi", TYPE_OTHER, 0, 0 },
{ "v8hi", TYPE_OTHER, 0, 0 },
{ "v2si", TYPE_OTHER, 0, 0 },
{ "v4si", TYPE_OTHER, 0, 0 },
{ "v1di", TYPE_OTHER, 0, 0 },
{ "v2di", TYPE_OTHER, 0, 0 },
{ "v2sf", TYPE_OTHER, 0, 0 },
{ "v4sf", TYPE_OTHER, 0, 0 },
{ "v16sf", TYPE_OTHER, 0, 0 },
{ "v2df", TYPE_OTHER, 0, 0 },
{ "u8qi", TYPE_OTHER, 0, 0 },
{ "u16qi", TYPE_OTHER, 0, 0 },
{ "u2hi", TYPE_OTHER, 0, 0 },
{ "u4hi", TYPE_OTHER, 0, 0 },
{ "u8hi", TYPE_OTHER, 0, 0 },
{ "u2si", TYPE_OTHER, 0, 0 },
{ "u4si", TYPE_OTHER, 0, 0 },
{ "u1di", TYPE_OTHER, 0, 0 },
{ "u2di", TYPE_OTHER, 0, 0 },
{ "u2sf", TYPE_OTHER, 0, 0 },
{ "u4sf", TYPE_OTHER, 0, 0 },
{ "u16sf", TYPE_OTHER, 0, 0 },
{ "u2df", TYPE_OTHER, 0, 0 },
{ "__m64", TYPE_OTHER, 0, 0 },
{ "__m128", TYPE_OTHER, 0, 0 }
#define NVTYPES2 (sizeof (vector_types) / sizeof (vector_types[0]))
};
struct types bitfld_types[NTYPES2];
int n_bitfld_types;
enum ETYPE
{
ETYPE_TYPE,
ETYPE_ARRAY,
ETYPE_BITFLD,
ETYPE_STRUCT,
ETYPE_UNION,
ETYPE_STRUCT_ARRAY,
ETYPE_UNION_ARRAY
};
struct entry
{
#ifdef __GNUC__
enum ETYPE etype : 8;
#else
unsigned char etype;
#endif
unsigned short len;
unsigned char arr_len;
struct types *type;
const char *attrib;
/* Used to chain together entries in the hash table. */
struct entry *next;
};
/* A prime number giving the number of slots in the hash table. */
#define HASH_SIZE 32749
static struct entry *hash_table[HASH_SIZE];
static int idx, limidx, output_one;
static const char *destdir;
static const char *srcdir;
FILE *outfile;
void
switchfiles (int fields)
{
static int filecnt;
static char *destbuf, *destptr;
++filecnt;
if (outfile)
fclose (outfile);
if (output_one)
{
outfile = stdout;
return;
}
if (destbuf == NULL)
{
size_t len = strlen (destdir);
destbuf = malloc (len + 20);
if (!destbuf)
abort ();
memcpy (destbuf, destdir, len);
if (!len || destbuf[len - 1] != '/')
destbuf[len++] = '/';
destptr = destbuf + len;
}
sprintf (destptr, "t%03d_main.m", filecnt);
outfile = fopen (destbuf, "w");
if (outfile == NULL)
{
fail:
fputs ("failed to create test files\n", stderr);
exit (1);
}
/* FIXME: these tests should not be xfailed on aix but they are because
libobjc uses GCC's headers for trying to find the struct layout but it
gets it wrong. */
if (filecnt == 2
|| filecnt == 3
|| filecnt == 4
|| filecnt == 6
|| filecnt == 7
|| filecnt == 8
|| filecnt == 11
|| filecnt == 12
|| filecnt == 15
|| filecnt == 22)
{
fprintf (outfile, "\
/* { dg-do run { xfail { powerpc*-*-aix* } } } */\n\
/* { dg-options \"-w -I%s -fgnu-runtime\" } */\n", srcdir);
}
/* FIXME: these should not be xfailed but they are because
of bugs in libobjc and the objc front-end. 25 is because
vectors are not encoded. The rest are because or zero sized
arrays are encoded as pointers. See PR objc/25361. */
else if (filecnt == 25 || (filecnt >= 27 && filecnt <= 29))
{
fprintf (outfile, "\
/* { dg-do run { xfail { { i?86-*-* x86_64-*-* } || { powerpc*-apple-darwin* && ilp32 } } } } */\n\
/* { dg-options \"-w -I%s -fgnu-runtime\" } */\n", srcdir);
}
else if (filecnt >= 30)
{
fprintf (outfile, "\
/* { dg-do run { xfail { i?86-*-* x86_64-*-* } } } */\n\
/* { dg-options \"-w -I%s -fgnu-runtime\" } */\n", srcdir);
}
else
{
fprintf (outfile, "\
/* { dg-do run } */\n\
/* { dg-options \"-w -I%s -fgnu-runtime\" } */\n", srcdir);
}
fprintf(outfile, "#include <objc/encoding.h> \n\
#include \"struct-layout-1.h\"\n\
\n\
int fails; \n\
#define TX(n, type, attrs, fields, ops) \\\n\
type S##n { fields } attrs; \\\n\
void test##n (void) \\\n\
{ \\\n\
char *encoding = @encode (type S##n); \\\n\
if (objc_sizeof_type (encoding) != sizeof(type S##n)) \\\n\
{ \\\n\
fails ++; \\\n\
printf(#type \" { \" #fields \"} size is %%u, but is calulated as %%u\\n\", \\\n\
sizeof(type S##n), objc_sizeof_type (encoding)); \\\n\
} \\\n\
if (objc_alignof_type (encoding) != __alignof__ (type S##n)) \\\n\
{ \\\n\
fails ++; \\\n\
printf(#type \" { \" #fields \"} align is %%u, but is calulated as %%u\\n\", \\\n\
__alignof__ (type S##n), objc_alignof_type (encoding)); \\\n\
} \\\n\
}\n\
#include \"t%03d_test.h\"\n\
#undef TX\n\
\n\
int main (void)\n\
{\n\
#define TX(n, type, attrs, fields, ops) test##n ();\n\
#include \"t%03d_test.h\"\n\
#undef TX\n\
if (fails)\n\
{\n\
fflush (stdout);\n\
abort ();\n\
}\n\
exit (0);\n\
}\n", filecnt, filecnt);
fclose (outfile);
sprintf (destptr, "t%03d_test.h", filecnt);
outfile = fopen (destbuf, "w");
if (outfile == NULL)
goto fail;
if (fields <= 2)
limidx = idx + 300;
else if (fields <= 4)
limidx = idx + 200;
else if (fields <= 6)
limidx = idx + 100;
else
limidx = idx + 50;
}
unsigned long long int
getrandll (void)
{
unsigned long long int ret;
ret = generate_random () & 0xffffff;
ret |= (generate_random () & 0xffffffLL) << 24;
ret |= ((unsigned long long int) generate_random ()) << 48;
return ret;
}
int
subfield (struct entry *e, char *letter)
{
int i, type;
char buf[20];
const char *p;
switch (e[0].etype)
{
case ETYPE_STRUCT:
case ETYPE_UNION:
case ETYPE_STRUCT_ARRAY:
case ETYPE_UNION_ARRAY:
type = e[0].attrib ? 1 + (generate_random () & 3) : 0;
if (e[0].etype == ETYPE_STRUCT || e[0].etype == ETYPE_STRUCT_ARRAY)
p = "struct";
else
p = "union";
if (e[0].etype == ETYPE_STRUCT_ARRAY || e[0].etype == ETYPE_UNION_ARRAY)
{
if (e[0].arr_len == 255)
snprintf (buf, 20, "%c[]", *letter);
else
snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
}
else
{
buf[0] = *letter;
buf[1] = '\0';
}
++*letter;
switch (type)
{
case 0:
case 3:
case 4:
fprintf (outfile, "%s{", p);
break;
case 1:
fprintf (outfile, "%s %s{", e[0].attrib, p);
break;
case 2:
fprintf (outfile, "%s %s{", p, e[0].attrib);
break;
}
for (i = 1; i <= e[0].len; )
i += subfield (e + i, letter);
switch (type)
{
case 0:
case 1:
case 2:
fprintf (outfile, "}%s;", buf);
break;
case 3:
fprintf (outfile, "}%s %s;", e[0].attrib, buf);
break;
case 4:
fprintf (outfile, "}%s %s;", buf, e[0].attrib);
break;
}
return 1 + e[0].len;
case ETYPE_TYPE:
case ETYPE_ARRAY:
if (e[0].etype == ETYPE_ARRAY)
{
if (e[0].arr_len == 255)
snprintf (buf, 20, "%c[]", *letter);
else
snprintf (buf, 20, "%c[%d]", *letter, e[0].arr_len);
}
else
{
buf[0] = *letter;
buf[1] = '\0';
}
++*letter;
if (e[0].attrib)
switch (generate_random () % 3)
{
case 0:
fprintf (outfile, "%s %s %s;", e[0].attrib, e[0].type->name, buf);
break;
case 1:
fprintf (outfile, "%s %s %s;", e[0].type->name, e[0].attrib, buf);
break;
case 2:
fprintf (outfile, "%s %s %s;", e[0].type->name, buf, e[0].attrib);
break;
}
else
fprintf (outfile, "%s %s;", e[0].type->name, buf);
return 1;
case ETYPE_BITFLD:
if (e[0].len == 0)
{
if (e[0].attrib)
switch (generate_random () % 3)
{
case 0:
fprintf (outfile, "%s %s:0;", e[0].attrib, e[0].type->name);
break;
case 1:
fprintf (outfile, "%s %s:0;", e[0].type->name, e[0].attrib);
break;
case 2:
fprintf (outfile, "%s:0 %s;", e[0].type->name, e[0].attrib);
break;
}
else
fprintf (outfile, "%s:0;", e[0].type->name);
++*letter;
return 1;
}
switch (e[0].type->bitfld)
{
case 'C':
case 'S':
case 'I':
case 'L':
case 'Q':
snprintf (buf, 20, "B%cN(%d)", e[0].type->bitfld, e[0].len);
break;
case 'B':
case ' ':
snprintf (buf, 20, "%d", e[0].len);
break;
default:
abort ();
}
if (e[0].attrib)
switch (generate_random () % 3)
{
case 0:
fprintf (outfile, "%s %s %c:%s;", e[0].attrib, e[0].type->name,
*letter, buf);
break;
case 1:
fprintf (outfile, "%s %s %c:%s;", e[0].type->name, e[0].attrib,
*letter, buf);
break;
case 2:
fprintf (outfile, "%s %c:%s %s;", e[0].type->name, *letter,
buf, e[0].attrib);
break;
}
else
fprintf (outfile, "%s %c:%s;", e[0].type->name, *letter, buf);
++*letter;
return 1;
default:
abort ();
}
}
char namebuf[1024];
void
output_FNB (char mode, struct entry *e)
{
unsigned long long int l1, l2, m;
int signs = 0;
const char *p, *q;
if (e->type->type == TYPE_OTHER)
{
if (mode == 'B')
abort ();
fprintf (outfile, "N(%d,%s)", idx, namebuf);
return;
}
fprintf (outfile, "%c(%d,%s,", mode, idx, namebuf);
l1 = getrandll ();
l2 = getrandll ();
switch (e->type->type)
{
case TYPE_INT:
signs = generate_random () & 3;
m = e->type->maxval;
if (mode == 'B')
m &= e->len > 1 ? (1ULL << (e->len - 1)) - 1 : 1;
l1 &= m;
l2 &= m;
fprintf (outfile, "%s%llu%s,%s%llu%s",
(signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
(signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
break;
case TYPE_UINT:
m = e->type->maxval;
if (mode == 'B')
m &= (1ULL << e->len) - 1;
l1 &= m;
l2 &= m;
fprintf (outfile, "%lluU%s,%lluU%s", l1, l1 > 4294967295U ? "LL" : "",
l2, l2 > 4294967295U ? "LL" : "");
break;
case TYPE_FLOAT:
l1 &= 0xffffff;
l2 &= 0xffffff;
signs = generate_random () & 3;
fprintf (outfile, "%s%f,%s%f", (signs & 1) ? "-" : "",
((double) l1) / 64, (signs & 2) ? "-" : "", ((double) l2) / 64);
break;
case TYPE_CINT:
signs = generate_random () & 3;
l1 &= e->type->maxval;
l2 &= e->type->maxval;
fprintf (outfile, "CINT(%s%llu%s,%s%llu%s),",
(signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
(signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
signs = generate_random () & 3;
l1 = getrandll ();
l2 = getrandll ();
l1 &= e->type->maxval;
l2 &= e->type->maxval;
fprintf (outfile, "CINT(%s%llu%s,%s%llu%s)",
(signs & 1) ? "-" : "", l1, l1 > 2147483647 ? "LL" : "",
(signs & 2) ? "-" : "", l2, l2 > 2147483647 ? "LL" : "");
break;
case TYPE_CUINT:
l1 &= e->type->maxval;
l2 &= e->type->maxval;
fprintf (outfile, "CINT(%lluU%s,%lluU%s),",
l1, l1 > 4294967295U ? "LL" : "",
l2, l2 > 4294967295U ? "LL" : "");
l1 = getrandll ();
l2 = getrandll ();
l1 &= e->type->maxval;
l2 &= e->type->maxval;
fprintf (outfile, "CINT(%lluU%s,%lluU%s)",
l1, l1 > 4294967295U ? "LL" : "",
l2, l2 > 4294967295U ? "LL" : "");
break;
case TYPE_CFLOAT:
l1 &= 0xffffff;
l2 &= 0xffffff;
signs = generate_random () & 3;
fprintf (outfile, "CDBL(%s%f,%s%f),",
(signs & 1) ? "-" : "", ((double) l1) / 64,
(signs & 2) ? "-" : "", ((double) l2) / 64);
l1 = getrandll ();
l2 = getrandll ();
l1 &= 0xffffff;
l2 &= 0xffffff;
signs = generate_random () & 3;
fprintf (outfile, "CDBL(%s%f,%s%f)",
(signs & 1) ? "-" : "", ((double) l1) / 64,
(signs & 2) ? "-" : "", ((double) l2) / 64);
break;
case TYPE_UENUM:
if (e->type->maxval == 0)
fputs ("e0_0,e0_0", outfile);
else if (e->type->maxval == 1)
fprintf (outfile, "e1_%lld,e1_%lld", l1 & 1, l2 & 1);
else
{
p = strchr (e->type->name, '\0');
while (--p >= e->type->name && *p >= '0' && *p <= '9');
p++;
l1 %= 7;
l2 %= 7;
if (l1 > 3)
l1 += e->type->maxval - 6;
if (l2 > 3)
l2 += e->type->maxval - 6;
fprintf (outfile, "e%s_%lld,e%s_%lld", p, l1, p, l2);
}
break;
case TYPE_SENUM:
p = strchr (e->type->name, '\0');
while (--p >= e->type->name && *p >= '0' && *p <= '9');
p++;
l1 %= 7;
l2 %= 7;
fprintf (outfile, "e%s_%s%lld,e%s_%s%lld",
p, l1 < 3 ? "m" : "",
l1 == 3 ? 0LL : e->type->maxval - (l1 & 3),
p, l2 < 3 ? "m" : "",
l2 == 3 ? 0LL : e->type->maxval - (l2 & 3));
break;
case TYPE_PTR:
l1 %= 256;
l2 %= 256;
fprintf (outfile, "(%s)&intarray[%lld],(%s)&intarray[%lld]",
e->type->name, l1, e->type->name, l2);
break;
case TYPE_FNPTR:
l1 %= 10;
l2 %= 10;
fprintf (outfile, "fn%lld,fn%lld", l1, l2);
break;
default:
abort ();
}
fputs (")", outfile);
}
int
subvalues (struct entry *e, char *p, char *letter)
{
int i, j;
char *q;
if (p >= namebuf + sizeof (namebuf) - 32)
abort ();
p[0] = *letter;
p[1] = '\0';
q = p + 1;
switch (e[0].etype)
{
case ETYPE_STRUCT_ARRAY:
case ETYPE_UNION_ARRAY:
if (e[0].arr_len == 0 || e[0].arr_len == 255)
{
*letter += 1 + e[0].len;
return 1 + e[0].len;
}
i = generate_random () % e[0].arr_len;
snprintf (p, sizeof (namebuf) - (p - namebuf) - 1,
"%c[%d]", *letter, i);
q = strchr (p, '\0');
/* FALLTHROUGH */
case ETYPE_STRUCT:
case ETYPE_UNION:
*q++ = '.';
++*letter;
for (i = 1; i <= e[0].len; )
{
i += subvalues (e + i, q, letter);
if (e[0].etype == ETYPE_UNION || e[0].etype == ETYPE_UNION_ARRAY)
{
*letter += e[0].len - i + 1;
break;
}
}
return 1 + e[0].len;
case ETYPE_TYPE:
++*letter;
output_FNB ('F', e);
return 1;
case ETYPE_ARRAY:
if (e[0].arr_len == 0 || e[0].arr_len == 255)
{
++*letter;
return 1;
}
i = generate_random () % e[0].arr_len;
snprintf (p, sizeof (namebuf) - (p - namebuf),
"%c[%d]", *letter, i);
output_FNB ('F', e);
if ((generate_random () & 7) == 0)
{
j = generate_random () % e[0].arr_len;
if (i != j)
{
snprintf (p, sizeof (namebuf) - (p - namebuf),
"%c[%d]", *letter, j);
output_FNB ('F', e);
}
}
++*letter;
return 1;
case ETYPE_BITFLD:
++*letter;
if (e[0].len != 0)
output_FNB ('B', e);
return 1;
}
}
/* DERIVED FROM:
--------------------------------------------------------------------
lookup2.c, by Bob Jenkins, December 1996, Public Domain.
hash(), hash2(), hash3, and mix() are externally useful functions.
Routines to test the hash are included if SELF_TEST is defined.
You can use this free for any purpose. It has no warranty.
--------------------------------------------------------------------
*/
/*
--------------------------------------------------------------------
mix -- mix 3 32-bit values reversibly.
For every delta with one or two bit set, and the deltas of all three
high bits or all three low bits, whether the original value of a,b,c
is almost all zero or is uniformly distributed,
* If mix() is run forward or backward, at least 32 bits in a,b,c
have at least 1/4 probability of changing.
* If mix() is run forward, every bit of c will change between 1/3 and
2/3 of the time. (Well, 22/100 and 78/100 for some 2-bit deltas.)
mix() was built out of 36 single-cycle latency instructions in a
structure that could supported 2x parallelism, like so:
a -= b;
a -= c; x = (c>>13);
b -= c; a ^= x;
b -= a; x = (a<<8);
c -= a; b ^= x;
c -= b; x = (b>>13);
...
Unfortunately, superscalar Pentiums and Sparcs can't take advantage
of that parallelism. They've also turned some of those single-cycle
latency instructions into multi-cycle latency instructions. Still,
this is the fastest good hash I could find. There were about 2^^68
to choose from. I only looked at a billion or so.
--------------------------------------------------------------------
*/
/* same, but slower, works on systems that might have 8 byte hashval_t's */
#define mix(a,b,c) \
{ \
a -= b; a -= c; a ^= (c>>13); \
b -= c; b -= a; b ^= (a<< 8); \
c -= a; c -= b; c ^= ((b&0xffffffff)>>13); \
a -= b; a -= c; a ^= ((c&0xffffffff)>>12); \
b -= c; b -= a; b = (b ^ (a<<16)) & 0xffffffff; \
c -= a; c -= b; c = (c ^ (b>> 5)) & 0xffffffff; \
a -= b; a -= c; a = (a ^ (c>> 3)) & 0xffffffff; \
b -= c; b -= a; b = (b ^ (a<<10)) & 0xffffffff; \
c -= a; c -= b; c = (c ^ (b>>15)) & 0xffffffff; \
}
/*
--------------------------------------------------------------------
hash() -- hash a variable-length key into a 32-bit value
k : the key (the unaligned variable-length array of bytes)
len : the length of the key, counting by bytes
level : can be any 4-byte value
Returns a 32-bit value. Every bit of the key affects every bit of
the return value. Every 1-bit and 2-bit delta achieves avalanche.
About 36+6len instructions.
The best hash table sizes are powers of 2. There is no need to do
mod a prime (mod is sooo slow!). If you need less than 32 bits,
use a bitmask. For example, if you need only 10 bits, do
h = (h & hashmask(10));
In which case, the hash table should have hashsize(10) elements.
If you are hashing n strings (ub1 **)k, do it like this:
for (i=0, h=0; i<n; ++i) h = hash( k[i], len[i], h);
By Bob Jenkins, 1996. bob_jenkins@burtleburtle.net. You may use this
code any way you wish, private, educational, or commercial. It's free.
See http://burtleburtle.net/bob/hash/evahash.html
Use for hash table lookup, or anything where one collision in 2^32 is
acceptable. Do NOT use for cryptographic purposes.
--------------------------------------------------------------------
*/
static hashval_t
iterative_hash (const void *k_in /* the key */,
register size_t length /* the length of the key */,
register hashval_t initval /* the previous hash, or
an arbitrary value */)
{
register const unsigned char *k = (const unsigned char *)k_in;
register hashval_t a,b,c,len;
/* Set up the internal state */
len = length;
a = b = 0x9e3779b9; /* the golden ratio; an arbitrary value */
c = initval; /* the previous hash value */
/*---------------------------------------- handle most of the key */
while (len >= 12)
{
a += (k[0] +((hashval_t)k[1]<<8) +((hashval_t)k[2]<<16) +((hashval_t)k[3]<<24));
b += (k[4] +((hashval_t)k[5]<<8) +((hashval_t)k[6]<<16) +((hashval_t)k[7]<<24));
c += (k[8] +((hashval_t)k[9]<<8) +((hashval_t)k[10]<<16)+((hashval_t)k[11]<<24));
mix(a,b,c);
k += 12; len -= 12;
}
/*------------------------------------- handle the last 11 bytes */
c += length;
switch(len) /* all the case statements fall through */
{
case 11: c+=((hashval_t)k[10]<<24);
case 10: c+=((hashval_t)k[9]<<16);
case 9 : c+=((hashval_t)k[8]<<8);
/* the first byte of c is reserved for the length */
case 8 : b+=((hashval_t)k[7]<<24);
case 7 : b+=((hashval_t)k[6]<<16);
case 6 : b+=((hashval_t)k[5]<<8);
case 5 : b+=k[4];
case 4 : a+=((hashval_t)k[3]<<24);
case 3 : a+=((hashval_t)k[2]<<16);
case 2 : a+=((hashval_t)k[1]<<8);
case 1 : a+=k[0];
/* case 0: nothing left to add */
}
mix(a,b,c);
/*-------------------------------------------- report the result */
return c;
}
hashval_t
e_hash (const void *a)
{
const struct entry *e = a;
hashval_t ret = 0;
int i;
if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
abort ();
for (i = 0; i <= e[0].len; ++i)
{
int attriblen;
ret = iterative_hash (&e[i], offsetof (struct entry, attrib), ret);
attriblen = e[i].attrib ? strlen (e[i].attrib) : -1;
ret = iterative_hash (&attriblen, sizeof (int), ret);
if (e[i].attrib)
ret = iterative_hash (e[i].attrib, attriblen, ret);
}
return ret;
}
int
e_eq (const void *a, const void *b)
{
const struct entry *ea = a, *eb = b;
int i;
if (ea[0].etype != ETYPE_STRUCT && ea[0].etype != ETYPE_UNION)
abort ();
if (ea[0].len != eb[0].len)
return 0;
for (i = 0; i <= ea[0].len; ++i)
{
if (ea[i].etype != eb[i].etype
|| ea[i].len != eb[i].len
|| ea[i].arr_len != eb[i].arr_len
|| ea[i].type != eb[i].type)
return 0;
if ((ea[i].attrib == NULL) ^ (eb[i].attrib == NULL))
return 0;
if (ea[i].attrib && strcmp (ea[i].attrib, eb[i].attrib) != 0)
return 0;
}
return 1;
}
static int
e_exists (const struct entry *e)
{
struct entry *h;
hashval_t hval;
hval = e_hash (e);
for (h = hash_table[hval % HASH_SIZE]; h; h = h->next)
if (e_eq (e, h))
return 1;
return 0;
}
static void
e_insert (struct entry *e)
{
hashval_t hval;
hval = e_hash (e);
e->next = hash_table[hval % HASH_SIZE];
hash_table[hval % HASH_SIZE] = e;
}
void
output (struct entry *e)
{
int i;
char c;
struct entry *n;
const char *skip_cint = "";
if (e[0].etype != ETYPE_STRUCT && e[0].etype != ETYPE_UNION)
abort ();
if (e_exists (e))
return;
n = (struct entry *) malloc ((e[0].len + 1) * sizeof (struct entry));
memcpy (n, e, (e[0].len + 1) * sizeof (struct entry));
e_insert (n);
if (idx == limidx)
switchfiles (e[0].len);
for (i = 1; i <= e[0].len; ++i)
if ((e[i].etype == ETYPE_TYPE || e[i].etype == ETYPE_ARRAY)
&& (e[i].type->type == TYPE_CINT || e[i].type->type == TYPE_CUINT))
break;
if (i <= e[0].len)
skip_cint = "CI";
if (e[0].attrib)
fprintf (outfile, (generate_random () & 1)
? "TX%s(%d,%s %s,," : "TX%s(%d,%s,%s,", skip_cint,
idx, e[0].etype == ETYPE_STRUCT ? "struct" : "union",
e[0].attrib);
else if (e[0].etype == ETYPE_STRUCT)
fprintf (outfile, "T%s(%d,", skip_cint, idx);
else
fprintf (outfile, "U%s(%d,", skip_cint, idx);
c = 'a';
for (i = 1; i <= e[0].len; )
i += subfield (e + i, &c);
fputs (",", outfile);
c = 'a';
for (i = 1; i <= e[0].len; )
{
i += subvalues (e + i, namebuf, &c);
if (e[0].etype == ETYPE_UNION)
break;
}
fputs (")\n", outfile);
if (output_one && idx == limidx)
exit (0);
++idx;
}
enum FEATURE
{
FEATURE_VECTOR = 1,
FEATURE_COMPLEX = 2,
FEATURE_ZEROARRAY = 8,
FEATURE_ZEROBITFLD = 16,
ALL_FEATURES = FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY
| FEATURE_ZEROBITFLD
};
void
singles (enum FEATURE features)
{
struct entry e[2];
int i;
memset (e, 0, sizeof (e));
e[0].etype = ETYPE_STRUCT;
output (e);
e[0].etype = ETYPE_UNION;
output (e);
e[0].len = 1;
e[0].attrib = NULL;
for (i = 0; i < NTYPES2; ++i)
{
e[0].etype = ETYPE_STRUCT;
e[1].etype = ETYPE_TYPE;
e[1].type = &base_types[i];
output (e);
e[0].etype = ETYPE_UNION;
output (e);
}
if (features & FEATURE_COMPLEX)
for (i = 0; i < NCTYPES2; ++i)
{
e[0].etype = ETYPE_STRUCT;
e[1].etype = ETYPE_TYPE;
e[1].type = &complex_types[i];
output (e);
e[0].etype = ETYPE_UNION;
output (e);
}
if (features & FEATURE_VECTOR)
for (i = 0; i < NVTYPES2; ++i)
{
e[0].etype = ETYPE_STRUCT;
e[1].etype = ETYPE_TYPE;
e[1].type = &vector_types[i];
output (e);
e[0].etype = ETYPE_UNION;
output (e);
}
}
void
choose_type (enum FEATURE features, struct entry *e, int r, int in_array)
{
int i;
i = NTYPES2 - NTYPES1;
if (features & FEATURE_COMPLEX)
i += NCTYPES2;
if (features & FEATURE_VECTOR)
i += NVTYPES2;
r >>= 2;
r %= i;
if (r < NTYPES2 - NTYPES1)
e->type = &base_types[r + NTYPES1];
r -= NTYPES2 - NTYPES1;
if (e->type == NULL && (features & FEATURE_COMPLEX))
{
if (r < NCTYPES2)
e->type = &complex_types[r];
r -= NCTYPES2;
}
if (e->type == NULL && (features & FEATURE_VECTOR))
{
if (r < NVTYPES2)
e->type = &vector_types[r];
r -= NVTYPES2;
}
if (e->type == NULL)
abort ();
}
/* This is from gcc.c-torture/execute/builtin-bitops-1.c. */
static int
my_ffsll (unsigned long long x)
{
int i;
if (x == 0)
return 0;
/* We've tested LLONG_MAX for 64 bits so this should be safe. */
for (i = 0; i < 64; i++)
if (x & (1ULL << i))
break;
return i + 1;
}
void
generate_fields (enum FEATURE features, struct entry *e, struct entry *parent,
int len)
{
int r, i, j, ret = 1, n, incr, sametype;
for (n = 0; n < len; n += incr)
{
r = generate_random ();
/* 50% ETYPE_TYPE base_types NTYPES1
12.5% ETYPE_TYPE other
12.5% ETYPE_ARRAY
12.5% ETYPE_BITFLD
12.5% ETYPE_STRUCT|ETYPE_UNION|ETYPE_STRUCT_ARRAY|ETYPE_UNION_ARRAY */
i = (r & 7);
r >>= 3;
incr = 1;
switch (i)
{
case 6: /* BITfields disabled for now as _Bool bitfields are broken. */
case 0:
case 1:
case 2:
case 3:
e[n].etype = ETYPE_TYPE;
e[n].type = &base_types[r % NTYPES1];
break;
case 4:
e[n].etype = ETYPE_TYPE;
choose_type (features, &e[n], r, 0);
break;
case 5:
e[n].etype = ETYPE_ARRAY;
i = r & 1;
r >>= 1;
if (i)
e[n].type = &base_types[r % NTYPES1];
else
choose_type (features, &e[n], r, 1);
r = generate_random ();
if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
{
e[n].arr_len = 0;
if (n == len - 1 && (r & 4)
&& (parent->etype == ETYPE_STRUCT
|| parent->etype == ETYPE_STRUCT_ARRAY))
{
int k;
for (k = 0; k < n; ++k)
if (e[k].etype != ETYPE_BITFLD || e[k].len)
{
e[n].arr_len = 255;
break;
}
}
}
else if ((r & 3) != 3)
e[n].arr_len = (r >> 2) & 7;
else
e[n].arr_len = (r >> 2) & 31;
break;
#if 0
case 6:
sametype = 1;
switch (r & 7)
{
case 0:
case 1:
case 2:
break;
case 3:
case 4:
case 5:
incr = 1 + (r >> 3) % (len - n);
break;
case 6:
case 7:
sametype = 0;
incr = 1 + (r >> 3) % (len - n);
break;
}
for (j = n; j < n + incr; ++j)
{
int mi, ma;
e[j].etype = ETYPE_BITFLD;
if (j == n || !sametype)
{
r = generate_random ();
r >>= 2;
e[j].type
= &bitfld_types[r % n_bitfld_types];
}
else
e[j].type = e[n].type;
r = generate_random ();
mi = 0;
ma = 0;
switch (e[j].type->bitfld)
{
case 'C': ma = 8; break;
case 'S': ma = 16; break;
case 'I': ma = 32; break;
case 'L':
case 'Q': ma = 64; break;
case 'B': ma = 1; break;
case ' ':
if (e[j].type->type == TYPE_UENUM)
mi = my_ffsll (e[j].type->maxval + 1) - 1;
else if (e[j].type->type == TYPE_SENUM)
mi = my_ffsll (e[j].type->maxval + 1);
else
abort ();
if (!mi)
mi = 1;
if (mi <= 32)
ma = 32;
else
ma = 64;
break;
default:
abort ();
}
e[j].len = ma + 1;
if (sametype && (r & 3) == 0 && ma > 1)
{
int sum = 0, k;
for (k = n; k < j; ++k)
sum += e[k].len;
sum %= ma;
e[j].len = sum ? ma - sum : ma;
}
r >>= 2;
if (! (features & FEATURE_ZEROBITFLD) && mi == 0)
mi = 1;
if (e[j].len < mi || e[j].len > ma)
e[j].len = mi + (r % (ma + 1 - mi));
r >>= 6;
if ((features & FEATURE_ZEROBITFLD) && (r & 3) == 0
&& mi == 0)
e[j].len = 0;
}
break;
#endif
case 7:
switch (r & 7)
{
case 0:
case 1:
case 2:
e[n].etype = ETYPE_STRUCT;
break;
case 3:
case 4:
e[n].etype = ETYPE_UNION;
break;
case 5:
case 6:
e[n].etype = ETYPE_STRUCT_ARRAY;
break;
case 7:
e[n].etype = ETYPE_UNION_ARRAY;
break;
}
r >>= 3;
e[n].len = r % (len - n);
incr = 1 + e[n].len;
generate_fields (features, &e[n + 1], &e[n], e[n].len);
if (e[n].etype == ETYPE_STRUCT_ARRAY
|| e[n].etype == ETYPE_UNION_ARRAY)
{
r = generate_random ();
if ((features & FEATURE_ZEROARRAY) && (r & 3) == 0)
{
e[n].arr_len = 0;
if (n + incr == len && (r & 4)
&& (parent->etype == ETYPE_STRUCT
|| parent->etype == ETYPE_STRUCT_ARRAY))
{
int k;
for (k = 0; k < n; ++k)
if (e[k].etype != ETYPE_BITFLD || e[k].len)
{
e[n].arr_len = 255;
break;
}
}
}
else if ((r & 3) != 3)
e[n].arr_len = (r >> 2) & 7;
else
e[n].arr_len = (r >> 2) & 31;
}
break;
}
}
}
void
generate_random_tests (enum FEATURE features, int len)
{
struct entry e[len + 1];
int i, r;
if (len > 'z' - 'a' + 1)
abort ();
memset (e, 0, sizeof (e));
r = generate_random ();
if ((r & 7) == 0)
e[0].etype = ETYPE_UNION;
else
e[0].etype = ETYPE_STRUCT;
r >>= 3;
e[0].len = len;
generate_fields (features, &e[1], &e[0], len);
output (e);
}
struct { const char *name; enum FEATURE f; }
features[] = {
{ "normal", 0 },
{ "complex", FEATURE_COMPLEX },
{ "vector", FEATURE_VECTOR },
{ "[0] :0", FEATURE_ZEROARRAY | FEATURE_ZEROBITFLD },
{ "complex vector [0]",
FEATURE_COMPLEX | FEATURE_VECTOR | FEATURE_ZEROARRAY }
};
int
main (int argc, char **argv)
{
int i, j, count, c, n = 3000;
char *optarg;
if (sizeof (int) != 4 || sizeof (long long) != 8)
return 1;
i = 1;
while (i < argc)
{
c = '\0';
if (argv[i][0] == '-' && argv[i][2] == '\0')
c = argv[i][1];
optarg = argv[i + 1];
if (!optarg)
goto usage;
switch (c)
{
case 'n':
n = atoi (optarg);
break;
case 'd':
destdir = optarg;
break;
case 's':
srcdir = optarg;
break;
case 'i':
output_one = 1;
limidx = atoi (optarg);
break;
default:
fprintf (stderr, "unrecognized option %s\n", argv[i]);
goto usage;
}
i += 2;
}
if (output_one)
{
outfile = fopen ("/dev/null", "w");
if (outfile == NULL)
{
fputs ("could not open /dev/null", stderr);
return 1;
}
n = limidx + 1;
}
if (destdir == NULL && !output_one)
{
usage:
fprintf (stderr, "Usage:\n\
%s [-s srcdir -d destdir] [-n count] [-i idx]\n\
Either -s srcdir -d destdir or -i idx must be used\n", argv[0]);
return 1;
}
if (srcdir == NULL && !output_one)
goto usage;
for (i = 0; i < NTYPES2; ++i)
if (base_types[i].bitfld)
bitfld_types[n_bitfld_types++] = base_types[i];
for (i = 0; i < sizeof (features) / sizeof (features[0]); ++i)
{
int startidx = idx;
if (! output_one)
limidx = idx;
if (!i)
count = 200;
else
count = 20;
for (j = 1; j <= 9; ++j)
while (idx < startidx + j * count)
generate_random_tests (features[i].f, j);
while (idx < startidx + count * 10)
generate_random_tests (features[i].f, 10 + (generate_random () % 16));
}
for (i = 0; n > 3000 && i < sizeof (features) / sizeof (features[0]); ++i)
{
int startidx;
startidx = idx;
if (! output_one)
limidx = idx;
singles (features[i].f);
if (!i)
{
count = 1000;
while (idx < startidx + 1000)
generate_random_tests (features[i].f, 1);
}
else
{
startidx = idx;
count = 100;
while (idx < startidx + 100)
generate_random_tests (features[i].f, 1);
}
startidx = idx;
for (j = 2; j <= 9; ++j)
while (idx < startidx + (j - 1) * count)
generate_random_tests (features[i].f, j);
while (idx < startidx + count * 9)
generate_random_tests (features[i].f, 10 + (generate_random () % 16));
}
if (! output_one)
limidx = idx;
while (idx < n)
generate_random_tests (ALL_FEATURES, 1 + (generate_random () % 25));
fclose (outfile);
return 0;
}
|