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
« 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# --------------------------------------------------------------------------------------------------
9from __future__ import annotations
11from typing import TYPE_CHECKING
13from .simlib_commercial import VivadoSimlibCommercial
14from .simlib_ghdl import VivadoSimlibGhdl
15from .simlib_nvc import VivadoSimlibNvc
17if TYPE_CHECKING:
18 from pathlib import Path
20 from vunit.ui import VUnit
22 from .simlib_common import VivadoSimlibCommon
25class VivadoSimlib:
26 """
27 Factory class for getting a Vivado simlib API.
28 """
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.
38 Will return a :class:`.VivadoSimlibCommon` subclass object.
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
48 if simulator_interface is None:
49 raise RuntimeError("VUnit found no simulator. Can not proceed.")
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 )
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 )
67 return VivadoSimlibCommercial(
68 vivado_path=vivado_path,
69 output_path=output_path,
70 vunit_proj=vunit_proj,
71 simulator_interface=simulator_interface,
72 )