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 

9from tsfpga import DEFAULT_FILE_ENCODING 

10 

11 

12class SbyWriter: 

13 """ 

14 Writes a SymbiYosys script file 

15 """ 

16 

17 @staticmethod 

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

19 """ 

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

21 """ 

22 

23 # Validate formal_settings 

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

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

26 raise ValueError( 

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

28 ) 

29 

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

31 g_args = [] 

32 if generics is not None: 

33 for key in iter(generics): 

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

35 

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

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

38 

39 sby = "" 

40 sby += "[options]\n" 

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

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

43 sby += "\n" 

44 sby += "[engines]\n" 

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

46 sby += "\n" 

47 sby += "[script]\n" 

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

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

50 sby += "\n" 

51 sby += "[files]\n" 

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

53 sby += "\n" 

54 

55 with open(output_path, "w", encoding=DEFAULT_FILE_ENCODING) as file_handle: 

56 file_handle.write(sby)