Skip to content

Commit 1d45643

Browse files
authored
Allow <<< ATXXX >> code hooks in any part of the generated JS. NFC (#24042)
This also simplify the writing of the final module to use the common `write_file` utility. I think in the past the generated JS could be so large that python could have trouble processing it but I think that dates back the asm.js days when the generated JS conatains all the asm.js generated code. These days the size of the JS clue is never proportional to the size of the input C/C++ program like it was back then.
1 parent bb29e61 commit 1d45643

1 file changed

Lines changed: 11 additions & 25 deletions

File tree

tools/emscripten.py

Lines changed: 11 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,6 @@
5353
]
5454

5555

56-
def write_output_file(outfile, module):
57-
for chunk in module:
58-
outfile.write(chunk)
59-
60-
6156
def maybe_disable_filesystem(imports):
6257
"""Disables filesystem if only a limited subset of syscalls is used.
6358
@@ -412,13 +407,6 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
412407

413408
report_missing_exports(forwarded_json['librarySymbols'])
414409

415-
if settings.MINIMAL_RUNTIME:
416-
# In MINIMAL_RUNTIME, atinit exists in the postamble part
417-
post = apply_static_code_hooks(forwarded_json, post)
418-
else:
419-
# In regular runtime, atinits etc. exist in the preamble part
420-
pre = apply_static_code_hooks(forwarded_json, pre)
421-
422410
asm_const_pairs = ['%s: %s' % (key, value) for key, value in asm_consts]
423411
if asm_const_pairs or settings.MAIN_MODULE:
424412
pre += 'var ASM_CONSTS = {\n ' + ', \n '.join(asm_const_pairs) + '\n};\n'
@@ -440,20 +428,18 @@ def emscript(in_wasm, out_wasm, outfile_js, js_syms, finalize=True, base_metadat
440428
function_exports['asyncify_start_rewind'] = webassembly.FuncType([webassembly.Type.I32], [])
441429
function_exports['asyncify_stop_rewind'] = webassembly.FuncType([], [])
442430

443-
with open(outfile_js, 'w', encoding='utf-8') as out:
444-
out.write(pre)
445-
pre = None
446-
447-
receiving = create_receiving(function_exports)
448-
if settings.WASM_ESM_INTEGRATION:
449-
sending = create_sending(metadata, forwarded_json['librarySymbols'])
450-
module = [sending, receiving]
451-
else:
452-
module = create_module(receiving, metadata, global_exports, forwarded_json['librarySymbols'])
453-
write_output_file(out, module)
431+
parts = [pre]
432+
receiving = create_receiving(function_exports)
433+
if settings.WASM_ESM_INTEGRATION:
434+
sending = create_sending(metadata, forwarded_json['librarySymbols'])
435+
parts += [sending, receiving]
436+
else:
437+
parts += create_module(receiving, metadata, global_exports, forwarded_json['librarySymbols'])
438+
parts.append(post)
454439

455-
out.write(post)
456-
module = None
440+
full_js_module = ''.join(parts)
441+
full_js_module = apply_static_code_hooks(forwarded_json, full_js_module)
442+
utils.write_file(outfile_js, full_js_module)
457443

458444
metadata.library_definitions = forwarded_json['libraryDefinitions']
459445
return metadata

0 commit comments

Comments
 (0)