Exemplo n.º 1
0
    def run(self,
            actions,
            verilator_includes=None,
            num_tests=0,
            _circuit=None):
        # Set defaults
        if verilator_includes is None:
            verilator_includes = []

        # Write the verilator driver to file.
        src = self.generate_code(actions, verilator_includes, num_tests,
                                 _circuit)
        driver_file = self.directory / Path(f"{self.circuit_name}_driver.cpp")
        with open(driver_file, "w") as f:
            f.write(src)

        # if use kratos, symbolic link the library to dest folder
        if self.use_kratos:
            from kratos_runtime import get_lib_path
            lib_name = os.path.basename(get_lib_path())
            dst_path = os.path.abspath(
                os.path.join(self.directory, "obj_dir", lib_name))
            if not os.path.isfile(dst_path):
                os.symlink(get_lib_path(), dst_path)
            # add ld library path
            env = {"LD_LIBRARY_PATH": os.path.dirname(dst_path)}
        else:
            env = None

        # Run makefile created by verilator
        make_cmd = verilator_make_cmd(self.circuit_name)
        subprocess_run(make_cmd, cwd=self.directory, disp_type=self.disp_type)

        # create the logs folder if necessary
        logs = Path(self.directory) / "logs"
        if not os.path.isdir(logs):
            os.mkdir(logs)

        # Run the executable created by verilator and write the standard
        # output to a logfile for later review or processing
        exe_cmd = [f'./obj_dir/V{self.circuit_name}']
        result = subprocess_run(exe_cmd,
                                cwd=self.directory,
                                disp_type=self.disp_type,
                                env=env)
        log = Path(self.directory) / 'obj_dir' / f'{self.circuit_name}.log'
        with open(log, 'w') as f:
            f.write(result.stdout)

        # post-process GetValue actions
        self.post_process_get_value_actions(actions)
Exemplo n.º 2
0
 def link_kratos_lib(self):
     from kratos_runtime import get_lib_path
     lib_path = get_lib_path()
     dst_path = os.path.join(self.directory, os.path.basename(lib_path))
     if not os.path.isfile(dst_path):
         os.symlink(lib_path, dst_path)
     # also add the directory to the current LD_LIBRARY_PATH
     self.sim_env["LD_LIBRARY_PATH"] = os.path.abspath(self.directory)
Exemplo n.º 3
0
def verilator_comp_cmd(top=None,
                       verilog_filename=None,
                       include_verilog_libraries=None,
                       include_directories=None,
                       driver_filename=None,
                       verilator_flags=None,
                       coverage=False,
                       use_kratos=False):
    # set defaults
    if include_verilog_libraries is None:
        include_verilog_libraries = []
    if include_directories is None:
        include_directories = []
    if verilator_flags is None:
        verilator_flags = []

    # build up the command
    retval = []
    retval += ['verilator']
    retval += ['-Wall']
    retval += ['-Wno-INCABSPATH']
    retval += ['-Wno-DECLFILENAME']
    retval += verilator_flags
    if verilog_filename is not None:
        retval += ['--cc', f'{verilog_filename}']
        if use_kratos:
            from kratos_runtime import get_lib_path
            retval += [os.path.basename(get_lib_path())]
    # -v arguments
    for file_ in include_verilog_libraries:
        retval += ['-v', f'{file_}']
    # -I arguments
    for dir_ in include_directories:
        retval += [f'-I{dir_}']
    if driver_filename is not None:
        retval += ['--exe', f'{driver_filename}']
    if top is not None:
        retval += ['--top-module', f'{top}']
    # vpi flag
    if use_kratos:
        retval += ["--vpi"]
    if coverage:
        retval += ["--coverage"]

    # return the command
    return retval