diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-10-25 16:51:18 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-10-25 17:01:44 -0700 |
commit | 296cd5f54cb598fad7c9e58776bac906da1add02 (patch) | |
tree | 80bbc4c143b780f62f4814d19b58c803466d22e1 /src | |
parent | 5041ed44a66938588e674b9f7c03b9281b99c4e1 (diff) |
support fround in function tables and asm module support functions
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | src/modules.js | 41 |
2 files changed, 28 insertions, 15 deletions
diff --git a/src/jsifier.js b/src/jsifier.js index 7a2fdde0..79ad9c03 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -1579,7 +1579,7 @@ function JSify(data, functionsOnly, givenFunctions) { 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 - var trueType = Functions.getSignatureReturnType(Functions.implementedFunctions[callIdent]); + var trueType = Functions.getSignatureType(Functions.implementedFunctions[callIdent][0]); if (trueType !== returnType && !isIdenticallyImplemented(trueType, returnType)) { if (VERBOSE) warnOnce('Fixing function call based on return type from signature, on ' + [callIdent, returnType, trueType]); returnType = trueType; diff --git a/src/modules.js b/src/modules.js index 814817a3..2e6edeba 100644 --- a/src/modules.js +++ b/src/modules.js @@ -253,13 +253,32 @@ var Functions = { aliases: {}, // in shared modules (MAIN_MODULE or SHARED_MODULE), a list of aliases for functions that have them + getSignatureLetter: function(type) { + switch(type) { + case 'float': return 'f'; + case 'double': return 'd'; + case 'void': return 'v'; + default: return 'i'; + } + }, + + getSignatureType: function(letter) { + switch(letter) { + case 'v': return 'void'; + case 'i': return 'i32'; + case 'f': return 'float'; + case 'd': return 'double'; + default: throw 'what is this sig? ' + sig; + } + }, + getSignature: function(returnType, argTypes, hasVarArgs) { - var sig = returnType == 'void' ? 'v' : (isIntImplemented(returnType) ? 'i' : 'f'); + var sig = Functions.getSignatureLetter(returnType); for (var i = 0; i < argTypes.length; i++) { var type = argTypes[i]; if (!type) break; // varargs if (type in Runtime.FLOAT_TYPES) { - sig += 'f'; + sig += Functions.getSignatureLetter(type); } else { var chunks = getNumIntChunks(type); for (var j = 0; j < chunks; j++) sig += 'i'; @@ -269,15 +288,6 @@ var Functions = { return sig; }, - getSignatureReturnType: function(sig) { - switch(sig[0]) { - case 'v': return 'void'; - case 'i': return 'i32'; - case 'f': return 'double'; - default: throw 'what is this sig? ' + sig; - } - }, - // Mark a function as needing indexing. Python will coordinate them all getIndex: function(ident, sig) { var ret; @@ -353,14 +363,17 @@ var Functions = { if (t[0] == 'i') { retPre = 'return '; retPost = '|0'; - } else { + } else if (t[0] === 'd') { retPre = 'return +'; + } else { + retPre = 'return Math_fround('; + retPost = ')'; } } for (var j = 1; j < t.length; j++) { args += (j > 1 ? ',' : '') + 'a' + j; - arg_coercions += 'a' + j + '=' + asmCoercion('a' + j, t[j] != 'i' ? 'float' : 'i32') + ';'; - call += (j > 1 ? ',' : '') + asmCoercion('a' + j, t[j] != 'i' ? 'float' : 'i32'); + arg_coercions += 'a' + j + '=' + asmCoercion('a' + j, Functions.getSignatureType(t[j])) + ';'; + call += (j > 1 ? ',' : '') + asmCoercion('a' + j, Functions.getSignatureType(t[j])); } call += ')'; if (short == '_setjmp') printErr('WARNING: setjmp used via a function pointer. If this is for libc setjmp (not something of your own with the same name), it will break things'); |