export global constructors from asm.js and get them dynamically in the outside scope
This commit is contained in:
Родитель
df5d5b0142
Коммит
e944bb4580
|
@ -128,10 +128,12 @@ def emscript(infile, settings, outfile, libraries=[]):
|
|||
|
||||
# Save settings to a file to work around v8 issue 1579
|
||||
settings_file = temp_files.get('.txt').name
|
||||
settings_text = json.dumps(settings)
|
||||
s = open(settings_file, 'w')
|
||||
s.write(settings_text)
|
||||
s.close()
|
||||
def save_settings():
|
||||
settings_text = json.dumps(settings)
|
||||
s = open(settings_file, 'w')
|
||||
s.write(settings_text)
|
||||
s.close()
|
||||
save_settings()
|
||||
|
||||
# Phase 1 - pre
|
||||
if DEBUG: t = time.time()
|
||||
|
@ -169,6 +171,9 @@ def emscript(infile, settings, outfile, libraries=[]):
|
|||
if DEBUG: t = time.time()
|
||||
forwarded_json = json.loads(forwarded_data)
|
||||
indexed_functions = set()
|
||||
if settings.get('ASM_JS'):
|
||||
settings['EXPORTED_FUNCTIONS'] = forwarded_json['EXPORTED_FUNCTIONS']
|
||||
save_settings()
|
||||
|
||||
chunks = shared.JCache.chunkify(funcs, chunk_size, 'emscript_files' if jcache else None)
|
||||
|
||||
|
@ -293,6 +298,7 @@ def emscript(infile, settings, outfile, libraries=[]):
|
|||
exports.append("'%s': %s" % (export, export))
|
||||
exports = '{ ' + ', '.join(exports) + ' }'
|
||||
# calculate globals
|
||||
del forwarded_json['Variables']['globals']['_llvm_global_ctors'] # not a true variable
|
||||
global_vars = forwarded_json['Variables']['globals'].keys()
|
||||
global_funcs = ['_' + x for x in forwarded_json['Functions']['libraryFunctions'].keys()]
|
||||
asm_globals = ''.join([' var ' + g + '=env.' + g + ';\n' for g in basics + global_funcs + global_vars])
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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({
|
||||
|
|
Загрузка…
Ссылка в новой задаче