Coverage for tsfpga/vivado/simlib.py: 88%

16 statements  

« prev     ^ index     » next       coverage.py v7.6.9, created at 2024-12-20 20:52 +0000

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

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

3# 

4# This file is part of the tsfpga project, a project platform for modern FPGA development. 

5# https://tsfpga.com 

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

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

8 

9# Standard libraries 

10from pathlib import Path 

11from typing import TYPE_CHECKING, Optional 

12 

13# Third party libraries 

14from vunit.ui import VUnit 

15 

16# Local folder libraries 

17from .simlib_commercial import VivadoSimlibCommercial 

18from .simlib_ghdl import VivadoSimlibGhdl 

19 

20if TYPE_CHECKING: 

21 # Local folder libraries 

22 from .simlib_common import VivadoSimlibCommon 

23 

24 

25class VivadoSimlib: 

26 """ 

27 Factory class for getting a Vivado simlib API. 

28 """ 

29 

30 @staticmethod 

31 def init( 

32 output_path: Path, vunit_proj: VUnit, vivado_path: Optional[Path] = None 

33 ) -> "VivadoSimlibCommon": 

34 """ 

35 Get a Vivado simlib API suitable for your current simulator. Uses VUnit mechanism 

36 for detecting the simulator currently in use. 

37 

38 Will return a :class:`.VivadoSimlibCommon` subclass object. 

39 

40 Arguments: 

41 output_path: The compiled simlib will be placed here. 

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

43 vivado_path: Path to Vivado executable. If left out, the default 

44 from system ``PATH`` will be used. 

45 """ 

46 simulator_interface = vunit_proj._simulator_class # pylint: disable=protected-access 

47 

48 if simulator_interface is None: 

49 raise RuntimeError("VUnit found no simulator. Can not proceed.") 

50 

51 if simulator_interface.name == "ghdl": 

52 return VivadoSimlibGhdl( 

53 vivado_path=vivado_path, 

54 output_path=output_path, 

55 vunit_proj=vunit_proj, 

56 simulator_interface=simulator_interface, 

57 ) 

58 

59 return VivadoSimlibCommercial( 

60 vivado_path=vivado_path, 

61 output_path=output_path, 

62 vunit_proj=vunit_proj, 

63 simulator_interface=simulator_interface, 

64 )