| 41 | |
| 42 | |
| 43 | def _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 | |
| 70 | def dump( |