Create "tokens" the bytecode of an Python code object. Largely these are the opcode name, but in some cases that has been modified to make parsing easier. returning a list of uncompyle6 Token's. Some transformations are made to assist the deparsing grammar:
(
self, co, classname=None, code_objects={}, show_asm=None
)
| 391 | return new_tokens |
| 392 | |
| 393 | def ingest( |
| 394 | self, co, classname=None, code_objects={}, show_asm=None |
| 395 | ) -> Tuple[list, dict]: |
| 396 | """ |
| 397 | Create "tokens" the bytecode of an Python code object. Largely these |
| 398 | are the opcode name, but in some cases that has been modified to make parsing |
| 399 | easier. |
| 400 | returning a list of uncompyle6 Token's. |
| 401 | |
| 402 | Some transformations are made to assist the deparsing grammar: |
| 403 | - various types of LOAD_CONST's are categorized in terms of what they load |
| 404 | - COME_FROM instructions are added to assist parsing control structures |
| 405 | - operands with stack argument counts or flag masks are appended to the |
| 406 | opcode name, e.g.: |
| 407 | * BUILD_LIST, BUILD_SET |
| 408 | * MAKE_FUNCTION and FUNCTION_CALLS append the number of positional |
| 409 | arguments |
| 410 | - EXTENDED_ARGS instructions are removed |
| 411 | |
| 412 | Also, when we encounter certain tokens, we add them to a set |
| 413 | which will cause custom grammar rules. Specifically, variable |
| 414 | arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific rules |
| 415 | for the specific number of arguments they take. |
| 416 | """ |
| 417 | |
| 418 | if not show_asm: |
| 419 | show_asm = self.show_asm |
| 420 | |
| 421 | bytecode = self.build_instructions(co) |
| 422 | |
| 423 | # show_asm = 'both' |
| 424 | if show_asm in ("both", "before"): |
| 425 | print("\n# ---- disassembly:") |
| 426 | bytecode.disassemble_bytes( |
| 427 | co.co_code, |
| 428 | varnames=co.co_varnames, |
| 429 | names=co.co_names, |
| 430 | constants=co.co_consts, |
| 431 | cells=bytecode._cell_names, |
| 432 | line_starts=bytecode._linestarts, |
| 433 | asm_format="extended", |
| 434 | ) |
| 435 | |
| 436 | # "customize" is in the process of going away here |
| 437 | customize = {} |
| 438 | |
| 439 | if self.is_pypy: |
| 440 | customize["PyPy"] = 0 |
| 441 | |
| 442 | # Scan for assertions. Later we will |
| 443 | # turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'. |
| 444 | # 'LOAD_ASSERT' is used in assert statements. |
| 445 | self.load_asserts = set() |
| 446 | |
| 447 | n = len(self.insts) |
| 448 | for i, inst in enumerate(self.insts): |
| 449 | opname = inst.opname |
| 450 | # We need to detect the difference between: |
no test coverage detected