Skip to content

Commit

Permalink
Move code in metadce to avoid handling mangling twice. NFC (emscrip…
Browse files Browse the repository at this point in the history
…ten-core#21812)

The stripping of the initial leading underscore can be done first
to avoid having to do when mapping the wasi function names.
  • Loading branch information
sbc100 authored Apr 23, 2024
1 parent b9e2a14 commit e57881a
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions tools/building.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,6 +762,13 @@ def metadce(js_file, wasm_file, debug_info):
export = asmjs_mangle(item['export'])
if settings.EXPORT_ALL or export in required_symbols:
item['root'] = True

# fixup wasm backend prefixing
for item in graph:
if 'import' in item:
if item['import'][1][0] == '_':
item['import'][1] = item['import'][1][1:]

# fix wasi imports TODO: support wasm stable with an option?
WASI_IMPORTS = {
'environ_get',
Expand All @@ -782,13 +789,9 @@ def metadce(js_file, wasm_file, debug_info):
'path_open',
}
for item in graph:
if 'import' in item and item['import'][1][1:] in WASI_IMPORTS:
if 'import' in item and item['import'][1] in WASI_IMPORTS:
item['import'][0] = settings.WASI_MODULE_NAME
# fixup wasm backend prefixing
for item in graph:
if 'import' in item:
if item['import'][1][0] == '_':
item['import'][1] = item['import'][1][1:]

# map import names from wasm to JS, using the actual name the wasm uses for the import
import_name_map = {}
for item in graph:
Expand Down

0 comments on commit e57881a

Please sign in to comment.