aboutsummaryrefslogtreecommitdiff
path: root/emscripten.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-12-13 21:40:51 -0800
committerAlon Zakai <alonzakai@gmail.com>2013-12-13 21:40:51 -0800
commitfd718ccd54c73ebc4445228796de49e6c4302817 (patch)
tree0df5523872ad87b0aa80610f328f24a2857ba8a5 /emscripten.py
parent60a343b491c05218bced3a22d5ce7c24600e0203 (diff)
wrap external functions for function tables in fastcomp
Diffstat (limited to 'emscripten.py')
-rwxr-xr-xemscripten.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/emscripten.py b/emscripten.py
index 4fdf048e..a0c9efc0 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -913,8 +913,13 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
Counter.i += 1
bad = 'b' + str(i)
params = ','.join(['p%d' % p for p in range(len(sig)-1)])
+ coerced_params = ','.join([shared.JS.make_coercion('p%d', sig[i+1], settings) % p for p in range(len(sig)-1)])
coercions = ';'.join(['p%d = %s' % (p, shared.JS.make_coercion('p%d' % p, sig[p+1], settings)) for p in range(len(sig)-1)]) + ';'
- ret = '' if sig[0] == 'v' else ('return %s' % shared.JS.make_initializer(sig[0], settings))
+ def make_func(name, code):
+ return 'function %s(%s) { %s %s }' % (name, params, coercions, code)
+ Counter.pre = [make_func(bad, ('abort' if not settings['ASSERTIONS'] else 'nullFunc') + '(' + str(i) + ');' + (
+ '' if sig[0] == 'v' else ('return %s' % shared.JS.make_initializer(sig[0], settings))
+ ))]
start = raw.index('[')
end = raw.rindex(']')
body = raw[start+1:end].split(',')
@@ -925,11 +930,20 @@ def emscript_fast(infile, settings, outfile, libraries=[], compiler_engine=None,
Counter.j += 1
newline = Counter.j % 30 == 29
if item == '0': return bad if not newline else (bad + '\n')
+ if item not in metadata['implementedFunctions']:
+ # this is imported into asm, we must wrap it
+ code = item + '(' + coerced_params + ')'
+ if sig[0] != 'v':
+ code = 'return ' + shared.JS.make_coercion(code, sig[0], settings)
+ code += ';'
+ Counter.pre.append(make_func(item + '__wrapper', code))
+ return item + '__wrapper'
return item if not newline else (item + '\n')
body = ','.join(map(fix_item, body))
- return ('function %s(%s) { %s %s(%d); %s }' % (bad, params, coercions, 'abort' if not settings['ASSERTIONS'] else 'nullFunc', i, ret), ''.join([raw[:start+1], body, raw[end:]]))
+ return ('\n'.join(Counter.pre), ''.join([raw[:start+1], body, raw[end:]]))
infos = [make_table(sig, raw) for sig, raw in last_forwarded_json['Functions']['tables'].iteritems()]
+ Counter.pre = []
function_tables_defs = '\n'.join([info[0] for info in infos]) + '\n// EMSCRIPTEN_END_FUNCS\n' + '\n'.join([info[1] for info in infos])