Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# -------------------------------------------------------------------------------------------------- 

2# Copyright (c) Lukas Vik. All rights reserved. 

3# 

4# This file is part of the tsfpga project. 

5# https://tsfpga.com 

6# https://gitlab.com/tsfpga/tsfpga 

7# -------------------------------------------------------------------------------------------------- 

8 

9 

10class SbyWriter: 

11 """ 

12 Writes a SymbiYosys script file 

13 """ 

14 

15 @staticmethod 

16 def write_sby(output_path, top, formal_settings, compiled_libraries, src_files, generics=None): 

17 """ 

18 Create SymbiYosys script. This script will run ghdl --synth 

19 """ 

20 

21 # Validate formal_settings 

22 valid_keys = set(["mode", "depth", "engine_command", "solver_command"]) 

23 if set(formal_settings.keys()) != valid_keys: 

24 raise ValueError( 

25 f"Unexpected keys. Got {formal_settings.keys()}, expected one of {valid_keys}" 

26 ) 

27 

28 p_args = [f"-P{compiled_library}" for compiled_library in compiled_libraries] 

29 g_args = [] 

30 if generics is not None: 

31 for key in iter(generics): 

32 g_args.append(f"-g{key}={generics[key]}") 

33 

34 # Assume that the top entity name is the same as file name 

35 ghdl_synth_cmd = ["ghdl", "--std=08", "-fpsl"] + p_args + g_args + [top + ".vhd", "-e", top] 

36 

37 sby = "" 

38 sby += "[options]\n" 

39 sby += f"mode {formal_settings['mode']} \n" 

40 sby += f"depth {str(formal_settings['depth'])} \n" 

41 sby += "\n" 

42 sby += "[engines]\n" 

43 sby += f"{formal_settings['engine_command']} {formal_settings['solver_command']}\n" 

44 sby += "\n" 

45 sby += "[script]\n" 

46 sby += f"{' '.join(ghdl_synth_cmd)} \n" 

47 sby += f"prep -top {top} \n" 

48 sby += "\n" 

49 sby += "[files]\n" 

50 sby += "\n".join([str(src_file) for src_file in src_files]) 

51 sby += "\n" 

52 

53 with open(output_path, "w") as file_handle: 

54 file_handle.write(sby)