aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemcc10
-rwxr-xr-xemscripten.py14
-rwxr-xr-xtests/runner.py2
-rw-r--r--tools/js-optimizer.js3
-rw-r--r--tools/js_optimizer.py26
-rw-r--r--tools/shared.py4
6 files changed, 43 insertions, 16 deletions
diff --git a/emcc b/emcc
index d368a4e5..775e2fe4 100755
--- a/emcc
+++ b/emcc
@@ -1024,9 +1024,6 @@ try:
if bind:
shared.Settings.ASM_JS = 0
logging.warning('disabling asm.js because it is not compatible with embind yet')
- if closure:
- logging.warning('disabling closure because it is not compatible with asm.js code generation')
- closure = False
if shared.Settings.CORRECT_SIGNS != 1:
logging.warning('setting CORRECT_SIGNS to 1 for asm.js code generation')
shared.Settings.CORRECT_SIGNS = 1
@@ -1549,7 +1546,7 @@ try:
if shared.Settings.RELOOP and not shared.Settings.ASM_JS:
js_optimizer_queue += ['optimizeShiftsAggressive', get_eliminate()] # aggressive shifts optimization requires loops, it breaks on switches
- if closure:
+ if closure and not shared.Settings.ASM_JS:
flush_js_optimizer_queue()
logging.debug('running closure')
@@ -1560,13 +1557,16 @@ try:
logging.debug('running post-closure post-opts')
js_optimizer_queue += ['simplifyExpressionsPost']
- if not closure and shared.Settings.RELOOP and not keep_js_debug:
+ if (not closure or shared.Settings.ASM_JS) and shared.Settings.RELOOP and not keep_js_debug:
# do this if closure is not enabled (it gives similar speedups), and we do not need to keep debug info around
js_optimizer_queue += ['registerize']
if minify_whitespace:
js_optimizer_queue += ['compress']
+ if closure and shared.Settings.ASM_JS:
+ js_optimizer_queue += ['closure']
+
js_optimizer_queue += ['last']
flush_js_optimizer_queue()
diff --git a/emscripten.py b/emscripten.py
index 629bbe5f..8ffdf458 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -459,7 +459,7 @@ function invoke_%s(%s) {
%sModule.dynCall_%s(%s);
} catch(e) {
if (typeof e !== 'number' && e !== 'longjmp') throw e;
- asm.setThrew(1, 0);
+ asm["setThrew"](1, 0);
}
}
''' % (sig, args, 'return ' if sig[0] != 'v' else '', sig, args)
@@ -489,11 +489,11 @@ function invoke_%s(%s) {
asm_global_vars = ''.join([' var ' + g + '=env.' + g + '|0;\n' for g in basic_vars + global_vars]) + \
''.join([' var ' + g + '=+env.' + g + ';\n' for g in basic_float_vars])
# sent data
- the_global = '{ ' + ', '.join([math_fix(s) + ': ' + s for s in fundamentals]) + ' }'
- sending = '{ ' + ', '.join([math_fix(s) + ': ' + s for s in basic_funcs + global_funcs + basic_vars + basic_float_vars + global_vars]) + ' }'
+ the_global = '{ ' + ', '.join(['"' + math_fix(s) + '": ' + s for s in fundamentals]) + ' }'
+ sending = '{ ' + ', '.join(['"' + math_fix(s) + '": ' + s for s in basic_funcs + global_funcs + basic_vars + basic_float_vars + global_vars]) + ' }'
# received
if not simple:
- receiving = ';\n'.join(['var ' + s + ' = Module["' + s + '"] = asm.' + s for s in exported_implemented_functions + function_tables])
+ receiving = ';\n'.join(['var ' + s + ' = Module["' + s + '"] = asm["' + s + '"]' for s in exported_implemented_functions + function_tables])
else:
receiving = 'var _main = Module["_main"] = asm;'
@@ -565,9 +565,9 @@ var asm = (function(global, env, buffer) {
// EMSCRIPTEN_END_ASM
(%s, %s, buffer);
%s;
-Runtime.stackAlloc = function(size) { return asm.stackAlloc(size) };
-Runtime.stackSave = function() { return asm.stackSave() };
-Runtime.stackRestore = function(top) { asm.stackRestore(top) };
+Runtime.stackAlloc = function(size) { return asm['stackAlloc'](size) };
+Runtime.stackSave = function() { return asm['stackSave']() };
+Runtime.stackRestore = function(top) { asm['stackRestore'](top) };
''' % (pre_tables + '\n'.join(function_tables_impls) + '\n' + function_tables_defs.replace('\n', '\n '), exports, the_global, sending, receiving)]
# Set function table masks
diff --git a/tests/runner.py b/tests/runner.py
index f1a97d9a..68d66d35 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -9642,6 +9642,8 @@ Options that are modified or new in %s include:
# emcc -s RELOOP=1 src.cpp ==> should pass -s to emscripten.py. --typed-arrays is a convenient alias for -s USE_TYPED_ARRAYS
for params, test, text in [
+ (['-O2'], lambda generated: 'function intArrayToString' in generated, 'shell has unminified utilities'),
+ (['-O2', '--closure', '1'], lambda generated: 'function intArrayToString' not in generated, 'closure minifies the shell'),
(['-O2'], lambda generated: 'var b=0' in generated and not 'function _main' in generated, 'registerize/minify is run by default in -O2'),
(['-O2', '--minify', '0'], lambda generated: 'var b = 0' in generated and not 'function _main' in generated, 'minify is cancelled, but not registerize'),
(['-O2', '-g'], lambda generated: 'var b=0' not in generated and 'var b = 0' not in generated and 'function _main' in generated, 'registerize/minify is cancelled by -g'),
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index ce67da89..32ed1cce 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -2408,7 +2408,8 @@ var passes = {
compress: function() { compress = true },
noPrintMetadata: function() { printMetadata = false },
asm: function() { asm = true },
- last: function() { last = true }
+ last: function() { last = true },
+ closure: function(){} // handled in python
};
// Main
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index b11d0449..0452a725 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -129,7 +129,7 @@ def run_on_js(filename, passes, js_engine, jcache):
end_funcs_marker = '// EMSCRIPTEN_END_FUNCS\n'
start_funcs = js.find(start_funcs_marker)
end_funcs = js.rfind(end_funcs_marker)
- assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix)
+ #assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix)
asm_registerize = 'asm' in passes and 'registerize' in passes
if asm_registerize:
start_asm_marker = '// EMSCRIPTEN_START_ASM\n'
@@ -265,6 +265,30 @@ EMSCRIPTEN_FUNCS();
for filename in filenames: temp_files.note(filename)
+ if 'closure' in passes:
+ # run closure on the shell code, everything but what we js-optimize
+ start_asm = '// EMSCRIPTEN_START_ASM\n'
+ end_asm = '// EMSCRIPTEN_END_ASM\n'
+ closure_sep = 'wakaUnknownBefore(); var asm=wakaUnknownAfter(global,env,buffer)\n'
+
+ closuree = temp_files.get('.closure.js').name
+ c = open(closuree, 'w')
+ pre_1, pre_2 = pre.split(start_asm)
+ post_1, post_2 = post.split(end_asm)
+ c.write(pre_1)
+ c.write(closure_sep)
+ c.write(post_2)
+ c.close()
+ closured = shared.Building.closure_compiler(closuree, pretty='compress' not in passes)
+ temp_files.note(closured)
+ coutput = open(closured).read()
+ coutput = coutput.replace('wakaUnknownBefore();', '')
+ after = 'wakaUnknownAfter'
+ start = coutput.find(after)
+ end = coutput.find(')', start)
+ pre = coutput[:start] + '(function(global,env,buffer) {\n' + start_asm + pre_2[pre_2.find('{')+1:]
+ post = post_1[:post_1.rfind('}')] + '\n' + end_asm + '\n})' + coutput[end+1:]
+
filename += '.jo.js'
f = open(filename, 'w')
f.write(pre);
diff --git a/tools/shared.py b/tools/shared.py
index 228f1253..321fa073 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -1208,7 +1208,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
return js_optimizer.run(filename, passes, listify(NODE_JS), jcache)
@staticmethod
- def closure_compiler(filename):
+ def closure_compiler(filename, pretty=True):
if not os.path.exists(CLOSURE_COMPILER):
raise Exception('Closure compiler appears to be missing, looked at: ' + str(CLOSURE_COMPILER))
@@ -1218,10 +1218,10 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
'-Xmx' + (os.environ.get('JAVA_HEAP_SIZE') or '1024m'), # if you need a larger Java heap, use this environment variable
'-jar', CLOSURE_COMPILER,
'--compilation_level', 'ADVANCED_OPTIMIZATIONS',
- '--formatting', 'PRETTY_PRINT',
'--language_in', 'ECMASCRIPT5',
#'--variable_map_output_file', filename + '.vars',
'--js', filename, '--js_output_file', filename + '.cc.js']
+ if pretty: args += ['--formatting', 'PRETTY_PRINT']
if os.environ.get('EMCC_CLOSURE_ARGS'):
args += shlex.split(os.environ.get('EMCC_CLOSURE_ARGS'))
process = Popen(args, stdout=PIPE, stderr=STDOUT)