MCPcopy Index your code
hub / github.com/python/cpython / _parse

Method _parse

Tools/jit/_targets.py:84–123  ·  view source on GitHub ↗
(self, path: pathlib.Path)

Source from the content-addressed store, hash-verified

82 return hasher.hexdigest()
83
84 async def _parse(self, path: pathlib.Path) -> _stencils.StencilGroup:
85 group = _stencils.StencilGroup()
86 args = ["--disassemble", "--reloc", f"{path}"]
87 output = await _llvm.maybe_run(
88 "llvm-objdump", args, echo=self.verbose, llvm_version=self.llvm_version
89 )
90 if output is not None:
91 # Make sure that full paths don't leak out (for reproducibility):
92 long, short = str(path), str(path.name)
93 group.code.disassembly.extend(
94 line.expandtabs().strip().replace(long, short)
95 for line in output.splitlines()
96 )
97 args = [
98 "--elf-output-style=JSON",
99 "--expand-relocs",
100 # "--pretty-print",
101 "--section-data",
102 "--section-relocations",
103 "--section-symbols",
104 "--sections",
105 f"{path}",
106 ]
107 output = await _llvm.run(
108 "llvm-readobj", args, echo=self.verbose, llvm_version=self.llvm_version
109 )
110 # --elf-output-style=JSON is only *slightly* broken on Mach-O...
111 output = output.replace("PrivateExtern\n", "\n")
112 output = output.replace("Extern\n", "\n")
113 # ...and also COFF:
114 output = output[output.index("[", 1, None) :]
115 output = output[: output.rindex("]", None, -1) + 1]
116 sections: list[dict[typing.Literal["Section"], _S]] = json.loads(output)
117 for wrapped_section in sections:
118 self._handle_section(wrapped_section["Section"], group)
119 assert group.symbols["_JIT_ENTRY"] == (_stencils.HoleValue.CODE, 0)
120 if group.data.body:
121 line = f"0: {str(bytes(group.data.body)).removeprefix('b')}"
122 group.data.disassembly.append(line)
123 return group
124
125 def _handle_section(self, section: _S, group: _stencils.StencilGroup) -> None:
126 raise NotImplementedError(type(self))

Callers 1

_compileMethod · 0.95

Calls 13

_handle_sectionMethod · 0.95
strFunction · 0.85
extendMethod · 0.45
replaceMethod · 0.45
stripMethod · 0.45
expandtabsMethod · 0.45
splitlinesMethod · 0.45
runMethod · 0.45
indexMethod · 0.45
rindexMethod · 0.45
loadsMethod · 0.45
removeprefixMethod · 0.45

Tested by

no test coverage detected