aboutsummaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-06-20 18:15:36 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-06-20 18:15:36 -0700
commitc3ed656997ea4515d846debf45121af1bd174a51 (patch)
treede84436eba40aedf96ca8c091c743e0d7d79e965 /tools
parent0ad87244178badf26cd5c8e0ed88116e87026472 (diff)
parent97d19be7f46bb3b0862e575fc6e06abafca74df7 (diff)
Merge branch 'incoming'
Diffstat (limited to 'tools')
-rw-r--r--tools/file_packager.py42
-rw-r--r--tools/js-optimizer.js87
-rw-r--r--tools/shared.py19
-rw-r--r--tools/test-js-optimizer-asm-pre-output.js364
-rw-r--r--tools/test-js-optimizer-asm-pre.js361
5 files changed, 827 insertions, 46 deletions
diff --git a/tools/file_packager.py b/tools/file_packager.py
index 1443d165..cc030f59 100644
--- a/tools/file_packager.py
+++ b/tools/file_packager.py
@@ -39,7 +39,7 @@ TODO: You can also provide .crn files yourself, pre-crunched. With this o
to dds files in the browser, exactly the same as if this tool compressed them.
'''
-import os, sys, shutil, random, uuid
+import os, sys, shutil, random, uuid, ctypes
import shared
from shared import Compression, execute, suffix, unsuffixed
@@ -50,6 +50,8 @@ if len(sys.argv) == 1:
See the source for more details.'''
sys.exit(0)
+DEBUG = os.environ.get('EMCC_DEBUG')
+
data_target = sys.argv[1]
IMAGE_SUFFIXES = ('.jpg', '.png', '.bmp')
@@ -150,6 +152,32 @@ function assert(check, msg) {
}
'''
+# Win32 code to test whether the given file has the hidden property set.
+def has_hidden_attribute(filepath):
+ if sys.platform != 'win32':
+ return False
+
+ try:
+ attrs = ctypes.windll.kernel32.GetFileAttributesW(unicode(filepath))
+ assert attrs != -1
+ result = bool(attrs & 2)
+ except (AttributeError, AssertionError):
+ result = False
+ return result
+
+# The packager should never preload/embed any directories that have a component starting with '.' in them,
+# or if the file is hidden (Win32). Note that this filter ONLY applies to directories. Explicitly specified single files
+# are always preloaded/embedded, even if they start with a '.'.
+def should_ignore(filename):
+ if has_hidden_attribute(filename):
+ return True
+
+ components = filename.replace('\\\\', '/').replace('\\', '/').split('/')
+ for c in components:
+ if c.startswith('.') and c != '.' and c != '..':
+ return True
+ return False
+
# Expand directories into individual files
def add(arg, dirname, names):
# rootpathsrc: The path name of the root directory on the local FS we are adding to emscripten virtual FS.
@@ -158,8 +186,12 @@ def add(arg, dirname, names):
for name in names:
fullname = os.path.join(dirname, name)
if not os.path.isdir(fullname):
- dstpath = os.path.join(rootpathdst, os.path.relpath(fullname, rootpathsrc)) # Convert source filename relative to root directory of target FS.
- data_files.append({ 'srcpath': fullname, 'dstpath': dstpath, 'mode': mode })
+ if should_ignore(fullname):
+ if DEBUG:
+ print >> sys.stderr, 'Skipping hidden file "' + fullname + '" from inclusion in the emscripten virtual file system.'
+ else:
+ dstpath = os.path.join(rootpathdst, os.path.relpath(fullname, rootpathsrc)) # Convert source filename relative to root directory of target FS.
+ data_files.append({ 'srcpath': fullname, 'dstpath': dstpath, 'mode': mode })
for file_ in data_files:
if os.path.isdir(file_['srcpath']):
@@ -171,6 +203,8 @@ for file_ in data_files:
if file_['dstpath'].endswith('/'): # If user has submitted a directory name as the destination but omitted the destination filename, use the filename from source file
file_['dstpath'] = file_['dstpath'] + os.path.basename(file_['srcpath'])
if file_['dstpath'].startswith('./'): file_['dstpath'] = file_['dstpath'][2:] # remove redundant ./ prefix
+ if DEBUG:
+ print >> sys.stderr, 'Packaging file "' + file_['srcpath'] + '" to VFS in path "' + file_['dstpath'] + '".'
# Remove duplicates (can occur naively, for example preload dir/, preload dir/subdir/)
seen = {}
@@ -202,7 +236,7 @@ if crunch:
function requestDecrunch(filename, data, callback) {
decrunchWorker.postMessage({
filename: filename,
- data: data,
+ data: new Uint8Array(data),
callbackID: decrunchCallbacks.length
});
decrunchCallbacks.push(callback);
diff --git a/tools/js-optimizer.js b/tools/js-optimizer.js
index 07317e0a..b02ae3cc 100644
--- a/tools/js-optimizer.js
+++ b/tools/js-optimizer.js
@@ -429,19 +429,47 @@ function simplifyExpressionsPre(ast) {
// 'useful' mathops already |0 anyhow.
function simplifyBitops(ast) {
- var SAFE_BINARY_OPS = set('+', '-', '*'); // division is unsafe as it creates non-ints in JS; mod is unsafe as signs matter so we can't remove |0's
+ var SAFE_BINARY_OPS;
+ if (asm) {
+ SAFE_BINARY_OPS = set('+', '-'); // division is unsafe as it creates non-ints in JS; mod is unsafe as signs matter so we can't remove |0's; mul does not nest with +,- in asm
+ } else {
+ SAFE_BINARY_OPS = set('+', '-', '*');
+ }
+ var COERCION_REQUIRING_OPS = set('sub', 'unary-prefix'); // ops that in asm must be coerced right away
+ var COERCION_REQUIRING_BINARIES = set('*', '/', '%'); // binary ops that in asm must be coerced
var ZERO = ['num', 0];
- var rerun = true;
- while (rerun) {
- rerun = false;
- traverse(ast, function process(node, type, stack) {
- if (type == 'binary' && node[1] == '|') {
- if (node[2][0] == 'num' && node[3][0] == 'num') {
- return ['num', node[2][1] | node[3][1]];
- } else if (jsonCompare(node[2], ZERO) || jsonCompare(node[3], ZERO)) {
+
+ function removeMultipleOrZero() {
+ var rerun = true;
+ while (rerun) {
+ rerun = false;
+ traverse(ast, function process(node, type, stack) {
+ if (type == 'binary' && node[1] == '|') {
+ if (node[2][0] == 'num' && node[3][0] == 'num') {
+ return ['num', node[2][1] | node[3][1]];
+ }
+ var go = false;
+ if (jsonCompare(node[2], ZERO)) {
+ // canonicalize order
+ var temp = node[3];
+ node[3] = node[2];
+ node[2] = temp;
+ go = true;
+ } else if (jsonCompare(node[3], ZERO)) {
+ go = true;
+ }
+ if (!go) {
+ stack.push(1);
+ return;
+ }
// We might be able to remove this correction
for (var i = stack.length-1; i >= 0; i--) {
- if (stack[i] == 1) {
+ if (stack[i] >= 1) {
+ if (asm) {
+ if (stack[stack.length-1] < 2 && node[2][0] == 'call') break; // we can only remove multiple |0s on these
+ if (stack[stack.length-1] < 1 && (node[2][0] in COERCION_REQUIRING_OPS ||
+ (node[2][0] == 'binary' && node[2][1] in COERCION_REQUIRING_BINARIES))) break; // we can remove |0 or >>2
+ }
// we will replace ourselves with the non-zero side. Recursively process that node.
var result = jsonCompare(node[2], ZERO) ? node[3] : node[2], other;
// replace node in-place
@@ -453,23 +481,23 @@ function simplifyExpressionsPre(ast) {
return process(result, result[0], stack);
} else if (stack[i] == -1) {
break; // Too bad, we can't
- } else if (asm) {
- break; // we must keep a coercion right on top of a heap access in asm mode
}
}
+ stack.push(2); // From here on up, no need for this kind of correction, it's done at the top
+ // (Add this at the end, so it is only added if we did not remove it)
+ } else if (type == 'binary' && node[1] in USEFUL_BINARY_OPS) {
+ stack.push(1);
+ } else if ((type == 'binary' && node[1] in SAFE_BINARY_OPS) || type == 'num' || type == 'name') {
+ stack.push(0); // This node is safe in that it does not interfere with this optimization
+ } else {
+ stack.push(-1); // This node is dangerous! Give up if you see this before you see '1'
}
- stack.push(1); // From here on up, no need for this kind of correction, it's done at the top
- // (Add this at the end, so it is only added if we did not remove it)
- } else if (type == 'binary' && node[1] in USEFUL_BINARY_OPS) {
- stack.push(1);
- } else if ((type == 'binary' && node[1] in SAFE_BINARY_OPS) || type == 'num' || type == 'name') {
- stack.push(0); // This node is safe in that it does not interfere with this optimization
- } else {
- stack.push(-1); // This node is dangerous! Give up if you see this before you see '1'
- }
- }, null, []);
+ }, null, []);
+ }
}
+ removeMultipleOrZero();
+
// & and heap-related optimizations
var heapBits, heapUnsigned;
@@ -480,7 +508,7 @@ function simplifyExpressionsPre(ast) {
return true;
}
- var hasTempDoublePtr = false;
+ var hasTempDoublePtr = false, rerunOrZeroPass = false;
traverse(ast, function(node, type) {
if (type == 'name') {
@@ -515,7 +543,6 @@ function simplifyExpressionsPre(ast) {
node[2][0] == 'binary' && node[2][1] == '<<' && node[2][3][0] == 'num' &&
node[2][2][0] == 'sub' && node[2][2][1][0] == 'name') {
// collapse HEAPU?8[..] << 24 >> 24 etc. into HEAP8[..] | 0
- // TODO: run this before | 0 | 0 removal, because we generate | 0
var amount = node[3][1];
var name = node[2][2][1][1];
if (amount == node[2][3][1] && parseHeap(name)) {
@@ -524,6 +551,7 @@ function simplifyExpressionsPre(ast) {
node[1] = '|';
node[2] = node[2][2];
node[3][1] = 0;
+ rerunOrZeroPass = true;
return node;
}
}
@@ -556,6 +584,8 @@ function simplifyExpressionsPre(ast) {
}
});
+ if (rerunOrZeroPass) removeMultipleOrZero();
+
if (asm) {
if (hasTempDoublePtr) {
traverse(ast, function(node, type) {
@@ -707,18 +737,11 @@ function simplifyExpressionsPre(ast) {
}
function asmOpts(fun) {
- // 1. Add final returns when necessary
- // 2. Remove unneeded coercions on function calls that have no targets (eliminator removed it)
+ // Add final returns when necessary
var returnType = null;
traverse(fun, function(node, type) {
if (type == 'return' && node[1]) {
returnType = detectAsmCoercion(node[1]);
- } else if (type == 'stat') {
- var inner = node[1];
- if ((inner[0] == 'binary' && inner[1] in ASSOCIATIVE_BINARIES && inner[2][0] == 'call' && inner[3][0] == 'num') ||
- (inner[0] == 'unary-prefix' && inner[1] == '+' && inner[2][0] == 'call')) {
- node[1] = inner[2];
- }
}
});
// Add a final return if one is missing.
diff --git a/tools/shared.py b/tools/shared.py
index 8a172d9c..c16c9115 100644
--- a/tools/shared.py
+++ b/tools/shared.py
@@ -273,7 +273,7 @@ def check_llvm_version():
except Exception, e:
logging.warning('Could not verify LLVM version: %s' % str(e))
-EXPECTED_NODE_VERSION = (0,6,8)
+EXPECTED_NODE_VERSION = (0,8,0)
def check_node_version():
try:
@@ -295,7 +295,7 @@ def check_node_version():
# we re-check sanity when the settings are changed)
# We also re-check sanity and clear the cache when the version changes
-EMSCRIPTEN_VERSION = '1.4.9'
+EMSCRIPTEN_VERSION = '1.5.0'
def generate_sanity():
return EMSCRIPTEN_VERSION + '|' + get_llvm_target()
@@ -454,9 +454,12 @@ EMSCRIPTEN_TEMP_DIR = configuration.EMSCRIPTEN_TEMP_DIR
DEBUG_CACHE = configuration.DEBUG_CACHE
CANONICAL_TEMP_DIR = configuration.CANONICAL_TEMP_DIR
-level = logging.DEBUG if os.environ.get('EMCC_DEBUG') else logging.INFO
-logging.basicConfig(level=level, format='%(levelname)-8s %(name)s: %(message)s')
-
+logging.basicConfig(format='%(levelname)-8s %(name)s: %(message)s')
+def set_logging():
+ logger = logging.getLogger()
+ logger.setLevel(logging.DEBUG if os.environ.get('EMCC_DEBUG') else logging.INFO)
+set_logging()
+
if not EMSCRIPTEN_TEMP_DIR:
EMSCRIPTEN_TEMP_DIR = tempfile.mkdtemp(prefix='emscripten_temp_', dir=configuration.TEMP_DIR)
def clean_temp():
@@ -1091,7 +1094,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
@staticmethod
def can_build_standalone():
- return not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE
+ return not Settings.BUILD_AS_SHARED_LIB and not Settings.LINKABLE and not Settings.EXPORT_ALL
@staticmethod
def can_use_unsafe_opts():
@@ -1285,6 +1288,9 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
emcc_debug = os.environ.get('EMCC_DEBUG')
if emcc_debug: del os.environ['EMCC_DEBUG']
+ emcc_optimize_normally = os.environ.get('EMCC_OPTIMIZE_NORMALLY')
+ if emcc_optimize_normally: del os.environ['EMCC_OPTIMIZE_NORMALLY']
+
def make(opt_level):
raw = relooper + '.raw.js'
Building.emcc(os.path.join('relooper', 'Relooper.cpp'), ['-I' + os.path.join('relooper'), '--post-js',
@@ -1315,6 +1321,7 @@ set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY)''' % { 'winfix': '' if not WINDOWS e
finally:
os.chdir(curr)
if emcc_debug: os.environ['EMCC_DEBUG'] = emcc_debug
+ if emcc_optimize_normally: os.environ['EMCC_OPTIMIZE_NORMALLY'] = emcc_optimize_normally
if not ok:
logging.error('bootstrapping relooper failed. You may need to manually create relooper.js by compiling it, see src/relooper/emscripten')
1/0
diff --git a/tools/test-js-optimizer-asm-pre-output.js b/tools/test-js-optimizer-asm-pre-output.js
index 25d521ab..0e95580f 100644
--- a/tools/test-js-optimizer-asm-pre-output.js
+++ b/tools/test-js-optimizer-asm-pre-output.js
@@ -6,9 +6,19 @@ function a() {
f(8);
HEAP[1024] = 5;
HEAP[1024] = 5;
- whee(12, 13);
- whee(12, 13);
+ whee(12, 13) | 0;
+ +whee(12, 13);
f((g = t(), g + g | 0) | 0);
+ f() | 0;
+ f((h() | 0) + 5 | 0);
+ f(x + y + z | 0);
+ +f();
+ f(+(+h() + 5));
+ $140 = $p_3_i + (-$mantSize_0_i | 0) | 0;
+ f(g() | 0);
+ f(g() | 0 & -1);
+ f((g() | 0) >> 2);
+ $56 = _fcntl() | 0 | 1;
}
function b($this, $__n) {
$this = $this | 0;
@@ -34,7 +44,7 @@ function b($this, $__n) {
$23 = HEAP32[($this + 4 & 16777215) >> 2] | 0;
}
if (($14 - $23 | 0) >>> 0 < $__n >>> 0) {
- __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEjjjjjj($this, $14, ($__n - $14 | 0) + $23 | 0, $23, $23);
+ __ZNSt3__112basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEE9__grow_byEjjjjjj($this, $14, $__n - $14 + $23 | 0, $23, $23);
$30 = HEAP8[$4 & 16777215] | 0;
} else {
$30 = $13;
@@ -161,4 +171,352 @@ function boxx($this, $aabb, $xf, $childIndex) {
HEAPF32[$51 + 4 >> 2] = $_sroa_0_0_insert_insert$1;
return;
}
+function _main($argc, $argv) {
+ $argc = $argc | 0;
+ $argv = $argv | 0;
+ var $def_i21 = 0, $def_i = 0, $world = 0, $bd = 0, $shape = 0, $shape1 = 0, $bd2 = 0, $result = 0, $6 = 0, $WARMUP_0 = 0, $14 = 0, $15 = 0, $17 = 0, $i_09_i_i = 0, $j_08_i_i = 0, $34 = 0, $j_1_i_i = 0, $38 = 0, $46 = 0, $48 = 0, $50 = 0, $54 = 0, $i_05_i_i_i = 0, $56 = 0, $62 = 0, $_lcssa_i_i_i = 0, $87 = 0, $96 = 0, $97 = 0, $98 = 0, $112 = 0, $115 = 0, $116 = 0, $118 = 0, $121 = 0, $126 = 0, $135 = 0, $137 = 0, $174 = 0, $176 = 0, $177 = 0, $178 = 0, $179 = 0, $180 = 0, $181 = 0, $182 = 0, $183 = 0, $185 = 0, $186 = 0, $188 = 0, $189 = 0, $190 = 0, $191 = 0, $192 = 0, $193 = 0, $194 = 0, $195 = 0, $196 = 0, $i_057 = 0, $x_sroa_0_0_load303656 = +0, $x_sroa_1_4_load313755 = +0, $j_052 = 0, $y_sroa_0_0_load283451 = +0, $y_sroa_1_4_load293550 = +0, $y_sroa_0_0_insert_insert$1 = +0, $205 = 0, $208 = 0, $209 = 0, $213 = 0, $223 = 0, $236 = 0, $i3_042 = 0, $241 = 0, $242 = 0, $243 = 0, $i4_038 = 0, $245 = 0, $260 = +0, $_0 = 0, label = 0, __stackBase__ = 0;
+ __stackBase__ = STACKTOP;
+ STACKTOP = STACKTOP + 103416 | 0;
+ $def_i21 = __stackBase__ | 0;
+ $def_i = __stackBase__ + 32 | 0;
+ $world = __stackBase__ + 64 | 0;
+ $bd = __stackBase__ + 103096 | 0;
+ $shape = __stackBase__ + 103152 | 0;
+ $shape1 = __stackBase__ + 103200 | 0;
+ $bd2 = __stackBase__ + 103352 | 0;
+ $result = __stackBase__ + 103408 | 0;
+ do {
+ if (($argc | 0) > 1) {
+ $6 = HEAP8[HEAP32[$argv + 4 >> 2] | 0] | 0;
+ if (($6 | 0) == 49) {
+ HEAP32[2414] = 35;
+ $WARMUP_0 = 5;
+ break;
+ } else if (($6 | 0) == 50) {
+ HEAP32[2414] = 161;
+ $WARMUP_0 = 32;
+ break;
+ } else if (($6 | 0) == 51) {
+ label = 43;
+ break;
+ } else if (($6 | 0) == 52) {
+ HEAP32[2414] = 2331;
+ $WARMUP_0 = 320;
+ break;
+ } else if (($6 | 0) == 53) {
+ HEAP32[2414] = 5661;
+ $WARMUP_0 = 640;
+ break;
+ } else if (($6 | 0) == 48) {
+ $_0 = 0;
+ STACKTOP = __stackBase__;
+ return $_0 | 0;
+ } else {
+ _printf(3512, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[tempInt >> 2] = $6 - 48, tempInt) | 0) | 0;
+ $_0 = -1;
+ STACKTOP = __stackBase__;
+ return $_0 | 0;
+ }
+ } else {
+ label = 43;
+ }
+ } while (0);
+ if ((label | 0) == 43) {
+ HEAP32[2414] = 333;
+ $WARMUP_0 = 64;
+ }
+ $14 = $world | 0;
+ $15 = $world + 8 | 0;
+ HEAP32[$15 >> 2] = 128;
+ HEAP32[$world + 4 >> 2] = 0;
+ $17 = _malloc(1024) | 0;
+ HEAP32[$world >> 2] = $17;
+ _memset($17 | 0, 0, HEAP32[$15 >> 2] << 3 | 0);
+ _memset($world + 12 | 0, 0, 56);
+ $j_08_i_i = 0;
+ $i_09_i_i = 1;
+ while (1) {
+ if (!(($j_08_i_i | 0) < 14)) {
+ label = 49;
+ break;
+ }
+ if (($i_09_i_i | 0) > (HEAP32[9600 + ($j_08_i_i << 2) >> 2] | 0)) {
+ $34 = $j_08_i_i + 1 | 0;
+ HEAP8[$i_09_i_i + 8952 | 0] = $34 & 255;
+ $j_1_i_i = $34;
+ } else {
+ HEAP8[$i_09_i_i + 8952 | 0] = $j_08_i_i & 255;
+ $j_1_i_i = $j_08_i_i;
+ }
+ $38 = $i_09_i_i + 1 | 0;
+ if (($38 | 0) < 641) {
+ $j_08_i_i = $j_1_i_i;
+ $i_09_i_i = $38;
+ } else {
+ break;
+ }
+ }
+ if ((label | 0) == 49) {
+ ___assert_func(3248, 73, 6448, 3360);
+ return 0;
+ }
+ HEAP32[$world + 102468 >> 2] = 0;
+ HEAP32[$world + 102472 >> 2] = 0;
+ HEAP32[$world + 102476 >> 2] = 0;
+ HEAP32[$world + 102864 >> 2] = 0;
+ HEAP32[$world + 102872 >> 2] = -1;
+ $46 = $world + 102884 | 0;
+ HEAP32[$46 >> 2] = 16;
+ HEAP32[$world + 102880 >> 2] = 0;
+ $48 = _malloc(576) | 0;
+ $50 = $world + 102876 | 0;
+ HEAP32[$50 >> 2] = $48;
+ _memset($48 | 0, 0, (HEAP32[$46 >> 2] | 0) * 36 & -1 | 0);
+ $54 = (HEAP32[$46 >> 2] | 0) - 1 | 0;
+ if (($54 | 0) > 0) {
+ $i_05_i_i_i = 0;
+ while (1) {
+ $56 = $i_05_i_i_i + 1 | 0;
+ HEAP32[(HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 20 >> 2] = $56;
+ HEAP32[(HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 32 >> 2] = -1;
+ $62 = (HEAP32[$46 >> 2] | 0) - 1 | 0;
+ if (($56 | 0) < ($62 | 0)) {
+ $i_05_i_i_i = $56;
+ } else {
+ $_lcssa_i_i_i = $62;
+ break;
+ }
+ }
+ } else {
+ $_lcssa_i_i_i = $54;
+ }
+ HEAP32[(HEAP32[$50 >> 2] | 0) + ($_lcssa_i_i_i * 36 & -1) + 20 >> 2] = -1;
+ HEAP32[(HEAP32[$50 >> 2] | 0) + (((HEAP32[$46 >> 2] | 0) - 1 | 0) * 36 & -1) + 32 >> 2] = -1;
+ _memset($world + 102888 | 0, 0, 16);
+ HEAP32[$world + 102920 >> 2] = 16;
+ HEAP32[$world + 102924 >> 2] = 0;
+ HEAP32[$world + 102916 >> 2] = _malloc(192) | 0;
+ HEAP32[$world + 102908 >> 2] = 16;
+ HEAP32[$world + 102912 >> 2] = 0;
+ HEAP32[$world + 102904 >> 2] = _malloc(64) | 0;
+ HEAP32[$world + 102932 >> 2] = 0;
+ HEAP32[$world + 102936 >> 2] = 0;
+ HEAP32[$world + 102940 >> 2] = 104;
+ HEAP32[$world + 102944 >> 2] = 96;
+ $87 = $world + 102948 | 0;
+ HEAP32[$world + 102980 >> 2] = 0;
+ HEAP32[$world + 102984 >> 2] = 0;
+ _memset($87 | 0, 0, 20);
+ HEAP8[$world + 102992 | 0] = 1;
+ HEAP8[$world + 102993 | 0] = 1;
+ HEAP8[$world + 102994 | 0] = 0;
+ HEAP8[$world + 102995 | 0] = 1;
+ $96 = $world + 102976 | 0;
+ HEAP8[$96] = 1;
+ $97 = $world + 102968 | 0;
+ HEAP32[$97 >> 2] = 0;
+ HEAP32[$97 + 4 >> 2] = -1054867456;
+ $98 = $world + 102868 | 0;
+ HEAP32[$98 >> 2] = 4;
+ HEAPF32[$world + 102988 >> 2] = +0;
+ HEAP32[$87 >> 2] = $14;
+ _memset($world + 102996 | 0, 0, 32);
+ HEAP8[$96] = 0;
+ HEAP32[$bd + 44 >> 2] = 0;
+ _memset($bd + 4 | 0, 0, 32);
+ HEAP8[$bd + 36 | 0] = 1;
+ HEAP8[$bd + 37 | 0] = 1;
+ HEAP8[$bd + 38 | 0] = 0;
+ HEAP8[$bd + 39 | 0] = 0;
+ HEAP32[$bd >> 2] = 0;
+ HEAP8[$bd + 40 | 0] = 1;
+ HEAPF32[$bd + 48 >> 2] = +1;
+ $112 = __ZN16b2BlockAllocator8AllocateEi($14, 152) | 0;
+ if (($112 | 0) == 0) {
+ $116 = 0;
+ } else {
+ $115 = $112;
+ __ZN6b2BodyC2EPK9b2BodyDefP7b2World($115, $bd, $world);
+ $116 = $115;
+ }
+ HEAP32[$116 + 92 >> 2] = 0;
+ $118 = $world + 102952 | 0;
+ HEAP32[$116 + 96 >> 2] = HEAP32[$118 >> 2];
+ $121 = HEAP32[$118 >> 2] | 0;
+ if (!(($121 | 0) == 0)) {
+ HEAP32[$121 + 92 >> 2] = $116;
+ }
+ HEAP32[$118 >> 2] = $116;
+ $126 = $world + 102960 | 0;
+ HEAP32[$126 >> 2] = (HEAP32[$126 >> 2] | 0) + 1;
+ HEAP32[$shape >> 2] = 8016;
+ HEAP32[$shape + 4 >> 2] = 1;
+ HEAPF32[$shape + 8 >> 2] = +.009999999776482582;
+ _memset($shape + 28 | 0, 0, 18);
+ $135 = $shape + 12 | 0;
+ HEAP32[$135 >> 2] = -1038090240;
+ HEAP32[$135 + 4 >> 2] = 0;
+ $137 = $shape + 20 | 0;
+ HEAP32[$137 >> 2] = 1109393408;
+ HEAP32[$137 + 4 >> 2] = 0;
+ HEAP8[$shape + 44 | 0] = 0;
+ HEAP8[$shape + 45 | 0] = 0;
+ HEAP16[$def_i + 22 >> 1] = 1;
+ HEAP16[$def_i + 24 >> 1] = -1;
+ HEAP16[$def_i + 26 >> 1] = 0;
+ HEAP32[$def_i + 4 >> 2] = 0;
+ HEAPF32[$def_i + 8 >> 2] = +.20000000298023224;
+ HEAPF32[$def_i + 12 >> 2] = +0;
+ HEAP8[$def_i + 20 | 0] = 0;
+ HEAP32[$def_i >> 2] = $shape;
+ HEAPF32[$def_i + 16 >> 2] = +0;
+ __ZN6b2Body13CreateFixtureEPK12b2FixtureDef($116, $def_i);
+ HEAP32[$shape1 >> 2] = 7968;
+ HEAP32[$shape1 + 4 >> 2] = 2;
+ HEAPF32[$shape1 + 8 >> 2] = +.009999999776482582;
+ HEAP32[$shape1 + 148 >> 2] = 4;
+ HEAPF32[$shape1 + 20 >> 2] = +-.5;
+ HEAPF32[$shape1 + 24 >> 2] = +-.5;
+ HEAPF32[$shape1 + 28 >> 2] = +.5;
+ HEAPF32[$shape1 + 32 >> 2] = +-.5;
+ HEAPF32[$shape1 + 36 >> 2] = +.5;
+ HEAPF32[$shape1 + 40 >> 2] = +.5;
+ HEAPF32[$shape1 + 44 >> 2] = +-.5;
+ HEAPF32[$shape1 + 48 >> 2] = +.5;
+ HEAPF32[$shape1 + 84 >> 2] = +0;
+ HEAPF32[$shape1 + 88 >> 2] = +-1;
+ HEAPF32[$shape1 + 92 >> 2] = +1;
+ HEAPF32[$shape1 + 96 >> 2] = +0;
+ HEAPF32[$shape1 + 100 >> 2] = +0;
+ HEAPF32[$shape1 + 104 >> 2] = +1;
+ HEAPF32[$shape1 + 108 >> 2] = +-1;
+ HEAPF32[$shape1 + 112 >> 2] = +0;
+ HEAPF32[$shape1 + 12 >> 2] = +0;
+ HEAPF32[$shape1 + 16 >> 2] = +0;
+ $174 = $bd2 + 44 | 0;
+ $176 = $bd2 + 36 | 0;
+ $177 = $bd2 + 4 | 0;
+ $178 = $bd2 + 37 | 0;
+ $179 = $bd2 + 38 | 0;
+ $180 = $bd2 + 39 | 0;
+ $181 = $bd2 | 0;
+ $182 = $bd2 + 40 | 0;
+ $183 = $bd2 + 48 | 0;
+ $185 = $bd2 + 4 | 0;
+ $186 = $shape1 | 0;
+ $188 = $def_i21 + 22 | 0;
+ $189 = $def_i21 + 24 | 0;
+ $190 = $def_i21 + 26 | 0;
+ $191 = $def_i21 | 0;
+ $192 = $def_i21 + 4 | 0;
+ $193 = $def_i21 + 8 | 0;
+ $194 = $def_i21 + 12 | 0;
+ $195 = $def_i21 + 16 | 0;
+ $196 = $def_i21 + 20 | 0;
+ $x_sroa_1_4_load313755 = +.75;
+ $x_sroa_0_0_load303656 = +-7;
+ $i_057 = 0;
+ L82 : while (1) {
+ $y_sroa_1_4_load293550 = $x_sroa_1_4_load313755;
+ $y_sroa_0_0_load283451 = $x_sroa_0_0_load303656;
+ $j_052 = $i_057;
+ while (1) {
+ HEAP32[$174 >> 2] = 0;
+ _memset($177 | 0, 0, 32);
+ HEAP8[$176] = 1;
+ HEAP8[$178] = 1;
+ HEAP8[$179] = 0;
+ HEAP8[$180] = 0;
+ HEAP8[$182] = 1;
+ HEAPF32[$183 >> 2] = +1;
+ HEAP32[$181 >> 2] = 2;
+ $y_sroa_0_0_insert_insert$1 = +$y_sroa_1_4_load293550;
+ HEAPF32[$185 >> 2] = $y_sroa_0_0_load283451;
+ HEAPF32[$185 + 4 >> 2] = $y_sroa_0_0_insert_insert$1;
+ if (!((HEAP32[$98 >> 2] & 2 | 0) == 0)) {
+ label = 65;
+ break L82;
+ }
+ $205 = __ZN16b2BlockAllocator8AllocateEi($14, 152) | 0;
+ if (($205 | 0) == 0) {
+ $209 = 0;
+ } else {
+ $208 = $205;
+ __ZN6b2BodyC2EPK9b2BodyDefP7b2World($208, $bd2, $world);
+ $209 = $208;
+ }
+ HEAP32[$209 + 92 >> 2] = 0;
+ HEAP32[$209 + 96 >> 2] = HEAP32[$118 >> 2];
+ $213 = HEAP32[$118 >> 2] | 0;
+ if (!(($213 | 0) == 0)) {
+ HEAP32[$213 + 92 >> 2] = $209;
+ }
+ HEAP32[$118 >> 2] = $209;
+ HEAP32[$126 >> 2] = (HEAP32[$126 >> 2] | 0) + 1;
+ HEAP16[$188 >> 1] = 1;
+ HEAP16[$189 >> 1] = -1;
+ HEAP16[$190 >> 1] = 0;
+ HEAP32[$192 >> 2] = 0;
+ HEAPF32[$193 >> 2] = +.20000000298023224;
+ HEAPF32[$194 >> 2] = +0;
+ HEAP8[$196] = 0;
+ HEAP32[$191 >> 2] = $186;
+ HEAPF32[$195 >> 2] = +5;
+ __ZN6b2Body13CreateFixtureEPK12b2FixtureDef($209, $def_i21);
+ $223 = $j_052 + 1 | 0;
+ if (($223 | 0) < 40) {
+ $y_sroa_1_4_load293550 = $y_sroa_1_4_load293550 + +0;
+ $y_sroa_0_0_load283451 = $y_sroa_0_0_load283451 + 1.125;
+ $j_052 = $223;
+ } else {
+ break;
+ }
+ }
+ $236 = $i_057 + 1 | 0;
+ if (($236 | 0) < 40) {
+ $x_sroa_1_4_load313755 = $x_sroa_1_4_load313755 + +1;
+ $x_sroa_0_0_load303656 = $x_sroa_0_0_load303656 + +.5625;
+ $i_057 = $236;
+ } else {
+ $i3_042 = 0;
+ break;
+ }
+ }
+ if ((label | 0) == 65) {
+ ___assert_func(112, 109, 5328, 2520);
+ return 0;
+ }
+ while (1) {
+ __ZN7b2World4StepEfii($world);
+ $i3_042 = $i3_042 + 1 | 0;
+ if (($i3_042 | 0) >= ($WARMUP_0 | 0)) {
+ break;
+ }
+ }
+ $241 = HEAP32[2414] | 0;
+ $242 = _llvm_stacksave() | 0;
+ $243 = STACKTOP;
+ STACKTOP = STACKTOP + ($241 * 4 & -1) | 0;
+ STACKTOP = STACKTOP + 7 >> 3 << 3;
+ if (($241 | 0) > 0) {
+ $i4_038 = 0;
+ while (1) {
+ $245 = _clock() | 0;
+ __ZN7b2World4StepEfii($world);
+ HEAP32[$243 + ($i4_038 << 2) >> 2] = (_clock() | 0) - $245;
+ $i4_038 = $i4_038 + 1 | 0;
+ if (($i4_038 | 0) >= (HEAP32[2414] | 0)) {
+ break;
+ }
+ }
+ }
+ __Z7measurePm($result, $243);
+ $260 = +HEAPF32[$result + 4 >> 2];
+ _printf(3480, (tempInt = STACKTOP, STACKTOP = STACKTOP + 16 | 0, HEAPF64[tempInt >> 3] = +HEAPF32[$result >> 2], HEAPF64[tempInt + 8 >> 3] = $260, tempInt) | 0) | 0;
+ _llvm_stackrestore($242 | 0);
+ __ZN7b2WorldD2Ev($world);
+ $_0 = 0;
+ STACKTOP = __stackBase__;
+ return $_0 | 0;
+}
diff --git a/tools/test-js-optimizer-asm-pre.js b/tools/test-js-optimizer-asm-pre.js
index 38487d2f..4f3ba780 100644
--- a/tools/test-js-optimizer-asm-pre.js
+++ b/tools/test-js-optimizer-asm-pre.js
@@ -9,6 +9,17 @@ function a() {
whee(12, 13) | 0;
+whee(12, 13);
f((g = t(), (g+g)|0)|0);
+ // always coerce function calls in asm
+ f() | 0;
+ f((h() | 0) + 5 | 0);
+ f(((x + y) | 0) + z | 0);
+ +f();
+ f(+(+h() + 5));
+ $140 = $p_3_i + (-$mantSize_0_i | 0) | 0;
+ f(g() | 0 | 0);
+ f(g() | 0 & -1);
+ f((g() | 0) >> 2);
+ $56 = (_fcntl() | 0) | 1;
}
function b($this, $__n) {
$this = $this | 0;
@@ -165,4 +176,352 @@ function boxx($this, $aabb, $xf, $childIndex) {
HEAP32[$51 + 4 >> 2] = $_sroa_0_0_insert_insert$1;
return;
}
-// EMSCRIPTEN_GENERATED_FUNCTIONS: ["a", "b", "rett", "ret2t", "retf", "i32_8", "tempDoublePtr", "boxx"]
+function _main($argc, $argv) {
+ $argc = $argc | 0;
+ $argv = $argv | 0;
+ var $def_i21 = 0, $def_i = 0, $world = 0, $bd = 0, $shape = 0, $shape1 = 0, $bd2 = 0, $result = 0, $6 = 0, $WARMUP_0 = 0, $14 = 0, $15 = 0, $17 = 0, $i_09_i_i = 0, $j_08_i_i = 0, $34 = 0, $j_1_i_i = 0, $38 = 0, $46 = 0, $48 = 0, $50 = 0, $54 = 0, $i_05_i_i_i = 0, $56 = 0, $62 = 0, $_lcssa_i_i_i = 0, $87 = 0, $96 = 0, $97 = 0, $98 = 0, $112 = 0, $115 = 0, $116 = 0, $118 = 0, $121 = 0, $126 = 0, $135 = 0, $137 = 0, $174 = 0, $176 = 0, $177 = 0, $178 = 0, $179 = 0, $180 = 0, $181 = 0, $182 = 0, $183 = 0, $185 = 0, $186 = 0, $188 = 0, $189 = 0, $190 = 0, $191 = 0, $192 = 0, $193 = 0, $194 = 0, $195 = 0, $196 = 0, $i_057 = 0, $x_sroa_0_0_load303656 = +0, $x_sroa_1_4_load313755 = +0, $j_052 = 0, $y_sroa_0_0_load283451 = +0, $y_sroa_1_4_load293550 = +0, $y_sroa_0_0_insert_insert$1 = 0, $205 = 0, $208 = 0, $209 = 0, $213 = 0, $223 = 0, $236 = 0, $i3_042 = 0, $241 = 0, $242 = 0, $243 = 0, $i4_038 = 0, $245 = 0, $260 = +0, $_0 = 0, label = 0, __stackBase__ = 0;
+ __stackBase__ = STACKTOP;
+ STACKTOP = STACKTOP + 103416 | 0;
+ $def_i21 = __stackBase__ | 0;
+ $def_i = __stackBase__ + 32 | 0;
+ $world = __stackBase__ + 64 | 0;
+ $bd = __stackBase__ + 103096 | 0;
+ $shape = __stackBase__ + 103152 | 0;
+ $shape1 = __stackBase__ + 103200 | 0;
+ $bd2 = __stackBase__ + 103352 | 0;
+ $result = __stackBase__ + 103408 | 0;
+ do {
+ if (($argc | 0) > 1) {
+ $6 = (HEAP8[HEAP32[($argv + 4 | 0) >> 2] | 0] | 0) << 24 >> 24;
+ if (($6 | 0 | 0) == (49 | 0)) {
+ HEAP32[9656 >> 2] = 35;
+ $WARMUP_0 = 5;
+ break;
+ } else if (($6 | 0 | 0) == (50 | 0)) {
+ HEAP32[9656 >> 2] = 161;
+ $WARMUP_0 = 32;
+ break;
+ } else if (($6 | 0 | 0) == (51 | 0)) {
+ label = 43;
+ break;
+ } else if (($6 | 0 | 0) == (52 | 0)) {
+ HEAP32[9656 >> 2] = 2331;
+ $WARMUP_0 = 320;
+ break;
+ } else if (($6 | 0 | 0) == (53 | 0)) {
+ HEAP32[9656 >> 2] = 5661;
+ $WARMUP_0 = 640;
+ break;
+ } else if (($6 | 0 | 0) == (48 | 0)) {
+ $_0 = 0;
+ STACKTOP = __stackBase__;
+ return $_0 | 0;
+ } else {
+ _printf(3512 | 0 | 0, (tempInt = STACKTOP, STACKTOP = STACKTOP + 8 | 0, HEAP32[tempInt >> 2] = $6 - 48 | 0, tempInt) | 0) | 0;
+ $_0 = -1;
+ STACKTOP = __stackBase__;
+ return $_0 | 0;
+ }
+ } else {
+ label = 43;
+ }
+ } while (0);
+ if ((label | 0) == 43) {
+ HEAP32[9656 >> 2] = 333;
+ $WARMUP_0 = 64;
+ }
+ $14 = $world | 0;
+ $15 = $world + 8 | 0;
+ HEAP32[$15 >> 2] = 128;
+ HEAP32[($world + 4 | 0) >> 2] = 0;
+ $17 = _malloc(1024) | 0;
+ HEAP32[($world | 0) >> 2] = $17;
+ _memset($17 | 0 | 0, 0 | 0 | 0, (HEAP32[$15 >> 2] | 0) << 3 | 0 | 0);
+ _memset($world + 12 | 0 | 0 | 0, 0 | 0 | 0, 56 | 0 | 0);
+ $j_08_i_i = 0;
+ $i_09_i_i = 1;
+ while (1) {
+ if (!(($j_08_i_i | 0) < 14)) {
+ label = 49;
+ break;
+ }
+ if (($i_09_i_i | 0) > (HEAP32[(9600 + ($j_08_i_i << 2) | 0) >> 2] | 0 | 0)) {
+ $34 = $j_08_i_i + 1 | 0;
+ HEAP8[$i_09_i_i + 8952 | 0] = $34 & 255;
+ $j_1_i_i = $34;
+ } else {
+ HEAP8[$i_09_i_i + 8952 | 0] = $j_08_i_i & 255;
+ $j_1_i_i = $j_08_i_i;
+ }
+ $38 = $i_09_i_i + 1 | 0;
+ if (($38 | 0) < 641) {
+ $j_08_i_i = $j_1_i_i;
+ $i_09_i_i = $38;
+ } else {
+ break;
+ }
+ }
+ if ((label | 0) == 49) {
+ ___assert_func(3248 | 0 | 0, 73 | 0, 6448 | 0 | 0, 3360 | 0 | 0);
+ return 0 | 0;
+ }
+ HEAP32[($world + 102468 | 0) >> 2] = 0;
+ HEAP32[($world + 102472 | 0) >> 2] = 0;
+ HEAP32[($world + 102476 | 0) >> 2] = 0;
+ HEAP32[($world + 102864 | 0) >> 2] = 0;
+ HEAP32[($world + 102872 | 0) >> 2] = -1;
+ $46 = $world + 102884 | 0;
+ HEAP32[$46 >> 2] = 16;
+ HEAP32[($world + 102880 | 0) >> 2] = 0;
+ $48 = _malloc(576) | 0;
+ $50 = $world + 102876 | 0;
+ HEAP32[$50 >> 2] = $48;
+ _memset($48 | 0 | 0, 0 | 0 | 0, (HEAP32[$46 >> 2] | 0) * 36 & -1 | 0 | 0);
+ $54 = (HEAP32[$46 >> 2] | 0) - 1 | 0;
+ if (($54 | 0) > 0) {
+ $i_05_i_i_i = 0;
+ while (1) {
+ $56 = $i_05_i_i_i + 1 | 0;
+ HEAP32[((HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 20 | 0) >> 2] = $56;
+ HEAP32[((HEAP32[$50 >> 2] | 0) + ($i_05_i_i_i * 36 & -1) + 32 | 0) >> 2] = -1;
+ $62 = (HEAP32[$46 >> 2] | 0) - 1 | 0;
+ if (($56 | 0) < ($62 | 0)) {
+ $i_05_i_i_i = $56;
+ } else {
+ $_lcssa_i_i_i = $62;
+ break;
+ }
+ }
+ } else {
+ $_lcssa_i_i_i = $54;
+ }
+ HEAP32[((HEAP32[$50 >> 2] | 0) + ($_lcssa_i_i_i * 36 & -1) + 20 | 0) >> 2] = -1;
+ HEAP32[((HEAP32[$50 >> 2] | 0) + (((HEAP32[$46 >> 2] | 0) - 1 | 0) * 36 & -1) + 32 | 0) >> 2] = -1;
+ _memset($world + 102888 | 0 | 0 | 0, 0 | 0 | 0, 16 | 0 | 0);
+ HEAP32[($world + 102920 | 0) >> 2] = 16;
+ HEAP32[($world + 102924 | 0) >> 2] = 0;
+ HEAP32[($world + 102916 | 0) >> 2] = _malloc(192) | 0;
+ HEAP32[($world + 102908 | 0) >> 2] = 16;
+ HEAP32[($world + 102912 | 0) >> 2] = 0;
+ HEAP32[($world + 102904 | 0) >> 2] = _malloc(64) | 0;
+ HEAP32[($world + 102932 | 0) >> 2] = 0;
+ HEAP32[($world + 102936 | 0) >> 2] = 0;
+ HEAP32[($world + 102940 | 0) >> 2] = 104;
+ HEAP32[($world + 102944 | 0) >> 2] = 96;
+ $87 = $world + 102948 | 0;
+ HEAP32[($world + 102980 | 0) >> 2] = 0;
+ HEAP32[($world + 102984 | 0) >> 2] = 0;
+ _memset($87 | 0 | 0, 0 | 0 | 0, 20 | 0 | 0);
+ HEAP8[$world + 102992 | 0] = 1;
+ HEAP8[$world + 102993 | 0] = 1;
+ HEAP8[$world + 102994 | 0] = 0;
+ HEAP8[$world + 102995 | 0] = 1;
+ $96 = $world + 102976 | 0;
+ HEAP8[$96] = 1;
+ $97 = $world + 102968 | 0;
+ HEAP32[($97 | 0) >> 2] = 0;
+ HEAP32[($97 + 4 | 0) >> 2] = -1054867456;
+ $98 = $world + 102868 | 0;
+ HEAP32[$98 >> 2] = 4;
+ HEAPF32[($world + 102988 | 0) >> 2] = +0;
+ HEAP32[$87 >> 2] = $14;
+ _memset($world + 102996 | 0 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0);
+ HEAP8[$96] = 0;
+ HEAP32[($bd + 44 | 0) >> 2] = 0;
+ _memset($bd + 4 | 0 | 0 | 0, 0 | 0 | 0, 32 | 0 | 0);
+ HEAP8[$bd + 36 | 0] = 1;
+ HEAP8[$bd + 37 | 0] = 1;
+ HEAP8[$bd + 38 | 0] = 0;
+ HEAP8[$bd + 39 | 0] = 0;
+ HEAP32[($bd | 0) >> 2] = 0;
+ HEAP8[$bd + 40 | 0] = 1;
+ HEAPF32[($bd + 48 | 0) >> 2] = +1;
+ $112 = __ZN16b2BlockAllocator8AllocateEi($14, 152) | 0;
+ if (($112 | 0) == 0) {
+ $116 = 0;
+ } else {
+ $115 = $112;
+ __ZN6b2BodyC2EPK9b2BodyDefP7b2World($115, $bd, $world);
+ $116 = $115;
+ }
+ HEAP32[($116 + 92 | 0) >> 2] = 0;
+ $118 = $world + 102952 | 0;
+ HEAP32[($116 + 96 | 0) >> 2] = HEAP32[$118 >> 2] | 0;
+ $121 = HEAP32[$118 >> 2] | 0;
+ if (!(($121 | 0) == 0)) {
+ HEAP32[($121 + 92 | 0) >> 2] = $116;
+ }
+ HEAP32[$118 >> 2] = $116;
+ $126 = $world + 102960 | 0;
+ HEAP32[$126 >> 2] = (HEAP32[$126 >> 2] | 0) + 1 | 0;
+ HEAP32[($shape | 0) >> 2] = 8016 | 0;
+ HEAP32[($shape + 4 | 0) >> 2] = 1;
+ HEAPF32[($shape + 8 | 0) >> 2] = +.009999999776482582;
+ _memset($shape + 28 | 0 | 0 | 0, 0 | 0 | 0, 18 | 0 | 0);
+ $135 = $shape + 12 | 0;
+ HEAP32[($135 | 0) >> 2] = -1038090240;
+ HEAP32[($135 + 4 | 0) >> 2] = 0;
+ $137 = $shape + 20 | 0;
+ HEAP32[($137 | 0) >> 2] = 1109393408;
+ HEAP32[($137 + 4 | 0) >> 2] = 0;