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

17 statements  

« prev     ^ index     » next       coverage.py v7.6.12, created at 2025-02-21 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 

15 

16if TYPE_CHECKING: 

17 from pathlib import Path 

18 

19 from vunit.ui import VUnit 

20 

21 from .simlib_common import VivadoSimlibCommon 

22 

23 

24class VivadoSimlib: 

25 """ 

26 Factory class for getting a Vivado simlib API. 

27 """ 

28 

29 @staticmethod 

30 def init( 

31 output_path: Path, vunit_proj: VUnit, vivado_path: Path | None = None 

32 ) -> VivadoSimlibCommon: 

33 """ 

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

35 for detecting the simulator currently in use. 

36 

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

38 

39 Arguments: 

40 output_path: The compiled simlib will be placed here. 

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

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

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

44 """ 

45 simulator_interface = vunit_proj._simulator_class # noqa: SLF001 

46 

47 if simulator_interface is None: 

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

49 

50 if simulator_interface.name == "ghdl": 

51 return VivadoSimlibGhdl( 

52 vivado_path=vivado_path, 

53 output_path=output_path, 

54 vunit_proj=vunit_proj, 

55 simulator_interface=simulator_interface, 

56 ) 

57 

58 return VivadoSimlibCommercial( 

59 vivado_path=vivado_path, 

60 output_path=output_path, 

61 vunit_proj=vunit_proj, 

62 simulator_interface=simulator_interface, 

63 )