Variables | Functions
Read From File Functions

Overview

Reading a data array from a file is very convenient when setting up ROM data and creating test vectors for testbench design. SpeakHDL offers two helper to help with the process. Because the VHDL language does not define integer_array or std_logic_vector_array types natively, SpeakHDL defines the (2) types along with the helper functions to read the data from a file.

When reading a std_logic_vector_array from a file, the length of the array is set by the length of the .dat file. However, care needs to be taken when resolving the width of each std_logic_vector. With SpeakHDL, the data path width of the framework module is set by the data_width parameter inside the config_file. In addition, it is assumed that the MSB are the leftmost bits. Thus, if the width of the data inside the .dat file is less than data_width number of bits, the read_array_from_file function will read the entire width of the std_logic_vector from file. However, if the width of the data inside the file is greater than the data_width number of bits, the read_array_from_file function will read only up to data_width number of bits.

Productivity Commands

In order to aid in productivity when reading from files, SpeakHDL provides the is hotkey command that can be used to alias a framework variable and also can be used define a constant array from a data file. For example if the user issues the following hotkey sequence command:

command_vector is command_data_file.dat

This will result in the following declaration being made which reads a constant std_logic_vector_array from a data file.

constant command_vector : std_logic_vector_array := read_array_from_file("command_data_file.dat");
See also
Data File

Types

integer_array  array ( natural range <> ) of integer
std_logic_vector_array  array ( natural range <> ) of std_logic_vector ( data_width- 1 downto 0 )

Functions

std_logic_vector_array   read_array_from_file ( constant filename: in string [ impure ]
integer_array   read_integer_array_from_file ( constant filename: in string [ impure ]