MCPcopy Index your code
hub / github.com/RustPython/RustPython / Formatter

Class Formatter

Lib/dis.py:440–553  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 4

disFunction · 0.70
__str__Method · 0.70
disassembleFunction · 0.70
disMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected