Commit | Line | Data |
---|---|---|
c350e9d7 WJ |
1 | /* genarch.c */ |
2 | /* Generate a header file (arch.h) with parameters */ | |
3 | /* reflecting the machine architecture and compiler characteristics. */ | |
4 | ||
5 | #include <stdio.h> | |
6 | ||
7 | /* We should write the result on stdout, but the Turbo C 'make' */ | |
8 | /* can't handle output redirection (sigh). */ | |
9 | ||
10 | main(argc, argv) | |
11 | int argc; | |
12 | char *argv[]; | |
13 | { char *fname = argv[1]; | |
14 | long one = 1; | |
15 | long lm1 = -1; | |
16 | long lr1 = lm1 >> 1, lr2 = lm1 >> 2; | |
17 | unsigned long um1 = ~(unsigned long)0; | |
18 | int im1 = -1; | |
19 | int ir1 = im1 >> 1, ir2 = im1 >> 2; | |
20 | int ars; | |
21 | int lwidth = sizeof(long) * 8; | |
22 | float f0 = 0.0, f1 = 1.0, fm1 = -1.0; | |
23 | FILE *f = fopen(fname, "w"); | |
24 | if ( f == NULL ) | |
25 | { fprintf(stderr, "genarch.c: can't open %s for writing\n", fname); | |
26 | exit(1); | |
27 | } | |
28 | fprintf(f, "/* Parameters derived from machine and compiler architecture */\n\n"); | |
29 | fprintf(f, "#define arch_is_big_endian %d\n", 1 - *(char *)&one); | |
30 | fprintf(f, "#define arch_sizeof_short %d\n", sizeof(short)); | |
31 | fprintf(f, "#define arch_sizeof_int %d\n", sizeof(int)); | |
32 | fprintf(f, "#define arch_sizeof_long %d\n", sizeof(long)); | |
33 | fprintf(f, "#define arch_floats_are_IEEE %d\n", | |
34 | (*(long *)&f0 == 0 && *(long *)&f1 == 0x3f800000L && | |
35 | *(long *)&fm1 == 0xbf800000L ? 1 : 0)); | |
36 | /* There are three cases for arithmetic right shift: */ | |
37 | /* always correct, correct except for right-shifting a long by 1 */ | |
38 | /* (a bug in some versions of the Turbo C compiler), and */ | |
39 | /* never correct. */ | |
40 | ars = (lr2 != -1 || ir1 != -1 || ir2 != -1 ? 0 : | |
41 | lr1 != -1 ? 1 : /* Turbo C problem */ | |
42 | 2); | |
43 | fprintf(f, "#define arch_arith_rshift %d\n", ars); | |
44 | /* Some machines can't handle a variable shift by */ | |
45 | /* the full width of a long. */ | |
46 | fprintf(f, "#define arch_can_shift_full_long %d\n", | |
47 | um1 >> lwidth == 0); | |
48 | fclose(f); | |
49 | return 0; | |
50 | } |