當前位置: 首頁>>代碼示例>>Python>>正文


Python DiGraph.successors方法代碼示例

本文整理匯總了Python中miasm2.core.graph.DiGraph.successors方法的典型用法代碼示例。如果您正苦於以下問題:Python DiGraph.successors方法的具體用法?Python DiGraph.successors怎麽用?Python DiGraph.successors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在miasm2.core.graph.DiGraph的用法示例。


在下文中一共展示了DiGraph.successors方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: ira_regs_ids

# 需要導入模塊: from miasm2.core.graph import DiGraph [as 別名]
# 或者: from miasm2.core.graph.DiGraph import successors [as 別名]

#.........這裏部分代碼省略.........
        @useful: useful statements from previous reach analysis
        Return True iff the block state has changed
        PRE: compute_reach(self)
        """
        modified = False
        for k, ir in enumerate(irb.irs):
            j = 0
            while j < len(ir):
                cur_instr = ir[j]
                if isinstance(cur_instr.dst, ExprId) and (irb.label, k, cur_instr) not in useful:
                    del ir[j]
                    modified = True
                else:
                    j += 1
        return modified

    def init_useful_instr(self):
        """Computes a set of triples (block, instruction number, instruction)
        containing initially useful instructions :
          - Instructions affecting final value of return registers
          - Instructions affecting IRDst register
          - Instructions writing in memory
          - Function call instructions
        Return set of intial useful instructions
        """

        useful = set()

        for node in self.g.nodes():
            if node not in self.blocs:
                continue

            block = self.blocs[node]
            successors = self.g.successors(node)
            has_son = bool(successors)
            for p_son in successors:
                if p_son not in self.blocs:
                    # Leaf has lost its son: don't remove anything
                    # reaching this block
                    for r in self.ira_regs_ids():
                        useful.update(block.cur_reach[-1][r].union(block.defout[-1][r]))

            # Function call, memory write or IRDst affectation
            for k, ir in enumerate(block.irs):
                for i_cur in ir:
                    if i_cur.src.is_function_call():
                        # /!\ never remove ir calls
                        useful.add((block.label, k, i_cur))
                    if isinstance(i_cur.dst, ExprMem):
                        useful.add((block.label, k, i_cur))
                    useful.update(block.defout[k][self.IRDst])

            # Affecting return registers
            if not has_son:
                for r in self.get_out_regs(block):
                    useful.update(block.defout[-1][r] if block.defout[-1][r] else block.cur_reach[-1][r])

        return useful

    def _mark_useful_code(self):
        """Mark useful statements using previous reach analysis

        Source : Kennedy, K. (1979). A survey of data flow analysis techniques.
        IBM Thomas J. Watson Research Division,  Algorithm MK

        Return a set of triplets (block, instruction number, instruction) of
開發者ID:CaineQT,項目名稱:miasm,代碼行數:70,代碼來源:analysis.py

示例2: sort_dst

# 需要導入模塊: from miasm2.core.graph import DiGraph [as 別名]
# 或者: from miasm2.core.graph.DiGraph import successors [as 別名]

#.........這裏部分代碼省略.........
                if not isinstance(i_cur.dst, ExprId):
                    pass
                elif (isinstance(i_cur.src, ExprOp) and
                    i_cur.src.op.startswith('call')):
                    # /!\ never remove ir calls
                    pass
                elif not i_cur.dst in c_out:
                    del(ir[j])
                    continue
                j += 1

    def remove_blocs_dead(self):
        for b in self.blocs.values():
            self.remove_dead(b)

    # for test XXX TODO
    def set_dead_regs(self, b):
        pass

    def add_unused_regs(self):
        pass

    def compute_in_out(self, b):
        # get out/in from bloc sons
        modified = False
        # set b in
        if b.c_in[-1] != set(b.r[-1].union(b.c_out[-1].difference(b.w[-1]))):
            modified = True
        b.c_in[-1] = set(b.r[-1].union(b.c_out[-1].difference(b.w[-1])))

        # set b out
        c_out = set()
        has_son = False
        for n_son in self.g.successors(b.label):
            # print n_me, n_son
            has_son = True
            if not n_son in self.blocs:
                print "leaf has lost her sons!"
                continue
            b_son = self.blocs[n_son]
            c_out.update(b_son.c_in[0])
        if not has_son:
            # special case: leaf nodes architecture dependant
            c_out = self.get_out_regs(b)
        if b.c_out[-1] != set(c_out):
            modified = True
        b.c_out[-1] = set(c_out)

        # get out/in for bloc
        for i in reversed(xrange(len(b.irs))):
            if b.c_in[i] != set(b.r[i].union(b.c_out[i].difference(b.w[i]))):
                modified = True
            b.c_in[i] = set(b.r[i].union(b.c_out[i].difference(b.w[i])))
            if b.c_out[i] != set(b.c_in[i + 1]):
                modified = True
            b.c_out[i] = set(b.c_in[i + 1])
        return modified

    def test_in_out_fix(self):
        fixed = True
        for n in self.g.nodes():
            if not n in self.blocs:
                # leaf has lost her son
                continue
            b = self.blocs[n]
            if b.c_in != b.l_in or b.c_out != b.l_out:
開發者ID:13572293130,項目名稱:miasm,代碼行數:70,代碼來源:analysis.py

示例3: sort_dst

# 需要導入模塊: from miasm2.core.graph import DiGraph [as 別名]
# 或者: from miasm2.core.graph.DiGraph import successors [as 別名]

#.........這裏部分代碼省略.........
        for b in self.blocs.values():
            modified |= self.remove_dead(b)
        return modified

    # for test XXX TODO
    def set_dead_regs(self, b):
        pass

    def add_unused_regs(self):
        pass

    def dump_bloc_state(self, irb):
        print '*'*80
        for i, (ir, c_in, c_out) in enumerate(zip(irb.irs, irb.c_in, irb.c_out)):
            print 'ir'
            for x in ir:
                print '\t', x
            print 'R', [str(x) for x in irb.r[i]]#c_in]
            print 'W', [str(x) for x in irb.w[i]]#c_out]
            print 'IN', [str(x) for x in c_in]
            print 'OUT', [str(x) for x in c_out]


    def compute_in_out(self, irb):
        """Liveness computation for a single bloc
        @irb: irbloc instance
        Return True iff bloc state has changed
        """
        modified = False

        # Compute OUT for last irb entry
        c_out = set()
        has_son = False
        for n_son in self.g.successors(irb.label):
            has_son = True
            if n_son not in self.blocs:
                # If the son is not defined, we will propagate our current out
                # nodes to the in nodes's son
                son_c_in = irb.c_out_missing
            else:
                son_c_in = self.blocs[n_son].c_in[0]
            c_out.update(son_c_in)
        if not has_son:
            # Special case: leaf nodes architecture dependant
            c_out = self.get_out_regs(irb)

        if irb.c_out[-1] != c_out:
            irb.c_out[-1] = c_out
            modified = True

        # Compute out/in intra bloc
        for i in reversed(xrange(len(irb.irs))):
            new_in = set(irb.r[i].union(irb.c_out[i].difference(irb.w[i])))
            if irb.c_in[i] != new_in:
                irb.c_in[i] = new_in
                modified = True

            if i >= len(irb.irs) - 1:
                # Last out has been previously updated
                continue
            new_out = set(irb.c_in[i + 1])
            if irb.c_out[i] != new_out:
                irb.c_out[i] = new_out
                modified = True

        return modified
開發者ID:avelik,項目名稱:miasm,代碼行數:70,代碼來源:analysis.py


注:本文中的miasm2.core.graph.DiGraph.successors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。