@@ -412,15 +412,14 @@ def _create(cls, op, arg, offset, start_offset, starts_line, line_number,
412
412
co_consts = None , varname_from_oparg = None , names = None ,
413
413
labels_map = None , exceptions_map = None ):
414
414
415
- label_width = 4 + len (str (len (labels_map )))
416
415
argval , argrepr = cls ._get_argval_argrepr (
417
416
op , arg , offset ,
418
417
co_consts , names , varname_from_oparg , labels_map )
419
418
label = labels_map .get (offset , None )
420
419
instr = Instruction (_all_opname [op ], op , arg , argval , argrepr ,
421
420
offset , start_offset , starts_line , line_number ,
422
421
label , positions )
423
- instr .label_width = label_width
422
+ instr .label_width = 4 + len ( str ( len ( labels_map )))
424
423
instr .exc_handler = exceptions_map .get (offset , None )
425
424
return instr
426
425
@@ -468,12 +467,14 @@ def is_jump_target(self):
468
467
"""True if other code jumps to here, otherwise False"""
469
468
return self .label is not None
470
469
471
- def _disassemble (self , lineno_width = 3 , mark_as_current = False , offset_width = 0 ):
470
+ def _disassemble (self , lineno_width = 3 , mark_as_current = False , offset_width = 0 ,
471
+ label_width = 0 ):
472
472
"""Format instruction details for inclusion in disassembly output.
473
473
474
474
*lineno_width* sets the width of the line number field (0 omits it)
475
475
*mark_as_current* inserts a '-->' marker arrow as part of the line
476
476
*offset_width* sets the width of the instruction offset field
477
+ *label_width* sets the width of the label field
477
478
"""
478
479
fields = []
479
480
# Column: Source code line number
@@ -488,9 +489,9 @@ def _disassemble(self, lineno_width=3, mark_as_current=False, offset_width=0):
488
489
# Column: Label
489
490
if self .label is not None :
490
491
lbl = f"L{ self .label } :"
491
- fields .append (f"{ lbl :>{self . label_width }} " )
492
+ fields .append (f"{ lbl :>{label_width }} " )
492
493
else :
493
- fields .append (' ' * self . label_width )
494
+ fields .append (' ' * label_width )
494
495
# Column: Instruction offset from start of code sequence
495
496
if offset_width > 0 :
496
497
fields .append (f"{ repr (self .offset ):>{offset_width }} " )
@@ -648,6 +649,7 @@ def make_labels_map(original_code, exception_entries):
648
649
return labels_map
649
650
650
651
labels_map = make_labels_map (original_code , exception_entries )
652
+ label_width = 4 + len (str (len (labels_map )))
651
653
652
654
exceptions_map = {}
653
655
for start , end , target , _ , _ in exception_entries :
@@ -756,6 +758,7 @@ def _disassemble_bytes(code, lasti=-1, varname_from_oparg=None,
756
758
else :
757
759
offset_width = 0
758
760
761
+ label_width = - 1
759
762
for instr in _get_instructions_bytes (code , varname_from_oparg , names ,
760
763
co_consts , linestarts ,
761
764
line_offset = line_offset ,
@@ -774,7 +777,9 @@ def _disassemble_bytes(code, lasti=-1, varname_from_oparg=None,
774
777
# Each CACHE takes 2 bytes
775
778
is_current_instr = instr .offset <= lasti \
776
779
<= instr .offset + 2 * _get_cache_size (_all_opname [_deoptop (instr .opcode )])
777
- print (instr ._disassemble (lineno_width , is_current_instr , offset_width ),
780
+ label_width = getattr (instr , 'label_width' , label_width )
781
+ assert label_width >= 0
782
+ print (instr ._disassemble (lineno_width , is_current_instr , offset_width , label_width ),
778
783
file = file )
779
784
if exception_entries :
780
785
print ("ExceptionTable:" , file = file )
0 commit comments