def bootstrap():
  parser = ArgumentParser(description='Compiler arguments.')
  parser.add_argument('file_names', metavar='File Names', type=str, nargs='+',
                      help='name of the input files.')
  parser.add_argument('-d', '--debug', action='store_true',
                      help='Enable debug logging to the console.')
  args = parser.parse_args()

  if args.debug:
    LOGGER.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    LOGGER.addHandler(ch)

  p = Parser(args.file_names[0])
  ir = IntermediateRepresentation(p)

  ir.generate()
  cfg = ir.build_cfg()
  cfg.compute_dominance_frontiers()

  ssa = SSA(ir, cfg)
  ssa.construct()

  optimize = Optimize(ssa)
  optimize.optimize()

  regalloc = RegisterAllocator(ssa)
  is_allocated, failed_subgraph = regalloc.allocate()
  regalloc.deconstruct_ssa()

  cg = CodeGenerator(ssa)
  cg.generate()

  return cg
def bootstrap():
  parser = ArgumentParser(description='Compiler arguments.')
  parser.add_argument('file_names', metavar='File Names', type=str, nargs='+',
                      help='name of the input files.')
  parser.add_argument('-d', '--debug', action='store_true',
                      help='Enable debug logging to the console.')
  parser.add_argument('-t', '--trace', metavar="Trace Mode", type=str,
                      nargs='?', const=True,
                      help='Enable trace mode for optimizations.')
  parser.add_argument('-o', '--optimized', metavar="Optimized", type=str,
                      nargs='?', const=True,
                      help='Generates the optimized output.')
  parser.add_argument('-g', '--vcg', metavar="VCG", type=str,
                      nargs='?', const=True,
                      help='Generate the Visualization Compiler Graph output.')
  args = parser.parse_args()

  if args.debug:
    LOGGER.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    LOGGER.addHandler(ch)

  try:
    p = Parser(args.file_names[0])
    ir = IntermediateRepresentation(p)

    ir.generate()
    cfg = ir.build_cfg()
    cfg.compute_dominance_frontiers()

    ssa = SSA(ir, cfg)
    ssa.construct()

    optimize = Optimize(ssa)
    optimize.optimize()

    if args.optimized:
      external_file = isinstance(args.optimized, str)
      optimized_file = open(args.optimized, 'w') if external_file \
          else sys.stdout
      optimized_file.write('\n'.join([str(s) for s in ssa.optimized()]))
      if external_file:
        optimized_file.close()

    if args.vcg:
      vcg_file = open(args.vcg, 'w') if isinstance(args.vcg, str) else \
          sys.stdout
      vcg_file.write(ssa.ssa_cfg.generate_vcg())
      vcg_file.close()

    return ssa

  except LanguageSyntaxError, e:
    print e
    sys.exit(1)
Example #3
0
def bootstrap():
  parser = ArgumentParser(description='Compiler arguments.')
  parser.add_argument('file_names', metavar='File Names', type=str, nargs='+',
                      help='name of the input files.')
  parser.add_argument('-d', '--debug', action='store_true',
                      help='Enable debug logging to the console.')
  parser.add_argument('-g', '--vcg', metavar="VCG", type=str,
                      nargs='?', const=True,
                      help='Generate the Visualization Compiler Graph output.')
  parser.add_argument('-r', '--ir', metavar="IR", type=str,
                      nargs='?', const=True,
                      help='Generate the Intermediate Representation.')
  parser.add_argument('-s', '--ssa', metavar="SSA", type=str,
                      nargs='?', const=True,
                      help='Generate the Static Single Assignment.')
  parser.add_argument('-t', '--dom', metavar="DominatorTree", type=str,
                      nargs='?', const=True,
                      help='Generate the Dominator Tree VCG output.')

  args = parser.parse_args()

  if args.debug:
    LOGGER.setLevel(logging.DEBUG)
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    LOGGER.addHandler(ch)

  try:
    p = Parser(args.file_names[0])
    ir = IntermediateRepresentation(p)

    ir.generate()
    cfg = ir.build_cfg()
    cfg.compute_dominance_frontiers()

    ssa = SSA(ir, cfg)
    ssa.construct()

    if args.vcg:
      external_file = isinstance(args.vcg, str)
      vcg_file = open(args.vcg, 'w') if external_file else \
          sys.stdout
      vcg_file.write(ssa.ssa_cfg.generate_vcg(ir=ssa.ssa))
      if external_file:
        vcg_file.close()

    if args.ir:
      external_file = isinstance(args.ir, str)
      ir_file = open(args.ir, 'w') if external_file else \
          sys.stdout
      ir_file.write(str(ir))
      if external_file:
        ir_file.close()

    if args.dom:
      external_file = isinstance(args.dom, str)
      dom_file = open(args.dom, 'w') if external_file else \
          sys.stdout
      dom_file.write(str(cfg.generate_dom_vcg()))
      if external_file:
        dom_file.close()

    if args.ssa:
      external_file = isinstance(args.ssa, str)
      ssa_file = open(args.ssa, 'w') if external_file else \
          sys.stdout
      ssa_file.write(str(ssa))
      if external_file:
        ssa_file.close()

    return ssa
  except LanguageSyntaxError, e:
    print e
    sys.exit(1)
Example #4
0
def bootstrap():
    parser = ArgumentParser(description="Compiler arguments.")
    parser.add_argument("file_names", metavar="File Names", type=str, nargs="+", help="name of the input files.")
    parser.add_argument("-d", "--debug", action="store_true", help="Enable debug logging to the console.")
    parser.add_argument(
        "-g",
        "--vcg",
        metavar="VCG",
        type=str,
        nargs="?",
        const=True,
        help="Generate the Visualization Compiler Graph output.",
    )
    parser.add_argument(
        "-r", "--ir", metavar="IR", type=str, nargs="?", const=True, help="Generate the Intermediate Representation."
    )
    parser.add_argument(
        "-s", "--ssa", metavar="SSA", type=str, nargs="?", const=True, help="Generate the Static Single Assignment."
    )
    parser.add_argument(
        "-t",
        "--dom",
        metavar="DominatorTree",
        type=str,
        nargs="?",
        const=True,
        help="Generate the Dominator Tree VCG output.",
    )

    args = parser.parse_args()

    if args.debug:
        LOGGER.setLevel(logging.DEBUG)
        ch = logging.StreamHandler()
        ch.setLevel(logging.DEBUG)
        LOGGER.addHandler(ch)

    try:
        p = Parser(args.file_names[0])
        ir = IntermediateRepresentation(p)

        ir.generate()
        cfg = ir.build_cfg()
        cfg.compute_dominance_frontiers()

        ssa = SSA(ir, cfg)
        ssa.construct()

        if args.vcg:
            ssa.regenerate_cfg()
            external_file = isinstance(args.vcg, str)
            vcg_file = open(args.vcg, "w") if external_file else sys.stdout
            vcg_file.write(ssa.ssa_cfg.generate_vcg(ir=ssa.ssa))
            if external_file:
                vcg_file.close()

        if args.ir:
            external_file = isinstance(args.ir, str)
            ir_file = open(args.ir, "w") if external_file else sys.stdout
            ir_file.write(str(ir))
            if external_file:
                ir_file.close()

        if args.dom:
            external_file = isinstance(args.dom, str)
            dom_file = open(args.dom, "w") if external_file else sys.stdout
            dom_file.write(str(cfg.generate_dom_vcg()))
            if external_file:
                dom_file.close()

        if args.ssa:
            external_file = isinstance(args.ssa, str)
            ssa_file = open(args.ssa, "w") if external_file else sys.stdout
            ssa_file.write(str(ssa))
            if external_file:
                ssa_file.close()

        return ssa
    except LanguageSyntaxError, e:
        print e
        sys.exit(1)