aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--AUTHORS1
-rwxr-xr-xemcc23
-rwxr-xr-xemscripten.py56
-rw-r--r--src/analyzer.js9
-rw-r--r--src/compiler.js1
-rw-r--r--src/fastLong.js298
-rw-r--r--src/jsifier.js65
-rw-r--r--src/library.js84
-rw-r--r--src/long.js56
-rw-r--r--src/modules.js2
-rw-r--r--src/parseTools.js17
-rw-r--r--src/settings.js2
-rw-r--r--system/lib/compiler-rt/LICENSE.TXT97
-rw-r--r--system/lib/compiler-rt/divdi3.c47
-rw-r--r--system/lib/compiler-rt/int_endianness.h116
-rw-r--r--system/lib/compiler-rt/int_lib.h46
-rw-r--r--system/lib/compiler-rt/int_math.h67
-rw-r--r--system/lib/compiler-rt/int_types.h140
-rw-r--r--system/lib/compiler-rt/int_util.h29
-rw-r--r--system/lib/compiler-rt/muldi3.c56
-rw-r--r--system/lib/compiler-rt/readme.txt20
-rw-r--r--system/lib/compiler-rt/udivdi3.c36
-rw-r--r--system/lib/compiler-rt/udivmoddi4.c251
-rw-r--r--tests/cases/call_i64_noret.ll17
-rw-r--r--tests/cases/uadd_overflow_64_ta2.ll30
-rw-r--r--tests/cases/uadd_overflow_64_ta2.txt2
-rw-r--r--tests/cases/uadd_overflow_ta2.ll6
-rw-r--r--tests/cases/uadd_overflow_ta2.txt1
-rwxr-xr-xtests/runner.py66
-rw-r--r--tests/unistd/misc.out2
30 files changed, 1490 insertions, 153 deletions
diff --git a/AUTHORS b/AUTHORS
index 35aa74a7..87a656d6 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -61,4 +61,5 @@ a license to everyone to use it as detailed in LICENSE.)
* Alexander Gladysh <ag@logiceditor.com>
* Arlo Breault <arlolra@gmail.com>
* Jacob Lee <artdent@gmail.com> (copyright owned by Google, Inc.)
+* Joe Lee <jlee@imvu.com> (copyright owned by IMVU)
diff --git a/emcc b/emcc
index adca1266..6c7ed2f5 100755
--- a/emcc
+++ b/emcc
@@ -473,7 +473,7 @@ Options that are modified or new in %s include:
--memory-init-file <on> If on, we generate a separate memory initialization
file. This is more efficient than storing the
memory initialization data embedded inside
- JavaScript as text. (default is on)
+ JavaScript as text. (default is off)
The target file, if specified (-o <target>), defines what will
be generated:
@@ -483,8 +483,8 @@ be generated:
<name>.bc LLVM bitcode (default)
<name>.o LLVM bitcode (same as .bc)
-Note that if --memory-init-file is used, then in addition to a
-.js or .html file that is generated, a .mem file will also appear.
+(Note that if --memory-init-file is used, then in addition to a
+.js or .html file that is generated, a .mem file will also appear.)
The -c option (which tells gcc not to run the linker) will
cause LLVM bitcode to be generated, as %s only generates
@@ -519,7 +519,7 @@ CONFIGURE_CONFIG = (os.environ.get('EMMAKEN_JUST_CONFIGURE') or 'conftest.c' in
CMAKE_CONFIG = 'CMakeFiles/cmTryCompileExec.dir' in ' '.join(sys.argv)# or 'CMakeCCompilerId' in ' '.join(sys.argv)
if CONFIGURE_CONFIG or CMAKE_CONFIG:
debug_configure = 0 # XXX use this to debug configure stuff. ./configure's generally hide our normal output including stderr so we write to a file
- use_clang = 1 # whether we fake configure tests using clang - the local, native compiler - or not. if not we generate JS and use node with a shebang
+ use_js = os.environ.get('EMCONFIGURE_JS') # whether we fake configure tests using clang - the local, native compiler - or not. if not we generate JS and use node with a shebang
# neither approach is perfect, you can try both, but may need to edit configure scripts in some cases
# XXX False is not fully tested yet
@@ -536,13 +536,16 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG:
if debug_configure: open(tempout, 'a').write('============= ' + sys.argv[i] + '\n' + src + '\n=============\n\n')
except:
pass
+ if sys.argv[i].endswith('.s'):
+ if debug_configure: open(tempout, 'a').write('(compiling .s assembly, must use clang\n')
+ use_js = 0
if src:
if 'fopen' in src and '"w"' in src:
- use_clang = True # we cannot write to files from js!
+ use_js = 0 # we cannot write to files from js!
if debug_configure: open(tempout, 'a').write('Forcing clang since uses fopen to write\n')
- compiler = os.environ.get('CONFIGURE_CC') or (shared.CLANG if use_clang else shared.EMCC) # if CONFIGURE_CC is defined, use that. let's you use local gcc etc. if you need that
+ 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
if not ('CXXCompiler' in ' '.join(sys.argv) or os.environ.get('EMMAKEN_CXX')):
compiler = shared.to_cc(compiler)
@@ -561,12 +564,12 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG:
idx += 1
cmd = [compiler] + list(filter_emscripten_options(sys.argv[1:]))
- if use_clang: cmd += shared.EMSDK_OPTS + ['-DEMSCRIPTEN']
+ if not use_js: cmd += shared.EMSDK_OPTS + ['-DEMSCRIPTEN']
if DEBUG: print >> sys.stderr, 'emcc, just configuring: ', ' '.join(cmd)
if debug_configure: open(tempout, 'a').write('emcc, just configuring: ' + ' '.join(cmd) + '\n\n')
- if use_clang:
+ if not use_js:
exit(subprocess.call(cmd))
else:
only_object = '-c' in cmd
@@ -589,7 +592,7 @@ if CONFIGURE_CONFIG or CMAKE_CONFIG:
shutil.copyfile(target, target[:-3])
target = target[:-3]
src = open(target).read()
- full_node = shared.NODE_JS
+ full_node = ' '.join(shared.listify(shared.NODE_JS))
if os.path.sep not in full_node:
full_node = '/usr/bin/' + full_node # TODO: use whereis etc. And how about non-*NIX?
open(target, 'w').write('#!' + full_node + '\n' + src) # add shebang
@@ -724,7 +727,7 @@ try:
bind = False
jcache = False
save_bc = False
- memory_init_file = True
+ memory_init_file = False
if use_cxx:
default_cxx_std = '-std=c++03' # Enforce a consistent C++ standard when compiling .cpp files, if user does not specify one on the cmdline.
diff --git a/emscripten.py b/emscripten.py
index 19c74531..b49008cd 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -98,19 +98,22 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
if DEBUG: t = time.time()
in_func = False
ll_lines = open(infile).readlines()
+ curr_func = None
for line in ll_lines:
if in_func:
- funcs[-1][1].append(line)
+ curr_func.append(line)
if line.startswith('}'):
in_func = False
- funcs[-1] = (funcs[-1][0], ''.join(funcs[-1][1]))
- pre.append(line) # pre needs it to, so we know about all implemented functions
+ funcs.append((curr_func[0], ''.join(curr_func))) # use the entire line as the identifier
+ # pre needs to know about all implemented functions, even for non-pre func
+ pre.append(curr_func[0])
+ pre.append(line)
+ curr_func = None
else:
if line.startswith(';'): continue
if line.startswith('define '):
in_func = True
- funcs.append((line, [line])) # use the entire line as the identifier
- pre.append(line) # pre needs it to, so we know about all implemented functions
+ curr_func = [line]
elif line.find(' = type { ') > 0:
pre.append(line) # type
elif line.startswith('!'):
@@ -222,10 +225,10 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
# TODO: minimize size of forwarded data from funcs to what we actually need
- if cores == 1 and total_ll_size < MAX_CHUNK_SIZE:
- assert len(chunks) == 1, 'no point in splitting up without multiple cores'
-
if len(chunks) > 0:
+ if cores == 1 and total_ll_size < MAX_CHUNK_SIZE:
+ assert len(chunks) == 1, 'no point in splitting up without multiple cores'
+
if DEBUG: print >> sys.stderr, ' emscript: phase 2 working on %d chunks %s (intended chunk size: %.2f MB, meta: %.2f MB, forwarded: %.2f MB, total: %.2f MB)' % (len(chunks), ('using %d cores' % cores) if len(chunks) > 1 else '', chunk_size/(1024*1024.), len(meta)/(1024*1024.), len(forwarded_data)/(1024*1024.), total_ll_size/(1024*1024.))
commands = [
@@ -344,6 +347,14 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
if settings.get('ASM_JS'):
post_funcs, post_rest = post.split('// EMSCRIPTEN_END_FUNCS\n')
post = post_rest
+
+ # Move preAsms to their right place
+ def move_preasm(m):
+ contents = m.groups(0)[0]
+ outfile.write(contents + '\n')
+ return ''
+ post_funcs = re.sub(r'/\* PRE_ASM \*/(.*)\n', lambda m: move_preasm(m), post_funcs)
+
funcs_js += ['\n' + post_funcs + '// EMSCRIPTEN_END_FUNCS\n']
simple = os.environ.get('EMCC_SIMPLE_ASM')
@@ -381,15 +392,12 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
if settings['CHECK_HEAP_ALIGN']: basic_funcs += ['CHECK_ALIGN_2', 'CHECK_ALIGN_4', 'CHECK_ALIGN_8']
basic_vars = ['STACKTOP', 'STACK_MAX', 'tempDoublePtr', 'ABORT']
basic_float_vars = ['NaN', 'Infinity']
- if forwarded_json['Types']['preciseI64MathUsed']:
- basic_funcs += ['i64Math_' + op for op in ['add', 'subtract', 'multiply', 'divide', 'modulo']]
- asm_setup += '''
-var i64Math_add = function(a, b, c, d) { i64Math.add(a, b, c, d) };
-var i64Math_subtract = function(a, b, c, d) { i64Math.subtract(a, b, c, d) };
-var i64Math_multiply = function(a, b, c, d) { i64Math.multiply(a, b, c, d) };
-var i64Math_divide = function(a, b, c, d, e) { i64Math.divide(a, b, c, d, e) };
-var i64Math_modulo = function(a, b, c, d, e) { i64Math.modulo(a, b, c, d, e) };
-'''
+
+ if forwarded_json['Types']['preciseI64MathUsed'] or \
+ forwarded_json['Functions']['libraryFunctions'].get('llvm_cttz_i32') or \
+ forwarded_json['Functions']['libraryFunctions'].get('llvm_ctlz_i32'):
+ basic_vars += ['cttz_i8', 'ctlz_i8']
+
asm_runtime_funcs = ['stackAlloc', 'stackSave', 'stackRestore', 'setThrew'] + ['setTempRet%d' % i for i in range(10)]
# function tables
def asm_coerce(value, sig):
@@ -410,6 +418,18 @@ var i64Math_modulo = function(a, b, c, d, e) { i64Math.modulo(a, b, c, d, e) };
%s;
}
''' % (sig, ',' if len(sig) > 1 else '', args, arg_coercions, ret))
+ args = ','.join(['a' + str(i) for i in range(1, len(sig))])
+ args = 'index' + (',' if args else '') + args
+ asm_setup += '''
+function invoke_%s(%s) {
+ try {
+ %sModule.dynCall_%s(%s);
+ } catch(e) {
+ asm.setThrew(1);
+ }
+}
+''' % (sig, args, 'return ' if sig[0] != 'v' else '', sig, args)
+ basic_funcs.append('invoke_%s' % sig)
# calculate exports
exported_implemented_functions = list(exported_implemented_functions)
@@ -427,7 +447,7 @@ var i64Math_modulo = function(a, b, c, d, e) { i64Math.modulo(a, b, c, d, e) };
pass
# If no named globals, only need externals
global_vars = map(lambda g: g['name'], filter(lambda g: settings['NAMED_GLOBALS'] or g.get('external') or g.get('unIndexable'), forwarded_json['Variables']['globals'].values()))
- global_funcs = ['_' + x for x in forwarded_json['Functions']['libraryFunctions'].keys()]
+ global_funcs = ['_' + key for key, value in forwarded_json['Functions']['libraryFunctions'].iteritems() if value != 2]
def math_fix(g):
return g if not g.startswith('Math_') else g.split('_')[1];
asm_global_funcs = ''.join([' var ' + g.replace('.', '_') + '=global.' + g + ';\n' for g in maths]) + \
diff --git a/src/analyzer.js b/src/analyzer.js
index c10f18cc..df5a435e 100644
--- a/src/analyzer.js
+++ b/src/analyzer.js
@@ -124,6 +124,10 @@ function analyzer(data, sidePass) {
bits = bits || 32; // things like pointers are all i32, but show up as 0 bits from getBits
if (allowLegal && bits <= 32) return [{ ident: base + ('i' + bits in Runtime.INT_TYPES ? '' : '$0'), bits: bits }];
if (isNumber(base)) return getLegalLiterals(base, bits);
+ if (base[0] == '{') {
+ warnOnce('seeing source of illegal data ' + base + ', likely an inline struct - assuming zeroinit');
+ return getLegalLiterals('0', bits);
+ }
var ret = new Array(Math.ceil(bits/32));
var i = 0;
if (base == 'zeroinitializer' || base == 'undef') base = 0;
@@ -320,12 +324,13 @@ function analyzer(data, sidePass) {
}
// call, return: Return the first 32 bits, the rest are in temp
case 'call': {
- bits = getBits(value.type);
- var elements = getLegalVars(item.assignTo, bits);
var toAdd = [value];
// legalize parameters
legalizeFunctionParameters(value.params);
+ // legalize return value, if any
if (value.assignTo && isIllegalType(item.type)) {
+ bits = getBits(value.type);
+ var elements = getLegalVars(item.assignTo, bits);
// legalize return value
value.assignTo = elements[0].ident;
for (var j = 1; j < elements.length; j++) {
diff --git a/src/compiler.js b/src/compiler.js
index 7cf43f09..9c19aeb0 100644
--- a/src/compiler.js
+++ b/src/compiler.js
@@ -178,7 +178,6 @@ assert(!(USE_TYPED_ARRAYS === 2 && QUANTUM_SIZE !== 4), 'For USE_TYPED_ARRAYS ==
if (ASM_JS) {
assert(!ALLOW_MEMORY_GROWTH, 'Cannot grow asm.js heap');
assert((TOTAL_MEMORY&(TOTAL_MEMORY-1)) == 0, 'asm.js heap must be power of 2');
- assert(DISABLE_EXCEPTION_CATCHING == 1, 'asm.js does not support C++ exceptions yet, you must compile with -s DISABLE_EXCEPTION_CATCHING=1');
}
assert(!(!NAMED_GLOBALS && BUILD_AS_SHARED_LIB)); // shared libraries must have named globals
diff --git a/src/fastLong.js b/src/fastLong.js
new file mode 100644
index 00000000..95f398db
--- /dev/null
+++ b/src/fastLong.js
@@ -0,0 +1,298 @@
+// ======== compiled code from system/lib/compiler-rt , see readme therein
+function ___muldsi3($a, $b) {
+ $a = $a | 0;
+ $b = $b | 0;
+ var $1 = 0, $2 = 0, $3 = 0, $6 = 0, $8 = 0, $11 = 0, $12 = 0;
+ $1 = $a & 65535;
+ $2 = $b & 65535;
+ $3 = Math.imul($2, $1);
+ $6 = $a >>> 16;
+ $8 = ($3 >>> 16) + Math.imul($2, $6) | 0;
+ $11 = $b >>> 16;
+ $12 = Math.imul($11, $1);
+ return (tempRet0 = (($8 >>> 16) + Math.imul($11, $6) | 0) + ((($8 & 65535) + $12 | 0) >>> 16) | 0, 0 | ($8 + $12 << 16 | $3 & 65535)) | 0;
+}
+function ___divdi3($a$0, $a$1, $b$0, $b$1) {
+ $a$0 = $a$0 | 0;
+ $a$1 = $a$1 | 0;
+ $b$0 = $b$0 | 0;
+ $b$1 = $b$1 | 0;
+ var $1$0 = 0, $1$1 = 0, $2$0 = 0, $2$1 = 0, $4$0 = 0, $4$1 = 0, $6$0 = 0, $7$0 = 0, $7$1 = 0, $8$0 = 0, $10$0 = 0;
+ $1$0 = $a$1 >> 31 | (($a$1 | 0) < 0 ? -1 : 0) << 1;
+ $1$1 = (($a$1 | 0) < 0 ? -1 : 0) >> 31 | (($a$1 | 0) < 0 ? -1 : 0) << 1;
+ $2$0 = $b$1 >> 31 | (($b$1 | 0) < 0 ? -1 : 0) << 1;
+ $2$1 = (($b$1 | 0) < 0 ? -1 : 0) >> 31 | (($b$1 | 0) < 0 ? -1 : 0) << 1;
+ $4$0 = _i64Subtract($1$0 ^ $a$0, $1$1 ^ $a$1, $1$0, $1$1);
+ $4$1 = tempRet0;
+ $6$0 = _i64Subtract($2$0 ^ $b$0, $2$1 ^ $b$1, $2$0, $2$1);
+ $7$0 = $2$0 ^ $1$0;
+ $7$1 = $2$1 ^ $1$1;
+ $8$0 = ___udivmoddi4($4$0, $4$1, $6$0, tempRet0, 0) | 0;
+ $10$0 = _i64Subtract($8$0 ^ $7$0, tempRet0 ^ $7$1, $7$0, $7$1);
+ return (tempRet0 = tempRet0, $10$0) | 0;
+}
+function ___remdi3($a$0, $a$1, $b$0, $b$1) {
+ $a$0 = $a$0 | 0;
+ $a$1 = $a$1 | 0;
+ $b$0 = $b$0 | 0;
+ $b$1 = $b$1 | 0;
+ var $rem = 0, $1$0 = 0, $1$1 = 0, $2$0 = 0, $2$1 = 0, $4$0 = 0, $4$1 = 0, $6$0 = 0, $10$0 = 0, $10$1 = 0, __stackBase__ = 0;
+ __stackBase__ = STACKTOP;
+ STACKTOP = STACKTOP + 8 | 0;
+ $rem = __stackBase__ | 0;
+ $1$0 = $a$1 >> 31 | (($a$1 | 0) < 0 ? -1 : 0) << 1;
+ $1$1 = (($a$1 | 0) < 0 ? -1 : 0) >> 31 | (($a$1 | 0) < 0 ? -1 : 0) << 1;
+ $2$0 = $b$1 >> 31 | (($b$1 | 0) < 0 ? -1 : 0) << 1;
+ $2$1 = (($b$1 | 0) < 0 ? -1 : 0) >> 31 | (($b$1 | 0) < 0 ? -1 : 0) << 1;
+ $4$0 = _i64Subtract($1$0 ^ $a$0, $1$1 ^ $a$1, $1$0, $1$1);
+ $4$1 = tempRet0;
+ $6$0 = _i64Subtract($2$0 ^ $b$0, $2$1 ^ $b$1, $2$0, $2$1);
+ ___udivmoddi4($4$0, $4$1, $6$0, tempRet0, $rem);
+ $10$0 = _i64Subtract(HEAP32[$rem >> 2] ^ $1$0, HEAP32[$rem + 4 >> 2] ^ $1$1, $1$0, $1$1);
+ $10$1 = tempRet0;
+ STACKTOP = __stackBase__;
+ return (tempRet0 = $10$1, $10$0) | 0;
+}
+function ___muldi3($a$0, $a$1, $b$0, $b$1) {
+ $a$0 = $a$0 | 0;
+ $a$1 = $a$1 | 0;
+ $b$0 = $b$0 | 0;
+ $b$1 = $b$1 | 0;
+ var $x_sroa_0_0_extract_trunc = 0, $y_sroa_0_0_extract_trunc = 0, $1$0 = 0, $1$1 = 0, $2 = 0;
+ $x_sroa_0_0_extract_trunc = $a$0;
+ $y_sroa_0_0_extract_trunc = $b$0;
+ $1$0 = ___muldsi3($x_sroa_0_0_extract_trunc, $y_sroa_0_0_extract_trunc) | 0;
+ $1$1 = tempRet0;
+ $2 = Math.imul($a$1, $y_sroa_0_0_extract_trunc);
+ return (tempRet0 = (Math.imul($b$1, $x_sroa_0_0_extract_trunc) + $2 | 0) + $1$1 | $1$1 & 0, 0 | $1$0 & -1) | 0;
+}
+function ___udivdi3($a$0, $a$1, $b$0, $b$1) {
+ $a$0 = $a$0 | 0;
+ $a$1 = $a$1 | 0;
+ $b$0 = $b$0 | 0;
+ $b$1 = $b$1 | 0;
+ var $1$0 = 0;
+ $1$0 = ___udivmoddi4($a$0, $a$1, $b$0, $b$1, 0) | 0;
+ return (tempRet0 = tempRet0, $1$0) | 0;
+}
+function ___uremdi3($a$0, $a$1, $b$0, $b$1) {
+ $a$0 = $a$0 | 0;
+ $a$1 = $a$1 | 0;
+ $b$0 = $b$0 | 0;
+ $b$1 = $b$1 | 0;
+ var $rem = 0, __stackBase__ = 0;
+ __stackBase__ = STACKTOP;
+ STACKTOP = STACKTOP + 8 | 0;
+ $rem = __stackBase__ | 0;
+ ___udivmoddi4($a$0, $a$1, $b$0, $b$1, $rem);
+ STACKTOP = __stackBase__;
+ return (tempRet0 = HEAP32[$rem + 4 >> 2] | 0, HEAP32[$rem >> 2] | 0) | 0;
+}
+function ___udivmoddi4($a$0, $a$1, $b$0, $b$1, $rem) {
+ $a$0 = $a$0 | 0;
+ $a$1 = $a$1 | 0;
+ $b$0 = $b$0 | 0;
+ $b$1 = $b$1 | 0;
+ $rem = $rem | 0;
+ var $n_sroa_0_0_extract_trunc = 0, $n_sroa_1_4_extract_shift$0 = 0, $n_sroa_1_4_extract_trunc = 0, $d_sroa_0_0_extract_trunc = 0, $d_sroa_1_4_extract_shift$0 = 0, $d_sroa_1_4_extract_trunc = 0, $4 = 0, $17 = 0, $37 = 0, $49 = 0, $51 = 0, $57 = 0, $58 = 0, $66 = 0, $78 = 0, $86 = 0, $88 = 0, $89 = 0, $91 = 0, $92 = 0, $95 = 0, $105 = 0, $117 = 0, $119 = 0, $125 = 0, $126 = 0, $130 = 0, $q_sroa_1_1_ph = 0, $q_sroa_0_1_ph = 0, $r_sroa_1_1_ph = 0, $r_sroa_0_1_ph = 0, $sr_1_ph = 0, $d_sroa_0_0_insert_insert99$0 = 0, $d_sroa_0_0_insert_insert99$1 = 0, $137$0 = 0, $137$1 = 0, $carry_0203 = 0, $sr_1202 = 0, $r_sroa_0_1201 = 0, $r_sroa_1_1200 = 0, $q_sroa_0_1199 = 0, $q_sroa_1_1198 = 0, $147 = 0, $149 = 0, $r_sroa_0_0_insert_insert42$0 = 0, $r_sroa_0_0_insert_insert42$1 = 0, $150$1 = 0, $151$0 = 0, $152 = 0, $154$0 = 0, $r_sroa_0_0_extract_trunc = 0, $r_sroa_1_4_extract_trunc = 0, $155 = 0, $carry_0_lcssa$0 = 0, $carry_0_lcssa$1 = 0, $r_sroa_0_1_lcssa = 0, $r_sroa_1_1_lcssa = 0, $q_sroa_0_1_lcssa = 0, $q_sroa_1_1_lcssa = 0, $q_sroa_0_0_insert_ext75$0 = 0, $q_sroa_0_0_insert_ext75$1 = 0, $q_sroa_0_0_insert_insert77$1 = 0, $_0$0 = 0, $_0$1 = 0;
+ $n_sroa_0_0_extract_trunc = $a$0;
+ $n_sroa_1_4_extract_shift$0 = $a$1;
+ $n_sroa_1_4_extract_trunc = $n_sroa_1_4_extract_shift$0;
+ $d_sroa_0_0_extract_trunc = $b$0;
+ $d_sroa_1_4_extract_shift$0 = $b$1;
+ $d_sroa_1_4_extract_trunc = $d_sroa_1_4_extract_shift$0;
+ if (($n_sroa_1_4_extract_trunc | 0) == 0) {
+ $4 = ($rem | 0) != 0;
+ if (($d_sroa_1_4_extract_trunc | 0) == 0) {
+ if ($4) {
+ HEAP32[$rem >> 2] = ($n_sroa_0_0_extract_trunc >>> 0) % ($d_sroa_0_0_extract_trunc >>> 0);
+ HEAP32[$rem + 4 >> 2] = 0;
+ }
+ $_0$1 = 0;
+ $_0$0 = ($n_sroa_0_0_extract_trunc >>> 0) / ($d_sroa_0_0_extract_trunc >>> 0) >>> 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ } else {
+ if (!$4) {
+ $_0$1 = 0;
+ $_0$0 = 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ HEAP32[$rem >> 2] = $a$0 & -1;
+ HEAP32[$rem + 4 >> 2] = $a$1 & 0;
+ $_0$1 = 0;
+ $_0$0 = 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ }
+ $17 = ($d_sroa_1_4_extract_trunc | 0) == 0;
+ do {
+ if (($d_sroa_0_0_extract_trunc | 0) == 0) {
+ if ($17) {
+ if (($rem | 0) != 0) {
+ HEAP32[$rem >> 2] = ($n_sroa_1_4_extract_trunc >>> 0) % ($d_sroa_0_0_extract_trunc >>> 0);
+ HEAP32[$rem + 4 >> 2] = 0;
+ }
+ $_0$1 = 0;
+ $_0$0 = ($n_sroa_1_4_extract_trunc >>> 0) / ($d_sroa_0_0_extract_trunc >>> 0) >>> 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ if (($n_sroa_0_0_extract_trunc | 0) == 0) {
+ if (($rem | 0) != 0) {
+ HEAP32[$rem >> 2] = 0;
+ HEAP32[$rem + 4 >> 2] = ($n_sroa_1_4_extract_trunc >>> 0) % ($d_sroa_1_4_extract_trunc >>> 0);
+ }
+ $_0$1 = 0;
+ $_0$0 = ($n_sroa_1_4_extract_trunc >>> 0) / ($d_sroa_1_4_extract_trunc >>> 0) >>> 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ $37 = $d_sroa_1_4_extract_trunc - 1 | 0;
+ if (($37 & $d_sroa_1_4_extract_trunc | 0) == 0) {
+ if (($rem | 0) != 0) {
+ HEAP32[$rem >> 2] = 0 | $a$0 & -1;
+ HEAP32[$rem + 4 >> 2] = $37 & $n_sroa_1_4_extract_trunc | $a$1 & 0;
+ }
+ $_0$1 = 0;
+ $_0$0 = $n_sroa_1_4_extract_trunc >>> ((_llvm_cttz_i32($d_sroa_1_4_extract_trunc | 0) | 0) >>> 0);
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ $49 = _llvm_ctlz_i32($d_sroa_1_4_extract_trunc | 0) | 0;
+ $51 = $49 - (_llvm_ctlz_i32($n_sroa_1_4_extract_trunc | 0) | 0) | 0;
+ if ($51 >>> 0 <= 30) {
+ $57 = $51 + 1 | 0;
+ $58 = 31 - $51 | 0;
+ $sr_1_ph = $57;
+ $r_sroa_0_1_ph = $n_sroa_1_4_extract_trunc << $58 | $n_sroa_0_0_extract_trunc >>> ($57 >>> 0);
+ $r_sroa_1_1_ph = $n_sroa_1_4_extract_trunc >>> ($57 >>> 0);
+ $q_sroa_0_1_ph = 0;
+ $q_sroa_1_1_ph = $n_sroa_0_0_extract_trunc << $58;
+ break;
+ }
+ if (($rem | 0) == 0) {
+ $_0$1 = 0;
+ $_0$0 = 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ HEAP32[$rem >> 2] = 0 | $a$0 & -1;
+ HEAP32[$rem + 4 >> 2] = $n_sroa_1_4_extract_shift$0 | $a$1 & 0;
+ $_0$1 = 0;
+ $_0$0 = 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ } else {
+ if (!$17) {
+ $117 = _llvm_ctlz_i32($d_sroa_1_4_extract_trunc | 0) | 0;
+ $119 = $117 - (_llvm_ctlz_i32($n_sroa_1_4_extract_trunc | 0) | 0) | 0;
+ if ($119 >>> 0 <= 31) {
+ $125 = $119 + 1 | 0;
+ $126 = 31 - $119 | 0;
+ $130 = $119 - 31 >> 31;
+ $sr_1_ph = $125;
+ $r_sroa_0_1_ph = $n_sroa_0_0_extract_trunc >>> ($125 >>> 0) & $130 | $n_sroa_1_4_extract_trunc << $126;
+ $r_sroa_1_1_ph = $n_sroa_1_4_extract_trunc >>> ($125 >>> 0) & $130;
+ $q_sroa_0_1_ph = 0;
+ $q_sroa_1_1_ph = $n_sroa_0_0_extract_trunc << $126;
+ break;
+ }
+ if (($rem | 0) == 0) {
+ $_0$1 = 0;
+ $_0$0 = 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ HEAP32[$rem >> 2] = 0 | $a$0 & -1;
+ HEAP32[$rem + 4 >> 2] = $n_sroa_1_4_extract_shift$0 | $a$1 & 0;
+ $_0$1 = 0;
+ $_0$0 = 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ $66 = $d_sroa_0_0_extract_trunc - 1 | 0;
+ if (($66 & $d_sroa_0_0_extract_trunc | 0) != 0) {
+ $86 = (_llvm_ctlz_i32($d_sroa_0_0_extract_trunc | 0) | 0) + 33 | 0;
+ $88 = $86 - (_llvm_ctlz_i32($n_sroa_1_4_extract_trunc | 0) | 0) | 0;
+ $89 = 64 - $88 | 0;
+ $91 = 32 - $88 | 0;
+ $92 = $91 >> 31;
+ $95 = $88 - 32 | 0;
+ $105 = $95 >> 31;
+ $sr_1_ph = $88;
+ $r_sroa_0_1_ph = $91 - 1 >> 31 & $n_sroa_1_4_extract_trunc >>> ($95 >>> 0) | ($n_sroa_1_4_extract_trunc << $91 | $n_sroa_0_0_extract_trunc >>> ($88 >>> 0)) & $105;
+ $r_sroa_1_1_ph = $105 & $n_sroa_1_4_extract_trunc >>> ($88 >>> 0);
+ $q_sroa_0_1_ph = $n_sroa_0_0_extract_trunc << $89 & $92;
+ $q_sroa_1_1_ph = ($n_sroa_1_4_extract_trunc << $89 | $n_sroa_0_0_extract_trunc >>> ($95 >>> 0)) & $92 | $n_sroa_0_0_extract_trunc << $91 & $88 - 33 >> 31;
+ break;
+ }
+ if (($rem | 0) != 0) {
+ HEAP32[$rem >> 2] = $66 & $n_sroa_0_0_extract_trunc;
+ HEAP32[$rem + 4 >> 2] = 0;
+ }
+ if (($d_sroa_0_0_extract_trunc | 0) == 1) {
+ $_0$1 = $n_sroa_1_4_extract_shift$0 | $a$1 & 0;
+ $_0$0 = 0 | $a$0 & -1;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ } else {
+ $78 = _llvm_cttz_i32($d_sroa_0_0_extract_trunc | 0) | 0;
+ $_0$1 = 0 | $n_sroa_1_4_extract_trunc >>> ($78 >>> 0);
+ $_0$0 = $n_sroa_1_4_extract_trunc << 32 - $78 | $n_sroa_0_0_extract_trunc >>> ($78 >>> 0) | 0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+ }
+ }
+ } while (0);
+ if (($sr_1_ph | 0) == 0) {
+ $q_sroa_1_1_lcssa = $q_sroa_1_1_ph;
+ $q_sroa_0_1_lcssa = $q_sroa_0_1_ph;
+ $r_sroa_1_1_lcssa = $r_sroa_1_1_ph;
+ $r_sroa_0_1_lcssa = $r_sroa_0_1_ph;
+ $carry_0_lcssa$1 = 0;
+ $carry_0_lcssa$0 = 0;
+ } else {
+ $d_sroa_0_0_insert_insert99$0 = 0 | $b$0 & -1;
+ $d_sroa_0_0_insert_insert99$1 = $d_sroa_1_4_extract_shift$0 | $b$1 & 0;
+ $137$0 = _i64Add($d_sroa_0_0_insert_insert99$0, $d_sroa_0_0_insert_insert99$1, -1, -1);
+ $137$1 = tempRet0;
+ $q_sroa_1_1198 = $q_sroa_1_1_ph;
+ $q_sroa_0_1199 = $q_sroa_0_1_ph;
+ $r_sroa_1_1200 = $r_sroa_1_1_ph;
+ $r_sroa_0_1201 = $r_sroa_0_1_ph;
+ $sr_1202 = $sr_1_ph;
+ $carry_0203 = 0;
+ while (1) {
+ $147 = $q_sroa_0_1199 >>> 31 | $q_sroa_1_1198 << 1;
+ $149 = $carry_0203 | $q_sroa_0_1199 << 1;
+ $r_sroa_0_0_insert_insert42$0 = 0 | ($r_sroa_0_1201 << 1 | $q_sroa_1_1198 >>> 31);
+ $r_sroa_0_0_insert_insert42$1 = $r_sroa_0_1201 >>> 31 | $r_sroa_1_1200 << 1 | 0;
+ _i64Subtract($137$0, $137$1, $r_sroa_0_0_insert_insert42$0, $r_sroa_0_0_insert_insert42$1);
+ $150$1 = tempRet0;
+ $151$0 = $150$1 >> 31 | (($150$1 | 0) < 0 ? -1 : 0) << 1;
+ $152 = $151$0 & 1;
+ $154$0 = _i64Subtract($r_sroa_0_0_insert_insert42$0, $r_sroa_0_0_insert_insert42$1, $151$0 & $d_sroa_0_0_insert_insert99$0, ((($150$1 | 0) < 0 ? -1 : 0) >> 31 | (($150$1 | 0) < 0 ? -1 : 0) << 1) & $d_sroa_0_0_insert_insert99$1);
+ $r_sroa_0_0_extract_trunc = $154$0;
+ $r_sroa_1_4_extract_trunc = tempRet0;
+ $155 = $sr_1202 - 1 | 0;
+ if (($155 | 0) == 0) {
+ break;
+ } else {
+ $q_sroa_1_1198 = $147;
+ $q_sroa_0_1199 = $149;
+ $r_sroa_1_1200 = $r_sroa_1_4_extract_trunc;
+ $r_sroa_0_1201 = $r_sroa_0_0_extract_trunc;
+ $sr_1202 = $155;
+ $carry_0203 = $152;
+ }
+ }
+ $q_sroa_1_1_lcssa = $147;
+ $q_sroa_0_1_lcssa = $149;
+ $r_sroa_1_1_lcssa = $r_sroa_1_4_extract_trunc;
+ $r_sroa_0_1_lcssa = $r_sroa_0_0_extract_trunc;
+ $carry_0_lcssa$1 = 0;
+ $carry_0_lcssa$0 = $152;
+ }
+ $q_sroa_0_0_insert_ext75$0 = $q_sroa_0_1_lcssa;
+ $q_sroa_0_0_insert_ext75$1 = 0;
+ $q_sroa_0_0_insert_insert77$1 = $q_sroa_1_1_lcssa | $q_sroa_0_0_insert_ext75$1;
+ if (($rem | 0) != 0) {
+ HEAP32[$rem >> 2] = 0 | $r_sroa_0_1_lcssa;
+ HEAP32[$rem + 4 >> 2] = $r_sroa_1_1_lcssa | 0;
+ }
+ $_0$1 = (0 | $q_sroa_0_0_insert_ext75$0) >>> 31 | $q_sroa_0_0_insert_insert77$1 << 1 | ($q_sroa_0_0_insert_ext75$1 << 1 | $q_sroa_0_0_insert_ext75$0 >>> 31) & 0 | $carry_0_lcssa$1;
+ $_0$0 = ($q_sroa_0_0_insert_ext75$0 << 1 | 0 >>> 31) & -2 | $carry_0_lcssa$0;
+ return (tempRet0 = $_0$1, $_0$0) | 0;
+}
+// =======================================================================
diff --git a/src/jsifier.js b/src/jsifier.js
index 23fbb4c5..926be71a 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -108,7 +108,7 @@ function JSify(data, functionsOnly, givenFunctions) {
}
});
- if (phase == 'funcs') { // pre has function shells, just to defined implementedFunctions
+ if (phase == 'funcs') { // || phase == 'pre') { // pre has function shells, just to defined implementedFunctions
var MAX_BATCH_FUNC_LINES = 1000;
while (data.unparsedFunctions.length > 0) {
var currFuncLines = [];
@@ -468,7 +468,7 @@ function JSify(data, functionsOnly, givenFunctions) {
asmLibraryFunctions.push(contentText);
contentText = ' ';
EXPORTED_FUNCTIONS[ident] = 1;
- delete Functions.libraryFunctions[ident.substr(1)];
+ Functions.libraryFunctions[ident.substr(1)] = 2;
}
}
if ((!ASM_JS || phase == 'pre') &&
@@ -1149,20 +1149,21 @@ function JSify(data, functionsOnly, givenFunctions) {
}
// If there is no current exception, set this one as it (during a resume, the current exception can be wiped out)
var ptr = makeStructuralAccess(item.ident, 0);
- return (EXCEPTION_DEBUG ? 'Module.print("Resuming exception");' : '') +
- 'if (' + makeGetValue('_llvm_eh_exception.buf', 0, 'void*') + ' == 0) { ' + makeSetValue('_llvm_eh_exception.buf', 0, ptr, 'void*') + ' } ' +
- makeThrow(ptr) + ';';
+ return '___resumeException(' + asmCoercion(ptr, 'i32') + ')';
});
makeFuncLineActor('invoke', function(item) {
// Wrapping in a function lets us easily return values if we are
// in an assignment
+ var disabled = DISABLE_EXCEPTION_CATCHING == 2 && !(item.funcData.ident in EXCEPTION_CATCHING_WHITELIST);
var phiSets = calcPhiSets(item);
- var call_ = makeFunctionCall(item.ident, item.params, item.funcData, item.type);
-
+ var call_ = makeFunctionCall(item.ident, item.params, item.funcData, item.type, ASM_JS && !disabled);
+
var ret;
- if (DISABLE_EXCEPTION_CATCHING == 2 && !(item.funcData.ident in EXCEPTION_CATCHING_WHITELIST)) {
+ if (disabled) {
ret = call_ + ';';
+ } else if (ASM_JS) {
+ ret = '(__THREW__ = 0,' + call_ + ');';
} else {
ret = '(function() { try { __THREW__ = 0; return '
+ call_ + ' '
@@ -1173,7 +1174,6 @@ function JSify(data, functionsOnly, givenFunctions) {
+ 'return null } })();';
}
-
if (item.assignTo) {
ret = 'var ' + item.assignTo + ' = ' + ret;
if (USE_TYPED_ARRAYS == 2 && isIllegalType(item.type)) {
@@ -1210,8 +1210,8 @@ function JSify(data, functionsOnly, givenFunctions) {
}
});
makeFuncLineActor('landingpad', function(item) {
- var catchTypeArray = item.catchables.map(finalizeLLVMParameter).join(',');
- var ret = '___cxa_find_matching_catch('+ makeGetValue('_llvm_eh_exception.buf', '0', 'void*') +',' + makeGetValue('_llvm_eh_exception.buf', QUANTUM_SIZE, 'void*') + ',[' + catchTypeArray +'])';
+ var catchTypeArray = item.catchables.map(finalizeLLVMParameter).map(function(element) { return asmCoercion(element, 'i32') }).join(',');
+ var ret = asmCoercion('___cxa_find_matching_catch(-1, -1' + (catchTypeArray.length > 0 ? ',' + catchTypeArray : '') +')', 'i32');
if (USE_TYPED_ARRAYS == 2) {
ret = makeVarDef(item.assignTo) + '$0 = ' + ret + '; ' + item.assignTo + '$1 = tempRet0;';
item.assignTo = null;
@@ -1291,7 +1291,7 @@ function JSify(data, functionsOnly, givenFunctions) {
return ret;
});
- function makeFunctionCall(ident, params, funcData, type) {
+ function makeFunctionCall(ident, params, funcData, type, forceByPointer) {
// We cannot compile assembly. See comment in intertyper.js:'Call'
assert(ident != 'asm', 'Inline assembly cannot be compiled to JavaScript!');
@@ -1319,6 +1319,11 @@ function JSify(data, functionsOnly, givenFunctions) {