aboutsummaryrefslogtreecommitdiff
path: root/emscripten.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-24 19:34:25 +0100
committerAlon Zakai <alonzakai@gmail.com>2012-12-07 14:23:18 -0800
commitdf6018759a472685fee5fafd188f091dab5fd4fd (patch)
tree223143ffb1dd7477a2077143fc9336244c1367e2 /emscripten.py
parent887ef685cd7e6d9af9e45016dc6c714feaf281d3 (diff)
add asm imports and exports, hello world works
Diffstat (limited to 'emscripten.py')
-rwxr-xr-xemscripten.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/emscripten.py b/emscripten.py
index ce2ab680..a9a1824d 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -238,11 +238,21 @@ def emscript(infile, settings, outfile, libraries=[]):
if key in all_exported_functions: exported_implemented_functions.add(key)
funcs_js = ''.join([output[0] for output in outputs])
+
if settings.get('ASM_JS'):
+ # calculate exports
exports = []
for export in exported_implemented_functions:
exports.append("'%s': %s" % (export, export))
exports = '{ ' + ', '.join(exports) + ' }'
+ # caculate globals
+ global_vars = forwarded_json['Variables']['globals'].keys()
+ global_funcs = ['_' + x for x in forwarded_json['Functions']['libraryFunctions']]
+ asm_globals = ''.join([' var ' + g + '=env.' + g + ';\n' for g in global_vars + global_funcs])
+ # sent data
+ basics = ['buffer', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
+ sending = '{ ' + ', '.join([s + ': ' + s for s in basics + global_vars + global_funcs]) + ' }'
+ # finalize
funcs_js = '''
var asm = (function(env, buffer) {
'use asm';
@@ -254,11 +264,12 @@ var asm = (function(env, buffer) {
var HEAPU32 = new env.Uint32Array(buffer);
var HEAPF32 = new env.Float32Array(buffer);
var HEAPF64 = new env.Float64Array(buffer);
-''' + funcs_js.replace('\n', '\n ') + '''
+''' + asm_globals + '\n' + funcs_js.replace('\n', '\n ') + '''
+
return %s;
-})({}, buffer);
+})(%s, buffer);
for (var _export in asm) Module[_export] = asm[_export];
-''' % exports
+''' % (exports, sending)
outputs = None
if DEBUG: print >> sys.stderr, ' emscript: phase 2b took %s seconds' % (time.time() - t)