Home My Page Projects Code Snippets Project Openings SML/NJ
Summary Activity Forums Tracker Lists Tasks Docs Surveys News SCM Files

SCM Repository

[smlnj] Annotation of /sml/trunk/src/runtime/config/gen-sizes.c
ViewVC logotype

Annotation of /sml/trunk/src/runtime/config/gen-sizes.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 250 - (view) (download) (as text)

1 : monnier 249 /* gen-sizes.c
2 :     *
3 :     * COPYRIGHT (c) 1993 by AT&T Bell Laboratories.
4 :     *
5 :     * This program generates the "ml-sizes.h" header file; this file is
6 :     * usable in both C and assembly files.
7 :     */
8 :    
9 :     #include <stdio.h>
10 :     #include "gen.h"
11 :    
12 :     #define NIL(ty) ((ty)0)
13 :    
14 :     #if defined(SIZES_C64_ML64)
15 :     # error "64 bits not supported yet"
16 :     #else
17 :     # define WORD_SZB 4
18 :     #endif
19 :     # define ADDR_SZB sizeof(char *)
20 :    
21 :     static union {
22 :     char bytes[sizeof(unsigned long)];
23 :     unsigned long l;
24 :     } U;
25 :    
26 :     int log2 (int x)
27 :     {
28 :     int i, j;
29 :    
30 :     for (i = 1, j = 2; j <= x; i++, j += j)
31 :     continue;
32 :    
33 :     return i-1;
34 :    
35 :     } /* end of log2 */
36 :    
37 :     main ()
38 :     {
39 :     char *i16, *i32, *i64;
40 :     FILE *f;
41 :    
42 :     i16 = i32 = i64 = NIL(char *);
43 :    
44 :     switch (sizeof(short)) {
45 :     case 2: i16 = "short"; break;
46 :     case 4: i32 = "short"; break;
47 :     case 8: i64 = "short"; break;
48 :     }
49 :    
50 :     switch (sizeof(int)) {
51 :     case 2: i16 = "int"; break;
52 :     case 4: i32 = "int"; break;
53 :     case 8: i64 = "int"; break;
54 :     }
55 :    
56 :     switch (sizeof(long)) {
57 :     case 2: i16 = "long"; break;
58 :     case 4: i32 = "long"; break;
59 :     case 8: i64 = "long"; break;
60 :     default:
61 :     fprintf(stderr, "gen-sizes: Error -- no 32-bit integer type\n");
62 :     exit (1);
63 :     }
64 :    
65 :     if (i16 == NIL(char *)) {
66 :     fprintf(stderr, "gen-sizes: Error -- no 16-bit integer type\n");
67 :     exit (1);
68 :     }
69 :     if (i32 == NIL(char *)) {
70 :     fprintf(stderr, "gen-sizes: Error -- no 32-bit integer type\n");
71 :     exit (1);
72 :     }
73 :     #if (defined(SIZES_C64_ML32) || defined(SIZES_C64_ML64))
74 :     if (i64 == NIL(char *)) {
75 :     fprintf(stderr, "gen-sizes: Error -- no 64-bit integer type\n");
76 :     exit (1);
77 :     }
78 :     #endif
79 :    
80 :     f = OpenFile ("ml-sizes.h", "_ML_SIZES_");
81 :    
82 :     fprintf (f, "#define WORD_SZB %d\n", WORD_SZB);
83 :     fprintf (f, "#define ADDR_SZB %d\n", ADDR_SZB);
84 :     fprintf (f, "#define REALD_SZB %d\n", sizeof(double));
85 :     fprintf (f, "#define BITS_PER_WORD %d\n", 8*WORD_SZB);
86 :     fprintf (f, "#define LOG_BITS_PER_WORD %d\n", log2(8*WORD_SZB));
87 :     fprintf (f, "#define LOG_BYTES_PER_WORD %d\n", log2(WORD_SZB));
88 :     fprintf (f, "\n");
89 :    
90 :     U.bytes[0] = 0x01;
91 :     U.bytes[sizeof(unsigned long)-1] = 0x02;
92 :     switch (U.l & 0xFF) {
93 :     case 0x01:
94 :     fprintf(f, "#define BYTE_ORDER_LITTLE\n");
95 :     break;
96 :     case 0x02:
97 :     fprintf(f, "#define BYTE_ORDER_BIG\n");
98 :     break;
99 :     default:
100 :     fprintf(stderr, "gen-sizes: Error -- unable to determine endianess\n");
101 :     exit(1);
102 :     } /* end of switch */
103 :     fprintf (f, "\n");
104 :    
105 :     /* the C part */
106 :     fprintf (f, "#ifndef _ASM_\n");
107 :    
108 :     fprintf (f, "typedef %s Int16_t;\n", i16);
109 :     fprintf (f, "typedef unsigned %s Unsigned16_t;\n", i16);
110 :     fprintf (f, "typedef %s Int32_t;\n", i32);
111 :     fprintf (f, "typedef unsigned %s Unsigned32_t;\n", i32);
112 :     #if (defined(SIZES_C64_ML32) || defined(SIZES_C64_ML64))
113 :     fprintf (f, "typedef %s Int64_t;\n", i64);
114 :     fprintf (f, "typedef unsigned %s Unsigned64_t;\n", i64);
115 :     #endif
116 :     fprintf (f, "\n");
117 :     fprintf (f, "typedef unsigned char Byte_t;\n");
118 :     #if defined(SIZES_C64_ML32)
119 :     fprintf (f, "typedef Unsigned32_t Word_t;\n");
120 :     fprintf (f, "typedef Int32_t Int_t;\n");
121 :     fprintf (f, "typedef Unsigned64_t Addr_t;\n");
122 :     #elif defined(SIZES_C64_ML64)
123 :     fprintf (f, "typedef Unsigned64_t Word_t;\n");
124 :     fprintf (f, "typedef Int64_t Int_t;\n");
125 :     fprintf (f, "typedef Unsigned64_t Addr_t;\n");
126 :     #else
127 :     fprintf (f, "typedef Unsigned32_t Word_t;\n");
128 :     fprintf (f, "typedef Int32_t Int_t;\n");
129 :     fprintf (f, "typedef Unsigned32_t Addr_t;\n");
130 :     #endif
131 :    
132 :     fprintf (f, "#endif\n");
133 :    
134 :     CloseFile (f, "_ML_SIZES_");
135 :    
136 :     exit (0);
137 :     }

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0