def place_declarations(graph, dvars, du, ud): idom = graph.immediate_dominators() for node in graph.post_order(): for loc, ins in node.get_loc_with_ins(): for var in ins.get_used_vars(): if (not isinstance(dvars[var], Variable) or isinstance(dvars[var], Param)): continue var_defs_locs = ud[var, loc] def_nodes = set() for def_loc in var_defs_locs: def_node = graph.get_node_from_loc(def_loc) # TODO: place declarations in catch if needed if def_node.in_catch: continue def_nodes.add(def_node) if not def_nodes: continue common_dominator = def_nodes.pop() for def_node in def_nodes: common_dominator = common_dom( idom, common_dominator, def_node) if any(var in range(*common_dominator.ins_range) for var in ud[var, loc]): continue common_dominator.add_variable_declaration(dvars[var])
def switch_struct(graph, idoms): unresolved = set() for node in graph.post_order(): if node.type.is_switch: m = node for suc in graph.sucs(node): if idoms[suc] is not node: m = common_dom(idoms, node, suc) ldominates = [] for n, dom in idoms.iteritems(): if m is dom and len(graph.all_preds(n)) > 1: ldominates.append(n) if len(ldominates) > 0: n = max(ldominates, key=lambda x: x.num) node.follow['switch'] = n for x in unresolved: x.follow['switch'] = n unresolved = set() else: unresolved.add(node) node.order_cases()