aboutsummaryrefslogtreecommitdiff
path: root/emscripten.py
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2012-11-30 16:29:52 -0800
committerAlon Zakai <alonzakai@gmail.com>2012-12-07 14:23:21 -0800
commit41359b35684cb512077d1a69ecaf1eb850fd305f (patch)
tree345aaa2e993b2433bb74fc0738541178ad706902 /emscripten.py
parent9db2fd8bc52246c1f073fcfa88ba375fe9391cbd (diff)
move stack manipulation into asm
Diffstat (limited to 'emscripten.py')
-rwxr-xr-xemscripten.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/emscripten.py b/emscripten.py
index 184559e6..7dfe92eb 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -292,12 +292,13 @@ def emscript(infile, settings, outfile, libraries=[]):
function_tables_defs = '\n'.join([table for table in last_forwarded_json['Functions']['tables'].itervalues()])
if settings.get('ASM_JS'):
fundamentals = ['buffer', 'Int8Array', 'Int16Array', 'Int32Array', 'Uint8Array', 'Uint16Array', 'Uint32Array', 'Float32Array', 'Float64Array']
- basics = ['abort', 'assert']
+ basics = ['abort', 'assert', 'STACKTOP', 'STACK_MAX']
+ asm_runtime_funcs = ['stackAlloc', 'stackSave', 'stackRestore']
# calculate exports
function_tables = ['FUNCTION_TABLE_' + table for table in last_forwarded_json['Functions']['tables'].iterkeys()]
exported_implemented_functions = list(exported_implemented_functions)
exports = []
- for export in exported_implemented_functions + function_tables:
+ for export in exported_implemented_functions + function_tables + asm_runtime_funcs:
exports.append("'%s': %s" % (export, export))
exports = '{ ' + ', '.join(exports) + ' }'
# calculate globals
@@ -324,7 +325,21 @@ var asmPre = (function(env, buffer) {
var HEAPU32 = new env.Uint32Array(buffer);
var HEAPF32 = new env.Float32Array(buffer);
var HEAPF64 = new env.Float64Array(buffer);
-''' + asm_globals + '\n' + funcs_js.replace('\n', '\n ') + '''
+''' + asm_globals + '''
+ function stackAlloc(size) {
+ var ret = STACKTOP;
+ STACKTOP = (STACKTOP + size)|0;
+ STACKTOP = ((STACKTOP + 3)>>2)<<2;
+ return ret;
+ }
+ function stackSave() {
+ return STACKTOP;
+ }
+ function stackRestore(top) {
+ top = top|0;
+ STACKTOP = top;
+ }
+''' + funcs_js.replace('\n', '\n ') + '''
%s
@@ -337,6 +352,9 @@ if (asmPre.toSource) { // works in sm but not v8, so we get full coverage betwee
}
var asm = asmPre(%s, buffer); // pass through Function to prevent seeing outside scope
%s;
+Runtime.stackAlloc = function(size) { return asm.stackAlloc(size) };
+Runtime.stackSave = function() { return asm.stackSave() };
+Runtime.stackRestore = function(top) { asm.stackRestore(top) };
''' % (function_tables_defs.replace('\n', '\n '), exports, sending, receiving)
else:
outfile.write(function_tables_defs)