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 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()
Beispiel #3
0
 def run_simrel_flow(self):
     _t = os.path.abspath(os.path.join(os.getcwd(), ".."))
     my_recov = xTools.ChangeDir(_t)
     import xSimrel
     bidi_type_name = ""
     simrel_section = self.flow_options.get("simrel")
     if simrel_section:
         _bidi_type = simrel_section.get("bidi_type")
         if _bidi_type:
             bidi_type_name = _bidi_type.lower()
     sts = xSimrel.main(self.simrel_path, self.run_simrel,
                        self.sim_vendor_name, bidi_type_name)
     my_recov.comeback()
     return sts
Beispiel #4
0
 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 process(self):
     self.create_sim_lib_path()
     base_dir = os.path.dirname(self.sim_lib_path)
     if xTools.wrap_md(base_dir, "Simulation Library Path"):
         return 1
     recov = xTools.ChangeDir(base_dir)
     if os.path.isdir(self.sim_lib_path):
         xTools.say_it("Check %s" % self.sim_lib_path)
         while True:
             if os.path.isfile(xTools.LOCK_FILE):
                 xTools.say_it("Message. found lock file: %s" %
                               xTools.LOCK_FILE)
                 time.sleep(5)
             else:
                 break
     else:
         xTools.wrap_md(self.sim_lib_path, "simulation library path")
         args = (self.diamond_path, self.hdl_type, self.family,
                 self.sim_name, self.sim_bin_path)
         xTools.run_safety(compile_library, *args)
         os.remove(xTools.LOCK_FILE)
     recov.comeback()
def get_lib_file(hdl_type, family_path):
    lib_files = list()
    p_hdl_type = re.compile("(.+)\Wvhdl\W(\w+)$")
    if hdl_type == "verilog":
        for foo in os.listdir(family_path):
            fext = xTools.get_fext_lower(foo)
            if fext == ".v":
                lib_files.append(os.path.join(family_path, foo))
            elif fext == ".vhd":
                xTools.say_it("Warning. found vhd file in %s" % family_path)
    else:  # vhdl
        mti_path = os.path.join(family_path, "mti")
        src_path = os.path.join(family_path, "src")

        list_v, list_vhd = list(), list()
        m = p_hdl_type.search(family_path)
        if m:
            outside_verilog_path = os.path.join(m.group(1), "verilog",
                                                m.group(2))
            if xTools.not_exists(outside_verilog_path,
                                 "Verilog simulation path"):
                pass
            else:
                for v_file in ("GSR.v", "PUR.v"):
                    real_v = os.path.join(outside_verilog_path, v_file)
                    if os.path.isfile(real_v):
                        list_v.append(real_v)
        pseudo_v = "pseudo_pullup.v"
        if os.path.isfile(pseudo_v):
            pass
        else:
            xTools.write_file(pseudo_v, v_file_lines)
        list_v.append(os.path.abspath(pseudo_v))

        for foo in os.listdir(src_path):
            fext = xTools.get_fext_lower(foo)
            abs_foo = os.path.join(src_path, foo)
            if fext == ".v":
                list_v.append(abs_foo)
            elif fext == ".vhd":
                list_vhd.append(abs_foo)
            else:
                xTools.say_it("Warning. found unknown file %s" % abs_foo)

        recov = xTools.ChangeDir(mti_path)
        if sys.platform[:3] == "win":
            bat_file = "orc_cmpl.bat"
        else:
            bat_file = "orc_cmpl.csh"
        already_have_v = 0
        for line in open(bat_file):
            line = line.strip()
            if line.startswith("rem"): continue
            if not line: continue
            line_list = re.split("\s+", line)
            if line_list[0] in ("vcom", "vlog"):
                hdl_file = os.path.abspath(line_list[-1])
                if os.path.isfile(hdl_file):
                    lib_files.append(hdl_file)
                else:
                    if re.search("\*\.v", line_list[-1]):
                        lib_files += list_v
                        already_have_v = 1
                    else:
                        xTools.say_it("Warning. un-support line: %s" % line)
        if not already_have_v:
            lib_files = list_v + lib_files
        recov.comeback()
    return lib_files
    def process(self):
        xTools.head_announce()

        if self.run_option_parser():
            return 1

        xTools.say_it(dict(os.environ), "Original Environments:", self.debug)
        if self.scan_only:
            return self.run_scan_only_flow()

        if self.sanity_check():
            return 1

        play_time = xTools.play_announce(self.src_design, self.dst_design)
        self.out_log = log_file = os.path.join(self.dst_design,
                                               "runtime_console.log")
        xTools.add_cmd_line_history(log_file)
        os.environ["BQS_L_O_G"] = log_file
        _recov = xTools.ChangeDir(self.dst_design)
        sts = 0

        if self.check_only:
            sts2 = self.run_check_flow()
            _recov.comeback()
            return sts2

        if not sts:
            self.record_debug_message()
            if self.run_ice:
                pass
            else:
                sts = self.create_env_setter()
        if not sts:
            sts = self.merge_local_options()

        if not sts:
            sts = self.copy_update_conf_file()
        xTools.say_it(dict(os.environ), "Original Environments:", self.debug)

        self.pre_process = self.scripts_options.get("pre_process")
        self.post_process = self.scripts_options.get("post_process")
        # run normal flow
        if self.pre_process:
            run_pre_post_process(self.src_design, self.pre_process)
        try:
            if not sts:
                if self.run_ice:
                    sts = self.run_ice_flow()
                else:
                    self.synthesis_only = xTools.get_true(
                        self.scripts_options, "synthesis_only")
                    if self.env_setter.will_run_simulation():
                        sts = self.run_simulation_flow()
                    else:
                        _ldf_file = self.scripts_options.get("ldf_file")
                        if _ldf_file:
                            sts = self.run_tcl_flow()
                        elif self.scripts_options.has_key("cmd_flow"):
                            sts = self.run_cmd_flow()
                        else:
                            sts = self.run_tcl_flow()
            xTools.stop_announce(play_time)
        except Exception, e:
            xTools.say_it("Error. %s" % e)
Beispiel #8
0
    def _run_simulation(self, sim_path, source_files, user_options):
        if xTools.wrap_md(sim_path, "Simulation Path"):
            return 1

        _recov = xTools.ChangeDir(sim_path)
        if self.copy_tb_files(""):
            _recov.comeback()
            return 1
        use_source_do_file = 0
        if not user_options:  # rtl simulation
            if self.others_path:
                self.copy_other_files()
            src_lines = xTools.get_content_in_start_end(
                self.do_template, self.p_src_start, self.p_src_end)
            for src in src_lines:
                if re.search("(vlog|vcom)", src):
                    use_source_do_file = 1

        do_lines = list()
        need_remove_ovi = 0
        if use_source_do_file:  # modify do file and use it!
            start_source = 0
            start_tb = 0
            for line in open(self.do_template):
                line = line.rstrip()
                m_src_start = self.p_src_start.search(line)
                m_src_end = self.p_src_end.search(line)
                m_tb_start = self.p_tb_start.search(line)
                m_tb_end = self.p_tb_end.search(line)
                if not start_source:
                    start_source = m_src_start
                if m_src_end:
                    start_source = 0

                if not start_tb:
                    start_tb = m_tb_start
                if m_tb_end:
                    start_tb = 0

                if not (start_source or start_tb):
                    do_lines.append(line)
                elif start_source or start_tb:
                    new_line = get_new_real_path(self.do_template, line)
                    if start_source:
                        line_list = re.split("\s+", line.strip())
                        if line_list[0] in ("vlog", "vcom"):
                            hdl_file = line_list[-1]
                            real_hdl_file = xTools.get_relative_path(
                                hdl_file, os.getcwd())
                            if not os.path.isfile(real_hdl_file):
                                real_hdl_file = xTools.get_relative_path(
                                    hdl_file, os.path.join("../../sim"))
                            if not os.path.isfile(real_hdl_file):
                                pass
                            else:
                                modified, real_hdl_file = get_real_hdl_file(
                                    real_hdl_file, self.run_scuba)
                                cur_fext = xTools.get_fext_lower(real_hdl_file)
                                if modified:
                                    if cur_fext == ".vhd":
                                        line_list = ["vcom", ""]
                                    else:
                                        line_list = ["vlog", ""]
                                line_list[-1] = real_hdl_file
                                if not need_remove_ovi:
                                    if xTools.get_fext_lower(
                                            real_hdl_file) in (".vho", ".vhd",
                                                               ".vhdl"):
                                        need_remove_ovi = 1
                                new_line = " ".join(line_list)
                    do_lines.append(new_line)
        else:
            start_source = start_tb = 0
            for line in open(self.do_template):
                line = line.rstrip()
                if re.search("%", line):
                    line = line % self.do_args
                    do_lines.append(line)
                    continue
                if start_source:
                    if self.p_src_end.search(line):
                        if not user_options:  # RTL simulation
                            source_files = [
                                xTools.get_relative_path(
                                    item, self.dst_design)
                                for item in source_files
                            ]
                        v_v_line = self.add_vlog_vcom_lines(source_files)
                        if not v_v_line:
                            xTools.say_it(
                                "Error. Not any source files for running %s" %
                                sim_path)
                            xTools.say_it("")
                            _recov.comeback()
                            return 1
                        need_remove_ovi = self.use_vhd
                        do_lines += v_v_line[:]
                        start_source = 0
                        do_lines.append(line)
                    continue
                else:
                    start_source = self.p_src_start.search(line)
                    if start_source:
                        do_lines.append(line)
                        continue

                if start_tb:
                    if self.p_tb_end.search(line):
                        _kk = self.use_vhd
                        v_v_line = self.add_vlog_vcom_lines(
                            self.final_tb_files, add_tb=1)
                        self.use_vhd = _kk
                        do_lines += v_v_line[:]
                        start_tb = 0
                        do_lines.append(line)
                    continue
                else:
                    start_tb = self.p_tb_start.search(line)
                    if start_tb:
                        do_lines.append(line)
                        continue
                do_lines.append(line)
        do_file = "do_%s.do" % sim_path

        new_do_lines = list()
        lib_name = xTools.get_fname(self.dev_lib)
        if need_remove_ovi:
            lib_name = re.sub("ovi_", "", lib_name)

        p1 = re.compile("vmap\s+(\S+)\s+(\$dev_lib)")
        p2 = ""
        tmp_lib_name = ""
        for _ in do_lines:
            if p1:
                m1 = p1.search(_)
                if m1:
                    p1 = ""
                    p2 = re.compile("vsim.+\s+-L\s+%s" % m1.group(1))
                    tmp_lib_name = m1.group(1)
                    _ = "vmap %s %s" % (lib_name, m1.group(2))
            elif p2:
                m2 = p2.search(_)
                if m2:
                    p2 = ""
                    _ = re.sub("-L\s+%s" % tmp_lib_name, "-L %s" % lib_name, _)
            new_do_lines.append(_)
        xTools.write_file(do_file, new_do_lines)
        utils.update_simulation_do_file(self.sim_vendor_name, do_file,
                                        self.lst_precision)

        args = "%s %s %s cmd %s %s" % (do_file, self.dev_lib, self.pri_lib,
                                       self.diamond, self.src_lib)

        if self.run_modelsim or self.run_questasim:
            sim_cmd = '%s/vsim -l sim_log.txt -c -do "do %s"' % (
                self.sim_vendor_bin, args)
        else:
            sim_cmd = "%s/vsimsa -l sim_log.txt -do %s" % (self.sim_vendor_bin,
                                                           args)
        sim_cmd = xTools.win2unix(sim_cmd, 0)
        if need_remove_ovi:
            sim_cmd = re.sub("ovi_", "", sim_cmd)
        # /*
        #  * If license not found, will launch again in 10 times.
        #  */
        log_file = "run_%s.log" % sim_path
        time_file = "run_%s.time" % sim_path
        sts = 0
        for i in range(10):
            if xTools.remove_dir_without_error(log_file):
                _recov.comeback()
                return 1
            sts = xTools.run_command(sim_cmd, log_file, time_file)
            if sts:
                if xTools.simple_parser(
                        log_file,
                    [re.compile("Unable to checkout a license")]):
                    xTools.say_it(
                        "Warning. No licence for running simulation. waiting ..."
                    )
                    time.sleep(i * 10)
                else:
                    break
            else:
                break
        dump_vcd_file()

        _recov.comeback()
        return sts