MCPcopy Create free account
hub / github.com/emscripten-core/emscripten / finalize_wasm

Function finalize_wasm

tools/emscripten.py:497–632  ·  view source on GitHub ↗
(infile, outfile, js_syms)

Source from the content-addressed store, hash-verified

495
496
497def finalize_wasm(infile, outfile, js_syms):
498 building.save_intermediate(infile, 'base.wasm')
499 args = []
500
501 # if we don't need to modify the wasm, don't tell finalize to emit a wasm file
502 modify_wasm = False
503 need_name_section = False
504
505 if settings.WASM2JS:
506 # wasm2js requires full legalization (and will do extra wasm binary
507 # later processing later anyhow)
508 modify_wasm = True
509 if settings.DEBUG_LEVEL >= 2 or settings.ASYNCIFY_ADD or settings.ASYNCIFY_ADVISE or settings.ASYNCIFY_ONLY or settings.ASYNCIFY_REMOVE or settings.EMIT_SYMBOL_MAP or settings.EMIT_NAME_SECTION:
510 need_name_section = True
511 args.append('-g')
512 if settings.WASM_BIGINT:
513 args.append('--bigint')
514 if settings.DYNCALLS:
515 # we need to add all dyncalls to the wasm
516 modify_wasm = True
517 else:
518 if settings.WASM_BIGINT:
519 args.append('--no-dyncalls')
520 else:
521 args.append('--dyncalls-i64')
522 # we need to add some dyncalls to the wasm
523 modify_wasm = True
524 if settings.AUTODEBUG:
525 # In AUTODEBUG mode we want to delay all legalization until later. This is hack
526 # to force wasm-emscripten-finalize not to do any legalization at all.
527 args.append('--bigint')
528 else:
529 if settings.LEGALIZE_JS_FFI:
530 # When we dynamically link our JS loader adds functions from wasm modules to
531 # the table. It must add the original versions of them, not legalized ones,
532 # so that indirect calls have the right type, so export those.
533 args += building.js_legalization_pass_flags()
534 modify_wasm = True
535 else:
536 args.append('--no-legalize-javascript-ffi')
537 if settings.SIDE_MODULE:
538 args.append('--side-module')
539 if settings.STACK_OVERFLOW_CHECK >= 2:
540 args.append('--check-stack-overflow')
541 # The check-stack pass in binaryen needs to be able to locate `__stack_pointer` by name.
542 modify_wasm = True
543 need_name_section = True
544 if settings.STANDALONE_WASM:
545 args.append('--standalone-wasm')
546
547 if settings.DEBUG_LEVEL >= 3:
548 args.append('--dwarf')
549
550 if infile != outfile:
551 shutil.copy(infile, outfile)
552
553 if settings.GENERATE_SOURCE_MAP:
554 building.emit_wasm_source_map(infile, outfile + '.map', outfile)

Callers 1

emscriptFunction · 0.85

Calls 11

asmjs_mangleFunction · 0.90
get_metadataFunction · 0.85
appendMethod · 0.80
get_fileMethod · 0.80
encodeMethod · 0.80
updateMethod · 0.80
warningMethod · 0.80
extendMethod · 0.80
setFunction · 0.50
copyMethod · 0.45
removeMethod · 0.45

Tested by

no test coverage detected