MCPcopy Create free account
hub / github.com/python/cpython / _dump_stencil

Function _dump_stencil

Tools/jit/_writer.py:43–67  ·  view source on GitHub ↗
(opname: str, group: _stencils.StencilGroup)

Source from the content-addressed store, hash-verified

41
42
43def _dump_stencil(opname: str, group: _stencils.StencilGroup) -> typing.Iterator[str]:
44 yield "void"
45 yield f"emit_{opname}("
46 yield " unsigned char *code, unsigned char *data, _PyExecutorObject *executor,"
47 yield " const _PyUOpInstruction *instruction, jit_state *state)"
48 yield "{"
49 for part, stencil in [("code", group.code), ("data", group.data)]:
50 for line in stencil.disassembly:
51 yield f" // {line}"
52 stripped = stencil.body.rstrip(b"\x00")
53 if stripped:
54 yield f" const unsigned char {part}_body[{len(stencil.body)}] = {{"
55 for i in range(0, len(stripped), 8):
56 row = " ".join(f"{byte:#04x}," for byte in stripped[i : i + 8])
57 yield f" {row}"
58 yield " };"
59 # Data is written first (so relaxations in the code work properly):
60 for part, stencil in [("data", group.data), ("code", group.code)]:
61 if stencil.body.rstrip(b"\x00"):
62 yield f" memcpy({part}, {part}_body, sizeof({part}_body));"
63 stencil.holes.sort(key=lambda hole: hole.offset)
64 for hole in stencil.holes:
65 yield f" {hole.as_c(part)}"
66 yield "}"
67 yield ""
68
69
70def dump(

Callers 1

dumpFunction · 0.85

Calls 4

rstripMethod · 0.45
joinMethod · 0.45
sortMethod · 0.45
as_cMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…