| 7 | |
| 8 | |
| 9 | def _dump_footer( |
| 10 | groups: dict[str, _stencils.StencilGroup], symbols: dict[str, int] |
| 11 | ) -> typing.Iterator[str]: |
| 12 | symbol_mask_size = max(math.ceil(len(symbols) / 32), 1) |
| 13 | yield f'static_assert(SYMBOL_MASK_WORDS >= {symbol_mask_size}, "SYMBOL_MASK_WORDS too small");' |
| 14 | yield "" |
| 15 | yield "typedef struct {" |
| 16 | yield " void (*emit)(" |
| 17 | yield " unsigned char *code, unsigned char *data, _PyExecutorObject *executor," |
| 18 | yield " const _PyUOpInstruction *instruction, jit_state *state);" |
| 19 | yield " size_t code_size;" |
| 20 | yield " size_t data_size;" |
| 21 | yield " symbol_mask trampoline_mask;" |
| 22 | yield " symbol_mask got_mask;" |
| 23 | yield "} StencilGroup;" |
| 24 | yield "" |
| 25 | yield f"static const StencilGroup shim = {groups['shim'].as_c('shim')};" |
| 26 | yield "" |
| 27 | yield "static const StencilGroup stencil_groups[MAX_UOP_REGS_ID + 1] = {" |
| 28 | for opname, group in sorted(groups.items()): |
| 29 | if opname == "shim": |
| 30 | continue |
| 31 | yield f" [{opname}] = {group.as_c(opname)}," |
| 32 | yield "};" |
| 33 | yield "" |
| 34 | yield f"static const void * const symbols_map[{max(len(symbols), 1)}] = {{" |
| 35 | if symbols: |
| 36 | for symbol, ordinal in symbols.items(): |
| 37 | yield f" [{ordinal}] = &{symbol}," |
| 38 | else: |
| 39 | yield " 0" |
| 40 | yield "};" |
| 41 | |
| 42 | |
| 43 | def _dump_stencil(opname: str, group: _stencils.StencilGroup) -> typing.Iterator[str]: |