diff options
author | Alon Zakai <alonzakai@gmail.com> | 2013-06-28 16:36:36 -0700 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2013-07-03 15:31:04 -0700 |
commit | f5c71a90e79a645ef9e44d6685907b86f8cf3c00 (patch) | |
tree | 16bb8b22271ea1a0504d864ed1a3b79547268466 /src | |
parent | 11db72239d48da525e0978a608e4cdfb91168981 (diff) |
clone aliased functions in shared modules
Diffstat (limited to 'src')
-rw-r--r-- | src/jsifier.js | 18 | ||||
-rw-r--r-- | src/modules.js | 2 |
2 files changed, 20 insertions, 0 deletions
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++) { |