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)
| 192 | return |
| 193 | |
| 194 | def ingest(self, co, classname=None, code_objects={}, show_asm=None): |
| 195 | """Create "tokens" the bytecode of an Python code object. Largely these |
| 196 | are the opcode name, but in some cases that has been modified to make parsing |
| 197 | easier. |
| 198 | returning a list of uncompyle6 Token's. |
| 199 | |
| 200 | Some transformations are made to assist the deparsing grammar: |
| 201 | - various types of LOAD_CONST's are categorized in terms of what they load |
| 202 | - COME_FROM instructions are added to assist parsing control structures |
| 203 | - operands with stack argument counts or flag masks are appended to the |
| 204 | opcode name, e.g.: |
| 205 | * BUILD_LIST, BUILD_SET |
| 206 | * MAKE_FUNCTION and FUNCTION_CALLS append the number of positional |
| 207 | arguments |
| 208 | - EXTENDED_ARGS instructions are removed |
| 209 | |
| 210 | Also, when we encounter certain tokens, we add them to a set |
| 211 | which will cause custom grammar rules. Specifically, variable |
| 212 | arg tokens like MAKE_FUNCTION or BUILD_LIST cause specific |
| 213 | rules for the specific number of arguments they take. |
| 214 | |
| 215 | """ |
| 216 | |
| 217 | def tokens_append(j, token): |
| 218 | tokens.append(token) |
| 219 | self.offset2tok_index[token.offset] = j |
| 220 | j += 1 |
| 221 | assert j == len(tokens) |
| 222 | return j |
| 223 | |
| 224 | if not show_asm: |
| 225 | show_asm = self.show_asm |
| 226 | |
| 227 | bytecode = self.build_instructions(co) |
| 228 | |
| 229 | if show_asm in ("both", "before"): |
| 230 | print("\n# ---- disassembly:") |
| 231 | bytecode.disassemble_bytes( |
| 232 | co.co_code, |
| 233 | varnames=co.co_varnames, |
| 234 | names=co.co_names, |
| 235 | constants=co.co_consts, |
| 236 | cells=bytecode._cell_names, |
| 237 | line_starts=bytecode._linestarts, |
| 238 | asm_format="extended", |
| 239 | filename=co.co_filename, |
| 240 | show_source=True, |
| 241 | first_line_number=co.co_firstlineno, |
| 242 | ) |
| 243 | |
| 244 | # "customize" is in the process of going away here |
| 245 | customize = {} |
| 246 | |
| 247 | if self.is_pypy: |
| 248 | customize["PyPy"] = 0 |
| 249 | |
| 250 | # Scan for assertions. Later we will |
| 251 | # turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'. |
no test coverage detected