def convertSubroutinesToProcedures(parse_tree, entry_points, line_mapper, options):
    logger.info("Convert subroutines to procedures")   
    entry_point_names_to_remove = []
    entry_points_to_add = {}
    for name, entry_point in entry_points.items():
        # TODO: This will only work with simple (i.e. single entry) subroutines
        print "name = %s, entry_point = %s" % (name, entry_point)
        subname = iter(entry_point.entryPoints).next()
        if subname.startswith('SUB'):
            procname = 'PROCSub' + subname[3:]
            assert len(entry_point.inEdges) == 0
            defproc = DefineProcedure(name=procname, formalParameters=None)
            insertStatementBefore(entry_point, defproc)
            deTagSuccessors(entry_point)
            entry_point.clearEntryPoints()
            entry_point_names_to_remove.append(name)
            entry_points_to_add[procname] = defproc
            entry_point.clearComeFromGosubEdges()
            tagSuccessors(defproc, line_mapper)
    for name in entry_point_names_to_remove:
        del entry_points[name]
    entry_points.update(entry_points_to_add)
    
    csv = ConvertSubVisitor()
    parse_tree.accept(csv)
def locateEntryPoints(parse_tree, line_mapper, options):
    '''
    Locate all the program, procedure, function and subroutine entry points in the program
    represented by parse_tree.
    :param parse_tree: The root AstNode of an abstract syntax tree representing the program.
    :param line_mapper: A LineMapper for the program.
    :param options: Command line options.
    :returns: A dictionary of entry point names to entry point AstStatement nodes.  The name
              of the program entry point, if there is one, will be '__owl__main'
    '''
    logging.debug("locateEntryPoints")    
    epv = EntryPointVisitor(line_mapper)
    parse_tree.accept(epv)
    first_statement = line_mapper.firstStatement()
    epv.mainEntryPoint(first_statement)
    entry_points = epv.entryPoints
    # Tag each statement with its predecessor entry point
    logging.debug("Tagging statements with entry point\n")
    for entry_point in entry_points.values():
        flow_analysis.tagSuccessors(entry_point, line_mapper)
        
    guardExecutableDefinitions(entry_points)
    return entry_points