Generate C code for the module code in 'co_bytes', write it to 'fp'.
(fp, co_bytes)
| 23 | |
| 24 | |
| 25 | def gen_c_code(fp, co_bytes): |
| 26 | """Generate C code for the module code in 'co_bytes', write it to 'fp'. |
| 27 | """ |
| 28 | def write(*args, **kwargs): |
| 29 | print(*args, **kwargs, file=fp) |
| 30 | write('/* Generated with Tools/freeze/regen_frozen.py */') |
| 31 | write('static unsigned char %s[] = {' % SYMBOL, end='') |
| 32 | bytes_per_row = 13 |
| 33 | for i, opcode in enumerate(co_bytes): |
| 34 | if (i % bytes_per_row) == 0: |
| 35 | # start a new row |
| 36 | write() |
| 37 | write(' ', end='') |
| 38 | write('%d,' % opcode, end='') |
| 39 | write() |
| 40 | write('};') |
| 41 | |
| 42 | |
| 43 | def main(): |