aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
Diffstat (limited to 'tools')
-rw-r--r--tools/find_bigfuncs.py2
-rw-r--r--tools/js-optimizer.js26
-rw-r--r--tools/shared.py9
-rw-r--r--tools/test-js-optimizer-asm-minlast-output.js2
-rw-r--r--tools/test-js-optimizer-asm-minlast.js8
5 files changed, 36 insertions, 11 deletions
diff --git a/tools/find_bigfuncs.py b/tools/find_bigfuncs.py
index c8e29833..79136343 100644
--- a/tools/find_bigfuncs.py
+++ b/tools/find_bigfuncs.py
@@ -18,6 +18,6 @@ for line in open(filename):
size = i - start
data.append([curr, size])
curr = None
-#data.sort(lambda x, y: x[1] - y[1])
+data.sort(lambda x, y: x[1] - y[1])
print ''.join(['%6d : %s' % (x[1], x[0]) for x in data])
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index e5e0d287..022bdf47 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -3788,11 +3788,27 @@ function asmLastOpts(ast) {
node[1] = simplifyNotCompsDirect(['unary-prefix', '!', conditionToBreak]);
return node;
}
- } else if (type == 'binary' && node[1] == '&' && node[3][0] == 'unary-prefix' && node[3][1] == '-' && node[3][2][0] == 'num' && node[3][2][1] == 1) {
- // Change &-1 into |0, at this point the hint is no longer needed
- node[1] = '|';
- node[3] = node[3][2];
- node[3][1] = 0;
+ } else if (type == 'binary') {
+ if (node[1] === '&') {
+ if (node[3][0] === 'unary-prefix' && node[3][1] === '-' && node[3][2][0] === 'num' && node[3][2][1] === 1) {
+ // Change &-1 into |0, at this point the hint is no longer needed
+ node[1] = '|';
+ node[3] = node[3][2];
+ node[3][1] = 0;
+ }
+ } else if (node[1] === '-' && node[3][0] === 'unary-prefix') {
+ // avoid X - (-Y) because some minifiers buggily emit X--Y which is invalid as -- can be a unary. Transform to
+ // X + Y
+ if (node[3][1] === '-') { // integer
+ node[1] = '+';
+ node[3] = node[3][2];
+ } else if (node[3][1] === '+') { // float
+ if (node[3][2][0] === 'unary-prefix' && node[3][2][1] === '-') {
+ node[1] = '+';
+ node[3][2] = node[3][2][2];
+ }
+ }
+ }
}
});
});
diff --git a/tools/shared.py b/tools/shared.py
index b3c3257b..c816f091 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -758,7 +758,6 @@ class Settings2(type):
self.attrs['ASM_JS'] = 1
self.attrs['ASSERTIONS'] = 0
self.attrs['DISABLE_EXCEPTION_CATCHING'] = 1
- if opt_level >= 2:
self.attrs['RELOOP'] = 1
self.attrs['ALIASING_FUNCTION_POINTERS'] = 1
if opt_level >= 3:
@@ -1425,11 +1424,11 @@ class Building:
emcc_leave_inputs_raw = os.environ.get('EMCC_LEAVE_INPUTS_RAW')
if emcc_leave_inputs_raw: del os.environ['EMCC_LEAVE_INPUTS_RAW']
- def make(opt_level):
+ def make(opt_level, reloop):
raw = relooper + '.raw.js'
Building.emcc(os.path.join('relooper', 'Relooper.cpp'), ['-I' + os.path.join('relooper'), '--post-js',
os.path.join('relooper', 'emscripten', 'glue.js'),
- '--memory-init-file', '0',
+ '--memory-init-file', '0', '-s', 'RELOOP=%d' % reloop,
'-s', 'EXPORTED_FUNCTIONS=["_rl_set_output_buffer","_rl_make_output_buffer","_rl_new_block","_rl_delete_block","_rl_block_add_branch_to","_rl_new_relooper","_rl_delete_relooper","_rl_relooper_add_block","_rl_relooper_calculate","_rl_relooper_render", "_rl_set_asm_js_mode"]',
'-s', 'DEFAULT_LIBRARY_FUNCS_TO_INCLUDE=["memcpy", "memset", "malloc", "free", "puts"]',
'-s', 'RELOOPER="' + relooper + '"',
@@ -1444,10 +1443,10 @@ class Building:
# bootstrap phase 1: generate unrelooped relooper, for which we do not need a relooper (so we cannot recurse infinitely in this function)
logging.info(' bootstrap phase 1')
- make(1)
+ make(2, 0)
# bootstrap phase 2: generate relooped relooper, using the unrelooped relooper (we see relooper.js exists so we cannot recurse infinitely in this function)
logging.info(' bootstrap phase 2')
- make(2)
+ make(2, 1)
logging.info('bootstrapping relooper succeeded')
logging.info('=======================================')
ok = True
diff --git a/tools/test-js-optimizer-asm-minlast-output.js b/tools/test-js-optimizer-asm-minlast-output.js
new file mode 100644
index 00000000..d25c6d9b
--- /dev/null
+++ b/tools/test-js-optimizer-asm-minlast-output.js
@@ -0,0 +1,2 @@
+function test($34){var $35=0;$35=$34+130.0;$35=$34+130;return $35|0}
+
diff --git a/tools/test-js-optimizer-asm-minlast.js b/tools/test-js-optimizer-asm-minlast.js
new file mode 100644
index 00000000..6d172899
--- /dev/null
+++ b/tools/test-js-optimizer-asm-minlast.js
@@ -0,0 +1,8 @@
+function test($34) {
+ var $35 = 0;
+ $35=($34)-((+-130));
+ $35=($34)-(-130);
+ return $35 | 0;
+}
+// EMSCRIPTEN_GENERATED_FUNCTIONS: ["test"]
+