aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xemscripten.py23
-rw-r--r--src/settings.js4
2 files changed, 22 insertions, 5 deletions
diff --git a/emscripten.py b/emscripten.py
index 35edc515..b99c0c09 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -302,13 +302,26 @@ 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
+ 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
+ if alias: i = max(table_counters.values())
+ forwarded_json['Functions']['nextIndex'] = i # post phase can continue to add, in getIndex
function_table_size = forwarded_json['Functions']['nextIndex']
i = 1
while i < function_table_size:
diff --git a/src/settings.js b/src/settings.js
index 8766277b..d3abb06e 100644
--- a/src/settings.js
+++ b/src/settings.js
@@ -142,6 +142,10 @@ var SAFE_DYNCALLS = 0; // Show stack traces on missing function pointer/virtual
var RESERVED_FUNCTION_POINTERS = 0; // In asm.js mode, we cannot simply add function pointers to
// function tables, so we reserve some slots for them.
+var ALIASING_FUNCTION_POINTERS = 0; // Whether to allow function pointers to alias if they have
+ // a different type. This can greatly decrease table sizes
+ // in asm.js, but can break code that compares function
+ // pointers across different types.
var ASM_HEAP_LOG = 0; // Simple heap logging, like SAFE_HEAP_LOG but cheaper, and in asm.js