1# 2# Copyright (C) 2016 The Android Open Source Project 3# 4# Licensed under the Apache License, Version 2.0 (the "License"); 5# you may not use this file except in compliance with the License. 6# You may obtain a copy of the License at 7# 8# http://www.apache.org/licenses/LICENSE-2.0 9# 10# Unless required by applicable law or agreed to in writing, software 11# distributed under the License is distributed on an "AS IS" BASIS, 12# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13# See the License for the specific language governing permissions and 14# limitations under the License. 15# 16 17 18class BlockSummary(object): 19 """Summarizes a block of code from a .gcno file. 20 21 Contains all the lines in the block and the entry/exit 22 arcs from/to other basic blocks. 23 24 Attributes: 25 flag: integer flag value. 26 entry_arcs: list of ArcSummary objects for each arc 27 entering the code block. 28 exit_arcs: list of ArcSummary objects for each arc exiting 29 the code block. 30 lines: list of line numbers represented by the basic block. 31 """ 32 33 def __init__(self, index, flag): 34 """Inits the block summary with provided values. 35 36 Initializes entryArcs, exitArcs, and lines to the empty list. 37 Stores the block flag in the flag attribute. 38 39 Args: 40 index: the basic block number 41 flag: integer block flag. 42 """ 43 self.index = index 44 self.flag = flag 45 self.entry_arcs = [] 46 self.exit_arcs = [] 47 self.count = 0 48 self.lines = [] 49 50 def __str__(self): 51 """Serializes the block summary as a string. 52 53 Returns: 54 String representation of the block. 55 """ 56 output = '\tBlock: %i, Count: %i' % (self.index, self.count) 57 if len(self.lines): 58 output += ', Lines: ' + ', '.join(str(line) for line in self.lines) 59 if len(self.entry_arcs): 60 output += ('\r\n\t\t' + str(self.index) + ' <-- ' + ', '.join( 61 str(a.src_block.index) for a in self.entry_arcs)) 62 if len(self.exit_arcs): 63 output += ('\r\n\t\t' + str(self.index) + ' --> ' + ', '.join( 64 str(a.dst_block.index) for a in self.exit_arcs)) 65 return output + '\r\n' 66