MCPcopy Create free account
hub / github.com/vercel/vercel / extract_core_module

Function extract_core_module

packages/python-analysis/scripts/profile-wasm.py:185–211  ·  view source on GitHub ↗

Extract the first core module from a component-model WASM.

(component_path, output_path)

Source from the content-addressed store, hash-verified

183
184
185def extract_core_module(component_path, output_path):
186 """Extract the first core module from a component-model WASM."""
187 dump = run(["wasm-tools", "objdump", str(component_path)])
188
189 for line in dump.splitlines():
190 m = re.match(
191 r"\s*module\b.*?\|\s*(0x[0-9a-fA-F]+)\s*-\s*(0x[0-9a-fA-F]+)\s*\|\s*(\d+)\s*bytes",
192 line,
193 )
194 if m:
195 offset = int(m.group(1), 16)
196 end = int(m.group(2), 16)
197 size = int(m.group(3))
198 break
199 else:
200 data = component_path.read_bytes()
201 pos = data.find(MODULE_MAGIC, len(COMPONENT_MAGIC))
202 if pos < 0:
203 print(f"{RED}Error: could not find core module in component{RESET}", file=sys.stderr)
204 sys.exit(1)
205 print(f"{YELLOW}Warning: using fallback module extraction (size may be approximate){RESET}")
206 output_path.write_bytes(data[pos:])
207 return output_path
208
209 data = component_path.read_bytes()
210 output_path.write_bytes(data[offset:end])
211 return output_path
212
213
214# ---------------------------------------------------------------------------

Callers 1

mainFunction · 0.85

Calls 6

splitlinesMethod · 0.80
groupMethod · 0.80
runFunction · 0.70
matchMethod · 0.45
findMethod · 0.45
exitMethod · 0.45

Tested by

no test coverage detected