Hi everyone!
I have an associative array, like this one:
string settings_block [string];//associative array wtih parameters
In it, i have parameters and their values in string type:
PARAM_NAME1 1
PARAM_NAME2 0 0 0 0
I try to get access to elments like this:
string el_name_of_set_bl;//name of the element of the setting block
string el_val_of_set_bl;//value of the element of the setting block
el_val_of_set_bl = settings_block.first (el_name_of_set_bl);//get first element of setting block
for (int i = 1; i < settings_block.size(); i++) begin//start from element #1 because first has already been read
el_val_of_set_bl = settings_block.next (el_name_of_set_bl);//get next element of setting block
end
compiler tells me, that output of .next() method should be int
When declare el_val_of_set_bl as int, i (surely) cannot get full value of PARAM2 (0 0 0 0), i only get 0
How should i get access to these elements?
Thank you!
here’s the complete code, hope this is enough to get the idea
//------------------------------------------------
//reads all parameters from text file and puts them in one string
//------------------------------------------------
function string make_append_string(
string file_name,//name of file
bit parse_by_name = 1'b1
);
string str_to_append;//string that will be appended to conf_string
int file_id;
string settings_block [string];//associative array wtih parameters
string el_name_of_set_bl;//name of the element of the setting block
string el_val_of_set_bl;//value of the element of the setting block
file_id = $fopen(file_name, "r");
parse_config_block(file_id,parse_by_name,settings_block);
$fclose(file_id);
el_val_of_set_bl = settings_block.first (el_name_of_set_bl);//get first element
for (int i = 1; i < settings_block.size(); i++) begin//first has already been read
str_to_append = $sformatf(str_to_append, el_name_of_set_bl," ", el_val_of_set_bl,"**");
el_val_of_set_bl = settings_block.next (el_name_of_set_bl);//get next element
end
//to add the last element to string
str_to_append = $sformatf(str_to_append, el_name_of_set_bl," ", el_val_of_set_bl, "**");
return str_to_append;
endfunction
function automatic int parse_config_block(
int fid,
bit parse_by_name,
ref string settings_block[string]
);
string next_word;
string param_name;
string param_value;
bit block_end_is_found;
begin
block_end_is_found = parse_by_name ? 0 : 1;
if(fid == 0) begin
$error("Wrong file identifier");
return -1;
end
else begin
$display("Inside the parse_config_block");
next_word = get_next_word(fid);
if(parse_by_name && next_word != "{") begin
return -1;
end
if(parse_by_name) begin
next_word = get_next_word(fid);
end
while(!(next_word.len() == 0 || $feof(fid) != 0)) begin
if(next_word == "}") begin
block_end_is_found = 1;
break;
end
param_name = next_word;
next_word = get_next_word(fid);
$display(next_word);
if(!is_value(next_word) || next_word.len() == 0) begin
return -1;
end
param_value = {next_word, " "};
next_word = get_next_word(fid);
$display(next_word);
while(next_word.len() > 0) begin
if(!is_value(next_word)) begin
break;
end
param_value = {param_value, next_word, " "};
next_word = get_next_word(fid);
$display(next_word);
end
settings_block[param_name] = param_value;
//param_name = next_word;
end
end
return (parse_by_name && !block_end_is_found) ? -1 : 1;
end
endfunction
input .txt file looks like this:
{
DC_IIR_ENABLE 0
DC_FIR_OR_LOOKUP_ENABLE 2
NOTCH_IIR_ENABLE 0
0
0
0
}
The error i get is:
assigning a packed type “int” to a string requires a cast
It refers to the line
el_val_of_set_bl = settings_block.next (el_name_of_set_bl);