aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemscripten.py17
-rw-r--r--src/jsifier.js1
-rw-r--r--src/modules.js1
-rw-r--r--src/postamble.js4
4 files changed, 18 insertions, 5 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)
diff --git a/src/jsifier.js b/src/jsifier.js
index a7c04c89..90e74db6 100644
--- a/src/jsifier.js
+++ b/src/jsifier.js
@@ -420,6 +420,7 @@ function JSify(data, functionsOnly, givenFunctions) {
snippet = snippet.replace('{', '{ var ret = (function() { if (Runtime.debug) Module.printErr("[library call:' + ident + ': " + Array.prototype.slice.call(arguments).map(Runtime.prettyPrint) + "]"); ');
snippet = snippet.substr(0, snippet.length-1) + '}).apply(this, arguments); if (Runtime.debug && typeof ret !== "undefined") Module.printErr(" [ return:" + Runtime.prettyPrint(ret)); return ret; }';
}
+ if (ASM_JS) Functions.libraryFunctions.push(ident);
}
var postsetId = ident + '__postset';
diff --git a/src/modules.js b/src/modules.js
index f9173f8e..94fe582c 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -218,6 +218,7 @@ var Types = {
var Functions = {
// All functions that will be implemented in this file
implementedFunctions: {},
+ libraryFunctions: [], // functions added from the library
indexedFunctions: {},
nextIndex: 2, // Start at a non-0 (even, see below) value
diff --git a/src/postamble.js b/src/postamble.js
index 144b5af9..83a4daa6 100644
--- a/src/postamble.js
+++ b/src/postamble.js
@@ -19,11 +19,11 @@ Module.callMain = function callMain(args) {
#if CATCH_EXIT_CODE
try {
- return _main(argc, argv, 0);
+ return Module['_main'](argc, argv, 0);
}
catch(e) { if (e.name == "ExitStatus") return e.status; throw e; }
#else
- return _main(argc, argv, 0);
+ return Module['_main'](argc, argv, 0);
#endif
}