예제 #1
0
    path, flag = sys.argv[1], int(
        sys.argv[2]
    ),  # dir name existing .vm file, wheather exist many file(1) or not(0)
    allasm_code = []

    if flag == 0:
        f_list = list(map(lambda x: path + '/' + x, os.listdir(path)))
        file = [f for f in f_list if re.search('.vm', f) != None][0][:-3]
        init_flag = get_init_flag(file)
        codewriter = CodeWriter(file, init_flag)
        parser = Parser(file)
        allasm_code += vm2asm_translater(codewriter, parser)
    else:
        old_return_addr = 0
        old_labelNum = 0
        init_flag = 1
        f_list = list(map(lambda x: path + '/' + x, os.listdir(path)))
        for f in f_list:
            if re.search('.*\.vm', f) != None:
                file = re.sub('\.vm', '', f)
                codewriter = CodeWriter(file, init_flag)
                parser = Parser(file)
                codewriter.labelNum = old_labelNum
                codewriter.return_address = old_return_addr
                allasm_code += vm2asm_translater(codewriter, parser)
                old_labelNum = codewriter.labelNum  # save old lable
                old_return_addr = codewriter.return_address  # save old address
                init_flag = 0

    fileToOutput(path, allasm_code)