Beispiel #1
0
    def split_if_nodes(self):
        '''
        Split IfNodes in two nodes, the first node is the header node, the
        second one is only composed of the jump condition.
        '''
        node_map = {}
        to_update = set()
        for node in self.nodes[:]:
            if node.type.is_cond:
                if len(node.get_ins()) > 1:
                    pre_ins = node.get_ins()[:-1]
                    last_ins = node.get_ins()[-1]
                    pre_node = StatementBlock('%s-pre' % node.name, pre_ins)
                    cond_node = CondBlock('%s-cond' % node.name, [last_ins])
                    node_map[node] = pre_node

                    pre_node.copy_from(node)
                    cond_node.copy_from(node)
                    for var in node.var_to_declare:
                        pre_node.add_variable_declaration(var)
                    pre_node.type.is_stmt = True
                    cond_node.true = node.true
                    cond_node.false = node.false

                    for pred in self.all_preds(node):
                        pred_node = node_map.get(pred, pred)
                        # Verify that the link is not an exception link
                        if node not in self.sucs(pred):
                            self.add_catch_edge(pred_node, pre_node)
                            continue
                        if pred is node:
                            pred_node = cond_node
                        if pred.type.is_cond:  # and not (pred is node):
                            if pred.true is node:
                                pred_node.true = pre_node
                            if pred.false is node:
                                pred_node.false = pre_node
                        self.add_edge(pred_node, pre_node)
                    for suc in self.sucs(node):
                        self.add_edge(cond_node, node_map.get(suc, suc))

                    # We link all the exceptions to the pre node instead of the
                    # condition node, which should not trigger any of them.
                    for suc in self.catch_edges.get(node, []):
                        self.add_catch_edge(pre_node, node_map.get(suc, suc))

                    if node is self.entry:
                        self.entry = pre_node

                    self.add_node(pre_node)
                    self.add_node(cond_node)
                    self.add_edge(pre_node, cond_node)
                    pre_node.update_attribute_with(node_map)
                    cond_node.update_attribute_with(node_map)
                    self.remove_node(node)
            else:
                to_update.add(node)
        for node in to_update:
            node.update_attribute_with(node_map)
Beispiel #2
0
    def split_if_nodes(self):
        """
        Split IfNodes in two nodes, the first node is the header node, the
        second one is only composed of the jump condition.
        """
        node_map = {}
        to_update = set()
        for node in self.nodes[:]:
            if node.type.is_cond:
                if len(node.get_ins()) > 1:
                    pre_ins = node.get_ins()[:-1]
                    last_ins = node.get_ins()[-1]
                    pre_node = StatementBlock("%s-pre" % node.name, pre_ins)
                    cond_node = CondBlock("%s-cond" % node.name, [last_ins])
                    node_map[node] = pre_node

                    pre_node.copy_from(node)
                    cond_node.copy_from(node)
                    for var in node.var_to_declare:
                        pre_node.add_variable_declaration(var)
                    pre_node.type.is_stmt = True
                    cond_node.true = node.true
                    cond_node.false = node.false

                    for pred in self.all_preds(node):
                        pred_node = node_map.get(pred, pred)
                        # Verify that the link is not an exception link
                        if node not in self.sucs(pred):
                            self.add_catch_edge(pred_node, pre_node)
                            continue
                        if pred is node:
                            pred_node = cond_node
                        if pred.type.is_cond:  # and not (pred is node):
                            if pred.true is node:
                                pred_node.true = pre_node
                            if pred.false is node:
                                pred_node.false = pre_node
                        self.add_edge(pred_node, pre_node)
                    for suc in self.sucs(node):
                        self.add_edge(cond_node, node_map.get(suc, suc))

                    # We link all the exceptions to the pre node instead of the
                    # condition node, which should not trigger any of them.
                    for suc in self.catch_edges.get(node, []):
                        self.add_catch_edge(pre_node, node_map.get(suc, suc))

                    if node is self.entry:
                        self.entry = pre_node

                    self.add_node(pre_node)
                    self.add_node(cond_node)
                    self.add_edge(pre_node, cond_node)
                    pre_node.update_attribute_with(node_map)
                    cond_node.update_attribute_with(node_map)
                    self.remove_node(node)
            else:
                to_update.add(node)
        for node in to_update:
            node.update_attribute_with(node_map)
Beispiel #3
0
    def split_if_nodes(self):
        '''
        Split IfNodes in two nodes, the first node is the header node, the
        second one is only composed of the jump condition.
        '''
        node_map = {}
        to_update = set()
        for node in self.nodes[:]:
            if node.type.is_cond:
                if len(node.get_ins()) > 1:
                    pre_ins = node.get_ins()[:-1]
                    last_ins = node.get_ins()[-1]
                    pre_node = StatementBlock('%s-pre' % node.name, pre_ins)
                    cond_node = CondBlock('%s-cond' % node.name, [last_ins])
                    node_map[node] = pre_node

                    pre_node.copy_from(node)
                    cond_node.copy_from(node)
                    pre_node.type.is_stmt = True
                    cond_node.true = node.true
                    cond_node.false = node.false

                    lpreds = self.preds(node)
                    lsuccs = self.sucs(node)

                    for pred in lpreds:
                        pred_node = node_map.get(pred, pred)
                        if pred is node:
                            pred_node = cond_node
                        if pred.type.is_cond:  # and not (pred is node):
                            if pred.true is node:
                                pred_node.true = pre_node
                            if pred.false is node:
                                pred_node.false = pre_node
                        self.add_edge(pred_node, pre_node)
                    for suc in lsuccs:
                        self.add_edge(cond_node, node_map.get(suc, suc))

                    if node is self.entry:
                        self.entry = pre_node

                    self.add_node(pre_node)
                    self.add_node(cond_node)
                    self.add_edge(pre_node, cond_node)
                    pre_node.update_attribute_with(node_map)
                    cond_node.update_attribute_with(node_map)
                    self.remove_node(node)
            else:
                to_update.add(node)
        for node in to_update:
            node.update_attribute_with(node_map)
Beispiel #4
0
    def split_if_nodes(self):
        '''
        Split IfNodes in two nodes, the first node is the header node, the
        second one is only composed of the jump condition.
        '''
        node_map = {}
        to_update = set()
        for node in self.nodes[:]:
            if node.type.is_cond:
                if len(node.get_ins()) > 1:
                    pre_ins = node.get_ins()[:-1]
                    last_ins = node.get_ins()[-1]
                    pre_node = StatementBlock('%s-pre' % node.name, pre_ins)
                    cond_node = CondBlock('%s-cond' % node.name, [last_ins])
                    node_map[node] = pre_node

                    pre_node.copy_from(node)
                    cond_node.copy_from(node)
                    pre_node.type.is_stmt = True
                    cond_node.true = node.true
                    cond_node.false = node.false

                    lpreds = self.preds(node)
                    lsuccs = self.sucs(node)

                    for pred in lpreds:
                        pred_node = node_map.get(pred, pred)
                        if pred is node:
                            pred_node = cond_node
                        if pred.type.is_cond:  # and not (pred is node):
                            if pred.true is node:
                                pred_node.true = pre_node
                            if pred.false is node:
                                pred_node.false = pre_node
                        self.add_edge(pred_node, pre_node)
                    for suc in lsuccs:
                        self.add_edge(cond_node, node_map.get(suc, suc))

                    if node is self.entry:
                        self.entry = pre_node

                    self.add_node(pre_node)
                    self.add_node(cond_node)
                    self.add_edge(pre_node, cond_node)
                    pre_node.update_attribute_with(node_map)
                    cond_node.update_attribute_with(node_map)
                    self.remove_node(node)
            else:
                to_update.add(node)
        for node in to_update:
            node.update_attribute_with(node_map)
Beispiel #5
0
def split_if_nodes(graph):
    '''
    Split IfNodes in two nodes, the first node is the header node, the
    second one is only composed of the jump condition.
    '''
    node_map = {n: n for n in graph}
    to_update = set()
    for node in graph.nodes[:]:
        if node.type.is_cond:
            if len(node.get_ins()) > 1:
                pre_ins = node.get_ins()[:-1]
                last_ins = node.get_ins()[-1]
                pre_node = StatementBlock('%s-pre' % node.name, pre_ins)
                cond_node = CondBlock('%s-cond' % node.name, [last_ins])
                node_map[node] = pre_node
                node_map[pre_node] = pre_node
                node_map[cond_node] = cond_node

                pre_node.copy_from(node)
                cond_node.copy_from(node)
                for var in node.var_to_declare:
                    pre_node.add_variable_declaration(var)
                pre_node.type.is_stmt = True
                cond_node.true = node.true
                cond_node.false = node.false

                for pred in graph.all_preds(node):
                    pred_node = node_map[pred]
                    # Verify that the link is not an exception link
                    if node not in graph.sucs(pred):
                        graph.add_catch_edge(pred_node, pre_node)
                        continue
                    if pred is node:
                        pred_node = cond_node
                    if pred.type.is_cond:  # and not (pred is node):
                        if pred.true is node:
                            pred_node.true = pre_node
                        if pred.false is node:
                            pred_node.false = pre_node
                    graph.add_edge(pred_node, pre_node)
                for suc in graph.sucs(node):
                    graph.add_edge(cond_node, node_map[suc])

                # We link all the exceptions to the pre node instead of the
                # condition node, which should not trigger any of them.
                for suc in graph.catch_edges.get(node, collections.deque()):
                    graph.add_catch_edge(pre_node, node_map[suc])

                if node is graph.entry:
                    graph.entry = pre_node

                graph.add_node(pre_node)
                graph.add_node(cond_node)
                graph.add_edge(pre_node, cond_node)
                pre_node.update_attribute_with(node_map)
                cond_node.update_attribute_with(node_map)
                graph.remove_node(node)
        else:
            to_update.add(node)
    for node in to_update:
        node.update_attribute_with(node_map)