def main():
    """Main entry point for iotile-sgcompile."""

    arg_parser = build_args()
    args = arg_parser.parse_args()

    model = DeviceModel()

    parser = SensorGraphFileParser()
    parser.parse_file(args.sensor_graph)

    if args.format == u'ast':
        write_output(parser.dump_tree(), True, args.output)
        sys.exit(0)

    parser.compile(model)

    if not args.disable_optimizer:
        opt = SensorGraphOptimizer()
        opt.optimize(parser.sensor_graph, model=model)

    if args.format == u'nodes':
        output = u'\n'.join(parser.sensor_graph.dump_nodes()) + u'\n'
        write_output(output, True, args.output)
    else:
        if args.format not in KNOWN_FORMATS:
            print("Unknown output format: {}".format(args.format))
            sys.exit(1)

        output_format = KNOWN_FORMATS[args.format]
        output = output_format.format(parser.sensor_graph)

        write_output(output, output_format.text, args.output)
Main entry point for iotile-sgcompile.