(
self,
op: Op | list[Op],
expected: str,
next_block: BasicBlock | None = None,
*,
rare: bool = False,
next_branch: Branch | None = None,
skip_next: bool = False,
)
| 972 | self.assert_emit(Assign(s, CString(b)), f'cpy_r_s = "{target}";') |
| 973 | |
| 974 | def assert_emit( |
| 975 | self, |
| 976 | op: Op | list[Op], |
| 977 | expected: str, |
| 978 | next_block: BasicBlock | None = None, |
| 979 | *, |
| 980 | rare: bool = False, |
| 981 | next_branch: Branch | None = None, |
| 982 | skip_next: bool = False, |
| 983 | ) -> None: |
| 984 | block = BasicBlock(0) |
| 985 | if isinstance(op, Op): |
| 986 | block.ops.append(op) |
| 987 | else: |
| 988 | block.ops.extend(op) |
| 989 | op = op[-1] |
| 990 | value_names = generate_names_for_ir(self.registers, [block]) |
| 991 | emitter = Emitter(self.context, value_names) |
| 992 | declarations = Emitter(self.context, value_names) |
| 993 | emitter.fragments = [] |
| 994 | declarations.fragments = [] |
| 995 | |
| 996 | visitor = FunctionEmitterVisitor(emitter, declarations, "prog.py", "prog") |
| 997 | visitor.next_block = next_block |
| 998 | visitor.rare = rare |
| 999 | if next_branch: |
| 1000 | visitor.ops = [op, next_branch] |
| 1001 | else: |
| 1002 | visitor.ops = [op] |
| 1003 | visitor.op_index = 0 |
| 1004 | |
| 1005 | op.accept(visitor) |
| 1006 | frags = declarations.fragments + emitter.fragments |
| 1007 | actual_lines = [line.strip(" ") for line in frags] |
| 1008 | assert all(line.endswith("\n") for line in actual_lines) |
| 1009 | actual_lines = [line.rstrip("\n") for line in actual_lines] |
| 1010 | if not expected.strip(): |
| 1011 | expected_lines = [] |
| 1012 | else: |
| 1013 | expected_lines = expected.rstrip().split("\n") |
| 1014 | expected_lines = [line.strip(" ") for line in expected_lines] |
| 1015 | assert_string_arrays_equal( |
| 1016 | expected_lines, actual_lines, msg="Generated code unexpected", traceback=True |
| 1017 | ) |
| 1018 | if skip_next: |
| 1019 | assert visitor.op_index == 1 |
| 1020 | else: |
| 1021 | assert visitor.op_index == 0 |
| 1022 | |
| 1023 | def assert_emit_binary_op( |
| 1024 | self, op: str, dest: Value, left: Value, right: Value, expected: str |
no test coverage detected