From f5c71a90e79a645ef9e44d6685907b86f8cf3c00 Mon Sep 17 00:00:00 2001 From: Alon Zakai Date: Fri, 28 Jun 2013 16:36:36 -0700 Subject: clone aliased functions in shared modules --- src/jsifier.js | 18 ++++++++++++++++++ src/modules.js | 2 ++ 2 files changed, 20 insertions(+) (limited to 'src') diff --git a/src/jsifier.js b/src/jsifier.js index 83cb7517..5eae2018 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -390,6 +390,11 @@ function JSify(data, functionsOnly, givenFunctions) { dependencies: set([value]), JS: item.ident + ' = ' + value + ';' + fix }); + if ((MAIN_MODULE || SIDE_MODULE) && isFunctionType(item.type)) { + var target = item.value.ident; + if (!Functions.aliases[target]) Functions.aliases[target] = []; + Functions.aliases[target].push(item.ident); + } return ret; } }); @@ -847,6 +852,19 @@ function JSify(data, functionsOnly, givenFunctions) { } func.JS = func.JS.replace(/\n *;/g, '\n'); // remove unneeded lines + + if (MAIN_MODULE || SIDE_MODULE) { + // Clone the function for each of its aliases. We do not know which name it will be used by in another module, + // and we do not have a heavyweight metadata system to resolve aliases during linking + var aliases = Functions.aliases[func.ident]; + if (aliases) { + var body = func.JS.substr(func.JS.indexOf('(')); + aliases.forEach(function(alias) { + func.JS += '\n' + 'function ' + alias + body; + }); + } + } + return func; } }); diff --git a/src/modules.js b/src/modules.js index d26acbd5..e04304fa 100644 --- a/src/modules.js +++ b/src/modules.js @@ -245,6 +245,8 @@ 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++) { -- cgit v1.2.3-18-g5258