sonar.core.backends package

Submodules

sonar.core.backends.common module

Defines prologue and epilogue functions for all language backends

sonar.core.backends.common.add_headers(testbench_config, testbench, lang)

Add any header files to the testbench

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
  • lang (str) – Language of the testbench
Returns:

Updated testbench

Return type:

str

sonar.core.backends.common.prologue(testbench_config, testbench, lang)

Run prior to any language-specific backend

Parameters:
  • testbench_config (Testbench) – Testbench configuration
  • testbench (str) – Testbench to generate
  • lang (str) – Language of the testbench
Returns:

Updated testbench

Return type:

str

sonar.core.backends.cpp module

The C++ backend for generating testbenches

sonar.core.backends.cpp.create_testbench(testbench_config, testbench, directory)

Create the testbench for this language backend

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
  • directory (str) – Path to the directory to place generated files
Returns:

The testbench and the data file

Return type:

Tuple(str, str)

sonar.core.backends.cpp.declare_signals(testbench_config, testbench)

Declare and instantiate the variables used for the signals in the testbench

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.cpp.set_interfaces(testbench_config, testbench)

Add commands to interact with interfaces when reading the data file

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.cpp.set_signals(testbench_config, testbench)

Add commands to interact with signals when reading the data file

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.cpp.write_data_file(testbench_config)

Based on the test vectors, write the data file

Parameters:testbench_config (Testbench) – The testbench configuration
Returns:List of commands to write to the data file
Return type:list
sonar.core.backends.cpp.write_line(data_file, command, vector_id)

Write one line to the data file

Parameters:
  • data_file (list) – List of commands for the data file
  • command (dict) – Current command to write
  • vector_id (int) – Index of the current test vector
Returns:

Updated data_file

Return type:

list

sonar.core.backends.include module

Defines some shared functions for all language backends to use

sonar.core.backends.include.command_var_replace(target_string, interface, indent, language, action_type, endpoint)

This function replaces the variables in an interface action block. There are two named variables: $$name (referring to the interface name) and $$signal (referring to a particular side signal). All other $$ variables must be keys in the interface declaration in the configuration file.

Parameters:
  • target_string (str) – The preceding string to append to
  • interface (Interface) –
  • indent (str) – String to add as leading indent for each line
  • language (str) – Language of the testbench
  • action_type (str) – Identifier for the list of actions to perform
  • endpoint (Endpoint) – The endpoint used to get the actions
Returns:

The updated target_string

Return type:

str

sonar.core.backends.include.get_data_file_args(args, language)

For a interface, return the language-specific set of data file arguments

Parameters:
  • args (dict) – Dictionary of data file arguments for an interface
  • language (str) – Language of the testbench
Returns:

Language-specific data file arguments

Return type:

dict

sonar.core.backends.include.get_indentation(keyword, search_str)

In a multi-line string with new line characters, find the indentation of a search string. Currently assumes that spaces are used for indentation and the search string directly follows the indent.

Parameters:
  • keyword (string) – The keyword to search for
  • search_str (string) – String to search
Returns:

The indent

Return type:

string

sonar.core.backends.include.get_interface(interface_name: str) → Type[base_interface.InterfaceCore]

Import an interface from sonar

Parameters:interface_name (str) – Name of the interface
Returns:The interface
Return type:Type[base_interface.InterfaceCore]
sonar.core.backends.include.replace_block(target_string, command, interface, indent, key=None)

For multi-line code blocks, replace the $$X variables in it while respecting indentation

Parameters:
  • target_string (str) – The preceding string to append this block onto
  • command (str) – The block in which to replace things
  • interface – An interface
  • indent (str) – String to add as leading indent for each line
  • key (str or int, optional) – If the replacement string is a data structure, use this key to index it. Defaults to None.
Returns:

The updated target_string

Return type:

str

sonar.core.backends.include.replace_in_testbenches(testbenches, search_str, replace, include_langs=None, exclude_langs=None)

In a testbench, replace a string with another string.

Parameters:
  • testbenches (str or dict) – The testbench to replace text in. This may be a string representing a single testbench or a dictionary where different testbenches are indexed by language
  • search_str (str) – String to search for
  • replace (str-like) – Converted to string and used to replace search_str
  • include_langs (iterable, optional) – Iterable of a subset of languages to perform the replacement. Defaults to None.
  • exclude_langs (iterable, optional) – Iterable of a subset of languages to exclude from replacement. Defaults to None.
Returns:

The modified testbench. Same type as testbenches

Return type:

str or dict

sonar.core.backends.include.replace_signals(interface, action, command, target_string, indent, args)

This function performs duplication and text replacement for $$signals

Parameters:
  • interface – An interface
  • action (dict) –
  • command (str) – The string in which to replace signals
  • target_string (str) – The preceding string to append this block to
  • indent (str) – String to add as leading indent for each line
  • args (dict) – The order of interface arguments as a function of language
Returns:

The updated target_string

Return type:

str

sonar.core.backends.include.replace_variables(input_string: str, interface: Any, key: Optional[int] = None) → str

In a string, attempt to replace all the “$$X” variables with their definitions from the interface. If not found in the interface, it skips the variable, leaving it to the user to replace afterwards

Parameters:
  • input_string (str) – String containing $$X variables
  • interface (Any) – An interface
  • key (Union[int, None], optional) – If the replacement string is a data structure, use this key to index it. Defaults to None.
Returns:

Updated string

Return type:

str

sonar.core.backends.include.set_metadata(testbench_config, testbench)

Perform the direct substitutions from the sonar testbench metadata into the the testbench

Parameters:
  • testbench_config (Testbench) – Sonar testbench description
  • testbench (str) – The testbench template

sonar.core.backends.sv module

The SystemVerilog backend for generating testbenches

sonar.core.backends.sv.add_exerciser_ports(testbench_config, testbench, used_interfaces)

Add the ports of the Exerciser

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
  • used_interfaces (dict) – Each used interface appears once
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.add_timeformat(testbench_config, testbench)

Configure the time format for the testbench

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Raises:

SonarInvalidArgError – Invalid time format

Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.calculate_seeks(data_file, max_repeat, update_str, seek_str, count_str, converged)

This function repeats over the generated data file for systemverilog and calculates the character counts for the different packets/parallel sections so the fseek function can work properly during readback. It’s repeated until all the values converge to a static value.

Parameters:
  • data_file (list) – List of commands
  • max_repeat (int) – Maximum number of times to repeat without convergence
  • update_str (str) –

    ???

  • seek_str (str) –

    ???

  • count_str (str) –

    ???

  • converged (bool) – True if the sizes converge
Returns:

The data file and converged state

Return type:

tuple(list, bool)

sonar.core.backends.sv.count_commands(commands)

Count the number of actual commands from a list of commands that may contain “macro” commands

Parameters:commands (list) – List of commands
Returns:The true number of commands
Return type:int
sonar.core.backends.sv.create_clocks(testbench_config, testbench)

Create clocks used in the testbench

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.create_testbench(testbench_config, testbench, directory)

Create the testbench for this language backend

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
  • directory (str) – Path to the directory to place generated files
Returns:

The testbench and the data file

Return type:

Tuple(str, str)

sonar.core.backends.sv.declare_signals(testbench_config, testbench)

Declare all signals used to connect to the DUT

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.instantiate_dut(testbench_config, testbench)

Instantiate the device-under-test

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.instantiate_exerciser(testbench_config, testbench)

Instantiate the Exerciser module

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.modify_signal_name(original_name, dut_type)

For Vivado HLS, some signal names are changed from the source file in the generated Verilog. Here, we address that change

Parameters:
  • original_name (str) – The original name of the port from the src file
  • dut_type (dict) – Information from the testbench config describing the
  • of DUT that is being used. (type) –
Returns:

The modified name of the signal, if changed

Return type:

str

sonar.core.backends.sv.set_interfaces(testbench_config, testbench)

When reading commands, add the logic to assign interact with interfaces

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.set_signals(testbench_config, testbench, used_interfaces)

When reading commands, add the logic to assign values to individual signals

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
  • used_interfaces (dict) – Each used interface appears once
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.set_waits(testbench_config, testbench)

Add the logic to handle wait conditions

Parameters:
  • testbench_config (Testbench) – The testbench configuration
  • testbench (str) – The testbench being generated
Returns:

Updated testbench

Return type:

str

sonar.core.backends.sv.write_data_file(testbench_config)

Write the data file

Parameters:testbench_config (Testbench) – The testbench configuration
Returns:
The data file commands as a list and max number of
threads in any one test vector
Return type:tuple(list, int)
sonar.core.backends.sv.write_line(data_file, command, vector_id)

Write one command to the data file

Parameters:
  • data_file (list) – List of commands to write
  • command (dict) – Current command being written
  • vector_id (int) – Index of the test vector this command belongs to
Returns:

Updated data_file

Return type:

list

Module contents