sonar/core/generate.py
def sonar(
    testbench_config,
    sonar_tb_filepath,
    languages="sv",
    force=False,
    legalize=True,
):
    """
    Call the appropriate backends to generate testbenches in the chosen
    languages.

    Args:
        testbench_config (Testbench): The user-defined testbench configuration
        sonar_tb_filepath (str): Path to the Python file used to generate
            testbench_config
        languages (str or tuple, optional): Language(s) to generate testbenches
            for. Defaults to "sv".
        force (bool, optional): Force testbench generation. Defaults to False
        legalize (bool, optional): Perform testbench legalization on the config

    Raises:
        SonarInvalidArgError: Raised for invalid languages
    """
    if legalize:
        testbench_config = legalize_config(testbench_config)
        # print(testbench_config)

    if isinstance(languages, str):
        if languages == "all":
            active_langs = ("sv", "cpp")
        else:
            active_langs = (languages,)
    elif isinstance(languages, (list, tuple)):
        active_langs = tuple(languages)
    else:
        raise SonarInvalidArgError(
            "Languages must be specified as a string or an iterable"
        )

    _, directory = parse_sonar_tb(sonar_tb_filepath)
    if not os.path.exists(directory):
        os.makedirs(directory)

    if not force:
        active_langs = filter_langs(active_langs, sonar_tb_filepath)

    testbenches = {}
    data_files = {}
    for lang in active_langs:
        template = os.path.join(
            os.path.dirname(__file__), "templates", f"template_tb.{lang}"
        )
        with open(template, "r") as f:
            testbenches[lang] = f.read()
        testbenches[lang] = prologue(testbench_config, testbenches[lang], lang)

    if "sv" in active_langs:
        testbenches["sv"], data_files["sv"] = create_sv_testbench(
            testbench_config, testbenches["sv"], directory
        )
    if "cpp" in active_langs:
        testbenches["cpp"], data_files["cpp"] = create_cpp_testbench(
            testbench_config, testbenches["cpp"], directory
        )

    for lang in active_langs:
        with open(get_tb_filepath(sonar_tb_filepath, lang), "w+") as f:
            f.write(testbenches[lang])
        with open(get_data_filepath(sonar_tb_filepath, lang), "w+") as f:
            f.write(data_files[lang])

    Call the appropriate backends to generate testbenches in the chosen
    languages.

    Args:
        testbench_config (Testbench): The user-defined testbench configuration
        sonar_tb_filepath (str): Path to the Python file used to generate
            testbench_config
        languages (str or tuple, optional): Language(s) to generate testbenches
            for. Defaults to "sv".
        force (bool, optional): Force testbench generation. Defaults to False
        legalize (bool, optional): Perform testbench legalization on the config

    Raises:
        SonarInvalidArgError: Raised for invalid languages
    
Call the appropriate backends to generate testbenches in the chosen
languages.
Call the appropriate backends to generate testbenches in the chosen languages .
def sonar(
    testbench_config,
    sonar_tb_filepath,
    languages="sv",
    force=False,
    legalize=True,
):
    if legalize:
        testbench_config = legalize_config(testbench_config)
    if isinstance(languages, str):
        if languages == "all":
            active_langs = ("sv", "cpp")
        else:
            active_langs = (languages,)
    elif isinstance(languages, (list, tuple)):
        active_langs = tuple(languages)
    else:
        raise SonarInvalidArgError(
            "Languages must be specified as a string or an iterable"
        )
    _, directory = parse_sonar_tb(sonar_tb_filepath)
    if not os.path.exists(directory):
        os.makedirs(directory)
    if not force:
        active_langs = filter_langs(active_langs, sonar_tb_filepath)
    testbenches = {}
    data_files = {}
    for lang in active_langs:
        template = os.path.join(
            os.path.dirname(__file__), "templates", f"template_tb.{lang}"
        )
        with open(template, "r") as f:
            testbenches[lang] = f.read()
        testbenches[lang] = prologue(testbench_config, testbenches[lang], lang)
    if "sv" in active_langs:
        testbenches["sv"], data_files["sv"] = create_sv_testbench(
            testbench_config, testbenches["sv"], directory
        )
    if "cpp" in active_langs:
        testbenches["cpp"], data_files["cpp"] = create_cpp_testbench(
            testbench_config, testbenches["cpp"], directory
        )
    for lang in active_langs:
        with open(get_tb_filepath(sonar_tb_filepath, lang), "w+") as f:
            f.write(testbenches[lang])
        with open(get_data_filepath(sonar_tb_filepath, lang), "w+") as f:
            f.write(data_files[lang])
def sonar ( testbench_config , sonar_tb_filepath , languages = "sv" , force = False , legalize = True , ) : if legalize : testbench_config = legalize_config ( testbench_config ) if isinstance ( languages , str ) : if languages == "all" : active_langs = ( "sv" , "cpp" ) else : active_langs = ( languages , ) elif isinstance ( languages , ( list , tuple ) ) : active_langs = tuple ( languages ) else : raise SonarInvalidArgError ( "Languages must be specified as a string or an iterable" ) _ , directory = parse_sonar_tb ( sonar_tb_filepath ) if not os . path . exists ( directory ) : os . makedirs ( directory ) if not force : active_langs = filter_langs ( active_langs , sonar_tb_filepath ) testbenches = { } data_files = { } for lang in active_langs : template = os . path . join ( os . path . dirname ( __file__ ) , "templates" , f"template_tb.{lang}" ) with open ( template , "r" ) as f : testbenches [ lang ] = f . read ( ) testbenches [ lang ] = prologue ( testbench_config , testbenches [ lang ] , lang ) if "sv" in active_langs : testbenches [ "sv" ] , data_files [ "sv" ] = create_sv_testbench ( testbench_config , testbenches [ "sv" ] , directory ) if "cpp" in active_langs : testbenches [ "cpp" ] , data_files [ "cpp" ] = create_cpp_testbench ( testbench_config , testbenches [ "cpp" ] , directory ) for lang in active_langs : with open ( get_tb_filepath ( sonar_tb_filepath , lang ) , "w+" ) as f : f . write ( testbenches [ lang ] ) with open ( get_data_filepath ( sonar_tb_filepath , lang ) , "w+" ) as f : f . write ( data_files [ lang ] )
Call the appropriate backends to generate testbenches in the chosen
languages.
Call the appropriate backends to generate testbenches in the chosen languages .
"""
    Call the appropriate backends to generate testbenches in the chosen
    languages.

    Args:
        testbench_config (Testbench): The user-defined testbench configuration
        sonar_tb_filepath (str): Path to the Python file used to generate
            testbench_config
        languages (str or tuple, optional): Language(s) to generate testbenches
            for. Defaults to "sv".
        force (bool, optional): Force testbench generation. Defaults to False
        legalize (bool, optional): Perform testbench legalization on the config

    Raises:
        SonarInvalidArgError: Raised for invalid languages
    """ # print(testbench_config)
Raised for invalid languages
Raised for invalid languages
SonarInvalidArgError
testbench_config
The user-defined testbench configuration
The user - defined testbench configuration
sonar_tb_filepath
Path to the Python file used to generate
testbench_config
Path to the Python file used to generate testbench_config
languages
Language(s) to generate testbenches
for. Defaults to "sv".
Language ( s ) to generate testbenches for . Defaults to " sv " .
force
Force testbench generation. Defaults to False
Force testbench generation . Defaults to False
legalize
Perform testbench legalization on the config
Perform testbench legalization on the config