aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/jsifier.js19
-rw-r--r--src/modules.js9
2 files changed, 22 insertions, 6 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) {