/[jscoverage]/trunk/js/jscpucfg.cpp
ViewVC logotype

Contents of /trunk/js/jscpucfg.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 507 - (show annotations)
Sun Jan 10 07:23:34 2010 UTC (9 years, 8 months ago) by siliconforks
File size: 6642 byte(s)
Update SpiderMonkey from Firefox 3.6rc1.

1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
2 *
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
5 *
6 * The contents of this file are subject to the Mozilla Public License Version
7 * 1.1 (the "License"); you may not use this file except in compliance with
8 * the License. You may obtain a copy of the License at
9 * http://www.mozilla.org/MPL/
10 *
11 * Software distributed under the License is distributed on an "AS IS" basis,
12 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 * for the specific language governing rights and limitations under the
14 * License.
15 *
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
18 *
19 * The Initial Developer of the Original Code is
20 * Netscape Communications Corporation.
21 * Portions created by the Initial Developer are Copyright (C) 1998
22 * the Initial Developer. All Rights Reserved.
23 *
24 * Contributor(s):
25 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
26 *
27 * Alternatively, the contents of this file may be used under the terms of
28 * either of the GNU General Public License Version 2 or later (the "GPL"),
29 * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 * in which case the provisions of the GPL or the LGPL are applicable instead
31 * of those above. If you wish to allow use of your version of this file only
32 * under the terms of either the GPL or the LGPL, and not to allow others to
33 * use your version of this file under the terms of the MPL, indicate your
34 * decision by deleting the provisions above and replace them with the notice
35 * and other provisions required by the GPL or the LGPL. If you do not delete
36 * the provisions above, a recipient may use your version of this file under
37 * the terms of any one of the MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41 /*
42 * Generate CPU-specific bit-size and similar #defines.
43 */
44 #include <stdio.h>
45 #include <stdlib.h>
46
47 #ifdef CROSS_COMPILE
48 #include <prtypes.h>
49 #endif
50
51 /************************************************************************/
52
53 #ifdef __GNUC__
54 #define NS_NEVER_INLINE __attribute__((noinline))
55 #else
56 #define NS_NEVER_INLINE
57 #endif
58
59 #ifdef __SUNPRO_C
60 static int StackGrowthDirection(int *dummy1addr);
61 #pragma no_inline(StackGrowthDirection)
62 #endif
63
64 static int NS_NEVER_INLINE StackGrowthDirection(int *dummy1addr)
65 {
66 int dummy2;
67
68 return (&dummy2 < dummy1addr) ? -1 : 1;
69 }
70
71 int main(int argc, char **argv)
72 {
73 int dummy1;
74
75 printf("#ifndef js_cpucfg___\n");
76 printf("#define js_cpucfg___\n\n");
77
78 printf("/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
79
80 #ifdef CROSS_COMPILE
81 #if defined(__APPLE__)
82 /*
83 * Darwin NSPR uses the same MDCPUCFG (_darwin.cfg) for multiple
84 * processors, and determines which processor to configure for based
85 * on compiler predefined macros. We do the same thing here.
86 */
87 printf("#ifdef __LITTLE_ENDIAN__\n");
88 printf("#define IS_LITTLE_ENDIAN 1\n");
89 printf("#undef IS_BIG_ENDIAN\n");
90 printf("#else\n");
91 printf("#undef IS_LITTLE_ENDIAN\n");
92 printf("#define IS_BIG_ENDIAN 1\n");
93 printf("#endif\n\n");
94 #elif defined(IS_LITTLE_ENDIAN)
95 printf("#define IS_LITTLE_ENDIAN 1\n");
96 printf("#undef IS_BIG_ENDIAN\n\n");
97 #elif defined(IS_BIG_ENDIAN)
98 printf("#undef IS_LITTLE_ENDIAN\n");
99 printf("#define IS_BIG_ENDIAN 1\n\n");
100 #else
101 #error "Endianess not defined."
102 #endif
103
104 #else
105
106 /*
107 * We don't handle PDP-endian or similar orders: if a short is big-endian,
108 * so must int and long be big-endian for us to generate the IS_BIG_ENDIAN
109 * #define and the IS_LITTLE_ENDIAN #undef.
110 */
111 {
112 int big_endian = 0, little_endian = 0, ntests = 0;
113
114 if (sizeof(short) == 2) {
115 /* force |volatile| here to get rid of any compiler optimisations
116 * (var in register etc.) which may be appiled to |auto| vars -
117 * even those in |union|s...
118 * (|static| is used to get the same functionality for compilers
119 * which do not honor |volatile|...).
120 */
121 volatile static union {
122 short i;
123 char c[2];
124 } u;
125
126 u.i = 0x0102;
127 big_endian += (u.c[0] == 0x01 && u.c[1] == 0x02);
128 little_endian += (u.c[0] == 0x02 && u.c[1] == 0x01);
129 ntests++;
130 }
131
132 if (sizeof(int) == 4) {
133 /* force |volatile| here ... */
134 volatile static union {
135 int i;
136 char c[4];
137 } u;
138
139 u.i = 0x01020304;
140 big_endian += (u.c[0] == 0x01 && u.c[1] == 0x02 &&
141 u.c[2] == 0x03 && u.c[3] == 0x04);
142 little_endian += (u.c[0] == 0x04 && u.c[1] == 0x03 &&
143 u.c[2] == 0x02 && u.c[3] == 0x01);
144 ntests++;
145 }
146
147 if (sizeof(long) == 8) {
148 /* force |volatile| here ... */
149 volatile static union {
150 long i;
151 char c[8];
152 } u;
153
154 /*
155 * Write this as portably as possible: avoid 0x0102030405060708L
156 * and <<= 32.
157 */
158 u.i = 0x01020304;
159 u.i <<= 16, u.i <<= 16;
160 u.i |= 0x05060708;
161 big_endian += (u.c[0] == 0x01 && u.c[1] == 0x02 &&
162 u.c[2] == 0x03 && u.c[3] == 0x04 &&
163 u.c[4] == 0x05 && u.c[5] == 0x06 &&
164 u.c[6] == 0x07 && u.c[7] == 0x08);
165 little_endian += (u.c[0] == 0x08 && u.c[1] == 0x07 &&
166 u.c[2] == 0x06 && u.c[3] == 0x05 &&
167 u.c[4] == 0x04 && u.c[5] == 0x03 &&
168 u.c[6] == 0x02 && u.c[7] == 0x01);
169 ntests++;
170 }
171
172 if (big_endian && big_endian == ntests) {
173 printf("#undef IS_LITTLE_ENDIAN\n");
174 printf("#define IS_BIG_ENDIAN 1\n\n");
175 } else if (little_endian && little_endian == ntests) {
176 printf("#define IS_LITTLE_ENDIAN 1\n");
177 printf("#undef IS_BIG_ENDIAN\n\n");
178 } else {
179 fprintf(stderr, "%s: unknown byte order"
180 "(big_endian=%d, little_endian=%d, ntests=%d)!\n",
181 argv[0], big_endian, little_endian, ntests);
182 return EXIT_FAILURE;
183 }
184 }
185
186 #endif /* CROSS_COMPILE */
187
188 printf("#define JS_STACK_GROWTH_DIRECTION (%d)\n", StackGrowthDirection(&dummy1));
189
190 printf("#endif /* js_cpucfg___ */\n");
191
192 return EXIT_SUCCESS;
193 }
194

  ViewVC Help
Powered by ViewVC 1.1.24