Bug 507665 - Avoid imacros for JSOP_GETELEM and JSOP_CALLELEM. r=gal.
[mozilla-central.git] / js / src / jscpucfg.cpp
blobc52d9b8102dd2ad1ceefeba96f63c530d922345d
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3 * ***** BEGIN LICENSE BLOCK *****
4 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
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/
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.
16 * The Original Code is Mozilla Communicator client code, released
17 * March 31, 1998.
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.
24 * Contributor(s):
25 * Roland Mainz <roland.mainz@informatik.med.uni-giessen.de>
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.
39 * ***** END LICENSE BLOCK ***** */
42 * Generate CPU-specific bit-size and similar #defines.
44 #include <stdio.h>
45 #include <stdlib.h>
47 #ifdef CROSS_COMPILE
48 #include <prtypes.h>
49 #endif
51 /************************************************************************/
53 #ifdef __GNUC__
54 #define NS_NEVER_INLINE __attribute__((noinline))
55 #else
56 #define NS_NEVER_INLINE
57 #endif
59 #ifdef __SUNPRO_C
60 static int StackGrowthDirection(int *dummy1addr);
61 #pragma no_inline(StackGrowthDirection)
62 #endif
64 static int NS_NEVER_INLINE StackGrowthDirection(int *dummy1addr)
66 int dummy2;
68 return (&dummy2 < dummy1addr) ? -1 : 1;
71 int main(int argc, char **argv)
73 int dummy1;
75 printf("#ifndef js_cpucfg___\n");
76 printf("#define js_cpucfg___\n\n");
78 printf("/* AUTOMATICALLY GENERATED - DO NOT EDIT */\n\n");
80 #ifdef CROSS_COMPILE
81 #if defined(__APPLE__)
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.
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
104 #else
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.
112 int big_endian = 0, little_endian = 0, ntests = 0;
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|...).
121 volatile static union {
122 short i;
123 char c[2];
124 } u;
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++;
132 if (sizeof(int) == 4) {
133 /* force |volatile| here ... */
134 volatile static union {
135 int i;
136 char c[4];
137 } u;
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++;
147 if (sizeof(long) == 8) {
148 /* force |volatile| here ... */
149 volatile static union {
150 long i;
151 char c[8];
152 } u;
155 * Write this as portably as possible: avoid 0x0102030405060708L
156 * and <<= 32.
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++;
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;
186 #endif /* CROSS_COMPILE */
188 printf("#define JS_STACK_GROWTH_DIRECTION (%d)\n", StackGrowthDirection(&dummy1));
190 printf("#endif /* js_cpucfg___ */\n");
192 return EXIT_SUCCESS;