Coverage for tsfpga/vivado/simlib_commercial.py: 85%

26 statements  

« prev     ^ index     » next       coverage.py v6.4, created at 2022-05-28 04:01 +0000

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 pathlib import Path 

10 

11from tsfpga.system_utils import create_file 

12from .common import get_vivado_path, run_vivado_tcl, to_tcl_path 

13from .simlib_common import VivadoSimlibCommon 

14 

15 

16class VivadoSimlibCommercial(VivadoSimlibCommon): 

17 

18 """ 

19 Handle Vivado simlib with a commercial simulator. 

20 """ 

21 

22 library_names = ["unisim", "secureip", "unimacro", "unifast", "xpm"] 

23 

24 _tcl = ( 

25 "set_param general.maxthreads 4\n" 

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

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

28 ) 

29 

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

31 """ 

32 Arguments: 

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

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

35 simulator_interface: A VUnit SimulatorInterface class. 

36 vivado_path (pathlib.Path): Path to Vivado executable. 

37 """ 

38 self._vunit_proj = vunit_proj 

39 self._vivado_path = get_vivado_path(vivado_path) 

40 

41 # Vivado uses a different name for Riviera-PRO 

42 self._simulator_name = ( 

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

44 ) 

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

46 

47 self.output_path = output_path / self._get_version_tag() 

48 

49 def _compile(self): 

50 tcl_file = self.output_path / "compile_simlib.tcl" 

51 tcl = self._tcl.format( 

52 simulator_name=self._simulator_name, 

53 simulator_folder=to_tcl_path(self._simulator_folder), 

54 output_path=to_tcl_path(self.output_path), 

55 ) 

56 create_file(tcl_file, tcl) 

57 run_vivado_tcl(self._vivado_path, tcl_file) 

58 

59 def _get_simulator_tag(self): 

60 """ 

61 Return e.g. modelsim_modeltech_pe_10_6c or riviera_riviera_pro_2018_10_x64. 

62 """ 

63 simulator_version = self._simulator_folder.parent.name 

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

65 

66 def _add_to_vunit_project(self): 

67 """ 

68 Add the compiled simlib to your VUnit project. 

69 """ 

70 for library_name in self.library_names: 

71 library_path = self.output_path / library_name 

72 assert library_path.exists(), library_path 

73 self._vunit_proj.add_external_library(library_name, library_path)