diff options
author | Alon Zakai <alonzakai@gmail.com> | 2012-11-29 15:05:41 -0800 |
---|---|---|
committer | Alon Zakai <alonzakai@gmail.com> | 2012-12-07 14:23:20 -0800 |
commit | e944bb4580c4105a6653bcba4c0832d85f389843 (patch) | |
tree | aeab5a5779166d663ce524303342c78ccf76cc5c /src | |
parent | df5d5b01426005ef577f5e7ddd9754804e53613c (diff) |
export global constructors from asm.js and get them dynamically in the outside scope
Diffstat (limited to 'src')
-rw-r--r-- | src/intertyper.js | 7 | ||||
-rw-r--r-- | src/jsifier.js | 2 | ||||
-rw-r--r-- | src/modules.js | 3 |
3 files changed, 9 insertions, 3 deletions
diff --git a/src/intertyper.js b/src/intertyper.js index e727cc8b..f63e0982 100644 --- a/src/intertyper.js +++ b/src/intertyper.js @@ -521,7 +521,12 @@ function intertyper(data, sidePass, baseLineNums) { if (item.tokens[3].item) { var subTokens = item.tokens[3].item.tokens; splitTokenList(subTokens).forEach(function(segment) { - ret.ctors.push(segment[1].tokens.slice(-1)[0].text); + var ctor = toNiceIdent(segment[1].tokens.slice(-1)[0].text); + ret.ctors.push(ctor); + if (ASM_JS) { // must export the global constructors from asm.js module, so mark as implemented and exported + Functions.implementedFunctions[ctor] = 'v'; + EXPORTED_FUNCTIONS[ctor] = 1; + } }); } } else if (!external) { diff --git a/src/jsifier.js b/src/jsifier.js index f6a3647b..aa18e269 100644 --- a/src/jsifier.js +++ b/src/jsifier.js @@ -260,7 +260,7 @@ function JSify(data, functionsOnly, givenFunctions) { var ret = [item]; if (item.ident == '_llvm_global_ctors') { item.JS = '\n__ATINIT__ = __ATINIT__.concat([\n' + - item.ctors.map(function(ctor) { return ' { func: ' + toNiceIdent(ctor) + ' }' }).join(',\n') + + item.ctors.map(function(ctor) { return ' { func: function() { ' + ctor + '() } }' }).join(',\n') + '\n]);\n'; return ret; } else { diff --git a/src/modules.js b/src/modules.js index 15aaa568..d201ceae 100644 --- a/src/modules.js +++ b/src/modules.js @@ -348,7 +348,8 @@ var PassManager = { print('\n//FORWARDED_DATA:' + JSON.stringify({ Types: Types, Variables: Variables, - Functions: Functions + Functions: Functions, + EXPORTED_FUNCTIONS: EXPORTED_FUNCTIONS // needed for asm.js global constructors (ctors) })); } else if (phase == 'funcs') { print('\n//FORWARDED_DATA:' + JSON.stringify({ |