aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-03-08 16:17:52 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-03-08 16:17:52 -0800
commitb31addd3ab55af8dddb703580ebf5d2a90660c61 (patch)
tree8fa41ceb8447eb1ed7f19eae120a25d2993b7c73
parent50c7f9f00e4666860bf1f39181cc6f9133ef46bb (diff)
split out asm shell in js optimizer, in preparation for minification of globals
-rwxr-xr-xemscripten.py5
-rw-r--r--tools/js_optimizer.py34
2 files changed, 26 insertions, 13 deletions
diff --git a/emscripten.py b/emscripten.py
index 2291a65a..09a57e37 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -433,6 +433,7 @@ var asm = (function(global, env, buffer) {
var tempInt = 0, tempBigInt = 0, tempBigIntP = 0, tempBigIntS = 0, tempBigIntR = 0.0, tempBigIntI = 0, tempBigIntD = 0, tempValue = 0, tempDouble = 0.0;
''' + ''.join(['''
var tempRet%d = 0;''' % i for i in range(10)]) + '\n' + asm_global_funcs + '''
+// EMSCRIPTEN_START_FUNCS
function stackAlloc(size) {
size = size|0;
var ret = 0;
@@ -457,9 +458,7 @@ var asm = (function(global, env, buffer) {
value = value|0;
tempRet%d = value;
}
-''' % (i, i) for i in range(10)]) + '''
-// EMSCRIPTEN_START_FUNCS
-''' + funcs_js + '''
+''' % (i, i) for i in range(10)]) + funcs_js + '''
%s
return %s;
diff --git a/tools/js_optimizer.py b/tools/js_optimizer.py
index a7d9c1e1..4661580b 100644
--- a/tools/js_optimizer.py
+++ b/tools/js_optimizer.py
@@ -102,13 +102,14 @@ def run_on_js(filename, passes, js_engine, jcache):
start_funcs_marker = '// EMSCRIPTEN_START_FUNCS\n'
end_funcs_marker = '// EMSCRIPTEN_END_FUNCS\n'
start_funcs = js.find(start_funcs_marker)
- end_funcs = js.find(end_funcs_marker)
+ end_funcs = js.rfind(end_funcs_marker)
assert (start_funcs >= 0) == (end_funcs >= 0) == (not not suffix)
- if 'asm' in passes:
+ asm_registerize = 'asm' in passes and 'registerize' in passes
+ if asm_registerize:
start_asm_marker = '// EMSCRIPTEN_START_ASM\n'
end_asm_marker = '// EMSCRIPTEN_END_ASM\n'
start_asm = js.find(start_asm_marker)
- end_asm = js.find(end_asm_marker)
+ end_asm = js.rfind(end_asm_marker)
assert (start_asm >= 0) == (end_asm >= 0)
if not suffix and jcache:
@@ -119,13 +120,26 @@ def run_on_js(filename, passes, js_engine, jcache):
jcache = False
if suffix:
- pre = js[:start_funcs + len(start_funcs_marker)]
- post = js[end_funcs:]
- js = js[start_funcs + len(start_funcs_marker):end_funcs]
- if 'asm' not in passes: # can have Module[..] and inlining prevention code, push those to post
- for line in js.split('\n'):
- if len(line) > 0 and not line.startswith((' ', 'function', '}')):
- post = line + '\n' + post
+ if not asm_registerize:
+ pre = js[:start_funcs + len(start_funcs_marker)]
+ post = js[end_funcs:]
+ js = js[start_funcs + len(start_funcs_marker):end_funcs]
+ if 'asm' not in passes: # can have Module[..] and inlining prevention code, push those to post
+ for line in js.split('\n'):
+ if len(line) > 0 and not line.startswith((' ', 'function', '}')):
+ post = line + '\n' + post
+ else:
+ # We need to split out the asm shell as well, for minification
+ pre = js[:start_asm + len(start_asm_marker)]
+ post = js[end_asm:]
+ asm_shell = js[start_asm + len(start_asm_marker):start_funcs + len(start_funcs_marker)] + '''
+EMSCRIPTEN_FUNCS();
+''' + js[end_funcs + len(end_funcs_marker):end_asm + len(end_asm_marker)]
+ minified_asm_shell = asm_shell # TODO: minification of globals
+ asm_shell_pre, asm_shell_post = minified_asm_shell.split('EMSCRIPTEN_FUNCS();');
+ pre += asm_shell_pre
+ post = asm_shell_post + post
+ js = js[start_funcs + len(start_funcs_marker):end_funcs]
else:
pre = ''
post = ''