diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-07-16 13:41:37 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-16 13:41:37 -0700 |
commit | b0d268d121d8868be33d8633b09499b34a4db45f (patch) | |
tree | d67eaf4f5e200b5b5f57099c46a1413d43cbd287 /src/modules.js | |
parent | 6b730836aa53f6b4896f24dd8a4b456669ae4f1a (diff) | |
parent | 475e72dc5539d9c59fc267927441a502c14a178f (diff) |
Merge branch 'incoming'
Diffstat (limited to 'src/modules.js')
-rw-r--r-- | src/modules.js | 36 |
1 files changed, 30 insertions, 6 deletions
diff --git a/src/modules.js b/src/modules.js index d26acbd5..9f419234 100644 --- a/src/modules.js +++ b/src/modules.js @@ -245,37 +245,60 @@ var Functions = { blockAddresses: {}, // maps functions to a map of block labels to label ids + aliases: {}, // in shared modules (MAIN_MODULE or SHARED_MODULE), a list of aliases for functions that have them + getSignature: function(returnType, argTypes, hasVarArgs) { var sig = returnType == 'void' ? 'v' : (isIntImplemented(returnType) ? 'i' : 'f'); for (var i = 0; i < argTypes.length; i++) { var type = argTypes[i]; if (!type) break; // varargs - sig += isIntImplemented(type) ? (getBits(type) == 64 ? 'ii' : 'i') : 'f'; // legalized i64s will be i32s + if (type in Runtime.FLOAT_TYPES) { + sig += 'f'; + } else { + var chunks = getNumIntChunks(type); + for (var j = 0; j < chunks; j++) sig += 'i'; + } } if (hasVarArgs) sig += 'i'; 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, doNotCreate) { + getIndex: function(ident, doNotCreate, sig) { if (doNotCreate && !(ident in this.indexedFunctions)) { if (!Functions.getIndex.tentative) Functions.getIndex.tentative = {}; // only used by GL emulation; TODO: generalize when needed Functions.getIndex.tentative[ident] = 0; } + var ret; if (phase != 'post' && singlePhase) { if (!doNotCreate) this.indexedFunctions[ident] = 0; // tell python we need this indexized - return "'{{ FI_" + toNiceIdent(ident) + " }}'"; // something python will replace later + ret = "'{{ FI_" + toNiceIdent(ident) + " }}'"; // something python will replace later } else { if (!singlePhase) return 'NO_INDEX'; // Should not index functions in post - var ret = this.indexedFunctions[ident]; + ret = this.indexedFunctions[ident]; if (!ret) { if (doNotCreate) return '0'; ret = this.nextIndex; this.nextIndex += 2; // Need to have indexes be even numbers, see |polymorph| test this.indexedFunctions[ident] = ret; } - return ret.toString(); + ret = ret.toString(); + } + if (SIDE_MODULE && sig) { // sig can be undefined for the GL library functions + ret = '((F_BASE_' + sig + ' + ' + ret + ')|0)'; + } else if (BUILD_AS_SHARED_LIB) { + ret = '(FUNCTION_TABLE_OFFSET + ' + ret + ')'; } + return ret; }, getTable: function(sig) { @@ -440,7 +463,8 @@ var PassManager = { Types: Types, Variables: Variables, Functions: Functions, - EXPORTED_FUNCTIONS: EXPORTED_FUNCTIONS // needed for asm.js global constructors (ctors) + EXPORTED_FUNCTIONS: EXPORTED_FUNCTIONS, // needed for asm.js global constructors (ctors) + Runtime: { GLOBAL_BASE: Runtime.GLOBAL_BASE } })); } else if (phase == 'funcs') { print('\n//FORWARDED_DATA:' + JSON.stringify({ |