(
op: parser.InstDef | parser.Pseudo, replace_op_arg_1: str | None = None
)
| 375 | |
| 376 | |
| 377 | def analyze_stack( |
| 378 | op: parser.InstDef | parser.Pseudo, replace_op_arg_1: str | None = None |
| 379 | ) -> StackEffect: |
| 380 | inputs: list[StackItem] = [ |
| 381 | convert_stack_item(i, replace_op_arg_1) |
| 382 | for i in op.inputs |
| 383 | if isinstance(i, parser.StackEffect) |
| 384 | ] |
| 385 | outputs: list[StackItem] = [ |
| 386 | convert_stack_item(i, replace_op_arg_1) for i in op.outputs |
| 387 | ] |
| 388 | # Mark variables with matching names at the base of the stack as "peek" |
| 389 | modified = False |
| 390 | input_names: dict[str, lexer.Token] = { i.name : i.first_token for i in op.inputs if i.name != "unused" } |
| 391 | for input, output in itertools.zip_longest(inputs, outputs): |
| 392 | if output is None: |
| 393 | pass |
| 394 | elif input is None: |
| 395 | if output.name in input_names: |
| 396 | raise analysis_error( |
| 397 | f"Reuse of variable '{output.name}' at different stack location", |
| 398 | input_names[output.name]) |
| 399 | elif input.name == output.name: |
| 400 | if not modified: |
| 401 | input.peek = output.peek = True |
| 402 | else: |
| 403 | modified = True |
| 404 | if output.name in input_names: |
| 405 | raise analysis_error( |
| 406 | f"Reuse of variable '{output.name}' at different stack location", |
| 407 | input_names[output.name]) |
| 408 | if isinstance(op, parser.InstDef): |
| 409 | output_names = [out.name for out in outputs] |
| 410 | for input in inputs: |
| 411 | if ( |
| 412 | variable_used(op, input.name) |
| 413 | or variable_used(op, "DECREF_INPUTS") |
| 414 | or (not input.peek and input.name in output_names) |
| 415 | ): |
| 416 | input.used = True |
| 417 | for output in outputs: |
| 418 | if variable_used(op, output.name): |
| 419 | output.used = True |
| 420 | check_unused(inputs, input_names) |
| 421 | return StackEffect(inputs, outputs) |
| 422 | |
| 423 | |
| 424 | def analyze_caches(inputs: list[parser.InputEffect]) -> list[CacheEntry]: |
no test coverage detected
searching dependent graphs…