Exemplo n.º 1
0
    def pruneBasicBlock(self, basicBlock):
        newNode = BasicBlock()
        newNode.blockType = basicBlock.blockType

        dontExpand = False
        dontExpandLevel = -1
        lastRowType = None

        for row in basicBlock.rows:
            rowType = row[0]
            rowLevel = row[3]
            if dontExpand:
                if rowLevel > dontExpandLevel:
                    continue
                else:
                    dontExpand = False

            if not self.pruneRow(row):
                rowAsString = self.row2StringConverter.convert(row)

                if len(
                        newNode.rows
                ) > 0 and lastRowType in self.mergeRows and rowType in self.mergeRows:
                    newNode.rows[-1] += (rowAsString)
                else:
                    newNode.rows.append(rowAsString)

            lastRowType = rowType

            if rowType in self.dontExpandNodes:
                dontExpand = True
                dontExpandLevel = rowLevel
        return newNode
Exemplo n.º 2
0
 def pruneBasicBlock(self, basicBlock):
     newNode = BasicBlock()
     newNode.blockType = basicBlock.blockType
     
     dontExpand = False
     dontExpandLevel = -1
     lastRowType = None
     
     for row in basicBlock.rows:
         rowType = row[0]
         rowLevel = row[3]
         if dontExpand:
             if rowLevel > dontExpandLevel:
                 continue
             else:
                 dontExpand = False
         
         
         if not self.pruneRow(row):
             rowAsString = self.row2StringConverter.convert(row)   
             
             if len(newNode.rows) > 0 and lastRowType in self.mergeRows and rowType in self.mergeRows:
                     newNode.rows[-1] += (rowAsString)
             else:
                 newNode.rows.append(rowAsString)
         
         lastRowType = rowType
         
         if rowType in self.dontExpandNodes:
             dontExpand = True
             dontExpandLevel = rowLevel    
     return newNode
Exemplo n.º 3
0
 def _initCFG(self, row):
     self.currentCFG = CFG()
     self.currentCFG.addNode(BasicBlock(row))
     self.currentLevel = int(getCSVRowLevel(row)) + 1
     self.functionLevel = self.currentLevel - 1
     self.functionName = row[5]
     self.functionPos = row[1]
     self.resetStacks()    
Exemplo n.º 4
0
 def handleElseNode(self, currentNodeId, row):
     (predNodeId, unused1, predNodeLevel) = self.scopeStack[-1]
     
     conditionStr = self.getCondition(predNodeId)
     conditionStr += ' == False'
     
     self.currentCFG.addEdge(predNodeId, currentNodeId + 1, conditionStr)
     self.currentCFG.addNode(BasicBlock(row))
     self.ifBodyStack.append((currentNodeId, predNodeLevel))
     self.enterScope(row)
Exemplo n.º 5
0
 def leaveLoopOrSwitch(self, predicateNodeType, predicateNodeId):
     if predicateNodeType == doNode:
         exitNodeId = self.leaveDoScope(predicateNodeId)
     elif predicateNodeType == switchNode:
         exitNodeId = self.currentCFG.getCurrentNodeId()
     else:
         self.currentCFG.addNode(BasicBlock(None))
         exitNodeId = self.currentCFG.getCurrentNodeId()
         conditionStr = self.getCondition(predicateNodeId) + ' == False'
         self.currentCFG.addEdge(predicateNodeId, exitNodeId, conditionStr)
         self.currentCFG.addEdge(exitNodeId - 1, predicateNodeId)
         
     self.attachBreakAndContinueNodes(exitNodeId, predicateNodeId)
Exemplo n.º 6
0
 def handleLabelNode(self, row, level):
     currentNodeId = self.currentCFG.getCurrentNodeId()
     currentNode = self.currentCFG.getNodeById(currentNodeId)
     
     if currentNode.rows != []:
         self.currentCFG.addNode(BasicBlock(row))
         
         currentNodeId = self.currentCFG.getCurrentNodeId()
         
         previousNode = self.currentCFG.getNodeById(currentNodeId -1)
         lastInstrType = previousNode.getLastInstrType()
         if not lastInstrType in controlStatementNodes:
             self.currentCFG.addEdge(currentNodeId -1, currentNodeId)
     else:
         self.currentCFG.appendToLatestNode(row)
     
     self.currentCFG.labeledNodes.append((currentNodeId,row))
Exemplo n.º 7
0
 def createAndConnectNode(self, row = None, conditionStr=None):
     newBasicBlock = BasicBlock(row)
     if row: newBasicBlock.blockType = row[0]
     newNodeId = self.currentCFG.addNode(newBasicBlock)
     self.currentCFG.addEdge(newNodeId - 1, newNodeId, conditionStr)