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

20 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-27 20:51 +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 

9from __future__ import annotations 

10 

11from typing import TYPE_CHECKING 

12 

13from .simlib_commercial import VivadoSimlibCommercial 

14from .simlib_ghdl import VivadoSimlibGhdl 

15from .simlib_nvc import VivadoSimlibNvc 

16 

17if TYPE_CHECKING: 

18 from pathlib import Path 

19 

20 from vunit.ui import VUnit 

21 

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: Path | None = None 

33 ) -> VivadoSimlibCommon: 

34 """ 

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

36 Uses VUnit mechanism 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. 

44 If left out, the default from system ``PATH`` will be used. 

45 """ 

46 simulator_interface = vunit_proj._simulator_class # noqa: SLF001 

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 if simulator_interface.name == "nvc": 

60 return VivadoSimlibNvc( 

61 vivado_path=vivado_path, 

62 output_path=output_path, 

63 vunit_proj=vunit_proj, 

64 simulator_interface=simulator_interface, 

65 ) 

66 

67 return VivadoSimlibCommercial( 

68 vivado_path=vivado_path, 

69 output_path=output_path, 

70 vunit_proj=vunit_proj, 

71 simulator_interface=simulator_interface, 

72 )