Beispiel #1
0
def main():
    import gonelex
    import goneparse
    import gonecheck
    import gonecode
    import goneblock
    import sys
    import ctypes
    from errors import subscribe_errors, errors_reported
    from llvm.ee import ExecutionEngine

    # Load the Gone runtime library (see Makefile)
    ctypes._dlopen('./gonert.so', ctypes.RTLD_GLOBAL)

    lexer = gonelex.make_lexer()
    parser = goneparse.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg+"\n")):
        program = parser.parse(open(sys.argv[1]).read())
        # Check the program
        gonecheck.check_program(program)
        # If no errors occurred, generate code
        if not errors_reported():
            functions = gonecode.generate_code(program)
            # Emit the code sequence
            bv = LLVMBlockVisitor()
            bv.generate_llvm(functions)
            print(bv.llvm.module)

            # Verify and run function that was created during code generation
            print(":::: RUNNING ::::")
            bv.llvm.function.verify()
            llvm_executor = ExecutionEngine.new(bv.llvm.module)
            llvm_executor.run_function(bv.llvm.vars['__start'], [])
Beispiel #2
0
def main():
    import gonelex
    import goneparse
    import sys
    from errors import subscribe_errors
    lexer = gonelex.make_lexer()
    parser = goneparse.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg + "\n")):
        program = parser.parse(open(sys.argv[1]).read())
        # Check the program
        check_program(program)
Beispiel #3
0
def main():
    import gonelex
    import goneparse
    import gonecheck
    import gonecode
    import sys
    import ctypes
    import time
    import argparse
    from errors import subscribe_errors, errors_reported
    from llvm.ee import ExecutionEngine

    global args
    parser = argparse.ArgumentParser("Compile and run a Gone program from a .g file")
    parser.add_argument('file', type=str, default='', nargs=1,
                        help="the file containing Gone source")
    parser.add_argument('--verbose', '-v', action="store_true",
                        help="print verbose output")
    parser.add_argument('--validate', '-c', action="store_true",
                        help="perform llvm bitcode validation prior to program execution")
    args = parser.parse_args()

    # Load the Gone runtime library (see Makefile)
    ctypes._dlopen('./gonert.so', ctypes.RTLD_GLOBAL)

    lexer = gonelex.make_lexer()
    parser = goneparse.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg + "\n")):
        program = parser.parse(open(args.file[0]).read())
        gonecheck.check_program(program)
        if not errors_reported():
            code = gonecode.generate_code(program)
            g = GenerateLLVMBlockVisitor()
            g.visit_functions(code.functions)

            if args.verbose:
                print("---- NATIVE ASSEMBLY ----")
                print(g.generator.module.to_native_assembly())
                print("---- END NATIVE ASSEMBLY ----")

            if args.verbose:
                print(":::: RUNNING ::::")
            start = time.time()

            llvm_executor = ExecutionEngine.new(g.generator.module)
            llvm_executor.run_function(g.generator.main_func, [])

            if args.verbose:
                print(":::: FINISHED ::::")
                print("execution time: {0:.15f}s".format(time.time() - start))
Beispiel #4
0
def main():
    import gonelex
    import goneparse
    import gonecheck
    import sys
    from errors import subscribe_errors, errors_reported
    lexer = gonelex.make_lexer()
    parser = goneparse.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg + "\n")):
        program = parser.parse(open(sys.argv[1]).read())
        # Check the program
        gonecheck.check_program(program)
        # If no errors occurred, generate code
        if not errors_reported():
            code = generate_code(program)
            code = EmitBlocksVisitor().loop(code.functions)
Beispiel #5
0
def main():
    import gonelex
    import goneparse
    import gonecheck
    import sys
    from errors import subscribe_errors, errors_reported
    from pprint import pformat
    lexer = gonelex.make_lexer()
    parser = goneparse.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg+"\n")):
        program = parser.parse(open(sys.argv[1]).read())
        # Check the program
        gonecheck.check_program(program)
        # If no errors occurred, generate code
        if not errors_reported():
            functions = generate_code(program)
            for fn in functions:
                print(fn, '\n')
Beispiel #6
0
def main():
    import gonelex
    import goneparse
    import gonecheck
    import gonecode
    import sys
    from errors import subscribe_errors, errors_reported

    lexer = gonelex.make_lexer()
    parser = goneparse.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg+"\n")):
        program = parser.parse(open(sys.argv[1]).read())
        # Check the program
        gonecheck.check_program(program)
        # If no errors occurred, generate code
        if not errors_reported():
            functions = gonecode.generate_code(program)
            functions = list(functions) # just be sure it doesn't exhause
            interpreter = Interpreter(functions)
            interpreter.run(functions[0]) # first func is the place to start
Beispiel #7
0
def main():
    import gonelex
    import goneparse
    import gonecheck
    import gonecode
    import sys
    import time
    from errors import subscribe_errors, errors_reported

    lexer = gonelex.make_lexer()
    parser = goneparse.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg + "\n")):
        program = parser.parse(open(sys.argv[1]).read())
        # Check the program
        gonecheck.check_program(program)
        # If no errors occurred, generate code
        if not errors_reported():
            code = gonecode.generate_code(program)
            interpreter = Interpreter()
            start = time.clock()
            interpreter.run(code.code)
            print(":::: FINISHED ::::")
            print("execution time: {0:.15f}s".format(time.clock() - start))