diff options
-rw-r--r-- | src/jsifier.js | 19 | ||||
-rw-r--r-- | src/modules.js | 9 | ||||
-rwxr-xr-x | tests/runner.py | 2 |
3 files changed, 23 insertions, 7 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 4b422bca..83b65b5b 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -424,7 +424,9 @@ function JSify(data, functionsOnly, givenFunctions) { deps.push(snippet); snippet = '_' + snippet; } - if (ASM_JS && (typeof target == 'function' || /Math\..+/.exec(snippet))) { + // In asm, we need to know about library functions. If there is a target, though, then no + // need to consider this a library function - we will call directly to it anyhow + if (ASM_JS && !redirectedIdent && (typeof target == 'function' || /Math\..+/.exec(snippet))) { Functions.libraryFunctions[ident] = 1; } } else if (typeof snippet === 'object') { @@ -1234,7 +1236,14 @@ function JSify(data, functionsOnly, givenFunctions) { // We cannot compile assembly. See comment in intertyper.js:'Call' assert(ident != 'asm', 'Inline assembly cannot be compiled to JavaScript!'); - var shortident = LibraryManager.getRootIdent(ident.slice(1)) || ident.slice(1); // ident may not be in library, if all there is is ident__inline + var shortident = ident.slice(1); + var callIdent = LibraryManager.getRootIdent(shortident); + if (callIdent) { + shortident = callIdent; // ident may not be in library, if all there is is ident__inline, but in this case it is + callIdent = '_' + callIdent; + } else { + callIdent = ident; + } var args = []; var argsTypes = []; var varargs = []; @@ -1322,12 +1331,12 @@ function JSify(data, functionsOnly, givenFunctions) { var sig = Functions.getSignature(returnType, argsTypes); if (ASM_JS) { assert(returnType.search(/\("'\[,/) == -1); // XXX need isFunctionType(type, out) - ident = '(' + ident + ')&{{{ FTM_' + sig + ' }}}'; // the function table mask is set in emscripten.py + callIdent = '(' + callIdent + ')&{{{ FTM_' + sig + ' }}}'; // the function table mask is set in emscripten.py } - ident = Functions.getTable(sig) + '[' + ident + ']'; + callIdent = Functions.getTable(sig) + '[' + callIdent + ']'; } - var ret = ident + '(' + args.join(', ') + ')'; + var ret = callIdent + '(' + args.join(', ') + ')'; if (ASM_JS) { // TODO: do only when needed (library functions and Math.*?) XXX && shortident in Functions.libraryFunctions) { ret = asmCoercion(ret, returnType); if (shortident == 'abort' && funcData.returnType != 'void') { diff --git a/src/modules.js b/src/modules.js index b31567be..18e98d76 100644 --- a/src/modules.js +++ b/src/modules.js @@ -275,17 +275,24 @@ var Functions = { if (!tables[sig]) tables[sig] = emptyTable(sig); // TODO: make them compact tables[sig][this.indexedFunctions[ident]] = ident; } - // Resolve multi-level aliases all the way down var generated = false; for (var t in tables) { generated = true; var table = tables[t]; for (var i = 0; i < table.length; i++) { + // Resolve multi-level aliases all the way down while (1) { var varData = Variables.globals[table[i]]; if (!(varData && varData.resolvedAlias)) break; table[i] = table[+varData.resolvedAlias || eval(varData.resolvedAlias)]; // might need to eval to turn (6) into 6 } + // Resolve library aliases + if (table[i]) { + var libName = LibraryManager.getRootIdent(table[i].substr(1)); + if (libName && typeof libName == 'string') { + table[i] = '_' + libName; + } + } } var indices = table.toString().replace('"', ''); if (BUILD_AS_SHARED_LIB) { diff --git a/tests/runner.py b/tests/runner.py index 24fbee95..93827ba5 100755 --- a/tests/runner.py +++ b/tests/runner.py @@ -10518,7 +10518,7 @@ elif 'benchmark' in str(sys.argv): try_delete(final_filename) output = Popen([PYTHON, EMCC, filename, #'-O3', - '-O2', '-s', 'INLINING_LIMIT=0', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0', + '-O2', '-s', 'INLINING_LIMIT=0', '-s', 'DOUBLE_MODE=0', '-s', 'PRECISE_I64_MATH=0',# '-s', 'ASM_JS=1', '-s', 'TOTAL_MEMORY=128*1024*1024', '-s', 'FAST_MEMORY=10*1024*1024', '-o', final_filename] + emcc_args, stdout=PIPE, stderr=self.stderr_redirect).communicate() assert os.path.exists(final_filename), 'Failed to compile file: ' + output[0] |