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

Function create_receiving

tools/emscripten.py:956–1082  ·  view source on GitHub ↗
(function_exports, other_exports, library_symbols, aliases)

Source from the content-addressed store, hash-verified

954
955
956def create_receiving(function_exports, other_exports, library_symbols, aliases):
957 generate_dyncall_assignment = 'dynCalls' in library_symbols
958 receiving = ['\n// Imports from the Wasm binary.']
959
960 if settings.WASM_ESM_INTEGRATION:
961 exported_symbols = [e[0].name for e in other_exports] + list(function_exports.keys())
962 exports = []
963 for sym in exported_symbols:
964 mangled = asmjs_mangle(sym)
965 if mangled != sym:
966 exports.append(f'{sym} as {mangled}')
967 else:
968 exports.append(sym)
969 for alias, target in aliases.items():
970 exports.append(f'{target} as {alias}')
971
972 receiving.append('import {')
973 receiving.append(' ' + ',\n '.join(exports))
974 receiving.append(f"}} from './{settings.WASM_BINARY_FILE}';")
975
976 if generate_dyncall_assignment:
977 receiving.append('\nfunction assignDynCalls() {')
978 receiving.append(' // Construct dynCalls mapping')
979 for sym in function_exports:
980 if sym.startswith('dynCall_'):
981 sig_str = sym.removeprefix('dynCall_')
982 receiving.append(f" dynCalls['{sig_str}'] = {sym};")
983 receiving.append('}')
984
985 return '\n'.join(receiving)
986
987 # When not declaring asm exports `assignWasmExports` is instead defined as a simple
988 # library function.
989 if not settings.DECLARE_ASM_MODULE_EXPORTS:
990 return ''
991
992 # Exports are assigned inside a function to variables
993 # existing in top level JS scope, i.e.
994 # var _main;
995 # function assignWasmExports(wasmExport) {
996 # _main = wasmExports["_main"];
997 exports = {name: sig for name, sig in function_exports.items() if name != building.WASM_CALL_CTORS}
998 for export, info in other_exports:
999 exports[export.name] = (export, info)
1000
1001 mangled = [asmjs_mangle(s) for s in exports] + list(aliases.keys())
1002 if settings.ASSERTIONS:
1003 # In debug builds we generate trapping functions in case
1004 # folks try to call/use a reference that was taken before the
1005 # wasm module is available.
1006 for sym in mangled:
1007 module_export = (settings.MODULARIZE or not settings.MINIMAL_RUNTIME) and should_export(sym) and settings.MODULARIZE != 'instance'
1008 if not js_manipulation.isidentifier(sym) and not module_export:
1009 continue
1010 assignment = f'var {sym}'
1011 if module_export:
1012 if js_manipulation.isidentifier(sym):
1013 assignment += f" = Module['{sym}']"

Callers 1

create_moduleFunction · 0.85

Calls 7

asmjs_mangleFunction · 0.90
should_exportFunction · 0.85
install_debug_wrapperFunction · 0.85
appendMethod · 0.80
keysMethod · 0.65
typeEnum · 0.50
joinMethod · 0.45

Tested by

no test coverage detected