VirtualBox

source: vbox/trunk/src/libs/xpcom18a4/nsprpub/pr/include/gencfg.c@ 4885

Last change on this file since 4885 was 1, checked in by vboxsync, 55 years ago

import

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 8.0 KB
Line 
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2/* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
9 *
10 * Software distributed under the License is distributed on an "AS IS" basis,
11 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 * for the specific language governing rights and limitations under the
13 * License.
14 *
15 * The Original Code is the Netscape Portable Runtime (NSPR).
16 *
17 * The Initial Developer of the Original Code is
18 * Netscape Communications Corporation.
19 * Portions created by the Initial Developer are Copyright (C) 1998-2000
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 *
24 * Alternatively, the contents of this file may be used under the terms of
25 * either the GNU General Public License Version 2 or later (the "GPL"), or
26 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
27 * in which case the provisions of the GPL or the LGPL are applicable instead
28 * of those above. If you wish to allow use of your version of this file only
29 * under the terms of either the GPL or the LGPL, and not to allow others to
30 * use your version of this file under the terms of the MPL, indicate your
31 * decision by deleting the provisions above and replace them with the notice
32 * and other provisions required by the GPL or the LGPL. If you do not delete
33 * the provisions above, a recipient may use your version of this file under
34 * the terms of any one of the MPL, the GPL or the LGPL.
35 *
36 * ***** END LICENSE BLOCK ***** */
37
38#include <stdio.h>
39
40#if defined(sgi)
41#ifndef IRIX
42 error - IRIX is not defined
43#endif
44#endif
45
46#if defined(__sun)
47#if defined(__svr4) || defined(__svr4__) || defined(__SVR4)
48#ifndef SOLARIS
49 error - SOLARIS is not defined
50#endif
51#else
52#ifndef SUNOS4
53 error - SUNOS4 is not defined
54#endif
55#endif
56#endif
57
58#if defined(__hpux)
59#ifndef HPUX
60 error - HPUX is not defined
61#endif
62#endif
63
64#if defined(__alpha)
65#if !(defined(_WIN32)) && !(defined(OSF1)) && !(defined(__linux)) && !(defined(__FreeBSD__))
66 error - None of OSF1, _WIN32, __linux, or __FreeBSD__ is defined
67#endif
68#endif
69
70#if defined(_IBMR2)
71#ifndef AIX
72 error - AIX is not defined
73#endif
74#endif
75
76#if defined(linux)
77#ifndef LINUX
78 error - LINUX is not defined
79#endif
80#endif
81
82#if defined(bsdi)
83#ifndef BSDI
84 error - BSDI is not defined
85#endif
86#endif
87
88#if defined(M_UNIX)
89#ifndef SCO
90 error - SCO is not defined
91#endif
92#endif
93#if !defined(M_UNIX) && defined(_USLC_)
94#ifndef UNIXWARE
95 error - UNIXWARE is not defined
96#endif
97#endif
98
99#if defined(__APPLE__)
100#ifndef DARWIN
101 error - DARWIN is not defined
102#endif
103#endif
104
105#if defined(__NeXT__)
106#ifndef NEXTSTEP
107 error - NEXTSTEP is not defined
108#endif
109#endif
110
111/************************************************************************/
112
113/* Generate cpucfg.h */
114
115#ifdef XP_PC
116#ifdef WIN32
117#define INT64 _PRInt64
118#else
119#define INT64 long
120#endif
121#else
122#if defined(HPUX) || defined(NECSVR4) || defined(SCO) || defined(UNIXWARE) || defined (NCR)
123#define INT64 long
124#else
125#define INT64 long long
126#endif
127#endif
128
129struct align_short {
130 char c;
131 short a;
132};
133struct align_int {
134 char c;
135 int a;
136};
137struct align_long {
138 char c;
139 long a;
140};
141struct align_PRInt64 {
142 char c;
143 INT64 a;
144};
145struct align_fakelonglong {
146 char c;
147 struct {
148 long hi, lo;
149 } a;
150};
151struct align_float {
152 char c;
153 float a;
154};
155struct align_double {
156 char c;
157 double a;
158};
159struct align_pointer {
160 char c;
161 void *a;
162};
163
164#define ALIGN_OF(type) \
165 (((char*)&(((struct align_##type *)0)->a)) - ((char*)0))
166
167int bpb;
168
169/* Used if shell doesn't support redirection. By default, assume it does. */
170FILE *stream;
171
172static int Log2(int n)
173{
174 int log2 = 0;
175
176 if (n & (n-1))
177 log2++;
178 if (n >> 16)
179 log2 += 16, n >>= 16;
180 if (n >> 8)
181 log2 += 8, n >>= 8;
182 if (n >> 4)
183 log2 += 4, n >>= 4;
184 if (n >> 2)
185 log2 += 2, n >>= 2;
186 if (n >> 1)
187 log2++;
188 return log2;
189}
190
191/* We assume that int's are 32 bits */
192static void do64(void)
193{
194 union {
195 int i;
196 char c[4];
197 } u;
198
199 u.i = 0x01020304;
200 if (u.c[0] == 0x01) {
201 fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
202 fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
203 } else {
204 fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
205 fprintf(stream, "#undef IS_BIG_ENDIAN\n\n");
206 }
207}
208
209static void do32(void)
210{
211 union {
212 long i;
213 char c[4];
214 } u;
215
216 u.i = 0x01020304;
217 if (u.c[0] == 0x01) {
218 fprintf(stream, "#undef IS_LITTLE_ENDIAN\n");
219 fprintf(stream, "#define IS_BIG_ENDIAN 1\n\n");
220 } else {
221 fprintf(stream, "#define IS_LITTLE_ENDIAN 1\n");
222 fprintf(stream, "#undef IS_BIG_ENDIAN\n\n");
223 }
224}
225
226/*
227** Concievably this could actually be used; but there is lots of code out
228** there with and's and shift's in it that assumes a byte is 8 bits, so
229** forget about porting THIS code to those non 8 bit byte machines.
230*/
231static void BitsPerByte(void)
232{
233 bpb = 8;
234}
235
236int main(int argc, char **argv)
237{
238 BitsPerByte();
239
240 /* If we got a command line argument, try to use it as the stream. */
241 ++argv;
242 if(*argv) {
243 if(!(stream = fopen ( *argv, "wt" ))) {
244 fprintf(stderr, "Could not write to output file %s.\n", *argv);
245 return 1;
246 }
247 } else {
248 stream = stdout;
249 }
250
251 fprintf(stream, "#ifndef nspr_cpucfg___\n");
252 fprintf(stream, "#define nspr_cpucfg___\n\n");
253
254 fprintf(stream, "/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
255
256 if (sizeof(long) == 8) {
257 do64();
258 } else {
259 do32();
260 }
261 fprintf(stream, "#define PR_BYTES_PER_BYTE %d\n", sizeof(char));
262 fprintf(stream, "#define PR_BYTES_PER_SHORT %d\n", sizeof(short));
263 fprintf(stream, "#define PR_BYTES_PER_INT %d\n", sizeof(int));
264 fprintf(stream, "#define PR_BYTES_PER_INT64 %d\n", 8);
265 fprintf(stream, "#define PR_BYTES_PER_LONG %d\n", sizeof(long));
266 fprintf(stream, "#define PR_BYTES_PER_FLOAT %d\n", sizeof(float));
267 fprintf(stream, "#define PR_BYTES_PER_DOUBLE %d\n\n", sizeof(double));
268
269 fprintf(stream, "#define PR_BITS_PER_BYTE %d\n", bpb);
270 fprintf(stream, "#define PR_BITS_PER_SHORT %d\n", bpb * sizeof(short));
271 fprintf(stream, "#define PR_BITS_PER_INT %d\n", bpb * sizeof(int));
272 fprintf(stream, "#define PR_BITS_PER_INT64 %d\n", bpb * 8);
273 fprintf(stream, "#define PR_BITS_PER_LONG %d\n", bpb * sizeof(long));
274 fprintf(stream, "#define PR_BITS_PER_FLOAT %d\n", bpb * sizeof(float));
275 fprintf(stream, "#define PR_BITS_PER_DOUBLE %d\n\n",
276 bpb * sizeof(double));
277
278 fprintf(stream, "#define PR_BITS_PER_BYTE_LOG2 %d\n", Log2(bpb));
279 fprintf(stream, "#define PR_BITS_PER_SHORT_LOG2 %d\n",
280 Log2(bpb * sizeof(short)));
281 fprintf(stream, "#define PR_BITS_PER_INT_LOG2 %d\n",
282 Log2(bpb * sizeof(int)));
283 fprintf(stream, "#define PR_BITS_PER_INT64_LOG2 %d\n", 6);
284 fprintf(stream, "#define PR_BITS_PER_LONG_LOG2 %d\n",
285 Log2(bpb * sizeof(long)));
286 fprintf(stream, "#define PR_BITS_PER_FLOAT_LOG2 %d\n",
287 Log2(bpb * sizeof(float)));
288 fprintf(stream, "#define PR_BITS_PER_DOUBLE_LOG2 %d\n\n",
289 Log2(bpb * sizeof(double)));
290
291 fprintf(stream, "#define PR_ALIGN_OF_SHORT %d\n", ALIGN_OF(short));
292 fprintf(stream, "#define PR_ALIGN_OF_INT %d\n", ALIGN_OF(int));
293 fprintf(stream, "#define PR_ALIGN_OF_LONG %d\n", ALIGN_OF(long));
294 if (sizeof(INT64) < 8) {
295 /* this machine doesn't actually support PRInt64's */
296 fprintf(stream, "#define PR_ALIGN_OF_INT64 %d\n",
297 ALIGN_OF(fakelonglong));
298 } else {
299 fprintf(stream, "#define PR_ALIGN_OF_INT64 %d\n", ALIGN_OF(PRInt64));
300 }
301 fprintf(stream, "#define PR_ALIGN_OF_FLOAT %d\n", ALIGN_OF(float));
302 fprintf(stream, "#define PR_ALIGN_OF_DOUBLE %d\n", ALIGN_OF(double));
303 fprintf(stream, "#define PR_ALIGN_OF_POINTER %d\n\n", ALIGN_OF(pointer));
304
305 fprintf(stream, "#endif /* nspr_cpucfg___ */\n");
306 fclose(stream);
307
308 return 0;
309}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette