Example #1
0
def ddump_optimizer(source):
    import parser
    import cfg
    import typecheck
    import codegen

    with errors.listen():
        parse = parser.make_parser()

        ast = parse(source)
        typecheck.typecheck(ast)

        functions = cfg.ssa_pass(ast)
        cgen = codegen.LLVMEmitter()
        blockgen = codegen.BlockEmitter(cgen)

        for name, retty, argtys, start_block in functions:
            function = blockgen.generate_function(
                name,
                retty,
                argtys,
                start_block
            )

            optimizer = codegen.LLVMOptimizer(cgen.module)

            print 'Optimizer Diff'.center(80, '=')
            optimizer.diff(function, cgen.module)
Example #2
0
 def parser(self):
     if not hasattr(self, '_parser'):
         self._parser = make_parser(self.placeholder, self.raw_marker,
                                    self.var_marker, self.const_marker,
                                    self.cntrl_marker,
                                    self.sub_start_marker,
                                    self.sub_end_marker, self.cntrls,
                                    self.lexer)
     return self._parser
Example #3
0
def ddump_tc(source, verbose=False):
    import sys
    import lexer
    import parser
    import errors
    import pprint

    with errors.listen():
        parse = parser.make_parser()

        ast = parse(source)
        symtab = typecheck(ast, verbose)

    if errors.occurred():
        sys.stdout.write("Not well-typed!\n")
    else:
        print 'Locals'.center(80, '=')
        sys.stdout.write(pprint.pformat(symtab._locals.items()) + '\n')
        print 'Globals'.center(80, '=')
        sys.stdout.write(pprint.pformat(symtab._globals) + '\n')
        sys.stdout.write("Well-typed!\n")
Example #4
0
def ddump_blocks(source):
    import errors

    import lexer
    import parser
    import typecheck

    parse = parser.make_parser()

    with errors.listen():
        program = parse(source)
        typecheck.typecheck(program)

        if not errors.reported():
            functions = ssa_pass(program)
            for funcname, retty, argtys, start_block in functions:
                fname = (" %s %s %s " % (funcname, retty, argtys))
                print fname.center(80, '-')
                print_block(start_block)
                print("")
        else:
            raise AssertionError
Example #5
0
def ddump_blocks(source):
    import errors

    import lexer
    import parser
    import typecheck

    parse = parser.make_parser()

    with errors.listen():
        program = parse(source)
        typecheck.typecheck(program)

        if not errors.reported():
            functions = ssa_pass(program)
            for funcname, retty, argtys, start_block in functions:
                fname = (" %s %s %s " % (funcname, retty, argtys))
                print fname.center(80, '-')
                print_block(start_block)
                print("")
        else:
            raise AssertionError
Example #6
0
def ddump_optimizer(source):
    import parser
    import cfg
    import typecheck
    import codegen

    with errors.listen():
        parse = parser.make_parser()

        ast = parse(source)
        typecheck.typecheck(ast)

        functions = cfg.ssa_pass(ast)
        cgen = codegen.LLVMEmitter()
        blockgen = codegen.BlockEmitter(cgen)

        for name, retty, argtys, start_block in functions:
            function = blockgen.generate_function(name, retty, argtys,
                                                  start_block)

            optimizer = codegen.LLVMOptimizer(cgen.module)

            print 'Optimizer Diff'.center(80, '=')
            optimizer.diff(function, cgen.module)
Example #7
0
    def __str__(self):
        return "~{}".format(str(self.expr))

    def typecheck(self, scope):
        _, ty = self.expr.typecheck(scope)

        if ty is not GLOBAL.integerType:
            self.error("neg type mismatch")
            
        return None, GLOBAL.integerType


if __name__ == "__main__":
    import sys
    import os
    import glob
    from parser import make_parser

    root_path = '/Users/Jack/Documents/programming/python/coolCompiler'
    test_folder = root_path + '/Tests'

    parser = make_parser()

    with open("Tests/strlen.cl") as file:
            cool_program_code = file.read()

    parse_result = parser.parse(cool_program_code)
    ret = parse_result.typecheck()
    if ret:
        parse_result.error("successful")
Example #8
0
                    help='如果不指定这个参数,那么对文件名去除混淆;'
                    '如果指定这个参数,那么对文件名进行混淆')
PARSER.add_argument('-l',
                    '--epub-list',
                    dest="list",
                    nargs='*',
                    default=[],
                    help='待处理的 ePub 文件(有多个用空格隔开)')
PARSER.add_argument('path',
                    nargs='*',
                    default=[],
                    help='待处理的 ePub 文件(有多个用空格隔开)(等价于 -l )')

subparsers = PARSER.add_subparsers(help='sub-command help')
subparser_full = subparsers.add_parser('full', help='使用完整版命令行参数')
make_parser(subparser_full)

args = PARSER.parse_args()

is_full_parser = 'full' in args

if not (args.path or args.list):
    if is_full_parser:
        PARSER.parse_args(['full', '-h'])
    PARSER.parse_args(['-h'])

from main import main

if is_full_parser:
    # 使用完整版
    main(args=args)
            else:
                check_type = sym.check_type
                if check_type is None:
                    error(node.lineno, "Using unrecognized type {}".format(valtype))
                node.check_type = check_type

    def visit_Literal(self,node):
        valtype = type(node.value)
        check_type = self.typemap.get(valtype, None)
        if check_type is None:
            error(node.lineno, "Using unrecognized type {}".format(valtype))
        if check_type==StringType and len(node.value)==1 :
            check_type = CharType
        node.check_type = check_type



def check_program(node):
    checker = CheckProgramVisitor()
    checker.visit(node)

if __name__ == '__main__':
    import lexer
    import parser
    import sys
    from errors import subscribe_errors
    pars = parser.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg+"\n")):
        program = pars.parse(open(sys.argv[1]).read())
        check_program(program)
Example #10
0
    for f in s["fields"]:
        if f["type"] == "TagReflexive":
            if f["struct"] not in dependencies:
                dependencies.append(f["struct"])

    for d in dependencies:
        add_struct(d)

    all_structs_arranged.append(struct_to_add)


for s in all_structs:
    add_struct(s["name"])


def to_hex(number):
    return "0x{:X}".format(number)


with open(sys.argv[1], "w") as f:
    with open(sys.argv[bitfield_cpp], "w") as bcpp:
        with open(sys.argv[bitfield_cpp + 1], "w") as ecpp:
            make_definitions(f, ecpp, bcpp, all_enums, all_bitfields,
                             all_structs_arranged)

parser_files = map(lambda fname: open(fname, "w"), sys.argv[2:15])
make_parser(all_enums, all_bitfields, all_structs_arranged, all_structs,
            *parser_files)
for f in parser_files:
    f.close()
Example #11
0
                                                with open(sys.argv[14],
                                                          "w") as cpp_compare:
                                                    with open(
                                                            sys.argv[15], "w"
                                                    ) as cpp_normalize:
                                                        with open(
                                                                sys.argv[16],
                                                                "w"
                                                        ) as cpp_hek_file:
                                                            make_parser(
                                                                all_enums,
                                                                all_bitfields,
                                                                all_structs_arranged,
                                                                all_structs,
                                                                extract_hidden,
                                                                hpp,
                                                                cpp_save_hek_data,
                                                                cpp_read_cache_file_data,
                                                                cpp_read_hek_data,
                                                                cpp_cache_format_data,
                                                                cpp_cache_deformat_data,
                                                                cpp_refactor_reference,
                                                                cpp_struct_value,
                                                                cpp_check_broken_enums,
                                                                cpp_check_invalid_references,
                                                                cpp_check_invalid_ranges,
                                                                cpp_check_invalid_indices,
                                                                cpp_compare,
                                                                cpp_normalize,
                                                                cpp_hek_file)
Example #12
0
def parse_pass(ast, env):
    parse = parser.make_parser()

    ast = parse(ast)
    return ast, env

    def visit_WhileBlock(self,block):
        # Emit a conditional jump around the if-branch
        #inst = ('while', block.condvar)
        #block+=inst)
        self.visit_BasicBlock(block)
        self.visit(block.truebranch)


if __name__ == '__main__':
    import lexer
    import parser as parser 
    import check
    import sys
    from errors import subscribe_errors, errors_reported
    lexer = lexer.make_lexer()
    parser = parser.make_parser()
    with subscribe_errors(lambda msg: sys.stdout.write(msg+"\n")):
        program = parser.parse(open(sys.argv[1]).read())
        # Check the program
        env = check.check_program(program)
        # If no errors occurred, generate code
        if not errors_reported():
            code = generate_code(program)
            print code
            # Emit the code sequence
            JumpGenerator().visit(code)
            #for inst in code:
            #    print(inst)
Example #14
0
def parse_pass(ast, env):
    parse = parser.make_parser()

    ast = parse(ast)
    return ast, env
Example #15
0
        os.path.join(common_args['drone_folder_path'], ('*.JPG')))

    pcl_img_loader = Loader()
    drone_img_loader = Loader()
    mask_img_loader = Loader()

    pcl_img_loader.load_img(os.path.join(common_args['pcl_path'], 'pcl.png'))

    resultWriter = ResultWriter(args)

    for idx, drone_path in enumerate(image_list):
        print(idx)
        mask_path = os.path.join(
            common_args['drone_mask_path'],
            drone_path.split("/")[-1].split(".")[0] + ".png")
        drone_img_loader.load_img(drone_path)
        mask_img_loader.load_img(mask_path)

        drone_image = drone_img_loader.get_img()
        pcl_image = pcl_img_loader.get_img()
        mask_image = mask_img_loader.get_img()

        result = registration.registrate(drone_image, pcl_image, mask_image,
                                         args)
        resultWriter.saveResults(result, idx)


if __name__ == '__main__':
    args = parser.make_parser()
    main(args)