def update_ucf_file(ucf_file, clocks, tf):
    mhz_str = "%.2f MHz HIGH 50%%;" % tf
    ucf_lines = list()
    if clocks:
        for line in open(ucf_file):
            line = line.strip()
            if re.search("TIMESPEC", line):
                continue
            ucf_lines.append(line)
        ucf_lines.append("# clocks number: %s" % len(clocks))

        for i, clk in enumerate(clocks):
            ucf_lines.append('NET "%s" TNM_NET = %s;' % (clk, clk))
            new_spec = re.sub("\W", "__", clk)
            ucf_lines.append('TIMESPEC TS_%s = PERIOD "%s" %s' %
                             (new_spec, new_spec, mhz_str))
            if not ((i + 1) % 5):
                ucf_lines.append("")
    else:
        for line in open(ucf_file):
            line = line.strip()
            line = re.sub('PERIOD\s+"([^"]+)".+', 'PERIOD "\\1" %s' % mhz_str,
                          line)
            ucf_lines.append(line)
    append_file(ucf_file, ucf_lines, append=False)
Exemple #2
0
def update_ucf_file(ucf_file, clocks, tf):
    ucf_lines = ["# clocks number: %s" % len(clocks)]
    mhz_str = "%.2f MHz HIGH 50%%;" % tf
    for i, clk in enumerate(clocks):
        ucf_lines.append('NET "%s" TNM_NET = %s;' % (clk, clk))
        new_spec = re.sub("\W", "_", clk)
        ucf_lines.append('TIMESPEC TS_%s = PERIOD "%s" %s' % (new_spec, clk, mhz_str))
        if not( (i+1)%5 ):
            ucf_lines.append("")
    append_file(ucf_file, ucf_lines, append=False)
def update_sdc_file(sdc_file, clocks, tf):
    sdc_lines = ["derive_pll_clocks -use_tan_name",
                 'derive_clocks -period "%.3f MHz"' % tf, ""]
    in_ns = 1.0/tf * 1000
    in_ns = '"%.3f ns"' % in_ns
    for clk in clocks:
        sdc_lines.append("create_clock -period %s {%s}" % (in_ns, clk))
    sdc_lines.append("")
    sdc_lines.append("set_clock_groups -asynchronous \\")
    for clk in clocks[:-1]:
        sdc_lines.append("    -group { %s } \\" % clk)
    sdc_lines.append("    -group { %s }" % clocks[-1])
    sdc_lines.append("# Found %d Clocks." % len(clocks))

    append_file(sdc_file, sdc_lines, append=False)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Seed_is_(.+)")
    if family:
        for_pattern = '_'+family
    if syn:
        for_pattern = for_pattern + '_'+syn
    dir_pattern = re.compile(for_pattern)
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    
    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir,dir+'.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner: #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name,subtex = os.path.splitext(report_file)
                report_file_mrp = report_name+'_mrp'+subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name+'_twr'+subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name+'_time'+subtex
                if not_exists(report_file_time):
                    title = ["Design"] +['Target_seed']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name+'_clock'+subtex
                append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
        for design in all_designs:
            if need_design:
                if design == need_design:
                    pass
                else:
                    continue
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)# e60_ecp3/g64
            srr_file = ''
            for dir in os.listdir(design_path): # dir:Target_Fmax_is_060MHz   
                dir_scan = os.path.join(design_path,dir)
                if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and (not srr_file):
                    srr_file = get_unique_file([dir_scan, ".srr"])
                if re.search("Target", dir) and os.path.isdir(dir_scan):
                    pass
                else:
                    continue
                recover = RecoverPath(dir_scan)
                used_dir = ''
                for f_d in os.listdir(dir_scan):
                    f_d_full = os.path.join(dir_scan,f_d)
                    if os.path.isdir(f_d_full):
                        if used_dir:
                            print 'Worning: There are two implementation in the design'
                        used_dir = f_d_full
                
                if not srr_file:
                    pass
                else:
                    srr_file = os.path.join(design_path,dir,srr_file) 
                    scan_time.scan_srr(srr_file)
                mrp_file = get_unique_file([used_dir, ".mrp"])
                if not_exists(mrp_file, "map report file"):
                    
                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                twr_file = time_file = par_file= ""
                target_fmax_for_time = '_'
                #------------------------------------------------#
                if 1:
                     useful_dir = used_dir
                     base_name = os.path.basename(useful_dir)
                     scan_time.reset_par_time_data()
                     target_fmax_for_match = target_fmax_re.search(dir)
                     if target_fmax_for_match:
                         target_fmax_for_time = target_fmax_for_match.group(1)
                     twr_p = os.path.join(useful_dir,'*'+base_name+".twr")
                     twr_file = get_unique_file(twr_p)
                     if not twr_file:
                         twr_file = get_unique_file([useful_dir, ".twr"])
                     time_file = os.path.join(useful_dir, time_file)
                     par_file = get_unique_file([useful_dir, ".par"])
                     if twr_file:
                         scan_twr.scan_report(twr_file)
                         scan_time.scan_report(time_file)
                         scan_time.scan_par(par_file)
                         #########################
                         #time_title = ['design']+scan_time.get_title2()
                         srr_data = scan_time.get_srr_time_data()
                         mrp_data = scan_time.get_mrp_time_data()
                         par_data = scan_time.get_par_time_data()
                         real_cpu_total = scan_time.get_total_time()
                         all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                         data_list = []
                         for key in scan_time.get_title():
                             value = all_time_data.get(key,'NA')
                             data_list.append(value)
                         data_list2 = [design]+[target_fmax_for_time] +data_list
                         append_file(report_file_time,",".join(data_list2))
                             
                         #########################
                         #data = [design] + scan_mrp.get_data() + \
                         #      scan_twr.get_data() + data_list
                         if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                             data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                         ['_']*len(data_list)
                         else:
                             data_list = scan_mrp.get_data() + \
                               scan_twr.get_data() + data_list
                         data = [design] + data_list
                         append_file(report_file, ",".join(data))
                         data = [design]
                         append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                         append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                         #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                         scan_time.reset_par_time_data()
                     if not twr_file:
                         srr_data = scan_time.get_srr_time_data()
                         mrp_data = scan_time.get_mrp_time_data()
                         par_data = scan_time.get_par_time_data()
                         real_cpu_total = scan_time.get_total_time()
                         all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                               real_cpu_total.items() )
                         data_list = []
                         for key in scan_time.get_title():
                             value = all_time_data.get(key,'NA')
                             data_list.append(value)
                         data_list2 = [design]+[target_fmax_for_time] +data_list
                         append_file(report_file_time,",".join(data_list2))
                         #data = [design] + scan_mrp.get_data()+ data_list
                         if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                             data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                         else:
                             data = [design] + scan_mrp.get_data()+ data_list
                         append_file(report_file, ",".join(data))
                         append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                         scan_time.reset_par_time_data()
                scan_mrp.scan_clocks(mrp_file)
                clock_dict = scan_mrp.get_parse_line_clocks()
                for key in clock_dict.keys():
                    line = design+','+key+','+clock_dict[key]
                    append_file(report_file_clock,line)
                recover.run()
        os.chdir(root_dir)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    design = opt.design
    syn = opt.synthesis
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_xilinx.ScanXilinxMrp()
    scan_twr = tool_scan_xilinx.ScanXilinxTwr()
    scan_time = tool_scan_xilinx.ScanXilinxTimeMem()
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)
    print for_pattern

    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    if design:
        print_always('scanning %s' % design)
        if design in all_designs:
            design_path = os.path.join(job_dir, design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(
                        os.path.join(design_path, dir)):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(job_dir, dir + '.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner:  #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))

                    if 1:
                        report_name, subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name + '_mrp' + subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name + '_twr' + subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name + '_time_mem' + subtex
                        if not_exists(report_file_time):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))

                ######################
                    dir_scan = os.path.join(design_path, dir)
                    twr_file = time_file = ""
                    if 'rev_1' in os.listdir(dir_scan):
                        scan_time.set_srr_data()
                        foo = os.path.join(dir_scan, 'rev_1', '*.srr')
                        srr_file = get_unique_file(foo)
                        if srr_file:
                            scan_time.scan_srr(srr_file)
                    for foo in os.listdir(dir_scan):
                        foo = os.path.join(dir_scan, foo)
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                print foo
                                recover = RecoverPath(
                                    os.path.join(design_path, dir, foo))
                                scan_mrp.reset()
                                #scan_time.reset()
                                scan_time.set_map_data()
                                scan_time.set_par_data()

                                scan_twr.reset()
                                print_always("  Scanning %s" % foo)
                                _project_name = "%s_%s" % (dir, design[:7])
                                project_name = _project_name.strip("_")
                                mrp_file = os.path.join(
                                    dir_scan, foo, project_name + "_map.mrp")
                                scan_mrp.scan_report(mrp_file)
                                scan_time.scan_map(mrp_file)
                                par_file = os.path.join(
                                    dir_scan, foo, project_name + ".par")
                                scan_time.scan_par(par_file)
                                twr_file = os.path.join(
                                    dir_scan, foo, project_name + ".twr")

                                scan_twr.scan_report(twr_file)
                                time_file = os.path.join(
                                    dir_scan, foo, "mpar_log.time")
                                #scan_time.scan_report(time_file)
                                data1 = scan_mrp.get_data()
                                append_file(report_file_mrp,
                                            ",".join([design] + data1))
                                data2 = scan_twr.get_data()
                                append_file(report_file_twr,
                                            ",".join([design] + data2))
                                data3 = scan_time.get_data()
                                append_file(report_file_time,
                                            ",".join([design] + data3))
                                data = data1 + data2 + data3
                                append_file(report_file,
                                            ",".join([design] + data))
                                recover.run()

        else:
            print 'The design is not exists in the job_dir'
            return
    else:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always('scanning %s' % design)
            design_path = os.path.join(job_dir, design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(
                        os.path.join(design_path, dir)):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(job_dir, dir + '.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner:  #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name, subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name + '_mrp' + subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name + '_twr' + subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name + '_time_mem' + subtex
                        if not_exists(report_file_time):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))

                ######################
                    dir_scan = os.path.join(design_path, dir)
                    twr_file = time_file = ""
                    if 'rev_1' in os.listdir(dir_scan):
                        scan_time.set_srr_data()
                        foo = os.path.join(dir_scan, 'rev_1', '*.srr')
                        srr_file = get_unique_file(foo)
                        if srr_file:
                            scan_time.scan_srr(srr_file)

                    for foo in os.listdir(dir_scan):
                        if os.path.isdir(os.path.join(design_path, dir, foo)):
                            if re.search("Target", foo):
                                recover = RecoverPath(
                                    os.path.join(design_path, dir, foo))
                                scan_mrp.reset()
                                #scan_time.reset()
                                scan_time.set_map_data()
                                scan_time.set_par_data()
                                scan_twr.reset()
                                print_always("  Scanning %s" % foo)
                                _project_name = "%s_%s" % (dir, design[:7])
                                project_name = _project_name.strip("_")
                                mrp_file = os.path.join(
                                    dir_scan, foo, project_name + "_map.mrp")
                                scan_mrp.scan_report(mrp_file)
                                scan_time.scan_map(mrp_file)
                                par_file = os.path.join(
                                    dir_scan, foo, project_name + ".par")
                                scan_time.scan_par(par_file)
                                twr_file = os.path.join(
                                    dir_scan, foo, project_name + ".twr")
                                scan_twr.scan_report(twr_file)
                                #time_file = os.path.join(dir_scan,foo,"mpar_log.time")
                                #scan_time.scan_report(time_file)
                                data1 = scan_mrp.get_data()
                                append_file(report_file_mrp,
                                            ",".join([design] + data1))
                                data2 = scan_twr.get_data()
                                append_file(report_file_twr,
                                            ",".join([design] + data2))
                                data3 = scan_time.get_data()
                                append_file(report_file_time,
                                            ",".join([design] + data3))
                                data = data1 + data2 + data3
                                append_file(report_file,
                                            ",".join([design] + data))
                                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    #----------------update run_stand-------------------#
    pass_log = glob.glob('*' + syn + '_pass_case.log')
    if pass_log:
        pass_log = pass_log[0]
    else:
        pass_log = '__'
    if os.path.isfile(pass_log):
        file_hand = file(pass_log, 'r')
        lines = file_hand.readlines()
        file_hand.close()
        stand_name = glob.glob('*' + syn + '_run_standard.bat')
        if stand_name:
            stand_name = stand_name[0]
        #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
        else:
            stand_name = ''
        run_standard = file(stand_name, 'r')
        run_standard_lines = run_standard.readlines()
        run_standard.close()
        useful_lines = []
        for case in lines:
            case = case.strip()
            if not case:
                continue
            else:
                pass
            case_tab = '--design=' + case
            case_tab_re = re.compile(case_tab + r'(\s+|$)')
            for line in run_standard_lines:
                line = line.strip()
                if not line:
                    continue
                if case_tab_re.search(line):
                    try:
                        fmax = float(design_fmax[case.strip()])
                        fmax = str(int(fmax))
                        #line = case_tab_re.sub('',line)
                        line = re.sub(r'--fmax-sweep=[\s\d]+\d', '', line)
                        line2 = line + ' --fmax-sweep=' + fmax + ' ' + fmax + ' ' + '10 \n'
                    except:
                        line2 = line

                    useful_lines.append(line2)
        run_standard = file(stand_name, 'w')
        run_standard.writelines(useful_lines)
        run_standard.close()
        '''        
Exemple #6
0
def scan_report():
    opt = option()
    scanner = (tool_scan_altera_temp.ScanAlteraFit(), tool_scan_altera_temp.ScanAlteraFmax())
    job_dir = opt.job_dir
    #design = opt.design
    #syn = opt.synthesis
    #family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    #pap = opt.pap
    scan_fit = tool_scan_altera_temp.ScanAlteraFit()
    scan_fmax =  tool_scan_altera_temp.ScanAlteraFmax()
    scan_time_mem = tool_scan_altera_temp.ScanTimeMem()
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    if 0:
        pass
        
    else:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path): #at here dir should be as "_cyclone4_syn"
                dir_scan = os.path.join(design_path,dir)
                if os.path.isdir(dir_scan):
                    pass
                else:
                    continue
                if 1:
                    #####################
                    scanner = (scan_fit, scan_fmax,scan_time_mem)
                    report_file = os.path.join(job_dir,dir+'.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_fit = report_name+'_fit'+subtex
                        if not_exists(report_file_fit):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_fit, ",".join(title))
                        report_file_sta = report_name+'_sta'+subtex
                        if not_exists(report_file_sta):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_sta, ",".join(title))
                        report_file_time_mem = report_name+'_time_mem'+subtex
                        if not_exists(report_file_time_mem):
                            title = ["Design"]
                            title += (scanner[2]).get_title()
                            append_file(report_file_time_mem, ",".join(title))
                        
                    ######################
                    recover = RecoverPath(dir_scan) 
                    fit_file = sta_file = map_file = srr_file =  ""
                    
                    if 'rev_1' in os.listdir('.'):
                        scan_time_mem.reset()
                        foo = os.path.join(dir_scan,'rev_1')
                        srr_file = get_unique_file(foo+'/'+'*.srr')
                        if srr_file:
                            scan_time_mem.scan_srr(srr_file)
                    
                    for foo in os.listdir("."):
                        data = []
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_fit.reset()
                                scan_fmax.reset()
                                scan_time_mem.set_fit_data()
                                scan_time_mem.set_map_data()
                                print_always("  Scanning %s" % foo)
                                fit_file = get_unique_file(foo+'/'+"*.fit.rpt")
                                sta_file = get_unique_file(foo+'/'+"*.sta.rpt")
                                map_file = get_unique_file(foo+'/'+'*.map.rpt')
                                if fit_file:
                                    scan_fit.scan_report(fit_file)
                                    scan_time_mem.scan_fit(fit_file)
                                    data1=[design]+scan_fit.get_data()
                                    append_file(report_file_fit, ",".join(data1))
                                    data = data + data1
                                if sta_file:
                                    scan_fmax.scan_report_temp(sta_file)
                                    data2=[design]+scan_fmax.get_data()
                                    append_file(report_file_sta, ",".join(data2))
                                    data = data + data2[1:]
                                if map_file:
                                    scan_time_mem.scan_map(map_file)
                                scan_t_m = scan_time_mem.get_data()
                                append_file(report_file_time_mem, ",".join([design]+scan_t_m))
                                data  = data + scan_t_m
                                append_file(report_file, ",".join(data))
                    recover.run()
            
            
            
            
        os.chdir(root_dir)               
    for f in report_file_list:
        if os.path.isfile(f):
            print '#######################################'
            file_sorted,note,design_fmax = report_sort_temp.sort_csv(f,col_key='PAP',add_average=1)
            report_sort_temp.write_note(file_sorted,note)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)

    all_designs = []
    if os.path.isdir(job_dir):
        for d in os.listdir(job_dir):
            if d.endswith('.csv'):
                d = os.path.join(job_dir, d)
                os.remove(d)
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir, dir + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        #for design in all_designs:
        for root1, dirs1, files1 in os.walk(job_dir):
            root1 = os.path.abspath(root1)
            find_mrp = 0
            for f in files1:
                if f.endswith('.mrp'):
                    find_mrp = 1
                    break
            if find_mrp == 1:
                pass
            else:
                continue
            design_path = os.path.join(root1)  # e60_ecp3/g64
            srr_file = ''
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                if (not re.search("Target", dir)
                    ) and os.path.isdir(dir_scan) and not srr_file:
                    srr_file = get_unique_file([dir_scan, ".srr"])
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz

                #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file
                recover = RecoverPath(design_path)

                mrp_file = get_unique_file([design_path, ".mrp"])
                if not_exists(mrp_file, "map report file"):

                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                append_file(report_file_mrp,
                            ",".join([design_path] + scan_mrp.get_data()))
                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    file_hand_pass = file('pass_case.log', 'w')
    #----------read fail case first:
    try:
        file_hand_fail = file('fail_case.log', 'r')
        fail_case_lines = file_hand_fail.readlines()
        file_hand_fail.close()
        fail_case_lines2 = [
            f_c.split(':')[0].strip() for f_c in fail_case_lines
        ]
    except:
        fail_case_lines2 = []
    file_hand_fail = file('fail_case.log', 'w')
    for key in design_fmax.keys():
        v = design_fmax[key]

        if re.search(r'\d', v):
            file_hand_pass.write(key + '\n')
        else:
            if key in fail_case_lines2:
                fail_k = fail_case_lines[fail_case_lines2.index(key)]
                file_hand_fail.write(fail_k.strip() + '\n')
            else:
                file_hand_fail.write(key + '\n')
    file_hand_pass.close()
    file_hand_fail.close()
Exemple #8
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    design = opt.design
    scan_mrp = tool_scan_xilinx.ScanXilinxMrp()
    scan_twr = tool_scan_xilinx.ScanXilinxTwr()
    scan_time = tool_scan_xilinx.ScanXilinxTimeMem()
    scan_timing_rpt = tool_scan_xilinx.ScanXilinxTimingRpt()
    scan_placed_rpt = tool_scan_xilinx.ScanXilinxPlacedRpt()
    tag = opt.special_structure
    report_name = opt.report_name  #this is useless now
    if report_name == 'report.csv':
        report_file = os.path.basename(job_dir) + '.csv'
    report_path = opt.report_path
    if not report_path:
        report_path = job_dir
    report_file = os.path.join(report_path, report_file)
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    if not design:
        for dir in os.listdir(job_dir):  # get all the design path
            dir2 = os.path.join(job_dir, dir)
            if os.path.isdir(dir2):
                all_designs.append(dir)
            else:
                pass
    else:
        all_designs.append(design)
    report_file_list = []
    if 1:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always('scanning %s' % design)
            design_path = os.path.join(job_dir, design, tag)
            for dir in os.listdir(design_path):
                if dir.endswith('.runs') and os.path.isdir(
                        os.path.join(design_path, dir)):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file_list.append(report_file)

                    ######################
                    dir_scan = os.path.join(design_path, dir)
                    twr_file = time_file = ""
                    if 'rev_1' in os.listdir(dir_scan):
                        scan_time.set_srr_data()
                        foo = os.path.join(dir_scan, 'rev_1', '*.srr')
                        srr_file = get_unique_file(foo)
                        if srr_file:
                            scan_time.scan_srr(srr_file)

                    for foo in os.listdir(dir_scan):
                        if os.path.isdir(os.path.join(design_path, dir, foo)):
                            if re.search("Target", foo):  # this is ISE
                                recover = RecoverPath(
                                    os.path.join(design_path, dir, foo))
                                scan_mrp.reset()
                                #scan_time.reset()
                                scan_time.set_map_data()
                                scan_time.set_par_data()
                                scan_twr.reset()
                                print_always("  Scanning %s" % foo)
                                _project_name = "%s_%s" % (dir, design[:7])
                                project_name = _project_name.strip("_")
                                mrp_file = os.path.join(
                                    dir_scan, foo, project_name + "_map.mrp")
                                if os.path.isfile(mrp_file):
                                    if not_exists(report_file):
                                        title = ["Design"]
                                        for item in scanner:  #mrp twr time
                                            title += item.get_title()
                                        append_file(report_file,
                                                    ",".join(title))
                                    if 1:
                                        report_name, subtex = os.path.splitext(
                                            report_file)
                                        report_file_mrp = report_name + '_mrp' + subtex
                                        if not_exists(report_file_mrp):
                                            title = ["Design"]
                                            #for item in scanner: #mrp twr time
                                            title += (scanner[0]).get_title()
                                            append_file(
                                                report_file_mrp,
                                                ",".join(title))
                                        report_file_twr = report_name + '_twr' + subtex
                                        if not_exists(report_file_twr):
                                            title = ["Design"]
                                            #for item in scanner: #mrp twr time
                                            title += (scanner[1]).get_title()
                                            append_file(
                                                report_file_twr,
                                                ",".join(title))
                                        report_file_time = report_name + '_time_mem' + subtex
                                        if not_exists(report_file_time):
                                            title = ["Design"]
                                            #for item in scanner: #mrp twr time
                                            title += (scanner[2]).get_title()
                                            append_file(
                                                report_file_time,
                                                ",".join(title))

                                    scan_mrp.scan_report(mrp_file)
                                    scan_time.scan_map(mrp_file)
                                    par_file = os.path.join(
                                        dir_scan, foo, project_name + ".par")
                                    scan_time.scan_par(par_file)
                                    twr_file = os.path.join(
                                        dir_scan, foo, project_name + ".twr")
                                    scan_twr.scan_report(twr_file)
                                    #time_file = os.path.join(dir_scan,foo,"mpar_log.time")
                                    #scan_time.scan_report(time_file)
                                    data1 = scan_mrp.get_data()
                                    append_file(report_file_mrp,
                                                ",".join([design] + data1))
                                    data2 = scan_twr.get_data()
                                    append_file(report_file_twr,
                                                ",".join([design] + data2))
                                    data3 = scan_time.get_data()
                                    append_file(report_file_time,
                                                ",".join([design] + data3))
                                    data = data1 + data2 + data3
                                    append_file(report_file,
                                                ",".join([design] + data))

                                #for vivado
                                if not os.path.isfile(twr_file):
                                    if 1:
                                        title = ["Design"]
                                        for item in [
                                                scan_timing_rpt,
                                                scan_placed_rpt
                                        ]:  #mrp twr time
                                            title += item.get_title()
                                        if not_exists(report_file):
                                            append_file(
                                                report_file, ",".join(title))
                                        if 0:
                                            report_name, subtex = os.path.splitext(
                                                report_file)
                                            report_file_mrp = report_name + '_mrp' + subtex
                                            if not_exists(report_file_mrp):
                                                title = ["Design"]
                                                #for item in scanner: #mrp twr time
                                                title += (
                                                    scanner[0]).get_title()
                                                append_file(
                                                    report_file_mrp,
                                                    ",".join(title))
                                            report_file_twr = report_name + '_twr' + subtex
                                            if not_exists(report_file_twr):
                                                title = ["Design"]
                                                #for item in scanner: #mrp twr time
                                                title += (
                                                    scanner[1]).get_title()
                                                append_file(
                                                    report_file_twr,
                                                    ",".join(title))
                                            report_file_time = report_name + '_time_mem' + subtex
                                            if not_exists(report_file_time):
                                                title = ["Design"]
                                                #for item in scanner: #mrp twr time
                                                title += (
                                                    scanner[2]).get_title()
                                                append_file(
                                                    report_file_time,
                                                    ",".join(title))
                                    timing_rpt = os.path.join(
                                        dir_scan, foo,
                                        '*timing_summary_routed.rpt')
                                    timing_rpt = get_unique_file(timing_rpt)
                                    total_data = [design]
                                    if timing_rpt:
                                        scan_timing_rpt.scan_report(timing_rpt)
                                        total_data += scan_timing_rpt.get_data(
                                        )
                                    else:
                                        total_data += ['NA'] * len(
                                            scan_timing_rpt.get_title())

                                    placed_rpt = os.path.join(
                                        dir_scan, foo,
                                        '*utilization_placed.rpt')
                                    placed_rpt = glob.glob(placed_rpt)
                                    used_rpt = ''
                                    for rpt in placed_rpt:
                                        if rpt.find('clock_utilization') != -1:
                                            continue
                                        else:
                                            used_rpt = rpt
                                            break
                                    if used_rpt:
                                        scan_placed_rpt.scan_report(used_rpt)
                                        total_data += scan_placed_rpt.get_data(
                                        )
                                    else:
                                        total_data += ['NA'] * len(
                                            scan_placed_rpt.get_title())

                                    append_file(report_file,
                                                ",".join(total_data))
                                    for_bqs_data = '<scan_case>\n'
                                    for id1, t in enumerate(title):

                                        for_bqs_data = for_bqs_data + "\t<%s>" % t + total_data[
                                            id1] + "</%s>\n" % t
                                    for_bqs_data = for_bqs_data + "</scan_case>"
                                    print '#BQS_RETRN_DATA_BEGIN#'
                                    print for_bqs_data
                                    print '#BQS_RETRN_DATA_END#'
                                recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    #----------------update run_stand-------------------#
    if 0:
        pass_log = glob.glob('*' + syn + '_pass_case.log')
        if pass_log:
            pass_log = pass_log[0]
        else:
            pass_log = '__'
        if os.path.isfile(pass_log):
            file_hand = file(pass_log, 'r')
            lines = file_hand.readlines()
            file_hand.close()
            stand_name = glob.glob('*' + syn + '_run_standard.bat')
            if stand_name:
                stand_name = stand_name[0]
            #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
            else:
                stand_name = ''
            run_standard = file(stand_name, 'r')
            run_standard_lines = run_standard.readlines()
            run_standard.close()
            useful_lines = []
            for case in lines:
                case = case.strip()
                if not case:
                    continue
                else:
                    pass
                case_tab = '--design=' + case
                case_tab_re = re.compile(case_tab + r'(\s+|$)')
                for line in run_standard_lines:
                    line = line.strip()
                    if not line:
                        continue
                    if case_tab_re.search(line):
                        try:
                            fmax = float(design_fmax[case.strip()])
                            fmax = str(int(fmax))
                            #line = case_tab_re.sub('',line)
                            line = re.sub(r'--fmax-sweep=[\s\d]+\d', '', line)
                            line2 = line + ' --fmax-sweep=' + fmax + ' ' + fmax + ' ' + '10 \n'
                        except:
                            line2 = line

                        useful_lines.append(line2)
            run_standard = file(stand_name, 'w')
            run_standard.writelines(useful_lines)
            run_standard.close()
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    report_name = opt.report_name  #this is useless now
    scan_mrp = tool_scan_xilinx_temp.ScanXilinxMrp()
    scan_twr = tool_scan_xilinx_temp.ScanXilinxTwr()
    scan_time = tool_scan_xilinx_temp.ScanXilinxTimeMem()

    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    if 0:
        pass
    else:
        root_dir = os.getcwd()
        for design in all_designs:
            design_path = os.path.join(job_dir, design)
            for dir in os.listdir(design_path):
                if os.path.isdir(os.path.join(design_path, dir)):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(job_dir, dir + '.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner:  #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name, subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name + '_mrp' + subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name + '_twr' + subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name + '_time_mem' + subtex
                        if not_exists(report_file_time):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                    for dir2 in os.listdir(os.path.join(design_path, dir)):
                        dir_scan = os.path.join(design_path, dir, dir2)
                        if os.path.isdir(dir_scan):
                            pass
                        else:
                            continue
                        print dir_scan
                        twr_file = time_file = ""
                        if 'rev_1' in os.listdir(os.path.join(
                                design_path, dir)):
                            scan_time.set_srr_data()
                            foo = os.path.join(dir_scan, '*.srr')
                            srr_file = get_unique_file(foo)
                            if srr_file:
                                scan_time.scan_srr(srr_file)

                        if 1:
                            foo = dir2
                            if 1:
                                if re.search("Target", foo):
                                    recover = RecoverPath(dir_scan)
                                    scan_mrp.reset()
                                    #scan_time.reset()
                                    scan_time.set_map_data()
                                    scan_time.set_par_data()
                                    scan_twr.reset()
                                    print_always("  Scanning %s" % foo)
                                    _project_name = "%s_%s" % (dir, design[:7])
                                    project_name = _project_name.strip("_")
                                    mrp_file = os.path.join(
                                        dir_scan, project_name + "_map.mrp")
                                    scan_mrp.scan_report(mrp_file)
                                    scan_time.scan_map(mrp_file)
                                    par_file = os.path.join(
                                        dir_scan, project_name + ".par")
                                    scan_time.scan_par(par_file)
                                    twr_file = os.path.join(
                                        dir_scan, project_name + ".twr")
                                    scan_twr.scan_report_temp(twr_file)
                                    #time_file = os.path.join(dir_scan,foo,"mpar_log.time")
                                    #scan_time.scan_report(time_file)
                                    data1 = scan_mrp.get_data()
                                    append_file(report_file_mrp,
                                                ",".join([design] + data1))
                                    data2 = scan_twr.get_data()
                                    append_file(report_file_twr,
                                                ",".join([design] + data2))
                                    data3 = scan_time.get_data()
                                    append_file(report_file_time,
                                                ",".join([design] + data3))
                                    data = data1 + data2 + data3
                                    append_file(report_file,
                                                ",".join([design] + data))
                                    recover.run()

        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort_temp.sort_csv(
                f, col_key='PAP', add_average=1)
            report_sort_temp.write_note(file_sorted, note)
 def scan_report(self):
     scan_mrp = tool_scan_lattice.ScanLatticeMrp()
     scan_twr = tool_scan_lattice.ScanLatticeTwr(self.pap)
     scan_time = tool_scan_lattice.ScanLatticeTime()
     if self.family:
         for_pattern = '_'+family
     if self.synthesis:
         for_pattern = for_pattern + '_'+syn
     dir_pattern = re.compile(for_pattern)
     if os.path.isdir(self.job_dir):
         pass
     else:
         print 'Error: The job_dir:%s is not a directory'%self.job_dir
         return
     report_file_list = []
     all_designs = []
     if not self.design:
         for dir in os.listdir(job_dir):  # get all the design path
             dir2 =  os.path.join(job_dir,dir)
             if os.path.isdir(dir2):
                 all_designs.append(dir)
             else:
                 pass
     else:
         dir = os.path.join(job_dir,self.design)
         if os.path.isdir(dir):
             all_designs.append(dir)
         else:
             print 'Error: Can not find case:%s'%self.design
     root_dir = os.getcwd()
     for design in all_designs:
         print_always( 'scanning %s'%design)
         design_path = os.path.join(job_dir,design)
         for dir in os.listdir(design_path):
             if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                 #####################
                 scanner = (scan_mrp, scan_twr, scan_time)
                 report_file = self.report_file
                 if report_file in report_file_list:
                     pass
                 else:
                     report_file_list.append(report_file)
                 if not_exists(report_file):
                     title = ["Design"]
                     for item in scanner: #mrp twr time
                         title += item.get_title()
                     append_file(report_file, ",".join(title))
                 if 1:
                     report_name,subtex = os.path.splitext(report_file)
                     report_file_mrp = report_name+'_mrp'+subtex
                     if not_exists(report_file_mrp):
                         title = ["Design"]
                         #for item in scanner: #mrp twr time
                         title += (scanner[0]).get_title()
                         append_file(report_file_mrp, ",".join(title))
                     report_file_twr = report_name+'_twr'+subtex
                     if not_exists(report_file_twr):
                         title = ["Design"]
                         #for item in scanner: #mrp twr time
                         title += (scanner[1]).get_title()
                         append_file(report_file_twr, ",".join(title))
                     report_file_time = report_name+'_time'+subtex
                     if not_exists(report_file_time):
                         title = ["Design"] +['Target_fmax']
                         #for item in scanner: #mrp twr time
                         title += (scanner[2]).get_title()
                         append_file(report_file_time, ",".join(title))
                     report_file_clock = report_name+'_clock'+subtex
                     if not_exists(report_file_clock):
                         append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
            
                 dir_scan = os.path.join(design_path,dir)
                 recover = RecoverPath(dir_scan)
                 if not_exists('rev_1', "srr file directory"):
                     continue
                 srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                 if not srr_file:
                     pass
                 else:
                     srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                     scan_time.scan_srr(srr_file)
                 _project_name = "%s_%s" % (dir, design[:7])
                 project_name = _project_name.strip("_")
                 mrp_file = project_name + ".mrp"
                 if not_exists(mrp_file, "map report file"):
                     continue
                 scan_mrp.scan_report(mrp_file)
                 scan_time.scan_mrp(mrp_file)
                 twr_file = time_file = par_file= ""
                 target_fmax_for_time = '_'
                 target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                 for foo in os.listdir("."):
                     if os.path.isdir(foo):
                         if re.search("Target", foo):
                             scan_time.reset_par_time_data()
                             print_always("  Scanning %s" % foo)
                             target_fmax_for_match = target_fmax_re.search(foo)
                             if target_fmax_for_match:
                                 target_fmax_for_time = target_fmax_for_match.group(1)
                             twr_file = get_unique_file([foo, ".twr"])
                             time_file = os.path.join(foo, time_file)
                             par_file = get_unique_file([foo, ".par"])
                         elif re.search("\.dir$", foo):
                             twr_file = get_unique_file([foo, ".twr"])
                             par_file = get_unique_file([foo, ".par"])
                             time_file = time_file
                         else:
                             continue
         
                         if twr_file:
                             scan_twr.scan_report(twr_file)
                             scan_time.scan_report(time_file)
                             scan_time.scan_par(par_file)
                             #########################
                             #time_title = ['design']+scan_time.get_title2()
                             srr_data = scan_time.get_srr_time_data()
                             mrp_data = scan_time.get_mrp_time_data()
                             par_data = scan_time.get_par_time_data()
                             real_cpu_total = scan_time.get_total_time()
                             all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                             data_list = []
                             for key in scan_time.get_title():
                                 value = all_time_data.get(key,'NA')
                                 data_list.append(value)
                             data_list2 = [design]+[target_fmax_for_time] +data_list
                             append_file(report_file_time,",".join(data_list2))
                                 
                             #########################
                             #data = [design] + scan_mrp.get_data() + \
                             #      scan_twr.get_data() + data_list
                             if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                 data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                             ['_']*len(data_list)
                             else:
                                 data_list = scan_mrp.get_data() + \
                                   scan_twr.get_data() + data_list
                             data = [design] + data_list
                             append_file(report_file, ",".join(data))
                             data = [design]
                             append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                             append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                             #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                             scan_time.reset_par_time_data()
                         if not twr_file:
                             srr_data = scan_time.get_srr_time_data()
                             mrp_data = scan_time.get_mrp_time_data()
                             par_data = scan_time.get_par_time_data()
                             real_cpu_total = scan_time.get_total_time()
                             all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                   real_cpu_total.items() )
                             data_list = []
                             for key in scan_time.get_title():
                                 value = all_time_data.get(key,'NA')
                                 data_list.append(value)
                             data_list2 = [design]+[target_fmax_for_time] +data_list
                             append_file(report_file_time,",".join(data_list2))
                             #data = [design] + scan_mrp.get_data()+ data_list
                             if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                 data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                             else:
                                 data = [design] + scan_mrp.get_data()+ data_list
                             append_file(report_file, ",".join(data))
                             append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                             scan_time.reset_par_time_data()
                 scan_mrp.scan_clocks(mrp_file)
                 clock_dict = scan_mrp.get_parse_line_clocks()
                 for key in clock_dict.keys():
                     line = design+','+key+','+clock_dict[key]
                     append_file(report_file_clock,line)
                 recover.run()
         
     os.chdir(root_dir)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    if family:
        for_pattern = '_'+family
    if syn:
        for_pattern = for_pattern + '_'+syn
    dir_pattern = re.compile(for_pattern)
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    if design:
        print_always( 'scanning %s'%design)
        if design in all_designs:
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,dir+'.csv')
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        if not_exists(report_file_clock):
                            append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan)
                    if not_exists('rev_1', "srr file directory"):
                        continue
                    srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                    if srr_file:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    _project_name = "%s_%s" % (dir, design[:7])
                    project_name = _project_name.strip("_")
                    mrp_file = project_name + ".mrp"
                    if not_exists(mrp_file, "map report file"):
                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file= ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([foo, ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                                scan_twr.scan_report(twr_file)
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) + ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+ ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    
        else:
            print 'The design is not exists in the job_dir'
            return
    
    else:
        root_dir = os.getcwd()
        for design in all_designs:
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path):
                if dir_pattern.search(dir) and os.path.isdir(os.path.join(design_path,dir)) and dir.startswith('_'):
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,dir+'.csv')
                    if report_file in report_file_list:
                        pass
                    else:
                        report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan)
                    if not_exists('rev_1', "srr file directory"):
                        
                        continue
                    srr_file = get_unique_file([os.path.join(design_path,dir,'rev_1'), ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    _project_name = "%s_%s" % (dir, design[:7])
                    project_name = _project_name.strip("_")
                    mrp_file = project_name + ".mrp"
                    if not_exists(mrp_file, "map report file"):
                        
                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file= ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_time.reset_par_time_data()
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([foo, ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                                scan_twr.scan_report(twr_file)
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                #data = [design] + scan_mrp.get_data() + \
                                #      scan_twr.get_data() + data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                                ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                                scan_time.reset_par_time_data()
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                      real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                #data = [design] + scan_mrp.get_data()+ data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                                scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    recover.run()
            
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted,note)
    #----------------update run_stand-------------------#
    pass_log = glob.glob('*'+syn+'_pass_case.log')
    if pass_log:
        pass_log = pass_log[0]
    else:
        pass_log = '__'
    if os.path.isfile(pass_log):
        file_hand = file(pass_log,'r')
        lines = file_hand.readlines()
        file_hand.close()
        stand_name = glob.glob('*'+syn+'_run_standard.bat')
        if stand_name:
            stand_name = stand_name[0]
        #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
        else:
            stand_name = ''
        run_standard = file(stand_name,'r')
        run_standard_lines = run_standard.readlines()
        run_standard.close()
        useful_lines = []
        for case in lines:
            case = case.strip()
            if not case:
                 continue
            else:
                 pass
            case_tab = '--design='+case
            case_tab_re = re.compile(case_tab+r'(\s+|$)')
            for line in run_standard_lines:
                line = line.strip()
                if not line:
                    continue
                if case_tab_re.search(line):
                    try:
                        fmax = float( design_fmax[case.strip()] )
                        fmax = str( int( fmax ))
                    #line = case_tab_re.sub('',line)
                        line = re.sub(r'--fmax-sweep=[\s\d]+\d','',line)
                        line2 = line + ' --fmax-sweep='+fmax+' '+fmax+' '+'10 \n'
                    except:
                        line2 = line
                    useful_lines.append(line2)
        run_standard = file(stand_name,'w')
        run_standard.writelines(useful_lines)
        run_standard.close()
Exemple #12
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name #this is useless now
    for_pattern=''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    
    all_designs = []
    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory'%job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 =  os.path.join(job_dir,dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []
    
    if 1:
        root_dir = os.getcwd()
        for design in all_designs:
            if need_design:
                if design ==  need_design:
                    pass
                else:
                    continue
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            if 1:
                if 1:
                    #####################
                    scanner = (scan_mrp, scan_twr, scan_time)
                    report_file = os.path.join(opt.job_dir,'aa'+'.csv')
                    if report_file in report_file_list:
                        pass
                    else:
                        report_file_list.append(report_file)
                    if not_exists(report_file):
                        title = ["Design"]
                        for item in scanner: #mrp twr time
                            title += item.get_title()
                        append_file(report_file, ",".join(title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_mrp = report_name+'_mrp'+subtex
                        if not_exists(report_file_mrp):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_mrp, ",".join(title))
                        report_file_twr = report_name+'_twr'+subtex
                        if not_exists(report_file_twr):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_twr, ",".join(title))
                        report_file_time = report_name+'_time'+subtex
                        if not_exists(report_file_time):
                            title = ["Design"] +['Target_fmax']
                            #for item in scanner: #mrp twr time
                            title += (scanner[2]).get_title()
                            append_file(report_file_time, ",".join(title))
                        report_file_clock = report_name+'_clock'+subtex
                        append_file(report_file_clock, ",".join(['Design','Colck','Loads']))
                ######################
                    #dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(design_path)
                    srr_file = get_unique_file([os.path.join(design_path,'impl'), ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path,dir,'rev_1',srr_file) 
                        scan_time.scan_srr(srr_file)
                    twr_file = time_file = par_file= mrp_file = ""
                    target_fmax_for_time = '_'
                    target_fmax_re = re.compile(r"Target_Seed_is_(.+)")
                    for foo in os.listdir("."):
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_time.reset_par_time_data()
                                print_always("  Scanning %s" % foo)
                                target_fmax_for_match = target_fmax_re.search(foo)
                                if target_fmax_for_match:
                                    target_fmax_for_time = target_fmax_for_match.group(1)
                                twr_file = get_unique_file([foo, ".twr"])
                                mrp_file = get_unique_file([foo, ".mrp"])
                                scan_mrp.scan_report(mrp_file)
                                scan_time.scan_mrp(mrp_file)
                                time_file = os.path.join(foo, time_file)
                                par_file = get_unique_file([os.path.join(foo,'PrjName.dir'), ".par"])
                            elif re.search("\.dir$", foo):
                                twr_file = get_unique_file([foo, ".twr"])
                                par_file = get_unique_file([foo, ".par"])
                                time_file = time_file
                            else:
                                continue
            
                            if twr_file:
                               
                                if design.startswith('hu'):
                                    scan_twr.scan_report(twr_file,'clk_246mhz_c') ### add by yu
                                
                                elif design =='fir1c':
                                        scan_twr.scan_report(twr_file,'fir_clk_c')
                                elif design.startswith('fir'):
                                        scan_twr.scan_report(twr_file,'fir_clk')
                                elif design.startswith('config'):
                                        scan_twr.scan_report(twr_file,'clk_c')
                                else:
                                    scan_twr.scan_report(twr_file,'i_clk')
                                
                                
                                scan_time.scan_report(time_file)
                                scan_time.scan_par(par_file)
                                #########################
                                #time_title = ['design']+scan_time.get_title2()
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                    
                                #########################
                                #data = [design] + scan_mrp.get_data() + \
                                #      scan_twr.get_data() + data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                                ['_']*len(data_list)
                                else:
                                    data_list = scan_mrp.get_data() + \
                                      scan_twr.get_data() + data_list
                                data = [design] + data_list
                                append_file(report_file, ",".join(data))
                                data = [design]
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data() ))
                                append_file(report_file_twr,",".join([design]+ scan_twr.get_data() ))
                                #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                                scan_time.reset_par_time_data()
                            if not twr_file:
                                srr_data = scan_time.get_srr_time_data()
                                mrp_data = scan_time.get_mrp_time_data()
                                par_data = scan_time.get_par_time_data()
                                real_cpu_total = scan_time.get_total_time()
                                all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                      real_cpu_total.items() )
                                data_list = []
                                for key in scan_time.get_title():
                                    value = all_time_data.get(key,'NA')
                                    data_list.append(value)
                                data_list2 = [design]+[target_fmax_for_time] +data_list
                                append_file(report_file_time,",".join(data_list2))
                                #data = [design] + scan_mrp.get_data()+ data_list
                                if all_time_data['Complete'] == 'NA' or all_time_data['Par_Done'] == 'NA':
                                    data = [design] + ['_']*len(scan_mrp.get_data())+  ['_']*len(data_list)
                                else:
                                    data = [design] + scan_mrp.get_data()+ data_list
                                append_file(report_file, ",".join(data))
                                append_file(report_file_mrp,",".join([design]+ scan_mrp.get_data()))
                                scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design+','+key+','+clock_dict[key]
                        append_file(report_file_clock,line)
                    recover.run()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f,add_average=1)
            report_sort.write_note(file_sorted,note)
    def prepare_kwargs(self):
        self.conf = self.flow_options.get("conf")
        same_ldf_dir = self.flow_options.get("same_ldf_dir")
        use_ice_prj = self.flow_options.get("use_ice_prj")
        self.kwargs = dict()
        if use_ice_prj:
            _project = self.flow_options.get("Project")

            implmnt_path = _project.get("Implementations")
            if not implmnt_path:
                xTools.say_it(
                    "-Error. Not found Implementations in project file")
                return 1

            self.kwargs["ProjectName"] = _project.get("ProjectName",
                                                      "DEF_PRJ_NAME")
            self.kwargs["implmnt_path"] = implmnt_path

            _src_files = _project.get("ProjectVFiles")
            _sdc_file = _project.get("ProjectCFiles")
            if _sdc_file:
                _sdc_file = xTools.get_relative_path(_sdc_file, same_ldf_dir)
            sdc_file = self.flow_options.get("sdc_file")
            ldc_file = self.flow_options.get("ldc_file")
            if sdc_file:
                sdc_file = xTools.get_relative_path(sdc_file, same_ldf_dir)
            if ldc_file:
                ldc_file = xTools.get_relative_path(ldc_file, same_ldf_dir)

            _src_files = re.split(",", _src_files)

            _src_files = [re.sub("=\w+", "", item) for item in _src_files]
            _src_files = [[xTools.get_relative_path(item, same_ldf_dir)]
                          for item in _src_files]

            #####################
            _implmnt = self.flow_options.get(implmnt_path)
            if not _implmnt:
                xTools.say_it("Error. Not found section: %s" % implmnt_path)
                return 1

            self.kwargs["DeviceFamily"] = _implmnt.get("DeviceFamily")
            self.kwargs["Device"] = _implmnt.get("Device")
            self.kwargs["DevicePackage"] = _implmnt.get("DevicePackage")

        else:
            _devkit = self.flow_options.get("devkit")
            _top_name = self.flow_options.get("top_module")
            _src_files = self.flow_options.get("src_files")
            _sdc_file = ""
            for item in _src_files:
                fext = xTools.get_fext_lower(item)
                if fext == ".sdc":
                    _sdc_file = item
                    break
            sdc_file = self.flow_options.get("sdc_file")
            ldc_file = self.flow_options.get("ldc_file")
            if sdc_file:
                sdc_file = xTools.get_relative_path(sdc_file, same_ldf_dir)
            if ldc_file:
                ldc_file = xTools.get_relative_path(ldc_file, same_ldf_dir)
            _src_files = [[xTools.get_relative_path(item, same_ldf_dir)]
                          for item in _src_files]

            implmnt_path = _top_name + "_Implmnt"
            _implmnt = dict()
            self.kwargs["ProjectName"] = _top_name
            self.kwargs["implmnt_path"] = implmnt_path
            self.kwargs["source_files"] = _src_files
            _dev_list = re.split("\s*,\s*", _devkit)

            self.kwargs["DeviceFamily"], self.kwargs["Device"], self.kwargs[
                "DevicePackage"] = _dev_list

        # --------------
        self.synthesis = self.flow_options.get("synthesis")

        if not self.synthesis:
            self.synthesis = "synplify"
        if self.synthesis == "synplify":
            _source_files = super_run.get_synp_source_files(_src_files)

            if sdc_file:
                kk = sdc_file
            elif _sdc_file:
                kk = _sdc_file
            else:
                kk = ""
            if kk:
                sdc_file = "add_file -constraint %s" % kk
            else:
                sdc_file = ""
        else:
            _source_files = super_run.get_lse_source_files(_src_files)
            if ldc_file:
                sdc_file = "-sdc %s" % ldc_file
            else:
                sdc_file = ""
        self.kwargs["source_files"] = _source_files
        self.kwargs["sdc_file"] = sdc_file
        # --------------

        _goal = self.flow_options.get("goal")
        _frequency = self.flow_options.get("frequency")
        if not _frequency:
            if self.synthesis == "lse":
                _frequency = 200
            else:
                _frequency = "Auto"
        _mixed_drivers = xTools.get_true(self.flow_options, "mixed_drivers")
        if _mixed_drivers:
            _mixed_drivers = "-resolve_mixed_drivers 1"  # For LSE
        else:
            _mixed_drivers = ""
        self.kwargs["mixed_drivers"] = _mixed_drivers
        if not _goal:
            _goal = "Timing"
        self.kwargs["goal"] = _goal
        self.kwargs["frequency"] = _frequency
        _DesignCell = _implmnt.get("DesignCell")
        if not _DesignCell:
            _DesignCell = self.kwargs["ProjectName"]
        self.kwargs["DesignCell"] = _DesignCell
        self.kwargs["cwd"] = xTools.win2unix(os.getcwd())
        self.kwargs["ice_opt_path"] = self.ice_opt_path
        ice_map_file = os.path.join(self.conf, "ice_synthesis", "ice.map")
        sts, ice_map_options = xTools.get_conf_options(ice_map_file,
                                                       key_lower=False)
        if sts:
            return sts

        _family = ice_map_options.get(self.kwargs.get("DeviceFamily"))
        if not _family:
            xTools.say_it("Warning. Not support Family: %s" %
                          self.kwargs.get("DeviceFamily"))
            return 1
        dev_lib = _family.get(self.kwargs.get("Device"))
        if not dev_lib:
            xTools.say_it("Warning. Not support %s" %
                          self.kwargs.get("Device"))
            return 1
        dev, lib = re.split("\s*,\s*", dev_lib)

        self.kwargs["dev_file"] = os.path.abspath(
            os.path.join(self.ice_root_path, "sbt_backend", "devices", dev))
        self.kwargs["lib_file"] = xTools.win2unix(
            os.path.join(self.ice_root_path, "sbt_backend", "devices", lib))

        # create dir
        _sbt_path = os.path.join(os.getcwd(), implmnt_path, "sbt")
        for item in ("bitmap", "gui", "netlister", "packer", "placer",
                     "router", "simulation_netlist", "timer"):
            tt = os.path.join(_sbt_path, "outputs", item)
            xTools.wrap_md(tt, "ice results path")

        for item in ("netlist", "sds"):
            tt = os.path.join(_sbt_path, "outputs", item)
            xTools.wrap_md(tt, "ice results path")
        self.kwargs["sdc_translator"] = os.path.abspath(
            os.path.join(self.ice_root_path,
                         r"sbt_backend\bin\sdc_translator.tcl"))

        info_line = "%s%s-%s" % (self.kwargs["DeviceFamily"],
                                 self.kwargs["Device"],
                                 self.kwargs["DevicePackage"])
        xTools.append_file(
            os.path.join(_sbt_path, "outputs", "device_info.txt"), info_line,
            False)

        tool_options = self.flow_options.get("tool options", dict())
        _BitmapInitRamBank = tool_options.get("BitmapInitRamBank")
        if not _BitmapInitRamBank:
            _BitmapInitRamBank = "1111"
        self.kwargs["BitmapInitRamBank"] = _BitmapInitRamBank
            def scan_sigal(job_dir, design):
                print_always('scanning %s' % design)
                design_path = os.path.join(job_dir, design)  # e60_ecp3/g64
                srr_file = ''
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    if (not re.search("Target", dir)
                        ) and os.path.isdir(dir_scan) and not srr_file:
                        srr_file = get_unique_file([dir_scan, ".srr"])
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file:
                    #    srr_file = get_unique_file([dir_scan, ".srr"])
                    if re.search("Target", dir) and os.path.isdir(dir_scan):
                        pass
                    else:
                        continue
                    recover = RecoverPath(dir_scan)
                    used_dir = ''
                    for f_d in os.listdir(dir_scan):
                        f_d_full = os.path.join(dir_scan, f_d)
                        if os.path.isdir(f_d_full):
                            if used_dir:
                                print 'Worning: There are two implementation in the design'
                            used_dir = f_d_full
                    #srr_file = get_unique_file([used_dir, ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path, dir, srr_file)
                        scan_time.scan_srr(srr_file)
                    mrp_file = get_unique_file([used_dir, ".mrp"])
                    if not_exists(mrp_file, "map report file"):

                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file = ""
                    target_fmax_for_time = '_'
                    #------------------------------------------------#
                    if 1:
                        useful_dir = used_dir
                        base_name = os.path.basename(useful_dir)
                        scan_time.reset_par_time_data()
                        target_fmax_for_match = target_fmax_re.search(dir)
                        if target_fmax_for_match:
                            target_fmax_for_time = target_fmax_for_match.group(
                                1)
                        twr_p = os.path.join(useful_dir,
                                             '*' + base_name + ".twr")
                        twr_file = get_unique_file(twr_p)
                        if not twr_file:
                            twr_file = get_unique_file([useful_dir, ".twr"])
                        time_file = os.path.join(useful_dir, time_file)
                        par_file = get_unique_file([useful_dir, ".par"])
                        if twr_file:
                            scan_twr.scan_report(twr_file)
                            scan_time.scan_report(time_file)
                            scan_time.scan_par(par_file)
                            #########################
                            #time_title = ['design']+scan_time.get_title2()
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items() +
                                                 mrp_data.items() +
                                                 par_data.items() +
                                                 real_cpu_total.items())
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))

                            #########################
                            #data = [design] + scan_mrp.get_data() + \
                            #      scan_twr.get_data() + data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                            ['_']*len(data_list)
                            else:
                                data_list = scan_mrp.get_data() + \
                                  scan_twr.get_data() + data_list
                            data = [design] + data_list
                            append_file(report_file, ",".join(data))
                            data = [design]
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            append_file(
                                report_file_twr,
                                ",".join([design] + scan_twr.get_data()))
                            #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                            scan_time.reset_par_time_data()
                            #lock.release()
                        if not twr_file:
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                  real_cpu_total.items() )
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))
                            #data = [design] + scan_mrp.get_data()+ data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data = [design] + ['_'] * len(
                                    scan_mrp.get_data()) + ['_'
                                                            ] * len(data_list)
                            else:
                                data = [design
                                        ] + scan_mrp.get_data() + data_list
                            append_file(report_file, ",".join(data))
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design + ',' + key + ',' + clock_dict[key]
                        append_file(report_file_clock, line)
                    lock.release()
                    recover.run()
Exemple #15
0
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    if not need_design:
        print 'In the bqs, you have to specify the design name'
        return
    pap = opt.pap
    report_dir = opt.report_dir
    print '--==--' * 20
    print report_dir
    print os.path.isdir(report_dir)
    print '--==--' * 20
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")

    if os.path.isdir(job_dir):
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    design_path = os.path.join(job_dir, need_design)
    design_path = re.sub(r'\\', '/', design_path)
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        design = os.path.basename(design_path)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir,
                                       dir + '_' + design + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        if 1:  # begin scan case
            if need_design:
                if design == need_design:
                    pass
                else:
                    return
            print_always('scanning %s' % design)
            srr_file = ''
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                if (not re.search("Target", dir)
                    ) and os.path.isdir(dir_scan) and not srr_file:
                    srr_file = get_unique_file([dir_scan, ".srr"])
            for dir in os.listdir(design_path):  # dir:Target_Fmax_is_060MHz
                dir_scan = os.path.join(design_path, dir)
                #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file:
                #    srr_file = get_unique_file([dir_scan, ".srr"])
                if re.search("Target", dir) and os.path.isdir(dir_scan):
                    pass
                else:
                    continue
                recover = RecoverPath(dir_scan)
                used_dir = ''
                for f_d in os.listdir(dir_scan):
                    f_d_full = os.path.join(dir_scan, f_d)
                    if os.path.isdir(f_d_full):
                        if used_dir:
                            print 'Warning: There are two implementation in the design'
                        used_dir = f_d_full
                #srr_file = get_unique_file([used_dir, ".srr"])
                if not srr_file:
                    pass
                else:
                    srr_file = os.path.join(design_path, dir, srr_file)
                    scan_time.scan_srr(srr_file)
                mrp_file = get_unique_file([used_dir, ".mrp"])
                if not_exists(mrp_file, "map report file"):

                    continue
                scan_mrp.scan_report(mrp_file)
                scan_time.scan_mrp(mrp_file)
                twr_file = time_file = par_file = ""
                target_fmax_for_time = '_'
                #------------------------------------------------#
                if 1:
                    useful_dir = used_dir
                    base_name = os.path.basename(useful_dir)
                    scan_time.reset_par_time_data()
                    target_fmax_for_match = target_fmax_re.search(dir)
                    if target_fmax_for_match:
                        target_fmax_for_time = target_fmax_for_match.group(1)
                    twr_p = os.path.join(useful_dir, '*' + base_name + ".twr")
                    twr_file = get_unique_file(twr_p)
                    if not twr_file:
                        twr_file = get_unique_file([useful_dir, ".twr"])
                    time_file = os.path.join(useful_dir, time_file)
                    par_file = get_unique_file([useful_dir, ".par"])
                    if twr_file:
                        scan_twr.scan_report(twr_file)
                        scan_time.scan_report(time_file)
                        scan_time.scan_par(par_file)
                        #########################
                        #time_title = ['design']+scan_time.get_title2()
                        srr_data = scan_time.get_srr_time_data()
                        mrp_data = scan_time.get_mrp_time_data()
                        par_data = scan_time.get_par_time_data()
                        real_cpu_total = scan_time.get_total_time()
                        all_time_data = dict(srr_data.items() +
                                             mrp_data.items() +
                                             par_data.items() +
                                             real_cpu_total.items())
                        data_list = []
                        for key in scan_time.get_title():
                            value = all_time_data.get(key, 'NA')
                            data_list.append(value)
                        data_list2 = [design] + [target_fmax_for_time
                                                 ] + data_list
                        append_file(report_file_time, ",".join(data_list2))

                        #########################
                        #data = [design] + scan_mrp.get_data() + \
                        #      scan_twr.get_data() + data_list
                        if all_time_data['Complete'] == 'NA' or all_time_data[
                                'Par_Done'] == 'NA':
                            data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                        ['_']*len(data_list)
                        else:
                            data_list = scan_mrp.get_data() + \
                              scan_twr.get_data() + data_list
                        data = [design] + data_list
                        append_file(report_file, ",".join(data))
                        #-------------------
                        #report_sort_bqs.sort_csv(report_file,job_dir)
                        #-------------------
                        data = [design]
                        append_file(report_file_mrp,
                                    ",".join([design] + scan_mrp.get_data()))
                        append_file(report_file_twr,
                                    ",".join([design] + scan_twr.get_data()))
                        #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                        scan_time.reset_par_time_data()
                    if not twr_file:
                        srr_data = scan_time.get_srr_time_data()
                        mrp_data = scan_time.get_mrp_time_data()
                        par_data = scan_time.get_par_time_data()
                        real_cpu_total = scan_time.get_total_time()
                        all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                              real_cpu_total.items() )
                        data_list = []
                        for key in scan_time.get_title():
                            value = all_time_data.get(key, 'NA')
                            data_list.append(value)
                        data_list2 = [design] + [target_fmax_for_time
                                                 ] + data_list
                        append_file(report_file_time, ",".join(data_list2))
                        #data = [design] + scan_mrp.get_data()+ data_list
                        if all_time_data['Complete'] == 'NA' or all_time_data[
                                'Par_Done'] == 'NA':
                            data = [design] + ['_'] * len(
                                scan_mrp.get_data()) + ['_'] * len(data_list)
                        else:
                            data = [design] + scan_mrp.get_data() + data_list
                        append_file(report_file, ",".join(data))
                        #-------------------
                        #report_sort_bqs.sort_csv(report_file,job_dir)

                        #-------------------

                        append_file(report_file_mrp,
                                    ",".join([design] + scan_mrp.get_data()))
                        scan_time.reset_par_time_data()
                scan_mrp.scan_clocks(mrp_file)
                clock_dict = scan_mrp.get_parse_line_clocks()
                for key in clock_dict.keys():
                    line = design + ',' + key + ',' + clock_dict[key]
                    append_file(report_file_clock, line)
                recover.run()
        report_sort_bqs.sort_csv(report_file, report_dir)
        os.chdir(root_dir)
def scan_report():
    opt = option()
    job_dir = opt.job_dir
    job_dir = os.path.abspath(job_dir)
    need_design = opt.design
    syn = opt.synthesis
    #syn = ''
    family = opt.family
    report_name = opt.report_name  #this is useless now
    for_pattern = ''
    pap = opt.pap
    scan_mrp = tool_scan_lattice.ScanLatticeMrp()
    scan_twr = tool_scan_lattice.ScanLatticeTwr(pap)
    scan_time = tool_scan_lattice.ScanLatticeTime()
    target_fmax_re = re.compile(r"Target_Fmax_is_(.+)MHz")
    if family:
        for_pattern = '_' + family
    if syn:
        for_pattern = for_pattern + '_' + syn
    dir_pattern = re.compile(for_pattern)

    all_designs = []
    if os.path.isdir(job_dir):
        for d in os.listdir(job_dir):
            if d.endswith('.csv'):
                d = os.path.join(job_dir, d)
                os.remove(d)
        pass
    else:
        print 'The job_dir:%s is not a directory' % job_dir
        return
    for dir in os.listdir(job_dir):  # get all the design path
        dir2 = os.path.join(job_dir, dir)
        if os.path.isdir(dir2):
            all_designs.append(dir)
        else:
            pass
    report_file_list = []

    if 1:
        root_dir = os.getcwd()
        dir = os.path.basename(opt.job_dir)
        if 1:
            scanner = (scan_mrp, scan_twr, scan_time)
            report_file = os.path.join(opt.job_dir, dir + '.csv')
            if report_file in report_file_list:
                pass
            else:
                report_file_list.append(report_file)
            if not_exists(report_file):
                title = ["Design"]
                for item in scanner:  #mrp twr time
                    title += item.get_title()
                append_file(report_file, ",".join(title))
            if 1:
                report_name, subtex = os.path.splitext(report_file)
                report_file_mrp = report_name + '_mrp' + subtex
                if not_exists(report_file_mrp):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[0]).get_title()
                    append_file(report_file_mrp, ",".join(title))
                report_file_twr = report_name + '_twr' + subtex
                if not_exists(report_file_twr):
                    title = ["Design"]
                    #for item in scanner: #mrp twr time
                    title += (scanner[1]).get_title()
                    append_file(report_file_twr, ",".join(title))
                report_file_time = report_name + '_time' + subtex
                if not_exists(report_file_time):
                    title = ["Design"] + ['Target_fmax']
                    #for item in scanner: #mrp twr time
                    title += (scanner[2]).get_title()
                    append_file(report_file_time, ",".join(title))
                report_file_clock = report_name + '_clock' + subtex
                append_file(report_file_clock,
                            ",".join(['Design', 'Colck', 'Loads']))
        for design in all_designs:
            lock = Lock()
            if need_design:
                if design == need_design:
                    pass
                else:
                    continue

            def scan_sigal(job_dir, design):
                print_always('scanning %s' % design)
                design_path = os.path.join(job_dir, design)  # e60_ecp3/g64
                srr_file = ''
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    if (not re.search("Target", dir)
                        ) and os.path.isdir(dir_scan) and not srr_file:
                        srr_file = get_unique_file([dir_scan, ".srr"])
                for dir in os.listdir(
                        design_path):  # dir:Target_Fmax_is_060MHz
                    dir_scan = os.path.join(design_path, dir)
                    #if (not re.search("Target", dir)) and os.path.isdir(dir_scan) and not srr_file:
                    #    srr_file = get_unique_file([dir_scan, ".srr"])
                    if re.search("Target", dir) and os.path.isdir(dir_scan):
                        pass
                    else:
                        continue
                    recover = RecoverPath(dir_scan)
                    used_dir = ''
                    for f_d in os.listdir(dir_scan):
                        f_d_full = os.path.join(dir_scan, f_d)
                        if os.path.isdir(f_d_full):
                            if used_dir:
                                print 'Worning: There are two implementation in the design'
                            used_dir = f_d_full
                    #srr_file = get_unique_file([used_dir, ".srr"])
                    if not srr_file:
                        pass
                    else:
                        srr_file = os.path.join(design_path, dir, srr_file)
                        scan_time.scan_srr(srr_file)
                    mrp_file = get_unique_file([used_dir, ".mrp"])
                    if not_exists(mrp_file, "map report file"):

                        continue
                    scan_mrp.scan_report(mrp_file)
                    scan_time.scan_mrp(mrp_file)
                    twr_file = time_file = par_file = ""
                    target_fmax_for_time = '_'
                    #------------------------------------------------#
                    if 1:
                        useful_dir = used_dir
                        base_name = os.path.basename(useful_dir)
                        scan_time.reset_par_time_data()
                        target_fmax_for_match = target_fmax_re.search(dir)
                        if target_fmax_for_match:
                            target_fmax_for_time = target_fmax_for_match.group(
                                1)
                        twr_p = os.path.join(useful_dir,
                                             '*' + base_name + ".twr")
                        twr_file = get_unique_file(twr_p)
                        if not twr_file:
                            twr_file = get_unique_file([useful_dir, ".twr"])
                        time_file = os.path.join(useful_dir, time_file)
                        par_file = get_unique_file([useful_dir, ".par"])
                        if twr_file:
                            scan_twr.scan_report(twr_file)
                            scan_time.scan_report(time_file)
                            scan_time.scan_par(par_file)
                            #########################
                            #time_title = ['design']+scan_time.get_title2()
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items() +
                                                 mrp_data.items() +
                                                 par_data.items() +
                                                 real_cpu_total.items())
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))

                            #########################
                            #data = [design] + scan_mrp.get_data() + \
                            #      scan_twr.get_data() + data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data_list = ['_']*len(scan_mrp.get_data()) +['_']*len(scan_twr.get_data()) +\
                                            ['_']*len(data_list)
                            else:
                                data_list = scan_mrp.get_data() + \
                                  scan_twr.get_data() + data_list
                            data = [design] + data_list
                            append_file(report_file, ",".join(data))
                            data = [design]
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            append_file(
                                report_file_twr,
                                ",".join([design] + scan_twr.get_data()))
                            #append_file(report_file_time,",".join([design]+ scan_time.get_data()))
                            scan_time.reset_par_time_data()
                            #lock.release()
                        if not twr_file:
                            srr_data = scan_time.get_srr_time_data()
                            mrp_data = scan_time.get_mrp_time_data()
                            par_data = scan_time.get_par_time_data()
                            real_cpu_total = scan_time.get_total_time()
                            all_time_data = dict(srr_data.items()+mrp_data.items()+par_data.items() + \
                                                  real_cpu_total.items() )
                            data_list = []
                            for key in scan_time.get_title():
                                value = all_time_data.get(key, 'NA')
                                data_list.append(value)
                            data_list2 = [design] + [target_fmax_for_time
                                                     ] + data_list
                            lock.acquire()
                            append_file(report_file_time, ",".join(data_list2))
                            #data = [design] + scan_mrp.get_data()+ data_list
                            if all_time_data[
                                    'Complete'] == 'NA' or all_time_data[
                                        'Par_Done'] == 'NA':
                                data = [design] + ['_'] * len(
                                    scan_mrp.get_data()) + ['_'
                                                            ] * len(data_list)
                            else:
                                data = [design
                                        ] + scan_mrp.get_data() + data_list
                            append_file(report_file, ",".join(data))
                            append_file(
                                report_file_mrp,
                                ",".join([design] + scan_mrp.get_data()))
                            scan_time.reset_par_time_data()
                    scan_mrp.scan_clocks(mrp_file)
                    clock_dict = scan_mrp.get_parse_line_clocks()
                    for key in clock_dict.keys():
                        line = design + ',' + key + ',' + clock_dict[key]
                        append_file(report_file_clock, line)
                    lock.release()
                    recover.run()

            Process(target=scan_sigal, args=(job_dir, design)).start()
        os.chdir(root_dir)
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted, note, design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted, note)
    file_hand_pass = file('pass_case.log', 'w')
    #----------read fail case first:
    try:
        file_hand_fail = file('fail_case.log', 'r')
        fail_case_lines = file_hand_fail.readlines()
        file_hand_fail.close()
        fail_case_lines2 = [
            f_c.split(':')[0].strip() for f_c in fail_case_lines
        ]
    except:
        fail_case_lines2 = []
    file_hand_fail = file('fail_case.log', 'w')
    for key in design_fmax.keys():
        v = design_fmax[key]

        if re.search(r'\d', v):
            file_hand_pass.write(key + '\n')
        else:
            if key in fail_case_lines2:
                fail_k = fail_case_lines[fail_case_lines2.index(key)]
                file_hand_fail.write(fail_k.strip() + '\n')
            else:
                file_hand_fail.write(key + '\n')
    file_hand_pass.close()
    file_hand_fail.close()

    #----------------update run_stand-------------------#
    if 1:
        pass_log = glob.glob('pass_case.log')
        if pass_log:
            pass_log = pass_log[0]
        else:
            pass_log = '__'
        if os.path.isfile(pass_log):
            file_hand = file(pass_log, 'r')
            lines = file_hand.readlines()
            file_hand.close()
            stand_name = glob.glob('*' + '_run_stand.bat')
            if stand_name:
                stand_name = stand_name[0]
            #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
            else:
                stand_name = ''
            run_standard = file(stand_name, 'r')
            run_standard_lines = run_standard.readlines()
            run_standard_lines = list(set(run_standard_lines))
            run_standard.close()
            #--------------
            try:
                again_name = glob.glob('*' + 'run_again.bat')
                if again_name:
                    again_name = again_name[0]
                #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
                else:
                    again_name = ''
                try:
                    again = file(again_name, 'r')
                    again_lines = again.readlines()
                    again_lines = list(set(again_lines))
                    again.close()
                    replaced_job_dir = os.path.basename(os.getcwd())
                    again_lines = [
                        re.sub(r'--job-dir=\S+',
                               '--job-dir=' + replaced_job_dir, ag)
                        for ag in again_lines
                    ]
                    new_again = []
                    #again_lines = [re.sub(r'--job-dir=\S+',replaced_job_dir,ag) for ag in again_lines]
                    #for ag in again_lines:
                    for ag in again_lines:
                        file_f = re.findall('--file=(\S+)', ag)
                        if file_f:
                            new_f = os.path.basename(file_f[-1])
                            ag = re.sub(r'--file=(\S+)', '--file=' + new_f, ag)
                        new_again.append(ag)

                    run_standard_lines1 = run_standard_lines + new_again
                    run_standard_lines1 = list(set(run_standard_lines1))
                except:
                    run_standard_lines1 = list(set(run_standard_lines))
                    #pass

                #run_standard_lines = run_standard_lines + again_lines
            except:
                pass

            useful_lines = []
            for case in lines:
                case = case.strip()
                if not case:
                    continue
                else:
                    pass
                case_tab = '--design=' + case
                case_tab_re = re.compile(case_tab + r'(\s+|$)')
                for line in run_standard_lines1:
                    line = line.strip()
                    if not line:
                        continue
                    if case_tab_re.search(line):
                        try:
                            fmax = float(design_fmax[case.strip()])
                            fmax = str(int(fmax))
                            line = re.sub(r'--fmax-sweep=[\s\d]+\d', '', line)
                            line2 = line + ' --fmax-sweep=' + fmax + ' ' + fmax + ' ' + '10 \n'
                            useful_lines.append(line2)
                        except:
                            #line2 = line
                            pass

            run_standard = file(stand_name, 'w')
            run_standard.writelines(useful_lines)
            run_standard.close()
def scan_report():
    opt = option()
    scanner = (tool_scan_altera.ScanAlteraFit(), tool_scan_altera.ScanAlteraFmax())
    job_dir = opt.job_dir
    if not os.path.isdir(job_dir):
        print 'Error, can not get directory:%s'%job_dir
        return -1
    design = opt.design
    tag = opt.special_structure
    report_name = opt.report_name #this is useless now
    if report_name == 'report.csv':
        report_file = os.path.basename(job_dir)+'.csv'
    report_path = opt.report_path
    if not report_path:
        report_path = job_dir
    report_file = os.path.join(report_path,report_file)
    scan_fit = tool_scan_altera.ScanAlteraFit()
    scan_fmax =  tool_scan_altera.ScanAlteraFmax()
    scan_time_mem = tool_scan_altera.ScanTimeMem()
    all_designs = []
    if not design:
        if os.path.isdir(job_dir):
            pass
        else:
            print 'The job_dir:%s is not a directory'%job_dir
            return
        for dir in os.listdir(job_dir):  # get all the design path
            dir2 =  os.path.join(job_dir,dir)
            if os.path.isdir(dir2):
                all_designs.append(dir)
            else:
                pass
    else:
        all_designs.append(design)
    report_file_list = []
    if 1:
        root_dir = os.getcwd()
        title = ["Design"]
        for item in (scan_fit,scan_fmax,scan_time_mem): #mrp twr time
            title += item.get_title()
        append_file(report_file, ",".join(title))
        global_title = title
        for design in all_designs:
            print_always( 'scanning %s'%design)
            design_path = os.path.join(job_dir,design)
            for dir in os.listdir(design_path): #at here dir should be as "_cyclone4_syn"
                if dir == tag:
                    #####################
                    scanner = (scan_fit, scan_fmax,scan_time_mem)
                    
                    report_file_list.append(report_file)
                    if not_exists(report_file):
                        append_file(report_file, ",".join(global_title))
                    if 1:
                        report_name,subtex = os.path.splitext(report_file)
                        report_file_fit = report_name+'_fit'+subtex
                        if not_exists(report_file_fit):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[0]).get_title()
                            append_file(report_file_fit, ",".join(title))
                        report_file_sta = report_name+'_sta'+subtex
                        if not_exists(report_file_sta):
                            title = ["Design"]
                            #for item in scanner: #mrp twr time
                            title += (scanner[1]).get_title()
                            append_file(report_file_sta, ",".join(title))
                        report_file_time_mem = report_name+'_time_mem'+subtex
                        if not_exists(report_file_time_mem):
                            title = ["Design"]
                            title += (scanner[2]).get_title()
                            append_file(report_file_time_mem, ",".join(title))  
                ######################
                    dir_scan = os.path.join(design_path,dir)
                    recover = RecoverPath(dir_scan) 
                    fit_file = sta_file = map_file = srr_file =  ""
                    
                    if 'rev_1' in os.listdir('.'): # this part used to scan srr if run synthesis with synpro
                        scan_time_mem.reset()
                        foo = os.path.join(dir_scan,'rev_1')
                        srr_file = get_unique_file(foo+'/'+'*.srr')
                        if srr_file:
                            scan_time_mem.scan_srr(srr_file)
                    
                    for foo in os.listdir("."):
                        data = []
                        if os.path.isdir(foo):
                            if re.search("Target", foo):
                                scan_fit.reset()
                                scan_fmax.reset()
                                scan_time_mem.set_fit_data()
                                scan_time_mem.set_map_data()
                                print_always("  Scanning %s" % foo)
                                fit_file = get_unique_file(foo+'/'+"*.fit.rpt")
                                sta_file = get_unique_file(foo+'/'+"*.sta.rpt")
                                map_file = get_unique_file(foo+'/'+'*.map.rpt')
                                if fit_file:
                                    scan_fit.scan_report(fit_file)
                                    #raw_input(1)
                                    scan_time_mem.scan_fit(fit_file)
                                    #raw_input(2)
                                    data1=[design]+scan_fit.get_data()
                                    append_file(report_file_fit, ",".join(data1))
                                    data = data + data1
                                else:
                                    data1=[design]+['NA']*len(scan_fit.get_title() )
                                    data = data + data1
                                    print 'AA'
                                if sta_file:
                                    scan_fmax.scan_report(sta_file)
                                    #raw_input(3)
                                    data2=[design]+scan_fmax.get_data()
                                    append_file(report_file_sta, ",".join(data2))
                                    data = data + data2[1:]
                                else:
                                    data1=['NA']*len(scan_fmax.get_title() )
                                    data = data + data1
                                if map_file:
                                    scan_time_mem.scan_map(map_file)
                                    #raw_input(4)
                                    scan_t_m = scan_time_mem.get_data()
                                    append_file(report_file_time_mem, ",".join([design]+scan_t_m))
                                    data  = data + scan_t_m
                                else:
                                    data1=['NA']*len(scan_time_mem.get_title() )
                                    data = data + data1
                                append_file(report_file, ",".join(data))
                                for_bqs_data = '<scan_case>\n'
                                for id1, t in enumerate( global_title):
                                    for_bqs_data = for_bqs_data + "\t<%s>"%t+data[id1]+"</%s>\n"%t
                                for_bqs_data = for_bqs_data +"</scan_case>"
                                print '#BQS_RETRN_DATA_BEGIN#'
                                print for_bqs_data
                                print '#BQS_RETRN_DATA_END#'
                    recover.run()
        os.chdir(root_dir) 
    #report_file_list = []    
    for f in report_file_list:
        if os.path.isfile(f):
            file_sorted,note,design_fmax = report_sort.sort_csv(f)
            report_sort.write_note(file_sorted,note)
    #----------------update run_stand-------------------#
    if 0:
        pass_log = glob.glob('*'+syn+'_pass_case.log')
        if pass_log:
            pass_log = pass_log[0]
        else:
            pass_log = '__'
        if os.path.isfile(pass_log):
            file_hand = file(pass_log,'r')
            lines = file_hand.readlines()
            file_hand.close()
            stand_name = glob.glob('*'+syn+'_run_standard.bat')
            if stand_name:
                stand_name = stand_name[0]
            #stand_name = os.path.join(top_base,top_base2+'_'+syn+'_run_standard.bat')
            else:
                stand_name = ''
            run_standard = file(stand_name,'r')
            run_standard_lines = run_standard.readlines()
            run_standard.close()
            useful_lines = []
            for case in lines:
                case = case.strip()
                if not case:
                     continue
                else:
                     pass
                case_tab = '--design='+case
                case_tab_re = re.compile(case_tab+r'(\s+|$)')
                for line in run_standard_lines:
                    line = line.strip()
                    if not line:
                        continue
                    if case_tab_re.search(line):
                        try:
                            fmax = float( design_fmax[case.strip()] )
                            fmax = str( int( fmax ))
                        #line = case_tab_re.sub('',line)
                            line = re.sub(r'--fmax-sweep=[\s\d]+\d','',line)
                            line2 = line + ' --fmax-sweep='+fmax+' '+fmax+' '+'10 \n'
                        except:
                            line2 = line
                        
                        useful_lines.append(line2)
            run_standard = file(stand_name,'w')
            run_standard.writelines(useful_lines)
            run_standard.close()