Skip to content

Commit c600155

Browse files
author
Dan Gohman
committed
Begin using the Emscripten toolchain in clang.
With the Emscripten toolchain, we can make clang do more of what we need directly rather than in the wrapper scripts.
1 parent 377e759 commit c600155

File tree

10 files changed

+136
-24
lines changed

10 files changed

+136
-24
lines changed

system/include/EGL/eglplatform.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ typedef HDC EGLNativeDisplayType;
7575
typedef HBITMAP EGLNativePixmapType;
7676
typedef HWND EGLNativeWindowType;
7777

78-
#elif defined(EMSCRIPTEN)
78+
#elif defined(__EMSCRIPTEN__)
7979

8080
typedef int EGLNativeDisplayType;
8181
typedef int EGLNativeWindowType;

system/include/SDL/SDL_config_minimal.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
#include <stddef.h>
3434
#include <stdarg.h>
3535

36-
#if !defined(EMSCRIPTEN) && !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
36+
#if !defined(__EMSCRIPTEN__) && !defined(_STDINT_H_) && (!defined(HAVE_STDINT_H) || !_HAVE_STDINT_H)
3737
typedef unsigned int size_t;
3838
typedef signed char int8_t;
3939
typedef unsigned char uint8_t;

system/include/SDL/SDL_stdinc.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
#endif
6666
#if defined(HAVE_INTTYPES_H)
6767
# include <inttypes.h>
68-
#elif defined(EMSCRIPTEN) || defined(HAVE_STDINT_H)
68+
#elif defined(__EMSCRIPTEN__) || defined(HAVE_STDINT_H)
6969
# include <stdint.h>
7070
#endif
7171
#ifdef HAVE_CTYPE_H

system/include/emscripten/emscripten.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
extern "C" {
1515
#endif
1616

17-
#if !EMSCRIPTEN
17+
#if !__EMSCRIPTEN__
1818
#include <SDL/SDL.h> /* for SDL_Delay in async_call */
1919
#endif
2020

@@ -141,7 +141,7 @@ extern void emscripten_async_load_script(const char *script, void (*onload)(), v
141141
* you created an object on the stack, it will be cleaned up
142142
* before the main loop will be called the first time.
143143
*/
144-
#if EMSCRIPTEN
144+
#if __EMSCRIPTEN__
145145
extern void emscripten_set_main_loop(void (*func)(), int fps, int simulate_infinite_loop);
146146
extern void emscripten_set_main_loop_arg(void (*func)(void*), void *arg, int fps, int simulate_infinite_loop);
147147
extern void emscripten_pause_main_loop();
@@ -166,7 +166,7 @@ extern void emscripten_cancel_main_loop();
166166
* are not counted, do not block the main loop, and can fire
167167
* at specific time in the future.
168168
*/
169-
#if EMSCRIPTEN
169+
#if __EMSCRIPTEN__
170170
extern void _emscripten_push_main_loop_blocker(void (*func)(void *), void *arg, const char *name);
171171
extern void _emscripten_push_uncounted_main_loop_blocker(void (*func)(void *), void *arg, const char *name);
172172
#else
@@ -188,7 +188,7 @@ inline void _emscripten_push_uncounted_main_loop_blocker(void (*func)(void *), v
188188
* to 10, then push 10 blockers, as they complete the user will
189189
* see x/10 and so forth.
190190
*/
191-
#if EMSCRIPTEN
191+
#if __EMSCRIPTEN__
192192
extern void emscripten_set_main_loop_expected_blockers(int num);
193193
#else
194194
inline void emscripten_set_main_loop_expected_blockers(int num) {}
@@ -203,7 +203,7 @@ inline void emscripten_set_main_loop_expected_blockers(int num) {}
203203
* If millis is negative, the browser's requestAnimationFrame
204204
* mechanism is used.
205205
*/
206-
#if EMSCRIPTEN
206+
#if __EMSCRIPTEN__
207207
extern void emscripten_async_call(void (*func)(void *), void *arg, int millis);
208208
#else
209209
inline void emscripten_async_call(void (*func)(void *), void *arg, int millis) {
@@ -247,7 +247,7 @@ void emscripten_get_canvas_size(int *width, int *height, int *isFullscreen);
247247
* absolute time, and is only meaningful in comparison to
248248
* other calls to this function. The unit is ms.
249249
*/
250-
#if EMSCRIPTEN
250+
#if __EMSCRIPTEN__
251251
double emscripten_get_now();
252252
#else
253253
#include <time.h>

system/include/jansson.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ typedef long long json_int_t;
8282
typedef long json_int_t;
8383
#endif /* JSON_INTEGER_IS_LONG_LONG */
8484

85-
#ifdef EMSCRIPTEN
85+
#ifdef __EMSCRIPTEN__
8686
extern "C" bool json_typeof(const void *object);
8787
extern "C" bool json_is_object(const void *object);
8888
extern "C" bool json_is_array(const void *object);

system/lib/compiler-rt/int_endianness.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100

101101
#endif /* Windows */
102102

103-
#if defined(EMSCRIPTEN)
103+
#if defined(__EMSCRIPTEN__)
104104

105105
#define _YUGA_LITTLE_ENDIAN 1
106106
#define _YUGA_BIG_ENDIAN 0

system/lib/dlmalloc.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
/* XXX Emscripten XXX */
3-
#if EMSCRIPTEN
3+
#if __EMSCRIPTEN__
44
#define DLMALLOC_EXPORT __attribute__((__weak__, __visibility__("default")))
55
/* mmap uses malloc, so malloc can't use mmap */
66
#define HAVE_MMAP 0

tests/asmjs-unknown-emscripten.c

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
#ifndef __EMSCRIPTEN__
2+
#error __EMSCRIPTEN__ is not defined
3+
#endif
4+
#ifndef __asmjs__
5+
#error __asmjs__ is not defined
6+
#endif
7+
#ifdef __cplusplus
8+
#ifndef _GNU_SOURCE
9+
#error _GNU_SOURCE is not defined in C++
10+
#endif
11+
#endif
12+
#ifndef __unix__
13+
#error __unix__ is not defined
14+
#endif
15+
#ifndef __LITTLE_ENDIAN__
16+
#error __LITTLE_ENDIAN__ is not defined
17+
#endif
18+
19+
#ifdef __clang__
20+
#if __has_feature(pnacl)
21+
#error has feature pnacl
22+
#endif
23+
#endif
24+
25+
#ifdef __native_client__
26+
#error __native_client__ is defined
27+
#endif
28+
#ifdef __pnacl__
29+
#error __pnacl__ is defined
30+
#endif
31+
#ifdef __ELF__
32+
#error __ELF__ is defined
33+
#endif
34+
#ifdef __i386__
35+
#error __i386__ is defined
36+
#endif
37+
#ifdef __i386
38+
#error __i386 is defined
39+
#endif
40+
#ifdef i386
41+
#error i386 is defined
42+
#endif
43+
#ifdef __SSE__
44+
#error __SSE__ is defined
45+
#endif
46+
#ifdef __SSE2__
47+
#error __SSE2__ is defined
48+
#endif
49+
#ifdef __SSE_MATH__
50+
#error __SSE_MATH__ is defined
51+
#endif
52+
#ifdef __SSE2_MATH__
53+
#error __SSE2_MATH__ is defined
54+
#endif
55+
#ifdef __MMX__
56+
#error __MMX__ is defined
57+
#endif
58+
#ifdef __APPLE__
59+
#error __APPLE__ is defined
60+
#endif
61+
#ifdef __linux__
62+
#error __linux__ is defined
63+
#endif
64+
#ifdef __BIG_ENDIAN__
65+
#error __BIG_ENDIAN__ is defined
66+
#endif
67+
#ifdef __LP64__
68+
#error __LP64__ is defined
69+
#endif
70+
71+
// We prefer to use __EMSCRIPTEN__, but for compatibility, we define
72+
// EMSCRIPTEN too.
73+
#ifndef EMSCRIPTEN
74+
#error EMSCRIPTEN is not defined
75+
#endif
76+
77+
#include <stdint.h>
78+
#include <stddef.h>
79+
#include <string.h>
80+
#include <assert.h>
81+
82+
#define STRINGIZE_HELPER(x) #x
83+
#define STRINGIZE(x) STRINGIZE_HELPER(x)
84+
85+
int main() {
86+
assert(sizeof(void*) == 4);
87+
assert(sizeof(long) == 4);
88+
assert(sizeof(intmax_t) == 8);
89+
assert(__alignof(double) == 8);
90+
assert(sizeof(long double) == 8);
91+
assert(__alignof(long double) == 8);
92+
assert(sizeof(intptr_t) == 4);
93+
assert(sizeof(size_t) == 4);
94+
assert(sizeof(ptrdiff_t) == 4);
95+
assert(__FLT_EVAL_METHOD__ == 0);
96+
assert(strcmp(STRINGIZE(__USER_LABEL_PREFIX__), "") == 0);
97+
return 0;
98+
}

tests/test_core.py

+5
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ def test_sha1(self):
504504

505505
self.do_run(open(path_from_root('tests', 'sha1.c')).read(), 'SHA1=15dd99a1991e0b3826fede3deffc1feba42278e6')
506506

507+
def test_asmjs_unknown_emscripten(self):
508+
if self.emcc_args == None: return self.skip('needs emcc')
509+
if not self.is_emscripten_abi(): return self.skip('asmjs-unknown-emscripten needed for asmjs-unknown-emscripten target test')
510+
self.do_run(open(path_from_root('tests', 'asmjs-unknown-emscripten.c')).read(), '')
511+
507512
def test_cube2md5(self):
508513
if self.emcc_args == None: return self.skip('needs emcc')
509514
if not self.is_emscripten_abi(): return self.skip('asmjs-unknown-emscripten needed for accurate math')

tools/shared.py

+21-12
Original file line numberDiff line numberDiff line change
@@ -626,20 +626,29 @@ def get_llvm_target():
626626
COMPILER_OPTS # Can be set in EM_CONFIG, optionally
627627
except:
628628
COMPILER_OPTS = []
629-
COMPILER_OPTS = COMPILER_OPTS + ['-m32', '-DEMSCRIPTEN', '-D__EMSCRIPTEN__',
630-
'-fno-math-errno',
631-
#'-fno-threadsafe-statics', # disabled due to issue 1289
629+
COMPILER_OPTS = COMPILER_OPTS + [#'-fno-threadsafe-statics', # disabled due to issue 1289
632630
'-target', LLVM_TARGET]
633631

634-
# For temporary compatibility, treat 'le32-unknown-nacl' as 'asmjs-unknown-emscripten'.
635-
if LLVM_TARGET == 'asmjs-unknown-emscripten' or LLVM_TARGET == 'le32-unknown-nacl':
636-
COMPILER_OPTS = filter(lambda opt: opt != '-m32', COMPILER_OPTS) # asmjs-unknown-emscripten target is 32-bit anyhow, no need for -m32
637-
COMPILER_OPTS += ['-U__native_client__', '-U__pnacl__', '-U__ELF__'] # The nacl target is originally used for Google Native Client. Emscripten is not NaCl, so remove the platform #define, when using their triple.
638-
639-
# Remove various platform specific defines, and set little endian
640-
COMPILER_STANDARDIZATION_OPTS = ['-U__i386__', '-U__i386', '-Ui386', '-U__STRICT_ANSI__', '-D__IEEE_LITTLE_ENDIAN',
641-
'-U__SSE__', '-U__SSE_MATH__', '-U__SSE2__', '-U__SSE2_MATH__', '-U__MMX__',
642-
'-U__APPLE__', '-U__linux__']
632+
# COMPILER_STANDARDIZATION_OPTS: Options to correct various predefined macro options.
633+
COMPILER_STANDARDIZATION_OPTS = []
634+
635+
# When we're not using an appropriate target triple, use -m32 to get i386, which we
636+
# can mostly make work.
637+
if LLVM_TARGET != 'asmjs-unknown-emscripten' and LLVM_TARGET != 'le32-unknown-nacl':
638+
COMPILER_OPTS += ['-m32']
639+
COMPILER_STANDARDIZATION_OPTS += ['-U__i386__', '-U__i386', '-Ui386',
640+
'-U__SSE__', '-U__SSE_MATH__', '-U__SSE2__', '-U__SSE2_MATH__', '-U__MMX__',
641+
'-U__APPLE__', '-U__linux__']
642+
643+
# With the asmjs-unknown-emscripten target triple, clang sets up language modes
644+
# and predefined macros properly. When using the other targets, we have to set things
645+
# up manually.
646+
if LLVM_TARGET != 'asmjs-unknown-emscripten':
647+
COMPILER_OPTS += ['-fno-math-errno']
648+
COMPILER_STANDARDIZATION_OPTS += ['-D__IEEE_LITTLE_ENDIAN']
649+
if LLVM_TARGET == 'le32-unknown-nacl':
650+
COMPILER_OPTS += ['-DEMSCRIPTEN', '-D__EMSCRIPTEN__', '-fno-math-errno',
651+
'-U__native_client__', '-U__pnacl__', '-U__ELF__']
643652

644653
USE_EMSDK = not os.environ.get('EMMAKEN_NO_SDK')
645654

0 commit comments

Comments
 (0)