Skip to content

Commit e79dfa3

Browse files
committed
Merge commit 'd49c33882b1c60a4dda2b5eb160ea70e3dc08581'
2 parents 76dea30 + d49c338 commit e79dfa3

File tree

275 files changed

+9569
-633
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

275 files changed

+9569
-633
lines changed

ChangeLog.markdown

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,27 @@ Current trunk code
1414
- Emscripten-LLVM: https://github.com/kripken/emscripten-fastcomp/compare/1.27.1...incoming
1515
- Emscripten-Clang: https://github.com/kripken/emscripten-fastcomp-clang/compare/1.27.1...incoming
1616

17+
v1.28.3: 01/04/2015
18+
-------------------
19+
- embuilder.py tool
20+
- Many fixes for native optimizer on Windows
21+
- Perform LLVM LTO in a separate invocation of opt, so that it does not mix with legalization and other stuff we do at link time
22+
23+
v1.28.2: 12/17/2014
24+
-------------------
25+
- Enable native optimizer by default
26+
- Disable slow2asm legacy testing (asm.js mode in pre-fastcomp)
27+
28+
v1.28.1: 12/15/2014
29+
-------------------
30+
- Use a lot more MUSL math functions
31+
32+
v1.28.0: 12/12/2014
33+
-------------------
34+
35+
v1.27.2: 12/10/2014
36+
-------------------
37+
1738
v1.27.1: 11/20/2014
1839
-------------------
1940
- Migrated to upstream PNaCl LLVM+Clang 3.4 from the previous 3.3.

em++

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,5 @@ See emcc.py. This script forwards to there, noting that we want C++ and not C by
77
import os, subprocess, sys
88
from tools import shared
99

10-
os.environ['EMMAKEN_CXX'] = '1'
11-
exit(subprocess.call([shared.PYTHON, shared.EMCC] + sys.argv[1:]))
10+
exit(subprocess.call([shared.PYTHON, shared.EMCC] + sys.argv[1:] + ['--emscripten-cxx']))
1211

embuilder.py

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
#!/usr/bin/env python2
2+
3+
'''
4+
Tool to manage building of various useful things, such as libc, libc++, native optimizer, as well as fetch and build ports like zlib and sdl2
5+
'''
6+
7+
import os, sys
8+
import tools.shared as shared
9+
10+
if len(sys.argv) < 2 or sys.argv[1] in ['-v', '-help', '--help', '-?', '?']:
11+
print '''
12+
Emscripten System Builder Tool
13+
==============================
14+
15+
You can use this tool to manually build parts of the emscripten system
16+
environment. In general emcc will build them automatically on demand, so
17+
you do not strictly need to use this tool, but it gives you more control
18+
over the process (in particular, if emcc does this automatically, and you
19+
are running multiple build commands in parallel, confusion can occur).
20+
21+
Usage:
22+
23+
embuilder.py OPERATION TASK1 [TASK2..]
24+
25+
Available operations and tasks:
26+
27+
build libc
28+
libcxx
29+
libcxxabi
30+
gl
31+
struct_info
32+
native_optimizer
33+
zlib
34+
sdl2
35+
sdl2-image
36+
37+
It is also possible to build native_optimizer manually by using CMake. To
38+
do that, run
39+
40+
1. cd $EMSCRIPTEN/tools/optimizer
41+
2. cmake . -DCMAKE_BUILD_TYPE=Release
42+
3. make (or mingw32-make/vcbuild/msbuild on Windows)
43+
44+
and set up the location to the native optimizer in ~/.emscripten
45+
46+
'''
47+
sys.exit(0)
48+
49+
temp_files = shared.configuration.get_temp_files()
50+
51+
def build(src, result_libs, args=[]):
52+
temp = temp_files.get('.cpp').name
53+
open(temp, 'w').write(src)
54+
temp_js = temp_files.get('.js').name
55+
shared.Building.emcc(temp, args, output_filename=temp_js)
56+
assert os.path.exists(temp_js), 'failed to build file'
57+
for lib in result_libs:
58+
assert os.path.exists(shared.Cache.get_path(lib)), 'not seeing that requested library %s has been built' % lib
59+
60+
operation = sys.argv[1]
61+
62+
if operation == 'build':
63+
for what in sys.argv[2:]:
64+
shared.logging.info('building and verifying ' + what)
65+
if what == 'libc':
66+
build('''
67+
#include <string.h>
68+
#include <stdlib.h>
69+
int main() {
70+
return int(malloc(10)) + int(strchr("str", 'c'));
71+
}
72+
''', ['libc.bc', 'libcextra.bc'])
73+
elif what == 'libcxx':
74+
build('''
75+
#include <iostream>
76+
int main() {
77+
std::cout << "hello";
78+
return 0;
79+
}
80+
''', ['libcxx.bc'])
81+
elif what == 'libcxxabi':
82+
build('''
83+
struct X { int x; virtual void a() {} };
84+
struct Y : X { int y; virtual void a() { y = 10; }};
85+
int main(int argc, char **argv) {
86+
Y* y = dynamic_cast<Y*>((X*)argv[1]);
87+
y->a();
88+
return y->y;
89+
}
90+
''', ['libcxxabi.bc'])
91+
elif what == 'gl':
92+
build('''
93+
extern "C" { extern void* emscripten_GetProcAddress(const char *x); }
94+
int main() {
95+
return int(emscripten_GetProcAddress("waka waka"));
96+
}
97+
''', ['gl.bc'])
98+
elif what == 'struct_info':
99+
build('''
100+
int main() {}
101+
''', ['struct_info.compiled.json'])
102+
elif what == 'native_optimizer':
103+
build('''
104+
int main() {}
105+
''', ['optimizer.exe'], ['-O2'])
106+
elif what == 'zlib':
107+
build('''
108+
int main() {}
109+
''', [os.path.join('ports-builds', 'zlib', 'libz.a')], ['-s', 'USE_ZLIB=1'])
110+
elif what == 'sdl2':
111+
build('''
112+
int main() {}
113+
''', [os.path.join('ports-builds', 'sdl2', 'libsdl2.bc')], ['-s', 'USE_SDL=2'])
114+
elif what == 'sdl2-image':
115+
build('''
116+
int main() {}
117+
''', [os.path.join('ports-builds', 'sdl2-image', 'libsdl2_image.bc')], ['-s', 'USE_SDL=2', '-s', 'USE_SDL_IMAGE=2'])
118+
else:
119+
shared.logging.error('unfamiliar build target: ' + what)
120+
sys.exit(1)
121+
122+
shared.logging.info('...success')
123+
124+
else:
125+
shared.logging.error('unfamiliar operation: ' + operation)
126+
sys.exit(1)
127+

emcc

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ if DEBUG and LEAVE_INPUTS_RAW: logging.warning('leaving inputs raw')
104104
stdout = PIPE if not DEBUG else None # suppress output of child processes
105105
stderr = PIPE if not DEBUG else None # unless we are in DEBUG mode
106106

107+
EMCC_CXX = '--emscripten-cxx' in sys.argv
108+
sys.argv = filter(lambda x: x != '--emscripten-cxx', sys.argv)
109+
107110
shared.check_sanity(force=DEBUG)
108111

109112
# Handle some global flags
@@ -126,8 +129,6 @@ while response_file:
126129
break
127130

128131
if len(sys.argv) == 1 or '--help' in sys.argv:
129-
this = os.path.basename('em++' if os.environ.get('EMMAKEN_CXX') else 'emcc')
130-
131132
# Documentation for emcc and its options must be updated in:
132133
# site/source/docs/tools_reference/emcc.rst
133134
# A prebuilt local version of the documentation is available at:
@@ -212,7 +213,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG:
212213
if debug_configure: open(tempout, 'a').write('Forcing clang since uses fopen to write\n')
213214

214215
compiler = os.environ.get('CONFIGURE_CC') or (shared.CLANG if not use_js else shared.EMCC) # if CONFIGURE_CC is defined, use that. let's you use local gcc etc. if you need that
215-
if not ('CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX')):
216+
if not ('CXXCompiler' in ' '.join(sys.argv) or EMCC_CXX):
216217
compiler = shared.to_cc(compiler)
217218

218219
def filter_emscripten_options(argv):
@@ -276,7 +277,7 @@ else:
276277
CC = shared.to_cc(CXX)
277278

278279
# If we got here from a redirection through emmakenxx.py, then force a C++ compiler here
279-
if os.environ.get('EMMAKEN_CXX'):
280+
if EMCC_CXX:
280281
CC = CXX
281282

282283
CC_ADDITIONAL_ARGS = shared.COMPILER_OPTS
@@ -830,7 +831,7 @@ try:
830831
break
831832
if found: break
832833
if found: break
833-
if not found and lib not in ['GL', 'GLU', 'glut']: # whitelist our default libraries
834+
if not found and lib not in ['GL', 'GLU', 'glut', 'SDL']: # whitelist our default libraries
834835
logging.warning('emcc: cannot find library "%s"', lib)
835836

836837
# If not compiling to JS, then we are compiling to an intermediate bitcode objects or library, so
@@ -865,6 +866,8 @@ try:
865866
# Set ASM_JS default here so that we can override it from the command line.
866867
shared.Settings.ASM_JS = 1 if opt_level > 0 else 2
867868

869+
pre_fastcomp_opts = []
870+
868871
# Apply -s settings in newargs here (after optimization levels, so they can override them)
869872
for change in settings_changes:
870873
key, value = change.split('=')
@@ -902,7 +905,6 @@ try:
902905
logging.warning('jcache is deprecated and not supported in fastcomp (you should not need it anyhow), disabling')
903906
jcache = False
904907

905-
pre_fastcomp_opts = []
906908
fastcomp_opts = []
907909
if shared.Settings.NO_EXIT_RUNTIME:
908910
pre_fastcomp_opts += ['-emscripten-no-exit-runtime']
@@ -1235,6 +1237,11 @@ try:
12351237
if not shared.Building.can_inline(): link_opts.append('-disable-inlining')
12361238
# do not internalize in std-link-opts - it ignores internalize-public-api-list - and add a manual internalize
12371239
link_opts += ['-disable-internalize'] + shared.Building.get_safe_internalize() + ['-std-link-opts']
1240+
# execute it now, so it is done entirely before we get to the stage of legalization etc.
1241+
shared.Building.llvm_opt(final, pre_fastcomp_opts + link_opts)
1242+
if DEBUG: save_intermediate('lto', 'bc')
1243+
pre_fastcomp_opts = []
1244+
link_opts = []
12381245
else:
12391246
# At minimum remove dead functions etc., this potentially saves a lot in the size of the generated code (and the time to compile it)
12401247
link_opts += shared.Building.get_safe_internalize() + ['-globaldce']

emscripten-version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
1.28.0
1+
1.28.3
22

emscripten.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,20 +1096,19 @@ def make_emulated_param(i):
10961096
simdfloattypes = ['float32x4']
10971097
simdinttypes = ['int32x4']
10981098
simdtypes = simdfloattypes + simdinttypes
1099-
# TODO: mul
1100-
simdfuncs = ['add', 'sub', 'neg',
1099+
simdfuncs = ['add', 'sub', 'neg', 'mul',
11011100
'equal', 'lessThan', 'greaterThan',
11021101
'notEqual', 'lessThanOrEqual', 'greaterThanOrEqual',
11031102
'select', 'and', 'or', 'xor', 'not',
11041103
'splat', 'swizzle', 'shuffle',
11051104
'withX', 'withY', 'withZ', 'withW',
11061105
'load', 'store']
1107-
# TODO: fromInt32x4
1108-
simdfloatfuncs = simdfuncs + ['mul', 'div', 'min', 'max', 'minNum', 'maxNum', 'sqrt',
1109-
'abs', 'fromInt32x4Bits'];
1110-
# TODO: fromFloat32x4
1111-
# TODO: shiftLeftByScalar, shiftRightArithmeticByScalar, shiftLeftArithmeticByScalar
1112-
simdintfuncs = simdfuncs + ['fromFloat32x4Bits'];
1106+
simdfloatfuncs = simdfuncs + ['div', 'min', 'max', 'minNum', 'maxNum', 'sqrt',
1107+
'abs', 'fromInt32x4', 'fromInt32x4Bits'];
1108+
simdintfuncs = simdfuncs + ['fromFloat32x4', 'fromFloat32x4Bits',
1109+
'shiftRightArithmeticByScalar',
1110+
'shiftRightLogicalByScalar',
1111+
'shiftLeftByScalar'];
11131112
fundamentals = ['Math', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
11141113
if metadata['simd']:
11151114
fundamentals += ['SIMD']

site/source/docs/getting_started/FAQ.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ or
207207

208208
What happens in practice is that when code is ready to be run, we check for ``Module._main``. If present, we call it. If a ``main()`` function was compiled from C, it will be there (and it will be a JavaScript function). But, you can also just define a JavaScript function there, either will work.
209209

210+
Another option is to define an ``onRuntimeInitialized`` function,
211+
212+
Module['onRuntimeInitialized'] = function() { ... };
213+
214+
That method will be called when the runtime is ready and it is ok for you to call compiled code. In practice, that is exactly the same time at which ``main()`` would be called, so ``onRuntimeInitialized`` doesn't let you do anything new, but it can be convenient in some cases - for example, if you use ``onRuntimeInitialized`` and don't define a ``main()`` function, then the runtime will not be shut down after ``main()`` exits, and you can keep calling compiled methods (you can also have a ``main()`` and build with ``-s NO_EXIT_RUNTIME=1`` to keep the runtime from being shut down). Thus, for libraries, ``onRuntimeInitialized`` can be convenient.
210215

211216
.. _faq-dead-code-elimination:
212217

site/source/docs/getting_started/Tutorial.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ JavaScript is usually run in the sandboxed environment of a web browser, without
9696
Files that you want to access should be :ref:`preloaded <emcc-preload-file>` or :ref:`embedded <emcc-embed-file>` into the virtual file system. Preloading (or embedding) generates a virtual file system that corresponds to the file system structure at *compile* time, *relative to the current directory*.
9797

9898

99-
The `hello_world_file.cpp <https://github.com/kripken/emscripten/blob/master/tests/hello_world.cpp>`_ example shows how to load a file (both the test code and the file to be loaded shown below):
99+
The `hello_world_file.cpp <https://github.com/kripken/emscripten/blob/master/tests/hello_world_file.cpp>`_ example shows how to load a file (both the test code and the file to be loaded shown below):
100100

101101
.. include:: ../../../../tests/hello_world_file.cpp
102102
:literal:

site/source/docs/introducing_emscripten/release_notes.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ ChangeLog
1616

1717
The ChangeLog for Emscripten |release| (|today|) is listed below (master version `here <https://github.com/kripken/emscripten/blob/master/ChangeLog.markdown>`_).
1818

19-
.. include:: ../../../../ChangeLog
19+
.. include:: ../../../../ChangeLog.markdown
2020
:literal:
2121

2222

src/ecmascript_simd.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,11 @@
1919
*/
2020

2121
if (typeof SIMD === "undefined") {
22-
// SIMD module.
23-
var SIMD = {};
22+
// SIMD module. We don't use the var keyword here, so that we put the
23+
// SIMD object in the global scope even if this polyfill code is included
24+
// within some other scope. The theory is that we're anticipating a
25+
// future where SIMD is predefined in the global scope.
26+
SIMD = {};
2427
}
2528

2629
// private stuff.
@@ -254,7 +257,7 @@ if (typeof SIMD.float32x4.fromUnsignedInt32x4 === "undefined") {
254257
* @param {int32x4} t An instance of int32x4.
255258
* @return {float32x4} An unsigned integer to float conversion copy of t.
256259
*/
257-
SIMD.float32x4.fromInt32x4 = function(t) {
260+
SIMD.float32x4.fromUnsignedInt32x4 = function(t) {
258261
t = SIMD.int32x4(t);
259262
return SIMD.float32x4(t.x>>>0, t.y>>>0, t.z>>>0, t.w>>>0);
260263
}
@@ -385,7 +388,7 @@ if (typeof SIMD.float64x2.fromUnsignedInt32x4 === "undefined") {
385388
* @param {int32x4} t An instance of int32x4.
386389
* @return {float64x2} A float64x2 with .x>>>0 and .y>>>0 from t
387390
*/
388-
SIMD.float64x2.fromInt32x4 = function(t) {
391+
SIMD.float64x2.fromUnsignedInt32x4 = function(t) {
389392
t = SIMD.int32x4(t);
390393
return SIMD.float64x2(t.x>>>0, t.y>>>0);
391394
}
@@ -534,7 +537,7 @@ if (typeof SIMD.int32x4.fromFloat32x4ToUnsigned === "undefined") {
534537
* @param {float32x4} t An instance of float32x4.
535538
* @return {int32x4} with an unsigned integer to float conversion of t.
536539
*/
537-
SIMD.int32x4.fromFloat32x4 = function(t) {
540+
SIMD.int32x4.fromFloat32x4ToUnsigned = function(t) {
538541
t = SIMD.float32x4(t);
539542
return SIMD.int32x4(t.x>>>0, t.y>>>0, t.z>>>0, t.w>>>0);
540543
}
@@ -556,7 +559,7 @@ if (typeof SIMD.int32x4.fromFloat64x2ToUnsigned === "undefined") {
556559
* @param {float64x2} t An instance of float64x2.
557560
* @return {int32x4} An int32x4 with .x>>>0 and .y>>>0 from t
558561
*/
559-
SIMD.int32x4.fromFloat64x2 = function(t) {
562+
SIMD.int32x4.fromFloat64x2ToUnsigned = function(t) {
560563
t = SIMD.float64x2(t);
561564
return SIMD.int32x4(t.x>>>0, t.y>>>0, 0, 0);
562565
}
@@ -567,7 +570,7 @@ if (typeof SIMD.int32x4.fromInt16x8 === "undefined") {
567570
* @param {int16x8} t An instance of int16x8.
568571
* @return {int32x4} with the s0, s1, s2, and s3 from t, sign-extended
569572
*/
570-
SIMD.int32x4.fromFloat32x4 = function(t) {
573+
SIMD.int32x4.fromInt16x8 = function(t) {
571574
t = SIMD.int16x8(t);
572575
return SIMD.int32x4(t.s0, t.s1, t.s2, t.s3);
573576
}
@@ -578,8 +581,8 @@ if (typeof SIMD.int32x4.fromUnsignedInt8x16 === "undefined") {
578581
* @param {int8x16} t An instance of int8x16.
579582
* @return {int32x4} with the s0, s1, s2, and s3 from t, zero-extended
580583
*/
581-
SIMD.int32x4.fromFloat32x4 = function(t) {
582-
t = SIMD.intint8x16(t);
584+
SIMD.int32x4.fromUnsignedInt8x16 = function(t) {
585+
t = SIMD.int8x16(t);
583586
return SIMD.int32x4(t.s0>>>0, t.s1>>>0, t.s2>>>0, t.s3>>>0);
584587
}
585588
}
@@ -589,7 +592,7 @@ if (typeof SIMD.int32x4.fromUnsignedInt16x8 === "undefined") {
589592
* @param {int16x8} t An instance of int16x8.
590593
* @return {int32x4} with the s0, s1, s2, and s3 from t, zero-extended
591594
*/
592-
SIMD.int32x4.fromFloat32x4 = function(t) {
595+
SIMD.int32x4.fromUnsignedInt16x8 = function(t) {
593596
t = SIMD.int16x8(t);
594597
return SIMD.int32x4(t.s0>>>0, t.s1>>>0, t.s2>>>0, t.s3>>>0);
595598
}
@@ -600,8 +603,8 @@ if (typeof SIMD.int32x4.fromInt8x16 === "undefined") {
600603
* @param {int8x16} t An instance of int8x16.
601604
* @return {int32x4} with the s0, s1, s2, and s3 from t
602605
*/
603-
SIMD.int32x4.fromFloat32x4 = function(t) {
604-
t = SIMD.intint8x16(t);
606+
SIMD.int32x4.fromInt8x16 = function(t) {
607+
t = SIMD.int8x16(t);
605608
return SIMD.int32x4(t.s0, t.s1, t.s2, t.s3);
606609
}
607610
}

0 commit comments

Comments
 (0)