Forum Discussion
Altera_Forum
Honored Contributor
9 years agoI can see what you're trying to do here - read the entire file into an array.
Modelsim definitely supports arrays of access types - I have done it plenty of times. And you can put access types in records (a handy way to build linked lists). The problem will be because the readline procedure deallocates current_line before putting the new line into current_line. As you are storing current_line in the array, and not current_line.all, the data dissapears. IMHO, you're overcomplicating things here. You could just have a function called "get_file_length" to return the number of lines in the file, then create an array of that length and return the array, without having it being a pointer to an array of lines. Something like this (I prefer functions for the type of stuff you have done):
function get_file_length(filename : string) return natural is
variable ret : natural := 0;
file f : text open read_mode is filename;
variable l : line;
begin
while not ENDFILE(f) loop
readline(f,l);
ret := ret + 1;
end loop;
return ret;
end;
function read_file(filename : string) return t_line_vector is
constant N_LINES : natural := get_file_length(filename);
file f : text open read_mode is filename;
variable res : t_line_vector(0 to N_LINES-1)
variable l : line;
begin
for i in res'range loop
readline(f, l);
res(i) = new string(l'range);
res(i).all = l.all;
end loop;
return res;
end function read_file;
function read_file(filename : string) return t_line_vector_ptr is
variable res : t_line_vector_ptr;
begin
res = new t_line_vector( t_line_vector'(read_file(filename) ) )
return res;
end function read_file;