def get_simrel_path(simrel_dirname, device): device = device.lower() p = re.compile("LFE5UM-(\d+)F", re.I) m = p.search(device) simrel_root, simrel_family = simrel_dirname, "" if m: simrel_family = os.path.join("sapphire", "sa_%sh" % m.group(1), "ncv") elif re.search("lif-", device): simrel_family = os.path.join("snow", "snow_5", "ncv") else: xTools.say_it("Error. Unknown device: %s" % device) return "", "", "" while True: xTools.say_it(" -- Searching real simrel path ...") time.sleep(5) for foo in os.listdir(simrel_root): abs_foo = os.path.join(simrel_root, foo) if os.path.isdir(abs_foo): check_file = os.path.join(abs_foo, "check_running.log") if os.path.isfile(check_file): continue else: t = open(check_file, "w") t.close() return simrel_root, foo, simrel_family
def dump_vcd_file(cur_dir=""): if not cur_dir: cur_dir = os.getcwd() if xTools.not_exists(cur_dir, "vcd path"): return 1 for foo in os.listdir(cur_dir): fname, fext = os.path.splitext(foo) if fext.lower() != ".vcd": continue try: vcd_data = Verilog_VCD.parse_vcd(os.path.join(cur_dir, foo)) except: xTools.say_it("Warning. Failed to dump from %s" % (os.path.join(cur_dir, foo))) return vcd_txt = "%s_vcd.txt" % fname dump_file = os.path.join(cur_dir, vcd_txt) xTools.say_it(" Dumping %s to %s" % (foo, vcd_txt)) dump_lines = list() keys = vcd_data.keys() keys.sort() for k in keys: v = vcd_data.get(k) nets = v.get("nets")[0] hier = nets.get("hier") if hier != "sim_top.uut": continue dump_lines.append("-" * 10) nets_keys = nets.keys() nets_keys.sort() dump_lines += ["%s : %s" % (nk, nets.get(nk)) for nk in nets_keys] dump_lines += xTools.distribute_list("time-value", v.get("tv"), 15) xTools.write_file(dump_file, dump_lines)
def copy_update_conf_file(self): if self.top_dir == self.job_dir: return # will copy conf file to src_design to dirname(_dst_design) conf_files = glob.glob(os.path.join(self.src_design, "*.conf")) if not conf_files: # not found conf file return if len(conf_files) > 1: xTools.say_it("Warning. Found more than 1 conf file under %s" % self.src_design) return 1 # now find a conf file # update it! src_conf = conf_files[0] dst_conf = os.path.join(os.path.dirname(self.dst_design), os.path.basename(src_conf)) p_golden = re.compile("^golden_file\s*=\s*(.+)$", re.I) ob_dst = open(dst_conf, "w") for line in open(src_conf): m_golden = p_golden.search(line) if m_golden: golden_file = m_golden.group(1) real_golden_file = xTools.get_abs_path(golden_file, self.src_design) if not os.path.isfile(real_golden_file): real_golden_file = golden_file print >> ob_dst, "golden_file = %s" % real_golden_file else: ob_dst.write(line) ob_dst.close()
def run_sim_ncv(simrel_dir, rbt_avc_folder): xTools.say_it(" -- Go to %s and run SimREL flow ..." % simrel_dir) _recov = xTools.ChangeDir(simrel_dir) src_files = ("fc.avc", "fc.rbt") temp_sh_file = "temp.sh" dst_files = ("fc.log", "fc.out", "irun.log", temp_sh_file) temp_sh = open(temp_sh_file, "w") for _file in (src_files + dst_files[:-1]): print >> temp_sh, "rm %s" % _file for _file in src_files: print >> temp_sh, "ln -s %s/%s %s" % (rbt_avc_folder, _file, _file) print >> temp_sh, "sim_ncv" temp_sh.close() sts = os.system("sh %s" % temp_sh_file) if sts: xTools.say_it("Failed to run simrel flow...") return sts # copy files t_copy = open("copy_files", "w") for _file in dst_files: print >> t_copy, "cp -f %s %s/." % (_file, rbt_avc_folder) print >> t_copy, "cp -rf outwaves %s/outwaves" % rbt_avc_folder t_copy.close() # execute it! sts = os.system("sh copy_files") _recov.comeback()
def get_local_bqs_options(xml_path, local_options, src_design): # section_qas = local_options.get("QAS Information") section_case = local_options.get("Case Information") # section_detail = local_options.get("QAS Description") local_bqs_options = dict() tb_file, file_list, uut_name = get_file_list(section_case, src_design) if not tb_file: say_it("-Warning. No tb file found") if not file_list: say_it("-Error. No source file list found.") return qa_options = get_qa_options(xml_path, section_case) if not qa_options: return qa_options["src_files"] = file_list sim_options = get_sim_options() if tb_file: sim_options["tb_file"] = tb_file if uut_name: sim_options["uut_name"] = uut_name _src_top_module = qa_options.get("src_top_module") sim_options["src_top_module"] = _src_top_module sim_options["resolution"] = "1ns" local_bqs_options["qa"] = qa_options local_bqs_options["sim"] = sim_options return local_bqs_options
def run_check_flow(self): # // run check flow always! report_path = self.scripts_options.get("cwd") #if(os.path.abspath(report_path) == os.path.abspath(self.job_dir)):# update by Yzhao1 # report_path = os.path.join(self.job_dir,self.design) if not self.check_rpt: report = "check_flow.csv" else: _check_rpt = xTools.get_abs_path(self.check_rpt, report_path) report_path, report = os.path.split(_check_rpt) check_py = os.path.join(os.path.dirname(__file__), '..', '..', 'tools', 'check', "check.py") check_py = os.path.abspath(check_py) if xTools.not_exists(check_py, "source script file"): return 1 cmd_kwargs = dict() cmd_kwargs["top_dir"] = "--top-dir=%s" % self.job_dir cmd_kwargs["design"] = "--design=%s" % self.design _check_conf = self.scripts_options.get("check_conf") if _check_conf: cmd_kwargs["conf_file"] = "--conf-file=%s" % _check_conf else: cmd_kwargs["conf_file"] = "" cmd_kwargs["report_path"] = "--report-path=%s" % report_path cmd_kwargs["tag"] = "--tag=%s" % self.tag cmd_kwargs["report"] = "--report=%s" % report cmd_kwargs["rerun_path"] = "--rerun-path=%s" % report_path # NEW check flow if self.scripts_options.get("synthesis_only"): _ = self.scripts_options.get("synthesis") if _ == "lse": cmd_kwargs["lse_check"] = "--lse-check" else: cmd_kwargs["synp_check"] = "--synp-check" else: for _ in ("run_par_trace", "run_par", "pushbutton"): if self.scripts_options.get(_): if self.scripts_options.get( "till_map"): # till map has higher priority pass else: cmd_kwargs["partrce_check"] = "--partrce-check" else: for _ in ("run_map", "till_map", "run_map_trace"): if self.scripts_options.get(_): cmd_kwargs["map_check"] = "--map-check" # cmd_line = r"%s %s " % (sys.executable, check_py) for key, value in cmd_kwargs.items(): cmd_line += " %s " % value cmd_line = xTools.win2unix(cmd_line, 0) xTools.say_it(" Launching %s" % cmd_line) sts, text = xTools.get_status_output(cmd_line) xTools.say_it(text) return sts
def run_pre_post_process(base_path, pp_scripts): """ add function for getting the real scripts if it has command arguments """ pp_scripts_list = re.split("\s+", pp_scripts) real_pp = xTools.get_abs_path(pp_scripts_list[0], base_path) if xTools.not_exists(real_pp, "pre/post process scripts"): return 1 start_from_dir, pp = os.path.split(real_pp) _recov = xTools.ChangeDir(start_from_dir) fext = xTools.get_fext_lower(real_pp) if fext == ".py": cmd_line = "%s %s " % (sys.executable, pp) elif fext == ".pl": cmd_line = "perl %s " % pp else: xTools.say_it("Unknown pre/post process scripts: %s" % pp) return 1 if len(pp_scripts_list) > 1: cmd_line += " ".join(pp_scripts_list[1:]) xTools.say_it("Launching %s" % cmd_line) #sts, text = xTools.get_status_output(cmd_line) #xTools.say_it(text) sts = os.system(cmd_line) _recov.comeback() return sts
def process(self): if not os.path.isfile(self.xml_file): if self.create_dev_xml_file(): return 1 else: # check the xml file, make sure its ok while 1: sts = xTools.simple_parser(self.xml_file, [re.compile("</DiamondDevKit>")], but_lines=3) if not sts: xTools.say_it("check %s after 15 seconds" % self.xml_file) time.sleep(15) continue break xml_parser = ElementTree.parse(self.xml_file) family_table = xml_parser.findall("Family") for item in family_table: family_name = item.get("name") family_text = item.get("text") t_family = dict(family=family_name, text=family_text) for part_table in item.getchildren(): part_name = part_table.get("name") part_dict = dict() part_dict.update(t_family) part_dict.update(part_table.attrib) ori_opt = part_dict.get("opt") if ori_opt: # mush have opt item part_dict["ori_opt"] = ori_opt part_dict["opt"] = self.opt_dict.get(ori_opt) self.devkit_dict[part_name] = part_dict
def merge_conf_options(self): ''' get the conf file setting, and merge them with command options ''' _conf = self.scripts_options.get("conf") if not _conf: _conf = os.path.join(os.path.dirname(sys.argv[0]), "..", "conf") if os.path.isdir(_conf): pass else: if xTools.not_exists(_conf, "Default Configuration Path"): return 1 _conf = os.path.abspath(_conf) self.scripts_options["conf"] = _conf conf_files = glob.glob(os.path.join(_conf, "*.ini")) if not conf_files: xTools.say_it("-Error. Not found any ini file under %s" % _conf) return 1 sts, conf_options = xTools.get_conf_options(conf_files) if sts: return 1 self._merge_options(conf_options) xTools.say_it(self.scripts_options, "Merge User/Default Configuration Options", self.debug)
def create_final_ldf_file(self): my_create = xLattice.CreateDiamondProjectFile(self.scripts_options) sts = my_create.process() self.final_ldf_file = my_create.final_ldf_file try: self.final_ldf_dict = xLattice.parse_ldf_file(self.final_ldf_file) except: self.final_ldf_dict = dict() xTools.say_it("-Error. Can not parse ldf file: %s" % self.final_ldf_file) if sts: return 1 self.final_ldf_dict = xLattice.parse_ldf_file(self.final_ldf_file) if sts: return sts if not self.final_ldf_dict: return 1 # after synthesis, set the backend environment if self.run_ice: pass elif self.env_setter.set_be_env(): return 1 current_diamond_version, small_version = xLattice.get_diamond_version() return xLattice.update_diamond_version(self.final_ldf_file, current_diamond_version)
def sanity_check(self): # get src_design and dst_design if self.top_dir: if not self.design: xTools.say_it("-Error. No design name specified") return 1 self.top_dir = os.path.abspath(self.top_dir) else: if self.design: if os.path.isabs(self.design): xTools.say_it( "-Warning. <--design=[single design_name or relative design path for top_dir]> is nicer" ) self.top_dir = os.getcwd() else: self.top_dir, self.design = os.path.split(os.getcwd()) self.src_design = xTools.get_abs_path(self.design, self.top_dir) if xTools.not_exists(self.top_dir, "Top Source path"): return 1 if xTools.not_exists(self.src_design, "Source Design"): return 1 if self.job_dir: self.job_dir = os.path.abspath(self.job_dir) else: self.job_dir = self.top_dir self.dst_design = os.path.join(self.job_dir, self.design, self.tag) if xTools.wrap_md(self.dst_design, "Job Working Design Path"): return 1 self.scripts_options["src_design"] = self.src_design self.scripts_options["dst_design"] = self.dst_design
def check_exists(self, a_file, comments): if not a_file: xTools.say_it("-Warning. No specified for %s" % comments) return 1, "" new_file = xTools.get_relative_path(a_file, self.src_design) if xTools.not_exists(new_file, comments): return 1, "" return 0, new_file
def get_conf_options(self): self.conf_options = dict() if self.conf: ini_files = glob.glob(os.path.join(self.conf, "*.ini")) if ini_files: sts, self.conf_options = xTools.get_conf_options(ini_files) if sts: return 1 else: xTools.say_it("Warning. No ini file found in %s" % self.conf)
def run_cmd_line_parser(self): self.parser = optparse.OptionParser() self.add_public_options() if self.run_vendor == "lattice": self.add_lattice_options() opts, args = self.parser.parse_args() _cmd_opts = eval(str(opts)) xTools.dict_none_to_new(self.scripts_options, _cmd_opts) self.debug = self.scripts_options.get("debug") xTools.say_it(self.scripts_options, "Command Options", self.debug)
def get_qa_options(xml_path, section_case): qa_options = dict() devkit = get_devkit_from_qas(xml_path, section_case) if not devkit: say_it("-Warning. Not get devkit for this design in qas info file") qa_options["devkit"] = devkit qa_options["project_name"] = section_case.get("project", "PrjName") qa_options["impl_name"] = section_case.get("impl_name", "DmTest") qa_options["src_top_module"] = section_case.get("design") qa_options["top_module"] = section_case.get("design") return qa_options
def merge_file_options(self): user_file = self.scripts_options.get("file") if not user_file: return elif user_file: if xTools.not_exists(user_file, "User Configuration File"): return 1 sts, file_options = xTools.get_conf_options(user_file) if sts: return 1 self._merge_options(file_options) xTools.say_it(self.scripts_options, "Merge User Configuration Options", self.debug)
def run_simulation_flow(self): xTools.say_it("-- Will launch simulation flow ...") if self.create_final_ldf_file(): pass # do Not care the implementation flow status, will run simulation flow straightly if self.dry_run: return if self.synthesis_only: return my_sim_flow = xSimulation.RunSimulationFlow(self.scripts_options, self.final_ldf_file, self.final_ldf_dict) sts = my_sim_flow.process() return sts
def run_flow(self, cmd_name, cmd_args, seed_number=0): cmd_template = self.template_dict.get(cmd_name) if not cmd_template: cmd_template = self.default_tmpl.get(cmd_name) if not cmd_template: xTools.say_it("- Error. Not support %s" % cmd_name) return 1 sts, cmd = xTools.get_cmd(cmd_template, cmd_args) if sts: return 1 if cmd_name == "par": if seed_number: cmd = re.sub("-t\s+\d+", "-t %d" % seed_number, cmd) return xTools.run_command(cmd, self.log_file, self.time_file)
def process(self): sts, qas_options = xTools.get_conf_options(self.qas_file, key_lower=False) if sts: return 1 self.case_info = qas_options.get(self.case_info_name) if not self.case_info: xTools.say_it("Error. No [%s] in %s" % (self.case_info_name, self.qas_file)) return 1 xTools.say_it(self.case_info, "[%s]" % self.case_info_name, self.debug) if self.parse_file_list(): return 1
def get_devkit_from_qas(xml_path, section_case): big_version, small_version = xLattice.get_diamond_version() xml_file = os.path.join( xml_path, "DiamondDevFile_%s%s.xml" % (big_version, small_version)) my_parser = xLatticeDev.DevkitParser(xml_file) if my_parser.process(): return device = section_case.get("device") speed = section_case.get("speed") package = section_case.get("package") family = section_case.get("family") if not device: say_it("-Warning. No device found in _qas.info") return if not speed: say_it("-Warning. No speed found in _qas.info") return if not package: say_it("-Warning. No package found in _qas.info") return if not family: say_it("-Warning. No family found in _qas.info") return device = device.lower() speed = speed.lower() package = package.lower() family = family.lower() devkit_detail = my_parser.devkit_dict for key, value in devkit_detail.items(): if value.get("ori_opt") != "COM": continue _family = value.get("family") if _family.lower() != family: continue _pty = value.get("pty") if _pty.lower() != device: continue _pkg = value.get("pkg") if _pkg.lower() != package: continue _spd = value.get("spd") if _spd.lower() == speed: return key say_it("-Warning. Can not find standard devkit for <%s %s %s %s>" % (family, device, package, speed)) return
def run_synthesis_flow(self, kwargs): src_files = xTools.get_src_files(self.src_files, self.src_design) if self.run_scuba: for item in src_files: real_file = item[-1] sts = xLattice.run_scuba_by_file(real_file, self.run_scuba) if sts == 1: return 1 if self.synthesis == "lse": self.run_lse_flow(src_files, kwargs) elif self.synthesis == "synplify": self.run_synplify_flow(src_files, kwargs) elif not self.synthesis: xTools.say_it("-Error. No synthesis name specified") return 1
def scan_report(self): scan_py = os.path.join(os.path.dirname(__file__), '..', '..', 'tools', 'scan_report', "bin", "run_scan_lattice_step_general_case.py") if xTools.not_exists(scan_py, "Scan scripts"): return 1 tag_dir = os.getcwd() design_dir, tag = os.path.split(tag_dir) job_dir, design = os.path.split(design_dir) args = "special-structure=%s --job-dir=%s --design=%s" % (tag, job_dir, design) cmd_line = "%s %s %s" % (sys.executable, scan_py, args) xTools.say_it(" Launching %s" % cmd_line) sts, text = xTools.get_status_output(cmd_line) xTools.say_raw(text)
def run_syn_vhd_simulation(self, sim_path): if self.synthesis == "lse": xTools.say_it( "Error. when synthesis is lse, --run-syn-vlg supported only") return else: xTools.say_it("TODO: Not support post synplify simulation flow.") source_file = os.path.join( self.impl_dir, "%s_%s_mapvho.vho" % (self.project_name, self.impl_name)) if xTools.not_exists(source_file, "Post synthesis Simulation VHDL File"): return 1 source_files = [os.path.join("..", source_file)] user_options = dict(run_syn_vhd=1) return self._run_simulation(sim_path, source_files, user_options)
def create_dev_xml_file(self): xml_file = xTools.win2unix(self.xml_file) xml_path = os.path.dirname(xml_file) recov = xTools.ChangeDir(xml_path) sts = xTools.run_safety(create_diamond_dev_xml, xml_file) while True: if not os.path.isfile(xTools.LOCK_FILE): break try: os.remove(xTools.LOCK_FILE) break except OSError: xTools.say_it("Try to remove %s in %s" % (xTools.LOCK_FILE, os.getcwd())) time.sleep(3) recov.comeback() return sts
def get_file_list(section_case, src_design): # say_it(section_case, "Section Case:") _file_list = section_case.get("file list") _file_list = re.split(",", _file_list) _file_list = [item.strip() for item in _file_list] file_list = list() tb_file = "" uut_name = "" p_tb = re.compile("(\w+)_tb$", re.I) for item in _file_list: fname = get_fname(item) fext = get_fext_lower(item) item = win2unix(item, 0) m_tb = p_tb.search(fname) if m_tb: tb_file = item continue if fext in (".v", ".vhd", ".sv"): file_list.append(item) else: say_it("Warning. %s found in _qas.info" % item) if tb_file: new_tb_file = get_relative_path(tb_file, src_design) if not os.path.isfile(new_tb_file): say_it("-Error. Not found testbench file: %s" % tb_file) else: base_module_name = "" for item in ("module", "project"): base_module_name = section_case.get(item) if base_module_name: break if not base_module_name: say_it("Error. Not found base module name") return tb_file, file_list, uut_name p_uut_name_verilog = re.compile("%s\s+(\w+)" % base_module_name) # add_16_SIGNED post( p_uut_name_vhdl = re.compile("(\S+)\s*:\s*%s" % base_module_name) # uut: mac_ecp4_m5678_09x09_ir_or_dc_mclk_up PORT MAP( fext = get_fext_lower(new_tb_file) if fext == ".v": matched_uut_name = simple_parser(new_tb_file, [ p_uut_name_verilog, ]) else: matched_uut_name = simple_parser(new_tb_file, [ p_uut_name_vhdl, ]) if not matched_uut_name: say_it("-Warning. can not find uut name in %s" % tb_file) else: uut_name = matched_uut_name[1].group(1) return tb_file, file_list, uut_name
def process(self): self.flatten_options() self.batch_flow = LatticeBatchFlow(self.section_cmd) if self.par_ncd: sts = self.run_from_par_ncd() elif self.map_ncd: sts = self.run_from_map_ncd() elif self.ngd_file: sts = self.run_from_ngd_file() elif self.edf_file: sts = self.run_from_edf_file() elif self.src_files: sts = self.run_from_src_files() else: xTools.say_it( "-Error. No input files found for running command flow") sts = 1 return sts
def _get_pty_sko(self, a_devkit): """ sko --- S: speed K: package O: opt """ pty_sko = dict() a_devkit = re.split("-", a_devkit) pty_sko["pty"] = "-".join(a_devkit[0:-1]) m_sko = self.p_sko.search(a_devkit[-1]) if not m_sko: xTools.say_it("Wrong spelling in DEVKIT %s" % a_devkit) return for item in ("speed", "short_pkg", "pkg_int", "short_opt"): t_value = m_sko.group(item) if item == "pkg_int": t_value = int(t_value) elif item == "speed": t_value = self._get_spd_list(t_value) pty_sko[item] = t_value return pty_sko
def flatten_options_1st(self): self.dry_run = self.scripts_options.get("dry_run") self.copy_all = self.scripts_options.get("copy_all") self.quiet = self.scripts_options.get("quiet") self.scan_only = self.scripts_options.get("scan_only") self.conf = self.scripts_options.get("conf") self.top_dir = self.scripts_options.get("top_dir") self.design = self.scripts_options.get("design") self.info_file_name = self.scripts_options.get("info") self.job_dir = self.scripts_options.get("job_dir") self.tag = self.scripts_options.get("tag") self.qas = self.scripts_options.get("qas") self.dsp = self.scripts_options.get("dsp") self.scuba_type = self.scripts_options.get("scuba_type") self.scuba_only = self.scripts_options.get("scuba_only") self.check_rpt = self.scripts_options.get("check_rpt") self.run_ice = self.scripts_options.get("run_ice") self.check_only = self.scripts_options.get("check_only") self.scan_rpt = self.scripts_options.get("scan_rpt") self.devkit = self.scripts_options.get("devkit") self.random_devkit = self.scripts_options.get("random_devkit") self.run_simrel = self.scripts_options.get("run_simrel") if self.run_simrel: _t = "{bit_out_format=Raw Bit File (ASCII)}" self.scripts_options["run_export_bitstream"] = 1 _set_strategy = self.scripts_options.get("set_strategy") if not _set_strategy: _set_strategy = _t else: if type(_set_strategy) is list: _set_strategy.append(_t) else: _set_strategy += ", %s" % _t self.scripts_options["set_strategy"] = _set_strategy if not self.devkit: if self.random_devkit: random_devkit = re.split(",", self.random_devkit) one_devkit = random.choice(random_devkit) self.devkit = one_devkit.strip() xTools.say_it("* MSG: select devkit %s from %s" % (self.devkit, random_devkit)) self.scripts_options["devkit"] = self.devkit
def run_syn_vlg_simulation(self, sim_path): if self.synthesis == "lse": glob_pattern = os.path.join(self.impl_dir, "*_prim.v") source_files = glob.glob(glob_pattern) if source_files: source_file = source_files[0] else: xTools.say_it( "Error. Not found _prim.v file for post lse simulation flow" ) return 1 else: xTools.say_it("TODO: Not support post synplify simulation flow.") return if xTools.not_exists(source_file, "Post synthesis Simulation Verilog File"): return 1 source_files = [os.path.join("..", source_file)] user_options = dict(run_syn_vlg=1) return self._run_simulation(sim_path, source_files, user_options)
def add_vlog_vcom_lines(self, src_files, add_tb=0): self.use_vhd = 0 if add_tb and not self.normal_tb: # use them directly. v_v_lines = src_files[:] else: v_v_lines = list() for item in src_files: fext = xTools.get_fext_lower(item) item = xTools.win2unix(item, 0) if fext in (".v", ".vo", ".sv"): v_v_lines.append("vlog %s" % item) elif fext in (".vho", ".vhd", ".vhdl"): v_v_lines.append("vcom %s" % item) if not self.use_vhd: self.use_vhd = 1 elif fext == ".lpf": continue else: xTools.say_it("-Warning. Unknown file: %s" % item) continue return v_v_lines