diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-15 18:00:57 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-15 18:26:40 -0700 |
commit | a1143f0cf7b7fd5e57a3231fbad13d226426f451 (patch) | |
tree | 9f96da0c04531ca5084e6be1e9389670e07a99ed /src/jsifier.js | |
parent | 8ac26578535936ae2191a8629b4fb3999e3f259f (diff) |
fix both number of arguments and return type based on implementation information, to work around silly llvm function casts
Diffstat (limited to 'src/jsifier.js')
-rw-r--r-- | src/jsifier.js | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index e86a345d..30cea99b 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1474,7 +1474,6 @@ function JSify(data, functionsOnly, givenFunctions) { } args = args.concat(varargs); - var argsText = args.join(', '); // Inline if either we inline whenever we can (and we can), or if there is no noninlined version var inline = LibraryManager.library[simpleIdent + '__inline']; @@ -1496,13 +1495,26 @@ function JSify(data, functionsOnly, givenFunctions) { } } + if (callIdent in Functions.implementedFunctions) { + // LLVM sometimes bitcasts for no reason. We must call using the exact same type as the actual function is generated as. + var numArgs = Functions.implementedFunctions[callIdent].length - 1; + if (numArgs !== args.length) { + if (VERBOSE) warnOnce('Fixing function call arguments based on signature, on ' + [callIdent, args.length, numArgs]); + while (args.length > numArgs) { args.pop(); argsTypes.pop() } + while (args.length < numArgs) { args.push('0'); argsTypes.push('i32') } + } + } + var returnType = 'void'; if ((byPointer || ASM_JS) && hasReturn) { + returnType = getReturnType(type); if (callIdent in Functions.implementedFunctions) { // LLVM sometimes bitcasts for no reason. We must call using the exact same type as the actual function is generated as - returnType = Functions.getSignatureReturnType(Functions.implementedFunctions[callIdent]); - } else { - returnType = getReturnType(type); + var trueType = Functions.getSignatureReturnType(Functions.implementedFunctions[callIdent]); + if (trueType !== returnType && !isIdenticallyImplemented(trueType, returnType)) { + if (VERBOSE) warnOnce('Fixing function call based on return type from signature, on ' + [callIdent, returnType, trueType]); + returnType = trueType; + } } } |