-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mypyc] Add debug op (and builder helper) for printing str or Value (#…
…18552) It generates C code to print to stdout, but tries to preserve the error state and not affect the code it's added to. Added test for it, but also tested this by adding `builder.debug_print(typ)` in `add_non_ext_class_attr_ann` and it prints the class name. It's also useful to use it like `builder.debug_print("MARKER")` and then to search in the generated C code for MARKER. For more complex debugging tasks, this is useful in finding your way around the generated C code and quickly looking at the interesting part. I saw that there's already a misc op `CPyDebug_Print`. I haven't seen it used though. I think we can remove that one if this is proving useful.
- Loading branch information
Showing
6 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
from __future__ import annotations | ||
|
||
import unittest | ||
|
||
from mypyc.ir.ops import BasicBlock | ||
from mypyc.ir.pprint import format_blocks, generate_names_for_ir | ||
from mypyc.irbuild.ll_builder import LowLevelIRBuilder | ||
from mypyc.options import CompilerOptions | ||
|
||
|
||
class TestMisc(unittest.TestCase): | ||
def test_debug_op(self) -> None: | ||
block = BasicBlock() | ||
builder = LowLevelIRBuilder(errors=None, options=CompilerOptions()) | ||
builder.activate_block(block) | ||
builder.debug_print("foo") | ||
|
||
names = generate_names_for_ir([], [block]) | ||
code = format_blocks([block], names, {}) | ||
assert code[:-1] == ["L0:", " r0 = 'foo'", " CPyDebug_PrintObject(r0)"] |