':param function:    A normalized Function object.
:returns:           A dictionary of basic block addresses and their distance to the exit of the function.'

@staticmethod
def _distances_from_function_exit(function):

    reverse_graph = function.graph.reverse()
    reverse_graph.add_node('start')
    found_exits = False
    for n in function.graph.nodes():
        if (len(function.graph.successors(n)) == 0):
            reverse_graph.add_edge('start', n)
            found_exits = True
    if (not found_exits):
        last = max(function.graph.nodes(), key=(lambda x: x.addr))
        reverse_graph.add_edge('start', last)
    dists = networkx.single_source_shortest_path_length(reverse_graph, 'start')
    del dists['start']
    for n in dists:
        dists[n] -= 1
    return dists
