aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlon Zakai <alonzakai@gmail.com>2013-05-15 17:23:23 -0700
committerAlon Zakai <alonzakai@gmail.com>2013-05-15 17:23:23 -0700
commit055e9d90a9737bb1188da696d83d0b983cd34b78 (patch)
treefb8069f800877d621ead8d8f46807f77b605ccce
parentfed8814b7019e90f0fc18e5c1eeac69ec2d09838 (diff)
emit each function table of its own size
-rwxr-xr-xemscripten.py2
-rw-r--r--src/modules.js26
-rwxr-xr-xtests/runner.py4
3 files changed, 20 insertions, 12 deletions
diff --git a/emscripten.py b/emscripten.py
index 367537c2..bc112e4d 100755
--- a/emscripten.py
+++ b/emscripten.py
@@ -322,8 +322,6 @@ def emscript(infile, settings, outfile, libraries=[], compiler_engine=None,
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()) if len(table_counters) > 0 else 2 + 2*settings['RESERVED_FUNCTION_POINTERS']
- forwarded_json['Functions']['nextIndex'] = i
def split_32(x):
x = int(x)
diff --git a/src/modules.js b/src/modules.js
index bd453add..8e029b27 100644
--- a/src/modules.js
+++ b/src/modules.js
@@ -229,6 +229,8 @@ var Types = {
preciseI64MathUsed: (PRECISE_I64_MATH == 2)
};
+var firstTableIndex = (ASM_JS ? 2*RESERVED_FUNCTION_POINTERS : 0) + 2;
+
var Functions = {
// All functions that will be implemented in this file. Maps id to signature
implementedFunctions: {},
@@ -236,7 +238,7 @@ var Functions = {
unimplementedFunctions: {}, // library etc. functions that we need to index, maps id to signature
indexedFunctions: {},
- nextIndex: (ASM_JS ? 2*RESERVED_FUNCTION_POINTERS : 0) + 2, // Start at a non-0 (even, see below) value
+ nextIndex: firstTableIndex, // Start at a non-0 (even, see below) value
neededTables: set('v', 'vi', 'ii', 'iii'), // signatures that appeared (initialized with library stuff
// we always use), and we will need a function table for
@@ -281,22 +283,21 @@ var Functions = {
// Generate code for function indexing
generateIndexing: function() {
- var total = this.nextIndex;
- if (ASM_JS) total = ceilPowerOfTwo(total); // must be power of 2 for mask
- function emptyTable(sig) {
- return zeros(total);
- }
var tables = { pre: '' };
if (ASM_JS) {
keys(Functions.neededTables).forEach(function(sig) { // add some default signatures that are used in the library
- tables[sig] = emptyTable(sig); // TODO: make them compact
+ tables[sig] = zeros(firstTableIndex);
});
}
for (var ident in this.indexedFunctions) {
var sig = ASM_JS ? Functions.implementedFunctions[ident] || Functions.unimplementedFunctions[ident] || LibraryManager.library[ident.substr(1) + '__sig'] : 'x';
assert(sig, ident);
- if (!tables[sig]) tables[sig] = emptyTable(sig); // TODO: make them compact
- tables[sig][this.indexedFunctions[ident]] = ident;
+ if (!tables[sig]) tables[sig] = zeros(firstTableIndex);
+ var index = this.indexedFunctions[ident];
+ for (var i = tables[sig].length; i < index; i++) {
+ tables[sig][i] = 0; // keep flat
+ }
+ tables[sig][index] = ident;
}
var generated = false;
var wrapped = {};
@@ -354,6 +355,13 @@ var Functions = {
j += 10;
}
}
+ if (ASM_JS) {
+ // asm function table mask must be power of two
+ var fullSize = ceilPowerOfTwo(table.length);
+ for (var i = table.length; i < fullSize; i++) {
+ table[i] = 0;
+ }
+ }
var indices = table.toString().replace('"', '');
if (BUILD_AS_SHARED_LIB) {
// Shared libraries reuse the parent's function table.
diff --git a/tests/runner.py b/tests/runner.py
index dc343673..65aea50d 100755
--- a/tests/runner.py
+++ b/tests/runner.py
@@ -7729,13 +7729,15 @@ void*:16
assert 'asm2g' in test_modes
if self.run_name == 'asm2g':
+ original = open('src.cpp.o.js').read()
results = {}
results[Settings.ALIASING_FUNCTION_POINTERS] = len(open('src.cpp.o.js').read())
Settings.ALIASING_FUNCTION_POINTERS = 1 - Settings.ALIASING_FUNCTION_POINTERS
self.do_run(path_from_root('tests', 'cubescript'), '*\nTemp is 33\n9\n5\nhello, everyone\n*', main_file='command.cpp')
results[Settings.ALIASING_FUNCTION_POINTERS] = len(open('src.cpp.o.js').read())
+ open('original.js', 'w').write(original)
print results
- assert results[1] < 0.99*results[0]
+ assert results[1] < results[0]
def test_gcc_unmangler(self):
Settings.NAMED_GLOBALS = 1 # test coverage for this