| 439 | |
| 440 | |
| 441 | class Formatter: |
| 442 | |
| 443 | def __init__(self, file=None, lineno_width=0, offset_width=0, label_width=0, |
| 444 | line_offset=0, show_caches=False, *, show_positions=False): |
| 445 | """Create a Formatter |
| 446 | |
| 447 | *file* where to write the output |
| 448 | *lineno_width* sets the width of the source location field (0 omits it). |
| 449 | Should be large enough for a line number or full positions (depending |
| 450 | on the value of *show_positions*). |
| 451 | *offset_width* sets the width of the instruction offset field |
| 452 | *label_width* sets the width of the label field |
| 453 | *show_caches* is a boolean indicating whether to display cache lines |
| 454 | *show_positions* is a boolean indicating whether full positions should |
| 455 | be reported instead of only the line numbers. |
| 456 | """ |
| 457 | self.file = file |
| 458 | self.lineno_width = lineno_width |
| 459 | self.offset_width = offset_width |
| 460 | self.label_width = label_width |
| 461 | self.show_caches = show_caches |
| 462 | self.show_positions = show_positions |
| 463 | |
| 464 | def print_instruction(self, instr, mark_as_current=False): |
| 465 | self.print_instruction_line(instr, mark_as_current) |
| 466 | if self.show_caches and instr.cache_info: |
| 467 | offset = instr.offset |
| 468 | for name, size, data in instr.cache_info: |
| 469 | for i in range(size): |
| 470 | offset += 2 |
| 471 | # Only show the fancy argrepr for a CACHE instruction when it's |
| 472 | # the first entry for a particular cache value: |
| 473 | if i == 0: |
| 474 | argrepr = f"{name}: {int.from_bytes(data, sys.byteorder)}" |
| 475 | else: |
| 476 | argrepr = "" |
| 477 | self.print_instruction_line( |
| 478 | Instruction("CACHE", CACHE, 0, None, argrepr, offset, offset, |
| 479 | False, None, None, instr.positions), |
| 480 | False) |
| 481 | |
| 482 | def print_instruction_line(self, instr, mark_as_current): |
| 483 | """Format instruction details for inclusion in disassembly output.""" |
| 484 | lineno_width = self.lineno_width |
| 485 | offset_width = self.offset_width |
| 486 | label_width = self.label_width |
| 487 | |
| 488 | new_source_line = (lineno_width > 0 and |
| 489 | instr.starts_line and |
| 490 | instr.offset > 0) |
| 491 | if new_source_line: |
| 492 | print(file=self.file) |
| 493 | |
| 494 | fields = [] |
| 495 | # Column: Source code locations information |
| 496 | if lineno_width: |
| 497 | if self.show_positions: |
| 498 | # reporting positions instead of just line numbers |
no outgoing calls
no test coverage detected
searching dependent graphs…