# Copyright 2024-2026 Universidad de Sevilla
# SPDX-License-Identifier: Apache-2.0
"""Toolchain interface for FVM"""
# Generic toolchain interface presented to the rest of the FVM framework. It
# imports different toolchain modules present in this same directory, which
# define the supported FVM methodology steps
import os
import importlib
# To add a toolchain, add it to this list and create a file with the same name
# and .py extension in the toolchains folder
toolchains = ['questa', 'sby']
DEFAULT_TOOLCHAIN = 'questa'
[docs]
def get_default_flags(toolchain):
"""
Returns tool flags for a specific toolchain
:param toolchain: toolchain name
:type toolchain: str
:return: list of default flags
:rtype: list
"""
module = importlib.import_module(f'fvm.toolchains.{toolchain}')
default_flags = module.default_flags
return default_flags
[docs]
def define_steps(framework, steps, toolchain):
"""
Import the corresponding toolchain module and call its define_steps function
to define the steps in the framework.
:param framework: the FvmFramework object
:type framework: fvm.framework.FvmFramework
:param steps: the Steps object where the steps will be registered
:type steps: fvm.steps.Steps
:param toolchain: toolchain name
:type toolchain: str
"""
module = importlib.import_module(f'fvm.toolchains.{toolchain}')
module.define_steps(framework, steps)
[docs]
def set_timeout(framework, toolchain, step, timeout):
"""
Import the corresponding toolchain module and call its set_timeout function
to set the timeout for a specific step.
:param framework: the FvmFramework object
:type framework: fvm.framework.FvmFramework
:param toolchain: toolchain name
:type toolchain: str
:param step: step name
:type step: str
:param timeout: timeout
:type timeout: str
"""
module = importlib.import_module(f'fvm.toolchains.{toolchain}')
module.set_timeout(framework, step, timeout)
[docs]
def set_coverage_goal(toolchain, step, goal):
"""
Import the corresponding toolchain module and call its set_coverage_goal function
to set the coverage goal for a specific step.
:param toolchain: toolchain name
:type toolchain: str
:param step: step name
:type step: str
:param goal: coverage goal
:type goal: int or float
"""
module = importlib.import_module(f'fvm.toolchains.{toolchain}')
module.set_coverage_goal(step, goal)
[docs]
def generics_to_args(toolchain, generics):
"""
Import the corresponding toolchain module and call its generics_to_args
function to convert generics to command line arguments.
:param toolchain: toolchain name
:type toolchain: str
:param generics: dictionary of generics
:type generics: dict
"""
module = importlib.import_module(f'fvm.toolchains.{toolchain}')
return module.generics_to_args(generics)
[docs]
def get_linecheck_patterns(framework, step=None):
"""
Import the corresponding toolchain module and call its
get_linecheck_{step} function to obtain patterns.
:param framework: the FvmFramework object
:type framework: fvm.framework.FvmFramework
:param step: step name (optional)
:type step: str or None
"""
if step is None:
return {}
module = importlib.import_module(f'fvm.toolchains.{framework.toolchain}')
func_name = f"get_linecheck_{step.replace('.', '_')}"
get_patterns_func = getattr(module, func_name, None)
if get_patterns_func is None:
return {}
return get_patterns_func()