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 

9import hashlib 

10from pathlib import Path 

11 

12from tsfpga.system_utils import create_file 

13from .common import get_vivado_path, run_vivado_tcl, to_tcl_path 

14from .simlib_common import VivadoSimlibCommon 

15 

16 

17class VivadoSimlibCommercial(VivadoSimlibCommon): 

18 

19 """ 

20 Handle Vivado simlib with a commercial simulator. 

21 """ 

22 

23 _libraries = ["unisim", "secureip", "unimacro", "unifast", "xpm"] 

24 

25 _tcl = ( 

26 "set_param general.maxthreads 4\n" 

27 "compile_simlib -simulator {simulator_name} -simulator_exec_path {{{simulator_folder}}} " 

28 "-family all -language all -library all -no_ip_compile -dir {{{output_path}}} -force" 

29 ) 

30 

31 def __init__(self, output_path, vunit_proj, simulator_interface, vivado_path): 

32 """ 

33 Arguments: 

34 output_path (`pathlib.Path`): The compiled simlib will be placed here. 

35 vunit_proj: The VUnit project that is used to run simulation. 

36 simulator_interface: A VUnit SimulatorInterface class. 

37 vivado_path (`pathlib.Path`): Path to Vivado executable. 

38 """ 

39 self._vunit_proj = vunit_proj 

40 self._vivado_path = get_vivado_path(vivado_path) 

41 

42 # Vivado uses a different name for Riviera-PRO 

43 self._simulator_name = ( 

44 "riviera" if simulator_interface.name == "rivierapro" else simulator_interface.name 

45 ) 

46 self._simulator_folder = Path(simulator_interface.find_prefix()) 

47 

48 self._output_path = output_path / self._get_version_tag() 

49 

50 def _compile(self): 

51 tcl_file = self._output_path / "compile_simlib.tcl" 

52 tcl = self._tcl.format( 

53 simulator_name=self._simulator_name, 

54 simulator_folder=to_tcl_path(self._simulator_folder), 

55 output_path=to_tcl_path(self._output_path), 

56 ) 

57 create_file(tcl_file, tcl) 

58 run_vivado_tcl(self._vivado_path, tcl_file) 

59 

60 def _get_version_tag(self): 

61 """ 

62 Add a hash of the TCL script to version tag. 

63 """ 

64 tag = super()._get_version_tag() 

65 tag += "." + self._get_tcl_hash() 

66 return tag 

67 

68 def _get_simulator_tag(self): 

69 """ 

70 Return e.g. modelsim_modeltech_pe_10_6c or riviera_riviera_pro_2018_10_x64. 

71 """ 

72 simulator_version = self._simulator_folder.parent.name 

73 return self._format_version(f"{self._simulator_name}_{simulator_version}") 

74 

75 def _get_tcl_hash(self): 

76 """ 

77 Return a (partial) hash of the TCL script that is used to compile simlib. 

78 """ 

79 return hashlib.md5(self._tcl.encode()).hexdigest()[0:8] 

80 

81 def _add_to_vunit_project(self): 

82 """ 

83 Add the compiled simlib to your VUnit project. 

84 """ 

85 for library in self._libraries: 

86 library_path = self._output_path / library 

87 assert library_path.exists(), library_path 

88 self._vunit_proj.add_external_library(library, library_path)