def write_vhdl_testbench(sim_dir, interface): file_name = "tb_file.vhd" with open(relative_file_path(file_name), "r") as test_bench_template: with open(os.path.join(sim_dir, "tb_file.vhd"), "w") as test_bench: for line in test_bench_template: if line == "--CHIPS UUT HERE\n": write_uut_vhdl(test_bench, interface) if line == "--use xil_defaultlib.foo;\n": test_bench.write("use xil_defaultlib.{};\n".format(interface.name)) else: test_bench.write(line) shutil.copyfile( relative_file_path("file_io.vhd"), os.path.join(sim_dir, "file_io.vhd"))
def run(self, chip_interface, sources, test_bench, inputs, stop_condition, constants_to_set): src_files = list(sources.design) + test_bench.source_files formatter = DataFormatter() script_call = [ "vivado", "-mode", "batch", "-source", relative_file_path("run-simulation.tcl"), "-tclargs", sources.project_file, "test", "1" if self.post_impl else "0" ] #TODO put into Simulator for io_port in chip_interface.io_ports: have_input = io_port in inputs constants_to_set.update( test_bench.configure_for_io_port( formatter, have_input, io_port, inputs[io_port] if have_input else None)) for name, value in constants_to_set.items(): if value.endswith("\""): value = value + ".vivadobugworkaround" script_call.append("{}={}".format(name, value)) subprocess.check_call(script_call) return simulation_file_results(test_bench, chip_interface)
def compile_chip(options, temp_dir, code_files, chip_name=None): if options.toolchain is Toolchain.Python: assert len(code_files) == 1, "can't compile multiple c files" # inputs, outputs = _parse_io_ports(code_files) main_file_name = os.path.basename(code_files[0]) if chip_name is None: chip_name = os.path.splitext(main_file_name)[0] compiler = os.path.abspath( relative_file_path("../../toolchain/compile.sh")) options = options.with_misc_opts( "-I", os.path.abspath(os.path.dirname(code_files[0]))) code_file_paths = [os.path.abspath(code_file) for code_file in code_files] chip_options = dict(dump_to=os.path.join(temp_dir, "instructions")) cmd_line_options = options.cmd_line_options code_file_paths.extend(mandatory_library_files()) if options.heap_size > 0: cmd_line_options.insert(0, "-DHEAP_SIZE={}".format(options.heap_size)) code_file_paths.append(library_file("optional/lib_malloc_memory.c")) if options.dont_initialize_memory: chip_options["no_initialize_memory"] = True if options.stack_size is not None: chip_options["stack_size"] = options.stack_size args = dict(options=chip_options) if options.toolchain is Toolchain.Llvm: with cwd(temp_dir): subprocess.check_call([compiler] + code_file_paths + cmd_line_options) with open(os.path.join(temp_dir, "out.opt.json"), "rb") as json_file: args["options"]["asm_params"] = json.load(json_file) with open(os.path.join(temp_dir, "out.stack-analysis.json"), "rb") as \ json_file: stack_analysis = json.load(json_file) if "stack_size" in stack_analysis: args["options"]["stack_size"] = stack_analysis["stack_size"] elif options.stack_size is None: sys.stderr.write( "Warning: No stack size defined; using default of 2000 bytes\n" ) args["options"]["stack_size"] = 2000 args["C_file"] = os.path.join(temp_dir, "code.bc.opt.s") args["options"]["is_asm"] = True else: args["C_file"] = os.path.join(temp_dir, code_file_paths[0]) return _instantiate_chip(chip_name, compilation_id(main_file_name, options), args, temp_dir)
def write(self, interface): with open(relative_file_path("tb.v"), "rb") as tb_file: testbench_format = tb_file.read() with open(os.path.join(self.directory, "tb.v"), "wb") as tb_file: writer = CodeWriter(tb_file) writer.write(testbench_format, inputs=interface.input_names, outputs=interface.output_names, chip_name=interface.name)
def run_implementation(self, results_dir): assert os.path.isfile(self.xpr_path) run_vivado_script(relative_file_path("synthesize.tcl"), [self.xpr_path]) impl_dir = os.path.join(self.vivado_project_dir, self.project_id + ".runs", "impl_1") for report_suffix in [ "_utilization_placed.rpt", "_timing_summary_routed.rpt"]: shutil.copyfile( os.path.join(impl_dir, self.chip_name + report_suffix), os.path.join(results_dir, self.project_id + report_suffix))
def generate_vivado_project(self): run_vivado_script(relative_file_path("make-project.tcl"), [self.directory, self.project_id, self.vivado_project_dir, self.board_name])