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

Function read_name_section

tools/building.py:1102–1125  ·  view source on GitHub ↗
(wasm_file)

Source from the content-addressed store, hash-verified

1100
1101
1102def read_name_section(wasm_file):
1103 with webassembly.Module(wasm_file) as module:
1104 for section in module.sections():
1105 if section.type == webassembly.SecType.CUSTOM:
1106 module.seek(section.offset)
1107 if module.read_string() == 'name':
1108 name_map = {}
1109 # The name section is made up of sub-sections.
1110 # We are looking for the function names sub-section
1111 while module.tell() < section.offset + section.size:
1112 name_type = module.read_uleb()
1113 subsection_size = module.read_uleb()
1114 subsection_end = module.tell() + subsection_size
1115 if name_type == webassembly.NameType.FUNCTION:
1116 # We found the function names sub-section
1117 num_names = module.read_uleb()
1118 for _ in range(num_names):
1119 id = module.read_uleb()
1120 name = module.read_string()
1121 name_map[id] = name
1122 return name_map
1123 module.seek(subsection_end)
1124
1125 return name_map
1126
1127
1128@ToolchainProfiler.profile()

Callers 1

write_symbol_mapFunction · 0.85

Calls 6

sectionsMethod · 0.80
read_stringMethod · 0.80
read_ulebMethod · 0.80
rangeFunction · 0.50
seekMethod · 0.45
tellMethod · 0.45

Tested by

no test coverage detected