diff options
Diffstat (limited to 'emscripten.py')
-rwxr-xr-x | emscripten.py | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/emscripten.py b/emscripten.py index 7352b293..248d0ce4 100755 --- a/emscripten.py +++ b/emscripten.py @@ -288,6 +288,8 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, exported_implemented_functions.add(key) for key, value in curr_forwarded_json['Functions']['unimplementedFunctions'].iteritems(): forwarded_json['Functions']['unimplementedFunctions'][key] = value + for key, value in curr_forwarded_json['Functions']['neededTables'].iteritems(): + forwarded_json['Functions']['neededTables'][key] = value if settings.get('ASM_JS'): parts = pre.split('// ASM_LIBRARY FUNCTIONS\n') @@ -302,13 +304,24 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, # calculations on merged forwarded data forwarded_json['Functions']['indexedFunctions'] = {} - i = 2 + i = 2 # universal counter if settings['ASM_JS']: i += 2*settings['RESERVED_FUNCTION_POINTERS'] + table_counters = {} # table-specific counters + alias = settings['ASM_JS'] and settings['ALIASING_FUNCTION_POINTERS'] + sig = None for indexed in indexed_functions: - #print >> sys.stderr, 'function indexing', indexed, i - forwarded_json['Functions']['indexedFunctions'][indexed] = i # make sure not to modify this python object later - we use it in indexize - i += 2 - forwarded_json['Functions']['nextIndex'] = i + if alias: + sig = forwarded_json['Functions']['implementedFunctions'].get(indexed) or forwarded_json['Functions']['unimplementedFunctions'].get(indexed) + assert sig, indexed + if sig not in table_counters: + table_counters[sig] = 2 + 2*settings['RESERVED_FUNCTION_POINTERS'] + curr = table_counters[sig] + table_counters[sig] += 2 + else: + curr = i + i += 2 + #print >> sys.stderr, 'function indexing', indexed, curr, sig + forwarded_json['Functions']['indexedFunctions'][indexed] = curr # make sure not to modify this python object later - we use it in indexize def split_32(x): x = int(x) @@ -365,14 +378,6 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, pre_tables = last_forwarded_json['Functions']['tables']['pre'] del last_forwarded_json['Functions']['tables']['pre'] - # Find function table calls without function tables generated for them - for funcs_js_item in funcs_js: - for use in set(re.findall(r'{{{ FTM_[\w\d_$]+ }}}', funcs_js_item)): - sig = use[8:len(use)-4] - if sig not in last_forwarded_json['Functions']['tables']: - if DEBUG: print >> sys.stderr, 'add empty function table', sig - last_forwarded_json['Functions']['tables'][sig] = 'var FUNCTION_TABLE_' + sig + ' = [' + ','.join(['0']*forwarded_json['Functions']['nextIndex']) + '];\n' - def make_table(sig, raw): i = Counter.i Counter.i += 1 @@ -451,10 +456,10 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None, asm_setup += ''' function invoke_%s(%s) { try { - %sModule.dynCall_%s(%s); + %sModule["dynCall_%s"](%s); } catch(e) { if (typeof e !== 'number' && e !== 'longjmp') throw e; - asm.setThrew(1, 0); + asm["setThrew"](1, 0); } } ''' % (sig, args, 'return ' if sig[0] != 'v' else '', sig, args) @@ -484,11 +489,11 @@ function invoke_%s(%s) { asm_global_vars = ''.join([' var ' + g + '=env.' + g + '|0;\n' for g in basic_vars + global_vars]) + \ ''.join([' var ' + g + '=+env.' + g + ';\n' for g in basic_float_vars]) # sent data - the_global = '{ ' + ', '.join([math_fix(s) + ': ' + s for s in fundamentals]) + ' }' - sending = '{ ' + ', '.join([math_fix(s) + ': ' + s for s in basic_funcs + global_funcs + basic_vars + basic_float_vars + global_vars]) + ' }' + the_global = '{ ' + ', '.join(['"' + math_fix(s) + '": ' + s for s in fundamentals]) + ' }' + sending = '{ ' + ', '.join(['"' + math_fix(s) + '": ' + s for s in basic_funcs + global_funcs + basic_vars + basic_float_vars + global_vars]) + ' }' # received if not simple: - receiving = ';\n'.join(['var ' + s + ' = Module["' + s + '"] = asm.' + s for s in exported_implemented_functions + function_tables]) + receiving = ';\n'.join(['var ' + s + ' = Module["' + s + '"] = asm["' + s + '"]' for s in exported_implemented_functions + function_tables]) else: receiving = 'var _main = Module["_main"] = asm;' @@ -560,9 +565,9 @@ var asm = (function(global, env, buffer) { // EMSCRIPTEN_END_ASM (%s, %s, buffer); %s; -Runtime.stackAlloc = function(size) { return asm.stackAlloc(size) }; -Runtime.stackSave = function() { return asm.stackSave() }; -Runtime.stackRestore = function(top) { asm.stackRestore(top) }; +Runtime.stackAlloc = function(size) { return asm['stackAlloc'](size) }; +Runtime.stackSave = function() { return asm['stackSave']() }; +Runtime.stackRestore = function(top) { asm['stackRestore'](top) }; ''' % (pre_tables + '\n'.join(function_tables_impls) + '\n' + function_tables_defs.replace('\n', '\n '), exports, the_global, sending, receiving)] # Set function table masks |