def main():
    global engine
    global module
    global intermediary_code
    global result
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    output_location = input_location.partition('.')[0]
    output_filename = output_location.split('/')[-1]

    intermediary_code = str(ir_ula.main())
    engine = create_run_engine()
    module = compile_intermediary_code(engine, intermediary_code)

    # Find pointer to function to execute
    function_ptr = engine.get_function_address("main")

    # Execute the function using ctypes
    c_function = CFUNCTYPE(c_float)(function_ptr)
    result = c_function()
    if (__name__ == "__main__"):
        output_location = output_filename + '.run'
        with open(output_location, 'w') as file_writer:
            file_writer.write(str(result) + '\n')
        print(str(result))
def main():
    global abstract_syntax_tree
    global builder
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    output_location = input_location.partition('.')[0]
    output_filename = output_location.split('/')[-1]
    errors_ula.main()
    abstract_syntax_tree = errors_ula.result
    flttyp = ir.FloatType()  # create float type
    fnctyp = ir.FunctionType(flttyp,
                             ())  # create function type to return a float
    module = ir.Module(name="ula")  # create module named "ula"
    func = ir.Function(module, fnctyp, name="main")  # create "main" function
    block = func.append_basic_block(name="entry")  # create block "entry" label
    builder = ir.IRBuilder(block)
    generate_code(abstract_syntax_tree
                  )  # call code_gen() to traverse tree & generate code
    builder.ret(builder.load(var_dict[last_var]))  # specify return value
    if (__name__ == "__main__"):
        output_location = output_filename + '.ir'
        with open(output_location, 'w') as file_writer:
            file_writer.write(str(module) + '\n')
        print(str(module))
    return module
def main():
    global engine
    global module
    global intermediary_code
    global result
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    output_location = input_location.partition('.')[0]
    output_filename = output_location.split('/')[-1]

    intermediary_code = str(ir_ula.main())
    engine = create_run_engine()
    module = compile_intermediary_code(engine, intermediary_code)

    # Find pointer to function to execute
    function_ptr = engine.get_function_address("main")

    # Execute the function using ctypes
    c_function = CFUNCTYPE(c_float)(function_ptr)
    result = c_function()
    if (__name__ == "__main__"):
        output_location = output_filename + '.run'
        with open(output_location, 'w') as file_writer:
            file_writer.write(str(result) + '\n')
        print(str(result))
def main():
    global assembly_code
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    output_location = input_location.partition('.')[0]
    output_filename = output_location.split('/')[-1]
    run_ula.main()
    assembly_code = emit_assembly_code(run_ula.target_machine, run_ula.module)
    if (__name__ == "__main__"):
        output_location = output_filename + '.asm'
        with open(output_location, 'w') as file_writer:
            file_writer.write(str(assembly_code) + '\n')
        print(str(assembly_code))
def main(error_writer=None):
    global error_file_writer
    error_file_writer = error_writer
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    if os.path.isfile(input_location):
        with open(input_location, 'r') as file_reader:
            input_data = file_reader.read()
        output_location = input_location.partition('.')[0]
        output_filename = output_location.split('/')[-1]
        parse_input(input_data, output_filename)
    else:
        print("File " + input_location + " does not exist.")
Exemplo n.º 6
0
def main():
    global assembly_code
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    output_location = input_location.partition('.')[0]
    output_filename = output_location.split('/')[-1]
    run_ula.main()
    assembly_code = emit_assembly_code(run_ula.target_machine, run_ula.module)
    if (__name__ == "__main__"):
        output_location = output_filename + '.asm'
        with open(output_location, 'w') as file_writer:
            file_writer.write(str(assembly_code) + '\n')
        print(str(assembly_code))
def main(error_writer=None):
    global error_file_writer
    error_file_writer = error_writer
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    if os.path.isfile(input_location):
        with open(input_location, 'r') as file_reader:
            input_data = file_reader.read()
        output_location = input_location.partition('.')[0]
        output_filename = output_location.split('/')[-1]
        parse_input(input_data, output_filename)
    else:
        print("File " + input_location + " does not exist.")
def main():
    global result
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    output_location = input_location.partition('.')[0]
    output_filename = output_location.split('/')[-1]

    # When lexing, ignore all comments and whitespace
    lex_ula.t_ignore_WHITESPACE = r'\s+'
    lex_ula.t_ignore_COMMENT = r'\/\*[^(\*\/);]+\*\/|\/\/.*'
    lex_ula.t_WHITESPACE = r'a^'
    lex_ula.t_COMMENT = r'a^'
    if (__name__ == "__main__"):
        output_location = output_filename + '.err'
        with open(output_location, 'w') as file_writer:
            lex_ula.main(file_writer)
            result = parse_ula.main(file_writer)
            apply_semantic_analysis(file_writer, result)
    else:
        lex_ula.main()
        result = parse_ula.main()
        apply_semantic_analysis(None, result)
def main():
    global abstract_syntax_tree
    global builder
    args = args_.manage_arguments()
    input_location = args.file_location[0]
    output_location = input_location.partition('.')[0]
    output_filename = output_location.split('/')[-1]
    errors_ula.main()
    abstract_syntax_tree = errors_ula.result
    flttyp = ir.FloatType()  # create float type
    fnctyp = ir.FunctionType(flttyp, ())  # create function type to return a float
    module = ir.Module(name="ula")  # create module named "ula"
    func = ir.Function(module, fnctyp, name="main")  # create "main" function
    block = func.append_basic_block(name="entry")  # create block "entry" label
    builder = ir.IRBuilder(block)
    generate_code(abstract_syntax_tree)  # call code_gen() to traverse tree & generate code
    builder.ret(builder.load(var_dict[last_var]))  # specify return value
    if (__name__ == "__main__"):
        output_location = output_filename + '.ir'
        with open(output_location, 'w') as file_writer:
            file_writer.write(str(module) + '\n')
        print(str(module))
    return module