Ejemplo n.º 1
0
def main(filename):
  char_stream = antlr3.ANTLRFileStream(filename)
  tokens = antlr3.CommonTokenStream(JumpLexer(char_stream))
  parser = JumpParser(tokens)
  root = parser.prog()

  g = make_graph(root.tree)
  g.optimize()
  print g.code_string()
Ejemplo n.º 2
0
def main(filename):
	char_stream = antlr3.ANTLRFileStream(filename)
	tokens = antlr3.CommonTokenStream(JumpLexer(char_stream))
	parser = JumpParser(tokens)
	graph = parser.prog().graph

	while True:
		graph.construct()
		#graph.print_CFG(sys.stdout)
		if graph.perform_JE():
			continue
		if graph.perform_UC():
			continue
		if graph.perform_CP():
			continue
		if graph.perform_DCE():
			continue
	
	graph.print_source(sys.stdout)
Ejemplo n.º 3
0
def main(fileobj):
    char_stream = antlr3.ANTLRInputStream(fileobj)
    tokens = antlr3.CommonTokenStream(JumpLexer(char_stream))
    parser = JumpParser(tokens)
    root = parser.prog()

    graph = CFGraph(root.tree)

    optimised = False
    code = [line for line in graph.generate()]
    while not optimised:
        graph.optimise(True)
        current_code = [line for line in graph.generate()]
        if code == current_code:
            optimised = True
        else:
            code = current_code
    
    print "\n".join(code)

    with open('cfg.dot', 'w') as f:
        graph.dotfile(f)