tools/binary_size/libsupersize/linker_map_parser.py
def Tokenize(self, lines):
    """Generator to filter and tokenize linker map lines."""
    # Extract e.g., 'lld_v0' -> 0, or 'lld-lto_v1' -> 1.
    map_file_version = int(self._linker_name.split('_v')[1])
    pattern = MapFileParserLld._LINE_RE[map_file_version]

    # A Level 3 symbol can have |size == 0| in some situations (e.g., assembly
    # code symbols). To provided better size estimates in this case, the "span"
    # of a Level 3 symbol is computed as:
    #  (A) The |address| difference compared to the next Level 3 symbol.
    #  (B) If the Level 3 symbol is the last among Level 3 lines nested under a
    #      Level 2 line: The difference between the Level 3 symbol's |address|
    #      and the containing Level 2 line's end address.
    # To handle (A), |lines| is visited using a one-step lookahead, using
    # |sentinel| to handle the last line. To handle (B), |level2_end_address| is
    # computed for each Level 2 line.
    sentinel = '0 0 0 0 THE_END'
    assert pattern.match(sentinel)
    level2_end_address = None
    thumb2_mode = False
    (line, address, size, level, tok) = (None, None, None, None, None)
    for next_line in itertools.chain(lines, (sentinel,)):
      m = pattern.match(next_line)
      if m is None:
        continue
      next_address = int(m.group(1), 16)
      next_size = int(m.group(2), 16)
      next_level = (len(m.group(4)) // 8) + 1  # Add 1 to agree with comments.
      next_tok = m.group(5)

      if next_level == 3:
        assert level >= 2, 'Cannot jump from Level 1 to Level 3.'
        # Detect annotations. If found, maybe update |thumb2_mode|, then skip.
        (is_annotation, next_thumb2_mode) = (
            MapFileParserLld.ParseArmAnnotations(next_tok))
        if is_annotation:
          if next_thumb2_mode:
            thumb2_mode = next_thumb2_mode
          continue  # Skip annotations.
        if thumb2_mode:
          # Adjust odd address to even. Alignment is not guanteed for all
          # symbols (e.g., data, or x86), so this is judiciously applied.
          next_address &= ~1
      else:
        thumb2_mode = False  # Resets on leaving Level 3.

      if address is not None:
        span = None
        if level == 3:
          span = next_address if next_level == 3 else level2_end_address
          span -= address
        elif level == 2:
          level2_end_address = address + size
        yield (line, address, size, level, span, tok)

      line = next_line
      address = next_address
      size = next_size
      level = next_level
      tok = next_tok
Generator to filter and tokenize linker map lines.
Generator to filter and tokenize linker map lines.
Generator to filter and tokenize linker map lines .
def Tokenize(self, lines):
    map_file_version = int(self._linker_name.split('_v')[1])
    pattern = MapFileParserLld._LINE_RE[map_file_version]
    sentinel = '0 0 0 0 THE_END'
    assert pattern.match(sentinel)
    level2_end_address = None
    thumb2_mode = False
    (line, address, size, level, tok) = (None, None, None, None, None)
    for next_line in itertools.chain(lines, (sentinel,)):
      m = pattern.match(next_line)
      if m is None:
        continue
      next_address = int(m.group(1), 16)
      next_size = int(m.group(2), 16)
      next_level = (len(m.group(4)) // 8) + 1  
      next_tok = m.group(5)
      if next_level == 3:
        assert level >= 2, 'Cannot jump from Level 1 to Level 3.'
        (is_annotation, next_thumb2_mode) = (
            MapFileParserLld.ParseArmAnnotations(next_tok))
        if is_annotation:
          if next_thumb2_mode:
            thumb2_mode = next_thumb2_mode
          continue  
        if thumb2_mode:
          next_address &= ~1
      else:
        thumb2_mode = False  
      if address is not None:
        span = None
        if level == 3:
          span = next_address if next_level == 3 else level2_end_address
          span -= address
        elif level == 2:
          level2_end_address = address + size
        yield (line, address, size, level, span, tok)
      line = next_line
      address = next_address
      size = next_size
      level = next_level
      tok = next_tok
def Tokenize ( self , lines ) : map_file_version = int ( self . _linker_name . split ( '_v' ) [ 1 ] ) pattern = MapFileParserLld . _LINE_RE [ map_file_version ] sentinel = '0 0 0 0 THE_END' assert pattern . match ( sentinel ) level2_end_address = None thumb2_mode = False ( line , address , size , level , tok ) = ( None , None , None , None , None ) for next_line in itertools . chain ( lines , ( sentinel , ) ) : m = pattern . match ( next_line ) if m is None : continue next_address = int ( m . group ( 1 ) , 16 ) next_size = int ( m . group ( 2 ) , 16 ) next_level = ( len ( m . group ( 4 ) ) // 8 ) + 1 next_tok = m . group ( 5 ) if next_level == 3 : assert level >= 2 , 'Cannot jump from Level 1 to Level 3.' ( is_annotation , next_thumb2_mode ) = ( MapFileParserLld . ParseArmAnnotations ( next_tok ) ) if is_annotation : if next_thumb2_mode : thumb2_mode = next_thumb2_mode continue if thumb2_mode : next_address &= ~ 1 else : thumb2_mode = False if address is not None : span = None if level == 3 : span = next_address if next_level == 3 else level2_end_address span -= address elif level == 2 : level2_end_address = address + size yield ( line , address , size , level , span , tok ) line = next_line address = next_address size = next_size level = next_level tok = next_tok
Generator to filter and tokenize linker map lines.
Generator to filter and tokenize linker map lines .
"""Generator to filter and tokenize linker map lines.""" # Extract e.g., 'lld_v0' -> 0, or 'lld-lto_v1' -> 1. # A Level 3 symbol can have |size == 0| in some situations (e.g., assembly # code symbols). To provided better size estimates in this case, the "span" # of a Level 3 symbol is computed as: #  (A) The |address| difference compared to the next Level 3 symbol. #  (B) If the Level 3 symbol is the last among Level 3 lines nested under a #      Level 2 line: The difference between the Level 3 symbol's |address| #      and the containing Level 2 line's end address. # To handle (A), |lines| is visited using a one-step lookahead, using # |sentinel| to handle the last line. To handle (B), |level2_end_address| is # computed for each Level 2 line. # Add 1 to agree with comments. # Detect annotations. If found, maybe update |thumb2_mode|, then skip. # Skip annotations. # Adjust odd address to even. Alignment is not guanteed for all # symbols (e.g., data, or x86), so this is judiciously applied. # Resets on leaving Level 3.
self
lines